background image

 

MediaTek LinkIt™ Development 

Platform for RTOS Wi-Fi Developer's 

Guide  

 

 

 

© 2015 - 2017 MediaTek Inc.

 

               Page 33 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. 

An example implementation is shown below.  

int32_t wps_get_auto_connection_status_example() 

    bool auto_conn  = false; 
    return wifi_wps_config_get_auto_connection(&auto_conn); 
}

 

2.7.1.2.

 

Register or unregister Wi-Fi WPS event handler  

To register Wi-Fi WPS credential handler:  

1)

 

Call

 

wifi_connection_register_event_handler()

.  

An example implementation for the event handler is shown below.  

int32_t wps_register_credential_event_handler_example() 

   return wifi_connection_register_event_handler( 
            WIFI_EVENT_IOT_WPS_COMPLETE, (wifi_event_handler_t)  
                              wifi_wps_credential_event_handler_example); 
}

 

An example implementation for the event handler 

wifi_wps_credential_event_handler_example() 

is 

shown below. 

int32_t int32_t wifi_wps_credential_event_handler_example( 
                                     wifi_event_t event, 
                                     uint8_t *payload, uint32_t length) 

    wifi_wps_credential_information_t *customer_cred = payload; 
 
    if (event = WIFI_EVENT_IOT_WPS_COMPLETE) { 
      LOG_I(minisupp, "WPS: ssid--%s\n", customer_cred->ssid); 
      LOG_I(minisupp, "WPS: ssid len--%d\n", customer_cred->ssid_len); 
      LOG_I(minisupp, "WPS: auth_mode-- %d\n" customer_cred->auth_mode); 
      LOG_I(minisupp, "WPS: encr_mode-- %d\n" customer_cred->encr_mode); 
      LOG_I(minisupp, "WPS: key_length--%d\n", customer_cred->key_length); 
      ...... 
      ...... 
 
      wifi_wps_unregister_credential_handler(); 
      return 0; 

 

To unregister Wi-Fi WPS credential event handler. 

1)

 

Call the function 

wifi_connection_unregister_event_handler()

 

to unregister the credential 

handler. An example implementation is shown below. 

int32_t wps_unregister_credential_event_handler_example() 

   return wifi_connection_unregister_event_handler( 
                   WIFI_EVENT_IOT_WPS_COMPLETE, (wifi_event_handler_t) 
                               wifi_wps_credential_event_handler_example); 
}

 

Summary of Contents for LinkIt

Page 1: ...ted 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 T...

Page 2: ...s 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 MT...

Page 3: ...EP 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 ...

Page 4: ...ies 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 S...

Page 5: ...odule 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...

Page 6: ...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 ...

Page 7: ...15 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 ...

Page 8: ...n 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_EV...

Page 9: ...ode 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 ...

Page 10: ...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 WIF...

Page 11: ..._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 C...

Page 12: ...ig 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_O...

Page 13: ...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 s...

Page 14: ...ress 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 o MAC address 6 bytes and p...

Page 15: ...i Fi API Reference Manual WIFI_EVENT_IOT_INIT_COMPLETE Initialization complete event for Wi Fi module Triggered when supplicant initialization is complete Event payload o Zero 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 enume...

Page 16: ...ample 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 b...

Page 17: ...es 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 w...

Page 18: ...y 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 driver wifi_config_get_mac_address This function gets the MAC address of a specific wireless port used by the Wi Fi driver wifi_co...

Page 19: ...nel 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 conf...

Page 20: ...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 infor...

Page 21: ...y index in the wifi_config_ext_t config_ext ap_wep_key_index structure as shown below 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_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_A...

Page 22: ...el WIFI_PORT_AP 4 g Apply the configuration by calling the function wifi_config_reload_setting as shown below wifi_config_reload_setting 2 2 4 Wi Fi connection support The APIs for connection support in AP mode 1 Get the station list associated with the device in AP mode Call the function wifi_connection_get_sta_list to get the station s associated AP information An example implementation is shown...

Page 23: ...onnect to the repeater using the repeater s SSID and each station can get IP address from the router The data packets can transfer between station and router through the repeater Figure 2 Repeater Mode Topology The STA communicates with the router through the repeater The repeater should connect to the router first Then the stations can get IP address from the router The remote AP also provides th...

Page 24: ...peater mode Using the static method to initialize the repeater mode at system reboot with the wifi_init API Using the dynamic method to provide Wi Fi settings in the configuration APIs The new settings take effect once the APIs reload 2 3 2 Using the static method Before applying this method a few assumptions to make The repeater operates on channel 6 with allocated bandwidth of 20MHz The AP port ...

Page 25: ...he function wifi_config_set_ssid port_apcli ssid_apcli strlen ssid_apcli to set the SSID of the AP Client port as shown below wifi_config_set_ssid WIFI_PORT_APCLI SSID_1 strlen SSID_1 b Call the function wifi_config_set_wpa_psk_key port_apcli password_apcli strlen password_apcli to set the APCLI port password wifi_config_set_wpa_psk_key WIFI_PORT_APCLI 12345678 strlen 12345678 3 To configure the A...

Page 26: ... scanned are decided by the product s country and region A probe request will be sent to each of these channels Not applied on regulatory channels 1 Passive scan in all channels Receives and processes the beacon No probe request is sent 2 Forced active scan Forced active scan in all channels A probe request is sent to each channel Table 10 and Table 11 provide the scanned channel list in different...

Page 27: ... 30 CH36 48 active scan CH52 64 passive scan CH100 140 passive scan CH149 165 active scan 31 CH52 64 passive scan CH100 140 passive scan CH149 165 active scan 32 CH36 48 active scan CH52 64 passive scan CH100 140 passive scan CH149 161 active scan 33 CH36 48 active scan CH52 64 passive scan CH100 140 passive scan 34 CH36 48 active scan CH52 64 passive scan CH149 165 active scan 35 CH36 48 active s...

Page 28: ... scan methods Apply this as a reference for other scan mode and scan option implementations There are two approaches to get the scan result one is to register an event callback and parse the Wi Fi beacon and probe request raw packet and the other method applies a scan table initialized through wifi_connection_scan_init 2 4 1 1 Using the wifi_connection_scan_init API 1 Define a buffer g_ap_list to ...

Page 29: ...ction wifi_connection_scan_deinit after the scan completes or after the scan has stopped by wifi_connect_stop_scan 2 4 1 2 Using a callback to parse the Wi Fi beacon and probe response raw packet 1 Register the event handler WIFI_EVENT_IOT_REPORT_BEACON_PROBE_RESPONSE The beacon and probe response raw packet in the air can be received and uploaded to the handler uint8_t status 0 int event_handler_...

Page 30: ...onnection configures the device without an input interface to connect to the wireless network The Smart Connection broadcasts the encrypted wireless network information SSID and password of the AP router through SmartConnection an Android application package APK built with the Smart Connection library so that the IoT device based on the LinkIt development platform can listen and decode the informa...

Page 31: ...int8_t password uint8_t password_length uint8_t tlv_data uint8_t tlv_data_length This function gets the wireless network information SSID and password collected during the Smart Connection The type length value TLV data is user defined data sent from the Smart Connection mobile application wifi_smart_connection_stop This function stops the Smart Connection 2 5 2 How to use the Smart Connection API...

Page 32: ... API The RX filter settings indicate the desired packet format to receive such as broadcast multicast and unicast frames as shown in Table 14 Table 14 RX filter definitions Input Parameter Description WIFI_RX_FILTER_DROP_STBC_BCN_BC_MC bit 0 drops STBC beacon BC MC frames WIFI_RX_FILTER_DROP_FCS_ERR bit 1 drops FCS error frames WIFI_RX_FILTER_RESERVED bit 2 a reserved bit not used WIFI_RX_FILTER_D...

Page 33: ... wifi_config_set_rx_filter API indicates the bits to configure the RX filter options The details for each bit can be found in the Wi Fi API Reference Manual 2 6 2 How to receive raw packets In order to process the raw packets register a raw packet handler to process the packets with wifi_config_register_rx_handler Note that besides the wifi_config_set_rx_filter API you can also use wifi_config_set...

Page 34: ... must support the push button method In PIN method of the WPS the wireless PIN can be found on the device label or display This PIN must then be entered at the representant the registrar of the network usually the network s access point Alternately a PIN provided by the access point may be entered into the new device A device seeking to join a wireless network is called Enrollee A device with the ...

Page 35: ...vent_handler This function registers the Wi Fi event handler The event is WIFI_EVENT_IOT_WPS_COMPLETE wifi_wps_unregister_credential_handler This function unregisters Wi Fi event handler The event is WIFI_EVENT_IOT_WPS_COMPLETE wifi_wps_connection_by_pbc This function triggers the WPS PBC process AP must act as Registrar and STA must act as Enrollee wifi_wps_connection_by_pin This function trigger...

Page 36: ... manufacturer else LOG_E minisupp manufacture length is too long n return 1 Set model_name as manufacturer Set model_number as manufacturer Set serial_number as manufacturer return wifi_wps_config_set_device_info input_devinfo 2 Call the function wifi_wps_config_get_device_info to retrieve the device information once it s already set An example implementation shows how to get device information wi...

Page 37: ...redential_event_handler_example An example implementation for the event handler wifi_wps_credential_event_handler_example is shown below int32_t int32_t wifi_wps_credential_event_handler_example wifi_event_t event uint8_t payload uint32_t length wifi_wps_credential_information_t customer_cred payload if event WIFI_EVENT_IOT_WPS_COMPLETE LOG_I minisupp WPS ssid s n customer_cred ssid LOG_I minisupp...

Page 38: ... is ignored when the function wps_ap_pbc_example is called An example implementation is shown below After the AP calls this API the Enrollee such as a smart phone also needs to push the WPS virtual button to trigger the Enrollee process During 120 seconds the Enrollee will connect with the AP and get an IP or prompt fail 2 STA as an Enrollee When the device is in station mode define the port direc...

Page 39: ...P s Registrar process During 120 seconds based on the official WPS specification the Enrollee will connect with the AP and get an IP or prompt fail An example implementation is shown below 2 AP as an Enrollee When the device is AP as an Enrollee the process is passive and there is no command or API to control it The process will be auto triggered by a Registrar AP needs to give its PIN code to the...

Page 40: ... on the PIN stays the same for each API call An example implementation is shown below 2 STA gets the PIN code When the device is in STA assign the parameter WIFI_PORT_STA to the port parameter of this API The STA s PIN code is randomly generated An example implementation is shown below return wifi_wps_connection_by_pin WIFI_PORT_STA bssid pin int32_t wps_sta_pin_example uint8_t bssid 00 11 22 33 4...

Reviews: