return list;
}
+static void get_uuid(uint8_t type, const void *val, bt_uuid_t *uuid)
+{
+ if (type == BT_UUID16)
+ bt_uuid16_create(uuid, get_le16(val));
+ else {
+ uint128_t u128;
+
+ /* Convert from 128-bit LE to BE */
+ bswap_128(val, &u128);
+ bt_uuid128_create(uuid, u128);
+ }
+}
+
uint16_t enc_read_by_grp_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
uint8_t *pdu, size_t len)
{
uint16_t *end, bt_uuid_t *uuid)
{
const size_t min_len = sizeof(pdu[0]) + sizeof(*start) + sizeof(*end);
+ uint8_t type;
if (pdu == NULL)
return 0;
if (pdu[0] != ATT_OP_READ_BY_GROUP_REQ)
return 0;
- if (len != (min_len + 2) && len != (min_len + 16))
+ if (len == (min_len + 2))
+ type = BT_UUID16;
+ else if (len == (min_len + 16))
+ type = BT_UUID128;
+ else
return 0;
*start = get_le16(&pdu[1]);
*end = get_le16(&pdu[3]);
- if (len == min_len + 2)
- bt_uuid16_create(uuid, get_le16(&pdu[5]));
- else
- *uuid = att_get_uuid128(&pdu[5]);
+
+ get_uuid(type, &pdu[5], uuid);
return len;
}
uint16_t *end, bt_uuid_t *uuid)
{
const size_t min_len = sizeof(pdu[0]) + sizeof(*start) + sizeof(*end);
+ uint8_t type;
if (pdu == NULL)
return 0;
if (start == NULL || end == NULL || uuid == NULL)
return 0;
- if (len != (min_len + 2) && len != (min_len + 16))
+ if (len == (min_len + 2))
+ type = BT_UUID16;
+ else if (len == (min_len + 16))
+ type = BT_UUID128;
+ else
return 0;
if (pdu[0] != ATT_OP_READ_BY_TYPE_REQ)
*start = get_le16(&pdu[1]);
*end = get_le16(&pdu[3]);
- if (len == min_len + 2)
- bt_uuid16_create(uuid, get_le16(&pdu[5]));
- else
- *uuid = att_get_uuid128(&pdu[5]);
+ get_uuid(type, &pdu[5], uuid);
return len;
}
bswap_128(&uuid->value.u128, dst);
}
+static void get_uuid128(uint8_t type, const void *val, bt_uuid_t *uuid)
+{
+ if (type == BT_UUID16) {
+ bt_uuid_t uuid16;
+
+ bt_uuid16_create(&uuid16, get_le16(val));
+ bt_uuid_to_uuid128(&uuid16, uuid);
+ } else {
+ uint128_t u128;
+
+ /* Convert from 128-bit LE to BE */
+ bswap_128(val, &u128);
+ bt_uuid128_create(uuid, u128);
+ }
+}
+
static guint16 encode_discover_primary(uint16_t start, uint16_t end,
bt_uuid_t *uuid, uint8_t *pdu, size_t len)
{
struct att_data_list *list;
unsigned int i, err;
uint16_t start, end;
+ uint8_t type;
if (status) {
err = status == ATT_ECODE_ATTR_NOT_FOUND ? 0 : status;
for (i = 0, end = 0; i < list->num; i++) {
const uint8_t *data = list->data[i];
struct gatt_primary *primary;
- bt_uuid_t uuid;
+ bt_uuid_t uuid128;
start = get_le16(&data[0]);
end = get_le16(&data[2]);
- if (list->len == 6) {
- bt_uuid_t uuid16;
-
- bt_uuid16_create(&uuid16, get_le16(&data[4]));
- bt_uuid_to_uuid128(&uuid16, &uuid);
- } else if (list->len == 20) {
- uuid = att_get_uuid128(&data[4]);
- } else {
+ /*
+ * FIXME: Check before "for". Elements in the Attribute
+ * Data List have the same length (list->len).
+ */
+ if (list->len == 6)
+ type = BT_UUID16;
+ else if (list->len == 20)
+ type = BT_UUID128;
+ else {
/* Skipping invalid data */
continue;
}
+ get_uuid128(type, &data[4], &uuid128);
+
primary = g_try_new0(struct gatt_primary, 1);
if (!primary) {
att_data_list_free(list);
}
primary->range.start = start;
primary->range.end = end;
- bt_uuid_to_string(&uuid, primary->uuid, sizeof(primary->uuid));
+ bt_uuid_to_string(&uuid128, primary->uuid, sizeof(primary->uuid));
dp->primaries = g_slist_append(dp->primaries, primary);
}
struct included_discovery *isd = query->isd;
struct gatt_included *incl = query->included;
unsigned int err = status;
- bt_uuid_t uuid;
+ bt_uuid_t uuid128;
size_t buflen;
uint8_t *buf;
goto done;
}
- uuid = att_get_uuid128(buf);
- bt_uuid_to_string(&uuid, incl->uuid, sizeof(incl->uuid));
+ get_uuid128(BT_UUID128, buf, &uuid128);
+
+ bt_uuid_to_string(&uuid128, incl->uuid, sizeof(incl->uuid));
isd->includes = g_slist_append(isd->includes, incl);
query->included = NULL;
for (i = 0; i < list->num; i++) {
uint8_t *value = list->data[i];
struct gatt_char *chars;
- bt_uuid_t uuid;
+ bt_uuid_t uuid128;
+ uint8_t type;
last = get_le16(value);
- if (list->len == 7) {
- bt_uuid_t uuid16;
+ /*
+ * FIXME: Check before "for". Elements in the Attribute
+ * Data List have the same length (list->len).
+ */
+ if (list->len == 7)
+ type = BT_UUID16;
+ else
+ type = BT_UUID128;
- bt_uuid16_create(&uuid16, get_le16(&value[5]));
- bt_uuid_to_uuid128(&uuid16, &uuid);
- } else
- uuid = att_get_uuid128(&value[5]);
+ get_uuid128(type, &value[5], &uuid128);
- if (dc->uuid && bt_uuid_cmp(dc->uuid, &uuid))
+ if (dc->uuid && bt_uuid_cmp(dc->uuid, &uuid128))
continue;
chars = g_try_new0(struct gatt_char, 1);
chars->handle = last;
chars->properties = value[2];
chars->value_handle = get_le16(&value[3]);
- bt_uuid_to_string(&uuid, chars->uuid, sizeof(chars->uuid));
+ bt_uuid_to_string(&uuid128, chars->uuid, sizeof(chars->uuid));
dc->characteristics = g_slist_append(dc->characteristics,
chars);
}