MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 8 of 36
This document contains information that is proprietary to MediaTek Inc. (“MediaTek”) and/or its licensor(s).
Any unauthorized use, reproduction or disclosure of this document in whole or in part is strictly prohibited.
2.1.4.
Two AP routers operate in WPA2PSK authentication mode
1)
In this example, two AP routers (AP1 and AP2) operate in WPA2PSK authentication mode with AES
encryption type. The password of each AP is "
12345678
" and the SSID of both routers is "
REMOTE_AP
".
The BSSID of AP1 is “00:11:22:33:44:55”. The BSSID of AP2 is “55:44:33:22:11:00”. The goal is to connect
to AP1. Initialize the module in STA mode, as shown below.
a)
Define the operation mode (
config.opmode
), password (
config.sta_config.password
), the
SSID (
config.sta_config.ssid
), BSSID present (
config.sta_config.bssid_present
) and
the BSSID (
config.sta_config.bssid
) in the
wifi_config_t
structure.
wifi_config_t config = {0};
uint8_t target_bssid[WIFI_MAC_ADDRESS_LENGTH] =
{0x00,0x11,0x22,0x33,0x44,0x55};
config.opmode = WIFI_MODE_STA_ONLY;
strcpy((char *)config.sta_config.ssid, "
REMOTE
_AP");
config.sta_config.ssid_length = strlen((char *)config.sta_config.ssid);
strcpy((char *)config.sta_config.password, "12345678");
config.sta_config.password_length = strlen((char
*)config.sta_config.password);
config.sta_config.bssid_present = 1;
os_memcpy(config.sta_config.bssid,
target_bssid, WIFI_MAC_ADDRESS_LENGTH
);
b)
Call the
wifi_init()
function to initialize the Wi-Fi driver.
wifi_init(&config, NULL);
2)
To use configuration APIs in STA mode to connect to the AP router:
a)
Call the
wifi_config_set_opmode()
function to set the opmode to WIFI_MODE_STA_ONLY.
wifi_config_set_opmode(WIFI_MODE_STA_ONLY);
b)
Call the
wifi_config_set_ssid()
function to set the port to WIFI_PORT_STA and the SSID to
"
REMOTE_AP
".
wifi_config_set_ssid(WIFI_PORT_STA, "
REMOTE_AP"
, strlen("
REMOTE_AP
"));
c)
Set the password to "12345678" by calling the
wifi_config_set_wpa_psk_key()
function.
wifi_config_set_wpa_psk_key(WIFI_PORT_STA, "12345678",
strlen("12345678"));
d)
Set the target BSSID to connect by calling the
wifi_config_set_bssid()
function.
uint8_t target_bssid = {0x00,0x11,0x22,0x33,0x44,0x55};
wifi_config_set_bssid(target_bssid);
e)
Apply the parameters by calling the
wifi_config_reload_setting()
function.
wifi_config_reload_setting();
2.1.5.
Disable and enable auto connect option in STA mode
The auto-connect option can be enabled or disabled during Wi-Fi initialization. If the option is enabled, the station
device automatically connects to the AP once the device is initialized, otherwise the device remains idle after the
initialization is complete, and connects to the AP only after calling the
wifi_config_reload_setting()
function. Auto-connect option is enabled as a default setting in the Wi-Fi driver.
1) Enable the auto-connect option.