Skip to content

Commit 64064df

Browse files
tokangasrlubos
authored andcommitted
lib: lte_link_control: fix %NCELLMEAS notification parsing
Added handling for %NCELLMEAS notification with status 2 (measurement interrupted), but no cells. NRF91-2269 Signed-off-by: Tommi Kangas <[email protected]>
1 parent 31d1fa5 commit 64064df

File tree

3 files changed

+90
-9
lines changed

3 files changed

+90
-9
lines changed

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@ Modem libraries
456456

457457
* Added the :c:func:`pdn_dynamic_params_get_v6` function to get PDN parameters for IPv6-only.
458458

459+
* :ref:`lte_lc_readme` library:
460+
461+
* Fixed handling of ``%NCELLMEAS`` notification with status 2 (measurement interrupted) and no cells.
462+
459463
Multiprotocol Service Layer libraries
460464
-------------------------------------
461465

lib/lte_link_control/modules/ncellmeas.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ static int parse_ncellmeas_gci(struct lte_lc_ncellmeas_params *params, const cha
167167
goto clean_exit;
168168
} else if (status == AT_NCELLMEAS_STATUS_VALUE_INCOMPLETE) {
169169
LOG_WRN("NCELLMEAS interrupted; results incomplete");
170+
if (param_count == 3) {
171+
/* No results, skip parsing. */
172+
goto clean_exit;
173+
}
170174
}
171175

172176
/* Go through the cells */
@@ -425,6 +429,14 @@ static int parse_ncellmeas(const char *at_response, struct lte_lc_cells_info *ce
425429
err = at_parser_init(&parser, at_response);
426430
__ASSERT_NO_MSG(err == 0);
427431

432+
err = at_parser_cmd_count_get(&parser, &count);
433+
if (err) {
434+
LOG_ERR("Could not get NCELLMEAS param count, "
435+
"potentially malformed notification, error: %d",
436+
err);
437+
goto clean_exit;
438+
}
439+
428440
/* Status code */
429441
err = at_parser_num_get(&parser, AT_NCELLMEAS_STATUS_INDEX, &status);
430442
if (err) {
@@ -437,6 +449,10 @@ static int parse_ncellmeas(const char *at_response, struct lte_lc_cells_info *ce
437449
goto clean_exit;
438450
} else if (status == AT_NCELLMEAS_STATUS_VALUE_INCOMPLETE) {
439451
LOG_WRN("NCELLMEAS interrupted; results incomplete");
452+
if (count == 2) {
453+
/* No results, skip parsing. */
454+
goto clean_exit;
455+
}
440456
}
441457

442458
/* Current cell ID */
@@ -518,14 +534,6 @@ static int parse_ncellmeas(const char *at_response, struct lte_lc_cells_info *ce
518534
size_t ta_meas_time_index = AT_NCELLMEAS_PRE_NCELLS_PARAMS_COUNT +
519535
cells->ncells_count * AT_NCELLMEAS_N_PARAMS_COUNT;
520536

521-
err = at_parser_cmd_count_get(&parser, &count);
522-
if (err) {
523-
LOG_ERR("Could not get NCELLMEAS param count, "
524-
"potentially malformed notification, error: %d",
525-
err);
526-
goto clean_exit;
527-
}
528-
529537
if (count > ta_meas_time_index) {
530538
err = at_parser_num_get(&parser, ta_meas_time_index,
531539
&cells->current_cell.timing_advance_meas_time);

tests/lib/lte_lc_api/src/lte_lc_api_test.c

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,41 @@ void test_lte_lc_neighbor_cell_measurement_normal_status_incomplete(void)
26912691
at_monitor_dispatch(at_notif);
26922692
}
26932693

2694+
void test_lte_lc_neighbor_cell_measurement_normal_status_incomplete_no_cells(void)
2695+
{
2696+
int ret;
2697+
struct lte_lc_ncellmeas_params params = {
2698+
.search_type = LTE_LC_NEIGHBOR_SEARCH_TYPE_DEFAULT,
2699+
.gci_count = 0,
2700+
};
2701+
strcpy(at_notif,
2702+
"%NCELLMEAS: 2\r\n");
2703+
2704+
lte_lc_callback_count_expected = 1;
2705+
2706+
__mock_nrf_modem_at_printf_ExpectAndReturn("AT%NCELLMEAS", EXIT_SUCCESS);
2707+
2708+
ret = lte_lc_neighbor_cell_measurement(&params);
2709+
TEST_ASSERT_EQUAL(EXIT_SUCCESS, ret);
2710+
2711+
test_event_data[0].type = LTE_LC_EVT_NEIGHBOR_CELL_MEAS;
2712+
test_event_data[0].cells_info.current_cell.mcc = 0;
2713+
test_event_data[0].cells_info.current_cell.mnc = 0;
2714+
test_event_data[0].cells_info.current_cell.id = LTE_LC_CELL_EUTRAN_ID_INVALID;
2715+
test_event_data[0].cells_info.current_cell.tac = 0;
2716+
test_event_data[0].cells_info.current_cell.earfcn = 0;
2717+
test_event_data[0].cells_info.current_cell.timing_advance = 0;
2718+
test_event_data[0].cells_info.current_cell.timing_advance_meas_time = 0;
2719+
test_event_data[0].cells_info.current_cell.measurement_time = 0;
2720+
test_event_data[0].cells_info.current_cell.phys_cell_id = 0;
2721+
test_event_data[0].cells_info.current_cell.rsrp = 0;
2722+
test_event_data[0].cells_info.current_cell.rsrq = 0;
2723+
test_event_data[0].cells_info.ncells_count = 0;
2724+
test_event_data[0].cells_info.gci_cells_count = 0;
2725+
2726+
at_monitor_dispatch(at_notif);
2727+
}
2728+
26942729
void test_lte_lc_neighbor_cell_measurement_cell_id_missing_fail(void)
26952730
{
26962731
int ret;
@@ -2955,6 +2990,41 @@ void test_lte_lc_neighbor_cell_measurement_gci_status_incomplete(void)
29552990
at_monitor_dispatch(at_notif);
29562991
}
29572992

2993+
void test_lte_lc_neighbor_cell_measurement_gci_status_incomplete_no_cells(void)
2994+
{
2995+
int ret;
2996+
struct lte_lc_ncellmeas_params params = {
2997+
.search_type = LTE_LC_NEIGHBOR_SEARCH_TYPE_GCI_DEFAULT,
2998+
.gci_count = 2,
2999+
};
3000+
strcpy(at_notif,
3001+
"%NCELLMEAS: 2\r\n");
3002+
3003+
lte_lc_callback_count_expected = 1;
3004+
3005+
__mock_nrf_modem_at_printf_ExpectAndReturn("AT%NCELLMEAS=3,2", EXIT_SUCCESS);
3006+
3007+
ret = lte_lc_neighbor_cell_measurement(&params);
3008+
TEST_ASSERT_EQUAL(EXIT_SUCCESS, ret);
3009+
3010+
test_event_data[0].type = LTE_LC_EVT_NEIGHBOR_CELL_MEAS;
3011+
test_event_data[0].cells_info.current_cell.mcc = 0;
3012+
test_event_data[0].cells_info.current_cell.mnc = 0;
3013+
test_event_data[0].cells_info.current_cell.id = LTE_LC_CELL_EUTRAN_ID_INVALID;
3014+
test_event_data[0].cells_info.current_cell.tac = 0;
3015+
test_event_data[0].cells_info.current_cell.earfcn = 0;
3016+
test_event_data[0].cells_info.current_cell.timing_advance = 0;
3017+
test_event_data[0].cells_info.current_cell.timing_advance_meas_time = 0;
3018+
test_event_data[0].cells_info.current_cell.measurement_time = 0;
3019+
test_event_data[0].cells_info.current_cell.phys_cell_id = 0;
3020+
test_event_data[0].cells_info.current_cell.rsrp = 0;
3021+
test_event_data[0].cells_info.current_cell.rsrq = 0;
3022+
test_event_data[0].cells_info.ncells_count = 0;
3023+
test_event_data[0].cells_info.gci_cells_count = 0;
3024+
3025+
at_monitor_dispatch(at_notif);
3026+
}
3027+
29583028
void test_lte_lc_neighbor_cell_measurement_gci_max_length(void)
29593029
{
29603030
int ret;
@@ -3775,7 +3845,6 @@ void test_lte_lc_neighbor_cell_measurement_no_event_handler(void)
37753845
lte_lc_register_handler(lte_lc_event_handler);
37763846
}
37773847

3778-
37793848
void test_lte_lc_modem_sleep_event(void)
37803849
{
37813850
lte_lc_callback_count_expected = 6;

0 commit comments

Comments
 (0)