예제 #1
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 ;
}
/*
 * 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");
    }

}
예제 #3
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    
}
/*
 * 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;
}
예제 #5
0
int wifi_start_supplicant_common(const char *config_file, bool bP2p)
{
    char daemon_cmd[PROPERTY_VALUE_MAX];
    char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
    int count = 200; /* wait at most 20 seconds for completion */
#ifdef HAVE_LIBC_SYSTEM_PROPERTIES
    const prop_info *pi;
    unsigned serial = 0;
#endif

    wifi_stop_supplicant();
    wifi_close_supplicant_connection();

    /* Check whether already running */
	if (bP2p)
	{
		if (property_get(P2P_SUPP_PROP_NAME, supp_status, NULL)
				&& strcmp(supp_status, "running") == 0) {
			LOGD ("P2P_SUPP_PROP_NAME is runing");
			return 0;
		}
	}
	else
	{
    if (property_get(SUPP_PROP_NAME, supp_status, NULL)
            && strcmp(supp_status, "running") == 0) {
        return 0;
    }
	}

    /* Before starting the daemon, make sure its config file exists */
    if (ensure_config_file_exists(config_file) < 0) {
        LOGE("Wi-Fi will not be enabled");
        return -1;
    }

    if (ensure_entropy_file_exists() < 0) {
        LOGE("Wi-Fi entropy file was not created");
    }

    /* Clear out any stale socket files that might be left over. */
    wifi_wpa_ctrl_cleanup();

#ifdef HAVE_LIBC_SYSTEM_PROPERTIES
    /*
     * Get a reference to the status property, so we can distinguish
     * the case where it goes stopped => running => stopped (i.e.,
     * it start up, but fails right away) from the case in which
     * it starts in the stopped state and never manages to start
     * running at all.
     */
    pi = __system_property_find(SUPP_PROP_NAME);
    if (pi != NULL) {
        serial = pi->serial;
    }
#endif
	if (bP2p)
	{
		LOGD ("start p2p0 script");
		property_set("ctl.start", "p2p0_at6k");
        usleep(100000);

		memset (iface, 0, sizeof(iface));  // todo!!!!
		strncpy (iface, "p2p0", strlen("p2p0"));
		snprintf(daemon_cmd, PROPERTY_VALUE_MAX, "%s", P2P_SUPPLICANT_NAME);
	}
	else
	{
    property_get("wifi.interface", iface, WIFI_TEST_INTERFACE);
		LOGD ("interface name[%s]\n", iface);
    snprintf(daemon_cmd, PROPERTY_VALUE_MAX, "%s", SUPPLICANT_NAME);
	}

	LOGD (">>>> start wpa_supplicant daemon_cmd[%s]\n", daemon_cmd);
    property_set("ctl.start", daemon_cmd);
    sched_yield();

    while (count-- > 0) {
#ifdef HAVE_LIBC_SYSTEM_PROPERTIES
        if (pi == NULL) {
            pi = __system_property_find(SUPP_PROP_NAME);
        }
        if (pi != NULL) {
            __system_property_read(pi, NULL, supp_status);
            if (strcmp(supp_status, "running") == 0) {
                return 0;
            } else if (pi->serial != serial &&
                    strcmp(supp_status, "stopped") == 0) {
                return -1;
            }
        }
#else
	if (bP2p)
	{
		if (property_get(P2P_SUPP_PROP_NAME, supp_status, NULL)) {
			if (strcmp(supp_status, "running") == 0)
				return 0;
		}
	}
	else
	{
        if (property_get(SUPP_PROP_NAME, supp_status, NULL)) {
            if (strcmp(supp_status, "running") == 0)
                return 0;
        }
	}
#endif
        usleep(100000);
    }
    return -1;
}