bool gatt_db_attribute_get_service_uuid(const struct gatt_db_attribute *attrib, bt_uuid_t *uuid) { struct gatt_db_service *service; if (!attrib || !uuid) return false; service = attrib->service; if (service->attributes[0]->value_len == sizeof(uint16_t)) { uint16_t value; value = get_le16(service->attributes[0]->value); bt_uuid16_create(uuid, value); return true; } if (service->attributes[0]->value_len == sizeof(uint128_t)) { uint128_t value; bswap_128(service->attributes[0]->value, &value); bt_uuid128_create(uuid, value); return true; } return false; }
static void put_uuid_le(const bt_uuid_t *uuid, void *dst) { if (uuid->type == BT_UUID16) put_le16(uuid->value.u16, dst); else /* Convert from 128-bit BE to LE */ bswap_128(&uuid->value.u128, dst); }
static inline void put_uuid_le(const bt_uuid_t *src, void *dst) { if (src->type == BT_UUID16) put_le16(src->value.u16, dst); else /* Convert from 128-bit BE to LE */ bswap_128(&src->value.u128, dst); }
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); } }
static int uuid_to_le(const bt_uuid_t *uuid, uint8_t *dst) { bt_uuid_t uuid128; if (uuid->type == BT_UUID16) { put_le16(uuid->value.u16, dst); return bt_uuid_len(uuid); } bt_uuid_to_uuid128(uuid, &uuid128); bswap_128(&uuid128.value.u128, dst); return bt_uuid_len(&uuid128); }
static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen, gpointer user_data) { struct att_data_list *list; guint8 format; int i; if (status != 0) { g_printerr("Discover all characteristic descriptors failed: " "%s\n", att_ecode2str(status)); goto done; } list = dec_find_info_resp(pdu, plen, &format); if (list == NULL) goto done; for (i = 0; i < list->num; i++) { char uuidstr[MAX_LEN_UUID_STR]; uint16_t handle; uint8_t *value; bt_uuid_t uuid; value = list->data[i]; handle = get_le16(value); if (format == ATT_FIND_INFO_RESP_FMT_16BIT) bt_uuid16_create(&uuid, get_le16(&value[2])); else { uint128_t u128; /* Converts from LE to BE byte order */ bswap_128(&value[2], &u128); bt_uuid128_create(&uuid, u128); } bt_uuid_to_string(&uuid, uuidstr, MAX_LEN_UUID_STR); g_print("handle = 0x%04x, uuid = %s\n", handle, uuidstr); } att_data_list_free(list); done: if (!opt_listen) g_main_loop_quit(event_loop); }
static bool get_uuid_le(const uint8_t *uuid, size_t len, bt_uuid_t *out_uuid) { uint128_t u128; switch (len) { case 2: bt_uuid16_create(out_uuid, get_le16(uuid)); return true; case 16: bswap_128(uuid, &u128.data); bt_uuid128_create(out_uuid, u128); return true; default: return false; } return false; }
int bt_uuid_to_le(const bt_uuid_t *src, void *dst) { bt_uuid_t uuid; switch (src->type) { case BT_UUID16: bt_put_le16(src->value.u16, dst); return 0; case BT_UUID32: bt_uuid32_to_uuid128(src, &uuid); src = &uuid; /* Fallthrough */ case BT_UUID128: /* Convert from 128-bit BE to LE */ bswap_128(&src->value.u128, dst); return 0; case BT_UUID_UNSPEC: default: return -EINVAL; } }
static bool le_to_uuid(const uint8_t *src, size_t len, bt_uuid_t *uuid) { uint128_t u128; if (len == 2) { bt_uuid16_create(uuid, get_le16(src)); return true; } if (len == 4) { bt_uuid32_create(uuid, get_le32(src)); return true; } if (len != 16) return false; bswap_128(src, &u128); bt_uuid128_create(uuid, u128); return true; }