summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2008-04-28 16:24:30 +0000
committerhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2008-04-28 16:24:30 +0000
commit6b18612b08254413bf7a34da229bddd39f6b1f2d (patch)
tree96bf2f0fc2f46001f2bf68053e598c5bde2524b0
parent640d692258d118779a184bbd512f979fe2b1f891 (diff)
Add code to change uid/nonce on the fly
git-svn-id: https://svn.openpcd.org:2342/trunk@475 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
-rw-r--r--openpicc/application/cmd.c44
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) );
personal git repositories of Harald Welte. Your mileage may vary