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(); lcdRefresh();
#else #else
uint32_t k[4] = {0xffff,0xffff,0xffff,0xffff}; //uint32_t k[4] = {0xffff,0xffff,0xffff,0xffff};
if( filetransfer_receive(mac,(uint32_t*)k) )
//k[0] = 0; k[1] = 0; k[2] = 0; k[3] = 0;
if( filetransfer_receive(mac,(uint32_t*)k1) )
continue; continue;
lcdPrintln("Done"); lcdPrintln("Done");
lcdPrintln("Right=OK"); lcdPrintln("Right=OK");
@ -270,7 +272,8 @@ void sendFile(char *filename)
#else #else
delayms(3000); delayms(3000);
uint32_t k[4] = {0xffff,0xffff,0xffff,0xffff}; 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("Done");
lcdPrintln("Right=OK"); lcdPrintln("Right=OK");
lcdPrintln("Left=Retry"); lcdPrintln("Left=Retry");
@ -340,6 +343,13 @@ void main_vcard(void) {
lcdPrintln("Done"); lcdPrintln("Done");
lcdRefresh(); lcdRefresh();
}else if(key==BTN_RIGHT){ }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", //encryption_decryption_demo("This is encrypted",

View File

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

View File

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