Skip to content

BLE 控制器

btble_controller_resource_config(conf)

配置 BLE 控制器资源(内存/EM)

返回值:无

btble_controller_set_task_stack_size(stack_size)

设置控制器任务栈大小

返回值:无

btble_controller_init(task_priority)

初始化 BLE 控制器(射频与链路层)

返回值:无

btblecontroller_main(pvParameters)

BLE 控制器主入口(固件内部)

返回值:无

btblecontroller_proc(data)

BLE 控制器处理函数(固件内部)

返回值:无

btble_controller_deinit()

反初始化 BLE 控制器

返回值:无

btble_controller_sleep(max_sleep_cycles)

让 BLE 控制器进入休眠

返回值:见 SDK 头文件

btble_controller_sleep_restore()

唤醒 BLE 控制器

返回值:无

btble_controller_get_state()

获取 BLE 控制器状态

返回值:见 SDK 头文件

btble_controller_reset()

复位 BLE 控制器

返回值:无

btble_controller_lp_fw_activity_restore(restore)

恢复 a BLE activity after LPFW returns control to the APP。

返回值:0 on success, otherwise an error code.

btble_controller_get_event_priority(event)

Get the priority of a specific BLE event

参数

  • event:The BLE event type to get priority for

返回值:uint32_t Event priority 值 (0-15) or 0xFFFFFFFF if event is invalid

btble_controller_set_event_priority(event, priority)

Set the priority for a specific BLE event

参数

  • event:The BLE event type to set priority for
  • priority:Priority 值 to set (0-15, where 15 is highest priority)

返回值:int 0 on success, -1 if event or priority is invalid

btblecontroller_set_private_key(event, priority)

Set the priority for a specific BLE event

参数

  • event:The BLE event type to set priority for
  • priority:Priority 值 to set (0-15, where 15 is highest priority)

返回值:int 0 on success, -1 if event or priority is invalid

btblecontroller_del_private_key(event, priority)

Set the priority for a specific BLE event

参数

  • event:The BLE event type to set priority for
  • priority:Priority 值 to set (0-15, where 15 is highest priority)

返回值:int 0 on success, -1 if event or priority is invalid

btble_controller_remaining_mem(event, priority)

Set the priority for a specific BLE event

参数

  • event:The BLE event type to set priority for
  • priority:Priority 值 to set (0-15, where 15 is highest priority)

返回值:int 0 on success, -1 if event or priority is invalid

btble_controller_set_cs2(event, priority)

Set the priority for a specific BLE event

参数

  • event:The BLE event type to set priority for
  • priority:Priority 值 to set (0-15, where 15 is highest priority)

返回值:int 0 on success, -1 if event or priority is invalid

btble_controller_set_local_sdk_ver(event, priority)

Set the priority for a specific BLE event

参数

  • event:The BLE event type to set priority for
  • priority:Priority 值 to set (0-15, where 15 is highest priority)

返回值:int 0 on success, -1 if event or priority is invalid

btble_controller_sleep_init(event, priority)

Set the priority for a specific BLE event

参数

  • event:The BLE event type to set priority for
  • priority:Priority 值 to set (0-15, where 15 is highest priority)

返回值:int 0 on success, -1 if event or priority is invalid

btble_controller_get_tx_pwr(event, priority)

Set the priority for a specific BLE event

参数

  • event:The BLE event type to set priority for
  • priority:Priority 值 to set (0-15, where 15 is highest priority)

返回值:int 0 on success, -1 if event or priority is invalid

btble_set_before_sleep_callback(event, priority)

Set the priority for a specific BLE event

参数

  • event:The BLE event type to set priority for
  • priority:Priority 值 to set (0-15, where 15 is highest priority)

返回值:int 0 on success, -1 if event or priority is invalid

btble_set_after_sleep_callback(event, priority)

Set the priority for a specific BLE event

参数

  • event:The BLE event type to set priority for
  • priority:Priority 值 to set (0-15, where 15 is highest priority)

返回值:int 0 on success, -1 if event or priority is invalid

btble_set_sleep_aborted_callback(event, priority)

Set the priority for a specific BLE event

参数

  • event:The BLE event type to set priority for
  • priority:Priority 值 to set (0-15, where 15 is highest priority)

返回值:int 0 on success, -1 if event or priority is invalid

btble_controller_sco_codec_callback_register(event, priority)

Set the priority for a specific BLE event

参数

  • event:The BLE event type to set priority for
  • priority:Priority 值 to set (0-15, where 15 is highest priority)

返回值:int 0 on success, -1 if event or priority is invalid

btble_controller_get_lp_fw_info()

获取低功耗固件信息

返回值:Pointer to the recorded LPFW handoff information.

btble_controller_get_lib_ver(event, priority)

获取 BLE 控制器库版本号

参数

  • event:The BLE event type to set priority for
  • priority:Priority 值 to set (0-15, where 15 is highest priority)

返回值:int 0 on success, -1 if event or priority is invalid

HCI 驱动

bt_recv(buf)

HCI 驱动向主机协议栈提交来自控制器的数据(普通事件)。

返回值:见 SDK 头文件

bt_recv_prio(buf)

向主机协议栈投递高优先级 HCI 事件(区别于普通 bt_recv)。

返回值:见 SDK 头文件

bt_hci_driver_register(drv)

向蓝牙协议栈注册 HCI 驱动;必须在 bt_enable() 之前调用。

参数

  • drv:A bt_hci_driver struct representing the driver.

返回值:0 on success or negative error number on failure.

bt_hci_transport_setup(dev)

Setup the HCI transport, which usually means to reset the Bluetooth IC.

参数

  • dev:The 设备 structure for the bus connecting to the IC

📎 设备名速查:支持的设备名(BL616)

返回值:0 on success, negative error 值 on failure

hci_driver_enque_recvq(buf)

enqueue 缓冲区 to hci received 队列.

参数

  • buf:缓冲区 containing 数据 received from firmware.

返回值:无

hci_driver_init(buf)

enqueue 缓冲区 to hci received 队列.

参数

  • buf:缓冲区 containing 数据 received from firmware.

返回值:见 SDK 头文件

BLE 主机(GAP)

bt_enable(cb)

使能 Bluetooth Enable Bluetooth. Must be the called before any calls that require communication with the local Bluetooth hardware。

参数

  • cb:回调 to notify completion or NULL to perform the

返回值:Zero on success or (negative) error code otherwise.

bt_set_name(name)

设置 Bluetooth 设备名 Set Bluetooth GAP 设备名。

参数

  • name:New 名称

📎 设备名速查:支持的设备名(BL616)

返回值:Zero on success or (negative) error code otherwise.

bt_set_id_addr(addr)

设置本机身份地址(Identity Address),须在 bt_enable() 之前调用,多用于测试等场景。

返回值:Zero on success or (negative) error code otherwise.

bt_id_get(addrs, count)

获取当前已配置的身份(identity)地址数组;数组长度应取 CONFIG_BT_ID_MAX。

参数

  • addrs:Array where to store the configured identities.
  • count:Should be initialized to the array size. Once the function

返回值:无

bt_id_create(addrs, count)

用指定地址与 IRK 创建新身份;bt_enable() 之后调用才会持久保存到 Flash。

参数

  • addrs:Array where to store the configured identities.
  • count:Should be initialized to the array size. Once the function

返回值:见 SDK 头文件

bt_id_reset(id, addr, irk)

重置/回收一个身份供复用,参数语义与 bt_id_create 相同。

参数

  • id:Existing identity identifier.
  • addr:地址 to use for the new identity. If NULL or initialized
  • irk:Identity Resolving 密钥 (16 bytes) to be used with this

返回值:Identity identifier (>= 0) in case of success, or a negative

bt_id_delete(id)

删除一个身份:断开其连接、清除配对密钥并标记为删除;默认身份不可删除。

参数

  • id:Existing identity identifier.

返回值:0 in case of success, or a negative error code on failure.

bt_le_adv_start(id)

启动广播 Set advertisement 数据, 扫描 response 数据, advertisement parameters and start 广播。

参数

  • id:Existing identity identifier.

返回值:0 in case of success, or a negative error code on failure.

bt_le_adv_update_data(ad, ad_len, sd, sd_len)

更新广播 Update advertisement and 扫描 response 数据。

参数

  • ad:数据 to be used in advertisement packets.
  • ad_len:Number of elements in ad
  • sd:数据 to be used in 扫描 response packets.
  • sd_len:Number of elements in sd

返回值:Zero on success or (negative) error code otherwise.

bt_le_adv_stop()

停止广播 Stops ongoing 广播。

返回值:见 SDK 头文件

bt_le_pts_scan_start(param, cb)

启动(LE) scanning Start LE scanning with given parameters and provide results through the specified 回调。

参数

  • param:扫描 parameters.
  • cb:回调 to notify 扫描 results.

返回值:Zero on success or error code otherwise, positive in case

bt_le_scan_start(param, cb)

启动(LE) scanning Start LE scanning with given parameters and provide results through the specified 回调。

返回值:Zero on success or (negative) error code otherwise.

bt_le_scan_stop()

停止(LE) scanning. Stops ongoing LE scanning。

返回值:Zero on success or error code otherwise, positive in case

bt_le_whitelist_add(addr)

添加设备 (LE) to whitelist. Add peer 设备 LE 地址 to the whitelist。

参数

  • addr:Bluetooth LE identity 地址.

返回值:Zero on success or error code otherwise, positive in case

bt_le_whitelist_rem(addr)

删除设备 (LE) from whitelist. Remove peer 设备 LE 地址 from the whitelist。

参数

  • addr:Bluetooth LE identity 地址.

返回值:Zero on success or error code otherwise, positive in case

bt_le_whitelist_clear()

清除 whitelist. Clear all devices from the whitelist。

返回值:Zero on success or error code otherwise, positive in case

bt_le_set_chan_map(chan_map)

设置(LE) 信道映射。

参数

  • chan_map:信道映射.

返回值:Zero on success or error code otherwise, positive in case

bt_le_oob_get_local(id, oob)

获取 LE 本地带外(OOB)信息;开启隐私时会生成临时可解析私有地址。

参数

  • id:Local identity, in most cases BT_ID_DEFAULT.
  • oob:LE related information

返回值:Zero on success or error code otherwise, positive in case

bt_br_discovery_start(param, results, count, cb)

启动 BR/EDR 发现(inquiry),结果经回调返回;结果过多时只报告 RSSI 最高的设备。

返回值:见 SDK 头文件

bt_br_discovery_stop()

Stop BR/EDR discovery. Stops ongoing BR/EDR discovery. If discovery was stopped by this call results won't be reported

返回值:Zero on success or error code otherwise, positive in case

bt_disable()

关闭蓝牙:退出连接/广播/扫描状态进入待机,并清除未持久化的身份与密钥。

返回值:Zero on success or (negative) error code otherwise.

bt_force_disable()

强制关闭蓝牙:发送 HCI Reset 强制退出各状态并释放 HCI 资源。

返回值:Zero on success or (negative) error code otherwise.

bt_br_oob_get_local(oob)

获取 BR/EDR 本地带外(OOB)信息,用于带外配对或连接创建。

参数

  • oob:Out Of Band information

返回值:见 SDK 头文件

bt_addr_from_str(str, addr)

转换 Bluetooth 地址 from string to binary。

返回值:Zero on success or (negative) error code otherwise.

bt_addr_le_from_str(str, type, addr)

转换 LE Bluetooth 地址 from string to binary。

返回值:Zero on success or (negative) error code otherwise.

bt_br_set_discoverable(enable)

使控制器进入可发现状态(监听 INQUIRY SCAN);需先处于可连接状态。

参数

  • enable:值 allowing/disallowing controller to become discoverable.

返回值:Negative if fail set to requested state or requested state has been

bt_br_set_connectable(enable)

使控制器可连接(监听 PAGE SCAN);关闭时同时重置可发现状态。

参数

  • enable:值 allowing/disallowing controller to be connectable.

返回值:Negative if fail set to requested state or requested state has been

bt_unpair(id, addr)

清除 pairing information。

参数

  • id:Local identity (mostly just BT_ID_DEFAULT).
  • addr:Remote 地址, NULL or BT_ADDR_LE_ANY to clear all remote

返回值:0 on success or negative error 值 on failure.

bt_br_write_local_name(name)

写入 local 名称。

📎 设备名速查:支持的设备名(BL616)

返回值:见 SDK 头文件

bt_br_write_eir(fec, data)

写入 extern inquiry response。

返回值:见 SDK 头文件

bt_br_internal_update_a2dp_status(conHandle, status)

更新 a2dp 状态 to controller。

参数

  • conHandle:连接 handle
  • status:current a2dp 状态(only a2dp stream start or suspend)

返回值:见 SDK 头文件

bt_br_set_a2dp_stream_duty(DutyValue)

It's used to set the 占空比 of the a2dp stream.

参数

  • DutyValue:the range is 0-100

返回值:见 SDK 头文件

bt_br_set_min_enc_key_size(KeySize)

It's used to set min encryption 密钥 size.

参数

  • KeySize:the range is 1-16

返回值:见 SDK 头文件

bt_br_set_tx_pwr(br_power, edr_power)

It's used to set min encryption 密钥 size.

参数

  • br_power:the range is 0-10, 0xff: use default power
  • edr_power:the range is 0-8, 0xff: use default power

返回值:见 SDK 头文件

bt_get_name()

获取本机 BLE 设备名

返回值:Bluetooth 设备名

连接管理

bt_conn_unref(conn)

Decrement a 连接's reference count. Decrement the reference count of a 连接 object.

参数

  • conn:连接 object.

返回值:无

le_check_valid_conn(id, peer)

Look up an existing 连接 by 地址. Look up an existing 连接 based on the remote 地址.

参数

  • id:Local identity (in most cases BT_ID_DEFAULT).
  • peer:Remote 地址.

返回值:连接 object or NULL if not found. The caller gets a

notify_disconnected(id, peer)

Look up an existing 连接 by 地址. Look up an existing 连接 based on the remote 地址.

参数

  • id:Local identity (in most cases BT_ID_DEFAULT).
  • peer:Remote 地址.

返回值:连接 object or NULL if not found. The caller gets a

notify_remote_version(id, peer)

Look up an existing 连接 by 地址. Look up an existing 连接 based on the remote 地址.

参数

  • id:Local identity (in most cases BT_ID_DEFAULT).
  • peer:Remote 地址.

返回值:连接 object or NULL if not found. The caller gets a

bt_conn_cleanup_all(id, peer)

Look up an existing 连接 by 地址. Look up an existing 连接 based on the remote 地址.

参数

  • id:Local identity (in most cases BT_ID_DEFAULT).
  • peer:Remote 地址.

返回值:连接 object or NULL if not found. The caller gets a

bt_conn_index(conn)

获取 array index of a 连接 This function maps a 连接 to its index in the corresponding LE or BR/EDR 连接 pool。

参数

  • conn:连接 object.

返回值:Index of the 连接 object.

bt_conn_get_info(conn, info)

Get 连接 info

参数

  • conn:连接 object.
  • info:连接 info object.

返回值:Zero on success or (negative) error code on failure.

bt_conn_get_remote_dev_info(info, type)

Get connected devices' info

参数

  • info:连接 info object.
  • type:Exact 连接 type to query (BT_CONN_TYPE_LE or

返回值:Connected 设备 number or (negative) error code on failure.

pts_bt_conn_le_param_update(conn, param)

更新 the 连接 parameters。

参数

  • conn:连接 object.
  • param:Updated 连接 parameters.

返回值:Zero on success or (negative) error code on failure.

bt_conn_le_param_update(conn, param)

更新 the 连接 parameters。

参数

  • conn:连接 object.
  • param:Updated 连接 parameters.

返回值:Zero on success or (negative) error code on failure.

bt_conn_disconnect(conn, reason)

断开与远端设备的连接(可带原因码),或取消正在发起的连接。

参数

  • conn:连接 to disconnect.
  • reason:Reason code for the disconnection.

返回值:Zero on success or (negative) error code on failure.

bt_conn_create_auto_le(param)

Automatically connect to remote devices in whitelist. This uses the Auto 连接 Establishment procedure.

参数

  • param:Initial 连接 parameters.

返回值:Zero on success or (negative) error code on failure.

bt_conn_create_auto_stop()

停止 automatic connect creation。

返回值:Zero on success or (negative) error code on failure.

bt_le_set_auto_conn(addr, param)

启用/禁用自动连接:断线后收到对端可连接广播时自动重连。

参数

  • addr:Remote Bluetooth 地址.
  • param:If non-NULL, auto connect is enabled with the given

返回值:Zero on success or error code otherwise.

bt_conn_set_security(conn, sec)

为连接设置安全等级(加密);密钥不足时自动发起配对。

参数

  • conn:连接 object.
  • sec:Requested security level.

返回值:0 on success or negative error

bt_conn_get_security(conn)

获取 security level for a 连接。

返回值:连接 security level

bt_conn_enc_key_size(conn)

获取 encryption 密钥 size. This function gets encryption 密钥 size. If there is no security (encryption) enabled 0 will be returned。

参数

  • conn:Existing 连接 object.

返回值:Encryption 密钥 size.

bt_set_mitm(conn, level, err)

The security level of a 连接 has changed. This 回调 notifies the application that the security level of a 连接 has changed.

参数

  • conn:连接 object.
  • level:New security level of the 连接.
  • err:Security error. Zero for success, non-zero otherwise.

返回值:无

bt_set_smpflag(conn, level, err)

The security level of a 连接 has changed. This 回调 notifies the application that the security level of a 连接 has changed.

参数

  • conn:连接 object.
  • level:New security level of the 连接.
  • err:Security error. Zero for success, non-zero otherwise.

返回值:无

bt_clear_smpflag(conn, level, err)

The security level of a 连接 has changed. This 回调 notifies the application that the security level of a 连接 has changed.

参数

  • conn:连接 object.
  • level:New security level of the 连接.
  • err:Security error. Zero for success, non-zero otherwise.

返回值:无

bt_conn_cb_register(cb)

注册连接 callbacks. Register callbacks to monitor the state of connections。

返回值:无

bt_conn_cb_unregister(cb)

注册连接 callbacks. Register callbacks to monitor the state of connections。

参数

  • cb:回调 struct.

返回值:无

bt_conn_cb_clear(cb)

注册连接 callbacks. Register callbacks to monitor the state of connections。

参数

  • cb:回调 struct.

返回值:无

bt_set_bondable(enable)

Enable/disable bonding.

参数

  • enable:值 allowing/disallowing to be bondable.

返回值:无

bt_set_oob_data_flag(enable)

Allow/disallow remote OOB 数据 to be used for pairing.

参数

  • enable:值 allowing/disallowing remote OOB 数据.

返回值:无

bt_le_oob_set_sc_data(conn, oobd_local, oobd_remote)

在 LE 安全连接(SC)配对过程中设置 OOB 数据。

参数

  • conn:连接 object
  • oobd_local:Local OOB 数据 or NULL if not present
  • oobd_remote:Remote OOB 数据 or NULL if not present

返回值:Zero on success or error code otherwise, positive in case

bt_le_oob_get_sc_data(conn, oobd_local, oobd_remote)

获取配对过程中设置的 OOB 数据(仅在关联连接有效时可用)。

参数

  • conn:连接 object
  • oobd_local:Local OOB 数据 or NULL if not set
  • oobd_remote:Remote OOB 数据 or NULL if not set

返回值:Zero on success or error code otherwise, positive in case

bt_passkey_set(passkey)

设置固定配对口令(需开启 CONFIG_BT_FIXED_PASSKEY 配置)。

参数

  • passkey:A valid passkey (0 - 999999) or BT_PASSKEY_INVALID

返回值:0 on success or a negative error code on failure.

bt_conn_auth_cb_register(cb)

注册 authentication callbacks. Register callbacks to handle authenticated pairing. Passing NULL unregisters a previous callbacks structure。

参数

  • cb:回调 struct.

返回值:Zero on success or negative error code otherwise

bt_conn_auth_passkey_entry(conn, passkey)

Reply with entered passkey. This function should be called only after passkey_entry 回调 from bt_conn_auth_cb structure was called.

参数

  • conn:连接 where pairing is currently active.
  • passkey:Passkey to show to the user.

返回值:见 SDK 头文件

bt_conn_auth_cancel(conn)

Cancel ongoing authenticated pairing. This function allows to cancel ongoing authenticated pairing.

参数

  • conn:连接 where pairing is currently active.

返回值:见 SDK 头文件

bt_conn_auth_passkey_confirm(conn)

回复用户确认的口令匹配结果(在 passkey_confirm 回调后调用)。

参数

  • conn:连接 where pairing is currently active.

返回值:见 SDK 头文件

bt_conn_auth_pairing_confirm(conn)

回复用户确认的配对请求(在 pairing_confirm 回调后调用)。

参数

  • conn:连接 where pairing is currently active.

返回值:见 SDK 头文件

bt_conn_auth_pincode_entry(conn)

回复用户输入的 PIN 码(用于传统蓝牙 2.0 设备)。

参数

  • conn:连接 where pairing is currently active.

返回值:见 SDK 头文件

bt_br_conn_enter_sniff(conn, min_interval, max_interval)

让 BR/EDR 连接进入 sniff 省电模式,减少空闲链路的射频占用。

参数

  • conn:BR/EDR 连接 object.
  • min_interval:Minimum sniff interval in 0.625ms slots.
  • max_interval:Maximum sniff interval in 0.625ms slots.

返回值:0 on success or negative 值 on error.

bt_br_conn_exit_sniff(conn)

Exit sniff 模式, returning the 连接 to active 模式.

参数

  • conn:BR/EDR 连接 object.

返回值:0 on success or negative 值 on error.

bt_conn_set_peripheral_pref_params(param)

Set peripheral preferred 连接 parameters

参数

  • param:the preferred 连接 parameters to be set.

返回值:0 in case of success or negative 值 in case of error.

bt_conn_get_peripheral_pref_params(param)

Get peripheral preferred 连接 parameters

参数

  • param:this API will assign peripheral preferred 连接 parameters.

返回值:0 in case of success or negative 值 in case of error.

bt_conn_enable_peripheral_pref_param_update(conn, enable)

Enable or disable peripheral preferred 连接 parameters udpate

参数

  • conn:连接 object.
  • enable:true:enable,false:disable

返回值:0 in case of success or negative 值 in case of error.

bt_conn_set_scan_parameters_in_general_conn_establish(scan_interval, scan_window)

设置扫描 interval and 扫描 window in scanning procedure of ble general conection establishement。

参数

  • scan_interval:扫描 interval.
  • scan_window:扫描 window.

返回值:0 in case of success or negative 值 in case of error.

bt_conn_ref(conn)

增加连接对象引用计数

参数

  • conn:连接 object.

返回值:连接 object with incremented reference count.

bt_conn_lookup_addr_le(id, peer)

按 BLE 地址查找连接对象

参数

  • id:Local identity (in most cases BT_ID_DEFAULT).
  • peer:Remote 地址.

返回值:连接 object or NULL if not found. The caller gets a

bt_conn_get_dst(conn)

获取连接的目标地址

参数

  • conn:连接 object.

返回值:Destination 地址.

bt_conn_get(conn)

获取当前默认连接对象

参数

  • conn:连接 object.

返回值:Destination 地址.

bt_conn_create_sco(peer)

创建面向连接的无绳电话(SCO)连接

参数

  • peer:Remote 地址.

返回值:Valid 连接 object on success or NULL otherwise.

GATT

bt_gatt_service_register(svc)

注册 GATT 服务(配合 BT_GATT_PRIMARY_SERVICE、BT_GATT_CHARACTERISTIC 等宏使用)。

参数

  • svc:Service containing the available attributes

返回值:0 in case of success or negative 值 in case of error.

bt_gatt_service_unregister(svc)

Unregister GATT 服务. *

参数

  • svc:Service to be unregistered.

返回值:0 in case of success or negative 值 in case of error.

bt_gatt_find_attr(handle)

Get GATT 属性 via 属性 handle. *

参数

  • handle:属性 handle.

返回值:attrubte pointer in case of success or NULL in case of error.

bt_gatt_foreach_attr_type(start_handle, end_handle, uuid, attr_data, num_matches, func, user_data)

属性 iterator by type. Iterate attributes in the given range matching given UUID and/or 数据.

参数

  • start_handle:Start handle.
  • end_handle:End handle.
  • uuid:UUID to match, passing NULL skips UUID matching.
  • attr_data:属性 数据 to match, passing NULL skips 数据 matching.
  • num_matches:Number matches, passing 0 makes it unlimited.
  • func:回调 function.
  • user_data:数据 to pass to the 回调.

返回值:无

bt_gatt_attr_value_handle(attr)

获取 the handle of the characteristic 值 descriptor。

参数

  • attr:A Characteristic 属性

返回值:the handle of the corresponding Characteristic 值. The

bt_gatt_attr_read(conn, attr, buf, buf_len, offset, value, value_len)

Generic Read 属性 值 helper. Read 属性 值 from local database storing the result into 缓冲区.

参数

  • conn:连接 object.
  • attr:属性 to read.
  • buf:缓冲区 to store the 值.
  • buf_len:缓冲区长度.
  • offset:Start offset.
  • value:属性 值.
  • value_len:Length of the 属性 值.

返回值:int number of bytes read in case of success or negative values in

bt_gatt_attr_read_service(conn, attr, buf, len, offset)

读取服务属性值到缓冲区(user_data 需为 bt_uuid)。

参数

  • conn:连接 object.
  • attr:属性 to read.
  • buf:缓冲区 to store the 值 read.
  • len:缓冲区长度.
  • offset:Start offset.

返回值:int number of bytes read in case of success or negative values in

bt_gatt_attr_read_included(conn, attr, buf, len, offset)

读取 Include 服务属性值到缓冲区(user_data 需为 bt_gatt_include)。

参数

  • conn:连接 object.
  • attr:属性 to read.
  • buf:缓冲区 to store the 值 read.
  • len:缓冲区长度.
  • offset:Start offset.

返回值:int number of bytes read in case of success or negative values in

bt_gatt_attr_read_chrc(conn, attr, buf, len, offset)

读取特征属性值到缓冲区(user_data 需为 bt_gatt_chrc)。

参数

  • conn:连接 object.
  • attr:属性 to read.
  • buf:缓冲区 to store the 值 read.
  • len:缓冲区长度.
  • offset:Start offset.

返回值:number of bytes read in case of success or negative values in

bt_gatt_attr_read_ccc(conn, attr, buf, len, offset)

读取客户端特征配置(CCC)属性值到缓冲区。

参数

  • conn:连接 object.
  • attr:属性 to read.
  • buf:缓冲区 to store the 值 read.
  • len:缓冲区长度.
  • offset:Start offset.

返回值:number of bytes read in case of success or negative values in

bt_gatt_attr_write_ccc(conn, attr, buf, len, offset, flags)

把缓冲区内容写入 CCC 属性。

参数

  • conn:连接 object.
  • attr:属性 to read.
  • buf:缓冲区 to store the 值 read.
  • len:缓冲区长度.
  • offset:Start offset.
  • flags:Write 标志.

返回值:number of bytes written in case of success or negative values in

bt_gatt_attr_read_cep(conn, attr, buf, len, offset)

读取特征扩展属性(CEP)值到缓冲区。

参数

  • conn:连接 object
  • attr:属性 to read
  • buf:缓冲区 to store the 值 read
  • len:缓冲区长度
  • offset:Start offset

返回值:number of bytes read in case of success or negative values in

bt_gatt_attr_read_cud(conn, attr, buf, len, offset)

读取特征用户描述(CUD)属性值到缓冲区。

参数

  • conn:连接 object
  • attr:属性 to read
  • buf:缓冲区 to store the 值 read
  • len:缓冲区长度
  • offset:Start offset

返回值:number of bytes read in case of success or negative values in

bt_gatt_attr_read_cpf(conn, attr, buf, len, offset)

读取特征表示格式(CPF)描述符值到缓冲区。

参数

  • conn:连接 object
  • attr:属性 to read
  • buf:缓冲区 to store the 值 read
  • len:缓冲区长度
  • offset:Start offset

返回值:number of bytes read in case of success or negative values in

bt_gatt_notify_at_cb(conn, params, attr_handle)

Notification 值 回调 用户数据

返回值:见 SDK 头文件

bt_gatt_notify_cb(conn, params)

发送属性值变更通知,发送完成后调用回调(系统工作队列上下文执行)。

参数

  • conn:连接 object.
  • params:Notification parameters.

返回值:0 in case of success or negative 值 in case of error.

bt_gatt_indicate(conn, attr, data, len)

发送属性值变更指示(Indication,对端需确认);conn 为 NULL 时通知所有已订阅的对端。

参数

  • conn:连接 object.
  • attr:Characteristic or Characteristic 值 属性.
  • data:Pointer to 属性 数据.
  • len:属性 数据长度.

返回值:0 in case of success or negative 值 in case of error.

service_change_test(conn, params)

发送属性值变更指示(与 bt_gatt_indicate 相同语义的测试入口)。

参数

  • conn:连接 object.
  • params:Indicate parameters.

返回值:0 in case of success or negative 值 in case of error.

bt_gatt_is_subscribed(conn, attr, ccc_value)

检查连接是否已订阅某属性的变更通知。

参数

  • conn:连接 object.
  • attr:属性 object.
  • ccc_value:The subscription type, either notifications or indications.

返回值:true if the 属性 object has been subscribed.

bt_gatt_get_mtu(conn)

获取连接协商后的 ATT MTU(注意不等于单包可传输的最大属性数据量)。

参数

  • conn:连接 object.

返回值:MTU in bytes

bt_gatt_set_mtu(conn)

设置连接协商后的 ATT MTU(接口语义见头文件)。

参数

  • conn:连接 object.

返回值:MTU in bytes

bt_gatt_exchange_mtu(conn, params)

客户端把 MTU 协商为缓冲区可容纳的最大值;每个连接只能调用一次。

参数

  • conn:连接 object.
  • params:Exchange MTU parameters.

返回值:0 in case of success or negative 值 in case of error.

bt_at_gatt_exchange_mtu(conn, params)

客户端协商 MTU(AT 命令接口版本)。

参数

  • conn:连接 object.
  • params:Exchange MTU parameters.

返回值:0 in case of success or negative 值 in case of error.

bt_gatt_discover(conn, params)

客户端发现服务器属性(主服务/包含服务/特征/描述符),每发现一个回调一次,可决定继续或停止。

参数

  • conn:连接 object.
  • params:Exchange MTU parameters.

返回值:0 in case of success or negative 值 in case of error.

bt_gatt_read(conn, params)

按句柄读取属性值,结果经回调返回;长值需按句柄+偏移分段读取。

参数

  • conn:连接 object.
  • params:Discover parameters.

返回值:0 in case of success or negative 值 in case of error.

bt_gatt_write(conn, params)

按句柄写入属性值,结果经回调返回。

参数

  • conn:连接 object.
  • params:Read parameters.

返回值:0 in case of success or negative 值 in case of error.

bt_gatt_cancle_prepare_writes(conn, params)

取消已准备的写入(Prepare Write 流程)。

参数

  • conn:连接 object.
  • params:Write parameters.

返回值:0 in case of success or negative 值 in case of error.

bt_gatt_prepare_write(conn, params)

准备写入(长写流程的一部分),结果经回调返回。

参数

  • conn:连接 object.
  • params:Write parameters.

返回值:0 in case of success or negative 值 in case of error.

bt_gatt_write_without_response_cb(conn, handle, data, length, sign, func, user_data)

无应答写并带完成回调(同时关闭内部流控,回调前不要继续提交数据)。

参数

  • conn:连接 object.
  • handle:属性 handle.
  • data:数据 to be written.
  • length:数据长度.
  • sign:Whether to sign 数据
  • func:Transmission complete 回调.
  • user_data:用户数据 to be passed back to 回调.

返回值:0 in case of success or negative 值 in case of error.

bt_gatt_subscribe(conn, handle, data, length, sign)

通过 CCC 句柄订阅属性通知;收到通知时回调通知值,可在回调中决定是否取消订阅。

参数

  • conn:连接 object.
  • handle:属性 handle.
  • data:数据 to be written.
  • length:数据长度.
  • sign:Whether to sign 数据

返回值:0 in case of success or negative 值 in case of error.

bt_gatt_unsubscribe(conn, params)

取消订阅属性通知;取消后通知回调会以 NULL 数据调用一次。

参数

  • conn:连接 object.
  • params:Subscribe parameters.

返回值:0 in case of success or negative 值 in case of error.

bt_gatt_cancel(conn, params)

Cancel GATT pending request

参数

  • conn:连接 object.
  • params:Requested params 地址.

返回值:无

bt_gatt_register_mtu_callback(conn, params)

Cancel GATT pending request

参数

  • conn:连接 object.
  • params:Requested params 地址.

返回值:无

bt_gatt_discover_status_set(conn, params)

Cancel GATT pending request

参数

  • conn:连接 object.
  • params:Requested params 地址.

返回值:无

bt_gatt_register_notification_callback(conn, params)

Cancel GATT pending request

参数

  • conn:连接 object.
  • params:Requested params 地址.

返回值:无

bt_gatt_ccc_load(void, void)

load gatt ccc from Flash

参数

  • void:.
  • void:.

返回值:无

bt_gatt_sc_indicate(start, end)

发送 service changed indication。

参数

  • start:start 属性 handle.
  • end:end 属性 handle.

返回值:无

bt_gatts_get_dync_attr_handle(start, end)

Get a Dynamic attrubute hanle(chrc_handle,vaule_handle,descriptor)

参数

  • start:start 属性 handle.
  • end:end 属性 handle.

返回值:见 SDK 头文件

bt_gatts_add_serv_attr(start, end)

Add service

参数

  • start:start 属性 handle.
  • end:end 属性 handle.

返回值:见 SDK 头文件

bt_gatts_add_char(start, end)

Add characteristics and characteristic 值

参数

  • start:start 属性 handle.
  • end:end 属性 handle.

返回值:见 SDK 头文件

bt_gatts_add_desc(start, end)

Add descriptor

参数

  • start:start 属性 handle.
  • end:end 属性 handle.

返回值:见 SDK 头文件

bt_gatts_get_service_simple_info(svc_id, info, info_num)

获取 simple service information。

参数

  • svc_id:ID of the service.
  • info:Pointer to a simple service information structure.
  • info_num:Number of Simple Service Information Structures.

返回值:0 in case of success or negative 值 in case of error.

bt_gatts_get_service_char(svc_id, info, info_num)

获取 service characteristics。

参数

  • svc_id:ID of the service.
  • info:Pointer to service characteristics information structure.
  • info_num:Number of service characteristics.

返回值:0 in case of success or negative 值 in case of error.

bt_gatts_get_service_desc(svc_id, info, info_num)

获取 service characteristics descriptor。

参数

  • svc_id:ID of the service.
  • info:Pointer to service characteristics descriptor information structure.
  • info_num:Number of service characteristics descriptor.

返回值:0 in case of success or negative 值 in case of error.

bt_gatts_add_service()

注册 service。

返回值:service id(>0) in case of success.

bt_gatts_del_service(svc_id, desp_attr)

添加 Unregister service。

参数

  • svc_id:ID of the service.
  • desp_attr:characteristics attribution.

返回值:0 in case of success or negative 值 in case of error.

bt_gatt_attr_next(attr)

遍历到下一个 GATT 属性

参数

  • attr:Current 属性.

返回值:The next 属性 or NULL if it cannot be found.

ATOMIC_DEFINE(flags, BT_GATT_SUBSCRIBE_NUM_FLAGS)

宏:定义一个原子变量(内部使用)

返回值:见 SDK 头文件

L2CAP

bt_l2cap_server_register(server)

为 PSM 注册 L2CAP 服务器;每个新连接用 accept 回调授权并分配通道结构。

返回值:见 SDK 头文件

bt_l2cap_br_server_register(server)

为 BR/EDR 面向连接的 PSM 注册 L2CAP 服务器。

参数

  • server:Server structure.

返回值:0 in case of success or negative 值 in case of error.

bt_l2cap_chan_connect(conn, chan, psm)

按 PSM 连接 L2CAP 通道,连接完成后回调 connected;被拒绝则回调 disconnected。

参数

  • conn:连接 object.
  • chan:通道 object.
  • psm:通道 PSM to connect to.

返回值:0 in case of success or negative 值 in case of error.

bt_l2cap_chan_disconnect(chan)

断开 L2CAP 通道;挂起的连接会被取消并回调 disconnected。

参数

  • chan:通道 object.

返回值:0 in case of success or negative 值 in case of error.

bt_l2cap_chan_send(chan, buf)

向 L2CAP 通道发送数据;信用不足时自动排队,待收到对端信用后再发。

返回值:Bytes sent in case of success or negative 值 in case of error.

bt_l2cap_chan_recv_complete(chan)

完成接收处理(当通道 recv 回调返回 -EINPROGRESS 时调用)。

参数

  • chan:The 通道 requesting a 缓冲区.

返回值:Allocated 缓冲区.

bt_l2cap_disconnect(chan, buf)

完成接收处理(与 chan_recv_complete 同语义的接口)。

参数

  • chan:通道 object.
  • buf:缓冲区 containing the 数据.

返回值:0 in case of success or negative 值 in case of error.

bt_l2cap_br_echo_req(chan, buf)

完成接收处理(BR/EDR echo 测试相关接口)。

参数

  • chan:通道 object.
  • buf:缓冲区 containing the 数据.

返回值:0 in case of success or negative 值 in case of error.

ATOMIC_DEFINE(status, BT_L2CAP_NUM_STATUS)

宏:定义一个原子变量(内部使用)

返回值:见 SDK 头文件

GAP

bt_gap_set_local_device_appearance(device_appearance)

Bluetooth Generic Access Profile defines and Assigned Numbers.

返回值:无

地址

bt_addr_le_create_nrpa(addr)

Bluetooth LE 设备 地址

返回值:见 SDK 头文件

bt_addr_le_create_static(addr)

Bluetooth LE 设备 地址

返回值:见 SDK 头文件

UUID

bt_uuid_cmp(u1, u2)

比较 Bluetooth UUIDs. Compares 2 Bluetooth UUIDs, if the types are different both UUIDs are first converted to 128 bits format before comparing。

参数

  • u1:First Bluetooth UUID to compare
  • u2:Second Bluetooth UUID to compare

返回值:negative 值 if @a u1 < @a u2, 0 if @a u1 == @a u2, else positive

bt_uuid_create(uuid, data, data_len)

从小端数据缓冲区创建 bt_uuid,按长度自动识别 16/32/128 位 UUID 格式。

参数

  • uuid:Pointer to the bt_uuid variable
  • data:pointer to UUID stored in little-endian 数据 缓冲区
  • data_len:length of the UUID in the 数据 缓冲区

返回值:true if the 数据 was valid and the UUID was successfully created.

bt_uuid_to_str(uuid, str, len)

转换 Bluetooth UUID to string. Converts Bluetooth UUID to string. UUID has to be in 16 bits or 128 bits format。

参数

  • uuid:Bluetooth UUID
  • str:pointer where to put converted string
  • len:length of str

返回值:N/A

bt_uuid_str_real(uuid, str, len)

把 UUID 转为可读字符串(实际实现)

参数

  • uuid:Bluetooth UUID
  • str:pointer where to put converted string
  • len:length of str

返回值:N/A

BLE 加密

bt_rand(buf, len)

Generate random 数据. A random number generation helper which utilizes the Bluetooth controller's own RNG.

参数

  • buf:缓冲区 to insert the random 数据
  • len:Length of random 数据 to generate

返回值:Zero on success or error code otherwise, positive in case

bt_encrypt_le(key, plaintext, enc_data)

使用控制器硬件 AES 加密小端数据。

参数

  • key:128 bit LS byte first 密钥 for the encryption of the plaintext
  • plaintext:128 bit LS byte first plaintext 数据 block to be encrypted
  • enc_data:128 bit LS byte first encrypted 数据 block

返回值:Zero on success or error code otherwise.

bt_encrypt_be(key, plaintext, enc_data)

使用控制器硬件 AES 加密大端数据。

参数

  • key:128 bit MS byte first 密钥 for the encryption of the plaintext
  • plaintext:128 bit MS byte first plaintext 数据 block to be encrypted
  • enc_data:128 bit MS byte first encrypted 数据 block

返回值:Zero on success or error code otherwise.

HCI 主机

bt_hci_cmd_send(opcode, param_len)

发送 a HCI command asynchronously。

参数

  • opcode:Command OpCode.
  • param_len:Length of command parameters.

返回值:Newly allocated 缓冲区.

bt_hci_cmd_send_sync(opcode, param_len)

发送 a HCI command synchronously。

参数

  • opcode:Command OpCode.
  • param_len:Length of command parameters.

返回值:Newly allocated 缓冲区.

bt_hci_get_conn_handle(opcode, buf, rsp)

获取连接 handle for a 连接。

参数

  • opcode:Command OpCode.
  • buf:Command 缓冲区 or NULL (if no parameters).
  • rsp:Place to store a reference to the command response. May

返回值:0 on success or negative error 值 on failure.

bt_hci_register_vnd_evt_cb(conn, conn_handle)

Register user 回调 for HCI Vendor-Specific Events

参数

  • conn:连接 object.
  • conn_handle:Place to store the 连接 handle.

返回值:0 on success or negative error 值 on failure.

bt_hci_cmd_create(opcode, param_len)

创建一个 HCI 命令缓冲区

参数

  • opcode:Command OpCode.
  • param_len:Length of command parameters.

返回值:Newly allocated 缓冲区.

遇到问题?

如有其他问题,请到统一的提问与讨论区:Ai-Thinker Discussions

Released under the MIT License. Build Time 2026-09-11 14:52:23