working encrypted filetransfer.

This commit is contained in:
schneider 2011-07-23 15:35:00 +02:00
parent 30d3089cc8
commit ec956a3263
3 changed files with 25 additions and 6 deletions

View File

@ -215,8 +215,10 @@ void receiveFile(void)
}
lcdRefresh();
#else
uint32_t k[4] = {0xffff,0xffff,0xffff,0xffff};
if( filetransfer_receive(mac,(uint32_t*)k) )
//uint32_t k[4] = {0xffff,0xffff,0xffff,0xffff};
//k[0] = 0; k[1] = 0; k[2] = 0; k[3] = 0;
if( filetransfer_receive(mac,(uint32_t*)k1) )
continue;
lcdPrintln("Done");
lcdPrintln("Right=OK");
@ -270,7 +272,8 @@ void sendFile(char *filename)
#else
delayms(3000);
uint32_t k[4] = {0xffff,0xffff,0xffff,0xffff};
filetransfer_send((uint8_t*)filename, 0, mac, (uint32_t*)k);
k[0] = 0; k[1] = 0; k[2] = 0; k[3] = 0;
filetransfer_send((uint8_t*)filename, 0, mac, (uint32_t*)k1);
lcdPrintln("Done");
lcdPrintln("Right=OK");
lcdPrintln("Left=Retry");
@ -340,6 +343,13 @@ void main_vcard(void) {
lcdPrintln("Done");
lcdRefresh();
}else if(key==BTN_RIGHT){
DoString(0,8,"MSC Enabled.");
lcdDisplay();
usbMSCInit();
while(!getInputRaw())delayms(10);
DoString(0,16,"MSC Disabled.");
usbMSCOff();
}
//encryption_decryption_demo("This is encrypted",

View File

@ -17,6 +17,7 @@ int filetransfer_send(uint8_t *filename, uint16_t size,
FRESULT res;
UINT readbytes;
if( size > MAXSIZE )
return 1; //File to big
@ -25,6 +26,9 @@ int filetransfer_send(uint8_t *filename, uint16_t size,
return res;
//res = f_read(&file, (char *)buf, size, &readbytes);
for(uint16_t i=0; i<MAXSIZE; i++)
buf[i] = 0;
res = f_read(&file, (char *)buf, MAXSIZE, &readbytes);
size = readbytes;

View File

@ -29,7 +29,7 @@ void rftransfer_send(uint16_t size, uint8_t *data)
buf[2] = index & 0xFF;
buf[3] = rand >> 8;
buf[4] = rand & 0xFF;
for(i=5; i<MAXPACKET && size>0; i++,size--){
for(i=5; i<MAXPACKET-2 && size>0; i++,size--){
buf[i] = *data++;
}
index++;
@ -45,6 +45,7 @@ void rftransfer_send(uint16_t size, uint8_t *data)
//nrf_snd_pkt_crc(5,buf); //crc packet
nrf_snd_pkt_crc(32,buf); //setup packet
delayms(20);
lcdPrint("crc="); lcdPrintIntHex(crc);lcdPrintln("");lcdRefresh();
}
uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout)
@ -67,7 +68,8 @@ uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout)
pos = 0;
if( size <= maxlen ){
lcdClear();
lcdPrintln("got l"); lcdRefresh();
lcdPrint("got l="); lcdPrintInt(size);
lcdPrintln(""); lcdRefresh();
state = 1;
}
}
@ -79,7 +81,7 @@ uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout)
lcdPrintln(" in seq"); lcdRefresh();
//if( (pos + n - 5)<maxlen ){
//for(i=5; i<n; i++,pos++){
for(i=5; i<n && pos<size; i++,pos++){
for(i=5; i<n-2 && pos<size; i++,pos++){
buffer[pos] = buf[i];
}
seq++;
@ -89,6 +91,8 @@ uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout)
if( pos == size ){
lcdPrintln("got all"); lcdRefresh();
crc = crc16(buffer, size);
lcdPrint("crc="); lcdPrintIntHex(crc);
lcdPrintln("");lcdRefresh();
state = 2;
}
break;
@ -99,6 +103,7 @@ uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout)
lcdPrintln(" ok"); lcdRefresh();
return size;
}else{
lcdPrintln(" nok"); lcdRefresh();
state = 0;
}
}