Skip to content

Commit e2d488c

Browse files
committed
Merge branch 'bugfix/fix_gatt_svc_attrs_count' into 'master'
Bluedroid: Configurable option to modify max gatt service attributes count Closes IDFGH-7861 See merge request espressif/esp-idf!19313
2 parents cda6360 + e29170b commit e2d488c

File tree

7 files changed

+29
-12
lines changed

7 files changed

+29
-12
lines changed

components/bt/host/bluedroid/Kconfig.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ config BT_GATT_MAX_SR_PROFILES
173173
help
174174
Maximum GATT Server Profiles Count
175175

176+
config BT_GATT_MAX_SR_ATTRIBUTES
177+
int "Max GATT Service Attributes"
178+
depends on BT_GATTS_ENABLE && BT_BLUEDROID_ENABLED
179+
range 1 500
180+
default 100
181+
help
182+
Maximum GATT Service Attributes Count
176183

177184

178185
choice BT_GATTS_SEND_SERVICE_CHANGE_MODE

components/bt/host/bluedroid/api/esp_gatts_api.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,19 @@ esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatts_if,
8585

8686
esp_err_t esp_ble_gatts_create_attr_tab(const esp_gatts_attr_db_t *gatts_attr_db,
8787
esp_gatt_if_t gatts_if,
88-
uint8_t max_nb_attr,
88+
uint16_t max_nb_attr,
8989
uint8_t srvc_inst_id)
9090
{
9191
btc_msg_t msg = {0};
9292
btc_ble_gatts_args_t arg;
9393

9494
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
9595

96+
if (max_nb_attr > ESP_GATT_ATTR_HANDLE_MAX) {
97+
LOG_ERROR("%s the number of attribute should not be greater than CONFIG_BT_GATT_MAX_SR_ATTRIBUTES\n");
98+
return ESP_ERR_INVALID_ARG;
99+
}
100+
96101
msg.sig = BTC_SIG_API_CALL;
97102
msg.pid = BTC_PID_GATTS;
98103
msg.act = BTC_GATTS_ACT_CREATE_ATTR_TAB;

components/bt/host/bluedroid/api/include/api/esp_gatt_defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern "C" {
1818
/// GATT INVALID HANDLE
1919
#define ESP_GATT_ILLEGAL_HANDLE 0
2020
/// GATT attribute max handle
21-
#define ESP_GATT_ATTR_HANDLE_MAX 100
21+
#define ESP_GATT_ATTR_HANDLE_MAX UC_CONFIG_BT_GATT_MAX_SR_ATTRIBUTES
2222
#define ESP_GATT_MAX_READ_MULTI_HANDLES 10 /* Max attributes to read in one request */
2323

2424

components/bt/host/bluedroid/api/include/api/esp_gatts_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatts_if,
351351
*/
352352
esp_err_t esp_ble_gatts_create_attr_tab(const esp_gatts_attr_db_t *gatts_attr_db,
353353
esp_gatt_if_t gatts_if,
354-
uint8_t max_nb_attr,
354+
uint16_t max_nb_attr,
355355
uint8_t srvc_inst_id);
356356
/**
357357
* @brief This function is called to add an included service. This function have to be called between

components/bt/host/bluedroid/btc/profile/std/gatt/btc_gatts.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
127127
break;
128128
}
129129
case BTC_GATTS_ACT_CREATE_ATTR_TAB: {
130-
uint8_t num_attr = src->create_attr_tab.max_nb_attr;
130+
uint16_t num_attr = src->create_attr_tab.max_nb_attr;
131131
if (src->create_attr_tab.gatts_attr_db && (num_attr > 0)) {
132132
dst->create_attr_tab.gatts_attr_db = (esp_gatts_attr_db_t *) osi_malloc(sizeof(esp_gatts_attr_db_t) * num_attr);
133133
if (dst->create_attr_tab.gatts_attr_db) {
@@ -217,7 +217,7 @@ void btc_gatts_arg_deep_free(btc_msg_t *msg)
217217

218218
static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
219219
esp_gatt_if_t gatts_if,
220-
uint8_t max_nb_attr,
220+
uint16_t max_nb_attr,
221221
uint8_t srvc_inst_id)
222222
{
223223
uint16_t uuid = 0;
@@ -568,24 +568,24 @@ static void btc_gatts_inter_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
568568
//save the service handle to the btc module after used
569569
//the attribute table method to creat a service
570570
bta_to_btc_uuid(&btc_creat_tab_env.svc_uuid, &p_data->create.uuid);
571-
uint8_t index = btc_creat_tab_env.handle_idx;
571+
uint16_t index = btc_creat_tab_env.handle_idx;
572572
btc_creat_tab_env.svc_start_hdl = p_data->create.service_id;
573573
btc_creat_tab_env.handles[index] = p_data->create.service_id;
574574
break;
575575
}
576576
case BTA_GATTS_ADD_INCL_SRVC_EVT: {
577-
uint8_t index = btc_creat_tab_env.handle_idx;
577+
uint16_t index = btc_creat_tab_env.handle_idx;
578578
btc_creat_tab_env.handles[index] = p_data->add_result.attr_id;
579579
break;
580580
}
581581
case BTA_GATTS_ADD_CHAR_EVT: {
582-
uint8_t index = btc_creat_tab_env.handle_idx;
582+
uint16_t index = btc_creat_tab_env.handle_idx;
583583
btc_creat_tab_env.handles[index] = p_data->add_result.attr_id - 1;
584584
btc_creat_tab_env.handles[index+1] = p_data->add_result.attr_id;
585585
break;
586586
}
587587
case BTA_GATTS_ADD_CHAR_DESCR_EVT: {
588-
uint8_t index = btc_creat_tab_env.handle_idx;
588+
uint16_t index = btc_creat_tab_env.handle_idx;
589589
btc_creat_tab_env.handles[index] = p_data->add_result.attr_id;
590590
break;
591591
}

components/bt/host/bluedroid/btc/profile/std/include/btc_gatts.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ typedef union {
5555
struct create_attr_tab_args{
5656
esp_gatt_if_t gatts_if;
5757
uint8_t srvc_inst_id;
58-
uint8_t max_nb_attr;
58+
uint16_t max_nb_attr;
5959
esp_gatts_attr_db_t *gatts_attr_db;
6060
}create_attr_tab;
6161

@@ -149,8 +149,8 @@ typedef struct {
149149
esp_bt_uuid_t svc_uuid;
150150
bool is_tab_creat_svc;
151151
bool is_use_svc;
152-
uint8_t num_handle;
153-
uint8_t handle_idx;
152+
uint16_t num_handle;
153+
uint16_t handle_idx;
154154
uint16_t handles[ESP_GATT_ATTR_HANDLE_MAX];
155155
} esp_btc_creat_tab_t;
156156

components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@
258258
#define UC_CONFIG_BT_GATT_MAX_SR_PROFILES 8
259259
#endif
260260

261+
#ifdef CONFIG_BT_GATT_MAX_SR_ATTRIBUTES
262+
#define UC_CONFIG_BT_GATT_MAX_SR_ATTRIBUTES CONFIG_BT_GATT_MAX_SR_ATTRIBUTES
263+
#else
264+
#define UC_CONFIG_BT_GATT_MAX_SR_ATTRIBUTES 100
265+
#endif
261266

262267
#ifdef CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE
263268
#define UC_BT_GATTS_SEND_SERVICE_CHANGE_MODE CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE

0 commit comments

Comments
 (0)