1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
#include "SisPublic.h"
#include <stdio.h>
#include <winscard.h>
//=====================================================================
//
// function prototypes
//
//=====================================================================
char *GetScardErrMsg(int code);
void Dump(const Pbdf *, const Isdf *);
//=====================================================================
//
// main function
//
//=====================================================================
int main(int argc, char **argv)
{
long lReturn;
char sis[SIS_LEN];
Pbdf pbdf;
Isdf isdf;
printf("reading SIS card ...\n");
if (SCARD_S_SUCCESS != (lReturn = SisPublicReadCard(sis)))
{
printf("An error occurred: %lx\n", lReturn);
printf("Error message: %s\n", GetScardErrMsg(lReturn));
}
else
{
//FILE *fp = fopen("c:/temp/sis.img", "wb");
//fwrite(sis, 1, sizeof(sis), fp);
//fclose(fp);
SisPublicError err;
if (ERR_OK == (err = SisPublicParse(sis, &pbdf, &isdf)))
{
Dump(&pbdf, &isdf);
}
else
{
printf("error: %d\n", err); // fixme: show error code ...
}
}
return 0;
}
//=====================================================================
//
// Dump
//
//=====================================================================
void Dump(const Pbdf *pPbdf, const Isdf *pIsdf)
{
printf("\n");
printf("Contents of PBDF:\n");
printf("-----------------\n");
printf("File Identification Number: %s\n", pPbdf->FIDN);
printf("File Secret Key Index: %s\n", pPbdf->FSKI);
printf("Social Security Identification Number: %s\n", pPbdf->SSIN);
printf("Data Capture Date: %s\n", pPbdf->DCDT);
printf("Holder's Firstname: %s\n", pPbdf->NAME);
printf("Holder's Surname: %s\n", pPbdf->SNME);
printf("Holder's Initial: %s\n", pPbdf->INIT);
printf("Holder's Sex: %s\n", pPbdf->SEXE);
printf("Holder's Birthdate: %s\n", pPbdf->BRDT);
printf("File Certificate: %s\n", pPbdf->FCTF);
printf("File Checksum: %s\n", pPbdf->FCSM);
printf("\n");
printf("Contents of ISDF:\n");
printf("-----------------\n");
printf("File Identification Number: %s\n", pIsdf->FIDN);
printf("File Secret Key Index: %s\n", pIsdf->FSKI);
printf("Social Security Identification Number: %s\n", pIsdf->SSIN);
printf("Data Capture Date: %s\n", pIsdf->DCDT);
printf("Card Name: %s\n", pIsdf->CNME);
printf("Card Language: %s\n", pIsdf->CLAN);
printf("Card Logical Number: %s\n", pIsdf->CLGN);
printf("Card Begin Date: %s\n", pIsdf->CBDT);
printf("Card End Date: %s\n", pIsdf->CEDT);
printf("File Certificate: %s\n", pIsdf->FCTF);
printf("File Checksum: %s\n", pIsdf->FCSM);
}
//=====================================================================
//
// GetScardErrMsg
//
//=====================================================================
char *GetScardErrMsg(int code)
{
switch(code)
{
// Smartcard Reader interface errors
case SCARD_E_CANCELLED:
return "The action was canceled by an SCardCancel request.";
case SCARD_E_CANT_DISPOSE:
return "The system could not dispose of the media in the requested manner.";
case SCARD_E_CARD_UNSUPPORTED:
return "The smart card does not meet minimal requirements for support.";
case SCARD_E_DUPLICATE_READER:
return "The reader driver didn't produce a unique reader name.";
case SCARD_E_INSUFFICIENT_BUFFER:
return "The data buffer for returned data is too small for the returned data.";
case SCARD_E_INVALID_ATR:
return "An ATR string obtained from the registry is not a valid ATR string.";
case SCARD_E_INVALID_HANDLE:
return "The supplied handle was invalid.";
case SCARD_E_INVALID_PARAMETER:
return "One or more of the supplied parameters could not be properly interpreted.";
case SCARD_E_INVALID_TARGET:
return "Registry startup information is missing or invalid.";
case SCARD_E_INVALID_VALUE:
return "One or more of the supplied parameter values could not be properly interpreted.";
case SCARD_E_NOT_READY:
return "The reader or card is not ready to accept commands.";
case SCARD_E_NOT_TRANSACTED:
return "An attempt was made to end a non-existent transaction.";
case SCARD_E_NO_MEMORY:
return "Not enough memory available to complete this command.";
case SCARD_E_NO_SERVICE:
return "The smart card resource manager is not running.";
case SCARD_E_NO_SMARTCARD:
return "The operation requires a smart card, but no smart card is currently in the device.";
case SCARD_E_PCI_TOO_SMALL:
return "The PCI receive buffer was too small.";
case SCARD_E_PROTO_MISMATCH:
return "The requested protocols are incompatible with the protocol currently in use with the card.";
case SCARD_E_READER_UNAVAILABLE:
return "The specified reader is not currently available for use.";
case SCARD_E_READER_UNSUPPORTED:
return "The reader driver does not meet minimal requirements for support.";
case SCARD_E_SERVICE_STOPPED:
return "The smart card resource manager has shut down.";
case SCARD_E_SHARING_VIOLATION:
return "The smart card cannot be accessed because of other outstanding connections.";
case SCARD_E_SYSTEM_CANCELLED:
return "The action was canceled by the system, presumably to log off or shut down.";
case SCARD_E_TIMEOUT:
return "The user-specified timeout value has expired.";
case SCARD_E_UNKNOWN_CARD:
return "The specified smart card name is not recognized.";
case SCARD_E_UNKNOWN_READER:
return "The specified reader name is not recognized.";
case SCARD_F_COMM_ERROR:
return "An internal communications error has been detected.";
case SCARD_F_INTERNAL_ERROR:
return "An internal consistency check failed.";
case SCARD_F_UNKNOWN_ERROR:
return "An internal error has been detected, but the source is unknown.";
case SCARD_F_WAITED_TOO_LONG:
return "An internal consistency timer has expired.";
case SCARD_W_REMOVED_CARD:
return "The smart card has been removed and no further communication is possible.";
case SCARD_W_RESET_CARD:
return "The smart card has been reset, so any shared state information is invalid.";
case SCARD_W_UNPOWERED_CARD:
return "Power has been removed from the smart card and no further communication is possible.";
case SCARD_W_UNRESPONSIVE_CARD:
return "The smart card is not responding to a reset.";
case SCARD_W_UNSUPPORTED_CARD:
return "The reader cannot communicate with the card due to ATR string configuration conflicts.";
}
return "Error is not documented.";
}
|