summaryrefslogtreecommitdiffstats
path: root/lock/bend.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2025-04-27 13:16:46 +0800
committerSadeep Madurange <sadeep@asciimx.com>2025-04-27 13:16:46 +0800
commit775d4a84f36d4d5d0700e9c44dfa4114a0cc022c (patch)
tree754c9d00ed1d56806dc35070895d5bba845f40d1 /lock/bend.c
parent4dc74efdd09b5244ef676aef4f5575b6d9e2694d (diff)
downloadsmart-home-775d4a84f36d4d5d0700e9c44dfa4114a0cc022c.tar.gz
Yay! working with session key encryption.
Diffstat (limited to 'lock/bend.c')
-rw-r--r--lock/bend.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/lock/bend.c b/lock/bend.c
index d7459eb..3957c55 100644
--- a/lock/bend.c
+++ b/lock/bend.c
@@ -36,7 +36,6 @@ static char tab[] = {
'P', 'f', ':', 'B', ']', 'Y', '^', 'F', '%', 'C', 'x'
};
-static uint8_t sync = 0;
static volatile uint8_t rxd = 0;
static uint16_t tablen = sizeof(tab) / sizeof(tab[0]);
@@ -129,10 +128,20 @@ int main(void)
radio_recv(buf, WDLEN);
rxd = 0;
xor(KEY, buf, msg, WDLEN);
- if (memcmp(msg, LOCK, WDLEN) == 0)
- lock();
- else if (memcmp(msg, UNLOCK, WDLEN) == 0)
- unlock();
+ if (memcmp(msg, SYN, WDLEN) == 0) {
+ keygen(key, WDLEN);
+ xor(KEY, key, buf, WDLEN);
+ radio_sendto(txaddr, buf, WDLEN);
+ } else {
+ xor(key, buf, msg, WDLEN);
+ if (memcmp(msg, LOCK, WDLEN) == 0) {
+ lock();
+ keydel(key, WDLEN);
+ } else if (memcmp(msg, UNLOCK, WDLEN) == 0) {
+ unlock();
+ keydel(key, WDLEN);
+ }
+ }
}
}
return 0;