scd.h File Reference

scd.h Header file More...

Go to the source code of this file.

Defines

#define WARM_RESET_VALUE   0xAA
 This is a magic value that may be used in detecting a warm reset.
#define MAX_EXCHANGES   50
 Maximum number of command-response pairs recorded when logging.
#define EEPROM_WARM_RESET   0x0
 EEPROM address for byte used on warm reset.
#define EEPROM_PIN   0x8
 EEPROM address for stored PIN.
#define EEPROM_APPLICATION   0x32
 EEPROM address for selected application.
#define EEPROM_COUNTER   0x40
 EEPROM address for transaction counter.
#define EEPROM_TLOG_POINTER_HI   0x48
 EEPROM address for log high address pointer.
#define EEPROM_TLOG_POINTER_LO   0x49
 EEPROM address for log low address pointer.
#define EEPROM_TLOG_DATA   0x80
 EEPROM address for transaction log data.
#define EEPROM_MAX_ADDRESS   0xFE0
 EEPROM maximum allowed address.
#define APP_STORE_PIN   0x01
 Store PIN.
#define APP_LOG_FORWARD   0x02
 Forward Commands and make log.
#define APP_FW_MODIFY_PIN   0x03
 Forward Commands and Modify PIN.
#define APP_FILTER_GENERATEAC   0x04
 Filter Transaction Amount.
#define APP_FILTER_LOG   0x05
 Filter amount and log commands.
#define APP_ERASE_EEPROM   0x06
 Erase EEPROM.
#define APP_TERMINAL_1   0x07
 Terminal application.
#define APPLICATION_COUNT   7
 Number of existing applications.

Functions

int main (void)
 Main function.
void InitSCD ()
 Initializes the SCD.
uint8_t SelectApplication ()
 Show menu and select application.
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.
void TestHardware ()
 Tests the hardware (LEDs, LCD and buttons).
uint8_t ForwardData ()
 Forward commands between terminal and ICC through the ICC.
uint8_t FilterGenerateACSimple ()
 Hard-codded version of the FilterGenerateAC function.
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 Terminal1 ()
 Run the terminal application Terminal1.
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.

Detailed Description

scd.h Header file

Contains definitions of functions used by the Smart Card Detective including filtering and modification of EMV commands

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.h.


Define Documentation

#define APP_ERASE_EEPROM   0x06

Erase EEPROM.

Definition at line 73 of file scd.h.

#define APP_FILTER_GENERATEAC   0x04

Filter Transaction Amount.

Definition at line 67 of file scd.h.

#define APP_FILTER_LOG   0x05

Filter amount and log commands.

Definition at line 70 of file scd.h.

#define APP_FW_MODIFY_PIN   0x03

Forward Commands and Modify PIN.

Definition at line 64 of file scd.h.

#define APP_LOG_FORWARD   0x02

Forward Commands and make log.

Definition at line 61 of file scd.h.

#define APP_STORE_PIN   0x01

Store PIN.

Definition at line 58 of file scd.h.

#define APP_TERMINAL_1   0x07

Terminal application.

Definition at line 76 of file scd.h.

#define APPLICATION_COUNT   7

Number of existing applications.

Definition at line 79 of file scd.h.

#define EEPROM_APPLICATION   0x32

EEPROM address for selected application.

Definition at line 40 of file scd.h.

#define EEPROM_COUNTER   0x40

EEPROM address for transaction counter.

Definition at line 43 of file scd.h.

#define EEPROM_MAX_ADDRESS   0xFE0

EEPROM maximum allowed address.

Definition at line 55 of file scd.h.

#define EEPROM_PIN   0x8

EEPROM address for stored PIN.

Definition at line 37 of file scd.h.

#define EEPROM_TLOG_DATA   0x80

EEPROM address for transaction log data.

Definition at line 52 of file scd.h.

#define EEPROM_TLOG_POINTER_HI   0x48

EEPROM address for log high address pointer.

Definition at line 46 of file scd.h.

#define EEPROM_TLOG_POINTER_LO   0x49

EEPROM address for log low address pointer.

Definition at line 49 of file scd.h.

#define EEPROM_WARM_RESET   0x0

EEPROM address for byte used on warm reset.

Definition at line 34 of file scd.h.

#define MAX_EXCHANGES   50

Maximum number of command-response pairs recorded when logging.

Definition at line 31 of file scd.h.

#define WARM_RESET_VALUE   0xAA

This is a magic value that may be used in detecting a warm reset.

Definition at line 28 of file scd.h.


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.

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.

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.

 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