Skip to content

Wireless LAN ​

Wireless LAN API.

The implementation supports station- and access-point mode. If they can both be used individually or even at the same time depends on the underlying chipset.

Sysprops ​

The Wireless LAN driver does not have any sysprops defined.

Types ​

Name
structwlan_ap_info_t
enumwlan_ioctl_t
enumwlan_security_mode_t
enumwlan_connection_state_t
enumwlan_interface_type_t
typedef void(*)(int)wlan_status_handler_t

Functions Overview ​

Name
CW_DRIVER_FUNCwlan_register_status_handler(int hDev, wlan_status_handler_t handler)
WLAN driver API minimum API for WLAN drivers.
CW_DRIVER_FUNCwlan_connect(int hDev, uint8_t * ssid, uint8_t * bssid, wlan_security_mode_t sec_type, void * secret_key, bool synchronous)
connects the WLAN subsystem to the AP with the specified ssid
CW_DRIVER_FUNCwlan_disconnect(int hDev)
disconnects the WLAN subsystem from an AP
CW_DRIVER_FUNCwlan_connection_state(int hDev, wlan_connection_state_t * state)
get the current state (connecting/connected/disconnected)
CW_DRIVER_FUNCwlan_get_hwaddr(int hDev, uint8_t * addr, uint8_t addr_len, wlan_interface_type_t interface)
retrieve the WLAN hardware MAC address
CW_DRIVER_FUNCwlan_scan(int hDev, uint8_t * ssid, uint8_t chno, wlan_ap_info_t * result, uint32_t * num_result, uint32_t max_result)
scans for available WLAN APs.
CW_DRIVER_FUNCwlan_start_ap(int hDev, uint16_t channel, uint8_t * ssid, uint32_t ssid_length, uint8_t hide_ssid, wlan_security_mode_t sec_type, uint8_t * passkey, uint16_t passkey_length)
opens an access-point for external clients to connect to.
CW_DRIVER_FUNCwlan_stop_ap(int hDev)
close a previously started access-point.

Defines ​

Name
SSID_MAX_LEN

Types Documentation ​

enum wlan_ioctl_t ​

EnumeratorDescription
WLAN_IOCTL_HOSTNAMEHostname.
WLAN_IOCTL_SCAN_TYPEScanType.

enum wlan_security_mode_t ​

EnumeratorDescription
WLAN_SEC_MODE_OPENNO security.
WLAN_SEC_MODE_WEPWEP Security with PSK.
WLAN_SEC_MODE_WPAWPA security with PSK.
WLAN_SEC_MODE_WPA2WPA2 security with PSK.
WLAN_SEC_MODE_WPA3WPA3 security with PSK.

enum wlan_connection_state_t ​

EnumeratorDescription
WLAN_STATE_DISCONNECTEDWLAN is currently not connected to an AP.
WLAN_STATE_CONNECTINGWLAN is trying to connect to an AP.
WLAN_STATE_CONNECTEDWLAN is connected to an AP.

enum wlan_interface_type_t ​

EnumeratorDescription
WLAN_STA_INTERFACEWLAN station mode interface.
WLAN_AP_INTERFACEWLAN accespoint-mode interface.

typedef wlan_status_handler_t ​

cpp
typedef void(* wlan_status_handler_t) (int);

Function Details ​

function wlan_register_status_handler ​

cpp
CW_DRIVER_FUNC wlan_register_status_handler(
    int hDev,
    wlan_status_handler_t handler
)

WLAN driver API minimum API for WLAN drivers.

Parameters:

  • hDev device handle as returned by open(const char*)
  • handler handler function to be called upon connection state change.

Return: 0 if the registration succeeded.

registration of a callback that gets invoked when the connecton state changes.

function wlan_connect ​

cpp
CW_DRIVER_FUNC wlan_connect(
    int hDev,
    uint8_t * ssid,
    uint8_t * bssid,
    wlan_security_mode_t sec_type,
    void * secret_key,
    bool synchronous
)

connects the WLAN subsystem to the AP with the specified ssid

Parameters:

  • hDev device handle as returned by open(const char*)
  • ssid identifier of the WLAN AP to connect to. null-terminated string
  • bssid MAC address of the WLAN AP to connect to. needed for WPA3
  • sec_type wlan_security_mode_t to use when connecting
  • secret_key the PSK to authenticate with. null-terminated string, max 63bytes (+ trailing \0)
  • synchronous true = wait for the connection process to complete or fail.

Return: 0 on success.

function wlan_disconnect ​

cpp
CW_DRIVER_FUNC wlan_disconnect(
    int hDev
)

disconnects the WLAN subsystem from an AP

Parameters:

function wlan_connection_state ​

cpp
CW_DRIVER_FUNC wlan_connection_state(
    int hDev,
    wlan_connection_state_t * state
)

get the current state (connecting/connected/disconnected)

Parameters:

Return:

function wlan_get_hwaddr ​

cpp
CW_DRIVER_FUNC wlan_get_hwaddr(
    int hDev,
    uint8_t * addr,
    uint8_t addr_len,
    wlan_interface_type_t interface
)

retrieve the WLAN hardware MAC address

Parameters:

  • hdev device handle as returned by open(const char*)
  • addr caller-allocated buffer.
  • addr_len length of the addr buffer. should be 6.
  • interface get the HW Addr of the STA or SOFTAP interface

function wlan_scan ​

cpp
CW_DRIVER_FUNC wlan_scan(
    int hDev,
    uint8_t * ssid,
    uint8_t chno,
    wlan_ap_info_t * result,
    uint32_t * num_result,
    uint32_t max_result
)

scans for available WLAN APs.

Parameters:

  • hdev device handle as returned by open(const char*)
  • ssid pass an SSID here, if only one network should be scanned for.
  • chno the 2.4GHz channel number to scan. pass 0 to scan all channels
  • result array of wlan_ap_info_t to hold the result of the scan. caller-allocated.
  • num_result number of results returned from the scan.
  • max_result maximum number of networks to return. has to match the size of the passed result-buffer.

Return: 0 if the scan succeeded.

a differentiation beteween active or passive scanning can be configured via ioctl calls, if the HAL implementation supports it.

function wlan_start_ap ​

cpp
CW_DRIVER_FUNC wlan_start_ap(
    int hDev,
    uint16_t channel,
    uint8_t * ssid,
    uint32_t ssid_length,
    uint8_t hide_ssid,
    wlan_security_mode_t sec_type,
    uint8_t * passkey,
    uint16_t passkey_length
)

opens an access-point for external clients to connect to.

Parameters:

  • hDev device handle as returned by open(const char*)
  • channel the 2.4GHz channel the access-point should be started on
  • ssid the SSID the access point should broadcast
  • ssid_length the length of the SSID string
  • hide_ssid if no SSID should be broadcast, but instead the AP should only be discoverable via BSSID, set to true
  • sec_type the wlan_security_mode_t security type the access-point should employ
  • passkey the PSK for connecting to the AP.
  • passkey_length the length of the PSK.

Return: 0 if the access point was successfully started, error-code otherwise.

be aware, that most WLAN chips will only allow a single (or maybe a few) clients to connect to an access point at the same time. This function therefore is mainly used as a means for commissioning of the station-mode WLAN, i.e. to connect the device to an access point with internet connection.

function wlan_stop_ap ​

cpp
CW_DRIVER_FUNC wlan_stop_ap(
    int hDev
)

close a previously started access-point.

Parameters:

Return: 0 if the access point was successfully started, error-code otherwise.

Macros Documentation ​

define SSID_MAX_LEN ​

cpp
#define SSID_MAX_LEN (32)