Winc Modes of Operation:
The Winc1500 can function in the following modes.
- Idle Mode
- Station (STA) Mode
- Access Point (AP) Mode
- Peer to Peer (P2P) Mode
- Monitoring mode (Sniffer mode)
The Winc1500 will enter this mode once the Winc1500 is initialized (when the m2m_wifi_init function is called). In this mode, the Winc's IEEE 802.11 radio and Cortus CPU are disabled. In addition, any unused peripherals will also be disabled. The Winc1500 will still accept commands from the host microcontroller in this mode.
In this mode, the Winc1500 is capable of scanning for and connecting to access points.
Scanning - A user can start a scan by calling the m2m_wifi_request_scan API.
It is possible to adjust how long the Winc1500 scans each Wi-Fi channel before it switches to the next channel. The longer the device spends on each channel, the more likely it is to detect an AP. However, increasing this wait time also causes the Winc1500 to consume more power. The user can adjust the wait time by calling the m2m_wifi_set_scan_options API. The user is able to change which channels the Winc scans by using the m2m_wifi_set_scan_region API.
Connecting - The Winc1500 is capable of connecting to an AP using two different methods which are listed below.
- m2m_wifi_connect API - Calling this function will start a Wi-Fi connection. In order to use this function, the application needs to know the connection parameters for the AP, which also serve as the parameters for the m2m_wifi_connect function.
The m2m_wifi_connect API has the following form: m2m_wifi_connect(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch). The parameters are listed below:
- pcSsid - Buffer holding the AP's SSID
- u8SsidLen - Length of SSID. Note: This does not include the null terminator.
- u8SecType - AP Security type. The Winc1500 is capable of connecting to AP's using OPEN, WEP, WPA/WPA2 and WPA enterprise security.
- pvAuthInfo - Authorization parameters (i.e password) needed to complete the connection. These vary with the security type being used.
- u16Ch - Wifi channel used to make the connection. Since the Winc1500 currently only operates in the 2.4 Ghz band, this parameter can vary from 1 to 14. The user can use the value M2M_WIFI_CH_ALL(255) to instruct the Winc to scan each channel until if finds and connects to the specified SSID.
- m2m_wifi_defualt_connect API - Calling this function will start a Wi-Fi connection with an AP whose profile is cached in serial flash. In order to create a cached profile, the Winc must first successfully connect with the AP using the m2m_wifi_connect API. This method is useful if your application requires the Winc to quickly reconnect to an AP after it exits sleep mode since the m2m_wifi_defualt_connect will create a connection faster than m2m_wifi_connect will. Another method of using this API is to have the AP's profile provisioned in flash beforehand via HTTP provisioning. Atmel provides a very good of example of how to do this in the Winc1500 Software Design Guide which can be found under the "Useful links" section of this article.
When using the m2m_wifi_connect and m2m_wifi_defualt_connect API's , it is important to remember that these functions completing successfully does not guarantee that a Wi-Fi connection will be established. These functions will only return errors when problems occur on the Winc1500's end of the connection.
Disconnecting - To disconnect from an AP, simply call the m2m_wifi_disconnect function. This will return the Winc to the Idle mode.
The Winc1500 is capable of operating as an AP. While using the Winc1500 in AP mode, it is important to remember the following:
- The Winc can only be connected to one station while operating as an AP
- OPEN and WEP security are supported
- STA/AP concurrence is not supported.
The Winc1500 can be put into AP mode by using the m2m_wifi_enable_ap function.
Configuring AP Parameters
The m2m_wifi_enable_ap function has a single parameter, the tstrM2MAPConfig structure. This structure contains all the configuration parameters for the AP.
The AP parameters are as follows:
- au8SSID - SSID for the AP
- u8ListenChannel - RF channel that the AP will operate on
- u8KeyIndx - WEP key index
- u8KeySz - WEP key size
- au8WepKey - WEP key size
- u8SecType - AP security type, either WEP or OPEN
- u8SsidHide - Determines whether of not the SSID is visible to stations or not
- au8DHCPServerIP - Server IP address for the AP
- __PAD24__ - Padding bytes used for aligning the Wi-Fi frames
It is not always necessary to configure each parameter of the structure. For example, there is no need to set the WEP parameters if your AP will be using the OPEN security type. The code block below shows the minimum amount of configuration needed to configure the Winc for AP mode with OPEN security.
/*Initialze AP parameters*/
tstrM2MAPConfig strM2MAPConfig; // Create AP parameter structure
strcpy((char *)&strM2MAPConfig.au8SSID, "Demo AP"); // Set SSID
strM2MAPConfig.u8ListenChannel = 6; // Set Wi-FI Channel to operate on
strM2MAPConfig.u8SecType = M2M_WIFI_SEC_OPEN; // Set Wifi Security mode
/* Enable AP mode */
Also known as Wi-Fi Direct, this mode allows two Wi-Fi enabled devices to communicate with each other without the use of a dedicated access point. This process begins with a Wi-Fi Direct device scanning for other Wi-Fi Direct devices. When another device is discovered, the devices will negotiate which device will function as the Group Owner (GO). The GO functions very similar to an AP. Once the GO is established, the other devices in the P2P group, (known as Clients), are able to connect to the GO in the same manner that STA's connect to AP's. It is important to note, that the role of GO cannot be transferred to one of the Clients in the group. If the GO leaves the P2P group, the group is destroyed and must be reformed in order for the devices to continue to communicate.
The Winc1500 is capable of operating in Wi-Fi P2P mode as a Client only. The Winc will enter P2P mode when the m2m_wifi_p2p function is called. It will then enter a "Listen State" where it will wait for another Wi-Fi P2P device to initiate a connection. When negotiation occurs, the device which initiates the connection needs to assume the GO role. Once the P2P group is formed, the Winc1500 can connect to the GO as if it were an AP by using the m2m_wifi_connect function. The diagram below illustrates this process.
Winc1500 P2P State Diagram: Image courtesy of Amtel's ATWINC1500 Software Design Guide
Note: There is a minor error in this diagram, the state on the left should read "Idle mode" instead of "Station mode"
In this mode, the Winc1500 will receive all packets on a selected wireless channel. The user is able to configure filters so that only specific types of packets are passed to the application. To enter the P2P mode from the Idle mode, call the function m2m_wifi_enable_monitoring_mode. This function has the form m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtril *pstrMtrCtrl, uint8 *pu8PayloadBuffer, uint16 BufferSize, uint16 u16DataOffset). It's parameters are as follows:
- pstrMtrCtrl - Structure that specifies what type of frames need to be captured.
- pu8PayloadBuffer - Buffer used to store incoming packet
- BufferSize -Size of incoming packet
- u16DataOffset - Data offset
In addition to receiving packets in this mode, the Winc can also send raw Wi-Fi frames over the air. The user's application is responsible for creating and formatting the packets, the Winc will transmit the packets without modifying them. Packets can be transmitted by using the function m2m_wifi_send_wlan_pkt which has the form m2m_wifi_send_wlan_pkt( uint8 *pu8WlanPacket, uint16 u16WlanHeaderLength, uint16 u16WlanPktSize). The parameters are as follows.:
- pu8WlanPacket - Buffer used to store the outgoing packet.
- u16WlanHeaderLength - Packet header length
- u16WlanPktSize - Size of the outgoing packet
Changing from one mode to another:
After the host MCU intitalizes the via the m2m_wifi_init API, the Winc will enter the Idle mode. To enter another mode from the idle mode, the host MCU needs to call that mode's respective connect/enable API. To enter another mode from a non-Idle mode, the host MCU must call that mode's disconnect/disable API. The disconnect/disable API will force the Winc back into the Idle mode. Once the Winc is in the Idle mode, the host MCU can then call the new mode's connect/enable API and enter that mode. The Winc cannot go from one non-Idle mode to another without first entering the Idle mode. In addition, it is also necessary to close all TCP and UDP sockets before the WINC1500 switches modes. The diagram below illustrates the mode change process.
Winc Modes of Operation: Image courtesy of Amtel's ATWINC1500 Software Design Guide