Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions applied_patches/official-merged/nimble#730.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 3cbef1a615a4d739c5bface245f827be2026a7b3 Mon Sep 17 00:00:00 2001
From: Andrzej Kaczmarek <[email protected]>
Date: Mon, 13 Jan 2020 22:59:17 +0100
Subject: [PATCH] nimble/host: Fix setting connection flags after pairing

---
nimble/host/src/ble_sm.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/nimble/host/src/ble_sm.c b/src/nimble/host/src/ble_sm.c
index e2315fb0f..cfd80fcbd 100644
--- a/src/nimble/host/src/ble_sm.c
+++ b/src/nimble/host/src/ble_sm.c
@@ -2015,7 +2015,10 @@ ble_sm_key_exch_success(struct ble_sm_proc *proc, struct ble_sm_result *res)
/* The procedure is now complete. Update connection bonded state and
* terminate procedure.
*/
- ble_sm_update_sec_state(proc->conn_handle, 1, 0, 1, proc->key_size);
+ ble_sm_update_sec_state(proc->conn_handle, 1,
+ !!(proc->flags & BLE_SM_PROC_F_AUTHENTICATED),
+ !!(proc->flags & BLE_SM_PROC_F_BONDING),
+ proc->key_size);
proc->state = BLE_SM_PROC_STATE_NONE;

res->app_status = 0;
130 changes: 130 additions & 0 deletions applied_patches/official-merged/nimble#790.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
From 9cb441213d9c56df44d97fb4eb121f0bb5146ee8 Mon Sep 17 00:00:00 2001
From: Prasad Alatkar <[email protected]>
Date: Fri, 3 Apr 2020 18:42:05 +0530
Subject: [PATCH 1/2] nimble/host: Fix return code in
`ble_gap_unpair_oldest_peer` when no bonded peer exist

---
nimble/host/src/ble_gap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/nimble/host/src/ble_gap.c b/src/nimble/host/src/ble_gap.c
index 4729dd02a..b44012d33 100644
--- a/src/nimble/host/src/ble_gap.c
+++ b/src/nimble/host/src/ble_gap.c
@@ -5594,7 +5594,7 @@ ble_gap_unpair_oldest_peer(void)
}

if (num_peers == 0) {
- return 0;
+ return BLE_HS_ENOENT;
}

rc = ble_gap_unpair(&oldest_peer_id_addr);

From bb9303ab2fa33dafdd152be5b31bc07eedf38c24 Mon Sep 17 00:00:00 2001
From: Prasad Alatkar <[email protected]>
Date: Wed, 1 Apr 2020 00:08:29 +0530
Subject: [PATCH 2/2] nimble/store: Fix store behavior when CCCDs exceed
maximum limit

- Add supporting API to skip input peer while unpairing oldest peer
---
nimble/host/include/host/ble_gap.h | 14 ++++++++++++++
nimble/host/src/ble_gap.c | 30 ++++++++++++++++++++++++++++++
nimble/host/src/ble_store_util.c | 16 +++++++++-------
3 files changed, 53 insertions(+), 7 deletions(-)

diff --git a/src/host/ble_gap.h b/src/host/ble_gap.h
index 20e7dab77..b58f350fb 100644
--- a/src/host/ble_gap.h
+++ b/src/host/ble_gap.h
@@ -1896,6 +1896,20 @@ int ble_gap_unpair(const ble_addr_t *peer_addr);
*/
int ble_gap_unpair_oldest_peer(void);

+/**
+ * Similar to `ble_gap_unpair_oldest_peer()`, except it makes sure that the
+ * peer received in input parameters is not deleted.
+ *
+ * @param peer_addr Address of the peer (not to be deleted)
+ *
+ * @return 0 on success;
+ * A BLE host HCI return code if the controller
+ * rejected the request;
+ * A BLE host core return code on unexpected
+ * error.
+ */
+int ble_gap_unpair_oldest_except(const ble_addr_t *peer_addr);
+
#define BLE_GAP_PRIVATE_MODE_NETWORK 0
#define BLE_GAP_PRIVATE_MODE_DEVICE 1

diff --git a/src/nimble/host/src/ble_gap.c b/src/nimble/host/src/ble_gap.c
index b44012d33..53c6bf308 100644
--- a/src/nimble/host/src/ble_gap.c
+++ b/src/nimble/host/src/ble_gap.c
@@ -5605,6 +5605,36 @@ ble_gap_unpair_oldest_peer(void)
return 0;
}

+int
+ble_gap_unpair_oldest_except(const ble_addr_t *peer_addr)
+{
+ ble_addr_t peer_id_addrs[MYNEWT_VAL(BLE_STORE_MAX_BONDS)];
+ int num_peers;
+ int rc, i;
+
+ rc = ble_store_util_bonded_peers(
+ &peer_id_addrs[0], &num_peers, MYNEWT_VAL(BLE_STORE_MAX_BONDS));
+ if (rc != 0) {
+ return rc;
+ }
+
+ if (num_peers == 0) {
+ return BLE_HS_ENOENT;
+ }
+
+ for (i = 0; i < num_peers; i++) {
+ if (ble_addr_cmp(peer_addr, &peer_id_addrs[i]) != 0) {
+ break;
+ }
+ }
+
+ if (i >= num_peers) {
+ return BLE_HS_ENOMEM;
+ }
+
+ return ble_gap_unpair(&peer_id_addrs[i]);
+}
+
void
ble_gap_passkey_event(uint16_t conn_handle,
struct ble_gap_passkey_params *passkey_params)
diff --git a/src/nimble/host/src/ble_store_util.c b/src/nimble/host/src/ble_store_util.c
index 444cc55d7..7de482721 100644
--- a/src/nimble/host/src/ble_store_util.c
+++ b/src/nimble/host/src/ble_store_util.c
@@ -233,13 +233,15 @@ ble_store_util_status_rr(struct ble_store_status_event *event, void *arg)
switch (event->event_code) {
case BLE_STORE_EVENT_OVERFLOW:
switch (event->overflow.obj_type) {
- case BLE_STORE_OBJ_TYPE_OUR_SEC:
- case BLE_STORE_OBJ_TYPE_PEER_SEC:
- case BLE_STORE_OBJ_TYPE_CCCD:
- return ble_gap_unpair_oldest_peer();
-
- default:
- return BLE_HS_EUNKNOWN;
+ case BLE_STORE_OBJ_TYPE_OUR_SEC:
+ case BLE_STORE_OBJ_TYPE_PEER_SEC:
+ return ble_gap_unpair_oldest_peer();
+ case BLE_STORE_OBJ_TYPE_CCCD:
+ /* Try unpairing oldest peer except current peer */
+ return ble_gap_unpair_oldest_except(&event->overflow.value->cccd.peer_addr);
+
+ default:
+ return BLE_HS_EUNKNOWN;
}

case BLE_STORE_EVENT_FULL:
153 changes: 153 additions & 0 deletions applied_patches/official-merged/nimble#802.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
From 87b23db462ac4ad6932b0c2d621bcb99cf4f1dfd Mon Sep 17 00:00:00 2001
From: h2zero <[email protected]>
Date: Sat, 18 Apr 2020 20:42:41 -0600
Subject: [PATCH] nimble/host: Add return parameter to the
ble_hs_misc_conn_chan_find_reqd()

ble_hs_misc_conn_chan_find_reqd() did not return an error code if
the connection and or the channel were not found, i.e in a disconnected state.
When debug is not enabled and `ble_hs_misc_conn_chan_find_reqd()` is called and
the device has disconnected from the peer various functions may attempt to access
memory that is not valid causing an null pointer exception.
---
nimble/host/src/ble_att_cmd.c | 7 +++----
nimble/host/src/ble_hs_misc.c | 8 ++++++--
nimble/host/src/ble_hs_priv.h | 6 +++---
nimble/host/src/ble_l2cap_sig.c | 9 +++++++--
nimble/host/src/ble_l2cap_sig_cmd.c | 8 +++++---
nimble/host/src/ble_sm_cmd.c | 11 ++++++++---
6 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/src/nimble/host/src/ble_att_cmd.c b/src/nimble/host/src/ble_att_cmd.c
index a123c857c..81b070f9c 100644
--- a/src/nimble/host/src/ble_att_cmd.c
+++ b/src/nimble/host/src/ble_att_cmd.c
@@ -66,11 +66,10 @@ ble_att_tx(uint16_t conn_handle, struct os_mbuf *txom)

ble_hs_lock();

- ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_ATT, &conn,
- &chan);
- if (chan == NULL) {
+ rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_ATT, &conn,
+ &chan);
+ if (rc != 0) {
os_mbuf_free_chain(txom);
- rc = BLE_HS_ENOTCONN;
} else {
ble_att_truncate_to_mtu(chan, txom);
rc = ble_l2cap_tx(conn, chan, txom);
diff --git a/src/nimble/host/src/ble_hs_misc.c b/src/nimble/host/src/ble_hs_misc.c
index 6c6da4675..dfb46b741 100644
--- a/src/nimble/host/src/ble_hs_misc.c
+++ b/src/nimble/host/src/ble_hs_misc.c
@@ -56,7 +56,7 @@ ble_hs_misc_conn_chan_find(uint16_t conn_handle, uint16_t cid,
return rc;
}

-void
+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)
@@ -66,7 +66,9 @@ 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_EVAL(rc == 0);
+ if (rc != 0) {
+ return rc;
+ }

if (out_conn != NULL) {
*out_conn = conn;
@@ -74,6 +76,8 @@ ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
if (out_chan != NULL) {
*out_chan = chan;
}
+
+ return 0;
}

uint8_t
diff --git a/src/nimble/host/src/ble_hs_priv.h b/src/nimble/host/src/ble_hs_priv.h
index 2cad6ef1d..538d07a97 100644
--- a/src/nimble/host/src/ble_hs_priv.h
+++ b/src/nimble/host/src/ble_hs_priv.h
@@ -114,9 +114,9 @@ int ble_hs_hci_evt_acl_process(struct os_mbuf *om);
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);
-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);
+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);
uint8_t ble_hs_misc_addr_type_to_id(uint8_t addr_type);
int ble_hs_misc_restore_irks(void);

diff --git a/src/nimble/host/src/ble_l2cap_sig.c b/src/nimble/host/src/ble_l2cap_sig.c
index bb4d8a5ac..58f96b0f3 100644
--- a/src/nimble/host/src/ble_l2cap_sig.c
+++ b/src/nimble/host/src/ble_l2cap_sig.c
@@ -508,8 +508,13 @@ ble_l2cap_sig_update(uint16_t conn_handle,
STATS_INC(ble_l2cap_stats, update_init);

ble_hs_lock();
- ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG,
- &conn, &chan);
+ rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG,
+ &conn, &chan);
+ if (rc != 0) {
+ ble_hs_unlock();
+ goto done;
+ }
+
master = conn->bhc_flags & BLE_HS_CONN_F_MASTER;
ble_hs_unlock();

diff --git a/src/nimble/host/src/ble_l2cap_sig_cmd.c b/src/nimble/host/src/ble_l2cap_sig_cmd.c
index 366dde625..510420f09 100644
--- a/src/nimble/host/src/ble_l2cap_sig_cmd.c
+++ b/src/nimble/host/src/ble_l2cap_sig_cmd.c
@@ -28,9 +28,11 @@ ble_l2cap_sig_tx(uint16_t conn_handle, struct os_mbuf *txom)
int rc;

ble_hs_lock();
- ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG,
- &conn, &chan);
- rc = ble_l2cap_tx(conn, chan, txom);
+ rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG,
+ &conn, &chan);
+ if (rc == 0) {
+ rc = ble_l2cap_tx(conn, chan, txom);
+ }
ble_hs_unlock();

return rc;
diff --git a/src/nimble/host/src/ble_sm_cmd.c b/src/nimble/host/src/ble_sm_cmd.c
index 5eef798d6..01651f1df 100644
--- a/src/nimble/host/src/ble_sm_cmd.c
+++ b/src/nimble/host/src/ble_sm_cmd.c
@@ -52,12 +52,17 @@ ble_sm_tx(uint16_t conn_handle, struct os_mbuf *txom)
{
struct ble_l2cap_chan *chan;
struct ble_hs_conn *conn;
+ int rc;

BLE_HS_DBG_ASSERT(ble_hs_locked_by_cur_task());

STATS_INC(ble_l2cap_stats, sm_tx);

- ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SM,
- &conn, &chan);
- return ble_l2cap_tx(conn, chan, txom);
+ rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SM,
+ &conn, &chan);
+ if (rc == 0) {
+ rc = ble_l2cap_tx(conn, chan, txom);
+ }
+
+ return rc;
}
Loading