16
16
#include <nrf_modem_at.h>
17
17
18
18
#include "common/work_q.h"
19
+ #include "common/helpers.h"
19
20
#include "common/event_handler_list.h"
20
21
#include "modules/edrx.h"
21
22
@@ -96,10 +97,21 @@ static void lte_lc_edrx_values_store(enum lte_lc_lte_mode mode, char *edrx_value
96
97
static void edrx_ptw_send_work_fn (struct k_work * work_item )
97
98
{
98
99
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 ();
100
103
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 ++ ) {
103
115
char * requested_ptw_value =
104
116
(actt [i ] == AT_CEDRXS_ACTT_WB ) ? requested_ptw_value_ltem :
105
117
(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)
114
126
115
127
err = nrf_modem_at_printf ("AT%%XPTW=%d,\"%s\"" , actt [i ],
116
128
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 ) {
121
130
LOG_ERR ("Failed to request PTW, reported error: %d" , err );
122
131
}
123
132
}
@@ -413,7 +422,22 @@ int edrx_ptw_set(enum lte_lc_lte_mode mode, const char *ptw)
413
422
int edrx_request (bool enable )
414
423
{
415
424
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 ++ ;
417
441
418
442
LOG_DBG ("enable=%d, "
419
443
"requested_edrx_value_ltem=%s, edrx_value_ltem=%s, "
@@ -444,8 +468,8 @@ int edrx_request(bool enable)
444
468
return 0 ;
445
469
}
446
470
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 ++ ) {
449
473
char * requested_edrx_value =
450
474
(actt [i ] == AT_CEDRXS_ACTT_WB ) ? requested_edrx_value_ltem :
451
475
(actt [i ] == AT_CEDRXS_ACTT_NB ) ? requested_edrx_value_nbiot :
@@ -467,10 +491,7 @@ int edrx_request(bool enable)
467
491
err = nrf_modem_at_printf ("AT+CEDRXS=2,%d" , actt [i ]);
468
492
}
469
493
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 ) {
474
495
LOG_ERR ("Failed to enable eDRX, reported error: %d" , err );
475
496
return - EFAULT ;
476
497
}
0 commit comments