Skip to content

Commit

Permalink
Anjay-zephyr 3.6.1
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Kucmasz committed Nov 21, 2023
1 parent 7363492 commit 3a2f5d2
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 22 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion Kconfig.anjay_zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions compat/mbedtls_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
*/

#include <mbedtls/entropy.h>
#include <mbedtls/platform.h>
#include <mbedtls/timing.h>

#include <avsystem/commons/avs_defs.h>
#include <avsystem/commons/avs_errno.h>
#include <avsystem/commons/avs_memory.h>
#include <avsystem/commons/avs_time.h>

#include <zephyr/drivers/entropy.h>
Expand Down Expand Up @@ -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)
11 changes: 11 additions & 0 deletions config/anjay/anjay_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions config/avsystem/commons/avs_commons_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <c>psa_generate_random()</c> 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 <c>dlsym()</c> function available?
*
Expand Down
2 changes: 1 addition & 1 deletion deps/anjay
Submodule anjay updated 104 files
12 changes: 12 additions & 0 deletions src/afu/nrf9160/afu_nrf9160_modem.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#include <modem/modem_info.h>
#include <modem/nrf_modem_lib.h>

#if __has_include("ncs_version.h")
# include "ncs_version.h"
#endif // __has_include("ncs_version.h")

#include "afu_nrf9160.h"

#include <pm_config.h>
Expand Down Expand Up @@ -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",
Expand All @@ -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);
Expand Down
51 changes: 41 additions & 10 deletions src/gps_impl/gps_nrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/location_services.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/network/network_nrf91.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/nrf_lc_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

#include <assert.h>
#include <stdatomic.h>
#include <string.h>

Expand Down
17 changes: 13 additions & 4 deletions src/objects/gnss_assistance.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@

#include <zephyr/logging/log.h>

#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 <net/nrf_cloud_agps.h>
#endif // CONFIG_ANJAY_ZEPHYR_GPS_NRF_A_GPS
# if NCS_VERSION_NUMBER >= 0x20463
# include <net/nrf_cloud_agnss.h>
# else // NCS_VERSION_NUMBER >= 0x20463
# include <net/nrf_cloud_agps.h>
# define nrf_cloud_agnss_process nrf_cloud_agps_process
# endif // NCS_VERSION_NUMBER >= 0x20463
#endif // CONFIG_ANJAY_ZEPHYR_GPS_NRF_A_GPS

#include <anjay/anjay.h>
#include <avsystem/commons/avs_defs.h>
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 12 additions & 4 deletions src/objects/location.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3a2f5d2

Please # to comment.