From 66bb6a2f2b5847393a1d78d93fb2954f1049afb9 Mon Sep 17 00:00:00 2001 From: Yulong Date: Fri, 19 May 2017 05:23:00 -0400 Subject: [PATCH] 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. --- .../bt/bluedroid/api/include/esp_bt_defs.h | 13 +++++---- .../bluedroid/api/include/esp_gap_ble_api.h | 7 +++++ .../btc/profile/std/gap/btc_gap_ble.c | 28 +++++++++++++++++-- components/bt/bluedroid/include/bt_defs.h | 2 +- .../bt/bluedroid/stack/include/bt_types.h | 1 + 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/components/bt/bluedroid/api/include/esp_bt_defs.h b/components/bt/bluedroid/api/include/esp_bt_defs.h index 85b0aff99..9e9ee904a 100644 --- a/components/bt/bluedroid/api/include/esp_bt_defs.h +++ b/components/bt/bluedroid/api/include/esp_bt_defs.h @@ -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; diff --git a/components/bt/bluedroid/api/include/esp_gap_ble_api.h b/components/bt/bluedroid/api/include/esp_gap_ble_api.h index 45c14b509..66334fbc5 100644 --- a/components/bt/bluedroid/api/include/esp_gap_ble_api.h +++ b/components/bt/bluedroid/api/include/esp_gap_ble_api.h @@ -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; /** diff --git a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c index c07b16be9..12a8c7aab 100644 --- a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -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, ¶m, + 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; diff --git a/components/bt/bluedroid/include/bt_defs.h b/components/bt/bluedroid/include/bt_defs.h index 3f12d578a..a1bdf02fd 100644 --- a/components/bt/bluedroid/include/bt_defs.h +++ b/components/bt/bluedroid/include/bt_defs.h @@ -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 diff --git a/components/bt/bluedroid/stack/include/bt_types.h b/components/bt/bluedroid/stack/include/bt_types.h index fdcd15629..c60fd3542 100644 --- a/components/bt/bluedroid/stack/include/bt_types.h +++ b/components/bt/bluedroid/stack/include/bt_types.h @@ -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 */