Skip to contentSkip to conversation

wiphy: add beacon bits to RM Enabled Capabilities

PATCH Superseded James Prestwood 2 participants 6 messages Nov 6, 2019 Kbuild

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 wiphy: add beacon bits to RM Enabled Capabilities

This tells AP's that we support Passive, Active, and Table beacon measurements.

---
 src/wiphy.c | 2 ++
 1 file changed, 2 insertions(+)
src/wiphy.c +2 -0
index ef22c0d3..eb0dfcc9 100644
@@ -1037,6 +1037,8 @@ static void wiphy_setup_rm_enabled_capabilities(struct wiphy *wiphy)
 
 	wiphy->rm_enabled_capabilities[0] = IE_TYPE_RM_ENABLED_CAPABILITIES;
 	wiphy->rm_enabled_capabilities[1] = 5;
+	/* Bits: Passive (4), Active (5), and Beacon Table (6) capabilities */
+	wiphy->rm_enabled_capabilities[2] = 0x70;
 
 	/*
 	 * TODO: Support at least Link Measurement if TX_POWER_INSERTION is
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 2/3 rrm: add radio resource management module

This module takes care of radio measurements which an AP can request. There are many types of requests, and for now only beacon requests are supported.

IWD will filter certain types of beacon requests that are NOT supported:

- AP channel reports. Only single channel requests will be supported
- Autonomous measurements. Only direct requests will be supported. IWD will not accept requets to trigger reports under certain conditions (SNR/RSSI thresholds, etc.)
- Timed measurements. Only immediate measurements will be performed. The accuracy for timed measurements cannot be reliably guaranteed due to kernel scheduling/queues.
- Full reporting detail. The AP can request the STA return the full set of IEs in a beacon. IWD does not currently save all IEs, plus there is quite a bit of complexity involved as certain IEs get truncated, and there are other length limitations.

There are other limitations not specific to beacon requests:

- IWD will support single measurement requests per report. Multiple measurement request IEs can be included, but the reports will be sent out separately.

- IWD will limit the number of requests it responds to in a given amount of time. As it stands now this is hard coded to 2 requests per second maximum. This will prevent DoS attacks.

- IWD will not accept any measurement requests from APs it is not connected to, and will not accept any requests until connected.

---
 Makefile.am |   1 +
 src/rrm.c   | 786 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 787 insertions(+)
 create mode 100644 src/rrm.c

-v2:
* Added a per-netdev 'rrm_state'. This holds values such as ifindex wdev_id, connected address etc which will be used for all requests on a given netdev
* Watch station and disable/enable rrm_state depending on if we get connected or disconnected.
* Refactored rrm_request_info/rrm_beacon_req_info to avoid extra allocations (using l_container_of)
* rrm_state also holds 'pending' requests and will ignore any requests made when we have an outstanding request
* Track scan ID's and cancel if station becomes disconnected

Makefile.am +1 -0
index 9c54cef0..13141848 100644
@@ -226,6 +226,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \
 					src/hotspot.c \
 					src/p2putil.h src/p2putil.c \
 					src/module.c \
+					src/rrm.c \
 					$(eap_sources) \
 					$(builtin_sources)
 
src/rrm.c new file +786 -0

786 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v2 2/3] rrm: add radio resource management module

Hi James,

Quoted 49 lines · James Prestwood

This module takes care of radio measurements which an AP can request. There are many types of requests, and for now only beacon requests are supported.

IWD will filter certain types of beacon requests that are NOT supported:

- AP channel reports. Only single channel requests will be supported
- Autonomous measurements. Only direct requests will be supported. IWD will not accept requets to trigger reports under certain conditions (SNR/RSSI thresholds, etc.)
- Timed measurements. Only immediate measurements will be performed. The accuracy for timed measurements cannot be reliably guaranteed due to kernel scheduling/queues.
- Full reporting detail. The AP can request the STA return the full set of IEs in a beacon. IWD does not currently save all IEs, plus there is quite a bit of complexity involved as certain IEs get truncated, and there are other length limitations.

There are other limitations not specific to beacon requests:

- IWD will support single measurement requests per report. Multiple measurement request IEs can be included, but the reports will be sent out separately.

- IWD will limit the number of requests it responds to in a given amount of time. As it stands now this is hard coded to 2 requests per second maximum. This will prevent DoS attacks.

- IWD will not accept any measurement requests from APs it is not connected to, and will not accept any requests until connected.

---
  Makefile.am |   1 +
  src/rrm.c   | 786 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 787 insertions(+)

create mode 100644 src/rrm.c

-v2:
* Added a per-netdev 'rrm_state'. This holds values such as ifindex wdev_id, connected address etc which will be used for all requests on a given netdev
* Watch station and disable/enable rrm_state depending on if we get connected or disconnected.
* Refactored rrm_request_info/rrm_beacon_req_info to avoid extra allocations (using l_container_of)
* rrm_state also holds 'pending' requests and will ignore any requests made when we have an outstanding request
* Track scan ID's and cancel if station becomes disconnected

<snip>

Quoted 4 lines
src/rrm.c new file +4 -0
+static void rrm_station_watch_cb(enum station_state state, void *userdata)
+{
+	struct rrm_state *rrm = userdata;
+	struct station *station;

src/rrm.c line 686

Quoted 10 lines
src/rrm.c new file +10 -0
+	struct scan_bss *bss;
+
+	switch (state) {
+	case STATION_STATE_CONNECTED:
+		station = station_find(rrm->ifindex);
+		bss = station_get_connected_bss(station);
+
+		rrm->enabled = true;
+		memcpy(rrm->connected_addr, bss->addr, 6);
+		rrm->connected_freq = bss->frequency;

Why not just save the station pointer instead of carrying all this info?

src/rrm.c line 689

Quoted 3 lines
src/rrm.c new file +3 -0
+
+		break;
+	case STATION_STATE_DISCONNECTED:

Also for DISCONNECTING?

src/rrm.c line 692

Quoted 3 lines
src/rrm.c new file +3 -0
+		rrm->enabled = false;
+
+		rrm_cancel_pending(rrm);

All you really care about here is the cancelation logic.

Quoted 24 lines
src/rrm.c new file +24 -0
+		break;
+	default:
+		return;
+	}
+}
+
+static void rrm_state_destroy(void *data)
+{
+	struct rrm_state *rrm = data;
+
+	if (rrm->pending)
+		rrm_info_destroy(rrm->pending);
+
+	l_free(rrm);
+}
+
+static void rrm_new_state(struct netdev *netdev)
+{
+	struct rrm_state *rrm;
+	uint16_t frame_type = 0x00d0;
+	uint8_t prefix[] = { 0x05, 0x00 };
+	struct station *station;
+
+	rrm = l_new(struct rrm_state, 1);

src/rrm.c line 726

Quoted 10 lines
src/rrm.c new file +10 -0
+
+	rrm->last_request = l_time_now();
+	rrm->ifindex = netdev_get_ifindex(netdev);
+	rrm->wdev_id = netdev_get_wdev_id(netdev);
+
+	netdev_frame_watch_add(netdev, frame_type, prefix, sizeof(prefix),
+					rrm_frame_watch_cb, rrm);
+
+	station = station_find(rrm->ifindex);
+	station_add_state_watch(station, rrm_station_watch_cb, rrm, NULL);

Shouldn't you be checking that station exists first? Also, you have a bit of a chicken/egg problem since station is watching the same netdev_watch. So by luck of the draw it may be getting notified (and thus created) after the rrm module.

How we get around this is unclear. One way would be to check the iftype to be station and just assume that the station object comes around eventually. Perhaps by lazy-instantiating the station watch only once an actual request arrives.

Quoted 19 lines
src/rrm.c new file +19 -0
+
+	l_queue_push_head(states, rrm);
+}
+
+static bool match_ifindex(const void *a, const void *b)
+{
+	const struct rrm_state *rrm = a;
+	uint32_t ifindex = L_PTR_TO_UINT(b);
+
+	return rrm->ifindex == ifindex;
+}
+
+static void rrm_netdev_watch(struct netdev *netdev,
+				enum netdev_watch_event event, void *user_data)
+{
+	struct rrm_state *rrm;
+	uint32_t ifindex = netdev_get_ifindex(netdev);
+
+	switch (event) {

src/rrm.c line 755

Quoted 10 lines
src/rrm.c new file +10 -0
+	case NETDEV_WATCH_EVENT_NEW:
+		rrm_new_state(netdev);
+		return;
+	case NETDEV_WATCH_EVENT_DEL:
+		rrm = l_queue_find(states, match_ifindex,
+					L_UINT_TO_PTR(ifindex));
+		if (!rrm)
+			return;
+
+		rrm_cancel_pending(rrm);

Shouldn't you be freeing the rrm state?

Quoted 22 lines
src/rrm.c new file +21 -0
+		return;
+	default:
+		break;
+	}
+}
+
+static int rrm_init(void)
+{
+	struct l_genl *genl = iwd_get_genl();
+
+	states = l_queue_new();
+
+	nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
+
+	netdev_watch = netdev_watch_add(rrm_netdev_watch, NULL, NULL);
+
+	return 0;
+}
+
+static void rrm_exit(void)
+{

src/rrm.c line 786

Quoted 10 lines
src/rrm.c new file +10 -0
+	l_genl_family_free(nl80211);
+	nl80211 = NULL;
+
+	netdev_watch_remove(netdev_watch);
+
+	l_queue_destroy(states, rrm_state_destroy);
+}
+
+IWD_MODULE(rrm, rrm_init, rrm_exit);
+IWD_MODULE_DEPENDS(rrm, netdev);

Regards,
-Denis

#3 lore raw

Re: [PATCH v2 2/3] rrm: add radio resource management module

Hi Denis,

<snip>

Quoted 29 lines
Quoted 20 lines
src/rrm.c new file +15 -0
+
+static void rrm_new_state(struct netdev *netdev)
+{
+	struct rrm_state *rrm;
+	uint16_t frame_type = 0x00d0;
+	uint8_t prefix[] = { 0x05, 0x00 };
+	struct station *station;
+
+	rrm = l_new(struct rrm_state, 1);
+
+	rrm->last_request = l_time_now();
+	rrm->ifindex = netdev_get_ifindex(netdev);
+	rrm->wdev_id = netdev_get_wdev_id(netdev);
+
+	netdev_frame_watch_add(netdev, frame_type, prefix,

sizeof(prefix),

src/rrm.c new file +4 -0
+					rrm_frame_watch_cb, rrm);
+
+	station = station_find(rrm->ifindex);
+	station_add_state_watch(station, rrm_station_watch_cb, rrm,
Quoted 1 line

NULL);

Shouldn't you be checking that station exists first? Also, you have a
bit of a chicken/egg problem since station is watching the same netdev_watch. So by luck of the draw it may be getting notified (and
thus created) after the rrm module.

Quoted 6 lines

How we get around this is unclear. One way would be to check the iftype
to be station and just assume that the station object comes around eventually. Perhaps by lazy-instantiating the station watch only once
an actual request arrives.

What about adding a module depends on station? This would make RRM get initialized after station which should make the netdev watch call into station before RRM.

Quoted 71 lines
Quoted 20 lines
src/rrm.c new file +14 -0
+
+	l_queue_push_head(states, rrm);
+}
+
+static bool match_ifindex(const void *a, const void *b)
+{
+	const struct rrm_state *rrm = a;
+	uint32_t ifindex = L_PTR_TO_UINT(b);
+
+	return rrm->ifindex == ifindex;
+}
+
+static void rrm_netdev_watch(struct netdev *netdev,
+				enum netdev_watch_event event, void

*user_data)

src/rrm.c new file +5 -0
+{
+	struct rrm_state *rrm;
+	uint32_t ifindex = netdev_get_ifindex(netdev);
+
+	switch (event) {

src/rrm.c line 755

Quoted 10 lines
src/rrm.c new file +10 -0
+	case NETDEV_WATCH_EVENT_NEW:
+		rrm_new_state(netdev);
+		return;
+	case NETDEV_WATCH_EVENT_DEL:
+		rrm = l_queue_find(states, match_ifindex,
+					L_UINT_TO_PTR(ifindex));
+		if (!rrm)
+			return;
+
+		rrm_cancel_pending(rrm);

Shouldn't you be freeing the rrm state?

Quoted 22 lines
src/rrm.c new file +21 -0
+		return;
+	default:
+		break;
+	}
+}
+
+static int rrm_init(void)
+{
+	struct l_genl *genl = iwd_get_genl();
+
+	states = l_queue_new();
+
+	nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
+
+	netdev_watch = netdev_watch_add(rrm_netdev_watch, NULL, NULL);
+
+	return 0;
+}
+
+static void rrm_exit(void)
+{

src/rrm.c line 786

Quoted 10 lines
src/rrm.c new file +10 -0
+	l_genl_family_free(nl80211);
+	nl80211 = NULL;
+
+	netdev_watch_remove(netdev_watch);
+
+	l_queue_destroy(states, rrm_state_destroy);
+}
+
+IWD_MODULE(rrm, rrm_init, rrm_exit);
+IWD_MODULE_DEPENDS(rrm, netdev);

Regards,
-Denis
_______________________________________________
iwd mailing list -- iwd(a)lists.01.org
To unsubscribe send an email to iwd-leave(a)lists.01.org

#4 lore raw

Re: [PATCH v2 2/3] rrm: add radio resource management module

Hi James,

Quoted 14 lines
Quoted 7 lines

Shouldn't you be checking that station exists first? Also, you have a
bit of a chicken/egg problem since station is watching the same netdev_watch. So by luck of the draw it may be getting notified (and
thus created) after the rrm module.

Quoted 6 lines

How we get around this is unclear. One way would be to check the iftype
to be station and just assume that the station object comes around eventually. Perhaps by lazy-instantiating the station watch only once
an actual request arrives.

Quoted 4 lines

What about adding a module depends on station? This would make RRM get initialized after station which should make the netdev watch call into station before RRM.

Possible, though that seems to be really unobvious. And if someone changes watchlist to use push_head instead of push_tail, things start to break.

Also, this is not really a module-initialization order issue but what order does the watchlist get called issue. So it just seems like the wrong way to go.

Perhaps we need an explicit API for when an interface gets added, or just cheat and use delayed-init.

Regards,
-Denis

#5 lore raw

PATCH v2 3/3 auto-t: add RRM autotest

In reply to James Prestwood

This test merely verifies hostapd receieved our measurement reports and verified they were valid. Hostapd does not verify the actual beacon report body. Really, the only way to test this is on an actual network which makes these requests.

---
 autotests/testRRM/connection_test.py | 114 +++++++++++++++++++++++++++
 autotests/testRRM/hw.conf            |   8 ++
 autotests/testRRM/ssidOther.conf     |  10 +++
 autotests/testRRM/ssidRRM.conf       |  13 +++
 4 files changed, 145 insertions(+)
 create mode 100644 autotests/testRRM/connection_test.py
 create mode 100644 autotests/testRRM/hw.conf
 create mode 100644 autotests/testRRM/ssidOther.conf
 create mode 100644 autotests/testRRM/ssidRRM.conf
autotests/testRRM/connection_test.py new file +114 -0
new file mode 100644
index 00000000..93fd6cb8
@@ -0,0 +1,114 @@
+#!/usr/bin/python3
+
+import unittest
+import sys
+
+sys.path.append('../util')
+import iwd
+from iwd import IWD
+from iwd import PSKAgent
+from iwd import NetworkType
+from hostapd import HostapdCLI
+import testutil
+
+from time import sleep
+
+# Table beacon with wildcard BSSID
+basic_beacon = '51000000000002ffffffffffff020100'
+# Table beacon with wildcard BSSID and SSID filter
+beacon_with_ssid = '51000000000002ffffffffffff02010000077373696452524d'
+# Passive beacon with wildcard BSSID
+beacon_passive = '510b0000000000ffffffffffff020100'
+# Active beacon with wildcard BSSID
+beacon_active = '510b0000000001ffffffffffff020100'
+
+class Test(unittest.TestCase):
+
+    def test_connection_success(self):
+        hapd = HostapdCLI(config='ssidRRM.conf')
+        wd = IWD()
+
+        psk_agent = PSKAgent("secret123")
+        wd.register_psk_agent(psk_agent)
+
+        devices = wd.list_devices(1)
+        device = devices[0]
+
+        condition = 'not obj.scanning'
+        wd.wait_for_object_condition(device, condition)
+
+        device.scan()
+
+        condition = 'not obj.scanning'
+        wd.wait_for_object_condition(device, condition)
+
+        ordered_network = device.get_ordered_network('ssidRRM')
+
+        self.assertEqual(ordered_network.type, NetworkType.psk)
+
+        condition = 'not obj.connected'
+        wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+        ordered_network.network_object.connect()
+
+        condition = 'obj.connected'
+        wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+        testutil.test_iface_operstate()
+        testutil.test_ifaces_connected()
+
+        hapd.wait_for_event('AP-STA-CONNECTED')
+
+        # This should return both APs
+        hapd.req_beacon(device.address, basic_beacon)
+
+        for e in ['BEACON-RESP-RX', 'BEACON-RESP-RX']:
+            event = hapd.wait_for_event(e)
+            if event:
+                print(event)
+
+        sleep(0.5)
+
+        # This should return just ssidRRM
+        hapd.req_beacon(device.address, beacon_with_ssid)
+        event = hapd.wait_for_event('BEACON-RESP-RX')
+        if event:
+            print(event)
+
+        sleep(0.5)
+
+        # This should passive scan on channel 11, returning otherSSID
+        hapd.req_beacon(device.address, beacon_passive)
+        # TODO: See if we are scanning here (scan not initiated from station)
+
+        event = hapd.wait_for_event('BEACON-RESP-RX')
+        if event:
+            print(event)
+
+        sleep(0.5)
+
+        # This should active scan on channel 11, returning otherSSID
+        hapd.req_beacon(device.address, beacon_active)
+        # TODO: See if we are scanning here (scan not initiated from station)
+
+        event = hapd.wait_for_event('BEACON-RESP-RX')
+        if event:
+            print(event)
+
+        device.disconnect()
+
+        condition = 'not obj.connected'
+        wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+        wd.unregister_psk_agent(psk_agent)
+
+    @classmethod
+    def setUpClass(cls):
+        pass
+
+    @classmethod
+    def tearDownClass(cls):
+        IWD.clear_storage()
+
+if __name__ == '__main__':
+    unittest.main(exit=True)
autotests/testRRM/hw.conf new file +8 -0
new file mode 100644
index 00000000..91c757ce
@@ -0,0 +1,8 @@
+[SETUP]
+num_radios=3
+max_test_exec_interval_sec=40
+reg_domain=US
+
+[HOSTAPD]
+rad0=ssidRRM.conf
+rad1=ssidOther.conf
autotests/testRRM/ssidOther.conf new file +10 -0
new file mode 100644
index 00000000..e0f0fd40
@@ -0,0 +1,10 @@
+ctrl_interface=/var/run/hostapd
+
+hw_mode=g
+channel=11
+ssid=ssidOther
+
+wpa=2
+wpa_pairwise=CCMP
+wpa_passphrase=secret123
+rrm_beacon_report=1
autotests/testRRM/ssidRRM.conf new file +13 -0
new file mode 100644
index 00000000..233392f9
@@ -0,0 +1,13 @@
+ctrl_interface=/var/run/hostapd
+
+hw_mode=a
+ssid=ssidRRM
+
+wpa=2
+wpa_pairwise=CCMP
+wpa_passphrase=secret123
+rrm_beacon_report=1
+ht_capab=[HT40+]
+
+ieee80211n=1
+channel=36
Signature · 1 line
2.17.1