ie: add ie_parse_oci
James Prestwood
PATCH v2 1/8 ie: add ie_parse_oci
This is a very minimal parser, more or less to put the type and length checks into a single location.
--- src/ie.c | 20 ++++++++++++++++++++ src/ie.h | 2 ++ 2 files changed, 22 insertions(+)
src/ie.c +20 -0
@@ -2552,3 +2552,23 @@ int ie_parse_owe_transition(const void *data, size_t len,return 0 ; } + +int ie_parse_oci (const void *data,size_t len,const uint8_t **oci) +{ +struct ie_tlv_iter iter; + +ie_tlv_iter_init (&iter, data, len); + +if (!ie_tlv_iter_next (&iter)) +return -EMSGSIZE ; + +if (ie_tlv_iter_get_length (&iter) !=3 ) +return -EMSGSIZE ; + +if (ie_tlv_iter_get_tag (&iter) !=IE_TYPE_OCI ) +return -EPROTOTYPE ; + + *oci =ie_tlv_iter_get_data (&iter); + +return 0 ; +}
src/ie.h +2 -0
@@ -645,3 +645,5 @@ int ie_parse_network_cost(const void *data, size_t len,int ie_parse_owe_transition (const void *data,size_t len,struct ie_owe_transition_info *info); + +int ie_parse_oci (const void *data,size_t len,const uint8_t **oci);
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 2/8 netdev: add OCI elements to SA Query request/response frames
SA query is the final protocol that requires OCI inclusion and verification. The OCI element is now included and verified in both request and response frames as required by 802.11.
--- src/netdev.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 115 insertions(+), 12 deletions(-)
src/netdev.c +115 -12
@@ -4863,13 +4863,26 @@ static void netdev_sa_query_resp_cb(struct l_genl_msg *msg, void *user_data) ext_error ? ext_error : strerror(-err)); } +static int netdev_build_oci (struct netdev *netdev,uint8_t *out) +{ + out[0 ] =IE_TYPE_EXTENSION ; + out[1 ] =4 ; + out[2 ] =IE_TYPE_OCI &0xff ; + +return oci_from_chandef (netdev->handshake->chandef, out +3 ); +} +static void netdev_sa_query_req_frame_event (const struct mmpdu_header *hdr,const void *body,size_t body_len,int rssi,void *user_data) { -uint8_t sa_resp[4 ]; +uint8_t sa_resp[10 ]; +uint8_t *ptr = sa_resp;uint16_t transaction; +const uint8_t *oci;struct netdev *netdev = user_data; +bool ocvc = netdev->handshake->supplicant_ocvc && + netdev->handshake->authenticator_ocvc;if (body_len <4 ) {l_debug ("SA Query request too short" );
@@ -4885,15 +4898,57 @@ static void netdev_sa_query_req_frame_event(const struct mmpdu_header *hdr, transaction =l_get_u16 (body +2 ); - sa_resp[0 ] =0x08 ;/* SA Query */ - sa_resp[1 ] =0x01 ;/* Response */ -memcpy (sa_resp +2 , &transaction,2 ); + body_len -=4 ; + +if (ocvc) { +/* +* IEEE 802.11 Section 11.13 +* +* "A STA that supports the SA Query procedure and receives an +* SA Query Request frame shall respond with an SA Query +* Response frame if none of the following are true... +* - OCI element is not present in the request or +* - Operating channel information indicated does not match the +* current channel information (see 12.2.9)." +*/ +if (ie_parse_oci (body +4 , body_len, &oci) <0 ) { +l_debug ("Could not parse OCI" ); +return ; + } + +if (oci_verify (oci, netdev->handshake->chandef) <0 ) { +l_debug ("Could not verify OCI" ); +return ; + } + } + + ptr[0 ] =0x08 ;/* SA Query */ + ptr[1 ] =0x01 ;/* Response */ +memcpy (ptr +2 , &transaction,2 ); + + ptr +=4 ; + +/* +* IEEE 802.11 Section 11.13 +* +* "A STA that responds with an SA Query Response frame to a STA that +* indicated OCVC capability shall include OCI element in the response +* frame if dot11RSNAOperatingChannelValidationActivated is true" +*/ +if (ocvc) { +if (netdev_build_oci (netdev, ptr) <0 ) { +l_debug ("Could not build OCI" ); +return ; + } + + ptr +=6 ; + }l_info ("received SA Query request from " MAC ", transaction=%u" ,MAC_STR (hdr->address_2), transaction);if (!netdev_send_action_frame (netdev, netdev->handshake->aa, - sa_resp,sizeof (sa_resp), + sa_resp, ptr - sa_resp, netdev->frequency, netdev_sa_query_resp_cb, netdev)) {l_error ("error sending SA Query response" );
@@ -4906,15 +4961,22 @@ static void netdev_sa_query_resp_frame_event(const struct mmpdu_header *hdr, int rssi, void *user_data) { struct netdev *netdev = user_data; +const uint8_t *ptr = body; +const uint8_t *oci; + +if (!netdev->connected) +return ;if (body_len <4 ) {l_debug ("SA Query frame too short" );return ; } + ptr +=2 ; +l_debug ("SA Query src=" MAC " dest=" MAC " bssid=" MAC " transaction=%u" ,MAC_STR (hdr->address_2),MAC_STR (hdr->address_1), -MAC_STR (hdr->address_3),l_get_u16 (body +2 )); +MAC_STR (hdr->address_3),l_get_u16 (ptr));if (!netdev->sa_query_timeout) {l_debug ("no SA Query request sent" );
@@ -4927,11 +4989,39 @@ static void netdev_sa_query_resp_frame_event(const struct mmpdu_header *hdr,return ; } -if (memcmp (body +2 , &netdev->sa_query_id,2 )) { +if (memcmp (ptr, &netdev->sa_query_id,2 )) {l_debug ("SA Query transaction ID's did not match" );return ; } +if (!(netdev->handshake->supplicant_ocvc && + netdev->handshake->authenticator_ocvc)) + goto keep_alive; + + ptr +=2 ; + body_len -=4 ; + +/* +* IEEE 802.11 Section 11.13 +* +* "When a non-AP or non-PCP STA receives the SA Query Response frame +* from a STA that indicated OCVC capability, it shall ensure that OCI +* element is present in the response and the channel information in the +* OCI element matches current operating channel parameters +* (see 12.2.9). Otherwise, the receiving STA shall deem the response +* as invalid and discard it" +*/ +if (ie_parse_oci (ptr, body_len, &oci) <0 ) { +l_debug ("Invalid OCI element" ); +return ; + } + +if (oci_verify (oci, netdev->handshake->chandef) <0 ) { +l_debug ("Could not verify OCI element" ); +return ; + } + +keep_alive:l_info ("SA Query response from connected BSS received, " "keeping the connection active" );
@@ -4981,7 +5071,8 @@ static void netdev_unprot_disconnect_event(struct l_genl_msg *msg,uint16_t type;uint16_t len;const void *data; -uint8_t action_frame[4 ]; +uint8_t action_frame[10 ]; +uint8_t *ptr = action_frame;uint8_t reason_code;if (!netdev->connected)
@@ -5025,14 +5116,26 @@ static void netdev_unprot_disconnect_event(struct l_genl_msg *msg,return ; } - action_frame[0 ] =0x08 ;/* Category: SA Query */ - action_frame[1 ] =0x00 ;/* SA Query Action: Request */ + ptr[0 ] =0x08 ;/* Category: SA Query */ + ptr[1 ] =0x00 ;/* SA Query Action: Request */ /* Transaction ID */ -l_getrandom (action_frame +2 ,2 ); +l_getrandom (ptr +2 ,2 ); + + ptr +=4 ; + +if (netdev->handshake->supplicant_ocvc && + netdev->handshake->authenticator_ocvc) { +if (netdev_build_oci (netdev, ptr) <0 ) { +l_debug ("Could not build OCI" ); +return ; + } + + ptr +=6 ; + }if (!netdev_send_action_frame (netdev, netdev->handshake->aa, - action_frame,sizeof (action_frame), + action_frame, ptr - action_frame, netdev->frequency, netdev_sa_query_req_cb, netdev)) {l_error ("error sending SA Query action frame" );
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 3/8 auto-t: SAQuery-spoofing replace sleep with condition wait
In reply to James PrestwoodBy sleeping for 4 seconds IWD had plenty of time to fully disconnect and reconnect in time to pass the final "connected" check. Instead use wait_for_object_condition to wait for disconnected and expect this to fail. This will let the test fail if IWD disconnects.
--- autotests/testSAQuery-spoofing/connection_test.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
autotests/testSAQuery-spoofing/connection_test.py +4 -2
@@ -51,8 +51,10 @@ class Test(unittest.TestCase): # Spoof a disassociate frame. This will kick off SA Query procedure. hwsim.spoof_disassociate(radio, hostapd.frequency, device.address) - # sleep to ensure hostapd responds and SA Query does not timeout - sleep(4) + # ensure hostapd responds and SA Query does not timeout + with self.assertRaises(TimeoutError): + condition = 'obj.state == DeviceState.disconnected' + wd.wait_for_object_condition(device, condition, 4) # Since disassociate was spoofed we should still be connected condition = 'obj.state == DeviceState.connected'
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 4/8 auto-t: add OCV to testSAQuery-spoofing
In reply to James Prestwood--- autotests/testSAQuery-spoofing/ssidCCMP.conf | 1 + 1 file changed, 1 insertion(+)
autotests/testSAQuery-spoofing/ssidCCMP.conf +1 -0
@@ -9,3 +9,4 @@ wpa_passphrase=secret123 ieee80211w=2 wpa_key_mgmt=WPA-PSK-SHA256 beacon_int=10 +ocv=1
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 5/8 nl80211cmd: make CH_SWITCH_STARTED_NOTIFY name unique
In reply to James PrestwoodThere are several events for channel switching, and nl80211cmd was naming two of them "Channel Switch Notify". Change CH_SWITCH_STARTED_NOTIFY to "Channel Switch Started Notify" to distinguish the two events.
--- src/nl80211cmd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
src/nl80211cmd.c +2 -1
@@ -142,7 +142,8 @@ static const struct { { NL80211_CMD_GET_MPP, "Get Mesh Proxy Path" }, { NL80211_CMD_JOIN_OCB, "Join OCB Network" }, { NL80211_CMD_LEAVE_OCB, "Leave OCB Network" }, - { NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, "Channel Switch Notify" }, + { NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, + "Channel Switch Started Notify"}, { NL80211_CMD_TDLS_CHANNEL_SWITCH, "TDLS Channel Switch" }, { NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, "Cancel TLDS Channel Switch" },
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 6/8 netdev: start SA Query on channel switch event
In reply to James Prestwood802.11 requires an STA initiate the SA Query procedure on channel switch events. This patch refactors sending the SA Query into its own routine and starts the procedure when the channel switch event comes in.
In addition the OCI needs to be verified, so the channel info is parsed and set into the handshakes chandef.
--- src/netdev.c | 171 +++++++++++++++++++++++++-------------------------- 1 file changed, 83 insertions(+), 88 deletions(-)
src/netdev.c +83 -88
@@ -4872,6 +4872,77 @@ static int netdev_build_oci(struct netdev *netdev, uint8_t *out)return oci_from_chandef (netdev->handshake->chandef, out +3 ); } +static void netdev_sa_query_timeout (struct l_timeout *timeout, +void *user_data) +{ +struct netdev *netdev = user_data; +struct l_genl_msg *msg; + +l_info ("SA Query timed out, connection is invalid. Disconnecting..." ); + +l_timeout_remove (netdev->sa_query_timeout); + netdev->sa_query_timeout =NULL ; + + msg =netdev_build_cmd_disconnect (netdev, +MMPDU_REASON_CODE_PREV_AUTH_NOT_VALID ); + netdev->disconnect_cmd_id =l_genl_family_send (nl80211, msg, + netdev_disconnect_cb, netdev,NULL ); +} + +static void netdev_sa_query_req_cb (struct l_genl_msg *msg,void *user_data) +{ +struct netdev *netdev = user_data; +int err =l_genl_msg_get_error (msg); +const char *ext_error; + +if (err >=0 ) +return ; + + ext_error =l_genl_msg_get_extended_error (msg); +l_debug ("error sending SA Query request: %s" , + ext_error ? ext_error :strerror (-err)); + +l_timeout_remove (netdev->sa_query_timeout); + netdev->sa_query_timeout =NULL ; +} + +static bool netdev_send_sa_query_request (struct netdev *netdev) +{ +uint8_t req[10 ]; +uint8_t *ptr = req; + + ptr[0 ] =0x08 ;/* Category: SA Query */ + ptr[1 ] =0x00 ;/* SA Query Action: Request */ + +/* Transaction ID */ +l_getrandom (ptr +2 ,2 ); + + ptr +=4 ; + +if (netdev->handshake->supplicant_ocvc && + netdev->handshake->authenticator_ocvc) { +if (netdev_build_oci (netdev, ptr) <0 ) { +l_debug ("Could not build OCI" ); +return false; + } + + ptr +=6 ; + } + +if (!netdev_send_action_frame (netdev, netdev->handshake->aa, req, + ptr - req, netdev->frequency, + netdev_sa_query_req_cb, netdev)) { +l_error ("error sending SA Query action frame" ); +return false; + } + + netdev->sa_query_id =l_get_u16 (req +2 ); + netdev->sa_query_timeout =l_timeout_create (3 , + netdev_sa_query_timeout, netdev,NULL ); + +return true; +} +static void netdev_sa_query_req_frame_event (const struct mmpdu_header *hdr,const void *body,size_t body_len,int rssi,void *user_data)
@@ -5029,40 +5100,6 @@ keep_alive: netdev->sa_query_timeout =NULL ; } -static void netdev_sa_query_req_cb (struct l_genl_msg *msg,void *user_data) -{ -struct netdev *netdev = user_data; -int err =l_genl_msg_get_error (msg); -const char *ext_error; - -if (err >=0 ) -return ; - - ext_error =l_genl_msg_get_extended_error (msg); -l_debug ("error sending SA Query request: %s" , - ext_error ? ext_error :strerror (-err)); - -l_timeout_remove (netdev->sa_query_timeout); - netdev->sa_query_timeout =NULL ; -} - -static void netdev_sa_query_timeout (struct l_timeout *timeout, -void *user_data) -{ -struct netdev *netdev = user_data; -struct l_genl_msg *msg; - -l_info ("SA Query timed out, connection is invalid. Disconnecting..." ); - -l_timeout_remove (netdev->sa_query_timeout); - netdev->sa_query_timeout =NULL ; - - msg =netdev_build_cmd_disconnect (netdev, -MMPDU_REASON_CODE_PREV_AUTH_NOT_VALID ); - netdev->disconnect_cmd_id =l_genl_family_send (nl80211, msg, - netdev_disconnect_cb, netdev,NULL ); -} -static void netdev_unprot_disconnect_event (struct l_genl_msg *msg,struct netdev *netdev) {
@@ -5071,8 +5108,6 @@ static void netdev_unprot_disconnect_event(struct l_genl_msg *msg,uint16_t type;uint16_t len;const void *data; -uint8_t action_frame[10 ]; -uint8_t *ptr = action_frame;uint8_t reason_code;if (!netdev->connected)
@@ -5116,35 +5151,7 @@ static void netdev_unprot_disconnect_event(struct l_genl_msg *msg,return ; } - ptr[0 ] =0x08 ;/* Category: SA Query */ - ptr[1 ] =0x00 ;/* SA Query Action: Request */ - -/* Transaction ID */ -l_getrandom (ptr +2 ,2 ); - - ptr +=4 ; - -if (netdev->handshake->supplicant_ocvc && - netdev->handshake->authenticator_ocvc) { -if (netdev_build_oci (netdev, ptr) <0 ) { -l_debug ("Could not build OCI" ); -return ; - } - - ptr +=6 ; - } - -if (!netdev_send_action_frame (netdev, netdev->handshake->aa, - action_frame, ptr - action_frame, - netdev->frequency, - netdev_sa_query_req_cb, netdev)) { -l_error ("error sending SA Query action frame" ); -return ; - } - - netdev->sa_query_id =l_get_u16 (action_frame +2 ); - netdev->sa_query_timeout =l_timeout_create (3 , - netdev_sa_query_timeout, netdev,NULL ); +netdev_send_sa_query_request (netdev); } static void netdev_station_event(struct l_genl_msg *msg,
@@ -5345,39 +5352,27 @@ failed:static void netdev_channel_switch_event (struct l_genl_msg *msg,struct netdev *netdev) { -struct l_genl_attr attr; -uint16_t type, len; -const void *data; -uint32_t *freq =NULL ; - -l_debug ("" ); + _auto_(l_free) struct band_chandef *chandef = + l_new(struct band_chandef, 1); -if (!l_genl_attr_init (&attr, msg)) +if (nl80211_parse_chandef (msg, chandef) <0 ) { +l_debug ("Couldn't parse operating channel info." );return ; - -while (l_genl_attr_next (&attr, &type, &len, &data)) { -switch (type) { -case NL80211_ATTR_WIPHY_FREQ : -if (len !=4 ) -continue ; - - freq = (uint32_t *) data; -break ; - } } -if (!freq) -return ; + netdev->frequency = chandef->frequency; + +l_debug ("Channel switch event, frequency: %u" , netdev->frequency); -l_debug ("Channel switch event, frequency: %u" , *freq); +handshake_state_set_chandef (netdev->handshake,l_steal_ptr (chandef)); - netdev->frequency = *freq; +netdev_send_sa_query_request (netdev);if (!netdev->event_filter)return ; - netdev->event_filter (netdev,NETDEV_EVENT_CHANNEL_SWITCHED , freq, - netdev->user_data); + netdev->event_filter (netdev,NETDEV_EVENT_CHANNEL_SWITCHED , + &netdev->frequency, netdev->user_data); }static void netdev_mlme_notify (struct l_genl_msg *msg,void *user_data)
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 7/8 auto-t: hostapd.py: add chan_switch()
In reply to James PrestwoodForces hostapd to channel switch
--- autotests/util/hostapd.py | 8 ++++++++ 1 file changed, 8 insertions(+)
autotests/util/hostapd.py +8 -0
@@ -216,6 +216,14 @@ class HostapdCLI(object): cmd = 'RESEND_M3 %s' % address self.ctrl_sock.sendall(cmd.encode('utf-8')) + def chan_switch(self, channel): + if channel > len(chan_freq_map): + raise Exception("Only 2.4GHz channels supported for chan_switch") + + cmd = self.cmdline + ['chan_switch', '50', str(chan_freq_map[channel])] + ctx.start_process(cmd).wait() + self.wait_for_event('AP-CSA-FINISHED') + @property def bssid(self): cmd = self.cmdline + ['status']
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 8/8 auto-t: Add channel switch test
In reply to James Prestwood--- .../testChannelSwitch/connection_test.py | 65 +++++++++++++++++++ autotests/testChannelSwitch/hw.conf | 5 ++ autotests/testChannelSwitch/ssidCCMP.conf | 7 ++ 3 files changed, 77 insertions(+) create mode 100644 autotests/testChannelSwitch/connection_test.py create mode 100644 autotests/testChannelSwitch/hw.conf create mode 100644 autotests/testChannelSwitch/ssidCCMP.conf
autotests/testChannelSwitch/connection_test.py new file +65 -0
@@ -0,0 +1,65 @@ +#!/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 + +class Test(unittest.TestCase): + + def test_connection_success(self): + hapd = HostapdCLI() + wd = IWD() + + psk_agent = PSKAgent("secret123") + wd.register_psk_agent(psk_agent) + + devices = wd.list_devices(1) + device = devices[0] + + ordered_network = device.get_ordered_network('ssidCCMP') + + 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.state == DeviceState.connected' + wd.wait_for_object_condition(device, condition) + + testutil.test_iface_operstate() + testutil.test_ifaces_connected() + + hapd.chan_switch(2) + + condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_condition(device, condition) + + testutil.test_iface_operstate() + testutil.test_ifaces_connected() + + 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/testChannelSwitch/hw.conf new file +5 -0
@@ -0,0 +1,5 @@ +[SETUP] +num_radios=2 + +[HOSTAPD] +rad0=ssidCCMP.conf
autotests/testChannelSwitch/ssidCCMP.conf new file +7 -0
@@ -0,0 +1,7 @@ +hw_mode=g +channel=1 +ssid=ssidCCMP + +wpa=2 +wpa_pairwise=CCMP +wpa_passphrase=secret123
Signature · 1 line
2.31.1
Denis Kenzior
Hi James,
Quoted 7 lines · James Prestwood
This is a very minimal parser, more or less to put the type and length checks into a single location.
--- src/ie.c | 20 ++++++++++++++++++++ src/ie.h | 2 ++ 2 files changed, 22 insertions(+)
All applied, thanks.
Regards,
-Denis