test_wpas_wmm_ac.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. import logging
  7. logger = logging.getLogger()
  8. import struct
  9. import hwsim_utils
  10. import hostapd
  11. def add_wmm_ap(apdev, acm_list):
  12. params = { "ssid": "wmm_ac",
  13. "hw_mode": "g",
  14. "channel": "11",
  15. "wmm_enabled" : "1"}
  16. for ac in acm_list:
  17. params["wmm_ac_%s_acm" % (ac.lower())] = "1"
  18. return hostapd.add_ap(apdev[0]['ifname'], params)
  19. def test_tspec(dev, apdev):
  20. """Basic addts/delts tests"""
  21. # configure ap with VO and VI requiring admission-control
  22. hapd = add_wmm_ap(apdev, ["VO", "VI"])
  23. dev[0].connect("wmm_ac", key_mgmt="NONE", scan_freq="2462")
  24. hwsim_utils.test_connectivity(dev[0], hapd)
  25. status = dev[0].request("WMM_AC_STATUS")
  26. if "WMM AC is Enabled" not in status:
  27. raise Exception("WMM-AC not enabled")
  28. if "TSID" in status:
  29. raise Exception("Unexpected TSID info")
  30. if "BK: acm=0 uapsd=0" not in status:
  31. raise Exception("Unexpected BK info" + status)
  32. if "BE: acm=0 uapsd=0" not in status:
  33. raise Exception("Unexpected BE info" + status)
  34. if "VI: acm=1 uapsd=0" not in status:
  35. raise Exception("Unexpected VI info" + status)
  36. if "VO: acm=1 uapsd=0" not in status:
  37. raise Exception("Unexpected VO info" + status)
  38. # no tsid --> tsid out of range
  39. if "FAIL" not in dev[0].request("WMM_AC_ADDTS downlink"):
  40. raise Exception("Invalid WMM_AC_ADDTS accepted")
  41. # no direction
  42. if "FAIL" not in dev[0].request("WMM_AC_ADDTS tsid=5"):
  43. raise Exception("Invalid WMM_AC_ADDTS accepted")
  44. # param out of range
  45. if "FAIL" not in dev[0].request("WMM_AC_ADDTS tsid=5 downlink"):
  46. raise Exception("Invalid WMM_AC_ADDTS accepted")
  47. tsid = 5
  48. # make sure we fail when the ac is not configured for acm
  49. try:
  50. dev[0].add_ts(tsid, 3)
  51. raise Exception("ADDTS succeeded although it should have failed")
  52. except Exception, e:
  53. if not str(e).startswith("ADDTS failed"):
  54. raise
  55. status = dev[0].request("WMM_AC_STATUS")
  56. if "TSID" in status:
  57. raise Exception("Unexpected TSID info")
  58. # add tspec for UP=6
  59. dev[0].add_ts(tsid, 6)
  60. status = dev[0].request("WMM_AC_STATUS")
  61. if "TSID" not in status:
  62. raise Exception("Missing TSID info")
  63. # using the same tsid for a different ac is invalid
  64. try:
  65. dev[0].add_ts(tsid, 5)
  66. raise Exception("ADDTS succeeded although it should have failed")
  67. except Exception, e:
  68. if not str(e).startswith("ADDTS failed"):
  69. raise
  70. # update the tspec for a different UP of the same ac
  71. dev[0].add_ts(tsid, 7, extra="fixed_nominal_msdu")
  72. dev[0].del_ts(tsid)
  73. status = dev[0].request("WMM_AC_STATUS")
  74. if "TSID" in status:
  75. raise Exception("Unexpected TSID info")
  76. # verify failure on uplink/bidi without driver support
  77. tsid = 6
  78. try:
  79. dev[0].add_ts(tsid, 7, direction="uplink")
  80. raise Exception("ADDTS succeeded although it should have failed")
  81. except Exception, e:
  82. if not str(e).startswith("ADDTS failed"):
  83. raise
  84. try:
  85. dev[0].add_ts(tsid, 7, direction="bidi")
  86. raise Exception("ADDTS succeeded although it should have failed")
  87. except Exception, e:
  88. if not str(e).startswith("ADDTS failed"):
  89. raise
  90. # attempt to delete non-existing tsid
  91. try:
  92. dev[0].del_ts(tsid)
  93. raise Exception("DELTS succeeded although it should have failed")
  94. except Exception, e:
  95. if not str(e).startswith("DELTS failed"):
  96. raise
  97. def test_tspec_protocol(dev, apdev):
  98. """Protocol tests for addts/delts"""
  99. # configure ap with VO and VI requiring admission-control
  100. hapd = add_wmm_ap(apdev, ["VO", "VI"])
  101. dev[0].connect("wmm_ac", key_mgmt="NONE", scan_freq="2462")
  102. dev[0].dump_monitor()
  103. hapd.set("ext_mgmt_frame_handling", "1")
  104. tsid = 6
  105. # timeout on ADDTS response
  106. dev[0].add_ts(tsid, 7, expect_failure=True)
  107. hapd.dump_monitor()
  108. req = "WMM_AC_ADDTS downlink tsid=6 up=7 nominal_msdu_size=1500 sba=9000 mean_data_rate=1500 min_phy_rate=6000000"
  109. if "OK" not in dev[0].request(req):
  110. raise Exception("WMM_AC_ADDTS failed")
  111. # a new request while previous is still pending
  112. if "FAIL" not in dev[0].request(req):
  113. raise Exception("WMM_AC_ADDTS accepted while oen was still pending")
  114. msg = hapd.mgmt_rx()
  115. payload = msg['payload']
  116. (categ, action, dialog, status) = struct.unpack('BBBB', payload[0:4])
  117. if action != 0:
  118. raise Exception("Unexpected Action code: %d" % action)
  119. msg['da'] = msg['sa']
  120. msg['sa'] = apdev[0]['bssid']
  121. # unexpected dialog token
  122. msg['payload'] = struct.pack('BBBB', 17, 1, (dialog + 1) & 0xff, 0) + payload[4:]
  123. hapd.mgmt_tx(msg)
  124. # valid response
  125. msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:]
  126. hapd.mgmt_tx(msg)
  127. ev = dev[0].wait_event(["TSPEC-ADDED"], timeout=10)
  128. if ev is None:
  129. raise Exception("Timeout on TSPEC-ADDED")
  130. if "tsid=%d" % tsid not in ev:
  131. raise Exception("Unexpected TSPEC-ADDED contents: " + ev)
  132. # duplicated response
  133. msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:]
  134. hapd.mgmt_tx(msg)
  135. # too short ADDTS
  136. msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0)
  137. hapd.mgmt_tx(msg)
  138. # invalid IE
  139. msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:] + struct.pack('BB', 0xdd, 100)
  140. hapd.mgmt_tx(msg)
  141. # too short WMM element
  142. msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:] + '\xdd\x06\x00\x50\xf2\x02\x02\x01'
  143. hapd.mgmt_tx(msg)
  144. # DELTS
  145. dev[0].dump_monitor()
  146. msg['payload'] = struct.pack('BBBB', 17, 2, 0, 0) + payload[4:]
  147. hapd.mgmt_tx(msg)
  148. ev = dev[0].wait_event(['TSPEC-REMOVED'], timeout=6)
  149. if ev is None:
  150. raise Exception("Timeout on TSPEC-REMOVED event")
  151. if "tsid=%d" % tsid not in ev:
  152. raise Exception("Unexpected TSPEC-REMOVED contents: " + ev)
  153. # DELTS duplicated
  154. msg['payload'] = struct.pack('BBBB', 17, 2, 0, 0) + payload[4:]
  155. hapd.mgmt_tx(msg)
  156. # start a new request
  157. hapd.dump_monitor()
  158. if "OK" not in dev[0].request(req):
  159. raise Exception("WMM_AC_ADDTS failed")
  160. msg = hapd.mgmt_rx()
  161. payload = msg['payload']
  162. (categ, action, dialog, status) = struct.unpack('BBBB', payload[0:4])
  163. if action != 0:
  164. raise Exception("Unexpected Action code: %d" % action)
  165. msg['da'] = msg['sa']
  166. msg['sa'] = apdev[0]['bssid']
  167. # modified parameters
  168. msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 1) + payload[4:12] + struct.pack('B', ord(payload[12]) & ~0x60) + payload[13:]
  169. hapd.mgmt_tx(msg)
  170. # reject request
  171. msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 1) + payload[4:]
  172. hapd.mgmt_tx(msg)
  173. ev = dev[0].wait_event(["TSPEC-REQ-FAILED"], timeout=10)
  174. if ev is None:
  175. raise Exception("Timeout on TSPEC-REQ-FAILED")
  176. if "tsid=%d" % tsid not in ev:
  177. raise Exception("Unexpected TSPEC-REQ-FAILED contents: " + ev)
  178. hapd.set("ext_mgmt_frame_handling", "0")
  179. def test_tspec_not_enabled(dev, apdev):
  180. """addts failing if AP does not support WMM"""
  181. params = { "ssid": "wmm_no_ac",
  182. "hw_mode": "g",
  183. "channel": "11",
  184. "wmm_enabled" : "0" }
  185. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  186. dev[0].connect("wmm_no_ac", key_mgmt="NONE", scan_freq="2462")
  187. status = dev[0].request("WMM_AC_STATUS")
  188. if "Not associated to a WMM AP, WMM AC is Disabled" not in status:
  189. raise Exception("Unexpected WMM_AC_STATUS: " + status)
  190. try:
  191. dev[0].add_ts(5, 6)
  192. raise Exception("ADDTS succeeded although it should have failed")
  193. except Exception, e:
  194. if not str(e).startswith("ADDTS failed"):
  195. raise
  196. # attempt to delete non-existing tsid
  197. try:
  198. dev[0].del_ts(5)
  199. raise Exception("DELTS succeeded although it should have failed")
  200. except Exception, e:
  201. if not str(e).startswith("DELTS failed"):
  202. raise
  203. # unexpected Action frame when WMM is disabled
  204. MGMT_SUBTYPE_ACTION = 13
  205. msg = {}
  206. msg['fc'] = MGMT_SUBTYPE_ACTION << 4
  207. msg['da'] = dev[0].p2p_interface_addr()
  208. msg['sa'] = apdev[0]['bssid']
  209. msg['bssid'] = apdev[0]['bssid']
  210. msg['payload'] = struct.pack('BBBB', 17, 2, 0, 0)
  211. hapd.mgmt_tx(msg)