2 \defgroup wifi_interface_gr WiFi Interface
3 \brief Driver API for WiFi (%Driver_WiFi.h)
6 Wi-Fi is technology for radio wireless local area networking of devices. Wi-Fi compatible devices typically
7 connect to the Internet via a WLAN and a wireless access point (AP) also called hotspot.
9 Wikipedia offers more information about
10 the <a href="http://en.wikipedia.org/wiki/Ethernet" target="_blank"><b>WiFi</b></a>.
12 <b>Driver Block Diagram</b>
14 \image html WiFi.png "Block Diagram of the WiFi interface"
18 The following header files define the Application Programming Interface (API) for the WiFi interface:
19 - \b %Driver_WiFi.h : Driver API for WiFi
21 The CMSIS-Driver WiFi provides access to the following interfaces:
23 - \ref wifi_control_gr "Control interface": setup and control the WiFi module.
24 - \ref wifi_management_gr "Management interface": allows you to configure and manage the connection
25 to the WiFi access point (AP) or configure and manage the access point (AP).
26 - \ref wifi_socket_gr "Socket interface": provides the interface to an IP stack that is running
27 on the WiFi module. This IP stack handles data communication.
28 - \ref wifi_bypass_gr "Bypass interface": is an optional interface and enables the transmission of
29 Ethernet frames with the WiFi module. Using this interface requires the IP stack running on the microcontroller.
31 The WiFi interface usually requires CMSIS-RTOS features (i.e. mutex) and is often implemented
32 with a peripheral device that is connected to the system using the SPI or UART interface. However,
33 there are also some microcontroller devices with WiFi interface on the chip.
35 The implementation of the WiFi CMSIS-Driver is therefore generally provided as a separate software pack.
36 It is often implemented as wrapper to the SDK (Software Development Kit) of the WiFi chipset.
39 <b>Driver Functions</b>
41 The driver functions are published in the access struct as explained in \ref DriverFunctions
42 - \ref ARM_DRIVER_WIFI : access struct for WiFi driver functions
51 \struct ARM_DRIVER_WIFI
53 The functions of the WiFi driver are accessed by function pointers exposed by this structure.
54 Refer to \ref DriverFunctions for overview information.
56 Each instance of a WiFi interface provides such an access structure.
57 The instance is identified by a postfix number in the symbol name of the access structure, for example:
58 - \b Driver_WiFi0 is the name of the access struct of the first instance (no. \token{0}).
59 - \b Driver_WiFi1 is the name of the access struct of the second instance (no. \token{1}).
61 A middleware configuration setting allows connecting the middleware to a specific driver instance \b %Driver_WiFi<i>n</i>.
62 The default is \token{0}, which connects a middleware to the first instance of a driver.
63 *******************************************************************************************************************/
67 \defgroup wifi_control_gr WiFi Control
68 \ingroup wifi_interface_gr
69 \brief Control functions for the WiFi module
71 The \ref wifi_control_gr functions setup and control the WiFi module.
76 \struct ARM_WIFI_CAPABILITIES
78 A WiFi driver can be implemented with different capabilities.
79 The data fields of this structure encode the capabilities implemented by this driver.
82 - \ref ARM_WIFI_GetCapabilities
83 *******************************************************************************************************************/
86 \typedef ARM_WIFI_SignalEvent_t
88 Provides the typedef for the callback function \ref ARM_WIFI_SignalEvent.
91 - \ref ARM_WIFI_Initialize
92 *******************************************************************************************************************/
95 \defgroup wifi_event WiFi Events
96 \ingroup wifi_control_gr
97 \brief The WiFi driver generates call back events that are notified via the function \ref ARM_WIFI_SignalEvent.
98 \details The following call back notification events are generated:
100 \def ARM_WIFI_EVENT_AP_CONNECT
101 \def ARM_WIFI_EVENT_AP_DISCONNECT
102 \def ARM_WIFI_EVENT_ETH_RX_FRAME
106 ARM_DRIVER_VERSION ARM_WIFI_GetVersion (void) {
110 \fn ARM_DRIVER_VERSION ARM_WIFI_GetVersion (void)
112 The function \b ARM_WIFI_GetVersion returns version information of the driver implementation in \ref ARM_DRIVER_VERSION.
114 API version is the version of the CMSIS-Driver specification used to implement this driver.
115 Driver version is source code version of the actual driver implementation.
119 extern ARM_DRIVER_WIFI Driver_WiFi0;
120 static ARM_DRIVER_WIFI *wifi;
122 void get_wifi_version (void) {
123 ARM_DRIVER_VERSION version;
126 version = wifi->GetVersion ();
127 if (version.api < 0x100U) { // requires at minimum API version 1.0 or higher
135 ARM_WIFI_CAPABILITIES ARM_WIFI_GetCapabilities (void) {
139 \fn ARM_WIFI_CAPABILITIES ARM_WIFI_GetCapabilities (void)
141 The function \b ARM_WIFI_GetCapabilities retrieves information about capabilities in this driver implementation.
142 The data fields of the struct \ref ARM_WIFI_CAPABILITIES encode various capabilities, for example
143 if a WiFi module supports the Access Point mode or the bypass mode, or is capable to signal events using
144 the \ref ARM_WIFI_SignalEvent callback function.
148 extern ARM_DRIVER_WIFI Driver_WiFi0;
149 static ARM_DRIVER_WIFI *wifi;
151 void get_wifi_capabilities (void) {
152 ARM_WIFI_CAPABILITIES capabilities;
154 wifi = &Driver_WiFi0;
155 capabilities = wifi->GetCapabilities ();
156 // interrogate capabilities
162 int32_t ARM_WIFI_Initialize (ARM_WIFI_SignalEvent_t cb_event) {
163 return ARM_DRIVER_OK;
166 \fn int32_t ARM_WIFI_Initialize (ARM_WIFI_SignalEvent_t cb_event)
168 The function \b ARM_WIFI_Initialize initializes the WiFi module.
170 It is called when the middleware component starts operation.
172 The \ref ARM_WIFI_Initialize function performs the following operations:
173 - Initializes the resources and peripherals required for the WiFi module.
174 - Registers the \ref ARM_WIFI_SignalEvent callback function.
176 The parameter \em cb_event is a pointer to the \ref ARM_WIFI_SignalEvent callback function;
177 use a \token{NULL} pointer when no callback signals are required.
181 extern ARM_DRIVER_WIFI Driver_WiFi0;
182 static ARM_DRIVER_WIFI *wifi;
183 static ARM_ETH_MAC_ADDR own_mac_address;
185 void initialize_wifi (void) {
186 wifi = &Driver_WiFi0;
188 // Initialize and Power-on WiFi Module
189 wifi->Initialize (NULL);
190 wifi->PowerControl (ARM_POWER_FULL);
192 // Populate own_mac_address with the address to use
193 wifi->SetOption(ARM_WIFI_MAC, &own_mac_address, 6U);
198 int32_t ARM_WIFI_Uninitialize (void) {
199 return ARM_DRIVER_OK;
202 \fn int32_t ARM_WIFI_Uninitialize (void)
204 The function \b ARM_WIFI_Uninitialize de-initializes the resources of the WiFi module.
206 It is called when the middleware component stops operation and releases the software resources
211 extern ARM_DRIVER_WIFI Driver_WiFi0;
212 static ARM_DRIVER_WIFI *wifi;
214 void uninitialize_wifi (void) {
215 wifi = &Driver_WiFi0;
217 // Power off and De-initialize WiFi Module
218 wifi->PowerControl (ARM_POWER_OFF);
219 wifi->Uninitialize ();
224 int32_t ARM_WIFI_PowerControl (ARM_POWER_STATE state) {
225 return ARM_DRIVER_OK;
228 \fn int32_t ARM_WIFI_PowerControl (ARM_POWER_STATE state)
230 The function \b ARM_WIFI_PowerControl allows you to configure the power modes of the WiFi module.
232 The parameter \em state specifies the \ref ARM_POWER_STATE.
234 Low-power mode depends on additional options set by \ref ARM_WIFI_SetOption :
235 - Deep-sleep mode is entered when \ref ARM_WIFI_LP_TIMER option is set to a value different than 0
236 - Sleep mode is entered otherwise
238 \b Deep-sleep mode (only for station):
239 Module turns off the radio and also internal CPU thus reducing power consumption to minimum,
240 only the timer is running that wakes-up the module after specified time.
241 When timer expires the module reconnects to the access point.
243 This mode is used when power consumption is a priority (battery powered devices) and when WiFi
244 is used in short intervals that do not occur very often
245 (example: sending a temperature from a sensor to a cloud every 10 seconds).
247 \b Sleep mode (only for station):
248 Module reduces power consumption by going into sleep and waking up periodically to listen for beacons.
250 Delivery Traffic Indication Message (DTIM) interval can be configured with option \ref ARM_WIFI_DTIM
251 (station and access point) and beacon interval with option \ref ARM_WIFI_BEACON (only for access point).
253 Default module intervals are used when those options are not explicitly set.
255 If power \em state specifies an unsupported mode, the function returns \ref ARM_DRIVER_ERROR_UNSUPPORTED as
256 status information and the previous power state of the peripheral is unchanged. Multiple calls with the same
257 \em state generate no error.
260 - see \ref ARM_WIFI_Initialize
261 - see \ref ARM_WIFI_Uninitialize
264 int32_t ARM_WIFI_GetModuleInfo (char *module_info, uint32_t max_len) {
265 return ARM_DRIVER_OK;
268 \fn int32_t ARM_WIFI_GetModuleInfo (char *module_info, uint32_t max_len)
270 The function \b ARM_WIFI_GetModuleInfo retrieves string containing information about the WiFi module.
272 The information might include module name, firmware version, ...
274 \note Module must be initialized and powered before module information can be retrieved.
278 extern ARM_DRIVER_WIFI Driver_WiFi0;
279 static ARM_DRIVER_WIFI *wifi;
281 void initialize_wifi (void) {
284 wifi = &Driver_WiFi0;
286 // Initialize and Power-on WiFi Module
287 wifi->Initialize (NULL);
288 wifi->PowerControl (ARM_POWER_FULL);
290 // Retrieve module information
291 wifi->GetModuleInfo(&info, sizeof(info));
296 void ARM_WIFI_SignalEvent (uint32_t event, void *arg) {
299 \fn void ARM_WIFI_SignalEvent (uint32_t event, void *arg)
301 The function \b ARM_WIFI_SignalEvent is a callback function registered by the function \ref ARM_WIFI_Initialize.
302 It is called by the WiFi driver to notify the application about WiFi Events occurred during operation.
304 The parameter \em event indicates the event that occurred during driver operation.
306 The parameter \em arg provides additional information about the event.
308 The following events can be generated:
310 Parameter \em event | Description
311 :------------------------------------|:------------------------------------------
312 \ref ARM_WIFI_EVENT_AP_CONNECT | Occurs in access point mode when a station has connected to the access point.
313 \ref ARM_WIFI_EVENT_AP_DISCONNECT | Occurs in access point mode when a station has disconnected from the access point.
314 \ref ARM_WIFI_EVENT_ETH_RX_FRAME | Occurs in \ref wifi_bypass_gr when an ethernet frame is received.
320 // end group wifi_control_gr
324 \defgroup wifi_management_gr WiFi Management
325 \ingroup wifi_interface_gr
326 \brief Configure and manage the connection to a WiFi access point (AP) or configure and manage the access point (AP).
327 \details The \ref wifi_management_gr functions are used to configure and manage the connection to a WiFi access point (AP)
328 also called hotspot when in station mode. They are also used to configure and manage the access point (AP) itself
329 when in access point mode.
334 \defgroup WiFi_option WiFi Option Codes
335 \ingroup wifi_management_gr
336 \brief WiFi Option Codes for \ref ARM_WIFI_SetOption or \ref ARM_WIFI_GetOption function.
338 Many parameters of the WiFi module are configured using the \ref ARM_WIFI_SetOption or \ref ARM_WIFI_GetOption function.
341 \details Specifies the BSSID of the access point to connect or the access point itself.
343 \def ARM_WIFI_TX_POWER
344 \details Specifies the transmit power in dBm.
346 \def ARM_WIFI_LP_TIMER
347 \details Specifies the low-power deep-sleep time in seconds for station (disabled when 0 - default).
350 \details Specifies the DTIM interval in number of beacons.
353 \details Specifies the beacon interval in milliseconds for access point.
356 \details Specifies the MAC address.
359 \details Specifies the IP address.
361 \def ARM_WIFI_IP_SUBNET_MASK
362 \details Specifies the subnet mask.
364 \def ARM_WIFI_IP_GATEWAY
365 \details Specifies the gateway IP address.
367 \def ARM_WIFI_IP_DNS1
368 \details Specifies the IP address of the primary DNS server.
370 \def ARM_WIFI_IP_DNS2
371 \details Specifies the IP address of the secondary DNS server.
373 \def ARM_WIFI_IP_DHCP
374 \details Enables or disables the DHCP client for station or DHCP server for access point.
376 \def ARM_WIFI_IP_DHCP_POOL_BEGIN
377 \details Specifies the start IP address for DHCP server (access point).
379 \def ARM_WIFI_IP_DHCP_POOL_END
380 \details Specifies the end IP address for DHCP server (access point).
382 \def ARM_WIFI_IP_DHCP_LEASE_TIME
383 \details Specifies the lease time for DHCP server (access point).
385 \def ARM_WIFI_IP6_GLOBAL
386 \details Specifies the global IPv6 address.
388 \def ARM_WIFI_IP6_LINK_LOCAL
389 \details Specifies the link-local IPv6 address.
391 \def ARM_WIFI_IP6_SUBNET_PREFIX_LEN
392 \details Specifies the address prefix length.
394 \def ARM_WIFI_IP6_GATEWAY
395 \details Specifies the gateway IPv6 address.
397 \def ARM_WIFI_IP6_DNS1
398 \details Specifies the IPv6 address of the primary DNS server.
400 \def ARM_WIFI_IP6_DNS2
401 \details Specifies the IPv6 address of the secondary DNS server.
403 \def ARM_WIFI_IP6_DHCP_MODE
404 \details Specifies the operation mode of the DHCPv6 client.
410 \defgroup wifi_sec_type WiFi Security Type
411 \ingroup wifi_management_gr
412 \brief Specifies WiFi security type for \ref ARM_WIFI_Activate.
414 The WiFi security type defines the standard used to protect the wireless network from unauthorized access.
416 \def ARM_WIFI_SECURITY_OPEN
417 \details This is an open system which provides \b no security.
419 \def ARM_WIFI_SECURITY_WEP
420 \details This security standard provides \b weak level of security.
422 \def ARM_WIFI_SECURITY_WPA
423 \details This security standard provides \b medium level of security.
425 \def ARM_WIFI_SECURITY_WPA2
426 \details This security standard provides \b strong level of security.
428 \def ARM_WIFI_SECURITY_UNKNOWN
429 \details Unknown security standard (reported by \ref ARM_WIFI_Scan).
435 \defgroup wifi_wps_method WiFi Protected Setup (WPS) Method
436 \ingroup wifi_management_gr
437 \brief Specifies WiFi WPS method for \ref ARM_WIFI_Activate.
439 The WiFi WPS method defines which WPS method is used.
441 \def ARM_WIFI_WPS_METHOD_NONE
442 \details WPS not used.
444 \def ARM_WIFI_WPS_METHOD_PBC
445 \details WPS with Push Button Configuration.
447 \def ARM_WIFI_WPS_METHOD_PIN
448 \details WPS with PIN.
454 \defgroup wifi_dhcp_v6_mode WiFi DHCPv6 Mode
455 \ingroup wifi_management_gr
456 \brief Specifies IPv6 Dynamic Host Configuration Protocol (DHCP) Mode.
458 The WiFi DHCPv6 mode defines the DHCP mode in IPv6.
460 \def ARM_WIFI_IP6_DHCP_OFF
462 In the static host configuration mode, the IPv6 address, the default gateway address,
463 and the addresses of DNS servers are statically configured from the preset values.
464 \sa wifi_dhcp_v6_mode
465 \def ARM_WIFI_IP6_DHCP_STATELESS
467 In the stateless DHCP configuration mode, the client obtains only extended information
468 from a DHCPv6 server, such as DNS server addresses. Stateless auto-configuration of
469 IPv6 allows the client device to self configure it's IPv6 addresses and routing based
470 on the router advertisements.
471 \sa wifi_dhcp_v6_mode
472 \def ARM_WIFI_IP6_DHCP_STATEFULL
474 In the stateful DHCP configuration mode, the client connects to a DHCPv6 server for
475 a leased IPv6 address and DNS server addresses.
476 \sa wifi_dhcp_v6_mode
481 \struct ARM_WIFI_CONFIG_t
483 Provides information needed to connect to the WiFi network for station or how to configure the access point (AP).
486 - \ref ARM_WIFI_Activate
487 *******************************************************************************************************************/
490 \struct ARM_WIFI_SCAN_INFO_t
492 Provides information about the wireless networks that were detected when searching for available WiFi networks. The structure
493 contains the information needed to connect to the WiFi network. Of course, the access password is not included and must
494 be provided separately.
498 *******************************************************************************************************************/
501 \struct ARM_WIFI_NET_INFO_t
503 Provides information about the network that the station is connected to.
506 - \ref ARM_WIFI_GetNetInfo
507 *******************************************************************************************************************/
509 int32_t ARM_WIFI_SetOption (uint32_t interface, uint32_t option, const void *data, uint32_t len) {
510 return ARM_DRIVER_OK;
513 \fn int32_t ARM_WIFI_SetOption (uint32_t interface, uint32_t option, const void *data, uint32_t len)
515 The function \b ARM_WIFI_SetOption sets the value of the specified option of the WiFi module.
517 The argument \em interface specifies the interface (0 = Station, 1 = Access Point).
519 The argument \em option specifies the option that is to be set (see below).
521 The argument \em data points to a buffer containing the value of the option to be set
522 and must be aligned to the data type of the corresponding option.
524 The argument \em len specifies the length of the buffer \em data and must be equal (or higher)
525 to the length of the corresponding option.
527 Option | Description | Data | Type/Length
528 :--------------------------------------|:---------------------------------------|:--------------|:-----------
529 \ref ARM_WIFI_BSSID | BSSID of AP to connect or AP | bssid | uint8_t[6]
530 \ref ARM_WIFI_TX_POWER | Transmit power | power[dbm] | uint32_t
531 \ref ARM_WIFI_LP_TIMER | Low-power deep-sleep time | time[seconds] | uint32_t
532 \ref ARM_WIFI_DTIM | DTIM interval | dtim[beacons] | uint32_t
533 \ref ARM_WIFI_BEACON | Beacon interval | interval[ms] | uint32_t
534 \ref ARM_WIFI_MAC | MAC address | mac | uint8_t[6]
535 \ref ARM_WIFI_IP | IPv4 address | ip | uint8_t[4]
536 \ref ARM_WIFI_IP_SUBNET_MASK | IPv4 subnet mask | mask | uint8_t[4]
537 \ref ARM_WIFI_IP_GATEWAY | IPv4 gateway address | ip | uint8_t[4]
538 \ref ARM_WIFI_IP_DNS1 | IPv4 primary DNS server address | ip | uint8_t[4]
539 \ref ARM_WIFI_IP_DNS2 | IPv4 secondary DNS server address | ip | uint8_t[4]
540 \ref ARM_WIFI_IP_DHCP | IPv4 DHCP client/server enable/disable | dhcp (0, 1) | uint32_t
541 \ref ARM_WIFI_IP_DHCP_POOL_BEGIN | IPv4 DHCP server begin address | ip | uint8_t[4]
542 \ref ARM_WIFI_IP_DHCP_POOL_END | IPv4 DHCP server end address | ip | uint8_t[4]
543 \ref ARM_WIFI_IP_DHCP_LEASE_TIME | IPv4 DHCP server lease time | time[seconds] | uint32_t
544 \ref ARM_WIFI_IP6_GLOBAL | IPv6 global address | ip6 | uint8_t[16]
545 \ref ARM_WIFI_IP6_LINK_LOCAL | IPv6 link-local address | ip6 | uint8_t[16]
546 \ref ARM_WIFI_IP6_SUBNET_PREFIX_LEN | IPv6 subnet prefix length | len (1..127) | uint32_t
547 \ref ARM_WIFI_IP6_GATEWAY | IPv6 gateway address | ip6 | uint8_t[16]
548 \ref ARM_WIFI_IP6_DNS1 | IPv6 primary DNS server address | ip6 | uint8_t[16]
549 \ref ARM_WIFI_IP6_DNS2 | IPv6 secondary DNS server address | ip6 | uint8_t[16]
550 \ref ARM_WIFI_IP6_DHCP_MODE | IPv6 DHCP client mode | mode | uint32_t
561 // Set IP static address of the Station
562 wifi->SetOption (0U, ARM_WIFI_IP, &ip, sizeof(ip));
566 int32_t ARM_WIFI_GetOption (uint32_t interface, uint32_t option, void *data, uint32_t *len) {
567 return ARM_DRIVER_OK;
570 \fn int32_t ARM_WIFI_GetOption (uint32_t interface, uint32_t option, void *data, uint32_t *len)
572 The function \b ARM_WIFI_GetOption retrieves the current value of the specified option of
575 The argument \em interface specifies the interface (0 = Station, 1 = Access Point).
577 The argument \em option specifies the option that is to be retrieved (see \ref ARM_WIFI_SetOption).
579 The argument \em data points to a buffer that will be used to store the value of
580 the \em option and must be aligned to the data type of the corresponding option.
582 The argument \em len is a pointer to the length of the buffer at input and returns the length
583 of the option information on the output.
587 uint8_t ip[4]; // IP address
588 uint8_t mask[4]; // Subnet mask
589 uint8_t gateway[4]; // Gateway address
591 // Get IP address, Subnet mask and Gateway address of the Station
592 wifi->GetOption (0U, ARM_WIFI_IP, &ip, sizeof(ip));
593 wifi->GetOption (0U, ARM_WIFI_IP_SUBNET_MASK, &mask, sizeof(mask));
594 wifi->GetOption (0U, ARM_WIFI_IP_GATEWAY, &gateway, sizeof(gateway));
598 int32_t ARM_WIFI_Scan (ARM_WIFI_SCAN_INFO_t scan_info[], uint32_t max_num) {
599 return ARM_DRIVER_OK;
602 \fn int32_t ARM_WIFI_Scan (ARM_WIFI_SCAN_INFO_t scan_info[], uint32_t max_num)
604 The function \b ARM_WIFI_Scan searches for available WiFi networks. Using this function,
605 you can determine which wireless networks are available for the connection. If the network is
606 secured, you must also know the password to connect.
608 The argument \em scan_info is a pointer to an array of network information structures, where
609 the available network information will be returned.
611 The argument \em max_num specifies maximum number of network information structures,
612 that can be stored to the \em scan_info.
616 ARM_WIFI_SCAN_INFO_t scan_info[8];
618 num = wifi->Scan (scan_info, 8U);
620 // Print SSIDs of available WiFi networks
621 for (i = 0; i < num; i++) {
622 printf ("%d. ssid=%s\n", i, scan_info[i].ssid);
627 int32_t ARM_WIFI_Activate (uint32_t interface, ARM_WIFI_CONFIG_t *config) {
628 return ARM_DRIVER_OK;
631 \fn int32_t ARM_WIFI_Activate (uint32_t interface, ARM_WIFI_CONFIG_t *config)
633 The function \b ARM_WIFI_Activate activates the specified interface.
635 The argument \em interface specifies the interface (0 = Station, 1 = Access Point).
637 When station interface is specified, the WiFi module connects to a wireless network.
639 The wireless network trying to connect to must be available,
640 otherwise the operation will fail after a timeout.
642 Available wireless networks can be scanned by using the function \ref ARM_WIFI_Scan.
644 When access point interface is specified, the WiFi module creates a wireless network
645 by activating the access point.
647 The argument \em config is a pointer to the configuration \ref ARM_WIFI_CONFIG_t
648 which provides information needed to connect to a WiFi network for station interface
649 or information used to configure the access point (AP) for access point interface.
651 \em ssid specifies the name of the network to connect to or the network to create.
653 \em pass specifies the password for accessing the wireless network.
655 \em security specifies the security type which will be used for the connection.
657 \em ch specifies the WiFi channel which will be used for the connection.
658 Valid channels for 2.4 GHz frequency are from \token{1} to \token{13}. If the value for \em ch = \token{0},
659 the system automatically selects the channel.
660 For station interface the channel of the AP being connected to is used.
661 For access point interface the module automatically selects the best channel for the WiFi connection.
664 Optionally BSSID parameter can be also set using \ref ARM_WIFI_SetOption.
665 It allows connection to specific BSSID when connecting to an access point or specifies
666 the BSSID of the access point.
668 \em wps_method specifies if WiFi Protected Setup (WPS) is used and which method.
670 \em wps_pin specifies the PIN used with WPS (\ref ARM_WIFI_WPS_METHOD_PIN).
672 With the \b push-button method, you typically press the button, either real or virtual,
673 both at the access point and the station. No credentials are needed.
675 With \b PIN method, you must provide the PIN code that you read from the label or screen
676 on the wireless device.
678 WPS configuration for station is used when station connects to an access point.
679 It enables to connect without specifying SSID, Password, Security Type or WiFi Channel.
680 The actual network information can be retrieved once connected with \ref ARM_WIFI_GetNetInfo.
682 WPS configuration for access point is used when access point is activated.
683 Subsequent activate calls re-trigger the WPS procedure.
686 WPS is typically activated by pressing the WPS button at the access point.
687 During the discovery mode (usually 2 minutes or less) any wireless device may connect
688 to the access point (PIN needs to match when PIN method is selected).
692 ARM_WIFI_CONFIG_t wifi_config;
694 wifi_config.ssid = "GuestAccess";
695 wifi_config.pass = "guest";
696 wifi_config.security = ARM_WIFI_SECURITY_WPA2;
698 wifi_config.wps_method = ARM_WIFI_WPS_METHOD_NONE;
700 // Connect to wireless network
701 status = wifi->Activate (0U, &wifi_config);
702 if (status != ARM_DRIVER_OK) {
708 int32_t ARM_WIFI_Deactivate (uint32_t interface) {
709 return ARM_DRIVER_OK;
712 \fn int32_t ARM_WIFI_Deactivate (uint32_t interface)
714 The function \b ARM_WIFI_Deactivate deactivates the specified interface.
716 The argument \em interface specifies the interface (0 = Station, 1 = Access Point).
718 When station interface is specified, the WiFi module disconnects from the wireless network.
720 When access point interface is specified, the WiFi module deactivates the access point.
723 - see \ref ARM_WIFI_GetNetInfo
726 uint32_t ARM_WIFI_IsConnected (void) {
730 \fn uint32_t ARM_WIFI_IsConnected (void)
732 The function \b ARM_WIFI_IsConnected checks if the station is connected to a wireless network
733 and returns the connection status.
735 The function returns a \token{non-zero} value, if the station is connected. If the station
736 is not connected, the function returns \token{0}.
739 - see \ref ARM_WIFI_GetNetInfo
742 int32_t ARM_WIFI_GetNetInfo (ARM_WIFI_NET_INFO_t *net_info) {
743 return ARM_DRIVER_OK;
746 \fn int32_t ARM_WIFI_GetNetInfo (ARM_WIFI_NET_INFO_t *net_info)
748 The function \b ARM_WIFI_GetNetInfo retrieves wireless network information of a connected station.
750 It can be used to retrieve network connection information for subsequent connections
751 after initially connecting using WPS.
755 ARM_WIFI_CONFIG_t wifi_config;
756 ARM_WIFI_NET_INFO_t net_info;
758 memset(&wifi_config, 0, sizeof(wifi_config));
760 wifi_config.wps_method = ARM_WIFI_WPS_METHOD_PBC;
762 // Connect to wireless network (WPS)
763 status = wifi->Activate (0U, &wifi_config);
764 if (status != ARM_DRIVER_OK) {
768 // Retrieve network information
769 if (wifi->IsConnected ()) {
770 status = wifi->GetNetInfo (&net_info);
771 if (status != ARM_DRIVER_OK) {
774 printf("SSID=%s, Password=%s",net_info.ssid, net_info.pass);
777 // Disconnect from wireless network
778 wifi->Deactivate (0U);
785 // end group wifi_management_gr
789 \defgroup wifi_bypass_gr WiFi Bypass Mode
790 \ingroup wifi_interface_gr
791 \brief Transfer Ethernet frames by WiFi module.
792 \details The \ref wifi_bypass_gr functions are an optional interface and enable the transmission of
793 Ethernet frames with WiFi modules. The use of this interface requires that the IP stack is running
794 on the microcontroller. The internal IP stack of the WiFi module is therefore not used, and this
795 usually means that the \ref wifi_socket_gr functions can not be used.
799 int32_t ARM_WIFI_BypassControl (uint32_t interface, uint32_t mode) {
800 return ARM_DRIVER_OK;
803 \fn int32_t ARM_WIFI_BypassControl (uint32_t interface, uint32_t mode)
805 The function \b ARM_WIFI_BypassControl enables or disables the WiFi bypass mode.
807 The WiFi Bypass mode can only be enabled, if there is a bypass mode supported in the WiFi driver.
808 You can check this by checking the driver's capabilities.
811 Bypass mode is enabled by default if the module does not support the Socket interface.
813 The argument \em mode specifies the desired state of the WiFi Bypass mode, which is
818 extern ARM_DRIVER_WIFI Driver_WiFi0;
819 static ARM_DRIVER_WIFI *wifi;
820 static ARM_ETH_MAC_ADDR own_mac_address;
822 static void wifi_notify (uint32_t event, ,void *arg) {
828 void initialize_wifi_bypass (void) {
829 ARM_WIFI_CAPABILITIES capabilities;
831 wifi = &Driver_WiFi0;
832 capabilities = wifi->GetCapabilities ();
833 if (capabilities.bypass_mode == 0) {
837 // Initialize and Power-on WiFi Interface
838 wifi->Initialize ((capabilities.eth_rx_frame_event) ? wifi_notify : NULL);
839 wifi->PowerControl (ARM_POWER_FULL);
841 // populate own_mac_address with the address to use for station
842 wifi->SetOption(0U, ARM_WIFI_MAC, &own_mac_address, 6U);
844 wifi->BypassControl (0U, 1U); // Enable bypass mode for station
849 int32_t ARM_WIFI_EthSendFrame (uint32_t interface, const uint8_t *frame, uint32_t len) {
850 return ARM_DRIVER_OK;
853 \fn int32_t ARM_WIFI_EthSendFrame (uint32_t interface, const uint8_t *frame, uint32_t len)
855 The function \b ARM_WIFI_EthSendFrame writes an <b>Ethernet frame</b> to the WiFi transmit buffer.
857 The WiFi bypass mode must be enabled by using the function \ref ARM_WIFI_BypassControl
858 before a call to this function.
860 The frame data addressed by \em frame starts with MAC destination and ends with the last
861 Payload data byte. The frame data is copied into the transmit buffer of the WiFi interface.
863 The maximum value for \em len is implied by the size restrictions of the Ethernet frame
864 but is not verified. Using an invalid value for \em len may generate unpredicted results.
868 status = wifi->EthSendFrame (0U, &frame_data[0], frame_length);
869 if (status != ARM_DRIVER_OK) {
875 int32_t ARM_WIFI_EthReadFrame (uint32_t interface, uint8_t *frame, uint32_t len) {
876 return ARM_DRIVER_OK;
879 \fn int32_t ARM_WIFI_EthReadFrame (uint32_t interface, uint8_t *frame, uint32_t len)
881 The function \b ARM_WIFI_EthReadFrame reads an <b>Ethernet frame</b> from the WiFi interface
884 The \em len of the Ethernet frame can be checked using the function \ref ARM_WIFI_EthGetRxFrameSize.
886 The frame data addressed by \em frame starts with MAC destination and ends with the last
887 Payload data byte. The frame data is read from the receive buffer of the WiFi interface and
888 the number of bytes written into the memory addressed by \em frame is returned.
889 A negative return value indicates an error whereby the status code is defined with
890 driver common return codes.
892 The function \ref ARM_WIFI_EthReadFrame may be called with \em buf = \token{NULL} and \em len = \token{0}
893 to discard or release a frame. This is useful when an incorrect frame has been received or
894 no memory is available to hold the Ethernet frame.
898 size = wifi->EthGetRxFrameSize ();
899 if ((size < 14) || (size > 1514)) { // frame excludes CRC
900 wifi->EthReadFrame (NULL, 0); // Frame error, release it
902 len = wifi->ReadFrame (0U, &frame_data[0], size);
909 uint32_t ARM_WIFI_EthGetRxFrameSize (uint32_t interface) {
913 \fn uint32_t ARM_WIFI_EthGetRxFrameSize (uint32_t interface)
915 The function \b ARM_WIFI_EthGetRxFrameSize returns the size of a received <b>Ethernet frame</b>
916 in the bypass mode. This function can be called before \ref ARM_WIFI_EthReadFrame and retrieves
919 The frame size includes MAC destination and ends with the last Payload data byte.
920 Value \token{0} indicates that no Ethernet frame is available in the receive buffer.
921 Values smaller than minimum size of Ethernet frame or larger than maximum size of Ethernet frame
922 indicate an invalid frame which needs to be discarded by calling \ref ARM_WIFI_EthReadFrame.
925 - see \ref ARM_WIFI_EthReadFrame
930 // end group wifi_bypass_gr
934 \defgroup wifi_socket_gr WiFi Socket
935 \ingroup wifi_interface_gr
936 \brief Socket interface to IP stack running on WiFi module
937 \details The \ref wifi_socket_gr functions provide the interface to an IP stack that is running
938 on the WiFi module. This IP stack handles data communication with the network and provides the user
939 with a communication endpoint called sockets.
944 \defgroup wifi_addr_family WiFi Socket Address Family definitions
945 \ingroup wifi_socket_gr
946 \brief WiFi Socket Address Family definitions.
947 \details The WiFi Socket Address Family specifies the addressing scheme that an instance of the WiFi socket can use.
949 \def ARM_SOCKET_AF_INET
950 \details Internet Address Family version 4.
951 \def ARM_SOCKET_AF_INET6
952 \details Internet Address Family version 6.
957 \defgroup wifi_socket_type WiFi Socket Type definitions
958 \ingroup wifi_socket_gr
959 \brief WiFi Socket Type definitions.
960 \details The WiFi Socket Type specifies the type of the WiFi socket.
962 \def ARM_SOCKET_SOCK_STREAM
963 \details Stream Socket is connection-oriented, sequenced and reliable, implemented on top of the TCP protocol.
964 \def ARM_SOCKET_SOCK_DGRAM
965 \details Datagram Socket is connectionless, unreliable, using the UDP protocol.
970 \defgroup wifi_protocol WiFi Socket Protocol definitions
971 \ingroup WiFi_socket_gr
972 \brief WiFi Socket Protocol definitions.
973 \details The WiFi Socket Protocol specifies the Internet Protocol Type that the socket is using.
975 \def ARM_SOCKET_IPPROTO_TCP
976 \details Transmission Control Protocol.
977 \def ARM_SOCKET_IPPROTO_UDP
978 \details User Datagram Protocol.
983 \defgroup wifi_soc_opt WiFi Socket Option definitions
984 \ingroup WiFi_socket_gr
985 \brief WiFi Socket Option definitions.
986 \details The WiFi Socket Option specifies the socket option for which the value is to be set or obtained.
988 \def ARM_SOCKET_IO_FIONBIO
989 \details Enables or disables the non-blocking mode for the WiFi socket.
991 \def ARM_SOCKET_SO_RCVTIMEO
992 \details Specifies the time limit for receiving in blocking mode. The time limit is in milliseconds.
994 \def ARM_SOCKET_SO_SNDTIMEO
995 \details Specifies the time limit for sending in blocking mode. The time limit is in milliseconds.
997 \def ARM_SOCKET_SO_KEEPALIVE
998 \details Enables or disables the keep-alive mode for the stream socket.
1000 \def ARM_SOCKET_SO_TYPE
1001 \details Obtains the type of the Wifi socket.
1007 \defgroup wifi_soc_func WiFi Socket Function return codes
1008 \ingroup WiFi_socket_gr
1009 \brief WiFi Socket Function return codes.
1010 \details This section lists all the return errors the WiFi socket functions will return.
1011 The error codes are negative. This makes it easy to check an error when the return
1012 code is less than \token{0}.
1014 \def ARM_SOCKET_ERROR
1016 \def ARM_SOCKET_ESOCK
1018 \def ARM_SOCKET_EINVAL
1020 \def ARM_SOCKET_ENOTSUP
1022 \def ARM_SOCKET_ENOMEM
1024 \def ARM_SOCKET_EAGAIN
1026 \def ARM_SOCKET_EINPROGRESS
1028 \def ARM_SOCKET_ETIMEDOUT
1030 \def ARM_SOCKET_EISCONN
1032 \def ARM_SOCKET_ENOTCONN
1034 \def ARM_SOCKET_ECONNREFUSED
1036 \def ARM_SOCKET_ECONNRESET
1038 \def ARM_SOCKET_ECONNABORTED
1040 \def ARM_SOCKET_EALREADY
1042 \def ARM_SOCKET_EADDRINUSE
1044 \def ARM_SOCKET_EHOSTNOTFOUND
1049 int32_t ARM_WIFI_SocketCreate (int32_t af, int32_t type, int32_t protocol) {
1053 \fn int32_t ARM_WIFI_SocketCreate (int32_t af, int32_t type, int32_t protocol)
1055 The function \b ARM_WIFI_SocketCreate creates a communication endpoint called a socket.
1057 The argument \em af specifies the address family. The following values are supported:
1058 Family | Description
1059 :----------------------------|:-------------------------------------------------
1060 \ref ARM_SOCKET_AF_INET | Address Family Internet
1061 \ref ARM_SOCKET_AF_INET6 | Address Family Internet version 6
1063 The argument \em type specifies the communication semantics. The following are the currently supported types:
1065 :----------------------------|:-------------------------------------------------
1066 \ref ARM_SOCKET_SOCK_STREAM | Provides a reliable connection based data stream that is full-duplex
1067 \ref ARM_SOCKET_SOCK_DGRAM | Provides connectionless communication that is unreliable
1069 The argument \em protocol specifies the protocol that must be used with the socket type:
1070 Protocol | Description
1071 :----------------------------|:-------------------------------------------------
1072 \ref ARM_SOCKET_IPPROTO_TCP | Must be used with ARM_SOCKET_SOCK_STREAM socket type
1073 \ref ARM_SOCKET_IPPROTO_UDP | Must be used with ARM_SOCKET_SOCK_DGRAM socket type
1076 - see \ref ARM_WIFI_SocketListen, \ref ARM_WIFI_SocketConnect
1079 int32_t ARM_WIFI_SocketBind (int32_t socket, const uint8_t *ip, uint32_t ip_len, uint16_t port) {
1083 \fn int32_t ARM_WIFI_SocketBind (int32_t socket, const uint8_t *ip, uint32_t ip_len, uint16_t port)
1085 The function \b ARM_WIFI_SocketBind assigns a name to an unnamed socket. The name represents the local address
1086 and port of the communication endpoint.
1088 The argument \em socket specifies a socket identification number returned from a previous call
1089 to \ref ARM_WIFI_SocketCreate.
1091 The argument \em ip is a pointer to the buffer containing the IP address octets of the local IP address.
1093 The argument \em ip_len specifies the length of the local IP address. The length is \token{4} bytes
1094 for the IPv4 address and \token{16} bytes for the IPv6 address.
1096 The argument \em port specifies the local port. If the argument \em port is \token{0}, the function returns error,
1097 because this port is reserved.
1100 - see \ref ARM_WIFI_SocketListen
1103 int32_t ARM_WIFI_SocketListen (int32_t socket, int32_t backlog) {
1107 \fn int32_t ARM_WIFI_SocketListen (int32_t socket, int32_t backlog)
1109 The function \b ARM_WIFI_SocketListen sets the specified socket to listening mode, that is to the
1110 server mode of operation. Before calling the \b ARM_WIFI_SocketListen function, the \ref ARM_WIFI_SocketBind
1111 function must be called.
1113 The argument \em socket specifies a socket identification number returned from a previous call
1114 to \ref ARM_WIFI_SocketCreate.
1116 The argument \em backlog specifies a maximum number of connection requests that can be queued.
1120 extern ARM_DRIVER_WIFI Driver_WiFi0;
1121 static ARM_DRIVER_WIFI *wifi;
1123 void Echo_Server_Thread (void *arg) {
1124 uint8_t ip[4] = { 0U, 0U, 0U, 0U };
1125 int32_t sock, sd, res;
1129 wifi = &Driver_WiFi0;
1130 sock = wifi->SocketCreate (ARM_SOCKET_AF_INET, ARM_SOCKET_SOCK_STREAM, ARM_SOCKET_IPPROTO_TCP);
1132 wifi->SocketBind (sock, (uint8_t *)ip, sizeof(ip), 7U);
1133 wifi->SocketListen (sock, 1);
1134 sd = wifi->SocketAccept (sock, NULL, NULL, NULL);
1135 wifi->SocketClose (sock);
1139 res = wifi->SocketRecv (sock, dbuf, sizeof(dbuf));
1141 break; // Error occurred
1144 wifi->SocketSend (sock, dbuf, res); // Echo the data
1147 wifi->SocketClose (sock);
1153 int32_t ARM_WIFI_SocketAccept (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port) {
1157 \fn int32_t ARM_WIFI_SocketAccept (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port)
1159 The function \b ARM_WIFI_SocketAccept accepts a connection request queued for a listening socket.
1160 If a connection request is pending, \b ARM_WIFI_SocketAccept removes the request from the queue,
1161 and creates a new socket for the connection. The original listening socket remains open and continues
1162 to queue new connection requests. The \em socket must be a socket of type \b ARM_SOCKET_SOCK_STREAM.
1164 In blocking mode, which is enabled by default, this function waits for a connection request. In
1165 non blocking mode, you must call the \b ARM_WIFI_SocketAccept function again if the error code
1166 \c ARM_SOCKET_EAGAIN is returned.
1168 The argument \em socket specifies a socket identification number returned from a previous call
1169 to \ref ARM_WIFI_SocketCreate.
1171 The argument \em ip is a pointer to the buffer that will receive the IP address of the connection node.
1172 If the \em ip is \token{NULL}, the IP address is not returned.
1174 The argument \em ip_len is a pointer to the IP address length. It should initially contain the amount of
1175 space pointed to by \em ip. On return it contains the actual length of the address returned in bytes.
1177 The argument \em port is a pointer to the buffer, that will receive the port number of the connection node.
1178 If the \em port is \token{NULL}, the port number is not returned.
1181 - see \ref ARM_WIFI_SocketListen
1184 int32_t ARM_WIFI_SocketConnect (int32_t socket, const uint8_t *ip, uint32_t ip_len, uint16_t port) {
1188 \fn int32_t ARM_WIFI_SocketConnect (int32_t socket, const uint8_t *ip, uint32_t ip_len, uint16_t port)
1190 The function \b ARM_WIFI_SocketConnect assigns the address of the peer communication endpoint. The function
1191 behaves differently according to the type of socket:
1193 - \b ARM_SOCKET_SOCK_STREAM: A connection is established between the endpoints.
1195 In blocking mode, which is enabled by default, this function waits for a connection to be established.
1197 In non blocking mode, the function returns the error code \c ARM_SOCKET_EINPROGRESS and the connection
1198 is established asynchronously. Subsequent calls to \b ARM_WIFI_SocketConnect for the same socket,
1199 before the connection is established, return the error code \c ARM_SOCKET_EALREADY. When the connection
1200 is established, the call to \b ARM_WIFI_SocketConnect returns the error code \c ARM_SOCKET_EISCONN.
1202 - \b ARM_SOCKET_SOCK_DGRAM: An address filter is established between the endpoints.
1204 The address filter is changed with another \b ARM_WIFI_SocketConnect function call. If the socket
1205 is not yet bound, the system implicitly binds to a random dynamic port.
1207 The argument \em socket specifies a socket identification number returned from a previous call
1208 to \ref ARM_WIFI_SocketCreate.
1210 The argument \em ip is a pointer to the buffer containing the IP address octets of the endpoint node.
1212 The argument \em ip_len specifies the length of the IP address. The length is \token{4} bytes
1213 for the IPv4 address and \token{16} bytes for the IPv6 address.
1215 The argument \em port specifies the port of the endpoint node. If the argument \em port is \token{0},
1216 the function returns error, because this port is reserved.
1220 extern ARM_DRIVER_WIFI Driver_WiFi0;
1221 static ARM_DRIVER_WIFI *wifi;
1223 static const char message[] = { "The quick brown fox jumps over the lazy dog." };
1225 void Echo_Client_Thread (void *arg) {
1226 uint8_t ip[4] = { 192U, 168U, 0U, 100U };
1231 wifi = &Driver_WiFi0;
1232 sock = wifi->SocketCreate (ARM_SOCKET_AF_INET, ARM_SOCKET_SOCK_STREAM, ARM_SOCKET_IPPROTO_TCP);
1234 res = wifi->SocketConnect (sock, (uint8_t *)ip, sizeof(ip), 7U);
1236 wifi->SocketSend (sock, message, sizeof(message));
1237 res = wifi->SocketRecv (sock, dbuf, sizeof(dbuf));
1239 break; // Error occured
1242 if (memcmp (dbuf, message, res) != 0) {
1243 // error handling, message is not the same as sent
1247 wifi->SocketClose (sock);
1254 int32_t ARM_WIFI_SocketRecv (int32_t socket, void *buf, uint32_t len) {
1258 \fn int32_t ARM_WIFI_SocketRecv (int32_t socket, void *buf, uint32_t len)
1260 The function \b ARM_WIFI_SocketRecv receives incoming data that has been queued for the socket.
1261 You can use this function with both, the stream and the datagram socket. It reads as much
1262 information as currently available up to the size of the buffer specified.
1264 In blocking mode, which is enabled by default, this function waits for received data. In non
1265 blocking mode, you must call the \b ARM_WIFI_SocketRecv function again if the error code
1266 \c ARM_SOCKET_EAGAIN is returned.
1268 The argument \em socket specifies a socket identification number returned from a previous call
1269 to \ref ARM_WIFI_SocketCreate.
1271 The argument \em buf is a pointer to the application data buffer for storing the data to.
1272 If the available data is too large to fit in the supplied application buffer \em buf, excess bytes
1273 are discarded in case of a datagram sockets. For stream sockets, the data is buffered internally
1274 so the application can retrieve all data by multiple calls of \b ARM_WIFI_SocketRecv function.
1276 The argument \em len specifies the size of the application data buffer.
1279 - see \ref ARM_WIFI_SocketListen
1282 int32_t ARM_WIFI_SocketRecvFrom (int32_t socket, void *buf, uint32_t len, uint8_t *ip, uint32_t *ip_len, uint16_t *port) {
1286 \fn int32_t ARM_WIFI_SocketRecvFrom (int32_t socket, void *buf, uint32_t len, uint8_t *ip, uint32_t *ip_len, uint16_t *port)
1288 The function \b ARM_WIFI_SocketRecvFrom is used to receive data that has been queued for a socket.
1289 It is normally used to receive messages on datagram sockets, but can also be used to receive a reliable,
1290 ordered stream of data on a connected stream sockets. It reads as much information as currently available
1291 up to the size of the buffer specified.
1293 In blocking mode, which is enabled by default, this function waits for received data. In non
1294 blocking mode, you must call the \b ARM_WIFI_SocketRecv function again if the error code
1295 \c ARM_SOCKET_EAGAIN is returned.
1297 The argument \em socket specifies a socket identification number returned from a previous call
1298 to \ref ARM_WIFI_SocketCreate.
1300 The argument \em buf is a pointer to the application data buffer for storing the data to.
1301 If the available data is too large to fit in the supplied application buffer \em buf, excess bytes
1302 are discarded in case of a datagram sockets. For stream sockets, the data is buffered internally
1303 so the application can retrieve all data by multiple calls of \b ARM_WIFI_SocketRecv function.
1305 The argument \em len specifies the size of the application data buffer.
1307 The argument \em ip is a pointer to the buffer that will receive the IP address of the sender.
1308 If the \em ip is \token{NULL}, the IP address is not returned.
1310 The argument \em ip_len is a pointer to the IP address length. It should initially contain the amount of
1311 space pointed to by \em ip. On return it contains the actual length of the address returned in bytes.
1313 The argument \em port is a pointer to the buffer, that will receive the port number of the sender.
1314 If the \em port is \token{NULL}, the port number is not returned.
1318 extern ARM_DRIVER_WIFI Driver_WiFi0;
1319 static ARM_DRIVER_WIFI *wifi;
1321 void Echo_Server_Thread (void *arg) {
1329 wifi = &Driver_WiFi0;
1330 sock = wifi->SocketCreate (ARM_SOCKET_AF_INET, ARM_SOCKET_SOCK_DGRAM, ARM_SOCKET_IPPROTO_UDP);
1332 ip[0] = 0U; // Unspecified address
1336 port = 7U; // Standard port for Echo service
1338 wifi->SocketBind (sock, (uint8_t *)ip, sizeof(ip), port);
1341 ip_len = sizeof(ip);
1342 res = wifi->SocketRecvFrom (sock, dbuf, sizeof(dbuf), (uint8_t *)ip, &ip_len, &port);
1344 break; // Error occurred
1346 if (res > 0) { // Echo the data
1347 wifi->SocketSendTo (sock, dbuf, res, (uint8_t *)ip, ip_len, port);
1350 wifi->SocketClose (sock);
1356 int32_t ARM_WIFI_SocketSend (int32_t socket, const void *buf, uint32_t len) {
1360 \fn int32_t ARM_WIFI_SocketSend (int32_t socket, const void *buf, uint32_t len)
1362 The function \b ARM_WIFI_SocketSend is used to send data on an already connected socket. This function is
1363 normally used to send a reliable, ordered stream of data bytes on a stream sockets. It can also be used
1364 to send messages on datagram sockets.
1366 The argument \em socket specifies a socket identification number returned from a previous call
1367 to \ref ARM_WIFI_SocketCreate.
1369 The argument \a buf is a pointer to the application data buffer containing data to transmit. The buffer
1370 data length is not limited in size. If the data length is too large for one packet, the \b ARM_WIFI_SocketSend function
1371 will fragment the data and send it in several successive data packets:
1372 - In blocking mode, which is enabled by default, this function returns after the data has been successfully queued for transmission.
1373 - In non blocking mode, the function returns immediately without blocking the system.
1375 The argument \a len specifies the length of data in bytes.
1377 Return value, when positive, represents the number of bytes sent, which can be less than \a len.
1380 - see \ref ARM_WIFI_SocketListen
1383 int32_t ARM_WIFI_SocketSendTo (int32_t socket, const void *buf, uint32_t len, const uint8_t *ip, uint32_t ip_len, uint16_t port) {
1387 \fn int32_t ARM_WIFI_SocketSendTo (int32_t socket, const void *buf, uint32_t len, const uint8_t *ip, uint32_t ip_len, uint16_t port)
1389 The function \b ARM_WIFI_SocketSendTo is used to send data. It is normally used to send messages
1390 on a datagram sockets, but can also be used to send data on a connected stream sockets.
1392 If the datagram socket is not yet bound, the system implicitly binds to a random dynamic port.
1394 The argument \em socket specifies a socket identification number returned from a previous call
1395 to \ref ARM_WIFI_SocketCreate.
1397 The argument \a buf is a pointer to the application data buffer containing data to transmit. The buffer
1398 data length is not limited in size. If the data length is too large for one packet, the \b ARM_WIFI_SocketSend function
1399 will fragment the data and send it in several successive data packets:
1400 - In blocking mode, which is enabled by default, this function returns after the data has been successfully queued for transmission.
1401 - In non blocking mode, the function returns immediately without blocking the system.
1403 The argument \a len specifies the length of data in bytes.
1405 The argument \em ip is a pointer to the buffer containing the IP address octets of the endpoint node.
1407 The argument \em ip_len specifies the length of the IP address. The length is \token{4} bytes
1408 for the IPv4 address and \token{16} bytes for the IPv6 address.
1410 The argument \em port specifies the port of the endpoint node. If the argument \em port is \token{0},
1411 the function returns error, because this port is reserved.
1413 For the stream sockets, arguments \em ip, \em ip_len and \em port are ignored.
1415 Return value, when positive, represents the number of bytes sent, which can be less than \a len.
1418 - see \ref ARM_WIFI_SocketRecvFrom
1421 int32_t ARM_WIFI_SocketGetSockName (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port) {
1425 \fn int32_t ARM_WIFI_SocketGetSockName (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port)
1427 The function \b ARM_WIFI_SocketGetSockName retrieves the local IP address and port for a socket.
1429 The argument \em socket specifies a socket identification number returned from a previous call
1430 to \ref ARM_WIFI_SocketCreate.
1432 The argument \em ip is a pointer to the buffer that will receive the local IP address.
1433 If the \em ip is \token{NULL}, the local IP address is not returned.
1435 The argument \em ip_len is a pointer to the IP address length. It should initially contain the amount of
1436 space pointed to by \em ip. On return it contains the actual length of the address returned in bytes.
1438 The argument \em port is a pointer to the buffer, that will receive the local port number.
1439 If the \em port is \token{NULL}, the local port number is not returned.
1443 static uint8_t local_ip[4]; // Socket address and port
1444 static uint16_t local_port;
1446 static void get_socket_local_info (void) {
1449 ip_len = sizeof(local_ip);
1450 wifi->SocketGetSockName (sock, (uint8_t *)local_ip, &ip_len, &local_port);
1455 int32_t ARM_WIFI_SocketGetPeerName (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port) {
1459 \fn int32_t ARM_WIFI_SocketGetPeerName (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port)
1461 The function \b ARM_WIFI_SocketGetPeerName retrieves the IP address and port of the peer to which
1462 a socket is connected.
1464 The argument \em socket specifies a socket identification number returned from a previous call
1465 to \ref ARM_WIFI_SocketCreate.
1467 The argument \em ip is a pointer to the buffer that will receive the IP address of the peer.
1468 If the \em ip is \token{NULL}, the IP address is not returned.
1470 The argument \em ip_len is a pointer to the IP address length. It should initially contain the amount of
1471 space pointed to by \em ip. On return it contains the actual length of the address returned in bytes.
1473 The argument \em port is a pointer to the buffer, that will receive the port number of the peer.
1474 If the \em port is \token{NULL}, the port number is not returned.
1478 static uint8_t peer_ip[4]; // Socket address and port
1479 static uint16_t peer_port;
1481 static void get_socket_peer_info (void) {
1484 ip_len = sizeof(peer_ip);
1485 wifi->SocketGetPeerName (sock, (uint8_t *)peer_ip, &ip_len, &peer_port);
1490 int32_t ARM_WIFI_SocketGetOpt (int32_t socket, int32_t opt_id, void *opt_val, uint32_t *opt_len) {
1494 \fn int32_t ARM_WIFI_SocketGetOpt (int32_t socket, int32_t opt_id, void *opt_val, uint32_t *opt_len)
1496 The function \b ARM_WIFI_SocketGetOpt retrieves options for a socket.
1498 The argument \em socket specifies a socket identification number returned from a previous call
1499 to \ref ARM_WIFI_SocketCreate.
1501 The argument \em opt_id is the socket option for which the value is to be retrieved. The following
1502 socket options are supported:
1503 Option | Description
1504 :----------------------------|:-------------------------------------------------
1505 \ref ARM_SOCKET_SO_RCVTIMEO | Timeout for receiving in blocking mode
1506 \ref ARM_SOCKET_SO_SNDTIMEO | Timeout for sending in blocking mode
1507 \ref ARM_SOCKET_SO_KEEPALIVE | Keep-alive mode for the stream socket
1508 \ref ARM_SOCKET_SO_TYPE | Type of the socket (stream or datagram)
1510 The argument \em opt_val points to the buffer that will receive the value of the \em opt_id.
1512 The argument \em opt_len contains the length of the buffer at the input and returns the length
1513 of the option information on the output.
1519 wifi->SocketGetOpt (sock, ARM_SOCKET_SO_TYPE, &type, sizeof(type));
1520 if (type == ARM_SOCKET_SOCK_STREAM) {
1523 if (type == ARM_SOCKET_SOCK_DGRAM) {
1529 int32_t ARM_WIFI_SocketSetOpt (int32_t socket, int32_t opt_id, const void *opt_val, uint32_t opt_len) {
1533 \fn int32_t ARM_WIFI_SocketSetOpt (int32_t socket, int32_t opt_id, const void *opt_val, uint32_t opt_len)
1535 The function \b ARM_WIFI_SocketSetOpt sets options for a socket.
1537 The argument \em socket specifies a socket identification number returned from a previous call
1538 to \ref ARM_WIFI_SocketCreate.
1540 The argument \em opt_id is the socket option for which the value is to be set. The following
1541 socket options are supported:
1542 Option | Description
1543 :----------------------------|:-------------------------------------------------
1544 \ref ARM_SOCKET_IO_FIONBIO | Non-blocking mode for the socket
1545 \ref ARM_SOCKET_SO_RCVTIMEO | Timeout for receiving in blocking mode
1546 \ref ARM_SOCKET_SO_SNDTIMEO | Timeout for sending in blocking mode
1547 \ref ARM_SOCKET_SO_KEEPALIVE | Keep-alive mode for the stream socket
1549 The argument \em opt_val points to the buffer containing the value of the \em opt_id.
1551 The argument \em opt_len tells the exact length of the option.
1555 uint32_t nonblocking = 0U; // Blocking mode
1556 uint32_t timeout = 10000U; // Timeout 10 seconds
1558 wifi->SocketSetOpt (sock, ARM_SOCKET_IO_FIONBIO, &nonblocking, sizeof(nonblocking));
1559 wifi->SocketSetOpt (sock, ARM_SOCKET_SO_RCVTIMEO, &timeout, sizeof(timeout));
1560 wifi->SocketSetOpt (sock, ARM_SOCKET_SO_SNDTIMEO, &timeout, sizeof(timeout));
1564 int32_t ARM_WIFI_SocketClose (int32_t socket) {
1568 \fn int32_t ARM_WIFI_SocketClose (int32_t socket)
1570 The function \b ARM_WIFI_SocketClose closes an existing socket and releases the socket descriptor.
1571 Further references to \em socket fail with \c ARM_SOCKET_EINVAL error code.
1573 The argument \em socket specifies a socket identification number returned from a previous call
1574 to \ref ARM_WIFI_SocketCreate.
1576 In blocking mode, which is enabled by default, this function will wait until a socket is closed.
1577 In non blocking mode, you must call the \b ARM_WIFI_SocketClose function again if the error code
1578 \c ARM_SOCKET_EAGAIN is returned.
1581 - see \ref ARM_WIFI_SocketListen
1584 int32_t ARM_WIFI_SocketGetHostByName (const char *name, int32_t af, uint8_t *ip, uint32_t *ip_len) {
1588 \fn int32_t ARM_WIFI_SocketGetHostByName (const char *name, int32_t af, uint8_t *ip, uint32_t *ip_len)
1590 The function \b ARM_WIFI_SocketGetHostByName retrieves host information corresponding to
1591 a host name from a host database. It does this by sending DNS requests to the DNS server.
1592 The IP address of the DNS server is specified in the network interface configuration or can be
1593 obtained from the DHCP server for the local area network.
1595 The argument \a name is a pointer to the \token{null}-terminated name of the host to resolve.
1597 The argument \em af specifies the address family, that is, which type of IP address you want
1598 to resolve. The following values are supported:
1599 Family | Description
1600 :----------------------------|:-------------------------------------------------
1601 \ref ARM_SOCKET_AF_INET | Resolve the IPv4 address
1602 \ref ARM_SOCKET_AF_INET6 | Resolve the IPv6 address
1604 The argument \em ip is a pointer to the buffer that will receive the resolved IP address of the host.
1605 If the argument \em ip is \token{NULL}, the function returns error.
1607 The argument \em ip_len is a pointer to the IP address length. It should initially contain the amount of
1608 space pointed to by \em ip. On return it contains the actual length of the address returned in bytes.
1612 extern ARM_DRIVER_WIFI Driver_WiFi0;
1613 static ARM_DRIVER_WIFI *wifi;
1615 void ping_arm_com (void) {
1620 wifi = &Driver_WiFi0;
1621 ip_len = sizeof(ip);
1622 res = wifi->SocketGetHostByName ("www.arm.com", ARM_SOCKET_AF_INET, (uint8_t *)ip, &ip_len);
1623 if (res == ARM_DRIVER_OK) {
1624 res = wifi->Ping ((uint8_t *)ip, sizeof(ip));
1625 if (res == ARM_DRIVER_OK) {
1626 // "www.arm.com" responded to ping
1630 // "www.arm.com" not resolved
1636 int32_t ARM_WIFI_Ping (const uint8_t *ip, uint32_t ip_len) {
1637 return ARM_DRIVER_OK;
1640 \fn int32_t ARM_WIFI_Ping (const uint8_t *ip, uint32_t ip_len)
1642 The function \b ARM_WIFI_Ping checks if the remote host is reachable. It does this by sending
1643 an echo request and waiting for an echo response. The function then returns the result
1644 of the operation. Check the \ref ARM_WIFI_CAPABILITIES of the driver, if this function
1645 is supported in the driver implementation.
1647 The argument \em ip is a pointer to the buffer containing the IP address octets of the host to ping.
1649 The argument \em ip_len specifies the length of the IP address. The length is \token{4} bytes
1650 for the IPv4 address and \token{16} bytes for the IPv6 address.
1653 The host availability check fails, if the remote host does not respond to echo requests,
1654 or intermediate routers do not forward the echo requests or echo responses.
1658 extern ARM_DRIVER_WIFI Driver_WiFi0;
1659 static ARM_DRIVER_WIFI *wifi;
1661 void ping_host (void) {
1662 uint8_t ip[4] = { 192U, 168U, 0U, 100U };
1665 wifi = &Driver_WiFi0;
1666 res = wifi->Ping ((uint8_t *)ip, sizeof(ip));
1667 if (res == ARM_DRIVER_OK) {
1676 // end group wifi_socket_gr
1682 // End WiFi Interface