diff --git a/subsys/bluetooth/mesh/lpn.c b/subsys/bluetooth/mesh/lpn.c index 0d14c9c55e5..a7e48e841d1 100644 --- a/subsys/bluetooth/mesh/lpn.c +++ b/subsys/bluetooth/mesh/lpn.c @@ -296,11 +296,11 @@ static void clear_friendship(bool force, bool disable) if (!disable) { lpn_set_state(BT_MESH_LPN_ENABLED); + k_work_reschedule(&lpn->timer, FRIEND_REQ_RETRY_TIMEOUT); + if (!IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) { bt_mesh_scan_enable(); } - - k_work_reschedule(&lpn->timer, FRIEND_REQ_RETRY_TIMEOUT); } if (was_established) { @@ -570,7 +570,6 @@ static void friend_response_received(struct bt_mesh_lpn *lpn) lpn->fsn++; } - bt_mesh_scan_disable(); lpn_set_state(BT_MESH_LPN_ESTABLISHED); lpn->req_attempts = 0U; lpn->sent_req = 0U; @@ -581,6 +580,7 @@ static void friend_response_received(struct bt_mesh_lpn *lpn) int32_t timeout = poll_timeout(lpn); k_work_reschedule(&lpn->timer, K_MSEC(timeout)); + bt_mesh_scan_disable(); } void bt_mesh_lpn_msg_received(struct bt_mesh_net_rx *rx) @@ -857,9 +857,9 @@ static void update_timeout(struct bt_mesh_lpn *lpn) { if (lpn->established) { LOG_WRN("No response from Friend during ReceiveWindow"); - bt_mesh_scan_disable(); lpn_set_state(BT_MESH_LPN_ESTABLISHED); k_work_reschedule(&lpn->timer, K_MSEC(POLL_RETRY_TIMEOUT)); + bt_mesh_scan_disable(); } else { if (IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) { bt_mesh_scan_disable(); @@ -903,19 +903,19 @@ static void lpn_timeout(struct k_work *work) send_friend_req(lpn); break; case BT_MESH_LPN_REQ_WAIT: - bt_mesh_scan_enable(); k_work_reschedule(&lpn->timer, K_MSEC(lpn->adv_duration + FRIEND_REQ_SCAN)); lpn_set_state(BT_MESH_LPN_WAIT_OFFER); + bt_mesh_scan_enable(); break; case BT_MESH_LPN_WAIT_OFFER: LOG_WRN("No acceptable Friend Offers received"); - if (IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) { - bt_mesh_scan_disable(); - } - lpn_set_state(BT_MESH_LPN_ENABLED); lpn->sent_req = 0U; k_work_reschedule(&lpn->timer, FRIEND_REQ_RETRY_TIMEOUT); + + if (IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) { + bt_mesh_scan_disable(); + } break; case BT_MESH_LPN_ESTABLISHED: if (lpn->req_attempts < REQ_ATTEMPTS(lpn)) { @@ -939,8 +939,8 @@ static void lpn_timeout(struct k_work *work) case BT_MESH_LPN_RECV_DELAY: k_work_reschedule(&lpn->timer, K_MSEC(SCAN_LATENCY + lpn->recv_win + RX_DELAY_CORRECTION(lpn))); - bt_mesh_scan_enable(); lpn_set_state(BT_MESH_LPN_WAIT_UPDATE); + bt_mesh_scan_enable(); break; case BT_MESH_LPN_WAIT_UPDATE: update_timeout(lpn);