蓝牙API
蓝牙API提供低功耗蓝牙(BLE)通信和管理接口。
Header File
Functions
-
ble_err_t bk_ble_create_db(struct bk_ble_db_cfg *ble_db_cfg)
Register a gatt service.
User example: First we must build test_service_db test_service_db is a database for att, which used in ble discovery. reading writing and other operation is used on a att database.
TEST_IDX_SVC is nessecery, is declare a primary att service. The macro define is:enum { TEST_IDX_SVC, TEST_IDX_CHAR_DECL, TEST_IDX_CHAR_VALUE, TEST_IDX_CHAR_DESC, TEST_IDX_CHAR_DATALEN_DECL, TEST_IDX_CHAR_DATALEN_VALUE, TEST_IDX_CHAR_INTER_DECL, TEST_IDX_CHAR_INTER_VALUE, TEST_IDX_NB, }; //att records database. ble_attm_desc_t test_service_db[TEST_IDX_NB] = { // Service Declaration [TEST_IDX_SVC] = {DECL_PRIMARY_SERVICE_128, BK_BLE_PERM_SET(RD, ENABLE), 0, 0}, // Characteristic declare [TEST_IDX_CHAR_DECL] = {DECL_CHARACTERISTIC_128, BK_BLE_PERM_SET(RD, ENABLE), 0, 0}, // Characteristic Value [TEST_IDX_CHAR_VALUE] = {{0x34, 0x12, 0}, BK_BLE_PERM_SET(NTF, ENABLE), BK_BLE_PERM_SET(RI, ENABLE) | BK_BLE_PERM_SET(UUID_LEN, UUID_16), 128}, //Client Characteristic Configuration Descriptor [TEST_IDX_CHAR_DESC] = {DESC_CLIENT_CHAR_CFG_128, BK_BLE_PERM_SET(RD, ENABLE) | BK_BLE_PERM_SET(WRITE_REQ, ENABLE), 0, 0}, };
#define DECL_PRIMARY_SERVICE_128 {0x00,0x28,0}which is an UUID say it is a “primary service” BK_BLE_PERM_SET(RD, ENABLE) means it can be read, and must be read, so it can be discove by peer master.
TEST_IDX_CHAR_DECL declare a characteristic as a element in service, it must be BK_BLE_PERM_SET(RD, ENABLE)
show it’s a “characteristic”#define DECL_CHARACTERISTIC_128 {0x03,0x28,0}BK_BLE_PERM_SET(RD, ENABLE) means it can be read, and must be read, so it can be discove by peer master.
TEST_IDX_CHAR_VALUE is the real value of TEST_IDX_CHAR_DECL, {0x34, 0x12, 0} means it’s type is 0x1234, you can determine by you self BK_BLE_PERM_SET(NTF, ENABLE) means it cant notify peer, such as value change. For exzample, BLE mouse report pos by “notify” peer. BK_BLE_PERM_SET(RI, ENABLE) means if peer read this att record, it will enable notification. BK_BLE_PERM_SET(UUID_LEN, UUID_16) means the first elem’s max len of TEST_IDX_CHAR_VALUE.
TEST_IDX_CHAR_DESC is a Client Characteristic Configuration Descriptor for TEST_IDX_CHAR_VALUE, it used by peer master as know as a client. As common usage, it config TEST_IDX_CHAR_VALUE indication or notification. Peer can write this att handle to triggle it. Must be BK_BLE_PERM_SET(RD, ENABLE) | BK_BLE_PERM_SET(WRITE_REQ, ENABLE)
Now, you have a basic database for peer, in this case, peer write TEST_IDX_CHAR_DESC or read TEST_IDX_CHAR_VALUE to enable notification, and then we notify peer by TEST_IDX_CHAR_VALUE
Secondlly, we build ble_db_cfg
prf_task_id is app handle. If you have multi att service, used prf_task_id to distinguish it. svc_perm show TEST_IDX_SVC UUID type’s len.struct bk_ble_db_cfg ble_db_cfg; ble_db_cfg.att_db = (ble_attm_desc_t *)test_service_db; ble_db_cfg.att_db_nb = TEST_IDX_NB; ble_db_cfg.prf_task_id = g_test_prf_task_id; ble_db_cfg.start_hdl = 0; ble_db_cfg.svc_perm = BK_BLE_PERM_SET(SVC_UUID_LEN, UUID_16);
- 参数
- – ble_db_cfg: service param
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
void bk_ble_set_notice_cb(ble_notice_cb_t func)
Register ble event notification callback.
User example:
void ble_at_notice_cb(ble_notice_t notice, void *param) { switch (notice) { case BLE_5_WRITE_EVENT: { if (w_req->prf_id == g_test_prf_task_id) { switch(w_req->att_idx) { case TEST_IDX_CHAR_DECL: break; case TEST_IDX_CHAR_VALUE: break; case TEST_IDX_CHAR_DESC: //when peer enable notification, we create time and notify peer, such as //write_buffer = (uint8_t *)os_malloc(s_test_data_len); //bk_ble_send_noti_value(s_test_data_len, write_buffer, g_test_prf_task_id, TEST_IDX_CHAR_VALUE); break; default: break; } } break; } case BLE_5_CREATE_DB: //bk_ble_create_db success here break; } } bk_ble_set_notice_cb(ble_at_notice_cb);
- Attention
1. you must regist it, otherwise you cant get any event !
- Attention
2. you must regist it before bk_ble_create_db, otherwise you cant get BLE_5_CREATE_DB event
- 参数
- – func: event callback
- 返回
void
-
uint8_t bk_ble_appm_get_dev_name(uint8_t *name, uint32_t buf_len)
Get device name.
- 参数
- – name: store the device name
buf_len: the length of buf to store the device name
- 返回
length: the length of device name
-
uint8_t bk_ble_appm_set_dev_name(uint8_t len, uint8_t *name)
Set device name.
- 参数
- – len: the length of device name
name: the device name to be set
- 返回
length: the length of device name
-
ble_err_t bk_ble_create_advertising(uint8_t actv_idx, ble_adv_param_t *adv_param, ble_cmd_cb_t callback)
Create a ble advertising activity.
User example:
ble_adv_param_t adv_param; adv_param.own_addr_type = 0;//BLE_STATIC_ADDR adv_param.adv_type = 0; //ADV_IND adv_param.chnl_map = 7; adv_param.adv_prop = 3; adv_param.adv_intv_min = 0x120; //min adv_param.adv_intv_max = 0x160; //max adv_param.prim_phy = 1;// 1M adv_param.second_phy = 1;// 1M actv_idx = bk_ble_get_idle_actv_idx_handle(); if (actv_idx != UNKNOW_ACT_IDX) { bk_ble_create_advertising(actv_idx, &adv_param, ble_at_cmd_cb); }
- Attention
1.you must wait callback status, 0 mean success.
- 参数
- – actv_idx: the index of activity
adv_param: the advertising parameter
callback: register a callback for this action, ble_cmd_t: BLE_CREATE_ADV
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_start_advertising(uint8_t actv_idx, uint16 duration, ble_cmd_cb_t callback)
Start a ble advertising.
- Attention
1.you must wait callback status, 0 mean success.
- Attention
2.must used after bk_ble_create_advertising
- 参数
- – actv_idx: the index of activity
duration: Advertising duration (in unit of 10ms). 0 means that advertising continues
callback: register a callback for this action, ble_cmd_t: BLE_START_ADV
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_stop_advertising(uint8_t actv_idx, ble_cmd_cb_t callback)
Stop the advertising that has been started.
- Attention
1.you must wait callback status, 0 mean success.
- Attention
2.must used after bk_ble_start_advertising
- 参数
- – actv_idx: the index of activity
callback: register a callback for this action, ble_cmd_t: BLE_STOP_ADV
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_delete_advertising(uint8_t actv_idx, ble_cmd_cb_t callback)
Delete the advertising that has been created.
- Attention
1.you must wait callback status, 0 mean success.
- Attention
2.must used after bk_ble_create_advertising
- 参数
- – actv_idx: the index of activity
callback: register a callback for this action, ble_cmd_t: BLE_DELETE_ADV
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_set_adv_data(uint8_t actv_idx, uint8_t *adv_buff, uint8_t adv_len, ble_cmd_cb_t callback)
Set the advertising data.
User example:
const uint8_t adv_data[] = {0x02, 0x01, 0x06, 0x0A, 0x09, 0x37 0x32, 0x33, 0x31, 0x4e, 0x5f, 0x42, 0x4c, 0x45}; bk_ble_set_adv_data(actv_idx, adv_data, sizeof(adv_data), ble_at_cmd_cb);
- Attention
1.you must wait callback status, 0 mean success.
- Attention
2.must used after bk_ble_create_advertising
- 参数
- – actv_idx: the index of activity
adv_buff: advertising data
adv_len: the length of advertising data
callback: register a callback for this action, ble_cmd_t: BLE_SET_ADV_DATA
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_set_scan_rsp_data(uint8_t actv_idx, uint8_t *scan_buff, uint8_t scan_len, ble_cmd_cb_t callback)
Set the scan response data.
User example:
const uint8_t scan_data[] = {0x02, 0x01, 0x06, 0x0A, 0x09, 0x37 0x32, 0x33, 0x31, 0x4e, 0x5f, 0x42, 0x4c, 0x45}; bk_ble_set_scan_rsp_data(actv_idx, scan_data, sizeof(scan_data), ble_at_cmd_cb);
- Attention
1.you must wait callback status, 0 mean success.
- Attention
2.scan rsp data similaly to adv data
- Attention
3.must used after bk_ble_create_advertising
- 参数
- – actv_idx: the index of activity
scan_buff: scan response data
scan_len: the length of scan response data
callback: register a callback for this action, ble_cmd_t: BLE_SET_RSP_DATA
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_set_per_adv_data(uint8_t actv_idx, uint8_t *per_adv_buff, uint8_t per_adv_len, ble_cmd_cb_t callback)
Set the periodic advertising data.
User example:
const uint8_t adv_data[] = {0x02, 0x01, 0x06, 0x0A, 0x09, 0x37 0x32, 0x33, 0x31, 0x4e, 0x5f, 0x42, 0x4c, 0x45}; bk_ble_set_per_adv_data(actv_idx, adv_data, sizeof(adv_data), ble_at_cmd_cb);
- Attention
1.you must wait callback status, 0 mean success.
- Attention
2.must used after bk_ble_create_advertising
- 参数
- – actv_idx: the index of activity
per_adv_buff: periodic advertising data
per_adv_len: the length of periodic advertising data
callback: register a callback for this action, ble_cmd_t: BLE_SET_ADV_DATA????
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_set_adv_random_addr(uint8_t actv_idx, uint8_t *addr, ble_cmd_cb_t callback)
Set the adv random addr.
- Attention
1.you must wait callback status, 0 mean success.
- Attention
2.must used after bk_ble_create_advertising
- 参数
- – actv_idx: the index of activity
addr: random address
callback: register a callback for this action, ble_cmd_t: BLE_SET_ADV_RANDOM_ADDR
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_read_phy(uint8_t conn_idx)
Read the phy of connection device.
User example:
bk_ble_read_phy(conn_idx);
- Attention
1.must used after after connected
- 参数
- – conn_idx: the index of connection device
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_set_phy(uint8_t conn_idx, ble_set_phy_t *phy_info)
Set the phy of connection device.
User example:
ble_set_phy_t * phy = {0x04, 0x01, 0x01}; //set tx phy to s2 coded phy, and set rx phy to 1M phy bk_ble_set_phy(1, phy);
- Attention
1.must used after after connected
- 参数
- – conn_idx: the index of connection device
phy_info: phy parameters
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_update_param(uint8_t conn_idx, ble_conn_param_t *conn_param)
Update connection parameters.
- Attention
1.must used after connected
- 参数
- – conn_idx: the index of connection
conn_param: connection parameters
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_disconnect(uint8_t conn_idx)
Disconnect a ble connection.
- Attention
1.must used after connected
- 参数
- – conn_idx: the index of connection
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_gatt_mtu_change(uint8_t conn_idx)
Exchange MTU.
- Attention
1.must used after connected
- 参数
- – conn_idx: the index of connection
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_set_max_mtu(uint16_t max_mtu)
Set maximal Exchange MTU.
- Attention
1.must used before connected
- 参数
- – max_mtu: the value to set
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_create_scaning(uint8_t actv_idx, ble_scan_param_t *scan_param, ble_cmd_cb_t callback)
Create a ble scan activity.
User exzample:
ble_scan_param_t scan_param; scan_param.own_addr_type = 0;//BLE_STATIC_ADDR scan_param.scan_phy = 5; scan_param.scan_intv = 0x64; //interval scan_param.scan_wd = 0x1e; //windows bk_ble_create_scaning(actv_idx, &, ble_at_cmd);
- Attention
1.you must wait callback status, 0 mean success.
- 参数
- – actv_idx: the index of activity
scan_param: the scan parameter
callback: register a callback for this action, ble_cmd_t: BLE_CREATE_SCAN
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_start_scaning(uint8_t actv_idx, ble_cmd_cb_t callback)
Start a ble scan.
- Attention
1.you must wait callback status, 0 mean success.
- Attention
2.must used after bk_ble_create_scaning
- Attention
3.adv will report in ble_notice_cb_t as BLE_5_REPORT_ADV
- 参数
- – actv_idx: the index of activity
callback: register a callback for this action, ble_cmd_t: BLE_START_SCAN
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_start_scaning_ex(uint8_t actv_idx, uint8_t filt_duplicate, uint16_t duration, uint16_t period, ble_cmd_cb_t callback)
-
ble_err_t bk_ble_stop_scaning(uint8_t actv_idx, ble_cmd_cb_t callback)
Stop the scan that has been started.
- Attention
1.you must wait callback status, 0 mean success.
- Attention
2.must used after bk_ble_start_scaning
- 参数
- – actv_idx: the index of activity
callback: register a callback for this action, ble_cmd_t: BLE_STOP_SCAN
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_delete_scaning(uint8_t actv_idx, ble_cmd_cb_t callback)
Delete the scan that has been created.
- Attention
1.you must wait callback status, 0 mean success.
- Attention
2.must used after bk_ble_create_scaning
- 参数
- – actv_idx: the index of activity
callback: register a callback for this action, ble_cmd_t: BLE_DELETE_SCAN
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_create_init(uint8_t con_idx, ble_conn_param_t *conn_param, ble_cmd_cb_t callback)
Create a activity for initiating a connection.
User example:
ble_conn_param_t conn_param; conn_param.intv_min = 0x40; //interval conn_param.intv_max = 0x40; //interval conn_param.con_latency = 0; conn_param.sup_to = 0x200;//supervision timeout conn_param.init_phys = 1;// 1M bk_ble_create_init(con_idx, &conn_param, ble_at_cmd);
- Attention
1.you must wait callback status, 0 mean success.
- 参数
- – con_idx: the index of connection
conn_param: the connection parameter
callback: register a callback for this action, ble_cmd_t: BLE_INIT_CREATE
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_init_start_conn(uint8_t con_idx, ble_cmd_cb_t callback)
Initiate a connection.
- Attention
1.you must wait callback status, 0 mean success.
- Attention
2.must used after bk_ble_create_init
- Attention
3.when connect result, will recv BLE_5_INIT_CONNECT_EVENT in ble_notice_cb_t
- 参数
- – con_idx: the index of connection
callback: register a callback for this action, ble_cmd_t: BLE_INIT_START_CONN
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_init_stop_conn(uint8_t con_idx, ble_cmd_cb_t callback)
Stop a connection.
- Attention
1.you must wait callback status, 0 mean success.
- Attention
2.must used after bk_ble_init_start_conn
- 参数
- – con_idx: the index of connection
callback: register a callback for this action, ble_cmd_t: BLE_INIT_STOP_CONN
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_init_set_connect_dev_addr(uint8_t connidx, bd_addr_t *bdaddr, uint8_t addr_type)
Set the address of the device to be connected.
- Attention
1.you must wait callback status, 0 mean success.
- Attention
2.must used after bk_ble_create_init
- Attention
3.addr_type must right, if wrong, cant connect
- 参数
- – connidx: the index of connection
bdaddr: the address of the device to be connected
addr_type: the address type of the device to be connected, 0: public 1: random
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_create_periodic_sync(uint8_t actv_idx, ble_cmd_cb_t callback)
-
ble_err_t bk_ble_start_periodic_sync(uint8_t actv_idx, ble_periodic_param_t *param, ble_cmd_cb_t callback)
-
ble_err_t bk_ble_stop_periodic_sync(uint8_t actv_idx, ble_cmd_cb_t callback)
-
ble_err_t bk_ble_delete_periodic_sync(uint8_t actv_idx, ble_cmd_cb_t callback)
-
uint8_t bk_ble_get_idle_actv_idx_handle(void)
Get an idle activity.
- 返回
xx: the idle activity’s index
-
uint8_t bk_ble_get_max_actv_idx_count(void)
Get the maximum count of activities.
- 返回
xx: the maximum count of activities
-
uint8_t bk_ble_get_max_conn_idx_count(void)
Get the maximum count of supported connections.
- 返回
xx: the maximum count of supported connections
-
uint8_t bk_ble_get_idle_conn_idx_handle(void)
Get an idle connection activity.
- 返回
xx: the idle connection activity’s index
-
uint8_t bk_ble_find_conn_idx_from_addr(bd_addr_t *connt_addr)
Find the specific connection activity by address.
- 参数
- – connt_addr: the address of the connected device
- 返回
xx: the index of the connection activity meeting the address
-
uint8_t bk_ble_get_connect_state(bd_addr_t *connt_addr)
Get the connection state of the specific device.
- 参数
- – connt_addr: the device’s address
- 返回
1: this device is connected
0: this device is disconnected
-
ble_err_t bk_ble_get_mac(uint8_t *mac)
get ble mac addr,this api is deprecated,please use bk_bluetooth_get_address
- Attention
1. return mac is 6 bytes.
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_send_noti_value(uint8_t con_idx, uint32_t len, uint8_t *buf, uint16_t prf_id, uint16_t att_idx)
As slaver, send a notification of an attribute’s value.
- 参数
- – con_idx: the index of connection
len: the length of attribute’s value
buf: attribute’s value
prf_id: The id of the profile
att_idx: The index of the attribute
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_send_ind_value(uint8_t con_idx, uint32_t len, uint8_t *buf, uint16_t prf_id, uint16_t att_idx)
As slaver, send an indication of an attribute’s value.
- 参数
- – con_idx: the index of connection
len: the length of attribute’s value
buf: attribute’s value
prf_id: The id of the profile
att_idx: The index of the attribute
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_reg_hci_recv_callback(ble_hci_to_host_cb evt_cb, ble_hci_to_host_cb acl_cb)
reg hci recv callback
- Attention
1. you must call this after recv BLE_5_STACK_OK evt !
- 参数
- – evt_cb: evt callback function
acl_cb: acl callback function
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_hci_to_controller(uint8_t type, uint8_t *buf, uint16_t len)
send hci to controller.
- Attention
1. you must call this after bk_ble_reg_hci_recv_callback !
- 参数
- – type: see BK_BLE_HCI_TYPE.
buf: payload
len: buf’s len
- 返回
BK_ERR_BLE_SUCCESS: succeed
-
ble_err_t bk_ble_hci_cmd_to_controller(uint8_t *buf, uint16_t len)
send hci cmd to controller.
- Attention
1. you must call this after bk_ble_reg_hci_recv_callback !
- 参数
- – buf: payload
len: buf’s len
- 返回
BK_ERR_BLE_SUCCESS: succeed
-
ble_err_t bk_ble_hci_acl_to_controller(uint8_t *buf, uint16_t len)
send hci acl to controller.
- Attention
1. you must call this after bk_ble_reg_hci_recv_callback !
- 参数
- – buf: payload
len: buf’s len
- 返回
BK_ERR_BLE_SUCCESS: succeed
-
uint8_t bk_ble_if_support_central(uint8_t *count)
-
BK_BLE_CONTROLLER_STACK_TYPE bk_ble_get_controller_stack_type(void)
-
BK_BLE_HOST_STACK_TYPE bk_ble_get_host_stack_type(void)
-
uint8_t bk_ble_get_env_state(void)
-
void bk_ble_register_app_sdp_charac_callback(app_sdp_charac_callback cb)
-
void bk_ble_register_app_sdp_common_callback(app_sdp_comm_callback cb)
-
uint8_t bk_ble_gatt_write_ccc(uint8_t con_idx, uint16_t ccc_handle, uint16_t ccc_value)
As master, enable notification or indication.
- 参数
- – con_idx: the index of connection
ccc_handle: the handle of Client Characteristic Configuration descriptor
ccc_value: descriptor value, 0x01 means notification ,0x02 means indication
- 返回
0: succeed
others: errors.
-
ble_err_t bk_ble_gatt_write_value(uint8_t con_idx, uint16_t att_handle, uint16_t len, uint8_t *data)
As master, write attribute value.
- 参数
- – con_idx: the index of connection
att_handle: the handle of attribute value
data: value data
len: the length of attribute value
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_read_response_value(uint8_t con_idx, uint32_t len, uint8_t *buf, uint16_t prf_id, uint16_t att_idx)
As slaver, send response value.
- 参数
- – con_idx: the idx of app connections
len: the length of attribute’s value
buf: attribute’s value
prf_id: The id of the profile
att_idx: The index of the attribute
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_sec_send_auth_mode(uint8_t con_idx, uint8_t mode, uint8_t iocap, uint8_t sec_req, uint8_t oob)
As master, configure attribute value.
- 参数
- – con_idx: the index of connection
mode: authentication features
iocap: IO Capability Values
sec_req: Security Defines
oob: OOB Data Present Flag Values
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_sec_send_auth_mode_ext(uint8_t con_idx, uint8_t mode, uint8_t iocap, uint8_t sec_req, uint8_t oob, uint8_t initiator_key_distr, uint8_t responder_key_distr)
As master, configure auth mode param.
- 参数
- – con_idx: the index of connection
mode: authentication features
iocap: IO Capability Values
sec_req: Security Defines
oob: OOB Data Present Flag Values
initiator_key_distr: init key distr, see gap_key_distr
responder_key_distr: resp key distr, see gap_key_distr
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_init(void)
ble init function,this api is deprecated,please use bk_bluetooth_init.
- Param
-
ble_err_t bk_ble_deinit(void)
ble deinit function,this api is deprecated,please use bk_bluetooth_deinit.
- Param
-
ble_err_t bk_ble_delete_service(struct bk_ble_db_cfg *ble_db_cfg)
Unregister a gatt service.
User example:
struct bk_ble_db_cfg ble_db_cfg; uint16 service_uuid = 0x1800; os_memcpy(&(ble_db_cfg.uuid[0]), &service_uuid, 2); ble_db_cfg.svc_perm = BK_BLE_PERM_SET(SVC_UUID_LEN, UUID_16);
- Attention
1.you must set the uuid of service and the len of uuid.
- 参数
- – ble_db_cfg: service param
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_att_read(uint8_t con_idx, uint16_t att_handle)
As master, read attribute value, the result is reported in the callback registered through bk_ble_register_app_sdp_charac_callback.
- 参数
- – con_idx: the index of connection
att_handle: the handle of attribute value
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_create_bond(uint8_t con_idx, uint8_t auth, uint8_t iocap, uint8_t sec_req, uint8_t oob)
start authentication the link
- Attention
if the link has not been bonded, it will trigger pairing, otherwise it will trigger the link encryption.
- 参数
- – con_idx: the index of connection
auth: authentication features(see enum gap_auth)
iocap: IO Capability Values(see enum bk_ble_gap_io_cap)
sec_req: Security Defines(see enum gap_sec_req)
oob: OOB Data Present Flag Values(see enum gap_oob)
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_create_bond_ext(uint8_t con_idx, uint8_t auth, uint8_t iocap, uint8_t sec_req, uint8_t oob, uint8_t initiator_key_distr, uint8_t responder_key_distr)
create bond
- Attention
if the link has not been bonded, it will trigger pairing, otherwise it will trigger the link encryption.
- 参数
- – con_idx: the index of connection
auth: authentication features(see enum gap_auth)
iocap: IO Capability Values(see enum bk_ble_gap_io_cap)
sec_req: Security Defines(see enum gap_sec_req)
oob: OOB Data Present Flag Values(see enum gap_oob)
initiator_key_distr: init key distr, see gap_key_distr
responder_key_distr: resp key distr, see gap_key_distr
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_passkey_send(uint8_t con_idx, uint8_t accept, uint32_t passkey)
send passkey when pairing
- 参数
- – con_idx: the index of connection
accept: accept pair
passkey: the num that peer need to input or local need to input
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_number_compare_send(uint8_t con_idx, uint8_t accept)
send number compare accept when pairing
- 参数
- – con_idx: the index of connection
accept: accept pair
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_read_rssi(uint8_t conn_idx)
Read the rssi of connection device. The result will report in callback registered through bk_ble_set_notice_cb with evt BLE_5_READ_RSSI_CMPL_EVENT, and param is ble_read_rssi_rsp_t *.
User example:
bk_ble_read_rssi(conn_idx);
- Attention
1.must used after after connected
- 参数
- – conn_idx: the index of connection device
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_config_local_appearance(uint16_t appearance)
set local gap appearance
- 参数
appearance – [in] - External appearance value, these values are defined by the Bluetooth SIG, please refer to https://specificationrefs.bluetooth.com/assigned-values/Appearance%20Values.pdf
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: other errors.
-
ble_err_t bk_ble_discover_primary_service(uint8_t conn_id, uint16_t sh, uint16_t eh)
Discover peer primary service. The result is report in the callback registered through bk_ble_register_app_sdp_common_callback, and evt is MST_TYPE_DISCOVER_PRI_SERVICE_RSP. When completed, callback will report MST_TYPE_DISCOVER_COMPLETED with ble_descover_complete_inf and MST_TYPE_DISCOVER_PRI_SERVICE_RSP.
- 参数
- – sh: att start handle
eh: att end handle
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_discover_primary_service_by_uuid(uint8_t conn_id, uint16_t sh, uint16_t eh, uint16_t uuid)
Discover peer primary service. The result is report in the callback registered through bk_ble_register_app_sdp_common_callback, and evt is MST_TYPE_DISCOVER_PRI_SERVICE_BY_UUID_RSP. When completed, callback will report MST_TYPE_DISCOVER_COMPLETED with ble_descover_complete_inf and MST_TYPE_DISCOVER_PRI_SERVICE_BY_UUID_RSP.
- 参数
- – sh: att start handle
eh: att end handle
- 返回
BK_ERR_BLE_SUCCESS: succeed
-
ble_err_t bk_ble_discover_primary_service_by_128uuid(uint8_t conn_id, uint16_t sh, uint16_t eh, uint8_t *uuid)
Discover peer primary service. The result is report in the callback registered through bk_ble_register_app_sdp_common_callback, and evt is MST_TYPE_DISCOVER_PRI_SERVICE_BY_128_UUID_RSP. When completed, callback will report MST_TYPE_DISCOVER_COMPLETED with ble_descover_complete_inf and MST_TYPE_DISCOVER_PRI_SERVICE_BY_128_UUID_RSP. bk_ble_read_rssi(conn_idx);.
- 参数
- – conn_id: the index of connection
sh: att start handle
eh: att end handle
uuid: uuid that service need to find in 128bits
- 返回
others: fail
-
ble_err_t bk_ble_discover_characteristic(uint8_t conn_id, uint16_t sh, uint16_t eh)
Discover peer characteristic. The result is report in the callback registered through bk_ble_register_app_sdp_common_callback, and evt is MST_TYPE_DISCOVER_CHAR_RSP. When completed, callback will report MST_TYPE_DISCOVER_COMPLETED with ble_descover_complete_inf and MST_TYPE_DISCOVER_CHAR_RSP.
- 参数
- – conn_id: the index of connection
sh: att start handle
eh: att end handle
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_discover_characteristic_by_uuid(uint8_t conn_id, uint16_t sh, uint16_t eh, uint16_t uuid)
Discover peer characteristic. The result is report in the callback registered through bk_ble_register_app_sdp_common_callback, and evt is MST_TYPE_DISCOVER_CHAR_BY_UUID_RSP. When completed, callback will report MST_TYPE_DISCOVER_COMPLETED with ble_descover_complete_inf and MST_TYPE_DISCOVER_CHAR_BY_UUID_RSP.
- 参数
- – conn_id: the index of connection
sh: att start handle
eh: att end handle
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_discover_characteristic_by_128uuid(uint8_t conn_id, uint16_t sh, uint16_t eh, uint8_t *uuid)
Discover peer characteristic. The result is report in the callback registered through bk_ble_register_app_sdp_common_callback, and evt is MST_TYPE_DISCOVER_CHAR_BY_128_UUID_RSP. When completed, callback will report MST_TYPE_DISCOVER_COMPLETED with ble_descover_complete_inf and MST_TYPE_DISCOVER_CHAR_BY_128_UUID_RSP.
- 参数
- – conn_id: the index of connection
sh: att start handle
eh: att end handle
- 返回
others: fail
-
ble_err_t bk_ble_discover_characteristic_descriptor(uint8_t conn_id, uint16_t sh, uint16_t eh)
Discover peer characteristic descriptor. The result is report in the callback registered through bk_ble_register_app_sdp_common_callback, and evt is MST_TYPE_DISCOVER_CHAR_DESC. When completed, callback will report MST_TYPE_DISCOVER_COMPLETED with ble_descover_complete_inf and MST_TYPE_DISCOVER_CHAR_DESC.
- 参数
- – conn_id: the index of connection
sh: att start handle
eh: att end handle
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_gattc_read(uint8_t con_idx, uint16_t att_handle, uint16_t offset)
As master, read attribute value, the result is reported in the callback registered through bk_ble_register_app_sdp_charac_callback.
- 参数
- – con_idx: the index of connection
att_handle: the handle of attribute value
offset: the offset of attribute value
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_gattc_read_by_uuid(uint8_t conn_id, uint16_t sh, uint16_t eh, uint8_t *uuid, uint8_t uuid_len)
As master, read attribute value, the result is reported in the callback registered through bk_ble_register_app_sdp_charac_callback.
- 参数
- – con_idx: the index of connection
sh: the start handle of attribute
eh: the end handle of attribute
uuid: uuid
uuid_len: uuid len, may be 2 or 16
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_gattc_write(uint8_t con_idx, uint16_t att_handle, uint8_t *data, uint16_t len, uint8_t is_write_cmd)
As master, write attribute value.
- 参数
- – con_idx: the index of connection
att_handle: the handle of attribute value
data: value data
len: the length of attribute value
is_write_cmd: when true, will trigger write cmd, otherwise write req.
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_clear_white_list(void)
clear the white list.
- Param
-
ble_err_t bk_ble_add_devices_to_while_list(bd_addr_t *addr, uint8_t addr_type)
Add a device to the while list.
- 参数
- – addr: the address of the device.
addr_type: the type of the address, 0 is public address, 1 is random address.
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_remove_devices_from_while_list(bd_addr_t *addr, uint8_t addr_type)
Remove a device from the while list.
- 参数
- – addr: the address of the device.
addr_type: the type of the address, 0 is public address, 1 is random address.
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_set_tx_powr(uint8_t pwr_gain)
Set tx power.
- 参数
- – pwr_gain: tx power gain
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail
-
ble_err_t bk_ble_enable_uart_controller_only(uint8_t enable, bluetooth_uart_controller_only_config_t *config)
enable controller only by uart.
- 参数
- – enable: enable or disable.
config: uart config
- 返回
BK_ERR_BLE_SUCCESS: succeed
others: fail