This is an automated email from the ASF dual-hosted git repository. naraj pushed a commit to branch revert-958-mesh_sync_march21 in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 5b28681369c20395304b9792be52801bc92cc908 Author: MichaĆ Narajowski <[email protected]> AuthorDate: Thu May 27 10:20:19 2021 +0200 Revert "mesh: Sync lpn.c with Zephyr" This reverts commit 8fe37356da9ab934dcf55c7759cb26e595ffefe6. --- nimble/host/mesh/src/lpn.c | 76 +++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/nimble/host/mesh/src/lpn.c b/nimble/host/mesh/src/lpn.c index 45c9004..bd48c08 100644 --- a/nimble/host/mesh/src/lpn.c +++ b/nimble/host/mesh/src/lpn.c @@ -148,24 +148,6 @@ static inline void group_clear(atomic_t *target, atomic_t *source) static void clear_friendship(bool force, bool disable); -static int32_t poll_timeout(struct bt_mesh_lpn *lpn) -{ - /* If we're waiting for segment acks keep polling at high freq */ - if (bt_mesh_tx_in_progress()) { - return min(POLL_TIMEOUT_MAX(lpn), K_SECONDS(1)); - } - - if (lpn->poll_timeout < POLL_TIMEOUT_MAX(lpn)) { - lpn->poll_timeout *= 2; - lpn->poll_timeout = min(lpn->poll_timeout, - POLL_TIMEOUT_MAX(lpn)); - } - - BT_DBG("Poll Timeout is %ums", (unsigned) lpn->poll_timeout); - - return lpn->poll_timeout; -} - static void friend_clear_sent(int err, void *user_data) { struct bt_mesh_lpn *lpn = &bt_mesh.lpn; @@ -229,7 +211,6 @@ static void clear_friendship(bool force, bool disable) bt_mesh_rx_reset(); - lpn_set_state(BT_MESH_LPN_DISABLED); k_delayed_work_cancel(&lpn->timer); if (lpn->clear_success) { @@ -248,7 +229,7 @@ static void clear_friendship(bool force, bool disable) lpn->recv_win = 0; lpn->queue_size = 0; lpn->disable = 0; - lpn->sent_req = 0U; + lpn->sent_req = 0; lpn->established = 0; lpn->clear_success = 0; lpn->sub = NULL; @@ -265,12 +246,13 @@ static void clear_friendship(bool force, bool disable) bt_mesh_hb_feature_changed(BT_MESH_FEAT_LOW_POWER); - if (!disable) { + if (disable) { lpn_set_state(BT_MESH_LPN_DISABLED); - k_delayed_work_submit(&lpn->timer, FRIEND_REQ_RETRY_TIMEOUT); return; } + lpn_set_state(BT_MESH_LPN_ENABLED); + k_delayed_work_submit(&lpn->timer, FRIEND_REQ_RETRY_TIMEOUT); } static void friend_req_sent(uint16_t duration, int err, void *user_data) @@ -349,7 +331,7 @@ static void req_sent(uint16_t duration, int err, void *user_data) if (err) { BT_ERR("Sending request failed (err %d)", err); - lpn->sent_req = 0U; + lpn->sent_req = 0; group_zero(lpn->pending); return; } @@ -477,14 +459,11 @@ static void friend_response_received(struct bt_mesh_lpn *lpn) lpn->fsn++; } + k_delayed_work_cancel(&lpn->timer); bt_mesh_scan_disable(); lpn_set_state(BT_MESH_LPN_ESTABLISHED); lpn->req_attempts = 0; - lpn->sent_req = 0U; - - int32_t timeout = poll_timeout(lpn); - - k_delayed_work_submit(&lpn->timer, K_MSEC(timeout)); + lpn->sent_req = 0; } void bt_mesh_lpn_msg_received(struct bt_mesh_net_rx *rx) @@ -497,10 +476,6 @@ void bt_mesh_lpn_msg_received(struct bt_mesh_net_rx *rx) return; } - if (lpn->state != BT_MESH_LPN_WAIT_UPDATE) { - return; - } - if (lpn->sent_req != TRANS_CTL_OP_FRIEND_POLL) { BT_WARN("Unexpected message withouth a preceding Poll"); return; @@ -570,6 +545,7 @@ int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx, } } /* TODO: Add offer acceptance criteria check */ + k_delayed_work_cancel(&lpn->timer); lpn->recv_win = msg->recv_win; lpn->queue_size = msg->queue_size; @@ -762,7 +738,7 @@ static void update_timeout(struct bt_mesh_lpn *lpn) if (lpn->req_attempts < REQ_ATTEMPTS(lpn)) { BT_WARN("Retrying first Friend Poll"); - lpn->sent_req = 0U; + lpn->sent_req = 0; if (send_friend_poll() == 0) { return; } @@ -817,7 +793,7 @@ static void lpn_timeout(struct ble_npl_event *work) if (lpn->req_attempts < REQ_ATTEMPTS(lpn)) { uint8_t req = lpn->sent_req; - lpn->sent_req = 0U; + lpn->sent_req = 0; if (!req || req == TRANS_CTL_OP_FRIEND_POLL) { send_friend_poll(); @@ -880,6 +856,24 @@ void bt_mesh_lpn_group_del(uint16_t *groups, size_t group_count) sub_update(TRANS_CTL_OP_FRIEND_SUB_REM); } +static int32_t poll_timeout(struct bt_mesh_lpn *lpn) +{ + /* If we're waiting for segment acks keep polling at high freq */ + if (bt_mesh_tx_in_progress()) { + return min(POLL_TIMEOUT_MAX(lpn), K_SECONDS(1)); + } + + if (lpn->poll_timeout < POLL_TIMEOUT_MAX(lpn)) { + lpn->poll_timeout *= 2; + lpn->poll_timeout = min(lpn->poll_timeout, + POLL_TIMEOUT_MAX(lpn)); + } + + BT_DBG("Poll Timeout is %ums", (unsigned) lpn->poll_timeout); + + return lpn->poll_timeout; +} + int bt_mesh_lpn_friend_sub_cfm(struct bt_mesh_net_rx *rx, struct os_mbuf *buf) { @@ -938,6 +932,12 @@ int bt_mesh_lpn_friend_sub_cfm(struct bt_mesh_net_rx *rx, send_friend_poll(); } + if (!lpn->sent_req) { + int32_t timeout = poll_timeout(lpn); + + k_delayed_work_submit(&lpn->timer, K_MSEC(timeout)); + } + return 0; } @@ -1020,6 +1020,12 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx, send_friend_poll(); } + if (!lpn->sent_req) { + int32_t timeout = poll_timeout(lpn); + + k_delayed_work_submit(&lpn->timer, K_MSEC(timeout)); + } + return 0; } @@ -1067,6 +1073,8 @@ int bt_mesh_lpn_init(void) BT_DBG(""); + lpn->groups_changed = 0; + k_delayed_work_init(&lpn->timer, lpn_timeout); if (lpn->state == BT_MESH_LPN_ENABLED) {
