test_mbo.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. # MBO tests
  2. # Copyright (c) 2016, Intel Deutschland GmbH
  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 hostapd
  10. import os
  11. import time
  12. from tshark import run_tshark
  13. from utils import alloc_fail, fail_test
  14. def test_mbo_assoc_disallow(dev, apdev, params):
  15. hapd1 = hostapd.add_ap(apdev[0], { "ssid": "MBO", "mbo": "1" })
  16. hapd2 = hostapd.add_ap(apdev[1], { "ssid": "MBO", "mbo": "1" })
  17. logger.debug("Set mbo_assoc_disallow with invalid value")
  18. if "FAIL" not in hapd1.request("SET mbo_assoc_disallow 2"):
  19. raise Exception("Set mbo_assoc_disallow for AP1 succeeded unexpectedly with value 2")
  20. logger.debug("Disallow associations to AP1 and allow association to AP2")
  21. if "OK" not in hapd1.request("SET mbo_assoc_disallow 1"):
  22. raise Exception("Failed to set mbo_assoc_disallow for AP1")
  23. if "OK" not in hapd2.request("SET mbo_assoc_disallow 0"):
  24. raise Exception("Failed to set mbo_assoc_disallow for AP2")
  25. dev[0].connect("MBO", key_mgmt="NONE", scan_freq="2412")
  26. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  27. "wlan.fc.type == 0 && wlan.fc.type_subtype == 0x00",
  28. wait=False)
  29. if "Destination address: " + hapd1.own_addr() in out:
  30. raise Exception("Association request sent to disallowed AP")
  31. timestamp = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  32. "wlan.fc.type_subtype == 0x00",
  33. display=['frame.time'], wait=False)
  34. logger.debug("Allow associations to AP1 and disallow assications to AP2")
  35. if "OK" not in hapd1.request("SET mbo_assoc_disallow 0"):
  36. raise Exception("Failed to set mbo_assoc_disallow for AP1")
  37. if "OK" not in hapd2.request("SET mbo_assoc_disallow 1"):
  38. raise Exception("Failed to set mbo_assoc_disallow for AP2")
  39. dev[0].request("DISCONNECT")
  40. dev[0].wait_disconnected()
  41. # Force new scan, so the assoc_disallowed indication is updated */
  42. dev[0].request("FLUSH")
  43. dev[0].connect("MBO", key_mgmt="NONE", scan_freq="2412")
  44. filter = 'wlan.fc.type == 0 && wlan.fc.type_subtype == 0x00 && frame.time > "' + timestamp.rstrip() + '"'
  45. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  46. filter, wait=False)
  47. if "Destination address: " + hapd2.own_addr() in out:
  48. raise Exception("Association request sent to disallowed AP 2")
  49. @remote_compatible
  50. def test_mbo_cell_capa_update(dev, apdev):
  51. """MBO cellular data capability update"""
  52. ssid = "test-wnm-mbo"
  53. params = { 'ssid': ssid, 'mbo': '1' }
  54. hapd = hostapd.add_ap(apdev[0], params)
  55. bssid = apdev[0]['bssid']
  56. if "OK" not in dev[0].request("SET mbo_cell_capa 1"):
  57. raise Exception("Failed to set STA as cellular data capable")
  58. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  59. addr = dev[0].own_addr()
  60. sta = hapd.get_sta(addr)
  61. if 'mbo_cell_capa' not in sta or sta['mbo_cell_capa'] != '1':
  62. raise Exception("mbo_cell_capa missing after association")
  63. if "OK" not in dev[0].request("SET mbo_cell_capa 3"):
  64. raise Exception("Failed to set STA as cellular data not-capable")
  65. # Duplicate update for additional code coverage
  66. if "OK" not in dev[0].request("SET mbo_cell_capa 3"):
  67. raise Exception("Failed to set STA as cellular data not-capable")
  68. time.sleep(0.2)
  69. sta = hapd.get_sta(addr)
  70. if 'mbo_cell_capa' not in sta:
  71. raise Exception("mbo_cell_capa missing after update")
  72. if sta['mbo_cell_capa'] != '3':
  73. raise Exception("mbo_cell_capa not updated properly")
  74. @remote_compatible
  75. def test_mbo_cell_capa_update_pmf(dev, apdev):
  76. """MBO cellular data capability update with PMF required"""
  77. ssid = "test-wnm-mbo"
  78. passphrase = "12345678"
  79. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  80. params["wpa_key_mgmt"] = "WPA-PSK-SHA256";
  81. params["ieee80211w"] = "2";
  82. params['mbo'] = '1'
  83. hapd = hostapd.add_ap(apdev[0], params)
  84. bssid = apdev[0]['bssid']
  85. if "OK" not in dev[0].request("SET mbo_cell_capa 1"):
  86. raise Exception("Failed to set STA as cellular data capable")
  87. dev[0].connect(ssid, psk=passphrase, key_mgmt="WPA-PSK-SHA256",
  88. proto="WPA2", ieee80211w="2", scan_freq="2412")
  89. addr = dev[0].own_addr()
  90. sta = hapd.get_sta(addr)
  91. if 'mbo_cell_capa' not in sta or sta['mbo_cell_capa'] != '1':
  92. raise Exception("mbo_cell_capa missing after association")
  93. if "OK" not in dev[0].request("SET mbo_cell_capa 3"):
  94. raise Exception("Failed to set STA as cellular data not-capable")
  95. time.sleep(0.2)
  96. sta = hapd.get_sta(addr)
  97. if 'mbo_cell_capa' not in sta:
  98. raise Exception("mbo_cell_capa missing after update")
  99. if sta['mbo_cell_capa'] != '3':
  100. raise Exception("mbo_cell_capa not updated properly")
  101. def test_mbo_wnm_token_wrap(dev, apdev):
  102. """MBO WNM token wrap around"""
  103. ssid = "test-wnm-mbo"
  104. params = { 'ssid': ssid, 'mbo': '1' }
  105. hapd = hostapd.add_ap(apdev[0], params)
  106. bssid = apdev[0]['bssid']
  107. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  108. # Trigger transmission of 256 WNM-Notification frames to wrap around the
  109. # 8-bit mbo_wnm_token counter.
  110. for i in range(128):
  111. if "OK" not in dev[0].request("SET mbo_cell_capa 1"):
  112. raise Exception("Failed to set STA as cellular data capable")
  113. if "OK" not in dev[0].request("SET mbo_cell_capa 3"):
  114. raise Exception("Failed to set STA as cellular data not-capable")
  115. @remote_compatible
  116. def test_mbo_non_pref_chan(dev, apdev):
  117. """MBO non-preferred channel list"""
  118. ssid = "test-wnm-mbo"
  119. params = { 'ssid': ssid, 'mbo': '1' }
  120. hapd = hostapd.add_ap(apdev[0], params)
  121. bssid = apdev[0]['bssid']
  122. if "FAIL" not in dev[0].request("SET non_pref_chan 81:7:200:99"):
  123. raise Exception("Invalid non_pref_chan value accepted")
  124. if "FAIL" not in dev[0].request("SET non_pref_chan 81:15:200:3"):
  125. raise Exception("Invalid non_pref_chan value accepted")
  126. if "FAIL" not in dev[0].request("SET non_pref_chan 81:7:200:3 81:7:201:3"):
  127. raise Exception("Invalid non_pref_chan value accepted")
  128. if "OK" not in dev[0].request("SET non_pref_chan 81:7:200:3"):
  129. raise Exception("Failed to set non-preferred channel list")
  130. if "OK" not in dev[0].request("SET non_pref_chan 81:7:200:1:123 81:9:100:2"):
  131. raise Exception("Failed to set non-preferred channel list")
  132. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  133. addr = dev[0].own_addr()
  134. sta = hapd.get_sta(addr)
  135. logger.debug("STA: " + str(sta))
  136. if 'non_pref_chan[0]' not in sta:
  137. raise Exception("Missing non_pref_chan[0] value (assoc)")
  138. if sta['non_pref_chan[0]'] != '81:200:1:123:7':
  139. raise Exception("Unexpected non_pref_chan[0] value (assoc)")
  140. if 'non_pref_chan[1]' not in sta:
  141. raise Exception("Missing non_pref_chan[1] value (assoc)")
  142. if sta['non_pref_chan[1]'] != '81:100:2:0:9':
  143. raise Exception("Unexpected non_pref_chan[1] value (assoc)")
  144. if 'non_pref_chan[2]' in sta:
  145. raise Exception("Unexpected non_pref_chan[2] value (assoc)")
  146. if "OK" not in dev[0].request("SET non_pref_chan 81:9:100:2"):
  147. raise Exception("Failed to update non-preferred channel list")
  148. time.sleep(0.1)
  149. sta = hapd.get_sta(addr)
  150. logger.debug("STA: " + str(sta))
  151. if 'non_pref_chan[0]' not in sta:
  152. raise Exception("Missing non_pref_chan[0] value (update 1)")
  153. if sta['non_pref_chan[0]'] != '81:100:2:0:9':
  154. raise Exception("Unexpected non_pref_chan[0] value (update 1)")
  155. if 'non_pref_chan[1]' in sta:
  156. raise Exception("Unexpected non_pref_chan[2] value (update 1)")
  157. if "OK" not in dev[0].request("SET non_pref_chan 81:9:100:2 81:10:100:2 81:8:100:2 81:7:100:1:123 81:5:100:1:124"):
  158. raise Exception("Failed to update non-preferred channel list")
  159. time.sleep(0.1)
  160. sta = hapd.get_sta(addr)
  161. logger.debug("STA: " + str(sta))
  162. if 'non_pref_chan[0]' not in sta:
  163. raise Exception("Missing non_pref_chan[0] value (update 2)")
  164. if sta['non_pref_chan[0]'] != '81:100:1:123:7':
  165. raise Exception("Unexpected non_pref_chan[0] value (update 2)")
  166. if 'non_pref_chan[1]' not in sta:
  167. raise Exception("Missing non_pref_chan[1] value (update 2)")
  168. if sta['non_pref_chan[1]'] != '81:100:1:124:5':
  169. raise Exception("Unexpected non_pref_chan[1] value (update 2)")
  170. if 'non_pref_chan[2]' not in sta:
  171. raise Exception("Missing non_pref_chan[2] value (update 2)")
  172. if sta['non_pref_chan[2]'] != '81:100:2:0:9,10,8':
  173. raise Exception("Unexpected non_pref_chan[2] value (update 2)")
  174. if 'non_pref_chan[3]' in sta:
  175. raise Exception("Unexpected non_pref_chan[3] value (update 2)")
  176. if "OK" not in dev[0].request("SET non_pref_chan 81:5:90:2 82:14:91:2"):
  177. raise Exception("Failed to update non-preferred channel list")
  178. time.sleep(0.1)
  179. sta = hapd.get_sta(addr)
  180. logger.debug("STA: " + str(sta))
  181. if 'non_pref_chan[0]' not in sta:
  182. raise Exception("Missing non_pref_chan[0] value (update 3)")
  183. if sta['non_pref_chan[0]'] != '81:90:2:0:5':
  184. raise Exception("Unexpected non_pref_chan[0] value (update 3)")
  185. if 'non_pref_chan[1]' not in sta:
  186. raise Exception("Missing non_pref_chan[1] value (update 3)")
  187. if sta['non_pref_chan[1]'] != '82:91:2:0:14':
  188. raise Exception("Unexpected non_pref_chan[1] value (update 3)")
  189. if 'non_pref_chan[2]' in sta:
  190. raise Exception("Unexpected non_pref_chan[2] value (update 3)")
  191. if "OK" not in dev[0].request("SET non_pref_chan "):
  192. raise Exception("Failed to update non-preferred channel list")
  193. time.sleep(0.1)
  194. sta = hapd.get_sta(addr)
  195. logger.debug("STA: " + str(sta))
  196. if 'non_pref_chan[0]' in sta:
  197. raise Exception("Unexpected non_pref_chan[0] value (update 4)")
  198. @remote_compatible
  199. def test_mbo_sta_supp_op_classes(dev, apdev):
  200. """MBO STA supported operating classes"""
  201. ssid = "test-wnm-mbo"
  202. params = { 'ssid': ssid, 'mbo': '1' }
  203. hapd = hostapd.add_ap(apdev[0], params)
  204. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  205. addr = dev[0].own_addr()
  206. sta = hapd.get_sta(addr)
  207. logger.debug("STA: " + str(sta))
  208. if 'supp_op_classes' not in sta:
  209. raise Exception("No supp_op_classes")
  210. supp = bytearray(sta['supp_op_classes'].decode("hex"))
  211. if supp[0] != 81:
  212. raise Exception("Unexpected current operating class %d" % supp[0])
  213. if 115 not in supp:
  214. raise Exception("Operating class 115 missing")
  215. def test_mbo_failures(dev, apdev):
  216. """MBO failure cases"""
  217. ssid = "test-wnm-mbo"
  218. params = { 'ssid': ssid, 'mbo': '1' }
  219. hapd = hostapd.add_ap(apdev[0], params)
  220. with alloc_fail(dev[0], 1, "wpas_mbo_ie"):
  221. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  222. with alloc_fail(dev[0], 1, "wpas_mbo_send_wnm_notification"):
  223. if "OK" not in dev[0].request("SET mbo_cell_capa 1"):
  224. raise Exception("Failed to set STA as cellular data capable")
  225. with fail_test(dev[0], 1, "wpas_mbo_send_wnm_notification"):
  226. if "OK" not in dev[0].request("SET mbo_cell_capa 3"):
  227. raise Exception("Failed to set STA as cellular data not-capable")
  228. with alloc_fail(dev[0], 1, "wpas_mbo_update_non_pref_chan"):
  229. if "FAIL" not in dev[0].request("SET non_pref_chan 81:7:200:3"):
  230. raise Exception("non_pref_chan value accepted during OOM")
  231. with alloc_fail(dev[0], 2, "wpas_mbo_update_non_pref_chan"):
  232. if "FAIL" not in dev[0].request("SET non_pref_chan 81:7:200:3"):
  233. raise Exception("non_pref_chan value accepted during OOM")