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 |
CRP * | transactionData [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) |
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 ICC_PRES_INT_ENABLE 1 |
#define LCD_ENABLED 1 |
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
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
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.
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.
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.
void InitSCD | ( | ) |
ISR | ( | TIMER3_COMPA_vect | , | |
ISR_NAKED | ||||
) |
ISR | ( | INT1_vect | ) |
ISR | ( | INT0_vect | ) |
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.
void SleepUntilCardInserted | ( | ) |
void SleepUntilTerminalClock | ( | ) |
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
void SwitchLeds | ( | ) |
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).
uint8_t TestDDA | ( | uint8_t | convention, | |
uint8_t | TC1 | |||
) |
void TestHardware | ( | ) |
void TestSCDICC | ( | ) |
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
FILE lcd_str = FDEV_SETUP_STREAM(LcdPutchar, NULL, _FDEV_SETUP_WRITE) |
uint8_t lcdAvailable |
uint8_t nTransactions |
CRP* transactionData[MAX_EXCHANGES] |
uint8_t warmResetByte |