From 6de5b79f9c11daf3373e565beae9f5fd033ac1ba Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 20 Aug 2019 17:23:33 +0300 Subject: [PATCH] Bluetooth: Mesh: Fix discarding messages with many segments The code for checking space in the Friend queue was faulty in the case that we receive a message with more segments than the configured Friend Queue size. This is not an issue for the default configuration but still a possible one. Move the check for exceeding Friend Queue Size to the per-LPN function, so that bt_mesh_friend_queue_has_space() iterates all LPNs before delivering its verdict. This allows us to return success in case no LPN matched (which is how the code was intended to work). Fixes #18522 Signed-off-by: Johan Hedberg --- subsys/bluetooth/mesh/friend.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/mesh/friend.c b/subsys/bluetooth/mesh/friend.c index 330287efcc0..88a5991446f 100644 --- a/subsys/bluetooth/mesh/friend.c +++ b/subsys/bluetooth/mesh/friend.c @@ -1226,6 +1226,10 @@ static bool friend_queue_has_space(struct bt_mesh_friend *frnd, u16_t addr, u32_t total = 0; int i; + if (seg_count > CONFIG_BT_MESH_FRIEND_QUEUE_SIZE) { + return false; + } + for (i = 0; i < ARRAY_SIZE(frnd->seg); i++) { struct bt_mesh_friend_seg *seg = &frnd->seg[i]; @@ -1259,10 +1263,6 @@ bool bt_mesh_friend_queue_has_space(u16_t net_idx, u16_t src, u16_t dst, bool someone_has_space = false, friend_match = false; int i; - if (seg_count > CONFIG_BT_MESH_FRIEND_QUEUE_SIZE) { - return false; - } - for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) { struct bt_mesh_friend *frnd = &bt_mesh.frnd[i];