1# Copyright Runtime.io 2018. All rights reserved.
2# Copyright Nordic Semiconductor ASA 2020-2023. All rights reserved.
3# SPDX-License-Identifier: Apache-2.0
4
5# The Kconfig file is dedicated to File System management group of
6# of MCUmgr subsystem and provides Kconfig options to configure
7# group commands behaviour and other aspects.
8#
9# Options defined in this file should be prefixed:
10#  MCUMGR_GRP_FS_ -- general group options;
11#
12# When adding Kconfig options, that control the same feature,
13# try to group them together by the same stem after prefix.
14
15menuconfig MCUMGR_GRP_FS
16	bool "MCUmgr handlers for file management"
17	depends on FILE_SYSTEM
18	select MCUMGR_SMP_CBOR_MIN_DECODING_LEVEL_2
19	help
20	  Enables MCUmgr handlers for file management
21
22	  This option allows MCUmgr clients to access anything in the
23	  file system, including application-stored secrets like
24	  private keys. Use of this feature in production without adequate
25	  protection mechanisms is strongly discouraged (applications can
26	  enable MCUMGR_GRP_FS_FILE_ACCESS_HOOK and register to receive
27	  callbacks when file access is attempted, which they can then filter,
28	  allow, deny or rewrite paths).
29
30if MCUMGR_GRP_FS
31
32choice MCUMGR_GRP_FS_MAX_FILE_SIZE
33	prompt "Maximum file size that could be uploaded/downloaded"
34	default MCUMGR_GRP_FS_MAX_FILE_SIZE_64KB
35	help
36	  Maximum file size that will be allowed to be downloaded from
37	  device.
38	  This option decides on number of bytes that are reserved in
39	  CBOR frame for storage of offset/size of file downloaded.
40
41config MCUMGR_GRP_FS_MAX_FILE_SIZE_64KB
42	bool "<= 64KB"
43	help
44	  Files that have size up to 64KB require 1 to 3 bytes to encode
45	  size/offset within CBOR frame with file chunk.
46
47config MCUMGR_GRP_FS_MAX_FILE_SIZE_4GB
48	bool "<= 4GB"
49	help
50	  Files that have size up to 4GB require 1 to 5 bytes to encode
51	  size/offset within CBOR frame with file chunk.
52
53endchoice
54
55config MCUMGR_GRP_FS_MAX_OFFSET_LEN
56	int
57	default	3 if MCUMGR_GRP_FS_MAX_FILE_SIZE_64KB
58	default 5 if MCUMGR_GRP_FS_MAX_FILE_SIZE_4GB
59	help
60	  Maximal byte length of encoded offset/size, within transferred
61	  CBOR frame containing chunk of downloaded file.
62	  This value affects how much of data will fit into download buffer,
63	  as it selects sizes of fields within headers.
64	  NOTE: This option is hidden intentionally as it is intended
65	  to be assigned from limited set of allowed values, depending on
66	  the selection made in MCUMGR_GRP_FS_MAX_FILE_SIZE menu.
67
68config MCUMGR_GRP_FS_DL_CHUNK_SIZE_LIMIT
69	bool "Setting custom size of download file chunk"
70	help
71	  By default file chunk, that will be read off storage and fit into
72	  MCUmgr frame, is automatically calculated to fit into buffer
73	  of size MCUGMR_TRANSPORT_NETBUF_SIZE with all headers.
74	  Enabling this option allows to set MAXIMUM value that will be
75	  allowed for such chunk.
76	  Look inside fs_mgmt_config.h for details.
77
78if MCUMGR_GRP_FS_DL_CHUNK_SIZE_LIMIT
79
80config MCUMGR_GRP_FS_DL_CHUNK_SIZE
81	int "Maximum chunk size for file downloads"
82	range 65 MCUMGR_TRANSPORT_NETBUF_SIZE
83	default MCUMGR_TRANSPORT_NETBUF_SIZE
84	help
85	  Sets the MAXIMUM size of chunk which will be rounded down to
86	  number of bytes that, with all the required headers, will fit
87	  into MCUMGR_TRANSPORT_NETBUF_SIZE. This means that actual value
88	  might be lower then selected, in which case compiler warning will
89	  be issued.  Look inside fs_mgmt_config.h for details.
90	  Note that header sizes are affected by MCUMGR_GRP_FS_MAX_OFFSET_LEN.
91
92endif
93
94config MCUMGR_GRP_FS_FILE_STATUS
95	bool "File status command"
96	default y
97	help
98	  This command allows a remote device to retrieve the status of a file,
99	  at present only the size of the file is returned (if it exists).
100
101config MCUMGR_GRP_FS_CHECKSUM_HASH
102	bool "Checksum/hash MCUmgr functions"
103	help
104	  Enable this to support the hash/checksum MCUmgr functionality,
105	  individual checksum and hash types need to be enabled below.
106	  Note that this requires enough stack space to buffer data
107	  from the file being read and generate the output hash/checksum.
108
109if MCUMGR_GRP_FS_CHECKSUM_HASH
110
111config MCUMGR_GRP_FS_CHECKSUM_HASH_CHUNK_SIZE
112	int "Checksum calculation buffer size"
113	range 32 16384
114	default 128
115	help
116	  Chunk size of buffer to use when calculating file checksum or hash
117	  (uses stack).
118
119config MCUMGR_GRP_FS_CHECKSUM_IEEE_CRC32
120	bool "IEEE CRC32 checksum support"
121	select CRC
122	default y
123	help
124	  Enable IEEE CRC32 checksum support for MCUmgr.
125
126config MCUMGR_GRP_FS_HASH_SHA256
127	bool "SHA256 hash support"
128	depends on BUILD_WITH_TFM || MBEDTLS_SHA256
129	select PSA_WANT_ALG_SHA_256 if BUILD_WITH_TFM
130	help
131	  Enable SHA256 hash support for MCUmgr.
132
133config MCUMGR_GRP_FS_CHECKSUM_HASH_SUPPORTED_CMD
134	bool "Supported hash/checksum command"
135	select MCUMGR_SMP_CBOR_MIN_ENCODING_LEVEL_3 if ZCBOR_CANONICAL
136	help
137	  Enable the supported hash/checksum command which will return details on
138	  supported hash and checksum types that can be used.
139
140config MCUMGR_GRP_FS_CHECKSUM_HASH_SUPPORTED_MAX_TYPES
141	int "Predicted maximum number of types to return on supported list"
142	default 10
143	depends on MCUMGR_GRP_FS_CHECKSUM_HASH_SUPPORTED_CMD
144	help
145	  This is used for defining CBOR map holding supported hash/checksum info.
146	  The value does not affect memory allocation, it is used by zcbor to
147	  figure out how to encode map depending on its predicted size.
148
149endif
150
151config MCUMGR_GRP_FS_PATH_LEN
152	int "Maximum file path length"
153	default 64
154	help
155	  Limits the maximum path length for file operations, in bytes.  A buffer
156	  of this size gets allocated on the stack during handling of file upload
157	  and download commands.
158
159config MCUMGR_GRP_FS_FILE_ACCESS_HOOK
160	bool "File access hooks"
161	depends on MCUMGR_MGMT_NOTIFICATION_HOOKS
162	help
163	  Allows applications to control file access (e.g. for uploading and
164	  downloading of files) by registering for a callback which is then
165	  triggered whenever a files are accessed using the FS management group
166	  function. This also, optionally, allows re-writing or changing of
167	  supplied file paths.
168	  Note that this may be called multiple times for each file read and
169	  write due to MCUmgr's method of operation with a single file state.
170
171config MCUMGR_GRP_FS_FILE_SEMAPHORE_TAKE_TIME
172	int "File handle semaphore take time (ms)"
173	default 100
174	help
175	  Maximum time (in ms) to acquire the file handle semaphore when a file
176	  upload/download command is used. If unable to acquire the semaphore,
177	  then MGMT_ERR_EBUSY will be returned.
178
179	  Can specify 0 to not wait for the lock and return instantly if it
180	  cannot be acquired.
181
182config MCUMGR_GRP_FS_FILE_AUTOMATIC_IDLE_CLOSE_TIME
183	int "Automatic file handle close time (ms)"
184	default 4000
185	range 1 99999999
186	help
187	  Time (in ms) for a file upload/download to be declared aborted and
188	  file handle cleaned up. Each access to the file will reset the idle
189	  time to 0.
190
191module = MCUMGR_GRP_FS
192module-str = mcumgr_grp_fs
193source "subsys/logging/Kconfig.template.log_config"
194
195endif
196