Skip to content

Commit

Permalink
Fixed the SD card read/write logic for card+PIN (cf. #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Oct 23, 2023
1 parent 1724530 commit e3b77af
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 21 deletions.
14 changes: 7 additions & 7 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
- [ ] card + PIN read
- [x] timeout on keycode
- [x] rework ACL as struct (with cards, timer, etc)
- [ ] Update all variants
- [ ] controller
- [x] Update all variants
- [x] controller
- [x] picow/base
- [x] picow/wifi
- [x] picow/wifi+usb
- [ ] pico/base
- [ ] pico/usb
- [ ] universal
- [x] pico/base
- [x] pico/usb
- [x] universal
- [x] picow/base
- [x] picow/wifi
- [x] picow/wifi+usb
- [ ] pico/base
- [ ] pico/usb
- [x] pico/base
- [x] pico/usb
- [ ] Remove debug stuff
- [ ] Check mode == CONTROLLER/READER in unlock, etc
- [ ] README
Expand Down
2 changes: 1 addition & 1 deletion pico/core/src/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ int acl_load() {
ACL.cards[i].start = cards[i].start;
ACL.cards[i].end = cards[i].end;
ACL.cards[i].allowed = cards[i].allowed;
snprintf(ACL.cards[i].PIN, sizeof(cards[i].PIN), "");
snprintf(ACL.cards[i].PIN, sizeof(cards[i].PIN), cards[i].PIN);
snprintf(ACL.cards[i].name, sizeof(cards[i].name), cards[i].name);
}

Expand Down
9 changes: 7 additions & 2 deletions pico/core/src/sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "../include/sdcard.h"
#include "../include/wiegand.h"

const char *NO_PIN = "-----";

void spi0_dma_isr();
datetime_t string2date(const char *);

Expand Down Expand Up @@ -207,7 +209,10 @@ int sdcard_read_acl(CARD cards[], int *N) {
if ((p = strtok(NULL, " ")) != NULL) {
cards[ix].allowed = strncmp(p, "Y", 1) == 0 || strncmp(p, "y", 1) == 0;
if ((p = strtok(NULL, " ")) != NULL) {
snprintf(cards[ix].PIN, sizeof(cards[ix].PIN), p);
if (strncmp(p, NO_PIN, CARD_PIN_SIZE) != 0) {
snprintf(cards[ix].PIN, sizeof(cards[ix].PIN), p);
}

if ((p = strtok(NULL, " ")) != NULL) {
snprintf(cards[ix].name, sizeof(cards[ix].name), p);
}
Expand Down Expand Up @@ -257,7 +262,7 @@ int sdcard_write_acl(CARD cards[], int N) {
card.end.month,
card.end.day,
card.allowed ? 'Y' : 'N',
card.PIN,
strncmp(card.PIN, "", CARD_PIN_SIZE) == 0 ? NO_PIN : card.PIN,
card.name);

if ((fr = f_printf(&file, "%s\n", record)) < 0) {
Expand Down
14 changes: 10 additions & 4 deletions pico/universal/common/src/universal.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ void dispatch(uint32_t v) {
on_card_read(v & 0x0fffffff);

if (last_card.ok && mode == READER) {
enum ACCESS access;
if ((access = acl_allowed(last_card.facility_code, last_card.card_number, "")) == GRANTED) {
enum ACCESS access = acl_allowed(last_card.facility_code, last_card.card_number, "");

switch (access) {
case GRANTED:
last_card.access = GRANTED;
led_blink(1);
door_unlock(5000);
} else if (access == NEEDS_PIN) {
break;

case NEEDS_PIN:
last_card.access = NEEDS_PIN;
led_blink(1);
} else {
break;

default:
last_card.access = DENIED;
led_blink(3);
}
Expand Down
4 changes: 2 additions & 2 deletions pico/universal/pico/base/src/universal.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ card last_card = {
};

int main() {
bi_decl(bi_program_description("Pico-Wiegand interface"));
bi_decl(bi_program_description("Pico-Wiegand Universal Interface"));
bi_decl(bi_program_version_string(VERSION));

stdio_init_all();
Expand Down Expand Up @@ -180,7 +180,7 @@ void sysinit() {
static repeating_timer_t syscheck_rt;

if (!initialised) {
puts(" *** WIEGAND REFERENCE IMPLEMENTATION");
puts(" Pico-Wiegand Universal Interface");

if (!gpio_get(JUMPER_READ) && gpio_get(JUMPER_WRITE)) {
mode = READER;
Expand Down
4 changes: 2 additions & 2 deletions pico/universal/pico/usb/src/universal.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ card last_card = {
};

int main() {
bi_decl(bi_program_description("Pico-Wiegand Reference interface (USB)"));
bi_decl(bi_program_description("Pico-Wiegand universal Interface (USB)"));
bi_decl(bi_program_version_string(VERSION));

stdio_init_all();
Expand Down Expand Up @@ -181,7 +181,7 @@ void sysinit() {
static repeating_timer_t syscheck_rt;

if (!initialised) {
puts(" *** WIEGAND REFERENCE IMPLEMENTATION (USB)");
puts(" Pico-Wiegand Universal Interface");

if (!gpio_get(JUMPER_READ) && gpio_get(JUMPER_WRITE)) {
mode = READER;
Expand Down
2 changes: 1 addition & 1 deletion pico/universal/picow/base/src/universal.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void sysinit() {
static repeating_timer_t syscheck_rt;

if (!initialised) {
puts(" *** WIEGAND REFERENCE IMPLEMENTATION");
puts(" PicoW-Wiegand Universal Interface");

if (!gpio_get(JUMPER_READ) && gpio_get(JUMPER_WRITE)) {
mode = READER;
Expand Down
2 changes: 1 addition & 1 deletion pico/universal/picow/wifi+usb/src/universal.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void sysinit() {
static repeating_timer_t syscheck_rt;

if (!initialised) {
puts(" *** WIEGAND REFERENCE IMPLEMENTATION (USB)");
puts(" PicoW-Wiegand Universal Interface (WiFi+USB)");

if (!gpio_get(JUMPER_READ) && gpio_get(JUMPER_WRITE)) {
mode = READER;
Expand Down
2 changes: 1 addition & 1 deletion pico/universal/picow/wifi/src/universal.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void sysinit() {
static repeating_timer_t syscheck_rt;

if (!initialised) {
puts(" *** WIEGAND REFERENCE IMPLEMENTATION (WIFI)");
puts(" PicoW-Wiegand Universal Interface (WiFi)");

if (!gpio_get(JUMPER_READ) && gpio_get(JUMPER_WRITE)) {
mode = READER;
Expand Down

0 comments on commit e3b77af

Please sign in to comment.