Skip to content

Commit

Permalink
lib: lte_link_control: Skip parsing of unexpected %NCELLMEAS notif
Browse files Browse the repository at this point in the history
Added check to skip %NCELLMEAS notification parsing when neighbor
cell measurement has not been requested by calling
lte_lc_neighbor_cell_measurement(). If the neighbor cell measurement
is triggered by sending the AT%NCELLMEAS AT command to the modem,
LTE LC does not know how the received notification should be parsed,
sometimes leading to a parsing error.

Signed-off-by: Tommi Kangas <tommi.kangas@nordicsemi.no>
  • Loading branch information
tokangas committed Jan 3, 2025
1 parent 9abba20 commit 1abc0fd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
30 changes: 29 additions & 1 deletion lib/lte_link_control/modules/ncellmeas.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,13 @@ static void at_handler_ncellmeas(const char *response)
goto exit;
}

if (k_sem_count_get(&ncellmeas_idle_sem) > 0) {
/* No need to parse the notification because neighbor cell measurement
* has not been requested.
*/
goto exit;
}

if (ncellmeas_params.search_type > LTE_LC_NEIGHBOR_SEARCH_TYPE_EXTENDED_COMPLETE) {
at_handler_ncellmeas_gci(response);
goto exit;
Expand Down Expand Up @@ -783,6 +790,23 @@ int ncellmeas_start(struct lte_lc_ncellmeas_params *params)
return err;
}

static void ncellmeas_cancel_timeout_work_fn(struct k_work *work)
{
struct lte_lc_evt evt = {0};

if (k_sem_count_get(&ncellmeas_idle_sem) == 0) {
LOG_WRN("No %%NCELLMEAS notification received after stop, sending empty results");

evt.type = LTE_LC_EVT_NEIGHBOR_CELL_MEAS;
evt.cells_info.current_cell.id = LTE_LC_CELL_EUTRAN_ID_INVALID;
event_handler_list_dispatch(&evt);

k_sem_give(&ncellmeas_idle_sem);
}
}

K_WORK_DELAYABLE_DEFINE(ncellmeas_cancel_timeout_work, ncellmeas_cancel_timeout_work_fn);

int ncellmeas_cancel(void)
{
LOG_DBG("Cancelling");
Expand All @@ -793,7 +817,11 @@ int ncellmeas_cancel(void)
err = -EFAULT;
}

k_sem_give(&ncellmeas_idle_sem);
/* Transition to idle happens when %NCELLMEAS notification is received. However, if modem
* had not yet started the measurement, no notification is sent and we need a timeout to
* handle it.
*/
k_work_schedule(&ncellmeas_cancel_timeout_work, K_SECONDS(1));

return err;
}
4 changes: 3 additions & 1 deletion tests/lib/location/src/location_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,9 @@ void test_location_cellular_cancel_during_ncellmeas(void)

err = location_request_cancel();
TEST_ASSERT_EQUAL(0, err);
k_sleep(K_MSEC(1));

/* Need to wait a bit because no %NCELLMEAS notification is sent after AT%NCELLMEASSTOP. */
k_sleep(K_SECONDS(2));
}

/* Test cellular timeout during the 1st NCELLMEAS. */
Expand Down

0 comments on commit 1abc0fd

Please sign in to comment.