You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2016/08/11 21:27:33 UTC
[33/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Check
conn state once before proc.
BLE Host - Check conn state once before proc.
Much of the host code repeatedly checks if a peer is connected while it
processes incoming data packets. This is not necessary, because:
1. The peer's connected state is checked at the top level before the
packet is processed.
2. Peer removal and packet processing is done in the same task.
This commit removes a bunch of redundant connectivity checks.
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/8e95fbe7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8e95fbe7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8e95fbe7
Branch: refs/heads/phyrx_no_mbuf
Commit: 8e95fbe714876dbd5a6f95593d995bdf9e0749fb
Parents: 9f944af
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Aug 10 13:45:12 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Thu Aug 11 14:26:26 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_att.c | 9 +-
net/nimble/host/src/ble_att_clt.c | 22 ++--
net/nimble/host/src/ble_att_priv.h | 4 +-
net/nimble/host/src/ble_att_svr.c | 179 +++++++++-------------------
net/nimble/host/src/ble_gattc.c | 10 +-
net/nimble/host/src/ble_hs_conn.c | 11 ++
net/nimble/host/src/ble_hs_conn_priv.h | 1 +
net/nimble/host/src/ble_hs_misc.c | 6 +-
net/nimble/host/src/ble_hs_priv.h | 6 +-
net/nimble/host/src/ble_l2cap_sig.c | 45 +++----
net/nimble/host/src/ble_sm.c | 68 +++--------
net/nimble/host/src/ble_sm_cmd.c | 9 +-
net/nimble/host/src/ble_sm_lgcy.c | 7 +-
net/nimble/host/src/ble_sm_priv.h | 8 +-
net/nimble/host/src/ble_sm_sc.c | 43 ++-----
15 files changed, 143 insertions(+), 285 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index 1743a4f..d5160d0 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -143,15 +143,12 @@ ble_att_rx_dispatch_entry_find(uint8_t op)
return NULL;
}
-int
+void
ble_att_conn_chan_find(uint16_t conn_handle, struct ble_hs_conn **out_conn,
struct ble_l2cap_chan **out_chan)
{
- int rc;
-
- rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_ATT,
- out_conn, out_chan);
- return rc;
+ ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_ATT,
+ out_conn, out_chan);
}
void
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/net/nimble/host/src/ble_att_clt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_clt.c b/net/nimble/host/src/ble_att_clt.c
index 87e2f44..ed36b7f 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -70,11 +70,9 @@ ble_att_clt_tx_req(uint16_t conn_handle, struct os_mbuf *txom)
ble_hs_lock();
- rc = ble_att_conn_chan_find(conn_handle, &conn, &chan);
- if (rc == 0) {
- ble_att_truncate_to_mtu(chan, txom);
- rc = ble_l2cap_tx(conn, chan, txom);
- }
+ ble_att_conn_chan_find(conn_handle, &conn, &chan);
+ ble_att_truncate_to_mtu(chan, txom);
+ rc = ble_l2cap_tx(conn, chan, txom);
ble_hs_unlock();
@@ -139,10 +137,8 @@ ble_att_clt_tx_mtu(uint16_t conn_handle, const struct ble_att_mtu_cmd *req)
ble_hs_lock();
- rc = ble_att_conn_chan_find(conn_handle, &conn, &chan);
- if (rc == 0) {
- chan->blc_flags |= BLE_L2CAP_CHAN_F_TXED_MTU;
- }
+ ble_att_conn_chan_find(conn_handle, &conn, &chan);
+ chan->blc_flags |= BLE_L2CAP_CHAN_F_TXED_MTU;
ble_hs_unlock();
@@ -166,11 +162,9 @@ ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom)
ble_hs_lock();
- rc = ble_att_conn_chan_find(conn_handle, NULL, &chan);
- if (rc == 0) {
- ble_att_set_peer_mtu(chan, cmd.bamc_mtu);
- mtu = ble_l2cap_chan_mtu(chan);
- }
+ ble_att_conn_chan_find(conn_handle, NULL, &chan);
+ ble_att_set_peer_mtu(chan, cmd.bamc_mtu);
+ mtu = ble_l2cap_chan_mtu(chan);
ble_hs_unlock();
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index edf9dce..ee9a9e9 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -158,8 +158,8 @@ SLIST_HEAD(ble_att_clt_entry_list, ble_att_clt_entry);
/*** @gen */
struct ble_l2cap_chan *ble_att_create_chan(void);
-int ble_att_conn_chan_find(uint16_t conn_handle, struct ble_hs_conn **out_conn,
- struct ble_l2cap_chan **out_chan);
+void ble_att_conn_chan_find(uint16_t conn_handle, struct ble_hs_conn **out_conn,
+ struct ble_l2cap_chan **out_chan);
void ble_att_inc_tx_stat(uint8_t att_op);
void ble_att_truncate_to_mtu(const struct ble_l2cap_chan *att_chan,
struct os_mbuf *txom);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/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 93c57ff..f224094 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -216,24 +216,18 @@ ble_att_svr_pullup_req_base(struct os_mbuf **om, int base_len,
return rc;
}
-static int
+static void
ble_att_svr_get_sec_state(uint16_t conn_handle,
struct ble_gap_sec_state *out_sec_state)
{
struct ble_hs_conn *conn;
ble_hs_lock();
- conn = ble_hs_conn_find(conn_handle);
- if (conn != NULL) {
- *out_sec_state = conn->bhc_sec_state;
- }
- ble_hs_unlock();
- if (conn == NULL) {
- return BLE_HS_ENOTCONN;
- } else {
- return 0;
- }
+ conn = ble_hs_conn_find_assert(conn_handle);
+ *out_sec_state = conn->bhc_sec_state;
+
+ ble_hs_unlock();
}
static int
@@ -245,7 +239,6 @@ ble_att_svr_check_perms(uint16_t conn_handle, int is_read,
int author;
int authen;
int enc;
- int rc;
if (is_read) {
if (!(entry->ha_flags & BLE_ATT_F_READ)) {
@@ -272,13 +265,7 @@ ble_att_svr_check_perms(uint16_t conn_handle, int is_read,
return 0;
}
- rc = ble_att_svr_get_sec_state(conn_handle, &sec_state);
- if (rc != 0) {
- /* Peer no longer connected. */
- *out_att_err = 0;
- return rc;
- }
-
+ ble_att_svr_get_sec_state(conn_handle, &sec_state);
if (enc && !sec_state.encrypted) {
/* XXX: Check security database; if required key present, respond with
* insufficient encryption error code.
@@ -542,10 +529,10 @@ err:
/**
* Transmits a response or error message over the specified connection.
*
- * The specified rc value controls what gets sent as follows:
+ * The specified rc and err_status values control what gets sent as follows:
* o If rc == 0: tx an affirmative response.
- * o If rc == BLE_HS_ENOTCONN: tx nothing.
- * o Else: tx an error response.
+ * o Else if err_status != 0: tx an error response.
+ * o Else: tx nothing.
*
* In addition, if transmission of an affirmative response fails, an error is
* sent instead.
@@ -570,10 +557,7 @@ ble_att_svr_tx_rsp(uint16_t conn_handle, int rc, struct os_mbuf *om,
struct ble_hs_conn *conn;
int do_tx;
- if (rc == BLE_HS_ENOTCONN) {
- /* No connection; tx is not possible. */
- do_tx = 0;
- } else if (rc != 0 && err_status == 0) {
+ if (rc != 0 && err_status == 0) {
/* Processing failed, but err_status of 0 means don't send error. */
do_tx = 0;
} else {
@@ -584,35 +568,33 @@ ble_att_svr_tx_rsp(uint16_t conn_handle, int rc, struct os_mbuf *om,
ble_hs_lock();
ble_att_conn_chan_find(conn_handle, &conn, &chan);
- if (chan == NULL) {
- rc = BLE_HS_ENOTCONN;
- } else {
- if (rc == 0) {
- BLE_HS_DBG_ASSERT(om != NULL);
+ BLE_HS_DBG_ASSERT(chan != NULL);
- ble_att_inc_tx_stat(om->om_data[0]);
- ble_att_truncate_to_mtu(chan, om);
- rc = ble_l2cap_tx(conn, chan, om);
- om = NULL;
- if (rc != 0) {
- err_status = BLE_ATT_ERR_UNLIKELY;
- }
- }
+ if (rc == 0) {
+ BLE_HS_DBG_ASSERT(om != NULL);
+ ble_att_inc_tx_stat(om->om_data[0]);
+ ble_att_truncate_to_mtu(chan, om);
+ rc = ble_l2cap_tx(conn, chan, om);
+ om = NULL;
if (rc != 0) {
- STATS_INC(ble_att_stats, error_rsp_tx);
+ err_status = BLE_ATT_ERR_UNLIKELY;
+ }
+ }
- /* Reuse om for error response. */
- if (om == NULL) {
- om = ble_hs_mbuf_l2cap_pkt();
- } else {
- os_mbuf_adj(om, OS_MBUF_PKTLEN(om));
- }
- if (om != NULL) {
- ble_att_svr_tx_error_rsp(conn, chan, om, att_op,
- err_handle, err_status);
- om = NULL;
- }
+ if (rc != 0) {
+ STATS_INC(ble_att_stats, error_rsp_tx);
+
+ /* Reuse om for error response. */
+ if (om == NULL) {
+ om = ble_hs_mbuf_l2cap_pkt();
+ } else {
+ os_mbuf_adj(om, OS_MBUF_PKTLEN(om));
+ }
+ if (om != NULL) {
+ ble_att_svr_tx_error_rsp(conn, chan, om, att_op,
+ err_handle, err_status);
+ om = NULL;
}
}
@@ -640,16 +622,10 @@ ble_att_svr_build_mtu_rsp(uint16_t conn_handle, struct os_mbuf **out_txom,
txom = NULL;
ble_hs_lock();
- rc = ble_att_conn_chan_find(conn_handle, NULL, &chan);
- if (rc == 0) {
- mtu = chan->blc_my_mtu;
- }
+ ble_att_conn_chan_find(conn_handle, NULL, &chan);
+ mtu = chan->blc_my_mtu;
ble_hs_unlock();
- if (rc != 0) {
- goto done;
- }
-
txom = ble_hs_mbuf_l2cap_pkt();
if (txom == NULL) {
*att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
@@ -708,11 +684,11 @@ done:
att_err, 0);
if (rc == 0) {
ble_hs_lock();
+
ble_att_conn_chan_find(conn_handle, &conn, &chan);
- if (chan != NULL) {
- ble_att_set_peer_mtu(chan, cmd.bamc_mtu);
- chan->blc_flags |= BLE_L2CAP_CHAN_F_TXED_MTU;
- }
+ ble_att_set_peer_mtu(chan, cmd.bamc_mtu);
+ chan->blc_flags |= BLE_L2CAP_CHAN_F_TXED_MTU;
+
ble_hs_unlock();
}
return rc;
@@ -830,10 +806,6 @@ ble_att_svr_build_find_info_rsp(uint16_t conn_handle,
txom = NULL;
mtu = ble_att_mtu(conn_handle);
- if (mtu == 0) {
- rc = BLE_HS_ENOTCONN;
- goto done;
- }
txom = ble_hs_mbuf_l2cap_pkt();
if (txom == NULL) {
@@ -1170,10 +1142,6 @@ ble_att_svr_build_find_type_value_rsp(uint16_t conn_handle,
/* Write the variable length Information Data field. */
mtu = ble_att_mtu(conn_handle);
- if (mtu == 0) {
- rc = BLE_HS_ENOTCONN;
- goto done;
- }
rc = ble_att_svr_fill_type_value(conn_handle, req, rxom, txom, mtu,
out_att_err);
@@ -1274,9 +1242,6 @@ ble_att_svr_build_read_type_rsp(uint16_t conn_handle,
prev_attr_len = 0;
mtu = ble_att_mtu(conn_handle);
- if (mtu == 0) {
- return BLE_HS_ENOTCONN;
- }
txom = ble_hs_mbuf_l2cap_pkt();
if (txom == NULL) {
@@ -1519,7 +1484,6 @@ ble_att_svr_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom)
struct ble_att_read_blob_req req;
struct os_mbuf *txom;
uint16_t err_handle;
- uint16_t mtu;
uint8_t *dptr;
uint8_t att_err;
int rc;
@@ -1529,12 +1493,6 @@ ble_att_svr_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom)
att_err = 0;
err_handle = 0;
- mtu = ble_att_mtu(conn_handle);
- if (mtu == 0) {
- rc = BLE_HS_ENOTCONN;
- goto done;
- }
-
rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_READ_BLOB_REQ_SZ, &att_err);
if (rc != 0) {
err_handle = 0;
@@ -1590,13 +1548,7 @@ ble_att_svr_build_read_mult_rsp(uint16_t conn_handle,
uint8_t *dptr;
int rc;
- txom = NULL;
-
mtu = ble_att_mtu(conn_handle);
- if (mtu == 0) {
- rc = BLE_HS_ENOTCONN;
- goto done;
- }
txom = ble_hs_mbuf_l2cap_pkt();
if (txom == NULL) {
@@ -1801,13 +1753,7 @@ ble_att_svr_build_read_group_type_rsp(uint16_t conn_handle,
*att_err = 0;
*err_handle = req->bagq_start_handle;
- txom = NULL;
-
mtu = ble_att_mtu(conn_handle);
- if (mtu == 0) {
- rc = BLE_HS_ENOTCONN;
- goto done;
- }
txom = ble_hs_mbuf_l2cap_pkt();
if (txom == NULL) {
@@ -2373,11 +2319,7 @@ ble_att_svr_insert_prep_entry(uint16_t conn_handle,
struct ble_hs_conn *conn;
int rc;
- conn = ble_hs_conn_find(conn_handle);
- if (conn == NULL) {
- *out_att_err = 0;
- return BLE_HS_ENOTCONN;
- }
+ conn = ble_hs_conn_find_assert(conn_handle);
prep_entry = ble_att_svr_prep_alloc();
if (prep_entry == NULL) {
@@ -2566,33 +2508,28 @@ ble_att_svr_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom)
done:
if (rc == 0) {
ble_hs_lock();
- conn = ble_hs_conn_find(conn_handle);
- if (conn == NULL) {
- rc = BLE_HS_ENOTCONN;
- } else {
- /* Extract the list of prepared writes from the connection so
- * that they can be processed after the mutex is unlocked. They
- * aren't processed now because attribute writes involve executing
- * an application callback.
- */
- prep_list = conn->bhc_att_svr.basc_prep_list;
- SLIST_INIT(&conn->bhc_att_svr.basc_prep_list);
- }
+ conn = ble_hs_conn_find_assert(conn_handle);
+
+ /* Extract the list of prepared writes from the connection so
+ * that they can be processed after the mutex is unlocked. They
+ * aren't processed now because attribute writes involve executing
+ * an application callback.
+ */
+ prep_list = conn->bhc_att_svr.basc_prep_list;
+ SLIST_INIT(&conn->bhc_att_svr.basc_prep_list);
ble_hs_unlock();
- if (conn != NULL) {
- if (req.baeq_flags & BLE_ATT_EXEC_WRITE_F_CONFIRM) {
- /* Perform attribute writes. */
- att_err = ble_att_svr_prep_write(conn_handle, &prep_list,
- &err_handle);
- if (att_err != 0) {
- rc = BLE_HS_EAPP;
- }
+ if (req.baeq_flags & BLE_ATT_EXEC_WRITE_F_CONFIRM) {
+ /* Perform attribute writes. */
+ att_err = ble_att_svr_prep_write(conn_handle, &prep_list,
+ &err_handle);
+ if (att_err != 0) {
+ rc = BLE_HS_EAPP;
}
-
- /* Free the prep entries. */
- ble_att_svr_prep_clear(&prep_list);
}
+
+ /* Free the prep entries. */
+ ble_att_svr_prep_clear(&prep_list);
}
rc = ble_att_svr_tx_rsp(conn_handle, rc, txom, BLE_ATT_OP_EXEC_WRITE_REQ,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 43d2134..3dee679 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -1042,16 +1042,10 @@ ble_gattc_exchange_mtu(uint16_t conn_handle, ble_gatt_mtu_fn *cb, void *cb_arg)
ble_gattc_log_proc_init("exchange mtu\n");
ble_hs_lock();
- rc = ble_att_conn_chan_find(proc->conn_handle, &conn, &chan);
- if (rc == 0) {
- req.bamc_mtu = chan->blc_my_mtu;
- }
+ ble_att_conn_chan_find(proc->conn_handle, &conn, &chan);
+ req.bamc_mtu = chan->blc_my_mtu;
ble_hs_unlock();
- if (rc != 0) {
- goto done;
- }
-
rc = ble_att_clt_tx_mtu(proc->conn_handle, &req);
if (rc != 0) {
goto done;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/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 76196ef..34d9590 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -245,6 +245,17 @@ ble_hs_conn_find(uint16_t conn_handle)
}
struct ble_hs_conn *
+ble_hs_conn_find_assert(uint16_t conn_handle)
+{
+ struct ble_hs_conn *conn;
+
+ conn = ble_hs_conn_find(conn_handle);
+ BLE_HS_DBG_ASSERT(conn != NULL);
+
+ return conn;
+}
+
+struct ble_hs_conn *
ble_hs_conn_find_by_addr(uint8_t addr_type, uint8_t *addr)
{
#if !NIMBLE_OPT(CONNECT)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/net/nimble/host/src/ble_hs_conn_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn_priv.h b/net/nimble/host/src/ble_hs_conn_priv.h
index cdcb363..da8d2fc 100644
--- a/net/nimble/host/src/ble_hs_conn_priv.h
+++ b/net/nimble/host/src/ble_hs_conn_priv.h
@@ -79,6 +79,7 @@ void ble_hs_conn_free(struct ble_hs_conn *conn);
void ble_hs_conn_insert(struct ble_hs_conn *conn);
void ble_hs_conn_remove(struct ble_hs_conn *conn);
struct ble_hs_conn *ble_hs_conn_find(uint16_t conn_handle);
+struct ble_hs_conn *ble_hs_conn_find_assert(uint16_t conn_handle);
struct ble_hs_conn *ble_hs_conn_find_by_addr(uint8_t addr_type, uint8_t *addr);
struct ble_hs_conn *ble_hs_conn_find_by_idx(int idx);
int ble_hs_conn_exists(uint16_t conn_handle);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/net/nimble/host/src/ble_hs_misc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_misc.c b/net/nimble/host/src/ble_hs_misc.c
index 216196b..649fc05 100644
--- a/net/nimble/host/src/ble_hs_misc.c
+++ b/net/nimble/host/src/ble_hs_misc.c
@@ -77,7 +77,7 @@ ble_hs_misc_conn_chan_find(uint16_t conn_handle, uint16_t cid,
return rc;
}
-int
+void
ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
struct ble_hs_conn **out_conn,
struct ble_l2cap_chan **out_chan)
@@ -87,7 +87,7 @@ ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
int rc;
rc = ble_hs_misc_conn_chan_find(conn_handle, cid, &conn, &chan);
- BLE_HS_DBG_ASSERT(conn == NULL || chan != NULL);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
if (out_conn != NULL) {
*out_conn = conn;
@@ -95,8 +95,6 @@ ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
if (out_chan != NULL) {
*out_chan = chan;
}
-
- return rc;
}
uint8_t
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index d61f0ba..6bebec9 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -91,9 +91,9 @@ int ble_hs_misc_malloc_mempool(void **mem, struct os_mempool *pool,
int ble_hs_misc_conn_chan_find(uint16_t conn_handle, uint16_t cid,
struct ble_hs_conn **out_conn,
struct ble_l2cap_chan **out_chan);
-int ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
- struct ble_hs_conn **out_conn,
- struct ble_l2cap_chan **out_chan);
+void ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
+ struct ble_hs_conn **out_conn,
+ struct ble_l2cap_chan **out_chan);
uint8_t ble_hs_misc_addr_type_to_id(uint8_t addr_type);
void ble_hs_cfg_init(struct ble_hs_cfg *cfg);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/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 4838067..a382b09 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -338,18 +338,16 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
/* Send L2CAP response. */
ble_hs_lock();
- rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG,
- &conn, &chan);
- if (rc == 0) {
- if (!sig_err) {
- rc = ble_l2cap_sig_update_rsp_tx(conn, chan, hdr->identifier,
- l2cap_result);
- } else {
- ble_l2cap_sig_reject_tx(conn, chan, hdr->identifier,
- BLE_L2CAP_SIG_ERR_CMD_NOT_UNDERSTOOD,
- NULL, 0);
- rc = BLE_HS_L2C_ERR(BLE_L2CAP_SIG_ERR_CMD_NOT_UNDERSTOOD);
- }
+ ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG,
+ &conn, &chan);
+ if (!sig_err) {
+ rc = ble_l2cap_sig_update_rsp_tx(conn, chan, hdr->identifier,
+ l2cap_result);
+ } else {
+ ble_l2cap_sig_reject_tx(conn, chan, hdr->identifier,
+ BLE_L2CAP_SIG_ERR_CMD_NOT_UNDERSTOOD,
+ NULL, 0);
+ rc = BLE_HS_L2C_ERR(BLE_L2CAP_SIG_ERR_CMD_NOT_UNDERSTOOD);
}
ble_hs_unlock();
@@ -421,11 +419,8 @@ ble_l2cap_sig_update(uint16_t conn_handle,
ble_hs_lock();
- rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG,
- &conn, &chan);
- if (rc != 0) {
- goto done;
- }
+ ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG,
+ &conn, &chan);
if (conn->bhc_flags & BLE_HS_CONN_F_MASTER) {
/* Only the slave can initiate the L2CAP connection update
* procedure.
@@ -499,16 +494,12 @@ ble_l2cap_sig_rx(uint16_t conn_handle, struct os_mbuf **om)
rx_cb = ble_l2cap_sig_dispatch_get(hdr.op);
if (rx_cb == NULL) {
ble_hs_lock();
- rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG,
- &conn, &chan);
- if (rc == 0) {
- ble_l2cap_sig_reject_tx(conn, chan, hdr.identifier,
- BLE_L2CAP_SIG_ERR_CMD_NOT_UNDERSTOOD,
- NULL, 0);
- rc = BLE_HS_L2C_ERR(BLE_L2CAP_SIG_ERR_CMD_NOT_UNDERSTOOD);
- } else {
- rc = BLE_HS_ENOTCONN;
- }
+ ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG,
+ &conn, &chan);
+ ble_l2cap_sig_reject_tx(conn, chan, hdr.identifier,
+ BLE_L2CAP_SIG_ERR_CMD_NOT_UNDERSTOOD,
+ NULL, 0);
+ rc = BLE_HS_L2C_ERR(BLE_L2CAP_SIG_ERR_CMD_NOT_UNDERSTOOD);
ble_hs_unlock();
} else {
rc = rx_cb(conn_handle, &hdr, om);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index f2a7b5c..4991e2e 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -494,24 +494,7 @@ ble_sm_fill_store_value(uint8_t peer_addr_type, uint8_t *peer_addr,
}
}
-int
-ble_sm_peer_addr(struct ble_sm_proc *proc,
- uint8_t *out_type, uint8_t **out_addr)
-{
- struct ble_hs_conn *conn;
-
- conn = ble_hs_conn_find(proc->conn_handle);
- if (conn == NULL) {
- return BLE_HS_ENOTCONN;
- }
-
- *out_type = conn->bhc_peer_addr_type;
- *out_addr = conn->bhc_peer_addr;
-
- return 0;
-}
-
-int
+void
ble_sm_ia_ra(struct ble_sm_proc *proc,
uint8_t *out_iat, uint8_t *out_ia,
uint8_t *out_rat, uint8_t *out_ra)
@@ -519,10 +502,7 @@ ble_sm_ia_ra(struct ble_sm_proc *proc,
struct ble_hs_conn_addrs addrs;
struct ble_hs_conn *conn;
- conn = ble_hs_conn_find(proc->conn_handle);
- if (conn == NULL) {
- return BLE_HS_ENOTCONN;
- }
+ conn = ble_hs_conn_find_assert(proc->conn_handle);
ble_hs_conn_addrs(conn, &addrs);
@@ -539,8 +519,6 @@ ble_sm_ia_ra(struct ble_sm_proc *proc,
*out_rat = addrs.our_id_addr_type;
memcpy(out_ra, addrs.our_ota_addr, 6);
}
-
- return 0;
}
static void
@@ -765,13 +743,16 @@ ble_sm_exec(struct ble_sm_proc *proc, struct ble_sm_result *res, void *arg)
{
ble_sm_state_fn *cb;
- BLE_HS_DBG_ASSERT(proc->state < BLE_SM_PROC_STATE_CNT);
- cb = ble_sm_state_dispatch[proc->state];
- BLE_HS_DBG_ASSERT(cb != NULL);
-
memset(res, 0, sizeof *res);
- cb(proc, res, arg);
+ if (!ble_hs_conn_exists(proc->conn_handle)) {
+ res->app_status = BLE_HS_ENOTCONN;
+ } else {
+ BLE_HS_DBG_ASSERT(proc->state < BLE_SM_PROC_STATE_CNT);
+ cb = ble_sm_state_dispatch[proc->state];
+ BLE_HS_DBG_ASSERT(cb != NULL);
+ cb(proc, res, arg);
+ }
}
void
@@ -1208,13 +1189,9 @@ ble_sm_ltk_req_rx(struct hci_le_lt_key_req *evt)
}
if (restore) {
- conn = ble_hs_conn_find(evt->connection_handle);
- if (conn == NULL) {
- res.app_status = BLE_HS_ENOTCONN;
- } else {
- ble_hs_conn_addrs(conn, &addrs);
- memcpy(peer_id_addr, addrs.peer_id_addr, 6);
- }
+ conn = ble_hs_conn_find_assert(evt->connection_handle);
+ ble_hs_conn_addrs(conn, &addrs);
+ memcpy(peer_id_addr, addrs.peer_id_addr, 6);
}
ble_hs_unlock();
@@ -1526,11 +1503,8 @@ ble_sm_pair_req_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
proc->pair_req = req;
- conn = ble_hs_conn_find(proc->conn_handle);
- if (conn == NULL) {
- res->sm_err = BLE_SM_ERR_UNSPECIFIED;
- res->app_status = BLE_HS_ENOTCONN;
- } else if (conn->bhc_flags & BLE_HS_CONN_F_MASTER) {
+ conn = ble_hs_conn_find_assert(proc->conn_handle);
+ if (conn->bhc_flags & BLE_HS_CONN_F_MASTER) {
res->sm_err = BLE_SM_ERR_CMD_NOT_SUPP;
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_CMD_NOT_SUPP);
} else if (!ble_sm_pair_cmd_is_valid(&req)) {
@@ -1630,10 +1604,8 @@ ble_sm_sec_req_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
ble_hs_lock();
- conn = ble_hs_conn_find(conn_handle);
- if (conn == NULL) {
- res->app_status = BLE_HS_ENOTCONN;
- } else if (!(conn->bhc_flags & BLE_HS_CONN_F_MASTER)) {
+ conn = ble_hs_conn_find_assert(conn_handle);
+ if (!(conn->bhc_flags & BLE_HS_CONN_F_MASTER)) {
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_CMD_NOT_SUPP);
res->sm_err = BLE_SM_ERR_CMD_NOT_SUPP;
} else {
@@ -1769,11 +1741,7 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
proc->our_keys.irk_valid = 1;
/* Send identity address information. */
- conn = ble_hs_conn_find(proc->conn_handle);
- if (conn == NULL) {
- rc = BLE_HS_ENOTCONN;
- goto err;
- }
+ conn = ble_hs_conn_find_assert(proc->conn_handle);
ble_hs_conn_addrs(conn, &addrs);
addr_info.addr_type = addrs.our_id_addr_type;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/net/nimble/host/src/ble_sm_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_cmd.c b/net/nimble/host/src/ble_sm_cmd.c
index 9854bde..0283137 100644
--- a/net/nimble/host/src/ble_sm_cmd.c
+++ b/net/nimble/host/src/ble_sm_cmd.c
@@ -38,13 +38,8 @@ ble_sm_tx(uint16_t conn_handle, struct os_mbuf *txom)
STATS_INC(ble_l2cap_stats, sm_tx);
- rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SM,
- &conn, &chan);
- if (rc != 0) {
- os_mbuf_free_chain(txom);
- return rc;
- }
-
+ ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SM,
+ &conn, &chan);
rc = ble_l2cap_tx(conn, chan, txom);
if (rc != 0) {
return rc;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/net/nimble/host/src/ble_sm_lgcy.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_lgcy.c b/net/nimble/host/src/ble_sm_lgcy.c
index d844a6f..7b1673c 100644
--- a/net/nimble/host/src/ble_sm_lgcy.c
+++ b/net/nimble/host/src/ble_sm_lgcy.c
@@ -109,12 +109,7 @@ ble_sm_lgcy_confirm_prepare_args(struct ble_sm_proc *proc,
uint8_t *iat, uint8_t *rat,
uint8_t *ia, uint8_t *ra)
{
- int rc;
-
- rc = ble_sm_ia_ra(proc, iat, ia, rat, ra);
- if (rc != 0) {
- return rc;
- }
+ ble_sm_ia_ra(proc, iat, ia, rat, ra);
memcpy(k, proc->tk, sizeof proc->tk);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index 80798e1..d15afbc 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -448,11 +448,9 @@ int ble_sm_ioact_state(uint8_t action);
int ble_sm_proc_can_advance(struct ble_sm_proc *proc);
void ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res);
void ble_sm_confirm_advance(struct ble_sm_proc *proc);
-int ble_sm_peer_addr(struct ble_sm_proc *proc,
- uint8_t *out_type, uint8_t **out_addr);
-int ble_sm_ia_ra(struct ble_sm_proc *proc,
- uint8_t *out_iat, uint8_t *out_ia,
- uint8_t *out_rat, uint8_t *out_ra);
+void ble_sm_ia_ra(struct ble_sm_proc *proc,
+ uint8_t *out_iat, uint8_t *out_ia,
+ uint8_t *out_rat, uint8_t *out_ra);
int32_t ble_sm_heartbeat(void);
void ble_sm_connection_broken(uint16_t conn_handle);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e95fbe7/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index 539d0f9..1c38d04 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -386,14 +386,7 @@ ble_sm_sc_random_rx(struct ble_sm_proc *proc, struct ble_sm_result *res)
}
/* Calculate the mac key and ltk. */
- rc = ble_sm_ia_ra(proc, &iat, ia, &rat, ra);
- if (rc != 0) {
- res->app_status = rc;
- res->sm_err = BLE_SM_ERR_UNSPECIFIED;
- res->enc_cb = 1;
- return;
- }
-
+ ble_sm_ia_ra(proc, &iat, ia, &rat, ra);
rc = ble_sm_alg_f5(proc->dhkey, proc->randm, proc->rands,
iat, ia, rat, ra, proc->mackey, proc->ltk);
if (rc != 0) {
@@ -531,7 +524,7 @@ ble_sm_sc_public_key_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
ble_hs_unlock();
}
-static int
+static void
ble_sm_sc_dhkey_addrs(struct ble_sm_proc *proc,
uint8_t *out_our_id_addr_type,
const uint8_t **out_our_ota_addr,
@@ -541,18 +534,13 @@ ble_sm_sc_dhkey_addrs(struct ble_sm_proc *proc,
struct ble_hs_conn_addrs addrs;
struct ble_hs_conn *conn;
- conn = ble_hs_conn_find(proc->conn_handle);
- if (conn == NULL) {
- return BLE_HS_ENOTCONN;
- }
+ conn = ble_hs_conn_find_assert(proc->conn_handle);
ble_hs_conn_addrs(conn, &addrs);
*out_our_id_addr_type = addrs.our_id_addr_type;
*out_our_ota_addr = addrs.our_ota_addr;
*out_peer_id_addr_type = addrs.peer_id_addr_type;
*out_peer_ota_addr = addrs.peer_ota_addr;
-
- return 0;
}
static void
@@ -582,12 +570,9 @@ ble_sm_sc_dhkey_check_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
ble_sm_sc_dhkey_check_iocap(&proc->pair_rsp, iocap);
}
- rc = ble_sm_sc_dhkey_addrs(proc,
- &our_id_addr_type, &our_ota_addr,
- &peer_id_addr_type, &peer_ota_addr);
- if (rc != 0) {
- goto err;
- }
+ ble_sm_sc_dhkey_addrs(proc,
+ &our_id_addr_type, &our_ota_addr,
+ &peer_id_addr_type, &peer_ota_addr);
rc = ble_sm_alg_f6(proc->mackey, ble_sm_our_pair_rand(proc),
ble_sm_peer_pair_rand(proc), proc->tk, iocap,
@@ -634,17 +619,11 @@ ble_sm_dhkey_check_process(struct ble_sm_proc *proc,
ble_sm_sc_dhkey_check_iocap(&proc->pair_req, iocap);
}
- res->app_status = ble_sm_sc_dhkey_addrs(proc,
- &our_id_addr_type,
- &our_ota_addr,
- &peer_id_addr_type,
- &peer_ota_addr);
- if (res->app_status != 0) {
- res->sm_err = BLE_SM_ERR_UNSPECIFIED;
- res->enc_cb = 1;
- return;
- }
-
+ ble_sm_sc_dhkey_addrs(proc,
+ &our_id_addr_type,
+ &our_ota_addr,
+ &peer_id_addr_type,
+ &peer_ota_addr);
BLE_HS_LOG(DEBUG, "tk=");
ble_hs_log_flat_buf(proc->tk, 32);
BLE_HS_LOG(DEBUG, "\n");