1 /*
2  * Copyright (c) 2018-2021 mcumgr authors
3  * Copyright (c) 2022-2023 Nordic Semiconductor ASA
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #ifndef H_MGMT_MGMT_DEFINES_
9 #define H_MGMT_MGMT_DEFINES_
10 
11 #include <inttypes.h>
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /**
18  * @brief MCUmgr mgmt API
19  * @defgroup mcumgr_mgmt_api MCUmgr mgmt API
20  * @ingroup mcumgr
21  * @{
22  */
23 
24 /**
25  * Used at end of MCUmgr handlers to return an error if the message size limit was reached,
26  * or OK if it was not
27  */
28 #define MGMT_RETURN_CHECK(ok) ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE
29 
30 /** Opcodes; encoded in first byte of header. */
31 enum mcumgr_op_t {
32 	/** Read op-code */
33 	MGMT_OP_READ		= 0,
34 
35 	/** Read response op-code */
36 	MGMT_OP_READ_RSP,
37 
38 	/** Write op-code */
39 	MGMT_OP_WRITE,
40 
41 	/** Write response op-code */
42 	MGMT_OP_WRITE_RSP,
43 };
44 
45 /**
46  * MCUmgr groups. The first 64 groups are reserved for system level mcumgr
47  * commands. Per-user commands are then defined after group 64.
48  */
49 enum mcumgr_group_t {
50 	/** OS (operating system) group */
51 	MGMT_GROUP_ID_OS	= 0,
52 
53 	/** Image management group, used for uploading firmware images */
54 	MGMT_GROUP_ID_IMAGE,
55 
56 	/** Statistic management group, used for retrieving statistics */
57 	MGMT_GROUP_ID_STAT,
58 
59 	/** Settings management (config) group, used for reading/writing settings */
60 	MGMT_GROUP_ID_SETTINGS,
61 
62 	/** Log management group (unused) */
63 	MGMT_GROUP_ID_LOG,
64 
65 	/** Crash group (unused) */
66 	MGMT_GROUP_ID_CRASH,
67 
68 	/** Split image management group (unused) */
69 	MGMT_GROUP_ID_SPLIT,
70 
71 	/** Run group (unused) */
72 	MGMT_GROUP_ID_RUN,
73 
74 	/** FS (file system) group, used for performing file IO operations */
75 	MGMT_GROUP_ID_FS,
76 
77 	/** Shell management group, used for executing shell commands */
78 	MGMT_GROUP_ID_SHELL,
79 
80 	/** Enumeration management group, used for listing supported command groups */
81 	MGMT_GROUP_ID_ENUM,
82 
83 	/** User groups defined from 64 onwards */
84 	MGMT_GROUP_ID_PERUSER	= 64,
85 
86 	/** Zephyr-specific groups decrease from PERUSER to avoid collision with upstream and
87 	 *  user-defined groups.
88 	 *  Zephyr-specific: Basic group
89 	 */
90 	ZEPHYR_MGMT_GRP_BASIC	= (MGMT_GROUP_ID_PERUSER - 1),
91 };
92 
93 /**
94  * MCUmgr error codes.
95  */
96 enum mcumgr_err_t {
97 	/** No error (success). */
98 	MGMT_ERR_EOK		= 0,
99 
100 	/** Unknown error. */
101 	MGMT_ERR_EUNKNOWN,
102 
103 	/** Insufficient memory (likely not enough space for CBOR object). */
104 	MGMT_ERR_ENOMEM,
105 
106 	/** Error in input value. */
107 	MGMT_ERR_EINVAL,
108 
109 	/** Operation timed out. */
110 	MGMT_ERR_ETIMEOUT,
111 
112 	/** No such file/entry. */
113 	MGMT_ERR_ENOENT,
114 
115 	/** Current state disallows command. */
116 	MGMT_ERR_EBADSTATE,
117 
118 	/** Response too large. */
119 	MGMT_ERR_EMSGSIZE,
120 
121 	/** Command not supported. */
122 	MGMT_ERR_ENOTSUP,
123 
124 	/** Corrupt */
125 	MGMT_ERR_ECORRUPT,
126 
127 	/** Command blocked by processing of other command */
128 	MGMT_ERR_EBUSY,
129 
130 	/** Access to specific function, command or resource denied */
131 	MGMT_ERR_EACCESSDENIED,
132 
133 	/** Requested SMP MCUmgr protocol version is not supported (too old) */
134 	MGMT_ERR_UNSUPPORTED_TOO_OLD,
135 
136 	/** Requested SMP MCUmgr protocol version is not supported (too new) */
137 	MGMT_ERR_UNSUPPORTED_TOO_NEW,
138 
139 	/** User errors defined from 256 onwards */
140 	MGMT_ERR_EPERUSER	= 256
141 };
142 
143 #define MGMT_HDR_SIZE		8
144 
145 /**
146  * @}
147  */
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif /* MGMT_MGMT_DEFINES_H_ */
154