mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
feat(ble/bluedroid): Support bluedroid encrypted advertising data
This commit is contained in:
@@ -1164,6 +1164,39 @@ void BTM_BleConfigLocalIcon(uint16_t icon)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (BT_GATTS_KEY_MATERIAL_CHAR == TRUE)
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTM_BleSetKeyMaterial
|
||||
**
|
||||
** Description Set the Encrypted Data Key Material in GAP service
|
||||
**
|
||||
** Parameters session_key: 16-byte session key (must not be NULL)
|
||||
** iv: 8-byte initialization vector (must not be NULL)
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
void BTM_BleSetKeyMaterial(const uint8_t *session_key, const uint8_t *iv)
|
||||
{
|
||||
#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE && GATTS_INCLUDED == TRUE)
|
||||
tGAP_BLE_ATTR_VALUE p_value;
|
||||
|
||||
if (session_key == NULL || iv == NULL) {
|
||||
BTM_TRACE_ERROR("%s: NULL pointer parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&p_value, 0, sizeof(tGAP_BLE_ATTR_VALUE));
|
||||
memcpy(p_value.key_material.session_key, session_key, GAP_KEY_MATERIAL_SESSION_KEY_SIZE);
|
||||
memcpy(p_value.key_material.iv, iv, GAP_KEY_MATERIAL_IV_SIZE);
|
||||
GAP_BleAttrDBUpdate(GATT_UUID_GAP_KEY_MATERIAL, &p_value);
|
||||
#else
|
||||
BTM_TRACE_ERROR("%s\n", __func__);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTM_BleConfigConnParams
|
||||
|
||||
@@ -262,6 +262,13 @@ tGATT_STATUS gap_read_attr_value (UINT16 handle, tGATT_VALUE *p_value, BOOLEAN i
|
||||
p_value->len = 2;
|
||||
break;
|
||||
#endif // (BT_GATTS_SECURITY_LEVELS_CHAR == TRUE)
|
||||
#if (BT_GATTS_KEY_MATERIAL_CHAR == TRUE)
|
||||
case GATT_UUID_GAP_KEY_MATERIAL:
|
||||
ARRAY_TO_STREAM(p, p_db_attr->attr_value.key_material.session_key, GAP_KEY_MATERIAL_SESSION_KEY_SIZE);
|
||||
ARRAY_TO_STREAM(p, p_db_attr->attr_value.key_material.iv, GAP_KEY_MATERIAL_IV_SIZE);
|
||||
p_value->len = GAP_KEY_MATERIAL_SIZE;
|
||||
break;
|
||||
#endif // (BT_GATTS_KEY_MATERIAL_CHAR == TRUE)
|
||||
}
|
||||
return GATT_SUCCESS;
|
||||
}
|
||||
@@ -481,6 +488,20 @@ void gap_attr_db_init(void)
|
||||
p_db_attr++;
|
||||
#endif // (BT_GATTS_SECURITY_LEVELS_CHAR == TRUE)
|
||||
|
||||
#if (BT_GATTS_KEY_MATERIAL_CHAR == TRUE)
|
||||
/* Add Encrypted Data Key Material Characteristic
|
||||
* Per Bluetooth spec: readable only when authenticated and authorized,
|
||||
* requires encrypted link to read.
|
||||
*/
|
||||
uuid.len = LEN_UUID_16;
|
||||
uuid.uu.uuid16 = p_db_attr->uuid = GATT_UUID_GAP_KEY_MATERIAL;
|
||||
p_db_attr->handle = GATTS_AddCharacteristic(service_handle, &uuid,
|
||||
GATT_PERM_READ_ENCRYPTED, GATT_CHAR_PROP_BIT_READ,
|
||||
NULL, NULL);
|
||||
memset(&p_db_attr->attr_value.key_material, 0, sizeof(tGAP_BLE_KEY_MATERIAL));
|
||||
p_db_attr++;
|
||||
#endif // (BT_GATTS_KEY_MATERIAL_CHAR == TRUE)
|
||||
|
||||
/* start service now */
|
||||
memset (&app_uuid.uu.uuid128, 0x81, LEN_UUID_128);
|
||||
|
||||
@@ -512,6 +533,11 @@ void GAP_BleAttrDBUpdate(UINT16 attr_uuid, tGAP_BLE_ATTR_VALUE *p_value)
|
||||
|
||||
GAP_TRACE_EVENT("GAP_BleAttrDBUpdate attr_uuid=0x%04x\n", attr_uuid);
|
||||
|
||||
if (p_value == NULL) {
|
||||
GAP_TRACE_ERROR("GAP_BleAttrDBUpdate: NULL pointer parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < GAP_MAX_CHAR_NUM; i ++, p_db_attr ++) {
|
||||
if (p_db_attr->uuid == attr_uuid) {
|
||||
GAP_TRACE_EVENT("Found attr_uuid=0x%04x\n", attr_uuid);
|
||||
@@ -540,6 +566,13 @@ void GAP_BleAttrDBUpdate(UINT16 attr_uuid, tGAP_BLE_ATTR_VALUE *p_value)
|
||||
break;
|
||||
#endif // (BT_GATTS_SECURITY_LEVELS_CHAR == TRUE)
|
||||
|
||||
#if (BT_GATTS_KEY_MATERIAL_CHAR == TRUE)
|
||||
case GATT_UUID_GAP_KEY_MATERIAL:
|
||||
memcpy(&p_db_attr->attr_value.key_material, &p_value->key_material,
|
||||
sizeof(tGAP_BLE_KEY_MATERIAL));
|
||||
break;
|
||||
#endif // (BT_GATTS_KEY_MATERIAL_CHAR == TRUE)
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,11 @@ typedef struct {
|
||||
|
||||
|
||||
#if BLE_INCLUDED == TRUE
|
||||
#if (BT_GATTS_KEY_MATERIAL_CHAR == TRUE)
|
||||
#define GAP_MAX_CHAR_NUM 6
|
||||
#else
|
||||
#define GAP_MAX_CHAR_NUM 5
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
UINT16 handle;
|
||||
|
||||
@@ -2948,6 +2948,22 @@ BOOLEAN BTM_BleConfigPrivacy(BOOLEAN enable, tBTM_SET_LOCAL_PRIVACY_CBACK *set_l
|
||||
*******************************************************************************/
|
||||
void BTM_BleConfigLocalIcon(uint16_t icon);
|
||||
|
||||
#if (BT_GATTS_KEY_MATERIAL_CHAR == TRUE)
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTM_BleSetKeyMaterial
|
||||
**
|
||||
** Description Set the Encrypted Data Key Material in GAP service
|
||||
**
|
||||
** Parameters session_key: 16-byte session key
|
||||
** iv: 8-byte initialization vector
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
void BTM_BleSetKeyMaterial(const uint8_t *session_key, const uint8_t *iv);
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTM_BleConfigConnParams
|
||||
|
||||
@@ -113,6 +113,17 @@ typedef struct {
|
||||
UINT16 sp_tout;
|
||||
} tGAP_BLE_PREF_PARAM;
|
||||
|
||||
#if (BT_GATTS_KEY_MATERIAL_CHAR == TRUE)
|
||||
#define GAP_KEY_MATERIAL_SESSION_KEY_SIZE 16 /* 128-bit session key */
|
||||
#define GAP_KEY_MATERIAL_IV_SIZE 8 /* 64-bit IV */
|
||||
#define GAP_KEY_MATERIAL_SIZE (GAP_KEY_MATERIAL_SESSION_KEY_SIZE + GAP_KEY_MATERIAL_IV_SIZE)
|
||||
|
||||
typedef struct {
|
||||
UINT8 session_key[GAP_KEY_MATERIAL_SESSION_KEY_SIZE];
|
||||
UINT8 iv[GAP_KEY_MATERIAL_IV_SIZE];
|
||||
} tGAP_BLE_KEY_MATERIAL;
|
||||
#endif // (BT_GATTS_KEY_MATERIAL_CHAR == TRUE)
|
||||
|
||||
typedef union {
|
||||
tGAP_BLE_PREF_PARAM conn_param;
|
||||
BD_ADDR reconn_bda;
|
||||
@@ -122,6 +133,9 @@ typedef union {
|
||||
#if (BT_GATTS_SECURITY_LEVELS_CHAR == TRUE)
|
||||
UINT16 security_level;
|
||||
#endif // (BT_GATTS_SECURITY_LEVELS_CHAR == TRUE)
|
||||
#if (BT_GATTS_KEY_MATERIAL_CHAR == TRUE)
|
||||
tGAP_BLE_KEY_MATERIAL key_material;
|
||||
#endif // (BT_GATTS_KEY_MATERIAL_CHAR == TRUE)
|
||||
|
||||
} tGAP_BLE_ATTR_VALUE;
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#define GATT_UUID_GAP_CENTRAL_ADDR_RESOL 0x2AA6
|
||||
|
||||
#define GATT_UUID_GAP_GATT_SECURITY_LEVELS 0x2BF5
|
||||
#define GATT_UUID_GAP_KEY_MATERIAL 0x2B88 /* Encrypted Data Key Material */
|
||||
|
||||
/* Attribute Profile Attribute UUID */
|
||||
#define GATT_UUID_GATT_SRV_CHGD 0x2A05
|
||||
|
||||
Reference in New Issue
Block a user