mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
component bt:debug the scan result and add the resove adv data method to the gapapi
This commit is contained in:
parent
645717b147
commit
2f7288ff03
@ -173,3 +173,35 @@ esp_err_t esp_ble_gap_set_device_name(char *name)
|
|||||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
** Function esp_ble_resolve_adv_data
|
||||||
|
**
|
||||||
|
** Description This function is called to get ADV data for a specific type.
|
||||||
|
**
|
||||||
|
** Parameters p_adv - pointer of ADV data
|
||||||
|
** type - finding ADV data type
|
||||||
|
** p_length - return the length of ADV data not including type
|
||||||
|
**
|
||||||
|
** Returns pointer of ADV data
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
uint8_t *esp_ble_resolve_adv_data( uint8_t *p_adv, uint8_t type, uint8_t *p_length )
|
||||||
|
{
|
||||||
|
if ((type < ESP_BLE_AD_TYPE_FLAG) || (type > ESP_BLE_AD_TYPE_128SERVICE_DATA) ||
|
||||||
|
(type != ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE))
|
||||||
|
{
|
||||||
|
LOG_ERROR("the eir type not define, type = %x\n", type);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_adv == NULL)
|
||||||
|
{
|
||||||
|
LOG_ERROR("Invalid p_eir data.\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (BTM_CheckAdvData( p_adv, type, p_length));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,34 @@
|
|||||||
#define ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT 2
|
#define ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT 2
|
||||||
#define ESP_GAP_BLE_SCAN_RESULT_EVT 3
|
#define ESP_GAP_BLE_SCAN_RESULT_EVT 3
|
||||||
|
|
||||||
|
/****************** define the adv type macro***************************************/
|
||||||
|
#define ESP_BLE_AD_TYPE_FLAG 0x01
|
||||||
|
#define ESP_BLE_AD_TYPE_16SRV_PART 0x02
|
||||||
|
#define ESP_BLE_AD_TYPE_16SRV_CMPL 0x03
|
||||||
|
#define ESP_BLE_AD_TYPE_32SRV_PART 0x04
|
||||||
|
#define ESP_BLE_AD_TYPE_32SRV_CMPL 0x05
|
||||||
|
#define ESP_BLE_AD_TYPE_128SRV_PART 0x06
|
||||||
|
#define ESP_BLE_AD_TYPE_128SRV_CMPL 0x07
|
||||||
|
#define ESP_BLE_AD_TYPE_NAME_SHORT 0x08
|
||||||
|
#define ESP_BLE_AD_TYPE_NAME_CMPL 0x09
|
||||||
|
#define ESP_BLE_AD_TYPE_TX_PWR 0x0A
|
||||||
|
#define ESP_BLE_AD_TYPE_DEV_CLASS 0x0D
|
||||||
|
#define ESP_BLE_AD_TYPE_SM_TK 0x10
|
||||||
|
#define ESP_BLE_AD_TYPE_SM_OOB_FLAG 0x11
|
||||||
|
#define ESP_BLE_AD_TYPE_INT_RANGE 0x12
|
||||||
|
#define ESP_BLE_AD_TYPE_SOL_SRV_UUID 0x14
|
||||||
|
#define ESP_BLE_AD_TYPE_128SOL_SRV_UUID 0x15
|
||||||
|
#define ESP_BLE_AD_TYPE_SERVICE_DATA 0x16
|
||||||
|
#define ESP_BLE_AD_TYPE_PUBLIC_TARGET 0x17
|
||||||
|
#define ESP_BLE_AD_TYPE_RANDOM_TARGET 0x18
|
||||||
|
#define ESP_BLE_AD_TYPE_APPEARANCE 0x19
|
||||||
|
#define ESP_BLE_AD_TYPE_ADV_INT 0x1A
|
||||||
|
#define ESP_BLE_AD_TYPE_32SOL_SRV_UUID 0x1B
|
||||||
|
#define ESP_BLE_AD_TYPE_32SERVICE_DATA 0x1C
|
||||||
|
#define ESP_BLE_AD_TYPE_128SERVICE_DATA 0x1D
|
||||||
|
#define ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE 0xFF
|
||||||
|
|
||||||
|
|
||||||
typedef uint32_t esp_gap_ble_event_t;
|
typedef uint32_t esp_gap_ble_event_t;
|
||||||
|
|
||||||
/// Advertising mode
|
/// Advertising mode
|
||||||
@ -169,6 +197,7 @@ typedef union {
|
|||||||
esp_bt_dev_type_t dev_type;
|
esp_bt_dev_type_t dev_type;
|
||||||
esp_ble_addr_type_t ble_addr_type;
|
esp_ble_addr_type_t ble_addr_type;
|
||||||
int rssi;
|
int rssi;
|
||||||
|
uint8_t *p_eir; /* received EIR */
|
||||||
int flag;
|
int flag;
|
||||||
int num_resps;
|
int num_resps;
|
||||||
} scan_rst;
|
} scan_rst;
|
||||||
@ -337,4 +366,20 @@ esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable);
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
esp_err_t esp_ble_gap_set_device_name(char *name);
|
esp_err_t esp_ble_gap_set_device_name(char *name);
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
** @function esp_ble_resolve_adv_data
|
||||||
|
**
|
||||||
|
** @brief This function is called to get ADV data for a specific type.
|
||||||
|
**
|
||||||
|
** @param[in] p_adv - pointer of ADV data whitch to be resolved
|
||||||
|
** @param[in] type - finding ADV data type
|
||||||
|
** @param[out] p_length - return the length of ADV data not including type
|
||||||
|
**
|
||||||
|
** @return pointer of ADV data
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
uint8_t *esp_ble_resolve_adv_data( uint8_t *p_adv, uint8_t type, uint8_t *p_length );
|
||||||
|
|
||||||
#endif /* __ESP_GAP_BLE_API_H__ */
|
#endif /* __ESP_GAP_BLE_API_H__ */
|
||||||
|
@ -411,6 +411,8 @@ static void btc_ble_start_advertising(esp_ble_adv_params_t *ble_adv_params)
|
|||||||
ble_adv_params->channel_map,
|
ble_adv_params->channel_map,
|
||||||
ble_adv_params->adv_filter_policy,
|
ble_adv_params->adv_filter_policy,
|
||||||
&bd_addr);
|
&bd_addr);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -463,11 +465,13 @@ static void btc_search_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data
|
|||||||
param.scan_rst.search_evt = event;
|
param.scan_rst.search_evt = event;
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case BTA_DM_INQ_RES_EVT: {
|
case BTA_DM_INQ_RES_EVT: {
|
||||||
|
LOG_ERROR("BTA_DM_INQ_RES_EVT\n");
|
||||||
bdcpy(param.scan_rst.bda, p_data->inq_res.bd_addr);
|
bdcpy(param.scan_rst.bda, p_data->inq_res.bd_addr);
|
||||||
param.scan_rst.dev_type = p_data->inq_res.device_type;
|
param.scan_rst.dev_type = p_data->inq_res.device_type;
|
||||||
param.scan_rst.rssi = p_data->inq_res.rssi;
|
param.scan_rst.rssi = p_data->inq_res.rssi;
|
||||||
param.scan_rst.ble_addr_type = p_data->inq_res.ble_addr_type;
|
param.scan_rst.ble_addr_type = p_data->inq_res.ble_addr_type;
|
||||||
param.scan_rst.flag = p_data->inq_res.flag;
|
param.scan_rst.flag = p_data->inq_res.flag;
|
||||||
|
param.scan_rst.p_eir = p_data->inq_res.p_eir;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BTA_DM_INQ_CMPL_EVT: {
|
case BTA_DM_INQ_CMPL_EVT: {
|
||||||
@ -475,8 +479,23 @@ static void btc_search_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data
|
|||||||
LOG_ERROR("%s BLE observe complete. Num Resp %d\n", __FUNCTION__,p_data->inq_cmpl.num_resps);
|
LOG_ERROR("%s BLE observe complete. Num Resp %d\n", __FUNCTION__,p_data->inq_cmpl.num_resps);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case BTA_DM_DISC_RES_EVT:
|
||||||
|
LOG_ERROR("BTA_DM_DISC_RES_EVT\n");
|
||||||
|
break;
|
||||||
|
case BTA_DM_DISC_BLE_RES_EVT:
|
||||||
|
LOG_ERROR("BTA_DM_DISC_BLE_RES_EVT\n");
|
||||||
|
break;
|
||||||
|
case BTA_DM_DISC_CMPL_EVT:
|
||||||
|
LOG_ERROR("BTA_DM_DISC_CMPL_EVT\n");
|
||||||
|
break;
|
||||||
|
case BTA_DM_DI_DISC_CMPL_EVT:
|
||||||
|
LOG_ERROR("BTA_DM_DI_DISC_CMPL_EVT\n");
|
||||||
|
break;
|
||||||
|
case BTA_DM_SEARCH_CANCEL_CMPL_EVT:
|
||||||
|
LOG_ERROR("BTA_DM_SEARCH_CANCEL_CMPL_EVT\n");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
LOG_ERROR("%s : Unknown event 0x%x", __FUNCTION__, event);
|
LOG_ERROR("%s : Unknown event 0x%x\n", __FUNCTION__, event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL);
|
btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL);
|
||||||
|
@ -795,7 +795,7 @@
|
|||||||
* resolution, local address rotation etc.
|
* resolution, local address rotation etc.
|
||||||
*/
|
*/
|
||||||
#ifndef BLE_PRIVACY_SPT
|
#ifndef BLE_PRIVACY_SPT
|
||||||
#define BLE_PRIVACY_SPT TRUE
|
#define BLE_PRIVACY_SPT FALSE ///TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -415,7 +415,7 @@ tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT8 duration,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BTM_TRACE_ERROR("%s Observe not active", __func__);
|
BTM_TRACE_ERROR("%s Observe not active\n", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@ -2869,13 +2869,14 @@ void btm_ble_process_adv_pkt (UINT8 *p_data)
|
|||||||
STREAM_TO_UINT8 (evt_type, p);
|
STREAM_TO_UINT8 (evt_type, p);
|
||||||
STREAM_TO_UINT8 (addr_type, p);
|
STREAM_TO_UINT8 (addr_type, p);
|
||||||
STREAM_TO_BDADDR (bda, p);
|
STREAM_TO_BDADDR (bda, p);
|
||||||
|
BTM_TRACE_ERROR("btm_ble_process_adv_pkt:bda= %0x:%0x:%0x:%0x:%0x:%0x\n",
|
||||||
|
bda[0],bda[1],bda[2],bda[3],bda[4],bda[5]);
|
||||||
#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
|
#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
|
||||||
/* map address to security record */
|
/* map address to security record */
|
||||||
match = btm_identity_addr_to_random_pseudo(bda, &addr_type, FALSE);
|
match = btm_identity_addr_to_random_pseudo(bda, &addr_type, FALSE);
|
||||||
|
|
||||||
BTM_TRACE_DEBUG("btm_ble_process_adv_pkt:bda= %0x:%0x:%0x:%0x:%0x:%0x",
|
// BTM_TRACE_ERROR("btm_ble_process_adv_pkt:bda= %0x:%0x:%0x:%0x:%0x:%0x\n",
|
||||||
bda[0],bda[1],bda[2],bda[3],bda[4],bda[5]);
|
// bda[0],bda[1],bda[2],bda[3],bda[4],bda[5]);
|
||||||
/* always do RRA resolution on host */
|
/* always do RRA resolution on host */
|
||||||
if (!match && BTM_BLE_IS_RESOLVE_BDA(bda))
|
if (!match && BTM_BLE_IS_RESOLVE_BDA(bda))
|
||||||
{
|
{
|
||||||
@ -2993,7 +2994,7 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt
|
|||||||
btm_send_sel_conn_callback(bda, evt_type, p, addr_type);
|
btm_send_sel_conn_callback(bda, evt_type, p, addr_type);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BTM_TRACE_DEBUG("None LE device, can not initiate selective connection");
|
BTM_TRACE_DEBUG("None LE device, can not initiate selective connection\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1687,7 +1687,7 @@ static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p)
|
|||||||
|
|
||||||
static void btu_ble_process_adv_pkt (UINT8 *p)
|
static void btu_ble_process_adv_pkt (UINT8 *p)
|
||||||
{
|
{
|
||||||
HCI_TRACE_EVENT("btu_ble_process_adv_pkt");
|
HCI_TRACE_ERROR("btu_ble_process_adv_pkt\n");
|
||||||
|
|
||||||
btm_ble_process_adv_pkt(p);
|
btm_ble_process_adv_pkt(p);
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ static void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data)
|
|||||||
|
|
||||||
void bt_app_init_ok(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param)
|
void bt_app_init_ok(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param)
|
||||||
{
|
{
|
||||||
BTA_EnableBluetooth(bte_dm_evt);
|
//BTA_EnableBluetooth(bte_dm_evt);
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
bt_app_start_timer(&main_boot_tle, BT_APP_TTYPE_MAIN_ENTRY, 8);
|
bt_app_start_timer(&main_boot_tle, BT_APP_TTYPE_MAIN_ENTRY, 8);
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
#include "bta_gatt_api.h"
|
#include "bta_gatt_api.h"
|
||||||
#include "esp_gap_ble_api.h"
|
#include "esp_gap_ble_api.h"
|
||||||
#include "esp_gattc_api.h"
|
#include "esp_gattc_api.h"
|
||||||
|
#include "esp_bt_main.h"
|
||||||
|
|
||||||
|
|
||||||
#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
|
#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||||
#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
|
#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
|
||||||
@ -129,12 +131,24 @@ static void esp_scan_result_cb(uint32_t event, void *param)
|
|||||||
case ESP_GAP_BLE_SCAN_RESULT_EVT:
|
case ESP_GAP_BLE_SCAN_RESULT_EVT:
|
||||||
{
|
{
|
||||||
esp_ble_gap_cb_param_t *scan_result = (esp_ble_gap_cb_param_t *)param;
|
esp_ble_gap_cb_param_t *scan_result = (esp_ble_gap_cb_param_t *)param;
|
||||||
//switch(scan_result->scan_rst.search_evt)
|
switch(scan_result->scan_rst.search_evt)
|
||||||
//{
|
{
|
||||||
// case ESP_GAP_SEARCH_DISC_BLE_RES_EVT:
|
case ESP_GAP_SEARCH_INQ_RES_EVT:
|
||||||
|
for (int i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
LOG_ERROR("%x\n", scan_result->scan_rst.bda[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_ERROR("\n");
|
||||||
|
//if(strcmp(scan_result->scan_rst.bda, ))
|
||||||
|
break;
|
||||||
|
case ESP_GAP_SEARCH_INQ_CMPL_EVT:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
// LOG_ERROR("ESP_GAP_SEARCH_DISC_BLE_RES_EVT\n");
|
// LOG_ERROR("ESP_GAP_SEARCH_DISC_BLE_RES_EVT\n");
|
||||||
// break;
|
// break;
|
||||||
//}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//case :
|
//case :
|
||||||
@ -401,6 +415,7 @@ void ble_client_appRegister(void)
|
|||||||
void gattc_client_test(void)
|
void gattc_client_test(void)
|
||||||
{
|
{
|
||||||
BTM_SetTraceLevel(BT_TRACE_LEVEL_DEBUG);
|
BTM_SetTraceLevel(BT_TRACE_LEVEL_DEBUG);
|
||||||
|
esp_init_bluetooth();
|
||||||
|
esp_enable_bluetooth();
|
||||||
ble_client_appRegister();
|
ble_client_appRegister();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user