Skip to content

Commit 9e6b5cd

Browse files
Jamie McCraecarlescufi
authored andcommitted
mgmt: mcumgr: lib: img: Add image header to callback
This allows an application to inspect a mcumgr img upload command to provide additional information for acceptance or rejection of it, and makes the previous private version compare function public so that application code can call it. Signed-off-by: Jamie McCrae <[email protected]>
1 parent 47850a3 commit 9e6b5cd

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

subsys/mgmt/mcumgr/lib/cmd/img_mgmt/include/img_mgmt/img_mgmt.h

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <inttypes.h>
1111
#include "img_mgmt_config.h"
12+
#include "image.h"
1213
#include "mgmt/mgmt.h"
1314
#include <zcbor_common.h>
1415

@@ -213,15 +214,14 @@ struct img_mgmt_dfu_callbacks_t {
213214
* proceeds. If the callback returns nonzero, the request is rejected with a
214215
* response containing an `rc` value equal to the return code.
215216
*
216-
* @param offset The offset specified by the incoming request.
217-
* @param size The total size of the image being uploaded.
218-
* @param arg Optional argument specified when the callback
219-
* was configured.
217+
* @param req Image upload request structure
218+
* @param action Image upload action structure
220219
*
221-
* @return 0 if the upload request should be accepted; nonzero to reject the request with the
222-
* specified status.
220+
* @return 0 if the upload request should be accepted; nonzero to reject
221+
* the request with the specified status.
223222
*/
224-
typedef int (*img_mgmt_upload_fn)(uint32_t offset, uint32_t size, void *arg);
223+
typedef int (*img_mgmt_upload_fn)(const struct img_mgmt_upload_req req,
224+
const struct img_mgmt_upload_action action);
225225

226226
/**
227227
* @brief Configures a callback that gets called whenever a valid image upload
@@ -233,15 +233,26 @@ typedef int (*img_mgmt_upload_fn)(uint32_t offset, uint32_t size, void *arg);
233233
* response containing an `rc` value equal to the return code.
234234
*
235235
* @param cb The callback to execute on rx of an upload request.
236-
* @param arg Optional argument that gets passed to the callback.
237236
*/
238-
void img_mgmt_set_upload_cb(img_mgmt_upload_fn cb, void *arg);
237+
void img_mgmt_set_upload_cb(img_mgmt_upload_fn cb);
239238
void img_mgmt_register_callbacks(const struct img_mgmt_dfu_callbacks_t *cb_struct);
240239
void img_mgmt_dfu_stopped(void);
241240
void img_mgmt_dfu_started(void);
242241
void img_mgmt_dfu_pending(void);
243242
void img_mgmt_dfu_confirmed(void);
244243

244+
/**
245+
* Compares two image version numbers in a semver-compatible way.
246+
*
247+
* @param a The first version to compare.
248+
* @param b The second version to compare.
249+
*
250+
* @return -1 if a < b
251+
* @return 0 if a = b
252+
* @return 1 if a > b
253+
*/
254+
int img_mgmt_vercmp(const struct image_version *a, const struct image_version *b);
255+
245256
#ifdef CONFIG_IMG_MGMT_VERBOSE_ERR
246257
#define IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action, rsn) ((action)->rc_rsn = (rsn))
247258
#define IMG_MGMT_UPLOAD_ACTION_RC_RSN(action) ((action)->rc_rsn)

subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/img_mgmt.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "img_mgmt_priv.h"
2323
#include "img_mgmt/img_mgmt_config.h"
2424

25-
static void *img_mgmt_upload_arg;
2625
static img_mgmt_upload_fn img_mgmt_upload_cb;
2726

2827
const struct img_mgmt_dfu_callbacks_t *img_mgmt_dfu_callbacks_fn;
@@ -385,7 +384,8 @@ img_mgmt_upload(struct mgmt_ctxt *ctxt)
385384
* request.
386385
*/
387386
if (img_mgmt_upload_cb != NULL) {
388-
rc = img_mgmt_upload_cb(req.off, action.size, img_mgmt_upload_arg);
387+
rc = img_mgmt_upload_cb(req, action);
388+
389389
if (rc != 0) {
390390
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(&action, img_mgmt_err_str_app_reject);
391391
goto end;
@@ -515,10 +515,9 @@ img_mgmt_dfu_confirmed(void)
515515
}
516516

517517
void
518-
img_mgmt_set_upload_cb(img_mgmt_upload_fn cb, void *arg)
518+
img_mgmt_set_upload_cb(img_mgmt_upload_fn cb)
519519
{
520520
img_mgmt_upload_cb = cb;
521-
img_mgmt_upload_arg = arg;
522521
}
523522

524523
void

subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/zephyr_img_mgmt.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,7 @@ img_mgmt_get_unused_slot_area_id(int image)
225225
#error "Unsupported number of images"
226226
#endif
227227

228-
/**
229-
* Compares two image version numbers in a semver-compatible way.
230-
*
231-
* @param a The first version to compare.
232-
* @param b The second version to compare.
233-
*
234-
* @return -1 if a < b
235-
* @return 0 if a = b
236-
* @return 1 if a > b
237-
*/
238-
static int
228+
int
239229
img_mgmt_vercmp(const struct image_version *a, const struct image_version *b)
240230
{
241231
if (a->iv_major < b->iv_major) {

0 commit comments

Comments
 (0)