diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2025-04-11 11:39:53 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2025-04-11 11:39:53 +0800 |
| commit | 31f41ecf75678e41a03f5aaf32e8e17ee81286e1 (patch) | |
| tree | 024778e5a8e20d2dbae4dbc778b593b503a38bf7 /lock/frnt.c | |
| parent | 014040f33f914a82031e15940924bc9c92236fec (diff) | |
| download | smart-home-31f41ecf75678e41a03f5aaf32e8e17ee81286e1.tar.gz | |
Add keygen() to utils.
Diffstat (limited to 'lock/frnt.c')
| -rw-r--r-- | lock/frnt.c | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/lock/frnt.c b/lock/frnt.c deleted file mode 100644 index 4ad2d11..0000000 --- a/lock/frnt.c +++ /dev/null @@ -1,89 +0,0 @@ -/* Door front, connected to the fingerprint scanner */ - -#include <stdint.h> -#include <stdlib.h> - -#include <avr/interrupt.h> -#include <util/delay.h> - -#include "nrfm.h" -#include "uart.h" -#include "util.h" - -#define RX_PIN PD7 -#define RX_DDR DDRD -#define RX_PORT PORTD -#define RX_PCIE PCIE2 -#define RX_PCINT PCINT23 -#define RX_PCMSK PCMSK2 -#define RX_PCINTVEC PCINT2_vect - -// todo: atomic var -static volatile int rxdr = 0; - -static inline void await_reply(void) -{ - int i; - - radio_listen(); - for (i = 0; i < 500 && rxdr == 0; i += 100) - _delay_ms(100); -} - -int main(void) -{ - uint8_t n; - uint8_t rxaddr[ADDRLEN] = { 194, 178, 82 }; - uint8_t txaddr[ADDRLEN] = { 194, 178, 83 }; - - char buf[WDLEN + 1], key[WDLEN + 1], msg[WDLEN + 1]; - - RX_DDR &= ~(1 << RX_PIN); - RX_PORT |= (1 << RX_PIN); - PCICR |= (1 << RX_PCIE); - RX_PCMSK |= (1 << RX_PCINT); - - uart_init(); - radio_init(rxaddr); - radio_print_config(); - - sei(); - - for (;;) { - _delay_ms(2000); /* todo: fingerprint check */ - xor(KEY, SYN, msg, WDLEN); - radio_sendto(txaddr, msg, WDLEN); - await_reply(); - if (rxdr) { - uart_write_line("reply received"); - n = radio_recv(buf, WDLEN); - buf[n] = '\0'; - if (n > 0) { - rxdr = 0; - xor(KEY, buf, key, WDLEN); - xor(key, MSG, msg, WDLEN); - radio_sendto(txaddr, msg, WDLEN); - await_reply(); - if (rxdr) { - n = radio_recv(buf, WDLEN); - buf[n] = '\0'; - rxdr = 0; - xor(key, buf, msg, WDLEN); - uart_write_line(msg); - } else { - // power down - uart_write_line("ERROR: no reply"); - } - } - } else { - // power down - uart_write_line("ERROR: no session key"); - } - } - return 0; -} - -ISR(RX_PCINTVEC) -{ - rxdr = 1; -} |
