Posted
: 2020-04-11
Status
:
Completed
Tags
:
CC2541
BLE
ble
特征值
Characteristic
Previous
:
BLE--CC2541的入门之绑定与配对
Next
:
树莓派上HomeBridge 的安装
simpleBLEPeripheral.c
文件内SimpleBLEPeripheral_Init
函数中的服务添加
GGS_AddService( GATT_ALL_SERVICES );
注释掉,重新编译下载,在BLE Device Monitor会看到Generic Access Service消失了
服务 | 代码 |
---|---|
Generic Access Service | GGS_AddService( GATT_ALL_SERVICES ) |
Generic Attribute Service | GATTServApp_AddService( GATT_ALL_SERVICES ) |
Device Information Service | DevInfo_AddService() |
Simple Profile Service | SimpleProfile_AddService( GATT_ALL_SERVICES ) |
GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName );
设置attDeviceName
值去验证
F0:FF
,即0xFFF0,低8位在前,高8位在后
gattservapp.h
文件内
1
2
3
4
5
6
7
8
#define GATT_PROP_BCAST 0x01 //!< Permits broadcasts of the Characteristic Value
#define GATT_PROP_READ 0x02 //!< Permits reads of the Characteristic Value
#define GATT_PROP_WRITE_NO_RSP 0x04 //!< Permits writes of the Characteristic Value without response
#define GATT_PROP_WRITE 0x08 //!< Permits writes of the Characteristic Value with response
#define GATT_PROP_NOTIFY 0x10 //!< Permits notifications of a Characteristic Value without acknowledgement
#define GATT_PROP_INDICATE 0x20 //!< Permits indications of a Characteristic Value with acknowledgement
#define GATT_PROP_AUTHEN 0x40 //!< Permits signed writes to the Characteristic Value
#define GATT_PROP_EXTENDED 0x80 //!< Additional characteristic properties are defined in the Characteristic Extended Properties Descriptor
属性 | 值 | 含义 |
---|---|---|
GATT_PROP_BCAST | 0x01 | 允许广播 |
GATT_PROP_READ | 0x02 | 允许读取 |
GATT_PROP_WRITE_NO_RSP | 0x04 | 允许写入而不响应 |
GATT_PROP_WRITE | 0x08 | 允许写入 |
GATT_PROP_NOTIFY | 0x10 | 允许通知 |
GATT_PROP_INDICATE | 0x20 | 允许指示 |
GATT_PROP_AUTHEN | 0x40 | 允许签名写入 |
GATT_PROP_EXTENDED | 0x80 | 其他特性属性在特性扩展属性描述符中定义 |
0A:25:00:F1:FF
0A
代表0x08+0x02
即允许写入和读取25:00
代表37,即Characteristic1的分配句柄,也可以在BLE Device Monito看到F1:FF
代表Characteristic1的UUID,0xFFF1gatt.h
文件内
1
2
3
4
5
6
7
8
#define GATT_PERMIT_READ 0x01 //!< Attribute is Readable
#define GATT_PERMIT_WRITE 0x02 //!< Attribute is Writable
#define GATT_PERMIT_AUTHEN_READ 0x04 //!< Read requires Authentication
#define GATT_PERMIT_AUTHEN_WRITE 0x08 //!< Write requires Authentication
#define GATT_PERMIT_AUTHOR_READ 0x10 //!< Read requires Authorization
#define GATT_PERMIT_AUTHOR_WRITE 0x20 //!< Write requires Authorization
#define GATT_PERMIT_ENCRYPT_READ 0x40 //!< Read requires Encryption
#define GATT_PERMIT_ENCRYPT_WRITE 0x80 //!< Write requires Encryption
权限 | 值 | 含义 |
---|---|---|
GATT_PERMIT_READ | 0x01 | 可读 |
GATT_PERMIT_WRITE | 0x02 | 可写 |
GATT_PERMIT_AUTHEN_READ | 0x04 | 读取需要身份验证 |
GATT_PERMIT_AUTHEN_WRITE | 0x08 | 写入需要身份验证 |
GATT_PERMIT_AUTHOR_READ | 0x10 | 读取需要授权 |
GATT_PERMIT_AUTHOR_WRITE | 0x20 | 写入需要授权 |
GATT_PERMIT_ENCRYPT_READ | 0x40 | 读取需要加密 |
GATT_PERMIT_ENCRYPT_WRITE | 0x80 | 写入需要加密 |
特征 | 属性 | 权限 |
---|---|---|
Characteristic1 | 0x0A | 读:正常 写:正常 |
Characteristic2 | 0x02 | 读:正常 写:err3 |
Characteristic3 | 0x08 | 读:err2 写:正常 |
Characteristic4 | 0x10 | 读:err2 写:err3 |
Characteristic5 | 0x02 | 读:err5 写:err3 |
simpleGATTprofile.c
特征 | 属性 | 权限 |
---|---|---|
Characteristic1 | 读写 | 读写 |
Characteristic2 | 读 | 读 |
Characteristic3 | 写 | 写 |
Characteristic4 | 通知 | 0 |
Characteristic5 | 读 | 读取需要身份验证 |
att.h
文件中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#define ATT_ERR_INVALID_HANDLE 0x01 //!< Attribute handle value given was not valid on this attribute server
#define ATT_ERR_READ_NOT_PERMITTED 0x02 //!< Attribute cannot be read
#define ATT_ERR_WRITE_NOT_PERMITTED 0x03 //!< Attribute cannot be written
#define ATT_ERR_INVALID_PDU 0x04 //!< The attribute PDU was invalid
#define ATT_ERR_INSUFFICIENT_AUTHEN 0x05 //!< The attribute requires authentication before it can be read or written
#define ATT_ERR_UNSUPPORTED_REQ 0x06 //!< Attribute server doesn't support the request received from the attribute client
#define ATT_ERR_INVALID_OFFSET 0x07 //!< Offset specified was past the end of the attribute
#define ATT_ERR_INSUFFICIENT_AUTHOR 0x08 //!< The attribute requires an authorization before it can be read or written
#define ATT_ERR_PREPARE_QUEUE_FULL 0x09 //!< Too many prepare writes have been queued
#define ATT_ERR_ATTR_NOT_FOUND 0x0a //!< No attribute found within the given attribute handle range
#define ATT_ERR_ATTR_NOT_LONG 0x0b //!< Attribute cannot be read or written using the Read Blob Request or Prepare Write Request
#define ATT_ERR_INSUFFICIENT_KEY_SIZE 0x0c //!< The Encryption Key Size used for encrypting this link is insufficient
#define ATT_ERR_INVALID_VALUE_SIZE 0x0d //!< The attribute value length is invalid for the operation
#define ATT_ERR_UNLIKELY 0x0e //!< The attribute request that was requested has encountered an error that was very unlikely, and therefore could not be completed as requested
#define ATT_ERR_INSUFFICIENT_ENCRYPT 0x0f //!< The attribute requires encryption before it can be read or written
#define ATT_ERR_UNSUPPORTED_GRP_TYPE 0x10 //!< The attribute type is not a supported grouping attribute as defined by a higher layer specification
#define ATT_ERR_INSUFFICIENT_RESOURCES 0x11 //!< Insufficient Resources to complete the request
错误 | 值 | 含义 |
---|---|---|
ATT_ERR_INVALID_HANDLE | 0x01 | 属性句柄值无效 |
ATT_ERR_READ_NOT_PERMITTED | 0x02 | 无权限读取 |
ATT_ERR_WRITE_NOT_PERMITTED | 0x03 | 无权限写入 |
ATT_ERR_INVALID_PDU | 0x04 | PDU无效 |
ATT_ERR_INSUFFICIENT_AUTHEN | 0x05 | 需要身份验证 |
ATT_ERR_UNSUPPORTED_REQ | 0x06 | 服务器不支持此请求 |
ATT_ERR_INVALID_OFFSET | 0x07 | 指定偏移量溢出 |
ATT_ERR_INSUFFICIENT_AUTHOR | 0x08 | 需要授权 |
ATT_ERR_PREPARE_QUEUE_FULL | 0x09 | 写入队列已满 |
ATT_ERR_ATTR_NOT_FOUND | 0x0a | 没有找到属性 |
ATT_ERR_ATTR_NOT_LONG | 0x0b | 属性不能用Blob读请求或Prepare写请求 |
ATT_ERR_INSUFFICIENT_KEY_SIZE | 0x0c | 加密密钥大小不够 |
ATT_ERR_INVALID_VALUE_SIZE | 0x0d | 属性值长度无效 |
ATT_ERR_UNLIKELY | 0x0e | 请求发生错误,无法完成请求 |
ATT_ERR_INSUFFICIENT_ENCRYPT | 0x0f | 需要加密 |
ATT_ERR_UNSUPPORTED_GRP_TYPE | 0x10 | 属性类型不支持 |
ATT_ERR_INSUFFICIENT_RESOURCES | 0x11 | 资源不足 |