station: Move 'connected' logic out of enter state func
PATCH v2 1/3 station: Move 'connected' logic out of enter state func
Previously, station state 'connected' used to identify an interface associated with AP. With the introduction of netconfig, an interface is assumed to be connected after the IP addresses have been assigned to it. If netconfig is disabled, the behavior remains unchanged.
--- src/station.c | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-)
src/station.c +17 -24
@@ -1158,26 +1158,9 @@ static void station_enter_state(struct station *station, IWD_NETWORK_INTERFACE, "Connected");/* fall through */ case STATION_STATE_DISCONNECTED : -periodic_scan_stop (station); - -break ;case STATION_STATE_CONNECTED :periodic_scan_stop (station); -if (!station->netconfig) -break ; - -if (station->state ==STATION_STATE_ROAMING ) { -netconfig_reconfigure (station->netconfig); - -break ; - } - -netconfig_configure (station->netconfig, -network_get_settings ( - station->connected_network), -netdev_get_address ( - station->netdev));break ;case STATION_STATE_DISCONNECTING :case STATION_STATE_ROAMING :
@@ -1302,6 +1285,11 @@ static void station_roamed(struct station *station) station->signal_low = false; station->roam_min_time.tv_sec =0 ; station->roam_no_orig_ap = false; + +if (station->netconfig) +netconfig_reconfigure (station->netconfig); + +station_enter_state (station,STATION_STATE_CONNECTED ); }static void station_roam_failed (struct station *station)
@@ -1338,10 +1326,9 @@ static void station_reassociate_cb(struct netdev *netdev,if (station->state !=STATION_STATE_ROAMING )return ; -if (result ==NETDEV_RESULT_OK ) { +if (result ==NETDEV_RESULT_OK )station_roamed (station); -station_enter_state (station,STATION_STATE_CONNECTED ); - }else +else station_roam_failed (station); }
@@ -1357,10 +1344,9 @@ static void station_fast_transition_cb(struct netdev *netdev,if (station->state !=STATION_STATE_ROAMING )return ; -if (result ==NETDEV_RESULT_OK ) { +if (result ==NETDEV_RESULT_OK )station_roamed (station); -station_enter_state (station,STATION_STATE_CONNECTED ); - }else +else station_roam_failed (station); }
@@ -2280,7 +2266,14 @@ static void station_connect_cb(struct netdev *netdev, enum netdev_result result, }network_connected (station->connected_network); -station_enter_state (station,STATION_STATE_CONNECTED ); + +if (station->netconfig) +netconfig_configure (station->netconfig, +network_get_settings ( + station->connected_network), +netdev_get_address (station->netdev)); +else +station_enter_state (station,STATION_STATE_CONNECTED ); } int __station_connect_network(struct station *station, struct network *network,
Signature · 1 line
2.13.6
PATCH v2 2/3 netconfig: Add netconfig event notifier
The notifier allows to subscribe for the netconfig events such as ‘connected’.
--- src/netconfig.c | 29 ++++++++++++++++++++++------- src/netconfig.h | 11 ++++++++++- 2 files changed, 32 insertions(+), 8 deletions(-)
src/netconfig.c +22 -7
@@ -50,6 +50,9 @@ struct netconfig {uint8_t rtm_v6_protocol;const struct l_settings *active_settings; + +netconfig_notify_func_t notify; +void *user_data; };struct netconfig_ifaddr {
@@ -595,11 +598,19 @@ static void netconfig_route_add_cmd_cb(int error, uint16_t type, const void *data, uint32_t len, void *user_data) { - if (!error) - return; + struct netconfig *netconfig = user_data; -l_error ("netconfig: Failed to add route. Error %d: %s" , +if (error) { +l_error ("netconfig: Failed to add route. Error %d: %s" , error,strerror (-error)); +return ; + } + +if (!netconfig->notify) +return ; + + netconfig->notify (NETCONFIG_EVENT_CONNECTED , netconfig->user_data); + netconfig->notify =NULL ; } static void netconfig_route_del_cmd_cb(int error, uint16_t type,
@@ -611,6 +622,7 @@ static void netconfig_route_del_cmd_cb(int error, uint16_t type,l_error ("netconfig: Failed to delete route. Error %d: %s" , error,strerror (-error)); + } static bool netconfig_ipv4_routes_install(struct netconfig *netconfig,
@@ -635,7 +647,7 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig, ifaddr->ip, netconfig->rtm_protocol, netconfig_route_add_cmd_cb, - NULL, NULL)) { + netconfig, NULL)) {l_error ("netconfig: Failed to add subnet route." );return false;
@@ -655,7 +667,7 @@ static bool netconfig_ipv4_routes_install(struct netconfig *netconfig, ROUTE_PRIORITY_OFFSET, netconfig->rtm_protocol, netconfig_route_add_cmd_cb, - NULL, NULL)) { + netconfig, NULL)) {l_error ("netconfig: Failed to add route for: %s gateway." , gateway);
@@ -723,7 +735,7 @@ static bool netconfig_ipv6_routes_install(struct netconfig *netconfig) ROUTE_PRIORITY_OFFSET, netconfig->rtm_v6_protocol, netconfig_route_add_cmd_cb, - NULL, NULL)) { + netconfig, NULL)) {l_error ("netconfig: Failed to add route for: %s gateway." , gateway);
@@ -1020,9 +1032,12 @@ static void netconfig_ipv6_select_and_uninstall(struct netconfig *netconfig)bool netconfig_configure (struct netconfig *netconfig,const struct l_settings *active_settings, -const uint8_t *mac_address) +const uint8_t *mac_address, +netconfig_notify_func_t notify,void *user_data) { netconfig->active_settings = active_settings; + netconfig->notify = notify; + netconfig->user_data = user_data;l_dhcp_client_set_address (netconfig->dhcp_client,ARPHRD_ETHER , mac_address,ETH_ALEN );
src/netconfig.h +10 -1
@@ -22,9 +22,18 @@struct netconfig ; +enum netconfig_event { +NETCONFIG_EVENT_CONNECTED , +}; + +typedef void (*netconfig_notify_func_t )(enum netconfig_event event, +void *user_data); +bool netconfig_configure (struct netconfig *netconfig,const struct l_settings *active_settings, -const uint8_t *mac_address); +const uint8_t *mac_address, +netconfig_notify_func_t notify, +void *user_data);bool netconfig_reconfigure (struct netconfig *netconfig);bool netconfig_reset (struct netconfig *netconfig);
Signature · 1 line
2.13.6
Re: [PATCH v2 2/3] netconfig: Add netconfig event notifier
Hi Tim,
Quoted 6 lines · Tim Kourt
The notifier allows to subscribe for the netconfig events such as ‘connected’.
--- src/netconfig.c | 29 ++++++++++++++++++++++------- src/netconfig.h | 11 ++++++++++- 2 files changed, 32 insertions(+), 8 deletions(-)
Patch 2 & 3 applied, thanks.
Regards,
-Denis
PATCH v2 3/3 station: Subscribe to netconfig event notifier
In reply to Tim Kourt--- src/station.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
src/station.c +19 -1
@@ -1314,6 +1314,22 @@ static void station_roam_failed(struct station *station)station_roam_timeout_rearm (station,60 ); } +static void station_netconfig_event_handler (enum netconfig_event event, +void *user_data) +{ +struct station *station = user_data; + +switch (event) { +case NETCONFIG_EVENT_CONNECTED : +station_enter_state (station,STATION_STATE_CONNECTED ); + +break ; +default : +l_error ("station: Unsupported netconfig event: %d." , event); +break ; + } +} + static void station_reassociate_cb(struct netdev *netdev, enum netdev_result result, void *event_data,
@@ -2271,7 +2287,9 @@ static void station_connect_cb(struct netdev *netdev, enum netdev_result result,netconfig_configure (station->netconfig,network_get_settings ( station->connected_network), -netdev_get_address (station->netdev)); +netdev_get_address (station->netdev), + station_netconfig_event_handler, + station); elsestation_enter_state (station ,STATION_STATE_CONNECTED ); }
Signature · 1 line
2.13.6
Denis Kenzior
AppliedHi Tim,
Quoted 8 lines · Tim Kourt
Previously, station state 'connected' used to identify an interface associated with AP. With the introduction of netconfig, an interface is assumed to be connected after the IP addresses have been assigned to it. If netconfig is disabled, the behavior remains unchanged.
--- src/station.c | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-)
Applied, thanks.
Regards,
-Denis