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 /kbc.c | |
| parent | 75ff498d410a42b4cce52409f2abcfa9e3856143 (diff) | |
use eeprom for pin
Diffstat (limited to 'kbc.c')
| -rw-r--r-- | kbc.c | 16 |
1 files changed, 13 insertions, 3 deletions
| @@ -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; | |||
| 331 | static uint8_t error; | 332 | static uint8_t error; |
| 332 | #endif | 333 | #endif |
| 333 | 334 | ||
| 334 | static const char passwd[sizeof(PIN) - 1] = PIN; | 335 | static const EEMEM char passwd[sizeof(PIN) - 1] = PIN; |
| 335 | static char code[sizeof(PIN)]; | 336 | static char code[sizeof(PIN)]; |
| 336 | 337 | ||
| 337 | static void state_enter(void) | 338 | static 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 { |
