mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-15 15:00:02 +01:00
Merge remote-tracking branch 'remotes/origin/feature/btdm_arch_debug1' into feature/btdm_arch
# Conflicts: # components/bt/bluedroid/api/include/esp_gatt_defs.h # components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c
This commit is contained in:
@@ -70,12 +70,24 @@ esp_err_t esp_ble_gap_start_scanning(uint32_t duration)
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_SET_SCAN_PARAM;
|
||||
msg.act = BTC_GAP_BLE_ACT_START_SCAN;
|
||||
arg.duration = duration;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gap_stop_scanning(void)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gap_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_STOP_SCAN;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gap_start_advertising(esp_ble_adv_params_t *adv_params)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
@@ -173,3 +185,35 @@ esp_err_t esp_ble_gap_set_device_name(char *name)
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_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,36 @@
|
||||
#define ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT 2
|
||||
#define ESP_GAP_BLE_SCAN_RESULT_EVT 3
|
||||
|
||||
#define ESP_BLE_ADV_DATA_LEN_MAX 31
|
||||
|
||||
/****************** 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;
|
||||
|
||||
/// Advertising mode
|
||||
@@ -70,6 +100,24 @@ typedef struct {
|
||||
uint8_t flag;
|
||||
} esp_ble_adv_data_t;
|
||||
|
||||
/// Own BD address source of the device
|
||||
typedef enum
|
||||
{
|
||||
/// Public Address
|
||||
ESP_PUBLIC_ADDR,
|
||||
/// Provided random address
|
||||
ESP_PROVIDED_RND_ADDR,
|
||||
/// Provided static random address
|
||||
ESP_GEN_STATIC_RND_ADDR,
|
||||
/// Generated resolvable private random address
|
||||
ESP_GEN_RSLV_ADDR,
|
||||
/// Generated non-resolvable private random address
|
||||
ESP_GEN_NON_RSLV_ADDR,
|
||||
/// Provided Reconnection address
|
||||
ESP_PROVIDED_RECON_ADDR,
|
||||
}esp_ble_own_addr_src_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
BLE_SCAN_TYPE_PASSIVE = 0x0,
|
||||
BLE_SCAN_TYPE_ACTIVE = 0x1,
|
||||
@@ -132,6 +180,7 @@ typedef union {
|
||||
esp_bt_dev_type_t dev_type;
|
||||
esp_ble_addr_type_t ble_addr_type;
|
||||
int rssi;
|
||||
uint8_t ble_adv[ESP_BLE_ADV_DATA_LEN_MAX]; /* received EIR */
|
||||
int flag;
|
||||
int num_resps;
|
||||
} scan_rst;
|
||||
@@ -199,6 +248,16 @@ esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params);
|
||||
esp_err_t esp_ble_gap_start_scanning(uint32_t duration);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_stop_scanning
|
||||
**
|
||||
** @brief This function call to stop the device scanning the peer device whith advertising on the air
|
||||
** @param void
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gap_stop_scanning(void);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
@@ -300,4 +359,20 @@ esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable);
|
||||
*******************************************************************************/
|
||||
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__ */
|
||||
|
||||
@@ -115,6 +115,7 @@ typedef enum {
|
||||
} esp_gatt_char_prop_t;
|
||||
|
||||
#define ESP_GATT_MAX_ATTR_LEN 600 //as same as GATT_MAX_ATTR_LEN
|
||||
|
||||
typedef struct {
|
||||
uint8_t value[ESP_GATT_MAX_ATTR_LEN];
|
||||
uint16_t handle;
|
||||
|
||||
@@ -191,10 +191,10 @@ void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data)
|
||||
tBTA_GATT_STATUS status = BTA_GATT_NO_RESOURCES;
|
||||
|
||||
|
||||
APPL_TRACE_DEBUG("bta_gattc_register state %d",p_cb->state);
|
||||
APPL_TRACE_DEBUG("bta_gattc_register state %d\n",p_cb->state);
|
||||
memset(&cb_data, 0, sizeof(cb_data));
|
||||
cb_data.reg_oper.status = BTA_GATT_NO_RESOURCES;
|
||||
|
||||
|
||||
/* check if GATTC module is already enabled . Else enable */
|
||||
if (p_cb->state == BTA_GATTC_STATE_DISABLED)
|
||||
{
|
||||
@@ -207,7 +207,7 @@ void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data)
|
||||
{
|
||||
if ((p_app_uuid == NULL) || (p_cb->cl_rcb[i].client_if = GATT_Register(p_app_uuid, &bta_gattc_cl_cback)) == 0)
|
||||
{
|
||||
APPL_TRACE_ERROR("Register with GATT stack failed.");
|
||||
APPL_TRACE_ERROR("Register with GATT stack failed.\n");
|
||||
status = BTA_GATT_ERROR;
|
||||
}
|
||||
else
|
||||
@@ -223,7 +223,7 @@ void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data)
|
||||
{
|
||||
p_buf->hdr.event = BTA_GATTC_INT_START_IF_EVT;
|
||||
p_buf->client_if = p_cb->cl_rcb[i].client_if;
|
||||
|
||||
APPL_TRACE_DEBUG("GATTC getbuf sucess.\n");
|
||||
bta_sys_sendmsg(p_buf);
|
||||
status = BTA_GATT_OK;
|
||||
}
|
||||
@@ -243,8 +243,7 @@ void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data)
|
||||
if (p_data->api_reg.p_cback)
|
||||
{
|
||||
if (p_app_uuid != NULL)
|
||||
memcpy(&(cb_data.reg_oper.app_uuid),p_app_uuid,sizeof(tBT_UUID));
|
||||
|
||||
memcpy(&(cb_data.reg_oper.app_uuid),p_app_uuid,sizeof(tBT_UUID));
|
||||
cb_data.reg_oper.status = status;
|
||||
(*p_data->api_reg.p_cback)(BTA_GATTC_REG_EVT, (tBTA_GATTC *)&cb_data);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "btc_gattc.h"
|
||||
#include "btc_gap_ble.h"
|
||||
#include "btc_blufi_prf.h"
|
||||
#include "bta_gatt_api.h"
|
||||
|
||||
|
||||
static xTaskHandle xBtcTaskHandle = NULL;
|
||||
static xQueueHandle xBtcQueue = 0;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "bt_types.h"
|
||||
#include "bta_api.h"
|
||||
#include "btc_task.h"
|
||||
#include "btc_manage.h"
|
||||
@@ -428,7 +429,6 @@ void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params)
|
||||
ble_adv_params->adv_filter_policy,
|
||||
&peer_addr);
|
||||
|
||||
|
||||
/*set connectable,discoverable, pairable and paired only modes of local device*/
|
||||
BTA_DmSetVisibility(disc_mode, conn_mode, (UINT8)BTA_DM_NON_PAIRABLE, (UINT8)BTA_DM_CONN_ALL);
|
||||
}
|
||||
@@ -474,12 +474,11 @@ static void btc_search_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data
|
||||
{
|
||||
esp_ble_gap_cb_param_t param;
|
||||
btc_msg_t msg;
|
||||
uint8_t len;
|
||||
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = ESP_GAP_BLE_SCAN_RESULT_EVT;
|
||||
|
||||
|
||||
param.scan_rst.search_evt = event;
|
||||
switch (event) {
|
||||
case BTA_DM_INQ_RES_EVT: {
|
||||
@@ -488,15 +487,32 @@ static void btc_search_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data
|
||||
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.flag = p_data->inq_res.flag;
|
||||
memcpy(param.scan_rst.ble_adv, p_data->inq_res.p_eir,
|
||||
ESP_BLE_ADV_DATA_LEN_MAX);
|
||||
break;
|
||||
}
|
||||
case BTA_DM_INQ_CMPL_EVT: {
|
||||
param.scan_rst.num_resps = p_data->inq_cmpl.num_resps;
|
||||
LOG_ERROR("%s BLE observe complete. Num Resp %d", __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;
|
||||
}
|
||||
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:
|
||||
LOG_ERROR("%s : Unknown event 0x%x", __FUNCTION__, event);
|
||||
LOG_ERROR("%s : Unknown event 0x%x\n", __FUNCTION__, event);
|
||||
return;
|
||||
}
|
||||
btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL);
|
||||
@@ -514,6 +530,12 @@ static void btc_ble_start_scanning(uint8_t duration, tBTA_DM_SEARCH_CBACK *resul
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_stop_scanning(void)
|
||||
{
|
||||
uint8_t duration = 0;
|
||||
BTA_DmBleObserve(false, duration, NULL);
|
||||
}
|
||||
|
||||
|
||||
static void btc_ble_stop_advertising(void)
|
||||
{
|
||||
@@ -663,6 +685,7 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
|
||||
btc_ble_start_scanning(arg->duration, btc_search_callback);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_STOP_SCAN:
|
||||
btc_ble_stop_scanning();
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_START_ADV:
|
||||
btc_ble_start_advertising(&arg->adv_params);
|
||||
|
||||
@@ -54,8 +54,8 @@ static void btc_gattc_cback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = (uint8_t) event;
|
||||
|
||||
ret = btc_transfer_context(&msg, &p_data, sizeof(tBTA_GATTC), btc_gattc_copy_req_data);
|
||||
LOG_ERROR("the gattc event = %x\n",event);
|
||||
ret = btc_transfer_context(&msg, p_data, sizeof(tBTA_GATTC), btc_gattc_copy_req_data);
|
||||
|
||||
if (ret)
|
||||
LOG_ERROR("%s transfer failed\n", __func__);
|
||||
@@ -425,7 +425,7 @@ void btc_gattc_call_handler(btc_msg_t *msg)
|
||||
btc_gattc_unreg_for_notify(arg);
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s: Unhandled event (%d)!", __FUNCTION__, msg->act);
|
||||
LOG_ERROR("%s: Unhandled event (%d)!\n", __FUNCTION__, msg->act);
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -436,7 +436,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
|
||||
tBTA_GATTC *arg = (tBTA_GATTC *)(msg->arg);
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
|
||||
switch (msg->act) {
|
||||
case BTA_GATTC_REG_EVT: {
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "bt_target.h"
|
||||
#include "gatt_api.h"
|
||||
#include "gattdefs.h"
|
||||
#include "esp_gatt_api.h"
|
||||
#include "esp_gatts_api.h"
|
||||
|
||||
#define DIS_SUCCESS GATT_SUCCESS
|
||||
#define DIS_ILLEGAL_PARAM GATT_ILLEGAL_PARAMETER
|
||||
|
||||
@@ -795,7 +795,7 @@
|
||||
* resolution, local address rotation etc.
|
||||
*/
|
||||
#ifndef BLE_PRIVACY_SPT
|
||||
#define BLE_PRIVACY_SPT TRUE
|
||||
#define BLE_PRIVACY_SPT FALSE ///TRUE
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
@@ -415,7 +415,7 @@ tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT8 duration,
|
||||
}
|
||||
else
|
||||
{
|
||||
BTM_TRACE_ERROR("%s Observe not active", __func__);
|
||||
BTM_TRACE_ERROR("%s Observe not active\n", __func__);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -2869,13 +2869,14 @@ void btm_ble_process_adv_pkt (UINT8 *p_data)
|
||||
STREAM_TO_UINT8 (evt_type, p);
|
||||
STREAM_TO_UINT8 (addr_type, 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)
|
||||
/* map address to security record */
|
||||
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",
|
||||
bda[0],bda[1],bda[2],bda[3],bda[4],bda[5]);
|
||||
// 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]);
|
||||
/* always do RRA resolution on host */
|
||||
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);
|
||||
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
|
||||
|
||||
@@ -1687,7 +1687,7 @@ static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p)
|
||||
|
||||
static void btu_ble_process_adv_pkt (UINT8 *p)
|
||||
{
|
||||
HCI_TRACE_EVENT("btu_ble_process_adv_pkt");
|
||||
HCI_TRACE_DEBUG("btu_ble_process_adv_pkt\n");
|
||||
|
||||
btm_ble_process_adv_pkt(p);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user