]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - tests/hwsim/test_fst_module.py
FT: Reject over-the-DS response with MFPC=0 if PMF is required
[thirdparty/hostap.git] / tests / hwsim / test_fst_module.py
index 0c4f080c07588ed5441bc23d6b37555fca3237f0..bb3b44ca3c57f041b4fff124f122fc41809fa08e 100644 (file)
@@ -84,7 +84,7 @@ bad_param_names = ("None",
                    "Bad fsts_id")
 
 def fst_start_session(apdev, test_params, bad_param_type, start_on_ap,
-                      peer_addr = None):
+                      peer_addr=None):
     """This function makes the necessary preparations and the adds and sets a
     session using either correct or incorrect parameters depending on the value
     of bad_param_type. If the call ends as expected (with session being
@@ -142,7 +142,7 @@ def fst_start_session(apdev, test_params, bad_param_type, start_on_ap,
                 sid = '-1'
             initiator.set_fst_parameters(llt=llt)
             initiator.configure_session(sid, new_iface, old_iface)
-    except Exception, e:
+    except Exception as e:
         if e.args[0].startswith("Cannot add FST session with groupid"):
             if bad_param_type == bad_param_group_id or bad_param_type == bad_param_session_add_no_params:
                 bad_parameter_detected = True
@@ -188,7 +188,7 @@ def fst_start_session(apdev, test_params, bad_param_type, start_on_ap,
                         exception_text = "Failure. Bad parameter was not detected (%s)" % bad_param_names[bad_param_type]
                     raise Exception(exception_text)
         else:
-            print "Failure. Unexpected exception"
+            logger.info("Failure. Unexpected exception")
 
 def fst_initiate_session(apdev, test_params, bad_param_type, init_on_ap):
     """This function makes the necessary preparations and then adds, sets and
@@ -238,7 +238,7 @@ def fst_initiate_session(apdev, test_params, bad_param_type, init_on_ap):
             initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
             setup_event = responder.wait_for_session_event(5, [],
                                                            ['EVENT_FST_SETUP'])
-            if not 'id' in setup_event:
+            if 'id' not in setup_event:
                 raise Exception("No session id in FST setup event")
             responder.send_session_setup_response(str(setup_event['id']),
                                                   "reject")
@@ -302,7 +302,7 @@ def fst_initiate_session(apdev, test_params, bad_param_type, init_on_ap):
             bad_parameter_detected = True
         else:
             initiator.initiate_session(sid, "accept")
-    except Exception, e:
+    except Exception as e:
         if e.args[0].startswith("Cannot initiate fst session"):
             if bad_param_type != bad_param_none:
                 bad_parameter_detected = True
@@ -326,7 +326,7 @@ def fst_initiate_session(apdev, test_params, bad_param_type, init_on_ap):
                 else:
                     raise Exception("Failure. Bad parameter was not detected (%s)" % bad_param_names[bad_param_type])
         else:
-            print "Failure. Unexpected exception"
+            logger.info("Failure. Unexpected exception")
 
 def fst_transfer_session(apdev, test_params, bad_param_type, init_on_ap,
                          rsn=False):
@@ -354,7 +354,7 @@ def fst_transfer_session(apdev, test_params, bad_param_type, init_on_ap,
             responder = ap1
             new_iface = sta2.ifname()
             new_peer_addr = sta2.get_actual_peer_addr()
-        initiator.add_peer(responder, new_peer_addr = new_peer_addr)
+        initiator.add_peer(responder, new_peer_addr=new_peer_addr)
         sid = initiator.add_session()
         initiator.configure_session(sid, new_iface)
         if bad_param_type != bad_param_session_transfer_setup_skipped:
@@ -364,7 +364,7 @@ def fst_transfer_session(apdev, test_params, bad_param_type, init_on_ap,
         elif bad_param_type == bad_param_session_transfer_bad_session_id:
             sid = '-1'
         initiator.transfer_session(sid)
-    except Exception, e:
+    except Exception as e:
         if e.args[0].startswith("Cannot transfer fst session"):
             if bad_param_type != bad_param_none:
                 bad_parameter_detected = True
@@ -385,7 +385,7 @@ def fst_transfer_session(apdev, test_params, bad_param_type, init_on_ap,
                 else:
                     raise Exception("Failure. Bad parameter was not detected (%s)" % bad_param_names[bad_param_type])
         else:
-            print "Failure. Unexpected exception"
+            logger.info("Failure. Unexpected exception")
 
 
 def fst_tear_down_session(apdev, test_params, bad_param_type, init_on_ap):
@@ -413,7 +413,7 @@ def fst_tear_down_session(apdev, test_params, bad_param_type, init_on_ap):
             responder = ap1
             new_iface = sta2.ifname()
             new_peer_addr = sta2.get_actual_peer_addr()
-        initiator.add_peer(responder, new_peer_addr = new_peer_addr)
+        initiator.add_peer(responder, new_peer_addr=new_peer_addr)
         sid = initiator.add_session()
         initiator.configure_session(sid, new_iface)
         if bad_param_type != bad_param_session_teardown_setup_skipped:
@@ -427,7 +427,7 @@ def fst_tear_down_session(apdev, test_params, bad_param_type, init_on_ap):
             elif bad_param_type == bad_param_session_teardown_bad_session_id:
                 sid = '-1'
             initiator.teardown_session(sid)
-    except Exception, e:
+    except Exception as e:
         if e.args[0].startswith("Cannot tear down fst session"):
             if (bad_param_type == bad_param_session_teardown_no_params or
                 bad_param_type == bad_param_session_teardown_bad_session_id or
@@ -453,7 +453,7 @@ def fst_tear_down_session(apdev, test_params, bad_param_type, init_on_ap):
                 else:
                     raise Exception("Failure. Bad parameter was not detected (%s)" % bad_param_names[bad_param_type])
         else:
-            print "Failure. Unexpected exception"
+            logger.info("Failure. Unexpected exception")
 
 
 #enum - remove session scenarios
@@ -492,7 +492,7 @@ def fst_remove_session(apdev, test_params, remove_session_scenario, init_on_ap):
             responder = ap1
             new_iface = sta2.ifname()
             new_peer_addr = sta2.get_actual_peer_addr()
-        initiator.add_peer(responder, new_peer_addr = new_peer_addr)
+        initiator.add_peer(responder, new_peer_addr=new_peer_addr)
         sid = initiator.add_session()
         initiator.configure_session(sid, new_iface)
         if remove_session_scenario != remove_scenario_no_params:
@@ -503,7 +503,7 @@ def fst_remove_session(apdev, test_params, remove_session_scenario, init_on_ap):
         elif remove_session_scenario == remove_scenario_bad_session_id:
             sid = '-1'
         initiator.remove_session(sid)
-    except Exception, e:
+    except Exception as e:
         if e.args[0].startswith("Cannot remove fst session"):
             if (remove_session_scenario == remove_scenario_no_params or
                 remove_session_scenario == remove_scenario_bad_session_id):
@@ -528,7 +528,7 @@ def fst_remove_session(apdev, test_params, remove_session_scenario, init_on_ap):
                 else:
                     raise Exception("Failure. Remove scenario ended in an unexpected way (%s)" % remove_scenario_names[remove_session_scenario])
         else:
-            print "Failure. Unexpected exception"
+            logger.info("Failure. Unexpected exception")
 
 
 #enum - frame types
@@ -544,7 +544,7 @@ frame_type_names = ("Session request",
                     "Ack response",
                     "Tear down")
 
-def fst_send_unexpected_frame(apdev, test_params, frame_type, send_from_ap, additional_param = ''):
+def fst_send_unexpected_frame(apdev, test_params, frame_type, send_from_ap, additional_param=''):
     """This function creates two pairs of APs and stations, makes them connect
     and then causes one side to send an unexpected FST frame of the specified
     type to the other. The other side should then identify and ignore the
@@ -568,8 +568,8 @@ def fst_send_unexpected_frame(apdev, test_params, frame_type, send_from_ap, addi
             receiver = ap1
             new_iface = sta2.ifname()
             new_peer_addr = sta2.get_actual_peer_addr()
-        sender.add_peer(receiver, new_peer_addr = new_peer_addr)
-        sid=sender.add_session()
+        sender.add_peer(receiver, new_peer_addr=new_peer_addr)
+        sid = sender.add_session()
         sender.configure_session(sid, new_iface)
         if frame_type == frame_type_session_request:
             sender.send_session_setup_request(sid)
@@ -592,7 +592,7 @@ def fst_send_unexpected_frame(apdev, test_params, frame_type, send_from_ap, addi
             #fsts_id doesn't matter, no actual session exists
             sender.send_test_tear_down('0')
             receiver.wait_for_session_event(5)
-    except Exception, e:
+    except Exception as e:
         if e.args[0].startswith("No FST-EVENT-SESSION received"):
             if frame_type != frame_type_session_request:
                 frame_receive_timeout = True
@@ -612,7 +612,7 @@ def fst_send_unexpected_frame(apdev, test_params, frame_type, send_from_ap, addi
                 else:
                     raise Exception("Failure. Frame was not ignored (%s)" % frame_type_names[frame_type])
         else:
-            print "Failure. Unexpected exception"
+            logger.info("Failure. Unexpected exception")
 
 
 #enum - bad session transfer scenarios
@@ -663,7 +663,7 @@ def fst_bad_transfer(apdev, test_params, bad_scenario_type, init_on_ap):
             responder = ap1
             new_iface = sta2.ifname()
             new_peer_addr = sta2.get_actual_peer_addr()
-        initiator.add_peer(responder, new_peer_addr = new_peer_addr)
+        initiator.add_peer(responder, new_peer_addr=new_peer_addr)
         sid = initiator.add_session()
         initiator.configure_session(sid, new_iface)
         if (bad_scenario_type != bad_scenario_ack_req_session_not_set_up and
@@ -672,7 +672,7 @@ def fst_bad_transfer(apdev, test_params, bad_scenario_type, init_on_ap):
                 bad_scenario_type != bad_scenario_ack_resp_session_not_established_init_side and
                 bad_scenario_type != bad_scenario_ack_req_session_not_established_resp_side and
                 bad_scenario_type != bad_scenario_ack_resp_session_not_established_resp_side):
-                response =  "accept"
+                response = "accept"
             else:
                 response = ''
             initiator.initiate_session(sid, response)
@@ -716,7 +716,7 @@ def fst_bad_transfer(apdev, test_params, bad_scenario_type, init_on_ap):
             responder.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
         else:
             raise Exception("Unknown bad scenario identifier")
-    except Exception, e:
+    except Exception as e:
         if e.args[0].startswith("No FST-EVENT-SESSION received"):
             bad_parameter_detected = True
         if not bad_parameter_detected:
@@ -733,34 +733,33 @@ def fst_bad_transfer(apdev, test_params, bad_scenario_type, init_on_ap):
             else:
                 raise Exception("Failure. Bad scenario was handled incorrectly (%s)" % bad_scenario_names[bad_scenario_type])
         else:
-            print "Failure. Unexpected exception"
+            logger.info("Failure. Unexpected exception")
 
 def test_fst_sta_connect_to_non_fst_ap(dev, apdev, test_params):
     """FST STA connecting to non-FST AP"""
     ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
     with HWSimRadio() as (radio, iface):
-        non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
+        non_fst_ap = hostapd.add_ap(iface, {"ssid": "non_fst_11g"})
         try:
             orig_sta1_mbies = sta1.get_local_mbies()
             orig_sta2_mbies = sta2.get_local_mbies()
-            vals = sta2.scan()
-            freq = vals['freq']
             sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
-                                        key_mgmt="NONE", scan_freq=freq)
+                                        key_mgmt="NONE", scan_freq='2412')
             time.sleep(2)
             res_sta1_mbies = sta1.get_local_mbies()
             res_sta2_mbies = sta2.get_local_mbies()
             if (orig_sta1_mbies.startswith("FAIL") or
                 orig_sta2_mbies.startswith("FAIL") or
-                not res_sta1_mbies.startswith("FAIL") or
-                not res_sta2_mbies.startswith("FAIL")):
-                raise Exception("Failure. MB IEs have not been removed on the stations")
-        except Exception, e:
+                res_sta1_mbies.startswith("FAIL") or
+                res_sta2_mbies.startswith("FAIL")):
+                raise Exception("Failure. MB IEs must be present on the stations")
+        except Exception as e:
             logger.info(e)
             raise
         finally:
             sta2.disconnect_from_external_ap()
             fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
+            hostapd.HostapdGlobal().remove(iface)
 
 def test_fst_sta_connect_to_fst_ap(dev, apdev, test_params):
     """FST STA connecting to FST AP"""
@@ -774,7 +773,7 @@ def test_fst_sta_connect_to_fst_ap(dev, apdev, test_params):
         res_sta2_mbies = sta2.get_local_mbies()
         if res_sta2_mbies == orig_sta2_mbies:
             raise Exception("Failure. MB IEs have not been updated")
-    except Exception, e:
+    except Exception as e:
         logger.info(e)
         raise
     finally:
@@ -793,7 +792,7 @@ def test_fst_ap_connect_to_fst_sta(dev, apdev, test_params):
         res_ap_mbies = ap1.get_local_mbies()
         if res_ap_mbies != orig_ap_mbies:
             raise Exception("Failure. MB IEs have been unexpectedly updated on the AP")
-    except Exception, e:
+    except Exception as e:
         logger.info(e)
         raise
     finally:
@@ -812,7 +811,7 @@ def test_fst_ap_connect_to_non_fst_sta(dev, apdev, test_params):
         res_ap_mbies = ap2.get_local_mbies()
         if res_ap_mbies != orig_ap_mbies:
             raise Exception("Failure. MB IEs have been unexpectedly updated on the AP")
-    except Exception, e:
+    except Exception as e:
         logger.info(e)
         raise
     finally:
@@ -823,42 +822,40 @@ def test_fst_second_sta_connect_to_non_fst_ap(dev, apdev, test_params):
     """FST STA 2nd connecting to non-FST AP"""
     fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
     with HWSimRadio() as (radio, iface):
-        non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
+        non_fst_ap = hostapd.add_ap(iface, {"ssid": "non_fst_11g"})
         try:
             vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
             sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
             time.sleep(2)
             orig_sta1_mbies = sta1.get_local_mbies()
             orig_sta2_mbies = sta2.get_local_mbies()
-            vals = sta2.scan()
-            freq = vals['freq']
-            sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g", key_mgmt="NONE", scan_freq=freq)
+            sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
+                                        key_mgmt="NONE", scan_freq='2412')
             time.sleep(2)
             res_sta1_mbies = sta1.get_local_mbies()
             res_sta2_mbies = sta2.get_local_mbies()
             if (orig_sta1_mbies.startswith("FAIL") or
                 orig_sta2_mbies.startswith("FAIL") or
-                not res_sta1_mbies.startswith("FAIL") or
-                not res_sta2_mbies.startswith("FAIL")):
-                raise Exception("Failure. MB IEs have not been removed on the stations")
-        except Exception, e:
+                res_sta1_mbies.startswith("FAIL") or
+                res_sta2_mbies.startswith("FAIL")):
+                raise Exception("Failure. MB IEs must be present on the stations")
+        except Exception as e:
             logger.info(e)
             raise
         finally:
             sta1.disconnect()
             sta2.disconnect_from_external_ap()
             fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
-
+            hostapd.HostapdGlobal().remove(iface)
 
 def test_fst_second_sta_connect_to_fst_ap(dev, apdev, test_params):
     """FST STA 2nd connecting to FST AP"""
     fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
     with HWSimRadio() as (radio, iface):
-        non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
+        non_fst_ap = hostapd.add_ap(iface, {"ssid": "non_fst_11g"})
         try:
-            vals = sta2.scan()
-            freq = vals['freq']
-            sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g", key_mgmt="NONE", scan_freq=freq)
+            sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
+                                        key_mgmt="NONE", scan_freq='2412')
             time.sleep(2)
             orig_sta1_mbies = sta1.get_local_mbies()
             orig_sta2_mbies = sta2.get_local_mbies()
@@ -867,30 +864,30 @@ def test_fst_second_sta_connect_to_fst_ap(dev, apdev, test_params):
             time.sleep(2)
             res_sta1_mbies = sta1.get_local_mbies()
             res_sta2_mbies = sta2.get_local_mbies()
-            if (not orig_sta1_mbies.startswith("FAIL") or
-                not orig_sta2_mbies.startswith("FAIL") or
-                not res_sta1_mbies.startswith("FAIL") or
-                not res_sta2_mbies.startswith("FAIL")):
-                raise Exception("Failure. MB IEs should have stayed non-present on the stations")
-        except Exception, e:
+            if (orig_sta1_mbies.startswith("FAIL") or
+                orig_sta2_mbies.startswith("FAIL") or
+                res_sta1_mbies.startswith("FAIL") or
+                res_sta2_mbies.startswith("FAIL")):
+                raise Exception("Failure. MB IEs must be present on the stations")
+        except Exception as e:
             logger.info(e)
             raise
         finally:
             sta1.disconnect()
             sta2.disconnect_from_external_ap()
             fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
+            hostapd.HostapdGlobal().remove(iface)
 
 def test_fst_disconnect_1_of_2_stas_from_non_fst_ap(dev, apdev, test_params):
     """FST disconnect 1 of 2 STAs from non-FST AP"""
     fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
     with HWSimRadio() as (radio, iface):
-        non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
+        non_fst_ap = hostapd.add_ap(iface, {"ssid": "non_fst_11g"})
         try:
             vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
             sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
-            vals = sta2.scan()
-            freq = vals['freq']
-            sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g", key_mgmt="NONE", scan_freq=freq)
+            sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
+                                        key_mgmt="NONE", scan_freq='2412')
             time.sleep(2)
             orig_sta1_mbies = sta1.get_local_mbies()
             orig_sta2_mbies = sta2.get_local_mbies()
@@ -898,31 +895,30 @@ def test_fst_disconnect_1_of_2_stas_from_non_fst_ap(dev, apdev, test_params):
             time.sleep(2)
             res_sta1_mbies = sta1.get_local_mbies()
             res_sta2_mbies = sta2.get_local_mbies()
-            if (not orig_sta1_mbies.startswith("FAIL") or
-                not orig_sta2_mbies.startswith("FAIL") or
+            if (orig_sta1_mbies.startswith("FAIL") or
+                orig_sta2_mbies.startswith("FAIL") or
                 res_sta1_mbies.startswith("FAIL") or
                 res_sta2_mbies.startswith("FAIL")):
-                raise Exception("Failure. MB IEs haven't reappeared on the stations")
-        except Exception, e:
+                raise Exception("Failure. MB IEs must be present on the stations")
+        except Exception as e:
             logger.info(e)
             raise
         finally:
             sta1.disconnect()
             sta2.disconnect_from_external_ap()
             fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
-
+            hostapd.HostapdGlobal().remove(iface)
 
 def test_fst_disconnect_1_of_2_stas_from_fst_ap(dev, apdev, test_params):
     """FST disconnect 1 of 2 STAs from FST AP"""
     fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
     with HWSimRadio() as (radio, iface):
-        non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
+        non_fst_ap = hostapd.add_ap(iface, {"ssid": "non_fst_11g"})
         try:
             vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
             sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
-            vals = sta2.scan()
-            freq = vals['freq']
-            sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g", key_mgmt="NONE", scan_freq=freq)
+            sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
+                                        key_mgmt="NONE", scan_freq='2412')
             time.sleep(2)
             orig_sta1_mbies = sta1.get_local_mbies()
             orig_sta2_mbies = sta2.get_local_mbies()
@@ -930,30 +926,30 @@ def test_fst_disconnect_1_of_2_stas_from_fst_ap(dev, apdev, test_params):
             time.sleep(2)
             res_sta1_mbies = sta1.get_local_mbies()
             res_sta2_mbies = sta2.get_local_mbies()
-            if (not orig_sta1_mbies.startswith("FAIL") or
-                not orig_sta2_mbies.startswith("FAIL") or
-                not res_sta1_mbies.startswith("FAIL") or
-                not res_sta2_mbies.startswith("FAIL")):
-                raise Exception("Failure. MB IEs should have stayed non-present on the stations")
-        except Exception, e:
+            if (orig_sta1_mbies.startswith("FAIL") or
+                orig_sta2_mbies.startswith("FAIL") or
+                res_sta1_mbies.startswith("FAIL") or
+                res_sta2_mbies.startswith("FAIL")):
+                raise Exception("Failure. MB IEs must be present on the stations")
+        except Exception as e:
             logger.info(e)
             raise
         finally:
             sta1.disconnect()
             sta2.disconnect_from_external_ap()
             fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
+            hostapd.HostapdGlobal().remove(iface)
 
 def test_fst_disconnect_2_of_2_stas_from_non_fst_ap(dev, apdev, test_params):
     """FST disconnect 2 of 2 STAs from non-FST AP"""
     fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
     with HWSimRadio() as (radio, iface):
-        non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
+        non_fst_ap = hostapd.add_ap(iface, {"ssid": "non_fst_11g"})
         try:
             vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
             sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
-            vals = sta2.scan()
-            freq = vals['freq']
-            sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g", key_mgmt="NONE", scan_freq=freq)
+            sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
+                                        key_mgmt="NONE", scan_freq='2412')
             time.sleep(2)
             sta1.disconnect()
             time.sleep(2)
@@ -963,30 +959,30 @@ def test_fst_disconnect_2_of_2_stas_from_non_fst_ap(dev, apdev, test_params):
             time.sleep(2)
             res_sta1_mbies = sta1.get_local_mbies()
             res_sta2_mbies = sta2.get_local_mbies()
-            if (not orig_sta1_mbies.startswith("FAIL") or
-                not orig_sta2_mbies.startswith("FAIL") or
+            if (orig_sta1_mbies.startswith("FAIL") or
+                orig_sta2_mbies.startswith("FAIL") or
                 res_sta1_mbies.startswith("FAIL") or
                 res_sta2_mbies.startswith("FAIL")):
-                raise Exception("Failure. MB IEs haven't reappeared on the stations")
-        except Exception, e:
+                raise Exception("Failure. MB IEs must be present on the stations")
+        except Exception as e:
             logger.info(e)
             raise
         finally:
             sta1.disconnect()
             sta2.disconnect_from_external_ap()
             fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
+            hostapd.HostapdGlobal().remove(iface)
 
 def test_fst_disconnect_2_of_2_stas_from_fst_ap(dev, apdev, test_params):
     """FST disconnect 2 of 2 STAs from FST AP"""
     fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
     with HWSimRadio() as (radio, iface):
-        non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g"})
+        non_fst_ap = hostapd.add_ap(iface, {"ssid": "non_fst_11g"})
         try:
             vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
             sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
-            vals = sta2.scan()
-            freq = vals['freq']
-            sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g", key_mgmt="NONE", scan_freq=freq)
+            sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
+                                        key_mgmt="NONE", scan_freq='2412')
             time.sleep(2)
             sta2.disconnect_from_external_ap()
             time.sleep(2)
@@ -1018,13 +1014,14 @@ def test_fst_disconnect_2_of_2_stas_from_fst_ap(dev, apdev, test_params):
                 addr_sta2_mbie1 != addr_sta2_mbie2 or
                 addr_sta2_mbie1 != addr_sta1_str):
                 raise Exception("Failure. STA Address in MB IEs should have been same as the other STA's")
-        except Exception, e:
+        except Exception as e:
             logger.info(e)
             raise
         finally:
             sta1.disconnect()
             sta2.disconnect_from_external_ap()
             fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
+            hostapd.HostapdGlobal().remove(iface)
 
 def test_fst_disconnect_non_fst_sta(dev, apdev, test_params):
     """FST disconnect non-FST STA"""
@@ -1048,7 +1045,7 @@ def test_fst_disconnect_non_fst_sta(dev, apdev, test_params):
         res_ap_mbies = ap2.get_local_mbies()
         if res_ap_mbies != orig_ap_mbies:
             raise Exception("Failure. MB IEs have been unexpectedly updated on the AP")
-    except Exception, e:
+    except Exception as e:
         logger.info(e)
         raise
     finally:
@@ -1060,7 +1057,7 @@ def test_fst_disconnect_non_fst_sta(dev, apdev, test_params):
 def test_fst_disconnect_fst_sta(dev, apdev, test_params):
     """FST disconnect FST STA"""
     ap1, ap2, fst_sta1, fst_sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
-    external_sta_connected = False;
+    external_sta_connected = False
     try:
         vals = fst_sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
         fst_sta1.connect(ap1, key_mgmt="NONE",
@@ -1079,7 +1076,7 @@ def test_fst_disconnect_fst_sta(dev, apdev, test_params):
         res_ap_mbies = ap2.get_local_mbies()
         if res_ap_mbies != orig_ap_mbies:
             raise Exception("Failure. MB IEs have been unexpectedly updated on the AP")
-    except Exception, e:
+    except Exception as e:
         logger.info(e)
         raise
     finally:
@@ -1140,7 +1137,7 @@ def test_fst_dynamic_iface_attach(dev, apdev, test_params):
             res_sta2_mbies.startswith("FAIL") or
             res_ap2_mbies.startswith("FAIL")):
             raise Exception("Failure. MB IEs should have appeared on the station and on the AP")
-    except Exception, e:
+    except Exception as e:
         logger.info(e)
         raise
     finally:
@@ -1447,51 +1444,51 @@ def test_fst_ap_ctrl_iface(dev, apdev, test_params):
         if len(res) != 1 + start_num_groups:
             raise Exception("Unexpected number of groups")
 
-        tests = [ "LIST_IFACES unknown",
-                  "LIST_IFACES     unknown2",
-                  "SESSION_GET 12345678",
-                  "SESSION_SET " + sid + " unknown=foo",
-                  "SESSION_RESPOND 12345678 foo",
-                  "SESSION_RESPOND " + sid,
-                  "SESSION_RESPOND " + sid + " foo",
-                  "TEST_REQUEST foo",
-                  "TEST_REQUEST SEND_SETUP_REQUEST",
-                  "TEST_REQUEST SEND_SETUP_REQUEST foo",
-                  "TEST_REQUEST SEND_SETUP_RESPONSE",
-                  "TEST_REQUEST SEND_SETUP_RESPONSE foo",
-                  "TEST_REQUEST SEND_ACK_REQUEST",
-                  "TEST_REQUEST SEND_ACK_REQUEST foo",
-                  "TEST_REQUEST SEND_ACK_RESPONSE",
-                  "TEST_REQUEST SEND_ACK_RESPONSE foo",
-                  "TEST_REQUEST SEND_TEAR_DOWN",
-                  "TEST_REQUEST SEND_TEAR_DOWN foo",
-                  "TEST_REQUEST GET_FSTS_ID",
-                  "TEST_REQUEST GET_FSTS_ID foo",
-                  "TEST_REQUEST GET_LOCAL_MBIES",
-                  "TEST_REQUEST GET_LOCAL_MBIES foo",
-                  "GET_PEER_MBIES",
-                  "GET_PEER_MBIES ",
-                  "GET_PEER_MBIES unknown",
-                  "GET_PEER_MBIES unknown unknown",
-                  "GET_PEER_MBIES unknown  " + initiator.get_new_peer_addr(),
-                  "GET_PEER_MBIES " + initiator.ifname() + " 01:ff:ff:ff:ff:ff",
-                  "GET_PEER_MBIES " + initiator.ifname() + " 00:ff:ff:ff:ff:ff",
-                  "GET_PEER_MBIES " + initiator.ifname() + " 00:00:00:00:00:00",
-                  "IFACE_PEERS",
-                  "IFACE_PEERS ",
-                  "IFACE_PEERS unknown",
-                  "IFACE_PEERS unknown unknown",
-                  "IFACE_PEERS " + initiator.fst_group,
-                  "IFACE_PEERS " + initiator.fst_group + " unknown" ]
+        tests = ["LIST_IFACES unknown",
+                 "LIST_IFACES     unknown2",
+                 "SESSION_GET 12345678",
+                 "SESSION_SET " + sid + " unknown=foo",
+                 "SESSION_RESPOND 12345678 foo",
+                 "SESSION_RESPOND " + sid,
+                 "SESSION_RESPOND " + sid + " foo",
+                 "TEST_REQUEST foo",
+                 "TEST_REQUEST SEND_SETUP_REQUEST",
+                 "TEST_REQUEST SEND_SETUP_REQUEST foo",
+                 "TEST_REQUEST SEND_SETUP_RESPONSE",
+                 "TEST_REQUEST SEND_SETUP_RESPONSE foo",
+                 "TEST_REQUEST SEND_ACK_REQUEST",
+                 "TEST_REQUEST SEND_ACK_REQUEST foo",
+                 "TEST_REQUEST SEND_ACK_RESPONSE",
+                 "TEST_REQUEST SEND_ACK_RESPONSE foo",
+                 "TEST_REQUEST SEND_TEAR_DOWN",
+                 "TEST_REQUEST SEND_TEAR_DOWN foo",
+                 "TEST_REQUEST GET_FSTS_ID",
+                 "TEST_REQUEST GET_FSTS_ID foo",
+                 "TEST_REQUEST GET_LOCAL_MBIES",
+                 "TEST_REQUEST GET_LOCAL_MBIES foo",
+                 "GET_PEER_MBIES",
+                 "GET_PEER_MBIES ",
+                 "GET_PEER_MBIES unknown",
+                 "GET_PEER_MBIES unknown unknown",
+                 "GET_PEER_MBIES unknown  " + initiator.get_new_peer_addr(),
+                 "GET_PEER_MBIES " + initiator.ifname() + " 01:ff:ff:ff:ff:ff",
+                 "GET_PEER_MBIES " + initiator.ifname() + " 00:ff:ff:ff:ff:ff",
+                 "GET_PEER_MBIES " + initiator.ifname() + " 00:00:00:00:00:00",
+                 "IFACE_PEERS",
+                 "IFACE_PEERS ",
+                 "IFACE_PEERS unknown",
+                 "IFACE_PEERS unknown unknown",
+                 "IFACE_PEERS " + initiator.fst_group,
+                 "IFACE_PEERS " + initiator.fst_group + " unknown"]
         for t in tests:
             if "FAIL" not in initiator.grequest("FST-MANAGER " + t):
                 raise Exception("Unexpected response for invalid FST-MANAGER command " + t)
         if "UNKNOWN FST COMMAND" not in initiator.grequest("FST-MANAGER unknown"):
             raise Exception("Unexpected response for unknown FST-MANAGER command")
 
-        tests = [ "FST-DETACH", "FST-DETACH ", "FST-DETACH unknown",
-                  "FST-ATTACH", "FST-ATTACH ", "FST-ATTACH unknown",
-                  "FST-ATTACH unknown unknown" ]
+        tests = ["FST-DETACH", "FST-DETACH ", "FST-DETACH unknown",
+                 "FST-ATTACH", "FST-ATTACH ", "FST-ATTACH unknown",
+                 "FST-ATTACH unknown unknown"]
         for t in tests:
             if "FAIL" not in initiator.grequest(t):
                 raise Exception("Unexpected response for invalid command " + t)
@@ -1501,13 +1498,13 @@ def test_fst_ap_ctrl_iface(dev, apdev, test_params):
             ap1.send_iface_attach_request(ap1.iface, ap1.fst_group,
                                           ap1.fst_llt, ap1.fst_pri)
             raise Exception("Duplicate FST-ATTACH succeeded")
-        except Exception, e:
+        except Exception as e:
             if not str(e).startswith("Cannot attach"):
                 raise
 
         try:
             ap1.get_fsts_id_by_sid("123")
-        except Exception, e:
+        except Exception as e:
             if not str(e).startswith("Cannot get fsts_id for sid"):
                 raise
     finally:
@@ -1522,6 +1519,13 @@ def test_fst_ap_start_session_oom(dev, apdev, test_params):
                                fst_test_common.fst_test_def_prio_low,
                                fst_test_common.fst_test_def_llt)
     ap1.start()
+    try:
+        run_fst_ap_start_session_oom(apdev, ap1)
+    finally:
+        ap1.stop()
+        fst_test_common.fst_clear_regdom()
+
+def run_fst_ap_start_session_oom(apdev, ap1):
     with alloc_fail(ap1, 1, "fst_iface_create"):
         ap2_started = False
         try:
@@ -1536,7 +1540,6 @@ def test_fst_ap_start_session_oom(dev, apdev, test_params):
             except:
                 pass
         finally:
-            ap1.stop()
             try:
                 ap2.stop()
             except:
@@ -1820,7 +1823,7 @@ FST_ACTION_ON_CHANNEL_TUNNEL = 5
 def hostapd_tx_and_status(hapd, msg):
     hapd.set("ext_mgmt_frame_handling", "1")
     hapd.mgmt_tx(msg)
-    ev = hapd.wait_event([ "MGMT-TX-STATUS" ], timeout=1)
+    ev = hapd.wait_event(["MGMT-TX-STATUS"], timeout=1)
     if ev is None or "ok=1" not in ev:
         raise Exception("No ACK")
     hapd.set("ext_mgmt_frame_handling", "0")
@@ -2064,7 +2067,7 @@ def test_fst_ack_response_proto(dev, apdev, test_params):
         s = sta1.grequest("FST-MANAGER SESSION_INITIATE "+ sid)
         if not s.startswith('OK'):
             raise Exception("Cannot initiate fst session: %s" % s)
-        ev = sta1.peer_obj.wait_gevent([ "FST-EVENT-SESSION" ], timeout=5)
+        ev = sta1.peer_obj.wait_gevent(["FST-EVENT-SESSION"], timeout=5)
         if ev is None:
             raise Exception("No FST-EVENT-SESSION received")
         event = fst_module_aux.parse_fst_session_event(ev)
@@ -2100,7 +2103,7 @@ def test_fst_ack_response_proto(dev, apdev, test_params):
         msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
                                      FST_ACTION_ACK_RESPONSE)
         hapd.mgmt_tx(msg)
-        ev = hapd.wait_event([ "MGMT-TX-STATUS" ], timeout=1)
+        ev = hapd.wait_event(["MGMT-TX-STATUS"], timeout=1)
         if ev is None or "ok=1" not in ev:
             raise Exception("No ACK")
 
@@ -2135,6 +2138,7 @@ def test_fst_ap_config_oom(dev, apdev, test_params):
         # This is allowed to complete currently
 
     ap1.stop()
+    fst_test_common.fst_clear_regdom()
 
 def test_fst_send_oom(dev, apdev, test_params):
     """FST send action OOM"""
@@ -2165,7 +2169,7 @@ def test_fst_send_oom(dev, apdev, test_params):
         if not res.startswith("OK"):
             raise Exception("SESSION_INITIATE failed")
 
-        tests = [ "", "foo", sid, sid + " foo", sid + " foo=bar" ]
+        tests = ["", "foo", sid, sid + " foo", sid + " foo=bar"]
         for t in tests:
             res = initiator.grequest("FST-MANAGER SESSION_SET " + t)
             if not res.startswith("FAIL"):
@@ -2229,7 +2233,7 @@ def test_fst_session_respond_fail(dev, apdev, test_params):
         sta1.send_session_setup_request(sid)
         sta1.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
         ev = ap1.wait_for_session_event(5, [], ['EVENT_FST_SETUP'])
-        if not 'id' in ev:
+        if 'id' not in ev:
             raise Exception("No session id in FST setup event")
         # Disconnect STA to make SESSION_RESPOND fail due to no peer found
         sta = sta1.get_instance()
@@ -2248,6 +2252,11 @@ def fst_session_set(dev, sid, param, value):
     if "OK" not in dev.global_request(cmd):
         raise Exception(cmd + " failed")
 
+def fst_session_set_ap(dev, sid, param, value):
+    cmd = "FST-MANAGER SESSION_SET %s %s=%s" % (sid, param, value)
+    if "OK" not in dev.request(cmd):
+        raise Exception(cmd + " failed")
+
 def fst_attach_ap(dev, ifname, group):
     cmd = "FST-ATTACH %s %s" % (ifname, group)
     if "OK" not in dev.request(cmd):
@@ -2255,7 +2264,7 @@ def fst_attach_ap(dev, ifname, group):
     ev = dev.wait_event(['FST-EVENT-IFACE'], timeout=5)
     if ev is None:
         raise Exception("No FST-EVENT-IFACE attached (AP)")
-    for t in [ "attached", "ifname=" + ifname, "group=" + group ]:
+    for t in ["attached", "ifname=" + ifname, "group=" + group]:
         if t not in ev:
             raise Exception("Unexpected FST-EVENT-IFACE data (AP): " + ev)
 
@@ -2265,7 +2274,7 @@ def fst_attach_sta(dev, ifname, group):
     ev = dev.wait_global_event(['FST-EVENT-IFACE'], timeout=5)
     if ev is None:
         raise Exception("No FST-EVENT-IFACE attached (STA)")
-    for t in [ "attached", "ifname=" + ifname, "group=" + group ]:
+    for t in ["attached", "ifname=" + ifname, "group=" + group]:
         if t not in ev:
             raise Exception("Unexpected FST-EVENT-IFACE data (STA): " + ev)
 
@@ -2275,7 +2284,7 @@ def fst_detach_ap(dev, ifname, group):
     ev = dev.wait_event(['FST-EVENT-IFACE'], timeout=5)
     if ev is None:
         raise Exception("No FST-EVENT-IFACE detached (AP) for " + ifname)
-    for t in [ "detached", "ifname=" + ifname, "group=" + group ]:
+    for t in ["detached", "ifname=" + ifname, "group=" + group]:
         if t not in ev:
             raise Exception("Unexpected FST-EVENT-IFACE data (AP): " + ev)
 
@@ -2286,7 +2295,7 @@ def fst_detach_sta(dev, ifname, group):
     ev = dev.wait_global_event(['FST-EVENT-IFACE'], timeout=5)
     if ev is None:
         raise Exception("No FST-EVENT-IFACE detached (STA) for " + ifname)
-    for t in [ "detached", "ifname=" + ifname, "group=" + group ]:
+    for t in ["detached", "ifname=" + ifname, "group=" + group]:
         if t not in ev:
             raise Exception("Unexpected FST-EVENT-IFACE data (STA): " + ev)
 
@@ -2294,7 +2303,7 @@ def fst_wait_event_peer_ap(dev, event, ifname, addr):
     ev = dev.wait_event(['FST-EVENT-PEER'], timeout=5)
     if ev is None:
         raise Exception("No FST-EVENT-PEER connected (AP)")
-    for t in [ " " + event + " ", "ifname=" + ifname, "peer_addr=" + addr ]:
+    for t in [" " + event + " ", "ifname=" + ifname, "peer_addr=" + addr]:
         if t not in ev:
             raise Exception("Unexpected FST-EVENT-PEER data (AP): " + ev)
 
@@ -2302,7 +2311,7 @@ def fst_wait_event_peer_sta(dev, event, ifname, addr):
     ev = dev.wait_global_event(['FST-EVENT-PEER'], timeout=5)
     if ev is None:
         raise Exception("No FST-EVENT-PEER connected (STA)")
-    for t in [ " " + event + " ", "ifname=" + ifname, "peer_addr=" + addr ]:
+    for t in [" " + event + " ", "ifname=" + ifname, "peer_addr=" + addr]:
         if t not in ev:
             raise Exception("Unexpected FST-EVENT-PEER data (STA): " + ev)
 
@@ -2327,9 +2336,9 @@ def fst_start_and_connect(apdev, group, sgroup):
     if "OK" not in hglobal.request("FST-MANAGER TEST_REQUEST IS_SUPPORTED"):
         raise HwsimSkip("No FST testing support")
 
-    params = { "ssid": "fst_11a", "hw_mode": "a", "channel": "36",
-               "country_code": "US" }
-    hapd = hostapd.add_ap(apdev[0]['ifname'], params)
+    params = {"ssid": "fst_11a", "hw_mode": "a", "channel": "36",
+              "country_code": "US"}
+    hapd = hostapd.add_ap(apdev[0], params)
 
     fst_attach_ap(hglobal, apdev[0]['ifname'], group)
 
@@ -2337,9 +2346,9 @@ def fst_start_and_connect(apdev, group, sgroup):
     if "FAIL" not in hglobal.request(cmd):
         raise Exception("Duplicated FST-ATTACH (AP) accepted")
 
-    params = { "ssid": "fst_11g", "hw_mode": "g", "channel": "1",
-               "country_code": "US" }
-    hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
+    params = {"ssid": "fst_11g", "hw_mode": "g", "channel": "1",
+              "country_code": "US"}
+    hapd2 = hostapd.add_ap(apdev[1], params)
     fst_attach_ap(hglobal, apdev[1]['ifname'], group)
 
     wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
@@ -2524,9 +2533,20 @@ def _test_fst_setup_mbie_diff(dev, apdev, test_params):
     req = "1200011a060000"
     stie = "a40b0100000000020001040001"
     mbie = "9e16040200010200000004000000000000000000000000ff"
-    with alloc_fail(hapd, 1, "mb_ies_by_info"):
-        fst_setup_req(wpas, hglobal, 5180, apdev[0]['bssid'], req, stie, mbie,
-                      no_wait=True)
+    try:
+        with alloc_fail(hapd, 1, "mb_ies_by_info"):
+            fst_setup_req(wpas, hglobal, 5180, apdev[0]['bssid'], req, stie,
+                          mbie, no_wait=True)
+    except HwsimSkip as e:
+        # Skip exception to allow proper cleanup
+        pass
+
+    # Remove sessions to avoid causing issues to following test ases
+    s = hglobal.request("FST-MANAGER LIST_SESSIONS " + group)
+    if not s.startswith("FAIL"):
+        for sid in s.split(' '):
+            if len(sid):
+                hglobal.request("FST-MANAGER SESSION_REMOVE " + sid)
 
 def test_fst_many_setup(dev, apdev, test_params):
     """FST setup multiple times"""
@@ -2630,6 +2650,8 @@ def _test_fst_many_setup(dev, apdev, test_params):
 
 def test_fst_attach_wpas_error(dev, apdev, test_params):
     """FST attach errors in wpa_supplicant"""
+    if "OK" not in dev[0].global_request("FST-MANAGER TEST_REQUEST IS_SUPPORTED"):
+        raise HwsimSkip("No FST testing support")
     group = "fstg0"
     wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
     wpas.interface_add("wlan5")
@@ -2640,3 +2662,164 @@ def test_fst_attach_wpas_error(dev, apdev, test_params):
     if "FAIL" not in wpas.global_request("FST-ATTACH %s %s" % ("foofoo",
                                                                group)):
         raise Exception("FST-ATTACH for unknown interface accepted")
+
+def test_fst_session_initiate_errors(dev, apdev, test_params):
+    """FST SESSION_INITIATE error cases"""
+    try:
+        _test_fst_session_initiate_errors(dev, apdev, test_params)
+    finally:
+        subprocess.call(['iw', 'reg', 'set', '00'])
+        dev[0].flush_scan_cache()
+        dev[1].flush_scan_cache()
+
+def _test_fst_session_initiate_errors(dev, apdev, test_params):
+    group = "fstg0"
+    sgroup = "fstg1"
+    hglobal, wpas, wpas2, hapd, hapd2 = fst_start_and_connect(apdev, group, sgroup)
+
+    sid = wpas.global_request("FST-MANAGER SESSION_ADD " + sgroup).strip()
+    if "FAIL" in sid:
+        raise Exception("FST-MANAGER SESSION_ADD (STA) failed")
+
+    # No old peer MAC address
+    if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
+        raise Exception("Invalid FST-MANAGER SESSION_INITIATE accepted")
+
+    fst_session_set(wpas, sid, "old_peer_addr", "00:ff:ff:ff:ff:ff")
+    # No new peer MAC address
+    if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
+        raise Exception("Invalid FST-MANAGER SESSION_INITIATE accepted")
+
+    fst_session_set(wpas, sid, "new_peer_addr", "00:ff:ff:ff:ff:fe")
+    # No old interface defined
+    if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
+        raise Exception("Invalid FST-MANAGER SESSION_INITIATE accepted")
+
+    fst_session_set(wpas, sid, "old_ifname", wpas.ifname)
+    # No new interface defined
+    if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
+        raise Exception("Invalid FST-MANAGER SESSION_INITIATE accepted")
+
+    fst_session_set(wpas, sid, "new_ifname", wpas.ifname)
+    # Same interface set as old and new
+    if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
+        raise Exception("Invalid FST-MANAGER SESSION_INITIATE accepted")
+
+    fst_session_set(wpas, sid, "new_ifname", wpas2.ifname)
+    # The preset old peer address is not connected
+    if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
+        raise Exception("Invalid FST-MANAGER SESSION_INITIATE accepted")
+
+    fst_session_set(wpas, sid, "old_peer_addr", apdev[0]['bssid'])
+    # The preset new peer address is not connected
+    if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
+        raise Exception("Invalid FST-MANAGER SESSION_INITIATE accepted")
+
+    fst_session_set(wpas, sid, "new_peer_addr", apdev[1]['bssid'])
+    # Initiate session setup
+    if "OK" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
+        raise Exception("FST-MANAGER SESSION_INITIATE failed")
+
+    # Session in progress
+    if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
+        raise Exception("Duplicated FST-MANAGER SESSION_INITIATE accepted")
+
+    sid2 = wpas.global_request("FST-MANAGER SESSION_ADD " + sgroup).strip()
+    if "FAIL" in sid:
+        raise Exception("FST-MANAGER SESSION_ADD (STA) failed")
+    fst_session_set(wpas, sid2, "old_ifname", wpas.ifname)
+    fst_session_set(wpas, sid2, "old_peer_addr", apdev[0]['bssid'])
+    fst_session_set(wpas, sid2, "new_ifname", wpas2.ifname)
+    fst_session_set(wpas, sid2, "new_peer_addr", apdev[1]['bssid'])
+
+    # There is another session in progress (old)
+    if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid2):
+        raise Exception("Duplicated FST-MANAGER SESSION_INITIATE accepted")
+
+    if "OK" not in wpas.global_request("FST-MANAGER SESSION_REMOVE " + sid):
+        raise Exception("FST-MANAGER SESSION_REMOVE failed")
+
+    while True:
+        ev = hglobal.wait_event(['FST-EVENT-SESSION'], timeout=5)
+        if ev is None:
+            raise Exception("No FST-EVENT-SESSION (AP)")
+        if "new_state=SETUP_COMPLETION" in ev:
+            f = re.search("session_id=(\d+)", ev)
+            if f is None:
+                raise Exception("No session_id in FST-EVENT-SESSION")
+            sid_ap = f.group(1)
+            break
+    if "OK" not in hglobal.request("FST-MANAGER SESSION_REMOVE " + sid_ap):
+        raise Exception("FST-MANAGER SESSION_REMOVE (AP) failed")
+
+    if "OK" not in wpas.global_request("FST-MANAGER SESSION_REMOVE " + sid2):
+        raise Exception("FST-MANAGER SESSION_REMOVE failed")
+
+def test_fst_session_respond_errors(dev, apdev, test_params):
+    """FST SESSION_RESPOND error cases"""
+    try:
+        _test_fst_session_respond_errors(dev, apdev, test_params)
+    finally:
+        subprocess.call(['iw', 'reg', 'set', '00'])
+        dev[0].flush_scan_cache()
+        dev[1].flush_scan_cache()
+
+def _test_fst_session_respond_errors(dev, apdev, test_params):
+    group = "fstg0b"
+    sgroup = "fstg1b"
+    hglobal, wpas, wpas2, hapd, hapd2 = fst_start_and_connect(apdev, group, sgroup)
+
+    sid = wpas.global_request("FST-MANAGER SESSION_ADD " + sgroup).strip()
+    if "FAIL" in sid:
+        raise Exception("FST-MANAGER SESSION_ADD (STA) failed")
+
+    fst_session_set(wpas, sid, "old_ifname", wpas.ifname)
+    fst_session_set(wpas, sid, "old_peer_addr", apdev[0]['bssid'])
+    fst_session_set(wpas, sid, "new_ifname", wpas2.ifname)
+    fst_session_set(wpas, sid, "new_peer_addr", apdev[1]['bssid'])
+
+    if "OK" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
+        raise Exception("FST-MANAGER SESSION_INITIATE failed")
+
+    while True:
+        ev = hglobal.wait_event(['FST-EVENT-SESSION'], timeout=5)
+        if ev is None:
+            raise Exception("No FST-EVENT-SESSION (AP)")
+        if "new_state=SETUP_COMPLETION" in ev:
+            f = re.search("session_id=(\d+)", ev)
+            if f is None:
+                raise Exception("No session_id in FST-EVENT-SESSION")
+            sid_ap = f.group(1)
+            break
+
+    # The preset peer address is not in the peer list
+    fst_session_set_ap(hglobal, sid_ap, "old_peer_addr", "00:00:00:00:00:01")
+    cmd = "FST-MANAGER SESSION_RESPOND %s accept" % sid_ap
+    if "FAIL" not in hglobal.request(cmd):
+        raise Exception("Invalid FST-MANAGER SESSION_RESPOND accepted")
+
+    # Same interface set as old and new
+    fst_session_set_ap(hglobal, sid_ap, "old_peer_addr", wpas.own_addr())
+    fst_session_set_ap(hglobal, sid_ap, "old_ifname", apdev[1]['ifname'])
+    cmd = "FST-MANAGER SESSION_RESPOND %s accept" % sid_ap
+    if "FAIL" not in hglobal.request(cmd):
+        raise Exception("Invalid FST-MANAGER SESSION_RESPOND accepted")
+
+    # valid command
+    fst_session_set_ap(hglobal, sid_ap, "old_ifname", apdev[0]['ifname'])
+    cmd = "FST-MANAGER SESSION_RESPOND %s accept" % sid_ap
+    if "OK" not in hglobal.request(cmd):
+        raise Exception("FST-MANAGER SESSION_RESPOND failed")
+
+    # incorrect state
+    cmd = "FST-MANAGER SESSION_RESPOND %s accept" % sid_ap
+    if "FAIL" not in hglobal.request(cmd):
+        raise Exception("Invalid FST-MANAGER SESSION_RESPOND accepted")
+
+    cmd = "FST-MANAGER SESSION_REMOVE " + sid
+    if "OK" not in wpas.global_request(cmd):
+        raise Exception("FST-MANAGER SESSION_REMOVE (STA) failed")
+
+    cmd = "FST-MANAGER SESSION_REMOVE %s" % sid_ap
+    if "OK" not in hglobal.request(cmd):
+        raise Exception("FST-MANAGER SESSION_REMOVE (AP) failed")