blob: 3f16a7e1b5404f71e1bd602d1fe7e6e253f5de59 [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
Harald Welte2fb59962016-02-28 12:34:26 +010030#ifdef HAVE_SNIFFER
31
Christina Quasta90eefa2015-02-24 17:52:29 +010032/*------------------------------------------------------------------------------
33 * Headers
34 *------------------------------------------------------------------------------*/
35
36#include "board.h"
37
38#include <string.h>
39
40/*------------------------------------------------------------------------------
41 * Internal definitions
42 *------------------------------------------------------------------------------*/
43
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 */
Harald Welte7dd3dfd2016-03-03 12:32:04 +010053static const Pin pinsISO7816_sniff[] = { PINS_SIM_SNIFF_SIM };
54static const Pin pins_bus[] = { PINS_BUS_SNIFF };
55
Christina Quasta90eefa2015-02-24 17:52:29 +010056static const Pin pPwr[] = {
Harald Welte7dd3dfd2016-03-03 12:32:04 +010057 /* Enable power converter 4.5-6V to 3.3V; low: off */
58 {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT},
59
60 /* Enable second power converter: VCC_PHONE to VCC_SIM; high: on */
61 {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
Christina Quasta90eefa2015-02-24 17:52:29 +010062};
63
Harald Welte7dd3dfd2016-03-03 12:32:04 +010064static struct Usart_info usart_info = {
65 .base = USART_PHONE,
66 .id = ID_USART_PHONE,
67 .state = USART_RCV,
68};
Christina Quaste24b9ac2015-04-10 17:44:49 +020069
Christina Quasta90eefa2015-02-24 17:52:29 +010070/*-----------------------------------------------------------------------------
Christina Quastd2b05f02015-02-25 18:44:24 +010071 * Initialization routine
Christina Quasta90eefa2015-02-24 17:52:29 +010072 *-----------------------------------------------------------------------------*/
Christina Quasta90eefa2015-02-24 17:52:29 +010073
Harald Welte7dd3dfd2016-03-03 12:32:04 +010074void Sniffer_configure(void)
Christina Quasta90eefa2015-02-24 17:52:29 +010075{
Harald Welte7dd3dfd2016-03-03 12:32:04 +010076 TRACE_INFO("Sniffer config\n");
Christina Quasta90eefa2015-02-24 17:52:29 +010077}
Christina Quastfb524b92015-02-27 13:39:45 +010078
Harald Welte7dd3dfd2016-03-03 12:32:04 +010079void Sniffer_exit(void)
Christina Quastfb524b92015-02-27 13:39:45 +010080{
Harald Welte7dd3dfd2016-03-03 12:32:04 +010081 TRACE_INFO("Sniffer exit\n");
82 USART_DisableIt(USART_PHONE, US_IER_RXRDY);
83 NVIC_DisableIRQ(USART1_IRQn);
84 USART_SetReceiverEnabled(USART_PHONE, 0);
85}
86
87void Sniffer_init(void)
88{
89 TRACE_INFO("Sniffer Init\n");
90 /* Configure ISO7816 driver */
91 PIO_Configure(pinsISO7816_sniff, PIO_LISTSIZE(pinsISO7816_sniff));
92 PIO_Configure(pins_bus, PIO_LISTSIZE(pins_bus));
93
94 PIO_Configure(pPwr, PIO_LISTSIZE(pPwr));
95
96 ISO7816_Init(&usart_info, CLK_SLAVE);
97
98 USART_SetReceiverEnabled(USART_PHONE, 1);
99 USART_EnableIt(USART_PHONE, US_IER_RXRDY);
100 NVIC_EnableIRQ(USART1_IRQn);
101}
102
103void Sniffer_run(void)
104{
105 check_data_from_phone();
Christina Quastfb524b92015-02-27 13:39:45 +0100106}
Harald Welte2fb59962016-02-28 12:34:26 +0100107#endif /* HAVE_SNIFFER */