Wi-Fi

[English]

Wi-Fi API提供Wi-Fi连接、扫描、配置等接口。

Header File

Functions

bk_err_t bk_wifi_init(const wifi_init_config_t *init_config)

This API initializes the WiFi driver, e.g. creating task for supplicant, allocating resource for low level WiFi driver etc.

Usage example:

 wifi_init_config_t init_config = WIFI_DEFAULT_INIT_CONFIG();
 BK_LOG_ON_ERR(bk_wifi_init(&init_config);

Attention

1. This API is the 1st API that should be called before any other WiFi API can be called.

Attention

2. Make sure the reserved field in config is zero, otherwise you may encounter compatibility issue in future if more config fields are added.

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_wifi_deinit(void)

Deinit the BK WiFi driver.

This API free all resources related to WiFi.

Attention

1. This API is not ready yet, will support in future release.

返回

  • BK_OK: succeed

  • BK_ERR_NOT_SUPPORT: The API is not supported yet.

  • others: other errors.

bk_err_t bk_wifi_sta_start(void)

Start the BK STA.

This API init the resoure specific to BK STA, e.g. init STA specific globals, init the supplicant and STA specific WiFi driver etc.

Attention

1. Make sure the bk_wifi_sta_set_config() are succeedful before calling this API.

Attention

2. This API connect the BK STA to the configured AP automatically.

Attention

3. If the BK STA is already started, this API ignores the request and returns BK_OK. if you want to restart the BK STA, call bk_wifi_sta_stop() first and then call this API.

Attention

4. TODO description about fast connection

返回

  • BK_OK: succeed

  • BK_ERR_WIFI_STA_NOT_CONFIG: the BK STA is not configured.

  • BK_ERR_WIFI_MONITOR_IP: the BK STA can’t be started because monitor is started.

  • others: other errors.

bk_err_t bk_wifi_sta_stop(void)

Stop the BK STA.

Attention

This API causes the BK STA disconnect from the AP, it similar as bk_wifi_sta_disconnect(), but this API may free resource.

返回

  • BK_OK: succeed

  • BK_FAIL: fail

bk_err_t bk_wifi_scan_stop(void)

Stop the pure scan operation.

Attention

This API causes the BK STA disconnect from the AP, it similar as bk_wifi_sta_disconnect(), but this API may free resource.

返回

  • BK_OK: succeed

  • BK_FAIL: fail

bk_err_t bk_wifi_sta_set_config(const wifi_sta_config_t *sta_config)

Config the BK STA.

This API configures the basic configurations of the BK STA, it should be called before we call bk_wifi_sta_start() to start the BK STA. It can also be used to update the configuration after the BK STA is started.

Usage example:

wifi_sta_config_t sta_config = WIFI_DEFAULT_STA_CONFIG();

os_strncpy(sta_config.ssid, "ssid", WIFI_SSID_STR_LEN);
os_strncpy(sta_config.password, "password", WIFI_PASSWORD_LEN);
//more initialization here
BK_LOG_ON_ERR(bk_wifi_sta_set_config(&sta_config));

Attention

1. Don’t call this API when the monitor is in-progress

Attention

2. If STA is already connected to AP, this API cases BK STA reconnects the AP.

Attention

3. Make sure the reserved fields in sta_config is zero, otherwise you may encounter compatibility issue in future if more config fields are added.

Attention

4. Auto reconnect max count and timeout can be set. When user app receives EVENT_WIFI_STA_DISCONNECTED event, it’s user app’s responsibility to reconnect to AP manually. Max count and timeout set to zero to let supplicant automatically handles connection without user app’s interaction.

参数

sta_config – the STA configuration

返回

  • BK_OK: succeed

  • BK_ERR_WIFI_NOT_INIT: the STA is not initialized, call bk_wifi_init() first.

  • BK_ERR_NULL_PARAM: parameter config is NULL.

  • BK_ERR_WIFI_RESERVED_FIELD: the reserved field of config is not 0.

  • others: other errors

bk_err_t bk_wifi_sta_get_config(wifi_sta_config_t *sta_config)

Get the configuration of the BK STA.

参数

sta_config – store the BK STA configuration

返回

  • BK_OK: succeed

  • BK_ERR_NULL_PARAM: the parameter config is NULL.

  • BK_ERR_WIFI_STA_NOT_CONFIG: STA is not configured yet.

  • others: other errors

bk_err_t bk_wifi_sta_get_linkstate_with_reason(wifi_linkstate_reason_t *info)

Get the WiFi station state of the BK STA.

  • If sta is idle or connected, reason code will be WIFI_REASON_MAX

Attention

the difference between this API and bk_wifi_sta_get_link_status() is

  • This API gets the actual WiFi STA link status and reason code

参数

state – store the WiFi station state of the BK STA

返回

  • BK_OK: succeed

  • BK_ERR_NULL_PARAM: the parameter config is NULL.

  • others: other errors

Get the WiFi link info of the BK STA.

Get the actual WiFi link status of the BK STA.

Attention

the difference between this API and bk_wifi_sta_get_config() is

  • This API gets the actual STA link info while the later gets the configured value

  • This API can get more info of the link, such as RSSI, WiFi link status, AID etc.

  • The AID is only valid if @link_status->state is WIFI_LINK_CONNECTED.

参数

link_status – store the WiFi link status of the BK STA

返回

  • BK_OK: succeed

  • BK_ERR_NULL_PARAM: the parameter link_info is NULL.

  • BK_ERR_WIFI_DRIVER: WiFi low level driver has failure.

  • BK_ERR_WIFI_NO_MEM: Not enough memory

  • others: other errors

bk_err_t bk_wifi_sta_connect(void)

Connect the BK STA to the AP.

Attention

1. Make sure STA is started by bk_wifi_sta_start() before calling this API.

Attention

2. Don’t call this API when the monitor is in-progress

Attention

3. If STA is already connected to AP, this API reconnects the BK STA.

Attention

4. TODO - multiple same SSID connect???

返回

  • BK_OK: succeed

  • BK_ERR_WIFI_STA_NOT_STARTED: the STA is not started, call bk_wifi_sta_start() first.

  • BK_ERR_WIFI_MONITOR_IP: the API is not allowed because monitor is in-progress.

  • others: other failures.

bk_err_t bk_wifi_sta_disconnect(void)

Disconnect the WiFi connection of the BK STA.

Attention

TODO - add description about disconnect event!

返回

  • BK_OK: succeed

  • others: other failures.

bk_err_t bk_wifi_scan_start(const wifi_scan_config_t *scan_config)

Start a scan.

This API notifies the WiFi driver to start a scan, the event EVENT_WIFI_SCAN_DONE will be raised if the scan is completed. General steps to use this API:

  • prepare the scan done event callback, the callback can call bk_wifi_scan_get_result() to get the scan result and then call bk_wifi_scan_free_result() to free the resource.

  • call bk_event_register_cb(EVENT_MOD_WIFI, EVENT_WIFI_SCAN_DONE, …) to register scan done event callback.

  • call this API to trigger this the scan.

Usage example:

//Define your scan done handler
int scan_done_handler(void *arg, event_module_t event_module, int event_id, void *event_data)
{
    wifi_scan_result_t scan_result = {0};

    BK_LOG_ON_ERR(bk_wifi_scan_get_result(&scan_result));
    bk_wifi_scan_dump_result(&scan_result);
    bk_wifi_scan_free_result(&scan_result);

    return BK_OK;
}

//Start the scan
wifi_scan_config_t config = {0};

BK_LOG_ON_ERR(bk_event_register_cb(EVENT_MOD_WIFI, EVENT_WIFI_SCAN_DONE, scan_done_handler, NULL));
BK_LOG_ON_ERR(bk_wifi_scan_start(&scan_config));

Attention

1. This API triggers an active scan on all channels (TODO double check)

Attention

2. Pass NULL scan_config to scan all APs, otherwise scan the SSID specified in scan_config.ssid

Attention

3. Make sure the reserved fields in scan_config is zero, otherwise you may encounter compatibility issue in future if more config fields are added.

Attention

4. TODO scan result limits???

参数

scan_config – the configuration of scan

返回

  • BK_OK: succeed

  • BK_ERR_WIFI_NOT_INIT: the STA is not initialized, call bk_wifi_init() first.

  • BK_ERR_WIFI_MONITOR_IP: the API is not allowed because monitor is in-progress.

  • others: other failures.

bk_err_t bk_wifi_scan_get_result(wifi_scan_result_t *scan_result)

Get the scan result.

Usage example:

wifi_scan_result_t scan_result = {0};

BK_LOG_ON_ERR(bk_wifi_scan_get_result(&scan_result));
bk_wifi_scan_free_result(&scan_result);

Attention

1. The caller don’t need to allocate memory for scan_result->aps, this API will allocate the memory for scan_result->aps according to the actual found AP number.

Attention

2. Don’t forget to call bk_wifi_scan_free_result(&scan_result) to free the the resource allocated in this API, otherwise memory leak.

参数

scan_result – store the scan result

返回

  • BK_OK: succeed

  • BK_ERR_NULL_PARAM: NULL scan_result

  • BK_ERR_NO_MEM: out of memory

  • others: other failures

bk_err_t bk_wifi_scan_dump_result(const wifi_scan_result_t *scan_result)

Dump the scan result.

参数

scan_result – The scan result to be dumped.

返回

  • BK_OK: succeed

  • BK_ERR_PARAM: invalid scan result

void bk_wifi_scan_free_result(wifi_scan_result_t *scan_result)

Free the scan result.

Attention

This API free scan_result->aps which allocated in bk_wifi_scan_get_result(), it doesn’t free scan_result. So if scan_result is allocated by the caller, the caller need to free it.

参数

scan_result – The scan result to be freed.

返回

  • BK_OK: always succeed

bk_err_t bk_wifi_sta_add_vendor_ie(uint8_t frame, uint8_t *vsie, uint8_t len)

Add/Update/Del STA’s Vendor Specific IE before connect to AP.

Attention

If you want to add vsie when sta starts, just initialize wifi_sta_config_t when call bk_wifi_sta_set_config().

参数
  • buf – vsie buf

  • len – vsie buf len

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_sta_update_vendor_ie(uint8_t frame, uint8_t *vsie, uint8_t len)
bk_err_t bk_wifi_sta_del_vendor_ie(uint8_t frame)
bk_err_t bk_wifi_ap_start(void)

Start the BK AP.

This API init the resoure specific to BK AP, e.g. init BK AP specific globals, init the hostapd and AP specific WiFi driver etc.

If the BK AP is already started, this API ignores the request and returns BK_OK, we can call bk_wifi_ap_stop() to stop BK AP first and then call bk_wifi_ap_start() to restart it.

Restart AP Usage example:

BK_LOG_ON_ERR(bk_wifi_ap_stop());
BK_LOG_ON_ERR(bk_wifi_ap_start());

Attention

1. Don’t call this API when the monitor is in-progress

Attention

2. If bk_wifi_ap_set_config() is not called, this API start the AP with default value, normally you should configure the AP first before calling this API.

返回

  • BK_OK: succeed

  • BK_ERR_WIFI_AP_NOT_CONFIG: the WiFi AP is not configured, call bk_wifi_ap_set_config() first.

  • others: other errors

bk_err_t bk_wifi_ap_stop(void)

Stop the BK AP.

返回

  • BK_OK: succeed

  • BK_WIFI_NOT_INIT: the WiFi is not initialized, call bk_wifi_init() first.

  • others: other errors

bk_err_t bk_wifi_ap_set_config(const wifi_ap_config_t *ap_config)

Config the BK AP.

Usage example:

wifi_ap_config_t ap_config = WIFI_DEFAULT_AP_CONFIG();

os_strncpy(ap_config.ssid, "ssid", WIFI_SSID_STR_LEN);
os_strncpy(ap_config.password, "password", WIFI_PASSWORD_LEN);
BK_LOG_ON_ERR(bk_wifi_ap_set_config(&ap_config));

Attention

1. Make sure the reserved field in config is zero, otherwise you may encounter compatibility issue in future if more config fields are added.

参数

ap_config – the AP configuration

返回

  • BK_OK: succeed

  • BK_ERR_NULL_PARAM: the ap_config is NULL.

  • others: other errors

bk_err_t bk_wifi_ap_get_config(wifi_ap_config_t *ap_config)

Get the configuration of the BK AP.

参数

ap_config – store the configuration of BK AP

返回

  • BK_OK: succeed

  • BK_ERR_NULL_PARAM: the parameter config is NULL.

  • others: other errors

bk_err_t bk_wifi_ap_get_sta_list(wlan_ap_stas_t *stas)

Get the STAs connected to BK AP.

Attention

Free stas->sta after usage.

参数

stas – store the STA list in BK AP

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_calculate_pmk(const char *ssid, const char *pwd, char *pmk)

Calculate softap’s Pmk when softap is starts.

参数
  • ssid – softap’s ssid

  • pwd – softap’s pwd

  • pmk – softap’s pmk

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_ap_add_vendor_ie(void *buf, uint8_t len)

Add softap’s Vendor Specific IE when softap is running.

Attention

If you want to add vsie when softap starts, just initialize wifi_ap_config_t when call bk_wifi_ap_start().

参数
  • buf – vsie buf

  • len – vsie buf len

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_ap_del_vendor_ie(void)

Delete softap’s Vendor Specific IE when softap is running.

Attention

If you want to add vsie when softap starts, just initialize wifi_ap_config_t when call bk_wifi_ap_start().

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_ap_update_hidden_cap(bool flag)

Update softap’s Hidden Ssid Capaility when softap is running.

  • BK_OK: succeed

  • others: other errors

Attention

If you want to update hidden ssid capability when softap starts, just call bk_wifi_ap_update_hidden_cap().

参数

flag – set true for hidden ssid

返回

bk_err_t bk_wifi_monitor_start(void)

Start the monitor.

Attention

1. When monitor mode is enabled, the scan will not work and bk_wifi_scan_start() returns BK_ERR_WIFI_MONITOR_IP.

Attention

2. When monitor mode is enabled, the STA connect will not work and bk_wifi_sta_connect() returns BK_ERR_WIFI_MONITOR_IP.

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_monitor_stop(void)

Stop the monitor.

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_monitor_set_config(const wifi_monitor_config_t *monitor_config)

Configure the monitor.

参数

monitor_config – the configuration of monitor

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_monitor_get_config(wifi_monitor_config_t *monitor_config)

Get the configuration of the monitor.

参数

monitor_config – store the configuration of monitor

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_monitor_register_cb(const wifi_monitor_cb_t monitor_cb)

Register the user callback of monitor.

参数

monitor_cb – monitor callback

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_monitor_set_channel(const wifi_channel_t *chan)

Set monitor channel.

Attention

1. Currently we only support HT20, chan->second should always be 0.

Attention

2. This API is only used for settting monitor channel, NOT for other purpose.

Attention

3. This API directly change the hardware channel, it may impacts BK STA/AP if the STA or AP interface is started. TODO describe details of the impact.

Attention

4. The channel range can be set is from channel 1 to channel 14,

参数

chan – channel of monitor

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_monitor_resume(void)

resume the monitor to wakeup Wi-Fi from sleep mode

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_monitor_suspend(void)

suspend the monitor to allow Wi-Fi can goto sleep mode

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_twt_setup(uint8_t setup_type, uint16_t mantissa, uint8_t min_twt)

twt set up

参数
  • setup_type – suggest/demand

  • mantissa – wake_int_mantissa

  • min_twt – min_twt_wake_dur

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_twt_teardown(void)

twt tear down

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_filter_set_config(const wifi_filter_config_t *filter_config)

Set the filter configuration.

The filter is used to configure what kind of management packets can be received by the filter callback registered by bk_wifi_filter_register_cb().

Per the WiFi receiving data path, the management frames are firstly received by WiFi hardware, then the hardware relays them to WiFi software (WiFi driver). Normally the hardware receives all management frames in the air, however it don’t relay all of them to WiFi driver (WiFi software), it only relays management frames necessary to STA or AP or scan or monitor, depends on which interface or function are enabled. In other word, WiFi driver only receives management frames necessary to them from hardware.

When no filter callback is registered, all management frame processing is ended in WiFi driver unless the filter callback is registered.

If filter callback is register and if filter_config.rx_all_default_mgmt is set to 1, then all the management frames received by WiFi driver are relayed to the filter callback. Notified that the default management frame types can be received depends on whether STA or AP or scan or monitor are enabled or not, e.g. when only STA is enabled, the WiFi driver needs to handle PROBE response, but don’t need to handle PROBE request, so the WiFi driver only receive PROBE response from WiFi hardware.

Here is summary about default management frame received by WiFi:

Condition

Default management frame

STA connected

Management frames sent by the connected AP, such as beacon etc.

AP started

Management frames sent by connected STA and probe request etc.

Scan starting

Probe response and beacon frames of all APs.

Monitor started

All kind of management frames

How about if the filter callback wants to receive more management frame types, e.g. want to receive PROBE request when only STA is enabled. We can set filter_config->rx_probe_req to receive PROBE response no matter whether AP is enabled or NOT.

Usage example:

// Only receive management frame default received by WiFi driver
// Equal to the case when bk_wifi_filter_set_config() is not called
wifi_filter_config_t filter_config = WIFI_DEFAULT_FILTER_CONFIG();
BK_LOG_ON_ERR(bk_wifi_filter_set_config(&filter_config);

// Receive all beacon and management frames default received by WiFi driver
filter_config.rx_all_beacon = 1;
BK_LOG_ON_ERR(bk_wifi_filter_set_config(&filter_config);

// Only receive all beacon
filter_config.rx_all_beacon = 1;
filter_config.rx_all_default_mgmt = 0;
BK_LOG_ON_ERR(bk_wifi_filter_set_config(&filter_config);

Attention

1. If this API is not called, the default filter is to relay all mamangement frames received by WiFi driver to the filter callback.

Attention

2. If STA is enabled, the WiFi driver only receives beacon from the connected AP, if scan is enabled or filter_config->rx_all_beacon is set, the WiFi driver receives beacons of all APs.

参数

filter_config – configuration of filter

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_filter_get_config(wifi_filter_config_t *filter_config)

Get the filter configuration.

参数

filter_config – store configuration of filter

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_filter_register_cb(const wifi_filter_cb_t filter_cb)

Register the filter user callback.

Attention

1. If the monitor is enabled, the management packets received by filter callback can also be received by monitor callback. If this is not what we want, we can disable filter when enabling monitor, or disable monitor when enabling filter.

Attention

2. During WiFi scan, the filter also works.

Attention

3. Pass NULL callback or set all fields of filter_config to 0 to disable the filter.

Attention

4. The memory used to hold the frame buffer and frame_info will be freed immediately when the callback is returned, so don’t relay them to other task. Make a copy of them and then relay to other task if necessary.

Attention

5. Don’t do too much work in the filter callback because it’s called in WiFi driver core thread, otherwise it may impact the WiFi performance.

参数

filter_cb – the filter user callback

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_sta_get_mac(uint8_t *mac)

Get the MAC of BK STA.

Attention

1. The AP’s MAC is derived from the base MAC of the system.

Attention

2. If you want to change the MAC of AP, call bk_set_mac() to set the base MAC of the system.

参数

mac – store the MAC of BK STA

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_ap_get_mac(uint8_t *mac)

Get the MAC of BK AP.

Attention

1. The AP’s MAC is derived from the base MAC of the system.

Attention

2. If you want to change the MAC of AP, call bk_set_mac() to set the base MAC of the system.

参数

mac – store the MAC of BK AP

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_send_raw(uint8_t *buffer, int len)

Send raw 802.11 frame.

Attention

1. This API can be used in WiFi station, softap, or monitor mode.

Attention

2. Only support to send non-QoS frame.

Attention

3. The frame sequence will be overwritten by WiFi driver.

Attention

4. The API doesn’t check the correctness of the raw frame, the caller need to guarantee the correctness of the frame.

参数
  • buffer – raw 802.11 frame

  • len – the length of the 802.11 frame

返回

  • kNoErr: succeed

  • otherwise: fail

bk_err_t bk_wifi_send_raw_ex(wifi_raw_tx_info_t *raw_tx, void *cb, void *param)

Send raw 802.11 frame.

Attention

1. This API can be used in WiFi station, softap, or monitor mode.

Attention

2. Only support to send non-QoS frame.

Attention

3. The frame sequence will be overwritten by WiFi driver.

Attention

4. The API doesn’t check the correctness of the raw frame, the caller need to guarantee the correctness of the frame.

参数
  • raw_tx – raw tx information, refer to struct wifi_raw_tx_info_t

  • cb – send status call back

  • param – send status call back paramter

返回

  • kNoErr: succeed

  • otherwise: fail

bk_err_t bk_wifi_send_tx_raw_ex(wifi_raw_tx_info_t *raw_tx, void *cb, void *param)

Send raw 802.11 tx frame.

Attention

1. This API can be used in WiFi station, softap, or monitor mode.

Attention

2. Only support to send non-QoS frame.

Attention

3. The frame sequence will be overwritten by WiFi driver.

Attention

4. The API doesn’t check the correctness of the raw frame, the caller need to guarantee the correctness of the frame.

参数
  • raw_tx – raw tx information, refer to struct wifi_raw_tx_info_t

  • cb – send status call back

  • param – send status call back paramter

返回

  • kNoErr: succeed

  • otherwise: fail

bk_err_t bk_wifi_set_tx_raw_rate_power(uint32_t rate, uint32_t power)

Update raw 802.11 frame TX rate and power.

参数
  • rate – TX rate control

  • power – TX power control

返回

  • kNoErr: succeed

  • otherwise: fail

bk_err_t bk_wifi_set_tx_raw_ac(uint8_t ac)

Update raw 802.11 frame TX AC.

参数

ac – TX AC

返回

  • kNoErr: succeed

  • otherwise: fail

bk_err_t bk_wifi_set_tx_raw_timeout(uint16_t timeout_ms)

Update raw 802.11 frame TX timeout.

参数

timeout_ms – TX timeout in ms

返回

  • kNoErr: succeed

  • otherwise: fail

bk_err_t bk_wifi_set_wifi_media_mode(bool flag)

Configure wifi multimedia mode when the multimedia is running.

This API is used to configure multimedia mode of Wi-Fi. Multimedia mode can enchance video fluency and make a better experience of video.

Attention

1. If you want to running multimedia mode,please configure this flag when open and close multimedia mode.

Attention

2. Please set this flag before running multimedia and clear this flag after closing multimedia.

Attention

3. If the flag is set when multimedia is turned on and it is not cleared after multimedia is turned off,the Wi-Fi will not be able to enter ps mode.

参数

flag – set true if you want to enable multimedia mode.

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_get_wifi_media_mode_config(bool *flag)

get wifi media mode configuration

参数

flag – store configuration of wifi media mode

返回

  • BK_OK: succeed

  • BK_ERR_NULL_PARAM: the parameter config is NULL

  • others: other errors

bk_err_t bk_wifi_set_video_quality(uint8_t quality)

Configure video quality when the video is running.

This API is used to configure video quality.There are three mode to choose:

Fluent definition(FD): The video transmission is relatively stable and has strong anti-interference ability,which can ensure the stable video transmission in a complex enviroment;

Standard definition(SD):The video transmission is stable in a clean environment and is slightly stuck in a complex environment,which transmission bandwidth is improved;

High definition(HD):The video transmission gives priority to high speed which can transmit high-bandwidth data in a clean environment, but the video transmission is relatively stuck in a complex environment;

The default value is HD mode when the video is running.

Attention

1. If you want to running video mode,please configure this parameter when open video mode.

Attention

2. Please configure this parameter before running video mode.

Attention

3. Please configure bk_wifi_set_wifi_media_mode(flag) before useing this API.

参数

quality – set the video quality when the video is running. Three mode can be choose: 0-FD,1-SD,2-HD,default is HD.

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_get_video_quality_config(uint8_t *quality)

get video quality configuration

参数

quality – store configuration of video quality

返回

  • BK_OK: succeed

  • BK_ERR_NULL_PARAM: the parameter config is NULL

  • others: other errors

bk_err_t bk_wifi_set_default_ac(uint32_t ac)

Configure defalut AC.

This API is used to configure default AC,rang in [0 3]

参数

ac – set default AC rang in [0 3]

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_get_default_ac(uint32_t *ac)

get default AC

参数

ac – store default AC

返回

  • BK_OK: succeed

  • BK_ERR_NULL_PARAM: the parameter config is NULL

  • others: other errors

bk_err_t bk_wifi_get_tx_raw_ac(uint8_t *ac)

get tx raw ac info

参数

ac – ac info

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_get_tx_raw_timeout(uint16_t *time)

get tx raw timeout info

参数

time – timeout info

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_set_min_rsv_mem(uint16_t mem_bytes)

Update the minimux heap memory size that Wi-Fi should reserve.

Attention

1. An small piece of extra memory will be malloced from heap for each TX packets delivered to Wi-Fi, so if the pending TX packets are too many for some reasons, the heap memory will be occupied too much by TX packets. To ensure the stability of whole system, this interface is provied to limit the memory size for Wi-Fi TX packets.

Attention

2. The maximum valid value of memory size which could update via this API is 30K bytes

Attention

3. The default minimux reserved memory size is 10K bytes

参数

mem_bytes – the expected reserved memory size(bytes)

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_get_min_rsv_mem(uint16_t *mem_bytes)

Get the minimux heap memory size that Wi-Fi currently creserves.

参数

mem_bytes – return currently reserved memory size(bytes)

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_set_tx_max_msdu_cnt(uint16_t max_cnt)

Update the maximum MSDU count that Wi-Fi could handle.

参数

max_cnt – the maxmimum MSDU count

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_get_tx_max_msdu_cnt(uint16_t *max_cnt)

Get the maximum MSDU count configuration that Wi-Fi could handle.

参数

max_cnt – return the maxmimum MSDU count

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_set_data_rty_num(uint8_t rty_num)

Set data frame retry numbers.

参数

rty_num – data frame retry numbers

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_get_data_rty_num(uint32_t *rty_num)

Get data frame retry numbers.

参数

rty_num – data frame retry numbers

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_set_mgmt_rty_num(uint8_t rty_num)

Set management frame retry numbers.

参数

rty_num – management frame retry numbers

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_get_mgmt_rty_num(uint32_t *rty_num)

Get management frame retry numbers.

参数

rty_num – management frame retry numbers

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_capa_config(wifi_capability_t capa_id, uint32_t capa_val)

Update Wi-Fi capability configuration.

This API is used to change some Wi-Fi capability configuration, please refer to wifi_capability_t to get the capability that has been supported.

Attention

1. Please keep in mind that Wi-Fi behavior may change if the capability is changed to different value compared with the default value.

Attention

2. We strongly suggest not using this API except you are very farmiliar with the Wi-Fi specification.

Attention

3. If you want Wi-Fi working on 11b only mode, please set 11b only mode by configurate paramter capa_id with WIFI_CAPA_ID_11B_ONLY_EN and capa_val with TRUE.

参数
  • capa_id – the specific capability you want to change

  • capa_val – new capability value

返回

  • BK_OK: succeed

  • others: other errors

bk_err_t bk_wifi_set_country(const wifi_country_t *country)

configure country info

Attention

1. The default country is {.cc=”CN”, .schan=1, .nchan=13, policy=WIFI_COUNTRY_POLICY_AUTO}

Attention

2. When the country policy is WIFI_COUNTRY_POLICY_AUTO, the country info of the AP to which the station is connected is used. E.g. if the configured country info is {.cc=”USA”, .schan=1, .nchan=11} and the country info of the AP to which the station is connected is {.cc=”JP”, .schan=1, .nchan=14} then the country info that will be used is {.cc=”JP”, .schan=1, .nchan=14}. If the station disconnected from the AP the country info is set back back to the country info of the station automatically, {.cc=”USA”, .schan=1, .nchan=11} in the example.

Attention

3. When the country policy is WIFI_COUNTRY_POLICY_MANUAL, always use the configured country info.

Attention

4. When the country info is changed because of configuration or because the station connects to a different external AP, the country IE in probe response/beacon of the soft-AP is changed also.

Attention

5. The country configuration is not stored into flash

Attention

6. This API doesn’t validate the per-country rules, it’s up to the user to fill in all fields according to local regulations.

参数

country – the configured country info

返回

  • BK_OK: succeed

  • BK_ERR_WIFI_NOT_INIT: WiFi is not initialized

  • BK_ERR_PARAM: invalid argument

bk_err_t bk_wifi_get_country(wifi_country_t *country)

get the current country info

参数

country – country info

返回

  • BK_OK: succeed

  • BK_ERR_WIFI_NOT_INIT: WiFi is not initialized

  • BK_ERR_PARAM: invalid argument

bk_err_t bk_wifi_sta_pm_enable(void)

enable wifi sta power management

返回

  • BK_OK: on succeed

  • others: real error, used for future.

bk_err_t bk_wifi_sta_pm_disable(void)

disable wifi sta power management

返回

  • BK_OK: on succeed

  • others: real error, used for future.

bk_err_t bk_wifi_get_channel(void)

get current channel ID

参数

basically – range from 1~13

返回

  • BK_OK: on succeed

  • others: real error, used for future.

bk_err_t bk_wifi_set_mac_address(char *mac)

Set Wi-Fi MAC addresses.

The given MAC address will become the station MAC address.The AP MAC address (i.e BSSID) will be the same MAC address but with the local bit set.

@usage example: mac c8478cxxyyzz txevm -e 2 //if needed

备注

on some platforms the change of MAC address can only take effect after reboot.

参数

mac – system mac

返回

- BK_OK: on succeed
 - others: real error, used for future.

bk_err_t bk_wifi_manual_cal_rfcali_status(void)

Get Wi-Fi Calibration status.

返回

  • BK_OK: on succeed

  • others: real error, used for future.

bk_err_t bk_wifi_ap_vif_probe_req_frame_cb_register(void *cb)

Register a cb of probe request for ap.

参数

cb – callback function of probe request to register

bk_err_t bk_wifi_send_listen_interval_req(uint8_t interval)

Set listen interval.

参数

any – value is acceptable,but 1, 3, 10 is recommended.

返回

-BK_OK: on success -others:real error, used for future.

bk_err_t bk_wifi_get_listen_interval(uint8_t *listen_interval)

Get listen interval.

参数

return – the configure listen interval

返回

-0: not set listen interval -others:return the configure listen interval value.

bk_err_t bk_wifi_print_bcn_loss_ratio(void)

print beacon loss ratio.

参数

prints – reception of the beacon, no return value

bk_err_t bk_wifi_send_arp_set_rate_req(uint16_t arp_tx_rate)

Set arp tx rate.

参数

any – value is acceptable,but 1, 6 is recommended.

返回

-BK_OK: on success -others:real error, used for future.

bk_err_t bk_wifi_send_bcn_loss_int_req(uint8_t interval, uint8_t repeat_num)

When beacon loss occurs,use beacon loss interval.

参数
  • interval – any value is acceptable,it is recommended that this value less than listen interval

  • repeat_num – set beacon loss interval number,the minimum value is 1

返回

-BK_OK: on success -others:real error, used for future.

bk_err_t bk_wifi_set_bcn_loss_time(uint8_t wait_cnt, uint8_t wake_cnt)

When beacon loss occurs,use bcn loss time.

@usage example:(10s no beacon frame received(normal reception for the first 5s,ps off for the next 5s),disconnect from the router) DTIM10:wait_cnt = 5,wake_cnt = 50 DTIM1 :wait_cnt = 50,wake_cnt = 50

参数
  • wait_cnt – failed to receive beacon for wait_cnt consecutive cycles, close ps,wait_cnt corresponds to dtimx(listen_interval)

  • wake_cnt – after ps is turned off,the beacon fails to receive for wake_cnt consecutive cycles, disconnect;wake_cnt corresponds to dtim1

返回

-BK_OK: on success -others:real error, used for future.

bk_err_t bk_wifi_set_bcn_recv_win(uint8_t default_win, uint8_t max_win, uint8_t step)

set beacon receive window.

参数
  • default_win – default beacon receive window(ms),minimum is 5,less than or equal to max_win.

  • max_win – max beacon receive window(ms),maximum is 20.

  • step – increase the beacon reception time by a step value(ms)

返回

-BK_OK: on success -others:real error, used for future.

bk_err_t bk_wifi_set_bcn_miss_time(uint8_t bcnmiss_time)

configure beacon miss time.

bcnmiss_time: bcnmiss_time not receive the beacon,disconnected from the router;unit: second

@usage example:(30s no beacon frame received,disconnect from the router) bcnmiss_time:30

返回

-BK_OK: on success -others:real error, used for future.

bk_err_t bk_wifi_set_conn_delay_time(uint8_t conn_delay_time)

set station connection delay time.

参数

conn_delay_time – delay time of starting station connection (in ms).

返回

-BK_OK: on success -others:real error, used for future.

bk_err_t bk_wifi_bcn_cc_rxed_register_cb(const wifi_beacon_cc_rxed_t cc_cb, void *ctxt)

regist bcn cc rxed callback.

参数

bcn – cc the callback function.

返回

-BK_OK: on success -others:real error, used for future.

int cc_scan_start(void)

start scan procedure to find AP’s country code

返回

-BK_OK: on success -others:real error, used for future.

void cc_scan_stop(void)

stop scan procedure to find AP’s country code

返回

success

int bk_scan_country_code(uint8_t *country_code)

Get country code by scan.

Attention

Need open CONFIG_WIFI_SCAN_COUNTRY_CODE=y in config

参数

country_code – The point of country code buffer

返回

  • > 0 : succeed, and the length of country code buffer

  • = 0 : not found

  • <= 0 : failures.

bk_err_t bk_wifi_set_arp_reply_config(uint8_t flag, uint8_t arp_period)

configure arp reply.

flag: indicates whether to send arp reply actively,but not respond to arp request,or use default value

  • * * 0:use default value(when dtim10 is configured,enable active arp_reply and arp_period is 30s);

  • * * 1:enable active arp_reply and set arp_reply period;

  • * * 2:disable active arp_reply arp_period:period for sending arp reply,unit: second

@usage example: flag:1 (an arp reply is activelt send every 30s) arp_period:30

flag:2 (disable active arp_reply) arp_period:0

返回

-BK_OK: on success -others:real error, used for future.

bk_err_t bk_wifi_get_statistic_info(wifi_statistics_info_t *wifiinfo)

Get wifi statistic info.

参数

get – wifi info from fw

返回

-BK_OK: on success -others:real error, used for future.

void bk_wifi_ota_dtim(bool is_open)

set wifi ps dtim info.

参数

dtim – 1 open or not

返回

-void.

void bk_wifi_set_td_active_percent(uint8_t active_percent)

Set active_percent.

参数

{10ms-100ms} – *

返回

-void.

void bk_wifi_mask_td_active_percent()

mask active_percent

参数

*

void bk_wifi_ap_power_register_cb(FUNC_1PARAM_PTR cb)

register callback to get wifi ap power

参数

callback – interface *

返回

-void.

void bk_wlan_phy_open_cca(void)
void bk_wlan_phy_close_cca(void)
void bk_wlan_phy_show_cca(void)
bk_err_t bk_wifi_ftm_start(const wifi_ftm_config_t *config, wifi_ftm_results_t *ftm_results)

Start a fine timing measurement (FTM)

This API notifies the WiFi driver to start a fine timing measurement, and get the ftm results.

参数
  • config – the configuration of ftm

  • ftm_results – the results of ftm

返回

  • BK_OK: succeed

  • BK_ERR_WIFI_NOT_INIT: WiFi is not initialized

  • BK_ERR_WIFI_STA_NOT_STARTED: the STA is not started, call bk_wifi_sta_start() first.

  • BK_ERR_WIFI_DRIVER: WiFi low level driver has failure.

  • others: other failures.

bk_err_t bk_wifi_ftm_dump_result(const wifi_ftm_results_t *ftm_results)

Dump the ftm results.

Attention

call bk_wifi_ftm_start() first before call bk_wifi_ftm_dump_result.

参数

ftm_results – The ftm result to be dumped.

返回

  • BK_OK: succeed

  • BK_ERR_PARAM: invalid scan result

void bk_wifi_ftm_free_result(wifi_ftm_results_t *ftm_results)

Free the ftm result.

Attention

This API free ftm_results->rsp which allocated in bk_wifi_ftm_start(), it doesn’t free ftm_results. So if ftm_results is allocated by the caller, the caller need to free it.

参数

ftm_results – The ftm result to be freed.

返回

  • BK_OK: always succeed

void bk_wifi_set_pkt_trx_dbg_cfg(uint32_t cfg_bit)

Set Wi-Fi TX/RX debug log configuration.

This API could enable the TX/RX debug log by setting the corresponding debug bit.

Attention

This API is only used for DEBUG Wi-Fi issues according to frame TX/RX, there will be a lot of logs generated after set debug bit and it will have affect on the performance. To capture the whole logs, you should increase the buadrate of UART.

参数

cfg_bit – Please refer to enum wifi_pkt_dbg_bit to get more detail.

返回

  • void: always succeed

void bk_wifi_set_ap_channel(uint8_t channel)

Set Wi-Fi Softap Channel.

This API could be used to change softap operation channel.

@channel The valid channel ID should range from 1-14.

Attention

This API can only be used when softap is enabled and make sure the internal CSA strategy is disabled by calling API bk_feature_close_coexist_csa.

返回

  • void: always succeed

bk_err_t bk_wifi_set_block_bcmc_en(uint8_t config)

Enable Wi-Fi rx block broadcast and multicast frame.

This API could enable Wi-Fi rx block broadcast and multicast frame.

参数

config – block type. 0:WIFI_BCMC_CLOSE 1:WIFI_MC_ON, 2:WIFI_BC_ON, 3:WIFI_BC_MC_ON,

返回

  • void: always succeed

bool bk_wifi_get_block_bcmc_en(void)

Get Wi-Fi rx block broadcast and multicast frame status.

参数

void.

返回

  • enable status

bk_err_t bk_wifi_set_ani_en(bool enable)

Enable Wi-Fi microwave anti-interference policy.

This API could enable Wi-Fi microwave anti-interference policy.

参数

enable.

返回

  • void: always succeed

bool bk_wifi_get_ani_en(void)

Get Wi-Fi microwave anti-interference policy enable status.

参数

void.

返回

  • enable status

bk_err_t bk_wifi_get_tx_stats(uint8_t mode, struct tx_stats_t *tx_stats)

Get tx stats.

    PER calculation formula:  per = (tx_agg_fail + tx_singel_retry)/(tx_agg_total + tx_singel_total*SINGLE_RETRY_CNT)
    - tx_agg_fail/tx_singel_retry/tx_agg_total/tx_singel_total: get from struct tx_stats,
    - SINGLE_RETRY_CNT: get from function bk_wifi_get_data_rty_num();
参数

config – mode. 0:STATION 1:SOFT AP

返回

  • tx_stats:tx statistics

bk_err_t bk_wifi_get_tx_power(wifi_standard standard, float *powerdBm)

Fetch 802.11 TX power by standards.

参数
  • standard – IEEE 80211 standard

  • power – TX power in dBm

返回

  • kNoErr: succeed

  • otherwise: fail

bk_err_t bk_wifi_set_tx_power(wifi_standard standard, float powerdBm)

Update 802.11 TX power by standards.

参数
  • standard – IEEE 80211 standard

  • power – TX power in dBm

返回

  • kNoErr: succeed

  • otherwise: fail