The Smart Card Detective (SCD)
Defines | Functions
apps.c File Reference

apps.c source file More...

#include <avr/boot.h>
#include <avr/io.h>
#include <avr/sleep.h>
#include <stdlib.h>
#include <string.h>
#include <util/delay.h>
#include "apps.h"
#include "emv.h"
#include "emv_values.h"
#include "scd.h"
#include "scd_hal.h"
#include "scd_io.h"
#include "scd_logger.h"
#include "scd_values.h"
#include "serial.h"
#include "terminal.h"
#include "utils.h"
#include "VirtualSerial.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 EEPROM_SIZE   4096
 size of SCD's EEPROM
#define BOOTLOADER_START_ADDRESS   0xF000
 address of bootloader section
#define TERMINAL_RESET_IO_WAIT   (ETU_TERMINAL * 42000)
 wait time for terminal reset or I/O lines to become low

Functions

uint8_t VirtualSerial (log_struct_t *logger)
uint8_t SerialInterface (uint16_t baudUBRR, log_struct_t *logger)
void EraseEEPROM ()
 Clears the contents of the EEPROM.
void ResetEEPROM ()
 Resets the data in EEPROM to default values.
void RunBootloader ()
 Jump to bootloader.
uint8_t TestDDA (uint8_t convention, uint8_t TC1)
uint8_t Terminal (log_struct_t *logger)
 Run the terminal application.
uint8_t FilterGenerateAC (log_struct_t *logger)
 Filter Generate AC command until user accepts or denies the transaction.
uint8_t StorePIN (log_struct_t *logger)
 Stores the PIN data from VERIFY command to EEPROM.
uint8_t ForwardAndChangePIN (log_struct_t *logger)
 Forward commands and modify VERIFY command with EEPROM PIN data.
uint8_t ForwardData (log_struct_t *logger)
 Forward commands between terminal and ICC through the ICC.
uint8_t ForwardDataLogAC (log_struct_t *logger)
 Forward commands and responses but log only from Generate AC onwards.
void WriteLogEEPROM (log_struct_t *logger)
 Write the log of the last transaction to EEPROM.

Detailed Description

apps.c source file

This file implements the applications available on the SCD

These functions are not microcontroller dependent but they are intended for the AVR 8-bit architecture

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 apps.c.


Define Documentation

#define BOOTLOADER_START_ADDRESS   0xF000

address of bootloader section

Definition at line 65 of file apps.c.

#define DEBUG   0

Set this to 1 to enable debug mode.

Definition at line 59 of file apps.c.

#define EEPROM_SIZE   4096

size of SCD's EEPROM

Definition at line 62 of file apps.c.

#define LCD_ENABLED   1

Set this to 1 to enable LCD functionality.

Definition at line 56 of file apps.c.

#define TERMINAL_RESET_IO_WAIT   (ETU_TERMINAL * 42000)

wait time for terminal reset or I/O lines to become low

Definition at line 68 of file apps.c.


Function Documentation

void EraseEEPROM ( )

Clears the contents of the EEPROM.

This function erases the entire contents of the EEPROM. Interrupts are disabled during operation.

Definition at line 194 of file apps.c.

uint8_t FilterGenerateAC ( log_struct_t logger)

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

Parameters:
loggerthe log structure or NULL if log is not desired
Returns:
0 if successful, non-zero otherwise

Definition at line 623 of file apps.c.

uint8_t ForwardAndChangePIN ( log_struct_t logger)

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.

Parameters:
loggerthe log structure or NULL if log is not desired
Returns:
0 if successful, non-zero otherwise
See also:
ForwardData

Definition at line 1035 of file apps.c.

uint8_t ForwardData ( log_struct_t logger)

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 log data into EEPROM as in the current implementation. The EEPROM data can then be retrieved using any programmer.

Parameters:
loggerthe log structure or NULL if log is not desired
Returns:
0 if successful, non-zero otherwise. See scd_values.h for details.

Definition at line 1198 of file apps.c.

uint8_t ForwardDataLogAC ( log_struct_t logger)

Forward commands and responses but log only from Generate AC onwards.

This function passively monitors a transaction, similarly to ForwardData, but it only logs the messages starting from the first Generate AC command in order to save space in EEPROM.

Parameters:
loggerthe log structure or NULL if log is not desired
Returns:
0 if successful, non-zero otherwise
See also:
ForwardData

Definition at line 1287 of file apps.c.

void ResetEEPROM ( )

Resets the data in EEPROM to default values.

Reset the data in EEPROM to default values. This method will first erase the EEPROM contents and then set the default values. Interrupts are disabled during operation.

See also:
EraseEEPROM

Definition at line 224 of file apps.c.

void RunBootloader ( )

Jump to bootloader.

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 247 of file apps.c.

uint8_t SerialInterface ( uint16_t  baudUBRR,
log_struct_t logger 
)

Serial Port interface application

Parameters:
baudUBRRthe baud UBRR parameter as given in table 18-12 of the datasheet, page 203. The formula is: baud = FCLK / (16 * (baudUBRR + 1)). So for FCLK = 16 MHz and desired BAUD = 9600 bps => baudUBRR = 103.
loggerthe log structure or NULL if no log is desired

Definition at line 147 of file apps.c.

uint8_t StorePIN ( log_struct_t logger)

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

Parameters:
loggerthe log structure or NULL if log is not desired
Returns:
This method returns zero (success) if the verify command is sent with plaintext PIN. The method returns non-zero otherwise.

Definition at line 926 of file apps.c.

uint8_t Terminal ( log_struct_t logger)

Run the terminal application.

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

Parameters:
loggerthe log structure or NULL if log is not desired
Returns:
0 if successful, non-zero otherwise

Definition at line 342 of file apps.c.

uint8_t TestDDA ( uint8_t  convention,
uint8_t  TC1 
)

Test function to make multiple DDA transactions

Definition at line 258 of file apps.c.

uint8_t VirtualSerial ( log_struct_t logger)

Virtual Serial Port application

Parameters:
loggerthe log structure.

Definition at line 88 of file apps.c.

void WriteLogEEPROM ( log_struct_t logger)

Write the log of the last transaction to EEPROM.

This method writes to EEPROM the log of the last transaction. The log is done either while monitoring a card-terminal transaction or by enabling logging while running other application (e.g. the Terminal() application).

Parameters:
loggerthe log structure. If this is NULL the function will exit promptly.

Definition at line 1417 of file apps.c.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines