This provides a low-level reader specific driver for the smart card interface on the Axis hardware platform. This dirver is used with the Linux PCSC interface library see http://www.linuxnet.com.
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <termios.h>
#include <axis.h>
#include "types.h"
#include "ifdhandler.h"
Include dependency graph for ifdhandler.c:

Data Structures | |
| struct | tsSMARTCARD_HARDWARE |
| Define a structure to hold the smart card infomation. More... | |
Defines | |
| #define | SMARTCARD_DEV "/dev/axis_%d/smart_card" |
| #define | T0_TA_SENT (0x10) |
| The mask to check and see if there is a TA command in the ATR. | |
| #define | T0_TB_SENT (0x20) |
| The mask to check and see if there is a TB command in the ATR. | |
| #define | T0_TC_SENT (0x40) |
| The mask to check and see if there is a TC command in the ATR. | |
| #define | T0_TD_SENT (0x80) |
| The mask to check and see if there is a TD command in the ATR. | |
| #define | T0_HISTORICAL_MASK (0x0f) |
| The mask to check and see there if the ATR hss any more data. | |
| #define | IFD_SINGLE_DEBUG(x) |
Enumerations | |
| enum | eIFDHANDLER_GENERIC_TYPES { eIFD_MIN_T1_PKT_SIZE = 4, eIFD_BWT_START = 12, eIFD_MAX_IFSD_SIZE = 32, eIFD_DEVICE_SIZE = 32, eIFD_MAX_ATR_SIZE = 33, eIFD_PCB_CHAINING = 0x20, eIFD_MAX_RX_SIZE = 257, eIDF_MAX_BUF_SIZE = 264 } |
| enum | T1_BLOCK_REPLYS { T1_SBLOCK_SUCCESS = 0x200, T1_SBLOCK_WTXREQUEST = 0x201, T1_RBLOCK_SUCCESS = 0x210, T1_IBLOCK_SUCCESS = 0x220, T1_ERROR_PARITY_EDC = 0x230, T1_ERROR_OTHER = 0x240, T1_INVALID_BLOCK = 0x250, T1_TIMEOUT = 0x260 } |
| enum | ePCB_FIELD { eIBLOCK_RSLT = 0x00, eIBLOCK_MASK = 0x80, eRBLOCK_RSLT = 0x80, eRBLOCK_MASK = 0xc0, eSBLOCK_RSLT = 0xc0, eSBLOCK_MASK = 0xc0 } |
Functions | |
| void | ifd_ReadAtr (HANDLE fdDev, BYTE *pbAtr, BYTE *bAtrSze) |
| Read the ATR from the smart card. | |
| LONG | ifd_T1ExchangeData (BYTE *pabTxBuf, LONG lTxLen, BYTE *pabRxBuf, LONG *plRxLen) |
| Send a T1 data packet to the smart card. | |
| BYTE | ifd_T1CalculateLRC (BYTE *pabBuf, LONG lLen) |
| Calculate packet checksum. | |
| LONG | ifd_T1Transaction (BYTE *pabRqst, LONG lRqstLen, BYTE *pabRply, LONG *plRplyLen) |
| perform a T1 transaction with the smart card | |
| LONG | ifd_T1GetResponseType (BYTE bPcb) |
| Return the type of PCB we got from the smart card. | |
| LONG | ifd_T1WTXResponse (BYTE bWtx, BYTE *bRxBuf, LONG lRxBufLen) |
| Send Response to the waiting time extension request. | |
| int | ifd_T1BuildPacket (BYTE *pabPktBuf, LONG lPktLen) |
| Try and make a packet from the data received so far if so then return 1. | |
| RESPONSECODE | IFDHCreateChannel (LONG lLun, LONG lChannel) |
| Called to open a channel to a smart card. | |
| RESPONSECODE | IFDHCloseChannel (LONG lLun) |
| RESPONSECODE | IFDHGetCapabilities (LONG lLun, LONG lTag, LONG *plLen, BYTE *pabVal) |
| Return the requested capibilities for a smart card. | |
| RESPONSECODE | IFDHSetCapabilities (LONG lLun, LONG lTag, LONG lLen, BYTE *pabVal) |
| Set the smart card capibilities for the smart card. | |
| RESPONSECODE | IFDHSetProtocolParameters (LONG lLun, LONG lProto, BYTE bFlgs, BYTE bPts1, BYTE bPts2, BYTE bPts3) |
| Set the protocol type selection using the three PTS parameters. | |
| RESPONSECODE | IFDHPowerICC (LONG lLun, LONG lAction, BYTE *pabAtr, LONG *plAtrLen) |
| Controls the power and reset signals of the smart card. | |
| RESPONSECODE | IFDHTransmitToICC (LONG lLun, SCARD_IO_HEADER sTxPci, BYTE *pabTxBuf, LONG lTxLen, BYTE *pabRxBuf, LONG *plRxLen, PSCARD_IO_HEADER psRxPci) |
| Perform an ADPU exchange with the smart card. | |
| RESPONSECODE | IFDHControl (LONG lLun, BYTE *pabTxBuf, LONG lTxlen, BYTE *pabRxBuf, LONG *plRxLen) |
| Perform a data exchange with the smart card reader. | |
| RESPONSECODE | IFDHICCPresence (LONG lLun) |
| Return the status of the card inserted into the reader. | |
Variables | |
| tsSMARTCARD_HARDWARE | sSmartCard |
|
|
/def SMARTCARD_DEV /brief This is the template for smartcard devices in the Axis system This template is use so that if there are ever more that one Axis device then as long as the devices keep the naming convention that is defined here only the file reader.conf will have to change to access the smart card on the other device |
|
|
The mask to check and see there if the ATR hss any more data.
|
|
|
The mask to check and see if there is a TA command in the ATR.
|
|
|
The mask to check and see if there is a TB command in the ATR.
|
|
|
The mask to check and see if there is a TC command in the ATR.
|
|
|
The mask to check and see if there is a TD command in the ATR.
|
|
|
|
|
|
|
|
|
||||||||||||||||
|
Read the ATR from the smart card. Read the ATR from the smart card after the channel has been opened. This code constructs an ATR from the data readin from the smart card. If at any stage an error occures then set the ATR to 0 and return. This makes the code a little untidy with a goto for all read errors.
History |
|
||||||||||||
|
Try and make a packet from the data received so far if so then return 1. Given a block of data and a length try and make a T1 packet out of the data. If a packet can be made then return that a valid packet was received otherwise return that a valid packet has not been made.
History |
Here is the call graph for this function:

|
||||||||||||
|
Calculate packet checksum.
History |
|
||||||||||||||||||||
|
Send a T1 data packet to the smart card. Called when a T1 transaction is performed. The smart card specification says that multi-packet transfers can only be perfromed in one direction either to the smart card or from the smart card. This function can send or receive a maximum of one 255 byte PDU.
History |
Here is the call graph for this function:

|
|
Return the type of PCB we got from the smart card.
History |
|
||||||||||||||||||||
|
perform a T1 transaction with the smart card
History |
Here is the call graph for this function:

|
||||||||||||||||
|
Send Response to the waiting time extension request. During the transmission of a buffer to the smart card the smart card may request an extension to the stardard block waiting time of this transaction. THis function will replay to this request from the smart card.
History |
Here is the call graph for this function:

|
|
History |
|
||||||||||||||||||||||||
|
Perform a data exchange with the smart card reader. This is not supported in this implementation
History |
|
||||||||||||
|
Called to open a channel to a smart card. Open the chanel to the smart card. In this implementation the open is done later This will just initialise the channel for comms and allow IFDHICCPresence to return the card status
History |
Here is the call graph for this function:

|
||||||||||||||||||||
|
Return the requested capibilities for a smart card. Return the requested capibilities. At the moment only the ATR is returned all other Tags get ignored and IFD)ERROR is returned. This is what the acs_mouse driver was doing for the basic cards.
History |
|
|
Return the status of the card inserted into the reader. This function is surposed to detect if a smart card is inserted onto the smartcard holder.
History |
|
||||||||||||||||||||
|
Controls the power and reset signals of the smart card. This function is surposed to control the power and reset signals of the smart card. Ok I had to add the extra functionality so lets see how that goes.
History< Reset Action < Power down action < Power up action |
Here is the call graph for this function:

|
||||||||||||||||||||
|
Set the smart card capibilities for the smart card. Return an error code this is what the acs_mouse driver did so this is what we are going to do. At least until I have a resonable need to do something better.
History |
|
||||||||||||||||||||||||||||
|
Set the protocol type selection using the three PTS parameters. Again this is what the acs_mouse driver was doing to this is what I'm going to do until ther eis a better reason to do anything else.
History |
|
||||||||||||||||||||||||||||||||
|
Perform an ADPU exchange with the smart card.
History |
Here is the call graph for this function:

|
|
Initial value:
{
-1, 0, 0, "", { 0 }, 0
}
|
1.3.6