Merge branch 'feature/btdm_raw_adv' into 'master'

Feature/btdm raw adv

Add APIs to set raw advertising data and scan response data by user self.

See merge request !451
This commit is contained in:
Jiang Jiang Jian 2017-01-19 18:57:39 +08:00
commit aea18f6e74
15 changed files with 570 additions and 85 deletions

View file

@ -252,3 +252,50 @@ uint8_t *esp_ble_resolve_adv_data( uint8_t *adv_data, uint8_t type, uint8_t *len
return (BTM_CheckAdvData( adv_data, type, length)); return (BTM_CheckAdvData( adv_data, type, length));
} }
esp_err_t esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_len)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
if (raw_data == NULL
|| (raw_data_len <= 0 || raw_data_len > ESP_BLE_ADV_DATA_LEN_MAX)) {
return ESP_ERR_INVALID_ARG;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW;
arg.cfg_adv_data_raw.raw_adv = raw_data;
arg.cfg_adv_data_raw.raw_adv_len = raw_data_len;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_data_len)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
if (raw_data == NULL
|| (raw_data_len <= 0 || raw_data_len > ESP_BLE_SCAN_RSP_DATA_LEN_MAX)) {
return ESP_ERR_INVALID_ARG;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW;
arg.cfg_scan_rsp_data_raw.raw_scan_rsp = raw_data;
arg.cfg_scan_rsp_data_raw.raw_scan_rsp_len = raw_data_len;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

View file

@ -44,6 +44,8 @@ typedef enum {
ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT, /*!< When scan response data set complete, the event comes */ ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT, /*!< When scan response data set complete, the event comes */
ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT, /*!< When scan parameters set complete, the event comes */ ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT, /*!< When scan parameters set complete, the event comes */
ESP_GAP_BLE_SCAN_RESULT_EVT, /*!< When one scan result ready, the event comes each time */ ESP_GAP_BLE_SCAN_RESULT_EVT, /*!< When one scan result ready, the event comes each time */
ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT, /*!< When raw advertising data set complete, the event comes */
ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT, /*!< When raw advertising data set complete, the event comes */
} esp_gap_ble_cb_event_t; } esp_gap_ble_cb_event_t;
/// Advertising data maximum length /// Advertising data maximum length
@ -270,6 +272,18 @@ typedef union {
int flag; /*!< Advertising data flag bit */ int flag; /*!< Advertising data flag bit */
int num_resps; /*!< Scan result number */ int num_resps; /*!< Scan result number */
} scan_rst; /*!< Event parameter of ESP_GAP_BLE_SCAN_RESULT_EVT */ } scan_rst; /*!< Event parameter of ESP_GAP_BLE_SCAN_RESULT_EVT */
/**
* @brief ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT
*/
struct ble_adv_data_raw_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate the set raw advertising data operation success status */
} adv_data_raw_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT
*/
struct ble_scan_rsp_data_raw_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate the set raw advertising data operation success status */
} scan_rsp_data_raw_cmpl; /*!< Event parameter of ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT */
} esp_ble_gap_cb_param_t; } esp_ble_gap_cb_param_t;
/** /**
@ -448,6 +462,33 @@ esp_err_t esp_ble_gap_set_device_name(const char *name);
*/ */
uint8_t *esp_ble_resolve_adv_data(uint8_t *adv_data, uint8_t type, uint8_t *length); uint8_t *esp_ble_resolve_adv_data(uint8_t *adv_data, uint8_t type, uint8_t *length);
/**
* @brief This function is called to set raw advertising data. User need to fill
* ADV data by self.
*
* @param[in] raw_data : raw advertising data
* @param[in] raw_data_len : raw advertising data length , less than 31 bytes
*
* @return
* - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_len);
/**
* @brief This function is called to set raw scan response data. User need to fill
* scan response data by self.
*
* @param[in] raw_data : raw scan response data
* @param[in] raw_data_len : raw scan response data length , less than 31 bytes
*
* @return
* - ESP_OK : success
* - other : failed
*/
esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_data_len);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -4608,6 +4608,30 @@ void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data)
} }
} }
/*******************************************************************************
**
** Function bta_dm_ble_set_adv_config_raw
**
** Description This function set the customized ADV data configuration
**
** Parameters:
**
*******************************************************************************/
void bta_dm_ble_set_adv_config_raw (tBTA_DM_MSG *p_data)
{
tBTA_STATUS status = BTA_FAILURE;
if (BTM_BleWriteAdvDataRaw(p_data->ble_set_adv_data_raw.p_raw_adv,
p_data->ble_set_adv_data_raw.raw_adv_len) == BTM_SUCCESS) {
status = BTA_SUCCESS;
}
if (p_data->ble_set_adv_data_raw.p_adv_data_cback) {
(*p_data->ble_set_adv_data_raw.p_adv_data_cback)(status);
}
}
/******************************************************************************* /*******************************************************************************
** **
** Function bta_dm_ble_set_scan_rsp ** Function bta_dm_ble_set_scan_rsp
@ -4631,6 +4655,29 @@ void bta_dm_ble_set_scan_rsp (tBTA_DM_MSG *p_data)
} }
} }
/*******************************************************************************
**
** Function bta_dm_ble_set_scan_rsp_raw
**
** Description This function set the raw scan response data
**
** Parameters:
**
*******************************************************************************/
void bta_dm_ble_set_scan_rsp_raw (tBTA_DM_MSG *p_data)
{
tBTA_STATUS status = BTA_FAILURE;
if (BTM_BleWriteScanRspRaw(p_data->ble_set_adv_data_raw.p_raw_adv,
p_data->ble_set_adv_data_raw.raw_adv_len) == BTM_SUCCESS) {
status = BTA_SUCCESS;
}
if (p_data->ble_set_adv_data_raw.p_adv_data_cback) {
(*p_data->ble_set_adv_data_raw.p_adv_data_cback)(status);
}
}
/******************************************************************************* /*******************************************************************************
** **
** Function bta_dm_ble_set_data_length ** Function bta_dm_ble_set_data_length

View file

@ -1077,6 +1077,35 @@ void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv
} }
} }
/*******************************************************************************
**
** Function BTA_DmBleSetAdvConfigRaw
**
** Description This function is called to set raw Advertising data
**
** Parameters p_raw_adv : raw advertising data.
** raw_adv_len : raw advertising data length.
** p_adv_data_cback : set adv data complete callback.
**
** Returns None
**
*******************************************************************************/
void BTA_DmBleSetAdvConfigRaw (UINT8 *p_raw_adv, UINT32 raw_adv_len,
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
{
tBTA_DM_API_SET_ADV_CONFIG_RAW *p_msg;
if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG_RAW *)
GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW))) != NULL) {
p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_RAW_EVT;
p_msg->p_adv_data_cback = p_adv_data_cback;
p_msg->p_raw_adv = p_raw_adv;
p_msg->raw_adv_len = raw_adv_len;
bta_sys_sendmsg(p_msg);
}
}
/******************************************************************************* /*******************************************************************************
** **
** Function BTA_DmBleSetScanRsp ** Function BTA_DmBleSetScanRsp
@ -1104,6 +1133,35 @@ extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *
} }
} }
/*******************************************************************************
**
** Function BTA_DmBleSetScanRspRaw
**
** Description This function is called to set raw scan response data
**
** Parameters p_raw_scan_rsp : raw scan_rspertising data.
** raw_scan_rsp_len : raw scan_rspertising data length.
** p_scan_rsp_data_cback : set scan_rsp data complete callback.
**
** Returns None
**
*******************************************************************************/
void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len,
tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback)
{
tBTA_DM_API_SET_ADV_CONFIG_RAW *p_msg;
if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG_RAW *)
GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW))) != NULL) {
p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_RAW_EVT;
p_msg->p_adv_data_cback = p_scan_rsp_data_cback;
p_msg->p_raw_adv = p_raw_scan_rsp;
p_msg->raw_adv_len = raw_scan_rsp_len;
bta_sys_sendmsg(p_msg);
}
}
/******************************************************************************* /*******************************************************************************
** **
** Function BTA_DmBleSetStorageParams ** Function BTA_DmBleSetStorageParams

View file

@ -109,7 +109,11 @@ enum {
support setting the ble advertising param by the APP******/ support setting the ble advertising param by the APP******/
BTA_DM_API_BLE_ADV_PARAM_All_EVT, BTA_DM_API_BLE_ADV_PARAM_All_EVT,
BTA_DM_API_BLE_SET_ADV_CONFIG_EVT, BTA_DM_API_BLE_SET_ADV_CONFIG_EVT,
/* Add for set raw advertising data */
BTA_DM_API_BLE_SET_ADV_CONFIG_RAW_EVT,
BTA_DM_API_BLE_SET_SCAN_RSP_EVT, BTA_DM_API_BLE_SET_SCAN_RSP_EVT,
/* Add for set raw scan response data */
BTA_DM_API_BLE_SET_SCAN_RSP_RAW_EVT,
BTA_DM_API_BLE_BROADCAST_EVT, BTA_DM_API_BLE_BROADCAST_EVT,
BTA_DM_API_SET_DATA_LENGTH_EVT, BTA_DM_API_SET_DATA_LENGTH_EVT,
@ -545,6 +549,15 @@ typedef struct {
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback; tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback;
} tBTA_DM_API_SET_ADV_CONFIG; } tBTA_DM_API_SET_ADV_CONFIG;
/* raw scan response and raw advertising data use
the same structure */
typedef struct {
BT_HDR hdr;
UINT8 *p_raw_adv;
UINT32 raw_adv_len;
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback;
} tBTA_DM_API_SET_ADV_CONFIG_RAW;
typedef struct { typedef struct {
BT_HDR hdr; BT_HDR hdr;
UINT8 batch_scan_full_max; UINT8 batch_scan_full_max;
@ -708,6 +721,7 @@ typedef union {
tBTA_DM_API_BLE_ADV_PARAMS ble_set_adv_params; tBTA_DM_API_BLE_ADV_PARAMS ble_set_adv_params;
tBTA_DM_API_BLE_ADV_PARAMS_ALL ble_set_adv_params_all; tBTA_DM_API_BLE_ADV_PARAMS_ALL ble_set_adv_params_all;
tBTA_DM_API_SET_ADV_CONFIG ble_set_adv_data; tBTA_DM_API_SET_ADV_CONFIG ble_set_adv_data;
tBTA_DM_API_SET_ADV_CONFIG_RAW ble_set_adv_data_raw;
#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
tBTA_DM_API_SCAN_FILTER_PARAM_SETUP ble_scan_filt_param_setup; tBTA_DM_API_SCAN_FILTER_PARAM_SETUP ble_scan_filt_param_setup;
tBTA_DM_API_CFG_FILTER_COND ble_cfg_filter_cond; tBTA_DM_API_CFG_FILTER_COND ble_cfg_filter_cond;
@ -1093,9 +1107,11 @@ extern void bta_dm_ble_set_rand_address(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_stop_advertising(tBTA_DM_MSG *p_data); extern void bta_dm_ble_stop_advertising(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_config_local_privacy (tBTA_DM_MSG *p_data); extern void bta_dm_ble_config_local_privacy (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_adv_params_all (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_adv_params_all(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_adv_config_raw (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_scan_rsp (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_scan_rsp (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_scan_rsp_raw (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_broadcast (tBTA_DM_MSG *p_data); extern void bta_dm_ble_broadcast (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_data_length(tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_data_length(tBTA_DM_MSG *p_data);

View file

@ -89,19 +89,28 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
bta_dm_ble_set_scan_fil_params, /* BTA_DM_API_BLE_SCAN_FIL_PARAM_EVT */ bta_dm_ble_set_scan_fil_params, /* BTA_DM_API_BLE_SCAN_FIL_PARAM_EVT */
bta_dm_ble_observe, /* BTA_DM_API_BLE_OBSERVE_EVT*/ bta_dm_ble_observe, /* BTA_DM_API_BLE_OBSERVE_EVT*/
bta_dm_ble_update_conn_params, /* BTA_DM_API_UPDATE_CONN_PARAM_EVT */ bta_dm_ble_update_conn_params, /* BTA_DM_API_UPDATE_CONN_PARAM_EVT */
/*******This handler function added by Yulong at 2016/9/9 to /* This handler function added by
support the random address setting for the APP******/ Yulong at 2016/9/9 to support the
bta_dm_ble_set_rand_address, /*BTA_DM_API_SET_RAND_ADDR_EVT*/ random address setting for the APP */
/*******This handler function added by Yulong at 2016/10/19 to bta_dm_ble_set_rand_address, /* BTA_DM_API_SET_RAND_ADDR_EVT*/
support stop the ble advertising setting by the APP******/ /* This handler function added by
bta_dm_ble_stop_advertising, /*BTA_DM_API_BLE_STOP_ADV_EVT*/ Yulong at 2016/10/19 to support
stop the ble advertising setting
by the APP */
bta_dm_ble_stop_advertising, /* BTA_DM_API_BLE_STOP_ADV_EVT*/
#if BLE_PRIVACY_SPT == TRUE #if BLE_PRIVACY_SPT == TRUE
bta_dm_ble_config_local_privacy, /* BTA_DM_API_LOCAL_PRIVACY_EVT */ bta_dm_ble_config_local_privacy, /* BTA_DM_API_LOCAL_PRIVACY_EVT */
#endif #endif
bta_dm_ble_set_adv_params, /* BTA_DM_API_BLE_ADV_PARAM_EVT */ bta_dm_ble_set_adv_params, /* BTA_DM_API_BLE_ADV_PARAM_EVT */
bta_dm_ble_set_adv_params_all, /* BTA_DM_API_BLE_ADV_PARAM_All_EVT */ bta_dm_ble_set_adv_params_all, /* BTA_DM_API_BLE_ADV_PARAM_All_EVT */
bta_dm_ble_set_adv_config, /* BTA_DM_API_BLE_SET_ADV_CONFIG_EVT */ bta_dm_ble_set_adv_config, /* BTA_DM_API_BLE_SET_ADV_CONFIG_EVT */
bta_dm_ble_set_scan_rsp, /* BTA_DM_API_BLE_SET_SCAN_RSPT */ /* New function to allow set raw adv
data to HCI */
bta_dm_ble_set_adv_config_raw, /* BTA_DM_API_BLE_SET_ADV_CONFIG_RAW_EVT */
bta_dm_ble_set_scan_rsp, /* BTA_DM_API_BLE_SET_SCAN_RSP_EVT */
/* New function to allow set raw scan
response data to HCI */
bta_dm_ble_set_scan_rsp_raw, /* BTA_DM_API_BLE_SET_SCAN_RSP_RAW_EVT */
bta_dm_ble_broadcast, /* BTA_DM_API_BLE_BROADCAST_EVT */ bta_dm_ble_broadcast, /* BTA_DM_API_BLE_BROADCAST_EVT */
bta_dm_ble_set_data_length, /* BTA_DM_API_SET_DATA_LENGTH_EVT */ bta_dm_ble_set_data_length, /* BTA_DM_API_SET_DATA_LENGTH_EVT */
#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE

View file

@ -2050,6 +2050,22 @@ extern void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask,
tBTA_BLE_ADV_DATA *p_adv_cfg, tBTA_BLE_ADV_DATA *p_adv_cfg,
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback);
/*******************************************************************************
**
** Function BTA_DmBleSetAdvConfigRaw
**
** Description This function is called to set raw Advertising data
**
** Parameters p_raw_adv : raw advertising data.
** raw_adv_len : raw advertising data length.
** p_adv_data_cback : set adv data complete callback.
**
** Returns None
**
*******************************************************************************/
extern void BTA_DmBleSetAdvConfigRaw (UINT8 *p_raw_adv, UINT32 raw_adv_len,
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback);
/******************************************************************************* /*******************************************************************************
** **
** Function BTA_DmBleSetScanRsp ** Function BTA_DmBleSetScanRsp
@ -2065,6 +2081,22 @@ extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask,
tBTA_BLE_ADV_DATA *p_adv_cfg, tBTA_BLE_ADV_DATA *p_adv_cfg,
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback);
/*******************************************************************************
**
** Function BTA_DmBleSetScanRspRaw
**
** Description This function is called to set raw scan response data
**
** Parameters p_raw_scan_rsp : raw scan_rspertising data.
** raw_scan_rsp_len : raw scan_rspertising data length.
** p_scan_rsp_data_cback : set scan_rsp data complete callback.
**
** Returns None
**
*******************************************************************************/
extern void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len,
tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback);
/******************************************************************************* /*******************************************************************************
** **
** Function BTA_DmBleBroadcast ** Function BTA_DmBleBroadcast

View file

@ -303,6 +303,44 @@ static void btc_scan_rsp_data_callback(tBTA_STATUS status)
} }
} }
static void btc_adv_data_raw_callback(tBTA_STATUS status)
{
esp_ble_gap_cb_param_t param;
bt_status_t ret;
btc_msg_t msg;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT;
param.adv_data_raw_cmpl.status = status;
ret = btc_transfer_context(&msg, &param,
sizeof(esp_ble_gap_cb_param_t), NULL);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
}
}
static void btc_scan_rsp_data_raw_callback(tBTA_STATUS status)
{
esp_ble_gap_cb_param_t param;
bt_status_t ret;
btc_msg_t msg;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT;
param.scan_rsp_data_raw_cmpl.status = status;
ret = btc_transfer_context(&msg, &param,
sizeof(esp_ble_gap_cb_param_t), NULL);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
}
}
static void btc_ble_set_adv_data(esp_ble_adv_data_t *adv_data, static void btc_ble_set_adv_data(esp_ble_adv_data_t *adv_data,
tBTA_SET_ADV_DATA_CMPL_CBACK p_adv_data_cback) tBTA_SET_ADV_DATA_CMPL_CBACK p_adv_data_cback)
{ {
@ -317,6 +355,18 @@ static void btc_ble_set_adv_data(esp_ble_adv_data_t *adv_data,
} }
} }
static void btc_ble_set_adv_data_raw(uint8_t *raw_adv, uint32_t raw_adv_len,
tBTA_SET_ADV_DATA_CMPL_CBACK p_adv_data_cback)
{
BTA_DmBleSetAdvConfigRaw(raw_adv, raw_adv_len, p_adv_data_cback);
}
static void btc_ble_set_scan_rsp_data_raw(uint8_t *raw_scan_rsp, uint32_t raw_scan_rsp_len,
tBTA_SET_ADV_DATA_CMPL_CBACK p_scan_rsp_data_cback)
{
BTA_DmBleSetScanRspRaw(raw_scan_rsp, raw_scan_rsp_len, p_scan_rsp_data_cback);
}
static void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params) static void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params)
{ {
tBLE_BD_ADDR peer_addr; tBLE_BD_ADDR peer_addr;
@ -520,6 +570,12 @@ void btc_gap_ble_cb_handler(btc_msg_t *msg)
case ESP_GAP_BLE_SCAN_RESULT_EVT: case ESP_GAP_BLE_SCAN_RESULT_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_RESULT_EVT, param); btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_RESULT_EVT, param);
break; break;
case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT, param);
break;
default: default:
break; break;
@ -551,6 +607,30 @@ void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
} }
break; break;
} }
case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW: {
btc_ble_gap_args_t *src = (btc_ble_gap_args_t *)p_src;
btc_ble_gap_args_t *dst = (btc_ble_gap_args_t *) p_dest;
if (src && src->cfg_adv_data_raw.raw_adv && src->cfg_adv_data_raw.raw_adv_len > 0) {
dst->cfg_adv_data_raw.raw_adv = GKI_getbuf(src->cfg_adv_data_raw.raw_adv_len);
if (dst->cfg_adv_data_raw.raw_adv) {
memcpy(dst->cfg_adv_data_raw.raw_adv, src->cfg_adv_data_raw.raw_adv, src->cfg_adv_data_raw.raw_adv_len);
}
}
break;
}
case BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW: {
btc_ble_gap_args_t *src = (btc_ble_gap_args_t *)p_src;
btc_ble_gap_args_t *dst = (btc_ble_gap_args_t *) p_dest;
if (src && src->cfg_scan_rsp_data_raw.raw_scan_rsp && src->cfg_scan_rsp_data_raw.raw_scan_rsp_len > 0) {
dst->cfg_scan_rsp_data_raw.raw_scan_rsp = GKI_getbuf(src->cfg_scan_rsp_data_raw.raw_scan_rsp_len);
if (dst->cfg_scan_rsp_data_raw.raw_scan_rsp) {
memcpy(dst->cfg_scan_rsp_data_raw.raw_scan_rsp, src->cfg_scan_rsp_data_raw.raw_scan_rsp, src->cfg_scan_rsp_data_raw.raw_scan_rsp_len);
}
}
break;
}
default: default:
LOG_ERROR("Unhandled deep copy %d\n", msg->act); LOG_ERROR("Unhandled deep copy %d\n", msg->act);
break; break;
@ -576,6 +656,20 @@ static void btc_gap_ble_arg_deep_free(btc_msg_t *msg)
} }
break; break;
} }
case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW: {
uint8_t *raw_adv = ((btc_ble_gap_args_t *)msg->arg)->cfg_adv_data_raw.raw_adv;
if (raw_adv) {
GKI_freebuf(raw_adv);
}
break;
}
case BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW: {
uint8_t *raw_scan_rsp = ((btc_ble_gap_args_t *)msg->arg)->cfg_scan_rsp_data_raw.raw_scan_rsp;
if (raw_scan_rsp) {
GKI_freebuf(raw_scan_rsp);
}
break;
}
default: default:
LOG_DEBUG("Unhandled deep free %d\n", msg->act); LOG_DEBUG("Unhandled deep free %d\n", msg->act);
break; break;
@ -631,6 +725,16 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
case BTC_GAP_BLE_ACT_SET_DEV_NAME: case BTC_GAP_BLE_ACT_SET_DEV_NAME:
BTA_DmSetDeviceName(arg->set_dev_name.device_name); BTA_DmSetDeviceName(arg->set_dev_name.device_name);
break; 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,
btc_adv_data_raw_callback);
break;
case BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW:
btc_ble_set_scan_rsp_data_raw(arg->cfg_scan_rsp_data_raw.raw_scan_rsp,
arg->cfg_scan_rsp_data_raw.raw_scan_rsp_len,
btc_scan_rsp_data_raw_callback);
break;
default: default:
break; break;
} }

View file

@ -32,6 +32,8 @@ typedef enum {
BTC_GAP_BLE_ACT_SET_RAND_ADDRESS, BTC_GAP_BLE_ACT_SET_RAND_ADDRESS,
BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY, BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY,
BTC_GAP_BLE_ACT_SET_DEV_NAME, BTC_GAP_BLE_ACT_SET_DEV_NAME,
BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW,
BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW,
} btc_gap_ble_act_t; } btc_gap_ble_act_t;
/* btc_ble_gap_args_t */ /* btc_ble_gap_args_t */
@ -76,6 +78,16 @@ typedef union {
#define ESP_GAP_DEVICE_NAME_MAX (32) #define ESP_GAP_DEVICE_NAME_MAX (32)
char device_name[ESP_GAP_DEVICE_NAME_MAX + 1]; char device_name[ESP_GAP_DEVICE_NAME_MAX + 1];
} set_dev_name; } set_dev_name;
//BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW,
struct config_adv_data_raw_args {
uint8_t *raw_adv;
uint32_t raw_adv_len;
} cfg_adv_data_raw;
//BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW,
struct config_scan_rsp_data_raw_args {
uint8_t *raw_scan_rsp;
uint32_t raw_scan_rsp_len;
} cfg_scan_rsp_data_raw;
} btc_ble_gap_args_t; } btc_ble_gap_args_t;
void btc_gap_ble_call_handler(btc_msg_t *msg); void btc_gap_ble_call_handler(btc_msg_t *msg);

View file

@ -1298,6 +1298,26 @@ tBTM_STATUS BTM_BleWriteScanRsp(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p
return status; return status;
} }
/*******************************************************************************
**
** Function BTM_BleWriteScanRspRaw
**
** Description This function is called to write raw scan response data
**
** Parameters: None.
**
** Returns void
**
*******************************************************************************/
tBTM_STATUS BTM_BleWriteScanRspRaw(UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len)
{
if (btsnd_hcic_ble_set_scan_rsp_data((UINT8)raw_scan_rsp_len, p_raw_scan_rsp)) {
return BTM_SUCCESS;
} else {
return BTM_NO_RESOURCES;
}
}
/******************************************************************************* /*******************************************************************************
** **
** Function BTM_BleWriteAdvData ** Function BTM_BleWriteAdvData
@ -1345,6 +1365,27 @@ tBTM_STATUS BTM_BleWriteAdvData(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p
} }
/*******************************************************************************
**
** Function BTM_BleWriteAdvDataRaw
**
** Description This function is called to write raw advertising data.
**
** Parameters: None.
**
** Returns void
**
*******************************************************************************/
tBTM_STATUS BTM_BleWriteAdvDataRaw(UINT8 *p_raw_adv, UINT32 raw_adv_len)
{
if (btsnd_hcic_ble_set_adv_data((UINT8)raw_adv_len, p_raw_adv)) {
return BTM_SUCCESS;
} else {
return BTM_NO_RESOURCES;
}
}
/******************************************************************************* /*******************************************************************************
** **
** Function BTM_BleSetRandAddress ** Function BTM_BleSetRandAddress

View file

@ -936,6 +936,22 @@ tBTM_STATUS BTM_BleSetAdvParamsStartAdv(UINT16 adv_int_min, UINT16 adv_int_max,
tBTM_STATUS BTM_BleWriteAdvData(tBTM_BLE_AD_MASK data_mask, tBTM_STATUS BTM_BleWriteAdvData(tBTM_BLE_AD_MASK data_mask,
tBTM_BLE_ADV_DATA *p_data); tBTM_BLE_ADV_DATA *p_data);
/*******************************************************************************
**
** Function BTM_BleWriteAdvDataRaw
**
** Description This function is called to write raw advertising data.
**
** Parameters: p_raw_adv : point to raw advertising data
** raw_adv_len : raw advertising data
**
** Returns BTM_SUCCESS means success.
**
*******************************************************************************/
//extern
tBTM_STATUS BTM_BleWriteAdvDataRaw(UINT8 *p_raw_adv, UINT32 raw_adv_len);
BOOLEAN BTM_BleSetRandAddress(BD_ADDR rand_addr); BOOLEAN BTM_BleSetRandAddress(BD_ADDR rand_addr);
@ -1136,6 +1152,20 @@ tBTM_STATUS BTM_BleTrackAdvertiser(tBTM_BLE_TRACK_ADV_CBACK *p_track_cback,
tBTM_STATUS BTM_BleWriteScanRsp(tBTM_BLE_AD_MASK data_mask, tBTM_STATUS BTM_BleWriteScanRsp(tBTM_BLE_AD_MASK data_mask,
tBTM_BLE_ADV_DATA *p_data); tBTM_BLE_ADV_DATA *p_data);
/*******************************************************************************
**
** Function BTM_BleWriteScanRspRaw
**
** Description This function is called to write raw scan response data
**
** Parameters: None.
**
** Returns void
**
*******************************************************************************/
//extern
tBTM_STATUS BTM_BleWriteScanRspRaw(UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len);
/******************************************************************************* /*******************************************************************************
** **
** Function BTM_BleObserve ** Function BTM_BleObserve

View file

@ -36,6 +36,7 @@ Macros
.. doxygendefine:: ESP_BLE_ADV_FLAG_DMT_HOST_SPT .. doxygendefine:: ESP_BLE_ADV_FLAG_DMT_HOST_SPT
.. doxygendefine:: ESP_BLE_ADV_FLAG_NON_LIMIT_DISC .. doxygendefine:: ESP_BLE_ADV_FLAG_NON_LIMIT_DISC
.. doxygendefine:: ESP_BLE_ADV_DATA_LEN_MAX .. doxygendefine:: ESP_BLE_ADV_DATA_LEN_MAX
.. doxygendefine:: ESP_BLE_SCAN_RSP_DATA_LEN_MAX
Type Definitions Type Definitions
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
@ -86,6 +87,12 @@ Structures
.. doxygenstruct:: esp_ble_gap_cb_param_t::ble_scan_result_evt_param .. doxygenstruct:: esp_ble_gap_cb_param_t::ble_scan_result_evt_param
:members: :members:
.. doxygenstruct:: esp_ble_gap_cb_param_t::ble_adv_data_raw_cmpl_evt_param
:members:
.. doxygenstruct:: esp_ble_gap_cb_param_t::ble_scan_rsp_data_raw_cmpl_evt_param
:members:
Functions Functions
^^^^^^^^^ ^^^^^^^^^
@ -103,4 +110,6 @@ Functions
.. doxygenfunction:: esp_ble_gap_config_local_privacy .. doxygenfunction:: esp_ble_gap_config_local_privacy
.. doxygenfunction:: esp_ble_gap_set_device_name .. doxygenfunction:: esp_ble_gap_set_device_name
.. doxygenfunction:: esp_ble_resolve_adv_data .. doxygenfunction:: esp_ble_resolve_adv_data
.. doxygenfunction:: esp_ble_gap_config_adv_data_raw
.. doxygenfunction:: esp_ble_gap_config_scan_rsp_data_raw

View file

@ -3,3 +3,18 @@ ESP-IDF GATT SERVER demo
This is the demo for user to use ESP_APIs to create a GATT Server. This is the demo for user to use ESP_APIs to create a GATT Server.
Options choose step:
1. make menuconfig.
2. enter menuconfig "Component config".
3. enter menuconfig "Example 'GATT SERVER' Config".
4. choose your options.
UPDATE NOTE
===========
2017-01-19:
1. Use New APIs to set raw advertising data and raw scan response data.
2. Could use macro CONFIG_SET_RAW_ADV_DATA (should use menuconfig) to config use raw advertising/scan_response
or use structure do automatically config. The macro CONFIG_SET_RAW_ADV will effect both advertising data
and scan_response data.

View file

@ -0,0 +1,10 @@
menu "Example 'GATT SERVER' Config"
config SET_RAW_ADV_DATA
bool "adv data or scan_rsp data use raw data or structure"
default "y"
help
Set raw advertising data/scan response data by self or use adv_data/scan_rsp_data structure to
set advertising data/scan response data. If use structure, lower layer will encapsulate the packets.
endmenu

View file

@ -30,6 +30,8 @@
#include "esp_bt_main.h" #include "esp_bt_main.h"
#include "esp_bt_main.h" #include "esp_bt_main.h"
#include "sdkconfig.h"
#define GATTS_TAG "GATTS_DEMO" #define GATTS_TAG "GATTS_DEMO"
///Declare the static function ///Declare the static function
@ -51,8 +53,7 @@ static void gatts_profile_b_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
#define GATTS_DEMO_CHAR_VAL_LEN_MAX 0x40 #define GATTS_DEMO_CHAR_VAL_LEN_MAX 0x40
uint8_t char1_str[] ={0x11,0x22,0x33}; uint8_t char1_str[] = {0x11,0x22,0x33};
esp_attr_value_t gatts_demo_char1_val = esp_attr_value_t gatts_demo_char1_val =
{ {
.attr_max_len = GATTS_DEMO_CHAR_VAL_LEN_MAX, .attr_max_len = GATTS_DEMO_CHAR_VAL_LEN_MAX,
@ -60,7 +61,12 @@ esp_attr_value_t gatts_demo_char1_val =
.attr_value = char1_str, .attr_value = char1_str,
}; };
#ifdef CONFIG_SET_RAW_ADV_DATA
static uint8_t raw_adv_data[] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe};
static uint8_t raw_scan_rsp_data[] = {0x7, 0x7, 0x7, 0x7, 0x8, 0x8, 0x8, 0x8, 0x9, 0x9, 0x9, 0x9, 0xa, 0xa, 0xa, 0xa,
0xb, 0xb, 0xb, 0xb, 0xc, 0xc, 0xc, 0xc, 0xd, 0xd, 0xd, 0xd, 0xe, 0xe, 0xe};
#else
static uint8_t test_service_uuid128[32] = { static uint8_t test_service_uuid128[32] = {
/* LSB <--------------------------------------------------------------------------------> MSB */ /* LSB <--------------------------------------------------------------------------------> MSB */
//first uuid, 16bit, [12],[13] is the value //first uuid, 16bit, [12],[13] is the value
@ -85,6 +91,7 @@ static esp_ble_adv_data_t test_adv_data = {
.p_service_uuid = test_service_uuid128, .p_service_uuid = test_service_uuid128,
.flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT), .flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT),
}; };
#endif /* CONFIG_SET_RAW_ADV_DATA */
static esp_ble_adv_params_t test_adv_params = { static esp_ble_adv_params_t test_adv_params = {
.adv_int_min = 0x20, .adv_int_min = 0x20,
@ -134,6 +141,12 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
esp_ble_gap_start_advertising(&test_adv_params); esp_ble_gap_start_advertising(&test_adv_params);
break; break;
case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:
esp_ble_gap_start_advertising(&test_adv_params);
break;
case ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT:
esp_ble_gap_start_advertising(&test_adv_params);
break;
default: default:
break; break;
} }
@ -149,8 +162,12 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A; gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A;
esp_ble_gap_set_device_name(TEST_DEVICE_NAME); esp_ble_gap_set_device_name(TEST_DEVICE_NAME);
#ifdef CONFIG_SET_RAW_ADV_DATA
esp_ble_gap_config_adv_data_raw(raw_adv_data, sizeof(raw_adv_data));
esp_ble_gap_config_scan_rsp_data_raw(raw_scan_rsp_data, sizeof(raw_scan_rsp_data));
#else
esp_ble_gap_config_adv_data(&test_adv_data); esp_ble_gap_config_adv_data(&test_adv_data);
#endif
esp_ble_gatts_create_service(gatts_if, &gl_profile_tab[PROFILE_A_APP_ID].service_id, GATTS_NUM_HANDLE_TEST_A); esp_ble_gatts_create_service(gatts_if, &gl_profile_tab[PROFILE_A_APP_ID].service_id, GATTS_NUM_HANDLE_TEST_A);
break; break;
case ESP_GATTS_READ_EVT: { case ESP_GATTS_READ_EVT: {
@ -252,9 +269,6 @@ static void gatts_profile_b_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
gl_profile_tab[PROFILE_B_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16; gl_profile_tab[PROFILE_B_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16;
gl_profile_tab[PROFILE_B_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_B; gl_profile_tab[PROFILE_B_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_B;
esp_ble_gap_set_device_name(TEST_DEVICE_NAME);
esp_ble_gap_config_adv_data(&test_adv_data);
esp_ble_gatts_create_service(gatts_if, &gl_profile_tab[PROFILE_B_APP_ID].service_id, GATTS_NUM_HANDLE_TEST_B); esp_ble_gatts_create_service(gatts_if, &gl_profile_tab[PROFILE_B_APP_ID].service_id, GATTS_NUM_HANDLE_TEST_B);
break; break;
case ESP_GATTS_READ_EVT: { case ESP_GATTS_READ_EVT: {