+
+def test_mbo_wnm_token_wrap(dev, apdev):
+ """MBO WNM token wrap around"""
+ ssid = "test-wnm-mbo"
+ params = { 'ssid': ssid, 'mbo': '1' }
+ hapd = hostapd.add_ap(apdev[0], params)
+ bssid = apdev[0]['bssid']
+
+ dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
+
+ # Trigger transmission of 256 WNM-Notification frames to wrap around the
+ # 8-bit mbo_wnm_token counter.
+ for i in range(128):
+ if "OK" not in dev[0].request("SET mbo_cell_capa 1"):
+ raise Exception("Failed to set STA as cellular data capable")
+ if "OK" not in dev[0].request("SET mbo_cell_capa 3"):
+ raise Exception("Failed to set STA as cellular data not-capable")
+
+@remote_compatible
+def test_mbo_non_pref_chan(dev, apdev):
+ """MBO non-preferred channel list"""
+ ssid = "test-wnm-mbo"
+ params = { 'ssid': ssid, 'mbo': '1' }
+ hapd = hostapd.add_ap(apdev[0], params)
+ bssid = apdev[0]['bssid']
+ if "FAIL" not in dev[0].request("SET non_pref_chan 81:7:200:99"):
+ raise Exception("Invalid non_pref_chan value accepted")
+ if "FAIL" not in dev[0].request("SET non_pref_chan 81:15:200:3"):
+ raise Exception("Invalid non_pref_chan value accepted")
+ if "FAIL" not in dev[0].request("SET non_pref_chan 81:7:200:3 81:7:201:3"):
+ raise Exception("Invalid non_pref_chan value accepted")
+ if "OK" not in dev[0].request("SET non_pref_chan 81:7:200:3"):
+ raise Exception("Failed to set non-preferred channel list")
+ if "OK" not in dev[0].request("SET non_pref_chan 81:7:200:1 81:9:100:2"):
+ raise Exception("Failed to set non-preferred channel list")
+
+ dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
+
+ addr = dev[0].own_addr()
+ sta = hapd.get_sta(addr)
+ logger.debug("STA: " + str(sta))
+ if 'non_pref_chan[0]' not in sta:
+ raise Exception("Missing non_pref_chan[0] value (assoc)")
+ if sta['non_pref_chan[0]'] != '81:200:1:7':
+ raise Exception("Unexpected non_pref_chan[0] value (assoc)")
+ if 'non_pref_chan[1]' not in sta:
+ raise Exception("Missing non_pref_chan[1] value (assoc)")
+ if sta['non_pref_chan[1]'] != '81:100:2:9':
+ raise Exception("Unexpected non_pref_chan[1] value (assoc)")
+ if 'non_pref_chan[2]' in sta:
+ raise Exception("Unexpected non_pref_chan[2] value (assoc)")
+
+ if "OK" not in dev[0].request("SET non_pref_chan 81:9:100:2"):
+ raise Exception("Failed to update non-preferred channel list")
+ time.sleep(0.1)
+ sta = hapd.get_sta(addr)
+ logger.debug("STA: " + str(sta))
+ if 'non_pref_chan[0]' not in sta:
+ raise Exception("Missing non_pref_chan[0] value (update 1)")
+ if sta['non_pref_chan[0]'] != '81:100:2:9':
+ raise Exception("Unexpected non_pref_chan[0] value (update 1)")
+ if 'non_pref_chan[1]' in sta:
+ raise Exception("Unexpected non_pref_chan[1] value (update 1)")
+
+ 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 81:5:100:1"):
+ raise Exception("Failed to update non-preferred channel list")
+ time.sleep(0.1)
+ sta = hapd.get_sta(addr)
+ logger.debug("STA: " + str(sta))
+ if 'non_pref_chan[0]' not in sta:
+ raise Exception("Missing non_pref_chan[0] value (update 2)")
+ if sta['non_pref_chan[0]'] != '81:100:1:7,5':
+ raise Exception("Unexpected non_pref_chan[0] value (update 2)")
+ if 'non_pref_chan[1]' not in sta:
+ raise Exception("Missing non_pref_chan[1] value (update 2)")
+ if sta['non_pref_chan[1]'] != '81:100:2:9,10,8':
+ raise Exception("Unexpected non_pref_chan[1] value (update 2)")
+ if 'non_pref_chan[2]' in sta:
+ raise Exception("Unexpected non_pref_chan[2] value (update 2)")
+
+ if "OK" not in dev[0].request("SET non_pref_chan 81:5:90:2 82:14:91:2"):
+ raise Exception("Failed to update non-preferred channel list")
+ time.sleep(0.1)
+ sta = hapd.get_sta(addr)
+ logger.debug("STA: " + str(sta))
+ if 'non_pref_chan[0]' not in sta:
+ raise Exception("Missing non_pref_chan[0] value (update 3)")
+ if sta['non_pref_chan[0]'] != '81:90:2:5':
+ raise Exception("Unexpected non_pref_chan[0] value (update 3)")
+ if 'non_pref_chan[1]' not in sta:
+ raise Exception("Missing non_pref_chan[1] value (update 3)")
+ if sta['non_pref_chan[1]'] != '82:91:2:14':
+ raise Exception("Unexpected non_pref_chan[1] value (update 3)")
+ if 'non_pref_chan[2]' in sta:
+ raise Exception("Unexpected non_pref_chan[2] value (update 3)")
+
+ if "OK" not in dev[0].request("SET non_pref_chan "):
+ raise Exception("Failed to update non-preferred channel list")
+ time.sleep(0.1)
+ sta = hapd.get_sta(addr)
+ logger.debug("STA: " + str(sta))
+ if 'non_pref_chan[0]' in sta:
+ raise Exception("Unexpected non_pref_chan[0] value (update 4)")
+
+@remote_compatible
+def test_mbo_sta_supp_op_classes(dev, apdev):
+ """MBO STA supported operating classes"""
+ ssid = "test-wnm-mbo"
+ params = { 'ssid': ssid, 'mbo': '1' }
+ hapd = hostapd.add_ap(apdev[0], params)
+
+ dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
+
+ addr = dev[0].own_addr()
+ sta = hapd.get_sta(addr)
+ logger.debug("STA: " + str(sta))
+ if 'supp_op_classes' not in sta:
+ raise Exception("No supp_op_classes")
+ supp = bytearray(sta['supp_op_classes'].decode("hex"))
+ if supp[0] != 81:
+ raise Exception("Unexpected current operating class %d" % supp[0])
+ if 115 not in supp:
+ raise Exception("Operating class 115 missing")
+
+def test_mbo_failures(dev, apdev):
+ """MBO failure cases"""
+ ssid = "test-wnm-mbo"
+ params = { 'ssid': ssid, 'mbo': '1' }
+ hapd = hostapd.add_ap(apdev[0], params)
+
+ with alloc_fail(dev[0], 1, "wpas_mbo_ie"):
+ dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
+
+ with alloc_fail(dev[0], 1, "wpas_mbo_send_wnm_notification"):
+ if "OK" not in dev[0].request("SET mbo_cell_capa 1"):
+ raise Exception("Failed to set STA as cellular data capable")
+ with fail_test(dev[0], 1, "wpas_mbo_send_wnm_notification"):
+ if "OK" not in dev[0].request("SET mbo_cell_capa 3"):
+ raise Exception("Failed to set STA as cellular data not-capable")
+ with alloc_fail(dev[0], 1, "wpas_mbo_update_non_pref_chan"):
+ if "FAIL" not in dev[0].request("SET non_pref_chan 81:7:200:3"):
+ raise Exception("non_pref_chan value accepted during OOM")
+ with alloc_fail(dev[0], 2, "wpas_mbo_update_non_pref_chan"):
+ if "FAIL" not in dev[0].request("SET non_pref_chan 81:7:200:3"):
+ raise Exception("non_pref_chan value accepted during OOM")
+
+def test_mbo_wnm_bss_tm_ie_parsing(dev, apdev):
+ """MBO BSS transition request MBO IE parsing"""
+ ssid = "test-wnm-mbo"
+ params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
+ hapd = hostapd.add_ap(apdev[0], params)
+ bssid = apdev[0]['bssid']
+ addr = dev[0].own_addr()
+ dev[0].connect(ssid, psk="12345678", key_mgmt="WPA-PSK",
+ proto="WPA2", ieee80211w="0", scan_freq="2412")
+
+ dev[0].request("SET ext_mgmt_frame_handling 1")
+ hdr = "d0003a01" + addr.replace(':', '') + bssid.replace(':', '') + bssid.replace(':', '') + "3000"
+ btm_hdr = "0a070100030001"
+
+ tests = [ ("Truncated attribute in MBO IE", "dd06506f9a160101"),
+ ("Unexpected cell data capa attribute length in MBO IE",
+ "dd09506f9a160501030500"),
+ ("Unexpected transition reason attribute length in MBO IE",
+ "dd06506f9a160600"),
+ ("Unexpected assoc retry delay attribute length in MBO IE",
+ "dd0c506f9a160100080200000800"),
+ ("Unknown attribute id 255 in MBO IE",
+ "dd06506f9a16ff00") ]
+
+ for test, mbo_ie in tests:
+ logger.info(test)
+ dev[0].request("NOTE " + test)
+ frame = hdr + btm_hdr + mbo_ie
+ if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame):
+ raise Exception("MGMT_RX_PROCESS failed")
+
+ logger.info("Unexpected association retry delay")
+ dev[0].request("NOTE Unexpected association retry delay")
+ btm_hdr = "0a070108030001112233445566778899aabbcc"
+ mbo_ie = "dd08506f9a1608020000"
+ frame = hdr + btm_hdr + mbo_ie
+ if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame):
+ raise Exception("MGMT_RX_PROCESS failed")
+
+ dev[0].request("SET ext_mgmt_frame_handling 0")