Skip to content

Commit a90d01c

Browse files
tokangasrlubos
authored andcommitted
lib: lte_link_control: Add support for environment evaluation
Added support for environment evaluation using the %ENVEVAL AT command introduced in nRF91x1 modem firmware v2.0.3. Signed-off-by: Tommi Kangas <[email protected]>
1 parent 6099934 commit a90d01c

File tree

11 files changed

+987
-4
lines changed

11 files changed

+987
-4
lines changed

doc/nrf/libraries/modem/lte_lc.rst

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Tracking Area Update (TAU) Pre-warning:
147147
* :c:enumerator:`LTE_LC_EVT_TAU_PRE_WARNING` events
148148
* :kconfig:option:`CONFIG_LTE_LC_TAU_PRE_WARNING_NOTIFICATIONS`
149149

150-
DNS fallback:
150+
DNS Fallback:
151151
The :kconfig:option:`CONFIG_LTE_LC_DNS_FALLBACK_MODULE` Kconfig option controls the use of a fallback DNS server address.
152152

153153
The device might or might not receive a DNS server address by the network during a PDN connection.
@@ -158,6 +158,13 @@ DNS fallback:
158158
If the application has configured a DNS server address in Zephyr's native networking stack using the :kconfig:option:`CONFIG_DNS_SERVER1` Kconfig option, the same server is set as the fallback address for DNS queries offloaded to the nRF91 Series modem.
159159
Otherwise, the :kconfig:option:`CONFIG_LTE_LC_DNS_FALLBACK_ADDRESS` Kconfig option controls the fallback DNS server address that is set to Cloudflare's DNS server: 1.1.1.1 by default.
160160

161+
Environment Evaluation:
162+
Use the :kconfig:option:`CONFIG_LTE_LC_ENV_EVAL_MODULE` Kconfig option to enable the following functionalities related to Environment Evaluation:
163+
164+
* :c:enumerator:`LTE_LC_EVT_ENV_EVAL_RESULT` events
165+
* :c:func:`lte_lc_env_eval`
166+
* :c:func:`lte_lc_env_eval_cancel`
167+
161168
For more information on the callback events received in :c:type:`lte_lc_evt_handler_t` and data associated with each event, see the documentation on :c:struct:`lte_lc_evt`.
162169
For more information on the functions and data associated with each, refer to the API documentation.
163170

@@ -254,6 +261,20 @@ To enable modem sleep and TAU pre-warning notifications, use the following optio
254261

255262
For additional configurations related to these features, see the API documentation.
256263

264+
Environment evaluation
265+
======================
266+
267+
Modem firmware mfw_nrf91x1 v2.0.3 and higher, and mfw_nrf9151-ntn support environment evaluation.
268+
Environment evaluation allows the application to evaluate available PLMNs and select the best PLMN to use before connecting to the network.
269+
This is useful especially in cases where the device has multiple SIMs or SIM profiles to select from.
270+
271+
Environment evaluation can only be performed in *receive only* functional mode.
272+
During the environment evaluation, the device searches for the best cell for each PLMN.
273+
274+
The :c:func:`lte_lc_env_eval` function starts the environment evaluation for the given PLMNs.
275+
When the environment evaluation is complete, an :c:enumerator:`LTE_LC_EVT_ENV_EVAL_RESULT` event with the evaluation results is received.
276+
For each found PLMN, the :c:struct:`lte_lc_conn_eval_params` structure is populated with the evaluation results.
277+
257278
Limitations
258279
***********
259280

doc/nrf/nrf.doxyfile.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,8 @@ PREDEFINED = __DOXYGEN__ \
24642464
"CONFIG_LTE_LC_PSM_MODULE=y" \
24652465
"CONFIG_LTE_LC_RAI_MODULE=y" \
24662466
"CONFIG_LTE_LC_MODEM_SLEEP_MODULE=y" \
2467-
"CONFIG_LTE_LC_TAU_PRE_WARNING_MODULE=y"
2467+
"CONFIG_LTE_LC_TAU_PRE_WARNING_MODULE=y" \
2468+
"CONFIG_LTE_LC_ENV_EVAL_MODULE=y"
24682469

24692470
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
24702471
# tag can be used to specify a list of macro names that should be expanded. The

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ Modem libraries
586586

587587
* Added:
588588

589+
* Support for environment evaluation.
589590
* Support for NTN NB-IoT system mode.
590591
* eDRX support for NTN NB-IoT.
591592

include/modem/lte_lc.h

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,20 @@ enum lte_lc_evt_type {
362362
*/
363363
LTE_LC_EVT_RAI_UPDATE = 12,
364364
#endif /* CONFIG_LTE_LC_RAI_MODULE */
365+
366+
#if defined(CONFIG_LTE_LC_ENV_EVAL_MODULE)
367+
/**
368+
* Environment evaluation result.
369+
*
370+
* The associated payload is the @c lte_lc_evt.env_eval_result member of type
371+
* @ref lte_lc_env_eval_result in the event.
372+
*
373+
* @note This is only supported by the following modem firmware:
374+
* - mfw_nrf91x1 >= v2.0.3
375+
* - mfw_nrf9151-ntn
376+
*/
377+
LTE_LC_EVT_ENV_EVAL_RESULT = 13,
378+
#endif /* CONFIG_LTE_LC_ENV_EVAL_MODULE */
365379
};
366380

367381
/** RRC connection state. */
@@ -1052,6 +1066,49 @@ struct lte_lc_ncellmeas_params {
10521066
uint8_t gci_count;
10531067
};
10541068

1069+
/** Environment evaluation type. */
1070+
enum lte_lc_env_eval_type {
1071+
/**
1072+
* PLMN search is stopped after light search if any of the PLMNs to evaluate were found.
1073+
* Search is continued over all frequency bands if light search did not find any results.
1074+
*/
1075+
LTE_LC_ENV_EVAL_TYPE_DYNAMIC = 0,
1076+
1077+
/** PLMN search is stopped after light search even if no PLMNs to evaluate were found. */
1078+
LTE_LC_ENV_EVAL_TYPE_LIGHT = 1,
1079+
1080+
/** PLMN search covers all channels in all supported frequency bands. */
1081+
LTE_LC_ENV_EVAL_TYPE_FULL = 2
1082+
};
1083+
1084+
/** PLMN to evaluate. */
1085+
struct lte_lc_env_eval_plmn {
1086+
/** Mobile Country Code (MCC). */
1087+
int mcc;
1088+
1089+
/** Mobile Network Code (MNC). */
1090+
int mnc;
1091+
};
1092+
1093+
/** Environment evaluation parameters. */
1094+
struct lte_lc_env_eval_params {
1095+
/**
1096+
* Environment evaluation type.
1097+
*/
1098+
enum lte_lc_env_eval_type eval_type;
1099+
1100+
/**
1101+
* Number of PLMNs to evaluate.
1102+
*
1103+
* Must be less than or equal to @c CONFIG_LTE_LC_ENV_EVAL_MAX_PLMN_COUNT.
1104+
*/
1105+
uint8_t plmn_count;
1106+
1107+
/**
1108+
* Pointer to an array of PLMNs to evaluate.
1109+
*/
1110+
struct lte_lc_env_eval_plmn *plmn_list;
1111+
};
10551112

10561113
/** Search pattern type. */
10571114
enum lte_lc_periodic_search_pattern_type {
@@ -1214,6 +1271,38 @@ struct lte_lc_periodic_search_cfg {
12141271
struct lte_lc_periodic_search_pattern patterns[4];
12151272
};
12161273

1274+
#if defined(CONFIG_LTE_LC_ENV_EVAL_MODULE)
1275+
/**
1276+
* @brief Environment evaluation results.
1277+
*
1278+
* This structure is used as the payload for event @ref LTE_LC_EVT_ENV_EVAL_RESULT.
1279+
*/
1280+
struct lte_lc_env_eval_result {
1281+
/**
1282+
* Status for the environment evaluation.
1283+
*
1284+
* 0 indicates successful completion of the evaluation.
1285+
* 5 indicates that evaluation failed, aborted due to higher priority operation.
1286+
* 7 indicates that evaluation failed, unspecified.
1287+
*/
1288+
uint8_t status;
1289+
1290+
/**
1291+
* Number of PLMN results available in the results array.
1292+
*
1293+
* Range: 0 to CONFIG_LTE_LC_ENV_EVAL_MAX_PLMN_COUNT
1294+
*/
1295+
uint8_t result_count;
1296+
1297+
/**
1298+
* Pointer to an array of environment evaluation results for different PLMNs.
1299+
*
1300+
* Each entry contains the evaluation result for a specific PLMN.
1301+
*/
1302+
struct lte_lc_conn_eval_params *results;
1303+
};
1304+
#endif /* CONFIG_LTE_LC_ENV_EVAL_MODULE */
1305+
12171306
/** Callback for modem functional mode changes. */
12181307
struct lte_lc_cfun_cb {
12191308
void (*callback)(enum lte_lc_func_mode, void *ctx);
@@ -1275,6 +1364,11 @@ struct lte_lc_evt {
12751364
/** Payload for event @ref LTE_LC_EVT_RAI_UPDATE. */
12761365
struct lte_lc_rai_cfg rai_cfg;
12771366
#endif /* CONFIG_LTE_LC_RAI_MODULE */
1367+
1368+
#if defined(CONFIG_LTE_LC_ENV_EVAL_MODULE)
1369+
/** Payload for event @ref LTE_LC_EVT_ENV_EVAL_RESULT. */
1370+
struct lte_lc_env_eval_result env_eval_result;
1371+
#endif /* CONFIG_LTE_LC_ENV_EVAL_MODULE */
12781372
};
12791373
};
12801374

@@ -1754,6 +1848,48 @@ int lte_lc_neighbor_cell_measurement_cancel(void);
17541848
*/
17551849
int lte_lc_conn_eval_params_get(struct lte_lc_conn_eval_params *params);
17561850

1851+
/**
1852+
* Start environment evaluation.
1853+
*
1854+
* Perform evaluation for PLMN selection. Evaluates available PLMNs and provides information
1855+
* of their estimated signalling conditions. Based on the evaluation results, the application
1856+
* can then select the best PLMN to use. This is useful especially in cases where the device
1857+
* has multiple SIMs or SIM profiles to select from.
1858+
*
1859+
* PLMNs (MCC/MNC pairs) to be evaluated are listed in the @ref lte_lc_env_eval_params
1860+
* structure. For each PLMN, evaluation results for the best found cell are returned. The results
1861+
* are returned with the @ref LTE_LC_EVT_ENV_EVAL_RESULT event.
1862+
*
1863+
* Environment evaluation can only be performed in receive only functional mode. The device does
1864+
* not transmit anything during the evaluation.
1865+
*
1866+
* @note This is only supported by the following modem firmware:
1867+
* - mfw_nrf91x1 >= v2.0.3
1868+
* - mfw_nrf9151-ntn
1869+
*
1870+
* @note Requires `CONFIG_LTE_LC_ENV_EVAL_MODULE` to be enabled.
1871+
*
1872+
* @param[in] params Environment evaluation parameters.
1873+
*
1874+
* @retval 0 if environment evaluation was successfully initiated.
1875+
* @retval -EFAULT if AT command failed or feature is not supported by the modem firmware.
1876+
* @retval -EINVAL if parameters are invalid.
1877+
* @retval -EOPNOTSUPP if environment evaluation is not available in the current functional mode.
1878+
*/
1879+
int lte_lc_env_eval(struct lte_lc_env_eval_params *params);
1880+
1881+
/**
1882+
* Cancel an ongoing environment evaluation.
1883+
*
1884+
* If environment evaluation was in progress, an @ref LTE_LC_EVT_ENV_EVAL_RESULT event is received.
1885+
*
1886+
* @note Requires `CONFIG_LTE_LC_ENV_EVAL_MODULE` to be enabled.
1887+
*
1888+
* @retval 0 if environment evaluation was cancelled.
1889+
* @retval -EFAULT if AT command failed.
1890+
*/
1891+
int lte_lc_env_eval_cancel(void);
1892+
17571893
/**
17581894
* Enable modem domain events.
17591895
*

lib/lte_link_control/Kconfig

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ config LTE_LC_CONN_EVAL_MODULE
2020
bool "Connection Parameters Evaluation module"
2121

2222
config LTE_LC_EDRX_MODULE
23-
bool "Extended Discountinuous Reception (eDRX) module"
23+
bool "Extended Discontinuous Reception (eDRX) module"
2424

2525
config LTE_LC_NEIGHBOR_CELL_MEAS_MODULE
2626
bool "Neighboring Cell Measurements module"
@@ -40,8 +40,11 @@ config LTE_LC_MODEM_SLEEP_MODULE
4040
config LTE_LC_TAU_PRE_WARNING_MODULE
4141
bool "Tracking Area Update (TAU) module"
4242

43+
config LTE_LC_ENV_EVAL_MODULE
44+
bool "Environment Evaluation module"
45+
4346
menuconfig LTE_LC_DNS_FALLBACK_MODULE
44-
bool "Fallback DNS module"
47+
bool "DNS Fallback module"
4548
default y
4649
help
4750
The device might or might not receive a DNS server address by the network during a PDN connection.
@@ -442,6 +445,12 @@ config LTE_LC_MODEM_SLEEP_NOTIFICATIONS_THRESHOLD_MS
442445

443446
endif # LTE_LC_MODEM_SLEEP_MODULE
444447

448+
config LTE_LC_ENV_EVAL_MAX_PLMN_COUNT
449+
int "Maximum number of PLMNs to evaluate"
450+
default 3
451+
help
452+
Maximum number of PLMNs that can be evaluated with lte_lc_env_eval().
453+
445454
config LTE_LC_TRACE
446455
bool "LTE link control tracing"
447456
help
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef ENVEVAL_H__
8+
#define ENVEVAL_H__
9+
10+
#include <modem/lte_lc.h>
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
/* Perform environment evaluation. */
17+
int env_eval(struct lte_lc_env_eval_params *params);
18+
19+
/* Cancel an ongoing environment evaluation. */
20+
int env_eval_cancel(void);
21+
22+
#ifdef __cplusplus
23+
}
24+
#endif
25+
26+
#endif /* ENVEVAL_H__ */

lib/lte_link_control/lte_lc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "modules/xmodemsleep.h"
3030
#include "modules/xsystemmode.h"
3131
#include "modules/xt3412.h"
32+
#include "modules/enveval.h"
3233

3334
#include "common/work_q.h"
3435
#include "common/event_handler_list.h"
@@ -184,6 +185,16 @@ int lte_lc_conn_eval_params_get(struct lte_lc_conn_eval_params *params)
184185
return coneval_params_get(params);
185186
}
186187

188+
int lte_lc_env_eval(struct lte_lc_env_eval_params *params)
189+
{
190+
return env_eval(params);
191+
}
192+
193+
int lte_lc_env_eval_cancel(void)
194+
{
195+
return env_eval_cancel();
196+
}
197+
187198
int lte_lc_modem_events_enable(void)
188199
{
189200
return mdmev_enable();

lib/lte_link_control/modules/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ zephyr_library_sources_ifdef(CONFIG_LTE_LC_PERIODIC_SEARCH_MODULE periodicsearch
1818
zephyr_library_sources_ifdef(CONFIG_LTE_LC_MODEM_SLEEP_MODULE xmodemsleep.c)
1919
zephyr_library_sources_ifdef(CONFIG_LTE_LC_TAU_PRE_WARNING_MODULE xt3412.c)
2020
zephyr_library_sources_ifdef(CONFIG_LTE_LC_DNS_FALLBACK_MODULE dns.c)
21+
zephyr_library_sources_ifdef(CONFIG_LTE_LC_ENV_EVAL_MODULE enveval.c)

0 commit comments

Comments
 (0)