Mediatek Labs LinkIt Instruction Manual

© 2015 - 2017 MediaTek Inc.
This document contains information that is proprietary to MediaTek Inc. (“MediaTek”) and/or its licensor(s). MediaTek cannot grant you
permission for any material that is owned by third parties. You may only use or reproduce this document if you have agreed to and been
bound by the applicable license agreement with MediaTek (“License Agreement”) and been granted explicit permission within the License
Agreement (“Permitted User”). If you are not a Permitted User, please cease any access or use of this document immediately. Any
unauthorized use, reproduction or disclosure of this document in whole or in part is strictly prohibited. THIS DOCUMENT IS PROVIDED ON AN
“AS-IS” BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES OF ANY KIND AND SHALL IN NO EVENT BE LIABLE FOR ANY
CLAIMS RELATING TO OR ARISING OUT OF THIS DOCUMENT OR ANY USE OR INABILITY TO USE THEREOF. Specifications contained herein are
subject to change without notice.
MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
Version: 1.7
Release date: 15 September 2017

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page i of iii
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.
Document Revision History
Revision Date Description
1.0 7 March 2016 Initial release
1.1 22 April 2016 •Wi-Fi WPS connection support.
•Replaced NVRAM with NVDM.
•Changed the API naming to register and unregister an event handler, such
as replacing the wifi_connection_register_event_notifier()
with wifi_connection_register_event_handler().
1.2 30 June 2016 •The document is updated to include Wi-Fi initialization APIs and supported
library descriptions for the Wi-Fi module.
•Instructions on how to configure the Wi-Fi module in repeater mode.
•Updated the Scan APIs and Smart Connection APIs.
•Deleted the Wi-Fi Profile.
1.3 2 September 2016 •Updated Table 3 to list the functions that can be invoked before task
scheduler running.
•Instructions on how to configure the Wi-Fi connection with a specific
BSSID.
•Updated Smart Connection Overview and Figure 3.
1.4 4 November 2016 •Renamed “libbsp.a”to “libwifi.a”.
1.5 13 January 2017 •Updated the software architecture diagram.
•Added the monitor mode for raw Wi-Fi packets.
1.6 5 May 2017 •Updated the overview to add description for MT7686/MT7682/MT5932
chipsets.
•Added Table 1 to describe supported features of different chipsets.
•Updated supported libraries.
•Added detailed description about payload of each event in Wi-Fi event
Table 5.
•Added
wifi_config_set_country_code()/wifi_config_get_country_
code() APIs in Table 6.
•Modified the example code to process the WEP key length when the
device is in AP mode.
•Renamed “Elian APK” to “SmartConnection APK”.
•Modified the folder name for APK and Smart Connection libraries.
•Updated the supported version of Smart Connection protocol.
1.7 15 September
2017
•Updated the software architecture in Figure 1.
•Updated section 1.1, “Supported features” to include support for
MT7682/MT7687 STA WPS and repeater modes.
•Updated section 2.7, “WPS”. AP + Enrollee PIN method is only supported in
MT7687 and MT7697.

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page ii of iii
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.
Table of Contents
1. Overview ............................................................................................................................................... 1
1.1. Supported features.............................................................................................................................1
1.2. Supported libraries .............................................................................................................................2
1.3. Software architecture of the Wi-Fi module........................................................................................2
2. Using the Module .................................................................................................................................. 4
2.1. Using the Wi-Fi module in STA mode .................................................................................................4
2.1.1. The AP router operates in open mode .............................................................................5
2.1.2. The AP router operates in WPA2PSK authentication mode .............................................6
2.1.3. The AP router operates in open WEP mode.....................................................................7
2.1.4. Two AP routers operate in WPA2PSK authentication mode ............................................8
2.1.5. Disable and enable auto connect option in STA mode.....................................................8
2.1.6. Wi-Fi connection support .................................................................................................9
2.2. Using the Wi-Fi module in AP mode.................................................................................................13
2.2.1. Use the device in AP open mode....................................................................................15
2.2.2. Use the device in AP mode with WPA2PSK method.......................................................16
2.2.3. Use the device in AP mode with open WEP method......................................................17
2.2.4. Wi-Fi connection support ...............................................................................................18
2.3. Using the Wi-Fi module in a repeater mode ....................................................................................19
2.3.1. Features in the repeater mode.......................................................................................19
2.3.2. Using the static method..................................................................................................20
2.3.3. Using the dynamic method.............................................................................................21
2.4. Scan ..................................................................................................................................................22
2.4.1. Scan APIs.........................................................................................................................23
2.5. Smart Connection .............................................................................................................................26
2.5.1. Smart Connection APIs ...................................................................................................26
2.5.2. How to use the Smart Connection API ...........................................................................27
2.6. Monitor mode and RX filter..............................................................................................................28
2.6.1. How to use the RX filter API............................................................................................28
2.6.2. How to receive raw packets............................................................................................29
2.7. WPS...................................................................................................................................................30
2.7.1. Using the APIs .................................................................................................................31
2.7.2. Wi-Fi WPS connection support.......................................................................................34

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page iii of iii
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.
Lists of Tables and Figures
Table 1. Supported features of different chipsets ..................................................................................................1
Table 2. Libraries for the Wi-Fi mode configuration ...............................................................................................2
Table 3. Configuration functions.............................................................................................................................4
Table 4. The supported security modes..................................................................................................................6
Table 5. Wi-Fi events.............................................................................................................................................10
Table 6. Configuration and connection APIs in the AP mode ...............................................................................14
Table 7. The functions not supported in repeater mode......................................................................................20
Table 8. Scan mode ...............................................................................................................................................22
Table 9. Scan option..............................................................................................................................................22
Table 10. Channels supporting 2.4G .....................................................................................................................22
Table 11. Channels supporting 5G ........................................................................................................................22
Table 12. Scan APIs ...............................................................................................................................................23
Table 13. Smart Connection APIs ..........................................................................................................................27
Table 14. RX filter definitions................................................................................................................................28
Table 15. WPS APIs................................................................................................................................................31
Figure 1. Software architecture ..............................................................................................................................3
Figure 2. Repeater mode topology .......................................................................................................................19
Figure 3. Communicating with an IoT device using Smart Connection.................................................................26

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 1 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.
1. Overview
MediaTek MT7687, MT7697, MT7686, MT7682 and MT5932 chipsets are based on Wi-Fi System-on-Chip (SOC)
with embedded TCP/IP stack for Internet of Things (IoT) devices that can connect to other smart devices or to
cloud applications and services directly. MediaTek LinkIt™ software development kit (SDK) provides API and
example applications for the Wi-Fi module.
This document guides you through the following:
•Initializing the Wi-Fi module in Access Point (AP) and Station (STA) modes.
•Configuring the module to operate in STA mode or AP mode.
•Scanning for the available stations.
•Using smart connection and the RX filter.
1.1. Supported features
The Wi-Fi module on LinkIt for RTOS platform supports the following features and modes.
•STA Open or wired equivalent privacy (WEP)/Wi-Fi protected access (WPA)/WPA2 personal.
•STA Wi-Fi power save mode and delivery traffic indication message (DTIM) configuration. Power save
mode and DTIM are essential in Wi-Fi connectivity support.
•STA Wi-Fi Protected Setup (WPS), is a network security standard to create a secure wireless home
network.
•Wi-Fi aggregated MAC protocol data unit (A-MPDU) support.It enables to pack multiple MPDUs together
to reduce the overheads and average them over multiple frames, thereby increasing the data rate.
•SoftAP Open/WEP-Open/WPA/WPA2 personal, the authentication modes are the same as for STA mode.
•SoftAP WPS.
•High throughput for 20 MHz and 40 MHz bandwidths or both (HT40/HT20/Mix). This module sets the Wi-
Fi bandwidth.
•Repeater Mode.
Supported features for each chipset are listed in Table 1.
Table 1. Supported features of different chipsets
Features MT7687 MT7697 MT7686 MT7682 MT5932
STA Open/WEP-Open/WPA/WPA2 Y Y Y Y Y
STA Wi-Fi power saving mode Y Y Y Y Y
STA WPS Y Y Y Y N
Wi-Fi (A-MPDU) Y Y Y Y Y
SoftAP Open/WEP-Open/WPA/WPA2 Y Y Y Y Y
HT40/HT20/Mix Y Y Y Y Y

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 2 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.
Features MT7687 MT7697 MT7686 MT7682 MT5932
Repeater Mode Y Y Y Y N
1.2. Supported libraries
The SDK provides configurable libraries to use in your projects. Simply link the corresponding library to your
project described in Table 2.
Table 2. Libraries for the Wi-Fi mode configuration
Wi-Fi Mode Library
MT7687 MT7697 MT7686 MT7682 MT5932
Station
SoftAP
Repeater
WPS
libwifi.a
libminisupp.a
libwifi.a
libwifi_ram.a
1.3. Software architecture of the Wi-Fi module
There are three software layers: Driver, Middleware and Application, as shown in Figure 1. The Wi-Fi module
is located in Middleware. For more details, refer to LinkIt for RTOS get started guide.

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 3 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.
Figure 1. Software architecture

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 4 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. Using the Module
The Wi-Fi module can only be applied once the settings are configured at system reboot. Apply your settings in the
wifi_init() API to initialize the driver in STA or AP mode. To configure the board as a repeater, see section 2.2,
“Using the Wi-Fi module in AP mode”.
Starting from the SDK v4, initialize the Wi-Fi settings by calling the wifi_init() function. The legacy Wi-Fi profile
API is disabled by default. To enable the legacy Wi-Fi profile API, define compile option
MTK_WIFI_PROFILE_ENABLE.
Most of the Wi-Fi APIs in wifi_api.h require FreeRTOS up and running. These APIs should be invoked in a task
triggered by vTaskStartScheduler(). The APIs in Table 3 are invoked in the main() function as an exception.
Table 3. Configuration functions
API
API
wifi_init() wifi_connection_register_event_handler()
wifi_config_get_mac_address () wifi_connection_unregister_event_handler ()
You can register an event handler to complete the initialization and call the Wi-Fi APIs, as shown in the example
code below.
/* Register wifi initialization event handler in main() function */
wifi_connection_register_event_handler(WIFI_EVENT_IOT_INIT_COMPLETE,
user_wifi_init_callback);
/* User-defined wifi initialization callback function */
bool g_wifi_init_ready = false;
void user_wifi_init_callback() { g_wifi_init_ready = true; }
void user_wifi_init_qurey_status(){
while(g_wifi_init_ready == false) {
vTaskDelay(20);
}
}
/* User-defined task */
user_task()
{
user_wifi_init_query_status();
/* Call APIs to connect only after Wi-Fi is initialized. */
wifi_config_set_ssid(WIFI_PORT_STA, "REMOTE_AP", sizeof("REMOTE_AP"));
wifi_config_set_wpa_psk_key(WIFI_PORT_STA, "12345678",
sizeof("12345678"));
wifi_config_reload_setting();
}
2.1. Using the Wi-Fi module in STA mode
In most cases, the configuration to initialize the Wi-Fi in STA mode takes effect immediately. However, some
settings can only take effect by calling the wifi_config_reload_setting() after calling the following APIs:
•wifi_config_set_pmk()
•wifi_config_set_security_mode()

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 5 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.
•wifi_config_set_ssid()
•wifi_config_set_wep_key()
•wifi_config_set_wpa_psk_key()
The configuration APIs use in-band mechanism for Wi-Fi driver and Wi-Fi firmware communication, thus these APIs
must be called after the OS task scheduler has started, to make sure an in-band task is running. The function
wifi_config_register_rx_handler() registers wifi_rx_handler() to manage the raw packets. There is
a limitation on calling this handler as it's using an in-band mechanism. It's restricted to call any in-band functions
like Wi-Fi configuration APIs or Wi-Fi connection APIs inside wifi_rx_handler().
Note 1. There is no need to configure the security mode in STA mode, as the security mode of the STA
can automatically match to the security mode of the AP.
Note 2. If AP’s security mode is unknown, call the wifi_config_set_wpa_psk_key() and
wifi_config_set_wep_key() APIs to set the password.
To use the module in a STA mode, apply any of the examples described below.
2.1.1. The AP router operates in open mode
1) In this example, the AP router operates in open mode with an SSID of "REMOTE_AP". Initialize the module
in STA mode, as shown below.
a) Define the operation mode (config.opmode) and the SSID (config.sta_config.ssid) in the
wifi_config_t structure.
wifi_config_t config = {0};
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);
b) Call the wifi_init() function to initialize the Wi-Fi driver.
wifi_init(&config, NULL);
You’ve now successfully initialized the Wi-Fi module in STA mode.
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) Apply the parameters by calling the wifi_config_reload_setting() function.
wifi_config_reload_setting();
You’ve successfully configured the Wi-Fi settings.

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 6 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.2. The AP router operates in WPA2PSK authentication mode
1) In this example, the AP router operates in WPA2PSK authentication mode with AES encryption type, the
password is "12345678" and the SSID of the AP router is "REMOTE_AP". Initialize the module in STA mode,
as shown below.
a) Define the operation mode (config.opmode), password (config.sta_config.password) and
the SSID (config.sta_config.ssid) in the wifi_config_t structure.
wifi_config_t config = {0};
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);
b) Call the wifi_init() function to initialize the Wi-Fi driver.
wifi_init(&config, NULL);
The STA mode supports various types of security modes, as shown in Table 4. For more information about the
authentication mode and encryption group types, refer to wifi_auth_mode_t and wifi_encrypt_type_t
types in the Wi-Fi API reference guide.
Table 4. The supported security modes
Authentication mode Encryption type
WIFI_AUTH_MODE_OPEN WIFI_ENCRYPT_TYPE_WEP_ENABLED
WIFI_AUTH_MODE_WPA_PSK WIFI_ENCRYPT_TYPE_TKIP_ENABLED
WIFI_AUTH_MODE_WPA_PSK WIFI_ENCRYPT_TYPE_AES_ENABLED
WIFI_AUTH_MODE_WPA_PSK WIFI_ENCRYPT_TYPE_TKIP_AES_MIX
WIFI_AUTH_MODE_WPA2_PSK WIFI_ENCRYPT_TYPE_TKIP_ENABLED
WIFI_AUTH_MODE_WPA2_PSK WIFI_ENCRYPT_TYPE_AES_ENABLED
WIFI_AUTH_MODE_WPA2_PSK WIFI_ENCRYPT_TYPE_TKIP_AES_MIX
WIFI_AUTH_MODE_WPA_PSK_WPA2_PSK WIFI_ENCRYPT_TYPE_TKIP_ENABLED
WIFI_AUTH_MODE_WPA_PSK_WPA2_PSK WIFI_ENCRYPT_TYPE_AES_ENABLED
WIFI_AUTH_MODE_WPA_PSK_WPA2_PSK WIFI_ENCRYPT_TYPE_TKIP_AES_MIX
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) Apply the parameters by calling the wifi_config_reload_setting() function.

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 7 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.
wifi_config_reload_setting();
The STA mode supports various types of security modes, as shown in Table 4. For more information about the
authentication mode and encryption group types, refer to wifi_auth_mode_t and wifi_encrypt_type_t
types in the Wi-Fi API Reference Manual.
2.1.3. The AP router operates in open WEP mode
1) In this example, the AP router operates in open WEP mode with the key index set to 0, the password set
to "1234567890" and the SSID of the router is "REMOTE_AP". Initialize the module in STA mode, as
shown below.
a) Define the operation mode (config.opmode), the SSID (config.sta_config.ssid), password
(config.sta_config.password) and key index (config_ext.sta_wep_key_index) in the
wifi_config_t and wifi_config_ext_t data structures. Set
config_ext.sta_wep_key_index_present to 1 to enable the presence of
config_ext.sta_wep_key_index.
wifi_config_t config = {0};
wifi_config_ext_t config_ext = {0};
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, "1234567890");
config.sta_config.password_length = strlen((char
*)config.sta_config.password);
config_ext.sta_wep_key_index_present = 1;
config_ext.sta_wep_key_index = 0;
b) Call the wifi_init() function to initialize the Wi-Fi driver.
wifi_init(&config, &config_ext);
Note, the open WEP mode is configured slightly different from the other two examples described in this section. It
requires both wifi_config_t and wifi_config_ext_t parameters.
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 WEP key by calling the wifi_config_set_wep_key() function.
wifi_wep_key_t wep_key = {{{0}}};
wep_key.wep_tx_key_index = 0;
wep_key.wep_key[0] = "1234567890";
wep_key.wep_key_length[0] = strlen("1234567890");
wifi_config_set_wep_key(WIFI_PORT_STA, &wep_key);
d) Apply the settings by calling wifi_config_reload_setting() function.
wifi_config_reload_setting();

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.

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 9 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.
a) Initialize the wifi_config_ext_t structure, as shown below. Set
config_ext.sta_auto_connect_present to 1 to enable the presence of
config_ext.sta_auto_connect.
wifi_config_ext_t config_ext;
config_ext.sta_auto_connect_present = 1;
config_ext.sta_auto_connect = 1; // Enable the auto connect.
b) Call the wifi_init() function to initialize the Wi-Fi driver, see section 2.1, “Using the Wi-Fi module
in STA mode”.
wifi_init(&config, &config_ext); // Assuming the config is already
initialized.
2) Disable the auto connect option.
a) Initialize the wifi_config_ext_t structure.
wifi_config_ext_t config_ext;
config_ext.sta_auto_connect_present = 1;
config_ext.sta_auto_connect = 0; // Disable the auto connect.
b) Call the wifi_init() function to initialize the Wi-Fi driver, see section 2.1, “Using the Wi-Fi module
in STA mode”.
wifi_init(&config, &config_ext); // Assuming the config is already
initialized
Note, if the mode is changed to STA mode by calling wifi_config_set_opmode(), the Wi-Fi driver will not
connect to the AP router using auto connect. And after calling wifi_config_reload_setting(), it will start
try to connect to AP.
2.1.6. Wi-Fi connection support
The connection APIs are used to manage the link status, such as, disconnect from the AP, disconnect the station,
get the link status, get the station list, start/stop the scan and register an event handler for scan, connect, or
disconnect events. The connection APIs use an in-band mechanism and must be called after the OS task scheduler
has started, to ensure the in-band task is running.
In the STA mode, the device can disconnect from the AP, get the link status, start or stop the scan and register an
event handler for scan, connect or disconnect events.
1) Get the link status.
Call the function wifi_connection_get_link_status() to get the link status in STA mode, as shown below.
2) Disconnect the AP.
Call the function wifi_connection_disconnect_ap() to disconnect the station from the AP router, as shown
below.
uint8_t status = 0;
uint8_t link = 0;
status = wifi_connection_get_link_status(&link);
if (link == 1){
printf("link=%d, the station is connecting to an AP router.\n", link);
}else if (link == 0) {
printf("link=%d, the station doesn’t connect to an AP router.\n",
link);
}

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 10 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.
3) Register or unregister an event handler.
The event handlers to register or unregister events are listed in Table 5. The table shows the supported events
generated by the Wi-Fi driver. The events will be sent to handlers registered by the upper layer. More details on
the event handlers can be found in the Wi-Fi API Reference Manual.
Table 5. Wi-Fi events
Event Description
WIFI_EVENT_IOT_CONNECTED •Connected event
The event is triggered when authentication and association are
complete.
•Event payload
oMAC address (6 bytes) and port number (1 byte).
MAC address. The MAC address of a remote AP that
the device is connected to or the MAC address of a
client connected to the device when it is in AP mode.
Port number indicates which port the event initiated
from.
0, STA port; 1, AP port.
WIFI_EVENT_IOT_SCAN_COMPLETE
•Scan complete event.
Triggered when the scan process is complete.
•Event payload
NULL.
WIFI_EVENT_IOT_DISCONNECTED •Disconnected event:
The device status switches from connected to disconnected.
•Event payload
oMAC address (6 bytes) and port number (1 byte).
MAC address: The MAC address of a remote AP that
the device disconnected from or the MAC address of
a disconnected client.
Port number indicates which port the event initiated
from.
0, STA port; 1, AP port.
WIFI_EVENT_IOT_PORT_SECURE
•Secure event, mainly processed in supplicant. It can be used
at the DHCP start.
oIn open mode, this event is triggered when
authentication and association are complete.
oIn WPA-PSK/WPA2-PSK mode, this event is triggered
when 4-way handshake (group handshake) is complete.
•Event payload
oMAC address (6 bytes) and port number (1 byte).
MAC address: the MAC address of a remote AP that
the device is connected to.
Port number indicates which port the event initiated
uint8_t status = 0;
status = wifi_connection_disconnect_ap();

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 11 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.
Event Description
from.
0, STA port; 1, AP port.
WIFI_EVENT_IOT_REPORT_BEACON_PROBE
_RESPONSE
•This event is triggered when beacon or probe response is
received during scan process (see the wifi_event_t
enumeration).
•Event payload
oThe beacon or probe response raw data, the length is
based on the packet frame received.
oThe payload can be parsed by the function
wifi_connection_parse_beacon(). More details
can be found in the Wi-Fi API Reference Manual.
WIFI_EVENT_IOT_WPS_COMPLETE •Credential event, triggered by the Enrollee when it
successfully parses the WPS credentials in M8 message.
•Event payload
Represents the credentials used for WPS, the payload format
follows wifi_wps_credential_info_t structure. More
details please refer to Wi-Fi API Reference Manual.
WIFI_EVENT_IOT_INIT_COMPLETE •Initialization complete event for Wi-Fi module.
Triggered when supplicant initialization is complete.
•Event payload
oZero data (6 bytes) and port number (1 byte).
Port number indicates which port the event initiated
from.
0, STA port; 1, AP port.
WIFI_EVENT_IOT_REPORT_FILTERED_FRA
ME
•Reports the expected management packet frame (see the
wifi_event_t enumeration).
Triggered after invoking the function
wifi_config_set_rx_filter().The user can choose several
types of frames at the same time. More details please refer to Wi-
Fi API Reference Manual.
•Event payload
Expected management packet frame.
WIFI_EVENT_IOT_CONNECTION_FAILED •Connection has failed.
This event can only be triggered when the current password is
wrong, other cases are not available yet.
•Event payload
oPort number (1 byte) and 2 bytes reason code.
Port number indicates which port the event initiated
from.
0, STA port; 1, AP port.
reason code: 100 means password wrong.
An example code to describe events to register or unregister a callback for the WIFI_EVENT_IOT_CONNECTED,
WIFI_EVENT_IOT_SCAN_COMPLETE,WIFI_EVENT_IOT_DISCONNECTED,WIFI_EVENT_IOT_PORT_SECURE
events is provided below. Each event needs to be registered or unregistered individually.

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 12 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.
/* Register event handler */
uint8_t status = 0;
int user_event_callback(wifi_event_t event_id, unsigned char *payload,
unsigned int len) /* The handler is triggered when the device connects to
an AP router*/
{
int handled = 0;
switch (event_id) {
case WIFI_EVENT_IOT_CONNECTED:
handled = 1;
if ((len == WIFI_MAC_ADDRESS_LENGTH) && (payload)) {
printf("[User Event Callback Sample]: LinkUp! CONNECTED MAC
= %02x:%02x:%02x:%02x:%02x:%02x\n",
payload[0],payload[1],payload[2],
payload[3],payload[4],payload[5]);
} else {
printf("[User Event Callback Sample]: LinkUp!\n");
}
break;
case WIFI_EVENT_IOT_SCAN_COMPLETE:
handled = 1;
printf("[User Event Callback Sample]: Scan Done!\n");
break;
case WIFI_EVENT_IOT_DISCONNECTED:
handled = 1;
if ((len == WIFI_MAC_ADDRESS_LENGTH) && (payload)) {
printf("[User Event Callback Sample]: Disconnect! DISCONNECTED
MAC
= %02x:%02x:%02x:%02x:%02x:%02x\n",
payload[0],payload[1],payload[2],
payload[3],payload[4],payload[5]);
} else {
printf("[User Event Callback Sample]: Disconnect!\n");
}
break;
case WIFI_EVENT_IOT_PORT_SECURE:
handled = 1;
if ((len == WIFI_MAC_ADDRESS_LENGTH) && (payload)) {
printf("[User Event Callback Sample]: Port Secure! CONNECTED
MAC
= %02x:%02x:%02x:%02x:%02x:%02x\n",
payload[0],payload[1],payload[2],
payload[3],payload[4],payload[5]);
} else {
printf("[User Event Callback Sample]: Port Secure! \n");
}
break;
default:
printf("[User Event Callback Sample]: Unknown event(%d)\n",
event_id);
break;
}
status = wifi_connection_register_event_handler(WIFI_EVENT_IOT_CONNECTED,
(wifi_event_handler_t) user_event_callback);
status =
wifi_connection_register_event_handler(WIFI_EVENT_IOT_SCAN_COMPLETE,
(wifi_event_handler_t) user_event_callback);

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 13 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.2. Using the Wi-Fi module in AP mode
This section introduces how to initialize and configure the Wi-Fi in AP mode. A wireless AP is a device that allows
wireless devices to connect to a wired network through Wi-Fi or related standards. The AP usually connects to
a router as a standalone device, but it can also be an integral component of the router. An AP is different from a
hotspot, which is the physical space where the wireless service is provided. The development board can be
configured as an AP. There are four authentication and three encryption modes supported on the platform. This
enables 11 combinations of Wi-Fi security modes, as listed below:
•Open mode
•WPA_PSK and AES mode
•WPA_PSK and TKIP mode
•WPA_PSK and AES+TKIP mode
•WPA2_PSK and AES mode
•WPA2_PSK and TKIP mode
•WPA2_PSK and AES+TKIP mode
•WPA_PSK_WPA2_PSK and AES mode
•WPA_PSK_WPA2_PSK and TKIP mode
•WPA_PSK_WPA2_PSK and AES+TKIP mode
•WEP Open mode
The supporting APIs to set the platform to AP mode are shown in Table 6.
status =
wifi_connection_register_event_handler(WIFI_EVENT_IOT_DISCONNECTED,
(wifi_event_handler_t) user_event_callback);
status =
wifi_connection_register_event_handler(WIFI_EVENT_IOT_PORT_SECURE,
(wifi_event_handler_t) user_event_callback);
/* Unregister event handler */
status =
wifi_connection_unregister_event_handler(WIFI_EVENT_IOT_CONNECTED,
(wifi_event_handler_t) user_event_callback);
status =
wifi_connection_unregister_event_handler(WIFI_EVENT_IOT_SCAN_COMPLETE,
(wifi_event_handler_t) user_event_callback);
status =
wifi_connection_unregister_event_handler(WIFI_EVENT_IOT_DISCONNECTED,
(wifi_event_handler_t) user_event_callback);
status =
wifi_connection_unregister_event_handler(WIFI_EVENT_IOT_PORT_SECURE,
(wifi_event_handler_t) user_event_callback);

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 14 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.
Table 6. Configuration and connection APIs in the AP mode
API Description
wifi_config_set_opmode() This function sets the Wi-Fi operation mode and it
takes effect immediately.
wifi_config_set_ssid() This function sets the SSID and SSID length that Wi-
Fi driver uses for a specific wireless port.
wifi_config_set_bandwidth() This function sets the bandwidth configuration that
the Wi-Fi driver uses for a specific wireless port.
wifi_config_set_wireless_mode() This function sets the wireless mode that the Wi-Fi
driver uses for a specific wireless port.
wifi_config_set_channel() This function sets the channel number that the Wi-Fi
driver uses for a specific wireless port.
wifi_config_set_security_mode() This function sets the authentication and encryption
modes used in the Wi-Fi driver for a specific wireless
wifi_config_set_wpa_psk_key() This function sets the password of WPA-PSK or
WPA2-PSK encryption type used in the Wi-Fi driver.
wifi_config_set_pmk() This function sets the PMK used in the Wi-Fi driver
for a specific wireless port.
wifi_config_set_wep_key() This function sets the WEP key group used in the Wi-
Fi driver for a specific wireless port.
wifi_config_set_country_code() This function sets the country code used in the Wi-Fi
driver.
wifi_config_get_opmode() This function receives the wireless operation mode
of the Wi-Fi d r i ver.
wifi_config_get_mac_address() This function gets the MAC address of a specific
wireless port used by the Wi-Fi driver.
wifi_config_get_ssid() This function gets the SSID and SSID length of a
specific wireless port used by the Wi-Fi d ri ver.
wifi_config_get_bandwidth() This function gets the bandwidth configuration that
the Wi-Fi driver uses for a specific wireless port.
wifi_config_get_channel() This function gets the channel number that the Wi-
Fi driver uses for a specific wireless port.
wifi_config_get_wireless_mode() This function gets the wireless mode that the Wi-Fi
driver uses for a specific wireless port.
wifi_config_get_security_mode() This function gets the authentication and encryption
modes used in the Wi-Fi driver for a specific wireless
wifi_config_get_wpa_psk_key() This function gets the password of WPA-PSK or
WPA2-PSK encryption type used in the Wi-Fi driver
for a specific wireless port
wifi_config_get_pmk() This function gets the PMK used in the Wi-Fi driver
for a specific wireless port.
wifi_config_get_wep_key() This function gets the WEP key group used in the
Wi-Fi driver for a specific wireless port.
wifi_config_get_country_code() This function gets the country code used in the Wi-Fi
driver.
wifi_connection_parse_beacon() This function parses the beacon or probe request
packets.

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 15 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.
API Description
wifi_connection_register_event_handler() This function registers the Wi-Fi Event handler.
wifi_connection_unregister_event_handler() This function unregisters Wi-Fi Event handler.
wifi_connection_disconnect_sta()
This function disconnects the connected Wi-Fi
station.
wifi_connection_get_sta_list() This function gets the Wi-Fi Associated Station List.
wifi_connection_get_max_sta_number() This function gets the maximum number of the
stations supported in AP mode or dual mode.
wifi_connection_get_link_status() This function gets the current STA port link up / link
down status of the connection.
You can find more information on the APIs in the Wi-Fi API Reference Manual.
To use the device in the AP mode, apply any of the three examples described below.
2.2.1. Use the device in AP open mode
1) In this example, initialize the device in AP open mode on channel 6 with the SSID of "MTK_SOFT_AP”, as
shown below.
a) Define the operation mode (config.opmode), SSID (config.ap_config.ssid), channel
(config.ap_config.channel), authentication mode (config.ap_config.auth_mode) and
encryption type (config.ap_config.encrypt_type) in the wifi_config_t structure, as shown
below.
wifi_config_t config = {0};
config.opmode = WIFI_MODE_AP_ONLY;
strcpy((char *)config.ap_config.ssid, "MTK_SOFT_AP");
config.ap_config.ssid_length = strlen((char *)config.ap_config.ssid);
config.ap_config.auth_mode = WIFI_AUTH_MODE_OPEN;
config.ap_config.encrypt_type = WIFI_ENCRYPT_TYPE_WEP_DISABLED;
config.ap_config.channel = 6;
b) Call the wifi_init() function to initialize the Wi-Fi driver.
wifi_init(&config, NULL);
2) Use configuration APIs to set the device in AP mode that operates on channel 6 in open mode with an
SSID of “MTK_SOFT_AP”.
a) Call the function wifi_config_set_opmode(opmode) to set the opmode to
WIFI_MODE_AP_ONLY, as shown below.
wifi_config_set_opmode(WIFI_MODE_AP_ONLY);
Call the function wifi_config_set_ssid(port, ssid_name, strlen(ssid_name)) to set the SSID
("MTK_SOFT_AP") of a given port (WIFI_PORT_AP), as shown below.
wifi_config_set_ssid(WIFI_PORT_AP, "MTK_SOFT_AP", strlen("MTK_SOFT_AP"));
b) Call the function wifi_config_set_security_mode(port, auth, encrypt) to set the
security mode of the AP router, as shown below.
wifi_config_set_security_mode(WIFI_PORT_AP, WIFI_AUTH_MODE_OPEN,
WIFI_ENCRYPT_TYPE_WEP_DISABLED);

MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 16 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.
c) Call the function wifi_config_set_channel(port, channel) to setup the channel on a given
port, as shown below.
wifi_config_set_channel(WIFI_PORT_AP, 6);
Apply the configuration by calling the function wifi_config_reload_setting(), as shown below.
wifi_config_reload_setting();
2.2.2. Use the device in AP mode with WPA2PSK method
1) In this example, the device is in AP mode and operates on channel 6, the authentication mode is
WPA2PSK (WIFI_AUTH_MODE_WPA2_PSK) with AES encryption type
(WIFI_ENCRYPT_TYPE_AES_ENABLED), the password is "12345678"and the SSID is "MTK_SOFT_AP".
Initialize the module in AP mode, as shown below.
a) Define the operation mode (config.opmode), SSID (config.ap_config.ssid), channel
(config.ap_config.channel), authentication mode (config.ap_config.auth_mode),
encryption type (config.ap_config.encrypt_type) and password
(config.ap_config.password) in the wifi_config_t structure, as shown below.
wifi_config_t config = {0};
config.opmode = WIFI_MODE_AP_ONLY;
strcpy((char *)config.ap_config.ssid, "MTK_SOFT_AP");
config.ap_config.ssid_length = strlen("MTK_SOFT_AP");
config.ap_config.auth_mode = WIFI_AUTH_MODE_WPA2_PSK;
config.ap_config.encrypt_type = WIFI_ENCRYPT_TYPE_AES_ENABLED;
strcpy((char *)config.ap_config.password, "12345678");
config.ap_config.password_length = strlen("12345678");
config.ap_config.channel = 6;
b) Call the wifi_init() function to initialize the Wi-Fi driver.
wifi_init(&config, NULL);
The device in AP mode supports various types of security modes, as shown in Table 4. More information about the
authentication mode and encryption group types can be found in wifi_auth_mode_t and
wifi_encrypt_type_t types in the Wi-Fi API Reference Manual.
2) Use configuration APIs to set the device in AP mode that operates in WPA2PSK mode with a given port,
channel, password and SSID.
a) Call the function wifi_config_set_opmode(opmode) to set the opmode to
WIFI_MODE_AP_ONLY, as shown below.
wifi_config_set_opmode(WIFI_MODE_AP_ONLY);
Call the function wifi_config_set_ssid(port, ssid_name, strlen(ssid_name)) to set the SSID
("MTK_SOFT_AP") of a given port (WIFI_PORT_AP), as shown below.
wifi_config_set_ssid(WIFI_PORT_AP, "MTK_SOFT_AP", strlen("MTK_SOFT_AP"));
b) Call the function wifi_config_set_security_mode(port, auth, encrypt) to set the
security mode of the AP router, as shown below.
wifi_config_set_security_mode(WIFI_PORT_AP, WIFI_AUTH_MODE_WPA2_PSK,
WIFI_ENCRYPT_TYPE_AES_KEY_ENABLED);
c) Call the function wifi_config_set_wpa_psk_key(port, password,
strlen(password)) to set the WPA2PSK key, as shown below.
wifi_config_set_wpa_psk_key(WIFI_PORT_AP, "12345678", strlen("12345678"));
d) Call the function wifi_config_set_channel(port, channel) to setup the channel on a
given port, as shown below.
Table of contents