component/bt: squash the branch of the early commit

component/bt: squash the branch of the early commit

component/bt: Added the set static random address callback to the bt project.

component/bt: fixed the set static random address error.

component/bt: fixed the set static random address error.
This commit is contained in:
Yulong 2017-05-19 05:23:00 -04:00
parent 972d1d9242
commit 66bb6a2f2b
5 changed files with 42 additions and 9 deletions

View file

@ -24,12 +24,13 @@ extern "C" {
/// Status Return Value
typedef enum {
ESP_BT_STATUS_SUCCESS = 0, /* Successful operation. */
ESP_BT_STATUS_FAILURE = 1, /* Generic failure. */
ESP_BT_STATUS_PENDING = 2, /* API cannot be completed right now */
ESP_BT_STATUS_BUSY = 3,
ESP_BT_STATUS_NO_RESOURCES = 4,
ESP_BT_STATUS_WRONG_MODE = 5,
ESP_BT_STATUS_SUCCESS = 0, /* Successful operation. */
ESP_BT_STATUS_FAILURE = 1, /* Generic failure. */
ESP_BT_STATUS_PENDING = 2, /* API cannot be completed right now */
ESP_BT_STATUS_BUSY = 3,
ESP_BT_STATUS_NO_RESOURCES = 4,
ESP_BT_STATUS_WRONG_MODE = 5,
ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR = 6,
} esp_bt_status_t;

View file

@ -87,6 +87,7 @@ typedef enum {
ESP_GAP_BLE_NC_REQ_EVT, /* Numeric Comparison request event */
ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT, /*!< When stop adv complete, the event comes */
ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT, /*!< When stop scan complete, the event comes */
ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT, /*!< When set the static rand address complete, the event comes */
} esp_gap_ble_cb_event_t;
/// Advertising data maximum length
@ -485,6 +486,12 @@ typedef union {
struct ble_adv_stop_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate adv stop operation success status */
} adv_stop_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT
*/
struct ble_set_rand_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate set static rand address operation success status */
} set_rand_addr_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT */
} esp_ble_gap_cb_param_t;
/**

View file

@ -634,10 +634,32 @@ static void btc_ble_set_pkt_data_len(BD_ADDR remote_device, uint16_t tx_data_len
static void btc_ble_set_rand_addr (BD_ADDR rand_addr)
{
esp_ble_gap_cb_param_t param;
bt_status_t ret;
btc_msg_t msg;
param.set_rand_addr_cmpl.status = ESP_BT_STATUS_SUCCESS;
if (rand_addr != NULL) {
BTA_DmSetRandAddress(rand_addr);
if((rand_addr[BD_ADDR_LEN - 1] & BT_STATIC_RAND_ADDR_MASK)
== BT_STATIC_RAND_ADDR_MASK) {
BTA_DmSetRandAddress(rand_addr);
} else {
param.set_rand_addr_cmpl.status = ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR;
LOG_ERROR("Invalid randrom address, the high bit should be 0x11xx");
}
} else {
LOG_ERROR("Invalid randrom address.\n");
param.set_rand_addr_cmpl.status = ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR;
LOG_ERROR("Invalid randrom addressm, the address value is NULL");
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT;
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__);
}
}
@ -709,6 +731,8 @@ void btc_gap_ble_cb_handler(btc_msg_t *msg)
case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT, param);
default:
break;

View file

@ -87,7 +87,7 @@ typedef enum {
BT_STATUS_UNHANDLED,
BT_STATUS_AUTH_FAILURE,
BT_STATUS_RMT_DEV_DOWN,
BT_STATUS_AUTH_REJECTED
BT_STATUS_AUTH_REJECTED,
} bt_status_t;
#ifndef CPU_LITTLE_ENDIAN

View file

@ -58,6 +58,7 @@ typedef bool BOOLEAN;
*/
#define BT_EVT_MASK 0xFF00
#define BT_SUB_EVT_MASK 0x00FF
#define BT_STATIC_RAND_ADDR_MASK 0xC0
/* To Bluetooth Upper Layers */
/************************************/
#define BT_EVT_TO_BTU_L2C_EVT 0x0900 /* L2CAP event */