diff --git a/autotests/testKnownNetworks/frequency_test.py b/autotests/testKnownNetworks/frequency_test.py
index 83e51c06..4443d2a1 100644
--- a/autotests/testKnownNetworks/frequency_test.py
+++ b/autotests/testKnownNetworks/frequency_test.py
@@ -8,13 +8,21 @@ import iwd
 from iwd import IWD
 from iwd import PSKAgent
 from iwd import NetworkType
+from hostapd import HostapdCLI
+from hwsim import Hwsim
 import testutil
 import os
 from configparser import ConfigParser
+from dataclasses import dataclass
+
+@dataclass
+class KnownFreq:
+    uuid: str
+    freqs: list
 
 class Test(unittest.TestCase):
-    def connect_network(self, wd, device, network):
-        ordered_network = device.get_ordered_network(network)
+    def connect_network(self, wd, device, network, scan=False):
+        ordered_network = device.get_ordered_network(network, full_scan=scan)
 
         condition = 'not obj.connected'
         wd.wait_for_object_condition(ordered_network.network_object, condition)
@@ -29,7 +37,39 @@ class Test(unittest.TestCase):
         condition = 'not obj.connected'
         wd.wait_for_object_condition(ordered_network.network_object, condition)
 
+    def read_known_freqs(self):
+        ret = {}
+        config = ConfigParser()
+        config.read('/tmp/iwd/.known_network.freq')
+        for s in config.sections():
+            ret[os.path.basename(config[s]['name'])] = KnownFreq(s, config[s]['list'].split(' '))
+
+        return ret
+
     def test_connection_success(self):
+        hostapd_psks = [
+            HostapdCLI(config="ssidCCMP-2G-1.conf"),
+            HostapdCLI(config="ssidCCMP-2G-2.conf"),
+            HostapdCLI(config="ssidCCMP-5G.conf"),
+        ]
+
+        hwsim = Hwsim()
+
+        rule0 = hwsim.rules.create()
+        rule0.source = hostapd_psks[0].bssid
+        rule0.signal = -2000
+        rule0.enabled = True
+
+        rule1 = hwsim.rules.create()
+        rule1.source = hostapd_psks[1].bssid
+        rule1.signal = -5000
+        rule1.enabled = True
+
+        rule2 = hwsim.rules.create()
+        rule2.source = hostapd_psks[2].bssid
+        rule2.signal = -7000
+        rule2.enabled = True
+
         wd = IWD(True, '/tmp')
 
         psk_agent = PSKAgent("secret123")
@@ -42,8 +82,7 @@ class Test(unittest.TestCase):
         # Connect to the PSK network, then Hotspot so IWD creates 2 entries in
         # the known frequency file.
         #
-
-        self.connect_network(wd, device, 'ssidCCMP')
+        self.connect_network(wd, device, "ssidCCMP")
 
         wd.unregister_psk_agent(psk_agent)
 
@@ -57,30 +96,27 @@ class Test(unittest.TestCase):
         psk_freqs = None
         psk_uuid = None
         hs20_freqs = None
-        hs20_uuid = None
-        config = ConfigParser()
-        config.read('/tmp/iwd/.known_network.freq')
-        for s in config.sections():
-            if os.path.basename(config[s]['name']) == 'ssidCCMP.psk':
-                psk_freqs = config[s]['list']
-                psk_freqs = psk_freqs.split(' ')
-                psk_uuid = s
-            elif os.path.basename(config[s]['name']) == 'example.conf':
-                hs20_freqs = config[s]['list']
-                hs20_freqs = hs20_freqs.split(' ')
-                hs20_uuid = s
+
+        freqs = self.read_known_freqs()
+
+        psk_freqs = freqs['ssidCCMP.psk']
+        hs20_freqs = freqs['example.conf']
 
         #
         # Verify the frequencies are what we expect
         #
         self.assertIsNotNone(psk_freqs)
-        self.assertIsNotNone(psk_uuid)
-        self.assertIn('5180', psk_freqs)
-        self.assertIn('2412', psk_freqs)
+        self.assertIsNotNone(psk_freqs.uuid)
+        # Save to compare later
+        psk_uuid = psk_freqs.uuid
+        self.assertIn('5180', psk_freqs.freqs)
+        # First should be the connected network. The other two's order is
+        # unknown since its based on whenever the BSS was seen.
+        self.assertEqual(psk_freqs.freqs[0], '2412')
 
         self.assertIsNotNone(hs20_freqs)
-        self.assertIsNotNone(hs20_uuid)
-        self.assertIn('2412', hs20_freqs)
+        self.assertIsNotNone(hs20_freqs.uuid)
+        self.assertIn('2417', hs20_freqs.freqs)
 
         #
         # Forget all know networks, this should remove all entries in the
@@ -92,11 +128,15 @@ class Test(unittest.TestCase):
         psk_agent = PSKAgent("secret123")
         wd.register_psk_agent(psk_agent)
 
+        # Rank a different BSS higher
+        rule0.signal = -7000
+        rule1.signal = -2000
+
         #
         # Reconnect, this should generate a completely new UUID since we
         # previously forgot the network.
         #
-        self.connect_network(wd, device, 'ssidCCMP')
+        self.connect_network(wd, device, 'ssidCCMP', scan=True)
 
         wd.unregister_psk_agent(psk_agent)
 
@@ -107,21 +147,33 @@ class Test(unittest.TestCase):
         psk_freqs = None
         psk_uuid2 = None
         hs20_freqs = None
-        config = ConfigParser()
-        config.read('/tmp/iwd/.known_network.freq')
-        for s in config.sections():
-            self.assertNotEqual(os.path.basename(config[s]['name']),
-                                    'example.conf')
-            if os.path.basename(config[s]['name']) == 'ssidCCMP.psk':
-                psk_freqs = config[s]['list']
-                psk_freqs = psk_freqs.split(' ')
-                psk_uuid2 = s
+
+        freqs = self.read_known_freqs()
+
+        psk_freqs = freqs['ssidCCMP.psk']
 
         self.assertIsNotNone(psk_freqs)
-        self.assertIsNotNone(psk_uuid2)
-        self.assertNotEqual(psk_uuid, psk_uuid2)
-        self.assertIn('5180', psk_freqs)
-        self.assertIn('2412', psk_freqs)
+        self.assertIsNotNone(psk_freqs.uuid)
+        self.assertNotEqual(psk_uuid2, psk_freqs.uuid)
+        self.assertIn('5180', psk_freqs.freqs)
+        # The 2417 frequency BSS should be first
+        self.assertEqual(psk_freqs.freqs[0], '2417')
+
+        # Rank the 5G BSS highest
+        rule0.signal = -7000
+        rule1.signal = -7000
+        rule2.signal = -2000
+
+        print("CONNECTING AGAGIn")
+        self.connect_network(wd, device, 'ssidCCMP', scan=True)
+
+        freqs = self.read_known_freqs()
+
+        psk_freqs = freqs['ssidCCMP.psk']
+
+        # The 5180 frequency BSS should now be first, followed by 2417
+        self.assertEqual(psk_freqs.freqs[0], '5180')
+        self.assertEqual(psk_freqs.freqs[1], '2417')
 
     @classmethod
     def setUpClass(cls):
diff --git a/autotests/testKnownNetworks/hw.conf b/autotests/testKnownNetworks/hw.conf
index 8a7ef73a..9fb3dbd5 100644
--- a/autotests/testKnownNetworks/hw.conf
+++ b/autotests/testKnownNetworks/hw.conf
@@ -1,10 +1,12 @@
 [SETUP]
-num_radios=5
+num_radios=6
 start_iwd=0
 reg_domain=US
+hwsim_medium=true
 
 [HOSTAPD]
 rad0=ssidNew.conf
-rad1=ssidCCMP-2G.conf
-rad2=ssidCCMP-5G.conf
-rad3=ssidHotspot.conf
+rad1=ssidCCMP-2G-1.conf
+rad2=ssidCCMP-2G-2.conf
+rad3=ssidCCMP-5G.conf
+rad4=ssidHotspot.conf
diff --git a/autotests/testKnownNetworks/ssidCCMP-2G.conf b/autotests/testKnownNetworks/ssidCCMP-2G-1.conf
similarity index 100%
rename from autotests/testKnownNetworks/ssidCCMP-2G.conf
rename to autotests/testKnownNetworks/ssidCCMP-2G-1.conf
diff --git a/autotests/testKnownNetworks/ssidCCMP-2G-2.conf b/autotests/testKnownNetworks/ssidCCMP-2G-2.conf
new file mode 100644
index 00000000..0d806fde
--- /dev/null
+++ b/autotests/testKnownNetworks/ssidCCMP-2G-2.conf
@@ -0,0 +1,8 @@
+hw_mode=g
+channel=2
+ssid=ssidCCMP
+
+wpa=2
+wpa_pairwise=CCMP
+wpa_passphrase=secret123
+beacon_int=10
diff --git a/autotests/testKnownNetworks/ssidHotspot.conf b/autotests/testKnownNetworks/ssidHotspot.conf
index 95170c84..35b31fbe 100644
--- a/autotests/testKnownNetworks/ssidHotspot.conf
+++ b/autotests/testKnownNetworks/ssidHotspot.conf
@@ -1,6 +1,6 @@
 #ctrl_interface=/var/run/hostapd
 hw_mode=g
-channel=1
+channel=2
 wpa=2
 ssid=Hotspot
 rsn_pairwise=CCMP
