[ English | 简体中文 ]
Wireless Network Interface (WAPI) API
The wapi_* series of interfaces is a wrapper around Linux Wireless Extensions (WEXT), providing wireless network configuration, scanning, association, power management, country code, and PMKSA cache capabilities.
Header: #include <wireless/wapi.h>
openvela Implementation Notes
- Underlying mechanism: Communicates with Wi-Fi drivers via the ioctl protocol of Linux Wireless Extensions (WEXT)
- Supported scenarios: Station (client) mode, AP mode, and promiscuous mode (depending on driver support)
- Configuration dependency: Requires
CONFIG_WIRELESS_WAPIand the corresponding Wi-Fi chip driver to be enabled - Typical usage:
wapi_set_ifup/wapi_set_ifdownto bring the interface up or downwapi_set_essid+wapi_set_modeto configure the connection targetwapi_scan_*/wapi_escan_*to scan surrounding APswapi_load_config/wapi_save_configto persist configuration
- Extended capabilities: Interact with driver-specific features via interfaces such as
wapi_extend_params/wapi_set_pmksa
Wireless Network Interface
Header: #include <wireless/wapi.h>
wapi provides wireless network configuration interfaces, including SSID scanning, connection, and frequency setting.
Connection Management
wapi_get_ifup
int wapi_get_ifup(int sock, const char *ifname, int *is_up);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.is_upInterface status; 0 means enabled, 1 means disabled.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_set_ifup
int wapi_set_ifup(int sock, const char *ifname);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_set_ifdown
int wapi_set_ifdown(int sock, const char *ifname);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name to be brought down.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_get_ip
int wapi_get_ip(int sock, const char *ifname, struct in_addr *addr);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.addrOutput parameter.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_set_ip
int wapi_set_ip(int sock, const char *ifname, const struct in_addr *addr);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name whose IP address is set.addrPointer to the structure containing the new IP address.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_get_netmask
int wapi_get_netmask(int sock, const char *ifname, struct in_addr *addr);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.addrOutput parameter.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_set_netmask
int wapi_set_netmask(int sock, const char *ifname, const struct in_addr *addr);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.addrPointer to the structure containing the new subnet mask.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_add_route_gw
int wapi_add_route_gw(int sock, enum wapi_route_target_e targettype, const struct in_addr *target, const struct in_addr *netmask, const struct in_addr *gw);
Parameters:
sockSocket descriptor (used for ioctl operations).targettypeTarget type.targetPointer to the target IP address.netmaskPointer to the subnet mask corresponding to the target address.gwPointer to the corresponding gateway (router) IP address, used for routing.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_del_route_gw
int wapi_del_route_gw(int sock, enum wapi_route_target_e targettype, const struct in_addr *target, const struct in_addr *netmask, const struct in_addr *gw);
Parameters:
sockSocket descriptor (used for ioctl operations).targettypeTarget type.targetPointer to the target IP address of the route.netmaskPointer to the subnet mask corresponding to the target address.gwPointer to the corresponding gateway (router) IP address, used for routing.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_get_freq
int wapi_get_freq(int sock, const char *ifname, double *freq, enum wapi_freq_flag_e *flag);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.freqOutput parameter.flagOutput parameter.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_set_freq
int wapi_set_freq(int sock, const char *ifname, double freq, enum wapi_freq_flag_e flag);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.freqFrequency value.flagFrequency value.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_freq2chan
int wapi_freq2chan(int sock, const char *ifname, double freq, int *chan);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.freqFrequency, in Hz, to be converted to a channel number.chanOutput parameter.
wapi_chan2freq
int wapi_chan2freq(int sock, const char *ifname, int chan, double *freq);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameChannel.chanChannel number to be converted to a frequency.freqOutput parameter.
wapi_get_essid
int wapi_get_essid(int sock, const char *ifname, char *essid, enum wapi_essid_flag_e *flag);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.essidUsed to store the result.flagOutput parameter.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_set_essid
int wapi_set_essid(int sock, const char *ifname, const char *essid, enum wapi_essid_flag_e flag);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.essidPointer to a\0-terminated ESSID string.flagControl flag.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_get_mode
int wapi_get_mode(int sock, const char *ifname, enum wapi_mode_e *mode);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.modeOutput parameter.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_set_mode
int wapi_set_mode(int sock, const char *ifname, enum wapi_mode_e mode);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.modeOutput parameter.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_make_broad_ether
int wapi_make_broad_ether(struct ether_addr *sa);
Parameters:
saOutput parameter.
Returns:
Returns the result of the underlying wapi_make_ether() call.
wapi_make_null_ether
int wapi_make_null_ether(struct ether_addr *sa);
Parameters:
saOutput parameter.
Returns:
Returns the result of the underlying wapi_make_ether() call.
wapi_get_ap
int wapi_get_ap(int sock, const char *ifname, struct ether_addr *ap);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.apAddress to set.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_set_ap
int wapi_set_ap(int sock, const char *ifname, const struct ether_addr *ap);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.apMAC address of the access point.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_get_bitrate
int wapi_get_bitrate(int sock, const char *ifname, int *bitrate, enum wapi_bitrate_flag_e *flag);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.bitrateOutput parameter for the retrieved bitrate.flagOutput parameter for the bitrate flag bits.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_set_bitrate
int wapi_set_bitrate(int sock, const char *ifname, int bitrate, enum wapi_bitrate_flag_e flag);
Parameters:
sockSocket descriptor (used for ioctl operations).ifnameNetwork interface name.bitrateBitrate.flagBitrate flag.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_dbm2mwatt
int wapi_dbm2mwatt(int dbm);
Parameters:
dbmdBm value to convert.
Returns:
The converted milliwatt value.
wapi_mwatt2dbm
int wapi_mwatt2dbm(int mwatt);
Parameters:
mwattMilliwatt value.
Returns:
The converted dBm value.
wapi_get_txpower
int wapi_get_txpower(int sock, const char *ifname, int *power, enum wapi_txpower_flag_e *flag);
Parameters:
sockSocket descriptor.ifnameNetwork interface name.powerOutput parameter for the transmit power value.flagOutput parameter for the unit of the transmit power.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_set_txpower
int wapi_set_txpower(int sock, const char *ifname, int power, enum wapi_txpower_flag_e flag);
Parameters:
sockSocket descriptor.ifnameNetwork interface name.powerTransmit power.flagTransmit power.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_make_socket
int wapi_make_socket(void);
wapi_scan_init
int wapi_scan_init(int sock, const char *ifname, const char *essid);
Parameters:
sockSocket descriptor.ifnameNetwork interface name.essidESSID to scan.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_scan_channel_init
int wapi_scan_channel_init(int sock, const char *ifname, const char *essid, uint8_t *channels, int num_channels);
Parameters:
sockSocket descriptor.ifnameNetwork interface name.essidESSID to scan.channelsPointer to an array of channel numbers to scan.num_channelsChannel count.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_escan_init
int wapi_escan_init(int sock, const char *ifname, uint8_t scan_type, const char *essid);
Parameters:
sockSocket descriptor.ifnameNetwork interface name.scan_typeScan type.essidESSID to scan.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_escan_channel_init
int wapi_escan_channel_init(int sock, const char *ifname, uint8_t scan_type, const char *essid, uint8_t *channels, int num_channels);
Parameters:
sockSocket descriptor.ifnameNetwork interface name.scan_typeScan type.essidESSID to scan.channelsPointer to an array of channel numbers to scan.num_channelsChannel count.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_scan_stat
int wapi_scan_stat(int sock, const char *ifname);
Parameters:
sockSocket descriptor.ifnameNetwork interface name.
wapi_scan_coll
int wapi_scan_coll(int sock, const char *ifname, struct wapi_list_s *aps);
Parameters:
sockSocket descriptor.ifnameNetwork interface name.apsList of collected scan results.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_scan_coll_free
void wapi_scan_coll_free(struct wapi_list_s *aps);
Parameters:
apsScan result list to free.
wapi_set_country
int wapi_set_country(int sock, const char *ifname, const char *country);
Parameters:
sockSocket descriptor.ifnameNetwork interface name.countryPointer to a two-character string indicating the country code to set.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_get_country
int wapi_get_country(int sock, const char *ifname, char *country);
Parameters:
sockSocket descriptor.ifnameNetwork interface name.countryPointer to the caller-provided buffer to receive the country code.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_get_sensitivity
int wapi_get_sensitivity(int sock, const char *ifname, int *sense);
Parameters:
sockSocket descriptor.ifnameNetwork interface name.sensePointer to the caller-provided integer variable to receive the sensitivity value.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_load_config
void *wapi_load_config(const char *ifname, const char *confname, struct wpa_wconfig_s *conf);
Parameters:
ifnameNetwork interface name.confnamePath.confPointer to the caller-provided structure to be filled with configuration data.
wapi_unload_config
void wapi_unload_config(void *load);
Parameters:
loadConfiguration resource handle.
wapi_save_config
int wapi_save_config(const char *ifname, const char *confname, const struct wpa_wconfig_s *conf);
Parameters:
ifnameNetwork interface name.confnamePath.confPointer to the structure containing the configuration information.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_set_pta_prio
int wapi_set_pta_prio(int sock, const char *ifname, enum wapi_pta_prio_e pta_prio);
Parameters:
sockFile descriptor.ifnameNetwork interface name.pta_prioPTA priority.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_get_pta_prio
int wapi_get_pta_prio(int sock, const char *ifname, enum wapi_pta_prio_e *pta_prio);
Parameters:
sockFile descriptor.ifnameNetwork interface name.pta_prioPointer to the variable that receives the current PTA priority.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_set_pmksa
int wapi_set_pmksa(int sock, const char *ifname, const uint8_t *pmk, int len);
Parameters:
sockFile descriptor.ifnameNetwork interface name.pmkPointer to the buffer containing the PMKSA data.lenLength.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_get_pmksa
int wapi_get_pmksa(int sock, const char *ifname, uint8_t *pmk, int len);
Parameters:
sockFile descriptor.ifnameNetwork interface name.pmkPointer to the buffer that receives the retrieved PMKSA data.lenBuffer size.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_extend_params
int wapi_extend_params(int sock, int cmd, struct iwreq *wrq);
Parameters:
sockFile descriptor.cmdPrivate ioctl command code.wrqPointer to aniwreqstructure that the caller must populate in advance.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_set_power_save
int wapi_set_power_save(int sock, const char *ifname, bool on);
Parameters:
sockFile descriptor.ifnameNetwork interface name.onControl flag.
Returns:
Returns 0 on success, or a negative error code on failure.
wapi_get_power_save
int wapi_get_power_save(int sock, const char *ifname, bool *on);
Parameters:
sockFile descriptor.ifnameNetwork interface name.onPointer to a boolean variable that receives the current state.
Returns:
Returns 0 on success, or a negative error code on failure.