Skip to content

Commit c2b872b

Browse files
nordicjmcarlescufi
authored andcommitted
mgmt: mcumgr: os_mgmt: Switch to new event callback system
Switches to the new event callback system for the os_mgmt functionality and removes the old code. Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
1 parent 986ea39 commit c2b872b

File tree

4 files changed

+22
-42
lines changed

4 files changed

+22
-42
lines changed

include/zephyr/mgmt/mcumgr/mgmt/callbacks.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ typedef int32_t (*mgmt_cb)(uint32_t event, int32_t rc, bool *abort_more, void *d
7474
enum mgmt_cb_groups {
7575
MGMT_EVT_GRP_ALL = 0,
7676
MGMT_EVT_GRP_SMP,
77+
MGMT_EVT_GRP_OS,
7778
MGMT_EVT_GRP_IMG,
7879
MGMT_EVT_GRP_FS,
7980

@@ -139,6 +140,17 @@ enum img_mgmt_group_events {
139140
MGMT_EVT_OP_IMG_MGMT_ALL = MGMT_DEF_EVT_OP_ALL(MGMT_EVT_GRP_IMG),
140141
};
141142

143+
/**
144+
* MGMT event opcodes for operating system management group.
145+
*/
146+
enum os_mgmt_group_events {
147+
/** Callback when a reset command has been received. */
148+
MGMT_EVT_OP_OS_MGMT_RESET = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 0),
149+
150+
/** Used to enable all os_mgmt_group events. */
151+
MGMT_EVT_OP_OS_MGMT_ALL = MGMT_DEF_EVT_OP_ALL(MGMT_EVT_GRP_OS),
152+
};
153+
142154
/**
143155
* MGMT callback struct
144156
*/

subsys/mgmt/mcumgr/lib/cmd/os_mgmt/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ config OS_MGMT_RESET_MS
1919
before performing the reset. This delay allows time for the mcumgr
2020
response to be delivered.
2121

22-
config OS_MGMT_RESET_HOOK
22+
config MCUMGR_GRP_OS_OS_RESET_HOOK
2323
bool "Reset hook"
2424
depends on REBOOT
25+
depends on MCUMGR_MGMT_NOTIFICATION_HOOKS
2526
help
2627
Allows applications to control and get notifications of when a reset
2728
command has been issued via an mcumgr command. With this option

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,11 @@ extern "C" {
2323
#define OS_MGMT_ID_RESET 5
2424
#define OS_MGMT_ID_MCUMGR_PARAMS 6
2525

26-
#ifdef CONFIG_OS_MGMT_RESET_HOOK
27-
/** @typedef os_mgmt_on_reset_evt_cb
28-
* @brief Function to be called on os mgmt reset event.
29-
*
30-
* This callback function is used to notify the application about a pending
31-
* reset request and to authorise or deny it.
32-
*
33-
* @return 0 to allow reset, MGMT_ERR_[...] code to disallow reset.
34-
*/
35-
typedef int (*os_mgmt_on_reset_evt_cb)(void);
36-
#endif
37-
3826
/**
3927
* @brief Registers the OS management command handler group.
4028
*/
4129
void os_mgmt_register_group(void);
4230

43-
#ifdef CONFIG_OS_MGMT_RESET_HOOK
44-
/**
45-
* @brief Register os reset event callback function.
46-
*
47-
* @param cb Callback function or NULL to disable.
48-
*/
49-
void os_mgmt_register_reset_evt_cb(os_mgmt_on_reset_evt_cb cb);
50-
#endif
51-
5231
#ifdef __cplusplus
5332
}
5433
#endif

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

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#include <zephyr/sys/reboot.h>
2121
#endif
2222

23+
#ifdef CONFIG_MCUMGR_MGMT_NOTIFICATION_HOOKS
24+
#include <zephyr/mgmt/mcumgr/mgmt/callbacks.h>
25+
#endif
26+
2327
#include "mgmt/mgmt.h"
2428
#include <smp/smp.h>
2529
#include "os_mgmt/os_mgmt.h"
@@ -41,10 +45,6 @@ static K_TIMER_DEFINE(os_mgmt_reset_timer, os_mgmt_reset_cb, NULL);
4145
*/
4246
#define TASKSTAT_COLUMNS_MAX 20
4347

44-
#ifdef CONFIG_OS_MGMT_RESET_HOOK
45-
static os_mgmt_on_reset_evt_cb os_reset_evt_cb;
46-
#endif
47-
4848
#ifdef CONFIG_OS_MGMT_TASKSTAT
4949
/* Thread iterator information passing structure */
5050
struct thread_iterator_info {
@@ -288,16 +288,11 @@ static void os_mgmt_reset_cb(struct k_timer *timer)
288288

289289
static int os_mgmt_reset(struct smp_streamer *ctxt)
290290
{
291-
#ifdef CONFIG_OS_MGMT_RESET_HOOK
292-
int rc;
293-
294-
if (os_reset_evt_cb != NULL) {
295-
/* Check with application prior to accepting reset */
296-
rc = os_reset_evt_cb();
291+
#if defined(CONFIG_MCUMGR_GRP_OS_OS_RESET_HOOK)
292+
int rc = mgmt_callback_notify(MGMT_EVT_OP_OS_MGMT_RESET, NULL, 0);
297293

298-
if (rc != 0) {
299-
return rc;
300-
}
294+
if (rc != MGMT_ERR_EOK) {
295+
return rc;
301296
}
302297
#endif
303298

@@ -363,10 +358,3 @@ void os_mgmt_module_init(void)
363358
{
364359
os_mgmt_register_group();
365360
}
366-
367-
#ifdef CONFIG_OS_MGMT_RESET_HOOK
368-
void os_mgmt_register_reset_evt_cb(os_mgmt_on_reset_evt_cb cb)
369-
{
370-
os_reset_evt_cb = cb;
371-
}
372-
#endif

0 commit comments

Comments
 (0)