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

Commit 3bf2a28d authored by Archie Pusaka's avatar Archie Pusaka
Browse files

floss: Add Appearance field to bt_property list

Floss needs this field from the EIR in order to emulate how metrics
work in BlueZ. Therefore, store the appearance into storage, and pass
it with the callback for Floss only.

Bug: 240782193
Tag: #floss
Test: Verify Appearance field in /var/lib/bluetooth/bt_config.conf
      after pairing with an LE mouse.

Change-Id: Iac4f2fea7f1f4f711b3f99a7d416799831b1f948
parent 19a91c3e
Loading
Loading
Loading
Loading
+43 −1
Original line number Diff line number Diff line
@@ -395,6 +395,39 @@ static bool check_eir_remote_name(tBTA_DM_SEARCH* p_search_data,
  return false;
}

/*******************************************************************************
 *
 * Function         check_eir_appearance
 *
 * Description      Check if appearance is in the EIR data
 *
 * Returns          true if appearance found
 *                  Populate p_appearance, if provided and appearance found
 *
 ******************************************************************************/
static bool check_eir_appearance(tBTA_DM_SEARCH* p_search_data,
                                 uint16_t* p_appearance) {
  const uint8_t* p_eir_appearance = NULL;
  uint8_t appearance_len = 0;

  /* Check EIR for remote name and services */
  if (p_search_data->inq_res.p_eir) {
    p_eir_appearance = AdvertiseDataParser::GetFieldByType(
        p_search_data->inq_res.p_eir, p_search_data->inq_res.eir_len,
        HCI_EIR_APPEARANCE_TYPE, &appearance_len);

    if (p_eir_appearance) {
      if (p_appearance) {
        *p_appearance = *((uint16_t*)p_eir_appearance);
      }

      return true;
    }
  }

  return false;
}

/*******************************************************************************
 *
 * Function         check_cached_remote_name
@@ -1234,7 +1267,7 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
      }

      {
        bt_property_t properties[7];
        bt_property_t properties[8];
        bt_device_type_t dev_type;
        uint32_t num_properties = 0;
        bt_status_t status;
@@ -1334,6 +1367,15 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
#endif
        }

        // Floss needs appearance for metrics purposes
        uint16_t appearance = 0;
        if (check_eir_appearance(p_search_data, &appearance)) {
          BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
                                     BT_PROPERTY_APPEARANCE, sizeof(appearance),
                                     &appearance);
          num_properties++;
        }

        status =
            btif_storage_add_remote_device(&bdaddr, num_properties, properties);
        ASSERTC(status == BT_STATUS_SUCCESS,
+22 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ using bluetooth::groups::DeviceGroups;
#define BTIF_STORAGE_PATH_REMOTE_DEVCLASS "DevClass"
#define BTIF_STORAGE_PATH_REMOTE_DEVTYPE "DevType"
#define BTIF_STORAGE_PATH_REMOTE_NAME "Name"
#define BTIF_STORAGE_PATH_REMOTE_APPEARANCE "Appearance"

//#define BTIF_STORAGE_PATH_REMOTE_LINKKEYS "remote_linkkeys"
#define BTIF_STORAGE_PATH_REMOTE_ALIASE "Aliase"
@@ -281,6 +282,10 @@ static int prop2cfg(const RawAddress* remote_bd_addr, bt_property_t* prop) {
      btif_config_set_int(bdstr, BT_CONFIG_KEY_REMOTE_VER_SUBVER,
                          info->sub_ver);
    } break;
    case BT_PROPERTY_APPEARANCE: {
      int val = *(uint16_t*)prop->val;
      btif_config_set_int(bdstr, BTIF_STORAGE_PATH_REMOTE_APPEARANCE, val);
    } break;

    default:
      BTIF_TRACE_ERROR("Unknown prop type:%d", prop->type);
@@ -407,6 +412,16 @@ static int cfg2prop(const RawAddress* remote_bd_addr, bt_property_t* prop) {
      }
    } break;

    case BT_PROPERTY_APPEARANCE: {
      int val;

      if (prop->len >= (int)sizeof(uint16_t)) {
        ret = btif_config_get_int(bdstr, BTIF_STORAGE_PATH_REMOTE_APPEARANCE,
                                  &val);
        *(uint16_t*)prop->val = (uint16_t)val;
      }
    } break;

    default:
      BTIF_TRACE_ERROR("Unknow prop type:%d", prop->type);
      return false;
@@ -1132,6 +1147,13 @@ bt_status_t btif_storage_load_bonded_devices(void) {
                                   remote_properties[num_props]);
      num_props++;

      // Floss needs appearance for metrics purposes
      uint16_t appearance = 0;
      BTIF_STORAGE_GET_REMOTE_PROP(p_remote_addr, BT_PROPERTY_APPEARANCE,
                                   &appearance, sizeof(appearance),
                                   remote_properties[num_props]);
      num_props++;

      btif_remote_properties_evt(BT_STATUS_SUCCESS, p_remote_addr, num_props,
                                 remote_properties);
    }
+7 −0
Original line number Diff line number Diff line
@@ -340,6 +340,13 @@ typedef enum {
   */
  BT_PROPERTY_REMOTE_IS_COORDINATED_SET_MEMBER,

  /**
   * Description - Appearance as specified in Assigned Numbers.
   * Access mode - GET.
   * Data Type - uint16_t.
   */
  BT_PROPERTY_APPEARANCE,

  BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
} bt_property_type_t;

+1 −0
Original line number Diff line number Diff line
@@ -734,6 +734,7 @@ typedef enum : uint16_t {
#define HCI_EIR_OOB_SSP_HASH_C_TYPE 0x0E
#define HCI_EIR_OOB_SSP_RAND_R_TYPE 0x0F
#define HCI_EIR_RSI_TYPE 0x2E
#define HCI_EIR_APPEARANCE_TYPE 0x19

/* Definitions for Write Simple Pairing Mode */
#define HCI_SP_MODE_ENABLED 0x01