Commit 1a96b767 by Sebastian Renner

Log to file for debugging

parent 726359a5
Read following action from stdin: c
Data sent to serial: b'c \x00\x00\x00'
Data sent to serial: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Read following action from stdin: s
Data sent to serial: b's\x00\x00\x00\x00'
Data sent to serial: b''
Read following action from stdin: m
Data sent to serial: b'm\x00\x00\x00\x00'
Data sent to serial: b''
Read following action from stdin: a
Data sent to serial: b'a\x00\x00\x00\x00'
Data sent to serial: b''
Read following action from stdin: k
Data sent to serial: b'k\x10\x00\x00\x00'
Data sent to serial: b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
Read following action from stdin: p
Data sent to serial: b'p\x0f\x00\x00\x00'
Data sent to serial: b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e'
Read following action from stdin: e
Data sent to serial: b'e'
Read following action from stdin: C
Data sent to serial: b'C'
...@@ -52,6 +52,7 @@ unsigned char m[MAX_LEN]; ...@@ -52,6 +52,7 @@ unsigned char m[MAX_LEN];
unsigned long long mlen = 0; unsigned long long mlen = 0;
unsigned char ad[MAX_LEN]; unsigned char ad[MAX_LEN];
unsigned long long adlen = 0; unsigned long long adlen = 0;
unsigned char text[6] = "HELLO";
unsigned char nsec[CRYPTO_NSECBYTES]; unsigned char nsec[CRYPTO_NSECBYTES];
const unsigned long long nslen = CRYPTO_NSECBYTES; const unsigned long long nslen = CRYPTO_NSECBYTES;
...@@ -80,17 +81,12 @@ static void write_serial(const void *src, unsigned int len) { ...@@ -80,17 +81,12 @@ static void write_serial(const void *src, unsigned int len) {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
while (!LL_USART_IsActiveFlag_TXE(USART1)); while (!LL_USART_IsActiveFlag_TXE(USART1));
LL_USART_TransmitData8(USART1, buf[i]); LL_USART_TransmitData8(USART1, buf[i]);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
} }
} }
static void read_variable_serial(unsigned char action) { static void read_variable_serial(unsigned char action) {
uint32_t len; uint32_t len;
read_serial(&len, sizeof(len)); read_serial(&len, sizeof(len));
switch(action) { switch(action) {
case 'k': case 'k':
while (len != CRYPTO_KEYBYTES); while (len != CRYPTO_KEYBYTES);
...@@ -187,7 +183,16 @@ int main(void) ...@@ -187,7 +183,16 @@ int main(void)
read_variable_serial(rcv); read_variable_serial(rcv);
break; break;
case 'C': write_variable_serial(c, clen); break; case 'C':
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
write_variable_serial(c, clen);
break;
case 'M': write_variable_serial(m, mlen); break; case 'M': write_variable_serial(m, mlen); break;
case 'A': write_variable_serial(ad, adlen); break; case 'A': write_variable_serial(ad, adlen); break;
case 'K': write_variable_serial(k, klen); break; case 'K': write_variable_serial(k, klen); break;
...@@ -195,15 +200,30 @@ int main(void) ...@@ -195,15 +200,30 @@ int main(void)
case 'P': write_variable_serial(npub, nplen); break; case 'P': write_variable_serial(npub, nplen); break;
case 'd': case 'd':
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
res = crypto_aead_decrypt(m, &mlen, nsec, c, clen, ad, adlen, npub, k); res = crypto_aead_decrypt(m, &mlen, nsec, c, clen, ad, adlen, npub, k);
break; break;
case 'e': case 'e':
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
res = crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k); res = crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k);
break; break;
default: default:
return 2; LL_mDelay(1);
} }
/* USER CODE END WHILE */ /* USER CODE END WHILE */
} }
......
#!/usr/bin/env python3 #!/usr/bin/python3 -u
import os import os
import sys import sys
...@@ -6,6 +6,8 @@ import struct ...@@ -6,6 +6,8 @@ import struct
import serial import serial
from subprocess import Popen, PIPE, run from subprocess import Popen, PIPE, run
f = open("subprocess.log", "w+")
ser = serial.Serial('/dev/ttyUSB0', 115200) ser = serial.Serial('/dev/ttyUSB0', 115200)
def flash(): def flash():
...@@ -25,6 +27,7 @@ def read(channel, l): ...@@ -25,6 +27,7 @@ def read(channel, l):
def write(channel, data): def write(channel, data):
if channel == 'ser': if channel == 'ser':
l = ser.write(data) l = ser.write(data)
f.write("Data sent to serial: " + str(data) + "\n")
elif channel == 'std': elif channel == 'std':
l = sys.stdout.write(data) l = sys.stdout.write(data)
else: else:
...@@ -47,7 +50,7 @@ def main(): ...@@ -47,7 +50,7 @@ def main():
#flash() #flash()
while(1): while(1):
action = read('std', 1) action = read('std', 1)
if (action): f.write("Read following action from stdin: " + action + "\n")
if action == 'c' or action == 'm' or action == 'a' or action == 'k' or action == 's' or action == 'p': if action == 'c' or action == 'm' or action == 'a' or action == 'k' or action == 's' or action == 'p':
data = obtain('std') data = obtain('std')
submit('ser', action, data) submit('ser', action, data)
...@@ -58,7 +61,9 @@ def main(): ...@@ -58,7 +61,9 @@ def main():
elif action == 'C' or action == 'M' or action == 'A' or action == 'K' or action == 'S' or action == 'P': elif action == 'C' or action == 'M' or action == 'A' or action == 'K' or action == 'S' or action == 'P':
write('ser', str.encode(action)) write('ser', str.encode(action))
data = obtain('ser') data = obtain('ser')
f.write("Obtained following data from serial: " + data + "\n")
submit('std', action, data) submit('std', action, data)
f.write("Submitted following data to stdout: " + data + "\n")
else: else:
raise Exception("no capiche aczione %s" % (action)) raise Exception("no capiche aczione %s" % (action))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment