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
}
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
	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
}
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
}
Example #5
0
int wifi_load_driver()
{
    char driver_status[PROPERTY_VALUE_MAX];
    int count = 100; /* wait at most 20 seconds for completion */

    if (check_driver_loaded()) {
        return 0;
    }

    if (!strcmp(PRELOADER,"") == 0) {
        LOGW("Starting WIFI pre-loader");
        property_set("ctl.start", PRELOADER);
    }

#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){
#ifdef WIFI_EXT_MODULE_NAME
        rmmod(EXT_MODULE_NAME);
#endif
        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)
                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;
}
Example #6
0
void disable_wifi()
{
    wifi_state = DISABLING;

    ALOGD("stop dhcp for wlan0...");
    dhcp_stop("wlan0");
    ifc_disable("wlan0");
    ifc_clear_addresses("wlan0");

    ALOGD("stop supplicant...");
    if(wifi_stop_supplicant(1) != 0)
    {
        ALOGE("stop supplicant failed!");
    }

    ALOGD("unload wlan driver...");
    wifi_unload_driver();

    wifi_state = DISABLED;
    WIFI_MSG_INFO_CALLBACK("Wifi diabled.");
    //disable wifi also a event automanager should check.
    sem_post(&sem);

    return ;
}
int wifi_send_command(struct wpa_ctrl *ctrl, const char *cmd, char *reply, size_t *reply_len)
{
    int ret;

    if (ctrl_conn == NULL) {
        LOGV("Not connected to wpa_supplicant - \"%s\" command dropped.\n", cmd);
        return -1;
    }

    if (strcmp(cmd, "DRIVER START") == 0) {
        LOGD("wifi.c : load driver after resume\n");
        wifi_load_driver();
    }

    ret = wpa_ctrl_request(ctrl, cmd, strlen(cmd), reply, reply_len, NULL);
    LOGV("wifi.c : cmd=%s, reply=%s\n", cmd, reply);

    if (strcmp(cmd, "DRIVER STOP") == 0) {
        LOGD("wifi.c : unload driver before suspend\n");
        wifi_unload_driver();
    }

    if (ret == -2) {
        LOGD("'%s' command timed out.\n", cmd);
        /* unblocks the monitor receive socket for termination */
        write(exit_sockets[0], "T", 1);
        return -2;
    } else if (ret < 0 || strncmp(reply, "FAIL", 4) == 0) {
        return -1;
    }
    if (strncmp(cmd, "PING", 4) == 0) {
        reply[*reply_len] = '\0';
    }
    return 0;
}
int wifi_unload_hotspot_driver()
{
#ifndef WIFI_AP_DRIVER_MODULE_PATH
    return wifi_unload_driver();
#else
    if (!is_wifi_hotspot_driver_loaded()) {
        return 0;
    }
    usleep(200000); /* allow to finish interface down */
    if (rmmod(AP_DRIVER_MODULE_NAME) == 0) {
        int count = 20; /* wait at most 10 seconds for completion */
        while (count-- > 0) {
            if (!is_wifi_hotspot_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;
#endif
}
int wifi_change_fw_path(const char *fwpath)
{
    int len;
    int fd;
    int ret = 0;
    static char previous_fwpath[4];

//    if (!fwpath)
//        return ret;

    LOGE("%s: %s\n", __FUNCTION__, fwpath);
    if(strncmp("P2P", fwpath, 3) == 0) {
        ret = wifi_load_driver();
    } else if(strncmp("P2P", previous_fwpath, 3) == 0) {
        ret = wifi_unload_driver();
    }

    strncpy(previous_fwpath, fwpath, 3);

#if 0
    fd = open(WIFI_DRIVER_FW_PATH_PARAM, O_WRONLY);
    if (fd < 0) {
        LOGE("Failed to open wlan fw path param (%s)", strerror(errno));
        return -1;
    }
    len = strlen(fwpath) + 1;
    if (write(fd, fwpath, len) != len) {
        LOGE("Failed to write wlan fw path param (%s)", strerror(errno));
        ret = -1;
    }
    close(fd);
#endif
    return ret;
}
Example #10
0
int wifi_load_driver()
{

    LOGE("zhiyuan add ********* wifi_load_driver() *******return 0 **********");
    
     return 0;

    char driver_status[PROPERTY_VALUE_MAX];
    int count = 100; /* wait at most 20 seconds for completion */

    if (check_driver_loaded()) {

        LOGE("zhiyuan add debug********* wifi_load_driver() ->check_driver_loaded() )fail*****************");
        return 0;
    }

   LOGE("zhiyuan add debug********* wifi_load_driver() ->check_driver_loaded() )OK*****************");

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

  //  LOGE("zhiyuan add debug*******cancel ** wifi_load_driver() ->insmod () OK*****************");

    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)
                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;
}
Example #11
0
char* UnloadWifiFn(const char* name, State* state, int argc, Expr* argv[]) {
    if (argc != 0)
        return ErrorAbort(state, "%s() expects 0 arg, got %d", name, argc);

    if (wifi_unload_driver() != 0) {
        return ErrorAbort(state, "Unable to unload wifi-driver: %s", strerror(errno));
    }
    return strdup("t");
}
int wifi_check_is_dongle_out()
{
    struct device_node *  ptmp = NULL;
    if(driver_is_load && pcurr_device == NULL)
    {
        LOGD("wifi_set_dongle_inside dongle already in");
        return wifi_unload_driver();
    }
    
    return -1;
}
/*
 * 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");
    }

}
Example #14
0
char* UnloadWifiFn(const char* name, State* state, int argc, Expr* argv[]) {
    if (argc != 0)
        return ErrorAbort(state, "%s() expects 0 arg, got %d", name, argc);

 void *h = dlopen("/system/lib/libhardware_legacy.so",RTLD_LAZY);
 int (*wifi_unload_driver)() = dlsym(h,"wifi_unload_driver");

  if (wifi_unload_driver) {
    if (wifi_unload_driver() != 0) {
      return ErrorAbort(state, "Unable to unload wifi-driver: %s", strerror(errno));
    }
    return strdup("t");
  }
  return ErrorAbort(state, "libhardware_legacy is not available.");
}
int wifi_load_driver()
{
    char driver_status[PROPERTY_VALUE_MAX];
    int count = 100; /* wait at most 20 seconds for completion */
    char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
    
    unsigned char tmp_buf[200] = {0};
    char *p_strstr  = NULL;
    int  ret        = 0;
    FILE *fp        = NULL;
    int sleep_count = 0;
    
    if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0) {
        LOGE("insmod rtl8192cu ko failed!");
        return -1;
    }    

    do{
       fp=fopen("/proc/net/wireless", "r");
       if (!fp) {
               LOGE("failed to fopen file /proc/net/wireless\n");
               return -1;
       }
       ret = fread(tmp_buf, 200, 1, fp);
       if (ret<0) {
               LOGE("faied to read proc/net/wireless");
       }
       fclose(fp);

       p_strstr = strstr(tmp_buf, "wlan0");
       if (p_strstr != NULL) {
               break;
       }
       usleep(200000);

   } while (sleep_count++ <=10);

   if(sleep_count > 10) {
       LOGE("timeout to poll wlan0");
       wifi_unload_driver(); 
       return -1;
   }

   return 0;
   
}
Example #16
0
/*
 * Arguments:
 *	argv[2] - interface name
 *	argv[3] - AP or STA
 */
int SoftapController::fwReloadSoftap(int argc, char *argv[])
{
    int ret, i = 0;
    char *iface;
    char *fwpath;

    if (mSock < 0) {
        LOGE("Softap fwrealod - failed to open socket");
        return -1;
    }
    if (argc < 4) {
        LOGE("Softap fwreload - missing arguments");
        return -1;
    }

    iface = argv[2];

    if (strcmp(argv[3], "AP") == 0) {
        fwpath = (char *)wifi_get_fw_path(WIFI_GET_FW_PATH_AP);
    } else if (strcmp(argv[3], "P2P") == 0) {
        fwpath = (char *)wifi_get_fw_path(WIFI_GET_FW_PATH_P2P);
    } else {
        fwpath = (char *)wifi_get_fw_path(WIFI_GET_FW_PATH_STA);
    }
    if (!fwpath)
        return -1;
#ifdef HAVE_HOSTAPD
    if(strcmp(argv[3],"AP") == 0)
        wifi_unload_driver();
    ret = wifi_change_fw_path((const char *)fwpath);
    if(strcmp(argv[3],"AP") == 0)
        wifi_load_driver();
#else
    sprintf(mBuf, "FW_PATH=%s", fwpath);
    ret = setCommand(iface, "WL_FW_RELOAD");
#endif
    if (ret) {
        LOGE("Softap fwReload - failed: %d", ret);
    }
    else {
        LOGD("Softap fwReload - Ok");
    }
    return ret;
}
Example #17
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
}
Example #18
0
int wifi_load_driver()
{
#ifdef RTL_USB_WIFI_USED

    char driver_status[PROPERTY_VALUE_MAX];
    int count = 100; /* wait at most 20 seconds for completion */
    char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
    
    unsigned char tmp_buf[200] = {0};
    char *p_strstr  = NULL;
    int  ret        = 0;
    FILE *fp        = NULL;
    int sleep_count = 0;
    
    /* Check whether is stopping */
    if (property_get(SUPP_PROP_NAME, supp_status, NULL)
            && strcmp(supp_status, "stopping") == 0) {
        LOGD("[wifiHW] wpa status is stopping!");    	
        LOGD("[wifiHW] try to stop supplicant again...");    	
        wifi_stop_supplicant();
        property_get(SUPP_PROP_NAME, supp_status, NULL);
        LOGD("[wifiHW] supp_status = %s", supp_status);    	
    }    
    
    LOGD("start to isnmod rtl8192cu.ko\n");
    
    if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0) {
        LOGE("insmod rtl8192cu ko failed!");
        #if defined NANO_SDIO_WIFI_USED 
        rmmod(DRIVER_MODULE_NAME);          
        #endif
        return -1;
    }    

    do{
       fp=fopen("/proc/net/wireless", "r");
       if (!fp) {
               LOGE("failed to fopen file /proc/net/wireless\n");
               return -1;
       }
       ret = fread(tmp_buf, 200, 1, fp);
       if (ret==0){
               LOGE("in hardware wifi_load_driver, faied to read proc/net/wireless");
       }
       fclose(fp);

       LOGE("in hardware wifi_load_driver, it is running to insmod wifi driver");
       p_strstr = strstr(tmp_buf, "wlan0");
       if (p_strstr != NULL) {
               break;
       }
       usleep(200000);

   } while (sleep_count++ <=10);

   if(sleep_count > 10) {
       LOGE("in hardware wifi_load_driver, timeout to poll wlan0");
       rmmod(DRIVER_MODULE_NAME); 
       return -1;
   }

   return 0;
    
#else 
	
    char driver_status[PROPERTY_VALUE_MAX];
    int count = 100; /* wait at most 20 seconds for completion */
    char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
    
    if (property_get(SUPP_PROP_NAME, supp_status, NULL)
            && strcmp(supp_status, "stopping") == 0) {
        LOGD("[wifiHW] wpa status is stopping!");    	
        LOGD("[wifiHW] try to stop supplicant again.......");    	
        wifi_stop_supplicant();
        property_get(SUPP_PROP_NAME, supp_status, NULL);
        LOGD("[wifiHW] supp_status = %s", supp_status);    	
    }   
    
    if (check_driver_loaded()) {
        return 0;
    }    
#ifdef NANO_SDIO_WIFI_USED    
    LOGD("begin insmod [nano] wifi firmware!");
    // load firmware, add by weiziheng 2011-06-21
    if(insmod(FIRMWARE_MODULE_PATH,FIRMWARE_MODULE_ARG) < 0) {
        LOGE("insmod [nano] wifi firmware failed!");
        rmmod(DRIVER_MODULE_NAME);
        rmmod(FIRMWARE_MODULE_NAME);
        return -1;
    }
#endif    
    if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0) {
        LOGE("insmod wifi ko failed!");
        #if defined NANO_SDIO_WIFI_USED 
        rmmod(FIRMWARE_MODULE_NAME);          
        #endif
        return -1;
    }
    
    if (strcmp(FIRMWARE_LOADER,"") == 0) {
#ifdef NANO_SDIO_WIFI_USED	    	
		unsigned char tmp_buf[200] = {0};  	
		FILE *profs_entry = NULL;
		int try_time = 0;	
		do {		
			profs_entry = fopen("/proc/net/wireless", "r");
			if(profs_entry == NULL){
				LOGE("[wifiHW] open /proc/net/wireless failed!");
				property_set(DRIVER_PROP_NAME, "failed");
				break;
		    }
		    
	        if( 0 == fread(tmp_buf, 200, 1, profs_entry) ){
	            LOGD("[wifiHW] faied to read proc/net/wireless");
	        }
			
			if(strstr(tmp_buf, "wlan0")) {
				LOGD("[wifiHW] insmod okay,try_time(%d)", try_time);
			    fclose(profs_entry);
			    profs_entry = NULL;
			    property_set(DRIVER_PROP_NAME, "ok");
			    break;			    
			}else {
				LOGD("[wifiHW] nano initial,try_time(%d)",try_time);
				property_set(DRIVER_PROP_NAME, "failed");				    		
			}			
	        fclose(profs_entry);
	        profs_entry = NULL;				
			usleep(200000);
		}while(try_time++ <= 20);// 4 seconds		
#else
        usleep(WIFI_DRIVER_LOADER_DELAY);
        property_set(DRIVER_PROP_NAME, "ok");
#endif		
    }
    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;
#endif    
}
Example #19
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
}
Example #20
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
}
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;
}
/*
 * Main
 *
 * Performs the following high-level sequence of operations:
 *
 *   1. Command-line parsing
 *
 *   2. Initialization
 *
 *   3. Execute passes that repeatedly perform the WiFi load, scan,
 *      associate, unload sequence.
 *
 *   4. Restore state of WiFi driver to state it was at the
 *      start of the test.
 *
 *   5. Restart framework
 */
int
main(int argc, char *argv[])
{
    FILE *fp;
    int rv, opt;
    int cpu;
    char *chptr;
    unsigned int pass;
    char cmd[MAXCMD];
    float duration = DEFAULT_DURATION;
    unsigned int startPass = DEFAULT_START_PASS, endPass = DEFAULT_END_PASS;
    struct timeval startTime, currentTime, delta;

    testSetLogCatTag(LOG_TAG);

    // Parse command line arguments
    while ((opt = getopt(argc, argv, "d:D:s:e:p:t:?")) != -1) {
        switch (opt) {
        case 'd': // Minimum Delay
            delayMin = strtod(optarg, &chptr);
            if ((*chptr != '\0') || (delayMin < 0.0)) {
                testPrintE("Invalid command-line specified minimum delay "
                    "of: %s", optarg);
                exit(1);
            }
            break;

        case 'D': // Maximum Delay
            delayMax = strtod(optarg, &chptr);
            if ((*chptr != '\0') || (delayMax < 0.0)) {
                testPrintE("Invalid command-line specified maximum delay "
                    "of: %s", optarg);
                exit(2);
            }
            break;

        case 't': // Duration
            duration = strtod(optarg, &chptr);
            if ((*chptr != '\0') || (duration < 0.0)) {
                testPrintE("Invalid command-line specified duration of: %s",
                    optarg);
                exit(3);
            }
            break;

        case 's': // Starting Pass
            if (sFlag || pFlag) {
                testPrintE("Invalid combination of command-line options,");
                if (sFlag) {
                    testPrintE("  -s flag specified multiple times.");
                } else {
                    testPrintE("  -s and -p flags are mutually exclusive.");
                }
                exit(10);
            }
            sFlag = true;
            startPass = strtoul(optarg, &chptr, 10);
            if (*chptr != '\0') {
                testPrintE("Invalid command-line specified starting pass "
                    "of: %s", optarg);
                exit(4);
            }
            break;

        case 'e': // Ending Pass
            if (eFlag || pFlag) {
                testPrintE("Invalid combination of command-line options,");
                if (sFlag) {
                    testPrintE("  -e flag specified multiple times.");
                } else {
                    testPrintE("  -e and -p flags are mutually exclusive.");
                }
                exit(11);
            }
            eFlag = true;
            endPass = strtoul(optarg, &chptr, 10);
            if (*chptr != '\0') {
                testPrintE("Invalid command-line specified ending pass "
                    "of: %s", optarg);
                exit(5);
            }
            break;

        case 'p': // Single Specific Pass
            if (pFlag || sFlag || eFlag) {
                testPrintE("Invalid combination of command-line options,");
                if (pFlag) {
                    testPrintE("  -p flag specified multiple times.");
                } else {
                    testPrintE("  -p and -%c flags are mutually exclusive.",
                        (sFlag) ? 's' : 'e');
                }
                exit(12);
            }
            pFlag = true;
            endPass = startPass = strtoul(optarg, &chptr, 10);
            if (*chptr != '\0') {
                testPrintE("Invalid command-line specified pass "
                    "of: %s", optarg);
                exit(13);
            }
            break;

        case '?':
        default:
            testPrintE("  %s [options]", basename(argv[0]));
            testPrintE("    options:");
            testPrintE("      -s Starting pass");
            testPrintE("      -e Ending pass");
            testPrintE("      -p Specific single pass");
            testPrintE("      -t Duration");
            testPrintE("      -d Delay min");
            testPrintE("      -D Delay max");
            exit(((optopt == 0) || (optopt == '?')) ? 0 : 6);
        }
    }
    if (delayMax < delayMin) {
        testPrintE("Unexpected maximum delay less than minimum delay");
        testPrintE("  delayMin: %f delayMax: %f", delayMin, delayMax);
        exit(7);
    }
    if (endPass < startPass) {
        testPrintE("Unexpected ending pass before starting pass");
        testPrintE("  startPass: %u endPass: %u", startPass, endPass);
        exit(8);
    }
    if (argc != optind) {
        testPrintE("Unexpected command-line postional argument");
        testPrintE("  %s [-s start_pass] [-e end_pass] [-d duration]",
            basename(argv[0]));
        exit(9);
    }
    testPrintI("duration: %g", duration);
    testPrintI("startPass: %u", startPass);
    testPrintI("endPass: %u", endPass);
    testPrintI("delayMin: %f", delayMin);
    testPrintI("delayMax: %f", delayMax);

    init();

    // For each pass
    gettimeofday(&startTime, NULL);
    for (pass = startPass; pass <= endPass; pass++) {
        // Stop if duration of work has already been performed
        gettimeofday(&currentTime, NULL);
        delta = tvDelta(&startTime, &currentTime);
        if (tv2double(&delta) > duration) { break; }

        testPrintI("==== Starting pass: %u", pass);

        // Use a pass dependent sequence of random numbers
        srand48(pass);

        // Load WiFi Driver
        randBind(&availCPU, &cpu);
        if ((rv = wifi_load_driver()) != 0) {
            testPrintE("CPU: %i wifi_load_driver() failed, rv: %i\n",
                cpu, rv);
            exit(20);
        }
        testPrintI("CPU: %i wifi_load_driver succeeded", cpu);

        // Start Supplicant
        randBind(&availCPU, &cpu);
        if ((rv = wifi_start_supplicant(false)) != 0) {
            testPrintE("CPU: %i wifi_start_supplicant() failed, rv: %i\n",
                cpu, rv);
            exit(21);
        }
        testPrintI("CPU: %i wifi_start_supplicant succeeded", cpu);

        // Sleep a random amount of time
        randDelay();

        /*
         * Obtain WiFi Status
         * Half the time skip this step, which helps increase the
         * level of randomization.
         */
        if (testRandBool()) {
            rv = snprintf(cmd, sizeof(cmd), "%s", CMD_STATUS);
            if (rv >= (signed) sizeof(cmd) - 1) {
                testPrintE("Command too long for: %s\n", CMD_STATUS);
                exit(22);
            }
            testExecCmd(cmd);
        }

        // Stop Supplicant
        randBind(&availCPU, &cpu);
        if ((rv = wifi_stop_supplicant(false)) != 0) {
            testPrintE("CPU: %i wifi_stop_supplicant() failed, rv: %i\n",
                cpu, rv);
            exit(23);
        }
        testPrintI("CPU: %i wifi_stop_supplicant succeeded", cpu);

        // Unload WiFi Module
        randBind(&availCPU, &cpu);
        if ((rv = wifi_unload_driver()) != 0) {
            testPrintE("CPU: %i wifi_unload_driver() failed, rv: %i\n",
                cpu, rv);
            exit(24);
        }
        testPrintI("CPU: %i wifi_unload_driver succeeded", cpu);

        testPrintI("==== Completed pass: %u", pass);
    }

    // If needed restore WiFi driver to state it was in at the
    // start of the test.  It is assumed that it the driver
    // was loaded, then the wpa_supplicant was also running.
    if (driverLoadedAtStart) {
        // Load driver
        if ((rv = wifi_load_driver()) != 0) {
            testPrintE("main load driver failed, rv: %i", rv);
            exit(25);
        }

        // Start supplicant
        if ((rv = wifi_start_supplicant(false)) != 0) {
            testPrintE("main start supplicant failed, rv: %i", rv);
            exit(26);
        }

        // Obtain WiFi Status
        rv = snprintf(cmd, sizeof(cmd), "%s", CMD_STATUS);
        if (rv >= (signed) sizeof(cmd) - 1) {
            testPrintE("Command too long for: %s\n", CMD_STATUS);
            exit(22);
        }
        testExecCmd(cmd);
    }

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

    testPrintI("Successfully completed %u passes", pass - startPass);

    return 0;
}