OSDN Git Service

Merge commit '7e701dbd4375ee00c3b72d4bda970d444f20c470' into manual_merge_7e701db
authorAndre Eisenbach <eisenbach@google.com>
Thu, 29 Sep 2016 00:26:14 +0000 (17:26 -0700)
committerAndre Eisenbach <eisenbach@google.com>
Thu, 29 Sep 2016 00:26:14 +0000 (17:26 -0700)
Change-Id: I12e74839725fe33e6739517e454a0941aa4bd986

1  2 
stack/btm/btm_ble.c
stack/btm/btm_dev.c
stack/btm/btm_int.h

  #include "osi/include/log.h"
  #include "smp_api.h"
  
 -#if SMP_INCLUDED == TRUE
 -extern BOOLEAN aes_cipher_msg_auth_code(BT_OCTET16 key, UINT8 *input, UINT16 length,
 -                                                 UINT16 tlen, UINT8 *p_signature);
 -extern void smp_link_encrypted(BD_ADDR bda, UINT8 encr_enable);
 -extern BOOLEAN smp_proc_ltk_request(BD_ADDR bda);
 +#if (SMP_INCLUDED == TRUE)
 +extern bool    aes_cipher_msg_auth_code(BT_OCTET16 key, uint8_t *input, uint16_t length,
 +                                                 uint16_t tlen, uint8_t *p_signature);
 +extern void smp_link_encrypted(BD_ADDR bda, uint8_t encr_enable);
 +extern bool    smp_proc_ltk_request(BD_ADDR bda);
  #endif
  extern void gatt_notify_enc_cmpl(BD_ADDR bd_addr);
  /*******************************************************************************/
  /* External Function to be called by other modules                             */
  /*******************************************************************************/
  **                  bd_name          - Name of the peer device.  NULL if unknown.
  **                  features         - Remote device's features (up to 3 pages). NULL if not known
  **                  trusted_mask     - Bitwise OR of services that do not
 -**                                     require authorization. (array of UINT32)
 +**                                     require authorization. (array of uint32_t)
  **                  link_key         - Connection link key. NULL if unknown.
  **
 -** Returns          TRUE if added OK, else FALSE
 +** Returns          true if added OK, else false
  **
  *******************************************************************************/
 -BOOLEAN BTM_SecAddDevice (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name,
 -                          UINT8 *features, UINT32 trusted_mask[],
 -                          LINK_KEY link_key, UINT8 key_type, tBTM_IO_CAP io_cap,
 -                          UINT8 pin_length)
 +bool    BTM_SecAddDevice (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name,
 +                          uint8_t *features, uint32_t trusted_mask[],
 +                          LINK_KEY link_key, uint8_t key_type, tBTM_IO_CAP io_cap,
 +                          uint8_t pin_length)
  {
-     tBTM_SEC_DEV_REC  *p_dev_rec;
-     int               i, j;
-     bool              found = false;
      BTM_TRACE_API("%s: link key type:%x", __func__, key_type);
-     p_dev_rec = btm_find_dev (bd_addr);
+     tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr);
      if (!p_dev_rec)
      {
-         if (list_length(btm_cb.sec_dev_rec) > BTM_SEC_MAX_DEVICE_RECORDS) {
-             BTM_TRACE_DEBUG("%s: Max devices reached!", __func__);
-             return false;
-         }
-         BTM_TRACE_DEBUG ("%s: allocate a new dev rec", __func__);
-         p_dev_rec = osi_calloc(sizeof(tBTM_SEC_DEV_REC));
-         list_append(btm_cb.sec_dev_rec, p_dev_rec);
+         p_dev_rec = btm_sec_allocate_dev_rec();
  
          memcpy (p_dev_rec->bd_addr, bd_addr, BD_ADDR_LEN);
          p_dev_rec->hci_handle = BTM_GetHCIConnHandle (bd_addr, BT_TRANSPORT_BR_EDR);
      p_dev_rec->num_read_pages = 0;
      if (features)
      {
 -        BOOLEAN found = FALSE;
++        bool found = false;
          memcpy (p_dev_rec->features, features, sizeof (p_dev_rec->features));
-         for (i = HCI_EXT_FEATURES_PAGE_MAX; i >= 0; i--)
+         for (int i = HCI_EXT_FEATURES_PAGE_MAX; !found && i >= 0; i--)
          {
-             for (j = 0; j < HCI_FEATURE_BYTES_PER_PAGE; j++)
+             for (int j = 0; j < HCI_FEATURE_BYTES_PER_PAGE; j++)
              {
                  if (p_dev_rec->features[i][j] != 0)
                  {
 -                    found = TRUE;
 +                    found = true;
+                     p_dev_rec->num_read_pages = i + 1;
                      break;
                  }
              }
  **
  ** Parameters:      bd_addr          - BD address of the peer
  **
 -** Returns          TRUE if removed OK, FALSE if not found or ACL link is active
 +** Returns          true if removed OK, false if not found or ACL link is active
  **
  *******************************************************************************/
 -BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr)
 +bool    BTM_SecDeleteDevice (BD_ADDR bd_addr)
  {
-     tBTM_SEC_DEV_REC *p_dev_rec;
      if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE) ||
          BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_BR_EDR))
      {
          BTM_TRACE_WARNING("%s FAILED: Cannot Delete when connection is active", __func__);
 -        return FALSE;
 +        return false;
      }
  
-     if ((p_dev_rec = btm_find_dev(bd_addr)) != NULL)
+     tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(bd_addr);
+     if (p_dev_rec != NULL)
      {
          btm_sec_free_dev(p_dev_rec);
          /* Tell controller to get rid of the link key, if it has one stored */
@@@ -295,17 -276,11 +276,11 @@@ tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD
  *******************************************************************************/
  void btm_sec_free_dev (tBTM_SEC_DEV_REC *p_dev_rec)
  {
-     p_dev_rec->bond_type = BOND_TYPE_UNKNOWN;
-     p_dev_rec->sec_flags = 0;
 -#if BLE_INCLUDED == TRUE
 +#if (BLE_INCLUDED == TRUE)
      /* Clear out any saved BLE keys */
      btm_sec_clear_ble_keys (p_dev_rec);
-     /* clear the ble block */
-     memset(&p_dev_rec->ble, 0, sizeof(tBTM_SEC_BLE));
  #endif
+     list_remove(btm_cb.sec_dev_rec, p_dev_rec);
  }
  
  /*******************************************************************************
@@@ -533,14 -504,13 +504,13 @@@ tBTM_SEC_DEV_REC *btm_find_or_alloc_de
  ** Returns          Pointer to the record or NULL
  **
  *******************************************************************************/
tBTM_SEC_DEV_REC *btm_find_oldest_dev (void)
static tBTM_SEC_DEV_REC* btm_find_oldest_dev_rec (void)
  {
      tBTM_SEC_DEV_REC *p_oldest = NULL;
-     uint32_t     ot = 0xFFFFFFFF;
 -    UINT32       ts_oldest = 0xFFFFFFFF;
++    uint32_t ts_oldest = 0xFFFFFFFF;
      tBTM_SEC_DEV_REC *p_oldest_paired = NULL;
-     uint32_t     ot_paired = 0xFFFFFFFF;
 -    UINT32       ts_oldest_paired = 0xFFFFFFFF;
++    uint32_t ts_oldest_paired = 0xFFFFFFFF;
  
-     /* First look for the non-paired devices for the oldest entry */
      list_node_t *end = list_end(btm_cb.sec_dev_rec);
      for (list_node_t *node = list_begin(btm_cb.sec_dev_rec); node != end; node = list_next(node)) {
          tBTM_SEC_DEV_REC *p_dev_rec = list_node(node);
@@@ -201,15 -1055,16 +201,16 @@@ extern void btm_report_device_status (t
  /* Internal functions provided by btm_dev.c
  **********************************************
  */
 -extern BOOLEAN btm_dev_support_switch (BD_ADDR bd_addr);
 +extern bool    btm_dev_support_switch (BD_ADDR bd_addr);
  
+ extern tBTM_SEC_DEV_REC  *btm_sec_allocate_dev_rec(void);
  extern tBTM_SEC_DEV_REC  *btm_sec_alloc_dev (BD_ADDR bd_addr);
  extern void               btm_sec_free_dev (tBTM_SEC_DEV_REC *p_dev_rec);
 -extern tBTM_SEC_DEV_REC  *btm_find_dev (BD_ADDR bd_addr);
 +extern tBTM_SEC_DEV_REC  *btm_find_dev (const BD_ADDR bd_addr);
  extern tBTM_SEC_DEV_REC  *btm_find_or_alloc_dev (BD_ADDR bd_addr);
 -extern tBTM_SEC_DEV_REC  *btm_find_dev_by_handle (UINT16 handle);
 +extern tBTM_SEC_DEV_REC  *btm_find_dev_by_handle (uint16_t handle);
  extern tBTM_BOND_TYPE     btm_get_bond_type_dev(BD_ADDR bd_addr);
 -extern BOOLEAN            btm_set_bond_type_dev(BD_ADDR bd_addr,
 +extern bool               btm_set_bond_type_dev(BD_ADDR bd_addr,
                                                  tBTM_BOND_TYPE bond_type);
  
  /* Internal functions provided by btm_sec.c