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
9697static 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)
413422int 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 }
0 commit comments