From 6b18612b08254413bf7a34da229bddd39f6b1f2d Mon Sep 17 00:00:00 2001 From: henryk Date: Mon, 28 Apr 2008 16:24:30 +0000 Subject: Add code to change uid/nonce on the fly git-svn-id: https://svn.openpcd.org:2342/trunk@475 6dc7ffe9-61d6-0310-9af1-9938baff3ed1 --- openpicc/application/cmd.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'openpicc') 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) ); -- cgit v1.2.3