Skip to content

Commit 6c4a344

Browse files
tokangasnordicjm
authored andcommitted
lib: lte_link_control: Fix missing eDRX events with non-NTN firmware
The library tried to always configure eDRX also for NTN NB-IoT. This causes an error with non-NTN modem firmware, which also causes the +CEDRXS notification subscription to be removed. To mitigate this, the order in which eDRX is configured for access technologies has been changed. This commit also adds checking of the modem firmware type, so that configuring eDRX for NTN NB-IoT is skipped when non-NTN firmware is detected. Signed-off-by: Tommi Kangas <[email protected]>
1 parent 0538930 commit 6c4a344

File tree

7 files changed

+215
-23
lines changed

7 files changed

+215
-23
lines changed

lib/lte_link_control/common/helpers.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,40 @@
77
#include <stdlib.h>
88
#include <zephyr/logging/log.h>
99

10+
#include <modem/nrf_modem_lib.h>
11+
#include <nrf_modem_at.h>
12+
1013
#include <common/helpers.h>
1114

1215
LOG_MODULE_DECLARE(lte_lc, CONFIG_LTE_LINK_CONTROL_LOG_LEVEL);
1316

17+
static enum mfw_type mfw_type = MFW_TYPE_UNKNOWN;
18+
19+
void mfw_type_init(void)
20+
{
21+
int err;
22+
char buf[64];
23+
24+
err = nrf_modem_at_cmd(buf, sizeof(buf), "AT+CGMR");
25+
if (err) {
26+
LOG_ERR("Failed to get modem firmware type, error: %d", err);
27+
return;
28+
}
29+
30+
if (strstr(buf, "nrf9160_") != NULL) {
31+
mfw_type = MFW_TYPE_NRF9160;
32+
} else if (strstr(buf, "nrf91x1_") != NULL) {
33+
mfw_type = MFW_TYPE_NRF91X1;
34+
} else if (strstr(buf, "nrf9151-ntn_") != NULL) {
35+
mfw_type = MFW_TYPE_NRF9151_NTN;
36+
}
37+
}
38+
39+
enum mfw_type mfw_type_get(void)
40+
{
41+
return mfw_type;
42+
}
43+
1444
int string_to_int(const char *str_buf, int base, int *output)
1545
{
1646
int temp;

lib/lte_link_control/common/work_q.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static struct k_work_q work_q;
1515
void work_q_start(void)
1616
{
1717
struct k_work_queue_config cfg = {
18-
.name = "work_q",
18+
.name = "lte_lc_work_q",
1919
};
2020

2121
k_work_queue_start(&work_q, work_q_stack, K_THREAD_STACK_SIZEOF(work_q_stack),

lib/lte_link_control/include/common/helpers.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
extern "C" {
1818
#endif
1919

20+
enum mfw_type {
21+
MFW_TYPE_UNKNOWN,
22+
MFW_TYPE_NRF9160,
23+
MFW_TYPE_NRF91X1,
24+
MFW_TYPE_NRF9151_NTN
25+
};
26+
27+
/* Initialize the modem firmware type (read it from the modem). */
28+
void mfw_type_init(void);
29+
30+
/* Get the modem firmware type. */
31+
enum mfw_type mfw_type_get(void);
32+
2033
/* Converts integer as string to integer type. */
2134
int string_to_int(const char *str_buf, int base, int *output);
2235

lib/lte_link_control/lte_lc_modem_hooks.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "modules/rai.h"
1313
#include "modules/dns.h"
14+
#include "common/helpers.h"
1415

1516
LOG_MODULE_DECLARE(lte_lc, CONFIG_LTE_LINK_CONTROL_LOG_LEVEL);
1617

@@ -30,6 +31,8 @@ static void on_modem_init(int err, void *ctx)
3031
return;
3132
}
3233

34+
mfw_type_init();
35+
3336
if (!IS_ENABLED(CONFIG_LTE_NETWORK_MODE_DEFAULT)) {
3437
err = lte_lc_system_mode_set(lte_lc_sys_mode, lte_lc_sys_mode_pref);
3538
if (err) {

lib/lte_link_control/modules/edrx.c

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <nrf_modem_at.h>
1717

1818
#include "common/work_q.h"
19+
#include "common/helpers.h"
1920
#include "common/event_handler_list.h"
2021
#include "modules/edrx.h"
2122

@@ -96,10 +97,21 @@ static void lte_lc_edrx_values_store(enum lte_lc_lte_mode mode, char *edrx_value
9697
static void edrx_ptw_send_work_fn(struct k_work *work_item)
9798
{
9899
int err;
99-
int actt[] = {AT_CEDRXS_ACTT_WB, AT_CEDRXS_ACTT_NB, AT_CEDRXS_ACTT_NTN_NB};
100+
int actt[3];
101+
uint8_t actt_count = 0;
102+
enum mfw_type mfw_type = mfw_type_get();
100103

101-
/* Apply the configurations for LTE-M, NB-IoT and NTN NB-IoT. */
102-
for (size_t i = 0; i < ARRAY_SIZE(actt); i++) {
104+
if (mfw_type == MFW_TYPE_NRF9151_NTN || mfw_type == MFW_TYPE_UNKNOWN) {
105+
actt[actt_count] = AT_CEDRXS_ACTT_NTN_NB;
106+
actt_count++;
107+
}
108+
actt[actt_count] = AT_CEDRXS_ACTT_WB;
109+
actt_count++;
110+
actt[actt_count] = AT_CEDRXS_ACTT_NB;
111+
actt_count++;
112+
113+
/* Apply the configurations. */
114+
for (size_t i = 0; i < actt_count; i++) {
103115
char *requested_ptw_value =
104116
(actt[i] == AT_CEDRXS_ACTT_WB) ? requested_ptw_value_ltem :
105117
(actt[i] == AT_CEDRXS_ACTT_NB) ? requested_ptw_value_nbiot :
@@ -114,10 +126,7 @@ static void edrx_ptw_send_work_fn(struct k_work *work_item)
114126

115127
err = nrf_modem_at_printf("AT%%XPTW=%d,\"%s\"", actt[i],
116128
requested_ptw_value);
117-
/* Setting PTW for NTN NB-IoT causes an error with non-NTN firmwares, so
118-
* silently ignore errors for it.
119-
*/
120-
if (err && actt[i] != AT_CEDRXS_ACTT_NTN_NB) {
129+
if (err) {
121130
LOG_ERR("Failed to request PTW, reported error: %d", err);
122131
}
123132
}
@@ -413,7 +422,22 @@ int edrx_ptw_set(enum lte_lc_lte_mode mode, const char *ptw)
413422
int edrx_request(bool enable)
414423
{
415424
int err = 0;
416-
int actt[] = {AT_CEDRXS_ACTT_WB, AT_CEDRXS_ACTT_NB, AT_CEDRXS_ACTT_NTN_NB};
425+
int actt[3];
426+
uint8_t actt_count = 0;
427+
enum mfw_type mfw_type = mfw_type_get();
428+
429+
/* Try to configure for NTN NB-IoT first, because a failing +CEDRXS command removes
430+
* the +CEDRXS notification subscription. eDRX is configured for NTN NB-IoT only when
431+
* when modem firmware has NTN support or when firmware type can not be determined.
432+
*/
433+
if (mfw_type == MFW_TYPE_NRF9151_NTN || mfw_type == MFW_TYPE_UNKNOWN) {
434+
actt[actt_count] = AT_CEDRXS_ACTT_NTN_NB;
435+
actt_count++;
436+
}
437+
actt[actt_count] = AT_CEDRXS_ACTT_WB;
438+
actt_count++;
439+
actt[actt_count] = AT_CEDRXS_ACTT_NB;
440+
actt_count++;
417441

418442
LOG_DBG("enable=%d, "
419443
"requested_edrx_value_ltem=%s, edrx_value_ltem=%s, "
@@ -444,8 +468,8 @@ int edrx_request(bool enable)
444468
return 0;
445469
}
446470

447-
/* Apply the configurations for LTE-M, NB-IoT and NTN NB-IoT. */
448-
for (size_t i = 0; i < ARRAY_SIZE(actt); i++) {
471+
/* Apply the configurations. */
472+
for (size_t i = 0; i < actt_count; i++) {
449473
char *requested_edrx_value =
450474
(actt[i] == AT_CEDRXS_ACTT_WB) ? requested_edrx_value_ltem :
451475
(actt[i] == AT_CEDRXS_ACTT_NB) ? requested_edrx_value_nbiot :
@@ -467,10 +491,7 @@ int edrx_request(bool enable)
467491
err = nrf_modem_at_printf("AT+CEDRXS=2,%d", actt[i]);
468492
}
469493

470-
/* Setting eDRX for NTN NB-IoT causes an error with non-NTN firmwares, so
471-
* silently ignore errors for it.
472-
*/
473-
if (err && actt[i] != AT_CEDRXS_ACTT_NTN_NB) {
494+
if (err) {
474495
LOG_ERR("Failed to enable eDRX, reported error: %d", err);
475496
return -EFAULT;
476497
}

samples/cellular/modem_shell/src/link/link.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ void link_ind_handler(const struct lte_lc_evt *const evt)
432432

433433
len = snprintf(
434434
log_buf, sizeof(log_buf),
435-
"eDRX parameter update: eDRX: %f, PTW: %f",
435+
"eDRX parameter update: eDRX: %.2f, PTW: %.2f",
436436
(double)evt->edrx_cfg.edrx, (double)evt->edrx_cfg.ptw);
437437
if (len > 0) {
438438
mosh_print("%s", log_buf);

0 commit comments

Comments
 (0)