diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d7deea..da9e81e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 3.6.1 (November 21st, 2023) + +### Bugfixes +- Added zero initialization for /6 Location Object Resources for the state + before catching the first fix in favor of blocking the Read operation + +### Improvements +- Fixed compatibility with newest versions of Zephyr and nRF Connect SDK + ## 3.5.0 (September 7th, 2023) ### Features diff --git a/Kconfig.anjay_zephyr b/Kconfig.anjay_zephyr index 9d8e06a..4aa1073 100644 --- a/Kconfig.anjay_zephyr +++ b/Kconfig.anjay_zephyr @@ -24,7 +24,7 @@ config ANJAY_ZEPHYR_MODEL_NUMBER config ANJAY_ZEPHYR_VERSION string "Client Version" - default "3.5.0" + default "3.5.1" config ANJAY_ZEPHYR_AUTOGENERATE_ENDPOINT_NAME bool "Autogenerate endpoint name" @@ -238,6 +238,7 @@ menu "GPS on nRF9160-based devices" config ANJAY_ZEPHYR_GPS_NRF_A_GPS bool "Enable A-GPS using Nordic Location Services over LwM2M" depends on ANJAY_ZEPHYR_GPS_NRF + select NRF_CLOUD_AGNSS select NRF_CLOUD_AGPS help Attempt to retrieve A-GPS data using Nordic Location Services over LwM2M. @@ -372,6 +373,9 @@ config ANJAY_ZEPHYR_FACTORY_PROVISIONING_INITIAL_FLASH select MCUMGR_CMD_FS_MGMT select MCUMGR_SMP_SHELL select UART_CONSOLE_MCUMGR + select NET_BUF + select ZCBOR + select CRC help This option should be used with specially tailored version of the application that will not perform any normal LwM2M client operation, but instead it will allow to diff --git a/compat/mbedtls_compat.c b/compat/mbedtls_compat.c index 577628e..618e79b 100644 --- a/compat/mbedtls_compat.c +++ b/compat/mbedtls_compat.c @@ -15,10 +15,12 @@ */ #include +#include #include #include #include +#include #include #include @@ -108,3 +110,22 @@ void anjay_zephyr_mbedtls_entropy_init__(mbedtls_entropy_context *ctx) { (void) result; AVS_ASSERT(!result, "Failed to add entropy source"); } + +#if defined(MBEDTLS_PLATFORM_MEMORY) \ + && !(defined(MBEDTLS_PLATFORM_CALLOC_MACRO) \ + && defined(MBEDTLS_PLATFORM_FREE_MACRO)) \ + && !(defined(MBEDTLS_PLATFORM_STD_CALLOC) \ + && defined(MBEDTLS_PLATFORM_STD_FREE)) \ + && !defined(CONFIG_MBEDTLS_ENABLE_HEAP) +static int mbedtls_alloc_init(void) { + mbedtls_platform_set_calloc_free(avs_calloc, avs_free); + return 0; +} + +SYS_INIT(mbedtls_alloc_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +#endif // defined(MBEDTLS_PLATFORM_MEMORY) && + // !(defined(MBEDTLS_PLATFORM_CALLOC_MACRO) && + // defined(MBEDTLS_PLATFORM_FREE_MACRO)) && + // !(defined(MBEDTLS_PLATFORM_STD_CALLOC) && + // defined(MBEDTLS_PLATFORM_STD_FREE)) && + // !defined(CONFIG_MBEDTLS_ENABLE_HEAP) diff --git a/config/anjay/anjay_config.h b/config/anjay/anjay_config.h index 402d309..f3470c2 100644 --- a/config/anjay/anjay_config.h +++ b/config/anjay/anjay_config.h @@ -739,6 +739,17 @@ #ifdef CONFIG_ANJAY_WITH_MODULE_OSCORE # define ANJAY_WITH_MODULE_OSCORE #endif // CONFIG_ANJAY_WITH_MODULE_OSCORE + +/** + * If enable Anjay doesn't handle composite operation (read, observe and write). + * Its use makes sense for LWM2M v1.1 upwards. + * + * This flag can be used to reduce the size of the resulting code. + * + * If active, anjay will respond with message code 5.01 Not Implemented to any + * composite type request. + */ +/* #undef ANJAY_WITHOUT_COMPOSITE_OPERATIONS */ /**@}*/ #endif // ANJAY_CONFIG_H diff --git a/config/avsystem/commons/avs_commons_config.h b/config/avsystem/commons/avs_commons_config.h index 6bcf32c..175428f 100644 --- a/config/avsystem/commons/avs_commons_config.h +++ b/config/avsystem/commons/avs_commons_config.h @@ -491,6 +491,18 @@ void anjay_zephyr_mbedtls_entropy_init__(struct mbedtls_entropy_context *ctx); */ /* #undef AVS_COMMONS_WITH_MBEDTLS_PSA_ENGINE_PROTECTED_STORAGE */ +/** + * Enables use of the psa_generate_random() function as the default + * random number generator when using the Mbed TLS crypto backend, instead of + * CTR-DRBG seeded by the Mbed TLS entropy pool. + * + * It's meaningful only when @ref AVS_COMMONS_WITH_MBEDTLS is enabled. However, + * it is independent from the above PSA engine settings. + */ +#ifdef CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG +# define AVS_COMMONS_WITH_MBEDTLS_PSA_RNG +#endif // CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG + /** * Is the dlsym() function available? * diff --git a/deps/anjay b/deps/anjay index 0acafc4..4f451c7 160000 --- a/deps/anjay +++ b/deps/anjay @@ -1 +1 @@ -Subproject commit 0acafc41f108527853416f541ea7a1363127d15c +Subproject commit 4f451c7382591072735767de28bc201c2d14e4b5 diff --git a/src/afu/nrf9160/afu_nrf9160_modem.c b/src/afu/nrf9160/afu_nrf9160_modem.c index 483e5d1..dd13337 100644 --- a/src/afu/nrf9160/afu_nrf9160_modem.c +++ b/src/afu/nrf9160/afu_nrf9160_modem.c @@ -26,6 +26,10 @@ #include #include +#if __has_include("ncs_version.h") +# include "ncs_version.h" +#endif // __has_include("ncs_version.h") + #include "afu_nrf9160.h" #include @@ -230,7 +234,11 @@ void _anjay_zephyr_afu_nrf9160_full_modem_apply(void) { goto finish; } +# if NCS_VERSION_NUMBER >= 0x20400 + result = nrf_modem_lib_bootloader_init(); +# else // NCS_VERSION_NUMBER >= 0x20400 result = nrf_modem_lib_init(BOOTLOADER_MODE); +# endif // NCS_VERSION_NUMBER >= 0x20400 if (result) { LOG_ERR("Could not initialize nrf_modem_lib in Bootloader (full DFU) " "mode: %d", @@ -253,7 +261,11 @@ void _anjay_zephyr_afu_nrf9160_full_modem_apply(void) { goto finish; } +# if NCS_VERSION_NUMBER >= 0x20400 + result = nrf_modem_lib_init(); +# else // NCS_VERSION_NUMBER >= 0x20400 result = nrf_modem_lib_init(NORMAL_MODE); +# endif // NCS_VERSION_NUMBER >= 0x20400 if (result) { LOG_ERR("Could not reinitialize nrf_modem_lib in normal mode: %d", result); diff --git a/src/gps_impl/gps_nrf.c b/src/gps_impl/gps_nrf.c index a3032e5..c29b6b8 100644 --- a/src/gps_impl/gps_nrf.c +++ b/src/gps_impl/gps_nrf.c @@ -36,6 +36,10 @@ # include "../objects/objects.h" #endif // CONFIG_ANJAY_ZEPHYR_GPS_NRF_A_GPS +#if __has_include("ncs_version.h") +# include "ncs_version.h" +#endif // __has_include("ncs_version.h") + LOG_MODULE_REGISTER(anjay_zephyr_gps_nrf); #define INTERRUPTED_FIXES_WARN_THRESHOLD 10 @@ -185,35 +189,62 @@ static void incoming_pvt_work_handler(struct k_work *work) { } #ifdef CONFIG_ANJAY_ZEPHYR_GPS_NRF_A_GPS +# if NCS_VERSION_NUMBER < 0x20463 +# define nrf_modem_gnss_agnss_data_frame nrf_modem_gnss_agps_data_frame +# define NRF_MODEM_GNSS_AGNSS_GPS_UTC_REQUEST \ + NRF_MODEM_GNSS_AGPS_GPS_UTC_REQUEST +# define NRF_MODEM_GNSS_AGNSS_KLOBUCHAR_REQUEST \ + NRF_MODEM_GNSS_AGPS_KLOBUCHAR_REQUEST +# define NRF_MODEM_GNSS_AGNSS_NEQUICK_REQUEST \ + NRF_MODEM_GNSS_AGPS_NEQUICK_REQUEST +# define NRF_MODEM_GNSS_AGNSS_GPS_SYS_TIME_AND_SV_TOW_REQUEST \ + NRF_MODEM_GNSS_AGPS_SYS_TIME_AND_SV_TOW_REQUEST +# define NRF_MODEM_GNSS_AGNSS_POSITION_REQUEST \ + NRF_MODEM_GNSS_AGPS_POSITION_REQUEST +# define NRF_MODEM_GNSS_AGNSS_INTEGRITY_REQUEST \ + NRF_MODEM_GNSS_AGPS_INTEGRITY_REQUEST +# define NRF_MODEM_GNSS_EVT_AGNSS_REQ NRF_MODEM_GNSS_EVT_AGPS_REQ +# define NRF_MODEM_GNSS_DATA_AGNSS_REQ NRF_MODEM_GNSS_DATA_AGPS_REQ +# endif // NCS_VERSION_NUMBER < 0x20463 + static void -handle_modem_agps_request_evt(struct nrf_modem_gnss_agps_data_frame req) { +handle_modem_agps_request_evt(struct nrf_modem_gnss_agnss_data_frame req) { uint32_t request_mask = 0; - if (req.data_flags & NRF_MODEM_GNSS_AGPS_GPS_UTC_REQUEST) { + if (req.data_flags & NRF_MODEM_GNSS_AGNSS_GPS_UTC_REQUEST) { request_mask |= LOC_SERVICES_A_GPS_MASK_UTC; } - if (req.data_flags & NRF_MODEM_GNSS_AGPS_KLOBUCHAR_REQUEST) { + if (req.data_flags & NRF_MODEM_GNSS_AGNSS_KLOBUCHAR_REQUEST) { request_mask |= LOC_SERVICES_A_GPS_MASK_KLOBUCHAR; } - if (req.data_flags & NRF_MODEM_GNSS_AGPS_NEQUICK_REQUEST) { + if (req.data_flags & NRF_MODEM_GNSS_AGNSS_NEQUICK_REQUEST) { request_mask |= LOC_SERVICES_A_GPS_MASK_NEQUICK; } - if (req.data_flags & NRF_MODEM_GNSS_AGPS_SYS_TIME_AND_SV_TOW_REQUEST) { + if (req.data_flags & NRF_MODEM_GNSS_AGNSS_GPS_SYS_TIME_AND_SV_TOW_REQUEST) { request_mask |= LOC_SERVICES_A_GPS_MASK_TOW | LOC_SERVICES_A_GPS_MASK_CLOCK; } - if (req.data_flags & NRF_MODEM_GNSS_AGPS_POSITION_REQUEST) { + if (req.data_flags & NRF_MODEM_GNSS_AGNSS_POSITION_REQUEST) { request_mask |= LOC_SERVICES_A_GPS_MASK_LOCATION; } - if (req.data_flags & NRF_MODEM_GNSS_AGPS_INTEGRITY_REQUEST) { + if (req.data_flags & NRF_MODEM_GNSS_AGNSS_INTEGRITY_REQUEST) { request_mask |= LOC_SERVICES_A_GPS_MASK_INTEGRITY; } +# if NCS_VERSION_NUMBER >= 0x20463 + if (req.system[0].sv_mask_ephe) { + request_mask |= LOC_SERVICES_A_GPS_MASK_EPHEMERIS; + } + if (req.system[0].sv_mask_alm) { + request_mask |= LOC_SERVICES_A_GPS_MASK_ALMANAC; + } +# else // NCS_VERSION_NUMBER >= 0x20463 if (req.sv_mask_ephe) { request_mask |= LOC_SERVICES_A_GPS_MASK_EPHEMERIS; } if (req.sv_mask_alm) { request_mask |= LOC_SERVICES_A_GPS_MASK_ALMANAC; } +# endif // NCS_VERSION_NUMBER >= 0x20463 SYNCHRONIZED(anjay_zephyr_gps_read_last_mtx) { // We're reassigning the mask instead of ORing it with previous state, @@ -242,11 +273,11 @@ static void gnss_event_handler(int event) { _anjay_zephyr_k_work_submit(&incoming_pvt_work); } #ifdef CONFIG_ANJAY_ZEPHYR_GPS_NRF_A_GPS - if (event == NRF_MODEM_GNSS_EVT_AGPS_REQ) { - struct nrf_modem_gnss_agps_data_frame req; + if (event == NRF_MODEM_GNSS_EVT_AGNSS_REQ) { + struct nrf_modem_gnss_agnss_data_frame req; if (nrf_modem_gnss_read( - &req, sizeof(req), NRF_MODEM_GNSS_DATA_AGPS_REQ)) { + &req, sizeof(req), NRF_MODEM_GNSS_DATA_AGNSS_REQ)) { LOG_ERR("Failed to retrieve a A-GPS REQ event"); return; } diff --git a/src/location_services.c b/src/location_services.c index 3d97a91..f97a908 100644 --- a/src/location_services.c +++ b/src/location_services.c @@ -450,10 +450,10 @@ static int send_agps_request(anjay_t *anjay, uint32_t request_mask) { } }; - LOG_INF("Requesting following types of A-GPS data:"); + LOG_INF("Requesting A-GPS data"); for (size_t i = 0; i < AVS_ARRAY_SIZE(agps_flag_names); i++) { if (agps_flag_names[i].req_flag & request_mask) { - LOG_INF("%s", agps_flag_names[i].name); + LOG_DBG("%s", agps_flag_names[i].name); } } diff --git a/src/network/network_nrf91.c b/src/network/network_nrf91.c index 72c67b4..ee88272 100644 --- a/src/network/network_nrf91.c +++ b/src/network/network_nrf91.c @@ -29,6 +29,10 @@ #include "../gps.h" #include "../utils.h" +#if __has_include("ncs_version.h") +# include "ncs_version.h" +#endif // __has_include("ncs_version.h") + LOG_MODULE_REGISTER(anjay_zephyr_network_nrf91); static volatile atomic_int lte_nw_reg_status; // enum lte_lc_nw_reg_status @@ -49,7 +53,11 @@ int _anjay_zephyr_network_internal_platform_initialize(void) { int ret; #if defined(CONFIG_LTE_LINK_CONTROL) && !defined(CONFIG_NRF_MODEM_LIB_SYS_INIT) +# if NCS_VERSION_NUMBER >= 0x20400 + ret = nrf_modem_lib_init(); +# else // NCS_VERSION_NUMBER >= 0x20400 ret = nrf_modem_lib_init(NORMAL_MODE); +# endif // NCS_VERSION_NUMBER >= 0x20400 if (ret) { # ifdef CONFIG_ANJAY_ZEPHYR_ADVANCED_FOTA_NRF9160 // nrf_modem_init (called indirectly) returns a positive code in case diff --git a/src/nrf_lc_info.c b/src/nrf_lc_info.c index e941a44..d82e5e7 100644 --- a/src/nrf_lc_info.c +++ b/src/nrf_lc_info.c @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include diff --git a/src/objects/gnss_assistance.c b/src/objects/gnss_assistance.c index 774a899..759425d 100644 --- a/src/objects/gnss_assistance.c +++ b/src/objects/gnss_assistance.c @@ -19,9 +19,18 @@ #include +#if __has_include("ncs_version.h") +# include "ncs_version.h" +#endif // __has_include("ncs_version.h") + #ifdef CONFIG_ANJAY_ZEPHYR_GPS_NRF_A_GPS -# include -#endif // CONFIG_ANJAY_ZEPHYR_GPS_NRF_A_GPS +# if NCS_VERSION_NUMBER >= 0x20463 +# include +# else // NCS_VERSION_NUMBER >= 0x20463 +# include +# define nrf_cloud_agnss_process nrf_cloud_agps_process +# endif // NCS_VERSION_NUMBER >= 0x20463 +#endif // CONFIG_ANJAY_ZEPHYR_GPS_NRF_A_GPS #include #include @@ -205,8 +214,8 @@ static int transaction_commit(anjay_t *anjay, if (obj->assistance_data_len > 0) { LOG_INF("Received %zu bytes of A-GPS data", obj->assistance_data_len); - int err = nrf_cloud_agps_process(obj->assistance_data_buf, - obj->assistance_data_len); + int err = nrf_cloud_agnss_process(obj->assistance_data_buf, + obj->assistance_data_len); obj->assistance_data_len = 0; if (err) { diff --git a/src/objects/location.c b/src/objects/location.c index 74f999a..d88791e 100644 --- a/src/objects/location.c +++ b/src/objects/location.c @@ -145,10 +145,6 @@ static int resource_read(anjay_t *anjay, assert(obj); assert(iid == 0); - if (!obj->cached_read.valid) { - return ANJAY_ERR_METHOD_NOT_ALLOWED; - } - switch (rid) { case RID_TIMESTAMP: assert(riid == ANJAY_ID_INVALID); @@ -212,6 +208,18 @@ const anjay_dm_object_def_t **anjay_zephyr_location_object_create(void) { } obj->def = &OBJ_DEF; obj->cached_read.valid = false; + obj->cached_read.timestamp = 0; + obj->cached_read.latitude = 0; + obj->cached_read.longitude = 0; +# ifdef CONFIG_ANJAY_ZEPHYR_GPS_ALTITUDE + obj->cached_read.altitude = 0; +# endif // CONFIG_ANJAY_ZEPHYR_GPS_ALTITUDE +# ifdef CONFIG_ANJAY_ZEPHYR_GPS_RADIUS + obj->cached_read.radius = 0; +# endif // CONFIG_ANJAY_ZEPHYR_GPS_RADIUS +# ifdef CONFIG_ANJAY_ZEPHYR_GPS_SPEED + obj->cached_read.speed = 0; +# endif // CONFIG_ANJAY_ZEPHYR_GPS_SPEED return &obj->def; }