|
|
@@ -1,40 +1,35 @@
|
|
|
#include "contactlessimpl.h"
|
|
|
-#include "cmb.h"
|
|
|
+#include "SSocket.h"
|
|
|
|
|
|
-#define DEVICE_NAME "CREATOR CRT-603 (CZ1) CCR RF 0"
|
|
|
+#define DEVICE_NAME "Creator 603 smart card (20120516)"
|
|
|
|
|
|
ContactlessCardImpl::ContactlessCardImpl()
|
|
|
{
|
|
|
- m_pConnect = new CPcscLibrary();
|
|
|
+ m_bDevOpen = false;
|
|
|
m_bCardConn = false;
|
|
|
}
|
|
|
|
|
|
ContactlessCardImpl::~ContactlessCardImpl()
|
|
|
{
|
|
|
- delete m_pConnect;
|
|
|
}
|
|
|
|
|
|
ErrorCodeEnum ContactlessCardImpl::DevOpen(DWORD dwPort,DWORD dwBaudRate)
|
|
|
{
|
|
|
LOG4VTM_FUNCTION();
|
|
|
+ GetCurLibsPath(m_sLibPath, NULL);
|
|
|
|
|
|
- char cFilePath[300] = {0};
|
|
|
- GetCurLibsPath(m_sLibPath, cFilePath);
|
|
|
+ char sTemp[400];
|
|
|
+ if (m_PcscCall.Load() == false)
|
|
|
+ return GetErrorInfo(PCSC_NOT_OPEN, "DevOpen");
|
|
|
+
|
|
|
+ Sleep(200);
|
|
|
+ if (m_PcscCall.Open(DEVICE_NAME) == false)
|
|
|
+ return GetErrorInfo(PCSC_HARDWARE_ERROR, "DevOpen %s", m_PcscCall.GetErrInfo());
|
|
|
|
|
|
- sprintf(cFilePath, "DevOpen GetCurProcPath = %s", m_sLibPath);
|
|
|
- LOG4VTM(INFO, cFilePath);
|
|
|
- sprintf(cFilePath, "%s/cw/libCRT603.cw.so", m_sLibPath); //usr symbolic link to point the real so
|
|
|
-
|
|
|
- bool bOK = m_pConnect->Load(cFilePath, cFilePath);
|
|
|
- if (!bOK) return GetErrorInfo(PCSC_HARDWARE_ERROR, "DevOpen");
|
|
|
- int iCount = 0;
|
|
|
- int iRt = m_pConnect->OpenConnect(&iCount);
|
|
|
- if (iRt != 0)
|
|
|
- return GetErrorInfo(PCSC_HARDWARE_ERROR, "DevOpen OpenConnect %d", iRt);
|
|
|
- iRt = m_pConnect->SetReaderName(0);
|
|
|
- if (iRt != 0)
|
|
|
- return GetErrorInfo(PCSC_HARDWARE_ERROR, "DevOpen SetReaderName %d", iRt);
|
|
|
- return GetErrorInfo(0, "DevOpen %d", iRt);
|
|
|
+ sprintf(sTemp, "DevOpen GetCurProcPath = %s", m_sLibPath);
|
|
|
+ LOG4VTM(INFO, sTemp);
|
|
|
+ m_bDevOpen = true;
|
|
|
+ return GetErrorInfo(0, "DevOpen");
|
|
|
}
|
|
|
|
|
|
int getFileVer(char* sFile, short& ch1, short& ch2)
|
|
|
@@ -64,21 +59,33 @@ int getFileVer(char* sFile, short& ch1, short& ch2)
|
|
|
ErrorCodeEnum ContactlessCardImpl::GetDevCategory(DevCategoryInfo &devCategory)
|
|
|
{
|
|
|
LOG4VTM_FUNCTION();
|
|
|
- if (!m_pConnect->IsLoadSucceed())
|
|
|
+ if (!m_bDevOpen)
|
|
|
return GetErrorInfo(PCSC_NOT_OPEN, "GetDevCategory");
|
|
|
|
|
|
- ErrorCodeEnum err = Error_Succeed;
|
|
|
-
|
|
|
char sSer[256];
|
|
|
memset(sSer, 0, sizeof(sSer));
|
|
|
- if (m_pConnect->GetVersionInfo(2, sSer) == 0)
|
|
|
+ Sleep(500);
|
|
|
+
|
|
|
+ char szType[] = {"PVER=CREATOR#MID=CRT-603"};
|
|
|
+ char szModel[] = "FWID=%s";
|
|
|
+ char sSend[32] = "6892000500";
|
|
|
+
|
|
|
+ int iRet = m_PcscCall.SendCMD(sSend, sSer);
|
|
|
+ if (iRet < 0)
|
|
|
{
|
|
|
- sSer[32] = 0;
|
|
|
- strcpy(devCategory.szType, sSer);
|
|
|
+ devCategory.eState = DEVICE_STATUS_NOT_READY;
|
|
|
+ sprintf(devCategory.szModel, szModel, "00000000");
|
|
|
}
|
|
|
else
|
|
|
- strcpy(devCategory.szType, DEVICE_NAME);
|
|
|
- strcpy(devCategory.szModel, "WID=Cashway001");
|
|
|
+ {
|
|
|
+ unsigned char chVer[16];
|
|
|
+ ::HexStrToANSI(sSer, chVer, 16);
|
|
|
+ chVer[8] = 0;
|
|
|
+ sprintf(devCategory.szModel, szModel, chVer);
|
|
|
+ devCategory.eState = DEVICE_STATUS_NORMAL;
|
|
|
+ }
|
|
|
+
|
|
|
+ strcpy(devCategory.szType, szType);
|
|
|
strcpy(devCategory.szVendor, "cw");
|
|
|
|
|
|
char cFilePath[300] = {0};
|
|
|
@@ -101,29 +108,24 @@ ErrorCodeEnum ContactlessCardImpl::GetDevCategory(DevCategoryInfo &devCategory)
|
|
|
ErrorCodeEnum ContactlessCardImpl::Reset()
|
|
|
{
|
|
|
LOG4VTM_FUNCTION();
|
|
|
- if (!m_pConnect->IsLoadSucceed())
|
|
|
- return GetErrorInfo(PCSC_NOT_OPEN, "Reset");
|
|
|
-
|
|
|
- m_pConnect->CloseConnect();
|
|
|
- int iCount = 0;
|
|
|
- int iRt = m_pConnect->OpenConnect(&iCount);
|
|
|
- if (iRt != 0)
|
|
|
- return GetErrorInfo(PCSC_HARDWARE_ERROR, "Reset OpenConnect %d", iRt);
|
|
|
- iRt = m_pConnect->SetReaderName(0);
|
|
|
- if (iRt != 0)
|
|
|
- return GetErrorInfo(PCSC_HARDWARE_ERROR, "Reset SetReaderName %d", iRt);
|
|
|
- return GetErrorInfo(0, "Reset %d", iRt);
|
|
|
+ if (!m_bDevOpen)
|
|
|
+ return GetErrorInfo(PCSC_NOT_OPEN, "Reset ");
|
|
|
+
|
|
|
+ m_PcscCall.Close();
|
|
|
+ bool bOK = m_PcscCall.Open(DEVICE_NAME);
|
|
|
+ if (!bOK)
|
|
|
+ return GetErrorInfo(PCSC_HARDWARE_ERROR, "Reset %s", m_PcscCall.GetErrInfo());
|
|
|
+ return GetErrorInfo(0, "Reset");
|
|
|
}
|
|
|
|
|
|
ErrorCodeEnum ContactlessCardImpl::DevClose()
|
|
|
{
|
|
|
LOG4VTM_FUNCTION();
|
|
|
- if (!m_pConnect->IsLoadSucceed())
|
|
|
+ if (!m_bDevOpen)
|
|
|
return GetErrorInfo(PCSC_NOT_OPEN, "DevClose");
|
|
|
-
|
|
|
- m_pConnect->CloseConnect();
|
|
|
- ErrorCodeEnum err = Error_Succeed;
|
|
|
- return err;
|
|
|
+ m_bDevOpen = false;
|
|
|
+ m_PcscCall.Close();
|
|
|
+ return Error_Succeed;
|
|
|
}
|
|
|
|
|
|
// DEC_SUCCESS DEC_HARDWARE DEC_TIMEOUT DEC_INVALID_PARAMETER DEC_INVALID_MASTER_KEY
|
|
|
@@ -190,18 +192,19 @@ ErrorCodeEnum ContactlessCardImpl::GetLastErr(DevErrorInfo &devErrInfo)
|
|
|
ErrorCodeEnum ContactlessCardImpl::GetDevStatus(RFICReaderStatus& devStatus)
|
|
|
{
|
|
|
LOG4VTM_FUNCTION();
|
|
|
- if (!m_pConnect->IsLoadSucceed())
|
|
|
+ if (!m_bDevOpen)
|
|
|
return GetErrorInfo(PCSC_NOT_OPEN, "GetDevStatus");
|
|
|
- int ia = m_pConnect->GetCardStatus();
|
|
|
- switch(ia){
|
|
|
- case 1:
|
|
|
+
|
|
|
+ int iRet = m_PcscCall.GetState();
|
|
|
+ if (iRet < 0)
|
|
|
+ return GetErrorInfo(PCSC_HARDWARE_ERROR, "GetDevStatus %s", m_PcscCall.GetErrInfo());
|
|
|
+
|
|
|
+ if (iRet > 0)
|
|
|
+ {
|
|
|
devStatus.eMediaPos = CI_MEDIA_RF;
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- devStatus.eMediaPos = CI_MEDIA_NOTPRESENT;
|
|
|
- m_bCardConn = false;
|
|
|
- break;
|
|
|
- default:
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
devStatus.eMediaPos = CI_MEDIA_NOTPRESENT;
|
|
|
m_bCardConn = false;
|
|
|
}
|
|
|
@@ -223,38 +226,32 @@ ErrorCodeEnum ContactlessCardImpl::AbortRead()
|
|
|
ErrorCodeEnum ContactlessCardImpl::ActiveContactlessICCard(char fstType, char scdType, char thdType, char& outType)
|
|
|
{
|
|
|
LOG4VTM_FUNCTION();
|
|
|
- if (!m_pConnect->IsLoadSucceed())
|
|
|
+ if (!m_bDevOpen)
|
|
|
return GetErrorInfo(PCSC_NOT_OPEN, "ActiveContactlessICCard");
|
|
|
|
|
|
- BYTE byAtrData[256] = {0};
|
|
|
- int iAtrLen = 0;
|
|
|
- m_bCardConn = false;
|
|
|
- int iRet = m_pConnect->ReaderConnect(byAtrData, &iAtrLen);
|
|
|
- if (iRet != 0 || iAtrLen < 1)
|
|
|
- {
|
|
|
- outType = '0';
|
|
|
- return GetErrorInfo(PCSC_NO_CARD, "ActiveContactlessICCard ReaderConnect %d %s", iRet, m_pConnect->GetLastError());
|
|
|
- }
|
|
|
- char sHexData[512];
|
|
|
- ::ANSIToHexStr(byAtrData, iAtrLen, sHexData);
|
|
|
- printf("ATR %d %s\n", iAtrLen, sHexData);
|
|
|
+ char sATR[256];
|
|
|
+ int iLen = 0;
|
|
|
+ if (!m_PcscCall.Connect(sATR, iLen))
|
|
|
+ return GetErrorInfo(PCSC_NOT_CONN, "ActiveContactlessICCard %s", m_PcscCall.GetErrInfo());
|
|
|
+
|
|
|
outType = 'A';
|
|
|
- if (strcmp(sHexData, "3B8F8001804F0CA000000306030001E00000018B") == 0)
|
|
|
+ if (strcmp(sATR, "3B8F8001804F0CA000000306030001E00000018B") == 0)
|
|
|
outType = '0';
|
|
|
- if (strcmp(sHexData, "3B8F8001804F0CA000000306030001000000006A") == 0) // 公交卡、房卡
|
|
|
+ if (strcmp(sATR, "3B8F8001804F0CA000000306030001000000006A") == 0) // 公交卡、房卡
|
|
|
outType = 'M';
|
|
|
- if (strcmp(sHexData, "3B8F8001804F0CA0000003060300020000000069") == 0)
|
|
|
+ if (strcmp(sATR, "3B8F8001804F0CA0000003060300020000000069") == 0)
|
|
|
outType = 'M';
|
|
|
- if (strcmp(sHexData, "3B8F8001804F0CA000000306030001E00000018B") == 0)
|
|
|
+ if (strcmp(sATR, "3B8F8001804F0CA000000306030001E00000018B") == 0)
|
|
|
outType = '0';
|
|
|
|
|
|
// if (strcmp(sHexData, "3B8E800180318066B1C5240100ED83009000F7") == 0) //
|
|
|
// outType = '2';
|
|
|
- if (iAtrLen == 13 && strstr(sHexData, "3B888001D103")) //身份证
|
|
|
+ if (strlen(sATR) == 26 && strstr(sATR, "3B888001D103")) //身份证
|
|
|
outType = 'B';
|
|
|
|
|
|
+ Sleep(400);
|
|
|
m_bCardConn = true;
|
|
|
- return GetErrorInfo(iRet, "ActiveContactlessICCard");
|
|
|
+ return GetErrorInfo(0, "ActiveContactlessICCard");
|
|
|
}
|
|
|
//
|
|
|
// Deactivate contactless IC card
|
|
|
@@ -262,14 +259,14 @@ ErrorCodeEnum ContactlessCardImpl::ActiveContactlessICCard(char fstType, char sc
|
|
|
ErrorCodeEnum ContactlessCardImpl::DeactContactlessICCard()
|
|
|
{
|
|
|
LOG4VTM_FUNCTION();
|
|
|
- if (!m_pConnect->IsLoadSucceed())
|
|
|
+ if (!m_bDevOpen)
|
|
|
return GetErrorInfo(PCSC_NOT_OPEN, "DeactContactlessICCard");
|
|
|
|
|
|
m_bCardConn = false;
|
|
|
- int iRet = m_pConnect->EjectCard();
|
|
|
- if (iRet == 0)
|
|
|
- return GetErrorInfo(0, "DeactContactlessICCard");
|
|
|
- return GetErrorInfo(PCSC_HARDWARE_ERROR, "ActiveCDeactContactlessICCard %d", iRet);;
|
|
|
+
|
|
|
+ if (!m_PcscCall.DicConnect())
|
|
|
+ return GetErrorInfo(PCSC_NOT_CONN, "DeactContactlessICCard %s", m_PcscCall.GetErrInfo());
|
|
|
+ return GetErrorInfo(0, "DeactContactlessICCard");
|
|
|
}
|
|
|
//
|
|
|
// Warm reset card(IC)
|
|
|
@@ -277,25 +274,21 @@ ErrorCodeEnum ContactlessCardImpl::DeactContactlessICCard()
|
|
|
ErrorCodeEnum ContactlessCardImpl::WarmReset()
|
|
|
{
|
|
|
LOG4VTM_FUNCTION();
|
|
|
- if (!m_pConnect->IsLoadSucceed())
|
|
|
+ if (!m_bDevOpen)
|
|
|
return GetErrorInfo(PCSC_NOT_OPEN, "WarmReset");
|
|
|
|
|
|
m_bCardConn = false;
|
|
|
- if (m_pConnect->GetCardStatus() != 1)
|
|
|
- return GetErrorInfo(PCSC_NO_CARD, "WarmReset");
|
|
|
- int iRet = m_pConnect->EjectCard();
|
|
|
- if (iRet != 0)
|
|
|
- return GetErrorInfo(iRet, "WarmReset");
|
|
|
-
|
|
|
- BYTE byAtrData[256] = {0};
|
|
|
- int iAtrLen = 0;
|
|
|
- iRet = m_pConnect->ReaderConnect(byAtrData, &iAtrLen);
|
|
|
- if (iRet == 0)
|
|
|
- {
|
|
|
- m_bCardConn = true;
|
|
|
- return GetErrorInfo(0, "WarmReset");
|
|
|
- }
|
|
|
- return GetErrorInfo(PCSC_HARDWARE_ERROR, "WarmReset %d", iRet);;
|
|
|
+
|
|
|
+ if (!m_PcscCall.DicConnect())
|
|
|
+ return GetErrorInfo(PCSC_NOT_CONN, "WarmReset %s", m_PcscCall.GetErrInfo());
|
|
|
+
|
|
|
+ char sATR[256];
|
|
|
+ int iLen = 0;
|
|
|
+ if (!m_PcscCall.Connect(sATR, iLen))
|
|
|
+ return GetErrorInfo(PCSC_NOT_CONN, "WarmReset %s", m_PcscCall.GetErrInfo());
|
|
|
+
|
|
|
+ m_bCardConn = true;
|
|
|
+ return GetErrorInfo(0, "WarmReset");;
|
|
|
}
|
|
|
//
|
|
|
// Mifare operation
|
|
|
@@ -332,14 +325,20 @@ ErrorCodeEnum ContactlessCardImpl::RFTypeABCommand(CmdInfo sendBuf, CmdInfo& rec
|
|
|
if (m_bCardConn == false)
|
|
|
return GetErrorInfo(PCSC_NOT_CONN, "RFTypeABCommand");
|
|
|
|
|
|
- unsigned char sAnsi[1024];
|
|
|
- int iRetCount = 0;
|
|
|
- ::HexStrToANSI((char*)sendBuf.data, sAnsi, sendBuf.dwSize);
|
|
|
- int iRet = m_pConnect->SendApdu(sAnsi, sendBuf.dwSize << 1, sAnsi, &iRetCount);
|
|
|
- if (iRet != 0)
|
|
|
- return GetErrorInfo(iRet, "RFTypeABCommand SendApdu %d %s", iRet, m_pConnect->GetLastError());
|
|
|
- ::ANSIToHexStr(sAnsi, iRetCount, (char*)recvBuf.data);
|
|
|
- recvBuf.dwSize = iRetCount << 1;
|
|
|
+ char sSend[600];
|
|
|
+ ::ANSIToHexStr(sendBuf.data, sendBuf.dwSize, sSend);
|
|
|
+ LOG4VTM(INFO, sSend);
|
|
|
+
|
|
|
+ int iRet = m_PcscCall.ChipIO(sSend, sSend);
|
|
|
+ if (iRet < 0)
|
|
|
+ return GetErrorInfo(PCSC_HARDWARE_ERROR, "RFTypeABCommand %s", m_PcscCall.GetErrInfo());
|
|
|
+
|
|
|
+ LOG4VTM(INFO, sSend);
|
|
|
+ int iLen = strlen(sSend);
|
|
|
+ recvBuf.dwSize = iLen/2;
|
|
|
+ ::HexStrToANSI(sSend, recvBuf.data, iLen);
|
|
|
+ recvBuf.data[recvBuf.dwSize] = 0;
|
|
|
+ Sleep(10);
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
|
@@ -348,14 +347,11 @@ ErrorCodeEnum ContactlessCardImpl::RFTypeABCommand(CmdInfo sendBuf, CmdInfo& rec
|
|
|
ErrorCodeEnum ContactlessCardImpl::HaltCard()
|
|
|
{
|
|
|
LOG4VTM_FUNCTION();
|
|
|
- if (!m_pConnect->IsLoadSucceed())
|
|
|
+ if (!m_bDevOpen)
|
|
|
return GetErrorInfo(PCSC_NOT_OPEN, "HaltCard");
|
|
|
|
|
|
- int iRet = m_pConnect->EjectCard();
|
|
|
- if (iRet == 0)
|
|
|
- {
|
|
|
- m_bCardConn = false;
|
|
|
- return GetErrorInfo(0, "HaltCard");
|
|
|
- }
|
|
|
- return GetErrorInfo(PCSC_HARDWARE_ERROR, "HaltCard %d", iRet);;
|
|
|
+ m_bCardConn = false;
|
|
|
+ if (!m_PcscCall.DicConnect())
|
|
|
+ return GetErrorInfo(PCSC_HARDWARE_ERROR, "HaltCard %s", m_PcscCall.GetErrInfo());
|
|
|
+ return GetErrorInfo(0, "HaltCard");
|
|
|
}
|