Skip to content

Commit da1cff1

Browse files
tokangasnordicjm
authored andcommitted
lib: lte_link_control: Apply missing settings after +CFUN=0
Band lock, RAI notification subscription and DNS fallback address were not applied after modem was put into minimal functionality mode (AT+CFUN=0). Those settings are not stored into NVM by the modem and the settings need to be applied again. Corrected the comments for PLMN lock in on_modem_init(). That setting is not volatile, but it is saved into NVM by the modem. Changed on_modem_init() callback to always continue execution in case setting a configuration to modem fails. Earlier some of the configurations caused the function to exit, while some did not. The callback does not return any value, so it does its best and tries to configure everything. Possible failures are logged. Jira: NRF91-2680 Signed-off-by: Tommi Kangas <[email protected]>
1 parent e27c2df commit da1cff1

File tree

7 files changed

+126
-133
lines changed

7 files changed

+126
-133
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,8 @@ Modem libraries
809809
* The order of the ``LTE_LC_MODEM_EVT_SEARCH_DONE`` modem event, and registration and cell related events.
810810
See the :ref:`migration guide <migration_3.2_required>` for more information.
811811

812+
* Fixed an issue where band lock, RAI notification subscription, and DNS fallback address were lost when the modem was put into :c:enumerator:`LTE_LC_FUNC_MODE_POWER_OFF` functional mode.
813+
812814
* :ref:`nrf_modem_lib_readme` library:
813815

814816
* Added the :c:func:`nrf_modem_lib_trace_peek_at` function to the :c:struct:`nrf_modem_lib_trace_backend` interface to peek trace data at a byte offset without consuming it.

lib/lte_link_control/include/modules/edrx.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ int edrx_param_set(enum lte_lc_lte_mode mode, const char *edrx);
2525
/* Request modem to enable or disable use of eDRX. */
2626
int edrx_request(bool enable);
2727

28+
/* Apply current eDRX configuration. Used after +CFUN=0 to restore the eDRX notification
29+
* subscription, which is not stored into NVM by the modem.
30+
*/
31+
void edrx_set(void);
32+
2833
#ifdef __cplusplus
2934
}
3035
#endif

lib/lte_link_control/include/modules/rai.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern "C" {
1212
#endif
1313

1414
/* Configure RAI. */
15-
int rai_set(void);
15+
void rai_set(void);
1616

1717
#ifdef __cplusplus
1818
}

lib/lte_link_control/lte_lc_modem_hooks.c

Lines changed: 69 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,28 @@
99
#include <modem/nrf_modem_lib.h>
1010
#include <zephyr/logging/log.h>
1111

12+
#include "modules/edrx.h"
1213
#include "modules/rai.h"
1314
#include "modules/dns.h"
1415
#include "common/helpers.h"
1516

1617
LOG_MODULE_DECLARE(lte_lc, CONFIG_LTE_LINK_CONTROL_LOG_LEVEL);
1718

19+
#if defined(CONFIG_LTE_LOCK_BANDS)
20+
static void band_lock_set(void)
21+
{
22+
int err;
23+
24+
/* Set LTE band lock (volatile setting).
25+
* Has to be done every time before activating the modem.
26+
*/
27+
err = nrf_modem_at_printf("AT%%XBANDLOCK=2,\""CONFIG_LTE_LOCK_BAND_MASK "\"");
28+
if (err) {
29+
LOG_ERR("Failed to lock LTE bands, err %d", err);
30+
}
31+
}
32+
#endif /* CONFIG_LTE_LOCK_BANDS */
33+
1834
#if defined(CONFIG_UNITY)
1935
void on_modem_init(int err, void *ctx)
2036
#else
@@ -37,7 +53,6 @@ static void on_modem_init(int err, void *ctx)
3753
err = lte_lc_system_mode_set(lte_lc_sys_mode, lte_lc_sys_mode_pref);
3854
if (err) {
3955
LOG_ERR("Failed to set system mode and mode preference, err %d", err);
40-
return;
4156
}
4257
}
4358

@@ -47,37 +62,32 @@ static void on_modem_init(int err, void *ctx)
4762
CONFIG_LTE_PSM_REQ_RAT_SECONDS);
4863
if (err) {
4964
LOG_ERR("Failed to set PSM params, err %d", err);
50-
return;
65+
} else {
66+
LOG_DBG("PSM configs set from seconds: tau=%ds, rat=%ds",
67+
CONFIG_LTE_PSM_REQ_RPTAU_SECONDS,
68+
CONFIG_LTE_PSM_REQ_RAT_SECONDS);
5169
}
52-
53-
LOG_DBG("PSM configs set from seconds: tau=%ds, rat=%ds",
54-
CONFIG_LTE_PSM_REQ_RPTAU_SECONDS,
55-
CONFIG_LTE_PSM_REQ_RAT_SECONDS);
5670
} else {
5771
__ASSERT_NO_MSG(IS_ENABLED(CONFIG_LTE_PSM_REQ_FORMAT_STRING));
5872

5973
err = lte_lc_psm_param_set(CONFIG_LTE_PSM_REQ_RPTAU, CONFIG_LTE_PSM_REQ_RAT);
6074
if (err) {
6175
LOG_ERR("Failed to set PSM params, err %d", err);
62-
return;
76+
} else {
77+
LOG_DBG("PSM configs set from string: tau=%s, rat=%s",
78+
CONFIG_LTE_PSM_REQ_RPTAU, CONFIG_LTE_PSM_REQ_RAT);
6379
}
64-
65-
LOG_DBG("PSM configs set from string: tau=%s, rat=%s",
66-
CONFIG_LTE_PSM_REQ_RPTAU, CONFIG_LTE_PSM_REQ_RAT);
6780
}
6881

69-
/* Request configured PSM and eDRX settings to save power. */
7082
err = lte_lc_psm_req(IS_ENABLED(CONFIG_LTE_PSM_REQ));
7183
if (err) {
7284
LOG_ERR("Failed to configure PSM, err %d", err);
73-
return;
7485
}
7586

7687
if (IS_ENABLED(CONFIG_LTE_PROPRIETARY_PSM_REQ)) {
7788
err = lte_lc_proprietary_psm_req(true);
7889
if (err) {
7990
LOG_ERR("Failed to configure proprietary PSM, err %d", err);
80-
return;
8191
}
8292
} else {
8393
/* Return value is ignored because this feature is not supported by all MFW
@@ -99,41 +109,69 @@ static void on_modem_init(int err, void *ctx)
99109
err = lte_lc_edrx_req(IS_ENABLED(CONFIG_LTE_EDRX_REQ));
100110
if (err) {
101111
LOG_ERR("Failed to configure eDRX, err %d", err);
102-
return;
103-
}
104-
#endif
105-
106-
#if defined(CONFIG_LTE_LOCK_BANDS)
107-
/* Set LTE band lock (volatile setting).
108-
* Has to be done every time before activating the modem.
109-
*/
110-
err = nrf_modem_at_printf("AT%%XBANDLOCK=2,\""CONFIG_LTE_LOCK_BAND_MASK "\"");
111-
if (err) {
112-
LOG_ERR("Failed to lock LTE bands, err %d", err);
113-
return;
114112
}
115113
#endif
116114

117115
#if defined(CONFIG_LTE_LOCK_PLMN)
118-
/* Manually select Operator (volatile setting).
119-
* Has to be done every time before activating the modem.
120-
*/
116+
/* Manually select the PLMN. */
121117
err = nrf_modem_at_printf("AT+COPS=1,2,\"" CONFIG_LTE_LOCK_PLMN_STRING "\"");
122118
if (err) {
123119
LOG_ERR("Failed to lock PLMN, err %d", err);
124-
return;
125120
}
126121
#elif defined(CONFIG_LTE_UNLOCK_PLMN)
127-
/* Automatically select Operator (volatile setting). */
122+
/* Automatically select the PLMN. */
128123
err = nrf_modem_at_printf("AT+COPS=0");
129124
if (err) {
130125
LOG_ERR("Failed to unlock PLMN, err %d", err);
126+
}
127+
#endif
128+
129+
#if defined(CONFIG_LTE_LOCK_BANDS)
130+
band_lock_set();
131+
#endif
132+
133+
#if defined(CONFIG_LTE_LC_RAI_MODULE)
134+
rai_set();
135+
#endif
136+
137+
#if defined(CONFIG_LTE_LC_DNS_FALLBACK_MODULE)
138+
dns_fallback_set();
139+
#endif
140+
}
141+
142+
#if defined(CONFIG_UNITY)
143+
void lte_lc_on_modem_cfun(int mode, void *ctx)
144+
#else
145+
NRF_MODEM_LIB_ON_CFUN(lte_lc_cfun_hook, lte_lc_on_modem_cfun, NULL);
146+
147+
static void lte_lc_on_modem_cfun(int mode, void *ctx)
148+
#endif /* CONFIG_UNITY */
149+
{
150+
ARG_UNUSED(ctx);
151+
152+
/* Settings not stored into NVM are lost when modem is put into functional mode
153+
* LTE_LC_FUNC_MODE_POWER_OFF. Because of this some of the settings need to be applied
154+
* again.
155+
*
156+
* We want to avoid sending AT commands in the callback. However, when modem is
157+
* powered off, we are not expecting AT notifications that could cause an assertion or
158+
* a missing notification.
159+
*/
160+
161+
if (mode != LTE_LC_FUNC_MODE_POWER_OFF) {
162+
/* Nothing to do */
131163
return;
132164
}
165+
166+
#if defined(CONFIG_LTE_LC_EDRX_MODULE)
167+
edrx_set();
168+
#endif
169+
170+
#if defined(CONFIG_LTE_LOCK_BANDS)
171+
band_lock_set();
133172
#endif
134173

135174
#if defined(CONFIG_LTE_LC_RAI_MODULE)
136-
/* Configure Release Assistance Indication (RAI). */
137175
rai_set();
138176
#endif
139177

lib/lte_link_control/modules/edrx.c

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -133,30 +133,6 @@ static void edrx_ptw_send_work_fn(struct k_work *work_item)
133133
}
134134
}
135135

136-
#if defined(CONFIG_UNITY)
137-
void lte_lc_edrx_on_modem_cfun(int mode, void *ctx)
138-
#else
139-
NRF_MODEM_LIB_ON_CFUN(lte_lc_edrx_cfun_hook, lte_lc_edrx_on_modem_cfun, NULL);
140-
141-
static void lte_lc_edrx_on_modem_cfun(int mode, void *ctx)
142-
#endif /* CONFIG_UNITY */
143-
{
144-
ARG_UNUSED(ctx);
145-
146-
/* If eDRX is enabled and modem is powered off, subscription of unsolicited eDRX
147-
* notifications must be re-newed because modem forgets that information
148-
* although it stores eDRX value and PTW for both system modes.
149-
*/
150-
if (mode == LTE_LC_FUNC_MODE_POWER_OFF && requested_edrx_enable) {
151-
lte_lc_edrx_current_values_clear();
152-
/* We want to avoid sending AT commands in the callback. However,
153-
* when modem is powered off, we are not expecting AT notifications
154-
* that could cause an assertion or missing notification.
155-
*/
156-
edrx_request(requested_edrx_enable);
157-
}
158-
}
159-
160136
/* Get Paging Time Window multiplier for the LTE mode.
161137
* Multiplier is 1.28 s for LTE-M, and 2.56 s for NB-IoT, derived from
162138
* Figure 10.5.5.32/3GPP TS 24.008.
@@ -534,3 +510,11 @@ int edrx_param_set(enum lte_lc_lte_mode mode, const char *edrx)
534510

535511
return 0;
536512
}
513+
514+
void edrx_set(void)
515+
{
516+
if (requested_edrx_enable) {
517+
lte_lc_edrx_current_values_clear();
518+
edrx_request(requested_edrx_enable);
519+
}
520+
}

lib/lte_link_control/modules/rai.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static void at_handler_rai(const char *response)
100100
event_handler_list_dispatch(&evt);
101101
}
102102

103-
int rai_set(void)
103+
void rai_set(void)
104104
{
105105
int err;
106106

@@ -119,9 +119,6 @@ int rai_set(void)
119119
}
120120
if (err) {
121121
LOG_ERR("Failed to configure RAI, err %d", err);
122-
return -EFAULT;
123122
}
124123
}
125-
126-
return err;
127124
}

0 commit comments

Comments
 (0)