You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2017/03/06 21:18:58 UTC
[22/50] incubator-mynewt-core git commit: nimble/l2cap: Refactor
update parameters handling
nimble/l2cap: Refactor update parameters handling
With this patch l2cap update parameters is handled in similar way as
other signaling commands.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/98ebb513
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/98ebb513
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/98ebb513
Branch: refs/heads/master
Commit: 98ebb5133ac345d8a9a93b335722e88b68373673
Parents: 506e373
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 2 10:21:57 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100
----------------------------------------------------------------------
net/nimble/host/src/ble_l2cap_sig.c | 55 +++++++++-----
net/nimble/host/src/ble_l2cap_sig_cmd.c | 94 ------------------------
net/nimble/host/src/ble_l2cap_sig_priv.h | 17 +----
net/nimble/host/test/src/ble_hs_test_util.c | 42 ++++++++++-
net/nimble/host/test/src/ble_l2cap_test.c | 20 ++++-
5 files changed, 98 insertions(+), 130 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98ebb513/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 9292137..7919a89 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -336,7 +336,9 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
struct ble_l2cap_sig_hdr *hdr,
struct os_mbuf **om)
{
- struct ble_l2cap_sig_update_req req;
+ struct ble_l2cap_sig_update_req *req;
+ struct os_mbuf *txom;
+ struct ble_l2cap_sig_update_rsp *rsp;
struct ble_gap_upd_params params;
ble_hs_conn_flags_t conn_flags;
uint16_t l2cap_result;
@@ -361,12 +363,12 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
return BLE_HS_EREJECT;
}
- ble_l2cap_sig_update_req_parse((*om)->om_data, (*om)->om_len, &req);
+ req = (struct ble_l2cap_sig_update_req *)(*om)->om_data;
- params.itvl_min = req.itvl_min;
- params.itvl_max = req.itvl_max;
- params.latency = req.slave_latency;
- params.supervision_timeout = req.timeout_multiplier;
+ params.itvl_min = le16toh(req->itvl_min);
+ params.itvl_max = le16toh(req->itvl_max);
+ params.latency = le16toh(req->slave_latency);
+ params.supervision_timeout = le16toh(req->timeout_multiplier);
params.min_ce_len = BLE_GAP_INITIAL_CONN_MIN_CE_LEN;
params.max_ce_len = BLE_GAP_INITIAL_CONN_MAX_CE_LEN;
@@ -383,11 +385,19 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
l2cap_result = BLE_L2CAP_SIG_UPDATE_RSP_RESULT_REJECT;
}
+ rsp = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_UPDATE_RSP, hdr->identifier,
+ sizeof(*rsp), &txom);
+ if (!rsp) {
+ /* No memory for response, lest allow to timeout on remote side */
+ return 0;
+ }
+
+ rsp->result = htole16(l2cap_result);
+
/* Send L2CAP response. */
- rc = ble_l2cap_sig_update_rsp_tx(conn_handle, hdr->identifier,
- l2cap_result);
+ ble_l2cap_sig_tx(conn_handle, txom);
- return rc;
+ return 0;
}
static int
@@ -395,7 +405,7 @@ ble_l2cap_sig_update_rsp_rx(uint16_t conn_handle,
struct ble_l2cap_sig_hdr *hdr,
struct os_mbuf **om)
{
- struct ble_l2cap_sig_update_rsp rsp;
+ struct ble_l2cap_sig_update_rsp *rsp;
struct ble_l2cap_sig_proc *proc;
int cb_status;
int rc;
@@ -413,9 +423,9 @@ ble_l2cap_sig_update_rsp_rx(uint16_t conn_handle,
goto done;
}
- ble_l2cap_sig_update_rsp_parse((*om)->om_data, (*om)->om_len, &rsp);
+ rsp = (struct ble_l2cap_sig_update_rsp *)(*om)->om_data;
- switch (rsp.result) {
+ switch (le16toh(rsp->result)) {
case BLE_L2CAP_SIG_UPDATE_RSP_RESULT_ACCEPT:
cb_status = 0;
rc = 0;
@@ -443,7 +453,8 @@ ble_l2cap_sig_update(uint16_t conn_handle,
struct ble_l2cap_sig_update_params *params,
ble_l2cap_sig_update_fn *cb, void *cb_arg)
{
- struct ble_l2cap_sig_update_req req;
+ struct os_mbuf *txom;
+ struct ble_l2cap_sig_update_req *req;
struct ble_l2cap_sig_proc *proc;
struct ble_l2cap_chan *chan;
struct ble_hs_conn *conn;
@@ -481,12 +492,20 @@ ble_l2cap_sig_update(uint16_t conn_handle,
proc->update.cb = cb;
proc->update.cb_arg = cb_arg;
- req.itvl_min = params->itvl_min;
- req.itvl_max = params->itvl_max;
- req.slave_latency = params->slave_latency;
- req.timeout_multiplier = params->timeout_multiplier;
+ req = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_UPDATE_REQ, proc->id,
+ sizeof(*req), &txom);
+ if (!req) {
+ STATS_INC(ble_l2cap_stats, update_fail);
+ rc = BLE_HS_ENOMEM;
+ goto done;
+ }
- rc = ble_l2cap_sig_update_req_tx(conn_handle, proc->id, &req);
+ req->itvl_min = htole16(params->itvl_min);
+ req->itvl_max = htole16(params->itvl_max);
+ req->slave_latency = htole16(params->slave_latency);
+ req->timeout_multiplier = htole16(params->timeout_multiplier);
+
+ rc = ble_l2cap_sig_tx(conn_handle, txom);
done:
ble_l2cap_sig_process_status(proc, rc);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98ebb513/net/nimble/host/src/ble_l2cap_sig_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_cmd.c b/net/nimble/host/src/ble_l2cap_sig_cmd.c
index f7e68c8..189efd7 100644
--- a/net/nimble/host/src/ble_l2cap_sig_cmd.c
+++ b/net/nimble/host/src/ble_l2cap_sig_cmd.c
@@ -158,99 +158,6 @@ ble_l2cap_sig_reject_invalid_cid_tx(uint16_t conn_handle, uint8_t id,
&data, sizeof data);
}
-static void
-ble_l2cap_sig_update_req_swap(struct ble_l2cap_sig_update_req *dst,
- struct ble_l2cap_sig_update_req *src)
-{
- dst->itvl_min = TOFROMLE16(src->itvl_min);
- dst->itvl_max = TOFROMLE16(src->itvl_max);
- dst->slave_latency = TOFROMLE16(src->slave_latency);
- dst->timeout_multiplier = TOFROMLE16(src->timeout_multiplier);
-}
-
-void
-ble_l2cap_sig_update_req_parse(void *payload, int len,
- struct ble_l2cap_sig_update_req *dst)
-{
- BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
- ble_l2cap_sig_update_req_swap(dst, payload);
-}
-
-void
-ble_l2cap_sig_update_req_write(void *payload, int len,
- struct ble_l2cap_sig_update_req *src)
-{
- BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
- ble_l2cap_sig_update_req_swap(payload, src);
-}
-
-int
-ble_l2cap_sig_update_req_tx(uint16_t conn_handle, uint8_t id,
- struct ble_l2cap_sig_update_req *req)
-{
- struct os_mbuf *txom;
- void *payload_buf;
- int rc;
-
- rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_UPDATE_REQ, id,
- BLE_L2CAP_SIG_UPDATE_REQ_SZ, &txom,
- &payload_buf);
- if (rc != 0) {
- return rc;
- }
-
- ble_l2cap_sig_update_req_write(payload_buf, BLE_L2CAP_SIG_UPDATE_REQ_SZ,
- req);
-
- return ble_l2cap_sig_tx(conn_handle, txom);
-}
-
-static void
-ble_l2cap_sig_update_rsp_swap(struct ble_l2cap_sig_update_rsp *dst,
- struct ble_l2cap_sig_update_rsp *src)
-{
- dst->result = TOFROMLE16(src->result);
-}
-
-void
-ble_l2cap_sig_update_rsp_parse(void *payload, int len,
- struct ble_l2cap_sig_update_rsp *dst)
-{
- BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
- ble_l2cap_sig_update_rsp_swap(dst, payload);
-}
-
-void
-ble_l2cap_sig_update_rsp_write(void *payload, int len,
- struct ble_l2cap_sig_update_rsp *src)
-{
- BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
- ble_l2cap_sig_update_rsp_swap(payload, src);
-}
-
-int
-ble_l2cap_sig_update_rsp_tx(uint16_t conn_handle, uint8_t id, uint16_t result)
-{
- struct ble_l2cap_sig_update_rsp rsp;
- struct os_mbuf *txom;
- void *payload_buf;
- int rc;
-
- rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_UPDATE_RSP, id,
- BLE_L2CAP_SIG_UPDATE_RSP_SZ, &txom,
- &payload_buf);
- if (rc != 0) {
- return rc;
- }
-
- rsp.result = result;
- ble_l2cap_sig_update_rsp_write(payload_buf, BLE_L2CAP_SIG_UPDATE_RSP_SZ,
- &rsp);
-
- return ble_l2cap_sig_tx(conn_handle, txom);
-}
-
-#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
void *
ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len,
struct os_mbuf **txom)
@@ -275,4 +182,3 @@ ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len,
return hdr->data;
}
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98ebb513/net/nimble/host/src/ble_l2cap_sig_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_priv.h b/net/nimble/host/src/ble_l2cap_sig_priv.h
index 48bff7e..f089dcb 100644
--- a/net/nimble/host/src/ble_l2cap_sig_priv.h
+++ b/net/nimble/host/src/ble_l2cap_sig_priv.h
@@ -92,28 +92,15 @@ void ble_l2cap_sig_hdr_write(void *payload, uint16_t len,
int ble_l2cap_sig_reject_tx(uint16_t conn_handle,
uint8_t id, uint16_t reason,
void *data, int data_len);
-void ble_l2cap_sig_update_req_parse(void *payload, int len,
- struct ble_l2cap_sig_update_req *req);
-void ble_l2cap_sig_update_req_write(void *payload, int len,
- struct ble_l2cap_sig_update_req *src);
-int ble_l2cap_sig_update_req_tx(uint16_t conn_handle, uint8_t id,
- struct ble_l2cap_sig_update_req *req);
-void ble_l2cap_sig_update_rsp_parse(void *payload, int len,
- struct ble_l2cap_sig_update_rsp *cmd);
-void ble_l2cap_sig_update_rsp_write(void *payload, int len,
- struct ble_l2cap_sig_update_rsp *src);
-int ble_l2cap_sig_update_rsp_tx(uint16_t conn_handle, uint8_t id,
- uint16_t result);
int ble_l2cap_sig_reject_invalid_cid_tx(uint16_t conn_handle, uint8_t id,
uint16_t src_cid, uint16_t dst_cid);
int ble_l2cap_sig_tx(uint16_t conn_handle, struct os_mbuf *txom);
+void *ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len,
+ struct os_mbuf **txom);
#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
int ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
struct os_mbuf *sdu_rx,
ble_l2cap_event_fn *cb, void *cb_arg);
-void *ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len,
- struct os_mbuf **txom);
-
int ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan);
#else
#define ble_l2cap_sig_coc_connect(conn_handle, psm, mtu, sdu_rx, cb, cb_arg) \
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98ebb513/net/nimble/host/test/src/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test_util.c b/net/nimble/host/test/src/ble_hs_test_util.c
index cd9e1b2..ceabd1c 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.c
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -1764,6 +1764,24 @@ ble_hs_test_util_verify_tx_l2cap_sig_hdr(uint8_t op, uint8_t id,
return om;
}
+static void
+ble_l2cap_test_update_req_swap(struct ble_l2cap_sig_update_req *dst,
+ struct ble_l2cap_sig_update_req *src)
+{
+ dst->itvl_min = le16toh(src->itvl_min);
+ dst->itvl_max = le16toh(src->itvl_max);
+ dst->slave_latency = le16toh(src->slave_latency);
+ dst->timeout_multiplier = le16toh(src->timeout_multiplier);
+}
+
+static void
+ble_l2cap_test_update_req_parse(void *payload, int len,
+ struct ble_l2cap_sig_update_req *dst)
+{
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
+ ble_l2cap_test_update_req_swap(dst, payload);
+}
+
/**
* @return The L2CAP sig identifier in the request.
*/
@@ -1783,7 +1801,7 @@ ble_hs_test_util_verify_tx_l2cap_update_req(
&hdr);
/* Verify payload. */
- ble_l2cap_sig_update_req_parse(om->om_data, om->om_len, &req);
+ ble_l2cap_test_update_req_parse(om->om_data, om->om_len, &req);
TEST_ASSERT(req.itvl_min == params->itvl_min);
TEST_ASSERT(req.itvl_max == params->itvl_max);
TEST_ASSERT(req.slave_latency == params->slave_latency);
@@ -1792,6 +1810,26 @@ ble_hs_test_util_verify_tx_l2cap_update_req(
return hdr.identifier;
}
+static void
+ble_l2cap_sig_update_rsp_parse(void *payload, int len,
+ struct ble_l2cap_sig_update_rsp *dst)
+{
+ struct ble_l2cap_sig_update_rsp *src = payload;
+
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
+ dst->result = le16toh(src->result);
+}
+
+static void
+ble_l2cap_test_update_rsp_write(void *payload, int len,
+ struct ble_l2cap_sig_update_rsp *src)
+{
+ struct ble_l2cap_sig_update_rsp *dst = payload;
+
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
+ dst->result = htole16(src->result);
+}
+
int
ble_hs_test_util_rx_l2cap_update_rsp(uint16_t conn_handle,
uint8_t id, uint16_t result)
@@ -1811,7 +1849,7 @@ ble_hs_test_util_rx_l2cap_update_rsp(uint16_t conn_handle,
TEST_ASSERT_FATAL(rc == 0);
rsp.result = result;
- ble_l2cap_sig_update_rsp_write(v, BLE_L2CAP_SIG_UPDATE_RSP_SZ, &rsp);
+ ble_l2cap_test_update_rsp_write(v, BLE_L2CAP_SIG_UPDATE_RSP_SZ, &rsp);
rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SIG,
&hci_hdr, om);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98ebb513/net/nimble/host/test/src/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_l2cap_test.c b/net/nimble/host/test/src/ble_l2cap_test.c
index f4f16bc..2958a6c 100644
--- a/net/nimble/host/test/src/ble_l2cap_test.c
+++ b/net/nimble/host/test/src/ble_l2cap_test.c
@@ -44,6 +44,24 @@ ble_l2cap_test_util_init(void)
}
static void
+ble_l2cap_test_update_req_swap(struct ble_l2cap_sig_update_req *dst,
+ struct ble_l2cap_sig_update_req *src)
+{
+ dst->itvl_min = le16toh(src->itvl_min);
+ dst->itvl_max = le16toh(src->itvl_max);
+ dst->slave_latency = le16toh(src->slave_latency);
+ dst->timeout_multiplier = le16toh(src->timeout_multiplier);
+}
+
+static void
+ble_l2cap_test_update_req_write(void *payload, int len,
+ struct ble_l2cap_sig_update_req *src)
+{
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
+ ble_l2cap_test_update_req_swap(payload, src);
+}
+
+static void
ble_l2cap_test_util_rx_update_req(uint16_t conn_handle, uint8_t id,
struct ble_l2cap_sig_update_params *params)
{
@@ -65,7 +83,7 @@ ble_l2cap_test_util_rx_update_req(uint16_t conn_handle, uint8_t id,
req.itvl_max = params->itvl_max;
req.slave_latency = params->slave_latency;
req.timeout_multiplier = params->timeout_multiplier;
- ble_l2cap_sig_update_req_write(v, BLE_L2CAP_SIG_UPDATE_REQ_SZ, &req);
+ ble_l2cap_test_update_req_write(v, BLE_L2CAP_SIG_UPDATE_REQ_SZ, &req);
ble_hs_test_util_set_ack(
ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,