halSCD.h File Reference

halSCD.h header file More...

Go to the source code of this file.

Functions

uint16_t GetTerminalFreq ()
 Returns the frequency of the terminal clock in khz, zero if there is no clock.
uint16_t ReadCounterTerminal ()
 Reads the value of the terminal counter.
void StartCounterTerminal ()
 Starts the counter for the external clock given by the terminal.
void StopCounterTerminal ()
 Stops the terminal clock counter.
void PauseCounterTerminal ()
 Pauses the terminal clock counter.
uint8_t GetResetStateTerminal ()
 Retrieves the state of the reset line from the terminal.
uint8_t SendByteTerminalParity (uint8_t byte, uint8_t inverse_convention)
 Sends a byte to the terminal with parity check.
void SendByteTerminalNoParity (uint8_t byte, uint8_t inverse_convention)
 Sends a byte to the terminal without parity check.
uint8_t GetByteTerminalParity (uint8_t inverse_convention, uint8_t *r_byte)
 Receives a byte from the terminal with parity check.
uint8_t GetByteTerminalNoParity (uint8_t inverse_convention, uint8_t *r_byte)
 Receives a byte from the terminal without parity check.
void LoopTerminalETU (uint8_t nEtus)
 Waits (loops) for a number of nEtus based on the Terminal clock.
void SendT0ATRTerminal (uint8_t inverse_convention, uint8_t TC1)
 Sends default ATR for T=0 to terminal.
uint8_t IsICCInserted ()
 Returns non-zero if ICC is inserted, zero otherwise.
uint8_t IsICCPowered ()
 Returns non-zero if ICC is powered up.
uint8_t PowerUpIcc ()
 Powers up the card, if possible.
void PowerDownICC ()
 Powers down the ICC.
void LoopICCETU (uint8_t nEtus)
 Waits (loops) for a number of nEtus based on the ICC clock.
uint8_t WaitForICCData (uint16_t max_cycles)
 Loops for max_cycles or until the I/O line from ICC becomes low.
uint8_t GetByteICCNoParity (uint8_t inverse_convention, uint8_t *r_byte)
 Receives a byte from the ICC without parity checking.
uint8_t GetByteICCParity (uint8_t inverse_convention, uint8_t *r_byte)
 Receives a byte from the ICC with parity checking.
void SendByteICCNoParity (uint8_t byte, uint8_t inverse_convention)
 Sends a byte to the ICC without parity check.
uint8_t SendByteICCParity (uint8_t byte, uint8_t inverse_convention)
 Sends a byte to the ICC with parity check.
uint8_t GetATRICC (uint8_t *inverse_convention, uint8_t *proto, uint8_t *TC1, uint8_t *TA3, uint8_t *TB3)
 Receives the ATR from ICC after a successful activation.
uint8_t ResetICC (uint8_t warm, uint8_t *inverse_convention, uint8_t *proto, uint8_t *TC1, uint8_t *TA3, uint8_t *TB3)
 Starts a cold or warm reset for ICC.
uint8_t ActivateICC (uint8_t warm)
 Starts the activation sequence for the ICC.
void DeactivateICC ()
 Starts the deactivation sequence for the ICC.

Detailed Description

halSCD.h header file

This file provides an abstract definition for all micro-controller dependent functions that are used in the Smartcard Defender

For each microcontroller a different halSCD.c source file should be used.

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


Function Documentation

uint8_t ActivateICC ( uint8_t  warm  ) 

Starts the activation sequence for the ICC.

Starts the activation sequence for the ICC

Parameters:
warm if warm=1 it specifies a warm reset activation, cold reset otherwise *
Returns:
0 if successful, non-zero otherwise

Definition at line 1128 of file halSCD.c.

void DeactivateICC (  ) 

Starts the deactivation sequence for the ICC.

Starts the deactivation sequence for the ICC

Definition at line 1188 of file halSCD.c.

uint8_t GetATRICC ( uint8_t *  inverse_convention,
uint8_t *  proto,
uint8_t *  TC1,
uint8_t *  TA3,
uint8_t *  TB3 
)

Receives the ATR from ICC after a successful activation.

Receives the ATR from ICC after a successful activation

Parameters:
inverse_convention non-zero if inverse convention is to be used
proto 0 for T=0 and non-zero for T=1
TC1 see ISO 7816-3 or EMV Book 1 section ATR
TA3 see ISO 7816-3 or EMV Book 1 section ATR
TB3 see ISO 7816-3 or EMV Book 1 section ATR
Returns:
zero if successful, non-zero otherwise

This implementation is compliant with EMV 4.2 Book 1

Definition at line 942 of file halSCD.c.

uint8_t GetByteICCNoParity ( uint8_t  inverse_convention,
uint8_t *  r_byte 
)

Receives a byte from the ICC without parity checking.

Receives a byte from the ICC without parity checking

Parameters:
inverse_convention different than 0 if inverse convention is to be used *
r_byte contains the byte read on return
Returns:
zero if read was successful, non-zero otherwise

ICC clock counter must be already enabled

Definition at line 660 of file halSCD.c.

uint8_t GetByteICCParity ( uint8_t  inverse_convention,
uint8_t *  r_byte 
)

Receives a byte from the ICC with parity checking.

Receives a byte from the ICC with parity checking

Parameters:
inverse_convention different than 0 if inverse convention is to be used *
r_byte contains the byte read on return
Returns:
zero if read was successful, non-zero otherwise

ICC clock counter must be already enabled

Definition at line 748 of file halSCD.c.

uint8_t GetByteTerminalNoParity ( uint8_t  inverse_convention,
uint8_t *  r_byte 
)

Receives a byte from the terminal without parity check.

Receives a byte from the terminal without parity checking

Parameters:
inverse_convention different than 0 if inverse convention is to be used
r_byte contains the byte read on return
Returns:
zero if read was successful, non-zero otherwise

Terminal clock counter must be already enabled

Definition at line 399 of file halSCD.c.

uint8_t GetByteTerminalParity ( uint8_t  inverse_convention,
uint8_t *  r_byte 
)

Receives a byte from the terminal with parity check.

Receives a byte from the terminal with parity checking

Parameters:
inverse_convention different than 0 if inverse convention is to be used
r_byte contains the byte read on return
Returns:
zero if read was successful, non-zero otherwise

Terminal clock counter must be enabled before calling this function

Definition at line 484 of file halSCD.c.

uint8_t GetResetStateTerminal (  ) 

Retrieves the state of the reset line from the terminal.

Retrieves the state of the reset line from the terminal

Returns:
0 if reset is low, non-zero otherwise

Definition at line 192 of file halSCD.c.

uint16_t GetTerminalFreq (  ) 

Returns the frequency of the terminal clock in khz, zero if there is no clock.

Returns:
the frequency of the terminal clock in khz, zero if there is no clock

Assumes the terminal counter is already started (Timer 3)

Definition at line 57 of file halSCD.c.

uint8_t IsICCInserted (  ) 

Returns non-zero if ICC is inserted, zero otherwise.

SCD to ICC functions

Returns non-zero if ICC is inserted, zero otherwise

Definition at line 561 of file halSCD.c.

uint8_t IsICCPowered (  ) 

Returns non-zero if ICC is powered up.

Returns non-zero if ICC is powered up

Definition at line 570 of file halSCD.c.

void LoopICCETU ( uint8_t  nEtus  ) 

Waits (loops) for a number of nEtus based on the ICC clock.

Waits (loops) for a number of nEtus based on the ICC clock

Parameters:
nEtus the number of ETUs to loop

Assumes the ICC clock counter is already started

Definition at line 608 of file halSCD.c.

void LoopTerminalETU ( uint8_t  nEtus  ) 

Waits (loops) for a number of nEtus based on the Terminal clock.

Waits (loops) for a number of nEtus based on the Terminal clock

Parameters:
nEtus the number of ETUs to loop

Assumes the terminal clock counter is already started

Definition at line 204 of file halSCD.c.

void PauseCounterTerminal (  ) 

Pauses the terminal clock counter.

Pauses the terminal clock counter

Definition at line 182 of file halSCD.c.

void PowerDownICC (  ) 

Powers down the ICC.

Powers down the ICC

Definition at line 594 of file halSCD.c.

uint8_t PowerUpIcc (  ) 

Powers up the card, if possible.

uint16_t ReadCounterTerminal (  ) 

Reads the value of the terminal counter.

Returns:
the value of the terminal counter

Definition at line 130 of file halSCD.c.

uint8_t ResetICC ( uint8_t  warm,
uint8_t *  inverse_convention,
uint8_t *  proto,
uint8_t *  TC1,
uint8_t *  TA3,
uint8_t *  TB3 
)

Starts a cold or warm reset for ICC.

Starts activation sequence for ICC

Parameters:
warm 0 if a cold reset is to be issued, 1 otherwise
inverse_convention non-zero if inverse convention is to be used
proto 0 for T=0 and non-zero for T=1
TC1 see ISO 7816-3 or EMV Book 1 section ATR
TA3 see ISO 7816-3 or EMV Book 1 section ATR
TB3 see ISO 7816-3 or EMV Book 1 section ATR
Returns:
zero if successful, non-zero otherwise

Definition at line 1085 of file halSCD.c.

void SendByteICCNoParity ( uint8_t  byte,
uint8_t  inverse_convention 
)

Sends a byte to the ICC without parity check.

Sends a byte to the ICC without parity error retransmission

Parameters:
byte byte to be sent
inverse_convention different than 0 if inverse convention is to be used

The ICC clock counter must be started before calling this function

Definition at line 797 of file halSCD.c.

uint8_t SendByteICCParity ( uint8_t  byte,
uint8_t  inverse_convention 
)

Sends a byte to the ICC with parity check.

Sends a byte to the ICC with parity error retransmission

Parameters:
byte byte to be sent
inverse_convention different than 0 if inverse convention is to be used
Returns:
0 if successful, non-zero otherwise

As in the No Parity version, this function relies on counter started

Definition at line 888 of file halSCD.c.

void SendByteTerminalNoParity ( uint8_t  byte,
uint8_t  inverse_convention 
)

Sends a byte to the terminal without parity check.

Sends a byte to the terminal without parity error retransmission

Parameters:
byte byte to be sent
inverse_convention different than 0 if inverse convention is to be used

The terminal clock counter must be started before calling this function

Definition at line 230 of file halSCD.c.

uint8_t SendByteTerminalParity ( uint8_t  byte,
uint8_t  inverse_convention 
)

Sends a byte to the terminal with parity check.

Sends a byte to the terminal with parity error retransmission

Parameters:
byte byte to be sent
inverse_convention different than 0 if inverse convention is to be used
Returns:
0 if successful, non-zero otherwise

As in the NoParity version, this function relies on counter started

Definition at line 324 of file halSCD.c.

void SendT0ATRTerminal ( uint8_t  inverse_convention,
uint8_t  TC1 
)

Sends default ATR for T=0 to terminal.

Sends default ATR for T=0 to terminal

Parameters:
inverse_convention specifies if direct (0) or inverse convention (non-zero) is to be used. Only direct convention should be used for future applications.
TC1 specifies the TC1 byte of the ATR. This should be as small as possible in order to limit the latency of communication, or large if a large timeout between bytes is desired.

Definition at line 539 of file halSCD.c.

void StartCounterTerminal (  ) 

Starts the counter for the external clock given by the terminal.

Starts the counter for the external clock given by the terminal

From hardware tests it seems that it is better to just leave the counter running all the time and just modify the register values as needed

Definition at line 154 of file halSCD.c.

void StopCounterTerminal (  ) 

Stops the terminal clock counter.

Stops the terminal clock counter

Definition at line 173 of file halSCD.c.

uint8_t WaitForICCData ( uint16_t  max_cycles  ) 

Loops for max_cycles or until the I/O line from ICC becomes low.

Loops until the I/O line from ICC becomes low

Parameters:
max_cycles the maximum number of clocks to wait for the I/O line to become low. Loops forever if this is 0
Returns:
0 if the I/O line is 0, non-zero otherwise

Definition at line 631 of file halSCD.c.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Mon Dec 20 16:40:30 2010 for The Smart Card Detective (SCD) by  doxygen 1.6.1