Skip to content

Commit ffe6305

Browse files
Tomasz BursztykaDaniel Wagner
authored andcommitted
wifi: Interface creation callback might arise when it is not ready yet
This fixes a corner cases: sometime, when an interface has been created it might not be ready yet when the callback is triggered. Thus leading to non-fully set up device: powered is still off, no bgscan, no autoscan. Reported by: Simon Busch <morphis@gravedo.de>
1 parent f62d6d6 commit ffe6305

1 file changed

Lines changed: 35 additions & 19 deletions

File tree

‎plugins/wifi.c‎

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ struct wifi_data {
9797
connman_bool_t disconnecting;
9898
connman_bool_t tethering;
9999
connman_bool_t bridged;
100+
connman_bool_t interface_ready;
100101
const char *bridge;
101102
int index;
102103
unsigned flags;
@@ -773,24 +774,9 @@ static void interface_autoscan_callback(int result,
773774
}
774775
}
775776

776-
static void interface_create_callback(int result,
777-
GSupplicantInterface *interface,
778-
void *user_data)
777+
static void finalize_interface_creation(struct wifi_data *wifi)
779778
{
780-
struct wifi_data *wifi = user_data;
781-
782-
DBG("result %d ifname %s, wifi %p", result,
783-
g_supplicant_interface_get_ifname(interface),
784-
wifi);
785-
786-
if (result < 0 || wifi == NULL)
787-
return;
788-
789-
wifi->interface = interface;
790-
g_supplicant_interface_set_data(interface, wifi);
791-
792-
if (g_supplicant_interface_get_ready(interface) == FALSE)
793-
return;
779+
GSupplicantInterface *interface = wifi->interface;
794780

795781
DBG("interface is ready wifi %p tethering %d", wifi, wifi->tethering);
796782

@@ -812,6 +798,28 @@ static void interface_create_callback(int result,
812798
}
813799
}
814800

801+
static void interface_create_callback(int result,
802+
GSupplicantInterface *interface,
803+
void *user_data)
804+
{
805+
struct wifi_data *wifi = user_data;
806+
807+
DBG("result %d ifname %s, wifi %p", result,
808+
g_supplicant_interface_get_ifname(interface),
809+
wifi);
810+
811+
if (result < 0 || wifi == NULL)
812+
return;
813+
814+
wifi->interface = interface;
815+
g_supplicant_interface_set_data(interface, wifi);
816+
817+
if (g_supplicant_interface_get_ready(interface) == TRUE) {
818+
wifi->interface_ready = TRUE;
819+
finalize_interface_creation(wifi);
820+
}
821+
}
822+
815823
static int wifi_enable(struct connman_device *device)
816824
{
817825
struct wifi_data *wifi = connman_device_get_data(device);
@@ -1562,10 +1570,18 @@ static void interface_state(GSupplicantInterface *interface)
15621570
if (wifi == NULL)
15631571
return;
15641572

1565-
network = wifi->network;
15661573
device = wifi->device;
1574+
if (device == NULL)
1575+
return;
15671576

1568-
if (device == NULL || network == NULL)
1577+
if (g_supplicant_interface_get_ready(interface) == TRUE &&
1578+
wifi->interface_ready == FALSE) {
1579+
wifi->interface_ready = TRUE;
1580+
finalize_interface_creation(wifi);
1581+
}
1582+
1583+
network = wifi->network;
1584+
if (network == NULL)
15691585
return;
15701586

15711587
switch (state) {

0 commit comments

Comments
 (0)