From d3dcf97e28cfeffe5d2e27a119077e12b61b2e7e Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sun, 6 Mar 2011 06:45:24 +0100 Subject: use eeprom for pin --- Makefile | 2 +- kbc.c | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 581165c..3f0732f 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ CC=gcc CXX=g++ -g LDXX=g++ -g -love: kbc.flash +love: kbc.flash kbc.eeprom %.flash: %.ld.o $(AOBJCOPY) -O binary $< $@ diff --git a/kbc.c b/kbc.c index 6a04e4a..81ba569 100644 --- a/kbc.c +++ b/kbc.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #ifndef PIN @@ -331,7 +332,7 @@ static uint8_t cntr = 0; static uint8_t error; #endif -static const char passwd[sizeof(PIN) - 1] = PIN; +static const EEMEM char passwd[sizeof(PIN) - 1] = PIN; static char code[sizeof(PIN)]; static void state_enter(void) @@ -543,17 +544,26 @@ static void handle_keypress(uint8_t data) unlock = ascii == ENT || data == NUMPAD_ENTER; if (lock || unlock) { + uint8_t eebyte, pos, ok = 1; + /* passwd: a b c d * code: \0 a b c d */ + + if (code[0]) + ok = 0; #ifdef KILLSWITCH - if (code[0] || !memcmp("9164", code + 1, 4)) { + if (!memcmp("9164", code + 1, 4)) { error = 0; nextstate = STATE_ERROR; return; } #endif - if (code[0] || memcmp(passwd, code + 1, sizeof(passwd))) { + for (pos = 1; pos < sizeof(code); pos++) + if (code[pos] != eeprom_read_byte(passwd + pos - 1)) + ok = 0; + + if (!ok) { dbg_wr(0x20); nextstate = STATE_REJECT; } else { -- cgit v1.2.1