diff options
-rw-r--r-- | openpicc/application/cmd.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/openpicc/application/cmd.c b/openpicc/application/cmd.c index b2b3d7a..2ffa2e6 100644 --- a/openpicc/application/cmd.c +++ b/openpicc/application/cmd.c @@ -23,6 +23,7 @@ #include "usb_print.h" #include "load_modulation.h" #include "tc_sniffer.h" +#include "iso14443a_pretender.h" xQueueHandle xCmdQueue; xTaskHandle xCmdTask; @@ -134,6 +135,37 @@ int atoiEx(const char * nptr, char * * eptr) return sign * curval; } +/* Common code between increment/decrement UID/nonce */ +static int change_value( int(* const getter)(u_int8_t*, size_t), int(* const setter)(u_int8_t*, size_t), + const s_int32_t increment, const char *name ) +{ + u_int8_t uid[4]; + int ret; + if( getter(uid, sizeof(uid)) >= 0) { + (*((u_int32_t*)uid)) += increment; + taskENTER_CRITICAL(); + ret = setter(uid, sizeof(uid)); + taskEXIT_CRITICAL(); + if(ret < 0) { + DumpStringToUSB("Failed to set the "); + DumpStringToUSB(name); + DumpStringToUSB("\n\r"); + } else { + DumpStringToUSB("Successfully set "); + DumpStringToUSB(name); + DumpStringToUSB(" to "); + DumpBufferToUSB((char*)uid, sizeof(uid)); + DumpStringToUSB("\n\r"); + } + } else { + DumpStringToUSB("Couldn't get "); + DumpStringToUSB(name); + DumpStringToUSB("\n\r"); + ret = -1; + } + return ret; +} + #define DYNAMIC_PIN_PLL_LOCK 1 static struct { int pin; int dynpin; char * description; } PIO_PINS[] = { {0,DYNAMIC_PIN_PLL_LOCK, "pll lock "}, @@ -340,6 +372,18 @@ void prvExecCommand(u_int32_t cmd, portCHAR *args) { DumpUIntToUSB(da_get_value()); DumpStringToUSB("\n\r"); break; + case 'U+': + i=atoiEx(args, &args); + change_value(get_UID, set_UID, i==0 ? +1 : +i , "UID"); break; + case 'U-': + i=atoiEx(args, &args); + change_value(get_UID, set_UID, i==0 ? -1 : -i , "UID"); break; + case 'N+': + i=atoiEx(args, &args); + change_value(get_nonce, set_nonce, i==0 ? +1 : +i, "nonce"); break; + case 'N-': + i=atoiEx(args, &args); + change_value(get_nonce, set_nonce, i==0 ? -1 : -i, "nonce"); break; case 'L': led = (led+1)%4; vLedSetRed( (led&1) ); |