Wi-Fi network management interface. More...
|
Data Structures | |
| struct | hw_wifi_network_t |
| Describes a discovered Wi-Fi network (scan result). More... | |
Macros | |
| #define | HW_WIFI_SSID_MAX_LENGTH 32 |
| Maximum SSID length in bytes, excluding the NULL terminator. | |
Typedefs | |
| typedef struct hw_wifi_t | hw_wifi_t |
| Opaque Wi-Fi handle. | |
| typedef void(* | hw_wifi_callback_t) (hw_wifi_t *wifi, hw_wifi_event_t event, const hw_wifi_network_t *network, void *userdata) |
| Callback invoked for Wi-Fi operation notifications. 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 = (1 << 4), hw_wifi_event_notfound = (1 << 5), hw_wifi_event_error = (1 << 6), hw_wifi_event_status = (1 << 7) } |
| Wi-Fi callback event flags. More... | |
Lifecycle | |
| hw_wifi_t * | hw_wifi_init_client (const char *country_code, hw_wifi_callback_t callback, void *userdata) |
| Initialize Wi-Fi as a client. More... | |
| hw_wifi_t * | hw_wifi_init_accesspoint (const char *country_code, const char *ssid, const char *password, hw_wifi_auth_t auth) |
| Initialize Wi-Fi as an access point. More... | |
| hw_wifi_t * | hw_wifi_init_device (const char *device, hw_wifi_callback_t callback, void *userdata) |
| Initialize Wi-Fi from a WPA supplicant device. More... | |
| void | hw_wifi_deinit (hw_wifi_t *wifi) |
| Deinitialize and release a Wi-Fi handle. More... | |
Methods | |
| 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.
A handle operates in one of two mutually exclusive modes, chosen by which init function created it and fixed for that handle's lifetime - there's no way to switch an existing handle from one mode to the other, only to hw_wifi_deinit() it and init a new one in the other mode:
When connecting (station mode only), 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 (station mode only), 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.
| typedef void(* hw_wifi_callback_t) (hw_wifi_t *wifi, hw_wifi_event_t event, const hw_wifi_network_t *network, void *userdata) |
Callback invoked for Wi-Fi operation notifications.
| wifi | The Wi-Fi handle associated with the operation. |
| event | The event type (see hw_wifi_event_t). |
| network | When event is hw_wifi_event_scan, this contains a pointer to the current scan result, or NULL to indicate the scan operation has completed. |
| userdata | User-defined data pointer supplied when the operation started. |
This callback is used when connecting or disconnecting from a network, and when scanning for networks.
| 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 60 of file wifi.h.
| enum hw_wifi_event_t |
Wi-Fi callback event flags.
Definition at line 75 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, from hw_wifi_init_client() or hw_wifi_init_device() - not hw_wifi_init_accesspoint(), see below. |
| network | Target network to connect to (SSID, BSSID, etc). |
| password | NUL-terminated password string. May be NULL or empty for open networks. |
| true | Connection attempt was started. |
| false | Handle or network is invalid, wifi is an access-point handle, or an operation (connection, disconnection or scanning) is already in progress. |
Initiates a non-blocking connection attempt to the specified network using the provided password. The handle's callback is invoked to report connection progress and completion. This function returns immediately.
The bssid field of network can optionally be set to the BSSID of the target access point, if known.
A handle from hw_wifi_init_accesspoint() always fails here - an access point doesn't join other networks; other devices join it.
| void hw_wifi_deinit | ( | hw_wifi_t * | wifi | ) |
Deinitialize and release a Wi-Fi handle.
| wifi | Wi-Fi handle. |
Safe to call on NULL. Requests that any in-progress connection, disconnection or scan stop first, but whether that request can actually interrupt an operation already under way is backend-dependent - some backends have no way to cancel a scan/connect once started (see hw_wifi_disconnect()'s own doc), in which case a callback for the old operation may still arrive after this call returns, referencing a handle that's already been released.
| bool hw_wifi_disconnect | ( | hw_wifi_t * | wifi | ) |
Disconnect from a previously-connected Wi-Fi network.
| wifi | Initialized Wi-Fi handle, from hw_wifi_init_client() or hw_wifi_init_device() - not hw_wifi_init_accesspoint(), see below. |
| true | Disconnect was initiated. |
| false | Handle is invalid, is an access-point handle, or not currently connected, connecting or scanning. |
Initiates a disconnect from the current network, or requests that an in-progress connection attempt or scan stop. This function returns immediately, but whether an in-progress operation can actually be interrupted is backend-dependent - some backends have no cancellation mechanism for a scan/connect already under way, in which case it runs to completion regardless and still delivers its own callback for whatever it was doing when this was called.
A handle from hw_wifi_init_accesspoint() always fails here - there is no "current network" for an access point to leave. Use hw_wifi_deinit() to stop broadcasting instead.
| hw_wifi_t* hw_wifi_init_accesspoint | ( | const char * | country_code, |
| const char * | ssid, | ||
| const char * | password, | ||
| hw_wifi_auth_t | auth | ||
| ) |
Initialize Wi-Fi as an access point.
| country_code | Country code for the Wi-Fi region (e.g. "US", "EU"). If NULL, defaults to "XX" (worldwide). |
| ssid | SSID to broadcast. Must not be NULL, and must not exceed HW_WIFI_SSID_MAX_LENGTH bytes. |
| password | NUL-terminated password string. May be NULL or empty only when auth is hw_wifi_auth_open. |
| auth | Authentication mode the access point requires. This selects exactly one mode, unlike hw_wifi_network_t's own auth field, which reports every mode a scanned network advertises support for. |
ssid/auth are invalid, or another handle is already live (see hw_wifi_t).Unlike hw_wifi_init_client()/hw_wifi_init_device(), this puts the radio into access-point mode - other devices connect to it, rather than it connecting to an existing network. Supported only where the backend's radio can run in AP mode (the CYW43 chip on Pico W/2W boards); NULL elsewhere.
There's no callback parameter: unlike station mode, backends have no way to report individual stations joining or leaving an access point (confirmed on Pico - the CYW43 driver's own low-level per-station association event handling for AP mode isn't wired up, and attempting to read the AP's aggregate link status from the polling loop was found to reliably deadlock the driver on real hardware). The access point itself stays up silently from here until hw_wifi_deinit().
| hw_wifi_t* hw_wifi_init_client | ( | const char * | country_code, |
| hw_wifi_callback_t | callback, | ||
| void * | userdata | ||
| ) |
Initialize Wi-Fi as a client.
| 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 asynchronous operations (must not be NULL). |
| userdata | User-defined data pointer forwarded to callback. |
| hw_wifi_t* hw_wifi_init_device | ( | const char * | device, |
| hw_wifi_callback_t | callback, | ||
| void * | userdata | ||
| ) |
Initialize Wi-Fi from a WPA supplicant device.
| device | Device identifier for the Wi-Fi interface, e.g. /var/run/wpa_supplicant/wlan0. |
| callback | Callback to notify progress/completion of connection, disconnection and scanning asynchronous operations (must not be NULL). |
| userdata | User-defined data pointer forwarded to callback. |
This entry point is intended for platforms where Wi-Fi is managed by a system service (wpa_supplicant) reachable over a control socket, rather than a radio directly driven by this process - on Linux, the standard way to manage Wi-Fi. Unsupported elsewhere.
| bool hw_wifi_scan | ( | hw_wifi_t * | wifi | ) |
Begin an asynchronous scan for nearby Wi-Fi networks.
| wifi | Initialized Wi-Fi handle, from hw_wifi_init_client() or hw_wifi_init_device() - not hw_wifi_init_accesspoint(), see below. |
| true | Scan was started. |
| false | Handle is invalid, is an access-point handle, or an operation (connection, disconnection or scanning) is already in progress. |
Starts a non-blocking scan. The handle's callback is invoked once per result (network != NULL) and once more with network == NULL when the scan completes. This function returns immediately.
A handle from hw_wifi_init_accesspoint() always fails here - scanning requires the radio to be in station mode.