diff options
author | Calvin On <con@google.com> | 2018-04-03 14:56:41 -0700 |
---|---|---|
committer | Calvin On <con@google.com> | 2018-04-24 17:25:09 +0000 |
commit | 23a2406046c232e1b11ba3ccaf1b4aed73f06c30 (patch) | |
tree | 39b3dcca5a978c515dd4f01194f7150188347359 | |
parent | 900acba649cd91c25929bdea60fdb3e0a9ab6e00 (diff) | |
download | hardware_replicant_wlan-23a2406046c232e1b11ba3ccaf1b4aed73f06c30.tar.gz hardware_replicant_wlan-23a2406046c232e1b11ba3ccaf1b4aed73f06c30.tar.bz2 hardware_replicant_wlan-23a2406046c232e1b11ba3ccaf1b4aed73f06c30.zip |
WiFi: Vendor HAL function to wait for driver ready
This commit adds a vendor hal function to wait for the driver to be
ready. This ensures the driver is ready for operation before framework
starts to use it.
Note: Broadcom mentioned that checking for the presence of
/sys/class/net/wlan0 may not guarantee that WiFi is fully
initialized, and we should check /sys/class/net/wlan0/flags
for IFF_UP instead.
However, this doesn't work. The /sys/class/net/wlan0/flags value
never moves beyond 0x1002 when WiFi is turned on, until after this
function (and its subsequent functions) is invoked.
Bug: 74120746
Change-Id: If8c624c4580d456abcb1437493783b3f114d5961
-rw-r--r-- | bcmdhd/wifi_hal/wifi_hal.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/bcmdhd/wifi_hal/wifi_hal.cpp b/bcmdhd/wifi_hal/wifi_hal.cpp index 511ff3f..81cad8a 100644 --- a/bcmdhd/wifi_hal/wifi_hal.cpp +++ b/bcmdhd/wifi_hal/wifi_hal.cpp @@ -60,6 +60,13 @@ #define WIFI_HAL_CMD_SOCK_PORT 644 #define WIFI_HAL_EVENT_SOCK_PORT 645 +/* + * Defines for wifi_wait_for_driver_ready() + * Specify durations between polls and max wait time + */ +#define POLL_DRIVER_DURATION_US (100000) +#define POLL_DRIVER_MAX_TIME_MS (10000) + static void internal_event_handler(wifi_handle handle, int events); static int internal_no_seq_check(nl_msg *msg, void *arg); static int internal_valid_message_handler(nl_msg *msg, void *arg); @@ -151,6 +158,7 @@ wifi_error init_wifi_vendor_hal_func_table(wifi_hal_fn *fn) return WIFI_ERROR_UNKNOWN; } fn->wifi_initialize = wifi_initialize; + fn->wifi_wait_for_driver_ready = wifi_wait_for_driver_ready; fn->wifi_cleanup = wifi_cleanup; fn->wifi_event_loop = wifi_event_loop; fn->wifi_get_supported_feature_set = wifi_get_supported_feature_set; @@ -306,6 +314,25 @@ wifi_error wifi_initialize(wifi_handle *handle) return WIFI_SUCCESS; } +wifi_error wifi_wait_for_driver_ready(void) +{ + // This function will wait to make sure basic client netdev is created + // Function times out after 10 seconds + int count = (POLL_DRIVER_MAX_TIME_MS * 1000) / POLL_DRIVER_DURATION_US; + FILE *fd; + + do { + if ((fd = fopen("/sys/class/net/wlan0", "r")) != NULL) { + fclose(fd); + return WIFI_SUCCESS; + } + usleep(POLL_DRIVER_DURATION_US); + } while(--count > 0); + + ALOGE("Timed out waiting on Driver ready ... "); + return WIFI_ERROR_TIMED_OUT; +} + static int wifi_add_membership(wifi_handle handle, const char *group) { hal_info *info = getHalInfo(handle); |