From eaaedb6ae892d90afcce57655742a79a48249cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Fri, 10 Mar 2023 16:53:35 +0100 Subject: [PATCH] wifi: defer supplicant start-up The SDIO connected wireless device on the PinePhone is not available on start-up, which leads to the supplicant failing to initalize 'wlan0'. Normally the supplicant would be used in a way that handling devices that appear at run-time happens gracefully. Rather than supporting this behavior we defer the start-up of the supplicant until the device could be openend successfully for now. Issue #4813 --- repos/pc/src/lib/wifi/socket_call.cc | 6 ------ repos/pc/src/lib/wifi/uplink.c | 29 +++++++++++++++++++++++++++- repos/pc/src/lib/wifi/wlan.cc | 13 ++++++++++++- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/repos/pc/src/lib/wifi/socket_call.cc b/repos/pc/src/lib/wifi/socket_call.cc index 97b240dcfd..353027155b 100644 --- a/repos/pc/src/lib/wifi/socket_call.cc +++ b/repos/pc/src/lib/wifi/socket_call.cc @@ -474,10 +474,6 @@ class Lx::Socket static Lx::Socket *_socket; - -/* implemented in wlan.cc */ -extern Blockade *wpa_blockade; - /* implemented in wlan.cc */ void _wifi_report_mac_address(Net::Mac_address const &mac_address); @@ -489,8 +485,6 @@ extern "C" int socketcall_task_function(void *) void const *mac_addr = nullptr; - wpa_blockade->wakeup(); - while (true) { /* diff --git a/repos/pc/src/lib/wifi/uplink.c b/repos/pc/src/lib/wifi/uplink.c index 11434c2b10..f9fd517a3a 100644 --- a/repos/pc/src/lib/wifi/uplink.c +++ b/repos/pc/src/lib/wifi/uplink.c @@ -227,6 +227,26 @@ static int uplink_netdev_event(struct notifier_block *this, } +static int new_device_netdev_event(struct notifier_block *this, + unsigned long event, void *ptr) +{ + if (event == NETDEV_REGISTER) + if (uplink_task_struct_ptr) + lx_emul_task_unblock(uplink_task_struct_ptr); + + return NOTIFY_DONE; +} + + +static struct notifier_block new_device_netdev_notifier = { + .notifier_call = new_device_netdev_event, +}; + + +/* implemented by wlan.cc */ +extern void wakeup_wpa(void); + + static int user_task_function(void *arg) { struct netdev_event_notification events; @@ -235,6 +255,12 @@ static int user_task_function(void *arg) events.nb.notifier_call = uplink_netdev_event; events.registered = false; + if (register_netdevice_notifier(&new_device_netdev_notifier)) { + printk("%s:%d: could not register netdev notifer for " + "new devices, abort\n", __func__, __LINE__); + return -1; + } + for (;;) { struct net_device *dev; @@ -246,7 +272,8 @@ static int user_task_function(void *arg) continue; /* enable link sensing, repeated calls are handled by testing IFF_UP */ - dev_open(dev, 0); + if (dev_open(dev, 0) == 0) + wakeup_wpa(); /* install rx handler once */ if (!netdev_is_rx_handler_busy(dev)) diff --git a/repos/pc/src/lib/wifi/wlan.cc b/repos/pc/src/lib/wifi/wlan.cc index 04380f9977..5b2e8c47c0 100644 --- a/repos/pc/src/lib/wifi/wlan.cc +++ b/repos/pc/src/lib/wifi/wlan.cc @@ -180,7 +180,18 @@ struct Wlan }; -Blockade *wpa_blockade; +static Blockade *wpa_blockade; + + +extern "C" void wakeup_wpa() +{ + static bool called_once = false; + if (called_once) + return; + + wpa_blockade->wakeup(); + called_once = true; +} void wifi_init(Env &env, Blockade &blockade)