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; }
t_osc_err osc_mem_decodeByteorder(unsigned char typetag, char *data, char **out) { size_t size = osc_sizeof(typetag, data); if(!osc_mem_shouldByteswap(typetag)){ memcpy(*out, data, size); return OSC_ERR_NONE; } char tmp[size]; switch(size){ case 1: break; case 2: *((uint16_t *)tmp) = ntoh16(*((uint16_t *)data)); break; case 4: *((uint32_t *)tmp) = ntoh32(*((uint32_t *)data)); break; case 8: *((uint64_t *)tmp) = ntoh64(*((uint64_t *)data)); break; case 16: *((uint128_t *)tmp) = ntoh128(*((uint128_t *)data)); break; } memcpy(*out, tmp, size); return OSC_ERR_NONE; }
static int bt_string_to_uuid128(bt_uuid_t *uuid, const char *string) { uint32_t data0, data4; uint16_t data1, data2, data3, data5; uint128_t n128, u128; uint8_t *val = (uint8_t *) &n128; if (sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx", &data0, &data1, &data2, &data3, &data4, &data5) != 6) return -EINVAL; data0 = htonl(data0); data1 = htons(data1); data2 = htons(data2); data3 = htons(data3); data4 = htonl(data4); data5 = htons(data5); memcpy(&val[0], &data0, 4); memcpy(&val[4], &data1, 2); memcpy(&val[6], &data2, 2); memcpy(&val[8], &data3, 2); memcpy(&val[10], &data4, 4); memcpy(&val[14], &data5, 2); ntoh128(&n128, &u128); bt_uuid128_create(uuid, u128); return 0; }