1.1. 蓝牙接口说明
1.1.1. 蓝牙初始化
蓝牙初始化部分以hid里面的app_keyboard.c case进行举例说明。
- void bt_pll_para(u32 osc, u32 sys, u8 low_power, u8 xosc)。
[brief] 设置蓝牙pll参数
[in] osc:蓝牙时钟频率; sys:系统时钟频率; low_power:待定;xosc:待定。
[out]
- void user_sele_dut_mode(bool set)。
[brief] 设置蓝牙dut模式使能。
[in] set:设置使能或者失能,默认不调用为失能。
[out]
- void btstack_ble_start_before_init(const ble_init_cfg_t *cfg, int param)。
[brief] 协议栈配置,协议栈初始化前调用。
[in] cfg:蓝牙初始化配置; param:预留。
[out]
[note] cfg参数包括对蓝牙图标设置,hid设备对report_map设置,设备电量设置。
le_hogp_set_icon(cfg->appearance);//蓝牙图标设置
le_hogp_set_ReportMap((u8 *)cfg->report_map, cfg->report_map_size);//设置hid report_map
le_hogp_regiest_get_battery(app_power_get_vbat_percent);//电量设置
- void bt_ble_before_start_init(void)。
[brief] 协议栈配置,对ble_comm_init(&hogp_gatt_control_block)主要说明
[in] hogp_gatt_control_block GATT传参
[out]
[note] 设置mut大小(GATT收发包大小)
[note] gatt cbuffer大小(GATT收发数据使用的buffer)
[note] server_config配置GATT从机配置,包括att_read/att_write/event_packet回调(用于接收主机数据处理)
[note] client_config配置GATT主机配置,一般只包括event_packet回调
static gatt_ctrl_t hogp_gatt_control_block = {
//public
.mtu_size = ATT_LOCAL_MTU_SIZE,//设置mut大小
.cbuffer_size = ATT_SEND_CBUF_SIZE,//gatt cbuffer大小
.multi_dev_flag = 0, //多机使用标识
const gatt_server_cfg_t hogp_server_init_cfg = {
.att_read_cb = &hogp_att_read_callback, //处理client 读操作,profile的读属性uuid 有配置 DYNAMIC 关键字,就有read_callback 回调
.att_write_cb = &hogp_att_write_callback, //处理client 写操作,profile的读属性uuid 有配置 DYNAMIC 关键字,就有write_callback 回调
.event_packet_handler = &hogp_event_packet_handler,//处理 gatt common 事件,hci & gatt
};
static const gatt_client_cfg_t central_client_init_cfg = {
.event_packet_handler = dg_central_event_packet_handler,//处理 gatt common 事件,hci & gatt
};
- void le_hogp_set_reconnect_adv_cfg(u8 adv_type, u32 adv_timeout)。
[brief] 配置回连广播使用的参数
[in] adv_type:回连广播类型; adv_timeout:回连广播超时时间。
[out]
- void cfg_file_parse(u8 idx)。
[brief] 蓝牙地址/名字/发射功率配置
[in] idx 预留。
[out]
[note] user_cfg.c中ble_name可以设置蓝牙的名字。
[note] 蓝牙地址按照规范生成,且生成一次不会再变化(存到vm里面)
[note] 通过设置SET_BLE_TX_POWER_LEVEL定义可以选择不同的发射功率档位
BT_CONFIG bt_cfg = {
.ble_name = "AW31N_HID",
syscfg_read(CFG_BT_MAC_ADDR, bt_mac_addr_for_testbox, 6);//读取mac_addr
/* #define SET_BLE_TX_POWER_LEVEL (0)//-5dBm */
/* #define SET_BLE_TX_POWER_LEVEL (1)//-2dBm */
#define SET_BLE_TX_POWER_LEVEL (2)//0dBm
/* #define SET_BLE_TX_POWER_LEVEL (3)//4dBm */
/* #define SET_BLE_TX_POWER_LEVEL (4)//7dBm */
/* #define SET_BLE_TX_POWER_LEVEL (5)//10dBm */
- int btstack_init()。
[brief] 蓝牙协议栈初始化
[in]
[out]
[note] 信息说明:在log中 le_support:2,1 的打印,第一个参数BIT(1)代表是BLE,第二个参数代表蓝牙处于什么模式,1为普通模式。
[note] 信息说明:log中 le_config:1 1 0 0 的打印,参数1为config_le_hci_connection_num(总配置的链路数),参数2为config_le_gatt_server_num(配置的从机个数),参数3为config_le_gatt_client_num(配置的主机个数),参数4为config_le_sm_support_enable(是否支持加密)
//蓝牙BLE
#define BT_MODULE_LE BIT(1)
//蓝牙模式
#define BT_NORMAL 0x01//普通模式
#define BT_BQB 0x02//BQB模式
#define BT_FCC 0x04//FCC模式
#define BT_FRE 0x10//FRE模式 no use
#define BT_PER 0x20//PER模式 no use
#define BT_QUA 0x40//QUA模式 no use
#define CONFIG_BT_MODE BT_NORMAL//设置为普通模式
1.1.2. 蓝牙全部api
蓝牙相关 API 介绍,具体软件代码见 apps/include_lib/bt_include/le/ble_api.h
Defines
-
ble_op_set_own_address_type(address_type)
配置设备的地址类型,默认为 0(public address).
\function ble_cmd_ret_e ble_op_set_own_address_type(u8 address_type).
Note
!!!注意:设置的时候必须在、设置广播参数、或者扫描参数、或者创建连接参数前配置好.
- Parameters:
address_type – [in] Range: 0x00 to 0x03.
- Returns:
see ble_cmd_ret_e.
-
ble_op_adv_enable(enable)
开关BLE广播.
\function ble_cmd_ret_e ble_op_adv_enable(int enable).
Note
!!!注意:开广播前必现先配置好广播的参数.
- Parameters:
enable – [in] 广播使能 :0(dis) or 1(en).
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_adv_filter_policy(type)
配置广播过滤策略(决定链路层如何处理扫描、连接请求);默认为 0.
\function ble_cmd_ret_e ble_op_set_adv_filter_policy(u8 type).
Note
!!!注意:设置的时候必须在“设置广播参数ble_op_set_adv_param前配置好.
- Parameters:
type – [in] 类型 :Range: 0x00 to 0x03.
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_adv_param(adv_interval, adv_type, adv_channel)
配置广播参数.
\function ble_cmd_ret_e ble_op_set_adv_param(u16 adv_interval,u8 adv_type).
Note
!!!注意:设置的时候必现在广播关闭的状态下.
- Parameters:
adv_interval – [in] 广播周期,Range: 0x0020 to 0x4000 (unit: 0.625ms).
adv_type – [in] 广播类型,Range: 0x00 to 0x04.
adv_channel – [in] 广播类型通道,range:Range: 0x01 to 0x07.
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_adv_param_ext(adv_interval, adv_type, adv_channel, peer_info)
配置广播参数+配对信息(相比配对广播参数,这个函数主要是针对定向广播使用).
\function ble_cmd_ret_e ble_op_set_adv_param_ext(u16 adv_interval,u8 adv_type,u8 adv_channel,const u8 *peer_info).
Note
!!!注意:设置的时候必现在广播关闭的状态下.
- Parameters:
adv_interval – [in] 广播周期,Range: 0x0020 to 0x4000 (unit: 0.625ms).
adv_type – [in] 广播类型,Range: 0x00 to 0x04.
adv_channel – [in] 广播类型通道,range:Range: 0x01 to 0x07.
peer_info – [in] (全局变量地址),定向广播时,填入对方的地址信息.
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_adv_data(adv_len, adv_data)
配置广播 Advertising Data内容.
\function ble_cmd_ret_e ble_op_set_adv_data(u8 adv_len,const *u8 adv_data).
Note
!!!注意:设置的时候必现在广播关闭的状态下.
- Parameters:
adv_len – [in] adv 数据包长度,Range: 0x00 to 0x1f.
adv_data – [in] (全局变量地址),adv数据包地址.
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_rsp_data(rsp_len, rsp_data)
配置广播 Scan Response Data内容.
\function ble_cmd_ret_e ble_op_set_rsp_data(u8 rsp_len,const *u8 rsp_data).
Note
!!!注意:设置的时候必现在广播关闭的状态下.
- Parameters:
rsp_len – [in] rsp 包长度,Range: 0x00 to 0x1f.
adv_data – [in] (全局变量地址),rsp数据包地址.
- Returns:
see ble_cmd_ret_e.
-
ble_op_disconnect(con_handle)
请求断开 ble 连接.
\function ble_cmd_ret_e ble_op_disconnect(u16 con_handle).
- Parameters:
con_handle – [in] range: >0.
- Returns:
see ble_cmd_ret_e.
-
ble_op_disconnect_ext(con_handle, reason)
请求断开 ble 连接,by reason
\function ble_cmd_ret_e ble_op_disconnect(u16 con_handle).
- Parameters:
con_handle – [in] range: >0.
reason – [in] range: see spec.
- Returns:
see ble_cmd_ret_e.
-
ble_op_att_send_init(con_handle, att_ram_addr, att_ram_size, att_payload_size)
配置ATT发送模块RAM大小.
\function ble_cmd_ret_e ble_op_att_send_init(u16 con_handle,u8 *att_ram_addr,int att_ram_size,int att_payload_size).
- Parameters:
con_handle – [in] range: >0.
att_ram_addr – [in] 传入ATT发送模块ram地址,地址按4字节对齐.
att_ram_size – [in] 传入ATT发送模块ram大小.
att_payload_size – [in] 发送ATT包payload的最大长度 <= MTU的payload,range:20 to MTU的payload size.
- Returns:
see ble_cmd_ret_e.
-
ble_op_multi_att_send_init(att_ram_addr, att_ram_size, att_payload_size)
MULTI API: 配置ATT发送模块初始化.
\function ble_cmd_ret_e ble_op_multi_att_send_init(u8 *att_ram_addr,int att_ram_size,int att_payload_size).
Note
多机处理,只需要初始化一次就可以.
- Parameters:
att_ram_addr – [in] 传入ATT发送模块ram地址,地址按4字节对齐.
att_ram_size – [in] 传入ATT发送模块ram大小.
att_payload_size – [in] 发送ATT包payload的最大长度 <= MTU的payload,range:20 to MTU的payload size.
- Returns:
see ble_cmd_ret_e.
-
ble_op_multi_att_send_conn_handle(con_handle, handle_index, role)
MULTI API: 配置ATT模块 使用的连接con_handle.
\function ble_cmd_ret_e ble_op_multi_att_send_conn_handle(u16 con_handle,int handle_index,int0 rolev).
Note
多机处理.
- Parameters:
con_handle – [in] range:>0.
handle_index – [in] range: 0~7 //多连接的hanlde id.
role – [in] range: 0-gatt_sever,1-gatt_client.
- Returns:
see ble_cmd_ret_e.
-
ble_op_att_set_send_mtu(mtu)
根据对方的接收MTU大小,配置本地可发送MTU的payload大小.
\function ble_cmd_ret_e ble_op_att_set_send_mtu(u16 mtu).
- Parameters:
mtu – [in] 对方mtu payload的大小.
- Returns:
see ble_cmd_ret_e.
-
ble_op_multi_att_set_send_mtu(con_handle, mtu)
MULTI API: 根据对方的接收MTU大小,配置本地可发送的MTU的大小.
\function ble_cmd_ret_e ble_op_multi_att_set_send_mtu(u16 con_handle,u16 mtu).
- Parameters:
con_handle – [in] 连接 con_handle,range:>0.
mtu – [in] 对方mtu payload的大小.
- Returns:
see ble_cmd_ret_e.
-
ble_op_att_get_remain(remain_size_ptr)
获取ATT发送模块,cbuffer可写入数据的长度.
\function ble_cmd_ret_e ble_op_att_get_remain(int *remain_size_ptr).
Note
TODO 裸机中请勿多次调用,增加协议栈消耗
- Parameters:
remain_size_ptr – [out] 输出可写入长度值.
- Returns:
see ble_cmd_ret_e.
-
ble_op_multi_att_get_remain(con_handle, remain_size_ptr)
MULTI API: 获取ATT发送模块,cbuffer 可写入数据的长度.
\function ble_cmd_ret_e ble_op_multi_att_get_remain(u16 con_handle,int *remain_size_ptr).
- Parameters:
con_handle – [in] range:>0.
remain_size_ptr – [out] 输出可写入长度值.
- Returns:
see ble_cmd_ret_e.
-
ble_op_att_send_data(att_handle, data, len, att_op_type)
ATT操作handle发送数据.
\function ble_cmd_ret_e ble_op_att_send_data(u16 att_handle,u8 *data,u16 len, att_op_type_e att_op_type).
- Parameters:
att_handle – [in] att操作的handle.
data – [in] 数据地址.
len – [in] 数据长度 <= cbuffer 可写入的长度.
att_op_type – [in] see att_op_type_e (att.h).
- Returns:
see ble_cmd_ret_e.
-
ble_op_multi_att_send_data(con_handle, att_handle, data, len, att_op_type)
MULTI API: ATT操作handle发送数据.
\function ble_cmd_ret_e ble_op_multi_att_send_data(u16 con_handle,u16 att_handle,u8 *data,u16 len, att_op_type_e att_op_type).
Note
多机处理.
- Parameters:
con_handle – [in] 连接 con_handle,range:>0.
att_handle – [in] att操作handle.
data – [in] 数据地址.
len – [in] 数据长度 <= cbuffer 可写入的长度.
att_op_type – [in] see att_op_type_e (att.h).
- Returns:
see ble_cmd_ret_e.
-
ble_op_att_clear_send_data(void)
ATT操作,清缓存发送的数据缓存
\function ble_op_att_clear_data(void).
- Returns:
see ble_cmd_ret_e.
-
ble_op_conn_param_request(con_handle, con_param)
从机请求更新连接参数,走l2cap命令.
\function ble_cmd_ret_e ble_op_conn_param_request(u16 con_handle,const struct conn_update_param_t *con_param).
- Parameters:
con_handle – [in] 连接 con_handle,range:>0.
con_param – [in] (全局变量地址),连接参数.
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_data_length(con_handle, tx_octets, tx_time)
发起data length 交换.(btctrl的feature打开支持DLE)
\function ble_cmd_ret_e ble_op_set_data_length(u16 con_handle,u16 tx_octets,u16 tx_time).
- Parameters:
tx_octets – [in] DLE发送长度.
tx_time – [in] DLE发送事件.
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_ext_adv_param(param, param_len)
ble5.0 配置广播参数.
\function ble_cmd_ret_e ble_op_set_ext_adv_param(u8 *param,u16 param_len).
- Parameters:
param – [in] 广播参数.
tx_time – [in] 参数长度.
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_ext_adv_data(data, data_len)
ble5.0 配置 adv 数据包.
\function ble_cmd_ret_e ble_op_set_ext_adv_data(u8 *data,u16 data_len).
- Parameters:
data – [in] 数据包内容.
data_len – [in] 数据包长度.
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_ext_rsp_data(data, data_len)
ble5.0 配置 respond 数据包.
\function ble_cmd_ret_e ble_op_set_ext_rsp_data(u8 *data,u16 data_len).
- Parameters:
data – [in] 数据包内容.
data_len – [in] 数据包长度.
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_ext_adv_enable(cmd, cmd_len)
ble5.0 开关广播.
\function ble_cmd_ret_e ble_op_set_ext_adv_enable(u8 *cmd,u16 cmd_le).
- Parameters:
cmd – [in] 命令信息.
cmd_len – [in] 命令长度.
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_ext_phy(con_handle, all_phys, tx_phy, rx_phy, phy_options)
ble5.0 配置phy.
\function ble_cmd_ret_e ble_op_set_ext_phy(u16 con_handle,u16 all_phys,u16 tx_phy,u16 rx_phy,u16 phy_options).
- Parameters:
con_handle – [in] 连接 con_handle,range:>0.
all_phys – [in] 0.
tx_phy – [in] CONN_SET_CODED_PHY.
rx_phy – [in] CONN_SET_CODED_PHY.
phy_options – [in] CONN_SET_PHY_OPTIONS.
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_ext_scan_param(param, param_len)
ble5.0 配置 主机scan 参数.
\function ble_cmd_ret_e ble_op_set_ext_scan_param(u8 *param,u16 param_le).
- Parameters:
param – [in] 参数内容.
param_len – [in] 参数长度.
- Returns:
see ble_cmd_ret_e.
-
ble_op_ext_scan_enable(cmd, cmd_len)
ble5.0 配置 主机scan 开关.
\function ble_cmd_ret_e ble_op_ext_scan_enable(u8 *cmd,u16 cmd_le).
- Parameters:
cmd – [in] 命令信息.
cmd_len – [in] 命令长度.
- Returns:
see ble_cmd_ret_e.
-
ble_op_ext_create_conn(conn_param, param_len)
ble5.0 配置 主机创建连接监听.
\function ble_cmd_ret_e ble_op_ext_create_conn(u8 *conn_param,u16 param_len_len).
- Parameters:
conn_param – [in] 连接参数信息.
param_len – [in] 参数长度.
- Returns:
see ble_cmd_ret_e.
-
ble_op_latency_skip(con_handle, skip_interval)
忽略进入latency 作用的次数
\function ble_cmd_ret_e ble_op_latency_skip(u16 con_handle,u16 skip_interval).
Note
!!!注意:让设备不进入latency模式,加快响应速度,但会耗电.
- Parameters:
con_handle – [in] range:>0.
skip_interval – [in] 忽略的interval的次数.
- Returns:
see ble_cmd_ret_e.
-
ble_op_latency_open(con_handle)
打开latency
\function ble_cmd_ret_e ble_op_latency_open(u16 con_handle).
- Parameters:
con_handle – [in] range:>0.
- Returns:
see ble_cmd_ret_e.
-
ble_op_latency_close(con_handle)
关闭latency
\function ble_cmd_ret_e ble_op_latency_close(u16 con_handle).
- Parameters:
con_handle – [in] range:>0.
- Returns:
see ble_cmd_ret_e.
-
ble_op_test_key_num(con_handle, key_num)
测试盒识别按键测试.
\function ble_cmd_ret_e ble_op_test_key_num(u16 con_handle,u8 key_num).
- Parameters:
con_handle – [in] range:>0.
key_num – [in] 按键.
- Returns:
see ble_cmd_ret_e.
-
ble_op_stack_exit(control)
退出ble协议栈.
\function ble_cmd_ret_e ble_op_stack_exit(u8 control).
Note
若已调用btstack_exit退出,则无需调用此接口
- Parameters:
control – [in] : 0—退出stack(默认),1—退出stack + controller.
- Returns:
see ble_cmd_ret_e.
-
ble_op_regist_thread_call(thread_callback)
挂载协议栈线程调用.
\function ble_cmd_ret_e ble_op_regist_thread_call(void (*thread_callback)(void)).
Note
用于同步线程处理,慎用
- Parameters:
thread_callback – [in] 回调函数.
- Returns:
see ble_cmd_ret_e.
-
ble_op_scan_enable(enable)
开关BLE搜索扫描.
\function ble_cmd_ret_e ble_op_scan_enable(u8 enable).
Note
filter_duplicate 默认为 1.
Note
!!!注意:开搜索前必现先配置好搜索的参数ble_op_set_scan_param.
- Parameters:
enable – [in] 0 or 1.
- Returns:
see ble_cmd_ret_e.
-
ble_op_scan_enable2(enable, filter_duplicate)
开关BLE搜索扫描2.
\function ble_cmd_ret_e ble_op_scan_enable2(u8 enable,u8 filter_duplicate).
Note
filter_duplicate 默认为 1.
Note
!!!注意:开搜索前必现先配置好搜索的参数ble_op_set_scan_param.
- Parameters:
enable – [in] 0 or 1.
filter_duplicate – [in] 0 or 1.
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_scan_filter_policy(type)
配置scan filter policy,默认type为0.
\function ble_cmd_ret_e ble_op_set_scan_filter_policy(u8 type).
Note
!!!注意:设置的时候必须在 设置扫描参数 ble_op_set_scan_param 前配置好.
- Parameters:
type – [in] Range: 0x00 to 0x03.
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_scan_param(scan_type, scan_interval, scan_window)
配置搜索参数.
\function ble_cmd_ret_e ble_op_set_scan_param(u8 scan_type,u16 scan_interval,u16 scan_window).
- Parameters:
scan_type – [in] 搜索类型 Range: 0x00 to 0x01 (unit: 0.625ms).
scan_interval – [in] 搜索周期 Range: 0x0004 to 0x4000 (unit: 0.625ms) >= scan_window.
scan_window – [in] 搜索窗口 Range: 0x0004 to 0x4000 (unit: 0.625ms), <= scan_interval.
- Returns:
see ble_cmd_ret_e.
-
ble_op_set_create_filter_policy(type)
配置creat filter policy,默认type: 0.
\function ble_cmd_ret_e ble_op_set_create_filter_policy(u8 type).
Note
!!!注意:设置的时候必须在 设置创建连接参数 ble_op_create_connection 前配置好.
- Parameters:
type – [in] Range: 0x00 to 0x03.
- Returns:
see ble_cmd_ret_e.
-
ble_op_create_connection(create_conn_param)
BLE创建连接监听.
\function ble_cmd_ret_e ble_op_create_connection(struct create_conn_param_t * create_conn_param).
- Parameters:
create_conn_param – [in] 连接参数.
- Returns:
see ble_cmd_ret_e.
-
ble_op_create_connection_ext(create_conn_param_ext)
BLE创建连接监听,扩展传入参数
\function ble_cmd_ret_e ble_op_create_connection_ext(cosnt struct create_conn_param_ext_t * create_conn_param_ext).
- Parameters:
create_conn_param_ext – [in] 连接参数.
- Returns:
see ble_cmd_ret_e.
-
ble_op_create_connection_cancel()
取消BLE连接监听.
\function ble_cmd_ret_e ble_op_create_connection_cancel(void).
- Returns:
see ble_cmd_ret_e.
-
ble_op_search_profile_all()
ble 主机搜索所有服务.
\function ble_cmd_ret_e ble_op_search_profile_all(void).
- Returns:
see ble_cmd_ret_e.
-
ble_op_search_profile_uuid16(uuid16)
ble 主机搜索指定UUID16服务.
\function ble_cmd_ret_e ble_op_search_profile_uuid16(u16 uuid16).
- Parameters:
uuid16 – [in] uuid.
- Returns:
see ble_cmd_ret_e.
-
ble_op_search_profile_uuid128(uuid128_pt)
ble 主机搜索指定UUID128服务.
\function ble_cmd_ret_e ble_op_search_profile_uuid128(const u8 *uuid128_pt).
- Parameters:
uuid128_pt – [in] uuid.
- Returns:
see ble_cmd_ret_e.
-
ble_op_conn_param_update(con_handle, con_param)
ble 主机更新连接参数.
\function ble_cmd_ret_e ble_op_conn_param_update(u16 con_handle,struct conn_update_param_t *con_param).
- Parameters:
con_handle – [in] range:>0.
con_param – [in] (全局变量地址),连接参数.
- Returns:
see ble_cmd_ret_e.
Functions
-
void gatt_client_init(void)
hci connection handle type
-—user (command) codes-—
Gatt client角色初始化.
-
void gatt_client_register_packet_handler(btstack_packet_handler_t handler)
注册gatt client角色,事件回调函数.
- Parameters:
handler – [in] 事件处理函数.
-
void le_device_db_init(void)
初始化配对表.
Note
上电初始化一次.
-
void reset_PK_cb_register(void (*reset_pk)(u32*))
注册passkey输入回调.
- Parameters:
reset_pk – [in] 复位按键输入.
-
int le_controller_set_mac(void *addr)
设置ble蓝牙的public地址.
Note
可以结合接口 ble_op_set_ownaddress_type 配置选择地址类型.
Note
修改地址必须在ble非工作状态下才能生效( 没有scan,没有adv,没有connected).
- Parameters:
addr – [in] public地址.
- Returns:
0->success ,非0->fail.
-
int le_controller_get_mac(void *addr)
获取ble蓝牙的public地址.
- Parameters:
addr – [out] pulic地址.
- Returns:
0->success ,非0->fail.
-
int le_controller_set_random_mac(void *addr)
初始化ble蓝牙random地址.
Note
结合接口ble_op_set_own_address_type 配置选择地址类型.
Note
修改地址必须在ble非工作状态下才能生效(内有scan,没有adv,没connected).
- Parameters:
addr – [in] random地址.
- Returns:
0->success ,非0->fail.
-
int le_controller_get_random_mac(void *addr)
获取ble蓝牙的random地址.
- Parameters:
addr – [out] random地址.
- Returns:
0->success ,非0->fail.
-
void ble_stack_gatt_role(u8 role)
配置协议栈 GATT 角色处理,default server.
- Parameters:
role – [in] GATT role: 0—server ,1—client ,2—server + client.
-
void user_client_init(u16 handle, u8 *buffer, u16 buffer_size)
client 连接后初始化.
- Parameters:
handle – [in] range :>0.
buffer – [in] 配置缓存地址.
buffer_size – [in] 缓存大小.
-
s8 ble_vendor_get_peer_rssi(u16 conn_handle)
获取链路对方的信号强度.
- Parameters:
con_handle – [in] range :>0.
- Returns:
rssi 强度 ,range :-127 ~128 dbm.
-
bool ble_vendor_interval_event_enable(u16 conn_handle, int enable)
使能周期interval事件上报.
- Parameters:
con_handle – [in] range :>0.
enable – [in] 1 or 0.
- Returns:
true or false.
-
u16 ble_vendor_set_default_att_mtu(u16 mtu_size)
配置协议栈ATT默认的MTU大小.
- Parameters:
mtu_size – [in] 配置MUT大小 ,range :23 ~517.
- Returns:
配置后mtu_size的值.
-
void user_client_set_search_complete(void)
设置 client 搜索结束.
-
bool ble_vendor_random_address_generate(u8 *address, u8 type)
提供生成ble对应的类型地址.
Note
生成RESOLVABLE_PRIVATE_ADDR,需要等协议栈初始化IRK后才能生成.
- Parameters:
address – [out] 类型对应地址.
type – [in] ble_type (eg:1.STATIC_DEVICE_ADDR. 2.NON_RESOLVABLE_PRIVATE_ADDR. 3.RESOLVABLE_PRIVATE_ADDR).
- Returns:
true or false.
-
void bt_make_ble_address(u8 *ble_address, u8 *edr_address)
根据提供的edr地址生成唯一对应的ble地址.
Note
用户可以自定义edr和ble地址关联规则,重写这个接口
- Parameters:
ble_adress – [out] BLE_address.
edr_adress – [in] EDR_address.
-
void ble_list_config_reset(u8 pair_devices_count, u8 is_allow_cover)
ble master&slave 配置配对表(可以不设置,使用sdk默认值).
Note
上电调用配置,若配置的个数跟之前不一样,默认清所有的配对表数据.
Note
VM 掉电记录保护.
Note
主从机共用一个配对表.
- Parameters:
pair_devices_count – [in] 记录配对设备,range: 0~10,默认10.若配置为0:则不使用配对表记录管理,不限制配对个数.
is_allow_cover – [in] 是否允许循环覆盖记录 1 or 0,默认1.
- Returns:
true or false.
-
bool ble_list_pair_accept(u8 enable)
配置是否接受新设备请求配对,记录在VM,(可以不设置,使用sdk默认值).
Note
VM 掉电记录保护.
Note
是否覆盖是由接口 ble_list_config_reset 的参数 is_allow_cover 决定.
- Parameters:
enable – [in] 允许新设备配对开关,1 or 0,默认1.
- Returns:
true or false.
-
u16 ble_list_get_count(void)
获取配对表已有配对个数.
- Returns:
0~10.
-
bool ble_list_bonding_remote(u8 *conn_addr, u8 conn_addr_type)
绑定已配对的指定设备,清除其他配对设备.
Note
VM 掉电记录保护.
- Parameters:
conn_addr – [in] 对方地址6bytes.
conn_addr_type – [in] 对方地址类型range: 0~1.
- Returns:
true or false.
-
bool ble_list_clear_all(void)
ble 清空配对表.
- Returns:
true or false.
-
bool ble_list_check_addr_is_exist(u8 *conn_addr, u8 conn_addr_type)
ble 检测连接地址是否在已配对表中.
- Parameters:
conn_addr – [in] 对方地址6bytes.
conn_addr_type – [in] 对方地址类型range: 0~1.
- Returns:
true or false.
-
bool ble_list_delete_device(u8 *conn_addr, u8 conn_addr_type)
ble 把设备从配对表中删除.
- Parameters:
conn_addr – [in] 对方地址6bytes.
conn_addr_type – [in] 对方地址类型range: 0~1.
- Returns:
true or false.
-
bool ble_list_get_last_id_addr(u8 *id_addr)
ble 获取配对表中最后连接设备的 id_address (public address).
- Parameters:
id_addr – [out] 输出最后连接设备的id地址.
- Returns:
true or false.
-
bool ble_list_get_id_addr(u8 *conn_addr, u8 conn_addr_type, u8 *id_addr)
ble 获取已配对设备连接地址对应的 id_address (public address or static address).
- Parameters:
conn_addr – [in] 对方连接地址6bytes.
conn_addr_type – [in] 对方连接地址类型range: 0~1.
id_addr – [out] 输出已配对设备的id地址.
- Returns:
true or false.
-
bool ble_list_get_remote_type(u8 *conn_addr, u8 conn_addr_type, u8 *output_type)
ble 获取已配对设备的系统类型.
Note
只支持作为从机获取手机类型.
- Parameters:
conn_addr – [in] 对方连接地址6bytes.
conn_addr_type – [in] 对方连接地址类型range: 0~1.
output_type – [out] 见 remote_type_e 定义.
- Returns:
true or false.
-
void att_server_set_exchange_mtu(u16 con_handle)
ble slave: att server 连接后主动发起请求MTU交换流程.
- Parameters:
handle – [in] range:>0.
-
void att_server_flow_enable(u8 enable)
ble slave: att server 使能流控功能.
Note
蓝牙初始化后可调用.
- Parameters:
handle – [in] range:>0.
enable – [in] 1 or 0.
-
void att_server_flow_hold(hci_con_handle_t con_handle, u8 hold_flag)
ble slave: att server 控制收数流控.
Note
蓝牙初始化后可调用,对方client要使用write的方式发送数据才能有流控生效
- Parameters:
handle – [in] range:>0.
hold_flag – [in] 1—停止收发数据,0—开始正常收发数.
-
void att_server_set_check_remote(u16 con_handle, void (*callback)(u16 con_handle, remote_type_e remote_type))
ble slave: server 配对连接时,检查对方操作系统.
Note
在第一次配对连接时调用,HCI_EVENT_ENCRYPTION_CHANGE 事件后.
- Parameters:
handle – [in] range:>0.
callback – [in] 检查完回调.
-
int att_send_check_multi_dev(u8 server_max, u8 client_max)
检测协议栈att模块是否支持多机.
- Parameters:
server_max – [in] 传入判断的从机个数.
client_max – [in] 传入判断的主机个数·.
- Returns:
0->success ,非0->fail.
-
int att_server_change_profile(u8 const *profile_data)
可修改GATT服务的profile.
Note
蓝牙未连接状态下,可调用修改.
- Parameters:
profile_data – [in] gatt profile.
- Returns:
0->success ,非0->fail.
-
u8 le_hw_check_all_instant_will_be_valid(void)
检测是否有链路处于instant点.
- Parameters:
NULL. – [in]
- Returns:
1->有链路处于instant点 ,0->没有链路处于instant点.
-
uint8_t *att_send_ram_alloc(uint32_t size)
-
void att_send_ram_free(uint8_t *ram_addr)