Skip to content

Commit

Permalink
Added PIN code to CARD struct (cf. #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Oct 12, 2023
1 parent b49e539 commit aa492c7
Show file tree
Hide file tree
Showing 23 changed files with 175 additions and 138 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [x] 8-bit burst mode read
- [x] card + PIN writer
- [ ] card + PIN read
- [ ] FIXME in acl.c


- [ ] PicoW+TCP/IP
Expand Down
15 changes: 11 additions & 4 deletions pico/controller/common/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,18 @@ void debug(txrx f, void *context) {
char *s;

if ((s = calloc(N, 1)) != NULL) {
snprintf(s, N, "%s", "12345");
uint32_t msg = MSG_CODE | ((uint32_t)s & 0x0fffffff); // SRAM_BASE is 0x20000000
if (queue_is_full(&queue) || !queue_try_add(&queue, &msg)) {
free(s);
// ... card
uint32_t v = MSG_CARD | (0x0C9C841 & 0x03ffffff); // 10058400
if (!queue_is_full(&queue)) {
queue_try_add(&queue, &v);
}

// // ... keycode
// snprintf(s, N, "%s", "12345");
// uint32_t msg = MSG_CODE | ((uint32_t)s & 0x0fffffff); // SRAM_BASE is 0x20000000
// if (queue_is_full(&queue) || !queue_try_add(&queue, &msg)) {
// free(s);
// }
}

f(context, ">> DEBUG OK");
Expand Down
23 changes: 23 additions & 0 deletions pico/controller/common/src/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,36 @@
#include <stdlib.h>

#include <acl.h>
#include <common.h>
#include <led.h>
#include <logd.h>
#include <read.h>
#include <relays.h>
#include <wiegand.h>

const uint32_t MSG_CARD = 0x40000000;
const uint32_t MSG_CODE = 0x50000000;

void dispatch(uint32_t v) {
if ((v & MSG) == MSG_CARD) {
on_card_read(v & 0x0fffffff);

if (last_card.ok && mode == CONTROLLER) {
if (acl_allowed(last_card.facility_code, last_card.card_number)) {
last_card.granted = GRANTED;
led_blink(1);
door_unlock(5000);
} else {
last_card.granted = DENIED;
led_blink(3);
}
}

char s[64];
cardf(&last_card, s, sizeof(s), false);
logd_log(s);
}

if ((v & MSG) == MSG_CODE) {
char *b = (char *)(SRAM_BASE | (v & 0x0fffffff));
char s[64];
Expand Down
38 changes: 18 additions & 20 deletions pico/controller/pico/base/src/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ const uint32_t MSG_WATCHDOG = 0x00000000;
const uint32_t MSG_SYSCHECK = 0x10000000;
const uint32_t MSG_RX = 0x20000000;
const uint32_t MSG_TX = 0x30000000;
const uint32_t MSG_CARD_READ = 0x40000000;
const uint32_t MSG_CODE = 0x50000000;
const uint32_t MSG_KEYPAD_DIGIT = 0x60000000;
const uint32_t MSG_LED = 0x70000000;
const uint32_t MSG_RELAY = 0x80000000;
Expand Down Expand Up @@ -112,24 +110,24 @@ int main() {
free(b);
}

if ((v & MSG) == MSG_CARD_READ) {
on_card_read(v & 0x0fffffff);

if (last_card.ok && mode == CONTROLLER) {
if (acl_allowed(last_card.facility_code, last_card.card_number)) {
last_card.granted = GRANTED;
led_blink(1);
door_unlock(5000);
} else {
last_card.granted = DENIED;
led_blink(3);
}
}

char s[64];
cardf(&last_card, s, sizeof(s), false);
logd_log(s);
}
// if ((v & MSG) == MSG_CARD) {
// on_card_read(v & 0x0fffffff);
//
// if (last_card.ok && mode == CONTROLLER) {
// if (acl_allowed(last_card.facility_code, last_card.card_number)) {
// last_card.granted = GRANTED;
// led_blink(1);
// door_unlock(5000);
// } else {
// last_card.granted = DENIED;
// led_blink(3);
// }
// }
//
// char s[64];
// cardf(&last_card, s, sizeof(s), false);
// logd_log(s);
// }

if ((v & MSG) == MSG_LED) {
led_event(v & 0x0fffffff);
Expand Down
38 changes: 18 additions & 20 deletions pico/controller/pico/usb/src/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ const uint32_t MSG_WATCHDOG = 0x00000000;
const uint32_t MSG_SYSCHECK = 0x10000000;
const uint32_t MSG_RX = 0x20000000;
const uint32_t MSG_TX = 0x30000000;
const uint32_t MSG_CARD_READ = 0x40000000;
const uint32_t MSG_CODE = 0x50000000;
const uint32_t MSG_KEYPAD_DIGIT = 0x60000000;
const uint32_t MSG_LED = 0x70000000;
const uint32_t MSG_RELAY = 0x80000000;
Expand Down Expand Up @@ -116,24 +114,24 @@ int main() {
free(b);
}

if ((v & MSG) == MSG_CARD_READ) {
on_card_read(v & 0x0fffffff);

if (last_card.ok && mode == CONTROLLER) {
if (acl_allowed(last_card.facility_code, last_card.card_number)) {
last_card.granted = GRANTED;
led_blink(1);
door_unlock(5000);
} else {
last_card.granted = DENIED;
led_blink(3);
}
}

char s[64];
cardf(&last_card, s, sizeof(s), false);
logd_log(s);
}
// if ((v & MSG) == MSG_CARD) {
// on_card_read(v & 0x0fffffff);
//
// if (last_card.ok && mode == CONTROLLER) {
// if (acl_allowed(last_card.facility_code, last_card.card_number)) {
// last_card.granted = GRANTED;
// led_blink(1);
// door_unlock(5000);
// } else {
// last_card.granted = DENIED;
// led_blink(3);
// }
// }
//
// char s[64];
// cardf(&last_card, s, sizeof(s), false);
// logd_log(s);
// }

if ((v & MSG) == MSG_LED) {
led_event(v & 0x0fffffff);
Expand Down
38 changes: 18 additions & 20 deletions pico/controller/picow/base/src/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ const uint32_t MSG_WATCHDOG = 0x00000000;
const uint32_t MSG_SYSCHECK = 0x10000000;
const uint32_t MSG_RX = 0x20000000;
const uint32_t MSG_TX = 0x30000000;
const uint32_t MSG_CARD_READ = 0x40000000;
const uint32_t MSG_CODE = 0x50000000;
const uint32_t MSG_KEYPAD_DIGIT = 0x60000000;
const uint32_t MSG_LED = 0x70000000;
const uint32_t MSG_RELAY = 0x80000000;
Expand Down Expand Up @@ -118,24 +116,24 @@ int main() {
free(b);
}

if ((v & MSG) == MSG_CARD_READ) {
on_card_read(v & 0x0fffffff);

if (last_card.ok && mode == CONTROLLER) {
if (acl_allowed(last_card.facility_code, last_card.card_number)) {
last_card.granted = GRANTED;
led_blink(1);
door_unlock(5000);
} else {
last_card.granted = DENIED;
led_blink(3);
}
}

char s[64];
cardf(&last_card, s, sizeof(s), false);
logd_log(s);
}
// if ((v & MSG) == MSG_CARD) {
// on_card_read(v & 0x0fffffff);
//
// if (last_card.ok && mode == CONTROLLER) {
// if (acl_allowed(last_card.facility_code, last_card.card_number)) {
// last_card.granted = GRANTED;
// led_blink(1);
// door_unlock(5000);
// } else {
// last_card.granted = DENIED;
// led_blink(3);
// }
// }
//
// char s[64];
// cardf(&last_card, s, sizeof(s), false);
// logd_log(s);
// }

if ((v & MSG) == MSG_LED) {
led_event(v & 0x0fffffff);
Expand Down
38 changes: 18 additions & 20 deletions pico/controller/picow/wifi+usb/src/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ const uint32_t MSG_WATCHDOG = 0x00000000;
const uint32_t MSG_SYSCHECK = 0x10000000;
const uint32_t MSG_RX = 0x20000000;
const uint32_t MSG_TX = 0x30000000;
const uint32_t MSG_CARD_READ = 0x40000000;
const uint32_t MSG_CODE = 0x50000000;
const uint32_t MSG_KEYPAD_DIGIT = 0x60000000;
const uint32_t MSG_LED = 0x70000000;
const uint32_t MSG_RELAY = 0x80000000;
Expand Down Expand Up @@ -120,24 +118,24 @@ int main() {
free(b);
}

if ((v & MSG) == MSG_CARD_READ) {
on_card_read(v & 0x0fffffff);

if (last_card.ok && mode == CONTROLLER) {
if (acl_allowed(last_card.facility_code, last_card.card_number)) {
last_card.granted = GRANTED;
led_blink(1);
door_unlock(5000);
} else {
last_card.granted = DENIED;
led_blink(3);
}
}

char s[64];
cardf(&last_card, s, sizeof(s), false);
logd_log(s);
}
// if ((v & MSG) == MSG_CARD) {
// on_card_read(v & 0x0fffffff);
//
// if (last_card.ok && mode == CONTROLLER) {
// if (acl_allowed(last_card.facility_code, last_card.card_number)) {
// last_card.granted = GRANTED;
// led_blink(1);
// door_unlock(5000);
// } else {
// last_card.granted = DENIED;
// led_blink(3);
// }
// }
//
// char s[64];
// cardf(&last_card, s, sizeof(s), false);
// logd_log(s);
// }

if ((v & MSG) == MSG_LED) {
led_event(v & 0x0fffffff);
Expand Down
38 changes: 18 additions & 20 deletions pico/controller/picow/wifi/src/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ const uint32_t MSG_WATCHDOG = 0x00000000;
const uint32_t MSG_SYSCHECK = 0x10000000;
const uint32_t MSG_RX = 0x20000000;
const uint32_t MSG_TX = 0x30000000;
const uint32_t MSG_CARD_READ = 0x40000000;
const uint32_t MSG_CODE = 0x50000000;
const uint32_t MSG_KEYPAD_DIGIT = 0x60000000;
const uint32_t MSG_LED = 0x70000000;
const uint32_t MSG_RELAY = 0x80000000;
Expand Down Expand Up @@ -119,24 +117,24 @@ int main() {
free(b);
}

if ((v & MSG) == MSG_CARD_READ) {
on_card_read(v & 0x0fffffff);

if (last_card.ok && mode == CONTROLLER) {
if (acl_allowed(last_card.facility_code, last_card.card_number)) {
last_card.granted = GRANTED;
led_blink(1);
door_unlock(5000);
} else {
last_card.granted = DENIED;
led_blink(3);
}
}

char s[64];
cardf(&last_card, s, sizeof(s), false);
logd_log(s);
}
// if ((v & MSG) == MSG_CARD) {
// on_card_read(v & 0x0fffffff);
//
// if (last_card.ok && mode == CONTROLLER) {
// if (acl_allowed(last_card.facility_code, last_card.card_number)) {
// last_card.granted = GRANTED;
// led_blink(1);
// door_unlock(5000);
// } else {
// last_card.granted = DENIED;
// led_blink(3);
// }
// }
//
// char s[64];
// cardf(&last_card, s, sizeof(s), false);
// logd_log(s);
// }

if ((v & MSG) == MSG_LED) {
led_event(v & 0x0fffffff);
Expand Down
6 changes: 4 additions & 2 deletions pico/core/include/wiegand.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "pico/util/queue.h"

#define CARD_PIN_SIZE 5
#define CARD_NAME_SIZE 48
#define MAX_CARDS 32

Expand Down Expand Up @@ -39,7 +40,8 @@ typedef struct CARD {
datetime_t start;
datetime_t end;
bool allowed;
char name[CARD_NAME_SIZE];
char PIN[CARD_PIN_SIZE + 1];
char name[CARD_NAME_SIZE + 1];
} CARD;

typedef struct card {
Expand Down Expand Up @@ -77,7 +79,7 @@ extern const uint32_t MSG;
extern const uint32_t MSG_SYSINIT;
extern const uint32_t MSG_SYSCHECK;
extern const uint32_t MSG_WATCHDOG;
extern const uint32_t MSG_CARD_READ;
extern const uint32_t MSG_CARD;
extern const uint32_t MSG_CODE;
extern const uint32_t MSG_KEYPAD_DIGIT;
extern const uint32_t MSG_LED;
Expand Down
10 changes: 7 additions & 3 deletions pico/core/src/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ int acl_load() {
ACL[i].start = cards[i].start;
ACL[i].end = cards[i].end;
ACL[i].allowed = cards[i].allowed;
snprintf(ACL[1].name, CARD_NAME_SIZE, cards[i].name);
snprintf(ACL[i].PIN, sizeof(cards[i].PIN), "");
snprintf(ACL[i].name, sizeof(cards[i].name), cards[i].name);
}

snprintf(s, sizeof(s), "DISK LOADED %d CARDS FROM SDCARD", N);
Expand All @@ -75,6 +76,7 @@ int acl_save() {
int N = 0;
char s[64];

// FIXME: check facility code and card number correctly
for (int i = 0; i < ACL_SIZE; i++) {
if (ACL[i].card_number > 99965535) {
ACL[i].card_number = 0xffffffff;
Expand Down Expand Up @@ -174,7 +176,8 @@ bool acl_grant(uint32_t facility_code, uint32_t card) {
ACL[i].start = start;
ACL[i].end = end;
ACL[i].allowed = true;
snprintf(ACL[i].name, CARD_NAME_SIZE, "----");
snprintf(ACL[i].PIN, sizeof(ACL[i].PIN), "");
snprintf(ACL[i].name, sizeof(ACL[i].name), "----");
return true;
}
}
Expand All @@ -185,7 +188,8 @@ bool acl_grant(uint32_t facility_code, uint32_t card) {
ACL[i].start = start;
ACL[i].end = end;
ACL[i].allowed = true;
snprintf(ACL[i].name, CARD_NAME_SIZE, "----");
snprintf(ACL[i].PIN, sizeof(ACL[i].PIN), "");
snprintf(ACL[i].name, sizeof(ACL[i].name), "----");

return true;
}
Expand Down
Loading

0 comments on commit aa492c7

Please sign in to comment.