00001
00008
00009 #pragma once
00010 #include "ManagerInterface.h"
00011 #include "DynamicLibrary.h"
00012
00013 #ifdef WIN32
00014 #define CTAPI __stdcall
00015 #else
00016 #define CTAPI
00017 #endif
00018
00019 struct CTDriver {
00020 struct CTPort {
00021 CTPort(CTDriver *d,ushort n) :
00022 dri(d),portNum(n),isConnected(false),mCtn(0),mLogger(NULL) {}
00023 CTDriver *dri;
00024 ushort portNum;
00025 bool isConnected;
00026 ushort mCtn;
00027 void performCmd(byte target,ByteVec cmd,ByteVec &resp,std::ostream *mLogger,bool consumeStatus = true);
00028 void performCmd(byte target,ByteVec cmd,std::ostream *mLogger);
00029 bool init(bool nothrow = false);
00030 void close();
00031 void resetCT(byte unit,std::ostream *mLogger);
00032 std::ostream *mLogger;
00033
00034
00035
00036
00037
00038
00039 };
00040 CTDriver(const char *libName,std::vector<ushort>);
00041 DynamicLibrary lib;
00042 ushort nextCtn;
00043 char (CTAPI *pCTInit)(ushort ctn,ushort pn);
00044 char (CTAPI *pCTClose)(ushort ctn);
00045 char (CTAPI *pCTData)(
00046 ushort ctn,byte * dad,byte * sad,ushort lenc,
00047 byte * command,ushort * lenr,byte * response);
00048 std::vector<CTPort> mPorts;
00049 private:
00050 CTDriver(const CTDriver &ref);
00051 CTDriver& operator=(const CTDriver &);
00052 };
00053
00054 typedef CTDriver::CTPort cPort;
00055
00057 struct CTAPIConnection : public ConnectionBase {
00058 CTAPIConnection(ManagerInterface &iface,unsigned int index,bool force) :
00059 ConnectionBase(iface,index,force),isT1(false) {}
00060 CTDriver::CTPort * dri;
00062 bool wasConnected;
00064 bool isT1;
00065 virtual bool isSecure() {return true;}
00066 };
00067
00069
00072 class CTAPIManager :
00073 public ManagerInterface
00074 {
00075 private:
00076 CTAPIManager(const CTAPIManager &);
00077 CTAPIManager& operator=(const CTAPIManager &);
00078
00079 std::vector<CTDriver *> mDrivers;
00080 std::vector<cPort *> mPorts;
00081
00082 protected:
00083 void makeConnection(ConnectionBase *c,uint idx);
00084 void deleteConnection(ConnectionBase *c);
00085 void beginTransaction(ConnectionBase *c);
00086 void endTransaction(ConnectionBase *c,bool forceReset = false);
00087 void execCommand(ConnectionBase *c,std::vector<byte> &cmd,
00088 std::vector<byte> &recv,unsigned int &recvLen);
00089 void execPinEntryCommand(ConnectionBase *c,std::vector<byte> &cmd);
00090 void execPinChangeCommand(ConnectionBase *c,std::vector<byte> &cmd
00091 ,size_t oldPinLen,size_t newPinLen);
00092
00093 bool isT1Protocol(ConnectionBase *c);
00094
00095 public:
00096 CTAPIManager(void);
00097 ~CTAPIManager(void);
00098 uint getReaderCount();
00099 std::string getReaderName(uint index);
00100 std::string getReaderState(uint index);
00101 std::string getATRHex(uint index);
00102 CTAPIConnection * connect(uint index,bool forceT0);
00104 void getDefaultLibAndPort(std::string &lib,uint &port);
00105 };
00106