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/12/10 22:03:48 UTC
incubator-mynewt-larva git commit: Fix server side ATT
read-by-group-type
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/master 4a12d183b -> c45b1c4ac
Fix server side ATT read-by-group-type
Vol. 3, Part G, 3.1:
"All Attributes on a Server shall either contain a service declaration or exist
within a service definition."
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/c45b1c4a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/c45b1c4a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/c45b1c4a
Branch: refs/heads/master
Commit: c45b1c4acd0b6a9595a4bebc7a60058541bbbf70
Parents: 4a12d18
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Dec 10 12:59:39 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Dec 10 13:03:39 2015 -0800
----------------------------------------------------------------------
net/nimble/host/src/ble_att_svr.c | 15 +-----
net/nimble/host/src/test/ble_att_svr_test.c | 67 ++++++++++--------------
project/hostctlrtest/src/main.c | 56 ++++++++++++++++----
3 files changed, 76 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/c45b1c4a/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index a45822d..eebcafe 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -1122,19 +1122,6 @@ ble_att_svr_is_valid_group_type(uint8_t *uuid128)
}
static int
-ble_att_svr_is_valid_group_member(uint8_t *uuid128)
-{
- uint16_t uuid16;
-
- /* Assumes the group type is primary or secondary service. */
-
- uuid16 = ble_hs_uuid_16bit(uuid128);
-
- return uuid16 == BLE_ATT_UUID_INCLUDE ||
- uuid16 == BLE_ATT_UUID_CHARACTERISTIC;
-}
-
-static int
ble_att_svr_service_uuid(struct ble_att_svr_entry *entry, uint16_t *uuid16,
uint8_t *uuid128)
{
@@ -1249,7 +1236,7 @@ ble_att_svr_tx_read_group_type(struct ble_hs_conn *conn,
if (start_group_handle != 0) {
/* We have already found the start of a group. */
- if (ble_att_svr_is_valid_group_member(entry->ha_uuid)) {
+ if (!ble_att_svr_is_valid_group_type(entry->ha_uuid)) {
/* This attribute is part of the current group. */
end_group_handle = entry->ha_handle_id;
} else {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/c45b1c4a/net/nimble/host/src/test/ble_att_svr_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_svr_test.c b/net/nimble/host/src/test/ble_att_svr_test.c
index 54a11ad..021d1d4 100644
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_att_svr_test.c
@@ -88,11 +88,9 @@ ble_att_svr_test_misc_attr_fn_r_group(struct ble_att_svr_entry *entry,
{
/* Service 0x1122 from 1 to 5 */
/* Service 0x2233 from 6 to 10 */
- /* Garbage from 11 to 13 */
- /* Service 1,2,3...16 from 14 to 19 */
- /* Garbage from 20 to 22 */
+ /* Service 1,2,3...16 from 11 to 19 */
- static uint8_t vals[23][16] = {
+ static uint8_t vals[20][16] = {
[1] = { 0x22, 0x11 },
[2] = { 0xdd, 0xdd },
[3] = { 0xdd, 0xdd },
@@ -103,18 +101,15 @@ ble_att_svr_test_misc_attr_fn_r_group(struct ble_att_svr_entry *entry,
[8] = { 0xee, 0xee },
[9] = { 0xee, 0xee },
[10] = { 0xee, 0xee },
- [11] = { 0xbe, 0xff },
- [12] = { 0xbe, 0xff },
- [13] = { 0xbe, 0xff },
- [14] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 },
+ [11] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 },
+ [12] = { 0xdd, 0xdd },
+ [13] = { 0xdd, 0xdd },
+ [14] = { 0xdd, 0xdd },
[15] = { 0xdd, 0xdd },
[16] = { 0xdd, 0xdd },
[17] = { 0xdd, 0xdd },
[18] = { 0xdd, 0xdd },
[19] = { 0xdd, 0xdd },
- [20] = { 0xbe, 0xff },
- [21] = { 0xbe, 0xff },
- [22] = { 0xbe, 0xff },
};
static uint8_t zeros[14];
@@ -168,9 +163,7 @@ ble_att_svr_test_misc_register_group_attrs(void)
{
/* Service 0x1122 from 1 to 5 */
/* Service 0x2233 from 6 to 10 */
- /* Garbage from 11 to 13 */
- /* Service 1,2,3...16 from 14 to 19 */
- /* Garbage from 20 to 22 */
+ /* Service 1,2,3...16 from 11 to 19 */
int i;
@@ -179,9 +172,15 @@ ble_att_svr_test_misc_register_group_attrs(void)
BLE_ATT_UUID_PRIMARY_SERVICE, 0, 1,
ble_att_svr_test_misc_attr_fn_r_group);
for (i = 2; i <= 5; i++) {
- ble_att_svr_test_misc_register_uuid16(
- BLE_ATT_UUID_CHARACTERISTIC, 0, i,
- ble_att_svr_test_misc_attr_fn_r_group);
+ if ((i - 2) % 2 == 0) {
+ ble_att_svr_test_misc_register_uuid16(
+ BLE_ATT_UUID_CHARACTERISTIC, 0, i,
+ ble_att_svr_test_misc_attr_fn_r_group);
+ } else {
+ ble_att_svr_test_misc_register_uuid16(
+ i, 0, i,
+ ble_att_svr_test_misc_attr_fn_r_group);
+ }
}
/* Service 0x2233 from 6 to 10 */
@@ -194,28 +193,20 @@ ble_att_svr_test_misc_register_group_attrs(void)
ble_att_svr_test_misc_attr_fn_r_group);
}
- /* Garbage from 11 to 13 */
- for (i = 11; i <= 13; i++) {
- ble_att_svr_test_misc_register_uuid16(
- 0x8797, 0, i,
- ble_att_svr_test_misc_attr_fn_r_group);
- }
-
- /* Service 1,2,3...16 from 14 to 19 */
+ /* Service 1,2,3...16 from 11 to 19 */
ble_att_svr_test_misc_register_uuid16(
- BLE_ATT_UUID_PRIMARY_SERVICE, 0, 14,
+ BLE_ATT_UUID_PRIMARY_SERVICE, 0, 11,
ble_att_svr_test_misc_attr_fn_r_group);
- for (i = 15; i <= 19; i++) {
- ble_att_svr_test_misc_register_uuid16(
- BLE_ATT_UUID_CHARACTERISTIC, 0, i,
- ble_att_svr_test_misc_attr_fn_r_group);
- }
-
- /* Garbage from 20 to 22 */
- for (i = 20; i <= 22; i++) {
- ble_att_svr_test_misc_register_uuid16(
- 0xabab, 0, i,
- ble_att_svr_test_misc_attr_fn_r_group);
+ for (i = 12; i <= 19; i++) {
+ if ((i - 12) % 2 == 0) {
+ ble_att_svr_test_misc_register_uuid16(
+ BLE_ATT_UUID_CHARACTERISTIC, 0, i,
+ ble_att_svr_test_misc_attr_fn_r_group);
+ } else {
+ ble_att_svr_test_misc_register_uuid16(
+ i, 0, i,
+ ble_att_svr_test_misc_attr_fn_r_group);
+ }
}
}
@@ -1235,7 +1226,7 @@ TEST_CASE(ble_att_svr_test_read_group_type)
ble_att_svr_test_misc_verify_tx_read_group_type_rsp(chan,
((struct ble_att_svr_test_group_type_entry[]) { {
- .start_handle = 14,
+ .start_handle = 11,
.end_handle = 19,
.uuid128 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
}, {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/c45b1c4a/project/hostctlrtest/src/main.c
----------------------------------------------------------------------
diff --git a/project/hostctlrtest/src/main.c b/project/hostctlrtest/src/main.c
index f759bb9..4e55b0a 100755
--- a/project/hostctlrtest/src/main.c
+++ b/project/hostctlrtest/src/main.c
@@ -201,8 +201,10 @@ hostctlrtest_on_disc_s(uint16_t conn_handle, uint8_t ble_hs_status,
#if HOSTCTLRTEST_CFG_ROLE == HOSTCTLRTEST_ROLE_INITIATOR
static uint16_t hostctlrtest_service_handle;
-static uint16_t hostctlrtest_char_handle;
-static uint16_t hostctlrtest_data_handle;
+static uint16_t hostctlrtest_char1_handle;
+static uint16_t hostctlrtest_data1_handle;
+static uint16_t hostctlrtest_char2_handle;
+static uint16_t hostctlrtest_data2_handle;
static int
hostctlrtest_attr_cb(struct ble_att_svr_entry *entry, uint8_t op,
@@ -217,23 +219,42 @@ hostctlrtest_attr_cb(struct ble_att_svr_entry *entry, uint8_t op,
htole16(buf, 0x1234);
arg->aha_read.attr_data = buf;
arg->aha_read.attr_len = 2;
- } else if (entry->ha_handle_id == hostctlrtest_char_handle) {
- console_printf("reading characteristic declaration");
+ } else if (entry->ha_handle_id == hostctlrtest_char1_handle) {
+ console_printf("reading characteristic1 declaration");
/* Properties. */
buf[0] = 0;
/* Value handle. */
- htole16(buf + 1, hostctlrtest_data_handle);
+ htole16(buf + 1, hostctlrtest_data1_handle);
/* UUID. */
htole16(buf + 3, 0x5656);
arg->aha_read.attr_data = buf;
arg->aha_read.attr_len = 5;
- } else if (entry->ha_handle_id == hostctlrtest_data_handle) {
- console_printf("reading characteristic value");
- memcpy(buf, "hello", 5);
+ } else if (entry->ha_handle_id == hostctlrtest_data1_handle) {
+ console_printf("reading characteristic1 value");
+ memcpy(buf, "char1", 5);
+ arg->aha_read.attr_data = buf;
+ arg->aha_read.attr_len = 5;
+ } else if (entry->ha_handle_id == hostctlrtest_char2_handle) {
+ console_printf("reading characteristic2 declaration");
+
+ /* Properties. */
+ buf[0] = 0;
+
+ /* Value handle. */
+ htole16(buf + 1, hostctlrtest_data2_handle);
+
+ /* UUID. */
+ htole16(buf + 3, 0x6767);
+
+ arg->aha_read.attr_data = buf;
+ arg->aha_read.attr_len = 5;
+ } else if (entry->ha_handle_id == hostctlrtest_data2_handle) {
+ console_printf("reading characteristic2 value");
+ memcpy(buf, "char2", 5);
arg->aha_read.attr_data = buf;
arg->aha_read.attr_len = 5;
} else {
@@ -249,21 +270,36 @@ hostctlrtest_register_attrs(void)
uint8_t uuid128[16];
int rc;
+ /* Service. */
rc = ble_hs_uuid_from_16bit(BLE_ATT_UUID_PRIMARY_SERVICE, uuid128);
assert(rc == 0);
rc = ble_att_svr_register(uuid128, 0, &hostctlrtest_service_handle,
hostctlrtest_attr_cb);
assert(rc == 0);
+ /* Characteristic 1 (UUID=0x5656).*/
rc = ble_hs_uuid_from_16bit(BLE_ATT_UUID_CHARACTERISTIC, uuid128);
assert(rc == 0);
- rc = ble_att_svr_register(uuid128, 0, &hostctlrtest_char_handle,
+ rc = ble_att_svr_register(uuid128, 0, &hostctlrtest_char1_handle,
hostctlrtest_attr_cb);
assert(rc == 0);
rc = ble_hs_uuid_from_16bit(0x5656, uuid128);
assert(rc == 0);
- rc = ble_att_svr_register(uuid128, 0, &hostctlrtest_data_handle,
+ rc = ble_att_svr_register(uuid128, 0, &hostctlrtest_data1_handle,
+ hostctlrtest_attr_cb);
+ assert(rc == 0);
+
+ /* Characteristic 2 (UUID=0x6767).*/
+ rc = ble_hs_uuid_from_16bit(BLE_ATT_UUID_CHARACTERISTIC, uuid128);
+ assert(rc == 0);
+ rc = ble_att_svr_register(uuid128, 0, &hostctlrtest_char2_handle,
+ hostctlrtest_attr_cb);
+ assert(rc == 0);
+
+ rc = ble_hs_uuid_from_16bit(0x6767, uuid128);
+ assert(rc == 0);
+ rc = ble_att_svr_register(uuid128, 0, &hostctlrtest_data2_handle,
hostctlrtest_attr_cb);
assert(rc == 0);
}