From 6dcdaf17fe9ed607f48d8288ca2068a93d3e51f1 Mon Sep 17 00:00:00 2001 From: schneider Date: Wed, 3 Aug 2011 17:38:30 +0200 Subject: [PATCH] added sendcard l0dable --- firmware/l0dable/EXPORTS | 12 ++ firmware/l0dable/loadable.ld | 2 +- firmware/l0dable/sendcard.c | 284 +++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 firmware/l0dable/sendcard.c diff --git a/firmware/l0dable/EXPORTS b/firmware/l0dable/EXPORTS index 05a3962..ea15048 100644 --- a/firmware/l0dable/EXPORTS +++ b/firmware/l0dable/EXPORTS @@ -35,3 +35,15 @@ push_queue the_config the_queue work_queue +selectFile +nrf_snd_pkt_crc_encr +nrf_rcv_pkt_time_encr +getInput +ECIES_encyptkeygen +f_open +f_read +strlen +strcpy +xxtea_encode_words +getRandom +crc16 diff --git a/firmware/l0dable/loadable.ld b/firmware/l0dable/loadable.ld index fb4d66c..b569c2f 100644 --- a/firmware/l0dable/loadable.ld +++ b/firmware/l0dable/loadable.ld @@ -1,5 +1,5 @@ MEMORY { - sram(rwx): ORIGIN = 0x10002000 - 2048, LENGTH = 2048 + sram(rwx): ORIGIN = 0x10002000 - 2548, LENGTH = 2548 } INCLUDE ram.ld diff --git a/firmware/l0dable/sendcard.c b/firmware/l0dable/sendcard.c new file mode 100644 index 0000000..8bcf110 --- /dev/null +++ b/firmware/l0dable/sendcard.c @@ -0,0 +1,284 @@ +#include +#include +#include +#include +#include +#include "basic/basic.h" +#include "lcd/render.h" +#include "lcd/allfonts.h" +#include "basic/ecc.h" +#include "funk/nrf24l01p.h" +#include "filesystem/ff.h" +#include "filesystem/diskio.h" +#include "funk/filetransfer.h" +#include "lcd/print.h" +#include +#include "funk/nrf24l01p.h" +#include "funk/filetransfer.h" +#include "funk/rftransfer.h" +#include "basic/basic.h" +#include "basic/xxtea.h" +#include "filesystem/ff.h" +#include "funk/rftransfer.h" +#include "funk/nrf24l01p.h" +#include +#include +#include +//#include + +#include "usetable.h" + +//#include "lcd/print.h" + + + +uint8_t mac[5] = {1,2,3,2,1}; + +void ram(void) +{ + char file[13]; + selectFile(file,"TXT"); + sendFile(file); +} + +void sendR(uint8_t *rx, uint8_t *ry) +{ + uint8_t exp[2 + 4*NUMWORDS + 2]; + exp[0] = 'R'; + for(int i=0; i<4*NUMWORDS; i++) + exp[2+i] = rx[i]; + exp[1] = 'X'; + nrf_snd_pkt_crc(32, exp); + delayms(10); + exp[1] = 'Y'; + for(int i=0; i<4*NUMWORDS; i++) + exp[2+i] = ry[i]; + nrf_snd_pkt_crc(32, exp); + delayms(10); +} + +int receiveKey(uint8_t type, uint8_t *x, uint8_t *y) +{ + uint8_t buf[32]; + uint8_t n; + + n = nrf_rcv_pkt_time(1000, 32, buf); + if( n == 32 && buf[0] == type && buf[1] == 'X' ){ + for(int i=0; i MAXSIZE ) + return 1; //File to big + + res=f_open(&file, (const char*)filename, FA_OPEN_EXISTING|FA_READ); + if( res ) + return res; + + //res = f_read(&file, (char *)buf, size, &readbytes); + for(uint16_t i=0; i> 8; + metadata[21] = size & 0xFF; + + //nrf_get_tx_max(5,macbuf); + + //nrf_set_tx_mac(5, mac); + nrf_snd_pkt_crc_encr(32, metadata, k); + delayms(20); + xxtea_encode_words((uint32_t *)buf, wordcount, k); + rftransfer_send(wordcount*4, buf); + //nrf_set_tx_mac(5, macbuf); + return 0; +} + +#define MAXPACKET 32 +void rftransfer_send(uint16_t size, uint8_t *data) +{ + uint8_t buf[MAXPACKET]; + buf[0] = 'L'; + buf[1] = size >> 8; + buf[2] = size & 0xFF; + + uint16_t rand = getRandom() & 0xFFFF; + buf[3] = rand >> 8; + buf[4] = rand & 0xFF; + + nrf_snd_pkt_crc(32,buf); //setup packet + delayms(20); + uint16_t index = 0; + uint8_t i; + uint16_t crc = crc16(data,size); + + while(size){ + buf[0] = 'D'; + buf[1] = index >> 8; + buf[2] = index & 0xFF; + buf[3] = rand >> 8; + buf[4] = rand & 0xFF; + for(i=5; i0; i++,size--){ + buf[i] = *data++; + } + index++; + nrf_snd_pkt_crc(32,buf); //data packet + delayms(20); + } + + buf[0] = 'C'; + buf[1] = crc >> 8; + buf[2] = crc & 0xFF; + buf[3] = rand >> 8; + buf[4] = rand & 0xFF; + nrf_snd_pkt_crc(32,buf); //setup packet + delayms(20); +} +