summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2016-01-27 22:43:34 -0500
committerAnas Nashif <anas.nashif@intel.com>2016-02-05 20:25:28 -0500
commitd5e23e86d23888d2da703b611c1a8415533ce45c (patch)
tree825d612231a8ffb811fb6d387c37cb6fe8815091 /samples
parent4e29c31512c34f86b35330cddc3454d691af4fa6 (diff)
Bluetooth: UUID: Introduce new API
Introduce new UUID API with bt_uuid, bt_uuid_16 and bt_uuid_32 structs. The specific size structs are derived from the common bt_uuid struct to make it possible to use CONTAINER_OF(). Change-Id: I9cb03c73406acb7768d410fdf29eae75d252163c Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Diffstat (limited to 'samples')
-rw-r--r--samples/bluetooth/central_hr/src/main.c22
-rw-r--r--samples/bluetooth/peripheral/src/main.c56
-rw-r--r--samples/bluetooth/shell/src/main.c9
-rw-r--r--samples/bluetooth/tester/src/gatt.c53
4 files changed, 63 insertions, 77 deletions
diff --git a/samples/bluetooth/central_hr/src/main.c b/samples/bluetooth/central_hr/src/main.c
index 7d81438fb..463a51d68 100644
--- a/samples/bluetooth/central_hr/src/main.c
+++ b/samples/bluetooth/central_hr/src/main.c
@@ -34,7 +34,7 @@
static struct bt_conn *default_conn;
-static struct bt_uuid uuid;
+static struct bt_uuid_16 uuid = BT_UUID_INIT_16(0);
static struct bt_gatt_discover_params discover_params;
static struct bt_gatt_subscribe_params subscribe_params;
@@ -56,9 +56,9 @@ static uint8_t discover_func(struct bt_conn *conn,
printk("[ATTRIBUTE] handle %u\n", attr->handle);
- if (!bt_uuid_cmp(discover_params.uuid, BT_UUID_HRS)) {
- bt_uuid_copy(&uuid, BT_UUID_HRS_MEASUREMENT);
- discover_params.uuid = &uuid;
+ if (BT_UUID_16(discover_params.uuid)->val == BT_UUID_HRS_VAL) {
+ uuid.val = BT_UUID_HRS_MEASUREMENT_VAL;
+ discover_params.uuid = &uuid.uuid;
discover_params.start_handle = attr->handle + 1;
discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC;
@@ -66,10 +66,10 @@ static uint8_t discover_func(struct bt_conn *conn,
if (err) {
printk("Discover failed (err %d)\n", err);
}
- } else if (!bt_uuid_cmp(discover_params.uuid,
- BT_UUID_HRS_MEASUREMENT)) {
- bt_uuid_copy(&uuid, BT_UUID_GATT_CCC);
- discover_params.uuid = &uuid;
+ } else if (BT_UUID_16(discover_params.uuid)->val ==
+ BT_UUID_HRS_MEASUREMENT_VAL) {
+ uuid.val = BT_UUID_GATT_CCC_VAL;
+ discover_params.uuid = &uuid.uuid;
discover_params.start_handle = attr->handle + 2;
discover_params.type = BT_GATT_DISCOVER_DESCRIPTOR;
subscribe_params.value_handle = attr->handle + 1;
@@ -109,8 +109,8 @@ static void connected(struct bt_conn *conn, uint8_t conn_err)
printk("Connected: %s\n", addr);
if (conn == default_conn) {
- bt_uuid_copy(&uuid, BT_UUID_HRS);
- discover_params.uuid = &uuid;
+ uuid.val = BT_UUID_HRS_VAL;
+ discover_params.uuid = &uuid.uuid;
discover_params.func = discover_func;
discover_params.start_handle = 0x0001;
discover_params.end_handle = 0xffff;
@@ -145,7 +145,7 @@ static bool eir_found(uint8_t type, const uint8_t *data, uint8_t data_len,
int err;
memcpy(&u16, &data[i], sizeof(u16));
- if (sys_le16_to_cpu(u16) != BT_UUID_HRS->u16) {
+ if (sys_le16_to_cpu(u16) != BT_UUID_HRS_VAL) {
continue;
}
diff --git a/samples/bluetooth/peripheral/src/main.c b/samples/bluetooth/peripheral/src/main.c
index cb482a701..6ae93716b 100644
--- a/samples/bluetooth/peripheral/src/main.c
+++ b/samples/bluetooth/peripheral/src/main.c
@@ -168,23 +168,17 @@ static int read_manuf(struct bt_conn *conn, const struct bt_gatt_attr *attr,
}
/* Custom Service Variables */
-static struct bt_uuid vnd_uuid = {
- .type = BT_UUID_128,
- .u128 = { 0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
- 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12 },
-};
+static struct bt_uuid_128 vnd_uuid = BT_UUID_INIT_128(
+ 0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
+ 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12);
-static struct bt_uuid vnd_enc_uuid = {
- .type = BT_UUID_128,
- .u128 = { 0xf1, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
- 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12 },
-};
+static struct bt_uuid_128 vnd_enc_uuid = BT_UUID_INIT_128(
+ 0xf1, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
+ 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12);
-static struct bt_uuid vnd_auth_uuid = {
- .type = BT_UUID_128,
- .u128 = { 0xf2, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
- 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12 },
-};
+static struct bt_uuid_128 vnd_auth_uuid = BT_UUID_INIT_128(
+ 0xf2, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
+ 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12);
static uint8_t vnd_value[] = { 'V', 'e', 'n', 'd', 'o', 'r' };
@@ -266,11 +260,9 @@ static int flush_long_vnd(struct bt_conn *conn,
return -EINVAL;
}
-static const struct bt_uuid vnd_long_uuid = {
- .type = BT_UUID_128,
- .u128 = { 0xf3, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
- 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12 },
-};
+static const struct bt_uuid_128 vnd_long_uuid = BT_UUID_INIT_128(
+ 0xf3, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
+ 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12);
static struct bt_gatt_cep vnd_long_cep = {
.properties = BT_GATT_CEP_RELIABLE_WRITE,
@@ -301,11 +293,9 @@ static int write_signed(struct bt_conn *conn, const struct bt_gatt_attr *attr,
return len;
}
-static const struct bt_uuid vnd_signed_uuid = {
- .type = BT_UUID_128,
- .u128 = { 0xf3, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x13,
- 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x13 },
-};
+static const struct bt_uuid_128 vnd_signed_uuid = BT_UUID_INIT_128(
+ 0xf3, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x13,
+ 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x13);
static struct bt_gatt_attr gap_attrs[] = {
BT_GATT_PRIMARY_SERVICE(BT_UUID_GAP),
@@ -370,28 +360,28 @@ static struct bt_gatt_attr dis_attrs[] = {
static struct bt_gatt_attr vnd_attrs[] = {
/* Vendor Primary Service Declaration */
BT_GATT_PRIMARY_SERVICE(&vnd_uuid),
- BT_GATT_CHARACTERISTIC(&vnd_enc_uuid,
+ BT_GATT_CHARACTERISTIC(&vnd_enc_uuid.uuid,
BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE),
- BT_GATT_DESCRIPTOR(&vnd_enc_uuid,
+ BT_GATT_DESCRIPTOR(&vnd_enc_uuid.uuid,
BT_GATT_PERM_READ | BT_GATT_PERM_READ_ENCRYPT |
BT_GATT_PERM_WRITE | BT_GATT_PERM_WRITE_ENCRYPT,
read_vnd, write_vnd, vnd_value),
- BT_GATT_CHARACTERISTIC(&vnd_auth_uuid,
+ BT_GATT_CHARACTERISTIC(&vnd_auth_uuid.uuid,
BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE),
- BT_GATT_DESCRIPTOR(&vnd_auth_uuid,
+ BT_GATT_DESCRIPTOR(&vnd_auth_uuid.uuid,
BT_GATT_PERM_READ | BT_GATT_PERM_READ_AUTHEN |
BT_GATT_PERM_WRITE | BT_GATT_PERM_WRITE_AUTHEN,
read_vnd, write_vnd, vnd_value),
- BT_GATT_CHARACTERISTIC(&vnd_long_uuid, BT_GATT_CHRC_READ |
+ BT_GATT_CHARACTERISTIC(&vnd_long_uuid.uuid, BT_GATT_CHRC_READ |
BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP),
- BT_GATT_LONG_DESCRIPTOR(&vnd_long_uuid,
+ BT_GATT_LONG_DESCRIPTOR(&vnd_long_uuid.uuid,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
read_long_vnd, write_long_vnd, flush_long_vnd,
&vnd_long_value),
BT_GATT_CEP(&vnd_long_cep),
- BT_GATT_CHARACTERISTIC(&vnd_signed_uuid, BT_GATT_CHRC_READ |
+ BT_GATT_CHARACTERISTIC(&vnd_signed_uuid.uuid, BT_GATT_CHRC_READ |
BT_GATT_CHRC_WRITE | BT_GATT_CHRC_AUTH),
- BT_GATT_DESCRIPTOR(&vnd_signed_uuid,
+ BT_GATT_DESCRIPTOR(&vnd_signed_uuid.uuid,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
read_signed, write_signed, &signed_value),
};
diff --git a/samples/bluetooth/shell/src/main.c b/samples/bluetooth/shell/src/main.c
index b5710f077..efd6134e2 100644
--- a/samples/bluetooth/shell/src/main.c
+++ b/samples/bluetooth/shell/src/main.c
@@ -626,7 +626,7 @@ fail:
}
static struct bt_gatt_discover_params discover_params;
-static struct bt_uuid uuid;
+static struct bt_uuid_16 uuid = BT_UUID_INIT_16(0);
static void print_chrc_props(uint8_t properties)
{
@@ -740,10 +740,9 @@ static void cmd_gatt_discover(int argc, char *argv[])
}
/* Only set the UUID if the value is valid (non zero) */
- uuid.u16 = strtoul(argv[1], NULL, 16);
- if (uuid.u16) {
- uuid.type = BT_UUID_16;
- discover_params.uuid = &uuid;
+ uuid.val = strtoul(argv[1], NULL, 16);
+ if (uuid.val) {
+ discover_params.uuid = &uuid.uuid;
}
if (argc > 2) {
diff --git a/samples/bluetooth/tester/src/gatt.c b/samples/bluetooth/tester/src/gatt.c
index a23c7f9d6..b2f5c56d5 100644
--- a/samples/bluetooth/tester/src/gatt.c
+++ b/samples/bluetooth/tester/src/gatt.c
@@ -122,18 +122,17 @@ static struct bt_gatt_attr *gatt_db_add(const struct bt_gatt_attr *pattern)
static uint8_t btp2bt_uuid(const uint8_t *uuid, uint8_t len,
struct bt_uuid *bt_uuid)
{
- switch (len) {
- case 0x02: { /* UUID 16 */
- uint16_t u16;
+ uint16_t le16;
- bt_uuid->type = BT_UUID_16;
- memcpy(&u16, uuid, sizeof(u16));
- bt_uuid->u16 = sys_le16_to_cpu(u16);
+ switch (len) {
+ case 0x02: /* UUID 16 */
+ bt_uuid->type = BT_UUID_TYPE_16;
+ memcpy(&le16, uuid, sizeof(le16));
+ BT_UUID_16(bt_uuid)->val = sys_le16_to_cpu(le16);
break;
- }
case 0x10: /* UUID 128*/
- bt_uuid->type = BT_UUID_128;
- memcpy(&bt_uuid->u128, uuid, sizeof(bt_uuid->u128));
+ bt_uuid->type = BT_UUID_TYPE_128;
+ memcpy(BT_UUID_128(bt_uuid)->val, uuid, 16);
break;
default:
return BTP_STATUS_FAILED;
@@ -839,8 +838,7 @@ static uint8_t disc_prim_uuid_cb(struct bt_conn *conn,
struct gatt_service *service;
uint8_t uuid_length;
- uuid_length = data->uuid->type == BT_UUID_16 ? sizeof(data->uuid->u16) :
- sizeof(data->uuid->u128);
+ uuid_length = data->uuid->type == BT_UUID_TYPE_16 ? 2 : 16;
service = gatt_buf_reserve(sizeof(*service) + uuid_length);
if (!service) {
@@ -858,12 +856,13 @@ static uint8_t disc_prim_uuid_cb(struct bt_conn *conn,
service->end_handle = sys_cpu_to_le16(data->end_handle);
service->uuid_length = uuid_length;
- if (data->uuid->type == BT_UUID_16) {
- uint16_t u16 = sys_cpu_to_le16(data->uuid->u16);
+ if (data->uuid->type == BT_UUID_TYPE_16) {
+ uint16_t u16 = sys_cpu_to_le16(BT_UUID_16(data->uuid)->val);
memcpy(service->uuid, &u16, uuid_length);
} else {
- memcpy(service->uuid, &data->uuid->u128, uuid_length);
+ memcpy(service->uuid, BT_UUID_128(data->uuid)->val,
+ uuid_length);
}
rp->services_count++;
@@ -936,8 +935,7 @@ static uint8_t find_included_cb(struct bt_conn *conn,
struct gatt_included *included;
uint8_t uuid_length;
- uuid_length = data->uuid->type == BT_UUID_16 ? sizeof(data->uuid->u16) :
- sizeof(data->uuid->u128);
+ uuid_length = data->uuid->type == BT_UUID_TYPE_16 ? 2 : 16;
included = gatt_buf_reserve(sizeof(*included) + uuid_length);
if (!included) {
@@ -956,8 +954,8 @@ static uint8_t find_included_cb(struct bt_conn *conn,
included->service.end_handle = sys_cpu_to_le16(data->end_handle);
included->service.uuid_length = uuid_length;
- if (data->uuid->type == BT_UUID_16) {
- uint16_t u16 = sys_cpu_to_le16(data->uuid->u16);
+ if (data->uuid->type == BT_UUID_TYPE_16) {
+ uint16_t u16 = sys_cpu_to_le16(BT_UUID_16(data->uuid)->val);
memcpy(included->service.uuid, &u16, uuid_length);
} else {
@@ -1030,8 +1028,7 @@ static uint8_t disc_chrc_cb(struct bt_conn *conn,
struct gatt_characteristic *chrc;
uint8_t uuid_length;
- uuid_length = data->uuid->type == BT_UUID_16 ? sizeof(data->uuid->u16) :
- sizeof(data->uuid->u128);
+ uuid_length = data->uuid->type == BT_UUID_TYPE_16 ? 2 : 16;
chrc = gatt_buf_reserve(sizeof(*chrc) + uuid_length);
if (!chrc) {
@@ -1050,12 +1047,12 @@ static uint8_t disc_chrc_cb(struct bt_conn *conn,
chrc->value_handle = sys_cpu_to_le16(attr->handle + 1);
chrc->uuid_length = uuid_length;
- if (data->uuid->type == BT_UUID_16) {
- uint16_t u16 = sys_cpu_to_le16(data->uuid->u16);
+ if (data->uuid->type == BT_UUID_TYPE_16) {
+ uint16_t u16 = sys_cpu_to_le16(BT_UUID_16(data->uuid)->val);
memcpy(chrc->uuid, &u16, uuid_length);
} else {
- memcpy(chrc->uuid, &data->uuid->u128, uuid_length);
+ memcpy(chrc->uuid, BT_UUID_128(data->uuid)->val, uuid_length);
}
rp->characteristics_count++;
@@ -1178,8 +1175,7 @@ static uint8_t disc_all_desc_cb(struct bt_conn *conn,
struct gatt_descriptor *descriptor;
uint8_t uuid_length;
- uuid_length = attr->uuid->type == BT_UUID_16 ? sizeof(attr->uuid->u16) :
- sizeof(attr->uuid->u128);
+ uuid_length = attr->uuid->type == BT_UUID_TYPE_16 ? 2 : 16;
descriptor = gatt_buf_reserve(sizeof(*descriptor) + uuid_length);
if (!descriptor) {
@@ -1196,12 +1192,13 @@ static uint8_t disc_all_desc_cb(struct bt_conn *conn,
descriptor->descriptor_handle = sys_cpu_to_le16(attr->handle);
descriptor->uuid_length = uuid_length;
- if (attr->uuid->type == BT_UUID_16) {
- uint16_t u16 = sys_cpu_to_le16(attr->uuid->u16);
+ if (attr->uuid->type == BT_UUID_TYPE_16) {
+ uint16_t u16 = sys_cpu_to_le16(BT_UUID_16(attr->uuid)->val);
memcpy(descriptor->uuid, &u16, uuid_length);
} else {
- memcpy(descriptor->uuid, &attr->uuid->u128, uuid_length);
+ memcpy(descriptor->uuid, BT_UUID_128(attr->uuid)->val,
+ uuid_length);
}
rp->descriptors_count++;