Ejemplo n.º 1
0
static int _wifi_unload_driver()
{
    char active_wlan_chip[PROPERTY_VALUE_MAX];
    int count = 20; /* wait at most 10 seconds for completion */
    char driver_status[PROPERTY_VALUE_MAX];
    int s, ret;

    property_get("wlan.driver.ath", active_wlan_chip, WIFI_WCN);

    if (rmmod(DRIVER_MODULE_NAME) == 0) {
        while (count-- > 0) {
            if (!is_wifi_driver_loaded())
                break;
            usleep(500000);
        }
        if (count) {
           if ('\0' != *DRIVER_SDIO_IF_MODULE_NAME && (0 == strcmp(active_wlan_chip, WIFI_WCN))) {
                if (!(rmmod(DRIVER_SDIO_IF_MODULE_NAME) == 0)) {
                    return -1;
                }
            }
           if ('\0' != *DRIVER_CFG80211_MODULE_NAME) {
                if (!(rmmod(DRIVER_CFG80211_MODULE_NAME) == 0)) {
                    return -1;
                }
            }
            return 0;
        }
        return -1;
    } else
        return -1;
}
int wifi_unload_driver()
{
    usleep(200000); /* allow to finish interface down */
#ifdef WIFI_DRIVER_MODULE_PATH
    if (rmmod(DRIVER_MODULE_NAME) == 0) {
        int count = 20; /* wait at most 10 seconds for completion */
        while (count-- > 0) {
            if (!is_wifi_driver_loaded())
                break;
            usleep(500000);
        }
        usleep(500000); /* allow card removal */
        if (count) {
#ifdef WIFI_EXT_MODULE_NAME
            if (rmmod(EXT_MODULE_NAME) == 0)
#endif
            return 0;
        }
        return -1;
    } else
        return -1;
#else
    property_set(DRIVER_PROP_NAME, "unloaded");
    return 0;
#endif
}
int wifi_unload_driver()
{
    usleep(200000); /* allow to finish interface down */
#ifdef WIFI_DRIVER_MODULE_PATH
    char modname[PROPERTY_VALUE_MAX];
    if (!property_get(DRIVER_NAME_PROP, modname, NULL))
        return -1;
    if (property_get("wlan.no-unload-driver", modname, NULL)
            && strcmp(modname, "1") == 0)
        return 0;

    if (rmmod(modname) == 0) {
        int count = 20; /* wait at most 10 seconds for completion */
        while (count-- > 0) {
            if (!is_wifi_driver_loaded())
                break;
            usleep(500000);
        }
        usleep(500000); /* allow card removal */
        if (count) {
            return 0;
        }
    }
    return -1;
#else
    property_set(DRIVER_PROP_NAME, "unloaded");
    return 0;
#endif
}
int is_wifi_hotspot_driver_loaded() {
#ifndef WIFI_AP_DRIVER_MODULE_PATH
    return is_wifi_driver_loaded();
#else
    char driver_status[PROPERTY_VALUE_MAX];
    FILE *proc;
    char line[sizeof(AP_DRIVER_MODULE_TAG)+10];

    if (!property_get(AP_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
     * over from a previous manual shutdown or a runtime
     * crash.
     */
    if ((proc = fopen(MODULE_FILE, "r")) == NULL) {
        LOGW("Could not open %s: %s", MODULE_FILE, strerror(errno));
        property_set(AP_DRIVER_PROP_NAME, "unloaded");
        return 0;
    }
    while ((fgets(line, sizeof(line), proc)) != NULL) {
        if (strncmp(line, AP_DRIVER_MODULE_TAG, strlen(AP_DRIVER_MODULE_TAG)) == 0) {
            fclose(proc);
            return 1;
        }
    }
    fclose(proc);
    property_set(AP_DRIVER_PROP_NAME, "unloaded");
    return 0;
#endif
}
Ejemplo n.º 5
0
int wifi_load_p2p_driver()
{
#ifdef WIFI_DRIVER_MODULE_PATH
    char driver_status[PROPERTY_VALUE_MAX];
    int count = 100; /* wait at most 20 seconds for completion */

    if (is_wifi_driver_loaded()) {
        return 0;
    }

#if defined(IMX5X)
    if (insmod(DRIVER_COMPAT_MODULE_PATH, DRIVER_COMPAT_MODULE_ARG) < 0) {
        return -1;
	}
#endif

    if (insmod(DRIVER_SDIO_IF_MODULE_PATH, DRIVER_SDIO_IF_MODULE_ARG) < 0) {
        return -1;
    }

    if (insmod(DRIVER_MODULE_PATH, DRIVER_P2P_MODULE_ARG) < 0) {
        return -1;
    }

    if (strcmp(FIRMWARE_LOADER,"") == 0) {
	  //usleep(1.5*WIFI_DRIVER_LOADER_DELAY);
        property_set(DRIVER_PROP_NAME, "ok");
    }
    else {
        property_set("ctl.start", FIRMWARE_LOADER);
    }

    sched_yield();

    while (count-- > 0) {
        if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
            if (strcmp(driver_status, "ok") == 0) {
                return 0;
            }
            else if (strcmp(DRIVER_PROP_NAME, "failed") == 0) {
                wifi_unload_driver();
                return -1;
            }
        }
        usleep(200000);
    }

    property_set(DRIVER_PROP_NAME, "timeout");
    wifi_unload_driver();

    return -1;
#else
    property_set(DRIVER_PROP_NAME, "ok");
    return 0;
#endif
}
/*
 * Initialize
 *
 * Perform testcase initialization, which includes:
 *
 *   1. Determine which CPUs are available for use
 *
 *   2. Determine total number of available CPUs
 *
 *   3. Stop framework
 *
 *   4. Determine whether WiFi driver is loaded and if so
 *      stop wpa_supplicant and unload WiFi driver.
 */
void
init(void)
{
    int rv;
    unsigned int n1;
    char cmd[MAXCMD];

    // Use whichever CPUs are available at start of test
    rv = sched_getaffinity(0, sizeof(availCPU), &availCPU);
    if (rv != 0) {
        testPrintE("init sched_getaffinity failed, rv: %i errno: %i",
            rv, errno);
        exit(40);
    }

    // How many CPUs are available
    numAvailCPU = 0;
    for (n1 = 0; n1 < CPU_SETSIZE; n1++) {
        if (CPU_ISSET(n1, &availCPU)) { numAvailCPU++; }
    }
    testPrintI("numAvailCPU: %u", numAvailCPU);

    // Stop framework
    rv = snprintf(cmd, sizeof(cmd), "%s", CMD_STOP_FRAMEWORK);
    if (rv >= (signed) sizeof(cmd) - 1) {
        testPrintE("Command too long for: %s\n", CMD_STOP_FRAMEWORK);
        exit(41);
    }
    testExecCmd(cmd);

    // Is WiFi driver loaded?
    // If so stop the wpa_supplicant and unload the driver.
    driverLoadedAtStart = is_wifi_driver_loaded();
    testPrintI("driverLoadedAtStart: %u", driverLoadedAtStart);
    if (driverLoadedAtStart) {
        // Stop wpa_supplicant
        // Might already be stopped, in which case request should
        // return immediately with success.
        if ((rv = wifi_stop_supplicant(false)) != 0) {
            testPrintE("init stop supplicant failed, rv: %i", rv);
            exit(42);
        }
        testPrintI("Stopped wpa_supplicant");

        if ((rv = wifi_unload_driver()) != 0) {
            testPrintE("init unload driver failed, rv: %i", rv);
            exit(43);
        }
        testPrintI("WiFi driver unloaded");
    }

}
int wifi_load_driver()
{
	do_wifi_workaround();
#ifdef WIFI_DRIVER_MODULE_PATH
    char driver_status[PROPERTY_VALUE_MAX];
    int count = 100; /* wait at most 20 seconds for completion */

    if (is_wifi_driver_loaded()) {
        return 0;
    }

    if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0)
        return -1;

    if (strcmp(FIRMWARE_LOADER,"") == 0) {
        if(strcmp(WIFI_DRIVER_MODULE_NAME,"8192cu") == 0){
            usleep(1600000);
        }
        else{
            usleep(WIFI_DRIVER_LOADER_DELAY);
        }
        property_set(DRIVER_PROP_NAME, "ok");
    }
    else {
        if(strcmp(WIFI_DRIVER_MODULE_NAME,"8192cu") == 0){
            usleep(1600000);
        }
        else{
            usleep(WIFI_DRIVER_LOADER_DELAY);
        }  	
        property_set("ctl.start", FIRMWARE_LOADER);
    }
    sched_yield();
    while (count-- > 0) {
        if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
            if (strcmp(driver_status, "ok") == 0)
                return 0;
            else if (strcmp(DRIVER_PROP_NAME, "failed") == 0) {
                wifi_unload_driver();
                return -1;
            }
        }
        usleep(200000);
    }
    property_set(DRIVER_PROP_NAME, "timeout");
    wifi_unload_driver();
    return -1;
#else
    property_set(DRIVER_PROP_NAME, "ok");
    return 0;
#endif
}
int wifi_load_driver()
{
#ifdef WIFI_DRIVER_MODULE_PATH
    char driver_status[PROPERTY_VALUE_MAX];
    char modname[PROPERTY_VALUE_MAX];
    char modpath[SYSFS_PATH_MAX];
    int count = 100; /* wait at most 20 seconds for completion */

    if (is_wifi_driver_loaded()) {
        return 0;
    }

    if (!property_get(DRIVER_PATH_PROP, modpath, NULL)) {
        property_get(DRIVER_NAME_PROP, modname, NULL);
        strcat(modname, ".ko");
        if (!get_driver_path(modname, MODULE_DEFAULT_DIR, modpath))
            strcpy(modpath, WIFI_DRIVER_MODULE_PATH);
    }

    ALOGI("got module path %s", modpath);
    if (insmod(modpath, DRIVER_MODULE_ARG) < 0)
        return -1;

    if (strcmp(FIRMWARE_LOADER,"") == 0) {
        /* usleep(WIFI_DRIVER_LOADER_DELAY); */
        property_set(DRIVER_PROP_NAME, "ok");
    }
    else {
        property_set("ctl.start", FIRMWARE_LOADER);
    }
    sched_yield();
    while (count-- > 0) {
        if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
            if (strcmp(driver_status, "ok") == 0) {
                get_driver_info(modname);
                return 0;
            } else if (strcmp(DRIVER_PROP_NAME, "failed") == 0) {
                wifi_unload_driver();
                return -1;
            }
        }
        usleep(200000);
    }
    property_set(DRIVER_PROP_NAME, "timeout");
    wifi_unload_driver();
    return -1;
#else
    property_set(DRIVER_PROP_NAME, "ok");
    return 0;
#endif
}
Ejemplo n.º 9
0
int wifi_load_driver()
{
#ifdef WIFI_DRIVER_MODULE
	LOGD ("wifi_load_driver\n");
    char driver_status[PROPERTY_VALUE_MAX];
    int count = 100; /* wait at most 20 seconds for completion */

    if (is_wifi_driver_loaded()) {
		LOGD ("wifi driver have load\n");
        return 0;
    }

	LOGD ("DRIVER_MODULE_PATH [%s]DRIVER_MODULE_ARG[%s]", DRIVER_MODULE_PATH, DRIVER_MODULE_ARG);
    if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0)
	{
		LOGD ("driver insmod failed");
        return -1;
	}

    if (strcmp(FIRMWARE_LOADER,"") == 0) {
        /* usleep(WIFI_DRIVER_LOADER_DELAY); */
		LOGD ("DRIVER_PROP_NAME ok\n");
        property_set(DRIVER_PROP_NAME, "ok");
    }
    else {
		
        property_set("ctl.start", FIRMWARE_LOADER);
		
    }
    sched_yield();
    while (count-- > 0) {
        if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
            if (strcmp(driver_status, "ok") == 0)
                return 0;
            else if (strcmp(DRIVER_PROP_NAME, "failed") == 0) {
                wifi_unload_driver();
                return -1;
            }
        }
        usleep(200000);
    }
	LOGD ("DRIVER_PROP_NAME timeout\n");
    property_set(DRIVER_PROP_NAME, "timeout");
    wifi_unload_driver();
    return -1;
#else
    driver_is_load = 1;
    property_set(DRIVER_PROP_NAME, "ok");
    return 0;
#endif
}
Ejemplo n.º 10
0
static int _wifi_unload_driver()
{
    int count = 20; /* wait at most 10 seconds for completion */
    char driver_status[PROPERTY_VALUE_MAX];
    int s, ret;

    if (rmmod(DRIVER_MODULE_NAME) == 0) {
        while (count-- > 0) {
            if (!is_wifi_driver_loaded())
                break;
            usleep(500000);
        }

        if (count) {
			/* unload cfg80211 kernel module */
            if (rmmod(DRIVER_SDIO_IF_MODULE_NAME) != 0) {
                return -1;
		 }

#if defined(IMX5X)
            /* unload compat kernel module */
	    if (rmmod(DRIVER_COMPAT_MODULE_NAME) != 0) {
                return -1;
		}
#endif
        }
        else {
            return -1;
        }

        return 0;
    }
    else {
        return -1;
    }
}
Ejemplo n.º 11
0
int wifi_load_driver()
{
#ifdef WIFI_DRIVER_MODULE_PATH
    char driver_status[PROPERTY_VALUE_MAX];
    char active_wlan_chip[PROPERTY_VALUE_MAX];
    int count = 100; /* wait at most 20 seconds for completion */
    int status = -1;

    if (is_wifi_driver_loaded()) {
        return 0;
    }

        /* ensure that wlan driver config file exists (if specified) */
    if (ensure_wlan_driver_config_file_exists()) {
        return -1;
    }
    property_set(DRIVER_PROP_NAME, "loading");

    /*SDIO polling is enabled by wifi-sdio-on service */
    property_set("ctl.start", "wifi-sdio-on");

    property_get("wlan.driver.ath", active_wlan_chip, WIFI_WCN);

    if ('\0' != *DRIVER_CFG80211_MODULE_PATH) {
        if (insmod(DRIVER_CFG80211_MODULE_PATH,DRIVER_CFG80211_MODULE_ARG) < 0) {
            ALOGI("insmod for %s failed \n",DRIVER_CFG80211_MODULE_PATH);
            goto end;
        }
    }
    if ('\0' != *DRIVER_SDIO_IF_MODULE_PATH && (0 == strcmp(active_wlan_chip, WIFI_WCN))) {
        if (insmod(DRIVER_SDIO_IF_MODULE_PATH, DRIVER_SDIO_IF_MODULE_ARG) < 0) {
            ALOGI("insmod for %s failed \n",DRIVER_SDIO_IF_MODULE_PATH);
            if ('\0' != *DRIVER_CFG80211_MODULE_NAME) {
                  rmmod(DRIVER_CFG80211_MODULE_NAME);
            }
                goto end;
        }
    }
    if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0) {
        ALOGI("insmod for %s failed \n",DRIVER_MODULE_PATH);
        if ('\0' != *DRIVER_CFG80211_MODULE_NAME) {
                rmmod(DRIVER_CFG80211_MODULE_NAME);
        }
            if ('\0' != *DRIVER_SDIO_IF_MODULE_NAME) {
                    rmmod(DRIVER_SDIO_IF_MODULE_NAME);
            }
                goto end;
    }
    if (strcmp(FIRMWARE_LOADER,"") == 0) {
        /* usleep(WIFI_DRIVER_LOADER_DELAY); */
        property_set(DRIVER_PROP_NAME, "ok");
    }
    else {
        property_set("ctl.start", FIRMWARE_LOADER);
    }
    sched_yield();
    while (count-- > 0) {
        if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
            if (strcmp(driver_status, "ok") == 0) {
                status = 0;
                goto end;
            }
            else if (strcmp(driver_status, "failed") == 0) {
                _wifi_unload_driver();
                goto end;
            }
        }
        usleep(200000);
    }
    property_set(DRIVER_PROP_NAME, "timeout");
    wifi_unload_driver();
end:
    return status;
#else
    property_set(DRIVER_PROP_NAME, "ok");
    return 0;
#endif
}
Ejemplo n.º 12
0
int wifi_load_driver()
{
#ifdef WIFI_DRIVER_MODULE_PATH
    char driver_status[PROPERTY_VALUE_MAX];
    int count = 100; /* wait at most 20 seconds for completion */
    char module_arg2[256];
#ifdef SAMSUNG_WIFI
    char* type = get_samsung_wifi_type();

    if (wifi_mode == 1) {
        snprintf(module_arg2, sizeof(module_arg2), "%s%s", DRIVER_MODULE_AP_ARG, type == NULL ? "" : type);
    } else {
        snprintf(module_arg2, sizeof(module_arg2), "%s%s", DRIVER_MODULE_ARG, type == NULL ? "" : type);
    }

    if (insmod(DRIVER_MODULE_PATH, module_arg2) < 0) {
#else

    property_set(DRIVER_PROP_NAME, "loading");

#ifdef WIFI_EXT_MODULE_PATH
    if (insmod(EXT_MODULE_PATH, EXT_MODULE_ARG) < 0)
        return -1;
    usleep(200000);
#endif

#ifdef HUAWEI_WIFI

#define P2P_INTERFACE			"p2p0"

char huawei_arg[PROPERTY_VALUE_MAX] = "mac_param=00:90:4c:ce:43:30";
char module_arg[256];

char mac_bits[PROPERTY_VALUE_MAX];
property_get("ro.serialno",mac_bits,NULL);
	sprintf(huawei_arg, "mac_param=%2.2s:%2.2s:%2.2s:%2.2s:%2.2s:%2.2s",
		"00", "90", "4C",
		mac_bits+6, mac_bits+8, mac_bits+10);	
		
	printf("%s\n", huawei_arg);	

sprintf(module_arg, "%s %s", DRIVER_MODULE_ARG, huawei_arg);
	if (insmod(DRIVER_MODULE_PATH, module_arg) < 0) {

#else
    if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0) {
#endif
#endif

#ifdef WIFI_EXT_MODULE_NAME
        rmmod(EXT_MODULE_NAME);
#endif
        return -1;
    }

    if (strcmp(FIRMWARE_LOADER,"") == 0) {
#ifdef WIFI_DRIVER_LOADER_DELAY
        usleep(WIFI_DRIVER_LOADER_DELAY);
#endif
        property_set(DRIVER_PROP_NAME, "ok");
    }
    else {
        property_set("ctl.start", FIRMWARE_LOADER);
    }
    sched_yield();
    while (count-- > 0) {
        if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
            if (strcmp(driver_status, "ok") == 0)
                return 0;
            else if (strcmp(DRIVER_PROP_NAME, "failed") == 0) {
                wifi_unload_driver();
                return -1;
            }
        }
        usleep(200000);
    }
    property_set(DRIVER_PROP_NAME, "timeout");
    wifi_unload_driver();
    return -1;
#else
    property_set(DRIVER_PROP_NAME, "ok");
    return 0;
#endif
}

int wifi_unload_driver()
{
    usleep(200000); /* allow to finish interface down */
#ifdef WIFI_DRIVER_MODULE_PATH
    if (rmmod(DRIVER_MODULE_NAME) == 0) {
        int count = 20; /* wait at most 10 seconds for completion */
        while (count-- > 0) {
            if (!is_wifi_driver_loaded())
                break;
            usleep(500000);
        }
        usleep(500000); /* allow card removal */
        if (count) {
#ifdef WIFI_EXT_MODULE_NAME
            if (rmmod(EXT_MODULE_NAME) == 0)
#endif
            return 0;
        }
        return -1;
    } else
        return -1;
#else
    property_set(DRIVER_PROP_NAME, "unloaded");
    return 0;
#endif
}
Ejemplo n.º 13
0
int wifi_load_driver()
{
#ifdef WIFI_DRIVER_MODULE_PATH
    char driver_status[PROPERTY_VALUE_MAX];
    int count = 100; /* wait at most 20 seconds for completion */
    char module_arg2[256];

#ifdef WIFI_DRIVER_MODULE_NAME2
     char node[50] = {'\0',};
     char buf[5] = {'\0',};
     DIR *dir = opendir("/sys/bus/usb/devices/");
     struct dirent *dent;
     if (dir != NULL) {
	 while ((dent = readdir(dir)) != NULL) {
	     memset(node, '\0', 50);
	     sprintf(node, "/sys/bus/usb/devices/%s/idVendor", dent->d_name);
	     int vid_fd = open(node, O_RDONLY);
	     memset(buf, '\0', 5);
	     if (vid_fd > 0) {
		 read(vid_fd, buf, 4);
		 ALOGE("node = %s, vid = %s", node, buf);
				if (strcmp(buf, "0bda") == 0 || 
                        strcmp(buf, "148f") == 0 || strcmp(buf, "7392") == 0) {
		     sprintf(node, "/sys/bus/usb/devices/%s/idProduct", dent->d_name);
		     int pid_fd = open(node, O_RDONLY);
		     read(pid_fd, buf, 4);
		     ALOGE("node = %s, pid = %s", node, buf);
		     if (pid_fd > 0) {
			 if (strcmp(buf, "8176") == 0 || strcmp(buf, "7811") == 0) {
			     ALOGE("rtl8192cu Wi-Fi Module 3");
			     //wifi module 3 rtl8192cu
			     strcpy(DRIVER_MODULE_NAME, WIFI_DRIVER_MODULE_NAME2);
			     strcpy(DRIVER_MODULE_TAG, WIFI_DRIVER_MODULE_NAME2 " ");
			     strcpy(DRIVER_MODULE_PATH, WIFI_DRIVER_MODULE_PATH2);
			     close(pid_fd);
			     close(vid_fd);
			     break;
			 } else if (strcmp(buf, "8172") == 0) {
			     ALOGE("rtl8191su Wi-Fi Module 2");
			     //wifi module 2 rtl8192cu
			     strcpy(DRIVER_MODULE_NAME, WIFI_DRIVER_MODULE_NAME);
			     strcpy(DRIVER_MODULE_TAG, WIFI_DRIVER_MODULE_NAME " ");
			     strcpy(DRIVER_MODULE_PATH, WIFI_DRIVER_MODULE_PATH);
			     close(pid_fd);
			     close(vid_fd);
			     break;
			 }
			 close(pid_fd);
		     }
		 }
		 close(vid_fd);
	     }
	 }
     }
     close(dir);

	ALOGE("DRIVER_MODULE_NAME = %s", DRIVER_MODULE_NAME);
	ALOGE("DRIVER_MODULE_PATH = %s", DRIVER_MODULE_PATH);
#endif

#ifdef SAMSUNG_WIFI
    char* type = get_samsung_wifi_type();

    if (wifi_mode == 1) {
        snprintf(module_arg2, sizeof(module_arg2), "%s%s", DRIVER_MODULE_AP_ARG, type == NULL ? "" : type);
    } else {
        snprintf(module_arg2, sizeof(module_arg2), "%s%s", DRIVER_MODULE_ARG, type == NULL ? "" : type);
    }

    if (insmod(DRIVER_MODULE_PATH, module_arg2) < 0) {
#else

    property_set(DRIVER_PROP_NAME, "loading");

#ifdef WIFI_EXT_MODULE_PATH
    if (insmod(EXT_MODULE_PATH, EXT_MODULE_ARG) < 0)
        return -1;
    usleep(200000);
#endif

    if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0) {
#endif

#ifdef WIFI_EXT_MODULE_NAME
        rmmod(EXT_MODULE_NAME);
#endif
        return -1;
    }

    if (strcmp(FIRMWARE_LOADER,"") == 0) {
#ifdef WIFI_DRIVER_LOADER_DELAY
        usleep(WIFI_DRIVER_LOADER_DELAY);
#endif
        property_set(DRIVER_PROP_NAME, "ok");
    }
    else {
        property_set("ctl.start", FIRMWARE_LOADER);
    }
    sched_yield();
    while (count-- > 0) {
        if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
            if (strcmp(driver_status, "ok") == 0)
                return 0;
            else if (strcmp(driver_status, "failed") == 0) {
                wifi_unload_driver();
                return -1;
            }
        }
        usleep(200000);
    }
    property_set(DRIVER_PROP_NAME, "timeout");
    wifi_unload_driver();
    return -1;
#else
    property_set(DRIVER_PROP_NAME, "ok");
    return 0;
#endif
}

int wifi_unload_driver()
{
    usleep(200000); /* allow to finish interface down */
#ifdef WIFI_DRIVER_MODULE_PATH
    if (rmmod(DRIVER_MODULE_NAME) == 0) {
        int count = 20; /* wait at most 10 seconds for completion */
        while (count-- > 0) {
            if (!is_wifi_driver_loaded())
                break;
            usleep(500000);
        }
        usleep(500000); /* allow card removal */
        if (count) {
#ifdef WIFI_EXT_MODULE_NAME
            if (rmmod(EXT_MODULE_NAME) == 0)
#endif
            return 0;
        }
        return -1;
    } else
        return -1;
#else
    property_set(DRIVER_PROP_NAME, "unloaded");
    return 0;
#endif
}
int wifi_load_driver()
{
#ifdef WIFI_DRIVER_MODULE_PATH
    char driver_status[PROPERTY_VALUE_MAX];
    int count = 100; /* wait at most 20 seconds for completion */
    char module_arg2[256];
#ifdef SAMSUNG_WIFI
    char* type = get_samsung_wifi_type();

    if (wifi_mode == 1) {
        snprintf(module_arg2, sizeof(module_arg2), "%s%s", DRIVER_MODULE_AP_ARG, type == NULL ? "" : type);
    } else {
        snprintf(module_arg2, sizeof(module_arg2), "%s%s", DRIVER_MODULE_ARG, type == NULL ? "" : type);
    }

    if (insmod(DRIVER_MODULE_PATH, module_arg2) < 0) {
#else

    property_set(DRIVER_PROP_NAME, "loading");

#ifdef WIFI_EXT_MODULE_PATH
    if (insmod(EXT_MODULE_PATH, EXT_MODULE_ARG) < 0)
        return -1;
    usleep(200000);
#endif

    if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0) {
#endif

#ifdef WIFI_EXT_MODULE_NAME
        rmmod(EXT_MODULE_NAME);
#endif
        return -1;
    }

    if (strcmp(FIRMWARE_LOADER,"") == 0) {
#ifdef WIFI_DRIVER_LOADER_DELAY
        usleep(WIFI_DRIVER_LOADER_DELAY);
#endif
        property_set(DRIVER_PROP_NAME, "ok");
    }
    else {
        property_set("ctl.start", FIRMWARE_LOADER);
    }
    sched_yield();
    while (count-- > 0) {
        if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
            if (strcmp(driver_status, "ok") == 0)
                return 0;
            else if (strcmp(DRIVER_PROP_NAME, "failed") == 0) {
                wifi_unload_driver();
                return -1;
            }
        }
        usleep(200000);
    }
    property_set(DRIVER_PROP_NAME, "timeout");
    wifi_unload_driver();
    return -1;
#else
    property_set(DRIVER_PROP_NAME, "ok");
    return 0;
#endif
}

int wifi_unload_driver()
{
    usleep(200000); /* allow to finish interface down */
#ifdef WIFI_DRIVER_MODULE_PATH
    if (rmmod(DRIVER_MODULE_NAME) == 0) {
        int count = 20; /* wait at most 10 seconds for completion */
        while (count-- > 0) {
            if (!is_wifi_driver_loaded())
                break;
            usleep(500000);
        }
        usleep(500000); /* allow card removal */
        if (count) {
#ifdef WIFI_EXT_MODULE_NAME
            if (rmmod(EXT_MODULE_NAME) == 0)
#endif
            return 0;
        }
        return -1;
    } else
        return -1;
#else
    property_set(DRIVER_PROP_NAME, "unloaded");
    return 0;
#endif
}
Ejemplo n.º 15
0
wifi_error wifi_initialize(wifi_handle *handle)
{
    int err = 0;
    bool driver_loaded = false;
    wifi_error ret = WIFI_SUCCESS;
    wifi_interface_handle iface_handle;
    srand(getpid());

    ALOGI("Initializing wifi");
    hal_info *info = (hal_info *)malloc(sizeof(hal_info));
    if (info == NULL) {
        ALOGE("Could not allocate hal_info");
        return WIFI_ERROR_UNKNOWN;
    }

    memset(info, 0, sizeof(*info));

    ALOGI("Creating socket");
    struct nl_sock *cmd_sock = wifi_create_nl_socket(WIFI_HAL_CMD_SOCK_PORT);
    if (cmd_sock == NULL) {
        ALOGE("Could not create handle");
        return WIFI_ERROR_UNKNOWN;
    }

    struct nl_sock *event_sock =
        wifi_create_nl_socket(WIFI_HAL_EVENT_SOCK_PORT);
    if (event_sock == NULL) {
        ALOGE("Could not create handle");
        nl_socket_free(cmd_sock);
        return WIFI_ERROR_UNKNOWN;
    }

    struct nl_cb *cb = nl_socket_get_cb(event_sock);
    if (cb == NULL) {
        ALOGE("Could not create handle");
        return WIFI_ERROR_UNKNOWN;
    }

    err = 1;
    nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
    nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
    nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
    nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);

    nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, internal_valid_message_handler,
            info);
    nl_cb_put(cb);

    info->cmd_sock = cmd_sock;
    info->event_sock = event_sock;
    info->clean_up = false;
    info->in_event_loop = false;

    info->event_cb = (cb_info *)malloc(sizeof(cb_info) * DEFAULT_EVENT_CB_SIZE);
    info->alloc_event_cb = DEFAULT_EVENT_CB_SIZE;
    info->num_event_cb = 0;

    info->cmd = (cmd_info *)malloc(sizeof(cmd_info) * DEFAULT_CMD_SIZE);
    info->alloc_cmd = DEFAULT_CMD_SIZE;
    info->num_cmd = 0;

    info->nl80211_family_id = genl_ctrl_resolve(cmd_sock, "nl80211");
    if (info->nl80211_family_id < 0) {
        ALOGE("Could not resolve nl80211 familty id");
        nl_socket_free(cmd_sock);
        nl_socket_free(event_sock);
        free(info);
        return WIFI_ERROR_UNKNOWN;
    }
    ALOGI("%s: family_id:%d", __func__, info->nl80211_family_id);

    *handle = (wifi_handle) info;

    wifi_add_membership(*handle, "scan");
    wifi_add_membership(*handle, "mlme");
    wifi_add_membership(*handle, "regulatory");
    wifi_add_membership(*handle, "vendor");

    if (!is_wifi_driver_loaded()) {
        ret = (wifi_error)wifi_load_driver();
        if(ret != WIFI_SUCCESS) {
            ALOGE("%s Failed to load driver : %d\n", __func__, ret);
            return WIFI_ERROR_UNKNOWN;
        }
        driver_loaded = true;
    }

    ret = wifi_init_interfaces(*handle);
    if (ret != WIFI_SUCCESS) {
        ALOGI("Failed to init interfaces");
        goto unload;
    }

    if (info->num_interfaces == 0) {
        ALOGI("No interfaces found");
        ret = WIFI_ERROR_UNINITIALIZED;
        goto unload;
    }

    iface_handle = wifi_get_iface_handle((info->interfaces[0])->handle,
            (info->interfaces[0])->name);
    if (iface_handle == NULL) {
        int i;
        for (i = 0; i < info->num_interfaces; i++)
        {
            free(info->interfaces[i]);
        }
        ALOGE("%s no iface with %s\n", __func__, info->interfaces[0]->name);
        return WIFI_ERROR_UNKNOWN;
    }
    ret = acquire_supported_features(iface_handle,
            &info->supported_feature_set);
    if (ret != WIFI_SUCCESS) {
        ALOGI("Failed to get supported feature set : %d", ret);
        //acquire_supported_features failure is acceptable condition as legacy
        //drivers might not support the required vendor command. So, do not
        //consider it as failure of wifi_initialize
        ret = WIFI_SUCCESS;
    }

    ALOGI("Initialized Wifi HAL Successfully; vendor cmd = %d Supported"
            " features : %x", NL80211_CMD_VENDOR, info->supported_feature_set);

unload:
    if (driver_loaded)
        wifi_unload_driver();
    return ret;
}