00001
00008
00009 #pragma once
00010 #include "ManagerInterface.h"
00011
00012 using std::vector;
00013
00015 class CardError: public std::runtime_error {
00016 public:
00017 const byte SW1,SW2;
00018 std::string desc;
00019 CardError(byte a,byte b);
00020 virtual const char * what() const throw() { return desc.c_str();}
00021 virtual ~CardError() throw(){};
00022 };
00023
00025 class CardDataError: public std::runtime_error {
00026 public:
00027 CardDataError( std::string p):runtime_error(p) {}
00028 };
00029
00031 class AuthError :public CardError {
00032 public:
00033 bool m_blocked;
00034 AuthError(byte a,byte b) : CardError(a,b), m_blocked(false) {};
00035 AuthError(byte a,byte b,bool block) : CardError(a,b), m_blocked(block) {};
00036 AuthError(CardError _base) : CardError(_base) , m_blocked(false) {}
00037 };
00038
00040
00043 class CardBase
00044 {
00045 protected:
00047 struct FCI {
00048 word fileID;
00049 dword fileLength;
00050 dword recCount;
00051 dword recMaxLen;
00052 } LPFCI;
00053 ManagerInterface &mManager;
00054 ConnectionBase *mConnection;
00055 std::ostream *mLogger;
00056
00058 ByteVec getTag(int identTag,int len,ByteVec &arr);
00060 FCI parseFCI(ByteVec fci);
00062 FCI selectMF(bool ignoreFCI = false);
00064 int selectDF(int fileID,bool ignoreFCI = false);
00066 FCI selectEF(int fileID,bool ignoreFCI = false);
00068 ByteVec readRecord(int numrec);
00070 ByteVec readEF(unsigned int fileLen);
00072 virtual ByteVec execute(ByteVec cmd,bool noreply=false);
00074 virtual void executePinEntry(ByteVec cmd);
00076 virtual void executePinChange(ByteVec cmd, size_t oldPinLen,size_t newPinLen);
00077 public:
00079 CardBase(ManagerInterface &ref);
00081 CardBase(ManagerInterface &ref,unsigned int idx);
00083 CardBase(ManagerInterface &ref,ConnectionBase *conn);
00084
00085 virtual ~CardBase(void);
00087 void connect(unsigned int idx,bool forceT0=false);
00089 virtual bool isInReader(unsigned int idx) {return false;}
00091 void setLogging(std::ostream *logStream);
00093 void endTransaction();
00094 };