The Smart Card Detective (SCD)
terminal.h
Go to the documentation of this file.
00001 
00033 #ifndef _TERMINAL_H_
00034 #define _TERMINAL_H_
00035 
00037 #define MAX_EXCHANGES 50
00038 
00039 /* Global external variables */
00040 extern CRP* transactionData[MAX_EXCHANGES];     // used to log data
00041 extern uint8_t nTransactions;                   // used to log data
00042 extern uint8_t nCounter;                        // number of transactions
00043 
00044 // -------------------------------------------------------------------
00045 // Structures and enums used by the terminal
00046 
00047 
00052 typedef enum {
00053    PDO_ATC = 0x36,
00054    PDO_LAST_ATC = 0x13,
00055    PDO_PIN_TRY_COUNTER = 0x17,
00056    PDO_LOG_FORMAT = 0x4F
00057 } CARD_PDO;
00058 
00062 typedef enum{
00063    AC_REQ_AAC = 0,
00064    AC_REQ_ARQC = 0x80,
00065    AC_REQ_TC = 0x40
00066 } AC_REQ_TYPE;
00067 
00071 typedef struct {
00072         uint8_t tag1;
00073         uint8_t tag2;
00074         uint8_t len;
00075         uint8_t *value;
00076 } TLV;
00077    
00081 typedef struct {
00082         uint8_t count;
00083         TLV **objects;
00084 } RECORD;
00085 
00089 typedef struct {
00090    uint8_t lenDFName;
00091    uint8_t* dfName;
00092    RECORD* fciData;
00093 } FCITemplate;
00094    
00098 typedef struct {
00099    uint8_t count;
00100    FCITemplate** objects;
00101 } FCIList;
00102 
00106 typedef struct {
00107    uint8_t count;
00108    RECORD** objects;
00109 } RECORDList;
00110 
00114 typedef struct {
00115    uint8_t sfi;
00116    uint8_t recordStart;
00117    uint8_t recordEnd;
00118    uint8_t recordsOfflineAuth;
00119 } AFL;
00120 
00124 typedef struct {
00125    uint8_t count;
00126    uint8_t aip[2];
00127    AFL** aflList;
00128 } APPINFO;
00129    
00138 typedef struct {
00139    uint8_t amount[6];                  // tag 0x9F02
00140    uint8_t amountOther[6];             // tag 0x9F03
00141    uint8_t terminalCountryCode[2];     // tag 0x9F1A
00142    uint8_t tvr[5];                     // tag 95
00143    uint8_t terminalCurrencyCode[2];    // tag 0x5F2A
00144    uint8_t transactionDate[3];         // tag 0x9A
00145    uint8_t transactionType;            // tag 0x9C
00146    uint8_t unpredictableNumber[4];     // tag 0x9F37
00147    uint8_t terminalType;               // tag 0x9F35
00148    uint8_t dataAuthCode[2];            // tag 0x9F45
00149    uint8_t iccDynamicNumber[8];        // tag 0x9F4C
00150    uint8_t cvmResults[3];              // tag 0x9F34
00151    uint8_t arc[2];                     // tag 0x8A
00152    uint8_t IssuerAuthData[8];          // tag 0x91
00153 } GENERATE_AC_PARAMS;
00154 
00155 
00156 // -------------------------------------------------------------------
00157 // Methods used by the terminal application
00158 
00160 RAPDU* TerminalSendT0Command(
00161         CAPDU* cmd,
00162         uint8_t inverse_convention,
00163         uint8_t TC1,
00164         log_struct_t *logger);
00165 
00167 FCITemplate* ApplicationSelection(
00168         uint8_t convention,
00169         uint8_t TC1,
00170         const ByteArray *aid,
00171         uint8_t autoselect,
00172         log_struct_t *logger);
00173 
00175 APPINFO* InitializeTransaction(
00176         uint8_t convention,
00177         uint8_t TC1,
00178         const FCITemplate *fci,
00179         log_struct_t *logger);
00180 
00182 RECORD* GetTransactionData(
00183         uint8_t convention,
00184         uint8_t TC1,
00185         const APPINFO* appInfo,
00186         ByteArray *offlineAuthData,
00187         log_struct_t *logger);
00188 
00190 FCITemplate* SelectFromAID(
00191         uint8_t convention,
00192         uint8_t TC1,
00193         const ByteArray *aid,
00194         log_struct_t *logger);
00195 
00197 FCITemplate* SelectFromPSE(
00198         uint8_t convention,
00199         uint8_t TC1,
00200         uint8_t sfiPSE,
00201         uint8_t autoselect,
00202         log_struct_t *logger);
00203 
00205 uint8_t VerifyPlaintextPIN(
00206         uint8_t convention,
00207         uint8_t TC1,
00208         const ByteArray *pin,
00209         log_struct_t *logger);
00210 
00212 RAPDU* SendGenerateAC(
00213         uint8_t convention,
00214         uint8_t TC1,
00215         AC_REQ_TYPE acType,
00216         const TLV* cdol,
00217         const GENERATE_AC_PARAMS *params,
00218         log_struct_t *logger);
00219 
00221 RAPDU* SignDynamicData(
00222         uint8_t convention,
00223         uint8_t TC1,
00224         const ByteArray *data,
00225         log_struct_t *logger);
00226 
00228 uint8_t GetSFIFromSELECT(const RAPDU *response);
00229 
00231 TLV* GetPDOLFromFCI(const FCITemplate *fci);
00232 
00234 TLV* GetPDOL(const FCITemplate *fci);
00235 
00237 ByteArray* GetDataObject(
00238         uint8_t convention,
00239         uint8_t TC1,
00240         CARD_PDO pdo,
00241         log_struct_t *logger);
00242 
00244 TLV* GetTLVFromRECORD(RECORD *rec, uint8_t tag1, uint8_t tag2);
00245 
00247 uint8_t AmountPositionInCDOLRecord(const RECORD *record);
00248 
00250 FCITemplate* ParseFCI(const uint8_t *data, uint8_t lenData);
00251 
00253 TLV* ParseTLV(const uint8_t *data, uint8_t lenData, uint8_t includeValue);
00254 
00256 TLV* CopyTLV(const TLV *data);
00257 
00259 RECORD* ParseRECORD(const uint8_t *data, uint8_t lenData);
00260 
00262 uint8_t AddRECORD(RECORD *dest, const RECORD *src);
00263 
00265 RECORD* ParseManyTLV(const uint8_t *data, uint8_t lenData);
00266 
00268 uint8_t ParsePSD(RECORDList *rlist, const uint8_t *data, uint8_t lenData);
00269 
00271 APPINFO* ParseApplicationInfo(const uint8_t* data, uint8_t len);
00272 
00274 ByteArray* SerializeTLV(const TLV* tlv);
00275 
00277 void FreeTLV(TLV *data);
00278 
00280 void FreeRECORD(RECORD *data);
00281 
00283 void FreeRECORDList(RECORDList *data);
00284 
00286 void FreeFCITemplate(FCITemplate *data);
00287 
00289 void FreeFCIList(FCIList *data);
00290 
00292 void FreeAPPINFO(APPINFO *data);
00293 
00294 #endif // _TERMINAL_H_
00295 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines