netdev: Replace bool randomize_mac with specific address
PATCH 1/4 netdev: Replace bool randomize_mac with specific address
Allow netdev_create_from_genl callers to draw a random or non-random MAC and pass it in the parameter instead of a bool to tell us to generating the MAC locally. In P2P we are generating the MAC some time before creating the netdev in order to pass it to the peer during negotiation.
--- src/manager.c | 22 ++++++++++++++++++---- src/netdev.c | 45 ++++++++++++++++++++++----------------------- src/netdev.h | 3 ++- 3 files changed, 42 insertions(+), 28 deletions(-)
src/manager.c +18 -4
@@ -102,6 +102,9 @@ static void wiphy_setup_state_destroy(struct wiphy_setup_state *state)static bool manager_use_default (struct wiphy_setup_state *state) { +uint8_t addr_buf[6 ]; +uint8_t *addr =NULL ; +l_debug ("" );if (!state->default_if_msg) {
@@ -110,13 +113,20 @@ static bool manager_use_default(struct wiphy_setup_state *state)return false; } -netdev_create_from_genl (state->default_if_msg, randomize); +if (randomize) { +wiphy_generate_random_address (state->wiphy, addr_buf); + addr = addr_buf; + } + +netdev_create_from_genl (state->default_if_msg, addr);return true; }static void manager_new_interface_cb (struct l_genl_msg *msg,void *user_data) {struct wiphy_setup_state *state = user_data; +uint8_t addr_buf[6 ]; +uint8_t *addr =NULL ;l_debug ("" );
@@ -134,9 +144,13 @@ static void manager_new_interface_cb(struct l_genl_msg *msg, void *user_data)return ; } -netdev_create_from_genl (msg, randomize && - !wiphy_has_feature (state->wiphy, -NL80211_FEATURE_MAC_ON_CREATE )); +if (randomize && !wiphy_has_feature (state->wiphy, +NL80211_FEATURE_MAC_ON_CREATE )) { +wiphy_generate_random_address (state->wiphy, addr_buf); + addr = addr_buf; + } + +netdev_create_from_genl (msg, addr); }static void manager_new_interface_done (void *user_data)
src/netdev.c +22 -23
89 lines not on this page · raw message
src/netdev.h +2 -1
@@ -205,5 +205,6 @@ uint32_t netdev_station_watch_add(struct netdev *netdev,bool netdev_station_watch_remove (struct netdev *netdev,uint32_t id); -struct netdev *netdev_create_from_genl (struct l_genl_msg *msg,bool random_mac); +struct netdev *netdev_create_from_genl (struct l_genl_msg *msg, +const uint8_t *set_mac);bool netdev_destroy (struct netdev *netdev);
Signature · 1 line
2.20.1
PATCH 2/4 wsc: Refactor to separate station-specific code
Split the interface-specific logic from the core WSC logic. The core WSC code is the part that we can re-use between P2P and station and doesn't include the D-Bus code, scanning for the target BSS or the attempt to make a station mode connection.
--- src/wsc.c | 141 ++++++++++++++++++++++++++++++++++++++---------------- src/wsc.h | 3 ++ 2 files changed, 103 insertions(+), 41 deletions(-)
src/wsc.c +100 -41
@@ -65,6 +65,11 @@ struct wsc {struct wsc_credentials_info creds[3 ];uint32_t n_creds;struct l_settings *eap_settings; +char *pin; + +wsc_done_cb_t done_cb; +void *done_data; +uint16_t config_method; bool wsc_association : 1; };
@@ -153,15 +158,12 @@ static void wsc_try_credentials(struct wsc *wsc)l_dbus_message_unref (wsc->pending); wsc->pending =NULL ; - goto done; +return ; }dbus_pending_reply (&wsc->pending,wsc_error_not_reachable (wsc->pending));station_set_autoconnect (wsc->station, true); -done: -memset (wsc->creds,0 ,sizeof (wsc->creds)); - wsc->n_creds =0 ; }static void wsc_store_credentials (struct wsc *wsc)
@@ -217,6 +219,22 @@ static void wsc_disconnect_cb(struct netdev *netdev, bool success,station_set_autoconnect (wsc->station, true); } +static void wsc_connect_cleanup (struct wsc *wsc) +{ + wsc->wsc_association = false; + +l_settings_free (wsc->eap_settings); + wsc->eap_settings =NULL ; + +if (wsc->pin) { +explicit_bzero (wsc->pin,strlen (wsc->pin)); +l_free (wsc->pin); + wsc->pin =NULL ; + } + + wsc->target =NULL ; +} +static void wsc_connect_cb (struct netdev *netdev,enum netdev_result result,void *event_data,void *user_data) {
@@ -224,33 +242,34 @@ static void wsc_connect_cb(struct netdev *netdev, enum netdev_result result,l_debug ("%d, result: %d" ,netdev_get_ifindex (wsc->netdev), result); - wsc->wsc_association = false; - -l_settings_free (wsc->eap_settings); - wsc->eap_settings =NULL ; +wsc_connect_cleanup (wsc);if (result ==NETDEV_RESULT_HANDSHAKE_FAILED && wsc->n_creds >0 ) { -wsc_store_credentials (wsc); -wsc_try_credentials (wsc); +struct wsc_credentials_info creds[L_ARRAY_SIZE (wsc->creds)]; +uint32_t n_creds = wsc->n_creds; + +memcpy (creds, wsc->creds,sizeof (creds)); +explicit_bzero (wsc->creds,sizeof (creds)); + wsc->n_creds =0 ; + wsc->done_cb (0 , creds, n_creds, wsc->done_data); +explicit_bzero (creds,sizeof (creds));return ; }switch (result) {case NETDEV_RESULT_ABORTED : -dbus_pending_reply (&wsc->pending, -dbus_error_aborted (wsc->pending)); + wsc->done_cb (-ECANCELED ,NULL ,0 , wsc->done_data);return ;case NETDEV_RESULT_HANDSHAKE_FAILED : -dbus_pending_reply (&wsc->pending, -wsc_error_no_credentials (wsc->pending)); + wsc->done_cb (-ENOKEY ,NULL ,0 , wsc->done_data);break ;default : -dbus_pending_reply (&wsc->pending, -dbus_error_failed (wsc->pending)); + wsc->done_cb (-EIO ,NULL ,0 , wsc->done_data);break ; } -station_set_autoconnect (wsc->station, true); +if (wsc->station) +station_set_autoconnect (wsc->station, true); } static void wsc_credential_obtained(struct wsc *wsc,
@@ -452,30 +471,24 @@ static void wsc_connect(struct wsc *wsc)l_settings_set_uint (settings,"WSC" ,"RFBand" ,freq_to_rf_band (bss->frequency));l_settings_set_uint (settings,"WSC" ,"ConfigurationMethods" , -WSC_CONFIGURATION_METHOD_VIRTUAL_DISPLAY_PIN | -WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON | -WSC_CONFIGURATION_METHOD_KEYPAD ); + wsc->config_method);l_settings_set_string (settings,"WSC" ,"PrimaryDeviceType" ,"0-00000000-0" );l_settings_set_string (settings,"WSC" ,"EnrolleeMAC" ,util_address_to_string (netdev_get_address (wsc->netdev))); -if (!strcmp (l_dbus_message_get_member (wsc->pending),"StartPin" )) { -const char *pin; - -if (l_dbus_message_get_arguments (wsc->pending,"s" , &pin)) { -enum wsc_device_password_id dpid; +if (wsc->config_method ==WSC_CONFIGURATION_METHOD_KEYPAD ) { +enum wsc_device_password_id dpid; -if (strlen (pin) ==4 ||wsc_pin_is_checksum_valid (pin)) - dpid =WSC_DEVICE_PASSWORD_ID_DEFAULT ; -else - dpid =WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED ; +if (strlen (wsc->pin) ==4 || +wsc_pin_is_checksum_valid (wsc->pin)) + dpid =WSC_DEVICE_PASSWORD_ID_DEFAULT ; +else + dpid =WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED ; -l_settings_set_uint (settings,"WSC" , -"DevicePasswordId" , dpid); -l_settings_set_string (settings,"WSC" , -"DevicePassword" , pin); - } +l_settings_set_uint (settings,"WSC" ,"DevicePasswordId" , dpid); +l_settings_set_string (settings,"WSC" ,"DevicePassword" , + wsc->pin); }handshake_state_set_event_func (hs, wsc_handshake_event, wsc);
@@ -511,8 +524,41 @@ static void wsc_connect(struct wsc *wsc)return ; error:handshake_state_free (hs); -dbus_pending_reply (&wsc->pending, -dbus_error_failed (wsc->pending)); +wsc_connect_cleanup (wsc); + wsc->done_cb (r,NULL ,0 , wsc->done_data); +} + +/* Done callback for when WSC is triggered by DBus methods */ +static void wsc_dbus_done_cb (int err,struct wsc_credentials_info *creds, +unsigned int n_creds,void *user_data) +{ +struct wsc *wsc = user_data; + +l_debug ("err=%i" , err); + +switch (err) { +case 0 : +break ; +case -ECANCELED : +dbus_pending_reply (&wsc->pending, +dbus_error_aborted (wsc->pending)); +return ; +case -ENOKEY : +dbus_pending_reply (&wsc->pending, +wsc_error_no_credentials (wsc->pending)); +return ; +case -EBUSY : +dbus_pending_reply (&wsc->pending, +dbus_error_busy (wsc->pending)); +return ; +default : +dbus_pending_reply (&wsc->pending, +dbus_error_failed (wsc->pending)); +return ; + } + +wsc_store_credentials (wsc); +wsc_try_credentials (wsc); }static void station_state_watch (enum station_state state,void *userdata)
@@ -541,6 +587,22 @@ static void wsc_check_can_connect(struct wsc *wsc, struct scan_bss *target) wsc->target = target;station_set_autoconnect (wsc->station, false); +if (!strcmp (l_dbus_message_get_member (wsc->pending),"StartPin" )) { +char *pin; + + wsc->config_method =WSC_CONFIGURATION_METHOD_KEYPAD ; + +if (!l_dbus_message_get_arguments (wsc->pending,"s" , &pin)) + goto error; + + wsc->pin =l_strdup (pin); + }else + wsc->config_method = +WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON ; + + wsc->done_cb = wsc_dbus_done_cb; + wsc->done_data = wsc; +switch (station_get_state (wsc->station)) {case STATION_STATE_DISCONNECTED :wsc_connect (wsc);
@@ -564,7 +626,7 @@ static void wsc_check_can_connect(struct wsc *wsc, struct scan_bss *target)break ; } error: - wsc->target =NULL ; +wsc_connect_cleanup (wsc);dbus_pending_reply (&wsc->pending,dbus_error_failed (wsc->pending)); }
@@ -1074,12 +1136,12 @@ static void wsc_free(void *userdata)struct wsc *wsc = userdata;wsc_cancel_scan (wsc); +wsc_connect_cleanup (wsc);if (wsc->station_state_watch) {station_remove_state_watch (wsc->station, wsc->station_state_watch); wsc->station_state_watch =0 ; - wsc->target =NULL ; }if (wsc->pending)
@@ -1090,9 +1152,6 @@ static void wsc_free(void *userdata)dbus_pending_reply (&wsc->pending_cancel,dbus_error_aborted (wsc->pending_cancel)); -if (wsc->eap_settings) -l_settings_free (wsc->eap_settings); -l_free (wsc); }
src/wsc.h +3 -0
@@ -30,3 +30,6 @@ struct wsc_credentials_info {uint8_t addr[6 ];bool has_passphrase; }; + +typedef void (*wsc_done_cb_t )(int err,struct wsc_credentials_info *creds, +unsigned int n_creds,void *user_data);
Signature · 1 line
2.20.1
Denis Kenzior
AppliedRe: [PATCH 2/4] wsc: Refactor to separate station-specific code
Hi Andrew,
Quoted 9 lines · Andrew Zaborowski
Split the interface-specific logic from the core WSC logic. The core WSC code is the part that we can re-use between P2P and station and doesn't include the D-Bus code, scanning for the target BSS or the attempt to make a station mode connection.
--- src/wsc.c | 141 ++++++++++++++++++++++++++++++++++++++---------------- src/wsc.h | 3 ++ 2 files changed, 103 insertions(+), 41 deletions(-)
<snip>
Quoted 9 lines
src/wsc.c +1
-4@@ -224,33 +242,34 @@ static void wsc_connect_cb(struct netdev *netdev, enum netdev_result result,l_debug ("%d, result: %d" ,netdev_get_ifindex (wsc->netdev), result); - wsc->wsc_association = false; - -l_settings_free (wsc->eap_settings); - wsc->eap_settings =NULL ; +wsc_connect_cleanup (wsc);
src/wsc.c static void wsc_connect_cb(struct netdev *netdev, enum netdev_result result, · line 253
Quoted 10 lines
src/wsc.c +6
-2if (result ==NETDEV_RESULT_HANDSHAKE_FAILED && wsc->n_creds >0 ) { -wsc_store_credentials (wsc); -wsc_try_credentials (wsc); +struct wsc_credentials_info creds[L_ARRAY_SIZE (wsc->creds)]; +uint32_t n_creds = wsc->n_creds; + +memcpy (creds, wsc->creds,sizeof (creds)); +explicit_bzero (wsc->creds,sizeof (creds)); + wsc->n_creds =0 ;
I added a comment here based on your response to my previous question about this. Please check to see that I got the gist of it correctly.
Quoted 5 lines
src/wsc.c +2
-0+ wsc->done_cb (0 , creds, n_creds, wsc->done_data); +explicit_bzero (creds,sizeof (creds));return ; }
<snip>
src/wsc.c static void wsc_connect(struct wsc *wsc) · line 474
Quoted 8 lines
src/wsc.c +1
-3@@ -452,30 +471,24 @@ static void wsc_connect(struct wsc *wsc)l_settings_set_uint (settings,"WSC" ,"RFBand" ,freq_to_rf_band (bss->frequency));l_settings_set_uint (settings,"WSC" ,"ConfigurationMethods" , -WSC_CONFIGURATION_METHOD_VIRTUAL_DISPLAY_PIN | -WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON | -WSC_CONFIGURATION_METHOD_KEYPAD ); + wsc->config_method);
I squashed this for now. I don't think it is actually correct and I brought this up previously. ConfigurationMethods are supposed to be all the methods we support, not the selected one... Why this is useful inside the EAP-WSC protocol is unclear, but that seems to be what the spec wants...
Applied, thanks.
Regards,
-Denis
Re: [PATCH 2/4] wsc: Refactor to separate station-specific code
Hi Denis,
Quoted 23 lines · Denis Kenzior
Quoted 9 lines · Andrew Zaborowski
Split the interface-specific logic from the core WSC logic. The core WSC code is the part that we can re-use between P2P and station and doesn't include the D-Bus code, scanning for the target BSS or the attempt to make a station mode connection.
--- src/wsc.c | 141 ++++++++++++++++++++++++++++++++++++++---------------- src/wsc.h | 3 ++ 2 files changed, 103 insertions(+), 41 deletions(-)<snip>
Quoted 10 lines
src/wsc.c +1
-4@@ -224,33 +242,34 @@ static void wsc_connect_cb(struct netdev *netdev, enum netdev_result result,l_debug ("%d, result: %d" ,netdev_get_ifindex (wsc->netdev), result); - wsc->wsc_association = false; - -l_settings_free (wsc->eap_settings); - wsc->eap_settings =NULL ; +wsc_connect_cleanup (wsc);
Quoted 12 lines
src/wsc.c static void wsc_connect_cb(struct netdev *netdev, enum netdev_result result, · line 253
Quoted 9 lines
src/wsc.c +6
-2if (result ==NETDEV_RESULT_HANDSHAKE_FAILED && wsc->n_creds >0 ) { -wsc_store_credentials (wsc); -wsc_try_credentials (wsc); +struct wsc_credentials_info creds[L_ARRAY_SIZE (wsc->creds)]; +uint32_t n_creds = wsc->n_creds; + +memcpy (creds, wsc->creds,sizeof (creds)); +explicit_bzero (wsc->creds,sizeof (creds)); + wsc->n_creds =0 ;I added a comment here based on your response to my previous question about this. Please check to see that I got the gist of it correctly.
Ok, good idea. The reason was basically that done_cb should be able to free @wsc (and it would in my earlier p2p implementation), but we needed to wipe the creds before freeing the memory so my only option was to always wipe it.
Quoted 8 lines
Quoted 5 lines
src/wsc.c +2
-0+ wsc->done_cb (0 , creds, n_creds, wsc->done_data); +explicit_bzero (creds,sizeof (creds));return ; }<snip>
Quoted 14 lines
src/wsc.c static void wsc_connect(struct wsc *wsc) · line 474
Quoted 8 lines
src/wsc.c +1
-3@@ -452,30 +471,24 @@ static void wsc_connect(struct wsc *wsc)l_settings_set_uint (settings,"WSC" ,"RFBand" ,freq_to_rf_band (bss->frequency));l_settings_set_uint (settings,"WSC" ,"ConfigurationMethods" , -WSC_CONFIGURATION_METHOD_VIRTUAL_DISPLAY_PIN | -WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON | -WSC_CONFIGURATION_METHOD_KEYPAD ); + wsc->config_method);I squashed this for now. I don't think it is actually correct and I brought this up previously. ConfigurationMethods are supposed to be all the methods we support, not the selected one... Why this is useful inside the EAP-WSC protocol is unclear, but that seems to be what the spec wants...
Oops, I think you brought this up twice actually and I definitely looked at the spec and dropped this change. So I don't know how it made it into the last iteration of this patch.
Best regards
PATCH 3/4 wsc: Refactor to make the DBus interface reusable
In reply to Andrew ZaborowskiAllow adding the DBus SimpleConfiguration interface on both station mode netdevs and P2P peers by putting public functions and callbacks between the DBus method handlers and their actual implementation. The implementation provides its own callbacks for each method using the wsc_ops struct.
For patch readability I didn't move some functions in wsc.c around and group them logically, we can do the moving separately.
--- src/wsc.c | 406 ++++++++++++++++++++++++++++++++---------------------- src/wsc.h | 21 ++- 2 files changed, 263 insertions(+), 164 deletions(-)
src/wsc.c +244 -162
@@ -52,6 +52,9 @@static uint32_t netdev_watch =0 ;struct wsc { +const struct wsc_ops *ops; +void *user_data; +struct netdev *netdev;struct station *station;struct l_dbus_message *pending;
@@ -66,9 +69,6 @@ struct wsc {uint32_t n_creds;struct l_settings *eap_settings;char *pin; - -wsc_done_cb_t done_cb; -void *done_data;uint16_t config_method; bool wsc_association : 1;
@@ -113,20 +113,20 @@ static struct l_dbus_message *wsc_error_time_expired(struct l_dbus_message *msg)"No APs in PIN mode found in " "the alloted time"); } -static void wsc_try_credentials (struct wsc *wsc) +static void wsc_try_credentials (struct wsc *wsc,struct wsc_credentials_info *creds, +unsigned int n_creds) {unsigned int i;struct network *network;struct scan_bss *bss; -for (i =0 ; i < wsc->n_creds; i++) { - network =station_network_find (wsc->station, - wsc->creds[i].ssid, - wsc->creds[i].security); +for (i =0 ; i < n_creds; i++) { + network =station_network_find (wsc->station, creds[i].ssid, + creds[i].security);if (!network)continue ; - bss =network_bss_find_by_addr (network, wsc->creds[i].addr); + bss =network_bss_find_by_addr (network, creds[i].addr);if (!bss) bss =network_bss_select (network, true);
@@ -134,7 +134,7 @@ static void wsc_try_credentials(struct wsc *wsc)if (!bss)continue ; -if (wsc->creds[i].security ==SECURITY_PSK ) { +if (creds[i].security ==SECURITY_PSK ) {bool ret;/*
@@ -142,12 +142,11 @@ static void wsc_try_credentials(struct wsc *wsc)* WPA2 and WPA3 since the PSK can always be generated * if needed */ -if (wsc->creds[i].has_passphrase) +if (creds[i].has_passphrase) ret =network_set_passphrase (network, - wsc->creds[i].passphrase); + creds[i].passphrase);else - ret =network_set_psk (network, - wsc->creds[i].psk); + ret =network_set_psk (network, creds[i].psk);if (!ret)continue ;
@@ -166,21 +165,22 @@ static void wsc_try_credentials(struct wsc *wsc)station_set_autoconnect (wsc->station, true); } -static void wsc_store_credentials (struct wsc *wsc) +static void wsc_store_credentials (struct wsc_credentials_info *creds, +unsigned int n_creds) {unsigned int i; -for (i =0 ; i < wsc->n_creds; i++) { -enum security security = wsc->creds[i].security; -const char *ssid = wsc->creds[i].ssid; +for (i =0 ; i < n_creds; i++) { +enum security security = creds[i].security; +const char *ssid = creds[i].ssid;struct l_settings *settings =l_settings_new ();l_debug ("Storing credential for '%s(%s)'" , ssid,security_to_str (security));if (security ==SECURITY_PSK ) { -char *hex =l_util_hexstring (wsc->creds[i].psk, -sizeof (wsc->creds[i].psk)); +char *hex =l_util_hexstring (creds[i].psk, +sizeof (creds[i].psk));l_settings_set_value (settings,"Security" ,"PreSharedKey" , hex);
@@ -210,8 +210,6 @@ static void wsc_disconnect_cb(struct netdev *netdev, bool success,l_debug ("%p, success: %d" , wsc, success); - wsc->wsc_association = false; - reply =l_dbus_message_new_method_return (wsc->pending_cancel);l_dbus_message_set_arguments (reply,"" );dbus_pending_reply (&wsc->pending_cancel, reply);
@@ -251,20 +249,20 @@ static void wsc_connect_cb(struct netdev *netdev, enum netdev_result result,memcpy (creds, wsc->creds,sizeof (creds));explicit_bzero (wsc->creds,sizeof (creds)); wsc->n_creds =0 ; - wsc->done_cb (0 , creds, n_creds, wsc->done_data); + wsc->ops->enrollee_done_cb (0 , creds, n_creds, wsc->user_data);explicit_bzero (creds,sizeof (creds));return ; }switch (result) {case NETDEV_RESULT_ABORTED : - wsc->done_cb (-ECANCELED ,NULL ,0 , wsc->done_data); + wsc->ops->enrollee_done_cb (-ECANCELED ,NULL ,0 , wsc->user_data);return ;case NETDEV_RESULT_HANDSHAKE_FAILED : - wsc->done_cb (-ENOKEY ,NULL ,0 , wsc->done_data); + wsc->ops->enrollee_done_cb (-ENOKEY ,NULL ,0 , wsc->user_data);break ;default : - wsc->done_cb (-EIO ,NULL ,0 , wsc->done_data); + wsc->ops->enrollee_done_cb (-EIO ,NULL ,0 , wsc->user_data);break ; }
@@ -525,40 +523,19 @@ static void wsc_connect(struct wsc *wsc) error:handshake_state_free (hs);wsc_connect_cleanup (wsc); - wsc->done_cb (r,NULL ,0 , wsc->done_data); + wsc->ops->enrollee_done_cb (r,NULL ,0 , wsc->user_data); } -/* Done callback for when WSC is triggered by DBus methods */ -static void wsc_dbus_done_cb (int err,struct wsc_credentials_info *creds, -unsigned int n_creds,void *user_data) +static void wsc_connect_set_method (struct wsc *wsc) { -struct wsc *wsc = user_data; - -l_debug ("err=%i" , err); +const char *pin; -switch (err) { -case 0 : -break ; -case -ECANCELED : -dbus_pending_reply (&wsc->pending, -dbus_error_aborted (wsc->pending)); -return ; -case -ENOKEY : -dbus_pending_reply (&wsc->pending, -wsc_error_no_credentials (wsc->pending)); -return ; -case -EBUSY : -dbus_pending_reply (&wsc->pending, -dbus_error_busy (wsc->pending)); -return ; -default : -dbus_pending_reply (&wsc->pending, -dbus_error_failed (wsc->pending)); -return ; - } +if (!strcmp (l_dbus_message_get_member (wsc->pending),"StartPin" )) +l_dbus_message_get_arguments (wsc->pending,"s" , &pin); +else + pin =NULL ; -wsc_store_credentials (wsc); -wsc_try_credentials (wsc); +wsc_start_enrollee (wsc, wsc->netdev, wsc->target, pin,NULL ,0 ); }static void station_state_watch (enum station_state state,void *userdata)
@@ -573,7 +550,7 @@ static void station_state_watch(enum station_state state, void *userdata)station_remove_state_watch (wsc->station, wsc->station_state_watch); wsc->station_state_watch =0 ; -wsc_connect (wsc); +wsc_connect_set_method (wsc); }static void wsc_check_can_connect (struct wsc *wsc,struct scan_bss *target)
@@ -587,25 +564,9 @@ static void wsc_check_can_connect(struct wsc *wsc, struct scan_bss *target) wsc->target = target;station_set_autoconnect (wsc->station, false); -if (!strcmp (l_dbus_message_get_member (wsc->pending),"StartPin" )) { -char *pin; - - wsc->config_method =WSC_CONFIGURATION_METHOD_KEYPAD ; - -if (!l_dbus_message_get_arguments (wsc->pending,"s" , &pin)) - goto error; - - wsc->pin =l_strdup (pin); - }else - wsc->config_method = -WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON ; - - wsc->done_cb = wsc_dbus_done_cb; - wsc->done_data = wsc; -switch (station_get_state (wsc->station)) {case STATION_STATE_DISCONNECTED : -wsc_connect (wsc); +wsc_connect_set_method (wsc);return ;case STATION_STATE_CONNECTING :case STATION_STATE_CONNECTED :
@@ -652,20 +613,13 @@ static void walk_timeout(struct l_timeout *timeout, void *user_data)wsc_cancel_scan (wsc); -if (wsc->pending) -dbus_pending_reply (&wsc->pending, -wsc_error_walk_time_expired (wsc->pending)); -} +if (wsc->pending) { +struct l_dbus_message *reply = wsc->pin ? +wsc_error_time_expired (wsc->pending) : +wsc_error_walk_time_expired (wsc->pending); -static void pin_timeout (struct l_timeout *timeout,void *user_data) -{ -struct wsc *wsc = user_data; - -wsc_cancel_scan (wsc); - -if (wsc->pending) -dbus_pending_reply (&wsc->pending, -wsc_error_time_expired (wsc->pending)); +dbus_pending_reply (&wsc->pending, reply); + } } static bool push_button_scan_results(int err, struct l_queue *bss_list,
@@ -1001,20 +955,7 @@ static struct l_dbus_message *wsc_push_button(struct l_dbus *dbus,l_debug ("" ); -if (wsc->pending) -return dbus_error_busy (message); - - wsc->station =station_find (netdev_get_ifindex (wsc->netdev)); -if (!wsc->station) -return dbus_error_not_available (message); - -if (!wsc_initiate_scan (wsc,WSC_DEVICE_PASSWORD_ID_PUSH_BUTTON , - push_button_scan_results)) -return dbus_error_failed (message); - - wsc->walk_timer =l_timeout_create (WALK_TIME , walk_timeout, wsc,NULL ); - wsc->pending =l_dbus_message_ref (message); - + wsc->ops->connect (message,NULL , wsc->user_data);return NULL ; }
@@ -1046,77 +987,29 @@ static struct l_dbus_message *wsc_start_pin(struct l_dbus *dbus, {struct wsc *wsc = user_data;const char *pin; -enum wsc_device_password_id dpid;l_debug ("" ); -if (wsc->pending) -return dbus_error_busy (message); - - wsc->station =station_find (netdev_get_ifindex (wsc->netdev)); -if (!wsc->station) -return dbus_error_not_available (message); -if (!l_dbus_message_get_arguments (message,"s" , &pin))return dbus_error_invalid_args (message);if (!wsc_pin_is_valid (pin))return dbus_error_invalid_format (message); -if (strlen (pin) ==4 ||wsc_pin_is_checksum_valid (pin)) - dpid =WSC_DEVICE_PASSWORD_ID_DEFAULT ; -else - dpid =WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED ; - -if (!wsc_initiate_scan (wsc, dpid, pin_scan_results)) -return dbus_error_failed (message); - - wsc->walk_timer =l_timeout_create (60 , pin_timeout, wsc,NULL ); - wsc->pending =l_dbus_message_ref (message); - + wsc->ops->connect (message, pin, wsc->user_data);return NULL ; } -static struct l_dbus_message *wsc_cancel (struct l_dbus *dbus, +static struct l_dbus_message *wsc_dbus_cancel (struct l_dbus *dbus,struct l_dbus_message *message,void *user_data) {struct wsc *wsc = user_data; -struct l_dbus_message *reply;l_debug ("" ); -if (!wsc->pending) -return dbus_error_not_available (message); - -wsc_cancel_scan (wsc); - -if (wsc->station_state_watch) { -station_remove_state_watch (wsc->station, - wsc->station_state_watch); - wsc->station_state_watch =0 ; - wsc->target =NULL ; - } - -if (wsc->wsc_association) { -int r; - - r =netdev_disconnect (wsc->netdev, wsc_disconnect_cb, wsc); -if (r ==0 ) { - wsc->pending_cancel =l_dbus_message_ref (message); -return NULL ; - } - -l_warn ("Unable to initiate disconnect: %s" ,strerror (-r)); - wsc->wsc_association = false; - } - -dbus_pending_reply (&wsc->pending,dbus_error_aborted (wsc->pending)); - - reply =l_dbus_message_new_method_return (message); -l_dbus_message_set_arguments (reply,"" ); - -return reply; + wsc->ops->cancel (message, wsc->user_data); +return NULL ; }static void setup_wsc_interface (struct l_dbus_interface *interface)
@@ -1128,7 +1021,7 @@ static void setup_wsc_interface(struct l_dbus_interface *interface)l_dbus_interface_method (interface,"StartPin" ,0 , wsc_start_pin,"" ,"s" ,"pin" );l_dbus_interface_method (interface,"Cancel" ,0 , - wsc_cancel,"" ,"" ); + wsc_dbus_cancel,"" ,"" ); }static void wsc_free (void *userdata)
@@ -1155,7 +1048,194 @@ static void wsc_free(void *userdata)l_free (wsc); } -static void wsc_add_interface (struct netdev *netdev) +struct wsc *wsc_new (const struct wsc_ops *ops,void *user_data) +{ +struct l_dbus *dbus =dbus_get_bus (); +struct wsc *wsc; +const char *path; + + wsc = l_new(struct wsc, 1); + wsc->ops = ops; + wsc->user_data = user_data; + + path = wsc->ops->get_path (wsc->user_data); +if (!path) +return wsc; + +if (l_dbus_object_add_interface (dbus, path,IWD_WSC_INTERFACE , wsc)) +return wsc; + +wsc_free (wsc); +l_info ("Unable to register interface %s at %s" ,IWD_WSC_INTERFACE , + path); +return NULL ; +} + +void wsc_destroy (struct wsc *wsc) +{ +l_dbus_object_remove_interface (dbus_get_bus (), + wsc->ops->get_path (wsc->user_data), +IWD_WSC_INTERFACE ); +} + +void wsc_start_enrollee (struct wsc *wsc,struct netdev *netdev, +struct scan_bss *target,const char *pin) +{ + wsc->netdev = netdev; + wsc->target = target; + wsc->config_method = pin ?WSC_CONFIGURATION_METHOD_KEYPAD : +WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON ; + wsc->pin =l_strdup (pin); + +wsc_connect (wsc); +} + +void wsc_cancel (struct wsc *wsc,netdev_disconnect_cb_t cb) +{ +int r; + +if (!wsc->wsc_association) +return ; + + r =netdev_disconnect (wsc->netdev, cb, wsc->user_data); +if (r ==0 ) +return ; + +l_warn ("Unable to initiate disconnect: %s" ,strerror (-r)); +wsc_connect_cleanup (wsc); + wsc->ops->enrollee_done_cb (-ECANCELED ,NULL ,0 , wsc->user_data); + +if (cb) +cb (wsc->netdev, false, wsc->user_data); +} + +static const char *wsc_device_get_path (void *user_data) +{ +struct wsc *wsc = user_data; + +if (!wsc || !wsc->netdev) +return NULL ; + +return netdev_get_path (wsc->netdev); +} + +static void wsc_device_connect (struct l_dbus_message *message,const char *pin, +void *user_data) +{ +struct wsc *wsc = user_data; +struct l_dbus *dbus =dbus_get_bus (); +unsigned int walk_time; +enum wsc_device_password_id dpid; +scan_notify_func_t results_cb; + +if (wsc->pending) { +l_dbus_send (dbus,dbus_error_busy (message)); +return ; + } + + wsc->station =station_find (netdev_get_ifindex (wsc->netdev)); +if (!wsc->station) { +l_dbus_send (dbus,dbus_error_not_available (message)); +return ; + } + +if (pin) { +if (strlen (pin) ==4 ||wsc_pin_is_checksum_valid (pin)) + dpid =WSC_DEVICE_PASSWORD_ID_DEFAULT ; +else + dpid =WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED ; + + walk_time =60 ; + results_cb = pin_scan_results; + }else { + dpid =WSC_DEVICE_PASSWORD_ID_PUSH_BUTTON ; + walk_time =WALK_TIME ; + results_cb = push_button_scan_results; + } + +if (!wsc_initiate_scan (wsc, dpid, results_cb)) { +l_dbus_send (dbus,dbus_error_failed (message)); +return ; + } + + wsc->walk_timer =l_timeout_create (walk_time, walk_timeout, wsc,NULL ); + wsc->pending =l_dbus_message_ref (message); +} + +static void wsc_device_cancel (struct l_dbus_message *message,void *user_data) +{ +struct wsc *wsc = user_data; +struct l_dbus *dbus =dbus_get_bus (); + +if (!wsc->pending) { +l_dbus_send (dbus,dbus_error_not_available (message)); +return ; + } + +if (wsc->pending_cancel) { +l_dbus_send (dbus,dbus_error_busy (message)); +return ; + } + +wsc_cancel_scan (wsc); + +if (wsc->station_state_watch) { +station_remove_state_watch (wsc->station, + wsc->station_state_watch); + wsc->station_state_watch =0 ; + wsc->target =NULL ; + } + +if (wsc->wsc_association) { + wsc->pending_cancel =l_dbus_message_ref (message); +wsc_cancel (wsc, wsc_disconnect_cb); +return ; + } + +dbus_pending_reply (&wsc->pending,dbus_error_aborted (wsc->pending)); +l_dbus_send (dbus,l_dbus_message_new_method_return (message)); +} + +static void wsc_device_enrollee_done (int err,struct wsc_credentials_info *creds, +unsigned int n_creds,void *user_data) +{ +struct wsc *wsc = user_data; + +l_debug ("err=%i" , err); + +switch (err) { +case 0 : +break ; +case -ECANCELED : +dbus_pending_reply (&wsc->pending, +dbus_error_aborted (wsc->pending)); +return ; +case -ENOKEY : +dbus_pending_reply (&wsc->pending, +wsc_error_no_credentials (wsc->pending)); +return ; +case -EBUSY : +dbus_pending_reply (&wsc->pending, +dbus_error_busy (wsc->pending)); +return ; +default : +dbus_pending_reply (&wsc->pending, +dbus_error_failed (wsc->pending)); +return ; + } + +wsc_store_credentials (creds, n_creds); +wsc_try_credentials (wsc, creds, n_creds); +} + +static const struct wsc_ops wsc_device_ops = { + .get_path = wsc_device_get_path, + .connect = wsc_device_connect, + .cancel = wsc_device_cancel, + .enrollee_done_cb = wsc_device_enrollee_done, +}; + +static void wsc_device_new (struct netdev *netdev) {struct l_dbus *dbus =dbus_get_bus ();struct wsc *wsc;
@@ -1167,15 +1247,17 @@ static void wsc_add_interface(struct netdev *netdev)return ; } - wsc = l_new(struct wsc, 1); + wsc =wsc_new (&wsc_device_ops,NULL ); + wsc->user_data = wsc; wsc->netdev = netdev; -if (!l_dbus_object_add_interface (dbus,netdev_get_path (netdev), -IWD_WSC_INTERFACE , - wsc)) { -wsc_free (wsc); -l_info ("Unable to register %s interface" ,IWD_WSC_INTERFACE ); - } +if (l_dbus_object_add_interface (dbus,netdev_get_path (netdev), +IWD_WSC_INTERFACE , wsc)) +return ; + +wsc_free (wsc); +l_info ("Unable to register interface %s at %s" ,IWD_WSC_INTERFACE , +netdev_get_path (netdev)); }static void wsc_remove_interface (struct netdev *netdev)
@@ -1194,7 +1276,7 @@ static void wsc_netdev_watch(struct netdev *netdev,case NETDEV_WATCH_EVENT_NEW :if (netdev_get_iftype (netdev) ==NETDEV_IFTYPE_STATION &&netdev_get_is_up (netdev)) -wsc_add_interface (netdev); +wsc_device_new (netdev);break ;case NETDEV_WATCH_EVENT_DOWN :case NETDEV_WATCH_EVENT_DEL :
src/wsc.h +19 -2
@@ -20,6 +20,11 @@* */ +struct wsc ; +struct netdev ; +struct scan_bss ; +struct iovec ; +struct wsc_credentials_info {char ssid[33 ];enum security security;
@@ -31,5 +36,17 @@ struct wsc_credentials_info {bool has_passphrase; }; -typedef void (*wsc_done_cb_t )(int err,struct wsc_credentials_info *creds, -unsigned int n_creds,void *user_data); +struct wsc_ops { +const char *(*get_path)(void *user_data); +void (*connect)(struct l_dbus_message *message,const char *pin, +void *user_data); +void (*cancel)(struct l_dbus_message *message,void *user_data); +void (*enrollee_done_cb)(int err,struct wsc_credentials_info *creds, +unsigned int n_creds,void *user_data); +}; + +struct wsc *wsc_new (const struct wsc_ops *ops,void *user_data); +void wsc_start_enrollee (struct wsc *wsc,struct netdev *netdev, +struct scan_bss *target,const char *pin); +void wsc_cancel (struct wsc *wsc,netdev_disconnect_cb_t cb); +void wsc_destroy (struct wsc *wsc);
Signature · 1 line
2.20.1
Re: [PATCH 3/4] wsc: Refactor to make the DBus interface reusable
Hi Andrew,
Quoted 13 lines · Andrew Zaborowski
Allow adding the DBus SimpleConfiguration interface on both station mode netdevs and P2P peers by putting public functions and callbacks between the DBus method handlers and their actual implementation. The implementation provides its own callbacks for each method using the
wsc_opsstruct.For patch readability I didn't move some functions in
wsc.caround and group them logically, we can do the moving separately.--- src/wsc.c | 406 ++++++++++++++++++++++++++++++++---------------------- src/wsc.h | 21 ++- 2 files changed, 263 insertions(+), 164 deletions(-)
<snip>
Quoted 71 lines
src/wsc.c +15
-15@@ -113,20 +113,20 @@ static struct l_dbus_message *wsc_error_time_expired(struct l_dbus_message *msg)"No APs in PIN mode found in " "the alloted time"); } -static void wsc_try_credentials (struct wsc *wsc) +static void wsc_try_credentials (struct wsc *wsc,struct wsc_credentials_info *creds, +unsigned int n_creds) {unsigned int i;struct network *network;struct scan_bss *bss; -for (i =0 ; i < wsc->n_creds; i++) { - network =station_network_find (wsc->station, - wsc->creds[i].ssid, - wsc->creds[i].security); +for (i =0 ; i < n_creds; i++) { + network =station_network_find (wsc->station, creds[i].ssid, + creds[i].security);if (!network)continue ; - bss =network_bss_find_by_addr (network, wsc->creds[i].addr); + bss =network_bss_find_by_addr (network, creds[i].addr);if (!bss) bss =network_bss_select (network, true);@@ -134,7 +134,7 @@ static void wsc_try_credentials(struct wsc *wsc)if (!bss)continue ; -if (wsc->creds[i].security ==SECURITY_PSK ) { +if (creds[i].security ==SECURITY_PSK ) {bool ret;/* @@ -142,12 +142,11 @@ static void wsc_try_credentials(struct wsc *wsc)* WPA2 and WPA3 since the PSK can always be generated * if needed */ -if (wsc->creds[i].has_passphrase) +if (creds[i].has_passphrase) ret =network_set_passphrase (network, - wsc->creds[i].passphrase); + creds[i].passphrase);else - ret =network_set_psk (network, - wsc->creds[i].psk); + ret =network_set_psk (network, creds[i].psk);if (!ret)continue ;@@ -166,21 +165,22 @@ static void wsc_try_credentials(struct wsc *wsc)station_set_autoconnect (wsc->station, true); } -static void wsc_store_credentials (struct wsc *wsc) +static void wsc_store_credentials (struct wsc_credentials_info *creds, +unsigned int n_creds) {unsigned int i; -for (i =0 ; i < wsc->n_creds; i++) { -enum security security = wsc->creds[i].security; -const char *ssid = wsc->creds[i].ssid; +for (i =0 ; i < n_creds; i++) { +enum security security = creds[i].security; +const char *ssid = creds[i].ssid;struct l_settings *settings =l_settings_new (); l_debug("Storing credential for '%s(%s)'", ssid,
src/wsc.c static void wsc_try_credentials(struct wsc *wsc) · line 186
Quoted 10 lines
src/wsc.c +2
-2security_to_str(security));if (security ==SECURITY_PSK ) { -char *hex =l_util_hexstring (wsc->creds[i].psk, -sizeof (wsc->creds[i].psk)); +char *hex =l_util_hexstring (creds[i].psk, +sizeof (creds[i].psk));l_settings_set_value (settings,"Security" ,"PreSharedKey" , hex);
I cherry-picked these two chunks as a separate commit.
src/wsc.c static void wsc_disconnect_cb(struct netdev *netdev, bool success, · line 215
Quoted 9 lines
src/wsc.c +0
-2@@ -210,8 +210,6 @@ static void wsc_disconnect_cb(struct netdev *netdev, bool success,l_debug ("%p, success: %d" , wsc, success); - wsc->wsc_association = false; - reply =l_dbus_message_new_method_return (wsc->pending_cancel);l_dbus_message_set_arguments (reply,"" );dbus_pending_reply (&wsc->pending_cancel, reply);
Is this chunk a straggler from some earlier refactoring? If so, then a separate patch would be desirable
<snip>
Quoted 36 lines
src/wsc.c +3
-25@@ -525,40 +523,19 @@ static void wsc_connect(struct wsc *wsc) error:handshake_state_free (hs);wsc_connect_cleanup (wsc); - wsc->done_cb (r,NULL ,0 , wsc->done_data); + wsc->ops->enrollee_done_cb (r,NULL ,0 , wsc->user_data); } -/* Done callback for when WSC is triggered by DBus methods */ -static void wsc_dbus_done_cb (int err,struct wsc_credentials_info *creds, -unsigned int n_creds,void *user_data) +static void wsc_connect_set_method (struct wsc *wsc) { -struct wsc *wsc = user_data; - -l_debug ("err=%i" , err); +const char *pin; -switch (err) { -case 0 : -break ; -case -ECANCELED : -dbus_pending_reply (&wsc->pending, -dbus_error_aborted (wsc->pending)); -return ; -case -ENOKEY : -dbus_pending_reply (&wsc->pending, -wsc_error_no_credentials (wsc->pending)); -return ; -case -EBUSY : -dbus_pending_reply (&wsc->pending, -dbus_error_busy (wsc->pending)); -return ; -default : -dbus_pending_reply (&wsc->pending, -dbus_error_failed (wsc->pending));
src/wsc.c static void wsc_connect(struct wsc *wsc) · line 538
Quoted 10 lines
src/wsc.c +5
-4-return ; - } +if (!strcmp (l_dbus_message_get_member (wsc->pending),"StartPin" )) +l_dbus_message_get_arguments (wsc->pending,"s" , &pin); +else + pin =NULL ; -wsc_store_credentials (wsc); -wsc_try_credentials (wsc); +wsc_start_enrollee (wsc, wsc->netdev, wsc->target, pin,NULL ,0 );
Is wsc_start_enrollee going to be called from p2p directly or only via the D-Bus API? This enclosing function (wsc_connect_set_method) is now quite strange looking. Maybe it'd look nicer to just set wsc->pin from inside the StartPin / PushButton handlers instead and avoid this completely?
Quoted 55 lines
src/wsc.c +6
-25}static void station_state_watch (enum station_state state,void *userdata)@@ -573,7 +550,7 @@ static void station_state_watch(enum station_state state, void *userdata)station_remove_state_watch (wsc->station, wsc->station_state_watch); wsc->station_state_watch =0 ; -wsc_connect (wsc); +wsc_connect_set_method (wsc); }static void wsc_check_can_connect (struct wsc *wsc,struct scan_bss *target)@@ -587,25 +564,9 @@ static void wsc_check_can_connect(struct wsc *wsc, struct scan_bss *target) wsc->target = target;station_set_autoconnect (wsc->station, false); -if (!strcmp (l_dbus_message_get_member (wsc->pending),"StartPin" )) { -char *pin; - - wsc->config_method =WSC_CONFIGURATION_METHOD_KEYPAD ; - -if (!l_dbus_message_get_arguments (wsc->pending,"s" , &pin)) - goto error; - - wsc->pin =l_strdup (pin); - }else - wsc->config_method = -WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON ; - - wsc->done_cb = wsc_dbus_done_cb; - wsc->done_data = wsc; -switch (station_get_state (wsc->station)) {case STATION_STATE_DISCONNECTED : -wsc_connect (wsc); +wsc_connect_set_method (wsc);return ;case STATION_STATE_CONNECTING :case STATION_STATE_CONNECTED :@@ -652,20 +613,13 @@ static void walk_timeout(struct l_timeout *timeout, void *user_data)wsc_cancel_scan (wsc); -if (wsc->pending) -dbus_pending_reply (&wsc->pending, -wsc_error_walk_time_expired (wsc->pending)); -} +if (wsc->pending) { +struct l_dbus_message *reply = wsc->pin ? +wsc_error_time_expired (wsc->pending) : +wsc_error_walk_time_expired (wsc->pending); -static void pin_timeout (struct l_timeout *timeout,void *user_data) -{ -struct wsc *wsc = user_data;
src/wsc.c static void walk_timeout(struct l_timeout *timeout, void *user_data) · line 624
Quoted 10 lines
src/wsc.c +2
-6- -wsc_cancel_scan (wsc); - -if (wsc->pending) -dbus_pending_reply (&wsc->pending, -wsc_error_time_expired (wsc->pending)); +dbus_pending_reply (&wsc->pending, reply); + } }
Okay, but this really belongs as a separate patch
src/wsc.c static struct l_dbus_message *wsc_push_button(struct l_dbus *dbus, · line 1006
Quoted 8 lines
src/wsc.c +0
-3static bool push_button_scan_results(int err, struct l_queue *bss_list,@@ -1001,20 +955,7 @@ static struct l_dbus_message *wsc_push_button(struct l_dbus *dbus,l_debug ("" ); -if (wsc->pending) -return dbus_error_busy (message); -
So why would you move this check out into the ops provided operation and not keep it here?
src/wsc.c static struct l_dbus_message *wsc_push_button(struct l_dbus *dbus, · line 1017
Quoted 11 lines
src/wsc.c +0
-11- wsc->station =station_find (netdev_get_ifindex (wsc->netdev)); -if (!wsc->station) -return dbus_error_not_available (message); - -if (!wsc_initiate_scan (wsc,WSC_DEVICE_PASSWORD_ID_PUSH_BUTTON , - push_button_scan_results)) -return dbus_error_failed (message); - - wsc->walk_timer =l_timeout_create (WALK_TIME , walk_timeout, wsc,NULL ); - wsc->pending =l_dbus_message_ref (message); -
Pending tracking should also likely be managed here...
Quoted 5 lines
src/wsc.c +1
-0+ wsc->ops->connect (message,NULL , wsc->user_data);return NULL ; }
src/wsc.c static struct l_dbus_message *wsc_start_pin(struct l_dbus *dbus, · line 1054
Quoted 9 lines
src/wsc.c +0
-3@@ -1046,77 +987,29 @@ static struct l_dbus_message *wsc_start_pin(struct l_dbus *dbus, {struct wsc *wsc = user_data;const char *pin; -enum wsc_device_password_id dpid;l_debug ("" ); -if (wsc->pending) -return dbus_error_busy (message);
Same comments as above apply here ...
Quoted 85 lines
src/wsc.c +5
-50- - wsc->station =station_find (netdev_get_ifindex (wsc->netdev)); -if (!wsc->station) -return dbus_error_not_available (message); -if (!l_dbus_message_get_arguments (message,"s" , &pin))return dbus_error_invalid_args (message);if (!wsc_pin_is_valid (pin))return dbus_error_invalid_format (message); -if (strlen (pin) ==4 ||wsc_pin_is_checksum_valid (pin)) - dpid =WSC_DEVICE_PASSWORD_ID_DEFAULT ; -else - dpid =WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED ; - -if (!wsc_initiate_scan (wsc, dpid, pin_scan_results)) -return dbus_error_failed (message); - - wsc->walk_timer =l_timeout_create (60 , pin_timeout, wsc,NULL ); - wsc->pending =l_dbus_message_ref (message); - + wsc->ops->connect (message, pin, wsc->user_data);return NULL ; } -static struct l_dbus_message *wsc_cancel (struct l_dbus *dbus, +static struct l_dbus_message *wsc_dbus_cancel (struct l_dbus *dbus,struct l_dbus_message *message,void *user_data) {struct wsc *wsc = user_data; -struct l_dbus_message *reply;l_debug ("" ); -if (!wsc->pending) -return dbus_error_not_available (message); - -wsc_cancel_scan (wsc); - -if (wsc->station_state_watch) { -station_remove_state_watch (wsc->station, - wsc->station_state_watch); - wsc->station_state_watch =0 ; - wsc->target =NULL ; - } - -if (wsc->wsc_association) { -int r; - - r =netdev_disconnect (wsc->netdev, wsc_disconnect_cb, wsc); -if (r ==0 ) { - wsc->pending_cancel =l_dbus_message_ref (message); -return NULL ; - } - -l_warn ("Unable to initiate disconnect: %s" ,strerror (-r)); - wsc->wsc_association = false; - } - -dbus_pending_reply (&wsc->pending,dbus_error_aborted (wsc->pending)); - - reply =l_dbus_message_new_method_return (message); -l_dbus_message_set_arguments (reply,"" ); - -return reply; + wsc->ops->cancel (message, wsc->user_data); +return NULL ; }static void setup_wsc_interface (struct l_dbus_interface *interface)@@ -1128,7 +1021,7 @@ static void setup_wsc_interface(struct l_dbus_interface *interface)l_dbus_interface_method (interface,"StartPin" ,0 , wsc_start_pin,"" ,"s" ,"pin" );l_dbus_interface_method (interface,"Cancel" ,0 , - wsc_cancel,"" ,"" ); + wsc_dbus_cancel,"" ,"" ); }static void wsc_free (void *userdata)@@ -1155,7 +1048,194 @@ static void wsc_free(void *userdata)l_free (wsc); }
src/wsc.c static void wsc_free(void *userdata) · line 1059
Quoted 10 lines
src/wsc.c +9
-1-static void wsc_add_interface (struct netdev *netdev) +struct wsc *wsc_new (const struct wsc_ops *ops,void *user_data) +{ +struct l_dbus *dbus =dbus_get_bus (); +struct wsc *wsc; +const char *path; + + wsc = l_new(struct wsc, 1); + wsc->ops = ops; + wsc->user_data = user_data;
This part seems rather weird
Quoted 110 lines
src/wsc.c +110
-0+ + path = wsc->ops->get_path (wsc->user_data); +if (!path) +return wsc; + +if (l_dbus_object_add_interface (dbus, path,IWD_WSC_INTERFACE , wsc)) +return wsc; + +wsc_free (wsc); +l_info ("Unable to register interface %s at %s" ,IWD_WSC_INTERFACE , + path); +return NULL ; +} + +void wsc_destroy (struct wsc *wsc) +{ +l_dbus_object_remove_interface (dbus_get_bus (), + wsc->ops->get_path (wsc->user_data), +IWD_WSC_INTERFACE ); +} + +void wsc_start_enrollee (struct wsc *wsc,struct netdev *netdev, +struct scan_bss *target,const char *pin) +{ + wsc->netdev = netdev; + wsc->target = target; + wsc->config_method = pin ?WSC_CONFIGURATION_METHOD_KEYPAD : +WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON ; + wsc->pin =l_strdup (pin); + +wsc_connect (wsc); +} + +void wsc_cancel (struct wsc *wsc,netdev_disconnect_cb_t cb) +{ +int r; + +if (!wsc->wsc_association) +return ; + + r =netdev_disconnect (wsc->netdev, cb, wsc->user_data); +if (r ==0 ) +return ; + +l_warn ("Unable to initiate disconnect: %s" ,strerror (-r)); +wsc_connect_cleanup (wsc); + wsc->ops->enrollee_done_cb (-ECANCELED ,NULL ,0 , wsc->user_data); + +if (cb) +cb (wsc->netdev, false, wsc->user_data); +} + +static const char *wsc_device_get_path (void *user_data) +{ +struct wsc *wsc = user_data; + +if (!wsc || !wsc->netdev) +return NULL ; + +return netdev_get_path (wsc->netdev); +} + +static void wsc_device_connect (struct l_dbus_message *message,const char *pin, +void *user_data) +{ +struct wsc *wsc = user_data; +struct l_dbus *dbus =dbus_get_bus (); +unsigned int walk_time; +enum wsc_device_password_id dpid; +scan_notify_func_t results_cb; + +if (wsc->pending) { +l_dbus_send (dbus,dbus_error_busy (message)); +return ; + } + + wsc->station =station_find (netdev_get_ifindex (wsc->netdev)); +if (!wsc->station) { +l_dbus_send (dbus,dbus_error_not_available (message)); +return ; + } + +if (pin) { +if (strlen (pin) ==4 ||wsc_pin_is_checksum_valid (pin)) + dpid =WSC_DEVICE_PASSWORD_ID_DEFAULT ; +else + dpid =WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED ; + + walk_time =60 ; + results_cb = pin_scan_results; + }else { + dpid =WSC_DEVICE_PASSWORD_ID_PUSH_BUTTON ; + walk_time =WALK_TIME ; + results_cb = push_button_scan_results; + } + +if (!wsc_initiate_scan (wsc, dpid, results_cb)) { +l_dbus_send (dbus,dbus_error_failed (message)); +return ; + } + + wsc->walk_timer =l_timeout_create (walk_time, walk_timeout, wsc,NULL ); + wsc->pending =l_dbus_message_ref (message); +} + +static void wsc_device_cancel (struct l_dbus_message *message,void *user_data) +{ +struct wsc *wsc = user_data; +struct l_dbus *dbus =dbus_get_bus (); +
src/wsc.c static void wsc_free(void *userdata) · line 1179
Quoted 10 lines
src/wsc.c +10
-0+if (!wsc->pending) { +l_dbus_send (dbus,dbus_error_not_available (message)); +return ; + } + +if (wsc->pending_cancel) { +l_dbus_send (dbus,dbus_error_busy (message)); +return ; + } +
As mentioned before, this doesn't seem like it belongs in the op itself but in the higher layer...
Quoted 7 lines
src/wsc.c +7
-0+wsc_cancel_scan (wsc); + +if (wsc->station_state_watch) { +station_remove_state_watch (wsc->station, + wsc->station_state_watch); + wsc->station_state_watch =0 ; + wsc->target =NULL ;
src/wsc.c static void wsc_free(void *userdata) · line 1196
Quoted 10 lines
src/wsc.c +10
-0+ } + +if (wsc->wsc_association) { + wsc->pending_cancel =l_dbus_message_ref (message); +wsc_cancel (wsc, wsc_disconnect_cb); +return ; + } + +dbus_pending_reply (&wsc->pending,dbus_error_aborted (wsc->pending)); +l_dbus_send (dbus,l_dbus_message_new_method_return (message));
As is this...
Quoted 57 lines
src/wsc.c +44
-4+} + +static void wsc_device_enrollee_done (int err,struct wsc_credentials_info *creds, +unsigned int n_creds,void *user_data) +{ +struct wsc *wsc = user_data; + +l_debug ("err=%i" , err); + +switch (err) { +case 0 : +break ; +case -ECANCELED : +dbus_pending_reply (&wsc->pending, +dbus_error_aborted (wsc->pending)); +return ; +case -ENOKEY : +dbus_pending_reply (&wsc->pending, +wsc_error_no_credentials (wsc->pending)); +return ; +case -EBUSY : +dbus_pending_reply (&wsc->pending, +dbus_error_busy (wsc->pending)); +return ; +default : +dbus_pending_reply (&wsc->pending, +dbus_error_failed (wsc->pending)); +return ; + } + +wsc_store_credentials (creds, n_creds); +wsc_try_credentials (wsc, creds, n_creds); +} + +static const struct wsc_ops wsc_device_ops = { + .get_path = wsc_device_get_path, + .connect = wsc_device_connect, + .cancel = wsc_device_cancel, + .enrollee_done_cb = wsc_device_enrollee_done, +}; + +static void wsc_device_new (struct netdev *netdev) {struct l_dbus *dbus =dbus_get_bus ();struct wsc *wsc;@@ -1167,15 +1247,17 @@ static void wsc_add_interface(struct netdev *netdev)return ; } - wsc = l_new(struct wsc, 1); + wsc =wsc_new (&wsc_device_ops,NULL ); + wsc->user_data = wsc; wsc->netdev = netdev; -if (!l_dbus_object_add_interface (dbus,netdev_get_path (netdev), -IWD_WSC_INTERFACE , - wsc)) {
src/wsc.c static void wsc_add_interface(struct netdev *netdev) · line 1260
Quoted 10 lines
src/wsc.c +7
-3-wsc_free (wsc); -l_info ("Unable to register %s interface" ,IWD_WSC_INTERFACE ); - } +if (l_dbus_object_add_interface (dbus,netdev_get_path (netdev), +IWD_WSC_INTERFACE , wsc)) +return ; + +wsc_free (wsc); +l_info ("Unable to register interface %s at %s" ,IWD_WSC_INTERFACE , +netdev_get_path (netdev));
This logic flipping seems gratuitous, I'd just leave it the way it was...
Quoted 31 lines
src/wsc.c +1
-1}static void wsc_remove_interface (struct netdev *netdev)@@ -1194,7 +1276,7 @@ static void wsc_netdev_watch(struct netdev *netdev,case NETDEV_WATCH_EVENT_NEW :if (netdev_get_iftype (netdev) ==NETDEV_IFTYPE_STATION &&netdev_get_is_up (netdev)) -wsc_add_interface (netdev); +wsc_device_new (netdev);break ;case NETDEV_WATCH_EVENT_DOWN :case NETDEV_WATCH_EVENT_DEL :src/wsc.h +5
-0@@ -20,6 +20,11 @@* */ +struct wsc ; +struct netdev ; +struct scan_bss ; +struct iovec ; +struct wsc_credentials_info {char ssid[33 ];enum security security;@@ -31,5 +36,17 @@ struct wsc_credentials_info {bool has_passphrase; };
src/wsc.h struct wsc_credentials_info { · line 45
Quoted 10 lines
src/wsc.h +7
-2-typedef void (*wsc_done_cb_t )(int err,struct wsc_credentials_info *creds, -unsigned int n_creds,void *user_data); +struct wsc_ops { +const char *(*get_path)(void *user_data); +void (*connect)(struct l_dbus_message *message,const char *pin, +void *user_data); +void (*cancel)(struct l_dbus_message *message,void *user_data); +void (*enrollee_done_cb)(int err,struct wsc_credentials_info *creds, +unsigned int n_creds,void *user_data);
So one thing I find very weird about this setup is the fact that you're mixing operations with a callback in something called 'wsc_ops'. Can't your 'connect' operation simply set the callback or perhaps provide the callback directly to wsc_start_enrollee?
src/wsc.h struct wsc_credentials_info { · line 52
Quoted 8 lines
src/wsc.h +7
-0+}; + +struct wsc *wsc_new (const struct wsc_ops *ops,void *user_data); +void wsc_start_enrollee (struct wsc *wsc,struct netdev *netdev, +struct scan_bss *target,const char *pin); +void wsc_cancel (struct wsc *wsc,netdev_disconnect_cb_t cb); +void wsc_destroy (struct wsc *wsc);
Regards,
-Denis
Re: [PATCH 3/4] wsc: Refactor to make the DBus interface reusable
Quoted 5 lines · Denis Kenzior
Quoted 4 lines · Andrew Zaborowski
src/wsc.c +0
-0@@ -210,8 +210,6 @@ static void wsc_disconnect_cb(struct netdev *netdev, bool success,l_debug ("%p, success: %d" , wsc, success);
Quoted 8 lines
src/wsc.c static void wsc_disconnect_cb(struct netdev *netdev, bool success, · line 215
Quoted 5 lines
src/wsc.c +0
-2- wsc->wsc_association = false; - reply =l_dbus_message_new_method_return (wsc->pending_cancel);l_dbus_message_set_arguments (reply,"" );dbus_pending_reply (&wsc->pending_cancel, reply);Is this chunk a straggler from some earlier refactoring? If so, then a separate patch would be desirable
So in the new setup we have parts of wsc.c that are common between the Station mode use case and the external user use case (i.e. P2P), and then we have parts that are relevant to Station mode only. We sort of have 3 parts:
1. the core part that sets up the EAP method config, starts the connection and receives the credentials.
2. the DBus interface that lives even when we're not doing WSC (also common to both modes now)
3. the Station-specific code which interfaces between 1. and 2. and does the scanning etc., i.e. everything used by @wsc_device_ops
wsc_disconnect_cb belongs in 3., while wsc->wsc_association belongs in
2. so wsc_disconnect_cb shouldn't be touching wsc->wsc_association. It's being set to false in wsc_connect_cleanup which now gets called from wsc_cancel before wsc_disconnect_cb. I think that the netdev_disconnect call also triggers an immediate wsc_connect_cb callback which also calls wsc_connect_cleanup, so wsc->wsc_association would have been always false.
Quoted 46 lines
<snip>
Quoted 43 lines
src/wsc.c +7
-27@@ -525,40 +523,19 @@ static void wsc_connect(struct wsc *wsc) error:handshake_state_free (hs);wsc_connect_cleanup (wsc); - wsc->done_cb (r,NULL ,0 , wsc->done_data); + wsc->ops->enrollee_done_cb (r,NULL ,0 , wsc->user_data); } -/* Done callback for when WSC is triggered by DBus methods */ -static void wsc_dbus_done_cb (int err,struct wsc_credentials_info *creds, -unsigned int n_creds,void *user_data) +static void wsc_connect_set_method (struct wsc *wsc) { -struct wsc *wsc = user_data; - -l_debug ("err=%i" , err); +const char *pin; -switch (err) { -case 0 : -break ; -case -ECANCELED : -dbus_pending_reply (&wsc->pending, -dbus_error_aborted (wsc->pending)); -return ; -case -ENOKEY : -dbus_pending_reply (&wsc->pending, -wsc_error_no_credentials (wsc->pending)); -return ; -case -EBUSY : -dbus_pending_reply (&wsc->pending, -dbus_error_busy (wsc->pending)); -return ; -default : -dbus_pending_reply (&wsc->pending, -dbus_error_failed (wsc->pending)); -return ; - } +if (!strcmp (l_dbus_message_get_member (wsc->pending),"StartPin" )) +l_dbus_message_get_arguments (wsc->pending,"s" , &pin); +else + pin =NULL ;
Quoted 6 lines
src/wsc.c static void wsc_connect(struct wsc *wsc) · line 538
Quoted 3 lines
src/wsc.c +1
-2-wsc_store_credentials (wsc); -wsc_try_credentials (wsc); +wsc_start_enrollee (wsc, wsc->netdev, wsc->target, pin,NULL ,0 );Is
wsc_start_enrolleegoing to be called from p2p directly or only via the D-Bus API?
So the D-Bus API will call the P2P code (to do GO Negotiation / Provision Discovery etc.) or the station-specific code inside wsc.c (to do the scanning) and they'll both call wsc_start_enrollee when ready. wsc_connect_set_method is the station-specific code path where this happens.
Quoted 3 lines
This enclosing function (
wsc_connect_set_method) is now
quite strange looking. Maybe it'd look nicer to just setwsc->pinfrom inside the StartPin / PushButton handlers instead and avoid this completely?
Well I can do this. I preferred to keep the parts 1. and 2. of the code independent (e.g. for scenarios like auto-connecting to some P2P devices in the future) but it makes little differnce.
I notice the way git formatted this patch makes it hard to read.
Quoted 53 lines
Quoted 53 lines
src/wsc.c +6
-22}static void station_state_watch (enum station_state state,void *userdata)@@ -573,7 +550,7 @@ static void station_state_watch(enum station_state state, void *userdata)station_remove_state_watch (wsc->station, wsc->station_state_watch); wsc->station_state_watch =0 ; -wsc_connect (wsc); +wsc_connect_set_method (wsc); }static void wsc_check_can_connect (struct wsc *wsc,struct scan_bss *target)@@ -587,25 +564,9 @@ static void wsc_check_can_connect(struct wsc *wsc, struct scan_bss *target) wsc->target = target;station_set_autoconnect (wsc->station, false); -if (!strcmp (l_dbus_message_get_member (wsc->pending),"StartPin" )) { -char *pin; - - wsc->config_method =WSC_CONFIGURATION_METHOD_KEYPAD ; - -if (!l_dbus_message_get_arguments (wsc->pending,"s" , &pin)) - goto error; - - wsc->pin =l_strdup (pin); - }else - wsc->config_method = -WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON ; - - wsc->done_cb = wsc_dbus_done_cb; - wsc->done_data = wsc; -switch (station_get_state (wsc->station)) {case STATION_STATE_DISCONNECTED : -wsc_connect (wsc); +wsc_connect_set_method (wsc);return ;case STATION_STATE_CONNECTING :case STATION_STATE_CONNECTED :@@ -652,20 +613,13 @@ static void walk_timeout(struct l_timeout *timeout, void *user_data)wsc_cancel_scan (wsc); -if (wsc->pending) -dbus_pending_reply (&wsc->pending, -wsc_error_walk_time_expired (wsc->pending)); -} +if (wsc->pending) { +struct l_dbus_message *reply = wsc->pin ? +wsc_error_time_expired (wsc->pending) : +wsc_error_walk_time_expired (wsc->pending);
Quoted 15 lines
src/wsc.c static void walk_timeout(struct l_timeout *timeout, void *user_data) · line 624
Quoted 13 lines
src/wsc.c +2
-9-static void pin_timeout (struct l_timeout *timeout,void *user_data) -{ -struct wsc *wsc = user_data; - -wsc_cancel_scan (wsc); - -if (wsc->pending) -dbus_pending_reply (&wsc->pending, -wsc_error_time_expired (wsc->pending)); +dbus_pending_reply (&wsc->pending, reply); + } }Okay, but this really belongs as a separate patch
Ok.
Quoted 13 lines
src/wsc.c static struct l_dbus_message *wsc_push_button(struct l_dbus *dbus, · line 1006
Quoted 9 lines
src/wsc.c +0
-3static bool push_button_scan_results(int err, struct l_queue *bss_list,@@ -1001,20 +955,7 @@ static struct l_dbus_message *wsc_push_button(struct l_dbus *dbus,l_debug ("" ); -if (wsc->pending) -return dbus_error_busy (message); -So why would you move this check out into the ops provided operation and not keep it here?
...
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +0
-2- wsc->pending = l_dbus_message_ref(message); -Pending tracking should also likely be managed here...
...
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +0
-2- if (wsc->pending) - return dbus_error_busy(message);Same comments as above apply here ...
For one, in the P2P case, it's not going to have access to the internals of struct wsc, so if P2P replies with success or an error message to the PushButton call, it would need some way to also clear wsc->pending. That's doable but it seems simpler to leave full control to the actual implementation. So my idea in this version was that the DBus handlers would be really simple and stateless.
Also remember that in the P2P case the PushButton method will kick off the connection process but there's a few different steps and WSC is just one of them and might be skipped completely in some scenarios.
Quoted 86 lines
Quoted 86 lines
src/wsc.c +5
-50- - wsc->station =station_find (netdev_get_ifindex (wsc->netdev)); -if (!wsc->station) -return dbus_error_not_available (message); -if (!l_dbus_message_get_arguments (message,"s" , &pin))return dbus_error_invalid_args (message);if (!wsc_pin_is_valid (pin))return dbus_error_invalid_format (message); -if (strlen (pin) ==4 ||wsc_pin_is_checksum_valid (pin)) - dpid =WSC_DEVICE_PASSWORD_ID_DEFAULT ; -else - dpid =WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED ; - -if (!wsc_initiate_scan (wsc, dpid, pin_scan_results)) -return dbus_error_failed (message); - - wsc->walk_timer =l_timeout_create (60 , pin_timeout, wsc,NULL ); - wsc->pending =l_dbus_message_ref (message); - + wsc->ops->connect (message, pin, wsc->user_data);return NULL ; } -static struct l_dbus_message *wsc_cancel (struct l_dbus *dbus, +static struct l_dbus_message *wsc_dbus_cancel (struct l_dbus *dbus,struct l_dbus_message *message,void *user_data) {struct wsc *wsc = user_data; -struct l_dbus_message *reply;l_debug ("" ); -if (!wsc->pending) -return dbus_error_not_available (message); - -wsc_cancel_scan (wsc); - -if (wsc->station_state_watch) { -station_remove_state_watch (wsc->station, - wsc->station_state_watch); - wsc->station_state_watch =0 ; - wsc->target =NULL ; - } - -if (wsc->wsc_association) { -int r; - - r =netdev_disconnect (wsc->netdev, wsc_disconnect_cb, wsc); -if (r ==0 ) { - wsc->pending_cancel =l_dbus_message_ref (message); -return NULL ; - } - -l_warn ("Unable to initiate disconnect: %s" ,strerror (-r)); - wsc->wsc_association = false; - } - -dbus_pending_reply (&wsc->pending,dbus_error_aborted (wsc->pending)); - - reply =l_dbus_message_new_method_return (message); -l_dbus_message_set_arguments (reply,"" ); - -return reply; + wsc->ops->cancel (message, wsc->user_data); +return NULL ; }static void setup_wsc_interface (struct l_dbus_interface *interface)@@ -1128,7 +1021,7 @@ static void setup_wsc_interface(struct l_dbus_interface *interface)l_dbus_interface_method (interface,"StartPin" ,0 , wsc_start_pin,"" ,"s" ,"pin" );l_dbus_interface_method (interface,"Cancel" ,0 , - wsc_cancel,"" ,"" ); + wsc_dbus_cancel,"" ,"" ); }static void wsc_free (void *userdata)@@ -1155,7 +1048,194 @@ static void wsc_free(void *userdata)l_free (wsc); }
Quoted 12 lines
src/wsc.c static void wsc_free(void *userdata) · line 1059
Quoted 10 lines
src/wsc.c +9
-1-static void wsc_add_interface (struct netdev *netdev) +struct wsc *wsc_new (const struct wsc_ops *ops,void *user_data) +{ +struct l_dbus *dbus =dbus_get_bus (); +struct wsc *wsc; +const char *path; + + wsc = l_new(struct wsc, 1); + wsc->ops = ops; + wsc->user_data = user_data;This part seems rather weird
Do you mean the whole function? and why?
Quoted 199 lines
Quoted 111 lines
src/wsc.c +110
-0+ + path = wsc->ops->get_path (wsc->user_data); +if (!path) +return wsc; + +if (l_dbus_object_add_interface (dbus, path,IWD_WSC_INTERFACE , wsc)) +return wsc; + +wsc_free (wsc); +l_info ("Unable to register interface %s at %s" ,IWD_WSC_INTERFACE , + path); +return NULL ; +} + +void wsc_destroy (struct wsc *wsc) +{ +l_dbus_object_remove_interface (dbus_get_bus (), + wsc->ops->get_path (wsc->user_data), +IWD_WSC_INTERFACE ); +} + +void wsc_start_enrollee (struct wsc *wsc,struct netdev *netdev, +struct scan_bss *target,const char *pin) +{ + wsc->netdev = netdev; + wsc->target = target; + wsc->config_method = pin ?WSC_CONFIGURATION_METHOD_KEYPAD : +WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON ; + wsc->pin =l_strdup (pin); + +wsc_connect (wsc); +} + +void wsc_cancel (struct wsc *wsc,netdev_disconnect_cb_t cb) +{ +int r; + +if (!wsc->wsc_association) +return ; + + r =netdev_disconnect (wsc->netdev, cb, wsc->user_data); +if (r ==0 ) +return ; + +l_warn ("Unable to initiate disconnect: %s" ,strerror (-r)); +wsc_connect_cleanup (wsc); + wsc->ops->enrollee_done_cb (-ECANCELED ,NULL ,0 , wsc->user_data); + +if (cb) +cb (wsc->netdev, false, wsc->user_data); +} + +static const char *wsc_device_get_path (void *user_data) +{ +struct wsc *wsc = user_data; + +if (!wsc || !wsc->netdev) +return NULL ; + +return netdev_get_path (wsc->netdev); +} + +static void wsc_device_connect (struct l_dbus_message *message,const char *pin, +void *user_data) +{ +struct wsc *wsc = user_data; +struct l_dbus *dbus =dbus_get_bus (); +unsigned int walk_time; +enum wsc_device_password_id dpid; +scan_notify_func_t results_cb; + +if (wsc->pending) { +l_dbus_send (dbus,dbus_error_busy (message)); +return ; + } + + wsc->station =station_find (netdev_get_ifindex (wsc->netdev)); +if (!wsc->station) { +l_dbus_send (dbus,dbus_error_not_available (message)); +return ; + } + +if (pin) { +if (strlen (pin) ==4 ||wsc_pin_is_checksum_valid (pin)) + dpid =WSC_DEVICE_PASSWORD_ID_DEFAULT ; +else + dpid =WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED ; + + walk_time =60 ; + results_cb = pin_scan_results; + }else { + dpid =WSC_DEVICE_PASSWORD_ID_PUSH_BUTTON ; + walk_time =WALK_TIME ; + results_cb = push_button_scan_results; + } + +if (!wsc_initiate_scan (wsc, dpid, results_cb)) { +l_dbus_send (dbus,dbus_error_failed (message)); +return ; + } + + wsc->walk_timer =l_timeout_create (walk_time, walk_timeout, wsc,NULL ); + wsc->pending =l_dbus_message_ref (message); +} + +static void wsc_device_cancel (struct l_dbus_message *message,void *user_data) +{ +struct wsc *wsc = user_data; +struct l_dbus *dbus =dbus_get_bus (); +src/wsc.c static void wsc_free(void *userdata) · line 1179
Quoted 10 lines
src/wsc.c +10
-0+if (!wsc->pending) { +l_dbus_send (dbus,dbus_error_not_available (message)); +return ; + } + +if (wsc->pending_cancel) { +l_dbus_send (dbus,dbus_error_busy (message)); +return ; + } +As mentioned before, this doesn't seem like it belongs in the op itself but in the higher layer...
Quoted 7 lines
src/wsc.c +7
-0+wsc_cancel_scan (wsc); + +if (wsc->station_state_watch) { +station_remove_state_watch (wsc->station, + wsc->station_state_watch); + wsc->station_state_watch =0 ; + wsc->target =NULL ;src/wsc.c static void wsc_free(void *userdata) · line 1196
Quoted 10 lines
src/wsc.c +10
-0+ } + +if (wsc->wsc_association) { + wsc->pending_cancel =l_dbus_message_ref (message); +wsc_cancel (wsc, wsc_disconnect_cb); +return ; + } + +dbus_pending_reply (&wsc->pending,dbus_error_aborted (wsc->pending)); +l_dbus_send (dbus,l_dbus_message_new_method_return (message));As is this...
Quoted 54 lines
src/wsc.c +44
-1+} + +static void wsc_device_enrollee_done (int err,struct wsc_credentials_info *creds, +unsigned int n_creds,void *user_data) +{ +struct wsc *wsc = user_data; + +l_debug ("err=%i" , err); + +switch (err) { +case 0 : +break ; +case -ECANCELED : +dbus_pending_reply (&wsc->pending, +dbus_error_aborted (wsc->pending)); +return ; +case -ENOKEY : +dbus_pending_reply (&wsc->pending, +wsc_error_no_credentials (wsc->pending)); +return ; +case -EBUSY : +dbus_pending_reply (&wsc->pending, +dbus_error_busy (wsc->pending)); +return ; +default : +dbus_pending_reply (&wsc->pending, +dbus_error_failed (wsc->pending)); +return ; + } + +wsc_store_credentials (creds, n_creds); +wsc_try_credentials (wsc, creds, n_creds); +} + +static const struct wsc_ops wsc_device_ops = { + .get_path = wsc_device_get_path, + .connect = wsc_device_connect, + .cancel = wsc_device_cancel, + .enrollee_done_cb = wsc_device_enrollee_done, +}; + +static void wsc_device_new (struct netdev *netdev) {struct l_dbus *dbus =dbus_get_bus ();struct wsc *wsc;@@ -1167,15 +1247,17 @@ static void wsc_add_interface(struct netdev *netdev)return ; } - wsc = l_new(struct wsc, 1); + wsc =wsc_new (&wsc_device_ops,NULL ); + wsc->user_data = wsc; wsc->netdev = netdev;
Quoted 15 lines
src/wsc.c static void wsc_add_interface(struct netdev *netdev) · line 1260
Quoted 13 lines
src/wsc.c +7
-6-if (!l_dbus_object_add_interface (dbus,netdev_get_path (netdev), -IWD_WSC_INTERFACE , - wsc)) { -wsc_free (wsc); -l_info ("Unable to register %s interface" ,IWD_WSC_INTERFACE ); - } +if (l_dbus_object_add_interface (dbus,netdev_get_path (netdev), +IWD_WSC_INTERFACE , wsc)) +return ; + +wsc_free (wsc); +l_info ("Unable to register interface %s at %s" ,IWD_WSC_INTERFACE , +netdev_get_path (netdev));This logic flipping seems gratuitous, I'd just leave it the way it was...
Ok.
Quoted 33 lines
Quoted 33 lines
src/wsc.c +1
-1}static void wsc_remove_interface (struct netdev *netdev)@@ -1194,7 +1276,7 @@ static void wsc_netdev_watch(struct netdev *netdev,case NETDEV_WATCH_EVENT_NEW :if (netdev_get_iftype (netdev) ==NETDEV_IFTYPE_STATION &&netdev_get_is_up (netdev)) -wsc_add_interface (netdev); +wsc_device_new (netdev);break ;case NETDEV_WATCH_EVENT_DOWN :case NETDEV_WATCH_EVENT_DEL :src/wsc.h +5
-0@@ -20,6 +20,11 @@* */ +struct wsc ; +struct netdev ; +struct scan_bss ; +struct iovec ; +struct wsc_credentials_info {char ssid[33 ];enum security security;@@ -31,5 +36,17 @@ struct wsc_credentials_info {bool has_passphrase; };
Quoted 14 lines
src/wsc.h struct wsc_credentials_info { · line 45
Quoted 9 lines
src/wsc.h +7
-2-typedef void (*wsc_done_cb_t )(int err,struct wsc_credentials_info *creds, -unsigned int n_creds,void *user_data); +struct wsc_ops { +const char *(*get_path)(void *user_data); +void (*connect)(struct l_dbus_message *message,const char *pin, +void *user_data); +void (*cancel)(struct l_dbus_message *message,void *user_data); +void (*enrollee_done_cb)(int err,struct wsc_credentials_info *creds, +unsigned int n_creds,void *user_data);So one thing I find very weird about this setup is the fact that you're mixing operations with a callback in something called '
wsc_ops'. Can't your 'connect' operation simply set the callback or perhaps provide the callback directly towsc_start_enrollee?
It would work equally well, yes. Maybe I was being lazy, I'll fix this.
One argument for keeping all the callbacks in this struct is that they implicitly use the same "user_data" and so we save both the callback parameter to wsc_start_enrollee, the user_data parameter (we often complained about our functions having too many arguments) and 2 fields in struct wsc for storing these two parameters.
Best regards
Re: [PATCH 3/4] wsc: Refactor to make the DBus interface reusable
Hi Andrew,
Quoted 27 lines · Andrew Zaborowski
Quoted 5 lines · Denis Kenzior
Quoted 4 lines · Andrew Zaborowski
src/wsc.c +0
-0@@ -210,8 +210,6 @@ static void wsc_disconnect_cb(struct netdev *netdev, bool success,l_debug ("%p, success: %d" , wsc, success);Quoted 8 lines
src/wsc.c static void wsc_disconnect_cb(struct netdev *netdev, bool success, · line 215
Quoted 5 lines
src/wsc.c +0
-2- wsc->wsc_association = false; - reply =l_dbus_message_new_method_return (wsc->pending_cancel);l_dbus_message_set_arguments (reply,"" );dbus_pending_reply (&wsc->pending_cancel, reply);Is this chunk a straggler from some earlier refactoring? If so, then a separate patch would be desirable
So in the new setup we have parts of
wsc.cthat are common between the Station mode use case and the external user use case (i.e. P2P), and then we have parts that are relevant to Station mode only. We sort of have 3 parts:1. the core part that sets up the EAP method config, starts the connection and receives the credentials.
2. the DBus interface that lives even when we're not doing WSC (also common to both modes now)
3. the Station-specific code which interfaces between 1. and 2. and does the scanning etc., i.e. everything used by @wsc_device_ops
Quoted 2 lines
wsc_disconnect_cbbelongs in 3., whilewsc->wsc_associationbelongs in
2. sowsc_disconnect_cbshouldn't be touchingwsc->wsc_association.
Not quite sure I follow. wsc_disconnect_cb is called when cancel is invoked via D-Bus API (or in your proposal it would be invoked via wsc_cancel). wsc->association tracks whether we have a connection established for the purposes of EAP-WSC. Hence if wsc->association is true, we have to disconnect it first. I see these two as inherently linked?
Quoted 5 lines
It's being set to false in
wsc_connect_cleanupwhich now gets called fromwsc_cancelbeforewsc_disconnect_cb. I think that thenetdev_disconnectcall also triggers an immediatewsc_connect_cbcallback which also callswsc_connect_cleanup, sowsc->wsc_associationwould have been always false.
Right. The intent was for connect callback to be called with aborted or whatever and have that clean up the state. You end up calling wsc_connect_cleanup multiple times. This is probably okay, but seems unnecessary.
Quoted 54 lines
Quoted 47 lines
<snip>
Quoted 43 lines
src/wsc.c +7
-27@@ -525,40 +523,19 @@ static void wsc_connect(struct wsc *wsc) error:handshake_state_free (hs);wsc_connect_cleanup (wsc); - wsc->done_cb (r,NULL ,0 , wsc->done_data); + wsc->ops->enrollee_done_cb (r,NULL ,0 , wsc->user_data); } -/* Done callback for when WSC is triggered by DBus methods */ -static void wsc_dbus_done_cb (int err,struct wsc_credentials_info *creds, -unsigned int n_creds,void *user_data) +static void wsc_connect_set_method (struct wsc *wsc) { -struct wsc *wsc = user_data; - -l_debug ("err=%i" , err); +const char *pin; -switch (err) { -case 0 : -break ; -case -ECANCELED : -dbus_pending_reply (&wsc->pending, -dbus_error_aborted (wsc->pending)); -return ; -case -ENOKEY : -dbus_pending_reply (&wsc->pending, -wsc_error_no_credentials (wsc->pending)); -return ; -case -EBUSY : -dbus_pending_reply (&wsc->pending, -dbus_error_busy (wsc->pending)); -return ; -default : -dbus_pending_reply (&wsc->pending, -dbus_error_failed (wsc->pending)); -return ; - } +if (!strcmp (l_dbus_message_get_member (wsc->pending),"StartPin" )) +l_dbus_message_get_arguments (wsc->pending,"s" , &pin); +else + pin =NULL ;Quoted 6 lines
src/wsc.c static void wsc_connect(struct wsc *wsc) · line 538
Quoted 3 lines
src/wsc.c +1
-2-wsc_store_credentials (wsc); -wsc_try_credentials (wsc); +wsc_start_enrollee (wsc, wsc->netdev, wsc->target, pin,NULL ,0 );Is
wsc_start_enrolleegoing to be called from p2p directly or only via the D-Bus API?
Quoted 5 lines
So the D-Bus API will call the P2P code (to do GO Negotiation / Provision Discovery etc.) or the station-specific code inside
wsc.c(to do the scanning) and they'll both callwsc_start_enrolleewhen ready.wsc_connect_set_methodis the station-specific code path where this happens.
Okay, but the PIN / PushButton setup is common to both, no? And it seems that would logically belong in the overall D-Bus layer handlers. No point passing pin around, especially since you already made the change to store it inside the wsc object.
Quoted 105 lines
Quoted 4 lines
This enclosing function (
wsc_connect_set_method) is now
quite strange looking. Maybe it'd look nicer to just setwsc->pinfrom inside the StartPin / PushButton handlers instead and avoid this completely?Well I can do this. I preferred to keep the parts 1. and 2. of the code independent (e.g. for scenarios like auto-connecting to some P2P devices in the future) but it makes little differnce.
I notice the way git formatted this patch makes it hard to read.
Quoted 53 lines
Quoted 53 lines
src/wsc.c +6
-22}static void station_state_watch (enum station_state state,void *userdata)@@ -573,7 +550,7 @@ static void station_state_watch(enum station_state state, void *userdata)station_remove_state_watch (wsc->station, wsc->station_state_watch); wsc->station_state_watch =0 ; -wsc_connect (wsc); +wsc_connect_set_method (wsc); }static void wsc_check_can_connect (struct wsc *wsc,struct scan_bss *target)@@ -587,25 +564,9 @@ static void wsc_check_can_connect(struct wsc *wsc, struct scan_bss *target) wsc->target = target;station_set_autoconnect (wsc->station, false); -if (!strcmp (l_dbus_message_get_member (wsc->pending),"StartPin" )) { -char *pin; - - wsc->config_method =WSC_CONFIGURATION_METHOD_KEYPAD ; - -if (!l_dbus_message_get_arguments (wsc->pending,"s" , &pin)) - goto error; - - wsc->pin =l_strdup (pin); - }else - wsc->config_method = -WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON ; - - wsc->done_cb = wsc_dbus_done_cb; - wsc->done_data = wsc; -switch (station_get_state (wsc->station)) {case STATION_STATE_DISCONNECTED : -wsc_connect (wsc); +wsc_connect_set_method (wsc);return ;case STATION_STATE_CONNECTING :case STATION_STATE_CONNECTED :@@ -652,20 +613,13 @@ static void walk_timeout(struct l_timeout *timeout, void *user_data)wsc_cancel_scan (wsc); -if (wsc->pending) -dbus_pending_reply (&wsc->pending, -wsc_error_walk_time_expired (wsc->pending)); -} +if (wsc->pending) { +struct l_dbus_message *reply = wsc->pin ? +wsc_error_time_expired (wsc->pending) : +wsc_error_walk_time_expired (wsc->pending);Quoted 15 lines
src/wsc.c static void walk_timeout(struct l_timeout *timeout, void *user_data) · line 624
Quoted 13 lines
src/wsc.c +2
-9-static void pin_timeout (struct l_timeout *timeout,void *user_data) -{ -struct wsc *wsc = user_data; - -wsc_cancel_scan (wsc); - -if (wsc->pending) -dbus_pending_reply (&wsc->pending, -wsc_error_time_expired (wsc->pending)); +dbus_pending_reply (&wsc->pending, reply); + } }Okay, but this really belongs as a separate patch
Ok.
Quoted 13 lines
src/wsc.c static struct l_dbus_message *wsc_push_button(struct l_dbus *dbus, · line 1006
Quoted 9 lines
src/wsc.c +0
-3static bool push_button_scan_results(int err, struct l_queue *bss_list,@@ -1001,20 +955,7 @@ static struct l_dbus_message *wsc_push_button(struct l_dbus *dbus,l_debug ("" ); -if (wsc->pending) -return dbus_error_busy (message); -So why would you move this check out into the ops provided operation and not keep it here?
...
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +0
-2- wsc->pending = l_dbus_message_ref(message); -Pending tracking should also likely be managed here...
...
Quoted 3 lines
Quoted 2 lines
(quoted diff) +0
-2- if (wsc->pending) - return dbus_error_busy(message);
Quoted 9 lines
Quoted 1 line
Same comments as above apply here ...
For one, in the P2P case, it's not going to have access to the internals of struct wsc, so if P2P replies with success or an error message to the PushButton call, it would need some way to also clear
wsc->pending. That's doable but it seems simpler to leave full control to the actual implementation. So my idea in this version was that the DBus handlers would be really simple and stateless.
But how would p2p set wsc->pending if it has no access to the wsc object? Or are you duplicating the D-Bus handling code inside p2p? I guess I was under the impression that you'd want to unify the D-Bus bits as well.
If you want to re-invent this inside p2p, then there's really no need for this wsc_ops abstraction. Just have something like:
struct wsc_dbus_object {
bool station;
union {
struct wsc_p2p *p2p;
struct wsc *wsc;
}
}Quoted 4 lines
Also remember that in the P2P case the PushButton method will kick off the connection process but there's a few different steps and WSC is just one of them and might be skipped completely in some scenarios.
Sure, so you'd abstract wsc eap connection behind wsc_eap_start_enrollee, wsc_eap_cancel, etc. This ends up being re-used and the rest you can do separate.
Quoted 99 lines
Quoted 86 lines
Quoted 86 lines
src/wsc.c +5
-50- - wsc->station =station_find (netdev_get_ifindex (wsc->netdev)); -if (!wsc->station) -return dbus_error_not_available (message); -if (!l_dbus_message_get_arguments (message,"s" , &pin))return dbus_error_invalid_args (message);if (!wsc_pin_is_valid (pin))return dbus_error_invalid_format (message); -if (strlen (pin) ==4 ||wsc_pin_is_checksum_valid (pin)) - dpid =WSC_DEVICE_PASSWORD_ID_DEFAULT ; -else - dpid =WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED ; - -if (!wsc_initiate_scan (wsc, dpid, pin_scan_results)) -return dbus_error_failed (message); - - wsc->walk_timer =l_timeout_create (60 , pin_timeout, wsc,NULL ); - wsc->pending =l_dbus_message_ref (message); - + wsc->ops->connect (message, pin, wsc->user_data);return NULL ; } -static struct l_dbus_message *wsc_cancel (struct l_dbus *dbus, +static struct l_dbus_message *wsc_dbus_cancel (struct l_dbus *dbus,struct l_dbus_message *message,void *user_data) {struct wsc *wsc = user_data; -struct l_dbus_message *reply;l_debug ("" ); -if (!wsc->pending) -return dbus_error_not_available (message); - -wsc_cancel_scan (wsc); - -if (wsc->station_state_watch) { -station_remove_state_watch (wsc->station, - wsc->station_state_watch); - wsc->station_state_watch =0 ; - wsc->target =NULL ; - } - -if (wsc->wsc_association) { -int r; - - r =netdev_disconnect (wsc->netdev, wsc_disconnect_cb, wsc); -if (r ==0 ) { - wsc->pending_cancel =l_dbus_message_ref (message); -return NULL ; - } - -l_warn ("Unable to initiate disconnect: %s" ,strerror (-r)); - wsc->wsc_association = false; - } - -dbus_pending_reply (&wsc->pending,dbus_error_aborted (wsc->pending)); - - reply =l_dbus_message_new_method_return (message); -l_dbus_message_set_arguments (reply,"" ); - -return reply; + wsc->ops->cancel (message, wsc->user_data); +return NULL ; }static void setup_wsc_interface (struct l_dbus_interface *interface)@@ -1128,7 +1021,7 @@ static void setup_wsc_interface(struct l_dbus_interface *interface)l_dbus_interface_method (interface,"StartPin" ,0 , wsc_start_pin,"" ,"s" ,"pin" );l_dbus_interface_method (interface,"Cancel" ,0 , - wsc_cancel,"" ,"" ); + wsc_dbus_cancel,"" ,"" ); }static void wsc_free (void *userdata)@@ -1155,7 +1048,194 @@ static void wsc_free(void *userdata)l_free (wsc); }Quoted 12 lines
src/wsc.c static void wsc_free(void *userdata) · line 1059
Quoted 10 lines
src/wsc.c +9
-1-static void wsc_add_interface (struct netdev *netdev) +struct wsc *wsc_new (const struct wsc_ops *ops,void *user_data) +{ +struct l_dbus *dbus =dbus_get_bus (); +struct wsc *wsc; +const char *path; + + wsc = l_new(struct wsc, 1); + wsc->ops = ops; + wsc->user_data = user_data;This part seems rather weird
Quoted 1 line
Do you mean the whole function? and why?
I really meant the user_data setting. You pass in user_data to all the callbacks, but it is set to NULL in wsc_new. I think the intent was for user_data to be the wsc object itself, but I don't see how that would even be accomplished in this setup. Have you actually tested this patch standalone?
Quoted 266 lines
Quoted 200 lines
Quoted 112 lines
src/wsc.c +110
-0+ + path = wsc->ops->get_path (wsc->user_data); +if (!path) +return wsc; + +if (l_dbus_object_add_interface (dbus, path,IWD_WSC_INTERFACE , wsc)) +return wsc; + +wsc_free (wsc); +l_info ("Unable to register interface %s at %s" ,IWD_WSC_INTERFACE , + path); +return NULL ; +} + +void wsc_destroy (struct wsc *wsc) +{ +l_dbus_object_remove_interface (dbus_get_bus (), + wsc->ops->get_path (wsc->user_data), +IWD_WSC_INTERFACE ); +} + +void wsc_start_enrollee (struct wsc *wsc,struct netdev *netdev, +struct scan_bss *target,const char *pin) +{ + wsc->netdev = netdev; + wsc->target = target; + wsc->config_method = pin ?WSC_CONFIGURATION_METHOD_KEYPAD : +WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON ; + wsc->pin =l_strdup (pin); + +wsc_connect (wsc); +} + +void wsc_cancel (struct wsc *wsc,netdev_disconnect_cb_t cb) +{ +int r; + +if (!wsc->wsc_association) +return ; + + r =netdev_disconnect (wsc->netdev, cb, wsc->user_data); +if (r ==0 ) +return ; + +l_warn ("Unable to initiate disconnect: %s" ,strerror (-r)); +wsc_connect_cleanup (wsc); + wsc->ops->enrollee_done_cb (-ECANCELED ,NULL ,0 , wsc->user_data); + +if (cb) +cb (wsc->netdev, false, wsc->user_data); +} + +static const char *wsc_device_get_path (void *user_data) +{ +struct wsc *wsc = user_data; + +if (!wsc || !wsc->netdev) +return NULL ; + +return netdev_get_path (wsc->netdev); +} + +static void wsc_device_connect (struct l_dbus_message *message,const char *pin, +void *user_data) +{ +struct wsc *wsc = user_data; +struct l_dbus *dbus =dbus_get_bus (); +unsigned int walk_time; +enum wsc_device_password_id dpid; +scan_notify_func_t results_cb; + +if (wsc->pending) { +l_dbus_send (dbus,dbus_error_busy (message)); +return ; + } + + wsc->station =station_find (netdev_get_ifindex (wsc->netdev)); +if (!wsc->station) { +l_dbus_send (dbus,dbus_error_not_available (message)); +return ; + } + +if (pin) { +if (strlen (pin) ==4 ||wsc_pin_is_checksum_valid (pin)) + dpid =WSC_DEVICE_PASSWORD_ID_DEFAULT ; +else + dpid =WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED ; + + walk_time =60 ; + results_cb = pin_scan_results; + }else { + dpid =WSC_DEVICE_PASSWORD_ID_PUSH_BUTTON ; + walk_time =WALK_TIME ; + results_cb = push_button_scan_results; + } + +if (!wsc_initiate_scan (wsc, dpid, results_cb)) { +l_dbus_send (dbus,dbus_error_failed (message)); +return ; + } + + wsc->walk_timer =l_timeout_create (walk_time, walk_timeout, wsc,NULL ); + wsc->pending =l_dbus_message_ref (message); +} + +static void wsc_device_cancel (struct l_dbus_message *message,void *user_data) +{ +struct wsc *wsc = user_data; +struct l_dbus *dbus =dbus_get_bus (); +src/wsc.c static void wsc_free(void *userdata) · line 1179
Quoted 10 lines
src/wsc.c +10
-0+if (!wsc->pending) { +l_dbus_send (dbus,dbus_error_not_available (message)); +return ; + } + +if (wsc->pending_cancel) { +l_dbus_send (dbus,dbus_error_busy (message)); +return ; + } +As mentioned before, this doesn't seem like it belongs in the op itself but in the higher layer...
Quoted 7 lines
src/wsc.c +7
-0+wsc_cancel_scan (wsc); + +if (wsc->station_state_watch) { +station_remove_state_watch (wsc->station, + wsc->station_state_watch); + wsc->station_state_watch =0 ; + wsc->target =NULL ;src/wsc.c static void wsc_free(void *userdata) · line 1196
Quoted 10 lines
src/wsc.c +10
-0+ } + +if (wsc->wsc_association) { + wsc->pending_cancel =l_dbus_message_ref (message); +wsc_cancel (wsc, wsc_disconnect_cb); +return ; + } + +dbus_pending_reply (&wsc->pending,dbus_error_aborted (wsc->pending)); +l_dbus_send (dbus,l_dbus_message_new_method_return (message));As is this...
Quoted 54 lines
src/wsc.c +44
-1+} + +static void wsc_device_enrollee_done (int err,struct wsc_credentials_info *creds, +unsigned int n_creds,void *user_data) +{ +struct wsc *wsc = user_data; + +l_debug ("err=%i" , err); + +switch (err) { +case 0 : +break ; +case -ECANCELED : +dbus_pending_reply (&wsc->pending, +dbus_error_aborted (wsc->pending)); +return ; +case -ENOKEY : +dbus_pending_reply (&wsc->pending, +wsc_error_no_credentials (wsc->pending)); +return ; +case -EBUSY : +dbus_pending_reply (&wsc->pending, +dbus_error_busy (wsc->pending)); +return ; +default : +dbus_pending_reply (&wsc->pending, +dbus_error_failed (wsc->pending)); +return ; + } + +wsc_store_credentials (creds, n_creds); +wsc_try_credentials (wsc, creds, n_creds); +} + +static const struct wsc_ops wsc_device_ops = { + .get_path = wsc_device_get_path, + .connect = wsc_device_connect, + .cancel = wsc_device_cancel, + .enrollee_done_cb = wsc_device_enrollee_done, +}; + +static void wsc_device_new (struct netdev *netdev) {struct l_dbus *dbus =dbus_get_bus ();struct wsc *wsc;@@ -1167,15 +1247,17 @@ static void wsc_add_interface(struct netdev *netdev)return ; } - wsc = l_new(struct wsc, 1); + wsc =wsc_new (&wsc_device_ops,NULL ); + wsc->user_data = wsc; wsc->netdev = netdev;Quoted 15 lines
src/wsc.c static void wsc_add_interface(struct netdev *netdev) · line 1260
Quoted 13 lines
src/wsc.c +7
-6-if (!l_dbus_object_add_interface (dbus,netdev_get_path (netdev), -IWD_WSC_INTERFACE , - wsc)) { -wsc_free (wsc); -l_info ("Unable to register %s interface" ,IWD_WSC_INTERFACE ); - } +if (l_dbus_object_add_interface (dbus,netdev_get_path (netdev), +IWD_WSC_INTERFACE , wsc)) +return ; + +wsc_free (wsc); +l_info ("Unable to register interface %s at %s" ,IWD_WSC_INTERFACE , +netdev_get_path (netdev));This logic flipping seems gratuitous, I'd just leave it the way it was...
Ok.
Quoted 33 lines
Quoted 33 lines
src/wsc.c +1
-1}static void wsc_remove_interface (struct netdev *netdev)@@ -1194,7 +1276,7 @@ static void wsc_netdev_watch(struct netdev *netdev,case NETDEV_WATCH_EVENT_NEW :if (netdev_get_iftype (netdev) ==NETDEV_IFTYPE_STATION &&netdev_get_is_up (netdev)) -wsc_add_interface (netdev); +wsc_device_new (netdev);break ;case NETDEV_WATCH_EVENT_DOWN :case NETDEV_WATCH_EVENT_DEL :src/wsc.h +5
-0@@ -20,6 +20,11 @@* */ +struct wsc ; +struct netdev ; +struct scan_bss ; +struct iovec ; +struct wsc_credentials_info {char ssid[33 ];enum security security;@@ -31,5 +36,17 @@ struct wsc_credentials_info {bool has_passphrase; };Quoted 14 lines
src/wsc.h struct wsc_credentials_info { · line 45
Quoted 9 lines
src/wsc.h +7
-2-typedef void (*wsc_done_cb_t )(int err,struct wsc_credentials_info *creds, -unsigned int n_creds,void *user_data); +struct wsc_ops { +const char *(*get_path)(void *user_data); +void (*connect)(struct l_dbus_message *message,const char *pin, +void *user_data); +void (*cancel)(struct l_dbus_message *message,void *user_data); +void (*enrollee_done_cb)(int err,struct wsc_credentials_info *creds, +unsigned int n_creds,void *user_data);So one thing I find very weird about this setup is the fact that you're mixing operations with a callback in something called '
wsc_ops'. Can't your 'connect' operation simply set the callback or perhaps provide the callback directly towsc_start_enrollee?
Quoted 7 lines
It would work equally well, yes. Maybe I was being lazy, I'll fix this.
One argument for keeping all the callbacks in this struct is that they implicitly use the same "
user_data" and so we save both the callback parameter towsc_start_enrollee, theuser_dataparameter (we often complained about our functions having too many arguments) and 2 fields in struct wsc for storing these two parameters.
Well, so far I only see a single callback being utilized. So there seems to be no need for this just yet? Also, see my comments above about user_data weirdness.
Regards,
-Denis
Re: [PATCH 3/4] wsc: Refactor to make the DBus interface reusable
Hi Denis,
Quoted 13 lines · Denis Kenzior
Quoted 12 lines · Andrew Zaborowski
So in the new setup we have parts of
wsc.cthat are common between the Station mode use case and the external user use case (i.e. P2P), and then we have parts that are relevant to Station mode only. We sort of have 3 parts:1. the core part that sets up the EAP method config, starts the connection and receives the credentials.
2. the DBus interface that lives even when we're not doing WSC (also common to both modes now)
3. the Station-specific code which interfaces between 1. and 2. and does the scanning etc., i.e. everything used by @wsc_device_ops
Quoted 8 lines
Quoted 2 lines
wsc_disconnect_cbbelongs in 3., whilewsc->wsc_associationbelongs in
2. sowsc_disconnect_cbshouldn't be touchingwsc->wsc_association.Not quite sure I follow.
wsc_disconnect_cbis called when cancel is invoked via D-Bus API (or in your proposal it would be invoked viawsc_cancel).wsc->associationtracks whether we have a connection established for the purposes of EAP-WSC. Hence ifwsc->associationis true, we have to disconnect it first. I see these two as inherently linked?
The disconnect is handled at a lower level, by wsc_cancel. wsc_disconnect_cb doesn't need to do anything related to the internal protocol state.
The part 1. exposes an API that is used by 3. in wsc.c, or by the external caller which also supplies a callback like wsc_disconnect_cb. That callback also can't mess with variables like wsc->wsc_association (sitting outside wsc.c it has no way anyway).
Quoted 59 lines
Quoted 53 lines
Quoted 46 lines
<snip>
Quoted 43 lines
src/wsc.c +7
-27@@ -525,40 +523,19 @@ static void wsc_connect(struct wsc *wsc) error:handshake_state_free (hs);wsc_connect_cleanup (wsc); - wsc->done_cb (r,NULL ,0 , wsc->done_data); + wsc->ops->enrollee_done_cb (r,NULL ,0 , wsc->user_data); } -/* Done callback for when WSC is triggered by DBus methods */ -static void wsc_dbus_done_cb (int err,struct wsc_credentials_info *creds, -unsigned int n_creds,void *user_data) +static void wsc_connect_set_method (struct wsc *wsc) { -struct wsc *wsc = user_data; - -l_debug ("err=%i" , err); +const char *pin; -switch (err) { -case 0 : -break ; -case -ECANCELED : -dbus_pending_reply (&wsc->pending, -dbus_error_aborted (wsc->pending)); -return ; -case -ENOKEY : -dbus_pending_reply (&wsc->pending, -wsc_error_no_credentials (wsc->pending)); -return ; -case -EBUSY : -dbus_pending_reply (&wsc->pending, -dbus_error_busy (wsc->pending)); -return ; -default : -dbus_pending_reply (&wsc->pending, -dbus_error_failed (wsc->pending)); -return ; - } +if (!strcmp (l_dbus_message_get_member (wsc->pending),"StartPin" )) +l_dbus_message_get_arguments (wsc->pending,"s" , &pin); +else + pin =NULL ;Quoted 6 lines
src/wsc.c static void wsc_connect(struct wsc *wsc) · line 538
Quoted 3 lines
src/wsc.c +1
-2-wsc_store_credentials (wsc); -wsc_try_credentials (wsc); +wsc_start_enrollee (wsc, wsc->netdev, wsc->target, pin,NULL ,0 );Is
wsc_start_enrolleegoing to be called from p2p directly or only via the D-Bus API?Quoted 5 lines
So the D-Bus API will call the P2P code (to do GO Negotiation / Provision Discovery etc.) or the station-specific code inside
wsc.c(to do the scanning) and they'll both callwsc_start_enrolleewhen ready.wsc_connect_set_methodis the station-specific code path where this happens.
Quoted 4 lines
Okay, but the PIN / PushButton setup is common to both, no? And it seems that would logically belong in the overall D-Bus layer handlers. No point passing pin around, especially since you already made the change to store it inside the wsc object.
Right, I guess the pin can be set directly when the method is called and cleared whenever we're replying to the method.
Quoted 31 lines
Quoted 21 lines
Quoted 11 lines
src/wsc.c static struct l_dbus_message *wsc_push_button(struct l_dbus *dbus, · line 1006
Quoted 7 lines
src/wsc.c +0
-3@@ -1001,20 +955,7 @@ static struct l_dbus_message *wsc_push_button(struct l_dbus *dbus,l_debug ("" ); -if (wsc->pending) -return dbus_error_busy (message); -So why would you move this check out into the ops provided operation and not keep it here?
...
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +0
-2- wsc->pending = l_dbus_message_ref(message); -Pending tracking should also likely be managed here...
...
Quoted 3 lines
Quoted 2 lines
(quoted diff) +0
-2- if (wsc->pending) - return dbus_error_busy(message);Quoted 9 lines
Quoted 1 line
Same comments as above apply here ...
For one, in the P2P case, it's not going to have access to the internals of struct wsc, so if P2P replies with success or an error message to the PushButton call, it would need some way to also clear
wsc->pending. That's doable but it seems simpler to leave full control to the actual implementation. So my idea in this version was that the DBus handlers would be really simple and stateless.
Quoted 4 lines
But how would p2p set
wsc->pendingif it has no access to the wsc object? Or are you duplicating the D-Bus handling code inside p2p? I guess I was under the impression that you'd want to unify the D-Bus bits as well.
In this case wsc->pending was only part of 3. (out of the three state machines in wsc.c I mentioned) and p2p.c had it's own "pending" which is also used as a flag internally. I guess it makes sense to change this to handle the dbus message completely in wsc.c so p2p.c doesn't have to see the actual messages.
Quoted 11 lines
If you want to re-invent this inside p2p, then there's really no need for this
wsc_opsabstraction. Just have something like:struct wsc_dbus_object { bool station; union { struct wsc_p2p *p2p; struct wsc *wsc; } }
I don't follow. Our entry points are the DBus method handlers, which are in wsc.c. How will the control pass from wsc.c to p2p.c (or to the station specific CBs) without the wsc_ops?
In terms of the structs in wsc.c, yeah, I was thinking of splitting the state of 1., 2. and 3. into separate structs, something I didn't do so they're all together in struct wsc now.
Quoted 27 lines
Quoted 5 lines
Also remember that in the P2P case the PushButton method will kick off the connection process but there's a few different steps and WSC is just one of them and might be skipped completely in some scenarios.
Sure, so you'd abstract wsc eap connection behind
wsc_eap_start_enrollee,wsc_eap_cancel, etc. This ends up being re-used and the rest you can do separate.Quoted 17 lines
Quoted 16 lines
Quoted 4 lines
src/wsc.c +0
-0@@ -1155,7 +1048,194 @@ static void wsc_free(void *userdata)l_free (wsc); }src/wsc.c static void wsc_free(void *userdata) · line 1059
Quoted 10 lines
src/wsc.c +9
-1-static void wsc_add_interface (struct netdev *netdev) +struct wsc *wsc_new (const struct wsc_ops *ops,void *user_data) +{ +struct l_dbus *dbus =dbus_get_bus (); +struct wsc *wsc; +const char *path; + + wsc = l_new(struct wsc, 1); + wsc->ops = ops; + wsc->user_data = user_data;This part seems rather weird
Quoted 7 lines
Quoted 1 line
Do you mean the whole function? and why?
I really meant the
user_datasetting. You pass inuser_datato all the callbacks, but it is set to NULL inwsc_new. I think the intent was foruser_datato be the wsc object itself, but I don't see how that would even be accomplished in this setup. Have you actually tested this patch standalone?
I think I did (this was a month ago) ;-) You're right, the idea is for the user_data to be the wsc object itself because I didn't split the state into separate structs. So in the station mode case wsc_add_interface calls wsc_new, then overwrites wsc->user_data.
Quoted 22 lines
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
src/wsc.h +0
-0@@ -31,5 +36,17 @@ struct wsc_credentials_info {bool has_passphrase; };Quoted 14 lines
src/wsc.h struct wsc_credentials_info { · line 45
Quoted 9 lines
src/wsc.h +7
-2-typedef void (*wsc_done_cb_t )(int err,struct wsc_credentials_info *creds, -unsigned int n_creds,void *user_data); +struct wsc_ops { +const char *(*get_path)(void *user_data); +void (*connect)(struct l_dbus_message *message,const char *pin, +void *user_data); +void (*cancel)(struct l_dbus_message *message,void *user_data); +void (*enrollee_done_cb)(int err,struct wsc_credentials_info *creds, +unsigned int n_creds,void *user_data);So one thing I find very weird about this setup is the fact that you're mixing operations with a callback in something called '
wsc_ops'. Can't your 'connect' operation simply set the callback or perhaps provide the callback directly towsc_start_enrollee?It would work equally well, yes. Maybe I was being lazy, I'll fix this.
Quoted 8 lines
Quoted 5 lines
One argument for keeping all the callbacks in this struct is that they implicitly use the same "
user_data" and so we save both the callback parameter towsc_start_enrollee, theuser_dataparameter (we often complained about our functions having too many arguments) and 2 fields in struct wsc for storing these two parameters.Well, so far I only see a single callback being utilized. So there seems to be no need for this just yet?
.connect and .cancel are both being utilized, and .enrollee_done_cb is also being utilized but at a different level. There's currently one user_data for them.
What I meant is that if I move enrollee_done_cb outside of the "ops" it's going to be part of the wsc instance state and it probably should have its own user_data so those are 2 new parameters and 2 new variables. But it may be worth it anyway.
Best regards
Re: [PATCH 3/4] wsc: Refactor to make the DBus interface reusable
Hi Andrew,
<snip>
Quoted 9 lines
The disconnect is handled at a lower level, by
wsc_cancel.wsc_disconnect_cbdoesn't need to do anything related to the internal protocol state.The part 1. exposes an API that is used by 3. in
wsc.c, or by the external caller which also supplies a callback likewsc_disconnect_cb. That callback also can't mess with variables likewsc->wsc_association(sitting outsidewsc.cit has no way anyway).
Okay, so I had to stare at this again for a while and I think I get it now. Note that you only call wsc_connect_cleanup if netdev_disconnect fails. So wsc_connect_cleanup is not called unnecessarily.
<snip>
Quoted 6 lines
In this case
wsc->pendingwas only part of 3. (out of the three state machines inwsc.cI mentioned) andp2p.chad it's own "pending" which is also used as a flag internally. I guess it makes sense to change this to handle the dbus message completely inwsc.csop2p.cdoesn't have to see the actual messages.
If it was me doing it, I'd try to unify the D-Bus API handling aspects. Especially since you went to the trouble of abstracting all the operations.
Quoted 13 lines
Quoted 5 lines
If you want to re-invent this inside p2p, then there's really no need for this
wsc_opsabstraction. Just have something like:Quoted 7 lines
struct wsc_dbus_object { bool station; union { struct wsc_p2p *p2p; struct wsc *wsc; } }
Quoted 3 lines
I don't follow. Our entry points are the DBus method handlers, which are in
wsc.c. How will the control pass fromwsc.ctop2p.c(or to the station specific CBs) without thewsc_ops?
it would just invoke the relevant function calls directly. i.e.
wsc_p2p_push_button(p2p, msg);wsc_p2p_start_pin(p2p, msg);wsc_p2p_cancel(p2p, msg);
That would give you a whole lot more freedom to do whatever in p2p.
Quoted 5 lines
I think I did (this was a month ago) ;-) You're right, the idea is for the
user_datato be the wsc object itself because I didn't split the state into separate structs. So in the station mode casewsc_add_interfacecallswsc_new, then overwriteswsc->user_data.
Yep, I think I missed the part of you overwriting the user_data. You went through all this trouble of defining an API for setting it and then turn around and backdoor it ;) That is what threw me off here and also in the disconnect_cb bits above. If user_data was meant to be set externally, it would have been clearer to add wsc_set_userdata() method or have the caller pass in the cb/userdata into the operation directly.
Quoted 4 lines
.connect and .cancel are both being utilized, and .enrollee_done_cb is also being utilized but at a different level. There's currently one
user_datafor them.
So while this works, I would think that separating the layers more explicitly would make things more elegant. You have the EAP-WSC state machine object that takes care of the actual WSC connection:
wsc_enrollee_new
wsc_enrollee_start
wsc_enrollee_cancel
wsc_enrollee_free
Then you have the p2p/station layers that take care of scanning, etc. This is where your ops stuff can live. Something like:
struct wsc {
const char *(*get_path)(struct wsc *wsc);
int (*connect)(struct wsc *wsc, const char *pin,
connect_cb_t cb, void *userdata);
int (*cancel)(struct wsc *wsc, cancel_cb_t cb, void *userdata);
void (*remove)(struct wsc *wsc);
};Then for p2p you can do:
struct wsc_p2p {
// some members
struct wsc super;
};struct wsc *wsc_p2p_new();
for station:
struct wsc_station {
struct wsc super;
// some members;
struct station *station;
uint32_t station_state_watch;
...
};struct wsc *wsc_station_new();
And if you want to unify the D-Bus bits, then:
struct wsc_dbus {
struct wsc *wsc;
struct l_dbus_message *pending;
struct l_dbus_message *pending_cancel;
};Regards,
-Denis
Re: [PATCH 3/4] wsc: Refactor to make the DBus interface reusable
Hi Denis,
Quoted 31 lines · Denis Kenzior
Hi Andrew,
<snip>
Quoted 6 lines
In this case
wsc->pendingwas only part of 3. (out of the three state machines inwsc.cI mentioned) andp2p.chad it's own "pending" which is also used as a flag internally. I guess it makes sense to change this to handle the dbus message completely inwsc.csop2p.cdoesn't have to see the actual messages.If it was me doing it, I'd try to unify the D-Bus API handling aspects. Especially since you went to the trouble of abstracting all the operations.
Quoted 13 lines
Quoted 5 lines
If you want to re-invent this inside p2p, then there's really no need for this
wsc_opsabstraction. Just have something like:Quoted 7 lines
struct wsc_dbus_object { bool station; union { struct wsc_p2p *p2p; struct wsc *wsc; } }Quoted 3 lines
I don't follow. Our entry points are the DBus method handlers, which are in
wsc.c. How will the control pass fromwsc.ctop2p.c(or to the station specific CBs) without thewsc_ops?
Quoted 7 lines
it would just invoke the relevant function calls directly. i.e.
wsc_p2p_push_button(p2p, msg);wsc_p2p_start_pin(p2p, msg);wsc_p2p_cancel(p2p, msg);That would give you a whole lot more freedom to do whatever in p2p.
I think I'd rather use the ops struct defined in wsc.h than expose these functions in p2p.h. A strict P2P API would look differently so this is shaped after WSC. It also needs the user-data to know which peer to connect to.
Quoted 10 lines
Quoted 6 lines
I think I did (this was a month ago) ;-) You're right, the idea is for the
user_datato be the wsc object itself because I didn't split the state into separate structs. So in the station mode casewsc_add_interfacecallswsc_new, then overwriteswsc->user_data.Yep, I think I missed the part of you overwriting the
user_data. You went through all this trouble of defining an API for setting it and then turn around and backdoor it ;)
True. Yep, I should've added a wsc_set_userdata.
Quoted 10 lines
That is what threw me off here and also
in thedisconnect_cbbits above. Ifuser_datawas meant to be set externally, it would have been clearer to addwsc_set_userdata()method or have the caller pass in the cb/userdata into the operation directly.Quoted 4 lines
.connect and .cancel are both being utilized, and .enrollee_done_cb is also being utilized but at a different level. There's currently one
user_datafor them.
Quoted 7 lines
So while this works, I would think that separating the layers more explicitly would make things more elegant. You have the EAP-WSC state machine object that takes care of the actual WSC connection:
wsc_enrollee_new
wsc_enrollee_start
wsc_enrollee_cancel
wsc_enrollee_free
Ok, this sounds good. I'm not even sure if we need a start and a cancel, or it's Ok to create and free this whole state machine as needed.
So those functions would operate on a "struct wsc_enrollee".
Quoted 11 lines
Then you have the p2p/station layers that take care of scanning, etc. This is where your ops stuff can live. Something like:
struct wsc { const char *(*get_path)(struct wsc *wsc); int (*connect)(struct wsc *wsc, const char *pin, connect_cb_t cb, void *userdata); int (*cancel)(struct wsc *wsc, cancel_cb_t cb, void *userdata); void (*remove)(struct wsc *wsc); };
So this would be exposed in wsc.h I understand. I think I'd still rather call it wsc_ops.
Quoted 9 lines
Then for p2p you can do:
struct wsc_p2p { // some members struct wsc super; };struct wsc
*wsc_p2p_new();
And this would live in p2p.c. We have one WSC interface per peer so this would really be called "struct p2p_peer_wsc_dbus" or similar and in the callbacks it can use container_of() instead of needing the user_data so that parameter can be dropped.
Quoted 12 lines
for station:
struct wsc_station { struct wsc super; // some members; struct station *station; uint32_t station_state_watch; ... };struct wsc
*wsc_station_new();
Quoted 7 lines
And if you want to unify the D-Bus bits, then:
struct wsc_dbus { struct wsc *wsc; struct l_dbus_message *pending; struct l_dbus_message *pending_cancel; };
Ok, so this would be created by a call to:
struct wsc_dbus *wsc_dbus_new(struct wsc *wsc) (or struct wsc_ops *wsc)
and it would either need to be public in wsc.h or have enough accessors for pending and pending_cancel.
Best regards
Re: [PATCH 3/4] wsc: Refactor to make the DBus interface reusable
Hi Andrew,
Quoted 11 lines
Quoted 7 lines
So while this works, I would think that separating the layers more explicitly would make things more elegant. You have the EAP-WSC state machine object that takes care of the actual WSC connection:
wsc_enrollee_new
wsc_enrollee_start
wsc_enrollee_cancel
wsc_enrollee_freeOk, this sounds good. I'm not even sure if we need a start and a cancel, or it's Ok to create and free this whole state machine as needed.
See how it looks. We might need a cancel at least since you have a 'destroy immediately' case where the device goes away due to hot-unplug.
Or cancel and try to cleanup first case.
Quoted 2 lines
So those functions would operate on a "struct
wsc_enrollee".
Right.
Quoted 13 lines
Quoted 5 lines
Then you have the p2p/station layers that take care of scanning, etc. This is where your ops stuff can live. Something like:
Quoted 7 lines
struct wsc { const char *(*get_path)(struct wsc *wsc); int (*connect)(struct wsc *wsc, const char *pin, connect_cb_t cb, void *userdata); int (*cancel)(struct wsc *wsc, cancel_cb_t cb, void *userdata); void (*remove)(struct wsc *wsc); };
Quoted 3 lines
So this would be exposed in
wsc.hI understand. I think I'd still rather call itwsc_ops.
Can do that too. But there might be state you can share across the different sub-types. Maybe the netdev for example.
Quoted 8 lines
Quoted 8 lines
Then for p2p you can do:
struct wsc_p2p { // some members struct wsc super; };
Quoted 7 lines
Quoted 1 line
struct wsc
*wsc_p2p_new();And this would live in
p2p.c. We have one WSC interface per peer so this would really be called "structp2p_peer_wsc_dbus" or similar and in the callbacks it can usecontainer_of()instead of needing theuser_dataso that parameter can be dropped.
Yep
Quoted 20 lines
Quoted 12 lines
for station:
struct wsc_station { struct wsc super; // some members; struct station *station; uint32_t station_state_watch; ... };struct wsc
*wsc_station_new();Quoted 7 lines
And if you want to unify the D-Bus bits, then:
struct wsc_dbus { struct wsc *wsc; struct l_dbus_message *pending; struct l_dbus_message *pending_cancel; };
Quoted 4 lines
Ok, so this would be created by a call to:
struct
wsc_dbus*wsc_dbus_new(struct wsc *wsc) (or structwsc_ops*wsc)
yes, something like that would be needed. Can also do something like wsc_dbus_object_add and let struct wsc_dbus be hidden away in wsc.c
Quoted 3 lines
and it would either need to be public in
wsc.hor have enough accessors for pending andpending_cancel.
Reegards,
-Denis
PATCH 4/4 wsc: Accept extra IEs in wsc_start_enrollee
In reply to Andrew Zaborowski--- src/wsc.c | 24 ++++++++++++++---------- src/wsc.h | 3 ++- 2 files changed, 16 insertions(+), 11 deletions(-)
src/wsc.c +14 -10
@@ -447,7 +447,8 @@ static inline enum wsc_rf_band freq_to_rf_band(uint32_t freq)return WSC_RF_BAND_2_4_GHZ ; } -static void wsc_connect (struct wsc *wsc) +static void wsc_connect (struct wsc *wsc,struct iovec *ies, +unsigned int ies_num) {struct handshake_state *hs;struct l_settings *settings =l_settings_new ();
@@ -456,7 +457,7 @@ static void wsc_connect(struct wsc *wsc)struct wsc_association_request request;uint8_t *pdu;size_t pdu_len; -struct iovec ie_iov; +struct iovec ie_iov[1 + ies_num]; wsc->target =NULL ;
@@ -502,18 +503,20 @@ static void wsc_connect(struct wsc *wsc) goto error; } - ie_iov.iov_base =ie_tlv_encapsulate_wsc_payload (pdu, pdu_len, - &ie_iov.iov_len); + ie_iov[0 ].iov_base =ie_tlv_encapsulate_wsc_payload (pdu, pdu_len, + &ie_iov[0 ].iov_len);l_free (pdu); -if (!ie_iov.iov_base) { +if (!ie_iov[0 ].iov_base) { r = -ENOMEM ; goto error; } - r =netdev_connect (wsc->netdev, bss, hs, &ie_iov,1 , wsc_netdev_event, - wsc_connect_cb, wsc); -l_free (ie_iov.iov_base); +memcpy (ie_iov +1 , ies,sizeof (struct iovec ) * ies_num); + + r =netdev_connect (wsc->netdev, bss, hs, ie_iov,1 + ies_num, + wsc_netdev_event, wsc_connect_cb, wsc); +l_free (ie_iov[0 ].iov_base);if (r <0 ) goto error;
@@ -1079,7 +1082,8 @@ void wsc_destroy(struct wsc *wsc) }void wsc_start_enrollee (struct wsc *wsc,struct netdev *netdev, -struct scan_bss *target,const char *pin) +struct scan_bss *target,const char *pin, +struct iovec *ies,unsigned int ies_num) { wsc->netdev = netdev; wsc->target = target;
@@ -1087,7 +1091,7 @@ void wsc_start_enrollee(struct wsc *wsc, struct netdev *netdev,WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON ; wsc->pin =l_strdup (pin); -wsc_connect (wsc); +wsc_connect (wsc, ies, ies_num); }void wsc_cancel (struct wsc *wsc,netdev_disconnect_cb_t cb)
src/wsc.h +2 -1
@@ -47,6 +47,7 @@ struct wsc_ops {struct wsc *wsc_new (const struct wsc_ops *ops,void *user_data);void wsc_start_enrollee (struct wsc *wsc,struct netdev *netdev, -struct scan_bss *target,const char *pin); +struct scan_bss *target,const char *pin, +struct iovec *ies,unsigned int ies_num);void wsc_cancel (struct wsc *wsc,netdev_disconnect_cb_t cb);void wsc_destroy (struct wsc *wsc);
Signature · 1 line
2.20.1
Denis Kenzior
AppliedHi Andrew,
Quoted 10 lines · Andrew Zaborowski
Allow
netdev_create_from_genlcallers to draw a random or non-random MAC and pass it in the parameter instead of a bool to tell us to generating the MAC locally. In P2P we are generating the MAC some time before creating the netdev in order to pass it to the peer during negotiation.--- src/manager.c | 22 ++++++++++++++++++---- src/netdev.c | 45 ++++++++++++++++++++++----------------------- src/netdev.h | 3 ++- 3 files changed, 42 insertions(+), 28 deletions(-)
Applied, thanks.
Regards,
-Denis