#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 <stdint.h>
#include "scd_logger.h"
#include "emv.h"
#include <stdio.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. |
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 BOOTLOADER_START_ADDRESS 0xF000 |
#define LCD_ENABLED 1 |
#define TERMINAL_RESET_IO_WAIT (ETU_TERMINAL * 42000) |
void EraseEEPROM | ( | ) |
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
logger | the log structure or NULL if log is not desired |
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.
logger | the log structure or NULL if log is not desired |
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.
logger | the log structure or NULL if log is not desired |
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.
logger | the log structure or NULL if log is not desired |
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.
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
uint8_t SerialInterface | ( | uint16_t | baudUBRR, | |
log_struct_t * | logger | |||
) |
Serial Port interface application
baudUBRR | the 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. | |
logger | the log structure or NULL if no log is desired |
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
logger | the log structure or NULL if log is not desired |
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).
logger | the log structure or NULL if log is not desired |
uint8_t TestDDA | ( | uint8_t | convention, | |
uint8_t | TC1 | |||
) |
uint8_t VirtualSerial | ( | log_struct_t * | logger | ) |
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).
logger | the log structure. If this is NULL the function will exit promptly. |