From ee6ba28850d60b2bf84e132aea99cc83cf14fdee Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 30 Jan 2013 01:27:30 +0000 Subject: further cleanup git-svn-id: https://svn.spreadspace.org/avr/trunk@97 aa12f405-d877-488e-9caf-2d797e2a1cc7 --- usb-i2c-sl018/tuer-rfid.c | 49 ++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/usb-i2c-sl018/tuer-rfid.c b/usb-i2c-sl018/tuer-rfid.c index bb9c1de..96535fc 100644 --- a/usb-i2c-sl018/tuer-rfid.c +++ b/usb-i2c-sl018/tuer-rfid.c @@ -26,6 +26,9 @@ #include #include +#include +#include + #include "util.h" #include "led.h" @@ -36,13 +39,7 @@ #include #define EEPROM_SIZE 1024 -typedef union -{ - uint8_t byte[8]; - uint16_t uint16[4]; - uint32_t uint32[2]; - uint64_t uint64; -} keyslot_t; +typedef uint8_t keyslot_t[8]; keyslot_t EEMEM keyslots[EEPROM_SIZE/sizeof(keyslot_t)]; #define TAG_STA_PIN PINB @@ -165,7 +162,6 @@ void EVENT_USB_Device_Disconnect(void) } /* end LUFA CDC-ACM specific definitions*/ - int16_t stdio_BytesReceived(void) { if(stdio == &usb_stream) @@ -237,9 +233,12 @@ void flash_eeprom_from_stdio(void) fprintf(stdio,"Flashing keys:\n\r"); fflush(stdio); for(keyslot_pos=0;keyslot_pos0) { - keyslot.byte[byte_pos++]=fgetc(stdio); + keyslot[byte_pos++]=fgetc(stdio); BytesReceived--; if (byte_pos == sizeof(keyslot)) { byte_pos=0; @@ -250,10 +249,9 @@ void flash_eeprom_from_stdio(void) led_toggle(); } } - CDC_Device_USBTask(&VirtualSerial_CDC_Interface); - USB_USBTask(); } fprintf(stdio,"\n"); + led_off(); } void dump_eeprom_to_stdio(void) @@ -264,7 +262,7 @@ void dump_eeprom_to_stdio(void) for(keyslot_pos=0;keyslot_posdata); - } break; case '4': //turn cardreader led off if(sl018_cmd(SL018CMD_ComRedLedOff)) @@ -299,7 +295,7 @@ void handle_stdio(uint8_t cmd) case 's': //get eeprom size fprintf(stdio,"%d\n\r",EEPROM_SIZE); break; - default: fprintf(stdio, "error, unknown command %02X\n\r",cmd); return; + default: fprintf(stdio, "error, unknown command %02X '%c'\n\r",cmd, cmd); return; } } @@ -314,12 +310,12 @@ uint8_t generate_csum(uint8_t* data) return sum2<<4 | sum1; } -uint8_t compare_keyslots(const keyslot_t* a, const keyslot_t* b) // constant time compare +uint8_t compare_keyslots(const keyslot_t a, const keyslot_t b) { uint8_t tmp=0, i; + // constant time compare for(i=0; ibyte[i] ^ b->byte[i]; - + tmp |= a[i] ^ b[i]; return tmp; } @@ -327,16 +323,16 @@ bool check_card(const uint8_t * uid, uint8_t uid_len) { keyslot_t card; keyslot_t eeprom_ks; - card.uint64=0; + memset(card, 0, sizeof(card)); uid_len = uid_len > sizeof(keyslot_t) ? sizeof(keyslot_t) : uid_len; for (uint8_t pos=0; pos 0) { + if(BytesReceived > 0) handle_stdio(fgetc(stdio)); - } + if(CARD_PRESENT != card_status) { card_status = CARD_PRESENT; if(card_status) handle_card(); } - CDC_Device_USBTask(&VirtualSerial_CDC_Interface); - USB_USBTask(); } } -- cgit v1.2.3