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

Commit 60e27d55 authored by Pulkit Bhuwalka's avatar Pulkit Bhuwalka
Browse files

Add ability to modify IO capability of Bluetooth device

Redirects all access to Bluetooth IO capability from
macros. This allows it to be config determined but fall back to #define
values to maintain backward compatibility.

There is also the addition of methods to set IO capability properties.
Since these are done at the adapter level, it reuses
set_adapter_property from the bluetooth interface by adding new
property configs.

Bug: 36015413
Test: Created a test activity to modify values using the API and pair
with different settings. Default value is picked up from macro.

Change-Id: I7b80ea70cef4eacab91d20a58e745281aed273cd
(cherry picked from commit 7a5281f7ffe6860f15fcc088c63b1109f98c0e0e)
parent d3af716a
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -47,6 +47,11 @@ interface IBluetooth
    BluetoothClass getBluetoothClass();
    boolean setBluetoothClass(in BluetoothClass bluetoothClass);

    int getIoCapability();
    boolean setIoCapability(int capability);
    int getLeIoCapability();
    boolean setLeIoCapability(int capability);

    int getScanMode();
    boolean setScanMode(int mode, int duration);

+28 −19
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include "bta_dm_co.h"
#include "bta_dm_int.h"
#include "bta_sys.h"
#include "btif_storage.h"
#include "btm_api.h"
#include "btm_int.h"
#include "btu.h"
@@ -245,6 +246,9 @@ uint8_t g_disc_raw_data_buf[MAX_DISC_RAW_DATA_BUF];

extern DEV_CLASS local_device_default_class;

// Stores the local Input/Output Capabilities of the Bluetooth device.
static uint8_t btm_local_io_caps;

/** Initialises the BT device manager */
void bta_dm_enable(tBTA_DM_SEC_CBACK* p_sec_cback) {
  /* if already in use, return an error */
@@ -275,6 +279,8 @@ void bta_dm_enable(tBTA_DM_SEC_CBACK* p_sec_cback) {
  sys_enable_event->hw_module = BTA_SYS_HW_BLUETOOTH;

  bta_sys_sendmsg(sys_enable_event);

  btm_local_io_caps = btif_storage_get_local_io_caps();
}

/*******************************************************************************
@@ -2463,20 +2469,20 @@ static uint8_t bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data) {
  /* TODO_SP */
  switch (event) {
    case BTM_SP_IO_REQ_EVT:
#if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE)
      if (btm_local_io_caps != BTM_IO_CAP_NONE) {
        /* translate auth_req */
        bta_dm_co_io_req(p_data->io_req.bd_addr, &p_data->io_req.io_cap,
                         &p_data->io_req.oob_data, &p_data->io_req.auth_req,
                         p_data->io_req.is_orig);
#endif
      }
      APPL_TRACE_EVENT("io mitm: %d oob_data:%d", p_data->io_req.auth_req,
                       p_data->io_req.oob_data);
      break;
    case BTM_SP_IO_RSP_EVT:
#if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE)
      if (btm_local_io_caps != BTM_IO_CAP_NONE) {
        bta_dm_co_io_rsp(p_data->io_rsp.bd_addr, p_data->io_rsp.io_cap,
                         p_data->io_rsp.oob_data, p_data->io_rsp.auth_req);
#endif
      }
      break;

    case BTM_SP_CFM_REQ_EVT:
@@ -2489,12 +2495,16 @@ static uint8_t bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data) {
      sec_event.cfm_req.rmt_io_caps = p_data->cfm_req.rmt_io_caps;

    /* continue to next case */
#if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE)
    /* Passkey entry mode, mobile device with output capability is very
        unlikely to receive key request, so skip this event */
    /*case BTM_SP_KEY_REQ_EVT: */
    case BTM_SP_KEY_NOTIF_EVT:
#endif
      if (btm_local_io_caps == BTM_IO_CAP_NONE &&
          BTM_SP_KEY_NOTIF_EVT == event) {
        status = BTM_NOT_AUTHORIZED;
        break;
      }

      bta_dm_cb.num_val = sec_event.key_notif.passkey =
          p_data->key_notif.passkey;

@@ -3761,13 +3771,12 @@ static uint8_t bta_dm_ble_smp_cback(tBTM_LE_EVT event, const RawAddress& bda,
  memset(&sec_event, 0, sizeof(tBTA_DM_SEC));
  switch (event) {
    case BTM_LE_IO_REQ_EVT:
#if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE)

      if (btm_local_io_caps != BTM_IO_CAP_NONE) {
        bta_dm_co_ble_io_req(
            bda, &p_data->io_req.io_cap, &p_data->io_req.oob_data,
            &p_data->io_req.auth_req, &p_data->io_req.max_key_size,
            &p_data->io_req.init_keys, &p_data->io_req.resp_keys);
#endif
      }
      APPL_TRACE_EVENT("io mitm: %d oob_data:%d", p_data->io_req.auth_req,
                       p_data->io_req.oob_data);

+9 −2
Original line number Diff line number Diff line
@@ -25,12 +25,17 @@
#include "bta_sys.h"
#include "bte_appl.h"
#include "btif_dm.h"
#include "btif_storage.h"
#include "osi/include/osi.h"

// tBTE_APPL_CFG.ble_io_cap is set to BTM_IO_CAP_UNKNOWN at structure
// initialization since btif_storage isn't ready yet for data to be fetched.
// This value is initialized properly during first use by fetching properly
// from btif_storage.
tBTE_APPL_CFG bte_appl_cfg = {
    BTA_LE_AUTH_REQ_SC_MITM_BOND,  // Authentication requirements
    BTM_LOCAL_IO_CAPS_BLE, BTM_BLE_INITIATOR_KEY_SIZE,
    BTM_BLE_RESPONDER_KEY_SIZE, BTM_BLE_MAX_KEY_SIZE};
    BTM_IO_CAP_UNKNOWN, BTM_BLE_INITIATOR_KEY_SIZE, BTM_BLE_RESPONDER_KEY_SIZE,
    BTM_BLE_MAX_KEY_SIZE};

/*******************************************************************************
 *
@@ -241,6 +246,8 @@ void bta_dm_co_ble_io_req(const RawAddress& bd_addr, tBTA_IO_CAP* p_io_cap,
                          tBTA_LE_AUTH_REQ* p_auth_req, uint8_t* p_max_key_size,
                          tBTA_LE_KEY_TYPE* p_init_key,
                          tBTA_LE_KEY_TYPE* p_resp_key) {
  bte_appl_cfg.ble_io_cap = btif_storage_get_local_io_caps_ble();

  /* Retrieve the properties from file system if possible */
  tBTE_APPL_CFG nv_config;
  if (btif_dm_get_smp_config(&nv_config)) bte_appl_cfg = nv_config;
+26 −0
Original line number Diff line number Diff line
@@ -97,6 +97,32 @@ bt_status_t btif_storage_get_remote_device_property(
bt_status_t btif_storage_set_remote_device_property(
    const RawAddress* remote_bd_addr, bt_property_t* property);

/*******************************************************************************
 *
 * Function         btif_storage_get_io_caps
 *
 * Description      BTIF storage API - Fetches the local Input/Output
 *                  capabilities of the device.
 *
 * Returns          Returns local IO Capability of device. If not stored,
 *                  returns BTM_LOCAL_IO_CAPS.
 *
 ******************************************************************************/
uint8_t btif_storage_get_local_io_caps();

/*******************************************************************************
 *
 * Function         btif_storage_get_io_caps_ble
 *
 * Description      BTIF storage API - Fetches the local Input/Output
 *                  capabilities of the BLE device.
 *
 * Returns          Returns local IO Capability of BLE device. If not stored,
 *                  returns BTM_LOCAL_IO_CAPS_BLE.
 *
 ******************************************************************************/
uint8_t btif_storage_get_local_io_caps_ble();

/*******************************************************************************
 *
 * Function         btif_storage_add_remote_device
+23 −1
Original line number Diff line number Diff line
@@ -618,7 +618,8 @@ bt_status_t btif_dut_mode_send(uint16_t opcode, uint8_t* buf, uint8_t len) {
 ****************************************************************************/

static bt_status_t btif_in_get_adapter_properties(void) {
  bt_property_t properties[6];
  const static uint32_t NUM_ADAPTER_PROPERTIES = 8;
  bt_property_t properties[NUM_ADAPTER_PROPERTIES];
  uint32_t num_props = 0;

  RawAddress addr;
@@ -628,6 +629,8 @@ static bt_status_t btif_in_get_adapter_properties(void) {
  RawAddress bonded_devices[BTM_SEC_MAX_DEVICE_RECORDS];
  Uuid local_uuids[BT_MAX_NUM_UUIDS];
  bt_status_t status;
  bt_io_cap_t local_bt_io_cap;
  bt_io_cap_t local_bt_io_cap_ble;

  /* RawAddress */
  BTIF_STORAGE_FILL_PROPERTY(&properties[num_props], BT_PROPERTY_BDADDR,
@@ -672,6 +675,18 @@ static bt_status_t btif_in_get_adapter_properties(void) {
  btif_storage_get_adapter_property(&properties[num_props]);
  num_props++;

  /* LOCAL IO Capabilities */
  BTIF_STORAGE_FILL_PROPERTY(&properties[num_props], BT_PROPERTY_LOCAL_IO_CAPS,
                             sizeof(bt_io_cap_t), &local_bt_io_cap);
  btif_storage_get_adapter_property(&properties[num_props]);
  num_props++;

  BTIF_STORAGE_FILL_PROPERTY(&properties[num_props],
                             BT_PROPERTY_LOCAL_IO_CAPS_BLE, sizeof(bt_io_cap_t),
                             &local_bt_io_cap_ble);
  btif_storage_get_adapter_property(&properties[num_props]);
  num_props++;

  HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, BT_STATUS_SUCCESS, num_props,
            properties);

@@ -1022,6 +1037,13 @@ bt_status_t btif_set_adapter_property(const bt_property_t* property) {
       * BTA events */
      status = BT_STATUS_FAIL;
      break;
    case BT_PROPERTY_LOCAL_IO_CAPS:
    case BT_PROPERTY_LOCAL_IO_CAPS_BLE: {
      // Changing IO Capability of stack at run-time is not currently supported.
      // This call changes the stored value which will affect the stack next
      // time it starts up.
      storage_req_id = BTIF_CORE_STORAGE_ADAPTER_WRITE;
    } break;
    default:
      BTIF_TRACE_ERROR("btif_get_adapter_property : invalid type %d",
                       property->type);
Loading