summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2011-03-06 06:45:24 +0100
committerDavid Lamparter <equinox@diac24.net>2011-03-06 06:45:24 +0100
commitd3dcf97e28cfeffe5d2e27a119077e12b61b2e7e (patch)
tree44bf0f8f022e4168f613f79c8b21bb39a8dd3e2e
parent75ff498d410a42b4cce52409f2abcfa9e3856143 (diff)
use eeprom for pin
-rw-r--r--Makefile2
-rw-r--r--kbc.c16
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
15CXX=g++ -g 15CXX=g++ -g
16LDXX=g++ -g 16LDXX=g++ -g
17 17
18love: kbc.flash 18love: kbc.flash kbc.eeprom
19 19
20%.flash: %.ld.o 20%.flash: %.ld.o
21 $(AOBJCOPY) -O binary $< $@ 21 $(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 @@
5#include <avr/interrupt.h> 5#include <avr/interrupt.h>
6#include <avr/sleep.h> 6#include <avr/sleep.h>
7#include <avr/pgmspace.h> 7#include <avr/pgmspace.h>
8#include <avr/eeprom.h>
8#include <util/delay.h> 9#include <util/delay.h>
9 10
10#ifndef PIN 11#ifndef PIN
@@ -331,7 +332,7 @@ static uint8_t cntr = 0;
331static uint8_t error; 332static uint8_t error;
332#endif 333#endif
333 334
334static const char passwd[sizeof(PIN) - 1] = PIN; 335static const EEMEM char passwd[sizeof(PIN) - 1] = PIN;
335static char code[sizeof(PIN)]; 336static char code[sizeof(PIN)];
336 337
337static void state_enter(void) 338static void state_enter(void)
@@ -543,17 +544,26 @@ static void handle_keypress(uint8_t data)
543 unlock = ascii == ENT || data == NUMPAD_ENTER; 544 unlock = ascii == ENT || data == NUMPAD_ENTER;
544 545
545 if (lock || unlock) { 546 if (lock || unlock) {
547 uint8_t eebyte, pos, ok = 1;
548
546 /* passwd: a b c d 549 /* passwd: a b c d
547 * code: \0 a b c d 550 * code: \0 a b c d
548 */ 551 */
552
553 if (code[0])
554 ok = 0;
549#ifdef KILLSWITCH 555#ifdef KILLSWITCH
550 if (code[0] || !memcmp("9164", code + 1, 4)) { 556 if (!memcmp("9164", code + 1, 4)) {
551 error = 0; 557 error = 0;
552 nextstate = STATE_ERROR; 558 nextstate = STATE_ERROR;
553 return; 559 return;
554 } 560 }
555#endif 561#endif
556 if (code[0] || memcmp(passwd, code + 1, sizeof(passwd))) { 562 for (pos = 1; pos < sizeof(code); pos++)
563 if (code[pos] != eeprom_read_byte(passwd + pos - 1))
564 ok = 0;
565
566 if (!ok) {
557 dbg_wr(0x20); 567 dbg_wr(0x20);
558 nextstate = STATE_REJECT; 568 nextstate = STATE_REJECT;
559 } else { 569 } else {