altos: Make ao_xmem funcs require __xdata void * instead of casting
[fw/altos] / src / core / ao_config.c
index ec2b61f6b7c1367549a0601c766e9d5380607c85..f0a576ee9692289b0784ba9e62a232fb1ab910fc 100644 (file)
@@ -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,
+               ao_xmemset(&ao_config.callsign, '\0', sizeof (ao_config.callsign));
+               ao_xmemcpy(&ao_config.callsign, CODE_TO_XDATA(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;
        }
@@ -143,7 +148,7 @@ ao_config_callsign_set(void) __reentrant
        uint8_t c;
        static __xdata char callsign[AO_MAX_CALLSIGN + 1];
 
-       memset(callsign, '\0', sizeof callsign);
+       ao_xmemset(callsign, '\0', sizeof callsign);
        ao_cmd_white();
        c = 0;
        while (ao_cmd_lex_c != '\n') {
@@ -156,7 +161,7 @@ ao_config_callsign_set(void) __reentrant
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       memcpy(&ao_config.callsign, &callsign,
+       ao_xmemcpy(&ao_config.callsign, &callsign,
               AO_MAX_CALLSIGN + 1);
        _ao_config_edit_finish();
 }
@@ -303,7 +308,7 @@ ao_config_radio_cal_set(void) __reentrant
        _ao_config_edit_finish();
 }
 
-#if HAS_EEPROM && HAS_FLIGHT
+#if HAS_LOG
 void
 ao_config_log_show(void) __reentrant
 {
@@ -331,7 +336,7 @@ ao_config_log_set(void) __reentrant
                _ao_config_edit_finish();
        }
 }
-#endif /* HAS_EEPROM && HAS_FLIGHT */
+#endif /* HAS_LOG */
 
 #if HAS_IGNITE
 void
@@ -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;
@@ -450,7 +482,7 @@ __code struct ao_config_var ao_config_vars[] = {
 #endif /* HAS_ACCEL */
        { "f <cal>\0Radio calib (cal = rf/(xtal/2^16))",
          ao_config_radio_cal_set,      ao_config_radio_cal_show },
-#if HAS_EEPROM && HAS_FLIGHT
+#if HAS_LOG
        { "l <size>\0Flight log size in kB",
          ao_config_log_set,            ao_config_log_show },
 #endif
@@ -461,6 +493,10 @@ __code struct ao_config_var ao_config_vars[] = {
 #if HAS_ACCEL
        { "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 },
@@ -499,7 +535,8 @@ ao_config_help(void) __reentrant
        for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++)
                printf("%-20s %s\n",
                       ao_config_vars[cmd].str,
-                      ao_config_vars[cmd].str+1+strlen(ao_config_vars[cmd].str));
+                      ao_config_vars[cmd].str+1+
+                      strlen(ao_config_vars[cmd].str));
 }
 
 static void