diff options
| author | David Lamparter <equinox@diac24.net> | 2011-03-06 06:45:24 +0100 |
|---|---|---|
| committer | David Lamparter <equinox@diac24.net> | 2011-03-06 06:45:24 +0100 |
| commit | d3dcf97e28cfeffe5d2e27a119077e12b61b2e7e (patch) | |
| tree | 44bf0f8f022e4168f613f79c8b21bb39a8dd3e2e | |
| parent | 75ff498d410a42b4cce52409f2abcfa9e3856143 (diff) | |
use eeprom for pin
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | kbc.c | 16 |
2 files changed, 14 insertions, 4 deletions
@@ -12,13 +12,13 @@ ACFLAGS=-g -mmcu=$(MCU) $(CFLAGS) $(DPIN) -Os -mcall-prologues # ALDFLAGS=-L/usr/avr/lib/avr4 -L/usr/lib/binutils/avr/2.18 LD=gcc CC=gcc CXX=g++ -g LDXX=g++ -g -love: kbc.flash +love: kbc.flash kbc.eeprom %.flash: %.ld.o $(AOBJCOPY) -O binary $< $@ %.eeprom: %.ld.o $(AOBJCOPY) -j .eeprom -O binary $^ $@ @@ -2,12 +2,13 @@ #include <stdint.h> #include <string.h> #include <avr/io.h> #include <avr/interrupt.h> #include <avr/sleep.h> #include <avr/pgmspace.h> +#include <avr/eeprom.h> #include <util/delay.h> #ifndef PIN #error need to define a PIN #endif @@ -328,13 +329,13 @@ static uint8_t wait_byte(void) static uint8_t cntr = 0; #ifdef KILLSWITCH 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) { switch (state) { case STATE_NONE: @@ -540,23 +541,32 @@ static void handle_keypress(uint8_t data) dbg_wr(0x80 | (ascii >> 4)); lock = ascii == ESC; 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 { dbg_wr(lock ? 0x21 : 0x22); nextstate = STATE_ACCEPT; } |
