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

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

Always use big endian for keeping service UUID

When adding services to GATT database, applications should always provide
it in big endian format.

Bug: 32750783
Change-Id: I5264357bdbb6bab453b63baae6563cde86d20bac
parent f9dbfb6a
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -78,8 +78,6 @@ void uuid_to_string(const bt_uuid_t *uuid, uuid_string_t *uuid_string);
bool uuid_128_to_16(const bt_uuid_t *uuid, uint16_t *uuid16);
bool uuid_128_to_32(const bt_uuid_t *uuid, uint32_t *uuid32);

void uuid_128_from_16(bt_uuid_t *uuid, uint16_t uuid16);

#ifdef __cplusplus
}
#endif
+0 −9
Original line number Diff line number Diff line
@@ -125,15 +125,6 @@ bool uuid_128_to_32(const bt_uuid_t *uuid, uint32_t *uuid32) {
  return true;
}

void uuid_128_from_16(bt_uuid_t *uuid, uint16_t uuid16) {
  assert(uuid != NULL);

  memcpy(uuid, &base_uuid, sizeof(bt_uuid_t));

  uuid->uu[2] = (uint8_t)((0xFF00 & uuid16)>>8);
  uuid->uu[3] = (uint8_t)(0x00FF & uuid16);
}

void uuid_to_string(const bt_uuid_t *uuid, uuid_string_t *uuid_string) {
  assert(uuid != NULL);
  assert(uuid_string != NULL);
+0 −25
Original line number Diff line number Diff line
@@ -136,31 +136,6 @@ TEST_F(UuidTest, uuid_128_to_32) {
  EXPECT_EQ((uint32_t)0, uuid32);
}

TEST_F(UuidTest, uuid_128_from_16) {
  bt_uuid_t *uuid = NULL;
  uint16_t uuid16 = 0x1234;

  uuid = uuid_new(UUID_ONES);
  uuid_128_from_16(uuid, uuid16);
  EXPECT_EQ(0x00, uuid->uu[0]);
  EXPECT_EQ(0x00, uuid->uu[1]);
  EXPECT_EQ(0x12, uuid->uu[2]);
  EXPECT_EQ(0x34, uuid->uu[3]);
  EXPECT_EQ(0x00, uuid->uu[4]);
  EXPECT_EQ(0x00, uuid->uu[5]);
  EXPECT_EQ(0x10, uuid->uu[6]);
  EXPECT_EQ(0x00, uuid->uu[7]);
  EXPECT_EQ(0x80, uuid->uu[8]);
  EXPECT_EQ(0x00, uuid->uu[9]);
  EXPECT_EQ(0x00, uuid->uu[10]);
  EXPECT_EQ(0x80, uuid->uu[11]);
  EXPECT_EQ(0x5f, uuid->uu[12]);
  EXPECT_EQ(0x9b, uuid->uu[13]);
  EXPECT_EQ(0x34, uuid->uu[14]);
  EXPECT_EQ(0xfb, uuid->uu[15]);
  uuid_free(uuid);
}

TEST_F(UuidTest, uuid_to_string) {
  bt_uuid_t *uuid = NULL;

+15 −9
Original line number Diff line number Diff line
@@ -120,16 +120,14 @@ bool GATTS_NVRegister (tGATT_APPL_INFO *p_cb_info)
    return status;
}


static unsigned char BASE_UUID[16] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
    0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb, };
static uint8_t BASE_UUID[16] = {0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
                                0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

static int uuidType(unsigned char* p_uuid)
{
    if (memcmp(p_uuid+4, BASE_UUID+4, 12) != 0)
    if (memcmp(p_uuid, BASE_UUID, 12) != 0)
        return LEN_UUID_128;
    if (memcmp(p_uuid, BASE_UUID, 2) != 0)
    if (memcmp(p_uuid + 14, BASE_UUID + 14, 2) != 0)
        return LEN_UUID_32;

    return LEN_UUID_16;
@@ -149,12 +147,12 @@ static void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src)
    switch (p_dest->len)
    {
        case LEN_UUID_16:
            p_dest->uu.uuid16 = (p_src->uu[2] << 8) + p_src->uu[3];
            p_dest->uu.uuid16 = (p_src->uu[13] << 8) + p_src->uu[12];
            break;

        case LEN_UUID_32:
            p_dest->uu.uuid32  = (p_src->uu[0] << 24) + (p_src->uu[1] << 16)
                               + (p_src->uu[2] <<  8) + p_src->uu[3];
            p_dest->uu.uuid32  = (p_src->uu[15] << 24) + (p_src->uu[14] << 16)
                               + (p_src->uu[13] <<  8) + p_src->uu[12];
            break;

        case LEN_UUID_128:
@@ -168,6 +166,14 @@ static void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src)
    }
}

void uuid_128_from_16(bt_uuid_t *uuid, uint16_t uuid16) {
  memcpy(uuid, &BASE_UUID, sizeof(bt_uuid_t));

  uuid->uu[13] = (uint8_t)((0xFF00 & uuid16)>>8);
  uuid->uu[12] = (uint8_t)(0x00FF & uuid16);
}


static uint16_t compute_service_size(btgatt_db_element_t *service, int count) {
    int db_size = 0;
    btgatt_db_element_t *el = service;
+3 −0
Original line number Diff line number Diff line
@@ -712,6 +712,9 @@ extern bool GATTS_AddHandleRange(tGATTS_HNDL_RANGE *p_hndl_range);
*******************************************************************************/
extern bool     GATTS_NVRegister (tGATT_APPL_INFO *p_cb_info);

/* Converts 16bit uuid to bt_uuid_t that can be used when adding
 * service/characteristic/descriptor with GATTS_AddService */
void uuid_128_from_16(bt_uuid_t *uuid, uint16_t uuid16);

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