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/01 04:48:02 UTC
incubator-mynewt-larva git commit: Initial implementation of ATT
batch commands.
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/master b390b9f9f -> af899083d
Initial implementation of ATT batch commands.
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/af899083
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/af899083
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/af899083
Branch: refs/heads/master
Commit: af899083d2bfd760ea92f009dcea1662a5bfba0d
Parents: b390b9f
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Nov 30 19:47:49 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Nov 30 19:47:49 2015 -0800
----------------------------------------------------------------------
net/nimble/host/src/ble_hs_att.h | 4 +-
net/nimble/host/src/ble_hs_att_batch.c | 96 +++++++++++++++++++--
net/nimble/host/src/ble_hs_att_clt.c | 5 +-
net/nimble/host/src/test/ble_hs_att_clt_test.c | 42 +++++++--
4 files changed, 132 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/af899083/net/nimble/host/src/ble_hs_att.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att.h b/net/nimble/host/src/ble_hs_att.h
index 0aa71ec..7a0da3e 100644
--- a/net/nimble/host/src/ble_hs_att.h
+++ b/net/nimble/host/src/ble_hs_att.h
@@ -144,7 +144,6 @@ uint16_t ble_hs_att_clt_find_entry_uuid128(struct ble_hs_conn *conn,
uint16_t ble_hs_att_clt_find_entry_uuid16(struct ble_hs_conn *conn,
uint16_t uuid16);
int ble_hs_att_clt_tx_find_info(struct ble_hs_conn *conn,
- struct ble_l2cap_chan *chan,
struct ble_hs_att_find_info_req *req);
int ble_hs_att_clt_rx_find_info(struct ble_hs_conn *conn,
struct ble_l2cap_chan *chan,
@@ -156,6 +155,9 @@ void ble_hs_att_batch_rx_error(struct ble_hs_conn *conn,
struct ble_hs_att_error_rsp *rsp);
void ble_hs_att_batch_rx_find_info(struct ble_hs_conn *conn, int status,
uint16_t last_handle_id);
+int ble_hs_att_batch_find_info(uint16_t conn_handle_id,
+ uint16_t att_start_handle,
+ uint16_t att_end_handle);
int ble_hs_att_batch_init(void);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/af899083/net/nimble/host/src/ble_hs_att_batch.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att_batch.c b/net/nimble/host/src/ble_hs_att_batch.c
index e8f7370..03ea64c 100644
--- a/net/nimble/host/src/ble_hs_att_batch.c
+++ b/net/nimble/host/src/ble_hs_att_batch.c
@@ -2,6 +2,7 @@
#include <assert.h>
#include <stdlib.h>
#include <errno.h>
+#include <string.h>
#include "os/os_mempool.h"
#include "ble_hs_conn.h"
#include "ble_hs_att_cmd.h"
@@ -11,14 +12,15 @@
#define BLE_HS_ATT_BATCH_OP_FIND_INFO 1
struct ble_hs_att_batch_entry {
- STAILQ_ENTRY(ble_hs_att_batch_entry) next;
+ SLIST_ENTRY(ble_hs_att_batch_entry) next;
uint8_t op;
- uint16_t peer_handle;
+ uint16_t conn_handle;
union {
struct {
uint16_t start_handle;
uint16_t end_handle;
+ /* XXX: Callback. */
} find_info;
};
};
@@ -27,15 +29,37 @@ struct ble_hs_att_batch_entry {
static void *ble_hs_att_batch_entry_mem;
static struct os_mempool ble_hs_att_batch_entry_pool;
-static STAILQ_HEAD(, ble_hs_att_batch_entry) ble_hs_att_batch_list;
+static SLIST_HEAD(, ble_hs_att_batch_entry) ble_hs_att_batch_list;
static struct ble_hs_att_batch_entry *
-ble_hs_att_batch_find(uint16_t peer_handle)
+ble_hs_att_batch_entry_alloc(void)
{
struct ble_hs_att_batch_entry *entry;
- STAILQ_FOREACH(entry, &ble_hs_att_batch_list, next) {
- if (entry->peer_handle == peer_handle) {
+ entry = os_memblock_get(&ble_hs_att_batch_entry_pool);
+ if (entry != NULL) {
+ memset(entry, 0, sizeof *entry);
+ }
+
+ return entry;
+}
+
+static void
+ble_hs_att_batch_entry_free(struct ble_hs_att_batch_entry *entry)
+{
+ int rc;
+
+ rc = os_memblock_put(&ble_hs_att_batch_entry_pool, entry);
+ assert(rc == 0);
+}
+
+static struct ble_hs_att_batch_entry *
+ble_hs_att_batch_find(uint16_t conn_handle)
+{
+ struct ble_hs_att_batch_entry *entry;
+
+ SLIST_FOREACH(entry, &ble_hs_att_batch_list, next) {
+ if (entry->conn_handle == conn_handle) {
return entry;
}
}
@@ -99,6 +123,64 @@ ble_hs_att_batch_rx_find_info(struct ble_hs_conn *conn, int status,
}
int
+ble_hs_att_batch_find_info(uint16_t conn_handle, uint16_t att_start_handle,
+ uint16_t att_end_handle)
+{
+ struct ble_hs_att_find_info_req req;
+ struct ble_hs_att_batch_entry *existing_entry;
+ struct ble_hs_att_batch_entry *entry;
+ struct ble_hs_conn *conn;
+ int rc;
+
+ entry = NULL;
+
+ /* Ensure we have a connection with the specified handle. */
+ conn = ble_hs_conn_find(conn_handle);
+ if (conn == NULL) {
+ rc = ENOTCONN;
+ goto err;
+ }
+
+ /* Ensure there isn't already an ATT job in progress for this
+ * connection.
+ */
+ existing_entry = ble_hs_att_batch_find(conn_handle);
+ if (existing_entry != NULL) {
+ rc = EALREADY;
+ goto err;
+ }
+
+ entry = ble_hs_att_batch_entry_alloc();
+ if (entry == NULL) {
+ rc = ENOMEM;
+ goto err;
+ }
+
+ entry->op = BLE_HS_ATT_BATCH_OP_FIND_INFO;
+ entry->conn_handle = conn_handle;
+ entry->find_info.start_handle = att_start_handle;
+ entry->find_info.end_handle = att_end_handle;
+
+ SLIST_INSERT_HEAD(&ble_hs_att_batch_list, entry, next);
+
+ req.bhafq_start_handle = att_start_handle;
+ req.bhafq_end_handle = att_end_handle;
+ rc = ble_hs_att_clt_tx_find_info(conn, &req);
+ if (rc != 0) {
+ goto err;
+ }
+
+ return 0;
+
+err:
+ if (entry != NULL) {
+ SLIST_REMOVE_HEAD(&ble_hs_att_batch_list, next);
+ ble_hs_att_batch_entry_free(entry);
+ }
+ return rc;
+}
+
+int
ble_hs_att_batch_init(void)
{
int rc;
@@ -122,7 +204,7 @@ ble_hs_att_batch_init(void)
goto err;
}
- STAILQ_INIT(&ble_hs_att_batch_list);
+ SLIST_INIT(&ble_hs_att_batch_list);
return 0;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/af899083/net/nimble/host/src/ble_hs_att_clt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att_clt.c b/net/nimble/host/src/ble_hs_att_clt.c
index a58485c..753a563 100644
--- a/net/nimble/host/src/ble_hs_att_clt.c
+++ b/net/nimble/host/src/ble_hs_att_clt.c
@@ -120,9 +120,9 @@ ble_hs_att_clt_find_entry_uuid16(struct ble_hs_conn *conn, uint16_t uuid16)
int
ble_hs_att_clt_tx_find_info(struct ble_hs_conn *conn,
- struct ble_l2cap_chan *chan,
struct ble_hs_att_find_info_req *req)
{
+ struct ble_l2cap_chan *chan;
struct os_mbuf *txom;
void *buf;
int rc;
@@ -136,6 +136,9 @@ ble_hs_att_clt_tx_find_info(struct ble_hs_conn *conn,
goto err;
}
+ chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
+ assert(chan != NULL);
+
txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
if (txom == NULL) {
rc = ENOMEM;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/af899083/net/nimble/host/src/test/ble_hs_att_clt_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_att_clt_test.c b/net/nimble/host/src/test/ble_hs_att_clt_test.c
index 00c6239..751ef59 100644
--- a/net/nimble/host/src/test/ble_hs_att_clt_test.c
+++ b/net/nimble/host/src/test/ble_hs_att_clt_test.c
@@ -34,25 +34,25 @@ TEST_CASE(ble_hs_att_clt_test_tx_find_info)
/*** Success. */
req.bhafq_start_handle = 1;
req.bhafq_end_handle = 0xffff;
- rc = ble_hs_att_clt_tx_find_info(conn, chan, &req);
+ rc = ble_hs_att_clt_tx_find_info(conn, &req);
TEST_ASSERT(rc == 0);
/*** Error: start handle of 0. */
req.bhafq_start_handle = 0;
req.bhafq_end_handle = 0xffff;
- rc = ble_hs_att_clt_tx_find_info(conn, chan, &req);
+ rc = ble_hs_att_clt_tx_find_info(conn, &req);
TEST_ASSERT(rc == EINVAL);
/*** Error: start handle greater than end handle. */
req.bhafq_start_handle = 500;
req.bhafq_end_handle = 499;
- rc = ble_hs_att_clt_tx_find_info(conn, chan, &req);
+ rc = ble_hs_att_clt_tx_find_info(conn, &req);
TEST_ASSERT(rc == EINVAL);
/*** Success; start and end handles equal. */
req.bhafq_start_handle = 500;
req.bhafq_end_handle = 500;
- rc = ble_hs_att_clt_tx_find_info(conn, chan, &req);
+ rc = ble_hs_att_clt_tx_find_info(conn, &req);
TEST_ASSERT(rc == 0);
}
@@ -83,7 +83,6 @@ TEST_CASE(ble_hs_att_clt_test_rx_find_info)
htole16(buf + off, 1);
off += 2;
-
memcpy(buf + off, uuid128_1, 16);
off += 16;
@@ -107,7 +106,6 @@ TEST_CASE(ble_hs_att_clt_test_rx_find_info)
htole16(buf + off, 2);
off += 2;
-
htole16(buf + off, 0x000f);
off += 2;
@@ -116,6 +114,38 @@ TEST_CASE(ble_hs_att_clt_test_rx_find_info)
handle_id = ble_hs_att_clt_find_entry_uuid16(conn, 0x000f);
TEST_ASSERT_FATAL(handle_id == 2);
+
+ /*** Two 16-bit UUIDs. */
+ /* Ensure attribute mappings are not initially present. */
+ handle_id = ble_hs_att_clt_find_entry_uuid16(conn, 0x0010);
+ TEST_ASSERT_FATAL(handle_id == 0);
+ handle_id = ble_hs_att_clt_find_entry_uuid16(conn, 0x0011);
+ TEST_ASSERT_FATAL(handle_id == 0);
+
+ /* Receive response with attribute mappings. */
+ off = 0;
+ rsp.bhafp_format = BLE_HS_ATT_FIND_INFO_RSP_FORMAT_16BIT;
+ rc = ble_hs_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
+ TEST_ASSERT(rc == 0);
+ off += BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ;
+
+ htole16(buf + off, 3);
+ off += 2;
+ htole16(buf + off, 0x0010);
+ off += 2;
+
+ htole16(buf + off, 4);
+ off += 2;
+ htole16(buf + off, 0x0011);
+ off += 2;
+
+ rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, off);
+ TEST_ASSERT(rc == 0);
+
+ handle_id = ble_hs_att_clt_find_entry_uuid16(conn, 0x0010);
+ TEST_ASSERT_FATAL(handle_id == 3);
+ handle_id = ble_hs_att_clt_find_entry_uuid16(conn, 0x0011);
+ TEST_ASSERT_FATAL(handle_id == 4);
}
TEST_SUITE(ble_hs_att_clt_suite)