Skip to content

Commit

Permalink
net: lwm2m_client_utils: use modem_info to find HW version
Browse files Browse the repository at this point in the history
In LwM2M Device object, as well as Advanced firmware object,
we have modem hardware type visible.
Query this information from modem_info library, instead
of using build-in values.
This allows same FW to run on 9161 and 9151 and we still
see from server side which HW is used.

Signed-off-by: Seppo Takalo <[email protected]>
  • Loading branch information
SeppoTakalo authored and cvinayak committed Feb 7, 2024
1 parent 85fef3c commit 713658c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
31 changes: 24 additions & 7 deletions samples/cellular/lwm2m_client/src/lwm2m/lwm2m_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
#include "pm_config.h"
#include "lwm2m_app_utils.h"

#ifdef CONFIG_SOC_SERIES_NRF91X
#include <modem/modem_info.h>
#endif

#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(app_lwm2m, CONFIG_APP_LOG_LEVEL);

#define CLIENT_MODEL_NUMBER CONFIG_BOARD
#define CLIENT_HW_VER CONFIG_SOC
#define CLIENT_FLASH_SIZE PM_MCUBOOT_SECONDARY_SIZE

#define UTC_OFFSET_STR_LEN 7 /* '+00:00' + '\0' = 7 */
Expand Down Expand Up @@ -47,9 +50,24 @@ static int device_factory_default_cb(uint16_t obj_inst_id, uint8_t *args, uint16

int lwm2m_app_init_device(char *serial_num)
{
char *client_sw_ver = (strlen(CONFIG_APP_CUSTOM_VERSION) > 0) ?
const void *hw_str = CONFIG_SOC;
uint16_t hw_str_len = sizeof(CONFIG_SOC);
const char *client_sw_ver = (strlen(CONFIG_APP_CUSTOM_VERSION) > 0) ?
CONFIG_APP_CUSTOM_VERSION : NCS_VERSION_STRING;

if (IS_ENABLED(CONFIG_SOC_SERIES_NRF91X)) {
int err;
static char hw_buf[sizeof("nRF91__ ____ ___ ")];

err = modem_info_get_hw_version(hw_buf, sizeof(hw_buf));
if (err == 0) {
hw_str = hw_buf;
hw_str_len = strlen(hw_buf) + 1;
} else {
LOG_ERR("modem_info_get_hw_version() failed, err %d", err);
}
}

lwm2m_set_res_buf(&LWM2M_OBJ(LWM2M_OBJECT_DEVICE_ID, 0, MANUFACTURER_RID),
CONFIG_APP_MANUFACTURER, sizeof(CONFIG_APP_MANUFACTURER),
sizeof(CONFIG_APP_MANUFACTURER), LWM2M_RES_DATA_FLAG_RO);
Expand All @@ -70,13 +88,12 @@ int lwm2m_app_init_device(char *serial_num)
CONFIG_APP_DEVICE_TYPE, sizeof(CONFIG_APP_DEVICE_TYPE),
sizeof(CONFIG_APP_DEVICE_TYPE), LWM2M_RES_DATA_FLAG_RO);
lwm2m_set_res_buf(&LWM2M_OBJ(LWM2M_OBJECT_DEVICE_ID, 0, HARDWARE_VERSION_RID),
CLIENT_HW_VER, sizeof(CLIENT_HW_VER), sizeof(CLIENT_HW_VER),
LWM2M_RES_DATA_FLAG_RO);
(void *)hw_str, hw_str_len, hw_str_len, LWM2M_RES_DATA_FLAG_RO);
lwm2m_set_res_buf(&LWM2M_OBJ(LWM2M_OBJECT_DEVICE_ID, 0, SOFTWARE_VERSION_RID),
client_sw_ver, strlen(client_sw_ver) + 1,
(void *)client_sw_ver, strlen(client_sw_ver) + 1,
strlen(client_sw_ver) + 1, LWM2M_RES_DATA_FLAG_RO);
lwm2m_set_res_buf(&LWM2M_OBJ(LWM2M_OBJECT_DEVICE_ID, 0, BATTERY_STATUS_RID),
&bat_status, sizeof(bat_status), sizeof(bat_status), 0);
lwm2m_set_res_buf(&LWM2M_OBJ(LWM2M_OBJECT_DEVICE_ID, 0, BATTERY_STATUS_RID), &bat_status,
sizeof(bat_status), sizeof(bat_status), 0);
lwm2m_set_res_buf(&LWM2M_OBJ(LWM2M_OBJECT_DEVICE_ID, 0, MEMORY_TOTAL_RID),
&mem_total, sizeof(mem_total), sizeof(mem_total), 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ int lwm2m_adv_firmware_create_inst(const char *component, lwm2m_engine_set_data_
return ret;
}

len = strlen(component);
len = strlen(component) + 1;
ret = lwm2m_set_res_buf(&LWM2M_OBJ(LWM2M_OBJECT_ADV_FIRMWARE_ID, idx,
FIRMWARE_COMPONENT_NAME_ID), (void *)component, len, len,
LWM2M_RES_DATA_FLAG_RO);
Expand Down
10 changes: 8 additions & 2 deletions subsys/net/lib/lwm2m_client_utils/lwm2m/lwm2m_firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <zephyr/net/lwm2m.h>
#include <modem/nrf_modem_lib.h>
#include <modem/modem_key_mgmt.h>
#include <modem/modem_info.h>
#include <net/fota_download.h>
#include <fota_download_util.h>
#include <lwm2m_util.h>
Expand Down Expand Up @@ -1266,8 +1267,13 @@ int lwm2m_init_firmware_cb(lwm2m_firmware_event_cb_t cb)
"application", firmware_block_received_cb, firmware_update_cb);
lwm2m_firmware_object_setup_init(application_obj_id);

modem_obj_id = lwm2m_adv_firmware_create_inst(
"modem:" CONFIG_SOC, firmware_block_received_cb, firmware_update_cb);
static char hw_buf[sizeof("modem:nRF91__ ____ ___ ")];

strcat(hw_buf, "modem:");
modem_info_get_hw_version(hw_buf + strlen("modem:"), sizeof(hw_buf) - strlen("modem:"));

modem_obj_id = lwm2m_adv_firmware_create_inst(hw_buf, firmware_block_received_cb,
firmware_update_cb);
lwm2m_firmware_object_setup_init(modem_obj_id);

lwm2m_adv_modem_firmware_versions_set();
Expand Down
1 change: 1 addition & 0 deletions tests/subsys/net/lib/lwm2m_fota_utils/src/stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ DEFINE_FAKE_VALUE_FUNC(int, modem_info_init);
DEFINE_FAKE_VALUE_FUNC(int, modem_info_params_init, struct modem_param_info *);
DEFINE_FAKE_VALUE_FUNC(int, modem_info_params_get, struct modem_param_info *);
DEFINE_FAKE_VALUE_FUNC(int, modem_info_rsrp_register, rsrp_cb_t);
DEFINE_FAKE_VALUE_FUNC(int, modem_info_get_hw_version, char *, uint8_t);
DEFINE_FAKE_VOID_FUNC(engine_trigger_update, bool);
DEFINE_FAKE_VALUE_FUNC(int, dfu_target_mcuboot_set_buf, uint8_t *, size_t);
DEFINE_FAKE_VALUE_FUNC(int, nrf_modem_lib_shutdown);
Expand Down
17 changes: 10 additions & 7 deletions tests/subsys/net/lib/lwm2m_fota_utils/src/stubs.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ DECLARE_FAKE_VOID_FUNC(engine_trigger_update, bool);
DECLARE_FAKE_VALUE_FUNC(int, modem_info_init);
DECLARE_FAKE_VALUE_FUNC(int, modem_info_params_init, struct modem_param_info *);
DECLARE_FAKE_VALUE_FUNC(int, modem_info_params_get, struct modem_param_info *);
DECLARE_FAKE_VALUE_FUNC(int, modem_info_get_hw_version, char *, uint8_t);
DECLARE_FAKE_VALUE_FUNC(int, lte_lc_lte_mode_get, enum lte_lc_lte_mode *);
DECLARE_FAKE_VALUE_FUNC(int, modem_info_rsrp_register, rsrp_cb_t);
DECLARE_FAKE_VALUE_FUNC(int, dfu_target_mcuboot_set_buf, uint8_t *, size_t);
Expand Down Expand Up @@ -93,6 +94,7 @@ DECLARE_FAKE_VALUE_FUNC(int, fota_download_util_image_schedule, enum dfu_target_
DECLARE_FAKE_VALUE_FUNC(int, fota_download_util_image_reset, enum dfu_target_image_type);
DECLARE_FAKE_VALUE_FUNC(int, fota_download_util_apply_update, enum dfu_target_image_type);


/* List of fakes used by this unit tester */
#define DO_FOREACH_FAKE(FUNC) \
do { \
Expand Down Expand Up @@ -155,13 +157,14 @@ DECLARE_FAKE_VALUE_FUNC(int, fota_download_util_apply_update, enum dfu_target_im
FUNC(lwm2m_notify_observer_path) \
FUNC(engine_remove_observer_by_id) \
FUNC(lwm2m_firmware_start_transfer) \
FUNC(fota_download_util_stream_init) \
FUNC(fota_download_util_dfu_target_init) \
FUNC(fota_download_util_download_start) \
FUNC(fota_download_util_download_cancel) \
FUNC(fota_download_util_image_schedule) \
FUNC(fota_download_util_image_reset) \
FUNC(fota_download_util_apply_update) \
FUNC(fota_download_util_stream_init) \
FUNC(fota_download_util_dfu_target_init) \
FUNC(fota_download_util_download_start) \
FUNC(fota_download_util_download_cancel) \
FUNC(fota_download_util_image_schedule) \
FUNC(fota_download_util_image_reset) \
FUNC(fota_download_util_apply_update) \
FUNC(modem_info_get_hw_version) \
} while (0)

#endif

0 comments on commit 713658c

Please sign in to comment.