From 6be69f0de0c5455758c7ab3a6a3c7d37a061e5fa Mon Sep 17 00:00:00 2001 From: henryk Date: Sat, 9 Feb 2008 17:49:39 +0000 Subject: 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 --- openpicc/application/iso14443_sniffer.c | 109 ++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 openpicc/application/iso14443_sniffer.c (limited to 'openpicc/application/iso14443_sniffer.c') 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 + * + *************************************************************** + + 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 +#include +#include +#include + +#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 --"); + } + } + } +} -- cgit v1.2.3