OSDN Git Service

Use device privacy mode as default
authorJakub Pawlowski <jpawlowski@google.com>
Fri, 7 Apr 2017 13:19:50 +0000 (06:19 -0700)
committerJakub Pawlowski <jpawlowski@google.com>
Sat, 8 Apr 2017 05:23:41 +0000 (05:23 +0000)
This change configures device privacy mode for each
remote device added to the resolving list.
Before exercising the privacy command it confirms
whether the set privacy HCI command is supported.

This patch is based on CAF patch by niarora@codeaurora.org
36fa3c528d2ae58e0b3f969665e3d25986dcdbaa

Test: manual
Bug: 35935853
Change-Id: I839045ccc3ddb73dc9c0cbe05d87c25dae9b9236

stack/btm/btm_ble_privacy.cc
stack/hcic/hciblecmds.cc
stack/include/hcidefs.h
stack/include/hcimsgs.h

index 1d735cd..a00b2df 100644 (file)
@@ -710,6 +710,12 @@ bool btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC* p_dev_rec) {
           btsnd_hcic_ble_add_device_resolving_list(
               p_dev_rec->ble.static_addr_type, p_dev_rec->ble.static_addr,
               peer_irk, local_irk);
+
+          if (controller_get_interface()->supports_ble_privacy()) {
+            BTM_TRACE_DEBUG("%s: adding device privacy mode", __func__);
+            btsnd_hcic_ble_set_privacy_mode(p_dev_rec->ble.static_addr_type,
+                                            p_dev_rec->ble.static_addr, 0x01);
+          }
         } else {
           uint8_t param[40] = {0};
           uint8_t* p = param;
index 2b410af..330764b 100644 (file)
@@ -595,6 +595,23 @@ void btsnd_hcic_ble_rm_device_resolving_list(uint8_t addr_type_peer,
   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
 }
 
+void btsnd_hcic_ble_set_privacy_mode(uint8_t addr_type_peer, BD_ADDR bda_peer,
+                                     uint8_t privacy_type) {
+  BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
+  uint8_t* pp = (uint8_t*)(p + 1);
+
+  p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_PRIVACY_MODE;
+  p->offset = 0;
+
+  UINT16_TO_STREAM(pp, HCI_BLE_SET_PRIVACY_MODE);
+  UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_PRIVACY_MODE);
+  UINT8_TO_STREAM(pp, addr_type_peer);
+  BDADDR_TO_STREAM(pp, bda_peer);
+  UINT8_TO_STREAM(pp, privacy_type);
+
+  btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
+}
+
 void btsnd_hcic_ble_clear_resolving_list(void) {
   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
   uint8_t* pp = (uint8_t*)(p + 1);
index e51c773..92421fa 100644 (file)
 #define HCI_LE_SET_EXTENDED_SCAN_PARAMETERS (0x0041 | HCI_GRP_BLE_CMDS)
 #define HCI_LE_SET_EXTENDED_SCAN_ENABLE (0x0042 | HCI_GRP_BLE_CMDS)
 #define HCI_LE_EXTENDED_CREATE_CONNECTION (0x0043 | HCI_GRP_BLE_CMDS)
+#define HCI_BLE_SET_PRIVACY_MODE (0x004E | HCI_GRP_BLE_CMDS)
 
 /* LE Get Vendor Capabilities Command OCF */
 #define HCI_BLE_VENDOR_CAP_OCF (0x0153 | HCI_GRP_VENDOR_SPECIFIC)
index f7ecdef..80a0387 100644 (file)
@@ -676,6 +676,7 @@ extern void btsnd_hcic_vendor_spec_cmd(void* buffer, uint16_t opcode,
 
 #define HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST (7 + HCIC_BLE_IRK_SIZE * 2)
 #define HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST 7
+#define HCIC_PARAM_SIZE_BLE_SET_PRIVACY_MODE 8
 #define HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST 0
 #define HCIC_PARAM_SIZE_BLE_READ_RESOLVING_LIST_SIZE 0
 #define HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER 7
@@ -835,6 +836,10 @@ extern void btsnd_hcic_ble_add_device_resolving_list(
 extern void btsnd_hcic_ble_rm_device_resolving_list(uint8_t addr_type_peer,
                                                     BD_ADDR bda_peer);
 
+extern void btsnd_hcic_ble_set_privacy_mode(uint8_t addr_type_peer,
+                                            BD_ADDR bda_peer,
+                                            uint8_t privacy_type);
+
 extern void btsnd_hcic_ble_clear_resolving_list(void);
 
 extern void btsnd_hcic_ble_read_resolvable_addr_peer(uint8_t addr_type_peer,