Repository: incubator-mynewt-core Updated Branches: refs/heads/develop 38d5ca851 -> 0266b2249
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/nimble/host/test/src/ble_uuid_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/test/src/ble_uuid_test.c b/net/nimble/host/test/src/ble_uuid_test.c index fa2245a..ac7d6ed 100644 --- a/net/nimble/host/test/src/ble_uuid_test.c +++ b/net/nimble/host/test/src/ble_uuid_test.c @@ -24,64 +24,55 @@ #include "host/ble_uuid.h" #include "ble_hs_test_util.h" -TEST_CASE(ble_uuid_test_128_to_16) +TEST_CASE(ble_uuid_test) { - uint16_t uuid16; - - /*** RFCOMM */ - uuid16 = ble_uuid_128_to_16(((uint8_t[]) { - 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x10, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00 - })); - TEST_ASSERT(uuid16 == 0x0003); - - /*** BNEP */ - uuid16 = ble_uuid_128_to_16(((uint8_t[]) { - 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x10, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00 - })); - TEST_ASSERT(uuid16 == 0x000f); - - /*** L2CAP */ - uuid16 = ble_uuid_128_to_16(((uint8_t[]) { - 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 - })); - TEST_ASSERT(uuid16 == 0x0100); - - /*** ObEXObjectPush */ - uuid16 = ble_uuid_128_to_16(((uint8_t[]) { - 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x10, 0x00, 0x00, 0x05, 0x11, 0x00, 0x00 - })); - TEST_ASSERT(uuid16 == 0x1105); - - /*** Invalid base. */ - uuid16 = ble_uuid_128_to_16(((uint8_t[]) { - 0xfb, 0x34, 0x9c, 0x5f, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x10, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00 - })); - TEST_ASSERT(uuid16 == 0); - - /*** Invalid prefix. */ - uuid16 = ble_uuid_128_to_16(((uint8_t[]) { - 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x10, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01 - })); - TEST_ASSERT(uuid16 == 0); - - /*** 16-bit UUID of 0. */ - uuid16 = ble_uuid_128_to_16(((uint8_t[]) { - 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - })); + uint8_t buf_16[2] = { 0x00, 0x18 }; + uint8_t buf_128[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; + + const ble_uuid_t *uuid16_1 = BLE_UUID16_DECLARE(0x1800); + const ble_uuid_t *uuid16_2 = BLE_UUID16_DECLARE(0x1801); + + const ble_uuid_t *uuid128_1 = + BLE_UUID128_DECLARE(0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF); + const ble_uuid_t *uuid128_2 = + BLE_UUID128_DECLARE(0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xEE); + + ble_uuid_any_t uuid; + int rc; + + rc = ble_uuid_init_from_buf(&uuid, buf_16, 2); + TEST_ASSERT(rc == 0); + + rc = ble_uuid_cmp(&uuid.u, uuid16_1); + TEST_ASSERT(rc == 0); + + rc = ble_uuid_cmp(&uuid.u, uuid16_2); + TEST_ASSERT(rc != 0); + + rc = ble_uuid_cmp(uuid16_1, uuid16_2); + TEST_ASSERT(rc != 0); + + rc = ble_uuid_init_from_buf(&uuid, buf_128, 16); + TEST_ASSERT(rc == 0); + + rc = ble_uuid_cmp(&uuid.u, uuid128_1); + TEST_ASSERT(rc == 0); + + rc = ble_uuid_cmp(&uuid.u, uuid128_2); + TEST_ASSERT(rc != 0); + + rc = ble_uuid_cmp(uuid128_1, uuid128_2); + TEST_ASSERT(rc != 0); } TEST_SUITE(ble_uuid_test_suite) { tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL); - ble_uuid_test_128_to_16(); + ble_uuid_test(); } int http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/oic/include/oic/oc_gatt.h ---------------------------------------------------------------------- diff --git a/net/oic/include/oic/oc_gatt.h b/net/oic/include/oic/oc_gatt.h index 2cf970e..99c7924 100644 --- a/net/oic/include/oic/oc_gatt.h +++ b/net/oic/include/oic/oc_gatt.h @@ -20,16 +20,20 @@ #ifndef OC_GATT_H #define OC_GATT_H +#include "host/ble_uuid.h" + #ifdef __cplusplus extern "C" { #endif +/* ADE3D529-C784-4F63-A987-EB69F70EE816 */ +#define OC_GATT_SERVICE_UUID 0x16, 0xe8, 0x0e, 0xf7, 0x69, 0xeb, 0x87, 0xa9, \ + 0x63, 0x4f, 0x84, 0xc7, 0x29, 0xd5, 0xe3, 0xad + int oc_ble_coap_gatt_srv_init(void); void oc_ble_coap_conn_new(uint16_t conn_handle); void oc_ble_coap_conn_del(uint16_t conn_handle); -extern const uint8_t oc_gatt_svc_uuid[]; - #ifdef __cplusplus } #endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1c14f3f/net/oic/src/port/mynewt/ble_adaptor.c ---------------------------------------------------------------------- diff --git a/net/oic/src/port/mynewt/ble_adaptor.c b/net/oic/src/port/mynewt/ble_adaptor.c index b3ff59e..434f286 100644 --- a/net/oic/src/port/mynewt/ble_adaptor.c +++ b/net/oic/src/port/mynewt/ble_adaptor.c @@ -38,24 +38,20 @@ /* service UUID */ /* ADE3D529-C784-4F63-A987-EB69F70EE816 */ -const uint8_t oc_gatt_svc_uuid[16] = { - 0x16, 0xe8, 0x0e, 0xf7, 0x69, 0xeb, 0x87, 0xa9, - 0x63, 0x4f, 0x84, 0xc7, 0x29, 0xd5, 0xe3, 0xad -}; +static const ble_uuid128_t oc_gatt_svc_uuid = + BLE_UUID128_INIT(OC_GATT_SERVICE_UUID); /* request characteristic UUID */ /* AD7B334F-4637-4B86-90B6-9D787F03D218 */ -static const uint8_t oc_gatt_req_chr_uuid[16] = { - 0x18, 0xd2, 0x03, 0x7f, 0x78, 0x9d, 0xb6, 0x90, - 0x86, 0x4b, 0x37, 0x46, 0x4f, 0x33, 0x7b, 0xad -}; +static const ble_uuid128_t oc_gatt_req_chr_uuid = + BLE_UUID128_INIT(0x18, 0xd2, 0x03, 0x7f, 0x78, 0x9d, 0xb6, 0x90, + 0x86, 0x4b, 0x37, 0x46, 0x4f, 0x33, 0x7b, 0xad); /* response characteristic UUID */ /* E9241982-4580-42C4-8831-95048216B256 */ -static const uint8_t oc_gatt_rsp_chr_uuid[16] = { - 0x56, 0xb2, 0x16, 0x82, 0x04, 0x95, 0x31, 0x88, - 0xc4, 0x42, 0x80, 0x45, 0x82, 0x19, 0x24, 0xe9 -}; +static const ble_uuid128_t oc_gatt_rsp_chr_uuid = + BLE_UUID128_INIT(0x56, 0xb2, 0x16, 0x82, 0x04, 0x95, 0x31, 0x88, + 0xc4, 0x42, 0x80, 0x45, 0x82, 0x19, 0x24, 0xe9); STATS_SECT_START(oc_ble_stats) STATS_SECT_ENTRY(iframe) @@ -92,18 +88,18 @@ static int oc_gatt_chr_access(uint16_t conn_handle, uint16_t attr_handle, static const struct ble_gatt_svc_def gatt_svr_svcs[] = { { /* Service: newtmgr */ .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid128 = (void *)oc_gatt_svc_uuid, + .uuid = &oc_gatt_svc_uuid.u, .characteristics = (struct ble_gatt_chr_def[]) { { /* Characteristic: Request */ - .uuid128 = (void *)oc_gatt_req_chr_uuid, + .uuid = &oc_gatt_req_chr_uuid.u, .access_cb = oc_gatt_chr_access, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_NO_RSP | BLE_GATT_CHR_F_NOTIFY, .val_handle = &oc_ble_coap_req_handle, },{ /* Characteristic: Response */ - .uuid128 = (void *)oc_gatt_rsp_chr_uuid, + .uuid = &oc_gatt_rsp_chr_uuid.u, .access_cb = oc_gatt_chr_access, .flags = BLE_GATT_CHR_F_NOTIFY, .val_handle = &oc_ble_coap_rsp_handle,
