wfd-source: Fix some races on iwd name owner change
PATCH 1/6 wfd-source: Fix some races on iwd name owner change
Subscribe to InterfacesAdded/Removed/PropertiesChanged signals before using GetManagedObjects. For some reason when iwd starts after the client, we consistently get the managed objects list from before Adapter interfaces are added but we miss the subsequent InterfacesAdded signals, probably has to do with the GetManagedObjects and the AddMatch calls all being synchronous.
Secondly call self.populate_devices() on init as it won't be called if IWD is not on the bus.
--- test/wfd-source | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
test/wfd-source +13 -11
@@ -826,6 +826,7 @@ class WFDSource(Gtk.Window): self.rtsp_port = 7236 self.devices = None self.objects = {} + self.populate_devices() self.dbus = dbus.SystemBus() self.dbus.watch_name_owner('net.connman.iwd', self.on_name_owner_change) self.on_name_owner_change('dummy' if self.dbus.name_has_owner('net.connman.iwd') else '')
@@ -857,17 +858,6 @@ class WFDSource(Gtk.Window): return True manager = dbus.Interface(self.dbus.get_object('net.connman.iwd', '/'), 'org.freedesktop.DBus.ObjectManager') - self.devices = {} - self.objects = manager.GetManagedObjects() - - for path in self.objects: - if DEVICE_IF in self.objects[path]: - self.add_dev(path) - for path in self.objects: - if PEER_IF in self.objects[path]: - self.add_peer(path) - - self.populate_devices() self.dbus.add_signal_receiver(self.on_properties_changed, bus_name="net.connman.iwd",
@@ -883,6 +873,18 @@ class WFDSource(Gtk.Window): dbus_interface="org.freedesktop.DBus.ObjectManager", signal_name="InterfacesRemoved") + self.objects = manager.GetManagedObjects() + self.devices = {} + + for path in self.objects: + if DEVICE_IF in self.objects[path]: + self.add_dev(path) + for path in self.objects: + if PEER_IF in self.objects[path]: + self.add_peer(path) + + self.populate_devices() + svc_mgr = dbus.Interface(self.dbus.get_object('net.connman.iwd', '/net/connman/iwd'), SVC_MGR_IF) svc_mgr.RegisterDisplayService({ 'Source': True,
Signature · 1 line
2.25.1
PATCH 2/6 wfd-source: Update the switch state using set_state
The Gtk.Switch representing the p2p.Device's Enabled property should use the "delayed state change" logic as described in Gtk.Switch docs, i.e. we need to use .set_state() instead of .set_active() when we get confirmation of the property having changed its value in the PropertiesChanged handler. The ::active property is automatically changed by Gtk.Switch on user input.
This way the UI gives visual feedback of when the device enable/disable op starts and ends (or fails).
--- test/wfd-source | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
test/wfd-source +1 -2
@@ -1116,7 +1116,7 @@ class WFDSource(Gtk.Window): dev_str = self.get_dev_string(path) name = str(device.props['Name']) label.set_markup(dev_str + '\n<small>' + ('Local name: ' + name + '\n' if dev_str != name else '') + 'State: ' + state + '</small>') - switch.set_active(device.props['Enabled']) + switch.set_state(device.props['Enabled']) def update_peer_props(self, dev_path, path): device = self.devices[dev_path]
@@ -1560,7 +1560,6 @@ class WFDSource(Gtk.Window): device = self.devices[path] if device.props['Enabled'] == state: return - device.props['Enabled'] = state device.props_proxy.Set(DEVICE_IF, 'Enabled', state) return True
Signature · 1 line
2.25.1
PATCH 3/6 scan: Always allocate results->bss_list
In reply to Andrew ZaborowskiInstead of creating the results->bss_list l_queue lazily, always create one before sending the GET_SCAN command. This is to make sure that an empty list is passed to the scan callback (e.g. in station.c) instead of a NULL. Passing NULL has been causing difficult to debug crashes in station.c, in fact I think I've been seeing them for over a year now but can't be sure. station_set_scan_results has been taking ownership of the new BSS list and, if station->connected_bss was not on the list, it would try to add it not realizing that l_queue_push_tail() was doing nothing. Always passing a valid list may help us prevent similar problems in the future.
The crash might start with:
==120489== Invalid read of size 8
==120489== at 0x425D38: network_bss_select (network.c:709) ==120489== by 0x415BD1: station_try_next_bss (station.c:2263) ==120489== by 0x415E31: station_retry_with_status (station.c:2323) ==120489== by 0x415E31: station_connect_cb (station.c:2367) ==120489== by 0x407E66: netdev_connect_failed (netdev.c:569) ==120489== by 0x40B93D: netdev_connect_event (netdev.c:1801) ==120489== by 0x40B93D: netdev_mlme_notify (netdev.c:3678) --- src/scan.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
src/scan.c +1 -3
@@ -1448,9 +1448,6 @@ static void get_scan_callback(struct l_genl_msg *msg, void *user_data)l_debug ("get_scan_callback" ); -if (!results->bss_list) - results->bss_list =l_queue_new (); - bss =scan_parse_result (msg, &wdev_id);if (!bss)return ;
@@ -1694,6 +1691,7 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data) results->sc = sc; results->time_stamp =l_time_now (); results->sr = sr; + results->bss_list =l_queue_new ();scan_parse_new_scan_results (msg, results);
Signature · 1 line
2.25.1
PATCH 4/6 ap: Put a public api between AP logic and DBus code
In reply to Andrew ZaborowskiSeparate AP logic from DBus code, add a public API to make the AP logic reusable from other files.
--- Makefile.am | 2 +- src/ap.c | 377 +++++++++++++++++++++++++++++++++++++--------------- src/ap.h | 56 ++++++++ 3 files changed, 328 insertions(+), 107 deletions(-) create mode 100644 src/ap.h
Makefile.am +1 -1
@@ -207,7 +207,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \ src/knownnetworks.c \ src/rfkill.h src/rfkill.c \ src/ft.h src/ft.c \ - src/ap.c src/adhoc.c \ + src/ap.h src/ap.c src/adhoc.c \ src/sae.h src/sae.c \ src/nl80211util.h src/nl80211util.c \ src/nl80211cmd.h src/nl80211cmd.c \
src/ap.c +271 -106
563 lines not on this page · raw message
src/ap.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 5/6 ap: Add a no_cck_rates flag
In reply to Andrew Zaborowski--- src/ap.c | 33 ++++++++++++++++++++++++++------- src/ap.h | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-)
src/ap.c +26 -7
@@ -71,6 +71,7 @@ struct ap_state { bool started : 1; bool gtk_set : 1; + bool no_cck_rates : 1; };struct sta_state {
@@ -382,6 +383,11 @@ static uint32_t ap_send_mgmt_frame(struct ap_state *ap,l_genl_msg_append_attr (msg,NL80211_ATTR_DONT_WAIT_FOR_ACK ,0 ,NULL ); +if (ap->no_cck_rates) +l_genl_msg_append_attr (msg,NL80211_ATTR_TX_NO_CCK_RATE ,0 , +NULL ); + + id =l_genl_family_send (ap->nl80211, msg, callback, user_data,NULL );if (!id)
@@ -1440,7 +1446,7 @@ static void ap_mlme_notify(struct l_genl_msg *msg, void *user_data)* @channel is optional. */ struct ap_state *ap_start (struct netdev *netdev,const char *ssid, -const char *psk,int channel, +const char *psk,int channel,bool no_cck_rates,ap_event_func_t event_func,void *user_data) {struct ap_state *ap;
@@ -1452,6 +1458,7 @@ struct ap_state *ap_start(struct netdev *netdev, const char *ssid, ap->nl80211 =l_genl_family_new (iwd_get_genl (),NL80211_GENL_NAME ); ap->ssid =l_strdup (ssid); ap->netdev = netdev; + ap->no_cck_rates = no_cck_rates; ap->event_func = event_func; ap->user_data = user_data;
@@ -1466,11 +1473,23 @@ struct ap_state *ap_start(struct netdev *netdev, const char *ssid, ap->ciphers =wiphy_select_cipher (wiphy,0xffff ); ap->group_cipher =wiphy_select_cipher (wiphy,0xffff ); ap->beacon_interval =100 ; -/* TODO: Use actual supported rates */ - ap->rates =l_uintset_new (200 ); -l_uintset_put (ap->rates,2 );/* 1 Mbps*/ -l_uintset_put (ap->rates,11 );/* 5.5 Mbps*/ -l_uintset_put (ap->rates,22 );/* 11 Mbps*/ + +/* TODO: Pick from actual supported rates */ +if (no_cck_rates) { +l_uintset_put (ap->rates,12 );/* 6 Mbps*/ +l_uintset_put (ap->rates,18 );/* 9 Mbps*/ +l_uintset_put (ap->rates,24 );/* 12 Mbps*/ +l_uintset_put (ap->rates,36 );/* 18 Mbps*/ +l_uintset_put (ap->rates,48 );/* 24 Mbps*/ +l_uintset_put (ap->rates,72 );/* 36 Mbps*/ +l_uintset_put (ap->rates,96 );/* 48 Mbps*/ +l_uintset_put (ap->rates,108 );/* 54 Mbps*/ + }else { + ap->rates =l_uintset_new (200 ); +l_uintset_put (ap->rates,2 );/* 1 Mbps*/ +l_uintset_put (ap->rates,11 );/* 5.5 Mbps*/ +l_uintset_put (ap->rates,22 );/* 11 Mbps*/ + }if (crypto_psk_from_passphrase (psk, (uint8_t *) ssid,strlen (ssid), ap->pmk) <0 )
@@ -1716,7 +1735,7 @@ static struct l_dbus_message *ap_dbus_start(struct l_dbus *dbus,if (!l_dbus_message_get_arguments (message,"ss" , &ssid, &wpa2_psk))return dbus_error_invalid_args (message); - ap_if->ap =ap_start (ap_if->netdev, ssid, wpa2_psk,0 , + ap_if->ap =ap_start (ap_if->netdev, ssid, wpa2_psk,0 , false, ap_if_event_func, ap_if);if (!ap_if->ap)return dbus_error_invalid_args (message);
src/ap.h +1 -1
@@ -46,7 +46,7 @@ typedef void (*ap_event_func_t)(enum ap_event_type type, const void *event_data,typedef void (*ap_stopped_func_t )(void *user_data);struct ap_state *ap_start (struct netdev *netdev,const char *ssid, -const char *psk,int channel, +const char *psk,int channel,bool no_cck_rates,ap_event_func_t event_func,void *user_data);void ap_shutdown (struct ap_state *ap,ap_stopped_func_t stopped_func,void *user_data);
Signature · 1 line
2.25.1
PATCH 6/6 ap: Add authorized_macs parameter
In reply to Andrew Zaborowski--- src/ap.c | 31 ++++++++++++++++++++++++++++++- src/ap.h | 1 + 2 files changed, 31 insertions(+), 1 deletion(-)
src/ap.c +30 -1
@@ -55,6 +55,8 @@ struct ap_state {void *user_data;char *ssid;uint8_t channel; +uint8_t *authorized_macs; +int authorized_macs_num;unsigned int ciphers;enum ie_rsn_cipher_suite group_cipher;
@@ -136,6 +138,7 @@ static void ap_reset(struct ap_state *ap)if (ap->rates)l_uintset_free (ap->rates); +l_free (ap->authorized_macs); ap->started = false; }
@@ -1243,6 +1246,19 @@ static void ap_auth_cb(const struct mmpdu_header *hdr, const void *body, memcmp(hdr->address_3, bssid, 6))return ; +if (ap->authorized_macs) { +int i; + +for (i =0 ; i < ap->authorized_macs_num; i++) +if (!memcmp (from, ap->authorized_macs + i *6 ,6 )) +break ; + +if (i == ap->authorized_macs_num) { +ap_auth_reply (ap, from,MMPDU_REASON_CODE_UNSPECIFIED ); +return ; + } + } +/* Only Open System authentication implemented here */ if (L_LE16_TO_CPU (auth->algorithm) !=MMPDU_AUTH_ALGO_OPEN_SYSTEM ) {
@@ -1447,6 +1463,7 @@ static void ap_mlme_notify(struct l_genl_msg *msg, void *user_data)*/ struct ap_state *ap_start (struct netdev *netdev,const char *ssid,const char *psk,int channel,bool no_cck_rates, +const uint8_t **authorized_macs,ap_event_func_t event_func,void *user_data) {struct ap_state *ap;
@@ -1469,6 +1486,18 @@ struct ap_state *ap_start(struct netdev *netdev, const char *ssid, ap->channel =6 ; } +if (authorized_macs) { +int i; + +for (i =0 ; authorized_macs[i]; i++); + ap->authorized_macs =l_malloc (i *6 ); + ap->authorized_macs_num = i; + +for (i =0 ; authorized_macs[i]; i++) +memcpy (ap->authorized_macs + i *6 , authorized_macs[i], +6 ); + } +/* TODO: Add all ciphers supported by wiphy */ ap->ciphers =wiphy_select_cipher (wiphy,0xffff ); ap->group_cipher =wiphy_select_cipher (wiphy,0xffff );
@@ -1735,7 +1764,7 @@ static struct l_dbus_message *ap_dbus_start(struct l_dbus *dbus,if (!l_dbus_message_get_arguments (message,"ss" , &ssid, &wpa2_psk))return dbus_error_invalid_args (message); - ap_if->ap =ap_start (ap_if->netdev, ssid, wpa2_psk,0 , false, + ap_if->ap =ap_start (ap_if->netdev, ssid, wpa2_psk,0 , false,NULL , ap_if_event_func, ap_if);if (!ap_if->ap)return dbus_error_invalid_args (message);
src/ap.h +1 -0
@@ -47,6 +47,7 @@ typedef void (*ap_stopped_func_t)(void *user_data);struct ap_state *ap_start (struct netdev *netdev,const char *ssid,const char *psk,int channel,bool no_cck_rates, +const uint8_t **authorized_macs,ap_event_func_t event_func,void *user_data);void ap_shutdown (struct ap_state *ap,ap_stopped_func_t stopped_func,void *user_data);
Signature · 1 line
2.25.1
Re: [PATCH 6/6] ap: Add authorized_macs parameter
Hi Andrew,
Quoted 5 lines · Andrew Zaborowski
--- src/ap.c | 31 ++++++++++++++++++++++++++++++- src/ap.h | 1 + 2 files changed, 31 insertions(+), 1 deletion(-)
<snip>
src/ap.h typedef void (*ap_stopped_func_t)(void *user_data); · line 51
Quoted 10 lines
src/ap.h +1
-0@@ -47,6 +47,7 @@ typedef void (*ap_stopped_func_t)(void *user_data);struct ap_state *ap_start (struct netdev *netdev,const char *ssid,const char *psk,int channel,bool no_cck_rates, +const uint8_t **authorized_macs,ap_event_func_t event_func,void *user_data);
By the way, you're pretty much at the limit of sane number of arguments here. If you decide to add any more, I suggest a struct ap_config object of some sort with a nice set/get api that ap_start could take ownership of.
src/ap.h typedef void (*ap_stopped_func_t)(void *user_data); · line 53
Quoted 3 lines
src/ap.h +0
-0void ap_shutdown (struct ap_state *ap,ap_stopped_func_t stopped_func,void *user_data);
Regards,
-Denis