Scope:

This Blog Post provides a guide on configuring the virtual AP interface as a STA interface in an existing WICED SDK framework.

 

Disclaimer:

Consider this document as a guide line and this feature hasn’t been tested extensively via any testing process. The examples attached have been tried on the 43907 and the 54907 platform and the application works.

 

Introduction:

Any Cypress WLAN chip can be operated as a STA (client), an AP (softAP), an ethernet interface or a P2P interface based on what is supported in that chip. Now, the STA, AP and P2P are nothing but virtual interfaces which the software creates. Most of our WLAN chips have the capability of operating these interfaces simultaneously. Most common is the operation of the WICED_STA_INTERFACE and the WICED_AP_INTERFACE. An example of this implementation can be found at /43xxx_Wi-Fi/apps/snip/apsta. Now instead of using one of the virtual interfaces as an AP, both the interfaces can be configured to be used as clients as discussed below.

 

Use Case:

As an example, this can be used say for example when a TCP and a UDP clients are needed to run simultaneously on a WLAN chip whereas the servers are running on two different networks.

 

Implementation:

The credentials for the second STA need to be defined in the respective wifi_config_dct.h file as below.

#define CLIENT_AP_2_SSID       "SSID_FOR_STA2"

#define CLIENT_AP_2_PASSPHRASE "PSK_FOR_STA2"

#define CLIENT_AP_2_SECURITY   WICED_SECURITY_WPA2_AES_PSK

#define CLIENT_AP_2_BSS_TYPE   WICED_BSS_TYPE_INFRASTRUCTURE

#define CLIENT_AP_2_CHANNEL    1

#define CLIENT_AP_2_BAND WICED_802_11_BAND_2_4GHZ

 

The WICED_AP_INTERFACE can be defined to function as a STA by un-commenting //#define WICED_USE_WIFI_TWO_STA_INTERFACE in wiced_defaults.h at /43xxx_Wi-Fi/include/

Once this is done, there are two ways of realizing the second STA.

 

The Easy Way:

Once the WICED_USE_WIFI_TWO_STA_INTERFACE is defined, all that needs to be done is connect the two clients from the application is as below.

wiced_network_up(WICED_STA_INTERFACE, wiced_network_config_t config, const wiced_ip_setting_t* ip_settings);

wiced_network_up(WICED_AP_INTERFACE, wiced_network_config_t config, const wiced_ip_setting_t* ip_settings);

 

The disadvantage of this is, if you go back to using the device in a single STA mode, the functionality of the application needs to be monitored to ensure that the device doesn’t throw errors during run time as these types of errors won’t be detected easily during compile time.

 

The Clean Way:

Here what can be done is the WICED_AP_INTERFACE can be defined as WICED_STA_2_INTERFACE as this would be much more comprehensible. There’s a small work around that needs to be done when doing this as WICED_AP_INTERFACE is intertwined in many places and this needs to be dealt with.

The changes to be done are as below

 

Change the wiced_interface_t enumeration in wiced_constants.h (/43xxx_Wi-Fi/include/) as

typedef enum

{

#ifndef WICED_USE_WIFI_TWO_STA_INTERFACE

    WICED_STA_INTERFACE      = WWD_STA_INTERFACE,         /**< STA or Client Interface  */

    WICED_AP_INTERFACE       = WWD_AP_INTERFACE,          /**< softAP Interface         */

    WICED_P2P_INTERFACE      = WWD_P2P_INTERFACE,         /**< P2P Interface            */

    WICED_ETHERNET_INTERFACE = WWD_ETHERNET_INTERFACE,     /**< Ethernet Interface      */

    WICED_INTERFACE_MAX,            /** DO NOT USE - MUST BE AFTER ALL NORMAL INTERFACES - used for counting interfaces */

    WICED_CONFIG_INTERFACE   = WICED_AP_INTERFACE | (1 << 7), /**< config softAP Interface  */

#else

    WICED_STA_INTERFACE      = WWD_STA_INTERFACE,        /**< STA or Client Interface  */

    WICED_STA_2_INTERFACE    = WWD_STA_2_INTERFACE,      /**< second STA Interface     */

    WICED_P2P_INTERFACE      = WWD_P2P_INTERFACE,        /**< P2P Interface            */

    WICED_ETHERNET_INTERFACE = WWD_ETHERNET_INTERFACE,   /**< Ethernet Interface    */

    WICED_INTERFACE_MAX,

    WICED_CONFIG_INTERFACE   = WWD_STA_2_INTERFACE | (1 << 7),

#endif

 

} wiced_interface_t;

 

Change the wwd_interface_t enumeration in wwd_constants.h (/43xxx_Wi-Fi/WICED/WWD/include/) as

typedef enum

{

#ifndef WICED_USE_WIFI_TWO_STA_INTERFACE

    WWD_STA_INTERFACE          = 0,        /**< STA or Client Interface*/

    WWD_AP_INTERFACE           = 1,        /**< softAP Interface*/

    WWD_P2P_INTERFACE          = 2,        /**< P2P Interface*/

    WWD_ETHERNET_INTERFACE     = 3,        /**< Ethernet Interface*/

 

    WWD_INTERFACE_MAX,          /** DO NOT USE - MUST BE LAST INTERFACE VALUE - used for counting interfaces */

    WWD_INTERFACE_FORCE_32_BIT = 0x7fffffff /**< Exists only to force wwd_interface_t type to 32 bits                    */

#else

WWD_STA_INTERFACE          = 0,         /**< STA or Client Interface*/

WWD_STA_2_INTERFACE        = 1,         /**< second STA Interface*/

WWD_AP_INTERFACE = WWD_STA_2_INTERFACE,

WWD_P2P_INTERFACE          = 2,         /**< P2P Interface*/

WWD_ETHERNET_INTERFACE     = 3,         /**< Ethernet Interface*/

WWD_INTERFACE_MAX,           /** DO NOT USE - MUST BE LAST INTERFACE VALUE - used for counting interfaces */

WWD_INTERFACE_FORCE_32_BIT = 0x7fffffff /**< Exists only to force wwd_interface_t type to 32 bits                    */

#endif

} wwd_interface_t;

And add the line #include "../../../include/wiced_defaults.h"

 

Add the following definition

#ifdef WICED_USE_WIFI_TWO_STA_INTERFACE

#define WICED_AP_INTERFACE WICED_STA_2_INTERFACE

#endif

in the files ,wifi.c (/43xxx_Wi-Fi/WICED/internal/), wiced_network_common.c(/43xxx_Wi-Fi/WICED/network/) ,wiced_network.c(/43xxx_Wi-Fi/WICED/network/NetX_Duo/WICED) [This will be depend on the network stack being used] and

command_console_wifi.c(/43xxx_Wi-Fi/libraries/utilities/command_console/wifi/)

 

Add the below lines in wwd_ap_common.c(/43xxx_Wi-Fi/WICED/WWD/internal/)

#ifdef WICED_USE_WIFI_TWO_STA_INTERFACE    

#define WWD_AP_INTERFACE WWD_STA_2_INTERFACE

 

#endif

 

Once the changes are done, upload the application on to your board, run the tcp_echo_server_py3.py and the udp_echo_server_py3.py on the respective networks and you should get the logs as below.

 

Known Issues:
  • There are some issues of the second STA not acquiring the DHCP address sometimes. At such a time, reset the board and try again and it should go through. Else try assigning a static IP and using it.
  • The board may keep on resetting after joining the 2nd STA network when using FreeRTOS-LwIP combination. If this is encountered, please use the NetX or the NetX_Duo as the network stack