Esempio n. 1
0
static int uuid128_cmp(const struct bt_uuid *u1, const struct bt_uuid *u2)
{
	struct bt_uuid_128 uuid1, uuid2;

	uuid_to_uuid128(u1, &uuid1);
	uuid_to_uuid128(u2, &uuid2);

	return memcmp(uuid1.val, uuid2.val, 16);
}
Esempio n. 2
0
SOL_API int
sol_bt_uuid_to_str(const struct sol_bt_uuid *uuid, struct sol_buffer *buffer)
{
    uint32_t tmp0, tmp4;
    uint16_t tmp1, tmp2, tmp3, tmp5;
    struct sol_bt_uuid u = BASE_UUID;
    int r;

    SOL_NULL_CHECK(uuid, -EINVAL);
    SOL_NULL_CHECK(buffer, -EINVAL);

    uuid_to_uuid128(uuid, &u);

    memcpy(&tmp0, &u.val128[0], sizeof(tmp0));
    memcpy(&tmp1, &u.val128[4], sizeof(tmp1));
    memcpy(&tmp2, &u.val128[6], sizeof(tmp2));
    memcpy(&tmp3, &u.val128[8], sizeof(tmp3));
    memcpy(&tmp4, &u.val128[10], sizeof(tmp4));
    memcpy(&tmp5, &u.val128[14], sizeof(tmp5));

    r = sol_buffer_append_printf(buffer, "%.8" PRIx32 "-%.4" PRIx16 "-%.4" PRIx16 "-%.4" PRIx16 "-%.8" PRIx32 "%.4" PRIx16,
        sol_util_cpu_to_be32(tmp0), sol_util_cpu_to_be16(tmp1),
        sol_util_cpu_to_be16(tmp2), sol_util_cpu_to_be16(tmp3),
        sol_util_cpu_to_be32(tmp4), sol_util_cpu_to_be16(tmp5));

    return r ? -errno : 0;
}
static int mgmt_remove_uuid(int index, uuid_t *uuid)
{
	char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_remove_uuid)];
	struct mgmt_hdr *hdr = (void *) buf;
	struct mgmt_cp_remove_uuid *cp = (void *) &buf[sizeof(*hdr)];
	uuid_t uuid128;
	uint128_t uint128;

	DBG("index %d", index);

	uuid_to_uuid128(&uuid128, uuid);

	memset(buf, 0, sizeof(buf));
	hdr->opcode = htobs(MGMT_OP_REMOVE_UUID);
	hdr->len = htobs(sizeof(*cp));
	hdr->index = htobs(index);

	ntoh128((uint128_t *) uuid128.value.uuid128.data, &uint128);
	htob128(&uint128, (uint128_t *) cp->uuid);

	if (write(mgmt_sock, buf, sizeof(buf)) < 0)
		return -errno;

	return 0;
}
Esempio n. 4
0
SOL_API bool
sol_bt_uuid_equal(const struct sol_bt_uuid *u1, const struct sol_bt_uuid *u2)
{
    struct sol_bt_uuid u1_128 = BASE_UUID;
    struct sol_bt_uuid u2_128 = BASE_UUID;

    if (!u1 && !u2)
        return true;

    if (!u1 || !u2)
        return false;

    if (u1->type == u2->type)
        return memcmp(u1->val, u2->val, u1->type) == 0;

    uuid_to_uuid128(u1, &u1_128);
    uuid_to_uuid128(u2, &u2_128);

    return memcmp(u1_128.val128, u2_128.val128, u1_128.type) == 0;
}
Esempio n. 5
0
static int mgmt_add_uuid(int index, uuid_t *uuid, uint8_t svc_hint)
{
	char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_add_uuid)];
	struct mgmt_hdr *hdr = (void *) buf;
	struct mgmt_cp_add_uuid *cp = (void *) &buf[sizeof(*hdr)];
	uuid_t uuid128;

	DBG("index %d", index);

	uuid_to_uuid128(&uuid128, uuid);

	memset(buf, 0, sizeof(buf));
	hdr->opcode = htobs(MGMT_OP_ADD_UUID);
	hdr->len = htobs(sizeof(*cp));

	cp->index = htobs(index);
	memcpy(cp->uuid, uuid128.value.uuid128.data, 16);
	cp->svc_hint = svc_hint;

	if (write(mgmt_sock, buf, sizeof(buf)) < 0)
		return -errno;

	return 0;
}