From 5a5493d70f1684b27ca83dfac266d6a7008937b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Tue, 22 Dec 2020 11:13:55 +0100 Subject: [PATCH] mesh: Fix friendship counter increasing order For Bluetooth Mesh, counter shall be increasing by one when every try to establishing friendship. Counter to be used when create friendship security material. So this value shall be consist between friend and lpn. Due to zephyr bluetooth mesh send previous counter, after that it will automatically increase one, which will result in the incorrect generation of friend key when key rephase. this is port of f8022fa01265deb72259f38dfcd8dfcf54c415ca --- nimble/host/mesh/src/friend.c | 3 +-- nimble/host/mesh/src/lpn.c | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nimble/host/mesh/src/friend.c b/nimble/host/mesh/src/friend.c index 6371b5cd2..9a83c87fc 100644 --- a/nimble/host/mesh/src/friend.c +++ b/nimble/host/mesh/src/friend.c @@ -173,6 +173,7 @@ static void friend_clear(struct bt_mesh_friend *frnd) seg->seg_count = 0U; } + frnd->counter++; frnd->subnet = NULL; frnd->established = 0; frnd->pending_buf = 0; @@ -884,8 +885,6 @@ static void enqueue_offer(struct bt_mesh_friend *frnd, int8_t rssi) goto done; } - frnd->counter++; - if (frnd->last) { net_buf_unref(frnd->last); } diff --git a/nimble/host/mesh/src/lpn.c b/nimble/host/mesh/src/lpn.c index 3b9e214f5..bd48c0883 100644 --- a/nimble/host/mesh/src/lpn.c +++ b/nimble/host/mesh/src/lpn.c @@ -293,6 +293,9 @@ static int send_friend_req(struct bt_mesh_lpn *lpn) .src = bt_mesh_primary_addr(), .xmit = POLL_XMIT, }; + + lpn->lpn_counter++; + struct bt_mesh_ctl_friend_req req = { .criteria = LPN_CRITERIA, .recv_delay = LPN_RECV_DELAY, @@ -556,8 +559,6 @@ int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx, return err; } - lpn->lpn_counter++; - return 0; }