1 /* 2 * Copyright (c) 2018-2021 mcumgr authors 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef H_FS_MGMT_CONFIG_ 8 #define H_FS_MGMT_CONFIG_ 9 10 /* File chunk needs to fit into the CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE with 11 * all required headers and other data fields. The following data reduces 12 * space available for file chunk in CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE: 13 * MGMT_HDR_SIZE - header that is placed in front of buffer and not 14 * visible by CBOR encoder (see smp_handle_single_req); 15 * 9 + 1 -- bytes taken by marker of CBOR undefined length map and map 16 * terminator (break) character; 17 * 1 + strlen("off") + [1, N] -- CBOR encoded pair of "off" key and 18 * offset value of the chunk within the file; 19 * 1 + strlen("data") + [1, N] -- CBOR encoded "data" key and value 20 * representing that should be <= CONFIG_MCUMGR_GRP_FS_DL_CHUNK_SIZE 21 * 1 + strlen("rc") + 1 -- status code of operation; 22 * 1 + strlen("len") + [1, N] -- CBOR encoded "len" marker and complete 23 * length of a file; this is only sent once when "off" is 0; 24 * 25 * MCUMGR_GRP_FS_DL_CHUNK_SIZE is calculated with most pessimistic estimations, 26 * where CBOR encoding of data takes longest form. 27 */ 28 #define CBOR_AND_OTHER_HDR \ 29 (MGMT_HDR_SIZE + \ 30 (9 + 1) + \ 31 (1 + 3 + CONFIG_MCUMGR_GRP_FS_MAX_OFFSET_LEN) + \ 32 (1 + 4 + CONFIG_MCUMGR_GRP_FS_MAX_OFFSET_LEN) + \ 33 (1 + 2 + 1) + \ 34 (1 + 3 + CONFIG_MCUMGR_GRP_FS_MAX_OFFSET_LEN)) 35 36 #if defined(CONFIG_MCUMGR_GRP_FS_DL_CHUNK_SIZE_LIMIT) 37 #if (CONFIG_MCUMGR_GRP_FS_DL_CHUNK_SIZE + CBOR_AND_OTHER_HDR) > CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE 38 #warning CONFIG_MCUMGR_GRP_FS_DL_CHUNK_SIZE too big, rounding it down. 39 #else 40 #define MCUMGR_GRP_FS_DL_CHUNK_SIZE (CONFIG_MCUMGR_GRP_FS_DL_CHUNK_SIZE) 41 #endif 42 #endif 43 44 #if !defined(MCUMGR_GRP_FS_DL_CHUNK_SIZE) 45 #define MCUMGR_GRP_FS_DL_CHUNK_SIZE (CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE - CBOR_AND_OTHER_HDR) 46 #endif 47 48 #endif 49