Wi-Fi network management interface. More...
![]() |
Data Structures | |
struct | hw_wifi_network_t |
Describes a discovered Wi‑Fi network (scan result). More... | |
Enumerations | |
enum | hw_wifi_auth_t { hw_wifi_auth_open = (1 << 0), hw_wifi_auth_wep = (1 << 1), hw_wifi_auth_wpa_tkip = (1 << 2), hw_wifi_auth_wpa_aes = (1 << 3), hw_wifi_auth_wpa2_tkip = (1 << 4), hw_wifi_auth_wpa2_aes = (1 << 5), hw_wifi_auth_wpa3_sae = (1 << 6), hw_wifi_auth_enterprise = (1 << 7) } |
Authentication and cipher modes for Wi‑Fi networks. More... | |
enum | hw_wifi_event_t { hw_wifi_event_scan = (1 << 0), hw_wifi_event_joining = (1 << 1), hw_wifi_event_connected = (1 << 2), hw_wifi_event_disconnected = (1 << 3), hw_wifi_event_badauth, hw_wifi_event_notfound = (1 << 5), hw_wifi_event_error = (1 << 6) } |
Callback events. More... | |
Functions | |
hw_wifi_t * | hw_wifi_init (const char *country_code, hw_wifi_callback_t callback, void *user_data) |
Initialize Wi-Fi management. More... | |
bool | hw_wifi_valid (hw_wifi_t *wifi) |
Determine if the Wi-Fi handle is initialized and usable. More... | |
void | hw_wifi_finalize (hw_wifi_t *wifi) |
Finalize and release any resources. More... | |
bool | hw_wifi_scan (hw_wifi_t *wifi) |
Begin an asynchronous scan for nearby Wi‑Fi networks. More... | |
bool | hw_wifi_connect (hw_wifi_t *wifi, const hw_wifi_network_t *network, const char *password) |
Begin an asynchronous connection to a Wi‑Fi network. More... | |
bool | hw_wifi_disconnect (hw_wifi_t *wifi) |
Disconnect from a previously-connected Wi‑Fi network. More... | |
Wi-Fi network management interface.
The Wi-Fi management interface provides discovery of, and connection to networks with authentication. The three main methods for connecting, disconnecting and scanning are asynchronous and call the provided callback function to update operation status.
When connecting, the callback will be invoked with the current status of the connection attempt, including any relevant network information. The callback will then be called occasionally with updates on the connection status (for example, the signal strength).
When scanning, the callback will be invoked with the results of the scan, including information about any discovered networks. The scan is completed when the callback is invoked with a NULL network pointer.
enum hw_wifi_auth_t |
Authentication and cipher modes for Wi‑Fi networks.
Bitmask describing the advertised/required authentication/cipher modes. Multiple bits may be set if a network supports more than one.
Definition at line 45 of file wifi.h.
enum hw_wifi_event_t |
Callback events.
Definition at line 60 of file wifi.h.
bool hw_wifi_connect | ( | hw_wifi_t * | wifi, |
const hw_wifi_network_t * | network, | ||
const char * | password | ||
) |
Begin an asynchronous connection to a Wi‑Fi network.
wifi | Initialized Wi‑Fi handle. |
network | Target network to connect to (SSID, BSSID, etc). |
password | NUL‑terminated password string (may be empty for open networks). |
Initiates a non‑blocking connection attempt to the specified network using the provided password. The callback will be invoked to report connection progress and completion. The function returns immediately.
The ssid and auth parameters must be filled in by the caller, and the bssid parameter can optionally be set to the BSSID of the target access point (if known).
The password
must be a NUL‑terminated string (may be empty or NULL for open networks).
Only one connection attempt may be active at a time per Wi‑Fi handle, and false will be returned if a connection attempt or scanning is already in progress.
bool hw_wifi_disconnect | ( | hw_wifi_t * | wifi | ) |
Disconnect from a previously-connected Wi‑Fi network.
wifi | Initialized Wi‑Fi handle. |
Initiates a disconnect from the current network. The function returns immediately. If not currently connected, this is a no‑op, and if a connection attempt or scan is in progress, it will be aborted and false will be returned.
void hw_wifi_finalize | ( | hw_wifi_t * | wifi | ) |
Finalize and release any resources.
wifi | Wi-Fi handle |
Safe to call on an already finalized; in that case it is a no‑op. After finalization, hw_wifi_valid() returns false.
hw_wifi_t* hw_wifi_init | ( | const char * | country_code, |
hw_wifi_callback_t | callback, | ||
void * | user_data | ||
) |
Initialize Wi-Fi management.
country_code | Country code for the Wi-Fi region (e.g., "US", "EU"). If NULL, defaults to "XX" (worldwide). |
callback | Callback to notify progress/completion of connection, disconnection and scanning asyncronous operations (must not be NULL). |
user_data | Opaque user pointer supplied to the callback. |
This function initializes the Wi-Fi management subsystem and returns a handle to the Wi-Fi instance. If initialization fails (for example, if WiFi is not available), it returns NULL.
bool hw_wifi_scan | ( | hw_wifi_t * | wifi | ) |
Begin an asynchronous scan for nearby Wi‑Fi networks.
wifi | Initialized Wi‑Fi handle. |
Starts a non‑blocking scan. The provided callback
will be invoked for each result (network != NULL) and once more with network == NULL when the scan completes. The function returns immediately.
If a operation (connection, disconnection or scanning) is already in progress or Wi‑Fi is disconnected, the function returns false and no callback will be invoked.
bool hw_wifi_valid | ( | hw_wifi_t * | wifi | ) |
Determine if the Wi-Fi handle is initialized and usable.
wifi | Wi-Fi handle |