test_mbo.py 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. @remote_compatible
  101. def test_mbo_non_pref_chan(dev, apdev):
  102. """MBO non-preferred channel list"""
  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. if "OK" not in dev[0].request("SET non_pref_chan 81:7:200:3"):
  108. raise Exception("Failed to set non-preferred channel list")
  109. if "OK" not in dev[0].request("SET non_pref_chan 81:7:200:1:123 81:9:100:2"):
  110. raise Exception("Failed to set non-preferred channel list")
  111. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  112. addr = dev[0].own_addr()
  113. sta = hapd.get_sta(addr)
  114. logger.debug("STA: " + str(sta))
  115. if 'non_pref_chan[0]' not in sta:
  116. raise Exception("Missing non_pref_chan[0] value (assoc)")
  117. if sta['non_pref_chan[0]'] != '81:200:1:123:7':
  118. raise Exception("Unexpected non_pref_chan[0] value (assoc)")
  119. if 'non_pref_chan[1]' not in sta:
  120. raise Exception("Missing non_pref_chan[1] value (assoc)")
  121. if sta['non_pref_chan[1]'] != '81:100:2:0:9':
  122. raise Exception("Unexpected non_pref_chan[1] value (assoc)")
  123. if 'non_pref_chan[2]' in sta:
  124. raise Exception("Unexpected non_pref_chan[2] value (assoc)")
  125. if "OK" not in dev[0].request("SET non_pref_chan 81:9:100:2"):
  126. raise Exception("Failed to update non-preferred channel list")
  127. time.sleep(0.1)
  128. sta = hapd.get_sta(addr)
  129. logger.debug("STA: " + str(sta))
  130. if 'non_pref_chan[0]' not in sta:
  131. raise Exception("Missing non_pref_chan[0] value (update 1)")
  132. if sta['non_pref_chan[0]'] != '81:100:2:0:9':
  133. raise Exception("Unexpected non_pref_chan[0] value (update 1)")
  134. if 'non_pref_chan[1]' in sta:
  135. raise Exception("Unexpected non_pref_chan[2] value (update 1)")
  136. 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"):
  137. raise Exception("Failed to update non-preferred channel list")
  138. time.sleep(0.1)
  139. sta = hapd.get_sta(addr)
  140. logger.debug("STA: " + str(sta))
  141. if 'non_pref_chan[0]' not in sta:
  142. raise Exception("Missing non_pref_chan[0] value (update 2)")
  143. if sta['non_pref_chan[0]'] != '81:100:1:123:7':
  144. raise Exception("Unexpected non_pref_chan[0] value (update 2)")
  145. if 'non_pref_chan[1]' not in sta:
  146. raise Exception("Missing non_pref_chan[1] value (update 2)")
  147. if sta['non_pref_chan[1]'] != '81:100:1:124:5':
  148. raise Exception("Unexpected non_pref_chan[1] value (update 2)")
  149. if 'non_pref_chan[2]' not in sta:
  150. raise Exception("Missing non_pref_chan[2] value (update 2)")
  151. if sta['non_pref_chan[2]'] != '81:100:2:0:9,10,8':
  152. raise Exception("Unexpected non_pref_chan[2] value (update 2)")
  153. if 'non_pref_chan[3]' in sta:
  154. raise Exception("Unexpected non_pref_chan[3] value (update 2)")
  155. if "OK" not in dev[0].request("SET non_pref_chan 81:5:90:2 82:14:91:2"):
  156. raise Exception("Failed to update non-preferred channel list")
  157. time.sleep(0.1)
  158. sta = hapd.get_sta(addr)
  159. logger.debug("STA: " + str(sta))
  160. if 'non_pref_chan[0]' not in sta:
  161. raise Exception("Missing non_pref_chan[0] value (update 3)")
  162. if sta['non_pref_chan[0]'] != '81:90:2:0:5':
  163. raise Exception("Unexpected non_pref_chan[0] value (update 3)")
  164. if 'non_pref_chan[1]' not in sta:
  165. raise Exception("Missing non_pref_chan[1] value (update 3)")
  166. if sta['non_pref_chan[1]'] != '82:91:2:0:14':
  167. raise Exception("Unexpected non_pref_chan[1] value (update 3)")
  168. if 'non_pref_chan[2]' in sta:
  169. raise Exception("Unexpected non_pref_chan[2] value (update 3)")
  170. if "OK" not in dev[0].request("SET non_pref_chan "):
  171. raise Exception("Failed to update non-preferred channel list")
  172. time.sleep(0.1)
  173. sta = hapd.get_sta(addr)
  174. logger.debug("STA: " + str(sta))
  175. if 'non_pref_chan[0]' in sta:
  176. raise Exception("Unexpected non_pref_chan[0] value (update 4)")
  177. @remote_compatible
  178. def test_mbo_sta_supp_op_classes(dev, apdev):
  179. """MBO STA supported operating classes"""
  180. ssid = "test-wnm-mbo"
  181. params = { 'ssid': ssid, 'mbo': '1' }
  182. hapd = hostapd.add_ap(apdev[0], params)
  183. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  184. addr = dev[0].own_addr()
  185. sta = hapd.get_sta(addr)
  186. logger.debug("STA: " + str(sta))
  187. if 'supp_op_classes' not in sta:
  188. raise Exception("No supp_op_classes")
  189. supp = bytearray(sta['supp_op_classes'].decode("hex"))
  190. if supp[0] != 81:
  191. raise Exception("Unexpected current operating class %d" % supp[0])
  192. if 115 not in supp:
  193. raise Exception("Operating class 115 missing")