summaryrefslogtreecommitdiff
path: root/openpicc/application/iso14443_sniffer.c
diff options
context:
space:
mode:
authorhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2008-02-09 17:49:39 +0000
committerhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2008-02-09 17:49:39 +0000
commit6be69f0de0c5455758c7ab3a6a3c7d37a061e5fa (patch)
tree54bc5f77817fd3e0f578ccc1b551363a6a193f70 /openpicc/application/iso14443_sniffer.c
parentf44e839dcc1ce0269c0608d76ee3d6fd222ba778 (diff)
Commit a first version of an iso 14443 layer 2 and a passive sniffer. Works for short frames, and sometimes even for long frames. Pending some major cleanup
git-svn-id: https://svn.openpcd.org:2342/trunk@408 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
Diffstat (limited to 'openpicc/application/iso14443_sniffer.c')
-rw-r--r--openpicc/application/iso14443_sniffer.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/openpicc/application/iso14443_sniffer.c b/openpicc/application/iso14443_sniffer.c
new file mode 100644
index 0000000..d5cf9c2
--- /dev/null
+++ b/openpicc/application/iso14443_sniffer.c
@@ -0,0 +1,109 @@
+/***************************************************************
+ *
+ * OpenPICC - ISO 14443 Layer 2 Type A Sniffer
+ * Also serves as PoC code for iso14443_layer2a usage
+ *
+ * Copyright 2008 Henryk Plötz <henryk@ploetzli.ch>
+ *
+ ***************************************************************
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#include <FreeRTOS.h>
+#include <board.h>
+#include <task.h>
+#include <errno.h>
+
+#include "openpicc.h"
+#include "iso14443_sniffer.h"
+#include "iso14443_layer2a.h"
+#include "iso14443a_miller.h"
+#include "usb_print.h"
+#include "cmd.h"
+
+static iso14443_frame rx_frame;
+
+void iso14443_sniffer (void *pvParameters)
+{
+ (void)pvParameters;
+ int res;
+
+ /* Delay until USB print etc. are ready */
+ vTaskDelay(1000 * portTICK_RATE_MS);
+
+ do {
+ res = iso14443_layer2a_init(0);
+ if(res < 0) {
+ usb_print_string("Sniffer: Initialization failed\n\r");
+ vTaskDelay(10000 * portTICK_RATE_MS);
+ }
+ } while(res < 0);
+
+ usb_print_string("Waiting for carrier. ");
+ while(iso14443_wait_for_carrier(1000 * portTICK_RATE_MS) != 0) {
+ }
+ usb_print_string("Carrier detected.\n\r");
+
+ iso14443_l2a_rx_start();
+ while(true) {
+ ssc_dma_rx_buffer_t *buffer = 0;
+ res = iso14443_receive(NULL, &buffer, 20000 * portTICK_RATE_MS);
+ if(res >= 0) {
+ DumpStringToUSB("\n\r");
+ DumpTimeToUSB(xTaskGetTickCount());
+ usb_print_string(": Frame received, consists of ");
+ DumpUIntToUSB(res);
+ usb_print_string(" transfers (");
+ DumpUIntToUSB(buffer->reception_mode->transfersize_ssc);
+ usb_print_string(" bits from SSC each)\n\r ");
+ if(buffer->len_transfers < 200)
+ DumpBufferToUSB((char*)buffer->data, (buffer->len_transfers * buffer->reception_mode->transfersize_pdc)/8);
+ else {
+ DumpBufferToUSB((char*)buffer->data, (200 * buffer->reception_mode->transfersize_pdc)/8);
+ usb_print_string("...");
+ }
+ usb_print_string("\n\r ");
+
+ iso14443a_decode_miller(&rx_frame, buffer);
+
+ usb_print_string("Decodes to ");
+ DumpUIntToUSB(rx_frame.numbytes);
+ usb_print_string(" bytes and ");
+ DumpUIntToUSB(rx_frame.numbits);
+ usb_print_string(" bits: ");
+ DumpBufferToUSB((char*)rx_frame.data, rx_frame.numbytes + (rx_frame.numbits+7)/8 );
+ usb_print_string("\n\r");
+
+ portENTER_CRITICAL();
+ buffer->state = FREE;
+ portEXIT_CRITICAL();
+ } else {
+ if(res != -ETIMEDOUT) {
+ usb_print_string("Receive error: ");
+ switch(res) {
+ case -ENETDOWN: usb_print_string("PLL is not locked or PLL lock lost\n\r"); break;
+ case -EBUSY: usb_print_string("A Tx is currently running or pending, can't receive\n\r"); break;
+ case -EALREADY: usb_print_string("There's already an iso14443_receive() invocation running\n\r"); break;
+ }
+ vTaskDelay(1000 * portTICK_RATE_MS); // FIXME Proper error handling, e.g. wait for Tx end in case of EBUSY
+ } else if(0) {
+ DumpStringToUSB("\n\r");
+ DumpTimeToUSB(xTaskGetTickCount());
+ usb_print_string(": -- Mark --");
+ }
+ }
+ }
+}
personal git repositories of Harald Welte. Your mileage may vary