OSDN Git Service

wifi: do not hardcode module name and path
authorChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 3 Sep 2010 03:11:32 +0000 (11:11 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Mon, 2 May 2011 10:49:42 +0000 (18:49 +0800)
The module name and path can be obtained by the properties
wlan.modname and wlan.modpath.

wifi/wifi.c

index 9a2cbbd..753efa2 100644 (file)
@@ -65,12 +65,11 @@ static char iface[PROPERTY_VALUE_MAX];
 #define WIFI_DRIVER_LOADER_DELAY       1000000
 
 static const char IFACE_DIR[]           = "/data/system/wpa_supplicant";
-static const char DRIVER_MODULE_NAME[]  = WIFI_DRIVER_MODULE_NAME;
-static const char DRIVER_MODULE_TAG[]   = WIFI_DRIVER_MODULE_NAME " ";
-static const char DRIVER_MODULE_PATH[]  = WIFI_DRIVER_MODULE_PATH;
 static const char DRIVER_MODULE_ARG[]   = WIFI_DRIVER_MODULE_ARG;
 static const char FIRMWARE_LOADER[]     = WIFI_FIRMWARE_LOADER;
 static const char DRIVER_PROP_NAME[]    = "wlan.driver.status";
+static const char DRIVER_NAME_PROP[]    = "wlan.modname";
+static const char DRIVER_PATH_PROP[]    = "wlan.modpath";
 static const char SUPPLICANT_NAME[]     = "wpa_supplicant";
 static const char SUPP_PROP_NAME[]      = "init.svc.wpa_supplicant";
 static const char SUPP_CONFIG_TEMPLATE[]= "/system/etc/wifi/wpa_supplicant.conf";
@@ -136,14 +135,16 @@ const char *get_dhcp_error_string() {
 }
 
 static int check_driver_loaded() {
-    char driver_status[PROPERTY_VALUE_MAX];
+    char modname[PROPERTY_VALUE_MAX];
+    char line[PROPERTY_VALUE_MAX];
     FILE *proc;
-    char line[sizeof(DRIVER_MODULE_TAG)+10];
+    int cnt = property_get(DRIVER_NAME_PROP, modname, WIFI_DRIVER_MODULE_NAME);
+
+    if (cnt > 0)
+        modname[cnt++] = ' ';
+    else
+        goto unloaded;
 
-    if (!property_get(DRIVER_PROP_NAME, driver_status, NULL)
-            || strcmp(driver_status, "ok") != 0) {
-        return 0;  /* driver not loaded */
-    }
     /*
      * If the property says the driver is loaded, check to
      * make sure that the property setting isn't just left
@@ -152,16 +153,18 @@ static int check_driver_loaded() {
      */
     if ((proc = fopen(MODULE_FILE, "r")) == NULL) {
         LOGW("Could not open %s: %s", MODULE_FILE, strerror(errno));
-        property_set(DRIVER_PROP_NAME, "unloaded");
-        return 0;
+        goto unloaded;
     }
+
     while ((fgets(line, sizeof(line), proc)) != NULL) {
-        if (strncmp(line, DRIVER_MODULE_TAG, strlen(DRIVER_MODULE_TAG)) == 0) {
+        if (strncmp(line, modname, cnt) == 0) {
             fclose(proc);
             return 1;
         }
     }
     fclose(proc);
+
+unloaded:
     property_set(DRIVER_PROP_NAME, "unloaded");
     return 0;
 }
@@ -175,7 +178,10 @@ int wifi_load_driver()
         return 0;
     }
 
-    if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0)
+    if (!property_get(DRIVER_PATH_PROP, driver_status, WIFI_DRIVER_MODULE_PATH))
+        return -1;
+
+    if (insmod(driver_status, DRIVER_MODULE_ARG) < 0)
         return -1;
 
     if (strcmp(FIRMWARE_LOADER,"") == 0) {
@@ -205,8 +211,12 @@ int wifi_load_driver()
 int wifi_unload_driver()
 {
     int count = 20; /* wait at most 10 seconds for completion */
+    char modname[PROPERTY_VALUE_MAX];
+
+    if (!property_get(DRIVER_NAME_PROP, modname, WIFI_DRIVER_MODULE_NAME))
+        return -1;
 
-    if (rmmod(DRIVER_MODULE_NAME) == 0) {
+    if (rmmod(modname) == 0) {
        while (count-- > 0) {
            if (!check_driver_loaded())
                break;
@@ -215,9 +225,8 @@ int wifi_unload_driver()
        if (count) {
            return 0;
        }
-       return -1;
-    } else
-        return -1;
+    }
+    return -1;
 }
 
 int ensure_config_file_exists()