blob: f12ad92740e14f6e4d12df1f375985a833892965 [file] [log] [blame]
Christina Quasta90eefa2015-02-24 17:52:29 +01001/* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2009, Atmel Corporation
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the disclaimer below.
13 *
14 * Atmel's name may not be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * ----------------------------------------------------------------------------
28 */
29
30/*------------------------------------------------------------------------------
31 * Headers
32 *------------------------------------------------------------------------------*/
33
34#include "board.h"
35
36#include <string.h>
37
38/*------------------------------------------------------------------------------
39 * Internal definitions
40 *------------------------------------------------------------------------------*/
Christina Quast4ba4d222015-03-02 16:14:09 +010041// FIXME: Remove:
42#define PR TRACE_DEBUG
Christina Quasta90eefa2015-02-24 17:52:29 +010043
44/** Maximum ucSize in bytes of the smartcard answer to a command.*/
45#define MAX_ANSWER_SIZE 10
46
47/** Maximum ATR ucSize in bytes.*/
48#define MAX_ATR_SIZE 55
Christina Quasta90eefa2015-02-24 17:52:29 +010049/*------------------------------------------------------------------------------
50 * Internal variables
51 *------------------------------------------------------------------------------*/
52/** ISO7816 pins */
53static const Pin pinsISO7816_sniff[] = {PINS_SIM_SNIFF_SIM};
Christina Quast27c643d2015-02-24 19:09:08 +010054static const Pin pins_bus[] = {PINS_BUS_SNIFF};
Christina Quasta90eefa2015-02-24 17:52:29 +010055static const Pin pPwr[] = {
56 /* Enable power converter 4.5-6V to 3.3V; low: off */
57 {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT},
58
Christina Quast27c643d2015-02-24 19:09:08 +010059 /* Enable second power converter: VCC_PHONE to VCC_SIM; high: on */
Christina Quasta90eefa2015-02-24 17:52:29 +010060 {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
61};
62
Christina Quastc0aa7692015-02-25 14:02:01 +010063extern uint32_t char_stat;
64extern uint8_t rcvdChar;
Christina Quast4ba4d222015-03-02 16:14:09 +010065extern ring_buffer buf;
Christina Quasta90eefa2015-02-24 17:52:29 +010066
67/*-----------------------------------------------------------------------------
Christina Quastd2b05f02015-02-25 18:44:24 +010068 * Initialization routine
Christina Quasta90eefa2015-02-24 17:52:29 +010069 *-----------------------------------------------------------------------------*/
Christina Quasta90eefa2015-02-24 17:52:29 +010070
71void Sniffer_Init( void )
72{
73 /* Configure ISO7816 driver */
74 PIO_Configure( pinsISO7816_sniff, PIO_LISTSIZE( pinsISO7816_sniff ) ) ;
75 PIO_Configure( pins_bus, PIO_LISTSIZE( pins_bus) ) ;
76
77 PIO_Configure(pPwr, PIO_LISTSIZE( pPwr ));
78
Christina Quastc0aa7692015-02-25 14:02:01 +010079 _ISO7816_Init();
Christina Quasta90eefa2015-02-24 17:52:29 +010080
Christina Quastc0aa7692015-02-25 14:02:01 +010081 USART_SetReceiverEnabled(USART_PHONE, 1);
Christina Quasta90eefa2015-02-24 17:52:29 +010082}
Christina Quastfb524b92015-02-27 13:39:45 +010083
84void Sniffer_run( void )
85{
86 if (rcvdChar != 0) {
Christina Quast4ba4d222015-03-02 16:14:09 +010087 /* DATA_IN for host side is data_out for simtrace side */
88 /* FIXME: Performancewise sending a USB packet for every byte is a disaster */
89 PR("----- %x %x %x ..\n\r", buf.buf[0], buf.buf[1],buf.buf[2] );
90 USBD_Write( DATAIN, buf.buf, BUFLEN, 0, 0 );
Christina Quast4ba4d222015-03-02 16:14:09 +010091 PR("----- Rcvd char\n\r");
Christina Quastfb524b92015-02-27 13:39:45 +010092 rcvdChar = 0;
93 }
94}