summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ao.h59
-rw-r--r--src/core/ao_cmd.c44
-rw-r--r--src/core/ao_config.c36
-rw-r--r--src/core/ao_task.c7
4 files changed, 133 insertions, 13 deletions
diff --git a/src/core/ao.h b/src/core/ao.h
index 2898852b..a5bbb6f1 100644
--- a/src/core/ao.h
+++ b/src/core/ao.h
@@ -68,6 +68,10 @@ ao_wakeup(__xdata void *wchan);
void
ao_alarm(uint16_t delay);
+/* Clear any pending alarm */
+void
+ao_clear_alarm(void);
+
/* Yield the processor to another task */
void
ao_yield(void) ao_arch_naked_declare;
@@ -342,6 +346,12 @@ ao_cmd_put16(uint16_t v);
void
ao_cmd_white(void);
+int8_t
+ao_cmd_hexchar(char c);
+
+void
+ao_cmd_hexbyte(void);
+
void
ao_cmd_hex(void);
@@ -1417,6 +1427,14 @@ enum ao_igniter_status {
ao_igniter_open, /* open circuit detected */
};
+struct ao_ignition {
+ uint8_t request;
+ uint8_t fired;
+ uint8_t firing;
+};
+
+extern __xdata struct ao_ignition ao_ignition[2];
+
enum ao_igniter_status
ao_igniter_status(enum ao_igniter igniter);
@@ -1431,7 +1449,8 @@ ao_igniter_init(void);
*/
#define AO_CONFIG_MAJOR 1
-#define AO_CONFIG_MINOR 8
+#define AO_CONFIG_MINOR 9
+#define AO_AES_LEN 16
struct ao_config {
uint8_t major;
@@ -1448,6 +1467,7 @@ struct ao_config {
uint8_t pad_orientation; /* minor version 6 */
uint32_t radio_setting; /* minor version 7 */
uint8_t radio_enable; /* minor version 8 */
+ uint8_t aes_key[AO_AES_LEN]; /* minor version 9 */
};
#define AO_IGNITE_MODE_DUAL 0
@@ -1635,8 +1655,6 @@ __xdata uint8_t ao_aes_mutex;
/* AES keys and blocks are 128 bits */
-#define AO_AES_LEN 16
-
enum ao_aes_mode {
ao_aes_mode_cbc_mac
};
@@ -1664,10 +1682,45 @@ ao_aes_init(void);
/* ao_radio_cmac.c */
+int8_t
+ao_radio_cmac_send(__xdata void *packet, uint8_t len) __reentrant;
+
+#define AO_RADIO_CMAC_OK 0
+#define AO_RADIO_CMAC_LEN_ERROR -1
+#define AO_RADIO_CMAC_CRC_ERROR -2
+#define AO_RADIO_CMAC_MAC_ERROR -3
+#define AO_RADIO_CMAC_TIMEOUT -4
+
+int8_t
+ao_radio_cmac_recv(__xdata void *packet, uint8_t len, uint16_t timeout) __reentrant;
+
void
ao_radio_cmac_init(void);
/* ao_launch.c */
+
+struct ao_launch_command {
+ uint16_t tick;
+ uint16_t serial;
+ uint8_t cmd;
+ uint8_t channel;
+ uint16_t unused;
+};
+
+#define AO_LAUNCH_QUERY 1
+
+struct ao_launch_query {
+ uint16_t tick;
+ uint16_t serial;
+ uint8_t channel;
+ uint8_t valid;
+ uint8_t arm_status;
+ uint8_t igniter_status;
+};
+
+#define AO_LAUNCH_ARM 2
+#define AO_LAUNCH_FIRE 3
+
void
ao_launch_init(void);
diff --git a/src/core/ao_cmd.c b/src/core/ao_cmd.c
index 7663d875..9e14c221 100644
--- a/src/core/ao_cmd.c
+++ b/src/core/ao_cmd.c
@@ -22,7 +22,7 @@ __pdata uint32_t ao_cmd_lex_u32;
__pdata char ao_cmd_lex_c;
__pdata enum ao_cmd_status ao_cmd_status;
-#define CMD_LEN 32
+#define CMD_LEN 48
static __xdata char cmd_line[CMD_LEN];
static __pdata uint8_t cmd_len;
@@ -128,22 +128,48 @@ ao_cmd_white(void)
ao_cmd_lex();
}
+int8_t
+ao_cmd_hexchar(char c)
+{
+ if ('0' <= c && c <= '9')
+ return (c - '0');
+ if ('a' <= c && c <= 'f')
+ return (c - 'a' + 10);
+ if ('A' <= c && c <= 'F')
+ return (c - 'A' + 10);
+ return -1;
+}
+
+void
+ao_cmd_hexbyte(void)
+{
+ uint8_t i;
+ int8_t n;
+
+ ao_cmd_lex_i = 0;
+ ao_cmd_white();
+ for (i = 0; i < 2; i++) {
+ n = ao_cmd_hexchar(ao_cmd_lex_c);
+ if (n < 0) {
+ ao_cmd_status = ao_cmd_syntax_error;
+ break;
+ }
+ ao_cmd_lex_i = (ao_cmd_lex_i << 4) | n;
+ ao_cmd_lex();
+ }
+}
+
void
ao_cmd_hex(void)
{
__pdata uint8_t r = ao_cmd_lex_error;
- uint8_t n;
+ int8_t n;
ao_cmd_lex_i = 0;
ao_cmd_white();
for(;;) {
- if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9')
- n = (ao_cmd_lex_c - '0');
- else if ('a' <= ao_cmd_lex_c && ao_cmd_lex_c <= 'f')
- n = (ao_cmd_lex_c - 'a' + 10);
- else if ('A' <= ao_cmd_lex_c && ao_cmd_lex_c <= 'F')
- n = (ao_cmd_lex_c - 'A' + 10);
- else
+ n = ao_cmd_hexchar(ao_cmd_lex_c);
+ if (n < 0)
break;
ao_cmd_lex_i = (ao_cmd_lex_i << 4) | n;
r = ao_cmd_success;
diff --git a/src/core/ao_config.c b/src/core/ao_config.c
index ec2b61f6..7f999feb 100644
--- a/src/core/ao_config.c
+++ b/src/core/ao_config.c
@@ -74,11 +74,14 @@ _ao_config_get(void)
if (ao_config.major != AO_CONFIG_MAJOR) {
ao_config.major = AO_CONFIG_MAJOR;
ao_config.minor = 0;
+
+ /* Version 0 stuff */
ao_config.main_deploy = AO_CONFIG_DEFAULT_MAIN_DEPLOY;
ao_config.radio_channel = AO_CONFIG_DEFAULT_RADIO_CHANNEL;
memset(&ao_config.callsign, '\0', sizeof (ao_config.callsign));
memcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN,
sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1);
+ ao_config_dirty = 1;
}
if (ao_config.minor < AO_CONFIG_MINOR) {
/* Fixups for minor version 1 */
@@ -104,6 +107,8 @@ _ao_config_get(void)
ao_config.radio_setting = ao_config.radio_cal;
if (ao_config.minor < 8)
ao_config.radio_enable = TRUE;
+ if (ao_config.minor < 9)
+ memset(&ao_config.aes_key, '\0', AO_AES_LEN);
ao_config.minor = AO_CONFIG_MINOR;
ao_config_dirty = 1;
}
@@ -414,6 +419,33 @@ ao_config_radio_enable_set(void) __reentrant
_ao_config_edit_finish();
}
+#if HAS_AES
+void
+ao_config_key_show(void) __reentrant
+{
+ uint8_t i;
+ printf("AES key: ");
+ for (i = 0; i < AO_AES_LEN; i++)
+ printf ("%02x", ao_config.aes_key[i]);
+ printf("\n");
+}
+
+void
+ao_config_key_set(void) __reentrant
+{
+ uint8_t i;
+
+ _ao_config_edit_start();
+ for (i = 0; i < AO_AES_LEN; i++) {
+ ao_cmd_hexbyte();
+ if (ao_cmd_status != ao_cmd_success)
+ break;
+ ao_config.aes_key[i] = ao_cmd_lex_i;
+ }
+ _ao_config_edit_finish();
+}
+#endif
+
struct ao_config_var {
__code char *str;
void (*set)(void) __reentrant;
@@ -462,6 +494,10 @@ __code struct ao_config_var ao_config_vars[] = {
{ "o <0 antenna up, 1 antenna down>\0Set pad orientation",
ao_config_pad_orientation_set,ao_config_pad_orientation_show },
#endif
+#if HAS_AES
+ { "k <32 hex digits>\0Set AES encryption key",
+ ao_config_key_set, ao_config_key_show },
+#endif
{ "s\0Show",
ao_config_show, 0 },
#if HAS_EEPROM
diff --git a/src/core/ao_task.c b/src/core/ao_task.c
index 32826114..a19a6a6f 100644
--- a/src/core/ao_task.c
+++ b/src/core/ao_task.c
@@ -107,7 +107,6 @@ ao_sleep(__xdata void *wchan)
ao_cur_task->wchan = wchan;
);
ao_yield();
- ao_cur_task->alarm = 0;
if (ao_cur_task->wchan) {
ao_cur_task->wchan = NULL;
return 1;
@@ -136,6 +135,12 @@ ao_alarm(uint16_t delay)
}
void
+ao_clear_alarm(void)
+{
+ ao_cur_task->alarm = 0;
+}
+
+void
ao_exit(void)
{
ao_arch_critical(