From fc05851b054477c1e54d7ae121e10502d3ce2329 Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Wed, 19 Jul 2017 14:50:40 +0800 Subject: [PATCH] Component/bt: add set local privacy func callback --- .../bluedroid/api/include/esp_gap_ble_api.h | 7 ++++ components/bt/bluedroid/bta/dm/bta_dm_act.c | 2 +- components/bt/bluedroid/bta/dm/bta_dm_api.c | 4 +-- components/bt/bluedroid/bta/dm/bta_dm_int.h | 1 + components/bt/bluedroid/bta/include/bta_api.h | 6 ++-- .../btc/profile/std/gap/btc_gap_ble.c | 32 +++++++++++++++++-- .../bt/bluedroid/stack/btm/btm_ble_addr.c | 8 +++++ .../bt/bluedroid/stack/btm/btm_ble_gap.c | 8 ++++- .../bt/bluedroid/stack/include/btm_api.h | 6 +++- .../bt/bluedroid/stack/include/btm_ble_api.h | 2 +- .../bt/bluedroid/stack/include/btm_ble_int.h | 1 + 11 files changed, 66 insertions(+), 11 deletions(-) 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 0492bd5d8..29be0982f 100644 --- a/components/bt/bluedroid/api/include/esp_gap_ble_api.h +++ b/components/bt/bluedroid/api/include/esp_gap_ble_api.h @@ -93,6 +93,7 @@ typedef enum { ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT, /*!< When set the static rand address complete, the event comes */ ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT, /*!< When update connection parameters complete, the event comes */ ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT, /*!< When set pkt lenght complete, the event comes */ + ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT, /*!< When Enable/disable privacy on the local device complete, the event comes */ } esp_gap_ble_cb_event_t; /// Advertising data maximum length @@ -539,6 +540,12 @@ typedef union { esp_bt_status_t status; /*!< Indicate the set pkt data length operation success status */ esp_ble_pkt_data_length_params_t params; /*!< pkt data length value */ } pkt_data_lenth_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT + */ + struct ble_local_privacy_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate the set local privacy operation success status */ + } local_privacy_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT */ } esp_ble_gap_cb_param_t; /** diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index 39a5f06d3..49289a9ab 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -4601,7 +4601,7 @@ void bta_dm_ble_stop_advertising(tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_ble_config_local_privacy (tBTA_DM_MSG *p_data) { - BTM_BleConfigPrivacy (p_data->ble_local_privacy.privacy_enable); + BTM_BleConfigPrivacy (p_data->ble_local_privacy.privacy_enable, p_data->ble_local_privacy.set_local_privacy_cback); } #endif diff --git a/components/bt/bluedroid/bta/dm/bta_dm_api.c b/components/bt/bluedroid/bta/dm/bta_dm_api.c index 7ef088761..fcb27004f 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_api.c @@ -1575,7 +1575,7 @@ void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int, ** Returns void ** *******************************************************************************/ -void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable) +void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback) { ///This function used the irk to generate the resolve address #if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE @@ -1586,7 +1586,7 @@ void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable) p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT; p_msg->privacy_enable = privacy_enable; - + p_msg->set_local_privacy_cback = set_local_privacy_cback; bta_sys_sendmsg(p_msg); } #else diff --git a/components/bt/bluedroid/bta/dm/bta_dm_int.h b/components/bt/bluedroid/bta/dm/bta_dm_int.h index 735778137..e4bf0fadb 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_int.h +++ b/components/bt/bluedroid/bta/dm/bta_dm_int.h @@ -444,6 +444,7 @@ typedef struct { typedef struct { BT_HDR hdr; BOOLEAN privacy_enable; + tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback; } tBTA_DM_API_LOCAL_PRIVACY; /* set scan parameter for BLE connections */ diff --git a/components/bt/bluedroid/bta/include/bta_api.h b/components/bt/bluedroid/bta/include/bta_api.h index f21803b1c..1313b90c8 100644 --- a/components/bt/bluedroid/bta/include/bta_api.h +++ b/components/bt/bluedroid/bta/include/bta_api.h @@ -404,6 +404,8 @@ typedef void (tBTA_START_ADV_CMPL_CBACK) (tBTA_STATUS status); typedef tBTM_SET_PKT_DATA_LENGTH_CBACK tBTA_SET_PKT_DATA_LENGTH_CBACK; +typedef tBTM_SET_LOCAL_PRIVACY_CBACK tBTA_SET_LOCAL_PRIVACY_CBACK; + /* advertising channel map */ #define BTA_BLE_ADV_CHNL_37 BTM_BLE_ADV_CHNL_37 #define BTA_BLE_ADV_CHNL_38 BTM_BLE_ADV_CHNL_38 @@ -2035,11 +2037,11 @@ extern void BTA_DmSetRandAddress(BD_ADDR rand_addr); ** Description Enable/disable privacy on the local device ** ** Parameters: privacy_enable - enable/disabe privacy on remote device. -** +** set_local_privacy_cback -callback to be called with result ** Returns void ** *******************************************************************************/ -extern void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable); +extern void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback); /******************************************************************************* ** 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 3863d5e3c..1e551b6f8 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 @@ -145,6 +145,12 @@ static esp_bt_status_t btc_btm_status_to_esp_status (uint8_t btm_status) case BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED: esp_status = ESP_BT_STATUS_CONTROL_LE_DATA_LEN_UNSUPPORTED; break; + case BTM_SET_PRIVACY_SUCCESS: + esp_status = ESP_BT_STATUS_SUCCESS; + break; + case BTM_SET_PRIVACY_FAIL: + esp_status = ESP_BT_STATUS_FAIL; + break; default: esp_status = ESP_BT_STATUS_FAIL; break; @@ -661,6 +667,23 @@ static void btc_set_pkt_length_callback(UINT8 status, tBTM_LE_SET_PKT_DATA_LENGT } } +static void btc_set_local_privacy_callback(UINT8 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_SET_LOCAL_PRIVACY_COMPLETE_EVT; + param.local_privacy_cmpl.status = btc_btm_status_to_esp_status(status); + 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__); + } +} + #if (SMP_INCLUDED == TRUE) static void btc_set_encryption_callback(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_STATUS enc_status) @@ -756,9 +779,9 @@ static void btc_ble_set_rand_addr (BD_ADDR rand_addr) } } -static void btc_ble_config_local_privacy(bool privacy_enable) +static void btc_ble_config_local_privacy(bool privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback) { - BTA_DmBleConfigLocalPrivacy(privacy_enable); + BTA_DmBleConfigLocalPrivacy(privacy_enable, set_local_privacy_cback); } static void btc_ble_disconnect(BD_ADDR bd_addr) @@ -837,6 +860,9 @@ void btc_gap_ble_cb_handler(btc_msg_t *msg) case ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT: btc_gap_ble_cb_to_app(ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT, param); break; + case ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT: + btc_gap_ble_cb_to_app(ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT, param); + break; default: break; @@ -1000,7 +1026,7 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) break; } case BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY: - btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable); + btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable, btc_set_local_privacy_callback); break; case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW: btc_ble_set_adv_data_raw(arg->cfg_adv_data_raw.raw_adv, diff --git a/components/bt/bluedroid/stack/btm/btm_ble_addr.c b/components/bt/bluedroid/stack/btm/btm_ble_addr.c index 4f6c443a5..cfc963275 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_addr.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_addr.c @@ -60,6 +60,10 @@ static void btm_gen_resolve_paddr_cmpl(tSMP_ENC *p) btsnd_hcic_ble_set_random_addr(p_cb->private_addr); p_cb->own_addr_type = BLE_ADDR_RANDOM; + if (p_cb->set_local_privacy_cback){ + (*p_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_SUCCESS); + p_cb->set_local_privacy_cback = NULL; + } /* start a periodical timer to refresh random addr */ btu_stop_timer_oneshot(&p_cb->raddr_timer_ent); @@ -73,6 +77,10 @@ static void btm_gen_resolve_paddr_cmpl(tSMP_ENC *p) } else { /* random address set failure */ BTM_TRACE_DEBUG("set random address failed"); + if (p_cb->set_local_privacy_cback){ + (*p_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_FAIL); + p_cb->set_local_privacy_cback = NULL; + } } } /******************************************************************************* diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index 523137aa0..1029977cb 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -640,10 +640,16 @@ void BTM_BleEnableMixedPrivacyMode(BOOLEAN mixed_on) ** Returns BOOLEAN privacy mode set success; otherwise failed. ** *******************************************************************************/ -BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode) +BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode, tBTM_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback) { #if BLE_PRIVACY_SPT == TRUE tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; + tBTM_LE_RANDOM_CB *random_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; + if (random_cb){ + random_cb->set_local_privacy_cback = set_local_privacy_cback; + }else{ + BTM_TRACE_ERROR("%s,random_cb = NULL", __func__); + } BTM_TRACE_EVENT ("%s\n", __func__); diff --git a/components/bt/bluedroid/stack/include/btm_api.h b/components/bt/bluedroid/stack/include/btm_api.h index 2976e497e..4af3a4863 100644 --- a/components/bt/bluedroid/stack/include/btm_api.h +++ b/components/bt/bluedroid/stack/include/btm_api.h @@ -69,7 +69,9 @@ enum { BTM_REPEATED_ATTEMPTS, /* 19 repeated attempts for LE security requests */ BTM_MODE4_LEVEL4_NOT_SUPPORTED, /* 20 Secure Connections Only Mode can't be supported */ BTM_PEER_LE_DATA_LEN_UNSUPPORTED, /* 21 peer setting data length is unsupported*/ - BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED /* 22 controller setting data length is unsupported*/ + BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED,/* 22 controller setting data length is unsupported*/ + BTM_SET_PRIVACY_SUCCESS, /* 23 enable/disable local privacy success */ + BTM_SET_PRIVACY_FAIL, /* 24 enable/disable local privacy failed*/ }; typedef uint8_t tBTM_STATUS; @@ -175,6 +177,8 @@ typedef void (tBTM_UPDATE_CONN_PARAM_CBACK) (UINT8 status, BD_ADDR bd_addr, tBTM typedef void (tBTM_SET_PKT_DATA_LENGTH_CBACK) (UINT8 status, tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS *data_length_params); +typedef void (tBTM_SET_LOCAL_PRIVACY_CBACK) (UINT8 status); + /***************************************************************************** ** DEVICE DISCOVERY - Inquiry, Remote Name, Discovery, Class of Device diff --git a/components/bt/bluedroid/stack/include/btm_ble_api.h b/components/bt/bluedroid/stack/include/btm_ble_api.h index 927812453..dda03d181 100644 --- a/components/bt/bluedroid/stack/include/btm_ble_api.h +++ b/components/bt/bluedroid/stack/include/btm_ble_api.h @@ -1596,7 +1596,7 @@ tBTM_STATUS BTM_BleBroadcast(BOOLEAN start); ** *******************************************************************************/ //extern -BOOLEAN BTM_BleConfigPrivacy(BOOLEAN enable); +BOOLEAN BTM_BleConfigPrivacy(BOOLEAN enable, tBTM_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cabck); /******************************************************************************* ** diff --git a/components/bt/bluedroid/stack/include/btm_ble_int.h b/components/bt/bluedroid/stack/include/btm_ble_int.h index 055591d77..60684bdb3 100644 --- a/components/bt/bluedroid/stack/include/btm_ble_int.h +++ b/components/bt/bluedroid/stack/include/btm_ble_int.h @@ -185,6 +185,7 @@ typedef struct { tBTM_BLE_ADDR_CBACK *p_generate_cback; void *p; TIMER_LIST_ENT raddr_timer_ent; + tBTM_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback; } tBTM_LE_RANDOM_CB; #define BTM_BLE_MAX_BG_CONN_DEV_NUM 10