kfsw-services/src/ftp-parameters/ftp_table.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <errno.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | #include <zephyr/sys/util.h> | ||
| 5 | |||
| 6 | #include <kfsw/services/ftp.h> | ||
| 7 | #include <kfsw/services/parameter.h> | ||
| 8 | |||
| 9 | static uint32_t ftp_transfers; | ||
| 10 | static uint32_t ftp_failures; | ||
| 11 | static uint32_t ftp_bytes; | ||
| 12 | static uint32_t ftp_timeout_ms = CONFIG_KFSW_FTP_TIMEOUT_MS; | ||
| 13 | static uint16_t ftp_chunk_size = KFSW_FTP_CHUNK_SIZE; | ||
| 14 | static uint8_t ftp_busy; | ||
| 15 | static char ftp_root[] = KFSW_FTP_STORAGE_ROOT; | ||
| 16 | |||
| 17 | ✗ | static void sample_stats(void) | |
| 18 | { | ||
| 19 | struct kfsw_ftp_stats stats; | ||
| 20 | |||
| 21 | ✗ | if (kfsw_ftp_get_stats(&stats) != 0) { | |
| 22 | ✗ | return; | |
| 23 | } | ||
| 24 | ✗ | ftp_transfers = stats.transfers; | |
| 25 | ✗ | ftp_failures = stats.failures; | |
| 26 | ✗ | ftp_bytes = stats.bytes; | |
| 27 | ✗ | ftp_busy = stats.busy ? 1U : 0U; | |
| 28 | } | ||
| 29 | |||
| 30 | #define FTP_SAMPLE(field, type) \ | ||
| 31 | static void sample_##field(void *value) \ | ||
| 32 | { \ | ||
| 33 | sample_stats(); \ | ||
| 34 | *(type *)value = ftp_##field; \ | ||
| 35 | } | ||
| 36 | |||
| 37 | ✗ | FTP_SAMPLE(transfers, uint32_t) | |
| 38 | ✗ | FTP_SAMPLE(failures, uint32_t) | |
| 39 | ✗ | FTP_SAMPLE(bytes, uint32_t) | |
| 40 | ✗ | FTP_SAMPLE(busy, uint8_t) | |
| 41 | |||
| 42 | ✗ | static void sample_timeout(void *value) | |
| 43 | { | ||
| 44 | ✗ | *(uint32_t *)value = kfsw_ftp_get_timeout_ms(); | |
| 45 | ✗ | } | |
| 46 | |||
| 47 | 2 | static void sample_chunk_size(void *value) | |
| 48 | { | ||
| 49 | 2 | *(uint16_t *)value = kfsw_ftp_get_chunk_size(); | |
| 50 | 2 | } | |
| 51 | |||
| 52 | /* Validators refuse bad values before they are stored. */ | ||
| 53 | 2 | static int validate_timeout(const union kfsw_param_scalar *value) | |
| 54 | { | ||
| 55 | 2 | return kfsw_ftp_check_timeout_ms(value->u32); | |
| 56 | } | ||
| 57 | |||
| 58 | 2 | static void apply_timeout(const union kfsw_param_scalar *value) | |
| 59 | { | ||
| 60 | 2 | (void)kfsw_ftp_set_timeout_ms(value->u32); | |
| 61 | 2 | } | |
| 62 | |||
| 63 | 8 | static int validate_chunk_size(const union kfsw_param_scalar *value) | |
| 64 | { | ||
| 65 | 8 | return kfsw_ftp_check_chunk_size(value->u16); | |
| 66 | } | ||
| 67 | |||
| 68 | 4 | static void apply_chunk_size(const union kfsw_param_scalar *value) | |
| 69 | { | ||
| 70 | 4 | (void)kfsw_ftp_set_chunk_size(value->u16); | |
| 71 | 4 | } | |
| 72 | |||
| 73 | static const struct kfsw_param_definition ftp_param_definitions[] = { | ||
| 74 | { | ||
| 75 | .offset = 0x00U, | ||
| 76 | .type = KFSW_PARAM_U32, | ||
| 77 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 78 | .name = "ftp_transfers", | ||
| 79 | .description = "Transfers that committed, in either direction", | ||
| 80 | .value = &ftp_transfers, | ||
| 81 | .sample = sample_transfers, | ||
| 82 | }, | ||
| 83 | { | ||
| 84 | .offset = 0x04U, | ||
| 85 | .type = KFSW_PARAM_U32, | ||
| 86 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 87 | .name = "ftp_failures", | ||
| 88 | .description = "Transfers that failed or were abandoned", | ||
| 89 | .value = &ftp_failures, | ||
| 90 | .sample = sample_failures, | ||
| 91 | }, | ||
| 92 | { | ||
| 93 | .offset = 0x08U, | ||
| 94 | .type = KFSW_PARAM_U32, | ||
| 95 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 96 | .name = "ftp_bytes", | ||
| 97 | .unit = "B", | ||
| 98 | .description = "Bytes moved by transfers that committed", | ||
| 99 | .value = &ftp_bytes, | ||
| 100 | .sample = sample_bytes, | ||
| 101 | }, | ||
| 102 | { | ||
| 103 | .offset = 0x0cU, | ||
| 104 | .type = KFSW_PARAM_U32, | ||
| 105 | .flags = KFSW_PARAM_FLAG_CONFIGURATION, | ||
| 106 | .name = "ftp_timeout_ms", | ||
| 107 | .unit = "ms", | ||
| 108 | .description = "Reply timeout for new transfers; a running one keeps its value", | ||
| 109 | .value = &ftp_timeout_ms, | ||
| 110 | .default_value = {.u32 = CONFIG_KFSW_FTP_TIMEOUT_MS}, | ||
| 111 | .validate = validate_timeout, | ||
| 112 | .changed = apply_timeout, | ||
| 113 | .sample = sample_timeout, | ||
| 114 | }, | ||
| 115 | { | ||
| 116 | .offset = 0x10U, | ||
| 117 | .type = KFSW_PARAM_U16, | ||
| 118 | .flags = KFSW_PARAM_FLAG_CONFIGURATION, | ||
| 119 | .name = "ftp_chunk_size", | ||
| 120 | .unit = "B", | ||
| 121 | .description = "File data per message; can only be shortened", | ||
| 122 | .value = &ftp_chunk_size, | ||
| 123 | .default_value = {.u16 = KFSW_FTP_CHUNK_SIZE}, | ||
| 124 | .validate = validate_chunk_size, | ||
| 125 | .changed = apply_chunk_size, | ||
| 126 | .sample = sample_chunk_size, | ||
| 127 | }, | ||
| 128 | { | ||
| 129 | .offset = 0x12U, | ||
| 130 | .type = KFSW_PARAM_U8, | ||
| 131 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 132 | .name = "ftp_busy", | ||
| 133 | .description = "Whether the server is handling a transfer", | ||
| 134 | .value = &ftp_busy, | ||
| 135 | .sample = sample_busy, | ||
| 136 | }, | ||
| 137 | { | ||
| 138 | .offset = 0x20U, | ||
| 139 | .type = KFSW_PARAM_STRING, | ||
| 140 | .capacity = sizeof(ftp_root), | ||
| 141 | /* Read-only: the path resolver uses a compile-time string. */ | ||
| 142 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 143 | .name = "ftp_root", | ||
| 144 | .description = "Sandbox the service resolves every path against", | ||
| 145 | .value = ftp_root, | ||
| 146 | .default_text = KFSW_FTP_STORAGE_ROOT, | ||
| 147 | }, | ||
| 148 | }; | ||
| 149 | |||
| 150 | KFSW_PARAM_TABLE_FITS_THE_LINK(ftp_param_definitions); | ||
| 151 | |||
| 152 | const struct kfsw_param_definition_set kfsw_ftp_param_definitions = { | ||
| 153 | .table = KFSW_FTP_PARAM_TABLE_ID, | ||
| 154 | .name = KFSW_FTP_PARAM_TABLE_NAME, | ||
| 155 | .description = "File transfers and limits", | ||
| 156 | .definitions = ftp_param_definitions, | ||
| 157 | .count = ARRAY_SIZE(ftp_param_definitions), | ||
| 158 | }; | ||
| 159 |