Skip to content

Commit

Permalink
Merge branch 'feature/config_device_name_in_eir_v5.1' into 'release/v…
Browse files Browse the repository at this point in the history
…5.1'

feat(bt/bluedroid): Add option whether to include device name in extended inquiry response

See merge request espressif/esp-idf!25541
  • Loading branch information
wmy-espressif committed Aug 28, 2023
2 parents 261af82 + 6340713 commit 09954c1
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
Expand Up @@ -106,6 +106,7 @@ typedef struct {
bool fec_required; /*!< FEC is required or not, true by default */
bool include_txpower; /*!< EIR data include TX power, false by default */
bool include_uuid; /*!< EIR data include UUID, false by default */
bool include_name; /*!< EIR data include device name, true by default */
uint8_t flag; /*!< EIR flags, see ESP_BT_EIR_FLAG for details, EIR will not include flag if it is 0, 0 by default */
uint16_t manufacturer_len; /*!< Manufacturer data length, 0 by default */
uint8_t *p_manufacturer_data; /*!< Manufacturer data point */
Expand Down
25 changes: 16 additions & 9 deletions components/bt/host/bluedroid/bta/dm/bta_dm_act.c
Expand Up @@ -788,6 +788,7 @@ void bta_dm_config_eir (tBTA_DM_MSG *p_data)
tBTA_DM_API_CONFIG_EIR *config_eir = &p_data->config_eir;

p_bta_dm_eir_cfg->bta_dm_eir_fec_required = config_eir->eir_fec_required;
p_bta_dm_eir_cfg->bta_dm_eir_included_name = config_eir->eir_included_name;
p_bta_dm_eir_cfg->bta_dm_eir_included_uuid = config_eir->eir_included_uuid;
p_bta_dm_eir_cfg->bta_dm_eir_included_tx_power = config_eir->eir_included_tx_power;
p_bta_dm_eir_cfg->bta_dm_eir_flags = config_eir->eir_flags;
Expand Down Expand Up @@ -4039,14 +4040,19 @@ static void bta_dm_set_eir (char *local_name)
}
return;
}
#endif // BTA_EIR_CANNED_UUID_LIST

/* if local name is not provided, get it from controller */
if ( local_name == NULL ) {
if ( BTM_ReadLocalDeviceName( &local_name ) != BTM_SUCCESS ) {
APPL_TRACE_ERROR("Fail to read local device name for EIR");
if (p_bta_dm_eir_cfg->bta_dm_eir_included_name) {
/* if local name is not provided, get it from controller */
if ( local_name == NULL ) {
if ( BTM_ReadLocalDeviceName( &local_name ) != BTM_SUCCESS ) {
APPL_TRACE_ERROR("Fail to read local device name for EIR");
}
}
} else {
local_name = NULL;
}
#endif // BTA_EIR_CANNED_UUID_LIST


/* Allocate a buffer to hold HCI command */
if ((p_buf = (BT_HDR *)osi_malloc(BTM_CMD_BUF_SIZE)) == NULL) {
Expand Down Expand Up @@ -4092,15 +4098,16 @@ static void bta_dm_set_eir (char *local_name)
}
}

UINT8_TO_STREAM(p, local_name_len + 1);
UINT8_TO_STREAM(p, data_type);
eir_type[eir_type_num++] = data_type;


if (local_name != NULL) {
UINT8_TO_STREAM(p, local_name_len + 1);
UINT8_TO_STREAM(p, data_type);
eir_type[eir_type_num++] = data_type;
memcpy(p, local_name, local_name_len);
p += local_name_len;
free_eir_length -= local_name_len + 2;
}
free_eir_length -= local_name_len + 2;

/* if UUIDs are provided in configuration */
if (p_bta_dm_eir_cfg->bta_dm_eir_included_uuid) {
Expand Down
1 change: 1 addition & 0 deletions components/bt/host/bluedroid/bta/dm/bta_dm_api.c
Expand Up @@ -226,6 +226,7 @@ void BTA_DmConfigEir(tBTA_DM_EIR_CONF *eir_config)
p_msg->hdr.event = BTA_DM_API_CONFIG_EIR_EVT;

p_msg->eir_fec_required = eir_config->bta_dm_eir_fec_required;
p_msg->eir_included_name = eir_config->bta_dm_eir_included_name;
p_msg->eir_included_tx_power = eir_config->bta_dm_eir_included_tx_power;
p_msg->eir_included_uuid = eir_config->bta_dm_eir_included_uuid;
p_msg->eir_flags = eir_config->bta_dm_eir_flags;
Expand Down
1 change: 1 addition & 0 deletions components/bt/host/bluedroid/bta/dm/bta_dm_cfg.c
Expand Up @@ -454,6 +454,7 @@ const UINT8 bta_dm_eir_uuid16_list[] = { 0x08, 0x11, /* Headset */
/* Extended Inquiry Response */
tBTA_DM_EIR_CONF bta_dm_eir_cfg = {
BTM_EIR_DEFAULT_FEC_REQUIRED, /* FEC required */
TRUE, /* Included local name */
50, /* minimum length of local name when it is shortened */
/* if length of local name is longer than this and EIR has not enough */
/* room for all UUID list then local name is shortened to this length */
Expand Down
1 change: 1 addition & 0 deletions components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h
Expand Up @@ -240,6 +240,7 @@ typedef struct {
typedef struct {
BT_HDR hdr;
BOOLEAN eir_fec_required;
BOOLEAN eir_included_name;
BOOLEAN eir_included_tx_power;
BOOLEAN eir_included_uuid;
UINT8 eir_flags;
Expand Down
1 change: 1 addition & 0 deletions components/bt/host/bluedroid/bta/include/bta/bta_api.h
Expand Up @@ -303,6 +303,7 @@ typedef void (tBTA_DM_CONFIG_EIR_CBACK) (tBTA_STATUS status, UINT8 eir_type_num,

typedef struct {
BOOLEAN bta_dm_eir_fec_required; /* FEC required */
BOOLEAN bta_dm_eir_included_name; /* Included device name or not */
UINT8 bta_dm_eir_min_name_len; /* minimum length of local name when it is shortened */

BOOLEAN bta_dm_eir_included_uuid; /* Included UUIDs or not */
Expand Down
Expand Up @@ -689,6 +689,7 @@ static void btc_gap_bt_config_eir(btc_gap_bt_args_t *arg)
esp_bt_eir_data_t *eir_data = &arg->config_eir.eir_data;

eir_config.bta_dm_eir_fec_required = eir_data->fec_required;
eir_config.bta_dm_eir_included_name = eir_data->include_name;
eir_config.bta_dm_eir_included_tx_power = eir_data->include_txpower;
eir_config.bta_dm_eir_included_uuid = eir_data->include_uuid;
eir_config.bta_dm_eir_flags = eir_data->flag;
Expand Down

0 comments on commit 09954c1

Please sign in to comment.