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_oper_mode WiFi Operating Mode
411 \ingroup wifi_management_gr
412 \brief Specifies WiFi operation for \ref ARM_WIFI_Activate.
414 The WiFi operation mode defines in which mode the WiFi module operates when activated.
416 \def ARM_WIFI_MODE_NONE
417 \details WiFi module is inactive (default).
419 \def ARM_WIFI_MODE_STATION
420 \details WiFi module operates in station mode.
422 \def ARM_WIFI_MODE_AP
423 \details WiFi module operates in access point mode.
425 \def ARM_WIFI_MODE_STATION_AP
426 \details WiFi module operates in station mode and access point mode simultaneously.
428 \def ARM_WIFI_MODE_AD_HOC
429 \details WiFi module operates in WiFi Ad-hoc mode.
435 \defgroup wifi_sec_type WiFi Security Type
436 \ingroup wifi_management_gr
437 \brief Specifies WiFi security type for \ref ARM_WIFI_Configure.
439 The WiFi security type defines the standard used to protect the wireless network from unauthorized access.
441 \def ARM_WIFI_SECURITY_OPEN
442 \details This is an open system which provides \b no security.
444 \def ARM_WIFI_SECURITY_WEP
445 \details This security standard provides \b weak level of security.
447 \def ARM_WIFI_SECURITY_WPA
448 \details This security standard provides \b medium level of security.
450 \def ARM_WIFI_SECURITY_WPA2
451 \details This security standard provides \b strong level of security.
453 \def ARM_WIFI_SECURITY_UNKNOWN
454 \details Unknown security standard (reported by \ref ARM_WIFI_Scan).
460 \defgroup wifi_wps_method WiFi Protected Setup (WPS) Method
461 \ingroup wifi_management_gr
462 \brief Specifies WiFi WPS method for \ref ARM_WIFI_Configure.
464 The WiFi WPS method defines which WPS method is used.
466 \def ARM_WIFI_WPS_METHOD_NONE
467 \details WPS not used.
469 \def ARM_WIFI_WPS_METHOD_PBC
470 \details WPS with Push Button Configuration.
472 \def ARM_WIFI_WPS_METHOD_PIN
473 \details WPS with PIN.
479 \defgroup wifi_dhcp_v6_mode WiFi DHCPv6 Mode
480 \ingroup wifi_management_gr
481 \brief Specifies IPv6 Dynamic Host Configuration Protocol (DHCP) Mode.
483 The WiFi DHCPv6 mode defines the DHCP mode in IPv6.
485 \def ARM_WIFI_IP6_DHCP_OFF
487 In the static host configuration mode, the IPv6 address, the default gateway address,
488 and the addresses of DNS servers are statically configured from the preset values.
489 \sa wifi_dhcp_v6_mode
490 \def ARM_WIFI_IP6_DHCP_STATELESS
492 In the stateless DHCP configuration mode, the client obtains only extended information
493 from a DHCPv6 server, such as DNS server addresses. Stateless autoconfiguration of
494 IPv6 allows the client device to self configure it's IPv6 addresses and routing based
495 on the router advertisements.
496 \sa wifi_dhcp_v6_mode
497 \def ARM_WIFI_IP6_DHCP_STATEFULL
499 In the stateful DHCP configuration mode, the client connects to a DHCPv6 server for
500 a leased IPv6 address and DNS server addresses.
501 \sa wifi_dhcp_v6_mode
506 \struct ARM_WIFI_CONFIG_t
508 Provides information needed to connect to the WiFi network for station or how to configure the access point (AP).
511 - \ref ARM_WIFI_Configure
512 *******************************************************************************************************************/
515 \struct ARM_WIFI_SCAN_INFO_t
517 Provides information about the wireless networks that were detected when searching for available WiFi networks. The structure
518 contains the information needed to connect to the WiFi network. Of course, the access password is not included and must
519 be provided separately.
523 *******************************************************************************************************************/
526 \struct ARM_WIFI_NET_INFO_t
528 Provides information about the network that the station is connected to.
531 - \ref ARM_WIFI_GetNetInfo
532 *******************************************************************************************************************/
534 int32_t ARM_WIFI_SetOption (uint32_t interface, uint32_t option, const void *data, uint32_t len) {
535 return ARM_DRIVER_OK;
538 \fn int32_t ARM_WIFI_SetOption (uint32_t interface, uint32_t option, const void *data, uint32_t len)
540 The function \b ARM_WIFI_SetOption sets the value of the specified option of the WiFi module.
542 The argument \em interface specifies the interface (0 = Station, 1 = Access Point).
544 The argument \em option specifies the option that is to be set (see below).
546 The argument \em data points to a buffer containing the value of the option to be set
547 and must be aligned to the data type of the corresponding option.
549 The argument \em len specifies the length of the buffer \em data and must be equal (or higher)
550 to the length of the corresponding option.
552 Option | Description | Data | Type/Length
553 :--------------------------------------|:---------------------------------------|:--------------|:-----------
554 \ref ARM_WIFI_BSSID | BSSID of AP to connect or AP | bssid | uint8_t[6]
555 \ref ARM_WIFI_TX_POWER | Transmit power | power[dbm] | uint32_t
556 \ref ARM_WIFI_LP_TIMER | Low-power deep-sleep time | time[seconds] | uint32_t
557 \ref ARM_WIFI_DTIM | DTIM interval | dtim[beacons] | uint32_t
558 \ref ARM_WIFI_BEACON | Beacon interval | interval[ms] | uint32_t
559 \ref ARM_WIFI_MAC | MAC address | mac | uint8_t[6]
560 \ref ARM_WIFI_IP | IPv4 address | ip | uint8_t[4]
561 \ref ARM_WIFI_IP_SUBNET_MASK | IPv4 subnet mask | mask | uint8_t[4]
562 \ref ARM_WIFI_IP_GATEWAY | IPv4 gateway address | ip | uint8_t[4]
563 \ref ARM_WIFI_IP_DNS1 | IPv4 primary DNS server address | ip | uint8_t[4]
564 \ref ARM_WIFI_IP_DNS2 | IPv4 secondary DNS server address | ip | uint8_t[4]
565 \ref ARM_WIFI_IP_DHCP | IPv4 DHCP client/server enable/disable | dhcp (0, 1) | uint32_t
566 \ref ARM_WIFI_IP_DHCP_POOL_BEGIN | IPv4 DHCP server begin address | ip | uint8_t[4]
567 \ref ARM_WIFI_IP_DHCP_POOL_END | IPv4 DHCP server end address | ip | uint8_t[4]
568 \ref ARM_WIFI_IP_DHCP_LEASE_TIME | IPv4 DHCP server lease time | time[seconds] | uint32_t
569 \ref ARM_WIFI_IP6_GLOBAL | IPv6 global address | ip6 | uint8_t[16]
570 \ref ARM_WIFI_IP6_LINK_LOCAL | IPv6 link-local address | ip6 | uint8_t[16]
571 \ref ARM_WIFI_IP6_SUBNET_PREFIX_LEN | IPv6 subnet prefix length | len (1..127) | uint32_t
572 \ref ARM_WIFI_IP6_GATEWAY | IPv6 gateway address | ip6 | uint8_t[16]
573 \ref ARM_WIFI_IP6_DNS1 | IPv6 primary DNS server address | ip6 | uint8_t[16]
574 \ref ARM_WIFI_IP6_DNS2 | IPv6 secondary DNS server address | ip6 | uint8_t[16]
575 \ref ARM_WIFI_IP6_DHCP_MODE | IPv6 DHCP client mode | mode | uint32_t
586 // Set IP static address
587 wifi->SetOption (ARM_WIFI_IP, &ip, sizeof(ip));
591 int32_t ARM_WIFI_GetOption (uint32_t interface, uint32_t option, void *data, uint32_t *len) {
592 return ARM_DRIVER_OK;
595 \fn int32_t ARM_WIFI_GetOption (uint32_t interface, uint32_t option, void *data, uint32_t *len)
597 The function \b ARM_WIFI_GetOption retrieves the current value of the specified option of
600 The argument \em interface specifies the interface (0 = Station, 1 = Access Point).
602 The argument \em option specifies the option that is to be retrieved (see \ref ARM_WIFI_SetOption).
604 The argument \em data points to a buffer that will be used to store the value of
605 the \em option and must be aligned to the data type of the corresponding option.
607 The argument \em len is a pointer to the length of the buffer at input and returns the length
608 of the option information on the output.
612 uint8_t ip[4]; // IP address
613 uint8_t mask[4]; // Subnet mask
614 uint8_t gateway[4]; // Gateway address
616 // Get IP address, Subnet mask and Gateway address
617 wifi->GetOption (ARM_WIFI_IP, &ip, sizeof(ip));
618 wifi->GetOption (ARM_WIFI_IP_SUBNET_MASK, &mask, sizeof(mask));
619 wifi->GetOption (ARM_WIFI_IP_GATEWAY, &gateway, sizeof(gateway));
623 int32_t ARM_WIFI_Scan (ARM_WIFI_SCAN_INFO_t scan_info[], uint32_t max_num) {
624 return ARM_DRIVER_OK;
627 \fn int32_t ARM_WIFI_Scan (ARM_WIFI_SCAN_INFO_t scan_info[], uint32_t max_num)
629 The function \b ARM_WIFI_Scan searches for available WiFi networks. Using this function,
630 you can determine which wireless networks are available for the connection. If the network is
631 secured, you must also know the password for access so you can connect.
633 The argument \em ap_info is a pointer to a buffer, where the available network information
636 The argument \em max_mum specifies maximum number of network information structures,
637 that can be stored to the \em ap_info.
641 ARM_WIFI_AP_INFO_t ap_info[8];
643 num = wifi->Scan (ap_info, 8U);
645 // Print SSIDs of available WiFi networks
646 for (i = 0; i < num; i++) {
647 printf ("%d. ssid=%s\n", i, ap_info[i].ssid);
652 int32_t ARM_WIFI_Configure (uint32_t interface, ARM_WIFI_CONFIG_t *config) {
653 return ARM_DRIVER_OK;
656 \fn int32_t ARM_WIFI_Configure (uint32_t interface, ARM_WIFI_CONFIG_t *config)
658 The function \b ARM_WIFI_Confiure configures the specified interface.
660 The argument \em interface specifies the interface (0 = Station, 1 = Access Point).
662 The argument \em config is a pointer to the configuration \ref ARM_WIFI_CONFIG_t
663 which provides information needed to connect to a WiFi network in station mode
664 or information used to configure the access point (AP) in access point mode.
666 \em ssid specifies the name of the network to connect to or the network to create.
668 \em pass specifies the password for accessing the wireless network.
670 \em security specifies the security type which will be used for the connection.
672 \em ch specifies the WiFi channel which will be used for the connection.
673 Valid channels are from \token{1} to \token{13}. If the value for \em ch = \token{0},
674 the system automatically selects the channel.
675 When in station mode the channel of the AP being connect to is used.
676 when in access point mode the AP automatically selects the best channel
677 for the WiFi connection.
680 Optionally BSSID parameter can be also set using \ref ARM_WIFI_SetOption.
681 It allows connection to specific BSSID when connecting to an access point or specifies
682 the BSSID of the access point.
684 \em wps_method specifies if WiFi Protected Setup (WPS) is used and which method.
686 \em wps_pin specifies the PIN used with WPS (\ref ARM_WIFI_WPS_METHOD_PIN).
688 With the \b push-button method, you typically press the button, either real or virtual,
689 both at the access point and the station. No credentials are needed.
691 With \b PIN method, you must provide the PIN code that you read from the label or screen
692 on the wireless device, in the access point.
694 WPS configuration for station is used when station is activated and connects to an access point.
695 It enables to connect without specifying SSID, Password, Security Type or WiFi Channel.
696 The actual network information can be retrieved once connected with \ref ARM_WIFI_GetNetInfo.
698 WPS configuration for access point is used when access point is activated (\ref ARM_WIFI_Activate).
699 Subsequent activate calls re-trigger the WPS procedure.
702 WPS is typically activated by pressing the WPS button at the access point.
703 During the discovery mode (usually 2 minutes or less) any wireless device may connect
704 to the access point (PIN needs to match when PIN method is selected).
708 ARM_WIFI_CONFIG_t wifi_config;
710 wifi_config.ssid = "GuestAccess";
711 wifi_config.pass = "guest";
712 wifi_config.security = ARM_WIFI_SECURITY_WPA2;
714 wifi_config.wps_method = ARM_WIFI_WPS_METHOD_NONE;
717 status = wifi->Configure (0U, &wifi_config);
718 if (status != ARM_DRIVER_OK) {
722 // Connect to wireless network
723 status = wifi->Activate (ARM_WIFI_MODE_STATION);
724 if (status != ARM_DRIVER_OK) {
730 int32_t ARM_WIFI_Activate (uint32_t mode) {
731 return ARM_DRIVER_OK;
734 \fn int32_t ARM_WIFI_Activate (uint32_t mode)
736 The function \b ARM_WIFI_Activate activates the specified mode of the WiFi module.
738 The argument \em mode specifies which mode will be activated:
739 - Station mode: connect to a wireless network
740 - Access Point mode: activate access point
741 - Station and Access point mode: connect to a wireless network and activate access point
742 - Ad-hoc mode: connect to or create a wireless network
744 The WiFi Station or Access Point needs to be configured before activating.
746 The function returns once the mode is activated:
747 - when station is connected to a wireless network (Station mode)
748 - when access point is activated (Access Point mode)
749 - when station is connected and access point is activated (Station and Access point mode)
750 - when station is connected or access point is activated (Ad-hoc mode)
752 When in station mode the wireless network trying to connect to must be available,
753 otherwise the connection will fail after a timeout.
755 Available wireless networks can be scaned by using the function \ref ARM_WIFI_Scan.
757 \b Ad-hoc mode is very similar to standard infrastructure mode with a difference that there
758 are no dedicated access points in the network but a device can temporarily offer access point
759 functionality as Soft-AP (no routing capabilities) to other devices in its vicinity.
761 When in Ad-hoc mode the module tries to connect to network with specified SSID.
762 If there is no such network available the module becomes a Soft-AP with BSSID being
763 randomly generated (BSSID can be retrieved by using \ref ARM_WIFI_GetOption).
766 - see \ref ARM_WIFI_Initialize
769 int32_t ARM_WIFI_Deactivate (void) {
770 return ARM_DRIVER_OK;
773 \fn int32_t ARM_WIFI_Deactivate (void)
775 The function \b ARM_WIFI_Deactivate deactivates the current mode:
776 - terminates the connection to a wireless network
777 - deactivates the access point
780 - see \ref ARM_WIFI_GetNetInfo
783 int32_t ARM_WIFI_IsConnected (void) {
787 \fn int32_t ARM_WIFI_IsConnected (void)
789 The function \b ARM_WIFI_IsConnected checks if the station is connected to a wireless network
790 and returns the connection status.
792 The function returns a \token{non-zero} value, if the station is connected. If the station
793 is not connected, the function returns \token{0}.
796 - see \ref ARM_WIFI_GetNetInfo
799 int32_t ARM_WIFI_GetNetInfo (ARM_WIFI_NET_INFO_t *net_info) {
800 return ARM_DRIVER_OK;
803 \fn int32_t ARM_WIFI_GetNetInfo (ARM_WIFI_NET_INFO_t *net_info)
805 The function \b ARM_WIFI_GetNetInfo retrieves wireless network information of a connected station.
807 It can be used to retrieve network connection information fur subsequent connections
808 after initially connecting using WPS.
812 ARM_WIFI_CONFIG_t wifi_config;
813 ARM_WIFI_NET_INFO_t net_info;
815 memset(&wifi_config, 0, sizeof(wifi_config);
817 wifi_config.wps_method = ARM_WIFI_WPS_METHOD_PBC;
819 // Configure station (WPS)
820 status = wifi->Configure (0U, &wifi_config);
821 if (status != ARM_DRIVER_OK) {
825 // Connect to wireless network
826 status = wifi->Activate (ARM_WIFI_MODE_STATION);
827 if (status != ARM_DRIVER_OK) {
831 // Retrieve network information
832 if (wifi->IsConnected ()) {
833 status = wifi->GetNetInfo (&net_info);
834 if (status != ARM_DRIVER_OK) {
837 printf("SSID=%s, Password=%s",net_info.ssid, net_info.pass);
840 // Disconnet from wireless network
848 // end group wifi_management_gr
852 \defgroup wifi_bypass_gr WiFi Bypass Mode
853 \ingroup wifi_interface_gr
854 \brief Transfer Ethernet frames by WiFi module.
855 \details The \ref wifi_bypass_gr functions are an optional interface and enable the transmission of
856 Ethernet frames with WiFi modules. The use of this interface requires that the IP stack is running
857 on the microcontroller. The internal IP stack of the WiFi module is therefore not used, and this
858 usually means that the \ref wifi_socket_gr functions can not be used.
862 int32_t ARM_WIFI_BypassControl (uint32_t interface, uint32_t mode) {
863 return ARM_DRIVER_OK;
866 \fn int32_t ARM_WIFI_BypassControl (uint32_t interface, uint32_t mode)
868 The function \b ARM_WIFI_BypassControl enables or disables the WiFi bypass mode.
870 The WiFi Bypass mode can only be enabled, if there is a bypass mode supported in the WiFi driver.
871 You can check this by checking the driver's capabilities.
874 Bypass mode is enabled by default if the module does not support the Socket interface.
876 The argument \em mode specifies the desired state of the WiFi Bypass mode, which is
881 extern ARM_DRIVER_WIFI Driver_WiFi0;
882 static ARM_DRIVER_WIFI *wifi;
883 static ARM_ETH_MAC_ADDR own_mac_address;
885 static void wifi_notify (uint32_t event, ,void *arg) {
891 void initialize_wifi_bypass (void) {
892 ARM_WIFI_CAPABILITIES capabilities;
894 wifi = &Driver_WiFi0;
895 capabilities = wifi->GetCapabilities ();
896 if (capabilities.bypass_mode == 0) {
900 // Initialize and Power-on WiFi Interface
901 wifi->Initialize ((capabilities.eth_rx_frame_event) ? wifi_notify : NULL);
902 wifi->PowerControl (ARM_POWER_FULL);
904 // populate own_mac_address with the address to use
905 wifi->SetOption(ARM_WIFI_MAC, &own_mac_address, 6U);
907 wifi->BypassControl (1U); // Enable bypass mode
912 int32_t ARM_WIFI_EthSendFrame (uint32_t interface, const uint8_t *frame, uint32_t len) {
913 return ARM_DRIVER_OK;
916 \fn int32_t ARM_WIFI_EthSendFrame (uint32_t interface, const uint8_t *frame, uint32_t len)
918 The function \b ARM_WIFI_EthSendFrame writes an <b>Ethernet frame</b> to the WiFi transmit buffer.
920 The WiFi bypass mode must be enabled by using the function \ref ARM_WIFI_BypassControl
921 before a call to this function.
923 The frame data addressed by \em frame starts with MAC destination and ends with the last
924 Payload data byte. The frame data is copied into the transmit buffer of the WiFi interface.
926 The maximum value for \em len is implied by the size restrictions of the Ethernet frame
927 but is not verified. Using an invalid value for \em len may generate unpredicted results.
931 status = wifi->EthSendFrame (&frame_data[0], frame_length);
932 if (status != ARM_DRIVER_OK) {
938 int32_t ARM_WIFI_EthReadFrame (uint32_t interface, uint8_t *frame, uint32_t len) {
939 return ARM_DRIVER_OK;
942 \fn int32_t ARM_WIFI_EthReadFrame (uint32_t interface, uint8_t *frame, uint32_t len)
944 The function \b ARM_WIFI_EthReadFrame reads an <b>Ethernet frame</b> from the WiFi interface
947 The \em len of the Ethernet frame can be checked using the function \ref ARM_WIFI_EthGetRxFrameSize.
949 The frame data addressed by \em frame starts with MAC destination and ends with the last
950 Payload data byte. The frame data is read from the receive buffer of the WiFi interface and
951 the number of bytes written into the memory addressed by \em frame is returned.
952 A negative return value indicates an error whereby the status code is defined with
953 driver common return codes.
955 The function \ref ARM_WIFI_EthReadFrame may be called with \em buf = \token{NULL} and \em len = \token{0}
956 to discard or release a frame. This is useful when an incorrect frame has been received or
957 no memory is available to hold the Ethernet frame.
961 size = wifi->EthGetRxFrameSize ();
962 if ((size < 14) || (size > 1514)) { // frame excludes CRC
963 wifi->EthReadFrame (NULL, 0); // Frame error, release it
965 len = wifi->ReadFrame (&frame_data[0], size);
972 uint32_t ARM_WIFI_EthGetRxFrameSize (uint32_t interface, ) {
976 \fn uint32_t ARM_WIFI_EthGetRxFrameSize (uint32_t interface, )
978 The function \b ARM_WIFI_EthGetRxFrameSize returns the size of a received <b>Ethernet frame</b>
979 in the bypass mode. This function is called before \ref ARM_WIFI_EthReadFrame and supplies
982 The frame size includes MAC destination and ends with the last Payload data byte.
983 Value \token{0} indicates that no Ethernet frame is available in the receive buffer.
984 Values smaller than minimum size of Ethernet frame or larger than maximum size of Ethernet frame
985 indicate an invalid frame which needs to be discarded by calling \ref ARM_WIFI_EthReadFrame.
988 - see \ref ARM_WIFI_EthReadFrame
993 // end group wifi_bypass_gr
997 \defgroup wifi_socket_gr WiFi Socket
998 \ingroup wifi_interface_gr
999 \brief Socket interface to IP stack running on WiFi module
1000 \details The \ref wifi_socket_gr functions provide the interface to an IP stack that is running
1001 on the WiFi module. This IP stack handles data communication with the network and provides the user
1002 with a communication endpoint called sockets.
1007 \defgroup wifi_addr_family WiFi Socket Address Family definitions
1008 \ingroup wifi_socket_gr
1009 \brief WiFi Socket Address Family definitions.
1010 \details The WiFi Socket Address Family specifies the addressing scheme that an instance of the WiFi socket can use.
1012 \def ARM_SOCKET_AF_INET
1013 \details Internet Address Family version 4.
1014 \def ARM_SOCKET_AF_INET6
1015 \details Internet Address Family version 6.
1020 \defgroup wifi_socket_type WiFi Socket Type definitions
1021 \ingroup wifi_socket_gr
1022 \brief WiFi Socket Type definitions.
1023 \details The WiFi Socket Type specifies the type of the WiFi socket.
1025 \def ARM_SOCKET_SOCK_STREAM
1026 \details Stream Socket is connection-oriented, sequenced and reliable, implemented on top of the TCP protocol.
1027 \def ARM_SOCKET_SOCK_DGRAM
1028 \details Datagram Socket is connectionless, unreliable, using the UDP protocol.
1033 \defgroup wifi_protocol WiFi Socket Protocol definitions
1034 \ingroup WiFi_socket_gr
1035 \brief WiFi Socket Protocol definitions.
1036 \details The WiFi Socket Protocol specifies the Internet Protocol Type that the socket is using.
1038 \def ARM_SOCKET_IPPROTO_TCP
1039 \details Transmission Control Protocol.
1040 \def ARM_SOCKET_IPPROTO_UDP
1041 \details User Datagram Protocol.
1046 \defgroup wifi_soc_opt WiFi Socket Option definitions
1047 \ingroup WiFi_socket_gr
1048 \brief WiFi Socket Option definitions.
1049 \details The WiFi Socket Option specifies the socket option for which the value is to be set or obtained.
1051 \def ARM_SOCKET_IO_FIONBIO
1052 \details Enables or disables the non-blocking mode for the WiFi socket.
1054 \def ARM_SOCKET_SO_RCVTIMEO
1055 \details Specifies the time limit for receiving in blocking mode. The time limit is in milliseconds.
1057 \def ARM_SOCKET_SO_SNDTIMEO
1058 \details Specifies the time limit for sending in blocking mode. The time limit is in milliseconds.
1060 \def ARM_SOCKET_SO_KEEPALIVE
1061 \details Enables or disables the keep-alive mode for the stream socket.
1063 \def ARM_SOCKET_SO_TYPE
1064 \details Obtains the type of the Wifi socket.
1070 \defgroup wifi_soc_func WiFi Socket Function return codes
1071 \ingroup WiFi_socket_gr
1072 \brief WiFi Socket Function return codes.
1073 \details This section lists all the return errors the WiFi socket functions will return.
1074 The error codes are negative. This makes it easy to check an error when the return
1075 code is less than \token{0}.
1077 \def ARM_SOCKET_ERROR
1079 \def ARM_SOCKET_ESOCK
1081 \def ARM_SOCKET_EINVAL
1083 \def ARM_SOCKET_ENOTSUP
1085 \def ARM_SOCKET_ENOMEM
1087 \def ARM_SOCKET_EAGAIN
1089 \def ARM_SOCKET_EINPROGRESS
1091 \def ARM_SOCKET_ETIMEDOUT
1093 \def ARM_SOCKET_EISCONN
1095 \def ARM_SOCKET_ENOTCONN
1097 \def ARM_SOCKET_ECONNREFUSED
1099 \def ARM_SOCKET_ECONNRESET
1101 \def ARM_SOCKET_ECONNABORTED
1103 \def ARM_SOCKET_EALREADY
1105 \def ARM_SOCKET_EADDRINUSE
1107 \def ARM_SOCKET_EHOSTNOTFOUND
1112 int32_t ARM_WIFI_SocketCreate (int32_t af, int32_t type, int32_t protocol) {
1116 \fn int32_t ARM_WIFI_SocketCreate (int32_t af, int32_t type, int32_t protocol)
1118 The function \b ARM_WIFI_SocketCreate creates a communication endpoint called a socket.
1120 The argument \em af specifies the address family. The following values are supported:
1121 Family | Description
1122 :----------------------------|:-------------------------------------------------
1123 \ref ARM_SOCKET_AF_INET | Address Family Internet
1124 \ref ARM_SOCKET_AF_INET6 | Address Family Internet version 6
1126 The argument \em type specifies the communication semantics. The following are the currently supported types:
1128 :----------------------------|:-------------------------------------------------
1129 \ref ARM_SOCKET_SOCK_STREAM | Provides a reliable connection based data stream that is full-duplex
1130 \ref ARM_SOCKET_SOCK_DGRAM | Provides connectionless communication that is unreliable
1132 The argument \em protocol specifies the protocol that must be used with the socket type:
1133 Protocol | Description
1134 :----------------------------|:-------------------------------------------------
1135 \ref ARM_SOCKET_IPPROTO_TCP | Must be used with ARM_SOCKET_SOCK_STREAM socket type
1136 \ref ARM_SOCKET_IPPROTO_UDP | Must be used with ARM_SOCKET_SOCK_DGRAM socket type
1139 - see \ref ARM_WIFI_SocketListen, \ref ARM_WIFI_SocketConnect
1142 int32_t ARM_WIFI_SocketBind (int32_t socket, const uint8_t *ip, uint32_t ip_len, uint16_t port) {
1146 \fn int32_t ARM_WIFI_SocketBind (int32_t socket, const uint8_t *ip, uint32_t ip_len, uint16_t port)
1148 The function \b ARM_WIFI_SocketBind assigns a name to an unnamed socket. The name represents the local address
1149 and port of the communication endpoint.
1151 The argument \em socket specifies a socket identification number returned from a previous call
1152 to \ref ARM_WIFI_SocketCreate.
1154 The argument \em ip is a pointer to the buffer containing the IP address octets of the local IP address.
1156 The argument \em ip_len specifies the length of the local IP address. The length is \token{4} bytes
1157 for the IPv4 address and \token{16} bytes for the IPv6 address.
1159 The argument \em port specifies the local port. If the argument \em port is \token{0}, the function returns error,
1160 because this port is reserved.
1163 - see \ref ARM_WIFI_SocketListen
1166 int32_t ARM_WIFI_SocketListen (int32_t socket, int32_t backlog) {
1170 \fn int32_t ARM_WIFI_SocketListen (int32_t socket, int32_t backlog)
1172 The function \b ARM_WIFI_SocketListen sets the specified socket to listening mode, that is to the
1173 server mode of operation. Before calling the \b ARM_WIFI_SocketListen function, the \ref ARM_WIFI_SocketBind
1174 function must be called.
1176 The argument \em socket specifies a socket identification number returned from a previous call
1177 to \ref ARM_WIFI_SocketCreate.
1179 The argument \em backlog specifies a maximum number of connection requests that can be queued.
1183 extern ARM_DRIVER_WIFI Driver_WiFi0;
1184 static ARM_DRIVER_WIFI *wifi;
1186 void Echo_Server_Thread (void *arg) {
1187 uint8_t ip[4] = { 0U, 0U, 0U, 0U };
1188 int32_t sock, sd, res;
1192 wifi = &Driver_WiFi0;
1193 sock = wifi->SocketCreate (ARM_SOCKET_AF_INET, ARM_SOCKET_SOCK_STREAM, ARM_SOCKET_IPPROTO_TCP);
1195 wifi->SocketBind (sock, (uint8_t *)ip, sizeof(ip), 7U);
1196 wifi->SocketListen (sock, 1);
1197 sd = wifi->SocketAccept (sock, NULL, NULL, NULL);
1198 wifi->SocketClose (sock);
1202 res = wifi->SocketRecv (sock, dbuf, sizeof(dbuf));
1204 break; // Error occurred
1207 wifi->SocketSend (sock, dbuf, res); // Echo the data
1210 wifi->SocketClose (sock);
1216 int32_t ARM_WIFI_SocketAccept (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port) {
1220 \fn int32_t ARM_WIFI_SocketAccept (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port)
1222 The function \b ARM_WIFI_SocketAccept accepts a connection request queued for a listening socket.
1223 If a connection request is pending, \b ARM_WIFI_SocketAccept removes the request from the queue,
1224 and creates a new socket for the connection. The original listening socket remains open and continues
1225 to queue new connection requests. The \em socket must be a socket of type \b ARM_SOCKET_SOCK_STREAM.
1227 In blocking mode, which is enabled by default, this function waits for a connection request. In
1228 non blocking mode, you must call the \b ARM_WIFI_SocketAccept function again if the error code
1229 \c ARM_SOCKET_EAGAIN is returned.
1231 The argument \em socket specifies a socket identification number returned from a previous call
1232 to \ref ARM_WIFI_SocketCreate.
1234 The argument \em ip is a pointer to the buffer that will receive the IP address of the connection node.
1235 If the \em ip is \token{NULL}, the IP address is not returned.
1237 The argument \em ip_len is a pointer to the IP address length. It should initially contain the amount of
1238 space pointed to by \em ip. On return it contains the actual length of the address returned in bytes.
1240 The argument \em port is a pointer to the buffer, that will receive the port number of the connection node.
1241 If the \em port is \token{NULL}, the port number is not returned.
1244 - see \ref ARM_WIFI_SocketListen
1247 int32_t ARM_WIFI_SocketConnect (int32_t socket, const uint8_t *ip, uint32_t ip_len, uint16_t port) {
1251 \fn int32_t ARM_WIFI_SocketConnect (int32_t socket, const uint8_t *ip, uint32_t ip_len, uint16_t port)
1253 The function \b ARM_WIFI_SocketConnect assigns the address of the peer communication endpoint. The function
1254 behaves differently according to the type of socket:
1256 - \b ARM_SOCKET_SOCK_STREAM: A connection is established between the endpoints.
1258 In blocking mode, which is enabled by default, this function waits for a connection to be established.
1260 In non blocking mode, the function returns the error code \c ARM_SOCKET_EINPROGRESS and the connection
1261 is established asynchronously. Subsequent calls to \b ARM_WIFI_SocketConnect for the same socket,
1262 before the connection is established, return the error code \c ARM_SOCKET_EALREADY. When the connection
1263 is established, the call to \b ARM_WIFI_SocketConnect returns the error code \c ARM_SOCKET_EISCONN.
1265 - \b ARM_SOCKET_SOCK_DGRAM: An address filter is established between the endpoints.
1267 The address filter is changed with another \b ARM_WIFI_SocketConnect function call. If the socket
1268 is not yet bound, the system implicitly binds to a random dynamic port.
1270 The argument \em socket specifies a socket identification number returned from a previous call
1271 to \ref ARM_WIFI_SocketCreate.
1273 The argument \em ip is a pointer to the buffer containing the IP address octets of the endpoint node.
1275 The argument \em ip_len specifies the length of the IP address. The length is \token{4} bytes
1276 for the IPv4 address and \token{16} bytes for the IPv6 address.
1278 The argument \em port specifies the port of the endpoint node. If the argument \em port is \token{0},
1279 the function returns error, because this port is reserved.
1283 extern ARM_DRIVER_WIFI Driver_WiFi0;
1284 static ARM_DRIVER_WIFI *wifi;
1286 static const char message[] = { "The quick brown fox jumps over the lazy dog." };
1288 void Echo_Client_Thread (void *arg) {
1289 uint8_t ip[4] = { 192U, 168U, 0U, 100U };
1294 wifi = &Driver_WiFi0;
1295 sock = wifi->SocketCreate (ARM_SOCKET_AF_INET, ARM_SOCKET_SOCK_STREAM, ARM_SOCKET_IPPROTO_TCP);
1297 res = wifi->SocketConnect (sock, (uint8_t *)ip, sizeof(ip), 7U);
1299 wifi->SocketSend (sock, message, sizeof(message));
1300 res = wifi->SocketRecv (sock, dbuf, sizeof(dbuf));
1302 break; // Error occured
1305 if (memcmp (dbuf, message, res) != 0) {
1306 // error handling, message is not the same as sent
1310 wifi->SocketClose (sock);
1317 int32_t ARM_WIFI_SocketRecv (int32_t socket, void *buf, uint32_t len) {
1321 \fn int32_t ARM_WIFI_SocketRecv (int32_t socket, void *buf, uint32_t len)
1323 The function \b ARM_WIFI_SocketRecv receives incoming data that has been queued for the socket.
1324 You can use this function with both, the stream and the datagram socket. It reads as much
1325 information as currently available up to the size of the buffer specified.
1327 In blocking mode, which is enabled by default, this function waits for received data. In non
1328 blocking mode, you must call the \b ARM_WIFI_SocketRecv function again if the error code
1329 \c ARM_SOCKET_EAGAIN is returned.
1331 The argument \em socket specifies a socket identification number returned from a previous call
1332 to \ref ARM_WIFI_SocketCreate.
1334 The argument \em buf is a pointer to the application data buffer for storing the data to.
1335 If the available data is too large to fit in the supplied application buffer \em buf, excess bytes
1336 are discarded in case of a datagram sockets. For stream sockets, the data is buffered internally
1337 so the application can retrieve all data by multiple calls of \b ARM_WIFI_SocketRecv function.
1339 The argument \em len specifies the size of the application data buffer.
1342 - see \ref ARM_WIFI_SocketListen
1345 int32_t ARM_WIFI_SocketRecvFrom (int32_t socket, void *buf, uint32_t len, uint8_t *ip, uint32_t *ip_len, uint16_t *port) {
1349 \fn int32_t ARM_WIFI_SocketRecvFrom (int32_t socket, void *buf, uint32_t len, uint8_t *ip, uint32_t *ip_len, uint16_t *port)
1351 The function \b ARM_WIFI_SocketRecvFrom is used to receive data that has been queued for a socket.
1352 It is normally used to receive messages on datagram sockets, but can also be used to receive a reliable,
1353 ordered stream of data on a connected stream sockets. It reads as much information as currently available
1354 up to the size of the buffer specified.
1356 In blocking mode, which is enabled by default, this function waits for received data. In non
1357 blocking mode, you must call the \b ARM_WIFI_SocketRecv function again if the error code
1358 \c ARM_SOCKET_EAGAIN is returned.
1360 The argument \em socket specifies a socket identification number returned from a previous call
1361 to \ref ARM_WIFI_SocketCreate.
1363 The argument \em buf is a pointer to the application data buffer for storing the data to.
1364 If the available data is too large to fit in the supplied application buffer \em buf, excess bytes
1365 are discarded in case of a datagram sockets. For stream sockets, the data is buffered internally
1366 so the application can retrieve all data by multiple calls of \b ARM_WIFI_SocketRecv function.
1368 The argument \em len specifies the size of the application data buffer.
1370 The argument \em ip is a pointer to the buffer that will receive the IP address of the sender.
1371 If the \em ip is \token{NULL}, the IP address is not returned.
1373 The argument \em ip_len is a pointer to the IP address length. It should initially contain the amount of
1374 space pointed to by \em ip. On return it contains the actual length of the address returned in bytes.
1376 The argument \em port is a pointer to the buffer, that will receive the port number of the sender.
1377 If the \em port is \token{NULL}, the port number is not returned.
1381 extern ARM_DRIVER_WIFI Driver_WiFi0;
1382 static ARM_DRIVER_WIFI *wifi;
1384 void Echo_Server_Thread (void *arg) {
1392 wifi = &Driver_WiFi0;
1393 sock = wifi->SocketCreate (ARM_SOCKET_AF_INET, ARM_SOCKET_SOCK_DGRAM, ARM_SOCKET_IPPROTO_UDP);
1395 ip[0] = 0U; // Unspecified address
1399 port = 7U; // Standard port for Echo service
1401 wifi->SocketBind (sock, (uint8_t *)ip, sizeof(ip), port);
1404 ip_len = sizeof(ip);
1405 res = wifi->SocketRecvFrom (sock, dbuf, sizeof(dbuf), (uint8_t *)ip, &ip_len, &port);
1407 break; // Error occurred
1409 if (res > 0) { // Echo the data
1410 wifi->SocketSendTo (sock, dbuf, res, (uint8_t *)ip, ip_len, port);
1413 wifi->SocketClose (sock);
1419 int32_t ARM_WIFI_SocketSend (int32_t socket, const void *buf, uint32_t len) {
1423 \fn int32_t ARM_WIFI_SocketSend (int32_t socket, const void *buf, uint32_t len)
1425 The function \b ARM_WIFI_SocketSend is used to send data on an already connected socket. This function is
1426 normally used to send a reliable, ordered stream of data bytes on a stream sockets. It can also be used
1427 to send messages on datagram sockets.
1429 The argument \em socket specifies a socket identification number returned from a previous call
1430 to \ref ARM_WIFI_SocketCreate.
1432 The argument \a buf is a pointer to the application data buffer containing data to transmit. The buffer
1433 data length is not limited in size. If the data length is too large for one packet, the \b ARM_WIFI_SocketSend function
1434 will fragment the data and send it in several successive data packets:
1435 - In blocking mode, which is enabled by default, this function returns after the data has been successfully queued for transmission.
1436 - In non blocking mode, the function returns immediately without blocking the system.
1438 The argument \a len specifies the length of data in bytes.
1440 Return value, when positive, represents the number of bytes sent, which can be less than \a len.
1443 - see \ref ARM_WIFI_SocketListen
1446 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) {
1450 \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)
1452 The function \b ARM_WIFI_SocketSendTo is used to send data. It is normally used to send messages
1453 on a datagram sockets, but can also be used to send data on a connected stream sockets.
1455 If the datagram socket is not yet bound, the system implicitly binds to a random dynamic port.
1457 The argument \em socket specifies a socket identification number returned from a previous call
1458 to \ref ARM_WIFI_SocketCreate.
1460 The argument \a buf is a pointer to the application data buffer containing data to transmit. The buffer
1461 data length is not limited in size. If the data length is too large for one packet, the \b ARM_WIFI_SocketSend function
1462 will fragment the data and send it in several successive data packets:
1463 - In blocking mode, which is enabled by default, this function returns after the data has been successfully queued for transmission.
1464 - In non blocking mode, the function returns immediately without blocking the system.
1466 The argument \a len specifies the length of data in bytes.
1468 The argument \em ip is a pointer to the buffer containing the IP address octets of the endpoint node.
1470 The argument \em ip_len specifies the length of the IP address. The length is \token{4} bytes
1471 for the IPv4 address and \token{16} bytes for the IPv6 address.
1473 The argument \em port specifies the port of the endpoint node. If the argument \em port is \token{0},
1474 the function returns error, because this port is reserved.
1476 For the stream sockets, arguments \em ip, \em ip_len and \em port are ignored.
1478 Return value, when positive, represents the number of bytes sent, which can be less than \a len.
1481 - see \ref ARM_WIFI_SocketRecvFrom
1484 int32_t ARM_WIFI_SocketGetSockName (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port) {
1488 \fn int32_t ARM_WIFI_SocketGetSockName (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port)
1490 The function \b ARM_WIFI_SocketGetSockName retrieves the local IP address and port for a socket.
1492 The argument \em socket specifies a socket identification number returned from a previous call
1493 to \ref ARM_WIFI_SocketCreate.
1495 The argument \em ip is a pointer to the buffer that will receive the local IP address.
1496 If the \em ip is \token{NULL}, the local IP address is not returned.
1498 The argument \em ip_len is a pointer to the IP address length. It should initially contain the amount of
1499 space pointed to by \em ip. On return it contains the actual length of the address returned in bytes.
1501 The argument \em port is a pointer to the buffer, that will receive the local port number.
1502 If the \em port is \token{NULL}, the local port number is not returned.
1506 static uint8_t local_ip[4]; // Socket address and port
1507 static uint16_t local_port;
1509 static void get_socket_local_info (void) {
1512 ip_len = sizeof(local_ip);
1513 wifi->SocketGetSockName (sock, (uint8_t *)local_ip, &ip_len, &local_port);
1518 int32_t ARM_WIFI_SocketGetPeerName (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port) {
1522 \fn int32_t ARM_WIFI_SocketGetPeerName (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port)
1524 The function \b ARM_WIFI_SocketGetPeerName retrieves the IP address and port of the peer to which
1525 a socket is connected.
1527 The argument \em socket specifies a socket identification number returned from a previous call
1528 to \ref ARM_WIFI_SocketCreate.
1530 The argument \em ip is a pointer to the buffer that will receive the IP address of the peer.
1531 If the \em ip is \token{NULL}, the IP address is not returned.
1533 The argument \em ip_len is a pointer to the IP address length. It should initially contain the amount of
1534 space pointed to by \em ip. On return it contains the actual length of the address returned in bytes.
1536 The argument \em port is a pointer to the buffer, that will receive the port number of the peer.
1537 If the \em port is \token{NULL}, the port number is not returned.
1541 static uint8_t peer_ip[4]; // Socket address and port
1542 static uint16_t peer_port;
1544 static void get_socket_peer_info (void) {
1547 ip_len = sizeof(peer_ip);
1548 wifi->SocketGetPeerName (sock, (uint8_t *)peer_ip, &ip_len, &peer_port);
1553 int32_t ARM_WIFI_SocketGetOpt (int32_t socket, int32_t opt_id, void *opt_val, uint32_t *opt_len) {
1557 \fn int32_t ARM_WIFI_SocketGetOpt (int32_t socket, int32_t opt_id, void *opt_val, uint32_t *opt_len)
1559 The function \b ARM_WIFI_SocketGetOpt retrieves options for a socket.
1561 The argument \em socket specifies a socket identification number returned from a previous call
1562 to \ref ARM_WIFI_SocketCreate.
1564 The argument \em opt_id is the socket option for which the value is to be retrieved. The following
1565 socket options are supported:
1566 Option | Description
1567 :----------------------------|:-------------------------------------------------
1568 \ref ARM_SOCKET_SO_RCVTIMEO | Timeout for receiving in blocking mode
1569 \ref ARM_SOCKET_SO_SNDTIMEO | Timeout for sending in blocking mode
1570 \ref ARM_SOCKET_SO_KEEPALIVE | Keep-alive mode for the stream socket
1571 \ref ARM_SOCKET_SO_TYPE | Type of the socket (stream or datagram)
1573 The argument \em opt_val points to the buffer that will receive the value of the \em opt_id.
1575 The argument \em opt_len contains the length of the buffer at the input and returns the length
1576 of the option information on the output.
1582 wifi->SocketGetOpt (sock, ARM_SOCKET_SO_TYPE, &type, sizeof(type));
1583 if (type == ARM_SOCKET_SOCK_STREAM) {
1586 if (type == ARM_SOCKET_SOCK_DGRAM) {
1592 int32_t ARM_WIFI_SocketSetOpt (int32_t socket, int32_t opt_id, const void *opt_val, uint32_t opt_len) {
1596 \fn int32_t ARM_WIFI_SocketSetOpt (int32_t socket, int32_t opt_id, const void *opt_val, uint32_t opt_len)
1598 The function \b ARM_WIFI_SocketSetOpt sets options for a socket.
1600 The argument \em socket specifies a socket identification number returned from a previous call
1601 to \ref ARM_WIFI_SocketCreate.
1603 The argument \em opt_id is the socket option for which the value is to be set. The following
1604 socket options are supported:
1605 Option | Description
1606 :----------------------------|:-------------------------------------------------
1607 \ref ARM_SOCKET_IO_FIONBIO | Non-blocking mode for the socket
1608 \ref ARM_SOCKET_SO_RCVTIMEO | Timeout for receiving in blocking mode
1609 \ref ARM_SOCKET_SO_SNDTIMEO | Timeout for sending in blocking mode
1610 \ref ARM_SOCKET_SO_KEEPALIVE | Keep-alive mode for the stream socket
1612 The argument \em opt_val points to the buffer containing the value of the \em opt_id.
1614 The argument \em opt_len tells the exact length of the option.
1618 uint32_t nonblocking = 0U; // Blocking mode
1619 uint32_t timeout = 10000U; // Timeout 10 seconds
1621 wifi->SocketSetOpt (sock, ARM_SOCKET_IO_FIONBIO, &nonblocking, sizeof(nonblocking));
1622 wifi->SocketSetOpt (sock, ARM_SOCKET_SO_RCVTIMEO, &timeout, sizeof(timeout));
1623 wifi->SocketSetOpt (sock, ARM_SOCKET_SO_SNDTIMEO, &timeout, sizeof(timeout));
1627 int32_t ARM_WIFI_SocketClose (int32_t socket) {
1631 \fn int32_t ARM_WIFI_SocketClose (int32_t socket)
1633 The function \b ARM_WIFI_SocketClose closes an existing socket and releases the socket descriptor.
1634 Further references to \em socket fail with \c ARM_SOCKET_EINVAL error code.
1636 The argument \em socket specifies a socket identification number returned from a previous call
1637 to \ref ARM_WIFI_SocketCreate.
1639 In blocking mode, which is enabled by default, this function will wait until a socket is closed.
1640 In non blocking mode, you must call the \b ARM_WIFI_SocketClose function again if the error code
1641 \c ARM_SOCKET_EAGAIN is returned.
1644 - see \ref ARM_WIFI_SocketListen
1647 int32_t ARM_WIFI_SocketGetHostByName (const char *name, int32_t af, uint8_t *ip, uint32_t *ip_len) {
1651 \fn int32_t ARM_WIFI_SocketGetHostByName (const char *name, int32_t af, uint8_t *ip, uint32_t *ip_len)
1653 The function \b ARM_WIFI_SocketGetHostByName retrieves host information corresponding to
1654 a host name from a host database. It does this by sending DNS requests to the DNS server.
1655 The IP address of the DNS server is specified in the network interface configuration or can be
1656 obtained from the DHCP server for the local area network.
1658 The argument \a name is a pointer to the \token{null}-terminated name of the host to resolve.
1660 The argument \em af specifies the address family, that is, which type of IP address you want
1661 to resolve. The following values are supported:
1662 Family | Description
1663 :----------------------------|:-------------------------------------------------
1664 \ref ARM_SOCKET_AF_INET | Resolve the IPv4 address
1665 \ref ARM_SOCKET_AF_INET6 | Resolve the IPv6 address
1667 The argument \em ip is a pointer to the buffer that will receive the resolved IP address of the host.
1668 If the argument \em ip is \token{NULL}, the function returns error.
1670 The argument \em ip_len is a pointer to the IP address length. It should initially contain the amount of
1671 space pointed to by \em ip. On return it contains the actual length of the address returned in bytes.
1675 extern ARM_DRIVER_WIFI Driver_WiFi0;
1676 static ARM_DRIVER_WIFI *wifi;
1678 void ping_arm_com (void) {
1683 wifi = &Driver_WiFi0;
1684 ip_len = sizeof(ip);
1685 res = wifi->SocketGetHostByName ("www.arm.com", ARM_SOCKET_AF_INET, (uint8_t *)ip, &ip_len);
1686 if (res == ARM_DRIVER_OK) {
1687 res = wifi->Ping ((uint8_t *)ip, sizeof(ip));
1688 if (res == ARM_DRIVER_OK) {
1689 // "www.arm.com" responded to ping
1693 // "www.arm.com" not resolved
1699 int32_t ARM_WIFI_Ping (const uint8_t *ip, uint32_t ip_len) {
1700 return ARM_DRIVER_OK;
1703 \fn int32_t ARM_WIFI_Ping (const uint8_t *ip, uint32_t ip_len)
1705 The function \b ARM_WIFI_Ping checks if the remote host is reachable. It does this by sending
1706 an echo request and waiting for an echo response. The function then returns the result
1707 of the operation. Check the \ref ARM_WIFI_CAPABILITIES of the driver, if this function
1708 is supported in the driver implementation.
1710 The argument \em ip is a pointer to the buffer containing the IP address octets of the host to ping.
1712 The argument \em ip_len specifies the length of the IP address. The length is \token{4} bytes
1713 for the IPv4 address and \token{16} bytes for the IPv6 address.
1716 The host availability check fails, if the remote host does not respond to echo requests,
1717 or intermediate routers do not forward the echo requests or echo responses.
1721 extern ARM_DRIVER_WIFI Driver_WiFi0;
1722 static ARM_DRIVER_WIFI *wifi;
1724 void ping_host (void) {
1725 uint8_t ip[4] = { 192U, 168U, 0U, 100U };
1728 wifi = &Driver_WiFi0;
1729 res = wifi->Ping ((uint8_t *)ip, sizeof(ip));
1730 if (res == ARM_DRIVER_OK) {
1739 // end group wifi_socket_gr
1745 // End WiFi Interface