scd.c File Reference

scd.c source file for Smart Card Detective More...

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/eeprom.h>
#include <string.h>
#include <util/delay.h>
#include <util/delay_basic.h>
#include <stdlib.h>
#include <avr/wdt.h>
#include "apps.h"
#include "emv.h"
#include "scd_hal.h"
#include "scd_io.h"
#include "scd.h"
#include "scd_logger.h"
#include "utils.h"
#include "emv_values.h"
#include "scd_values.h"
#include "VirtualSerial.h"
#include "serial.h"

Go to the source code of this file.

Defines

#define LCD_ENABLED   1
 Set this to 1 to enable LCD functionality.
#define DEBUG   0
 Set this to 1 to enable debug mode.
#define ICC_PRES_INT_ENABLE   1
 Set this to 1 to enable card presence interrupt.

Functions

int main (void)
 Main function.
uint8_t SelectApplication ()
 Show menu and select application.
void InitSCD ()
 Initializes the SCD.
 ISR (INT0_vect)
 ISR (INT1_vect)
 ISR (WDT_vect)
 ISR (TIMER3_COMPA_vect, ISR_NAKED)
void BootloaderJumpCheck ()
void TestHardware ()
 Tests the hardware (LEDs, LCD and buttons).
void TestSCDTerminal ()
 Tests the SCD-Terminal communication.
void TestSCDICC (log_struct_t *logger)
void SwitchLeds ()
 Simple application to switch some LEDs on and off.

Variables

log_struct_t scd_logger
uint8_t warmResetByte
uint8_t lcdAvailable
uint8_t nCounter
uint8_t selected
uint8_t bootkey
uint16_t revision = 0x24
FILE lcd_str = FDEV_SETUP_STREAM(LcdPutchar, NULL, _FDEV_SETUP_WRITE)

Detailed Description

scd.c source file for Smart Card Detective

This file implements the main application of the Smart Card Detective

It uses the functions defined in scd_hal.h and emv.h to communicate with the ICC and Terminal and the functions from scd_io.h to communicate with the LCD, buttons and LEDs

Copyright (C) 2012 Omar Choudary (omar.choudary@cl.cam.ac.uk)

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file scd.c.


Define Documentation

#define DEBUG   0

Set this to 1 to enable debug mode.

Definition at line 70 of file scd.c.

#define ICC_PRES_INT_ENABLE   1

Set this to 1 to enable card presence interrupt.

Definition at line 73 of file scd.c.

#define LCD_ENABLED   1

Set this to 1 to enable LCD functionality.

Definition at line 67 of file scd.c.


Function Documentation

void BootloaderJumpCheck ( void   ) 

Interrupt routine for Timer2 Compare Match A overflow. This interrupt can fire when the Timer2 matches the OCR2A value and the corresponding interrupt is enabled. We could put the IncrementCounter() code directly into the subroutine to save some clock cycles but we must take care to save all used registers since they are probably used by other functions.

Uncomment the code below to combine avr-gcc handling of register with the IncrementCounter assembler routine. Else the interrupt handler is entirely in assembler without calling the extra function.

See also:
file scd.S Jump into the Bootloader application, typically the DFU bootloader for USB programming.

Code taken from: http://www.fourwalledcubicle.com/files/LUFA/Doc/100807/html/_page__software_bootloader_start.html

Definition at line 465 of file scd.c.

void InitSCD (  ) 

Initializes the SCD.

This method should be called before any other operation. It sets the I/O ports to a correct state and it also recovers any necessary data from EEPROM.

Definition at line 261 of file scd.c.

ISR ( TIMER3_COMPA_vect  ,
ISR_NAKED   
)

Interrupt routine for Timer3 Compare Match A overflow. This interrupt can fire when the Timer3 matches the OCR3A value and the corresponding interrupt is enabled

Definition at line 434 of file scd.c.

ISR ( WDT_vect   ) 

Interrupt routine for the Watch Dog Timer.

Definition at line 418 of file scd.c.

ISR ( INT1_vect   ) 

Interrupt routine for INT1. This interrupt can fire when the ICC is inserted or removed and the corresponding interrupt is enabled

Definition at line 401 of file scd.c.

ISR ( INT0_vect   ) 

Interrupt routine for INT0. This interrupt can fire when the reset signal from the Terminal goes low (active) and the corresponding interrupt is enabled

Definition at line 350 of file scd.c.

int main ( void   ) 

Main function.

Main program

Definition at line 109 of file scd.c.

uint8_t SelectApplication (  ) 

Show menu and select application.

This function shows a menu with the existing applications and allows the user to select one of them.

The different applications are shown on the LCD and the user can use the buttons to scroll between the list and to select the desired application.

Returns:
a number representing the selected application. The relation between numbers and applications is done by the define directives (APP_STORE_PIN, etc.). If any error occurs, this method will return 0 (i.e. no application selected).

Definition at line 210 of file scd.c.

void SwitchLeds (  ) 

Simple application to switch some LEDs on and off.

This function is used just to switch leds on and off

Definition at line 778 of file scd.c.

void TestHardware (  ) 

Tests the hardware (LEDs, LCD and buttons).

This function performs a test of the hardware.

Definition at line 496 of file scd.c.

void TestSCDICC ( log_struct_t logger  ) 

This function makes a simple test with the ICC

It powers the ICC, expects the ATR and sends a select command, waiting also for the answer

Parameters:
logger the log structure or NULL if no log is desired

Definition at line 689 of file scd.c.

void TestSCDTerminal (  ) 

Tests the SCD-Terminal communication.

This function implements an infinite communication loop between the SCD and my terminal emulator, by continuously replying to the SELECT command for "1PAY.SYS.DDF01"

The main role of this function is to test the correct transfer of bytes between the terminal and the SCD

Definition at line 551 of file scd.c.


Variable Documentation

uint8_t bootkey

Definition at line 99 of file scd.c.

FILE lcd_str = FDEV_SETUP_STREAM(LcdPutchar, NULL, _FDEV_SETUP_WRITE)

Definition at line 103 of file scd.c.

uint8_t lcdAvailable

Definition at line 96 of file scd.c.

uint8_t nCounter

Definition at line 97 of file scd.c.

uint16_t revision = 0x24

Definition at line 100 of file scd.c.

Definition at line 92 of file scd.c.

uint8_t selected

Definition at line 98 of file scd.c.

uint8_t warmResetByte

Definition at line 95 of file scd.c.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
Generated on Tue Apr 24 12:00:29 2012 for The Smart Card Detective (SCD) by  doxygen 1.6.3