diff --git a/components/bt/host/bluedroid/Kconfig.in b/components/bt/host/bluedroid/Kconfig.in index 5c0b84c829..dd65fdca3e 100644 --- a/components/bt/host/bluedroid/Kconfig.in +++ b/components/bt/host/bluedroid/Kconfig.in @@ -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 diff --git a/components/bt/host/bluedroid/api/esp_gatts_api.c b/components/bt/host/bluedroid/api/esp_gatts_api.c index 881aec7fe7..cbeabf6485 100644 --- a/components/bt/host/bluedroid/api/esp_gatts_api.c +++ b/components/bt/host/bluedroid/api/esp_gatts_api.c @@ -85,7 +85,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) { btc_msg_t msg = {0}; @@ -93,6 +93,11 @@ esp_err_t esp_ble_gatts_create_attr_tab(const esp_gatts_attr_db_t *gatts_attr_db 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; diff --git a/components/bt/host/bluedroid/api/include/api/esp_gatt_defs.h b/components/bt/host/bluedroid/api/include/api/esp_gatt_defs.h index bf9546feba..3e5a9c190f 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gatt_defs.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gatt_defs.h @@ -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 */ diff --git a/components/bt/host/bluedroid/api/include/api/esp_gatts_api.h b/components/bt/host/bluedroid/api/include/api/esp_gatts_api.h index 6215f57f7e..ae1a0245b8 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gatts_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gatts_api.h @@ -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 diff --git a/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gatts.c b/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gatts.c index 4f49c8872e..dacf03c92a 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gatts.c +++ b/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gatts.c @@ -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) { @@ -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; @@ -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; } diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_gatts.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_gatts.h index 35a09a5fdd..866495646c 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_gatts.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_gatts.h @@ -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; @@ -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; 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 e6aae09935..6cafa6e41e 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 @@ -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