Skip to content

Commit

Permalink
Removed CLI debug commands from controller/universal
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Oct 24, 2023
1 parent e3b77af commit aec5570
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 113 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,31 @@ The supported command set comprises:
| REBOOT | _ALL_ | Reboot |
| ? | _ALL_ | Display list of commands |

## Operating Modes

The code supports two operating modes:
- emulator/writer
- controller/reader

In _emulator_ mode the implementation writes a Wiegand-26 card code (or keypad PIN code) to an external Wiegand-26 interface
(e.g. a UHPPOTE controller). It also:
- emulates a door open/closed sensor
- emulates a door pushbutton
- detects the door locked/unlocked state

In _controller_ mode the implementation reads a Wiegand-26 card code (or keypad PIN code) from an external Wiegand-26 reader/keypad. It also:
- detects a door open/closed sensor state change
- detects a door pushbutton state change
- emulates a door lock/unlock
- implements card permissions and keypad passcodes

The operating mode is set by the combination of the code and the JUMPER_READ and JUMPER_WRITE inputs (set in _hwconfig.c_,
GPIO7 and GPIO8 by default):
- the _controller_ binaries expect the JUMPER_READ input to be pulled LOW
- the _emulator_ binaries expected the JUMPER_WRITE input to be pulled LOW
- the _universal_ binaries start in _reader_ mode if the JUMPER_READ input is pulled LOW, or in _writer_ mode if the
JUMPER_WRITE is pulled LOW
- if both JUMPER_READ and JUMPER_WRITE are pulled LOW the operating mode is UNKNOWN.

## Build constants

Expand Down
16 changes: 3 additions & 13 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,17 @@
- [x] 8-bit burst mode read
- [x] card + PIN writer
- [x] FIXME in acl.c
- [ ] card + PIN read
- [x] card + PIN read
- [x] timeout on keycode
- [x] rework ACL as struct (with cards, timer, etc)
- [x] Update all variants
- [x] controller
- [x] picow/base
- [x] picow/wifi
- [x] picow/wifi+usb
- [x] pico/base
- [x] pico/usb
- [x] universal
- [x] picow/base
- [x] picow/wifi
- [x] picow/wifi+usb
- [x] pico/base
- [x] pico/usb
- [ ] Remove debug stuff
- [x] Remove debug stuff
- [ ] Check mode == CONTROLLER/READER in unlock, etc
- [ ] README
- [x] build constants
- [ ] _modes_
- [x] _operating modes_
- [ ] keypad modes
- [ ] passcodes
- [ ] master passcode
Expand Down
69 changes: 34 additions & 35 deletions pico/controller/common/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

typedef void (*handler)(uint32_t, uint32_t, txrx, void *);

void debug(txrx, void *, int);
void help(txrx, void *);
void query(txrx, void *);

Expand Down Expand Up @@ -84,47 +83,47 @@ void execw(char *cmd, txrx f, void *context) {
cli_set_passcodes(&cmd[9], f, context);
} else if (strncasecmp(cmd, "query", 5) == 0) {
query(f, context);
} else if (strncasecmp(cmd, "debugx", 7) == 0) {
debug(f, context, 1);
} else if (strncasecmp(cmd, "debugy", 7) == 0) {
debug(f, context, 2);
// } else if (strncasecmp(cmd, "debugx", 7) == 0) {
// debug(f, context, 1);
// } else if (strncasecmp(cmd, "debugy", 7) == 0) {
// debug(f, context, 2);
} else {
help(f, context);
}
}
}
}

/* -- DEBUG --
*
*/
void debug(txrx f, void *context, int action) {
// ... card
if (action == 1) {
uint32_t v = MSG_CARD | (0x0C9C841 & 0x03ffffff); // 10058400
if (!queue_is_full(&queue)) {
queue_try_add(&queue, &v);
}

f(context, ">> DEBUG CARD");
}

// ... keycode
if (action == 2) {
int N = 6;
char *code;

if ((code = calloc(N, 1)) != NULL) {
snprintf(code, N, "%s", "12345");
uint32_t msg = MSG_CODE | ((uint32_t)code & 0x0fffffff); // SRAM_BASE is 0x20000000
if (queue_is_full(&queue) || !queue_try_add(&queue, &msg)) {
free(code);
} else {
f(context, ">> DEBUG CODE");
}
}
}
}
// /* -- DEBUG --
// *
// */
// void debug(txrx f, void *context, int action) {
// // ... card
// if (action == 1) {
// uint32_t v = MSG_CARD | (0x0C9C841 & 0x03ffffff); // 10058400
// if (!queue_is_full(&queue)) {
// queue_try_add(&queue, &v);
// }
//
// f(context, ">> DEBUG CARD");
// }
//
// // ... keycode
// if (action == 2) {
// int N = 6;
// char *code;
//
// if ((code = calloc(N, 1)) != NULL) {
// snprintf(code, N, "%s", "12345");
// uint32_t msg = MSG_CODE | ((uint32_t)code & 0x0fffffff); // SRAM_BASE is 0x20000000
// if (queue_is_full(&queue) || !queue_try_add(&queue, &msg)) {
// free(code);
// } else {
// f(context, ">> DEBUG CODE");
// }
// }
// }
// }

/* Displays the last read/write card, if any.
*
Expand Down
33 changes: 18 additions & 15 deletions pico/controller/common/src/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,31 @@ void dispatch(uint32_t v) {
char *b = (char *)(SRAM_BASE | (v & 0x0fffffff));
enum ACCESS access;

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

cardf(&last_card, s, sizeof(s), false);

} else if (mode == CONTROLLER && acl_passcode(b)) {
snprintf(s, sizeof(s), "CODE OK");
led_blink(8);
door_unlock(5000);
} else {
last_card.access = DENIED;
snprintf(s, sizeof(s), "CODE INVALID");
led_blink(3);
}

cardf(&last_card, s, sizeof(s), false);

} else if (mode == CONTROLLER && acl_passcode(b)) {
snprintf(s, sizeof(s), "CODE OK");
led_blink(8);
door_unlock(5000);
} else {
snprintf(s, sizeof(s), "CODE INVALID");
led_blink(3);
logd_log(s);
}

logd_log(s);
free(b);
}

Expand Down
69 changes: 34 additions & 35 deletions pico/universal/common/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

typedef void (*handler)(uint32_t, uint32_t, txrx, void *);

void debug(txrx, void *, int);
void help(txrx, void *);
void query(txrx, void *);

Expand Down Expand Up @@ -98,47 +97,47 @@ void execw(char *cmd, txrx f, void *context) {
cli_swipe(&cmd[5], f, context);
} else if (strncasecmp(cmd, "code ", 5) == 0) {
keypad(&cmd[1], f, context);
} else if (strncasecmp(cmd, "debugx", 7) == 0) {
debug(f, context, 1);
} else if (strncasecmp(cmd, "debugy", 7) == 0) {
debug(f, context, 2);
// } else if (strncasecmp(cmd, "debugx", 7) == 0) {
// debug(f, context, 1);
// } else if (strncasecmp(cmd, "debugy", 7) == 0) {
// debug(f, context, 2);
} else {
help(f, context);
}
}
}
}

/* -- DEBUG --
*
*/
void debug(txrx f, void *context, int action) {
// ... card
if (action == 1) {
uint32_t v = MSG_CARD | (0x0C9C841 & 0x03ffffff); // 10058400
if (!queue_is_full(&queue)) {
queue_try_add(&queue, &v);
}

f(context, ">> DEBUG CARD");
}

// ... keycode
if (action == 2) {
int N = 6;
char *code;

if ((code = calloc(N, 1)) != NULL) {
snprintf(code, N, "%s", "12345");
uint32_t msg = MSG_CODE | ((uint32_t)code & 0x0fffffff); // SRAM_BASE is 0x20000000
if (queue_is_full(&queue) || !queue_try_add(&queue, &msg)) {
free(code);
} else {
f(context, ">> DEBUG CODE");
}
}
}
}
// /* -- DEBUG --
// *
// */
// void debug(txrx f, void *context, int action) {
// // ... card
// if (action == 1) {
// uint32_t v = MSG_CARD | (0x0C9C841 & 0x03ffffff); // 10058400
// if (!queue_is_full(&queue)) {
// queue_try_add(&queue, &v);
// }
//
// f(context, ">> DEBUG CARD");
// }
//
// // ... keycode
// if (action == 2) {
// int N = 6;
// char *code;
//
// if ((code = calloc(N, 1)) != NULL) {
// snprintf(code, N, "%s", "12345");
// uint32_t msg = MSG_CODE | ((uint32_t)code & 0x0fffffff); // SRAM_BASE is 0x20000000
// if (queue_is_full(&queue) || !queue_try_add(&queue, &msg)) {
// free(code);
// } else {
// f(context, ">> DEBUG CODE");
// }
// }
// }
// }

/* Displays the last read/write card, if any.
*
Expand Down
33 changes: 18 additions & 15 deletions pico/universal/common/src/universal.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,31 @@ void dispatch(uint32_t v) {
char *b = (char *)(SRAM_BASE | (v & 0x0fffffff));
enum ACCESS access;

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

cardf(&last_card, s, sizeof(s), false);

} else if (acl_passcode(b)) {
snprintf(s, sizeof(s), "CODE OK");
led_blink(8);
door_unlock(5000);
} else {
last_card.access = DENIED;
snprintf(s, sizeof(s), "CODE INVALID");
led_blink(3);
}

cardf(&last_card, s, sizeof(s), false);

} else if (mode == READER && acl_passcode(b)) {
snprintf(s, sizeof(s), "CODE OK");
led_blink(8);
door_unlock(5000);
} else {
snprintf(s, sizeof(s), "CODE INVALID");
led_blink(3);
logd_log(s);
}

logd_log(s);
free(b);
}

Expand Down

0 comments on commit aec5570

Please sign in to comment.