/* DUAL mode, uap start at system initilize state. */ static void dual_uap_start(void) { sys_config_t *pconfig = get_running_config(); base_config_t *pbase = &pconfig->base; extra_config_t *pextra = &pconfig->extra; sys_unconfig_t *punconfig = get_un_config(); struct wlan_network wlan_config; if (pbase->wifi_mode != DUAL_MODE) return; memset(&wlan_config, 0, sizeof(wlan_config)); /* Set profile name */ strcpy(wlan_config.name, "UAP"); strcpy(wlan_config.ssid, pextra->uap_ssid); wlan_config.channel = 0; wlan_config.mode = WLAN_MODE_UAP; switch(pextra->uap_secmode) { case SEC_MODE_WEP: case SEC_MODE_WEP_HEX: wlan_config.security.type = WLAN_SECURITY_WEP_OPEN; break; case SEC_MODE_WPA_NONE: wlan_config.security.type = WLAN_SECURITY_NONE; break; case SEC_MODE_WPA_PSK: wlan_config.security.type = WLAN_SECURITY_WPA2; break; default: wlan_config.security.type = WLAN_SECURITY_WPA2; break; } if (SEC_MODE_WEP_HEX == pextra->uap_secmode) { wlan_config.security.psk_len = str2hex(pextra->uap_key, wlan_config.security.psk, 32); } else { strcpy(wlan_config.security.psk, pextra->uap_key); wlan_config.security.psk_len = strlen(pextra->uap_key); } if (punconfig->pmk_invalid[0] == 0) { wlan_config.security.pmk_valid = 1; memcpy(wlan_config.security.pmk, punconfig->pmk[0], WLAN_PMK_LENGTH); } wlan_config.address.addr_type = ADDR_TYPE_STATIC; wlan_config.address.ip = 0x0a0a0a01; wlan_config.address.gw = 0x0a0a0a02; wlan_config.address.netmask = 0xffffff00; wlan_config.address.dns1 = 0x0a0a0a01; wlan_add_network(&wlan_config); wlan_start_network(wlan_config.name); }
static void test_wlan_start_network(int argc, char **argv) { int ret; if (argc < 2) { wmprintf("Usage: %s <profile_name>\r\n", argv[0]); wmprintf("Error: specify a network to start\r\n"); return; } ret = wlan_start_network(argv[1]); if (ret != WLAN_ERROR_NONE) wmprintf("Error: unable to start network\r\n"); }
/* WPS main processing thread * */ static void wps_main(os_thread_arg_t data) { #ifdef CONFIG_P2P struct timeval tv, now; WPS_DATA *wps_s = (WPS_DATA *) &wps_global; WFD_DATA *pwfd_data = &wps_global.wfd_data; bss_config_t bss_config; #endif int ret; #ifdef CONFIG_WPA2_ENTP struct wpa2_command *wpa2_cmd = NULL; WPS_DATA *wps_s = (WPS_DATA *) &wps_global; #else struct wps_command *wps_cmd = NULL; #endif #ifdef CONFIG_P2P memset(&bss_config, 0, sizeof(bss_config_t)); /* * Download Wfd configuration if supplied with -p command line. */ if (local_wcc->role == WFD_ROLE) { if (wfd_wlan_update_bss_mode(BSS_MODE_WIFIDIRECT_GO) != WPS_STATUS_SUCCESS) { wps_printf(MSG_ERROR, "ERROR - Fail to initialize " "BSS Mode!\n"); goto fail; } /* Set WFD uAP configuration */ wifidirectapcmd_sys_config(); if (wfd_wlan_update_bss_mode(BSS_MODE_WIFIDIRECT_CLIENT) != WPS_STATUS_SUCCESS) { wps_printf(MSG_ERROR, "ERROR - Fail to initialize " "BSS Mode!\n"); goto fail; } /* Set WFD configuration */ wifidirectcmd_config(); if (wfd_set_mode(WFD_MODE_START) != WPS_STATUS_SUCCESS) { wps_printf(MSG_ERROR, "ERROR - Fail to " "initialize WFD!\n"); goto fail; } if (auto_go) { if (wfd_wlan_update_bss_mode(BSS_MODE_WIFIDIRECT_GO) != WPS_STATUS_SUCCESS) { wps_printf(MSG_ERROR, "ERROR - Fail to " "initialize BSS Mode!\n"); goto fail; } if (wfd_set_mode(WFD_MODE_START_GROUP_OWNER) != WPS_STATUS_SUCCESS) { wps_printf(MSG_ERROR, "ERROR - Fail to " "initialize WFD!\n"); goto fail; } if (!wps_s->current_ssid.ssid_len) { apcmd_get_bss_config(&bss_config); load_cred_info(wps_s, gpwps_info, &bss_config); /* * For Wi-Fi Direct, we need to * convert the passphrase to PSK. * * Hence update the default * passphrase */ wlan_generate_psk(gpwps_info); } if (wps.cb(P2P_AUTO_GO_STARTED, &WFD_devicename, strlen(WFD_devicename)) == -WM_FAIL) P2P_LOG("WFD Callback failed for " "event: %d\r\n", P2P_AUTO_GO_STARTED); if (wlan_add_network(&p2p_uap_network) != WLAN_ERROR_NONE) { wps_printf(MSG_ERROR, "failed to add " "wfd network\r\n"); goto fail; } if (wlan_start_network(p2p_uap_network.name) != WLAN_ERROR_NONE) { wps_printf(MSG_ERROR, "failed to start " "wfd network\r\n"); goto fail; } } else { mlanconfig_bgscan(1); if (wfd_set_mode(WFD_MODE_START_FIND_PHASE) != WPS_STATUS_SUCCESS) { wps_printf(MSG_ERROR, "ERROR - Fail to " "initialize WFD!\n"); goto fail; } wps_set_wfd_cfg(); if (wps.cb(P2P_DEVICE_STARTED, &WFD_devicename, strlen(WFD_devicename)) == -WM_FAIL) P2P_LOG("WFD Callback failed for " "event: %d\r\n", P2P_DEVICE_STARTED); wfd_start_peer_ageout_timer(pwfd_data); p2p_scan_on = 1; } } #endif #ifndef CONFIG_P2P if (wps.cb(WPS_STARTED, NULL, 0) == -WM_FAIL) WPS_LOG("WPS Callback failed for event: %d\r\n", WPS_STARTED); #endif #ifndef CONFIG_WPA2_ENTP wps_register_rx_callback(WPSEAPoLRxDataHandler); #endif while (1) { #ifdef CONFIG_WPA2_ENTP ret = os_queue_recv(&wps.cmd_queue, &wpa2_cmd, RX_WAIT); if (ret != WM_SUCCESS || wpa2_cmd == NULL) continue; #else #ifdef CONFIG_P2P if (!auto_go && p2p_scan_on) { if (wps_loop.timeout) { now.tv_sec = os_ticks_to_msec(os_ticks_get()) / 1000; now.tv_usec = (os_ticks_to_msec (os_ticks_get()) % 1000) * 1000; if (timer_cmp(&now, &wps_loop.timeout->time)) timersub(&wps_loop.timeout->time, &now, &tv); else tv.tv_sec = tv.tv_usec = 0; } /* check if some registered timeouts have occurred */ if (wps_loop.timeout) { struct wps_timeout_s *tmp; now.tv_sec = os_ticks_to_msec(os_ticks_get()) / 1000; now.tv_usec = (os_ticks_to_msec (os_ticks_get()) % 1000) * 1000; if (!timer_cmp(&now, &wps_loop.timeout->time)) { tmp = wps_loop.timeout; wps_loop.timeout = wps_loop.timeout->next; tmp->handler(tmp->callback_data); wps_mem_free(tmp); } } } if (go_request) { p2p_scan_on = 0; g_method = CMD_WPS_PBC; wps_init(); go_request = 0; } ret = os_queue_recv(&wps.cmd_queue, &wps_cmd, os_msec_to_ticks(1000)); #else ret = os_queue_recv(&wps.cmd_queue, &wps_cmd, RX_WAIT); #endif if (ret != WM_SUCCESS || wps_cmd == NULL) continue; #endif #ifdef CONFIG_WPA2_ENTP memcpy(&wps_s->wpa2_network, &wpa2_cmd->wpa2_network, sizeof(struct wlan_network)); wps_mem_free(wpa2_cmd); g_method = CMD_WPS_PBC; ret = wps_private_info_allocate(&gpwps_info); ret = wps_init(); continue; #else g_method = wps_cmd->command; g_channel = wps_cmd->res.channel; #ifdef CONFIG_P2P g_bssid = (u8 *) wps_cmd->res.bssid; g_ssid = (u8 *) wps_cmd->res.ssid; #else memcpy(g_ssid, (u8 *) wps_cmd->res.ssid, MAX_SSID_LEN + 1); memcpy(g_bssid, (u8 *) wps_cmd->res.bssid, ETH_ALEN); #endif wps_mem_free(wps_cmd); switch (g_method) { case CMD_WPS_PIN: g_gen_pin = wps_cmd->wps_pin; wps_init(); break; case CMD_WPS_PBC: wps_init(); break; } #endif } #ifdef CONFIG_P2P fail: if (wps.cb(P2P_FAILED, NULL, 0) == -WM_FAIL) P2P_LOG("WPS Callback failed for event: %d\r\n", P2P_FAILED); wps_stop(); #endif }