workrarounds in vcard

This commit is contained in:
schneider 2011-08-06 07:16:03 +02:00
parent 31355b6a4a
commit cf5f06b228
2 changed files with 64 additions and 10 deletions

View File

@ -34,10 +34,8 @@ uint8_t mac[5] = {1,2,3,2,1};
void ram(void) void ram(void)
{ {
memset(0,0,0);
nrf_config_set(&config); nrf_config_set(&config);
if( sendKeys() ) if( sendKeys() )
return; return;
@ -103,9 +101,15 @@ void sendPublicKey(void)
FIL file; FIL file;
if( f_open(&file, "pubx.key", FA_OPEN_EXISTING|FA_READ) ){ if( f_open(&file, "pubx.key", FA_OPEN_EXISTING|FA_READ) ){
lcdPrint("pubx.key");
lcdRefresh();
while(1);
return; return;
} }
if( f_read(&file, buf, 41, &readbytes) || readbytes != 41 ){ if( f_read(&file, buf, 41, &readbytes) || readbytes != 41 ){
lcdPrint("read x");
lcdRefresh();
while(1);
return; return;
} }
f_close(&file); f_close(&file);
@ -114,13 +118,22 @@ void sendPublicKey(void)
exp[0] = 'P'; exp[0] = 'P';
bitstr_parse_export((char*)exp+2, buf); bitstr_parse_export((char*)exp+2, buf);
exp[1] = 'X'; exp[1] = 'X';
nrf_config_set(&config);
nrf_snd_pkt_crc(32, exp); nrf_snd_pkt_crc(32, exp);
delayms(10); delayms(10);
if( f_open(&file, "puby.key", FA_OPEN_EXISTING|FA_READ) ){ if( f_open(&file, "puby.key", FA_OPEN_EXISTING|FA_READ) ){
lcdPrint("puby.key");
lcdRefresh();
while(1);
return; return;
} }
if( f_read(&file, buf, 41, &readbytes) || readbytes != 41 ){ if( f_read(&file, buf, 41, &readbytes) || readbytes != 41 ){
lcdPrint("read x");
lcdRefresh();
while(1);
return; return;
} }
f_close(&file); f_close(&file);
@ -128,6 +141,7 @@ void sendPublicKey(void)
exp[1] = 'Y'; exp[1] = 'Y';
bitstr_parse_export((char*)exp+2, buf); bitstr_parse_export((char*)exp+2, buf);
nrf_config_set(&config);
nrf_snd_pkt_crc(32, exp); nrf_snd_pkt_crc(32, exp);
delayms(10); delayms(10);
} }
@ -138,10 +152,12 @@ int receiveKey(uint8_t type, uint8_t *x, uint8_t *y)
uint8_t buf[32]; uint8_t buf[32];
uint8_t n; uint8_t n;
nrf_config_set(&config);
n = nrf_rcv_pkt_time(1000, 32, buf); n = nrf_rcv_pkt_time(1000, 32, buf);
if( n == 32 && buf[0] == type && buf[1] == 'X' ){ if( n == 32 && buf[0] == type && buf[1] == 'X' ){
for(int i=0; i<NUMWORDS*4; i++) for(int i=0; i<NUMWORDS*4; i++)
x[i] = buf[i+2]; x[i] = buf[i+2];
nrf_config_set(&config);
n = nrf_rcv_pkt_time(100, 32, buf); n = nrf_rcv_pkt_time(100, 32, buf);
if( n == 32 && buf[0] ==type && buf[1] == 'Y' ){ if( n == 32 && buf[0] ==type && buf[1] == 'Y' ){
for(int i=0; i<NUMWORDS*4; i++) for(int i=0; i<NUMWORDS*4; i++)
@ -167,6 +183,7 @@ void sendMac(void)
buf[4] = mac[2]; buf[4] = mac[2];
buf[5] = mac[3]; buf[5] = mac[3];
buf[6] = mac[4]; buf[6] = mac[4];
nrf_config_set(&config);
nrf_snd_pkt_crc(32, buf); nrf_snd_pkt_crc(32, buf);
delayms(10); delayms(10);
} }
@ -177,7 +194,7 @@ int sendKeys(void)
char key; char key;
while( !done ){ while( !done ){
lcdClear(); lcdClear();
lcdPrintln("Sending PUBKEY");lcdRefresh(); lcdPrintln("Sending PUBKEX");lcdRefresh();
sendPublicKey(); sendPublicKey();
sendMac(); sendMac();
lcdPrintln("Done"); lcdPrintln("Done");
@ -217,6 +234,7 @@ int filetransfer_receive(uint8_t *mac, uint32_t const k[4])
uint8_t metadata[32]; uint8_t metadata[32];
//nrf_set_rx_mac(0, 32, 5, mac); //nrf_set_rx_mac(0, 32, 5, mac);
nrf_config_set(&config);
n = nrf_rcv_pkt_time_encr(3000, 32, metadata, k); n = nrf_rcv_pkt_time_encr(3000, 32, metadata, k);
if( n != 32 ) if( n != 32 )
return 1; //timeout return 1; //timeout
@ -279,6 +297,7 @@ int16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout)
unsigned int startTick = currentTick; unsigned int startTick = currentTick;
while(systickGetTicks() < (startTick+timeout) ){//this fails if either overflows while(systickGetTicks() < (startTick+timeout) ){//this fails if either overflows
nrf_config_set(&config);
n = nrf_rcv_pkt_time(1000, MAXPACKET, buf); n = nrf_rcv_pkt_time(1000, MAXPACKET, buf);
switch(state){ switch(state){
case 0: case 0:

View File

@ -43,12 +43,9 @@ uint8_t mac[5] = {1,2,3,2,1};
void ram(void) void ram(void)
{ {
nrf_config_set(&config);
char file[13]; char file[13];
selectFile(file,"TXT"); selectFile(file,"CRD");
nrf_config_set(&config);
sendFile(file); sendFile(file);
} }
@ -60,11 +57,13 @@ void sendR(uint8_t *rx, uint8_t *ry)
for(int i=0; i<4*NUMWORDS; i++) for(int i=0; i<4*NUMWORDS; i++)
exp[2+i] = rx[i]; exp[2+i] = rx[i];
exp[1] = 'X'; exp[1] = 'X';
nrf_config_set(&config);
nrf_snd_pkt_crc(32, exp); nrf_snd_pkt_crc(32, exp);
delayms(10); delayms(10);
exp[1] = 'Y'; exp[1] = 'Y';
for(int i=0; i<4*NUMWORDS; i++) for(int i=0; i<4*NUMWORDS; i++)
exp[2+i] = ry[i]; exp[2+i] = ry[i];
nrf_config_set(&config);
nrf_snd_pkt_crc(32, exp); nrf_snd_pkt_crc(32, exp);
delayms(10); delayms(10);
@ -74,17 +73,47 @@ int receiveKey(uint8_t type, uint8_t *x, uint8_t *y)
{ {
uint8_t buf[32]; uint8_t buf[32];
uint8_t n; uint8_t n;
//static int count = 0;
//for(n=0; n<32;n++)
// buf[n] = 0;
//lcdPrintln("get packet");
//lcdPrintInt(count++);
//lcdRefresh();
//int reg5 = nrf_read_reg(5);
//int reg11 = nrf_read_reg(0x11);
//lcdPrint("reg5=");
//lcdPrintInt(reg5);
//lcdPrintln("");
//lcdPrint("regx11=");
//lcdPrintInt(reg11);
//lcdPrintln("");
//lcdRefresh();
//delayms(1000);
nrf_config_set(&config);
n = nrf_rcv_pkt_time(1000, 32, buf); n = nrf_rcv_pkt_time(1000, 32, buf);
//lcdPrintInt(n);
//lcdPrintln(IntToStrX(*(uint32_t*)buf,8));
//lcdPrintln(IntToStrX(*(uint32_t*)(buf+4),8));
//lcdPrintln(IntToStrX(*(uint32_t*)(buf+8),8));
//lcdPrintln(IntToStrX(*(uint32_t*)(buf+12),8));
//lcdRefresh();
//delayms(1000);
if( n == 32 && buf[0] == type && buf[1] == 'X' ){ if( n == 32 && buf[0] == type && buf[1] == 'X' ){
//lcdPrint("got packet");
//lcdRefresh();
//while(1);
for(int i=0; i<NUMWORDS*4; i++) for(int i=0; i<NUMWORDS*4; i++)
x[i] = buf[i+2]; x[i] = buf[i+2];
nrf_config_set(&config);
n = nrf_rcv_pkt_time(100, 32, buf); n = nrf_rcv_pkt_time(100, 32, buf);
if( n == 32 && buf[0] ==type && buf[1] == 'Y' ){ if( n == 32 && buf[0] ==type && buf[1] == 'Y' ){
for(int i=0; i<NUMWORDS*4; i++) for(int i=0; i<NUMWORDS*4; i++)
y[i] = buf[i+2]; y[i] = buf[i+2];
return 0; return 0;
} }
}else{
} }
return -1; return -1;
} }
@ -104,6 +133,7 @@ void sendMac(void)
buf[4] = mac[2]; buf[4] = mac[2];
buf[5] = mac[3]; buf[5] = mac[3];
buf[6] = mac[4]; buf[6] = mac[4];
nrf_config_set(&config);
nrf_snd_pkt_crc(32, buf); nrf_snd_pkt_crc(32, buf);
delayms(10); delayms(10);
} }
@ -113,6 +143,7 @@ int receiveMac(uint8_t *mac)
uint8_t buf[32]; uint8_t buf[32];
uint8_t n; uint8_t n;
nrf_config_set(&config);
n = nrf_rcv_pkt_time(100, 32, buf); n = nrf_rcv_pkt_time(100, 32, buf);
if( n == 32 && buf[0] == 'M' && buf[1] == 'C' ){ if( n == 32 && buf[0] == 'M' && buf[1] == 'C' ){
for(int i=0; i<5; i++) for(int i=0; i<5; i++)
@ -246,6 +277,7 @@ int filetransfer_send(uint8_t *filename, uint16_t size,
//nrf_get_tx_max(5,macbuf); //nrf_get_tx_max(5,macbuf);
//nrf_set_tx_mac(5, mac); //nrf_set_tx_mac(5, mac);
nrf_config_set(&config);
nrf_snd_pkt_crc_encr(32, metadata, k); nrf_snd_pkt_crc_encr(32, metadata, k);
delayms(20); delayms(20);
xxtea_encode_words((uint32_t *)buf, wordcount, k); xxtea_encode_words((uint32_t *)buf, wordcount, k);
@ -266,6 +298,7 @@ void rftransfer_send(uint16_t size, uint8_t *data)
buf[3] = rand >> 8; buf[3] = rand >> 8;
buf[4] = rand & 0xFF; buf[4] = rand & 0xFF;
nrf_config_set(&config);
nrf_snd_pkt_crc(32,buf); //setup packet nrf_snd_pkt_crc(32,buf); //setup packet
delayms(20); delayms(20);
uint16_t index = 0; uint16_t index = 0;
@ -282,6 +315,7 @@ void rftransfer_send(uint16_t size, uint8_t *data)
buf[i] = *data++; buf[i] = *data++;
} }
index++; index++;
nrf_config_set(&config);
nrf_snd_pkt_crc(32,buf); //data packet nrf_snd_pkt_crc(32,buf); //data packet
delayms(20); delayms(20);
} }
@ -291,6 +325,7 @@ void rftransfer_send(uint16_t size, uint8_t *data)
buf[2] = crc & 0xFF; buf[2] = crc & 0xFF;
buf[3] = rand >> 8; buf[3] = rand >> 8;
buf[4] = rand & 0xFF; buf[4] = rand & 0xFF;
nrf_config_set(&config);
nrf_snd_pkt_crc(32,buf); //setup packet nrf_snd_pkt_crc(32,buf); //setup packet
delayms(20); delayms(20);
} }