From 078ebedbc78d4a897dfb68abcca575b3b873ed3c Mon Sep 17 00:00:00 2001 From: Dheeraj CVR Date: Sun, 21 Dec 2014 01:45:29 +0530 Subject: bcmdhd: workaround for driver compiled as a module BCMDHD driver on several Samsung and few Sony devices is compiled as a module rather than being built into the kernel. Hence, the wlan0 interface is removed when the WiFi is turned off and the driver is unloaded. This causes the WiFi HAL to crash when the device is booted with WiFi turned off since with the absence of wlan0 interface, the WiFi interfaces in the HAL are not initialized. As a workaround, we check if the driver is loaded and if not, we temporarily load and unload the WiFi driver inorder to query the interfaces and initialize them. This atleast prevents the system from crashing and rebooting when the device is suspended. Change-Id: Ia7c2ce79a58e9eb6711fbf5f53f1d449cc27af87 --- bcmdhd/wifi_hal/wifi_hal.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bcmdhd/wifi_hal/wifi_hal.cpp b/bcmdhd/wifi_hal/wifi_hal.cpp index a99b156..ff7a6ec 100644 --- a/bcmdhd/wifi_hal/wifi_hal.cpp +++ b/bcmdhd/wifi_hal/wifi_hal.cpp @@ -27,6 +27,7 @@ #include +#include "wifi.h" #include "wifi_hal.h" #include "common.h" #include "cpp_bindings.h" @@ -646,6 +647,22 @@ wifi_error wifi_init_interfaces(wifi_handle handle) hal_info *info = (hal_info *)handle; struct dirent *de; + int moduleflag = 0; + int ret = 0; + + /* Check to see if the wifi driver is loaded */ + if (!is_wifi_driver_loaded()) { + /* If the bcmdhd driver is built as a module, + * it may not be loaded at this stage. Hence + * we load the driver manually just for the + * sake of querying the interfaces. + */ + ret = wifi_load_driver(); + if (ret < 0) + return WIFI_ERROR_UNKNOWN; + + moduleflag = 1; + } DIR *d = opendir("/sys/class/net"); if (d == 0) @@ -686,6 +703,13 @@ wifi_error wifi_init_interfaces(wifi_handle handle) closedir(d); + /* Unload the wifi driver if we have loaded it previously. */ + if (moduleflag) { + ret = wifi_unload_driver(); + if (ret < 0) + return WIFI_ERROR_UNKNOWN; + } + info->num_interfaces = n; return WIFI_SUCCESS; } -- cgit v1.2.3