test_mbo.py 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. time.sleep(0.2)
  65. sta = hapd.get_sta(addr)
  66. if 'mbo_cell_capa' not in sta:
  67. raise Exception("mbo_cell_capa missing after update")
  68. if sta['mbo_cell_capa'] != '3':
  69. raise Exception("mbo_cell_capa not updated properly")
  70. @remote_compatible
  71. def test_mbo_cell_capa_update_pmf(dev, apdev):
  72. """MBO cellular data capability update with PMF required"""
  73. ssid = "test-wnm-mbo"
  74. passphrase = "12345678"
  75. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  76. params["wpa_key_mgmt"] = "WPA-PSK-SHA256";
  77. params["ieee80211w"] = "2";
  78. params['mbo'] = '1'
  79. hapd = hostapd.add_ap(apdev[0], params)
  80. bssid = apdev[0]['bssid']
  81. if "OK" not in dev[0].request("SET mbo_cell_capa 1"):
  82. raise Exception("Failed to set STA as cellular data capable")
  83. dev[0].connect(ssid, psk=passphrase, key_mgmt="WPA-PSK-SHA256",
  84. proto="WPA2", ieee80211w="2", scan_freq="2412")
  85. addr = dev[0].own_addr()
  86. sta = hapd.get_sta(addr)
  87. if 'mbo_cell_capa' not in sta or sta['mbo_cell_capa'] != '1':
  88. raise Exception("mbo_cell_capa missing after association")
  89. if "OK" not in dev[0].request("SET mbo_cell_capa 3"):
  90. raise Exception("Failed to set STA as cellular data not-capable")
  91. time.sleep(0.2)
  92. sta = hapd.get_sta(addr)
  93. if 'mbo_cell_capa' not in sta:
  94. raise Exception("mbo_cell_capa missing after update")
  95. if sta['mbo_cell_capa'] != '3':
  96. raise Exception("mbo_cell_capa not updated properly")
  97. @remote_compatible
  98. def test_mbo_non_pref_chan(dev, apdev):
  99. """MBO non-preferred channel list"""
  100. ssid = "test-wnm-mbo"
  101. params = { 'ssid': ssid, 'mbo': '1' }
  102. hapd = hostapd.add_ap(apdev[0], params)
  103. bssid = apdev[0]['bssid']
  104. if "OK" not in dev[0].request("SET non_pref_chan 81:7:200:3"):
  105. raise Exception("Failed to set non-preferred channel list")
  106. if "OK" not in dev[0].request("SET non_pref_chan 81:7:200:1:123 81:9:100:2"):
  107. raise Exception("Failed to set non-preferred channel list")
  108. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  109. addr = dev[0].own_addr()
  110. sta = hapd.get_sta(addr)
  111. logger.debug("STA: " + str(sta))
  112. if 'non_pref_chan[0]' not in sta:
  113. raise Exception("Missing non_pref_chan[0] value (assoc)")
  114. if sta['non_pref_chan[0]'] != '81:200:1:123:7':
  115. raise Exception("Unexpected non_pref_chan[0] value (assoc)")
  116. if 'non_pref_chan[1]' not in sta:
  117. raise Exception("Missing non_pref_chan[1] value (assoc)")
  118. if sta['non_pref_chan[1]'] != '81:100:2:0:9':
  119. raise Exception("Unexpected non_pref_chan[1] value (assoc)")
  120. if 'non_pref_chan[2]' in sta:
  121. raise Exception("Unexpected non_pref_chan[2] value (assoc)")
  122. if "OK" not in dev[0].request("SET non_pref_chan 81:9:100:2"):
  123. raise Exception("Failed to update non-preferred channel list")
  124. time.sleep(0.1)
  125. sta = hapd.get_sta(addr)
  126. logger.debug("STA: " + str(sta))
  127. if 'non_pref_chan[0]' not in sta:
  128. raise Exception("Missing non_pref_chan[0] value (update 1)")
  129. if sta['non_pref_chan[0]'] != '81:100:2:0:9':
  130. raise Exception("Unexpected non_pref_chan[0] value (update 1)")
  131. if 'non_pref_chan[1]' in sta:
  132. raise Exception("Unexpected non_pref_chan[2] value (update 1)")
  133. 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"):
  134. raise Exception("Failed to update non-preferred channel list")
  135. time.sleep(0.1)
  136. sta = hapd.get_sta(addr)
  137. logger.debug("STA: " + str(sta))
  138. if 'non_pref_chan[0]' not in sta:
  139. raise Exception("Missing non_pref_chan[0] value (update 2)")
  140. if sta['non_pref_chan[0]'] != '81:100:1:123:7':
  141. raise Exception("Unexpected non_pref_chan[0] value (update 2)")
  142. if 'non_pref_chan[1]' not in sta:
  143. raise Exception("Missing non_pref_chan[1] value (update 2)")
  144. if sta['non_pref_chan[1]'] != '81:100:1:124:5':
  145. raise Exception("Unexpected non_pref_chan[1] value (update 2)")
  146. if 'non_pref_chan[2]' not in sta:
  147. raise Exception("Missing non_pref_chan[2] value (update 2)")
  148. if sta['non_pref_chan[2]'] != '81:100:2:0:9,10,8':
  149. raise Exception("Unexpected non_pref_chan[2] value (update 2)")
  150. if 'non_pref_chan[3]' in sta:
  151. raise Exception("Unexpected non_pref_chan[3] value (update 2)")
  152. if "OK" not in dev[0].request("SET non_pref_chan 81:5:90:2 82:14:91:2"):
  153. raise Exception("Failed to update non-preferred channel list")
  154. time.sleep(0.1)
  155. sta = hapd.get_sta(addr)
  156. logger.debug("STA: " + str(sta))
  157. if 'non_pref_chan[0]' not in sta:
  158. raise Exception("Missing non_pref_chan[0] value (update 3)")
  159. if sta['non_pref_chan[0]'] != '81:90:2:0:5':
  160. raise Exception("Unexpected non_pref_chan[0] value (update 3)")
  161. if 'non_pref_chan[1]' not in sta:
  162. raise Exception("Missing non_pref_chan[1] value (update 3)")
  163. if sta['non_pref_chan[1]'] != '82:91:2:0:14':
  164. raise Exception("Unexpected non_pref_chan[1] value (update 3)")
  165. if 'non_pref_chan[2]' in sta:
  166. raise Exception("Unexpected non_pref_chan[2] value (update 3)")
  167. if "OK" not in dev[0].request("SET non_pref_chan "):
  168. raise Exception("Failed to update non-preferred channel list")
  169. time.sleep(0.1)
  170. sta = hapd.get_sta(addr)
  171. logger.debug("STA: " + str(sta))
  172. if 'non_pref_chan[0]' in sta:
  173. raise Exception("Unexpected non_pref_chan[0] value (update 4)")
  174. @remote_compatible
  175. def test_mbo_sta_supp_op_classes(dev, apdev):
  176. """MBO STA supported operating classes"""
  177. ssid = "test-wnm-mbo"
  178. params = { 'ssid': ssid, 'mbo': '1' }
  179. hapd = hostapd.add_ap(apdev[0], params)
  180. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  181. addr = dev[0].own_addr()
  182. sta = hapd.get_sta(addr)
  183. logger.debug("STA: " + str(sta))
  184. if 'supp_op_classes' not in sta:
  185. raise Exception("No supp_op_classes")
  186. supp = bytearray(sta['supp_op_classes'].decode("hex"))
  187. if supp[0] != 81:
  188. raise Exception("Unexpected current operating class %d" % supp[0])
  189. if 115 not in supp:
  190. raise Exception("Operating class 115 missing")