dpp: don't allocate transient ssid strings
James Prestwood
PATCH 1/5 dpp: don't allocate transient ssid strings
These can be kept on the stack and avoid the need for allocated memory and unneeded auto-free functionality.
--- src/dpp.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
src/dpp.c +2 -3
@@ -400,7 +400,7 @@ static void send_config_result(struct dpp_sm *dpp, const uint8_t *to)static void dpp_write_config (struct dpp_configuration *config,struct network *network) { - _auto_(l_free) char *ssid = l_malloc(config->ssid_len + 1); +char ssid[33 ]; _auto_(l_settings_free) struct l_settings *settings = l_settings_new(); _auto_(l_free) char *path; _auto_(l_free) uint8_t *psk = NULL;
@@ -494,7 +494,7 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame,struct station *station =station_find (netdev_get_ifindex (dpp->netdev));struct network *network;struct scan_bss *bss =NULL ; - _auto_(l_free) char *ssid = NULL; +char ssid[33 ];if (dpp->state !=DPP_STATE_CONFIGURING )return ;
@@ -618,7 +618,6 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame,return ; } - ssid =l_malloc (config->ssid_len +1 );memcpy (ssid, config->ssid, config->ssid_len); ssid[config->ssid_len] ='\0' ;
Signature · 1 line
2.31.1
James Prestwood
PATCH 2/5 dpp: don't allow StartEnrollee while connected
While connected the driver ends up choosing quite small ROC durations leading to excessive calls to ROC. This also will negatively effect any wireless performance for the current network and possibly lead to missed DPP frames.
--- src/dpp.c | 6 ++++++ 1 file changed, 6 insertions(+)
src/dpp.c +6 -0
@@ -1638,10 +1638,16 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,struct dpp_sm *dpp = user_data;uint32_t freq =band_channel_to_freq (6 ,BAND_FREQ_2_4_GHZ );struct l_dbus_message *reply; +struct station *station =station_find (netdev_get_ifindex (dpp->netdev));if (dpp->state !=DPP_STATE_NOTHING )return dbus_error_busy (message); +if (!station ||station_get_connected_network (station)) { +l_warn ("cannot be enrollee while connected, please disconnect" ); +return dbus_error_busy (message); + } + dpp->uri =dpp_generate_uri (dpp->pub_asn1, dpp->pub_asn1_len,2 ,netdev_get_address (dpp->netdev), &freq,1 ,NULL ,NULL );
Signature · 1 line
2.31.1
James Prestwood
PATCH 3/5 dpp: move r_auth into dpp_sm
In reply to James PrestwoodIn order to support channel switching during authentication r_auth needs to be held onto in dpp_sm for after the ROC call starts.
--- src/dpp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
src/dpp.c +5 -5
@@ -102,6 +102,7 @@ struct dpp_sm {uint64_t ke[L_ECC_MAX_DIGITS ];uint64_t k2[L_ECC_MAX_DIGITS ]; +uint64_t r_auth[L_ECC_MAX_DIGITS ];struct l_ecc_scalar *proto_private;struct l_ecc_point *proto_public;
@@ -967,7 +968,7 @@ static void dpp_handle_config_result_frame(struct dpp_sm *dpp,* ad1 = attrs * ad1_len = ptr - attrs */ -static void send_authenticate_response (struct dpp_sm *dpp,void *r_auth) +static void send_authenticate_response (struct dpp_sm *dpp) {uint8_t hdr[32 ];uint8_t attrs[256 ];
@@ -998,7 +999,7 @@ static void send_authenticate_response(struct dpp_sm *dpp, void *r_auth)/* Wrap up secondary data (R-Auth) */ wrapped2_len =dpp_append_attr (wrapped2_plaintext,DPP_ATTR_RESPONDER_AUTH_TAG , - r_auth, dpp->key_len); + dpp->r_auth, dpp->key_len);/* * "Invocations of AES-SIV in the DPP Authentication protocol that * produce ciphertext that is part of an additional AES-SIV invocation
@@ -1222,7 +1223,6 @@ static void authenticate_request(struct dpp_sm *dpp, const uint8_t *from, _auto_(l_ecc_scalar_free) struct l_ecc_scalar *m = NULL; _auto_(l_ecc_scalar_free) struct l_ecc_scalar *n = NULL;uint64_t k1[L_ECC_MAX_DIGITS ]; -uint64_t r_auth[L_ECC_MAX_DIGITS ];const void *ad0 = body +2 ;const void *ad1 = body +8 ;
@@ -1363,7 +1363,7 @@ static void authenticate_request(struct dpp_sm *dpp, const uint8_t *from,if (!dpp_derive_r_auth (dpp->i_nonce, dpp->r_nonce, dpp->nonce_len, dpp->i_proto_public, dpp->proto_public, - dpp->boot_public, r_auth)) + dpp->boot_public, dpp->r_auth)) goto auth_request_failed;memcpy (dpp->auth_addr, from,6 );
@@ -1371,7 +1371,7 @@ static void authenticate_request(struct dpp_sm *dpp, const uint8_t *from, dpp->state =DPP_STATE_AUTHENTICATING ;dpp_reset_protocol_timer (dpp); -send_authenticate_response (dpp, r_auth); +send_authenticate_response (dpp);return ;
Signature · 1 line
2.31.1
James Prestwood
PATCH 4/5 dpp: refactor calls to offchannel_start into common function
In reply to James PrestwoodThis will aid in channel switching during authentication by allowing an arbitrary channel to be passed in rather than dpp->current_freq.
--- src/dpp.c | 203 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 107 insertions(+), 96 deletions(-)
src/dpp.c +107 -96
@@ -1204,6 +1204,112 @@ static bool dpp_check_roles(struct dpp_sm *dpp, uint8_t peer_capa)return true; } +static void dpp_presence_announce (struct dpp_sm *dpp) +{ +struct netdev *netdev = dpp->netdev; +uint8_t hdr[32 ]; +uint8_t attrs[32 +4 ]; +uint8_t hash[32 ]; +uint8_t *ptr = attrs; +const uint8_t *addr =netdev_get_address (netdev); +struct iovec iov[2 ]; + + iov[0 ].iov_len =dpp_build_header (addr, broadcast, +DPP_FRAME_PRESENCE_ANNOUNCEMENT , hdr); + iov[0 ].iov_base = hdr; + +dpp_hash (L_CHECKSUM_SHA256 , hash,2 ,"chirp" ,strlen ("chirp" ), + dpp->pub_asn1, dpp->pub_asn1_len); + + ptr +=dpp_append_attr (ptr,DPP_ATTR_RESPONDER_BOOT_KEY_HASH , hash,32 ); + + iov[1 ].iov_base = attrs; + iov[1 ].iov_len = ptr - attrs; + +l_debug ("Sending presense annoucement on frequency %u and waiting %u" , + dpp->current_freq, dpp->dwell); + +dpp_send_frame (netdev_get_wdev_id (netdev), iov,2 , dpp->current_freq); +} + +static void dpp_roc_started (void *user_data) +{ +struct dpp_sm *dpp = user_data; + +/* +* If not in presence procedure or in a configurator role, just stay +* on channel. +*/ +if (dpp->state !=DPP_STATE_PRESENCE || + dpp->role ==DPP_CAPABILITY_CONFIGURATOR ) +return ; + +dpp_presence_announce (dpp); +} + +static void dpp_start_offchannel (struct dpp_sm *dpp,uint32_t freq); + +static void dpp_presence_timeout (int error,void *user_data) +{ +struct dpp_sm *dpp = user_data; + + dpp->offchannel_id =0 ; + +/* +* If cancelled this is likely due to netdev going down or from Stop(). +* Otherwise there was some other problem which is probably not +* recoverable. +*/ +if (error == -ECANCELED ) +return ; +else if (error == -EIO ) + goto next_roc; +else if (error <0 ) + goto protocol_failed; + +switch (dpp->state) { +case DPP_STATE_PRESENCE : +break ; +case DPP_STATE_NOTHING : +/* Protocol already terminated */ +return ; +case DPP_STATE_AUTHENTICATING : +case DPP_STATE_CONFIGURING : + goto next_roc; + } + + dpp->freqs_idx++; + +if (dpp->freqs_idx >= dpp->freqs_len) { +l_debug ("Max retries on presence announcements" ); + dpp->freqs_idx =0 ; + } + + dpp->current_freq = dpp->freqs[dpp->freqs_idx]; + +l_debug ("Presence timeout, moving to next frequency %u, duration %u" , + dpp->current_freq, dpp->dwell); + +next_roc: +dpp_start_offchannel (dpp, dpp->current_freq); + +return ; + +protocol_failed: +dpp_reset (dpp); +return ; +} + +static void dpp_start_offchannel (struct dpp_sm *dpp,uint32_t freq) +{ +if (dpp->offchannel_id) +offchannel_cancel (dpp->wdev_id, dpp->offchannel_id); + + dpp->offchannel_id =offchannel_start (netdev_get_wdev_id (dpp->netdev), + freq, dpp->dwell, dpp_roc_started, + dpp, dpp_presence_timeout); +} +static void authenticate_request (struct dpp_sm *dpp,const uint8_t *from,const uint8_t *body,size_t body_len) {
@@ -1414,49 +1520,6 @@ static void dpp_handle_frame(const struct mmpdu_header *frame, } } -static void dpp_presence_announce (struct dpp_sm *dpp) -{ -struct netdev *netdev = dpp->netdev; -uint8_t hdr[32 ]; -uint8_t attrs[32 +4 ]; -uint8_t hash[32 ]; -uint8_t *ptr = attrs; -const uint8_t *addr =netdev_get_address (netdev); -struct iovec iov[2 ]; - - iov[0 ].iov_len =dpp_build_header (addr, broadcast, -DPP_FRAME_PRESENCE_ANNOUNCEMENT , hdr); - iov[0 ].iov_base = hdr; - -dpp_hash (L_CHECKSUM_SHA256 , hash,2 ,"chirp" ,strlen ("chirp" ), - dpp->pub_asn1, dpp->pub_asn1_len); - - ptr +=dpp_append_attr (ptr,DPP_ATTR_RESPONDER_BOOT_KEY_HASH , hash,32 ); - - iov[1 ].iov_base = attrs; - iov[1 ].iov_len = ptr - attrs; - -l_debug ("Sending presense annoucement on frequency %u and waiting %u" , - dpp->current_freq, dpp->dwell); - -dpp_send_frame (netdev_get_wdev_id (netdev), iov,2 , dpp->current_freq); -} - -static void dpp_roc_started (void *user_data) -{ -struct dpp_sm *dpp = user_data; - -/* -* If not in presence procedure or in a configurator role, just stay -* on channel. -*/ -if (dpp->state !=DPP_STATE_PRESENCE || - dpp->role ==DPP_CAPABILITY_CONFIGURATOR ) -return ; - -dpp_presence_announce (dpp); -} -static void dpp_create (struct netdev *netdev) {struct l_dbus *dbus =dbus_get_bus ();
@@ -1517,56 +1580,6 @@ static void dpp_netdev_watch(struct netdev *netdev, } } -static void dpp_presence_timeout (int error,void *user_data) -{ -struct dpp_sm *dpp = user_data; - -/* -* If cancelled this is likely due to netdev going down or from Stop(). -* Otherwise there was some other problem which is probably not -* recoverable. -*/ -if (error == -ECANCELED ) -return ; -else if (error == -EIO ) - goto next_roc; -else if (error <0 ) - goto protocol_failed; - -switch (dpp->state) { -case DPP_STATE_PRESENCE : -break ; -case DPP_STATE_NOTHING : -/* Protocol already terminated */ -return ; -case DPP_STATE_AUTHENTICATING : -case DPP_STATE_CONFIGURING : - goto next_roc; - } - - dpp->freqs_idx++; - -if (dpp->freqs_idx >= dpp->freqs_len) { -l_debug ("Max retries on presence announcements" ); - dpp->freqs_idx =0 ; - } - - dpp->current_freq = dpp->freqs[dpp->freqs_idx]; - -l_debug ("Presence timeout, moving to next frequency %u, duration %u" , - dpp->current_freq, dpp->dwell); - -next_roc: - dpp->offchannel_id =offchannel_start (netdev_get_wdev_id (dpp->netdev), - dpp->current_freq, dpp->dwell, dpp_roc_started, - dpp, dpp_presence_timeout); -return ; - -protocol_failed: -dpp_reset (dpp); -return ; -} -/* * EasyConnect 2.0 - 6.2.2 */
@@ -1626,9 +1639,7 @@ static void dpp_start_presence(struct dpp_sm *dpp, uint32_t *limit_freqs, dpp->freqs_idx =0 ; dpp->current_freq = dpp->freqs[0 ]; - dpp->offchannel_id =offchannel_start (netdev_get_wdev_id (dpp->netdev), - dpp->current_freq, dpp->dwell, dpp_roc_started, - dpp, dpp_presence_timeout); +dpp_start_offchannel (dpp, dpp->current_freq); } static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
Signature · 1 line
2.31.1
James Prestwood
PATCH 5/5 dpp: handle CHANNEL attribute in auth request
In reply to James PrestwoodWhen this attribute is included, the initiator is requesting all future frames be sent on this channel. There is no reason for a configurator to act on this attribute (at least for now) so the request frame will be dropped in this case. Enrollees will act on it by switching to the new channel and sending the authentication response.
--- src/dpp.c | 77 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 19 deletions(-)
src/dpp.c +58 -19
@@ -91,6 +91,7 @@ struct dpp_sm {size_t freqs_idx;uint32_t dwell;uint32_t current_freq; +uint32_t new_freq;struct scan_freq_set *presence_list;uint32_t offchannel_id;
@@ -169,6 +170,7 @@ static void dpp_reset(struct dpp_sm *dpp) } dpp->state =DPP_STATE_NOTHING ; + dpp->new_freq =0 ;explicit_bzero (dpp->r_nonce, dpp->nonce_len);explicit_bzero (dpp->i_nonce, dpp->nonce_len);
@@ -1237,14 +1239,29 @@ static void dpp_roc_started(void *user_data)struct dpp_sm *dpp = user_data;/* -* If not in presence procedure or in a configurator role, just stay -* on channel. +* - If a configurator, nothing to do but wait for a request +* - If in the presence state continue sending announcements. +* - If authenticating, and this is a result of a channel switch send +* the authenticate response now. */ -if (dpp->state !=DPP_STATE_PRESENCE || - dpp->role ==DPP_CAPABILITY_CONFIGURATOR ) +if (dpp->role ==DPP_CAPABILITY_CONFIGURATOR )return ; -dpp_presence_announce (dpp); +switch (dpp->state) { +case DPP_STATE_PRESENCE : +dpp_presence_announce (dpp); +break ; +case DPP_STATE_AUTHENTICATING : +if (dpp->new_freq) { + dpp->current_freq = dpp->new_freq; + dpp->new_freq =0 ; +send_authenticate_response (dpp); + } + +break ; +default : +break ; + } }static void dpp_start_offchannel (struct dpp_sm *dpp,uint32_t freq);
@@ -1331,6 +1348,7 @@ static void authenticate_request(struct dpp_sm *dpp, const uint8_t *from,uint64_t k1[L_ECC_MAX_DIGITS ];const void *ad0 = body +2 ;const void *ad1 = body +8 ; +uint32_t freq;if (dpp->state !=DPP_STATE_PRESENCE )return ;
@@ -1370,20 +1388,39 @@ static void authenticate_request(struct dpp_sm *dpp, const uint8_t *from, }break ; -/* -* TODO: Go on this channel for remainder of auth protocol. -* -* "the Responder determines whether it can use the requested -* channel for the following exchanges. If so, it sends the DPP -* Authentication Response frame on that channel. If not, it -* discards the DPP Authentication Request frame without -* replying to it." -* -* For the time being this feature is not being implemented and -* the frame will be dropped. -*/ +case DPP_ATTR_CHANNEL : -return ; +if (len !=2 ) +return ; + + freq =oci_to_frequency (l_get_u8 (data), +l_get_u8 (data +1 )); + +if (freq == dpp->current_freq) +break ; + +/* +* Configurators are already connected to a network, so +* to preserve wireless performance the enrollee will +* be required to be on this channel, not a channel it +* requests. +*/ +if (dpp->role ==DPP_CAPABILITY_CONFIGURATOR ) +return ; + +/* +* Otherwise, as an enrollee, we can jump to whatever +* channel the configurator requests +*/ + dpp->new_freq = freq; + +l_debug ("Configurator requested a new frequency %u" , + dpp->new_freq); + +offchannel_cancel (dpp->wdev_id, dpp->offchannel_id); +dpp_start_offchannel (dpp, dpp->new_freq); + +break ;default :break ; }
@@ -1477,7 +1514,9 @@ static void authenticate_request(struct dpp_sm *dpp, const uint8_t *from, dpp->state =DPP_STATE_AUTHENTICATING ;dpp_reset_protocol_timer (dpp); -send_authenticate_response (dpp); +/* Don't send if the frequency is changing */ +if (!dpp->new_freq) +send_authenticate_response (dpp);return ;
Signature · 1 line
2.31.1