diff options
| author | codeworkx <daniel.hillenbrand@codeworkx.de> | 2018-02-03 22:13:53 +0100 |
|---|---|---|
| committer | Michael Bestas <mkbestas@lineageos.org> | 2018-02-19 02:07:17 +0200 |
| commit | a79094a6111c79404332e1e98b5678a8246b3578 (patch) | |
| tree | 0674d661a62bf1480d81402b30dc335ad500af7a /wifi/wifi.c | |
| parent | ec33ac38aedabf66b832bb1c869b8490f2c0121e (diff) | |
| download | android_hardware_libhardware_legacy-cm-14.1.tar.gz android_hardware_libhardware_legacy-cm-14.1.tar.bz2 android_hardware_libhardware_legacy-cm-14.1.zip | |
wifi: add flag to wait for kernel driver to get readycm-14.1
If the wifi hal comes up before the kernel driver gets ready then wifi
will be disabled after the device has fully booted up regardless of the previous state.
This confuses users and is not an expected behaviour.
Example:
WIFI_DRIVER_OPERSTATE_PATH := "/sys/class/net/wlan0/operstate"
Bug: Wifi down after boot
Test: Enable wifi, reboot and check if it's still up
Change-Id: If23d5d6ef0fe75e64053ea779feb6acb37d98850
Diffstat (limited to 'wifi/wifi.c')
| -rw-r--r-- | wifi/wifi.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/wifi/wifi.c b/wifi/wifi.c index e9a2958..de2f8ee 100644 --- a/wifi/wifi.c +++ b/wifi/wifi.c @@ -139,6 +139,11 @@ static const char EXT_MODULE_PATH[] = WIFI_EXT_MODULE_PATH; #define WIFI_DRIVER_FW_PATH_PARAM "/sys/module/wlan/parameters/fwpath" #endif +#ifdef WIFI_DRIVER_OPERSTATE_PATH +#define OPERSTATE_UP "up" +#define OPERSTATE_DOWN "down" +#endif + #define WIFI_DRIVER_LOADER_DELAY 1000000 static const char IFACE_DIR[] = "/data/system/wpa_supplicant"; @@ -347,6 +352,40 @@ int is_wifi_driver_loaded() { #endif } +#ifdef WIFI_DRIVER_OPERSTATE_PATH +int is_wifi_driver_ready() { + struct stat sbuf; + FILE *fstate; + char operstate[8]; + int open_count = 25, read_count = 25; + while (open_count-- >= 0) { + if (stat(WIFI_DRIVER_OPERSTATE_PATH, &sbuf) == 0) { + if ((fstate = fopen(WIFI_DRIVER_OPERSTATE_PATH, "r")) == NULL) { + usleep(500000); + } else { + break; + } + } else { + usleep(500000); + } + } + if (fstate != NULL) { + while (read_count-- >= 0) { + fgets(operstate, sizeof(operstate), fstate); + if (strncmp(operstate, OPERSTATE_UP, strlen(OPERSTATE_UP)) == 0 || + strncmp(operstate, OPERSTATE_DOWN, strlen(OPERSTATE_DOWN)) == 0) { + ALOGI("Wifi driver is ready"); + return 1; + } + ALOGW("Waiting for Wifi driver to get ready. (%d)", read_count); + usleep(500000); + } + fclose(fstate); + } + return 0; +} +#endif + int wifi_load_driver() { char driver_status[PROPERTY_VALUE_MAX]; @@ -396,6 +435,12 @@ int wifi_load_driver() return -1; #endif #endif +#ifdef WIFI_DRIVER_OPERSTATE_PATH + if (!is_wifi_driver_ready()) { + ALOGE("Wifi driver didn't get ready in time, giving up!"); + return -1; + } +#endif if (strcmp(FIRMWARE_LOADER,"") == 0) { /* usleep(WIFI_DRIVER_LOADER_DELAY); */ |
