test_mbo.py 11 KB

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