diff --git a/components/bt/host/bluedroid/Kconfig.in b/components/bt/host/bluedroid/Kconfig.in index 734fe0a730..4a3ad65333 100644 --- a/components/bt/host/bluedroid/Kconfig.in +++ b/components/bt/host/bluedroid/Kconfig.in @@ -377,6 +377,13 @@ config BT_GATTS_APPEARANCE_WRITABLE help Enabling this option allows remote GATT clients to write appearance +config BT_GATTS_SECURITY_LEVELS_CHAR + bool "Enable LE GATT Security Levels Characteristic" + depends on BT_GATTS_ENABLE + default n + help + Enable LE GATT Security Levels Characteristic + menuconfig BT_GATTC_ENABLE bool "Include GATT client module(GATTC)" depends on BT_BLE_ENABLED diff --git a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h index c2318de1d0..48d06fba6b 100644 --- a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h +++ b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h @@ -580,6 +580,12 @@ #define UC_BT_GATTS_APPEARANCE_WRITABLE FALSE #endif +#ifdef CONFIG_BT_GATTS_SECURITY_LEVELS_CHAR +#define UC_BT_GATTS_SECURITY_LEVELS_CHAR CONFIG_BT_GATTS_SECURITY_LEVELS_CHAR +#else +#define UC_BT_GATTS_SECURITY_LEVELS_CHAR FALSE +#endif + #ifdef CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN #define UC_BT_BLE_ACT_SCAN_REP_ADV_SCAN CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN #else diff --git a/components/bt/host/bluedroid/common/include/common/bt_target.h b/components/bt/host/bluedroid/common/include/common/bt_target.h index 4dadb8a29f..a62caff1a2 100644 --- a/components/bt/host/bluedroid/common/include/common/bt_target.h +++ b/components/bt/host/bluedroid/common/include/common/bt_target.h @@ -798,6 +798,12 @@ #define GATTS_APPEARANCE_WRITABLE FALSE #endif +#if (UC_BT_GATTS_SECURITY_LEVELS_CHAR == TRUE) +#define BT_GATTS_SECURITY_LEVELS_CHAR TRUE +#else +#define BT_GATTS_SECURITY_LEVELS_CHAR FALSE +#endif + #ifdef UC_BT_BLE_ACT_SCAN_REP_ADV_SCAN #define BTM_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY UC_BT_BLE_ACT_SCAN_REP_ADV_SCAN #endif diff --git a/components/bt/host/bluedroid/stack/gap/gap_ble.c b/components/bt/host/bluedroid/stack/gap/gap_ble.c index bf3d97d666..5dd00e5e79 100644 --- a/components/bt/host/bluedroid/stack/gap/gap_ble.c +++ b/components/bt/host/bluedroid/stack/gap/gap_ble.c @@ -256,6 +256,12 @@ tGATT_STATUS gap_read_attr_value (UINT16 handle, tGATT_VALUE *p_value, BOOLEAN i UINT8_TO_STREAM(p, p_db_attr->attr_value.addr_resolution); p_value->len = 1; break; +#if (BT_GATTS_SECURITY_LEVELS_CHAR == TRUE) + case GATT_UUID_GAP_GATT_SECURITY_LEVELS: + UINT16_TO_STREAM(p, p_db_attr->attr_value.security_level); + p_value->len = 2; + break; +#endif // (BT_GATTS_SECURITY_LEVELS_CHAR == TRUE) } return GATT_SUCCESS; } @@ -464,6 +470,17 @@ void gap_attr_db_init(void) p_db_attr->attr_value.addr_resolution = 0; p_db_attr++; +#if (BT_GATTS_SECURITY_LEVELS_CHAR == TRUE) + /* Add LE Security Levels Characteristic */ + uuid.len = LEN_UUID_16; + uuid.uu.uuid16 = p_db_attr->uuid = GATT_UUID_GAP_GATT_SECURITY_LEVELS; + p_db_attr->handle = GATTS_AddCharacteristic(service_handle, &uuid, + GATT_PERM_READ, GATT_CHAR_PROP_BIT_READ, + NULL, NULL); + p_db_attr->attr_value.security_level = 0x0101; + p_db_attr++; +#endif // (BT_GATTS_SECURITY_LEVELS_CHAR == TRUE) + /* start service now */ memset (&app_uuid.uu.uuid128, 0x81, LEN_UUID_128); @@ -517,6 +534,12 @@ void GAP_BleAttrDBUpdate(UINT16 attr_uuid, tGAP_BLE_ATTR_VALUE *p_value) p_db_attr->attr_value.addr_resolution = p_value->addr_resolution; break; +#if (BT_GATTS_SECURITY_LEVELS_CHAR == TRUE) + case GATT_UUID_GAP_GATT_SECURITY_LEVELS: + p_db_attr->attr_value.security_level = p_value->security_level; + break; +#endif // (BT_GATTS_SECURITY_LEVELS_CHAR == TRUE) + } break; } diff --git a/components/bt/host/bluedroid/stack/include/stack/gap_api.h b/components/bt/host/bluedroid/stack/include/stack/gap_api.h index 62062d2f21..a79d9748c8 100644 --- a/components/bt/host/bluedroid/stack/include/stack/gap_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/gap_api.h @@ -119,6 +119,9 @@ typedef union { UINT16 icon; UINT8 *p_dev_name; UINT8 addr_resolution; +#if (BT_GATTS_SECURITY_LEVELS_CHAR == TRUE) + UINT16 security_level; +#endif // (BT_GATTS_SECURITY_LEVELS_CHAR == TRUE) } tGAP_BLE_ATTR_VALUE; diff --git a/components/bt/host/bluedroid/stack/include/stack/gattdefs.h b/components/bt/host/bluedroid/stack/include/stack/gattdefs.h index d8e4cb591e..2ae8cef839 100644 --- a/components/bt/host/bluedroid/stack/include/stack/gattdefs.h +++ b/components/bt/host/bluedroid/stack/include/stack/gattdefs.h @@ -52,6 +52,8 @@ #define GATT_UUID_GAP_PREF_CONN_PARAM 0x2A04 #define GATT_UUID_GAP_CENTRAL_ADDR_RESOL 0x2AA6 +#define GATT_UUID_GAP_GATT_SECURITY_LEVELS 0x2BF5 + /* Attribute Profile Attribute UUID */ #define GATT_UUID_GATT_SRV_CHGD 0x2A05 /* Attribute Protocol Test */ @@ -81,7 +83,7 @@ #define GATT_UUID_GM_CONTROL_POINT 0x2A52 #define GATT_UUID_GM_FEATURE 0x2A51 -/* device infor characteristic */ +/* device information characteristic */ #define GATT_UUID_SYSTEM_ID 0x2A23 #define GATT_UUID_MODEL_NUMBER_STR 0x2A24 #define GATT_UUID_SERIAL_NUMBER_STR 0x2A25