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/04/06 02:37:26 UTC
[5/6] incubator-mynewt-core git commit: ble host: sm procedures time
out after 30 seconds.
ble host: sm procedures time out after 30 seconds.
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/6e099aa6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/6e099aa6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/6e099aa6
Branch: refs/heads/develop
Commit: 6e099aa6c1e2d660b77a78a90249c4fba23e7a28
Parents: 5bf00b0
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Apr 5 16:29:48 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Apr 5 17:36:31 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_hs.c | 1 +
net/nimble/host/src/ble_l2cap_sm.c | 56 ++++++++++++++++++++++++++++++++-
net/nimble/host/src/ble_l2cap_sm.h | 2 ++
3 files changed, 58 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e099aa6/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index f8990d9..af30e0e 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -134,6 +134,7 @@ ble_hs_heartbeat(void *unused)
ble_gattc_heartbeat();
ble_gap_heartbeat();
+ ble_l2cap_sm_heartbeat();
ble_hs_heartbeat_timer_reset();
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e099aa6/net/nimble/host/src/ble_l2cap_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sm.c b/net/nimble/host/src/ble_l2cap_sm.c
index 06b0925..6d89466 100644
--- a/net/nimble/host/src/ble_l2cap_sm.c
+++ b/net/nimble/host/src/ble_l2cap_sm.c
@@ -41,10 +41,14 @@
#define BLE_L2CAP_SM_PROC_F_INITIATOR 0x01
+/** Procedure timeout; 30 seconds. */
+#define BLE_L2CAP_SM_TIMEOUT_OS_TICKS (30 * OS_TICKS_PER_SEC)
+
typedef uint16_t ble_l2cap_sm_proc_flags;
struct ble_l2cap_sm_proc {
struct ble_fsm_proc fsm_proc;
+ uint32_t exp_os_ticks;
ble_l2cap_sm_proc_flags flags;
uint8_t pair_alg;
@@ -249,6 +253,7 @@ ble_l2cap_sm_gen_start_rand(void)
static int
ble_l2cap_sm_proc_kick(struct ble_fsm_proc *proc)
{
+ struct ble_l2cap_sm_proc *sm_proc;
ble_l2cap_sm_kick_fn *kick_cb;
int rc;
@@ -256,7 +261,12 @@ ble_l2cap_sm_proc_kick(struct ble_fsm_proc *proc)
kick_cb = ble_l2cap_sm_kick[proc->op];
BLE_HS_DBG_ASSERT(kick_cb != NULL);
- rc = kick_cb((struct ble_l2cap_sm_proc *)proc);
+ /* Set a timeout of 30 seconds. */
+ sm_proc = (struct ble_l2cap_sm_proc *)proc;
+
+ sm_proc->exp_os_ticks = os_time_get() + BLE_L2CAP_SM_TIMEOUT_OS_TICKS;
+ rc = kick_cb(sm_proc);
+
return rc;
}
@@ -329,6 +339,25 @@ ble_l2cap_sm_proc_new(uint16_t conn_handle, uint8_t op,
return 0;
}
+/**
+ * Extraction callback used for removing all pairing procedures that have timed
+ * out.
+ */
+static int
+ble_l2cap_sm_proc_extract_expired_cb(struct ble_fsm_proc *proc, void *unused)
+{
+ uint32_t now;
+ int32_t diff;
+
+ now = os_time_get();
+ diff = now - ((struct ble_l2cap_sm_proc *)proc)->exp_os_ticks;
+ if (diff >= 0) {
+ return BLE_FSM_EXTRACT_EMOVE_CONTINUE;
+ } else {
+ return BLE_FSM_EXTRACT_EKEEP_CONTINUE;
+ }
+}
+
static int
ble_l2cap_sm_proc_extract_cb(struct ble_fsm_proc *proc, void *arg)
{
@@ -1196,6 +1225,31 @@ ble_l2cap_sm_rx(uint16_t conn_handle, struct os_mbuf **om)
* $api *
*****************************************************************************/
+void
+ble_l2cap_sm_heartbeat(void)
+{
+ struct ble_fsm_proc_list exp_list;
+ struct ble_l2cap_sm_proc *proc;
+ struct ble_fsm_proc *fsm_proc;
+
+ /* Remove all timed out procedures and insert them into a temporary
+ * list.
+ */
+ ble_fsm_proc_extract_list(&ble_l2cap_sm_fsm, &exp_list,
+ ble_l2cap_sm_proc_extract_expired_cb, NULL);
+
+ /* Notify application of each failure and free the corresponding procedure
+ * objects.
+ */
+ while ((fsm_proc = STAILQ_FIRST(&exp_list)) != NULL) {
+ proc = (struct ble_l2cap_sm_proc *)fsm_proc;
+ ble_l2cap_sm_gap_event(proc, BLE_HS_ETIMEOUT, 0);
+
+ STAILQ_REMOVE_HEAD(&exp_list, next);
+ ble_l2cap_sm_proc_free(&proc->fsm_proc);
+ }
+}
+
int
ble_l2cap_sm_initiate(uint16_t conn_handle)
{
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e099aa6/net/nimble/host/src/ble_l2cap_sm.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sm.h b/net/nimble/host/src/ble_l2cap_sm.h
index b1328aa..f2dc776 100644
--- a/net/nimble/host/src/ble_l2cap_sm.h
+++ b/net/nimble/host/src/ble_l2cap_sm.h
@@ -129,6 +129,7 @@ int ble_l2cap_sm_alg_c1(uint8_t *k, uint8_t *r,
void ble_l2cap_sm_rx_encryption_change(struct hci_encrypt_change *evt);
int ble_l2cap_sm_rx_lt_key_req(struct hci_le_lt_key_req *evt);
+void ble_l2cap_sm_heartbeat(void);
int ble_l2cap_sm_initiate(uint16_t conn_handle);
void ble_l2cap_sm_wakeup(void);
int ble_l2cap_sm_init(void);
@@ -156,6 +157,7 @@ int ble_l2cap_sm_init(void);
#define ble_l2cap_sm_rx_encryption_change(evt) ((void)(evt))
#define ble_l2cap_sm_rx_lt_key_req(evt) ((void)(evt))
+#define ble_l2cap_sm_heartbeat()
#define ble_l2cap_sm_wakeup()
#define ble_l2cap_sm_init() 0