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 <stdlib.h>
#include <avr/wdt.h>
#include "emv.h"
#include "scd_hal.h"
#include "scd_io.h"
#include <stdio.h>
#include "emv_values.h"
#include "scd_values.h"

Go to the source code of this file.

Defines

#define F_CPU   16000000UL
#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.
uint8_t TestDDA (uint8_t convention, uint8_t TC1)
uint8_t Terminal1 ()
 Run the terminal application Terminal1.
uint8_t FilterGenerateAC ()
 Filter Generate AC command until user accepts or denies the transaction.
uint8_t StorePIN ()
 Stores the PIN data from VERIFY command to EEPROM.
uint8_t ForwardAndChangePIN ()
 Forward commands and modify VERIFY command with EEPROM PIN data.
uint8_t FilterAndLog ()
 Filter Generate AC command and log transaction.
uint8_t ForwardData ()
 Forward commands between terminal and ICC through the ICC.
void InitSCD ()
 Initializes the SCD.
void SleepUntilTerminalClock ()
 Puts the SCD to sleep until receives clock from terminal.
void SleepUntilCardInserted ()
 Puts the SCD to sleep until card is inserted or removed.
 ISR (INT0_vect)
 ISR (INT1_vect)
 ISR (TIMER3_COMPA_vect, ISR_NAKED)
void TestHardware ()
 Tests the hardware (LEDs, LCD and buttons).
uint8_t FilterGenerateACSimple ()
 Hard-codded version of the FilterGenerateAC function.
void TestSCDTerminal ()
 Tests the SCD-Terminal communication.
void TestSCDICC ()
 Tests the SCD-ICC communication.
void SwitchLeds ()
 Simple application to switch some LEDs on and off.

Variables

uint8_t warmResetByte
CRPtransactionData [MAX_EXCHANGES]
uint8_t nTransactions
uint8_t lcdAvailable
uint8_t nCounter
uint8_t selected
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 halSCD.h and EMV.h to communicate with the ICC and Terminal and the functions from scdIO.h to communicate with the LCD, buttons and LEDs

Copyright (C) 2010 Omar Choudary (osc22@cam.ac.uk)

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, either version 3 of the License, or (at your option) any later version.

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, see <http://www.gnu.org/licenses/>.

Definition in file scd.c.


Define Documentation

#define DEBUG   0

Set this to 1 to enable debug mode.

Definition at line 58 of file scd.c.

#define F_CPU   16000000UL

Definition at line 28 of file scd.c.

#define ICC_PRES_INT_ENABLE   1

Set this to 1 to enable card presence interrupt.

Definition at line 61 of file scd.c.

#define LCD_ENABLED   1

Set this to 1 to enable LCD functionality.

Definition at line 55 of file scd.c.


Function Documentation

uint8_t FilterAndLog (  ) 

Filter Generate AC command and log transaction.

This function filters the Generate AC command just like the FilterGenerateAC function but it also logs all the information about the transaction

Returns:
0 if successful, non-zero otherwise
See also:
FilterGenerateAC

Definition at line 1035 of file scd.c.

uint8_t FilterGenerateAC (  ) 

Filter Generate AC command until user accepts or denies the transaction.

This function initiates the communication between ICC and terminal and then forwards the commands and responses from terminal to ICC but blocks the Generate AC request until the user accepts or denies the transaction.

Transaction amount is displayed on LCD and thus the LCD is required for this application.

If the terminal enables the reset line (either by warm reset or by interrupting the transaction the INT0 interrupt routing will be called

Returns:
0 if successful, non-zero otherwise

Definition at line 521 of file scd.c.

uint8_t FilterGenerateACSimple (  ) 

Hard-codded version of the FilterGenerateAC function.

This function initiates the communication between ICC and terminal and then forwards the commands and responses from terminal to ICC but blocks the Generate AC request until the user accepts or denies the transaction *

If the terminal enables the reset line (either by warm reset or by interrupting the transaction the INT0 interrupt routing will be called

This function uses hard-coded data. Please use FilterGenerateAC instead.

Returns:
0 if successful, non-zero otherwise
See also:
FilterGenerateAC

Definition at line 1763 of file scd.c.

uint8_t ForwardAndChangePIN (  ) 

Forward commands and modify VERIFY command with EEPROM PIN data.

This function is similar to ForwardData but it modifies the VERIFY command. The command data of the VERIFY command is replaced with stored data in EEPROM when the command is sent to the ICC.

Returns:
0 if successful, non-zero otherwise
See also:
ForwardData

Definition at line 897 of file scd.c.

uint8_t ForwardData (  ) 

Forward commands between terminal and ICC through the ICC.

This function initiates the communication between ICC and terminal and then forwards the commands and responses from terminal to ICC and back until the terminal sends a reset signal.

When a reset signal is received the SCD restarts. The reset signal can be used to copy the transaction data into EEPROM as in the current implementation. The EEPROM data can then be retrieved using any programmer.

Returns:
0 if successful, non-zero otherwise

Definition at line 1341 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 1405 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 1692 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 1673 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 1557 of file scd.c.

int main ( void   ) 

Main function.

Main program

Definition at line 107 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 200 of file scd.c.

void SleepUntilCardInserted (  ) 

Puts the SCD to sleep until card is inserted or removed.

This function puts the SCD to sleep (including all peripherials), until the card is inserted or removed

Definition at line 1524 of file scd.c.

void SleepUntilTerminalClock (  ) 

Puts the SCD to sleep until receives clock from terminal.

This function puts the SCD to sleep (including all peripherials), until there is clock received from terminal

Definition at line 1486 of file scd.c.

uint8_t StorePIN (  ) 

Stores the PIN data from VERIFY command to EEPROM.

This function forwards commands between the terminal and ICC much like the ForwardData method, but when it receives the Verify command it stores the PIN entered by the user in the EEPROM. This is useful in order to store the PIN once and then use it in further transactions so that the original PIN is never revealed.

This method returns immediately after receiving the verify command. Thus PIN entry should be done for example using a CAP reader, where the completion of this transaction is not essential.

The PIN is stored in the EEPROM at the address mentioned by the parameter EEPROM_PIN

Returns:
This method returns zero (success) if the verify command is sent with plaintext PIN. The method returns non-zero otherwise.

Definition at line 794 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 2142 of file scd.c.

uint8_t Terminal1 (  ) 

Run the terminal application Terminal1.

This method implements a terminal application with the basic steps of an EMV transaction. This includes selection by AID, DDA signature, PIN verification and transaction data authorization (Generate AC).

Returns:
0 if successful, non-zero otherwise

Definition at line 332 of file scd.c.

uint8_t TestDDA ( uint8_t  convention,
uint8_t  TC1 
)

Test function to make multiple DDA transactions

Definition at line 249 of file scd.c.

void TestHardware (  ) 

Tests the hardware (LEDs, LCD and buttons).

This function performs a test of the hardware.

Definition at line 1700 of file scd.c.

void TestSCDICC (  ) 

Tests the SCD-ICC communication.

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

Definition at line 2053 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 1917 of file scd.c.


Variable Documentation

FILE lcd_str = FDEV_SETUP_STREAM(LcdPutchar, NULL, _FDEV_SETUP_WRITE)

Definition at line 101 of file scd.c.

uint8_t lcdAvailable

Definition at line 95 of file scd.c.

uint8_t nCounter

Definition at line 96 of file scd.c.

uint8_t nTransactions

Definition at line 94 of file scd.c.

uint8_t selected

Definition at line 97 of file scd.c.

CRP* transactionData[MAX_EXCHANGES]

Definition at line 93 of file scd.c.

uint8_t warmResetByte

Definition at line 92 of file scd.c.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
Generated on Wed Mar 16 14:48:51 2011 for The Smart Card Detective (SCD) by  doxygen 1.6.3