summaryrefslogtreecommitdiffstats
path: root/door_lock/cmd.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2024-11-06 13:02:18 +0800
committerSadeep Madurange <sadeep@asciimx.com>2024-11-06 13:02:18 +0800
commit7327d5e93e0386914dbe712f8f82e2d015ad7029 (patch)
tree72b9cb669a43ed4ee8ff3b8924c7c3f32b65ccd5 /door_lock/cmd.c
parentbe35226d9ebbe3679c38c118a3c7bff34e04c10b (diff)
downloadsmart-home-7327d5e93e0386914dbe712f8f82e2d015ad7029.tar.gz
USe enum for commands.
Diffstat (limited to 'door_lock/cmd.c')
-rw-r--r--door_lock/cmd.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/door_lock/cmd.c b/door_lock/cmd.c
index f00eb6a..a1edc8f 100644
--- a/door_lock/cmd.c
+++ b/door_lock/cmd.c
@@ -3,11 +3,13 @@
#include "cmd.h"
-#define XORLEN 32
-#define KEY "dM>}jdb,6gsnC$J^K 8(I5vyPemPs%;K"
-#define ULOCK_CMD "43iqr5$NB8SpN?Z/52{iVl>o|i!.'dsT"
+#define XORLEN 32
-static char ulock_crypt_cmd[XORLEN];
+#define KEY "dM>}jdb,6gsnC$J^K 8(I5vyPemPs%;K"
+#define LOCK_CMD "43iqr5$NB8SpN?Z/52{iVl>o|i!.'dsT"
+#define UNLOCK_CMD "43iqr5$NB8SpN?Z/52{iVl>o|i!.'dsT"
+
+static char cmd[XORLEN];
static inline void xor(const char *s, char *d, uint8_t n)
{
@@ -17,18 +19,42 @@ static inline void xor(const char *s, char *d, uint8_t n)
d[i] = s[i] ^ KEY[i];
}
-int is_ulock_cmd(const char *s)
+int is_valid_cmd(const char *s, enum command c)
{
+ int rc;
char buf[XORLEN + 1];
xor(s, buf, XORLEN);
buf[XORLEN] = 0;
- return strcmp(ULOCK_CMD, buf) == 0;
+ switch (c) {
+ case DOOR_LOCK:
+ rc = strcmp(LOCK_CMD, buf) == 0;
+ break;
+ case DOOR_UNLOCK:
+ rc = strcmp(UNLOCK_CMD, buf) == 0;
+ break;
+ default:
+ rc = 0;
+ break;
+ }
+
+ return rc;
}
-char * get_encrypted_ulock_cmd(void)
+char * get_cmd_hash(enum command c)
{
- xor(ULOCK_CMD, ulock_crypt_cmd, XORLEN);
- return ulock_crypt_cmd;
+ switch (c) {
+ case DOOR_LOCK:
+ xor(LOCK_CMD, cmd, XORLEN);
+ break;
+ case DOOR_UNLOCK:
+ xor(UNLOCK_CMD, cmd, XORLEN);
+ break;
+ default:
+ cmd[0] = 0;
+ break;
+ }
+
+ return cmd;
}