Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ecc2ea9f authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Andre Eisenbach
Browse files

BLE OOB Pairing - parse address type (1/5)

When address type is not parsed, creating bond to devices not using
random address is impossible.

Bug: 32780409
Test: try pairing with nRF52DK using random address
Change-Id: I95c4ebc7bd03cd1b895c9f17deef2e57d8b57d2a
parent f5491b87
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -672,7 +672,15 @@ static void btif_dm_cb_create_bond(bt_bdaddr_t* bd_addr,
    }
    if (btif_storage_get_remote_addr_type(bd_addr, &addr_type) !=
        BT_STATUS_SUCCESS) {
      btif_storage_set_remote_addr_type(bd_addr, BLE_ADDR_PUBLIC);

      // Try to read address type. OOB pairing might have set it earlier, but
      // didn't store it, it defaults to BLE_ADDR_PUBLIC
      uint8_t tmp_dev_type;
      uint8_t tmp_addr_type;
      BTM_ReadDevInfo(bd_addr->address, &tmp_dev_type, &tmp_addr_type);
      addr_type = tmp_addr_type;

      btif_storage_set_remote_addr_type(bd_addr, addr_type);
    }
  }
  if ((btif_config_get_int((char const*)&bdstr, "DevType", &device_type) &&
@@ -2292,6 +2300,19 @@ bt_status_t btif_dm_create_bond_out_of_band(
  bdcpy(oob_cb.bdaddr, bd_addr->address);
  memcpy(&oob_cb.oob_data, oob_data, sizeof(bt_out_of_band_data_t));

  uint8_t empty[] = {0, 0, 0, 0, 0, 0, 0};
  // If LE Bluetooth Device Address is provided, use provided address type
  // value.
  if (memcmp(oob_data->le_bt_dev_addr, empty, 7) != 0) {
    /* byte no 7 is address type in LE Bluetooth Address OOB data */
    uint8_t address_type = oob_data->le_bt_dev_addr[6];
    if (address_type == BLE_ADDR_PUBLIC || address_type == BLE_ADDR_RANDOM) {
      // bd_addr->address is already reversed, so use it instead of
      // oob_data->le_bt_dev_addr
      BTM_SecAddBleDevice(bd_addr->address, NULL, BT_DEVICE_TYPE_BLE, address_type);
    }
  }

  bdstr_t bdstr;
  BTIF_TRACE_EVENT("%s: bd_addr=%s, transport=%d", __func__,
                   bdaddr_to_string(bd_addr, bdstr, sizeof(bdstr)), transport);
+1 −1
Original line number Diff line number Diff line
@@ -1388,7 +1388,7 @@ uint16_t btm_get_acl_disc_reason_code (void)
** Returns          the handle of the connection, or 0xFFFF if none.
**
*******************************************************************************/
uint16_t BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport)
uint16_t BTM_GetHCIConnHandle (const BD_ADDR remote_bda, tBT_TRANSPORT transport)
{
    tACL_CONN   *p;
    BTM_TRACE_DEBUG ("BTM_GetHCIConnHandle");
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ extern bool aes_cipher_msg_auth_code(BT_OCTET16 key, uint8_t *input, uint16_t
** Returns          true if added OK, else false
**
*******************************************************************************/
bool    BTM_SecAddBleDevice (BD_ADDR bd_addr, BD_NAME bd_name, tBT_DEVICE_TYPE dev_type,
bool    BTM_SecAddBleDevice (const BD_ADDR bd_addr, BD_NAME bd_name, tBT_DEVICE_TYPE dev_type,
                             tBLE_ADDR_TYPE addr_type)
{
    BTM_TRACE_DEBUG ("%s: dev_type=0x%x", __func__, dev_type);
+1 −1
Original line number Diff line number Diff line
@@ -1851,7 +1851,7 @@ extern tBTM_STATUS BTM_SetSsrParams (BD_ADDR remote_bda, uint16_t max_lat,
** Returns          the handle of the connection, or 0xFFFF if none.
**
*******************************************************************************/
extern uint16_t BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport);
extern uint16_t BTM_GetHCIConnHandle (const BD_ADDR remote_bda, tBT_TRANSPORT transport);

/*******************************************************************************
**
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ tBTM_BLE_SCAN_SETUP_CBACK bta_ble_scan_setup_cb;
** Returns          true if added OK, else false
**
*******************************************************************************/
extern bool    BTM_SecAddBleDevice (BD_ADDR bd_addr, BD_NAME bd_name,
extern bool    BTM_SecAddBleDevice (const BD_ADDR bd_addr, BD_NAME bd_name,
                                           tBT_DEVICE_TYPE dev_type, tBLE_ADDR_TYPE addr_type);

/*******************************************************************************