From 103bd442cefc22138404cc90f7a29aabcfa4ecb4 Mon Sep 17 00:00:00 2001 From: Kyle Sun Date: Fri, 17 May 2019 21:08:00 -0700 Subject: [PATCH] net: lwm2m: Publicize firmware block context This change is to allow access to the firmware block context in order to give the firmware update callback implementation an indication of when to reset the flash context. Additionally, it allows for a validity check between the total expected size downloaded and the actual size downloaded. A simple implementation can check if the block context's current downloaded blocks is equal to the expected block size in order to determine if the flash context needs to be reset. This approach seemed the simplest, and knowing the firmware block context can have other purposes. This has been tested by accessing the block context during the update in the block received callback and confirming that the callback had information regarding the current downloaded bytes. Fixes #16122 Signed-off-by: Kyle Sun --- include/net/lwm2m.h | 7 +++++++ subsys/net/lib/lwm2m/lwm2m_obj_firmware_pull.c | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/net/lwm2m.h b/include/net/lwm2m.h index e70951e8583b..d1b5161d8002 100644 --- a/include/net/lwm2m.h +++ b/include/net/lwm2m.h @@ -323,6 +323,13 @@ void lwm2m_firmware_set_update_cb(lwm2m_engine_user_cb_t cb); * @return A registered callback function to receive the execute event. */ lwm2m_engine_user_cb_t lwm2m_firmware_get_update_cb(void); + +/** + * @brief Get the block context of the current firmware block. + * + * @param[out] ctx A buffer to store the block context. + */ +struct coap_block_context *lwm2m_firmware_get_block_context(); #endif #endif diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_firmware_pull.c b/subsys/net/lib/lwm2m/lwm2m_obj_firmware_pull.c index 5e54aaab018a..f873c9afe4a2 100644 --- a/subsys/net/lib/lwm2m/lwm2m_obj_firmware_pull.c +++ b/subsys/net/lib/lwm2m/lwm2m_obj_firmware_pull.c @@ -464,3 +464,13 @@ int lwm2m_firmware_start_transfer(char *package_uri) return 0; } + +/** + * @brief Get the block context of the current firmware block. + * + * @return A pointer to the firmware block context + */ +struct coap_block_context *lwm2m_firmware_get_block_context() +{ + return &firmware_block_ctx; +}