wiphy: add beacon bits to RM Enabled Capabilities
PATCH v3 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
@@ -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
PATCH v3 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 | 814 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 815 insertions(+) create mode 100644 src/rrm.c
-v3:
* Store station object inside rrm_state rather than using station_find in several places (also avoids needing to save connected_{addr,freq}
* Check that station exists when initializing rrm_state. If station is not found we can initialized when a request comes in.
Makefile.am +1 -0
@@ -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 +814 -0
814 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v3 2/3] rrm: add radio resource management module
Hi James,
src/rrm.c line 610
Quoted 7 lines
src/rrm.c new file +7
-0+static void rrm_station_watch_cb (enum station_state state,void *userdata) +{ +struct rrm_state *rrm = userdata; + +switch (state) { +case STATION_STATE_CONNECTED : + rrm->enabled = true;
Can't you use station_get_state instead?
Quoted 130 lines
src/rrm.c new file +130
-0+ +break ; +case STATION_STATE_DISCONNECTING : +case STATION_STATE_DISCONNECTED : + rrm->enabled = false; + +rrm_cancel_pending (rrm); +break ; +default : +return ; + } +} + +static void rrm_frame_watch_cb (struct netdev *netdev, +const struct mmpdu_header *mpdu, +const void *body,size_t body_len, +void *user_data) +{ +struct rrm_state *rrm = user_data; +const uint8_t *request = body; +uint8_t dialog_token; +struct ie_tlv_iter iter; +struct scan_bss *bss; + +if (!rrm->station) { +/* +* Just in case the station interface was not found during init +* we can try and find it here. If found, we also setup the +* station watch and set the correct enabled state. +*/ + rrm->station =station_find (rrm->ifindex); + +if (!rrm->station) { +l_error ("station interface could not be found" ); +return ; + } + +station_add_state_watch (rrm->station, rrm_station_watch_cb, + rrm,NULL ); + +if (station_get_state (rrm->station) ==STATION_STATE_CONNECTED ) + rrm->enabled = true; + } + +/* +* Ignore if not connected or already have an outstanding request +*/ +if (!rrm->enabled || rrm->pending) +return ; + + bss =station_get_connected_bss (rrm->station); + +if (memcmp (bss->addr, mpdu->address_2,6 )) +return ; + +if (body_len <5 ) +return ; + +if (request[0 ] !=0x05 ) +return ; + +if (request[1 ] !=0x00 ) +return ; + +/* +* We have reached our max requests per second, no point in continuing +*/ +if (l_time_now () - rrm->last_request <MIN_MICROS_BETWEEN_REQUESTS ) { +l_debug ("Max requests per second reached, ignoring request" ); +return ; + } + + dialog_token = request[2 ]; + +/* Update time regardless of success */ + rrm->last_request =l_time_now (); + +ie_tlv_iter_init (&iter, request +5 , body_len -5 ); + +while (ie_tlv_iter_next (&iter)) { +const uint8_t *req; +size_t req_len; + +if (ie_tlv_iter_get_tag (&iter) !=IE_TYPE_MEASUREMENT_REQUEST ) +continue ; + + req =ie_tlv_iter_get_data (&iter); + req_len =ie_tlv_iter_get_length (&iter); + +if (req_len <3 ) +return ; + +switch (req[2 ]) { +case 5 :/* beacon */ +rrm_handle_beacon_request (rrm, dialog_token, req, + req_len); +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 }; + +if (netdev_get_iftype (netdev) !=NETDEV_IFTYPE_STATION ) +return ; + + 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), + rrm_frame_watch_cb, rrm);
src/rrm.c line 750
Quoted 10 lines
src/rrm.c new file +10
-0+ + rrm->station =station_find (rrm->ifindex); + +/* +* Station may not exist yet, if not we can try and initialize this +* once the first request comes in. +*/ +if (rrm->station) +station_add_state_watch (rrm->station, rrm_station_watch_cb, + rrm,NULL );
This seems rather superfluous. Why make your job and code harder? :)
Quoted 21 lines
src/rrm.c new file +21
-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) { +case NETDEV_WATCH_EVENT_NEW : +rrm_new_state (netdev);
src/rrm.c line 781
Quoted 10 lines
src/rrm.c new file +10
-0+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); + +l_queue_remove (states, rrm);
Please do not ever do this. l_queue_find and l_queue_remove in succession are just waste. This should really be:
rrm = l_queue_remove_if...
if (rrm) {
rrm_cancel
rrm_state_destroy
}
src/rrm.c line 788
Quoted 7 lines
src/rrm.c new file +7
-0+rrm_state_destroy (rrm); + +return ; +default : +break ; + } +}
Regards,
-Denis
PATCH v3 3/3 auto-t: add RRM autotest
In reply to James PrestwoodThis 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
@@ -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
@@ -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
@@ -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
@@ -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