| CMSIS-Driver Peripheral Interface for Middleware and Application Code |

Loading...
Searching...
No Matches
Content | Data Structures | Functions
WiFi Management
WiFi Interface

Configure and manage the connection to a WiFi access point (AP) or configure and manage the access point (AP). More...

## Content
| WiFi Option Codes
| WiFi Option Codes for ARM_WIFI_SetOption or ARM_WIFI_GetOption function.
| WiFi Security Type
| Specifies WiFi security type for ARM_WIFI_Activate.
| WiFi Protected Setup (WPS) Method
| Specifies WiFi WPS method for ARM_WIFI_Activate.
| WiFi DHCPv6 Mode
| Specifies IPv6 Dynamic Host Configuration Protocol (DHCP) Mode.

## Data Structures
struct | ARM_WIFI_CONFIG_t
| WiFi Configuration. More...
struct | ARM_WIFI_SCAN_INFO_t
| WiFi Scan Information. More...
struct | ARM_WIFI_NET_INFO_t
| WiFi Network Information. More...

## Functions
int32_t | ARM_WIFI_SetOption (uint32_t interface, uint32_t option, const void *data, uint32_t len)
| Set WiFi Module Options.
int32_t | ARM_WIFI_GetOption (uint32_t interface, uint32_t option, void *data, uint32_t *len)
| Get WiFi Module Options.
int32_t | ARM_WIFI_Scan (ARM_WIFI_SCAN_INFO_t scan_info[], uint32_t max_num)
| Scan for available networks in range.
int32_t | ARM_WIFI_Activate (uint32_t interface, const ARM_WIFI_CONFIG_t *config)
| Activate interface (Connect to a wireless network or activate an access point).
int32_t | ARM_WIFI_Deactivate (uint32_t interface)
| Deactivate interface (Disconnect from a wireless network or deactivate an access point).
uint32_t | ARM_WIFI_IsConnected (void)
| Get station connection status.
int32_t | ARM_WIFI_GetNetInfo (ARM_WIFI_NET_INFO_t *net_info)
| Get station Network Information.

## Description

Configure and manage the connection to a WiFi access point (AP) or configure and manage the access point (AP).

The WiFi Management functions are used to configure and manage the connection to a WiFi access point (AP) also called hotspot when in station mode. They are also used to configure and manage the access point (AP) itself when in access point mode.

## Data Structure Documentation

## ◆ ARM_WIFI_CONFIG_t

struct ARM_WIFI_CONFIG_t

WiFi Configuration.

Provides information needed to connect to the WiFi network for station or how to configure the access point (AP).

Used in:

- ARM_WIFI_Activate

Data Fields
const char * | ssid | Pointer to Service Set Identifier (SSID) null-terminated string.
const char * | pass | Pointer to Password null-terminated string.
uint8_t | security | Security type (ARM_WIFI_SECURITY_xxx)
uint8_t | ch | WiFi Channel (0 = auto, otherwise = exact channel)
uint8_t | reserved | Reserved.
uint8_t | wps_method | WiFi Protected Setup (WPS) method (ARM_WIFI_WPS_METHOD_xxx)
const char * | wps_pin | Pointer to WiFi Protected Setup (WPS) PIN null-terminated string.

## ◆ ARM_WIFI_SCAN_INFO_t

struct ARM_WIFI_SCAN_INFO_t

WiFi Scan Information.

Provides information about the wireless networks that were detected when searching for available WiFi networks. The structure contains the information needed to connect to the WiFi network. Of course, the access password is not included and must be provided separately.

Used in:

- ARM_WIFI_Scan

Data Fields
char | ssid[32+1] | Service Set Identifier (SSID) null-terminated string.
uint8_t | bssid[6] | Basic Service Set Identifier (BSSID)
uint8_t | security | Security type (ARM_WIFI_SECURITY_xxx)
uint8_t | ch | WiFi Channel.
uint8_t | rssi | Received Signal Strength Indicator.

## ◆ ARM_WIFI_NET_INFO_t

struct ARM_WIFI_NET_INFO_t

WiFi Network Information.

Provides information about the network that the station is connected to.

Used in:

- ARM_WIFI_GetNetInfo

Data Fields
char | ssid[32+1] | Service Set Identifier (SSID) null-terminated string.
char | pass[64+1] | Password null-terminated string.
uint8_t | security | Security type (ARM_WIFI_SECURITY_xxx)
uint8_t | ch | WiFi Channel.
uint8_t | rssi | Received Signal Strength Indicator.

## Function Documentation

## ◆ ARM_WIFI_SetOption()

int32_t ARM_WIFI_SetOption | ( | uint32_t | interface,
|  | uint32_t | option,
|  | const void * | data,
|  | uint32_t | len
| ) |  |

Set WiFi Module Options.

Parameters

  [in] | interface | Interface (0 = Station, 1 = Access Point)
  [in] | option | Option to set
  [in] | data | Pointer to data relevant to selected option
  [in] | len | Length of data (in bytes)

Returns
  execution status
  - ARM_DRIVER_OK : Operation successful
  - ARM_DRIVER_ERROR : Operation failed
  - ARM_DRIVER_ERROR_UNSUPPORTED : Operation not supported
  - ARM_DRIVER_ERROR_PARAMETER : Parameter error (invalid interface, NULL data pointer or len less than option specifies)

The function ARM_WIFI_SetOption sets the value of the specified option of the WiFi module.

The argument interface specifies the interface (0 = Station, 1 = Access Point).

The argument option specifies the option that is to be set (see below).

The argument data points to a buffer containing the value of the option to be set and must be aligned to the data type of the corresponding option.

The argument len specifies the length of the buffer data and must be equal (or higher) to the length of the corresponding option.

Option | Description | Data | Type/Length
--- | --- | --- | ---
ARM_WIFI_BSSID | BSSID of AP to connect or AP | bssid | uint8_t[6]
ARM_WIFI_TX_POWER | Transmit power | power[dbm] | uint32_t
ARM_WIFI_LP_TIMER | Low-power deep-sleep time | time[seconds] | uint32_t
ARM_WIFI_DTIM | DTIM interval | dtim[beacons] | uint32_t
ARM_WIFI_BEACON | Beacon interval | interval[ms] | uint32_t
ARM_WIFI_MAC | MAC address | mac | uint8_t[6]
ARM_WIFI_IP | IPv4 address | ip | uint8_t[4]
ARM_WIFI_IP_SUBNET_MASK | IPv4 subnet mask | mask | uint8_t[4]
ARM_WIFI_IP_GATEWAY | IPv4 gateway address | ip | uint8_t[4]
ARM_WIFI_IP_DNS1 | IPv4 primary DNS server address | ip | uint8_t[4]
ARM_WIFI_IP_DNS2 | IPv4 secondary DNS server address | ip | uint8_t[4]
ARM_WIFI_IP_DHCP | IPv4 DHCP client/server enable/disable | dhcp (0, 1) | uint32_t
ARM_WIFI_IP_DHCP_POOL_BEGIN | IPv4 DHCP server begin address | ip | uint8_t[4]
ARM_WIFI_IP_DHCP_POOL_END | IPv4 DHCP server end address | ip | uint8_t[4]
ARM_WIFI_IP_DHCP_LEASE_TIME | IPv4 DHCP server lease time | time[seconds] | uint32_t
ARM_WIFI_IP6_GLOBAL | IPv6 global address | ip6 | uint8_t[16]
ARM_WIFI_IP6_LINK_LOCAL | IPv6 link-local address | ip6 | uint8_t[16]
ARM_WIFI_IP6_SUBNET_PREFIX_LEN | IPv6 subnet prefix length | len (1..127) | uint32_t
ARM_WIFI_IP6_GATEWAY | IPv6 gateway address | ip6 | uint8_t[16]
ARM_WIFI_IP6_DNS1 | IPv6 primary DNS server address | ip6 | uint8_t[16]
ARM_WIFI_IP6_DNS2 | IPv6 secondary DNS server address | ip6 | uint8_t[16]
ARM_WIFI_IP6_DHCP_MODE | IPv6 DHCP client mode | mode | uint32_t

Example:

uint8_t ip[4];
ip[0] = 192U;
ip[1] = 168U;
ip[2] = 0U;
ip[3] = 1U;
// Set IP static address of the Station
wifi->SetOption (0U, ARM_WIFI_IP, &ip, sizeof(ip));
ARM_WIFI_IP
#define ARM_WIFI_IP
Station/AP Set/Get IPv4 static/assigned address; data = &ip, len = 4, uint8_t[4].

## ◆ ARM_WIFI_GetOption()

int32_t ARM_WIFI_GetOption | ( | uint32_t | interface,
|  | uint32_t | option,
|  | void * | data,
|  | uint32_t * | len
| ) |  |

Get WiFi Module Options.

Parameters

  [in] | interface | Interface (0 = Station, 1 = Access Point)
  [in] | option | Option to get
  [out] | data | Pointer to memory where data for selected option will be returned
  [in,out] | len | Pointer to length of data (input/output) input: maximum length of data that can be returned (in bytes) output: length of returned data (in bytes)

Returns
  execution status
  - ARM_DRIVER_OK : Operation successful
  - ARM_DRIVER_ERROR : Operation failed
  - ARM_DRIVER_ERROR_UNSUPPORTED : Operation not supported
  - ARM_DRIVER_ERROR_PARAMETER : Parameter error (invalid interface, NULL data or len pointer, or *len less than option specifies)

The function ARM_WIFI_GetOption retrieves the current value of the specified option of the WiFi module.

The argument interface specifies the interface (0 = Station, 1 = Access Point).

The argument option specifies the option that is to be retrieved (see ARM_WIFI_SetOption).

The argument data points to a buffer that will be used to store the value of the option and must be aligned to the data type of the corresponding option.

The argument len is a pointer to the length of the buffer at input and returns the length of the option information on the output.

Example:

uint8_t ip[4]; // IP address
uint8_t mask[4]; // Subnet mask
uint8_t gateway[4]; // Gateway address
// Get IP address, Subnet mask and Gateway address of the Station
wifi->GetOption (0U, ARM_WIFI_IP, &ip, sizeof(ip));
wifi->GetOption (0U, ARM_WIFI_IP_SUBNET_MASK, &mask, sizeof(mask));
wifi->GetOption (0U, ARM_WIFI_IP_GATEWAY, &gateway, sizeof(gateway));
ARM_WIFI_IP_SUBNET_MASK
#define ARM_WIFI_IP_SUBNET_MASK
Station/AP Set/Get IPv4 subnet mask; data = &mask, len = 4, uint8_t[4].
ARM_WIFI_IP_GATEWAY
#define ARM_WIFI_IP_GATEWAY
Station/AP Set/Get IPv4 gateway address; data = &ip, len = 4, uint8_t[4].

## ◆ ARM_WIFI_Scan()

int32_t ARM_WIFI_Scan | ( | ARM_WIFI_SCAN_INFO_t | scan_info[],
|  | uint32_t | max_num
| ) |  |

Scan for available networks in range.

Parameters

  [out] | scan_info | Pointer to array of ARM_WIFI_SCAN_INFO_t structures where available Scan Information will be returned
  [in] | max_num | Maximum number of Network Information structures to return

Returns
  number of ARM_WIFI_SCAN_INFO_t structures returned or error code
  - value >= 0 : Number of ARM_WIFI_SCAN_INFO_t structures returned
  - ARM_DRIVER_ERROR : Operation failed
  - ARM_DRIVER_ERROR_PARAMETER : Parameter error (NULL scan_info pointer or max_num equal to 0)

The function ARM_WIFI_Scan searches for available WiFi networks. Using this function, you can determine which wireless networks are available for the connection. If the network is secured, you must also know the password to connect.

The argument scan_info is a pointer to an array of network information structures, where the available network information will be returned.

The argument max_num specifies maximum number of network information structures, that can be stored to the scan_info.

Example:

ARM_WIFI_SCAN_INFO_t scan_info[8];
num = wifi->Scan (scan_info, 8U);
// Print SSIDs of available WiFi networks
for (i = 0; i < num; i++) {
printf ("%d. ssid=%s\n", i, scan_info[i].ssid);
}
ARM_WIFI_SCAN_INFO_t
WiFi Scan Information.
Definition: Driver_WiFi.h:111

## ◆ ARM_WIFI_Activate()

int32_t ARM_WIFI_Activate | ( | uint32_t | interface,
|  | const ARM_WIFI_CONFIG_t * | config
| ) |  |

Activate interface (Connect to a wireless network or activate an access point).

Parameters

  [in] | interface | Interface (0 = Station, 1 = Access Point)
  [in] | config | Pointer to ARM_WIFI_CONFIG_t structure where Configuration parameters are located

Returns
  execution status
  - ARM_DRIVER_OK : Operation successful
  - ARM_DRIVER_ERROR : Operation failed
  - ARM_DRIVER_ERROR_TIMEOUT : Timeout occurred
  - ARM_DRIVER_ERROR_UNSUPPORTED : Operation not supported (security type, channel autodetect or WPS not supported)
  - ARM_DRIVER_ERROR_PARAMETER : Parameter error (invalid interface, NULL config pointer or invalid configuration)

The function ARM_WIFI_Activate activates the specified interface.

The argument interface specifies the interface (0 = Station, 1 = Access Point).

When station interface is specified, the WiFi module connects to a wireless network.

The wireless network trying to connect to must be available, otherwise the operation will fail after a timeout.

Available wireless networks can be scanned by using the function ARM_WIFI_Scan.

When access point interface is specified, the WiFi module creates a wireless network by activating the access point.

The argument config is a pointer to the configuration ARM_WIFI_CONFIG_t which provides information needed to connect to a WiFi network for station interface or information used to configure the access point (AP) for access point interface.

ssid specifies the name of the network to connect to or the network to create.

pass specifies the password for accessing the wireless network.

security specifies the security type which will be used for the connection.

ch specifies the WiFi channel which will be used for the connection. Valid channels for 2.4 GHz frequency are from 1 to 13. If the value for ch = 0, the system automatically selects the channel. For station interface the channel of the AP being connected to is used. For access point interface the module automatically selects the best channel for the WiFi connection.

Note
  Optionally BSSID parameter can be also set using ARM_WIFI_SetOption. It allows connection to specific BSSID when connecting to an access point or specifies the BSSID of the access point.

wps_method specifies if WiFi Protected Setup (WPS) is used and which method.

wps_pin specifies the PIN used with WPS (ARM_WIFI_WPS_METHOD_PIN).

With the push-button method, you typically press the button, either real or virtual, both at the access point and the station. No credentials are needed.

With PIN method, you must provide the PIN code that you read from the label or screen on the wireless device.

WPS configuration for station is used when station connects to an access point. It enables to connect without specifying SSID, Password, Security Type or WiFi Channel. The actual network information can be retrieved once connected with ARM_WIFI_GetNetInfo.

WPS configuration for access point is used when access point is activated. Subsequent activate calls re-trigger the WPS procedure.

Note
  WPS is typically activated by pressing the WPS button at the access point. During the discovery mode (usually 2 minutes or less) any wireless device may connect to the access point (PIN needs to match when PIN method is selected).

Example:

ARM_WIFI_CONFIG_t wifi_config;
wifi_config.ssid = "GuestAccess";
wifi_config.pass = "guest";
wifi_config.security = ARM_WIFI_SECURITY_WPA2;
wifi_config.ch = 0U;
wifi_config.wps_method = ARM_WIFI_WPS_METHOD_NONE;
// Connect to wireless network
status = wifi->Activate (0U, &wifi_config);
if (status != ARM_DRIVER_OK) {
// error handling
}
ARM_DRIVER_OK
#define ARM_DRIVER_OK
Operation succeeded.
ARM_WIFI_CONFIG_t::pass
const char * pass
Pointer to Password null-terminated string.
Definition: Driver_WiFi.h:100
ARM_WIFI_CONFIG_t::ssid
const char * ssid
Pointer to Service Set Identifier (SSID) null-terminated string.
Definition: Driver_WiFi.h:99
ARM_WIFI_CONFIG_t::security
uint8_t security
Security type (ARM_WIFI_SECURITY_xxx)
Definition: Driver_WiFi.h:101
ARM_WIFI_CONFIG_t::wps_method
uint8_t wps_method
WiFi Protected Setup (WPS) method (ARM_WIFI_WPS_METHOD_xxx)
Definition: Driver_WiFi.h:104
ARM_WIFI_CONFIG_t::ch
uint8_t ch
WiFi Channel (0 = auto, otherwise = exact channel)
Definition: Driver_WiFi.h:102
ARM_WIFI_CONFIG_t
WiFi Configuration.
Definition: Driver_WiFi.h:98
ARM_WIFI_SECURITY_WPA2
#define ARM_WIFI_SECURITY_WPA2
WiFi Protected Access II (WPA2) with PSK.
ARM_WIFI_WPS_METHOD_NONE
#define ARM_WIFI_WPS_METHOD_NONE
Not used.

## ◆ ARM_WIFI_Deactivate()

int32_t ARM_WIFI_Deactivate | ( | uint32_t | interface | ) |

Deactivate interface (Disconnect from a wireless network or deactivate an access point).

Parameters

  [in] | interface | Interface (0 = Station, 1 = Access Point)

Returns
  execution status
  - ARM_DRIVER_OK : Operation successful
  - ARM_DRIVER_ERROR : Operation failed
  - ARM_DRIVER_ERROR_PARAMETER : Parameter error (invalid interface)

The function ARM_WIFI_Deactivate deactivates the specified interface.

The argument interface specifies the interface (0 = Station, 1 = Access Point).

When station interface is specified, the WiFi module disconnects from the wireless network.

When access point interface is specified, the WiFi module deactivates the access point.

Example:

- see ARM_WIFI_GetNetInfo

## ◆ ARM_WIFI_IsConnected()

uint32_t ARM_WIFI_IsConnected | ( | void |  | ) |

Get station connection status.

Returns
  station connection status
  - value != 0: Station connected
  - value = 0: Station not connected

The function ARM_WIFI_IsConnected checks if the station is connected to a wireless network and returns the connection status.

The function returns a non-zero value, if the station is connected. If the station is not connected, the function returns 0.

Example:

- see ARM_WIFI_GetNetInfo

## ◆ ARM_WIFI_GetNetInfo()

int32_t ARM_WIFI_GetNetInfo | ( | ARM_WIFI_NET_INFO_t * | net_info | ) |

Get station Network Information.

Parameters

  [out] | net_info | Pointer to ARM_WIFI_NET_INFO_t structure where station Network Information will be returned

Returns
  execution status
  - ARM_DRIVER_OK : Operation successful
  - ARM_DRIVER_ERROR : Operation failed (station not connected)
  - ARM_DRIVER_ERROR_UNSUPPORTED : Operation not supported
  - ARM_DRIVER_ERROR_PARAMETER : Parameter error (invalid interface or NULL net_info pointer)

The function ARM_WIFI_GetNetInfo retrieves wireless network information of a connected station.

It can be used to retrieve network connection information for subsequent connections after initially connecting using WPS.

Example:

ARM_WIFI_CONFIG_t wifi_config;
ARM_WIFI_NET_INFO_t net_info;
memset(&wifi_config, 0, sizeof(wifi_config));
wifi_config.wps_method = ARM_WIFI_WPS_METHOD_PBC;
// Connect to wireless network (WPS)
status = wifi->Activate (0U, &wifi_config);
if (status != ARM_DRIVER_OK) {
// error handling
}
// Retrieve network information
if (wifi->IsConnected ()) {
status = wifi->GetNetInfo (&net_info);
if (status != ARM_DRIVER_OK) {
// error handling
}
printf("SSID=%s, Password=%s",net_info.ssid, net_info.pass);
}
// Disconnect from wireless network
wifi->Deactivate (0U);
ARM_WIFI_NET_INFO_t::pass
char pass[64+1]
Password null-terminated string.
Definition: Driver_WiFi.h:124
ARM_WIFI_NET_INFO_t::ssid
char ssid[32+1]
Service Set Identifier (SSID) null-terminated string.
Definition: Driver_WiFi.h:123
ARM_WIFI_NET_INFO_t
WiFi Network Information.
Definition: Driver_WiFi.h:122
ARM_WIFI_WPS_METHOD_PBC
#define ARM_WIFI_WPS_METHOD_PBC
Push Button Configuration.