summaryrefslogtreecommitdiff
path: root/openpicc
diff options
context:
space:
mode:
authorhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2008-04-28 16:24:08 +0000
committerhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2008-04-28 16:24:08 +0000
commit640d692258d118779a184bbd512f979fe2b1f891 (patch)
tree3016806135ba2225ce2fe3f0a553eef122d69797 /openpicc
parent64dfc1c67cb3e7c841836a8cda915ced07892330 (diff)
Check received length of the frame that is supposed to contain the PCD challenge
Add code to get/set uid/nonce git-svn-id: https://svn.openpcd.org:2342/trunk@474 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
Diffstat (limited to 'openpicc')
-rw-r--r--openpicc/application/iso14443a_pretender.c30
-rw-r--r--openpicc/application/iso14443a_pretender.h5
2 files changed, 30 insertions, 5 deletions
diff --git a/openpicc/application/iso14443a_pretender.c b/openpicc/application/iso14443a_pretender.c
index 0ecaaac..917ab47 100644
--- a/openpicc/application/iso14443a_pretender.c
+++ b/openpicc/application/iso14443a_pretender.c
@@ -47,6 +47,7 @@ struct challenge_response {
struct {
u_int8_t data[8];
u_int8_t parity[2];
+ size_t len;
} response;
};
@@ -73,7 +74,8 @@ static const iso14443_frame ATS_FRAME = {
};
static iso14443_frame UID_FRAME, NONCE_FRAME;
-static u_int8_t UID[] = {0xF4, 0xAC, 0xF9, 0xD7}; // bcc = 0x76
+//static u_int8_t UID[] = {0xF4, 0xAC, 0xF9, 0xD7}; // bcc = 0x76
+static u_int8_t UID[] = {0x00, 0x00, 0x00, 0x00};
static u_int8_t nonce[] = {0x00, 0x00, 0x00, 0x00};
#define FRAME_SIZE(bytes) (2* (1+(9*bytes)+1) )
@@ -191,17 +193,21 @@ static void fast_receive_callback(ssc_dma_rx_buffer_t *buffer, iso14443_frame *f
challenge_response.waiting_for_response = 1;
usb_print_string_f("nonce", 0);
} else if(challenge_response.waiting_for_response) {
- memcpy(&challenge_response.response.data, frame->data, 8);
- memcpy(&challenge_response.response.parity, frame->parity, 1);
challenge_response.waiting_for_response = 0;
-
+ if(frame->numbytes != 8) {
+ usb_print_string_f("tilt ",0);
+ }
+ challenge_response.response.len = frame->numbytes + (frame->numbits+7)/8;
+ memcpy(&challenge_response.response.data, frame->data, challenge_response.response.len);
+ memcpy(&challenge_response.response.parity, frame->parity, 1);
+
int old=usb_print_set_default_flush(0);
DumpStringToUSB("[[");
DumpBufferToUSB((char*)challenge_response.UID, 5);
DumpStringToUSB(" ");
DumpBufferToUSB((char*)challenge_response.nonce, 4);
DumpStringToUSB(" ");
- DumpBufferToUSB((char*)challenge_response.response.data, 8);
+ DumpBufferToUSB((char*)challenge_response.response.data, challenge_response.response.len);
DumpStringToUSB("]]");
usb_print_set_default_flush(old);
}
@@ -241,6 +247,13 @@ int set_UID(u_int8_t *uid, size_t len)
return 0;
}
+int get_UID(u_int8_t *uid, size_t len)
+{
+ if(len < 4 || len > 4) return -1;
+ memcpy(uid, UID, len);
+ return 0;
+}
+
int set_nonce(u_int8_t *_nonce, size_t len)
{
prepare_frame(&NONCE_FRAME, len);
@@ -256,6 +269,13 @@ int set_nonce(u_int8_t *_nonce, size_t len)
return 0;
}
+int get_nonce(u_int8_t *_nonce, size_t len)
+{
+ if(len < 4 || len > 4) return -1;
+ memcpy(_nonce, nonce, len);
+ return 0;
+}
+
void iso14443a_pretender (void *pvParameters)
{
(void)pvParameters;
diff --git a/openpicc/application/iso14443a_pretender.h b/openpicc/application/iso14443a_pretender.h
index 0d7042b..ad4ac5b 100644
--- a/openpicc/application/iso14443a_pretender.h
+++ b/openpicc/application/iso14443a_pretender.h
@@ -2,6 +2,11 @@
#define ISO14443A_PRETENDER_H_
extern void iso14443a_pretender (void *pvParameters);
+
extern int set_UID(u_int8_t *uid, size_t len);
+extern int get_UID(u_int8_t *uid, size_t len);
+
+extern int set_nonce(u_int8_t *uid, size_t len);
+extern int get_nonce(u_int8_t *uid, size_t len);
#endif /*ISO14443A_PRETENDER_H_*/
personal git repositories of Harald Welte. Your mileage may vary