Beispiel #1
0
/* 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);
}
Beispiel #2
0
int app_connect_to_p2p_go(struct wlan_network *net)
{
	app_l("connecting to P2P GO");
	memcpy(net->name, DEF_NET_NAME, sizeof(net->name));
	int ret = wlan_add_network(net);
	if (ret != WLAN_ERROR_NONE) {
		app_e("network_mgr: failed to add network %d", ret);
		return -WM_E_AF_NW_ADD;
	}
	wlan_connect(net->name);
	return WM_SUCCESS;
}
Beispiel #3
0
/* 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
}
void test_wlan_add(int argc, char **argv)
{
	struct wlan_network network;
	int ret = 0;
	int arg = 1;
	struct {
		unsigned ssid:1;
		unsigned bssid:1;
		unsigned channel:1;
		unsigned address:2;
		unsigned security:1;
		unsigned role:1;
	} info;

	memset(&info, 0, sizeof(info));
	memset(&network, 0, sizeof(struct wlan_network));

	if (argc < 4) {
		dump_wlan_add_usage();
		wmprintf("Error: invalid number of arguments\r\n");
		return;
	}

	if (strlen(argv[arg]) >= WLAN_NETWORK_NAME_MAX_LENGTH) {
		wmprintf("Error: network name too long\r\n");
		return;
	}

	memcpy(network.name, argv[arg], strlen(argv[arg]));
	arg++;
	info.address = ADDR_TYPE_DHCP;
	do {
		if (!info.ssid && string_equal("ssid", argv[arg])) {
			if (strlen(argv[arg + 1]) > IEEEtypes_SSID_SIZE) {
				wmprintf("Error: SSID is too long\r\n");
				return;
			}
			memcpy(network.ssid, argv[arg + 1],
			       strlen(argv[arg + 1]));
			arg += 2;
			info.ssid = 1;
		} else if (!info.bssid && string_equal("bssid", argv[arg])) {
			ret = get_mac(argv[arg + 1], network.bssid, ':');
			if (ret) {
				wmprintf("Error: invalid BSSID argument"
					"\r\n");
				return;
			}
			arg += 2;
			info.bssid = 1;
		} else if (!info.channel && string_equal("channel", argv[arg])) {
			if (arg + 1 >= argc ||
			    get_uint(argv[arg + 1], &network.channel,
				     strlen(argv[arg + 1]))) {
				wmprintf("Error: invalid channel"
					" argument\n");
				return;
			}
			arg += 2;
			info.channel = 1;
		} else if (!strncmp(argv[arg], "ip:", 3)) {
			ret = get_address(argv[arg], &network.address);
			if (ret) {
				wmprintf("Error: invalid address"
					" argument\n");
				return;
			}
			arg++;
			info.address = ADDR_TYPE_STATIC;
		} else if (!info.security && string_equal("wep", argv[arg])) {
			ret =
				get_security(argc - arg - 1,
					     (char **)(argv + arg + 1),
					     WLAN_SECURITY_WEP_OPEN,
					     &network.security);
			if (ret) {
				wmprintf("Error: invalid WEP security"
					" argument\r\n");
				return;
			}
			arg += 3;
			info.security++;
		} else if (!info.security && string_equal("wpa", argv[arg])) {
			ret =
			    get_security(argc - arg - 1, argv + arg + 1,
					 WLAN_SECURITY_WPA, &network.security);
			if (ret) {
				wmprintf("Error: invalid WPA security"
					" argument\r\n");
				return;
			}
			arg += 2;
			info.security++;
		} else if (!info.security && string_equal("wpa2", argv[arg])) {
			ret =
			    get_security(argc - arg - 1, argv + arg + 1,
					 WLAN_SECURITY_WPA2, &network.security);
			if (ret) {
				wmprintf("Error: invalid WPA2 security"
					" argument\r\n");
				return;
			}
			arg += 2;
			info.security++;
		} else if (!info.role && string_equal("role", argv[arg])) {
			if (arg + 1 >= argc ||
			    get_role(argv[arg + 1], &network.role)) {
				wmprintf("Error: invalid wireless"
					" network role\r\n");
				return;
			}
			arg += 2;
			info.role++;
		} else if (!strncmp(argv[arg], "autoip", 6)) {
			info.address = ADDR_TYPE_LLA;
			arg++;
		} else {
			dump_wlan_add_usage();
			wmprintf("Error: argument %d is invalid\r\n", arg);
			return;
		}
	} while (arg < argc);

	if (!info.ssid && !info.bssid) {
		dump_wlan_add_usage();
		wmprintf("Error: specify at least the SSID or BSSID\r\n");
		return;
	}

	network.address.addr_type = info.address;

	ret = wlan_add_network(&network);
	switch (ret) {
	case WLAN_ERROR_NONE:
		wmprintf("Added \"%s\"\r\n", network.name);
		break;
	case WLAN_ERROR_PARAM:
		wmprintf("Error: that network already exists\r\n");
		break;
	case WLAN_ERROR_NOMEM:
		wmprintf("Error: network list is full\r\n");
		break;
	case WLAN_ERROR_STATE:
		wmprintf("Error: can't add networks in this state\r\n");
		break;
	default:
		wmprintf("Error: unable to add network for unknown"
			" reason\r\n");
		break;
	}
}
/**
 *  @brief Process WPS Enrollee PIN mode and PBC user selection operations
 *
 *  @param pwps_info    A pointer to WPS_INFO structure
 *  @param wps_s        A pointer to global WPS structure
 *  @return             WPS_STATUS_SUCCESS--success, otherwise--fail
 */
int wps_enrollee_start(PWPS_INFO pwps_info, WPS_DATA *wps_s)
{
	int ret = WPS_STATUS_SUCCESS;
#ifndef CONFIG_WPA2_ENTP
	int retry_cnt = 5;
	int connect_retry = 10;
	enum wlan_connection_state state;
#endif

	ENTER();

	pwps_info->enrollee.auth_type_flag = AUTHENTICATION_TYPE_ALL;
	pwps_info->enrollee.encry_type_flag = ENCRYPTION_TYPE_ALL;

#ifndef CONFIG_WPA2_ENTP
	if (pwps_info->enrollee.device_password_id == DEVICE_PASSWORD_ID_PIN) {
		/* Generate PIN */
		wps_generate_PIN(pwps_info);

		if (pwps_info->pin_generator == WPS_ENROLLEE) {
			pwps_info->input_state = WPS_INPUT_STATE_NO_INPUT;
			pwps_info->pin_pbc_set = WPS_SET;
		} else {
			pwps_info->enrollee.updated_device_password_id =
			    DEVICE_PASSWORD_REG_SPECIFIED;
		}
	}

	memset(&wps_network, 0, sizeof(struct wlan_network));

	if (g_ssid && strlen((const char *)g_ssid))
		strncpy(wps_network.name, (const char *) g_ssid,
				MAX_SSID_LEN + 1);
	else
		strncpy(wps_network.name, "p2p_network", MAX_SSID_LEN + 1);
	memcpy(wps_network.ssid, (const char *) g_ssid, MAX_SSID_LEN + 1);
	memcpy(wps_network.bssid, (const char *) g_bssid, ETH_ALEN);
	wps_network.channel = g_channel;
	wps_network.address.addr_type = ADDR_TYPE_DHCP;
    #ifdef CONFIG_WPS2
	wps_network.wps_specific = 1;
    #endif
	if (g_channel)
		wps_network.channel_specific = 1;
	else if (is_mac_all_zero(g_bssid))
		wps_network.ssid_specific = 1;
	else
		wps_network.bssid_specific = 1;

	wps_network.security.type = WLAN_SECURITY_NONE;
#ifdef CONFIG_P2P
	wps_network.type = WLAN_BSS_TYPE_WIFIDIRECT;
	wps_network.role = WLAN_BSS_ROLE_STA;
#endif
	ret = wlan_add_network(&wps_network);

	if (ret != 0) {
		WPS_LOG(" Failed to add network %d\r\n", ret);
		goto fail;
	}

	do {
		WPS_LOG("Connecting to %s .....", wps_network.ssid);

		ret = wlan_connect(wps_network.name);

		if (ret != 0) {
			WPS_LOG("Failed to connect %d\r\n", ret);
			goto retry;
		}

		connect_retry = 200;

		do {

			/* wait for interface up */
			os_thread_sleep(os_msec_to_ticks(50));

			if (wlan_get_connection_state(&state)) {
				P2P_LOG("Error: unable to get "
					"connection state\r\n");
				continue;
			}

			if (state == WLAN_ASSOCIATED || connect_retry == 0)
				break;
#ifdef CONFIG_P2P
			connect_retry--;

		} while (state != WLAN_DISCONNECTED);
#else
		} while (connect_retry--);
#endif

		if (state != WLAN_ASSOCIATED) {
			WPS_LOG("Error: Not connected.\r\n");
			goto retry;
		}

		WPS_LOG("Connected to following BSS (or IBSS) :");
		WPS_LOG
		    ("SSID = [%s], BSSID = [%02x:%02x:%02x:%02x:%02x:%02x]",
		     wps_network.ssid,
		     wps_network.bssid[0],
		     wps_network.bssid[1],
		     wps_network.bssid[2],
		     wps_network.bssid[3],
		     wps_network.bssid[4], wps_network.bssid[5]);

		/* Save information to global structure */
		wps_s->current_ssid.ssid_len =
			strlen(wps_network.ssid);
		memcpy(wps_s->current_ssid.ssid,
		       wps_network.ssid, wps_s->current_ssid.ssid_len);

		memcpy(wps_s->current_ssid.bssid, wps_network.bssid, ETH_ALEN);

		/* Store Peer MAC Address */
		if (pwps_info->role == WPS_ENROLLEE
		    || (IS_DISCOVERY_ENROLLEE(pwps_info))
		    ) {
			if (is_mac_all_zero((u8 *) wps_network.bssid)) {
				if (wlan_get_current_network(&sta_network))
					goto fail;
				memcpy(pwps_info->registrar.mac_address,
					sta_network.bssid, ETH_ALEN);
			} else
				memcpy(pwps_info->registrar.mac_address,
					wps_network.bssid, ETH_ALEN);
		}
#else
		/* Save information to global structure */
		wps_s->current_ssid.ssid_len =
			strlen(wps_s->wpa2_network.ssid);
		memcpy(wps_s->current_ssid.ssid,
		       wps_s->wpa2_network.ssid, wps_s->current_ssid.ssid_len);

		memcpy(wps_s->current_ssid.bssid,
			wps_s->wpa2_network.bssid, ETH_ALEN);

		/* Store Peer MAC Address */
		if (pwps_info->role == WPS_ENROLLEE
		    || (IS_DISCOVERY_ENROLLEE(pwps_info))
		    ) {
			if (is_mac_all_zero((u8 *) wps_s->wpa2_network.bssid)) {
				if (wlan_get_current_network(&sta_network))
					goto fail;
				memcpy(pwps_info->registrar.mac_address,
					sta_network.bssid, ETH_ALEN);
			} else
				memcpy(pwps_info->registrar.mac_address,
					wps_s->wpa2_network.bssid, ETH_ALEN);
		}
#endif
#ifdef CONFIG_P2P
		WPS_LOG("Registration Process Started....");
#elif CONFIG_WPA2_ENTP
		WPS_LOG("Connected to following BSS (or IBSS) :");
		WPS_LOG
		    ("SSID = [%s], BSSID = [%02x:%02x:%02x:%02x:%02x:%02x]",
		     wps_s->wpa2_network.ssid,
		     wps_s->wpa2_network.bssid[0],
		     wps_s->wpa2_network.bssid[1],
		     wps_s->wpa2_network.bssid[2],
		     wps_s->wpa2_network.bssid[3],
		     wps_s->wpa2_network.bssid[4],
		     wps_s->wpa2_network.bssid[5]);
		WPS_LOG("WPA2 Enterprise (EAP-TLS) Protocol Started .....");
#else
		WPS_LOG("WPS Registration Protocol Started .....");

		if (wps.cb(WPS_SESSION_STARTED, NULL, 0) == -WM_FAIL)
			WPS_LOG("WPS Callback failed for event: %d\r\n",
				WPS_SESSION_STARTED);
#endif
		/* Start WPS registration timer */
		wps_start_registration_timer(pwps_info);

		/* Starting WPS Message Exchange Engine */

		wps_state_machine_start(pwps_info);

		ret = WPS_STATUS_SUCCESS;
#ifndef CONFIG_WPA2_ENTP
		break;

retry:
		retry_cnt--;
		WPS_LOG("Connect to AP FAIL ! Retrying ..... \r\n");
		wps_printf(DEBUG_WLAN | DEBUG_INIT, "Retry Count = %d",
			   retry_cnt);

	} while (retry_cnt != 0);