Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Wi-Fi credentials library

Library that provides a way to store and load Wi-Fi credentials. More...

Files

file  wifi_credentials.h
 Library for storing and loading Wi-Fi credentials.

Data Structures

struct  wifi_credentials_header
 Wi-Fi credentials entry header. More...
struct  wifi_credentials_personal
 Wi-Fi Personal credentials entry. More...
struct  wifi_credentials_enterprise
 Wi-Fi Enterprise credentials entry. More...

Macros

#define WIFI_CREDENTIALS_FLAG_BSSID   BIT(0)
 This entry contains a BSSID.
#define WIFI_CREDENTIALS_FLAG_FAVORITE   BIT(1)
 This entry is to be preferred over others.
#define WIFI_CREDENTIALS_FLAG_2_4GHz   BIT(2)
 This entry can use the 2.4 GHz band.
#define WIFI_CREDENTIALS_FLAG_5GHz   BIT(3)
 This entry can use the 5 GHz band.
#define WIFI_CREDENTIALS_FLAG_6GHz   BIT(4)
 This entry can use the 6 GHz band.
#define WIFI_CREDENTIALS_FLAG_MFP_REQUIRED   BIT(5)
 This entry requires management frame protection.
#define WIFI_CREDENTIALS_FLAG_MFP_DISABLED   BIT(6)
 This entry disables management frame protection.
#define WIFI_CREDENTIALS_FLAG_ANONYMOUS_IDENTITY   BIT(7)
 This entry has anonymous identity configured.
#define WIFI_CREDENTIALS_FLAG_KEY_PASSWORD   BIT(8)
 This entry has key password configured.
#define WIFI_CREDENTIALS_MAX_PASSWORD_LEN   MAX(WIFI_PSK_MAX_LEN, CONFIG_WIFI_CREDENTIALS_SAE_PASSWORD_LENGTH)
 Maximum length of the password.

Typedefs

typedef void(* wifi_credentials_ssid_cb) (void *cb_arg, const char *ssid, size_t ssid_len)
 Callback type for wifi_credentials_for_each_ssid.

Functions

int wifi_credentials_get_by_ssid_personal (const char *ssid, size_t ssid_len, enum wifi_security_type *type, uint8_t *bssid_buf, size_t bssid_buf_len, char *password_buf, size_t password_buf_len, size_t *password_len, uint32_t *flags, uint8_t *channel, uint32_t *timeout)
 Get credentials for given SSID.
int wifi_credentials_set_personal (const char *ssid, size_t ssid_len, enum wifi_security_type type, const uint8_t *bssid, size_t bssid_len, const char *password, size_t password_len, uint32_t flags, uint8_t channel, uint32_t timeout)
 Set credentials for given SSID.
int wifi_credentials_get_by_ssid_personal_struct (const char *ssid, size_t ssid_len, struct wifi_credentials_personal *buf)
 Get credentials for given SSID by struct.
int wifi_credentials_set_personal_struct (const struct wifi_credentials_personal *creds)
 Set credentials for given SSID by struct.
int wifi_credentials_delete_by_ssid (const char *ssid, size_t ssid_len)
 Delete credentials for given SSID.
bool wifi_credentials_is_empty (void)
 Check if credentials storage is empty.
int wifi_credentials_delete_all (void)
 Deletes all stored Wi-Fi credentials.
void wifi_credentials_for_each_ssid (wifi_credentials_ssid_cb cb, void *cb_arg)
 Call callback for each registered SSID.

Detailed Description

Library that provides a way to store and load Wi-Fi credentials.

Since
4.0
Version
0.1.0

Macro Definition Documentation

◆ WIFI_CREDENTIALS_FLAG_2_4GHz

#define WIFI_CREDENTIALS_FLAG_2_4GHz   BIT(2)

#include <zephyr/net/wifi_credentials.h>

This entry can use the 2.4 GHz band.

◆ WIFI_CREDENTIALS_FLAG_5GHz

#define WIFI_CREDENTIALS_FLAG_5GHz   BIT(3)

#include <zephyr/net/wifi_credentials.h>

This entry can use the 5 GHz band.

◆ WIFI_CREDENTIALS_FLAG_6GHz

#define WIFI_CREDENTIALS_FLAG_6GHz   BIT(4)

#include <zephyr/net/wifi_credentials.h>

This entry can use the 6 GHz band.

◆ WIFI_CREDENTIALS_FLAG_ANONYMOUS_IDENTITY

#define WIFI_CREDENTIALS_FLAG_ANONYMOUS_IDENTITY   BIT(7)

#include <zephyr/net/wifi_credentials.h>

This entry has anonymous identity configured.

◆ WIFI_CREDENTIALS_FLAG_BSSID

#define WIFI_CREDENTIALS_FLAG_BSSID   BIT(0)

#include <zephyr/net/wifi_credentials.h>

This entry contains a BSSID.

◆ WIFI_CREDENTIALS_FLAG_FAVORITE

#define WIFI_CREDENTIALS_FLAG_FAVORITE   BIT(1)

#include <zephyr/net/wifi_credentials.h>

This entry is to be preferred over others.

◆ WIFI_CREDENTIALS_FLAG_KEY_PASSWORD

#define WIFI_CREDENTIALS_FLAG_KEY_PASSWORD   BIT(8)

#include <zephyr/net/wifi_credentials.h>

This entry has key password configured.

◆ WIFI_CREDENTIALS_FLAG_MFP_DISABLED

#define WIFI_CREDENTIALS_FLAG_MFP_DISABLED   BIT(6)

#include <zephyr/net/wifi_credentials.h>

This entry disables management frame protection.

◆ WIFI_CREDENTIALS_FLAG_MFP_REQUIRED

#define WIFI_CREDENTIALS_FLAG_MFP_REQUIRED   BIT(5)

#include <zephyr/net/wifi_credentials.h>

This entry requires management frame protection.

◆ WIFI_CREDENTIALS_MAX_PASSWORD_LEN

#define WIFI_CREDENTIALS_MAX_PASSWORD_LEN   MAX(WIFI_PSK_MAX_LEN, CONFIG_WIFI_CREDENTIALS_SAE_PASSWORD_LENGTH)

#include <zephyr/net/wifi_credentials.h>

Maximum length of the password.

Typedef Documentation

◆ wifi_credentials_ssid_cb

typedef void(* wifi_credentials_ssid_cb) (void *cb_arg, const char *ssid, size_t ssid_len)

#include <zephyr/net/wifi_credentials.h>

Callback type for wifi_credentials_for_each_ssid.

Parameters
[in]cb_argarguments for the callback function. Appropriate cb_arg is transferred by wifi_credentials_for_each_ssid.
[in]ssidSSID
[in]ssid_lenlength of SSID

Function Documentation

◆ wifi_credentials_delete_all()

int wifi_credentials_delete_all ( void )

#include <zephyr/net/wifi_credentials.h>

Deletes all stored Wi-Fi credentials.

This function deletes all Wi-Fi credentials that have been stored in the system. It is typically used when you want to clear all saved networks. It also deletes the stored entries that could not be loaded, so it can be used to recover when the other functions return -EACCES. An entry that the backend can neither load nor remove is left in storage and its slot is not used.

Returns
0 on successful, otherwise a negative error code

◆ wifi_credentials_delete_by_ssid()

int wifi_credentials_delete_by_ssid ( const char * ssid,
size_t ssid_len )

#include <zephyr/net/wifi_credentials.h>

Delete credentials for given SSID.

Parameters
[in]ssidSSID to look for
[in]ssid_lenlength of SSID
Returns
-ENOENT if No network with this SSID was found.
-EACCES if the stored credentials could not be loaded.
0 on success, otherwise a negative error code

◆ wifi_credentials_for_each_ssid()

void wifi_credentials_for_each_ssid ( wifi_credentials_ssid_cb cb,
void * cb_arg )

#include <zephyr/net/wifi_credentials.h>

Call callback for each registered SSID.

If the stored credentials could not be loaded, the callback is not called.

Parameters
cbcallback
cb_argargument for callback function

◆ wifi_credentials_get_by_ssid_personal()

int wifi_credentials_get_by_ssid_personal ( const char * ssid,
size_t ssid_len,
enum wifi_security_type * type,
uint8_t * bssid_buf,
size_t bssid_buf_len,
char * password_buf,
size_t password_buf_len,
size_t * password_len,
uint32_t * flags,
uint8_t * channel,
uint32_t * timeout )

#include <zephyr/net/wifi_credentials.h>

Get credentials for given SSID.

Parameters
[in]ssidSSID to look for
[in]ssid_lenlength of SSID
[out]typeWi-Fi security type
[out]bssid_bufbuffer to store BSSID if it was fixed
[in]bssid_buf_lenlength of bssid_buf
[out]password_bufbuffer to store password
[in]password_buf_lenlength of password_buf
[out]password_lenlength of password
[out]flagsflags
[out]channelchannel
[out]timeouttimeout
Returns
0 Success.
-ENOENT No network with this SSID was found.
-EINVAL A required buffer was NULL or invalid SSID length.
-EPROTO The network with this SSID is not a personal network.
-EACCES The stored credentials could not be loaded.

◆ wifi_credentials_get_by_ssid_personal_struct()

int wifi_credentials_get_by_ssid_personal_struct ( const char * ssid,
size_t ssid_len,
struct wifi_credentials_personal * buf )

#include <zephyr/net/wifi_credentials.h>

Get credentials for given SSID by struct.

Parameters
[in]ssidSSID to look for
[in]ssid_lenlength of SSID
[out]bufcredentials Pointer to struct where credentials are stored
Returns
0 Success.
-ENOENT No network with this SSID was found.
-EINVAL A required buffer was NULL or too small.
-EPROTO The network with this SSID is not a personal network.
-EACCES The stored credentials could not be loaded.

◆ wifi_credentials_is_empty()

bool wifi_credentials_is_empty ( void )

#include <zephyr/net/wifi_credentials.h>

Check if credentials storage is empty.

If the stored credentials could not be loaded, the storage is reported as empty.

Returns
true if credential storage is empty, otherwise false

◆ wifi_credentials_set_personal()

int wifi_credentials_set_personal ( const char * ssid,
size_t ssid_len,
enum wifi_security_type type,
const uint8_t * bssid,
size_t bssid_len,
const char * password,
size_t password_len,
uint32_t flags,
uint8_t channel,
uint32_t timeout )

#include <zephyr/net/wifi_credentials.h>

Set credentials for given SSID.

Note
Storing credentials for an SSID that is already stored overwrites the existing entry rather than adding a second one. Only distinct SSIDs consume storage slots.
Parameters
[in]ssidSSID to look for
[in]ssid_lenlength of SSID
[in]typeWi-Fi security type
[in]bssidBSSID (may be NULL)
[in]bssid_lenlength of BSSID buffer (either 0 or WIFI_MAC_ADDR_LEN)
[in]passwordpassword
[in]password_lenlength of password
[in]flagsflags
[in]channelChannel
[in]timeoutTimeout
Returns
0 Success. Credentials are stored in persistent storage.
-EINVAL A required buffer was NULL or security type is not supported.
-ENOTSUP Security type is not supported.
-ENOBUFS All slots are already taken.
-EACCES The stored credentials could not be loaded.

◆ wifi_credentials_set_personal_struct()

int wifi_credentials_set_personal_struct ( const struct wifi_credentials_personal * creds)

#include <zephyr/net/wifi_credentials.h>

Set credentials for given SSID by struct.

Note
Storing credentials for an SSID that is already stored overwrites the existing entry rather than adding a second one. Only distinct SSIDs consume storage slots.
Parameters
[in]credscredentials Pointer to struct from which credentials are loaded
Returns
0 Success.
-ENOENT No network with this SSID was found.
-EINVAL A required buffer was NULL or incorrect size.
-ENOBUFS All slots are already taken.
-EACCES The stored credentials could not be loaded.