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 2016/01/28 00:35:34 UTC
incubator-mynewt-larva git commit: Sort L2CAP channels by channel ID.
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/master 1afa1dac4 -> f36c61287
Sort L2CAP channels by channel ID.
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/f36c6128
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/f36c6128
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/f36c6128
Branch: refs/heads/master
Commit: f36c612872c03c8f76b847883399010d8fb1e1ce
Parents: 1afa1da
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Jan 27 14:59:10 2016 -0500
Committer: Christopher Collins <cc...@gmail.com>
Committed: Wed Jan 27 18:34:05 2016 -0500
----------------------------------------------------------------------
net/nimble/host/src/ble_hs_conn.c | 68 ++++++++++++++++++++------
net/nimble/host/src/ble_hs_conn.h | 2 +
net/nimble/host/src/test/ble_l2cap_test.c | 2 +-
3 files changed, 55 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/f36c6128/net/nimble/host/src/ble_hs_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c
index 2a1657f..26e7d6c 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -37,6 +37,50 @@ ble_hs_conn_can_alloc(void)
return ble_hs_conn_pool.mp_num_free >= 1;
}
+struct ble_l2cap_chan *
+ble_hs_conn_chan_find(struct ble_hs_conn *conn, uint16_t cid)
+{
+ struct ble_l2cap_chan *chan;
+
+ SLIST_FOREACH(chan, &conn->bhc_channels, blc_next) {
+ if (chan->blc_cid == cid) {
+ return chan;
+ }
+ if (chan->blc_cid > cid) {
+ return NULL;
+ }
+ }
+
+ return NULL;
+}
+
+int
+ble_hs_conn_chan_insert(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
+{
+ struct ble_l2cap_chan *prev;
+ struct ble_l2cap_chan *cur;
+
+ prev = NULL;
+ SLIST_FOREACH(cur, &conn->bhc_channels, blc_next) {
+ if (cur->blc_cid == chan->blc_cid) {
+ return BLE_HS_EALREADY;
+ }
+ if (cur->blc_cid > chan->blc_cid) {
+ break;
+ }
+
+ prev = cur;
+ }
+
+ if (prev == NULL) {
+ SLIST_INSERT_HEAD(&conn->bhc_channels, chan, blc_next);
+ } else {
+ SLIST_INSERT_AFTER(prev, chan, blc_next);
+ }
+
+ return 0;
+}
+
struct ble_hs_conn *
ble_hs_conn_alloc(void)
{
@@ -56,13 +100,19 @@ ble_hs_conn_alloc(void)
if (chan == NULL) {
goto err;
}
- SLIST_INSERT_HEAD(&conn->bhc_channels, chan, blc_next);
+ rc = ble_hs_conn_chan_insert(conn, chan);
+ if (rc != 0) {
+ goto err;
+ }
chan = ble_l2cap_sig_create_chan();
if (chan == NULL) {
goto err;
}
- SLIST_INSERT_HEAD(&conn->bhc_channels, chan, blc_next);
+ rc = ble_hs_conn_chan_insert(conn, chan);
+ if (rc != 0) {
+ goto err;
+ }
rc = ble_gatts_conn_init(&conn->bhc_gatt_svr);
if (rc != 0) {
@@ -148,20 +198,6 @@ ble_hs_conn_first(void)
return SLIST_FIRST(&ble_hs_conns);
}
-struct ble_l2cap_chan *
-ble_hs_conn_chan_find(struct ble_hs_conn *conn, uint16_t cid)
-{
- struct ble_l2cap_chan *chan;
-
- SLIST_FOREACH(chan, &conn->bhc_channels, blc_next) {
- if (chan->blc_cid == cid) {
- return chan;
- }
- }
-
- return NULL;
-}
-
static void
ble_hs_conn_txable_transition(struct ble_hs_conn *conn)
{
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/f36c6128/net/nimble/host/src/ble_hs_conn.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.h b/net/nimble/host/src/ble_hs_conn.h
index 2f6ccd1..2e6c62d 100644
--- a/net/nimble/host/src/ble_hs_conn.h
+++ b/net/nimble/host/src/ble_hs_conn.h
@@ -62,6 +62,8 @@ struct ble_hs_conn *ble_hs_conn_find(uint16_t conn_handle);
struct ble_hs_conn *ble_hs_conn_first(void);
struct ble_l2cap_chan *ble_hs_conn_chan_find(struct ble_hs_conn *conn,
uint16_t cid);
+int ble_hs_conn_chan_insert(struct ble_hs_conn *conn,
+ struct ble_l2cap_chan *chan);
void ble_hs_conn_rx_num_completed_pkts(uint16_t handle, uint16_t num_pkts);
int ble_hs_conn_can_tx(struct ble_hs_conn *conn);
int ble_hs_conn_init(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/f36c6128/net/nimble/host/src/test/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_test.c b/net/nimble/host/src/test/ble_l2cap_test.c
index 6168e94..fd6be31 100644
--- a/net/nimble/host/src/test/ble_l2cap_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_test.c
@@ -58,7 +58,7 @@ ble_l2cap_test_create_conn(uint16_t handle, uint8_t *addr)
chan->blc_default_mtu = 240;
chan->blc_rx_fn = ble_l2cap_test_util_rx;
- SLIST_INSERT_HEAD(&conn->bhc_channels, chan, blc_next);
+ ble_hs_conn_chan_insert(conn, chan);
return conn;
}