gatt
GATT (Generic Attribute Profile) 提供BLE设备之间的属性数据交互能力,包括客户端发现远端服务结构、读写属性值,以及服务端创建服务实例、发送通知与指示。
头文件清单
#include "protocol/bt/host/include/bs_service/bs_ble_gatt_client.h"
#include "protocol/bt/host/include/bs_service/bs_ble_gatt_server.h"
#include "protocol/bt/host/include/bs_service/bs_ble_gatt_stru.h"
接口清单
| 接口名称 | 功能简述 |
|---|---|
| bs_gattc_register | 注册GATT客户端 |
| bs_gattc_unregister | 注销GATT客户端 |
| bs_gattc_find_all_service | 发现远端设备所有服务结构 |
| bs_gattc_find_service_by_uuid | 通过UUID发现远端设备服务结构 |
| bs_gattc_register_callbacks | 注册GATT客户端多服务回调函数 |
| bs_gattc_unregister_callbacks | 去注册GATT客户端多服务回调函数 |
| bs_gattc_read | 按句柄发起读取请求 |
| bs_gattc_write | 发起写请求 |
| bs_gattc_exchange_mtu_req | 发送交换MTU请求 |
| bs_gatts_register | 注册GATT服务端 |
| bs_gatts_unregister | 注销GATT服务端 |
| bs_gatts_service_instance_init | 添加GATT服务实例 |
| bs_gatts_service_instance_deinit | 删除GATT服务实例 |
| bs_gatts_send_rsp | 发送读写响应 |
| bs_gatts_notify_indicate | 向对端发送通知或指示 |
| bs_gatts_set_mtu_size | 设置服务端接收MTU大小 |
Functions
bs_gattc_register
头文件清单
功能说明
- 注册GATT客户端,分配客户端ID
- 通过应用UUID标识上层应用
- 注册成功后可使用客户端ID进行后续GATT客户端操作
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| app_uuid | bt_uuid_t * | 上层应用UUID | 非NULL |
出参
| 名称 | 数据类型 | 输出说明 |
|---|---|---|
| client_id | uint8_t * | 客户端ID,非NULL |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | 注册成功 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gattc_unregister
头文件清单
功能说明
- 注销已注册的GATT客户端
- 释放客户端ID对应的资源
- 注销后该客户端ID不再可用
前置条件
- 调用时序约束:必须在bs_gattc_register()成功返回后调用
- 依赖关系:当前接口依赖GATT客户端已注册
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| client_id | uint8_t | 客户端ID | 已注册的有效客户端ID |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | 注销成功 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gattc_find_all_service
errcode_t bs_gattc_find_all_service(uint16_t dev_id, uint8_t client_id, bs_gattc_find_service_callback find_structure_cbk, bool is_remote)
头文件清单
功能说明
- 发现远端设备的所有服务结构,包括服务、特征和描述符
- 支持从远端设备强制获取或从本地缓存获取服务信息
- 发现结果通过回调函数异步返回
前置条件
- 调用时序约束:必须在bs_gattc_register()成功返回后调用
- 依赖关系:当前接口依赖BLE连接已建立
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| dev_id | uint16_t | 设备ID | 有效的已连接设备ID |
| client_id | uint8_t | 客户端ID | 已注册的有效客户端ID |
| find_structure_cbk | bs_gattc_find_service_callback | 服务发现完成回调函数 | 非NULL |
| is_remote | bool | 是否强制从远端获取 | true:强制从远端获取;false:优先从缓存获取 |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | 请求成功发起 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gattc_find_service_by_uuid
errcode_t bs_gattc_find_service_by_uuid(uint16_t dev_id, uint8_t client_id, uint8_t uuid_num, bt_uuid_t *uuid_list, bs_gattc_find_service_callback find_structure_cbk)
头文件清单
功能说明
- 通过UUID发现远端设备指定服务结构,包括服务、特征和描述符
- 支持指定多个UUID进行过滤发现
- 发现结果通过回调函数异步返回
前置条件
- 调用时序约束:必须在bs_gattc_register()成功返回后调用
- 依赖关系:当前接口依赖BLE连接已建立
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| dev_id | uint16_t | 设备ID | 有效的已连接设备ID |
| client_id | uint8_t | 客户端ID | 已注册的有效客户端ID |
| uuid_num | uint8_t | 待发现的UUID数量 | 大于0 |
| uuid_list | bt_uuid_t * | 待发现的UUID列表 | 非NULL |
| find_structure_cbk | bs_gattc_find_service_callback | 服务发现完成回调函数 | 非NULL |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | 请求成功发起 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gattc_register_callbacks
errcode_t bs_gattc_register_callbacks(uint16_t dev_id, uint8_t client_id, bt_uuid_t *service_uuid, bs_gattc_operation_cbk_t *func)
头文件清单
功能说明
- 注册GATT客户端多服务回调函数
- 通过服务UUID区分不同服务的回调
- 注册后可接收指定服务的读写响应、通知、指示及MTU变更事件
前置条件
- 调用时序约束:必须在bs_gattc_register()成功返回且服务发现完成后调用
- 依赖关系:当前接口与gattc_register_callbacks接口互斥,只能使用其中一个
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| dev_id | uint16_t | 设备ID | 有效的已连接设备ID |
| client_id | uint8_t | 客户端ID | 已注册的有效客户端ID |
| service_uuid | bt_uuid_t * | 服务UUID | 非NULL |
| func | bs_gattc_operation_cbk_t * | 回调函数结构体指针 | 非NULL |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | 注册成功 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gattc_unregister_callbacks
errcode_t bs_gattc_unregister_callbacks(uint16_t dev_id, uint8_t client_id, bt_uuid_t *service_uuid)
头文件清单
功能说明
- 去注册GATT客户端多服务回调函数
- 通过服务UUID取消指定服务的回调注册
- 去注册后不再接收该服务的读写响应、通知、指示等事件
前置条件
- 调用时序约束:必须在bs_gattc_register_callbacks()成功注册后调用
- 依赖关系:当前接口依赖对应服务回调已注册
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| dev_id | uint16_t | 设备ID | 有效的已连接设备ID |
| client_id | uint8_t | 客户端ID | 已注册的有效客户端ID |
| service_uuid | bt_uuid_t * | 服务UUID | 非NULL,已注册回调的服务UUID |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | 去注册成功 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gattc_read
头文件清单
功能说明
- 按句柄向远端设备发起读取请求
- 读取结果通过bs_gattc_read_cfm_callback回调异步返回
- 支持读取指定属性句柄的值
前置条件
- 调用时序约束:必须在bs_gattc_register_callbacks()成功注册后调用
- 依赖关系:当前接口依赖BLE连接已建立且已注册读回调
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| dev_id | uint16_t | 设备ID | 有效的已连接设备ID |
| client_id | uint8_t | 客户端ID | 已注册的有效客户端ID |
| handle | uint16_t | 属性句柄 | 有效的属性句柄 |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | 读取请求成功发起 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gattc_write
头文件清单
功能说明
- 向远端设备发起写请求
- 写结果通过bs_gattc_write_cfm_callback回调异步返回
- 支持设置是否需要对端确认
前置条件
- 调用时序约束:必须在bs_gattc_register_callbacks()成功注册后调用
- 依赖关系:当前接口依赖BLE连接已建立且已注册写回调
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| dev_id | uint16_t | 设备ID | 有效的已连接设备ID |
| client_id | uint8_t | 客户端ID | 已注册的有效客户端ID |
| param | bs_gattc_write_value_t * | 写信息参数 | 非NULL |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | 写请求成功发起 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gattc_exchange_mtu_req
头文件清单
功能说明
- 向远端设备发送交换MTU请求
- MTU变更结果通过bs_gattc_mtu_changed_callback回调异步返回
- 设置客户端接收MTU大小
前置条件
- 调用时序约束:必须在bs_gattc_register()成功返回后调用
- 依赖关系:当前接口依赖BLE连接已建立
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| dev_id | uint16_t | 设备ID | 有效的已连接设备ID |
| client_id | uint8_t | 客户端ID | 已注册的有效客户端ID |
| mtu_size | uint16_t | 客户端接收MTU大小 | BS_BLE_MTU_MIN ~ BS_BLE_MTU_MAX |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | MTU交换请求成功发起 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gatts_register
头文件清单
功能说明
- 注册GATT服务端,分配服务端ID
- 通过应用UUID标识上层应用
- 注册成功后可使用服务端ID进行后续GATT服务端操作
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| app_uuid | bt_uuid_t * | 上层应用UUID | 非NULL |
出参
| 名称 | 数据类型 | 输出说明 |
|---|---|---|
| server_id | uint8_t * | 服务端ID,非NULL |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | 注册成功 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gatts_unregister
头文件清单
功能说明
- 注销已注册的GATT服务端
- 释放服务端ID对应的资源
- 注销后该服务端ID不再可用
前置条件
- 调用时序约束:必须在bs_gatts_register()成功返回后调用
- 依赖关系:当前接口依赖GATT服务端已注册
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| server_id | uint8_t | 服务端ID | 已注册的有效服务端ID |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | 注销成功 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gatts_service_instance_init
errcode_t bs_gatts_service_instance_init(uint8_t server_id, bs_gatt_service_template_t *service, uint8_t *inst_id)
头文件清单
功能说明
- 添加GATT服务实例,根据服务模板创建服务
- 支持配置服务UUID、属性(特征和描述符)及回调函数
- 添加成功后返回服务实例ID
前置条件
- 调用时序约束:必须在bs_gatts_register()成功返回后调用
- 依赖关系:当前接口依赖GATT服务端已注册
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| server_id | uint8_t | 服务端ID | 已注册的有效服务端ID |
| service | bs_gatt_service_template_t * | 服务模板 | 非NULL |
出参
| 名称 | 数据类型 | 输出说明 |
|---|---|---|
| inst_id | uint8_t * | 服务实例ID,非NULL |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | 服务实例添加成功 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gatts_service_instance_deinit
头文件清单
功能说明
- 删除GATT服务实例
- 释放服务实例对应的资源
- 删除后该服务实例ID不再可用
前置条件
- 调用时序约束:必须在bs_gatts_service_instance_init()成功返回后调用
- 依赖关系:当前接口依赖GATT服务实例已创建
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| server_id | uint8_t | 服务端ID | 已注册的有效服务端ID |
| inst_id | uint8_t | 服务实例ID | 已创建的有效服务实例ID |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | 服务实例删除成功 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gatts_send_rsp
头文件清单
功能说明
- 收到需要用户回复的读写请求时,发送响应
- 响应内容通过bs_gatts_read_request_callback或bs_gatts_write_request_callback回调触发
- 支持设置响应状态码和响应数据
前置条件
- 调用时序约束:必须在收到读写请求回调且need_rsp为true后调用
- 依赖关系:当前接口依赖GATT服务端已注册且已收到读写请求
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| dev_id | uint16_t | 设备ID | 有效的已连接设备ID |
| server_id | uint8_t | 服务端ID | 已注册的有效服务端ID |
| param | bs_gatts_send_rsp_t * | 响应参数 | 非NULL |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | 响应发送成功 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gatts_notify_indicate
头文件清单
功能说明
- 向对端设备发送通知或指示
- 具体发送类型取决于特征描述符中的客户端特征配置
- 支持指定服务实例和属性ID发送数据
前置条件
- 调用时序约束:必须在bs_gatts_service_instance_init()成功且服务启动后调用
- 依赖关系:当前接口依赖BLE连接已建立且对端已订阅通知或指示
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| dev_id | uint16_t | 设备ID | 有效的已连接设备ID |
| server_id | uint8_t | 服务端ID | 已注册的有效服务端ID |
| param | bs_gatts_ntf_ind_t * | 通知或指示参数 | 非NULL |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | 通知或指示发送成功 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
bs_gatts_set_mtu_size
头文件清单
功能说明
- 在连接之前设置服务端接收MTU大小
- MTU大小影响单次传输的数据量
- 必须在BLE连接建立之前调用
前置条件
- 调用时序约束:必须在BLE连接建立之前调用
- 依赖关系:当前接口依赖GATT服务端已注册
入参
| 名称 | 参数类型 | 详细说明 | 约束取值范围 |
|---|---|---|---|
| server_id | uint8_t | 服务端ID | 已注册的有效服务端ID |
| mtu_size | uint16_t | 服务端接收MTU大小 | BS_BLE_MTU_MIN ~ BS_BLE_MTU_MAX |
返回值
| 返回值 | 文字含义 | 触发场景 |
|---|---|---|
| ERRCODE_BT_SUCCESS(0x00) | 执行成功 | MTU设置成功 |
| Other | 其他错误码,参考errcode_bt_t | 执行失败 |
Enumerations
bs_gatt_characteristic_property_t
typedef enum {
BS_GATT_CHARACTER_PROPERTY_BIT_BROADCAST = 0x01,
BS_GATT_CHARACTER_PROPERTY_BIT_READ = 0x02,
BS_GATT_CHARACTER_PROPERTY_BIT_WRITE_NO_RSP = 0x04,
BS_GATT_CHARACTER_PROPERTY_BIT_WRITE = 0x08,
BS_GATT_CHARACTER_PROPERTY_BIT_NOTIFY = 0x10,
BS_GATT_CHARACTER_PROPERTY_BIT_INDICATE = 0x20,
BS_GATT_CHARACTER_PROPERTY_BIT_SIGNED_WRITE = 0x40,
BS_GATT_CHARACTER_PROPERTY_BIT_EXTENDED_PROPERTY = 0x80,
} bs_gatt_characteristic_property_t;
| 枚举成员 | 取值 | 描述 |
|---|---|---|
| BS_GATT_CHARACTER_PROPERTY_BIT_BROADCAST | 0x01 | 广播特征值 |
| BS_GATT_CHARACTER_PROPERTY_BIT_READ | 0x02 | 读特征值 |
| BS_GATT_CHARACTER_PROPERTY_BIT_WRITE_NO_RSP | 0x04 | 写特征值并且不需要响应 |
| BS_GATT_CHARACTER_PROPERTY_BIT_WRITE | 0x08 | 写特征值 |
| BS_GATT_CHARACTER_PROPERTY_BIT_NOTIFY | 0x10 | 通知特征值 |
| BS_GATT_CHARACTER_PROPERTY_BIT_INDICATE | 0x20 | 指示特征值 |
| BS_GATT_CHARACTER_PROPERTY_BIT_SIGNED_WRITE | 0x40 | 签名写特征值 |
| BS_GATT_CHARACTER_PROPERTY_BIT_EXTENDED_PROPERTY | 0x80 | 在特征扩展特性描述符中定义了附加的特征特性 |
bs_gatt_attribute_permission_t
typedef enum {
BS_GATT_ATTRIBUTE_PERMISSION_READ = 0x01,
BS_GATT_ATTRIBUTE_PERMISSION_WRITE = 0x02,
BS_GATT_ATTRIBUTE_PERMISSION_ENCRYPTION_NEED = 0x04,
BS_GATT_ATTRIBUTE_PERMISSION_AUTHENTICATION_NEED = 0x08,
BS_GATT_ATTRIBUTE_PERMISSION_AUTHORIZATION_NEED = 0x10,
BS_GATT_ATTRIBUTE_PERMISSION_MITM_NEED = 0x20,
} bs_gatt_attribute_permission_t;
| 枚举成员 | 取值 | 描述 |
|---|---|---|
| BS_GATT_ATTRIBUTE_PERMISSION_READ | 0x01 | 可读 |
| BS_GATT_ATTRIBUTE_PERMISSION_WRITE | 0x02 | 可写 |
| BS_GATT_ATTRIBUTE_PERMISSION_ENCRYPTION_NEED | 0x04 | 需要加密 |
| BS_GATT_ATTRIBUTE_PERMISSION_AUTHENTICATION_NEED | 0x08 | 需要认证 |
| BS_GATT_ATTRIBUTE_PERMISSION_AUTHORIZATION_NEED | 0x10 | 需要授权 |
| BS_GATT_ATTRIBUTE_PERMISSION_MITM_NEED | 0x20 | 需要MITM保护 |
bs_gatt_status_t
typedef enum {
BS_GATT_STATUS_SUCCESS = 0x00,
BS_GATT_STATUS_INVALID_HANDLE = 0x01,
BS_GATT_STATUS_READ_NOT_PERMITTED = 0x02,
BS_GATT_STATUS_WRITE_NOT_PERMITTED = 0x03,
BS_GATT_STATUS_INVALID_PDU = 0x04,
BS_GATT_STATUS_INSUFFICIENT_AUTHENTICATION = 0x05,
BS_GATT_STATUS_REQUEST_NOT_SUPPORTED = 0x06,
BS_GATT_STATUS_INVALID_OFFSET = 0x07,
BS_GATT_STATUS_INSUFFICIENT_AUTHORIZATION = 0x08,
BS_GATT_STATUS_PREPARE_QUEUE_FULL = 0x09,
BS_GATT_STATUS_ATTRIBUTE_NOT_FOUND = 0x0A,
BS_GATT_STATUS_ATTRIBUTE_NOT_LONG = 0x0B,
BS_GATT_STATUS_INSUFFICIENT_ENCRYPTION_KEY_SIZE = 0x0C,
BS_GATT_STATUS_INVALID_ATTRIBUTE_VALUE_LENGTH = 0x0D,
BS_GATT_STATUS_UNLIKELY_ERROR = 0x0E,
BS_GATT_STATUS_INSUFFICIENT_ENCRYPTION = 0x0F,
BS_GATT_STATUS_UNSUPPORTED_GROUP_TYPE = 0x10,
BS_GATT_STATUS_INSUFFICIENT_RESOURCES = 0x11,
BS_GATT_STATUS_DATABASE_OUT_OF_SYNC = 0x12,
BS_GATT_STATUS_VALUE_NOT_ALLOWED = 0x13,
} bs_gatt_status_t;
| 枚举成员 | 取值 | 描述 |
|---|---|---|
| BS_GATT_STATUS_SUCCESS | 0x00 | 执行成功错误码 |
| BS_GATT_STATUS_INVALID_HANDLE | 0x01 | 无效handle错误码 |
| BS_GATT_STATUS_READ_NOT_PERMITTED | 0x02 | 不可读错误码 |
| BS_GATT_STATUS_WRITE_NOT_PERMITTED | 0x03 | 不可写错误码 |
| BS_GATT_STATUS_INVALID_PDU | 0x04 | 无效PDU错误码 |
| BS_GATT_STATUS_INSUFFICIENT_AUTHENTICATION | 0x05 | 未认证的读写错误码 |
| BS_GATT_STATUS_REQUEST_NOT_SUPPORTED | 0x06 | 不支持client发送的请求 |
| BS_GATT_STATUS_INVALID_OFFSET | 0x07 | 无效偏移的读写错误码 |
| BS_GATT_STATUS_INSUFFICIENT_AUTHORIZATION | 0x08 | 未授权错误码 |
| BS_GATT_STATUS_PREPARE_QUEUE_FULL | 0x09 | 排队的prepare writes太多,队列已满错误码 |
| BS_GATT_STATUS_ATTRIBUTE_NOT_FOUND | 0x0A | 属性未找到错误码 |
| BS_GATT_STATUS_ATTRIBUTE_NOT_LONG | 0x0B | 该attribute不是long attribute,不能使用ATT_READ_BLOB_REQ PDU |
| BS_GATT_STATUS_INSUFFICIENT_ENCRYPTION_KEY_SIZE | 0x0C | 加密密钥大小不足错误码 |
| BS_GATT_STATUS_INVALID_ATTRIBUTE_VALUE_LENGTH | 0x0D | 属性值长度无效错误码 |
| BS_GATT_STATUS_UNLIKELY_ERROR | 0x0E | 不可能的错误码 |
| BS_GATT_STATUS_INSUFFICIENT_ENCRYPTION | 0x0F | 加密不足错误码 |
| BS_GATT_STATUS_UNSUPPORTED_GROUP_TYPE | 0x10 | 不支持的grouping attribute错误码 |
| BS_GATT_STATUS_INSUFFICIENT_RESOURCES | 0x11 | 资源不足错误码 |
| BS_GATT_STATUS_DATABASE_OUT_OF_SYNC | 0x12 | 服务端与客户端未同步数据库错误码 |
| BS_GATT_STATUS_VALUE_NOT_ALLOWED | 0x13 | 非法的参数值错误码 |
Structures
bs_gattc_handle_value_t
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| handle | uint16_t | 属性句柄 |
| data_len | uint16_t | 数据长度 |
| data | uint8_t * | 数据 |
bs_gattc_write_value_t
typedef struct {
uint16_t handle;
bool is_need_confirm;
uint16_t data_len;
uint8_t *data;
} bs_gattc_write_value_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| handle | uint16_t | 属性句柄 |
| is_need_confirm | bool | 是否需要对端确认,false:无需对端回复,true:对端确认后结果在bs_gattc_write_cfm_callback回调中返回 |
| data_len | uint16_t | 数据长度 |
| data | uint8_t * | 数据 |
bs_gattc_discovery_service_result_t
typedef struct {
uint16_t start_hdl;
uint16_t end_hdl;
bt_uuid_t uuid;
} bs_gattc_discovery_service_result_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| start_hdl | uint16_t | 服务起始句柄 |
| end_hdl | uint16_t | 服务结束句柄 |
| uuid | bt_uuid_t | 服务UUID |
bs_gattc_discovery_character_result_t
typedef struct {
bt_uuid_t uuid;
uint16_t declare_handle;
uint16_t value_handle;
uint8_t properties;
} bs_gattc_discovery_character_result_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| uuid | bt_uuid_t | 特征UUID |
| declare_handle | uint16_t | 特征声明句柄 |
| value_handle | uint16_t | 特征值句柄 |
| properties | uint8_t | 特征特性,参考bs_gatt_characteristic_property_t |
bs_gattc_discovery_descriptor_result_t
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| descriptor_hdl | uint16_t | 特征描述符句柄 |
| uuid | bt_uuid_t | 特征描述符UUID |
bs_gattc_find_service_result_node_t
typedef struct {
bs_gattc_discovery_service_result_t service;
uint8_t character_count;
bs_gattc_discovery_character_result_t *character_list;
uint8_t descriptor_count;
bs_gattc_discovery_descriptor_result_t *descriptor_list;
} bs_gattc_find_service_result_node_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| service | bs_gattc_discovery_service_result_t | 服务信息 |
| character_count | uint8_t | 服务的特征个数 |
| character_list | bs_gattc_discovery_character_result_t * | 特征元素数组 |
| descriptor_count | uint8_t | 服务的描述符个数 |
| descriptor_list | bs_gattc_discovery_descriptor_result_t * | 描述符元素数组 |
bs_gattc_read_write_callbacks_t
typedef struct {
bs_gattc_read_cfm_callback read_cb;
bs_gattc_write_cfm_callback write_cb;
} bs_gattc_read_write_callbacks_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| read_cb | bs_gattc_read_cfm_callback | 收到读响应回调函数 |
| write_cb | bs_gattc_write_cfm_callback | 收到写响应回调函数 |
bs_gattc_notication_indication_callbacks_t
typedef struct {
bs_gattc_notification_callback notification_cb;
bs_gattc_indication_callback indication_cb;
} bs_gattc_notication_indication_callbacks_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| notification_cb | bs_gattc_notification_callback | 收到通知回调函数 |
| indication_cb | bs_gattc_indication_callback | 收到指示回调函数 |
bs_gattc_operation_cbk_t
typedef struct {
bs_gattc_read_write_callbacks_t read_write_cbk;
bs_gattc_notication_indication_callbacks_t notication_indication_cbk;
bs_gattc_mtu_changed_callback mtu_changed_cb;
} bs_gattc_operation_cbk_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| read_write_cbk | bs_gattc_read_write_callbacks_t | 读写回调函数接口定义 |
| notication_indication_cbk | bs_gattc_notication_indication_callbacks_t | 通知和指示回调函数接口定义 |
| mtu_changed_cb | bs_gattc_mtu_changed_callback | MTU改变回调函数 |
bs_gatts_add_chara_info_t
typedef struct {
bt_uuid_t uuid;
uint8_t permissions;
uint8_t properties;
uint16_t value_len;
uint8_t *value;
} bs_gatts_add_chara_info_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| uuid | bt_uuid_t | GATT特征UUID |
| permissions | uint8_t | 特征权限,参考bs_gatt_attribute_permission_t |
| properties | uint8_t | 特征特性,参考bs_gatt_characteristic_property_t |
| value_len | uint16_t | 特征数据长度 |
| value | uint8_t * | 特征数据 |
bs_gatts_add_desc_info_t
typedef struct {
bt_uuid_t uuid;
uint8_t permissions;
uint16_t value_len;
uint8_t *value;
} bs_gatts_add_desc_info_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| uuid | bt_uuid_t | GATT描述符UUID |
| permissions | uint8_t | 描述符权限,参考bs_gatt_attribute_permission_t |
| value_len | uint16_t | 描述符数据长度 |
| value | uint8_t * | 描述符数据 |
bs_gatts_attribute_info
typedef struct {
uint8_t type;
union {
bs_gatts_add_chara_info_t character;
bs_gatts_add_desc_info_t descriptor;
};
} bs_gatts_attribute_info;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| type | uint8_t | 类型标识,0:特征,1:描述符 |
| character | bs_gatts_add_chara_info_t | 添加特征信息(type为0时有效) |
| descriptor | bs_gatts_add_desc_info_t | 添加特征描述符信息(type为1时有效) |
bs_gatts_req_read_cb_t
typedef struct {
uint8_t inst_id;
uint8_t attribute_id;
uint16_t request_id;
bool need_rsp;
bool need_authorize;
} bs_gatts_req_read_cb_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| inst_id | uint8_t | 服务实例ID |
| attribute_id | uint8_t | 当前服务实例下的属性ID |
| request_id | uint16_t | 请求ID |
| need_rsp | bool | 是否需要发送响应 |
| need_authorize | bool | 是否需要授权 |
bs_gatts_req_write_cb_t
typedef struct {
uint8_t inst_id;
uint8_t attribute_id;
uint16_t request_id;
bool need_rsp;
bool need_authorize;
uint16_t value_len;
uint8_t *value;
} bs_gatts_req_write_cb_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| inst_id | uint8_t | 服务实例ID |
| attribute_id | uint8_t | 当前服务实例下的属性ID |
| request_id | uint16_t | 请求ID |
| need_rsp | bool | 是否需要发送响应 |
| need_authorize | bool | 是否需要授权 |
| value_len | uint16_t | 请求写的数据长度 |
| value | uint8_t * | 请求写的数据 |
bs_gatts_send_rsp_t
typedef struct {
uint16_t request_id;
uint8_t status;
uint16_t value_len;
uint8_t *value;
} bs_gatts_send_rsp_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| request_id | uint16_t | 请求ID |
| status | uint8_t | 读写结果的状态,参考bs_gatt_status_t |
| value_len | uint16_t | 响应的数据长度 |
| value | uint8_t * | 响应的数据 |
bs_gatts_ntf_ind_t
typedef struct {
uint8_t instance_id;
uint8_t attribute_id;
uint16_t value_len;
uint8_t *value;
} bs_gatts_ntf_ind_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| instance_id | uint8_t | 服务实例ID |
| attribute_id | uint8_t | 属性ID |
| value_len | uint16_t | 通知或指示数据长度 |
| value | uint8_t * | 发送的通知或指示数据 |
bs_gatt_service_callbacks_t
typedef struct {
bs_gatts_start_service_callback start_service_cb;
bs_gatts_stop_service_callback stop_service_cb;
bs_gatts_delete_service_callback delete_service_cb;
bs_gatts_read_request_callback read_request_cb;
bs_gatts_write_request_callback write_request_cb;
bs_gatts_indication_confirm_callback indicate_cfm_cb;
bs_gatts_mtu_changed_callback mtu_changed_cb;
} bs_gatt_service_callbacks_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| start_service_cb | bs_gatts_start_service_callback | 启动服务回调函数 |
| stop_service_cb | bs_gatts_stop_service_callback | 停止服务回调函数 |
| delete_service_cb | bs_gatts_delete_service_callback | 删除服务回调函数 |
| read_request_cb | bs_gatts_read_request_callback | 收到远端读请求回调函数 |
| write_request_cb | bs_gatts_write_request_callback | 收到远端写请求回调函数 |
| indicate_cfm_cb | bs_gatts_indication_confirm_callback | 指示确认回调函数 |
| mtu_changed_cb | bs_gatts_mtu_changed_callback | MTU大小更新回调函数 |
bs_gatt_service_extend_param_t
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| resverved | uint8_t | 预留 |
bs_gatt_service_template_t
typedef struct {
bt_uuid_t uuid;
uint8_t is_primary;
uint8_t attribute_count;
bs_gatt_service_callbacks_t cbks;
bs_gatt_service_extend_param_t extend_param;
bs_gatts_attribute_info attribute_array[0];
} bs_gatt_service_template_t;
成员说明
| 成员名称 | 数据类型 | 描述 |
|---|---|---|
| uuid | bt_uuid_t | 该服务UUID |
| is_primary | uint8_t | 是否是主服务标记 |
| attribute_count | uint8_t | attribute_array中存储的属性(包括特征和描述符)个数 |
| cbks | bs_gatt_service_callbacks_t | 服务端回调函数 |
| extend_param | bs_gatt_service_extend_param_t | 服务端扩展参数 |
| attribute_array | bs_gatts_attribute_info[0] | 服务中的属性(包括特征和描述符)数组 |