diff --git a/firmware/src/common/sa-aes-128.c b/firmware/src/common/sa-aes-128.c index 8b1e6d7..8cfa946 100644 --- a/firmware/src/common/sa-aes-128.c +++ b/firmware/src/common/sa-aes-128.c @@ -15,6 +15,7 @@ Copyright (C) 2015 OLogN Technologies AG 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *******************************************************************************/ +#include "sa-common.h" #include "sa-aes-128.h" const uint8_t rijndael_sbox[256] ZEPTO_PROG_CONSTANT_LOCATION = { @@ -107,7 +108,7 @@ void sa_aes_128_encrypt_block( const uint8_t* key, const uint8_t* _block, uint8_ { uint8_t block[16], ksc[16]; memcpy( block, _block, 16 ); - memcpy( ksc, key, 16 ); + ZEPTO_MEMCPY_FROM_PROGMEM( ksc, key, 16 ); uint8_t rcon = 1; uint8_t i; diff --git a/firmware/src/common/saccp_protocol.c b/firmware/src/common/saccp_protocol.c index 25962fe..28a86b5 100644 --- a/firmware/src/common/saccp_protocol.c +++ b/firmware/src/common/saccp_protocol.c @@ -170,14 +170,16 @@ uint8_t handler_saccp_receive( MEMORY_HANDLE mem_h ) #else // USED_AS_MASTER -#include "../plugins/smart-echo/smart-echo.h" +//#include "../plugins/smart-echo/smart-echo.h" +#include "../sa_bodypart_list.h" -SmartEchoPluginConfig pl_conf; -SmartEchoPluginState pl_state; +//SmartEchoPluginConfig pl_conf; +//SmartEchoPluginState pl_state; void zepto_vm_init() { - smart_echo_plugin_handler_init( (void*)(&pl_conf), (void*)(&pl_state) ); +// smart_echo_plugin_handler_init( (void*)(&pl_conf), (void*)(&pl_state) ); + smart_echo_plugin_handler_init( (void*)(bodyparts[0].ph_config), (void*)(bodyparts[0].ph_state) ); } @@ -229,7 +231,7 @@ void handler_zepto_vm( MEMORY_HANDLE mem_h, uint8_t first_byte ) // handler_zepto_test_plugin( MEMORY_HANDLE_DEFAULT_PLUGIN ); parser_obj po3; zepto_parser_init( &po3, MEMORY_HANDLE_DEFAULT_PLUGIN ); - smart_echo_plugin_handler( &pl_conf, &pl_state, &po3, MEMORY_HANDLE_DEFAULT_PLUGIN/*, WaitingFor* waiting_for*/, first_byte ); + smart_echo_plugin_handler( (void*)(bodyparts[0].ph_config), (void*)(bodyparts[0].ph_state), &po3, MEMORY_HANDLE_DEFAULT_PLUGIN/*, WaitingFor* waiting_for*/, first_byte ); // now we have raw data from plugin; form a frame // TODO: here is a place to form optional headers, if any uint16_t ret_data_sz = zepto_writer_get_response_size( MEMORY_HANDLE_DEFAULT_PLUGIN ); diff --git a/firmware/src/sa-main.c b/firmware/src/sa-main.c index adef58e..4a3a808 100755 --- a/firmware/src/sa-main.c +++ b/firmware/src/sa-main.c @@ -39,11 +39,13 @@ Copyright (C) 2015 OLogN Technologies AG #endif // #include "test-generator.h" #include +#include "zepto_config.h" // TODO: actual key loading, etc -uint8_t sasp_key[16]; +//uint8_t AES_ENCRYPTION_KEY[16]; +DECLARE_AES_ENCRYPTION_KEY // tester_initTestSystem(); @@ -71,7 +73,7 @@ bool sa_main_init() wait_for.wait_packet = 1; TIME_MILLISECONDS16_TO_TIMEVAL( 1000, wait_for.wait_time ); //+++TODO: actual processing throughout the code - memset( sasp_key, 0xab, 16 ); +// memset( AES_ENCRYPTION_KEY, 0xab, 16 ); // SASP_initAtLifeStart( &sasp_data ); // TODO: replace by more extensive restore-from-backup-etc SASP_initAtLifeStart(); // TODO: replace by more extensive restore-from-backup-etc // sagdp_init( &sagdp_data ); @@ -308,7 +310,7 @@ ZEPTO_DEBUG_PRINTF_1( "Processing continued...\n" ); // 2.2. Pass to SASP - ret_code = handler_sasp_receive( sasp_key, pid, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ ); + ret_code = handler_sasp_receive( AES_ENCRYPTION_KEY, pid, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ ); zepto_response_to_request( MEMORY_HANDLE_MAIN_LOOP ); ZEPTO_DEBUG_PRINTF_4( "SASP1: ret: %d; rq_size: %d, rsp_size: %d\n", ret_code, ugly_hook_get_request_size( MEMORY_HANDLE_MAIN_LOOP ), ugly_hook_get_response_size( MEMORY_HANDLE_MAIN_LOOP ) ); @@ -633,7 +635,7 @@ ZEPTO_DEBUG_PRINTF_3( "Processing in progress... (period = %d, time = %d)\n", wa // SASP saspsend: - ret_code = handler_sasp_send( sasp_key, nonce, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ ); + ret_code = handler_sasp_send( AES_ENCRYPTION_KEY, nonce, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ ); zepto_response_to_request( MEMORY_HANDLE_MAIN_LOOP ); ZEPTO_DEBUG_PRINTF_4( "SASP2: ret: %d; rq_size: %d, rsp_size: %d\n", ret_code, ugly_hook_get_request_size( MEMORY_HANDLE_MAIN_LOOP ), ugly_hook_get_response_size( MEMORY_HANDLE_MAIN_LOOP ) ); diff --git a/firmware/src/zepto_config.h b/firmware/src/zepto_config.h new file mode 100644 index 0000000..d9f7481 --- /dev/null +++ b/firmware/src/zepto_config.h @@ -0,0 +1,49 @@ +/******************************************************************************* +Copyright (C) 2015 OLogN Technologies AG + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*******************************************************************************/ + +/******************************************************************************* +THIS FILE IS MANUALLY OR AUTOMATICALLY GENERATED BASED ON DESIRED PLUGIN LIST +*******************************************************************************/ + + + +#if !defined __ZEPTO_CONFIG_H__ +#define __ZEPTO_CONFIG_H__ + +#define DECLARE_AES_ENCRYPTION_KEY \ +const uint8_t AES_ENCRYPTION_KEY[16] ZEPTO_PROG_CONSTANT_LOCATION = \ +{ \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ +}; \ + + +#endif // __ZEPTO_CONFIG_H__ \ No newline at end of file diff --git a/tests/emulator/sa_client_comm_stack.c b/tests/emulator/sa_client_comm_stack.c index 507cc01..9cfbd72 100644 --- a/tests/emulator/sa_client_comm_stack.c +++ b/tests/emulator/sa_client_comm_stack.c @@ -25,6 +25,9 @@ Copyright (C) 2015 OLogN Technologies AG #include "../../firmware/src/common/saccp_protocol.h" #include "test-generator.h" #include +#include "../../firmware/src/zepto_config.h" + +DECLARE_AES_ENCRYPTION_KEY int main_loop() @@ -43,9 +46,9 @@ int main_loop() tester_initTestSystem(); // TODO: actual key loading, etc - uint8_t sasp_key[16]; -// memcpy( sasp_key, "16-byte fake key", 16 ); - memset( sasp_key, 0xab, 16 ); +// uint8_t AES_ENCRYPTION_KEY[16]; +// memcpy( AES_ENCRYPTION_KEY, "16-byte fake key", 16 ); +// memset( AES_ENCRYPTION_KEY, 0xab, 16 ); // timeout_action tact; // tact.action = 0; @@ -210,7 +213,7 @@ int main_loop() } // 2.2. Pass to SASP - ret_code = handler_sasp_receive( sasp_key, pid, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ ); + ret_code = handler_sasp_receive( AES_ENCRYPTION_KEY, pid, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ ); zepto_response_to_request( MEMORY_HANDLE_MAIN_LOOP ); ZEPTO_DEBUG_PRINTF_4( "SASP1: ret: %d; rq_size: %d, rsp_size: %d\n", ret_code, ugly_hook_get_request_size( MEMORY_HANDLE_MAIN_LOOP ), ugly_hook_get_response_size( MEMORY_HANDLE_MAIN_LOOP ) ); @@ -407,7 +410,7 @@ int main_loop() // SASP saspsend: - ret_code = handler_sasp_send( sasp_key, nonce, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ ); + ret_code = handler_sasp_send( AES_ENCRYPTION_KEY, nonce, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ ); zepto_response_to_request( MEMORY_HANDLE_MAIN_LOOP ); ZEPTO_DEBUG_PRINTF_4( "SASP2: ret: %d; rq_size: %d, rsp_size: %d\n", ret_code, ugly_hook_get_request_size( MEMORY_HANDLE_MAIN_LOOP ), ugly_hook_get_response_size( MEMORY_HANDLE_MAIN_LOOP ) );