Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_gatt_svc_attrs_count' into 'master'
Browse files Browse the repository at this point in the history
Bluedroid: Configurable option to modify max gatt service attributes count

Closes IDFGH-7861

See merge request espressif/esp-idf!19313
  • Loading branch information
esp-cjh committed Aug 18, 2022
2 parents cda6360 + e29170b commit e2d488c
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
7 changes: 7 additions & 0 deletions components/bt/host/bluedroid/Kconfig.in
Expand Up @@ -173,6 +173,13 @@ config BT_GATT_MAX_SR_PROFILES
help
Maximum GATT Server Profiles Count

config BT_GATT_MAX_SR_ATTRIBUTES
int "Max GATT Service Attributes"
depends on BT_GATTS_ENABLE && BT_BLUEDROID_ENABLED
range 1 500
default 100
help
Maximum GATT Service Attributes Count


choice BT_GATTS_SEND_SERVICE_CHANGE_MODE
Expand Down
7 changes: 6 additions & 1 deletion components/bt/host/bluedroid/api/esp_gatts_api.c
Expand Up @@ -85,14 +85,19 @@ esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatts_if,

esp_err_t esp_ble_gatts_create_attr_tab(const esp_gatts_attr_db_t *gatts_attr_db,
esp_gatt_if_t gatts_if,
uint8_t max_nb_attr,
uint16_t max_nb_attr,
uint8_t srvc_inst_id)
{
btc_msg_t msg = {0};
btc_ble_gatts_args_t arg;

ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);

if (max_nb_attr > ESP_GATT_ATTR_HANDLE_MAX) {
LOG_ERROR("%s the number of attribute should not be greater than CONFIG_BT_GATT_MAX_SR_ATTRIBUTES\n");
return ESP_ERR_INVALID_ARG;
}

msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_CREATE_ATTR_TAB;
Expand Down
Expand Up @@ -18,7 +18,7 @@ extern "C" {
/// GATT INVALID HANDLE
#define ESP_GATT_ILLEGAL_HANDLE 0
/// GATT attribute max handle
#define ESP_GATT_ATTR_HANDLE_MAX 100
#define ESP_GATT_ATTR_HANDLE_MAX UC_CONFIG_BT_GATT_MAX_SR_ATTRIBUTES
#define ESP_GATT_MAX_READ_MULTI_HANDLES 10 /* Max attributes to read in one request */


Expand Down
Expand Up @@ -351,7 +351,7 @@ esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatts_if,
*/
esp_err_t esp_ble_gatts_create_attr_tab(const esp_gatts_attr_db_t *gatts_attr_db,
esp_gatt_if_t gatts_if,
uint8_t max_nb_attr,
uint16_t max_nb_attr,
uint8_t srvc_inst_id);
/**
* @brief This function is called to add an included service. This function have to be called between
Expand Down
12 changes: 6 additions & 6 deletions components/bt/host/bluedroid/btc/profile/std/gatt/btc_gatts.c
Expand Up @@ -127,7 +127,7 @@ void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
break;
}
case BTC_GATTS_ACT_CREATE_ATTR_TAB: {
uint8_t num_attr = src->create_attr_tab.max_nb_attr;
uint16_t num_attr = src->create_attr_tab.max_nb_attr;
if (src->create_attr_tab.gatts_attr_db && (num_attr > 0)) {
dst->create_attr_tab.gatts_attr_db = (esp_gatts_attr_db_t *) osi_malloc(sizeof(esp_gatts_attr_db_t) * num_attr);
if (dst->create_attr_tab.gatts_attr_db) {
Expand Down Expand Up @@ -217,7 +217,7 @@ void btc_gatts_arg_deep_free(btc_msg_t *msg)

static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
esp_gatt_if_t gatts_if,
uint8_t max_nb_attr,
uint16_t max_nb_attr,
uint8_t srvc_inst_id)
{
uint16_t uuid = 0;
Expand Down Expand Up @@ -568,24 +568,24 @@ static void btc_gatts_inter_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
//save the service handle to the btc module after used
//the attribute table method to creat a service
bta_to_btc_uuid(&btc_creat_tab_env.svc_uuid, &p_data->create.uuid);
uint8_t index = btc_creat_tab_env.handle_idx;
uint16_t index = btc_creat_tab_env.handle_idx;
btc_creat_tab_env.svc_start_hdl = p_data->create.service_id;
btc_creat_tab_env.handles[index] = p_data->create.service_id;
break;
}
case BTA_GATTS_ADD_INCL_SRVC_EVT: {
uint8_t index = btc_creat_tab_env.handle_idx;
uint16_t index = btc_creat_tab_env.handle_idx;
btc_creat_tab_env.handles[index] = p_data->add_result.attr_id;
break;
}
case BTA_GATTS_ADD_CHAR_EVT: {
uint8_t index = btc_creat_tab_env.handle_idx;
uint16_t index = btc_creat_tab_env.handle_idx;
btc_creat_tab_env.handles[index] = p_data->add_result.attr_id - 1;
btc_creat_tab_env.handles[index+1] = p_data->add_result.attr_id;
break;
}
case BTA_GATTS_ADD_CHAR_DESCR_EVT: {
uint8_t index = btc_creat_tab_env.handle_idx;
uint16_t index = btc_creat_tab_env.handle_idx;
btc_creat_tab_env.handles[index] = p_data->add_result.attr_id;
break;
}
Expand Down
Expand Up @@ -55,7 +55,7 @@ typedef union {
struct create_attr_tab_args{
esp_gatt_if_t gatts_if;
uint8_t srvc_inst_id;
uint8_t max_nb_attr;
uint16_t max_nb_attr;
esp_gatts_attr_db_t *gatts_attr_db;
}create_attr_tab;

Expand Down Expand Up @@ -149,8 +149,8 @@ typedef struct {
esp_bt_uuid_t svc_uuid;
bool is_tab_creat_svc;
bool is_use_svc;
uint8_t num_handle;
uint8_t handle_idx;
uint16_t num_handle;
uint16_t handle_idx;
uint16_t handles[ESP_GATT_ATTR_HANDLE_MAX];
} esp_btc_creat_tab_t;

Expand Down
Expand Up @@ -258,6 +258,11 @@
#define UC_CONFIG_BT_GATT_MAX_SR_PROFILES 8
#endif

#ifdef CONFIG_BT_GATT_MAX_SR_ATTRIBUTES
#define UC_CONFIG_BT_GATT_MAX_SR_ATTRIBUTES CONFIG_BT_GATT_MAX_SR_ATTRIBUTES
#else
#define UC_CONFIG_BT_GATT_MAX_SR_ATTRIBUTES 100
#endif

#ifdef CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE
#define UC_BT_GATTS_SEND_SERVICE_CHANGE_MODE CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE
Expand Down

0 comments on commit e2d488c

Please sign in to comment.