test_wpas_wmm_ac.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. # Test cases for wpa_supplicant WMM-AC operations
  2. # Copyright (c) 2014, Intel Corporation
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. from remotehost import remote_compatible
  7. import logging
  8. logger = logging.getLogger()
  9. import struct
  10. import hwsim_utils
  11. import hostapd
  12. from utils import fail_test
  13. def add_wmm_ap(apdev, acm_list):
  14. params = { "ssid": "wmm_ac",
  15. "hw_mode": "g",
  16. "channel": "11",
  17. "wmm_enabled" : "1"}
  18. for ac in acm_list:
  19. params["wmm_ac_%s_acm" % (ac.lower())] = "1"
  20. return hostapd.add_ap(apdev, params)
  21. def test_tspec(dev, apdev):
  22. """Basic addts/delts tests"""
  23. # configure ap with VO and VI requiring admission-control
  24. hapd = add_wmm_ap(apdev[0], ["VO", "VI"])
  25. dev[0].connect("wmm_ac", key_mgmt="NONE", scan_freq="2462")
  26. hwsim_utils.test_connectivity(dev[0], hapd)
  27. status = dev[0].request("WMM_AC_STATUS")
  28. if "WMM AC is Enabled" not in status:
  29. raise Exception("WMM-AC not enabled")
  30. if "TSID" in status:
  31. raise Exception("Unexpected TSID info")
  32. if "BK: acm=0 uapsd=0" not in status:
  33. raise Exception("Unexpected BK info" + status)
  34. if "BE: acm=0 uapsd=0" not in status:
  35. raise Exception("Unexpected BE info" + status)
  36. if "VI: acm=1 uapsd=0" not in status:
  37. raise Exception("Unexpected VI info" + status)
  38. if "VO: acm=1 uapsd=0" not in status:
  39. raise Exception("Unexpected VO info" + status)
  40. # no tsid --> tsid out of range
  41. if "FAIL" not in dev[0].request("WMM_AC_ADDTS downlink"):
  42. raise Exception("Invalid WMM_AC_ADDTS accepted")
  43. # no direction
  44. if "FAIL" not in dev[0].request("WMM_AC_ADDTS tsid=5"):
  45. raise Exception("Invalid WMM_AC_ADDTS accepted")
  46. # param out of range
  47. if "FAIL" not in dev[0].request("WMM_AC_ADDTS tsid=5 downlink"):
  48. raise Exception("Invalid WMM_AC_ADDTS accepted")
  49. tsid = 5
  50. # make sure we fail when the ac is not configured for acm
  51. try:
  52. dev[0].add_ts(tsid, 3)
  53. raise Exception("ADDTS succeeded although it should have failed")
  54. except Exception, e:
  55. if not str(e).startswith("ADDTS failed"):
  56. raise
  57. status = dev[0].request("WMM_AC_STATUS")
  58. if "TSID" in status:
  59. raise Exception("Unexpected TSID info")
  60. # add tspec for UP=6
  61. dev[0].add_ts(tsid, 6)
  62. status = dev[0].request("WMM_AC_STATUS")
  63. if "TSID" not in status:
  64. raise Exception("Missing TSID info")
  65. # using the same tsid for a different ac is invalid
  66. try:
  67. dev[0].add_ts(tsid, 5)
  68. raise Exception("ADDTS succeeded although it should have failed")
  69. except Exception, e:
  70. if not str(e).startswith("ADDTS failed"):
  71. raise
  72. # update the tspec for a different UP of the same ac
  73. dev[0].add_ts(tsid, 7, extra="fixed_nominal_msdu")
  74. dev[0].del_ts(tsid)
  75. status = dev[0].request("WMM_AC_STATUS")
  76. if "TSID" in status:
  77. raise Exception("Unexpected TSID info")
  78. # verify failure on uplink/bidi without driver support
  79. tsid = 6
  80. try:
  81. dev[0].add_ts(tsid, 7, direction="uplink")
  82. raise Exception("ADDTS succeeded although it should have failed")
  83. except Exception, e:
  84. if not str(e).startswith("ADDTS failed"):
  85. raise
  86. try:
  87. dev[0].add_ts(tsid, 7, direction="bidi")
  88. raise Exception("ADDTS succeeded although it should have failed")
  89. except Exception, e:
  90. if not str(e).startswith("ADDTS failed"):
  91. raise
  92. # attempt to delete non-existing tsid
  93. try:
  94. dev[0].del_ts(tsid)
  95. raise Exception("DELTS succeeded although it should have failed")
  96. except Exception, e:
  97. if not str(e).startswith("DELTS failed"):
  98. raise
  99. # "CTRL: Invalid WMM_AC_ADDTS parameter: 'foo'
  100. if "FAIL" not in dev[0].request("WMM_AC_ADDTS foo"):
  101. raise Exception("Invalid WMM_AC_ADDTS command accepted")
  102. def test_tspec_protocol(dev, apdev):
  103. """Protocol tests for addts/delts"""
  104. # configure ap with VO and VI requiring admission-control
  105. hapd = add_wmm_ap(apdev[0], ["VO", "VI"])
  106. dev[0].connect("wmm_ac", key_mgmt="NONE", scan_freq="2462")
  107. dev[0].dump_monitor()
  108. hapd.set("ext_mgmt_frame_handling", "1")
  109. tsid = 6
  110. # timeout on ADDTS response
  111. dev[0].add_ts(tsid, 7, expect_failure=True)
  112. hapd.dump_monitor()
  113. req = "WMM_AC_ADDTS downlink tsid=6 up=7 nominal_msdu_size=1500 sba=9000 mean_data_rate=1500 min_phy_rate=6000000"
  114. if "OK" not in dev[0].request(req):
  115. raise Exception("WMM_AC_ADDTS failed")
  116. # a new request while previous is still pending
  117. if "FAIL" not in dev[0].request(req):
  118. raise Exception("WMM_AC_ADDTS accepted while oen was still pending")
  119. msg = hapd.mgmt_rx()
  120. payload = msg['payload']
  121. (categ, action, dialog, status) = struct.unpack('BBBB', payload[0:4])
  122. if action != 0:
  123. raise Exception("Unexpected Action code: %d" % action)
  124. msg['da'] = msg['sa']
  125. msg['sa'] = apdev[0]['bssid']
  126. # unexpected dialog token
  127. msg['payload'] = struct.pack('BBBB', 17, 1, (dialog + 1) & 0xff, 0) + payload[4:]
  128. hapd.mgmt_tx(msg)
  129. # valid response
  130. msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:]
  131. hapd.mgmt_tx(msg)
  132. ev = dev[0].wait_event(["TSPEC-ADDED"], timeout=10)
  133. if ev is None:
  134. raise Exception("Timeout on TSPEC-ADDED")
  135. if "tsid=%d" % tsid not in ev:
  136. raise Exception("Unexpected TSPEC-ADDED contents: " + ev)
  137. # duplicated response
  138. msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:]
  139. hapd.mgmt_tx(msg)
  140. # too short ADDTS
  141. msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0)
  142. hapd.mgmt_tx(msg)
  143. # invalid IE
  144. msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:] + struct.pack('BB', 0xdd, 100)
  145. hapd.mgmt_tx(msg)
  146. # too short WMM element
  147. msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:] + '\xdd\x06\x00\x50\xf2\x02\x02\x01'
  148. hapd.mgmt_tx(msg)
  149. # DELTS
  150. dev[0].dump_monitor()
  151. msg['payload'] = struct.pack('BBBB', 17, 2, 0, 0) + payload[4:]
  152. hapd.mgmt_tx(msg)
  153. ev = dev[0].wait_event(['TSPEC-REMOVED'], timeout=6)
  154. if ev is None:
  155. raise Exception("Timeout on TSPEC-REMOVED event")
  156. if "tsid=%d" % tsid not in ev:
  157. raise Exception("Unexpected TSPEC-REMOVED contents: " + ev)
  158. # DELTS duplicated
  159. msg['payload'] = struct.pack('BBBB', 17, 2, 0, 0) + payload[4:]
  160. hapd.mgmt_tx(msg)
  161. # start a new request
  162. hapd.dump_monitor()
  163. if "OK" not in dev[0].request(req):
  164. raise Exception("WMM_AC_ADDTS failed")
  165. msg = hapd.mgmt_rx()
  166. payload = msg['payload']
  167. (categ, action, dialog, status) = struct.unpack('BBBB', payload[0:4])
  168. if action != 0:
  169. raise Exception("Unexpected Action code: %d" % action)
  170. msg['da'] = msg['sa']
  171. msg['sa'] = apdev[0]['bssid']
  172. # modified parameters
  173. msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 1) + payload[4:12] + struct.pack('B', ord(payload[12]) & ~0x60) + payload[13:]
  174. hapd.mgmt_tx(msg)
  175. # reject request
  176. msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 1) + payload[4:]
  177. hapd.mgmt_tx(msg)
  178. ev = dev[0].wait_event(["TSPEC-REQ-FAILED"], timeout=10)
  179. if ev is None:
  180. raise Exception("Timeout on TSPEC-REQ-FAILED")
  181. if "tsid=%d" % tsid not in ev:
  182. raise Exception("Unexpected TSPEC-REQ-FAILED contents: " + ev)
  183. hapd.set("ext_mgmt_frame_handling", "0")
  184. @remote_compatible
  185. def test_tspec_not_enabled(dev, apdev):
  186. """addts failing if AP does not support WMM"""
  187. params = { "ssid": "wmm_no_ac",
  188. "hw_mode": "g",
  189. "channel": "11",
  190. "wmm_enabled" : "0" }
  191. hapd = hostapd.add_ap(apdev[0], params)
  192. dev[0].connect("wmm_no_ac", key_mgmt="NONE", scan_freq="2462")
  193. status = dev[0].request("WMM_AC_STATUS")
  194. if "Not associated to a WMM AP, WMM AC is Disabled" not in status:
  195. raise Exception("Unexpected WMM_AC_STATUS: " + status)
  196. try:
  197. dev[0].add_ts(5, 6)
  198. raise Exception("ADDTS succeeded although it should have failed")
  199. except Exception, e:
  200. if not str(e).startswith("ADDTS failed"):
  201. raise
  202. # attempt to delete non-existing tsid
  203. try:
  204. dev[0].del_ts(5)
  205. raise Exception("DELTS succeeded although it should have failed")
  206. except Exception, e:
  207. if not str(e).startswith("DELTS failed"):
  208. raise
  209. # unexpected Action frame when WMM is disabled
  210. MGMT_SUBTYPE_ACTION = 13
  211. msg = {}
  212. msg['fc'] = MGMT_SUBTYPE_ACTION << 4
  213. msg['da'] = dev[0].p2p_interface_addr()
  214. msg['sa'] = apdev[0]['bssid']
  215. msg['bssid'] = apdev[0]['bssid']
  216. msg['payload'] = struct.pack('BBBB', 17, 2, 0, 0)
  217. hapd.mgmt_tx(msg)
  218. @remote_compatible
  219. def test_tspec_ap_roam_open(dev, apdev):
  220. """Roam between two open APs while having tspecs"""
  221. hapd0 = add_wmm_ap(apdev[0], ["VO", "VI"])
  222. dev[0].connect("wmm_ac", key_mgmt="NONE")
  223. hwsim_utils.test_connectivity(dev[0], hapd0)
  224. dev[0].add_ts(5, 6)
  225. hapd1 = add_wmm_ap(apdev[1], ["VO", "VI"])
  226. dev[0].scan_for_bss(apdev[1]['bssid'], freq=2462)
  227. dev[0].roam(apdev[1]['bssid'])
  228. hwsim_utils.test_connectivity(dev[0], hapd1)
  229. if dev[0].tspecs():
  230. raise Exception("TSPECs weren't deleted on roaming")
  231. dev[0].scan_for_bss(apdev[0]['bssid'], freq=2462)
  232. dev[0].roam(apdev[0]['bssid'])
  233. hwsim_utils.test_connectivity(dev[0], hapd0)
  234. @remote_compatible
  235. def test_tspec_reassoc(dev, apdev):
  236. """Reassociation to same BSS while having tspecs"""
  237. hapd0 = add_wmm_ap(apdev[0], ["VO", "VI"])
  238. dev[0].connect("wmm_ac", key_mgmt="NONE")
  239. hwsim_utils.test_connectivity(dev[0], hapd0)
  240. dev[0].add_ts(5, 6)
  241. last_tspecs = dev[0].tspecs()
  242. dev[0].request("REASSOCIATE")
  243. dev[0].wait_connected()
  244. hwsim_utils.test_connectivity(dev[0], hapd0)
  245. if dev[0].tspecs() != last_tspecs:
  246. raise Exception("TSPECs weren't saved on reassociation")
  247. def test_wmm_element(dev, apdev):
  248. """hostapd FTM range request timeout"""
  249. try:
  250. run_wmm_element(dev, apdev)
  251. finally:
  252. dev[0].request("VENDOR_ELEM_REMOVE 13 *")
  253. def run_wmm_element(dev, apdev):
  254. params = { "ssid": "wmm" }
  255. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  256. bssid = hapd.own_addr()
  257. # Too short WMM IE
  258. dev[0].request("VENDOR_ELEM_ADD 13 dd060050f2020001")
  259. dev[0].scan_for_bss(bssid, freq=2412)
  260. dev[0].connect("wmm", key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  261. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  262. if ev is None:
  263. raise Exception("Association not rejected")
  264. dev[0].request("REMOVE_NETWORK all")
  265. # Unsupported WMM IE Subtype/Version
  266. dev[0].request("VENDOR_ELEM_ADD 13 dd070050f202000000")
  267. dev[0].connect("wmm", key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  268. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  269. if ev is None:
  270. raise Exception("Association not rejected")
  271. dev[0].request("REMOVE_NETWORK all")
  272. # Unsupported WMM IE Subtype/Version
  273. dev[0].request("VENDOR_ELEM_ADD 13 dd070050f202010100")
  274. dev[0].connect("wmm", key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  275. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  276. if ev is None:
  277. raise Exception("Association not rejected")
  278. dev[0].request("REMOVE_NETWORK all")
  279. def test_tspec_ap_fail(dev, apdev):
  280. """AP failing to send tspec response"""
  281. # configure ap with VO and VI requiring admission-control
  282. hapd = add_wmm_ap(apdev[0], ["VO", "VI"])
  283. dev[0].connect("wmm_ac", key_mgmt="NONE", scan_freq="2462")
  284. tsid = 5
  285. with fail_test(hapd, 1, "wmm_send_action"):
  286. try:
  287. # add tspec for UP=6
  288. dev[0].add_ts(tsid, 6)
  289. except:
  290. pass
  291. def test_tspec_ap_parsing(dev, apdev):
  292. """TSPEC AP parsing tests"""
  293. # configure ap with VO and VI requiring admission-control
  294. hapd = add_wmm_ap(apdev[0], ["VO", "VI"])
  295. bssid = hapd.own_addr()
  296. dev[0].connect("wmm_ac", key_mgmt="NONE", scan_freq="2462")
  297. addr = dev[0].own_addr()
  298. tests = [ "WMM_AC_ADDTS downlink tsid=5 up=6 nominal_msdu_size=1500 sba=9000 mean_data_rate=1500 min_phy_rate=600000",
  299. "WMM_AC_ADDTS downlink tsid=5 up=6 nominal_msdu_size=1500 sba=8192 mean_data_rate=1500 min_phy_rate=6000000",
  300. "WMM_AC_ADDTS downlink tsid=5 up=6 nominal_msdu_size=32767 sba=65535 mean_data_rate=1500 min_phy_rate=1000000",
  301. "WMM_AC_ADDTS downlink tsid=5 up=6 nominal_msdu_size=10000 sba=65535 mean_data_rate=2147483647 min_phy_rate=1000000" ]
  302. for t in tests:
  303. if "OK" not in dev[0].request(t):
  304. raise Exception("WMM_AC_ADDTS failed")
  305. ev = dev[0].wait_event(["TSPEC-REQ-FAILED"], timeout=1)
  306. if ev is None:
  307. raise Exception("No response")
  308. tests = []
  309. # WMM: Invalid Nominal MSDU Size (0)
  310. tests += [ "11000400dd3d0050f2020201aa300000000000000000000000000000000000000000000000000000000000ffffff7f00000000000000000000000040420f00ffff0000" ]
  311. # hostapd_wmm_action - missing or wrong length tspec
  312. tests += [ "11000400dd3e0050f2020201aa300010270000000000000000000000000000000000000000000000000000ffffff7f00000000000000000000000040420f00ffff000000" ]
  313. # hostapd_wmm_action - could not parse wmm action
  314. tests += [ "11000400dd3d0050f2020201aa300010270000000000000000000000000000000000000000000000000000ffffff7f00000000000000000000000040420f00ffff00" ]
  315. # valid form
  316. tests += [ "11000400dd3d0050f2020201aa300010270000000000000000000000000000000000000000000000000000ffffff7f00000000000000000000000040420f00ffff0000" ]
  317. hdr = "d0003a01" + bssid.replace(':', '') + addr.replace(':', '') + bssid.replace(':', '') + "1000"
  318. hapd.set("ext_mgmt_frame_handling", "1")
  319. for t in tests:
  320. if "OK" not in hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + t):
  321. raise Exception("MGMT_RX_PROCESS failed")
  322. hapd.set("ext_mgmt_frame_handling", "0")
  323. def test_wmm_disabled(dev, apdev):
  324. """WMM disabled and unexpected TSPEC"""
  325. params = { "ssid": "no-wmm", "ieee80211n": "0", "wmm_enabled": "0" }
  326. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  327. bssid = hapd.own_addr()
  328. dev[0].connect("no-wmm", key_mgmt="NONE", scan_freq="2412")
  329. addr = dev[0].own_addr()
  330. # wmm action received is not from associated wmm station
  331. hdr = "d0003a01" + bssid.replace(':', '') + addr.replace(':', '') + bssid.replace(':', '') + "1000"
  332. hapd.set("ext_mgmt_frame_handling", "1")
  333. if "OK" not in hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + "11000400dd3d0050f2020201aa300010270000000000000000000000000000000000000000000000000000ffffff7f00000000000000000000000040420f00ffff0000"):
  334. raise Exception("MGMT_RX_PROCESS failed")
  335. # IEEE 802.11: Ignored Action frame (category=17) from unassociated STA
  336. hdr = "d0003a01" + bssid.replace(':', '') + "112233445566" + bssid.replace(':', '') + "1000"
  337. if "OK" not in hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + "11000400dd3d0050f2020201aa300010270000000000000000000000000000000000000000000000000000ffffff7f00000000000000000000000040420f00ffff0000"):
  338. raise Exception("MGMT_RX_PROCESS failed")
  339. hapd.set("ext_mgmt_frame_handling", "0")