component/bt: Modify the bluetooth device name length limits

This commit is contained in:
XieWenxiang 2021-09-11 07:31:10 +08:00 committed by xiewenxiang
parent 5a26d7008d
commit 1ea757c0f1
6 changed files with 51 additions and 4 deletions

View File

@ -1026,6 +1026,16 @@ config BT_BLE_ESTAB_LINK_CONN_TOUT
Bluetooth Connection establishment maximum time, if connection time exceeds this value, the connection
establishment fails, ESP_GATTC_OPEN_EVT or ESP_GATTS_OPEN_EVT is triggered.
config BT_MAX_DEVICE_NAME_LEN
int "length of bluetooth device name"
depends on BT_BLUEDROID_ENABLED
range 32 248
default 32
help
Bluetooth Device name length shall be no larger than 248 octets, If the broadcast data cannot contain
the complete device name, then only the shortname will be displayed, the rest parts that can't fit in
will be truncated.
config BT_BLE_RPA_SUPPORTED
bool "Update RPA to Controller"
depends on BT_BLUEDROID_ENABLED

View File

@ -39,13 +39,18 @@ esp_err_t esp_bt_dev_set_device_name(const char *name)
if (!name){
return ESP_ERR_INVALID_ARG;
}
if (strlen(name) > ESP_DEV_DEVICE_NAME_MAX) {
if (strlen(name) > BTC_MAX_LOC_BD_NAME_LEN) {
return ESP_ERR_INVALID_ARG;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_DEV;
msg.act = BTC_DEV_ACT_SET_DEVICE_NAME;
arg.set_dev_name.device_name = (char *)malloc((BTC_MAX_LOC_BD_NAME_LEN + 1) * sizeof(char));
if (!arg.set_dev_name.device_name) {
return ESP_ERR_NO_MEM;
}
strcpy(arg.set_dev_name.device_name, name);
return (btc_transfer_context(&msg, &arg, sizeof(btc_dev_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);

View File

@ -13,11 +13,30 @@
// limitations under the License.
#include <string.h>
#include "osi/allocator.h"
#include "bta/bta_api.h"
#include "btc/btc_task.h"
#include "btc/btc_manage.h"
#include "btc/btc_dev.h"
void btc_dev_arg_deep_free(btc_msg_t *msg)
{
BTC_TRACE_DEBUG("%s \n", __func__);
switch (msg->act) {
case BTC_DEV_ACT_SET_DEVICE_NAME:{
char *device_name = ((btc_dev_args_t *)msg->arg)->set_dev_name.device_name;
if (device_name) {
osi_free(device_name);
}
break;
}
default:
BTC_TRACE_DEBUG("Unhandled deep free %d\n", msg->act);
break;
}
}
void btc_dev_call_handler(btc_msg_t *msg)
{
btc_dev_args_t *arg = (btc_dev_args_t *)msg->arg;
@ -31,4 +50,6 @@ void btc_dev_call_handler(btc_msg_t *msg)
default:
break;
}
btc_dev_arg_deep_free(msg);
}

View File

@ -27,8 +27,7 @@ typedef enum {
typedef union {
// BTC_BT_GAP_ACT_SET_DEV_NAME
struct set_bt_dev_name_args {
#define ESP_DEV_DEVICE_NAME_MAX (32)
char device_name[ESP_DEV_DEVICE_NAME_MAX + 1];
char *device_name;
} set_dev_name;
} btc_dev_args_t;

View File

@ -149,6 +149,14 @@
#endif
#if CONFIG_BT_CTRL_ESP32
//Device Nane Maximum Length
#ifdef CONFIG_BT_MAX_DEVICE_NAME_LEN
#define UC_MAX_LOC_BD_NAME_LEN CONFIG_BT_MAX_DEVICE_NAME_LEN
#else
#define UC_MAX_LOC_BD_NAME_LEN 64
#endif
//BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP
#ifdef CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP
#define UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP

View File

@ -827,8 +827,12 @@
/* Maximum local device name length stored btm database.
'0' disables storage of the local name in BTM */
#ifndef BTM_MAX_LOC_BD_NAME_LEN
#if UC_MAX_LOC_BD_NAME_LEN
#define BTM_MAX_LOC_BD_NAME_LEN UC_MAX_LOC_BD_NAME_LEN
#define BTC_MAX_LOC_BD_NAME_LEN BTM_MAX_LOC_BD_NAME_LEN
#else
#define BTM_MAX_LOC_BD_NAME_LEN 64
#define BTC_MAX_LOC_BD_NAME_LEN BTM_MAX_LOC_BD_NAME_LEN
#endif
/* Fixed Default String. When this is defined as null string, the device's