You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2015/11/16 23:46:22 UTC
incubator-mynewt-larva git commit: Fix 128-bit to 16-bit UUID
conversion.
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/master a4cceb7ed -> 4255270f4
Fix 128-bit to 16-bit UUID conversion.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/4255270f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/4255270f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/4255270f
Branch: refs/heads/master
Commit: 4255270f43555fc59300597967ac72983f5b68e8
Parents: a4cceb7
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Nov 16 14:46:04 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Nov 16 14:46:04 2015 -0800
----------------------------------------------------------------------
net/nimble/host/include/host/ble_hs_test.h | 1 +
net/nimble/host/src/ble_hs_uuid.c | 22 ++++++--
net/nimble/host/src/test/ble_hs_test.c | 1 +
net/nimble/host/src/test/ble_hs_uuid_test.c | 67 ++++++++++++++++++++++++
4 files changed, 88 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4255270f/net/nimble/host/include/host/ble_hs_test.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs_test.h b/net/nimble/host/include/host/ble_hs_test.h
index cd4b396..8ddd8f4 100644
--- a/net/nimble/host/include/host/ble_hs_test.h
+++ b/net/nimble/host/include/host/ble_hs_test.h
@@ -22,6 +22,7 @@ int ble_hs_att_test_all(void);
int ble_host_hci_test_all(void);
int ble_hs_conn_test_all(void);
int ble_gap_test_all(void);
+int ble_hs_uuid_test_all(void);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4255270f/net/nimble/host/src/ble_hs_uuid.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_uuid.c b/net/nimble/host/src/ble_hs_uuid.c
index 32a458b..2c9e1aa 100644
--- a/net/nimble/host/src/ble_hs_uuid.c
+++ b/net/nimble/host/src/ble_hs_uuid.c
@@ -23,19 +23,35 @@ static uint8_t ble_hs_uuid_base[16] = {
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
};
+/**
+ * Attempts to convert the supplied 128-bit UUID into its shortened 16-bit
+ * form.
+ *
+ * @return Positive 16-bit unsigned integer on
+ * success;
+ * -1 if the UUID could not be converted.
+ */
int
ble_hs_uuid_16bit(uint8_t *uuid128)
{
uint16_t uuid16;
int rc;
- rc = memcmp(uuid128 + 2, ble_hs_uuid_base + 2,
- sizeof ble_hs_uuid_base - 2);
+ /* The UUID can only be converted if its final 96 bits are equal to the
+ * base UUID.
+ */
+ rc = memcmp(uuid128 + 4, ble_hs_uuid_base + 4,
+ sizeof ble_hs_uuid_base - 4);
if (rc != 0) {
return -1;
}
- uuid16 = (uuid128[0] << 8) + uuid128[1];
+ if (uuid128[0] != 0 || uuid128[1] != 0) {
+ /* This UUID has a 32-bit form, but not a 16-bit form. */
+ return -1;
+ }
+
+ uuid16 = (uuid128[2] << 8) + uuid128[3];
return uuid16;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4255270f/net/nimble/host/src/test/ble_hs_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test.c b/net/nimble/host/src/test/ble_hs_test.c
index 74338be..c0e2f1c 100644
--- a/net/nimble/host/src/test/ble_hs_test.c
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -30,6 +30,7 @@ main(void)
ble_host_hci_test_all();
ble_hs_conn_test_all();
ble_gap_test_all();
+ ble_hs_uuid_test_all();
return tu_any_failed;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4255270f/net/nimble/host/src/test/ble_hs_uuid_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_uuid_test.c b/net/nimble/host/src/test/ble_hs_uuid_test.c
new file mode 100644
index 0000000..449418f
--- /dev/null
+++ b/net/nimble/host/src/test/ble_hs_uuid_test.c
@@ -0,0 +1,67 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stddef.h>
+#include <string.h>
+#include "host/ble_hs_test.h"
+#include "testutil/testutil.h"
+#include "ble_hs_uuid.h"
+
+TEST_CASE(ble_hs_uuid_test_128_to_16)
+{
+ int uuid16;
+
+ /*** RFCOMM */
+ uuid16 = ble_hs_uuid_16bit(((uint8_t[]) {
+ 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x10, 0x00,
+ 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}));
+
+ TEST_ASSERT(uuid16 == 0x0003);
+
+ /*** BNEP */
+ uuid16 = ble_hs_uuid_16bit(((uint8_t[]) {
+ 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x10, 0x00,
+ 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}));
+
+ TEST_ASSERT(uuid16 == 0x000f);
+
+ /*** L2CAP */
+ uuid16 = ble_hs_uuid_16bit(((uint8_t[]) {
+ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00,
+ 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}));
+
+ TEST_ASSERT(uuid16 == 0x0100);
+
+ /*** ObEXObjectPush */
+ uuid16 = ble_hs_uuid_16bit(((uint8_t[]) {
+ 0x00, 0x00, 0x11, 0x05, 0x00, 0x00, 0x10, 0x00,
+ 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}));
+
+ TEST_ASSERT(uuid16 == 0x1105);
+}
+
+TEST_SUITE(ble_hs_uuid_test_suite)
+{
+ ble_hs_uuid_test_128_to_16();
+}
+
+int
+ble_hs_uuid_test_all(void)
+{
+ ble_hs_uuid_test_suite();
+
+ return tu_any_failed;
+}