mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
bluedroid: support get bluetooth device name
This commit is contained in:
parent
527a23d63f
commit
564c4b644d
@ -390,6 +390,19 @@ esp_err_t esp_ble_gap_set_device_name(const char *name)
|
||||
return esp_bt_dev_set_device_name(name);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gap_get_device_name(void)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_GET_DEV_NAME;
|
||||
|
||||
return (btc_transfer_context(&msg, NULL, 0, NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gap_get_local_used_addr(esp_bd_addr_t local_used_addr, uint8_t * addr_type)
|
||||
{
|
||||
if(esp_bluedroid_get_status() != (ESP_BLUEDROID_STATUS_ENABLED)) {
|
||||
|
@ -167,6 +167,7 @@ typedef enum {
|
||||
ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT, /*!< When adding or removing whitelist complete, the event comes */
|
||||
ESP_GAP_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_COMPLETE_EVT, /*!< When updating duplicate exceptional list complete, the event comes */
|
||||
ESP_GAP_BLE_SET_CHANNELS_EVT, /*!< When setting BLE channels complete, the event comes */
|
||||
ESP_GAP_BLE_GET_DEV_NAME_COMPLETE_EVT, /*!< When getting BT device name complete, the event comes */
|
||||
ESP_GAP_BLE_EVT_MAX,
|
||||
} esp_gap_ble_cb_event_t;
|
||||
|
||||
@ -636,6 +637,13 @@ typedef uint8_t esp_duplicate_info_t[ESP_BD_ADDR_LEN];
|
||||
* @brief Gap callback parameters union
|
||||
*/
|
||||
typedef union {
|
||||
/**
|
||||
* @brief ESP_GAP_BLE_GET_DEV_NAME_COMPLETE_EVT
|
||||
*/
|
||||
struct ble_get_dev_name_cmpl_evt_param {
|
||||
esp_bt_status_t status; /*!< Indicate the get device name success status */
|
||||
char *name; /*!< Name of bluetooth device */
|
||||
} get_dev_name_cmpl; /*!< Event parameter of ESP_GAP_BLE_GET_DEV_NAME_COMPLETE_EVT */
|
||||
/**
|
||||
* @brief ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT
|
||||
*/
|
||||
@ -1033,7 +1041,17 @@ esp_err_t esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr,
|
||||
esp_err_t esp_ble_gap_set_device_name(const char *name);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get local used address and adress type.
|
||||
* @brief Get device name of the local device
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_get_device_name(void);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get local used address and address type.
|
||||
* uint8_t *esp_bt_dev_get_address(void) get the public address
|
||||
*
|
||||
* @param[in] local_used_addr - current local used ble address (six bytes)
|
||||
|
@ -666,6 +666,27 @@ void bta_dm_set_dev_name (tBTA_DM_MSG *p_data)
|
||||
#endif /// CLASSIC_BT_INCLUDED
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function bta_dm_get_dev_name
|
||||
**
|
||||
** Description Gets local device name
|
||||
**
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
void bta_dm_get_dev_name (tBTA_DM_MSG *p_data)
|
||||
{
|
||||
tBTM_STATUS status;
|
||||
char *name = NULL;
|
||||
|
||||
status = BTM_ReadLocalDeviceName(&name);
|
||||
if (p_data->get_name.p_cback) {
|
||||
(*p_data->get_name.p_cback)(status, name);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function bta_dm_set_afh_channels
|
||||
|
@ -181,6 +181,27 @@ void BTA_DmSetDeviceName(const char *p_name)
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTA_DmGetDeviceName
|
||||
**
|
||||
** Description This function gets the Bluetooth name of local device
|
||||
**
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
void BTA_DmGetDeviceName(tBTA_GET_DEV_NAME_CBACK *p_cback)
|
||||
{
|
||||
tBTA_DM_API_GET_NAME *p_msg;
|
||||
|
||||
if ((p_msg = (tBTA_DM_API_GET_NAME *) osi_malloc(sizeof(tBTA_DM_API_GET_NAME))) != NULL) {
|
||||
p_msg->hdr.event = BTA_DM_API_GET_NAME_EVT;
|
||||
p_msg->p_cback = p_cback;
|
||||
bta_sys_sendmsg(p_msg);
|
||||
}
|
||||
}
|
||||
|
||||
void BTA_DmConfigEir(tBTA_DM_EIR_CONF *eir_config)
|
||||
{
|
||||
tBTA_DM_API_CONFIG_EIR *p_msg;
|
||||
|
@ -57,6 +57,7 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
|
||||
bta_dm_enable, /* BTA_DM_API_ENABLE_EVT */
|
||||
bta_dm_disable, /* BTA_DM_API_DISABLE_EVT */
|
||||
bta_dm_set_dev_name, /* BTA_DM_API_SET_NAME_EVT */
|
||||
bta_dm_get_dev_name, /* BTA_DM_API_GET_NAME_EVT */
|
||||
bta_dm_config_eir, /* BTA_DM_API_CONFIG_EIR_EVT */
|
||||
bta_dm_set_afh_channels, /* BTA_DM_API_SET_AFH_CHANNELS_EVT */
|
||||
#if (SDP_INCLUDED == TRUE)
|
||||
|
@ -52,6 +52,7 @@ enum {
|
||||
BTA_DM_API_ENABLE_EVT = BTA_SYS_EVT_START(BTA_ID_DM),
|
||||
BTA_DM_API_DISABLE_EVT,
|
||||
BTA_DM_API_SET_NAME_EVT,
|
||||
BTA_DM_API_GET_NAME_EVT,
|
||||
BTA_DM_API_CONFIG_EIR_EVT,
|
||||
BTA_DM_API_SET_AFH_CHANNELS_EVT,
|
||||
#if (SDP_INCLUDED == TRUE)
|
||||
@ -201,6 +202,11 @@ typedef struct {
|
||||
BD_NAME name; /* max 248 bytes name, plus must be Null terminated */
|
||||
} tBTA_DM_API_SET_NAME;
|
||||
|
||||
typedef struct {
|
||||
BT_HDR hdr;
|
||||
tBTA_GET_DEV_NAME_CBACK *p_cback;
|
||||
} tBTA_DM_API_GET_NAME;
|
||||
|
||||
/* data type for BTA_DM_API_CONFIG_EIR_EVT */
|
||||
typedef struct {
|
||||
BT_HDR hdr;
|
||||
@ -848,6 +854,7 @@ typedef union {
|
||||
tBTA_DM_API_ENABLE enable;
|
||||
|
||||
tBTA_DM_API_SET_NAME set_name;
|
||||
tBTA_DM_API_GET_NAME get_name;
|
||||
tBTA_DM_API_CONFIG_EIR config_eir;
|
||||
|
||||
tBTA_DM_API_SET_AFH_CHANNELS set_afh_channels;
|
||||
@ -1318,6 +1325,7 @@ extern void bta_dm_search_sm_disable( void );
|
||||
extern void bta_dm_enable (tBTA_DM_MSG *p_data);
|
||||
extern void bta_dm_disable (tBTA_DM_MSG *p_data);
|
||||
extern void bta_dm_set_dev_name (tBTA_DM_MSG *p_data);
|
||||
extern void bta_dm_get_dev_name (tBTA_DM_MSG *p_data);
|
||||
extern void bta_dm_config_eir (tBTA_DM_MSG *p_data);
|
||||
extern void bta_dm_set_afh_channels (tBTA_DM_MSG *p_data);
|
||||
extern void bta_dm_read_rmt_name(tBTA_DM_MSG *p_data);
|
||||
|
@ -176,6 +176,8 @@ typedef struct {
|
||||
|
||||
typedef UINT16 tBTA_SEC;
|
||||
|
||||
typedef tBTM_GET_DEV_NAME_CBACK tBTA_GET_DEV_NAME_CBACK;
|
||||
|
||||
/* Ignore for Discoverable, Connectable, Pairable and Connectable Paired only device modes */
|
||||
#define BTA_DM_IGNORE 0x00FF
|
||||
|
||||
@ -1474,6 +1476,18 @@ extern void BTA_DisableTestMode(void);
|
||||
*******************************************************************************/
|
||||
extern void BTA_DmSetDeviceName(const char *p_name);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTA_DmGetDeviceName
|
||||
**
|
||||
** Description This function gets the Bluetooth name of the local device.
|
||||
**
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
extern void BTA_DmGetDeviceName(tBTA_GET_DEV_NAME_CBACK *p_cback);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTA_DmGetRemoteName
|
||||
|
@ -54,6 +54,32 @@ static inline void btc_gap_ble_cb_to_app(esp_gap_ble_cb_event_t event, esp_ble_g
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_gap_ble_get_dev_name_callback(UINT8 status, char *name)
|
||||
{
|
||||
esp_ble_gap_cb_param_t param;
|
||||
bt_status_t ret;
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
memset(¶m, 0, sizeof(esp_ble_gap_cb_param_t));
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = ESP_GAP_BLE_GET_DEV_NAME_COMPLETE_EVT;
|
||||
|
||||
param.get_dev_name_cmpl.status = btc_btm_status_to_esp_status(status);
|
||||
param.get_dev_name_cmpl.name = (char *)osi_malloc(BTC_MAX_LOC_BD_NAME_LEN + 1);
|
||||
if (param.get_dev_name_cmpl.name) {
|
||||
BCM_STRNCPY_S(param.get_dev_name_cmpl.name, name, BTC_MAX_LOC_BD_NAME_LEN + 1);
|
||||
} else {
|
||||
param.get_dev_name_cmpl.status = ESP_BT_STATUS_NOMEM;
|
||||
}
|
||||
|
||||
ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL);
|
||||
if (ret != BT_STATUS_SUCCESS) {
|
||||
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_gap_adv_point_cleanup(void **buf)
|
||||
{
|
||||
if (NULL == *buf) {
|
||||
@ -1096,6 +1122,13 @@ void btc_gap_ble_cb_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
BTC_TRACE_DEBUG("%s", __func__);
|
||||
switch (msg->act) {
|
||||
case ESP_GAP_BLE_GET_DEV_NAME_COMPLETE_EVT: {
|
||||
char *value = ((esp_ble_gap_cb_param_t *)msg->arg)->get_dev_name_cmpl.name;
|
||||
if (value) {
|
||||
osi_free(value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BTC_TRACE_DEBUG("Unhandled deep free %d", msg->act);
|
||||
break;
|
||||
@ -1175,6 +1208,9 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
|
||||
case BTC_GAP_BLE_ACT_SET_DEV_NAME:
|
||||
BTA_DmSetDeviceName(arg->set_dev_name.device_name);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_GET_DEV_NAME:
|
||||
BTA_DmGetDeviceName(btc_gap_ble_get_dev_name_callback);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW:
|
||||
btc_ble_set_adv_data_raw(arg->cfg_adv_data_raw.raw_adv,
|
||||
arg->cfg_adv_data_raw.raw_adv_len,
|
||||
|
@ -58,6 +58,7 @@ typedef enum {
|
||||
BTC_GAP_BLE_OOB_REQ_REPLY_EVT,
|
||||
BTC_GAP_BLE_UPDATE_DUPLICATE_SCAN_EXCEPTIONAL_LIST,
|
||||
BTC_GAP_BLE_SET_AFH_CHANNELS,
|
||||
BTC_GAP_BLE_ACT_GET_DEV_NAME,
|
||||
} btc_gap_ble_act_t;
|
||||
|
||||
/* btc_ble_gap_args_t */
|
||||
|
@ -788,6 +788,7 @@
|
||||
'0' disables storage of the local name in BTM */
|
||||
#ifndef BTM_MAX_LOC_BD_NAME_LEN
|
||||
#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
|
||||
|
@ -156,6 +156,7 @@ typedef enum{
|
||||
|
||||
typedef void (tBTM_DEV_STATUS_CB) (tBTM_DEV_STATUS status);
|
||||
|
||||
typedef void (tBTM_GET_DEV_NAME_CBACK) (UINT8 status, char *name);
|
||||
|
||||
/* Callback function for when a vendor specific event occurs. The length and
|
||||
** array of returned parameter bytes are included. This asynchronous event
|
||||
|
Loading…
Reference in New Issue
Block a user