nimble: Refactor UUID handling (ATT/GATT)
This patch introduces dedicated type for UUIDs in order to handle them
consistently everywhere. It not only makes handling of UUIDs easier,
but also allows for some flash and RAM savings due to some extra code
being removed and less memory required to store UUIDs in common cases
(especially with 16-bit UUIDs).
*IMPORTANT NOTES*
- ble_uuid_t is a "stub" type which shall be always used as a pointer;
to access actual UUID value other helpers and types shall be used
- when registering services using new API, only UUID pointer is stored
for all attributes (there is *no* copy of value made) thus it is not
allowed to pass UUIDs created e.g. on stack
- it is illegal to have 128-bit UUID declared which has its 16-bit UUID
equivalent - there is no implicit conversion from 128-bit to 16-bit
UUID done inside Nimble
- ...but this means you can rely on UUID type received from Nimble and
128-bit UUID will be always non-Bluetooth one
Below are few examples how to use new UUIDs API:
// 16-bit UUID value with initialization
ble_uuid16_t uuid16 = BLE_UUID16_INIT(0x2801);
// 128-bit UUID value with initialization
ble_uuid128_t uuid128 = BLE_UUID128_INIT(0x00, 0x11, ... 0xFF);
// "stub" type is used to pass any type of UUID via API
ble_uuid_t *uuid1 = &uuid16.u;
ble_uuid_t *uuid2 = &uuid128.u;
// comparing UUIDs is really easy now
if (ble_uuid_cmp(uuid1, uuid2) == 0) { /* equal */ )
// since in most cases we use 16-bit UUIDs, it's convenient to easily
// retrieve 16-bit value (or 0 if UUID is not 16-bit)
uint16_t u16 = ble_uuid_u16(uuid1);
// the above is equivalent of
u16 = uuid1->type == BLE_UUID_TYPE_16 ? BLE_UUID16(uuid1)->value : 0;
// we can easily define UUID inline as well, e.g. when defining service
static const struct ble_gatt_svc_def ble_svc_gap_defs[] = {
{
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = BLE_UUID16_DECLARE(BLE_SVC_GAP_UUID16),
(...)
// finally, if we need to store any UUID there is an union defined to help
ble_uuid_any_t uuid;
uuid.u16 = uuid16;
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit:
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/b1c14f3f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b1c14f3f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b1c14f3f
Branch: refs/heads/develop
Commit: b1c14f3fd599198995602dc7de3572d719942df0
Parents: e7fc231
Author: Andrzej Kaczmarek <[email protected]>
Authored: Fri Jan 6 16:31:04 2017 +0100
Committer: Andrzej Kaczmarek <[email protected]>
Committed: Tue Jan 17 12:23:54 2017 +0100
----------------------------------------------------------------------
apps/blecent/src/blecent.h | 12 +-
apps/blecent/src/main.c | 14 +-
apps/blecent/src/misc.c | 26 +-
apps/blecent/src/peer.c | 20 +-
apps/bleprph/src/gatt_svr.c | 66 ++---
apps/bleprph_oic/src/gatt_svr.c | 79 +++---
apps/bleprph_oic/src/main.c | 3 +-
apps/bletiny/src/bletiny.h | 10 +-
apps/bletiny/src/cmd.c | 24 +-
apps/bletiny/src/gatt_svr.c | 150 +++++-------
apps/bletiny/src/main.c | 16 +-
apps/bletiny/src/misc.c | 20 +-
apps/bletiny/src/parse.c | 27 ++-
apps/bleuart/src/main.c | 2 +-
mgmt/newtmgr/transport/ble/src/newtmgr_ble.c | 18 +-
net/nimble/host/include/host/ble_gatt.h | 39 +--
net/nimble/host/include/host/ble_uuid.h | 92 +++++--
net/nimble/host/profiles/lls/src/ble_svc_lls.c | 4 +-
net/nimble/host/services/ans/src/ble_svc_ans.c | 14 +-
.../services/bleuart/include/bleuart/bleuart.h | 2 +-
net/nimble/host/services/bleuart/src/bleuart.c | 28 +--
net/nimble/host/services/gap/src/ble_svc_gap.c | 16 +-
.../host/services/gatt/src/ble_svc_gatt.c | 4 +-
net/nimble/host/services/ias/src/ble_svc_ias.c | 4 +-
net/nimble/host/services/lls/src/ble_svc_lls.c | 4 +-
net/nimble/host/services/tps/src/ble_svc_tps.c | 4 +-
net/nimble/host/src/ble_att_clt.c | 14 +-
net/nimble/host/src/ble_att_priv.h | 16 +-
net/nimble/host/src/ble_att_svr.c | 199 ++++++---------
net/nimble/host/src/ble_gattc.c | 146 ++++-------
net/nimble/host/src/ble_gatts.c | 138 +++++------
net/nimble/host/src/ble_uuid.c | 240 ++++++++++++-------
net/nimble/host/src/ble_uuid_priv.h | 9 +-
net/nimble/host/test/src/ble_att_svr_test.c | 169 +++++++------
net/nimble/host/test/src/ble_gatt_conn_test.c | 16 +-
net/nimble/host/test/src/ble_gatt_disc_c_test.c | 150 ++++++------
net/nimble/host/test/src/ble_gatt_disc_d_test.c | 74 +++---
net/nimble/host/test/src/ble_gatt_disc_s_test.c | 119 ++++-----
net/nimble/host/test/src/ble_gatt_find_s_test.c | 56 ++---
net/nimble/host/test/src/ble_gatt_read_test.c | 12 +-
.../host/test/src/ble_gatts_notify_test.c | 16 +-
net/nimble/host/test/src/ble_gatts_read_test.c | 8 +-
net/nimble/host/test/src/ble_gatts_reg_test.c | 190 +++++++--------
net/nimble/host/test/src/ble_hs_test_util.c | 76 ++----
net/nimble/host/test/src/ble_hs_test_util.h | 10 +-
net/nimble/host/test/src/ble_uuid_test.c | 93 ++++---
net/oic/include/oic/oc_gatt.h | 8 +-
net/oic/src/port/mynewt/ble_adaptor.c | 26 +-
48 files changed, 1165 insertions(+), 1318 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/apps/blecent/src/blecent.h
----------------------------------------------------------------------
diff --git a/apps/blecent/src/blecent.h b/apps/blecent/src/blecent.h
index 6165e70..2dfa85b 100644
--- a/apps/blecent/src/blecent.h
+++ b/apps/blecent/src/blecent.h
@@ -57,7 +57,7 @@ void gatt_svr_init_cfg(struct ble_hs_cfg *cfg);
void print_bytes(const uint8_t *bytes, int len);
void print_mbuf(const struct os_mbuf *om);
char *addr_str(const void *addr);
-void print_uuid(const void *uuid128);
+void print_uuid(const ble_uuid_t *uuid);
void print_conn_desc(const struct ble_gap_conn_desc *desc);
void print_adv_fields(const struct ble_hs_adv_fields *fields);
@@ -107,13 +107,13 @@ struct peer {
int peer_disc_all(uint16_t conn_handle, peer_disc_fn *disc_cb,
void *disc_cb_arg);
const struct peer_dsc *
-peer_dsc_find_uuid(const struct peer *peer, const uint8_t *svc_uuid128,
- const uint8_t *chr_uuid128, const uint8_t *dsc_uuid128);
+peer_dsc_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
+ const ble_uuid_t *chr_uuid, const ble_uuid_t *dsc_uuid);
const struct peer_chr *
-peer_chr_find_uuid(const struct peer *peer, const uint8_t *svc_uuid128,
- const uint8_t *chr_uuid128);
+peer_chr_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
+ const ble_uuid_t *chr_uuid);
const struct peer_svc *
-peer_svc_find_uuid(const struct peer *peer, const uint8_t *uuid128);
+peer_svc_find_uuid(const struct peer *peer, const ble_uuid_t *uuid);
int peer_delete(uint16_t conn_handle);
int peer_add(uint16_t conn_handle);
int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/apps/blecent/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index c3d2c32..8f6a524 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -129,8 +129,8 @@ blecent_read_write_subscribe(const struct peer *peer)
/* Read the supported-new-alert-category characteristic. */
chr = peer_chr_find_uuid(peer,
- BLE_UUID16(BLECENT_SVC_ALERT_UUID),
- BLE_UUID16(BLECENT_CHR_SUP_NEW_ALERT_CAT_UUID));
+ BLE_UUID16_DECLARE(BLECENT_SVC_ALERT_UUID),
+
BLE_UUID16_DECLARE(BLECENT_CHR_SUP_NEW_ALERT_CAT_UUID));
if (chr == NULL) {
BLECENT_LOG(ERROR, "Error: Peer doesn't support the Supported New "
"Alert Category characteristic\n");
@@ -149,8 +149,8 @@ blecent_read_write_subscribe(const struct peer *peer)
* characteristic.
*/
chr = peer_chr_find_uuid(peer,
- BLE_UUID16(BLECENT_SVC_ALERT_UUID),
- BLE_UUID16(BLECENT_CHR_ALERT_NOT_CTRL_PT));
+ BLE_UUID16_DECLARE(BLECENT_SVC_ALERT_UUID),
+
BLE_UUID16_DECLARE(BLECENT_CHR_ALERT_NOT_CTRL_PT));
if (chr == NULL) {
BLECENT_LOG(ERROR, "Error: Peer doesn't support the Alert "
"Notification Control Point characteristic\n");
@@ -171,9 +171,9 @@ blecent_read_write_subscribe(const struct peer *peer)
* characteristic's client-characteristic-configuration-descriptor (CCCD).
*/
dsc = peer_dsc_find_uuid(peer,
- BLE_UUID16(BLECENT_SVC_ALERT_UUID),
- BLE_UUID16(BLECENT_CHR_UNR_ALERT_STAT_UUID),
- BLE_UUID16(BLE_GATT_DSC_CLT_CFG_UUID16));
+ BLE_UUID16_DECLARE(BLECENT_SVC_ALERT_UUID),
+
BLE_UUID16_DECLARE(BLECENT_CHR_UNR_ALERT_STAT_UUID),
+ BLE_UUID16_DECLARE(BLE_GATT_DSC_CLT_CFG_UUID16));
if (dsc == NULL) {
BLECENT_LOG(ERROR, "Error: Peer lacks a CCCD for the Unread Alert "
"Status characteristic\n");
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/apps/blecent/src/misc.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/misc.c b/apps/blecent/src/misc.c
index 5559879..18f723b 100644
--- a/apps/blecent/src/misc.c
+++ b/apps/blecent/src/misc.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <string.h>
#include "host/ble_hs.h"
+#include "host/ble_uuid.h"
#include "blecent.h"
/**
@@ -67,26 +68,11 @@ addr_str(const void *addr)
}
void
-print_uuid(const void *uuid128)
+print_uuid(const ble_uuid_t *uuid)
{
- uint16_t uuid16;
- const uint8_t *u8p;
-
- uuid16 = ble_uuid_128_to_16(uuid128);
- if (uuid16 != 0) {
- BLECENT_LOG(DEBUG, "0x%04x", uuid16);
- return;
- }
-
- u8p = uuid128;
+ char buf[BLE_UUID_STR_LEN];
- /* 00001101-0000-1000-8000-00805f9b34fb */
- BLECENT_LOG(DEBUG, "%02x%02x%02x%02x-", u8p[15], u8p[14], u8p[13],
- u8p[12]);
- BLECENT_LOG(DEBUG, "%02x%02x-%02x%02x-", u8p[11], u8p[10], u8p[9], u8p[8]);
- BLECENT_LOG(DEBUG, "%02x%02x%02x%02x%02x%02x%02x%02x",
- u8p[7], u8p[6], u8p[5], u8p[4],
- u8p[3], u8p[2], u8p[1], u8p[0]);
+ BLECENT_LOG(DEBUG, "%s", ble_uuid_to_str(uuid, buf));
}
/**
@@ -119,6 +105,7 @@ print_adv_fields(const struct ble_hs_adv_fields *fields)
{
char s[BLE_HCI_MAX_ADV_DATA_LEN];
const uint8_t *u8p;
+ ble_uuid_any_t uuid;
int i;
if (fields->flags_is_present) {
@@ -148,7 +135,8 @@ print_adv_fields(const struct ble_hs_adv_fields *fields)
fields->uuids128_is_complete ? "" : "in");
u8p = fields->uuids128;
for (i = 0; i < fields->num_uuids128; i++) {
- print_uuid(u8p);
+ ble_uuid_init_from_buf(&uuid, u8p, 16);
+ print_uuid(&uuid.u);
BLECENT_LOG(DEBUG, " ");
u8p += 16;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/apps/blecent/src/peer.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/peer.c b/apps/blecent/src/peer.c
index 766ccd3..05ec8a0 100644
--- a/apps/blecent/src/peer.c
+++ b/apps/blecent/src/peer.c
@@ -497,12 +497,12 @@ peer_svc_find_range(struct peer *peer, uint16_t
attr_handle)
}
const struct peer_svc *
-peer_svc_find_uuid(const struct peer *peer, const uint8_t *uuid128)
+peer_svc_find_uuid(const struct peer *peer, const ble_uuid_t *uuid)
{
const struct peer_svc *svc;
SLIST_FOREACH(svc, &peer->svcs, next) {
- if (memcmp(svc->svc.uuid128, uuid128, 16) == 0) {
+ if (ble_uuid_cmp(&svc->svc.uuid.u, uuid) == 0) {
return svc;
}
}
@@ -511,19 +511,19 @@ peer_svc_find_uuid(const struct peer *peer, const uint8_t
*uuid128)
}
const struct peer_chr *
-peer_chr_find_uuid(const struct peer *peer, const uint8_t *svc_uuid128,
- const uint8_t *chr_uuid128)
+peer_chr_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
+ const ble_uuid_t *chr_uuid)
{
const struct peer_svc *svc;
const struct peer_chr *chr;
- svc = peer_svc_find_uuid(peer, svc_uuid128);
+ svc = peer_svc_find_uuid(peer, svc_uuid);
if (svc == NULL) {
return NULL;
}
SLIST_FOREACH(chr, &svc->chrs, next) {
- if (memcmp(chr->chr.uuid128, chr_uuid128, 16) == 0) {
+ if (ble_uuid_cmp(&chr->chr.uuid.u, chr_uuid) == 0) {
return chr;
}
}
@@ -532,19 +532,19 @@ peer_chr_find_uuid(const struct peer *peer, const uint8_t
*svc_uuid128,
}
const struct peer_dsc *
-peer_dsc_find_uuid(const struct peer *peer, const uint8_t *svc_uuid128,
- const uint8_t *chr_uuid128, const uint8_t *dsc_uuid128)
+peer_dsc_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
+ const ble_uuid_t *chr_uuid, const ble_uuid_t *dsc_uuid)
{
const struct peer_chr *chr;
const struct peer_dsc *dsc;
- chr = peer_chr_find_uuid(peer, svc_uuid128, chr_uuid128);
+ chr = peer_chr_find_uuid(peer, svc_uuid, chr_uuid);
if (chr == NULL) {
return NULL;
}
SLIST_FOREACH(dsc, &chr->dscs, next) {
- if (memcmp(dsc->dsc.uuid128, dsc_uuid128, 16) == 0) {
+ if (ble_uuid_cmp(&dsc->dsc.uuid.u, dsc_uuid) == 0) {
return dsc;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/apps/bleprph/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/gatt_svr.c b/apps/bleprph/src/gatt_svr.c
index 2a64547..7025aaf 100644
--- a/apps/bleprph/src/gatt_svr.c
+++ b/apps/bleprph/src/gatt_svr.c
@@ -22,6 +22,7 @@
#include <string.h>
#include "bsp/bsp.h"
#include "host/ble_hs.h"
+#include "host/ble_uuid.h"
#include "bleprph.h"
/**
@@ -34,22 +35,19 @@
*/
/* 59462f12-9543-9999-12c8-58b459a2712d */
-const uint8_t gatt_svr_svc_sec_test_uuid[16] = {
- 0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12,
- 0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59
-};
+static const ble_uuid128_t gatt_svr_svc_sec_test_uuid =
+ BLE_UUID128_INIT(0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12,
+ 0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59);
/* 5c3a659e-897e-45e1-b016-007107c96df6 */
-const uint8_t gatt_svr_chr_sec_test_rand_uuid[16] = {
- 0xf6, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
- 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c
-};
+static const ble_uuid128_t gatt_svr_chr_sec_test_rand_uuid =
+ BLE_UUID128_INIT(0xf6, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
+ 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
/* 5c3a659e-897e-45e1-b016-007107c96df7 */
-const uint8_t gatt_svr_chr_sec_test_static_uuid[16] = {
- 0xf7, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
- 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c
-};
+static const ble_uuid128_t gatt_svr_chr_sec_test_static_uuid =
+ BLE_UUID128_INIT(0xf7, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
+ 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
static uint8_t gatt_svr_sec_test_static_val;
@@ -62,15 +60,15 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
{
/*** Service: Security test. */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = gatt_svr_svc_sec_test_uuid,
+ .uuid = &gatt_svr_svc_sec_test_uuid.u,
.characteristics = (struct ble_gatt_chr_def[]) { {
/*** Characteristic: Random number generator. */
- .uuid128 = gatt_svr_chr_sec_test_rand_uuid,
+ .uuid = &gatt_svr_chr_sec_test_rand_uuid.u,
.access_cb = gatt_svr_chr_access_sec_test,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC,
}, {
/*** Characteristic: Static value. */
- .uuid128 = gatt_svr_chr_sec_test_static_uuid,
+ .uuid = &gatt_svr_chr_sec_test_static_uuid.u,
.access_cb = gatt_svr_chr_access_sec_test,
.flags = BLE_GATT_CHR_F_READ |
BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_ENC,
@@ -109,17 +107,17 @@ gatt_svr_chr_access_sec_test(uint16_t conn_handle,
uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt,
void *arg)
{
- const void *uuid128;
+ const ble_uuid_t *uuid;
int rand_num;
int rc;
- uuid128 = ctxt->chr->uuid128;
+ uuid = ctxt->chr->uuid;
/* Determine which characteristic is being accessed by examining its
* 128-bit UUID.
*/
- if (memcmp(uuid128, gatt_svr_chr_sec_test_rand_uuid, 16) == 0) {
+ if (ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_rand_uuid.u) == 0) {
assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
/* Respond with a 32-bit random number. */
@@ -128,7 +126,7 @@ gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t
attr_handle,
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
- if (memcmp(uuid128, gatt_svr_chr_sec_test_static_uuid, 16) == 0) {
+ if (ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_static_uuid.u) == 0) {
switch (ctxt->op) {
case BLE_GATT_ACCESS_OP_READ_CHR:
rc = os_mbuf_append(ctxt->om, &gatt_svr_sec_test_static_val,
@@ -155,51 +153,29 @@ gatt_svr_chr_access_sec_test(uint16_t conn_handle,
uint16_t attr_handle,
return BLE_ATT_ERR_UNLIKELY;
}
-static char *
-gatt_svr_uuid_to_s(const void *uuid128, char *dst)
-{
- const uint8_t *u8p;
- uint16_t uuid16;
-
- uuid16 = ble_uuid_128_to_16(uuid128);
- if (uuid16 != 0) {
- sprintf(dst, "0x%04x", uuid16);
- return dst;
- }
-
- u8p = uuid128;
-
- sprintf(dst, "%02x%02x%02x%02x-", u8p[15], u8p[14], u8p[13], u8p[12]);
- sprintf(dst + 9, "%02x%02x-%02x%02x-", u8p[11], u8p[10], u8p[9], u8p[8]);
- sprintf(dst + 19, "%02x%02x%02x%02x%02x%02x%02x%02x",
- u8p[7], u8p[6], u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
-
- return dst;
-}
-
void
gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
{
- char buf[40];
+ char buf[BLE_UUID_STR_LEN];
switch (ctxt->op) {
case BLE_GATT_REGISTER_OP_SVC:
BLEPRPH_LOG(DEBUG, "registered service %s with handle=%d\n",
- gatt_svr_uuid_to_s(ctxt->svc.svc_def->uuid128, buf),
+ ble_uuid_to_str(ctxt->svc.svc_def->uuid, buf),
ctxt->svc.handle);
break;
case BLE_GATT_REGISTER_OP_CHR:
BLEPRPH_LOG(DEBUG, "registering characteristic %s with "
"def_handle=%d val_handle=%d\n",
- gatt_svr_uuid_to_s(ctxt->chr.chr_def->uuid128, buf),
+ ble_uuid_to_str(ctxt->chr.chr_def->uuid, buf),
ctxt->chr.def_handle,
ctxt->chr.val_handle);
break;
case BLE_GATT_REGISTER_OP_DSC:
BLEPRPH_LOG(DEBUG, "registering descriptor %s with handle=%d\n",
- gatt_svr_uuid_to_s(ctxt->dsc.dsc_def->uuid128, buf),
+ ble_uuid_to_str(ctxt->dsc.dsc_def->uuid, buf),
ctxt->dsc.handle);
break;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/apps/bleprph_oic/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bleprph_oic/src/gatt_svr.c b/apps/bleprph_oic/src/gatt_svr.c
index 3e3ef21..659a9c1 100644
--- a/apps/bleprph_oic/src/gatt_svr.c
+++ b/apps/bleprph_oic/src/gatt_svr.c
@@ -34,22 +34,19 @@
*/
/* 59462f12-9543-9999-12c8-58b459a2712d */
-const uint8_t gatt_svr_svc_sec_test_uuid[16] = {
- 0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12,
- 0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59
-};
+static const ble_uuid128_t gatt_svr_svc_sec_test_uuid =
+ BLE_UUID128_INIT(0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12, \
+ 0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59);
/* 5c3a659e-897e-45e1-b016-007107c96df6 */
-const uint8_t gatt_svr_chr_sec_test_rand_uuid[16] = {
- 0xf6, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
- 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c
-};
+static const ble_uuid128_t gatt_svr_chr_sec_test_rand_uuid =
+ BLE_UUID128_INIT(0xf6, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0, \
+ 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
/* 5c3a659e-897e-45e1-b016-007107c96df7 */
-const uint8_t gatt_svr_chr_sec_test_static_uuid[16] = {
- 0xf7, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
- 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c
-};
+static const ble_uuid128_t gatt_svr_chr_sec_test_static_uuid =
+ BLE_UUID128_INIT(0xf7, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0, \
+ 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
static uint8_t gatt_svr_sec_test_static_val;
@@ -67,25 +64,25 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
{
/*** Alert Notification Service. */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = BLE_UUID16(GATT_SVR_SVC_ALERT_UUID),
+ .uuid = BLE_UUID16_DECLARE(GATT_SVR_SVC_ALERT_UUID),
.characteristics = (struct ble_gatt_chr_def[]) { {
- .uuid128 = BLE_UUID16(GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID),
+ .uuid = BLE_UUID16_DECLARE(GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID),
.access_cb = gatt_svr_chr_access_alert,
.flags = BLE_GATT_CHR_F_READ,
}, {
- .uuid128 = BLE_UUID16(GATT_SVR_CHR_NEW_ALERT),
+ .uuid = BLE_UUID16_DECLARE(GATT_SVR_CHR_NEW_ALERT),
.access_cb = gatt_svr_chr_access_alert,
.flags = BLE_GATT_CHR_F_NOTIFY,
}, {
- .uuid128 = BLE_UUID16(GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID),
+ .uuid = BLE_UUID16_DECLARE(GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID),
.access_cb = gatt_svr_chr_access_alert,
.flags = BLE_GATT_CHR_F_READ,
}, {
- .uuid128 = BLE_UUID16(GATT_SVR_CHR_UNR_ALERT_STAT_UUID),
+ .uuid = BLE_UUID16_DECLARE(GATT_SVR_CHR_UNR_ALERT_STAT_UUID),
.access_cb = gatt_svr_chr_access_alert,
.flags = BLE_GATT_CHR_F_NOTIFY,
}, {
- .uuid128 = BLE_UUID16(GATT_SVR_CHR_ALERT_NOT_CTRL_PT),
+ .uuid = BLE_UUID16_DECLARE(GATT_SVR_CHR_ALERT_NOT_CTRL_PT),
.access_cb = gatt_svr_chr_access_alert,
.flags = BLE_GATT_CHR_F_WRITE,
}, {
@@ -96,15 +93,15 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
{
/*** Service: Security test. */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = gatt_svr_svc_sec_test_uuid,
+ .uuid = &gatt_svr_svc_sec_test_uuid.u,
.characteristics = (struct ble_gatt_chr_def[]) { {
/*** Characteristic: Random number generator. */
- .uuid128 = gatt_svr_chr_sec_test_rand_uuid,
+ .uuid = &gatt_svr_chr_sec_test_rand_uuid.u,
.access_cb = gatt_svr_chr_access_sec_test,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC,
}, {
/*** Characteristic: Static value. */
- .uuid128 = gatt_svr_chr_sec_test_static_uuid,
+ .uuid = &gatt_svr_chr_sec_test_static_uuid.u,
.access_cb = gatt_svr_chr_access_sec_test,
.flags = BLE_GATT_CHR_F_READ |
BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_ENC,
@@ -155,7 +152,7 @@ gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t
attr_handle,
uint16_t uuid16;
int rc;
- uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128);
+ uuid16 = ble_uuid_u16(ctxt->chr->uuid);
assert(uuid16 != 0);
switch (uuid16) {
@@ -215,17 +212,17 @@ gatt_svr_chr_access_sec_test(uint16_t conn_handle,
uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt,
void *arg)
{
- const void *uuid128;
+ const ble_uuid_t *uuid;
int rand_num;
int rc;
- uuid128 = ctxt->chr->uuid128;
+ uuid = ctxt->chr->uuid;
/* Determine which characteristic is being accessed by examining its
* 128-bit UUID.
*/
- if (memcmp(uuid128, gatt_svr_chr_sec_test_rand_uuid, 16) == 0) {
+ if (ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_rand_uuid.u) == 0) {
assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
/* Respond with a 32-bit random number. */
@@ -234,7 +231,7 @@ gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t
attr_handle,
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
- if (memcmp(uuid128, gatt_svr_chr_sec_test_static_uuid, 16) == 0) {
+ if (ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_static_uuid.u) == 0) {
switch (ctxt->op) {
case BLE_GATT_ACCESS_OP_READ_CHR:
rc = os_mbuf_append(ctxt->om, &gatt_svr_sec_test_static_val,
@@ -261,51 +258,29 @@ gatt_svr_chr_access_sec_test(uint16_t conn_handle,
uint16_t attr_handle,
return BLE_ATT_ERR_UNLIKELY;
}
-static char *
-gatt_svr_uuid_to_s(const void *uuid128, char *dst)
-{
- const uint8_t *u8p;
- uint16_t uuid16;
-
- uuid16 = ble_uuid_128_to_16(uuid128);
- if (uuid16 != 0) {
- sprintf(dst, "0x%04x", uuid16);
- return dst;
- }
-
- u8p = uuid128;
-
- sprintf(dst, "%02x%02x%02x%02x-", u8p[15], u8p[14], u8p[13], u8p[12]);
- sprintf(dst + 9, "%02x%02x-%02x%02x-", u8p[11], u8p[10], u8p[9], u8p[8]);
- sprintf(dst + 19, "%02x%02x%02x%02x%02x%02x%02x%02x",
- u8p[7], u8p[6], u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
-
- return dst;
-}
-
void
gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
{
- char buf[40];
+ char buf[BLE_UUID_STR_LEN];
switch (ctxt->op) {
case BLE_GATT_REGISTER_OP_SVC:
BLEPRPH_LOG(DEBUG, "registered service %s with handle=%d\n",
- gatt_svr_uuid_to_s(ctxt->svc.svc_def->uuid128, buf),
+ ble_uuid_to_str(ctxt->svc.svc_def->uuid, buf),
ctxt->svc.handle);
break;
case BLE_GATT_REGISTER_OP_CHR:
BLEPRPH_LOG(DEBUG, "registering characteristic %s with "
"def_handle=%d val_handle=%d\n",
- gatt_svr_uuid_to_s(ctxt->chr.chr_def->uuid128, buf),
+ ble_uuid_to_str(ctxt->chr.chr_def->uuid, buf),
ctxt->chr.def_handle,
ctxt->chr.val_handle);
break;
case BLE_GATT_REGISTER_OP_DSC:
BLEPRPH_LOG(DEBUG, "registering descriptor %s with handle=%d\n",
- gatt_svr_uuid_to_s(ctxt->dsc.dsc_def->uuid128, buf),
+ ble_uuid_to_str(ctxt->dsc.dsc_def->uuid, buf),
ctxt->dsc.handle);
break;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/apps/bleprph_oic/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph_oic/src/main.c b/apps/bleprph_oic/src/main.c
index b59e12b..b5fa010 100755
--- a/apps/bleprph_oic/src/main.c
+++ b/apps/bleprph_oic/src/main.c
@@ -124,7 +124,8 @@ bleprph_advertise(void)
fields.name_len = strlen(name);
fields.name_is_complete = 1;
- fields.uuids128 = (void *)oc_gatt_svc_uuid;
+ fields.uuids128 =
+ BLE_UUID128(BLE_UUID128_DECLARE(OC_GATT_SERVICE_UUID))->value;
fields.num_uuids128 = 1;
fields.uuids128_is_complete = 1;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index 32f4ea3..3c11b1d 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -115,7 +115,7 @@ int parse_arg_kv_default(char *name, struct kv_pair *kvs,
int def_val,
int parse_arg_byte_stream(char *name, int max_len, uint8_t *dst, int *out_len);
int parse_arg_byte_stream_exact_length(char *name, uint8_t *dst, int len);
int parse_arg_mac(char *name, uint8_t *dst);
-int parse_arg_uuid(char *name, uint8_t *dst_uuid128);
+int parse_arg_uuid(char *name, ble_uuid_any_t *uuid);
int parse_err_too_few_args(char *cmd_name);
int parse_arg_all(int argc, char **argv);
int cmd_init(void);
@@ -128,11 +128,11 @@ void bletiny_lock(void);
void bletiny_unlock(void);
int bletiny_exchange_mtu(uint16_t conn_handle);
int bletiny_disc_svcs(uint16_t conn_handle);
-int bletiny_disc_svc_by_uuid(uint16_t conn_handle, uint8_t *uuid128);
+int bletiny_disc_svc_by_uuid(uint16_t conn_handle, const ble_uuid_t *uuid);
int bletiny_disc_all_chrs(uint16_t conn_handle, uint16_t start_handle,
uint16_t end_handle);
int bletiny_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
- uint16_t end_handle, uint8_t *uuid128);
+ uint16_t end_handle, const ble_uuid_t *uuid);
int bletiny_disc_all_dscs(uint16_t conn_handle, uint16_t chr_val_handle,
uint16_t chr_end_handle);
int bletiny_disc_full(uint16_t conn_handle);
@@ -142,7 +142,7 @@ int bletiny_read(uint16_t conn_handle, uint16_t
attr_handle);
int bletiny_read_long(uint16_t conn_handle, uint16_t attr_handle,
uint16_t offset);
int bletiny_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
- uint16_t end_handle, uint8_t *uuid128);
+ uint16_t end_handle, const ble_uuid_t *uuid);
int bletiny_read_mult(uint16_t conn_handle, uint16_t *attr_handles,
int num_attr_handles);
int bletiny_write(uint16_t conn_handle, uint16_t attr_handle,
@@ -202,7 +202,7 @@ int gatt_svr_init(void);
void print_bytes(const uint8_t *bytes, int len);
void print_mbuf(const struct os_mbuf *om);
void print_addr(const void *addr);
-void print_uuid(const void *uuid128);
+void print_uuid(const ble_uuid_t *uuid);
int svc_is_empty(const struct bletiny_svc *svc);
uint16_t chr_end_handle(const struct bletiny_svc *svc,
const struct bletiny_chr *chr);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 99c29b4..533d163 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -79,7 +79,7 @@ static void
cmd_print_dsc(struct bletiny_dsc *dsc)
{
console_printf(" dsc_handle=%d uuid=", dsc->dsc.handle);
- print_uuid(dsc->dsc.uuid128);
+ print_uuid(&dsc->dsc.uuid.u);
console_printf("\n");
}
@@ -91,7 +91,7 @@ cmd_print_chr(struct bletiny_chr *chr)
console_printf(" def_handle=%d val_handle=%d properties=0x%02x "
"uuid=", chr->chr.def_handle, chr->chr.val_handle,
chr->chr.properties);
- print_uuid(chr->chr.uuid128);
+ print_uuid(&chr->chr.uuid.u);
console_printf("\n");
SLIST_FOREACH(dsc, &chr->dscs, next) {
@@ -106,7 +106,7 @@ cmd_print_svc(struct bletiny_svc *svc)
console_printf(" start=%d end=%d uuid=", svc->svc.start_handle,
svc->svc.end_handle);
- print_uuid(svc->svc.uuid128);
+ print_uuid(&svc->svc.uuid.u);
console_printf("\n");
SLIST_FOREACH(chr, &svc->chrs, next) {
@@ -830,7 +830,7 @@ cmd_disc_chr(int argc, char **argv)
uint16_t start_handle;
uint16_t conn_handle;
uint16_t end_handle;
- uint8_t uuid128[16];
+ ble_uuid_any_t uuid;
int rc;
if (argc > 1 && strcmp(argv[1], "help") == 0) {
@@ -845,10 +845,10 @@ cmd_disc_chr(int argc, char **argv)
return rc;
}
- rc = parse_arg_uuid("uuid", uuid128);
+ rc = parse_arg_uuid("uuid", &uuid);
if (rc == 0) {
rc = bletiny_disc_chrs_by_uuid(conn_handle, start_handle, end_handle,
- uuid128);
+ &uuid.u);
} else if (rc == ENOENT) {
rc = bletiny_disc_all_chrs(conn_handle, start_handle, end_handle);
} else {
@@ -915,7 +915,7 @@ bletiny_disc_svc_help(void)
static int
cmd_disc_svc(int argc, char **argv)
{
- uint8_t uuid128[16];
+ ble_uuid_any_t uuid;
int conn_handle;
int rc;
@@ -931,9 +931,9 @@ cmd_disc_svc(int argc, char **argv)
return rc;
}
- rc = parse_arg_uuid("uuid", uuid128);
+ rc = parse_arg_uuid("uuid", &uuid);
if (rc == 0) {
- rc = bletiny_disc_svc_by_uuid(conn_handle, uuid128);
+ rc = bletiny_disc_svc_by_uuid(conn_handle, &uuid.u);
} else if (rc == ENOENT) {
rc = bletiny_disc_svcs(conn_handle);
} else {
@@ -1274,7 +1274,7 @@ cmd_read(int argc, char **argv)
uint16_t start;
uint16_t end;
uint16_t offset;
- uint8_t uuid128[16];
+ ble_uuid_any_t uuid;
uint8_t num_attr_handles;
int is_uuid;
int is_long;
@@ -1315,7 +1315,7 @@ cmd_read(int argc, char **argv)
}
}
- rc = parse_arg_uuid("uuid", uuid128);
+ rc = parse_arg_uuid("uuid", &uuid);
if (rc == ENOENT) {
is_uuid = 0;
} else if (rc == 0) {
@@ -1365,7 +1365,7 @@ cmd_read(int argc, char **argv)
if (start == 0 || end == 0) {
rc = EINVAL;
} else {
- rc = bletiny_read_by_uuid(conn_handle, start, end, uuid128);
+ rc = bletiny_read_by_uuid(conn_handle, start, end, &uuid.u);
}
} else {
rc = EINVAL;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/apps/bletiny/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/gatt_svr.c b/apps/bletiny/src/gatt_svr.c
index 67b13b2..354ff9f 100644
--- a/apps/bletiny/src/gatt_svr.c
+++ b/apps/bletiny/src/gatt_svr.c
@@ -18,19 +18,19 @@
*/
#include <assert.h>
-#include <stdio.h>
#include <string.h>
#include "bsp/bsp.h"
#include "console/console.h"
#include "host/ble_hs.h"
+#include "host/ble_uuid.h"
#include "bletiny.h"
-/* 00xxxx-8c26-476f-89a7-a108033a69c7 */
-#define PTS_UUID(uuid16) ((uint8_t[16]) { \
- 0xc7, 0x69, 0x3a, 0x03, 0x08, 0xa1, 0xa7, 0x89, \
- 0x6f, 0x47, 0x26, 0x8c, (uuid16) & 0xff, (((uuid16) & 0xff00) >> 8), \
- 0x00, 0x00 \
-})
+/* 0000xxxx-8c26-476f-89a7-a108033a69c7 */
+#define PTS_UUID_DECLARE(uuid16) \
+ ((const ble_uuid_t *) (&(ble_uuid128_t) BLE_UUID128_INIT( \
+ 0xc7, 0x69, 0x3a, 0x03, 0x08, 0xa1, 0xa7, 0x89, \
+ 0x6f, 0x47, 0x26, 0x8c, uuid16, uuid16 >> 8, 0x00, 0x00 \
+ )))
#define PTS_SVC 0x0001
#define PTS_CHR_READ 0x0002
@@ -70,28 +70,24 @@
*/
/* 59462f12-9543-9999-12c8-58b459a2712d */
-const uint8_t gatt_svr_svc_sec_test_uuid[16] = {
- 0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12,
- 0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59
-};
+static const ble_uuid128_t gatt_svr_svc_sec_test_uuid =
+ BLE_UUID128_INIT(0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12,
+ 0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59);
/* 5c3a659e-897e-45e1-b016-007107c96df6 */
-const uint8_t gatt_svr_chr_sec_test_rand_uuid[16] = {
- 0xf6, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
- 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c
-};
+static const ble_uuid128_t gatt_svr_chr_sec_test_rand_uuid =
+ BLE_UUID128_INIT(0xf6, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
+ 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
/* 5c3a659e-897e-45e1-b016-007107c96df7 */
-const uint8_t gatt_svr_chr_sec_test_static_uuid[16] = {
- 0xf7, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
- 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c
-};
+static const ble_uuid128_t gatt_svr_chr_sec_test_static_uuid =
+ BLE_UUID128_INIT(0xf7, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
+ 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
/* 5c3a659e-897e-45e1-b016-007107c96df8 */
-const uint8_t gatt_svr_chr_sec_test_static_auth_uuid[16] = {
- 0xf8, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
- 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c
-};
+static const ble_uuid128_t gatt_svr_chr_sec_test_static_auth_uuid =
+ BLE_UUID128_INIT(0xf8, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
+ 0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
static uint8_t gatt_svr_sec_test_static_val;
@@ -118,59 +114,59 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
{
/*** Service: PTS test. */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = PTS_UUID(PTS_SVC),
+ .uuid = PTS_UUID_DECLARE(PTS_SVC),
.characteristics = (struct ble_gatt_chr_def[]) { {
- .uuid128 = PTS_UUID(PTS_CHR_READ),
+ .uuid = PTS_UUID_DECLARE(PTS_CHR_READ),
.access_cb = gatt_svr_access_test,
.flags = BLE_GATT_CHR_F_READ,
}, {
- .uuid128 = PTS_UUID(PTS_CHR_WRITE),
+ .uuid = PTS_UUID_DECLARE(PTS_CHR_WRITE),
.access_cb = gatt_svr_access_test,
.flags = BLE_GATT_CHR_F_WRITE,
}, {
- .uuid128 = PTS_UUID(PTS_CHR_RELIABLE_WRITE),
+ .uuid = PTS_UUID_DECLARE(PTS_CHR_RELIABLE_WRITE),
.access_cb = gatt_svr_access_test,
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_RELIABLE_WRITE,
}, {
- .uuid128 = PTS_UUID(PTS_CHR_WRITE_NO_RSP),
+ .uuid = PTS_UUID_DECLARE(PTS_CHR_WRITE_NO_RSP),
.access_cb = gatt_svr_access_test,
.flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
}, {
- .uuid128 = PTS_UUID(PTS_CHR_READ_WRITE),
+ .uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE),
.access_cb = gatt_svr_access_test,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
}, {
- .uuid128 = PTS_UUID(PTS_CHR_READ_WRITE_ENC),
+ .uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_ENC),
.access_cb = gatt_svr_access_test,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC |
BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_ENC,
.min_key_size = 16,
}, {
- .uuid128 = PTS_UUID(PTS_CHR_READ_WRITE_AUTHEN),
+ .uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_AUTHEN),
.access_cb = gatt_svr_access_test,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_AUTHEN |
BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_AUTHEN,
.descriptors = (struct ble_gatt_dsc_def[]){ {
- .uuid128 = PTS_UUID(PTS_DSC_READ),
+ .uuid = PTS_UUID_DECLARE(PTS_DSC_READ),
.access_cb = gatt_svr_access_test,
.att_flags = BLE_ATT_F_READ,
}, {
- .uuid128 = PTS_UUID(PTS_DSC_WRITE),
+ .uuid = PTS_UUID_DECLARE(PTS_DSC_WRITE),
.access_cb = gatt_svr_access_test,
.att_flags = BLE_ATT_F_WRITE,
}, {
- .uuid128 = PTS_UUID(PTS_DSC_READ_WRITE),
+ .uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE),
.access_cb = gatt_svr_access_test,
.att_flags = BLE_ATT_F_READ | BLE_ATT_F_WRITE,
}, {
- .uuid128 = PTS_UUID(PTS_DSC_READ_WRITE_ENC),
+ .uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE_ENC),
.access_cb = gatt_svr_access_test,
.att_flags = BLE_ATT_F_READ | BLE_ATT_F_READ_ENC |
BLE_ATT_F_WRITE | BLE_ATT_F_WRITE_ENC,
.min_key_size = 16,
}, {
- .uuid128 = PTS_UUID(PTS_DSC_READ_WRITE_AUTHEN),
+ .uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE_AUTHEN),
.access_cb = gatt_svr_access_test,
.att_flags = BLE_ATT_F_READ | BLE_ATT_F_READ_AUTHEN |
BLE_ATT_F_WRITE | BLE_ATT_F_WRITE_AUTHEN,
@@ -185,59 +181,59 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
{
/*** Service: PTS long test. */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = PTS_UUID(PTS_LONG_SVC),
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_SVC),
.characteristics = (struct ble_gatt_chr_def[]) { {
- .uuid128 = PTS_UUID(PTS_LONG_CHR_READ),
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ),
.access_cb = gatt_svr_long_access_test,
.flags = BLE_GATT_CHR_F_READ,
}, {
- .uuid128 = PTS_UUID(PTS_LONG_CHR_WRITE),
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_WRITE),
.access_cb = gatt_svr_long_access_test,
.flags = BLE_GATT_CHR_F_WRITE,
}, {
- .uuid128 = PTS_UUID(PTS_LONG_CHR_RELIABLE_WRITE),
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_RELIABLE_WRITE),
.access_cb = gatt_svr_long_access_test,
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_RELIABLE_WRITE,
}, {
- .uuid128 = PTS_UUID(PTS_LONG_CHR_READ_WRITE),
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE),
.access_cb = gatt_svr_long_access_test,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
}, {
- .uuid128 = PTS_UUID(PTS_LONG_CHR_READ_WRITE_ALT),
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE_ALT),
.access_cb = gatt_svr_long_access_test,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
}, {
- .uuid128 = PTS_UUID(PTS_LONG_CHR_READ_WRITE_ENC),
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE_ENC),
.access_cb = gatt_svr_long_access_test,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC |
BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_ENC,
.min_key_size = 16,
}, {
- .uuid128 = PTS_UUID(PTS_LONG_CHR_READ_WRITE_AUTHEN),
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE_AUTHEN),
.access_cb = gatt_svr_long_access_test,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_AUTHEN |
BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_AUTHEN,
.descriptors = (struct ble_gatt_dsc_def[]){ {
- .uuid128 = PTS_UUID(PTS_LONG_DSC_READ),
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_READ),
.access_cb = gatt_svr_long_access_test,
.att_flags = BLE_ATT_F_READ,
}, {
- .uuid128 = PTS_UUID(PTS_LONG_DSC_WRITE),
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_WRITE),
.access_cb = gatt_svr_long_access_test,
.att_flags = BLE_ATT_F_WRITE,
}, {
- .uuid128 = PTS_UUID(PTS_LONG_DSC_READ_WRITE),
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_READ_WRITE),
.access_cb = gatt_svr_long_access_test,
.att_flags = BLE_ATT_F_READ | BLE_ATT_F_WRITE,
}, {
- .uuid128 = PTS_UUID(PTS_LONG_DSC_READ_WRITE_ENC),
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_READ_WRITE_ENC),
.access_cb = gatt_svr_long_access_test,
.att_flags = BLE_ATT_F_READ | BLE_ATT_F_READ_ENC |
BLE_ATT_F_WRITE | BLE_ATT_F_WRITE_ENC,
.min_key_size = 16,
}, {
- .uuid128 = PTS_UUID(PTS_LONG_DSC_READ_WRITE_AUTHEN),
+ .uuid =
PTS_UUID_DECLARE(PTS_LONG_DSC_READ_WRITE_AUTHEN),
.access_cb = gatt_svr_long_access_test,
.att_flags = BLE_ATT_F_READ | BLE_ATT_F_READ_AUTHEN |
BLE_ATT_F_WRITE | BLE_ATT_F_WRITE_AUTHEN,
@@ -252,21 +248,21 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
{
/*** Service: Security test. */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = gatt_svr_svc_sec_test_uuid,
+ .uuid = &gatt_svr_svc_sec_test_uuid.u,
.characteristics = (struct ble_gatt_chr_def[]) { {
/*** Characteristic: Random number generator. */
- .uuid128 = gatt_svr_chr_sec_test_rand_uuid,
+ .uuid = &gatt_svr_chr_sec_test_rand_uuid.u,
.access_cb = gatt_svr_chr_access_sec_test,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC,
}, {
/*** Characteristic: Static value. */
- .uuid128 = gatt_svr_chr_sec_test_static_uuid,
+ .uuid = &gatt_svr_chr_sec_test_static_uuid.u,
.access_cb = gatt_svr_chr_access_sec_test,
.flags = BLE_GATT_CHR_F_READ |
BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_ENC,
}, {
/*** Characteristic: Static value. */
- .uuid128 = gatt_svr_chr_sec_test_static_auth_uuid,
+ .uuid = &gatt_svr_chr_sec_test_static_auth_uuid.u,
.access_cb = gatt_svr_chr_access_sec_test,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_AUTHEN,
}, {
@@ -304,17 +300,17 @@ gatt_svr_chr_access_sec_test(uint16_t conn_handle,
uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt,
void *arg)
{
- const void *uuid128;
+ const ble_uuid_t *uuid;
int rand_num;
int rc;
- uuid128 = ctxt->chr->uuid128;
+ uuid = ctxt->chr->uuid;
/* Determine which characteristic is being accessed by examining its
* 128-bit UUID.
*/
- if (memcmp(uuid128, gatt_svr_chr_sec_test_rand_uuid, 16) == 0) {
+ if (ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_rand_uuid.u) == 0) {
assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
/* Respond with a 32-bit random number. */
@@ -323,8 +319,8 @@ gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t
attr_handle,
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
- if (memcmp(uuid128, gatt_svr_chr_sec_test_static_uuid, 16) == 0 ||
- memcmp(uuid128, gatt_svr_chr_sec_test_static_auth_uuid, 16) == 0) {
+ if (ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_static_uuid.u) == 0 ||
+ ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_static_auth_uuid.u) == 0) {
switch (ctxt->op) {
case BLE_GATT_ACCESS_OP_READ_CHR:
rc = os_mbuf_append(ctxt->om, &gatt_svr_sec_test_static_val,
@@ -355,12 +351,12 @@ gatt_svr_chr_access_sec_test(uint16_t conn_handle,
uint16_t attr_handle,
* from 128 bit vendor specific UUID.
*/
static uint16_t
-extract_uuid16_from_pts_uuid128(const void *uuid128)
+extract_uuid16_from_pts_uuid128(const ble_uuid_t *uuid)
{
const uint8_t *u8ptr;
uint16_t uuid16;
- u8ptr = uuid128;
+ u8ptr = BLE_UUID128(uuid)->value;
uuid16 = u8ptr[12];
uuid16 |= (uint16_t)u8ptr[13] << 8;
return uuid16;
@@ -374,7 +370,7 @@ gatt_svr_access_test(uint16_t conn_handle, uint16_t
attr_handle,
uint16_t uuid16;
int rc;
- uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid128);
+ uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
assert(uuid16 != 0);
switch (uuid16) {
@@ -448,7 +444,7 @@ gatt_svr_long_access_test(uint16_t conn_handle, uint16_t
attr_handle,
uint16_t uuid16;
int rc;
- uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid128);
+ uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
assert(uuid16 != 0);
switch (uuid16) {
@@ -536,51 +532,29 @@ gatt_svr_long_access_test(uint16_t conn_handle, uint16_t
attr_handle,
}
}
-static char *
-gatt_svr_uuid_to_s(const void *uuid128, char *dst)
-{
- const uint8_t *u8p;
- uint16_t uuid16;
-
- uuid16 = ble_uuid_128_to_16(uuid128);
- if (uuid16 != 0) {
- sprintf(dst, "0x%04x", uuid16);
- return dst;
- }
-
- u8p = uuid128;
-
- sprintf(dst, "%02x%02x%02x%02x-", u8p[15], u8p[14], u8p[13], u8p[12]);
- sprintf(dst + 9, "%02x%02x-%02x%02x-", u8p[11], u8p[10], u8p[9], u8p[8]);
- sprintf(dst + 19, "%02x%02x%02x%02x%02x%02x%02x%02x",
- u8p[7], u8p[6], u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
-
- return dst;
-}
-
void
gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
{
- char buf[40];
+ char buf[BLE_UUID_STR_LEN];
switch (ctxt->op) {
case BLE_GATT_REGISTER_OP_SVC:
BLETINY_LOG(DEBUG, "registered service %s with handle=%d\n",
- gatt_svr_uuid_to_s(ctxt->svc.svc_def->uuid128, buf),
+ ble_uuid_to_str(ctxt->svc.svc_def->uuid, buf),
ctxt->svc.handle);
break;
case BLE_GATT_REGISTER_OP_CHR:
BLETINY_LOG(DEBUG, "registering characteristic %s with "
"def_handle=%d val_handle=%d\n",
- gatt_svr_uuid_to_s(ctxt->chr.chr_def->uuid128, buf),
+ ble_uuid_to_str(ctxt->chr.chr_def->uuid, buf),
ctxt->chr.def_handle,
ctxt->chr.val_handle);
break;
case BLE_GATT_REGISTER_OP_DSC:
BLETINY_LOG(DEBUG, "registering descriptor %s with handle=%d\n",
- gatt_svr_uuid_to_s(ctxt->dsc.dsc_def->uuid128, buf),
+ ble_uuid_to_str(ctxt->dsc.dsc_def->uuid, buf),
ctxt->dsc.handle);
break;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 0d7623f..f8dbfbc 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -129,6 +129,7 @@ static void
bletiny_print_adv_fields(const struct ble_hs_adv_fields *fields)
{
uint8_t *u8p;
+ ble_uuid_any_t uuid;
int i;
if (fields->flags_is_present) {
@@ -175,7 +176,8 @@ bletiny_print_adv_fields(const struct ble_hs_adv_fields
*fields)
fields->uuids128_is_complete ? "" : "in");
u8p = fields->uuids128;
for (i = 0; i < fields->num_uuids128; i++) {
- print_uuid(u8p);
+ ble_uuid_init_from_buf(&uuid, u8p, 16);
+ print_uuid(&uuid.u);
console_printf(" ");
u8p += 16;
}
@@ -1125,14 +1127,14 @@ bletiny_disc_all_chrs(uint16_t conn_handle, uint16_t
start_handle,
int
bletiny_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
- uint16_t end_handle, uint8_t *uuid128)
+ uint16_t end_handle, const ble_uuid_t *uuid)
{
intptr_t svc_start_handle;
int rc;
svc_start_handle = start_handle;
rc = ble_gattc_disc_chrs_by_uuid(conn_handle, start_handle, end_handle,
- uuid128, bletiny_on_disc_c,
+ uuid, bletiny_on_disc_c,
(void *)svc_start_handle);
return rc;
}
@@ -1147,11 +1149,11 @@ bletiny_disc_svcs(uint16_t conn_handle)
}
int
-bletiny_disc_svc_by_uuid(uint16_t conn_handle, uint8_t *uuid128)
+bletiny_disc_svc_by_uuid(uint16_t conn_handle, const ble_uuid_t *uuid)
{
int rc;
- rc = ble_gattc_disc_svc_by_uuid(conn_handle, uuid128,
+ rc = ble_gattc_disc_svc_by_uuid(conn_handle, uuid,
bletiny_on_disc_s, NULL);
return rc;
}
@@ -1235,11 +1237,11 @@ bletiny_read_long(uint16_t conn_handle, uint16_t
attr_handle, uint16_t offset)
int
bletiny_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
- uint16_t end_handle, uint8_t *uuid128)
+ uint16_t end_handle, const ble_uuid_t *uuid)
{
int rc;
- rc = ble_gattc_read_by_uuid(conn_handle, start_handle, end_handle, uuid128,
+ rc = ble_gattc_read_by_uuid(conn_handle, start_handle, end_handle, uuid,
bletiny_on_read, NULL);
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/apps/bletiny/src/misc.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/misc.c b/apps/bletiny/src/misc.c
index 90ec844..e8ed345 100644
--- a/apps/bletiny/src/misc.c
+++ b/apps/bletiny/src/misc.c
@@ -64,25 +64,13 @@ print_addr(const void *addr)
}
void
-print_uuid(const void *uuid128)
+print_uuid(const ble_uuid_t *uuid)
{
- uint16_t uuid16;
- const uint8_t *u8p;
-
- uuid16 = ble_uuid_128_to_16(uuid128);
- if (uuid16 != 0) {
- console_printf("0x%04x", uuid16);
- return;
- }
+ char buf[BLE_UUID_STR_LEN];
- u8p = uuid128;
+ ble_uuid_to_str(uuid, buf);
- /* 00001101-0000-1000-8000-00805f9b34fb */
- console_printf("%02x%02x%02x%02x-", u8p[15], u8p[14], u8p[13], u8p[12]);
- console_printf("%02x%02x-%02x%02x-", u8p[11], u8p[10], u8p[9], u8p[8]);
- console_printf("%02x%02x%02x%02x%02x%02x%02x%02x",
- u8p[7], u8p[6], u8p[5], u8p[4],
- u8p[3], u8p[2], u8p[1], u8p[0]);
+ console_printf(buf);
}
int
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/apps/bletiny/src/parse.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/parse.c b/apps/bletiny/src/parse.c
index 0b23d83..4cb2eb7 100644
--- a/apps/bletiny/src/parse.c
+++ b/apps/bletiny/src/parse.c
@@ -448,9 +448,11 @@ parse_arg_mac(char *name, uint8_t *dst)
}
int
-parse_arg_uuid(char *str, uint8_t *dst_uuid128)
+parse_arg_uuid(char *str, ble_uuid_any_t *uuid)
{
uint16_t uuid16;
+ uint8_t val[16];
+ int len;
int rc;
uuid16 = parse_arg_uint16_peek(str, &rc);
@@ -460,18 +462,27 @@ parse_arg_uuid(char *str, uint8_t *dst_uuid128)
return ENOENT;
case 0:
- rc = ble_uuid_16_to_128(uuid16, dst_uuid128);
+ len = 2;
+ val[0] = uuid16;
+ val[1] = uuid16 >> 8;
parse_arg_extract(str);
+ break;
+
+ default:
+ len = 16;
+ rc = parse_arg_byte_stream_exact_length(str, val, 16);
if (rc != 0) {
return EINVAL;
- } else {
- return 0;
}
+ parse_reverse_bytes(val, 16);
+ break;
+ }
- default:
- rc = parse_arg_byte_stream_exact_length(str, dst_uuid128, 16);
- parse_reverse_bytes(dst_uuid128, 16);
- return rc;
+ rc = ble_uuid_init_from_buf(uuid, val, len);
+ if (rc != 0) {
+ return EINVAL;
+ } else {
+ return 0;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/apps/bleuart/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleuart/src/main.c b/apps/bleuart/src/main.c
index fa559fc..241fff2 100755
--- a/apps/bleuart/src/main.c
+++ b/apps/bleuart/src/main.c
@@ -96,7 +96,7 @@ bleuart_advertise(void)
fields.tx_pwr_lvl_is_present = 1;
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
- fields.uuids128 = (void *)gatt_svr_svc_uart;
+ fields.uuids128 = BLE_UUID128(&gatt_svr_svc_uart_uuid.u)->value;
fields.num_uuids128 = 1;
fields.uuids128_is_complete = 1;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c
b/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c
index 395e866..4c72200 100644
--- a/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c
+++ b/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c
@@ -45,16 +45,14 @@ uint16_t g_ble_nmgr_attr_handle;
*/
/* {8D53DC1D-1DB7-4CD3-868B-8A527460AA84} */
-const uint8_t gatt_svr_svc_newtmgr[16] = {
- 0x84, 0xaa, 0x60, 0x74, 0x52, 0x8a, 0x8b, 0x86,
- 0xd3, 0x4c, 0xb7, 0x1d, 0x1d, 0xdc, 0x53, 0x8d
-};
+static const ble_uuid128_t gatt_svr_svc_newtmgr =
+ BLE_UUID128_INIT(0x84, 0xaa, 0x60, 0x74, 0x52, 0x8a, 0x8b, 0x86,
+ 0xd3, 0x4c, 0xb7, 0x1d, 0x1d, 0xdc, 0x53, 0x8d);
/* {DA2E7828-FBCE-4E01-AE9E-261174997C48} */
-const uint8_t gatt_svr_chr_newtmgr[16] = {
- 0x48, 0x7c, 0x99, 0x74, 0x11, 0x26, 0x9e, 0xae,
- 0x01, 0x4e, 0xce, 0xfb, 0x28, 0x78, 0x2e, 0xda
-};
+static const ble_uuid128_t gatt_svr_chr_newtmgr =
+ BLE_UUID128_INIT(0x48, 0x7c, 0x99, 0x74, 0x11, 0x26, 0x9e, 0xae,
+ 0x01, 0x4e, 0xce, 0xfb, 0x28, 0x78, 0x2e, 0xda);
static int
gatt_svr_chr_access_newtmgr(uint16_t conn_handle, uint16_t attr_handle,
@@ -64,10 +62,10 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
{
/* Service: newtmgr */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = (void *)gatt_svr_svc_newtmgr,
+ .uuid = &gatt_svr_svc_newtmgr.u,
.characteristics = (struct ble_gatt_chr_def[]) { {
/* Characteristic: Write No Rsp */
- .uuid128 = (void *)gatt_svr_chr_newtmgr,
+ .uuid = &gatt_svr_chr_newtmgr.u,
.access_cb = gatt_svr_chr_access_newtmgr,
.flags = BLE_GATT_CHR_F_WRITE_NO_RSP | BLE_GATT_CHR_F_NOTIFY,
.val_handle = &g_ble_nmgr_attr_handle,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/nimble/host/include/host/ble_gatt.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gatt.h
b/net/nimble/host/include/host/ble_gatt.h
index 5055beb..50b3aad 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -22,6 +22,7 @@
#include <inttypes.h>
#include "host/ble_att.h"
+#include "host/ble_uuid.h"
#ifdef __cplusplus
extern "C" {
#endif
@@ -80,7 +81,7 @@ struct ble_gatt_error {
struct ble_gatt_svc {
uint16_t start_handle;
uint16_t end_handle;
- uint8_t uuid128[16];
+ ble_uuid_any_t uuid;
};
struct ble_gatt_attr {
@@ -93,12 +94,12 @@ struct ble_gatt_chr {
uint16_t def_handle;
uint16_t val_handle;
uint8_t properties;
- uint8_t uuid128[16];
+ ble_uuid_any_t uuid;
};
struct ble_gatt_dsc {
uint16_t handle;
- uint8_t uuid128[16];
+ ble_uuid_any_t uuid;
};
typedef int ble_gatt_mtu_fn(uint16_t conn_handle,
@@ -143,7 +144,7 @@ int ble_gattc_exchange_mtu(uint16_t conn_handle,
ble_gatt_mtu_fn *cb, void *cb_arg);
int ble_gattc_disc_all_svcs(uint16_t conn_handle,
ble_gatt_disc_svc_fn *cb, void *cb_arg);
-int ble_gattc_disc_svc_by_uuid(uint16_t conn_handle, const void *svc_uuid128,
+int ble_gattc_disc_svc_by_uuid(uint16_t conn_handle, const ble_uuid_t *uuid,
ble_gatt_disc_svc_fn *cb, void *cb_arg);
int ble_gattc_find_inc_svcs(uint16_t conn_handle, uint16_t start_handle,
uint16_t end_handle,
@@ -152,7 +153,7 @@ int ble_gattc_disc_all_chrs(uint16_t conn_handle, uint16_t
start_handle,
uint16_t end_handle, ble_gatt_chr_fn *cb,
void *cb_arg);
int ble_gattc_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
- uint16_t end_handle, const void *uuid128,
+ uint16_t end_handle, const ble_uuid_t *uuid,
ble_gatt_chr_fn *cb, void *cb_arg);
int ble_gattc_disc_all_dscs(uint16_t conn_handle, uint16_t chr_val_handle,
uint16_t chr_end_handle,
@@ -160,7 +161,7 @@ int ble_gattc_disc_all_dscs(uint16_t conn_handle, uint16_t
chr_val_handle,
int ble_gattc_read(uint16_t conn_handle, uint16_t attr_handle,
ble_gatt_attr_fn *cb, void *cb_arg);
int ble_gattc_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
- uint16_t end_handle, const void *uuid128,
+ uint16_t end_handle, const ble_uuid_t *uuid,
ble_gatt_attr_fn *cb, void *cb_arg);
int ble_gattc_read_long(uint16_t conn_handle, uint16_t handle, uint16_t offset,
ble_gatt_attr_fn *cb, void *cb_arg);
@@ -201,10 +202,10 @@ typedef uint16_t ble_gatt_chr_flags;
struct ble_gatt_chr_def {
/**
- * Pointer to first element in a uint8_t[16]; use the BLE_UUID16 macro for
- * 16-bit UUIDs; NULL if there are no more characteristics in the service.
+ * Pointer to characteristic UUID; use BLE_UUIDxx_DECLARE macros to declare
+ * proper UUID; NULL if there are no more characteristics in the service.
*/
- const uint8_t *uuid128;
+ const ble_uuid_t *uuid;
/**
* Callback that gets executed when this characteristic is read or
@@ -245,10 +246,10 @@ struct ble_gatt_svc_def {
uint8_t type;
/**
- * Pointer to first element in a uint8_t[16]; use the BLE_UUID16 macro for
- * 16-bit UUIDs.
+ * Pointer to service UUID; use BLE_UUIDxx_DECLARE macros to declare
+ * proper UUID; NULL if there are no more characteristics in the service.
*/
- const uint8_t *uuid128;
+ const ble_uuid_t *uuid;
/**
* Array of pointers to other service definitions. These services are
@@ -266,10 +267,10 @@ struct ble_gatt_svc_def {
struct ble_gatt_dsc_def {
/**
- * The first element in a uint8_t[16]; use the BLE_UUID16 macro for 16-bit
- * UUIDs; NULL if there are no more descriptors in the characteristic.
+ * Pointer to descriptor UUID; use BLE_UUIDxx_DECLARE macros to declare
+ * proper UUID; NULL if there are no more characteristics in the service.
*/
- uint8_t *uuid128;
+ const ble_uuid_t *uuid;
/** Specifies the set of permitted operations for this descriptor. */
uint8_t att_flags;
@@ -450,11 +451,11 @@ int ble_gatts_count_cfg(const struct ble_gatt_svc_def
*defs);
void ble_gatts_chr_updated(uint16_t chr_def_handle);
-int ble_gatts_find_svc(const void *uuid128, uint16_t *out_handle);
-int ble_gatts_find_chr(const void *svc_uuid128, const void *chr_uuid128,
+int ble_gatts_find_svc(const ble_uuid_t *uuid, uint16_t *out_handle);
+int ble_gatts_find_chr(const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid,
uint16_t *out_def_handle, uint16_t *out_val_handle);
-int ble_gatts_find_dsc(const void *svc_uuid128, const void *chr_uuid128,
- const void *dsc_uuid128, uint16_t *out_dsc_handle);
+int ble_gatts_find_dsc(const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid,
+ const ble_uuid_t *dsc_uuid, uint16_t *out_dsc_handle);
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/nimble/host/include/host/ble_uuid.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_uuid.h
b/net/nimble/host/include/host/ble_uuid.h
index 2a7d53d..a2be095 100644
--- a/net/nimble/host/include/host/ble_uuid.h
+++ b/net/nimble/host/include/host/ble_uuid.h
@@ -21,30 +21,90 @@
#define H_BLE_UUID_
#include <inttypes.h>
+#include <stddef.h>
+
#ifdef __cplusplus
extern "C" {
#endif
struct os_mbuf;
-uint16_t ble_uuid_128_to_16(const void *uuid128);
-int ble_uuid_16_to_128(uint16_t uuid16, void *dst);
+enum {
+ BLE_UUID_TYPE_16 = 16,
+ BLE_UUID_TYPE_32 = 32,
+ BLE_UUID_TYPE_128 = 128,
+};
-#define BLE_UUID16_ARR(uuid16) { \
- 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, \
- 0x00, 0x10, 0x00, 0x00, (uuid16) & 0xff, (((uuid16) & 0xff00) >> 8), \
- 0x00, 0x00 \
-}
+/* Generic UUID type, to be used only as a pointer */
+typedef struct {
+ uint8_t type;
+} ble_uuid_t;
-/**
- * Expands to a designated initializer byte array containing the 128-bit
- * representation of the specified 16-bit UUID.
- */
-#define BLE_UUID16(uuid16) ((uint8_t[16]) { \
- 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, \
- 0x00, 0x10, 0x00, 0x00, (uuid16) & 0xff, (((uuid16) & 0xff00) >> 8), \
- 0x00, 0x00 \
-})
+typedef struct {
+ ble_uuid_t u;
+ uint16_t value;
+} ble_uuid16_t;
+
+typedef struct {
+ ble_uuid_t u;
+ uint32_t value;
+} ble_uuid32_t;
+
+typedef struct {
+ ble_uuid_t u;
+ uint8_t value[16];
+} ble_uuid128_t;
+
+/* Universal UUID type, to be used for any-UUID static allocation */
+typedef union {
+ ble_uuid_t u;
+ ble_uuid16_t u16;
+ ble_uuid32_t u32;
+ ble_uuid128_t u128;
+} ble_uuid_any_t;
+
+#define BLE_UUID16_INIT(uuid16) \
+ { \
+ .u.type = BLE_UUID_TYPE_16, \
+ .value = (uuid16), \
+ }
+
+#define BLE_UUID32_INIT(uuid32) \
+ { \
+ .u.type = BLE_UUID_TYPE_32, \
+ .value = (uuid32), \
+ }
+
+#define BLE_UUID128_INIT(uuid128...) \
+ { \
+ .u.type = BLE_UUID_TYPE_128, \
+ .value = { uuid128 }, \
+ }
+
+#define BLE_UUID16_DECLARE(uuid16) \
+ ((ble_uuid_t *) (&(ble_uuid16_t) BLE_UUID16_INIT(uuid16)))
+
+#define BLE_UUID32_DECLARE(uuid32) \
+ ((ble_uuid_t *) (&(ble_uuid32_t) BLE_UUID32_INIT(uuid32)))
+
+#define BLE_UUID128_DECLARE(uuid128...) \
+ ((ble_uuid_t *) (&(ble_uuid128_t) BLE_UUID128_INIT(uuid128)))
+
+#define BLE_UUID16(u) \
+ ((ble_uuid16_t *) (u))
+
+#define BLE_UUID32(u) \
+ ((ble_uuid32_t *) (u))
+
+#define BLE_UUID128(u) \
+ ((ble_uuid128_t *) (u))
+
+#define BLE_UUID_STR_LEN (37)
+
+int ble_uuid_init_from_buf(ble_uuid_any_t *uuid, const void *buf, size_t len);
+int ble_uuid_cmp(const ble_uuid_t *uuid1, const ble_uuid_t *uuid2);
+char *ble_uuid_to_str(const ble_uuid_t *uuid, char *dst);
+uint16_t ble_uuid_u16(const ble_uuid_t *uuid);
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/nimble/host/profiles/lls/src/ble_svc_lls.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/profiles/lls/src/ble_svc_lls.c
b/net/nimble/host/profiles/lls/src/ble_svc_lls.c
index dca7ee8..c896c80 100644
--- a/net/nimble/host/profiles/lls/src/ble_svc_lls.c
+++ b/net/nimble/host/profiles/lls/src/ble_svc_lls.c
@@ -42,10 +42,10 @@ static const struct ble_gatt_svc_def ble_svc_lls_defs[] = {
{
/*** Service: Link Loss Service (LLS). */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = BLE_UUID16(BLE_SVC_LLS_UUID16),
+ .uuid = BLE_UUID16(BLE_SVC_LLS_UUID16),
.characteristics = (struct ble_gatt_chr_def[]) { {
/*** Characteristic: Alert Level. */
- .uuid128 = BLE_UUID16(BLE_SVC_LLS_CHR_UUID16_ALERT_LEVEL),
+ .uuid = BLE_UUID16(BLE_SVC_LLS_CHR_UUID16_ALERT_LEVEL),
.access_cb = ble_svc_lls_access,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
}, {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/nimble/host/services/ans/src/ble_svc_ans.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/src/ble_svc_ans.c
b/net/nimble/host/services/ans/src/ble_svc_ans.c
index ca4ee8a..f3386a5 100644
--- a/net/nimble/host/services/ans/src/ble_svc_ans.c
+++ b/net/nimble/host/services/ans/src/ble_svc_ans.c
@@ -81,14 +81,14 @@ static const struct ble_gatt_svc_def ble_svc_ans_defs[] = {
{
/*** Alert Notification Service. */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = BLE_UUID16(BLE_SVC_ANS_UUID16),
+ .uuid = BLE_UUID16_DECLARE(BLE_SVC_ANS_UUID16),
.characteristics = (struct ble_gatt_chr_def[]) { {
/** Supported New Alert Catagory
*
* This characteristic exposes what categories of new
* alert are supported in the server.
*/
- .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_SUP_NEW_ALERT_CAT),
+ .uuid =
BLE_UUID16_DECLARE(BLE_SVC_ANS_CHR_UUID16_SUP_NEW_ALERT_CAT),
.access_cb = ble_svc_ans_access,
.flags = BLE_GATT_CHR_F_READ,
}, {
@@ -97,7 +97,7 @@ static const struct ble_gatt_svc_def ble_svc_ans_defs[] = {
* This characteristic exposes information about
* the count of new alerts (for a given category).
*/
- .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_NEW_ALERT),
+ .uuid = BLE_UUID16_DECLARE(BLE_SVC_ANS_CHR_UUID16_NEW_ALERT),
.access_cb = ble_svc_ans_access,
.val_handle = &ble_svc_ans_new_alert_val_handle,
.flags = BLE_GATT_CHR_F_NOTIFY,
@@ -107,7 +107,7 @@ static const struct ble_gatt_svc_def ble_svc_ans_defs[] = {
* This characteristic exposes what categories of
* unread alert are supported in the server.
*/
- .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_SUP_UNR_ALERT_CAT),
+ .uuid =
BLE_UUID16_DECLARE(BLE_SVC_ANS_CHR_UUID16_SUP_UNR_ALERT_CAT),
.access_cb = ble_svc_ans_access,
.flags = BLE_GATT_CHR_F_READ,
}, {
@@ -116,7 +116,7 @@ static const struct ble_gatt_svc_def ble_svc_ans_defs[] = {
* This characteristic exposes the count of unread
* alert events existing in the server.
*/
- .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_UNR_ALERT_STAT),
+ .uuid = BLE_UUID16_DECLARE(BLE_SVC_ANS_CHR_UUID16_UNR_ALERT_STAT),
.access_cb = ble_svc_ans_access,
.val_handle = &ble_svc_ans_unr_alert_val_handle,
.flags = BLE_GATT_CHR_F_NOTIFY,
@@ -130,7 +130,7 @@ static const struct ble_gatt_svc_def ble_svc_ans_defs[] = {
* Client Characteristic Configuration for each alert
* characteristic.
*/
- .uuid128 = BLE_UUID16(BLE_SVC_ANS_CHR_UUID16_ALERT_NOT_CTRL_PT),
+ .uuid =
BLE_UUID16_DECLARE(BLE_SVC_ANS_CHR_UUID16_ALERT_NOT_CTRL_PT),
.access_cb = ble_svc_ans_access,
.flags = BLE_GATT_CHR_F_WRITE,
}, {
@@ -160,7 +160,7 @@ ble_svc_ans_access(uint16_t conn_handle, uint16_t
attr_handle,
uint8_t cat_bit_mask;
int i;
- uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128);
+ uuid16 = ble_uuid_u16(ctxt->chr->uuid);
assert(uuid16 != 0);
switch (uuid16) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/nimble/host/services/bleuart/include/bleuart/bleuart.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/bleuart/include/bleuart/bleuart.h
b/net/nimble/host/services/bleuart/include/bleuart/bleuart.h
index a8c29c1..ab64b9c 100644
--- a/net/nimble/host/services/bleuart/include/bleuart/bleuart.h
+++ b/net/nimble/host/services/bleuart/include/bleuart/bleuart.h
@@ -33,7 +33,7 @@ bleuart_gatt_svr_init(void);
void
bleuart_set_conn_handle(uint16_t conn_handle);
-extern const uint8_t gatt_svr_svc_uart[16];
+extern const ble_uuid128_t gatt_svr_svc_uart_uuid;
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/nimble/host/services/bleuart/src/bleuart.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/bleuart/src/bleuart.c
b/net/nimble/host/services/bleuart/src/bleuart.c
index 3c26ffc..d481a86 100644
--- a/net/nimble/host/services/bleuart/src/bleuart.c
+++ b/net/nimble/host/services/bleuart/src/bleuart.c
@@ -23,6 +23,7 @@
#include "sysinit/sysinit.h"
#include "host/ble_hs.h"
+#include "host/ble_uuid.h"
#include "bleuart/bleuart.h"
#include "os/endian.h"
#include "console/console.h"
@@ -47,23 +48,20 @@ uint16_t g_console_conn_handle;
*/
/* {6E400001-B5A3-F393-E0A9-E50E24DCCA9E} */
-const uint8_t gatt_svr_svc_uart[16] = {
- 0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
- 0x93, 0xf3, 0xa3, 0xb5, 0x01, 0x00, 0x40, 0x6e
-};
+const ble_uuid128_t gatt_svr_svc_uart_uuid =
+ BLE_UUID128_INIT(0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
+ 0x93, 0xf3, 0xa3, 0xb5, 0x01, 0x00, 0x40, 0x6e);
/* {6E400002-B5A3-F393-E0A9-E50E24DCCA9E} */
-const uint8_t gatt_svr_chr_uart_write[16] = {
- 0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
- 0x93, 0xf3, 0xa3, 0xb5, 0x02, 0x00, 0x40, 0x6e
-};
+const ble_uuid128_t gatt_svr_chr_uart_write_uuid =
+ BLE_UUID128_INIT(0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
+ 0x93, 0xf3, 0xa3, 0xb5, 0x02, 0x00, 0x40, 0x6e);
/* {6E400003-B5A3-F393-E0A9-E50E24DCCA9E} */
-const uint8_t gatt_svr_chr_uart_read[16] = {
- 0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
- 0x93, 0xf3, 0xa3, 0xb5, 0x03, 0x00, 0x40, 0x6e
-};
+const ble_uuid128_t gatt_svr_chr_uart_read_uuid =
+ BLE_UUID128_INIT(0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
+ 0x93, 0xf3, 0xa3, 0xb5, 0x03, 0x00, 0x40, 0x6e);
static int
gatt_svr_chr_access_uart_write(uint16_t conn_handle, uint16_t attr_handle,
@@ -73,15 +71,15 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
{
/* Service: uart */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = (void *)gatt_svr_svc_uart,
+ .uuid = &gatt_svr_svc_uart_uuid.u,
.characteristics = (struct ble_gatt_chr_def[]) { {
- .uuid128 = gatt_svr_chr_uart_read,
+ .uuid = &gatt_svr_chr_uart_read_uuid.u,
.val_handle = &g_bleuart_attr_read_handle,
.access_cb = gatt_svr_chr_access_uart_write,
.flags = BLE_GATT_CHR_F_NOTIFY,
}, {
/* Characteristic: Write */
- .uuid128 = (void *)gatt_svr_chr_uart_write,
+ .uuid = &gatt_svr_chr_uart_write_uuid.u,
.access_cb = gatt_svr_chr_access_uart_write,
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_NO_RSP,
.val_handle = &g_bleuart_attr_write_handle,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/nimble/host/services/gap/src/ble_svc_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/gap/src/ble_svc_gap.c
b/net/nimble/host/services/gap/src/ble_svc_gap.c
index e0ccd7c..87de6fb 100644
--- a/net/nimble/host/services/gap/src/ble_svc_gap.c
+++ b/net/nimble/host/services/gap/src/ble_svc_gap.c
@@ -41,31 +41,31 @@ static const struct ble_gatt_svc_def ble_svc_gap_defs[] = {
{
/*** Service: GAP. */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = BLE_UUID16(BLE_SVC_GAP_UUID16),
+ .uuid = BLE_UUID16_DECLARE(BLE_SVC_GAP_UUID16),
.characteristics = (struct ble_gatt_chr_def[]) { {
/*** Characteristic: Device Name. */
- .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_DEVICE_NAME),
+ .uuid = BLE_UUID16_DECLARE(BLE_SVC_GAP_CHR_UUID16_DEVICE_NAME),
.access_cb = ble_svc_gap_access,
.flags = BLE_GATT_CHR_F_READ,
}, {
/*** Characteristic: Appearance. */
- .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_APPEARANCE),
+ .uuid = BLE_UUID16_DECLARE(BLE_SVC_GAP_CHR_UUID16_APPEARANCE),
.access_cb = ble_svc_gap_access,
.flags = BLE_GATT_CHR_F_READ,
}, {
/*** Characteristic: Peripheral Privacy Flag. */
- .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_PERIPH_PRIV_FLAG),
+ .uuid =
BLE_UUID16_DECLARE(BLE_SVC_GAP_CHR_UUID16_PERIPH_PRIV_FLAG),
.access_cb = ble_svc_gap_access,
.flags = BLE_GATT_CHR_F_READ,
}, {
/*** Characteristic: Reconnection Address. */
- .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_RECONNECT_ADDR),
+ .uuid = BLE_UUID16_DECLARE(BLE_SVC_GAP_CHR_UUID16_RECONNECT_ADDR),
.access_cb = ble_svc_gap_access,
.flags = BLE_GATT_CHR_F_WRITE,
}, {
/*** Characteristic: Peripheral Preferred Connection Parameters. */
- .uuid128 =
- BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS),
+ .uuid =
+
BLE_UUID16_DECLARE(BLE_SVC_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS),
.access_cb = ble_svc_gap_access,
.flags = BLE_GATT_CHR_F_READ,
}, {
@@ -85,7 +85,7 @@ ble_svc_gap_access(uint16_t conn_handle, uint16_t attr_handle,
uint16_t uuid16;
int rc;
- uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128);
+ uuid16 = ble_uuid_u16(ctxt->chr->uuid);
assert(uuid16 != 0);
switch (uuid16) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/nimble/host/services/gatt/src/ble_svc_gatt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/gatt/src/ble_svc_gatt.c
b/net/nimble/host/services/gatt/src/ble_svc_gatt.c
index 666e672..8b7139d 100644
--- a/net/nimble/host/services/gatt/src/ble_svc_gatt.c
+++ b/net/nimble/host/services/gatt/src/ble_svc_gatt.c
@@ -35,9 +35,9 @@ static const struct ble_gatt_svc_def ble_svc_gatt_defs[] = {
{
/*** Service: GATT */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = BLE_UUID16(BLE_GATT_SVC_UUID16),
+ .uuid = BLE_UUID16_DECLARE(BLE_GATT_SVC_UUID16),
.characteristics = (struct ble_gatt_chr_def[]) { {
- .uuid128 = BLE_UUID16(BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16),
+ .uuid =
BLE_UUID16_DECLARE(BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16),
.access_cb = ble_svc_gatt_access,
.val_handle = &ble_svc_gatt_changed_val_handle,
.flags = BLE_GATT_CHR_F_INDICATE,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/nimble/host/services/ias/src/ble_svc_ias.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ias/src/ble_svc_ias.c
b/net/nimble/host/services/ias/src/ble_svc_ias.c
index 5644ccd..74c9778 100644
--- a/net/nimble/host/services/ias/src/ble_svc_ias.c
+++ b/net/nimble/host/services/ias/src/ble_svc_ias.c
@@ -44,10 +44,10 @@ static const struct ble_gatt_svc_def ble_svc_ias_defs[] = {
{
/*** Service: Immediate Alert Service (IAS). */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = BLE_UUID16(BLE_SVC_IAS_UUID16),
+ .uuid = BLE_UUID16(BLE_SVC_IAS_UUID16),
.characteristics = (struct ble_gatt_chr_def[]) { {
/*** Characteristic: Alert Level. */
- .uuid128 = BLE_UUID16(BLE_SVC_IAS_CHR_UUID16_ALERT_LEVEL),
+ .uuid = BLE_UUID16(BLE_SVC_IAS_CHR_UUID16_ALERT_LEVEL),
.access_cb = ble_svc_ias_access,
.flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
}, {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/nimble/host/services/lls/src/ble_svc_lls.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/lls/src/ble_svc_lls.c
b/net/nimble/host/services/lls/src/ble_svc_lls.c
index 9c7b900..434814f 100644
--- a/net/nimble/host/services/lls/src/ble_svc_lls.c
+++ b/net/nimble/host/services/lls/src/ble_svc_lls.c
@@ -42,10 +42,10 @@ static const struct ble_gatt_svc_def ble_svc_lls_defs[] = {
{
/*** Service: Link Loss Service (LLS). */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = BLE_UUID16(BLE_SVC_LLS_UUID16),
+ .uuid = BLE_UUID16(BLE_SVC_LLS_UUID16),
.characteristics = (struct ble_gatt_chr_def[]) { {
/*** Characteristic: Alert Level. */
- .uuid128 = BLE_UUID16(BLE_SVC_LLS_CHR_UUID16_ALERT_LEVEL),
+ .uuid = BLE_UUID16(BLE_SVC_LLS_CHR_UUID16_ALERT_LEVEL),
.access_cb = ble_svc_lls_access,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
}, {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/nimble/host/services/tps/src/ble_svc_tps.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/tps/src/ble_svc_tps.c
b/net/nimble/host/services/tps/src/ble_svc_tps.c
index 74c2df4..fe71b79 100644
--- a/net/nimble/host/services/tps/src/ble_svc_tps.c
+++ b/net/nimble/host/services/tps/src/ble_svc_tps.c
@@ -41,10 +41,10 @@ static const struct ble_gatt_svc_def ble_svc_tps_defs[] = {
{
/*** Service: Tx Power Service. */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = BLE_UUID16(BLE_SVC_TPS_UUID16),
+ .uuid = BLE_UUID16(BLE_SVC_TPS_UUID16),
.characteristics = (struct ble_gatt_chr_def[]) { {
/*** Characteristic: Tx Power Level. */
- .uuid128 = BLE_UUID16(BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL),
+ .uuid = BLE_UUID16(BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL),
.access_cb = ble_svc_tps_access,
.flags = BLE_GATT_CHR_F_READ,
}, {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/nimble/host/src/ble_att_clt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_clt.c
b/net/nimble/host/src/ble_att_clt.c
index fe57e8d..8b3a95d 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -238,7 +238,6 @@ static int
ble_att_clt_parse_find_info_entry(struct os_mbuf **rxom, uint8_t rsp_format,
struct ble_att_find_info_idata *idata)
{
- uint16_t uuid16;
int entry_len;
int rc;
@@ -264,15 +263,14 @@ ble_att_clt_parse_find_info_entry(struct os_mbuf **rxom,
uint8_t rsp_format,
switch (rsp_format) {
case BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT:
- uuid16 = le16toh((*rxom)->om_data + 2);
- rc = ble_uuid_16_to_128(uuid16, idata->uuid128);
+ rc = ble_uuid_init_from_mbuf(&idata->uuid, *rxom, 2, 2);
if (rc != 0) {
return BLE_HS_EBADDATA;
}
break;
case BLE_ATT_FIND_INFO_RSP_FORMAT_128BIT:
- rc = os_mbuf_copydata(*rxom, 2, 16, idata->uuid128);
+ rc = ble_uuid_init_from_mbuf(&idata->uuid, *rxom, 2, 16);
if (rc != 0) {
return BLE_HS_EBADDATA;
}
@@ -441,7 +439,7 @@ ble_att_clt_rx_find_type_value(uint16_t conn_handle, struct
os_mbuf **rxom)
int
ble_att_clt_tx_read_type(uint16_t conn_handle,
const struct ble_att_read_type_req *req,
- const void *uuid128)
+ const ble_uuid_t *uuid)
{
#if !NIMBLE_BLE_ATT_CLT_READ_TYPE
return BLE_HS_ENOTSUP;
@@ -465,7 +463,7 @@ ble_att_clt_tx_read_type(uint16_t conn_handle,
}
ble_att_read_type_req_write(txom->om_data, txom->om_len, req);
- rc = ble_uuid_append(txom, uuid128);
+ rc = ble_uuid_to_mbuf(uuid, txom);
if (rc != 0) {
rc = BLE_HS_ENOMEM;
goto err;
@@ -750,7 +748,7 @@ ble_att_clt_rx_read_mult(uint16_t conn_handle, struct
os_mbuf **rxom)
int
ble_att_clt_tx_read_group_type(uint16_t conn_handle,
const struct ble_att_read_group_type_req *req,
- const void *uuid128)
+ const ble_uuid_t *uuid)
{
#if !NIMBLE_BLE_ATT_CLT_READ_GROUP_TYPE
return BLE_HS_ENOTSUP;
@@ -774,7 +772,7 @@ ble_att_clt_tx_read_group_type(uint16_t conn_handle,
}
ble_att_read_group_type_req_write(txom->om_data, txom->om_len, req);
- rc = ble_uuid_append(txom, uuid128);
+ rc = ble_uuid_to_mbuf(uuid, txom);
if (rc != 0) {
goto err;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h
b/net/nimble/host/src/ble_att_priv.h
index 44e4d23..ed696df 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -24,6 +24,7 @@
#include "stats/stats.h"
#include "os/queue.h"
#include "host/ble_att.h"
+#include "host/ble_uuid.h"
#ifdef __cplusplus
extern "C" {
#endif
@@ -139,17 +140,14 @@ typedef int ble_att_svr_access_fn(uint16_t conn_handle,
uint16_t attr_handle,
uint8_t op, uint16_t offset,
struct os_mbuf **om, void *arg);
-int ble_att_svr_register(const uint8_t *uuid, uint8_t flags,
+int ble_att_svr_register(const ble_uuid_t *uuid, uint8_t flags,
uint8_t min_key_size, uint16_t *handle_id,
ble_att_svr_access_fn *cb, void *cb_arg);
-int ble_att_svr_register_uuid16(uint16_t uuid16, uint8_t flags,
- uint8_t min_key_size, uint16_t *handle_id,
- ble_att_svr_access_fn *cb, void *cb_arg);
struct ble_att_svr_entry {
STAILQ_ENTRY(ble_att_svr_entry) ha_next;
- uint8_t ha_uuid[16];
+ const ble_uuid_t *ha_uuid;
uint8_t ha_flags;
uint8_t ha_min_key_size;
uint16_t ha_handle_id;
@@ -182,7 +180,7 @@ int ble_att_svr_start(void);
struct ble_att_svr_entry *
ble_att_svr_find_by_uuid(struct ble_att_svr_entry *start_at,
- const uint8_t *uuid,
+ const ble_uuid_t *uuid,
uint16_t end_handle);
uint16_t ble_att_svr_prev_handle(void);
int ble_att_svr_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom);
@@ -225,7 +223,7 @@ int ble_att_svr_init(void);
/** An information-data entry in a find information response. */
struct ble_att_find_info_idata {
uint16_t attr_handle;
- uint8_t uuid128[16];
+ ble_uuid_any_t uuid;
};
/** A handles-information entry in a find by type value response. */
@@ -265,11 +263,11 @@ int ble_att_clt_tx_read_mult(uint16_t conn_handle,
int ble_att_clt_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom);
int ble_att_clt_tx_read_type(uint16_t conn_handle,
const struct ble_att_read_type_req *req,
- const void *uuid128);
+ const ble_uuid_t *uuid);
int ble_att_clt_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom);
int ble_att_clt_tx_read_group_type(
uint16_t conn_handle, const struct ble_att_read_group_type_req *req,
- const void *uuid128);
+ const ble_uuid_t *uuid128);
int ble_att_clt_rx_read_group_type(uint16_t conn_handle,
struct os_mbuf **rxom);
int ble_att_clt_tx_find_info(uint16_t conn_handle,