kfsw-modules/radio-uhf/parameters/radio_uhf_table.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <stdint.h> | ||
| 2 | #include <string.h> | ||
| 3 | #if CONFIG_KFSW_RADIO_UHF_CRYPTO | ||
| 4 | #include "radio_crypto_internal.h" | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <zephyr/sys/util.h> | ||
| 8 | |||
| 9 | #include <kfsw/modules/radio_uhf.h> | ||
| 10 | #include <kfsw/services/parameter.h> | ||
| 11 | |||
| 12 | /* | ||
| 13 | * Radio identity and expected settings. The module doesn't configure or query | ||
| 14 | * the modem, so link_state stays unknown. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #define KFSW_RADIO_UHF_NAME_SIZE 24U | ||
| 18 | |||
| 19 | static char radio_implementation[KFSW_RADIO_UHF_NAME_SIZE]; | ||
| 20 | static char radio_expected_hardware[KFSW_RADIO_UHF_NAME_SIZE]; | ||
| 21 | static uint32_t radio_expected_baud; | ||
| 22 | static uint8_t radio_expected_flow_control; | ||
| 23 | static uint8_t radio_status_available; | ||
| 24 | static uint8_t radio_link_state; | ||
| 25 | |||
| 26 | ✗ | static void copy_name(char *destination, const char *source) | |
| 27 | { | ||
| 28 | ✗ | size_t length = 0U; | |
| 29 | |||
| 30 | ✗ | while ((length + 1U < KFSW_RADIO_UHF_NAME_SIZE) && (source != NULL) && | |
| 31 | ✗ | (source[length] != '\0')) { | |
| 32 | ✗ | destination[length] = source[length]; | |
| 33 | ✗ | length++; | |
| 34 | } | ||
| 35 | ✗ | destination[length] = '\0'; | |
| 36 | ✗ | } | |
| 37 | |||
| 38 | ✗ | static void sample_info(void) | |
| 39 | { | ||
| 40 | struct kfsw_radio_uhf_info info; | ||
| 41 | |||
| 42 | ✗ | if (kfsw_radio_uhf_get_info(&info) != 0) { | |
| 43 | ✗ | return; | |
| 44 | } | ||
| 45 | ✗ | copy_name(radio_implementation, info.implementation); | |
| 46 | ✗ | copy_name(radio_expected_hardware, info.expected_hardware); | |
| 47 | ✗ | radio_expected_baud = info.expected_serial_baud; | |
| 48 | ✗ | radio_expected_flow_control = info.expected_hardware_flow_control ? 1U : 0U; | |
| 49 | ✗ | radio_status_available = info.hardware_status_available ? 1U : 0U; | |
| 50 | ✗ | radio_link_state = (uint8_t)info.link_state; | |
| 51 | } | ||
| 52 | |||
| 53 | ✗ | static void sample_implementation(void *value) | |
| 54 | { | ||
| 55 | ✗ | sample_info(); | |
| 56 | ✗ | copy_name(value, radio_implementation); | |
| 57 | ✗ | } | |
| 58 | |||
| 59 | ✗ | static void sample_expected_hardware(void *value) | |
| 60 | { | ||
| 61 | ✗ | sample_info(); | |
| 62 | ✗ | copy_name(value, radio_expected_hardware); | |
| 63 | ✗ | } | |
| 64 | |||
| 65 | #define RADIO_SAMPLE(field, type) \ | ||
| 66 | static void sample_##field(void *value) \ | ||
| 67 | { \ | ||
| 68 | sample_info(); \ | ||
| 69 | *(type *)value = radio_##field; \ | ||
| 70 | } | ||
| 71 | |||
| 72 | ✗ | RADIO_SAMPLE(expected_baud, uint32_t) | |
| 73 | ✗ | RADIO_SAMPLE(expected_flow_control, uint8_t) | |
| 74 | ✗ | RADIO_SAMPLE(status_available, uint8_t) | |
| 75 | ✗ | RADIO_SAMPLE(link_state, uint8_t) | |
| 76 | |||
| 77 | #if CONFIG_KFSW_RADIO_UHF_CRYPTO | ||
| 78 | static char key_hex[65]; | ||
| 79 | static struct kfsw_radio_crypto_info crypto_info; | ||
| 80 | static uint8_t crypto_enable = 1, crypto_tx = 1, crypto_rx = 1; | ||
| 81 | static uint8_t crypto_key_set, crypto_tx_ready, crypto_rx_ready; | ||
| 82 | static uint32_t crypto_authenticated, crypto_rejected, crypto_replays; | ||
| 83 | static int32_t crypto_error; | ||
| 84 | |||
| 85 | 8 | static void key_changed(const char *text) | |
| 86 | { | ||
| 87 | 8 | radio_crypto_set_key(text); | |
| 88 | 8 | radio_crypto_clear(key_hex, sizeof(key_hex)); | |
| 89 | 8 | } | |
| 90 | |||
| 91 | #define CRYPTO_SAMPLE(name, field, type) \ | ||
| 92 | static void sample_crypto_##name(void *value) \ | ||
| 93 | { \ | ||
| 94 | kfsw_radio_uhf_crypto_get(&crypto_info); \ | ||
| 95 | *(type *)value = (type)crypto_info.field; \ | ||
| 96 | } | ||
| 97 | |||
| 98 | ✗ | CRYPTO_SAMPLE(enable, enabled, uint8_t) | |
| 99 | ✗ | CRYPTO_SAMPLE(tx, encrypt_tx, uint8_t) | |
| 100 | ✗ | CRYPTO_SAMPLE(rx, encrypt_rx, uint8_t) | |
| 101 | ✗ | CRYPTO_SAMPLE(key_set, key_set, uint8_t) | |
| 102 | ✗ | CRYPTO_SAMPLE(tx_ready, tx_ready, uint8_t) | |
| 103 | ✗ | CRYPTO_SAMPLE(rx_ready, rx_ready, uint8_t) | |
| 104 | ✗ | CRYPTO_SAMPLE(authenticated, authenticated, uint32_t) | |
| 105 | ✗ | CRYPTO_SAMPLE(rejected, rejected, uint32_t) | |
| 106 | ✗ | CRYPTO_SAMPLE(replays, replays, uint32_t) | |
| 107 | ✗ | CRYPTO_SAMPLE(error, last_error, int32_t) | |
| 108 | #endif | ||
| 109 | |||
| 110 | static const struct kfsw_param_definition radio_uhf_param_definitions[] = { | ||
| 111 | { | ||
| 112 | .offset = 0x00U, | ||
| 113 | .type = KFSW_PARAM_STRING, | ||
| 114 | .capacity = KFSW_RADIO_UHF_NAME_SIZE, | ||
| 115 | .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_SYSTEM_INFO, | ||
| 116 | .name = "uhf_implementation", | ||
| 117 | .description = "Radio implementation this build selected", | ||
| 118 | .value = radio_implementation, | ||
| 119 | .sample = sample_implementation, | ||
| 120 | }, | ||
| 121 | { | ||
| 122 | .offset = 0x20U, | ||
| 123 | .type = KFSW_PARAM_STRING, | ||
| 124 | .capacity = KFSW_RADIO_UHF_NAME_SIZE, | ||
| 125 | .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_SYSTEM_INFO, | ||
| 126 | .name = "uhf_expected_hardware", | ||
| 127 | .description = "Hardware this composition expects; not a live readback", | ||
| 128 | .value = radio_expected_hardware, | ||
| 129 | .sample = sample_expected_hardware, | ||
| 130 | }, | ||
| 131 | { | ||
| 132 | .offset = 0x40U, | ||
| 133 | .type = KFSW_PARAM_U32, | ||
| 134 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 135 | .name = "uhf_expected_baud", | ||
| 136 | .unit = "baud", | ||
| 137 | .description = "Serial rate the radio profile expects; not applied here", | ||
| 138 | .value = &radio_expected_baud, | ||
| 139 | .sample = sample_expected_baud, | ||
| 140 | }, | ||
| 141 | { | ||
| 142 | .offset = 0x44U, | ||
| 143 | .type = KFSW_PARAM_U8, | ||
| 144 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 145 | .name = "uhf_expected_flow", | ||
| 146 | .description = "Whether the profile expects hardware flow control", | ||
| 147 | .value = &radio_expected_flow_control, | ||
| 148 | .sample = sample_expected_flow_control, | ||
| 149 | }, | ||
| 150 | { | ||
| 151 | .offset = 0x45U, | ||
| 152 | .type = KFSW_PARAM_U8, | ||
| 153 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 154 | .name = "uhf_status_available", | ||
| 155 | .description = "Whether this implementation reads the modem back at all", | ||
| 156 | .value = &radio_status_available, | ||
| 157 | .sample = sample_status_available, | ||
| 158 | }, | ||
| 159 | { | ||
| 160 | .offset = 0x46U, | ||
| 161 | .type = KFSW_PARAM_U8, | ||
| 162 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 163 | .name = "uhf_link_state", | ||
| 164 | /* No readback, so the link state is unknown. */ | ||
| 165 | .description = "unknown, down or up; unknown unless the modem is read back", | ||
| 166 | .value = &radio_link_state, | ||
| 167 | .sample = sample_link_state, | ||
| 168 | }, | ||
| 169 | #if CONFIG_KFSW_RADIO_UHF_CRYPTO | ||
| 170 | { | ||
| 171 | .offset = 0x50U, | ||
| 172 | .type = KFSW_PARAM_STRING, | ||
| 173 | .capacity = sizeof(key_hex), | ||
| 174 | .flags = KFSW_PARAM_FLAG_CONFIGURATION | KFSW_PARAM_FLAG_LOCAL_ONLY, | ||
| 175 | .name = "uhf_key_hex", | ||
| 176 | .description = "Local 64-digit hex key; reads return empty", | ||
| 177 | .value = key_hex, | ||
| 178 | .validate_text = radio_crypto_validate_key, | ||
| 179 | .changed_text = key_changed, | ||
| 180 | }, | ||
| 181 | { | ||
| 182 | .offset = 0x98U, | ||
| 183 | .type = KFSW_PARAM_U8, | ||
| 184 | .flags = KFSW_PARAM_FLAG_CONFIGURATION | KFSW_PARAM_FLAG_LOCAL_ONLY, | ||
| 185 | .name = "uhf_encrypt_enable", | ||
| 186 | .description = "Enable radio packet protection", | ||
| 187 | .value = &crypto_enable, | ||
| 188 | .default_value.u8 = 1, | ||
| 189 | .validate = radio_crypto_validate_switch, | ||
| 190 | .changed = radio_crypto_set_enable, | ||
| 191 | .sample = sample_crypto_enable, | ||
| 192 | }, | ||
| 193 | { | ||
| 194 | .offset = 0x99U, | ||
| 195 | .type = KFSW_PARAM_U8, | ||
| 196 | .flags = KFSW_PARAM_FLAG_CONFIGURATION | KFSW_PARAM_FLAG_LOCAL_ONLY, | ||
| 197 | .name = "uhf_encrypt_tx", | ||
| 198 | .description = "Encrypt transmitted radio packets", | ||
| 199 | .value = &crypto_tx, | ||
| 200 | .default_value.u8 = 1, | ||
| 201 | .validate = radio_crypto_validate_switch, | ||
| 202 | .changed = radio_crypto_set_tx, | ||
| 203 | .sample = sample_crypto_tx, | ||
| 204 | }, | ||
| 205 | { | ||
| 206 | .offset = 0x9aU, | ||
| 207 | .type = KFSW_PARAM_U8, | ||
| 208 | .flags = KFSW_PARAM_FLAG_CONFIGURATION | KFSW_PARAM_FLAG_LOCAL_ONLY, | ||
| 209 | .name = "uhf_encrypt_rx", | ||
| 210 | .description = "Require authenticated encrypted radio packets", | ||
| 211 | .value = &crypto_rx, | ||
| 212 | .default_value.u8 = 1, | ||
| 213 | .validate = radio_crypto_validate_switch, | ||
| 214 | .changed = radio_crypto_set_rx, | ||
| 215 | .sample = sample_crypto_rx, | ||
| 216 | }, | ||
| 217 | { | ||
| 218 | .offset = 0x9bU, | ||
| 219 | .type = KFSW_PARAM_U8, | ||
| 220 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 221 | .name = "uhf_key_set", | ||
| 222 | .value = &crypto_key_set, | ||
| 223 | .sample = sample_crypto_key_set, | ||
| 224 | }, | ||
| 225 | { | ||
| 226 | .offset = 0x9cU, | ||
| 227 | .type = KFSW_PARAM_U8, | ||
| 228 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 229 | .name = "uhf_tx_ready", | ||
| 230 | .value = &crypto_tx_ready, | ||
| 231 | .sample = sample_crypto_tx_ready, | ||
| 232 | }, | ||
| 233 | { | ||
| 234 | .offset = 0x9dU, | ||
| 235 | .type = KFSW_PARAM_U8, | ||
| 236 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 237 | .name = "uhf_rx_ready", | ||
| 238 | .value = &crypto_rx_ready, | ||
| 239 | .sample = sample_crypto_rx_ready, | ||
| 240 | }, | ||
| 241 | { | ||
| 242 | .offset = 0xa0U, | ||
| 243 | .type = KFSW_PARAM_U32, | ||
| 244 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 245 | .name = "uhf_authenticated", | ||
| 246 | .value = &crypto_authenticated, | ||
| 247 | .sample = sample_crypto_authenticated, | ||
| 248 | }, | ||
| 249 | { | ||
| 250 | .offset = 0xa4U, | ||
| 251 | .type = KFSW_PARAM_U32, | ||
| 252 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 253 | .name = "uhf_rejected", | ||
| 254 | .value = &crypto_rejected, | ||
| 255 | .sample = sample_crypto_rejected, | ||
| 256 | }, | ||
| 257 | { | ||
| 258 | .offset = 0xa8U, | ||
| 259 | .type = KFSW_PARAM_U32, | ||
| 260 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 261 | .name = "uhf_replays", | ||
| 262 | .value = &crypto_replays, | ||
| 263 | .sample = sample_crypto_replays, | ||
| 264 | }, | ||
| 265 | { | ||
| 266 | .offset = 0xacU, | ||
| 267 | .type = KFSW_PARAM_I32, | ||
| 268 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 269 | .name = "uhf_crypto_error", | ||
| 270 | .value = &crypto_error, | ||
| 271 | .sample = sample_crypto_error, | ||
| 272 | }, | ||
| 273 | #endif | ||
| 274 | |||
| 275 | }; | ||
| 276 | |||
| 277 | KFSW_PARAM_TABLE_FITS_THE_LINK(radio_uhf_param_definitions); | ||
| 278 | |||
| 279 | const struct kfsw_param_definition_set kfsw_radio_uhf_param_definitions = { | ||
| 280 | .table = KFSW_RADIO_UHF_PARAM_TABLE_ID, | ||
| 281 | .name = KFSW_RADIO_UHF_PARAM_TABLE_NAME, | ||
| 282 | .description = "UHF radio identity, link and encryption", | ||
| 283 | .definitions = radio_uhf_param_definitions, | ||
| 284 | .count = ARRAY_SIZE(radio_uhf_param_definitions), | ||
| 285 | }; | ||
| 286 |