|
@@ -1,1993 +0,0 @@
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-#include "GrgPinPadImpl.h"
|
|
|
-#include <stdio.h>//必要头文件和依赖顄1�7
|
|
|
-#include <stdlib.h>
|
|
|
-#include <dlfcn.h>
|
|
|
-#include <unistd.h>
|
|
|
-#include "log4vendor.h"
|
|
|
-
|
|
|
-#define APCSyncCall(func, para) func((void*)para)
|
|
|
-#define SetEvent(xxx)
|
|
|
-#define ResetEvent(xxx)
|
|
|
-tDevReturn DevRetInfo[8] = {0};
|
|
|
-static CGrgPinPadImpl *pCGrgPinPadImpl = NULL;
|
|
|
-
|
|
|
-#define SM4 0x01
|
|
|
-
|
|
|
-#define SM3 0x01
|
|
|
-
|
|
|
-#define SM2 0x01
|
|
|
-
|
|
|
-#define Sleep(mscount) usleep(1000*mscount)
|
|
|
-
|
|
|
-const static unsigned short InputKeyTimeOut = 60;
|
|
|
-
|
|
|
-HANDLE m_hTimerManagerThread = NULL;
|
|
|
-int mode = 0;
|
|
|
-
|
|
|
-/*void epptest()
|
|
|
-{
|
|
|
- OEPPDevDll *epp = new OEPPDevDll();
|
|
|
- if(!epp) {
|
|
|
- printf("==epp new failed\n");
|
|
|
- return;
|
|
|
- }
|
|
|
- tDevReturn l_psStatus;
|
|
|
- int ret = epp->iSetCommPara(l_psStatus);
|
|
|
- if( 0 != ret) {
|
|
|
- printf("==setcomm failed:%d\n",ret);
|
|
|
- //exit(ret);
|
|
|
- }
|
|
|
- else {
|
|
|
- printf("==setcomm ok.\n");
|
|
|
- }
|
|
|
- delete epp;
|
|
|
-}*/
|
|
|
-
|
|
|
-static std::string int2str(int nTemp)
|
|
|
-{
|
|
|
- std::stringstream stream;
|
|
|
- stream << nTemp;
|
|
|
- return stream.str();
|
|
|
-}
|
|
|
-static void unpack_(char *pSrc, char * pDest, int iSrcLen)
|
|
|
-{
|
|
|
- unsigned char ch1, ch2;
|
|
|
- for( int i = 0; i < iSrcLen; i++ )
|
|
|
- {
|
|
|
- ch1 = (pSrc[i] & 0xF0) >> 4;
|
|
|
- ch2 = pSrc[i] & 0x0F;
|
|
|
- ch1 += ( (ch1 > 9 ) ? 0x37 : 0x30 );
|
|
|
- ch2 += ( (ch2 > 9 ) ? 0x37 : 0x30 );
|
|
|
- pDest[i*2] = ch1;
|
|
|
- pDest[i*2 + 1] = ch2;
|
|
|
- }
|
|
|
-}
|
|
|
-//%2
|
|
|
-static void pack_(char *pSrc, char *pDest, int iSrcLen)
|
|
|
-{
|
|
|
- char ch1, ch2;
|
|
|
- for( int i = 0; i < (iSrcLen / 2); i++ )
|
|
|
- {
|
|
|
- ch1 = pSrc[i*2];
|
|
|
- ch2 = pSrc[i*2 + 1];
|
|
|
- (ch1 >= 'a' && ch1 <= 'z') ? (ch1 -= 32) : (ch1);
|
|
|
- (ch2 >= 'a' && ch2 <= 'z') ? (ch2 -= 32) : (ch2);
|
|
|
- ch1 -= ( (ch1 > '9' ) ? 0x37 : 0x30 );
|
|
|
- ch2 -= ( (ch2 > '9' ) ? 0x37 : 0x30 );
|
|
|
- pDest[i] = ( ch1 << 4 ) | ch2;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-//CUserIoDll useIo;
|
|
|
-#if 0 // windows
|
|
|
-HMODULE GetSelfModuleHandle()
|
|
|
-{
|
|
|
- MEMORY_BASIC_INFORMATION mbi;
|
|
|
- return ((::VirtualQuery(GetSelfModuleHandle, &mbi, sizeof(mbi)) != 0) ? (HMODULE)mbi.AllocationBase : NULL);
|
|
|
-}
|
|
|
-
|
|
|
-std::string GetLibPath(HMODULE p_hMod)
|
|
|
-{
|
|
|
- char lpszPath[MAX_PATH] = {0};
|
|
|
- GetModuleFileNameA(p_hMod,lpszPath,MAX_PATH);
|
|
|
-
|
|
|
- int len = strlen(lpszPath);
|
|
|
- if(len>=1)
|
|
|
- {
|
|
|
- int i=0;
|
|
|
- for (i=len -1;i>=0;i--)
|
|
|
- {
|
|
|
- if (lpszPath[i] =='\\')
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- lpszPath[i+1] =0;
|
|
|
- }
|
|
|
- return lpszPath;
|
|
|
-}
|
|
|
-#else
|
|
|
-HMODULE GetSelfModuleHandle()
|
|
|
-{
|
|
|
- return NULL;
|
|
|
-}
|
|
|
-
|
|
|
-std::string GetLibPath(HMODULE p_hMod)
|
|
|
-{
|
|
|
- std::string wdir;
|
|
|
- Dl_info dl_info;
|
|
|
- dladdr((void*)GetLibPath, &dl_info);
|
|
|
-
|
|
|
- std::string path(dl_info.dli_fname);
|
|
|
- wdir = path.substr(0, path.find_last_of('/') + 1);
|
|
|
-
|
|
|
- return wdir;
|
|
|
-}
|
|
|
-#endif
|
|
|
-
|
|
|
-CGrgPinPadImpl::CGrgPinPadImpl() :
|
|
|
-m_EppDll(NULL),
|
|
|
-nIsListenExit(false),
|
|
|
-nIsListenStop(true),
|
|
|
-m_bKeyValue(0),
|
|
|
-nIsConnecting(false),
|
|
|
-nIskeyReadstatus_(false),
|
|
|
-m_hEvent(NULL),
|
|
|
-PinKeyLength(6),
|
|
|
-m_KeyReadMode(E_NULL_MODE),
|
|
|
-m_nWorkKeyMode(0),
|
|
|
-m_bActiveWkKeyNum(0),
|
|
|
-m_bActiveMsKeyNum(0),
|
|
|
-isRunExit(false),
|
|
|
-isPlaySound(false),
|
|
|
-m_PinPadDllPath(L"")
|
|
|
-{
|
|
|
- memset(&m_tDevErrorInfo,0,sizeof(m_tDevErrorInfo));
|
|
|
-
|
|
|
- memset(m_tAccountInfo.account,0,MAX_ACCOUNT_LEN);
|
|
|
- m_tAccountInfo.dwAccLen = 0;
|
|
|
-
|
|
|
- m_eEncryptMethod = EPP_ALGO_METHOD_3DES;
|
|
|
- m_eMacAlgorithm = EPP_MAC_ALGO_ASNIX99;
|
|
|
- m_ePinAlgorithm = EPP_PIN_ALGO_ISO9564_1_ANSI;
|
|
|
- m_eEcbCbcMode = EPP_ALGO_MODE_DEC_ECB;
|
|
|
-
|
|
|
-
|
|
|
- m_EppDll = new CBaseEPPDevDll();
|
|
|
- //LOG4VTM(INFO,"++++begin iSetCommPara");
|
|
|
- //int ret = m_EppDll->iSetCommPara(DevRetInfo);
|
|
|
- //LOG4VTM(INFO,"++++begin iSetCommPara end");
|
|
|
-
|
|
|
-
|
|
|
- m_hTimerManagerThread = NULL;
|
|
|
- pCGrgPinPadImpl = this;
|
|
|
-
|
|
|
- LOG4VTM(INFO,"Enter CGrgPinPadImpl::CGrgPinPadImpl");
|
|
|
-
|
|
|
- if (NULL == m_hTimerManagerThread)
|
|
|
- {
|
|
|
- //m_hTimerManagerThread = CreateThread(NULL, 0, OnProThreadEnter, this, 0, NULL);
|
|
|
- }
|
|
|
-
|
|
|
- m_EppDll->vSetProcFun(UpdataProFun);
|
|
|
-
|
|
|
-// m_pCRunQueueAPC = new CRunQueueAPC();
|
|
|
-
|
|
|
- // for test play wav
|
|
|
- //isPlaySound=true;
|
|
|
- //mPlaySound();
|
|
|
-
|
|
|
-// m_hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
|
|
|
-
|
|
|
- LOG4VTM(INFO,"Return CGrgPinPadImpl::CGrgPinPadImpl");
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-CGrgPinPadImpl::~CGrgPinPadImpl(void)
|
|
|
-{
|
|
|
- LOG4VTM(INFO,"Enter CGrgPinPadImpl::~CGrgPinPadImpl");
|
|
|
- nIsListenStop = false;
|
|
|
- nIsListenExit = true;
|
|
|
- isRunExit = true;
|
|
|
-// SetEvent(m_eventExit);
|
|
|
- //CloseRunThread();
|
|
|
-// if(m_eventExit!=NULL)
|
|
|
-// {
|
|
|
-// CloseHandle(m_eventExit);
|
|
|
- // m_eventExit = NULL;
|
|
|
- // }
|
|
|
-
|
|
|
- /* if(m_pCRunQueueAPC!=NULL)
|
|
|
- {
|
|
|
- delete m_pCRunQueueAPC;
|
|
|
- m_pCRunQueueAPC = NULL;
|
|
|
- }*/
|
|
|
- if(m_hEvent!=NULL)
|
|
|
- {
|
|
|
- //CloseHandle(m_hEvent);
|
|
|
- m_hEvent = NULL;
|
|
|
- }
|
|
|
- isPlaySound = false;
|
|
|
-
|
|
|
- delete m_EppDll;
|
|
|
- m_EppDll = NULL;
|
|
|
-
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::~CGrgPinPadImpl success");
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::CreateRunThread()
|
|
|
-{
|
|
|
-
|
|
|
-/* if (NULL==m_pCRunQueueAPC)
|
|
|
- {
|
|
|
- return Error_NoTarget;
|
|
|
- }*/
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::DevOpen(DWORD dwPort,DWORD dwBaudRate)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- LOG4VTM(INFO,"enter CGrgPinPadImpl::DevOpen");
|
|
|
- if(nIsConnecting)
|
|
|
- {
|
|
|
- DevClose();
|
|
|
- }
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- if(CreateRunThread()!=Error_Succeed)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoTarget,Error_NoTarget,"CreateRunThread Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
- l_apcRet.m_iReturn = -1;
|
|
|
- APCSyncCall(DevOpenWrapper,&l_apcRet);
|
|
|
-
|
|
|
- if(l_apcRet.m_iReturn!=0)
|
|
|
- {
|
|
|
- UpdatalastErr(DevRetInfo[0].iLogicCode,DevRetInfo[0].iPhyCode,"DevOpen Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_DevConnFailed;
|
|
|
- }
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::DevOpen success");
|
|
|
- nIsConnecting = true;
|
|
|
-
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-void CALLBACK CGrgPinPadImpl::DevOpenWrapper(void* dwPARAM)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- PAPCReturn pAPCRet = NULL;
|
|
|
- pAPCRet = (PAPCReturn)dwPARAM;
|
|
|
- CGrgPinPadImpl *pPinPad = (CGrgPinPadImpl*)(pAPCRet->m_Object);
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
-
|
|
|
- LOG4VTM(INFO,"begin iSetCommPara");
|
|
|
- int ret = pPinPad->m_EppDll->iSetCommPara(DevRetInfo);
|
|
|
- // LOG4VTM(INFO,"end iSetCommPara");
|
|
|
-
|
|
|
- if(ret == 0)
|
|
|
- {
|
|
|
- BYTE SM4_B = 0x00;
|
|
|
- BYTE SM2_B = 0x00;
|
|
|
- BYTE SM3_B = 0x00;
|
|
|
- ret = pPinPad->m_EppDll->iSM_AlgorithmMode(SM4_B,SM2_B,SM3_B,DevRetInfo);//
|
|
|
- }
|
|
|
-
|
|
|
- char buffer[32] = {0};
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- if(pAPCRet->m_hEvent)
|
|
|
- {
|
|
|
- SetEvent(pAPCRet->m_hEvent);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::KeyRead(BYTE &ch)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- ch = 0;
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- UpdatalastErr(Error_DevCommFailed,Error_DevCommFailed,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- return Error_DevCommFailed;
|
|
|
- }
|
|
|
- if(!nIskeyReadstatus_)return Error_InvalidState;
|
|
|
-
|
|
|
- return GetKeyValue(ch);
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::SetParam(SetParamTypeEnum eType,SetParamValueEnum eValue)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- std::string str = "CGrgPinPadImpl::SetParam SetParamTypeEnum: "+int2str(eType)+" SetParamValueEnum"+int2str(eValue);
|
|
|
- // LOG4VTM(INFO,Lstr.c_str());
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
- if(eType == EPP_PT_SET_ENCRYPT_METHOD)
|
|
|
- {
|
|
|
- m_eEncryptMethod = eValue;
|
|
|
- }else if(eType == EPP_PT_SET_MAC_ALGORITH)
|
|
|
- {
|
|
|
- m_eMacAlgorithm = eValue;
|
|
|
- }else if(eType == EPP_PT_SET_PIN_ALGORITH)
|
|
|
- {
|
|
|
- m_ePinAlgorithm = eValue;
|
|
|
- }else if(eType == EPP_PT_SET_ECB_CBC_MODE)
|
|
|
- {
|
|
|
- m_eEcbCbcMode = eValue;
|
|
|
- }
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::SetAccNo(AccountInfo accInfo)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::SetAccNo");
|
|
|
- char buffer[32] = {0};
|
|
|
- unpack_((char*)accInfo.account,buffer,accInfo.dwAccLen);
|
|
|
- std::string str = "AccountInfo dwAccLen:"+int2str(accInfo.dwAccLen);
|
|
|
-
|
|
|
- memcpy(m_tAccountInfo.account,accInfo.account,accInfo.dwAccLen);
|
|
|
- m_tAccountInfo.dwAccLen = accInfo.dwAccLen;
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::SetAccNo success");
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::LoadMasterKey(MasterKeyParam masterKey)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::LoadMasterKey");
|
|
|
- int mkLen = strlen((char*)masterKey.key);
|
|
|
- if(mkLen > 32)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_Param,Error_Param,"MasterKey size only{16,24}",__FUNCTION__,__LINE__);
|
|
|
- return Error_Param;
|
|
|
- }
|
|
|
-
|
|
|
- if((mkLen!=32 && mkLen!=48))
|
|
|
- {
|
|
|
- UpdatalastErr(Error_Param,Error_Param,"MasterKey size only{16,24}",__FUNCTION__,__LINE__);
|
|
|
- return Error_Param;
|
|
|
- }
|
|
|
- if(!mCreateThread())
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoDefine,Error_NoDefine,"mCreateThread error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoDefine;
|
|
|
- }
|
|
|
- std::string info = "LoadMasterKey smFlag: "+int2str(masterKey.smFlag)+"dwSN:"+int2str(masterKey.dwSN)+" masterKey len:"+int2str(mkLen);
|
|
|
- //LOG4VTM(INFO,Linfo.c_str());
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
-
|
|
|
- /*MasterKeyParam newMsKey = {0};
|
|
|
- newMsKey.dwSN = masterKey.dwSN;
|
|
|
- newMsKey.smFlag = masterKey.smFlag;
|
|
|
- memcpy(newMsKey.key,buffer,mkLen);*/
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_iReturn = -1;
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- l_apcRet.m_p1 = &masterKey;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- if(CreateRunThread()!=Error_Succeed)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoTarget,Error_NoTarget,"CreateRunThread Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
- APCSyncCall(LoadMasterKeyWrapper,&l_apcRet);
|
|
|
- //QueueUserAPC(LoadMasterKeyWrapper,m_hTimerManagerThread,(DWORD)&l_apcRet);
|
|
|
- //WaitForSingleObject(l_apcRet.m_hEvent,INFINITE);
|
|
|
- //CloseRunThread();
|
|
|
- if(l_apcRet.m_iReturn!=0)
|
|
|
- {
|
|
|
- UpdatalastErr(DevRetInfo[0].iLogicCode,DevRetInfo[0].iPhyCode,"LoadMasterKey::iLoadKeyPart Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_Exception;
|
|
|
- }
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::LoadMasterKey success");
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-void CALLBACK CGrgPinPadImpl::LoadMasterKeyWrapper(void* dwPARAM)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- PAPCReturn pAPCRet = (PAPCReturn)dwPARAM;
|
|
|
- CGrgPinPadImpl *pPinPad = (CGrgPinPadImpl*)(pAPCRet->m_Object);
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- MasterKeyParam *pmasterKey = (MasterKeyParam*)pAPCRet->m_p1;
|
|
|
- int ret = Error_Exception;
|
|
|
- char buffer[8] = {0};
|
|
|
- if(pmasterKey->dwSN<10)
|
|
|
- {
|
|
|
- sprintf(buffer, "MK%d", pmasterKey->dwSN);
|
|
|
- }else
|
|
|
- {
|
|
|
- sprintf(buffer, "M%d", pmasterKey->dwSN);
|
|
|
- }
|
|
|
-
|
|
|
- unsigned char PackKeybuffer[30] = {0};
|
|
|
- int mkLen = strlen((char*)pmasterKey->key);
|
|
|
- pack_((char*)pmasterKey->key,(char*)PackKeybuffer,mkLen);
|
|
|
- mkLen = mkLen/2;
|
|
|
-
|
|
|
- std::string info = "LoadMasterKey WorkKey len:"+int2str(mkLen);
|
|
|
- // LOG4VTM(INFO,Linfo.c_str());
|
|
|
-
|
|
|
- int l_iResult = FAIL;
|
|
|
- //获取设备状��1�7�1�7
|
|
|
- int tryCnt =0;
|
|
|
- bool bl = false;
|
|
|
- int TRYCNT = 3;
|
|
|
-
|
|
|
- int mainTryCnt = 0;
|
|
|
- bool isLoadPartOk = false;
|
|
|
-
|
|
|
- while(mainTryCnt < TRYCNT)
|
|
|
- {
|
|
|
- while(tryCnt < TRYCNT)
|
|
|
- {
|
|
|
- ret = pPinPad->m_EppDll->iLoadKeyPart(buffer,'A',(char*)PackKeybuffer,mkLen,DevRetInfo);
|
|
|
- if(SUCCESS != ret) {
|
|
|
- //int openRet = pPinPad->m_EppDll->iCloseComm();
|
|
|
- // tDevReturn devRet[8] = {0};
|
|
|
- Sleep(100);
|
|
|
- // openRet = pPinPad->m_EppDll->iSetCommPara(devRet);
|
|
|
- // pPinPad->LOG4VTM(ERROR,"iLoadKeyPart a ones error");
|
|
|
- ++tryCnt;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- bl =true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(ret!=0)
|
|
|
- {
|
|
|
- isLoadPartOk = false;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- l_iResult = FAIL;
|
|
|
- //获取设备状��1�7�1�7
|
|
|
- tryCnt =0;
|
|
|
- bl = false;
|
|
|
- while(tryCnt < TRYCNT)
|
|
|
- {
|
|
|
- char x_park[32] = {0};
|
|
|
- ret = pPinPad->m_EppDll->iLoadKeyPart(buffer,'X',(char*)x_park,mkLen,DevRetInfo);
|
|
|
- if(SUCCESS != ret) {
|
|
|
- if(DevRetInfo[0].iLogicCode == 40042)
|
|
|
- {
|
|
|
- break;
|
|
|
- }else
|
|
|
- {
|
|
|
- //int openRet = pPinPad->m_EppDll->iCloseComm();
|
|
|
- // tDevReturn devRet[8] = {0};
|
|
|
- Sleep(100);
|
|
|
- // openRet = pPinPad->m_EppDll->iSetCommPara(devRet);
|
|
|
-// pPinPad->LOG4VTM(ERROR,"iLoadKeyPart x ones error");
|
|
|
- ++tryCnt;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- isLoadPartOk = true;
|
|
|
- bl =true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if(isLoadPartOk)
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- mainTryCnt++;
|
|
|
- }
|
|
|
-
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::LoadWorkingKey(WorkKeyParam wkKey)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- LOG4VTM(INFO,"endter CGrgPinPadImpl::LoadWorkingKey");
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
- int mkLen = strlen((char*)wkKey.key);
|
|
|
-
|
|
|
- if(mkLen!=32&&mkLen!=48)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_Param,Error_Param,"WorkingKey size only{16,24}",__FUNCTION__,__LINE__);
|
|
|
- return Error_Param;
|
|
|
- }
|
|
|
-
|
|
|
- if(!mCreateThread())
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoDefine,Error_NoDefine,"mCreateThread Error",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoDefine;
|
|
|
- }
|
|
|
- std::string info = "LoadWorkingKey smFlag: "+int2str(wkKey.smFlag)+" MasterSN: "+int2str(wkKey.dwMasterSN)+" WorkSN:"+int2str(wkKey.dwWorkingSN)+" WorkKey len:"+int2str(mkLen);
|
|
|
-// LOG4VTM(INFO,Linfo.c_str());
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
-
|
|
|
- /*WorkKeyParam wkKey_new = {0};
|
|
|
- memcpy(&wkKey_new,&wkKey,sizeof(wkKey_new));
|
|
|
- memset(wkKey_new.key,0,sizeof(wkKey_new.key));
|
|
|
- memcpy(wkKey_new.key,buffer,mkLen);
|
|
|
-*/
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- l_apcRet.m_p1 = &wkKey;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- if(CreateRunThread()!=Error_Succeed)
|
|
|
- {
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
- l_apcRet.m_iReturn = -1;
|
|
|
- APCSyncCall(LoadWorkingKeyWrapper,&l_apcRet);
|
|
|
- //QueueUserAPC(LoadWorkingKeyWrapper,m_hTimerManagerThread,(DWORD)&l_apcRet);
|
|
|
- //WaitForSingleObject(l_apcRet.m_hEvent,INFINITE);
|
|
|
- //CloseRunThread();
|
|
|
-
|
|
|
- if(l_apcRet.m_iReturn!=0)
|
|
|
- {
|
|
|
- UpdatalastErr(DevRetInfo[0].iLogicCode,DevRetInfo[0].iPhyCode,"LoadMasterKey::LoadWorkingKey Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_Exception;
|
|
|
- }
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::LoadWorkingKey success");
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-void CALLBACK CGrgPinPadImpl::LoadWorkingKeyWrapper(void* dwPARAM)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- PAPCReturn pAPCRet = (PAPCReturn)dwPARAM;
|
|
|
- CGrgPinPadImpl *pPinPad = (CGrgPinPadImpl*)(pAPCRet->m_Object);
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- WorkKeyParam *pWorkKey = (WorkKeyParam*)pAPCRet->m_p1;
|
|
|
- int ret = Error_Exception;
|
|
|
- int mkLen = strlen((char*)pWorkKey->key);
|
|
|
- int retMode = -1;
|
|
|
-
|
|
|
- std::string MsName = "MK0";
|
|
|
- char WkBuff[8] = {0};
|
|
|
- char WkBuff_ver[8] = {0};
|
|
|
- if(pWorkKey->smFlag==1)
|
|
|
- {
|
|
|
- //国密
|
|
|
- MsName = "MK1";
|
|
|
- sprintf(WkBuff, "W%02d", pWorkKey->dwWorkingSN+10);
|
|
|
- sprintf(WkBuff_ver, "W%02d", pWorkKey->dwWorkingSN+30);
|
|
|
- BYTE SM4_B = 0x01;
|
|
|
- BYTE SM2_B = 0x01;
|
|
|
- BYTE SM3_B = 0x01;
|
|
|
-
|
|
|
- retMode = pPinPad->m_EppDll->iSM_AlgorithmMode(SM4_B,SM2_B,SM3_B,DevRetInfo);//
|
|
|
- }else if(pWorkKey->smFlag==0)
|
|
|
- {
|
|
|
- std::string MsName = "MK0";
|
|
|
- sprintf(WkBuff, "W%02d", pWorkKey->dwWorkingSN);
|
|
|
- sprintf(WkBuff_ver, "W%02d", pWorkKey->dwWorkingSN+20);
|
|
|
- BYTE SM4_B = 0x00;
|
|
|
- BYTE SM2_B = 0x00;
|
|
|
- BYTE SM3_B = 0x00;
|
|
|
- retMode = pPinPad->m_EppDll->iSM_AlgorithmMode(SM4_B,SM2_B,SM3_B,DevRetInfo);//
|
|
|
- }
|
|
|
-
|
|
|
- char PackKeybuffer[30] = {0};
|
|
|
- pack_((char*)pWorkKey->key,PackKeybuffer,mkLen);
|
|
|
- mkLen = mkLen/2;
|
|
|
- std::string info = "LoadWorkingKey WorkKey len:"+int2str(mkLen);
|
|
|
-// LOG4VTM(INFO,Linfo.c_str());
|
|
|
- char kvv_buf[8] = {0};
|
|
|
- int l_iResult = FAIL;
|
|
|
- //获取设备状��1�7�1�7
|
|
|
- int tryCnt =0;
|
|
|
- bool bl = false;
|
|
|
- int TRYCNT = 3;
|
|
|
- if(pWorkKey->dwWorkingSN == 0)
|
|
|
- {//pin加密
|
|
|
-
|
|
|
- while(tryCnt < TRYCNT)
|
|
|
- {
|
|
|
- ret = pPinPad->m_EppDll->iImportKey(WkBuff,(char*)MsName.c_str(),0x04,(char*)PackKeybuffer,mkLen,kvv_buf,DevRetInfo,0);
|
|
|
- if(SUCCESS != ret) {
|
|
|
- int openRet = pPinPad->m_EppDll->iCloseComm2();
|
|
|
- tDevReturn devRet[8] = {0};
|
|
|
- Sleep(500);
|
|
|
- openRet = pPinPad->m_EppDll->iSetCommPara(devRet);
|
|
|
-// pPinPad->LOG4VTM(ERROR,"iImport pin Key a ones error");
|
|
|
- ++tryCnt;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- bl =true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(ret!=0)
|
|
|
- {
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- l_iResult = FAIL;
|
|
|
- //获取设备状��1�7�1�7
|
|
|
- tryCnt =0;
|
|
|
- bl = false;
|
|
|
- TRYCNT = 3;
|
|
|
- while(tryCnt < TRYCNT)
|
|
|
- {
|
|
|
- ret = pPinPad->m_EppDll->iImportKey(WkBuff_ver,(char*)MsName.c_str(),0x01,(char*)PackKeybuffer,mkLen,kvv_buf,DevRetInfo,0);
|
|
|
- if(SUCCESS != ret) {
|
|
|
- //int openRet = pPinPad->m_EppDll->iCloseComm();
|
|
|
- // tDevReturn devRet[8] = {0};
|
|
|
- Sleep(500);
|
|
|
- // openRet = pPinPad->m_EppDll->iSetCommPara(devRet);
|
|
|
-// pPinPad->LOG4VTM(ERROR,"iImportKey pin two error");
|
|
|
- ++tryCnt;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- bl =true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(ret!=0)
|
|
|
- {
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- }else if(pWorkKey->dwWorkingSN == 1)
|
|
|
- {//数据加密
|
|
|
-
|
|
|
- l_iResult = FAIL;
|
|
|
- //获取设备状��1�7�1�7
|
|
|
- tryCnt =0;
|
|
|
- bl = false;
|
|
|
- TRYCNT = 3;
|
|
|
- while(tryCnt < TRYCNT)
|
|
|
- {
|
|
|
- ret = pPinPad->m_EppDll->iImportKey(WkBuff,(char*)MsName.c_str(),0x01,(char*)PackKeybuffer,mkLen,kvv_buf,DevRetInfo,0);
|
|
|
- if(SUCCESS != ret) {
|
|
|
- //int openRet = pPinPad->m_EppDll->iCloseComm();
|
|
|
- //tDevReturn devRet[8] = {0};
|
|
|
- Sleep(500);
|
|
|
- //openRet = pPinPad->m_EppDll->iSetCommPara(devRet);
|
|
|
-// pPinPad->LOG4VTM(ERROR,"iImport data Key a ones error");
|
|
|
- ++tryCnt;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- bl =true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(ret!=0)
|
|
|
- {
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- }else if(pWorkKey->dwWorkingSN == 2)
|
|
|
- {
|
|
|
- ret = pPinPad->m_EppDll->iImportKey(WkBuff,(char*)MsName.c_str(),0x02,(char*)PackKeybuffer,mkLen,kvv_buf,DevRetInfo,0);
|
|
|
- }else if(pWorkKey->dwWorkingSN == 3)
|
|
|
- {//作为MAC校验密钥使用
|
|
|
- ret = pPinPad->m_EppDll->iImportKey(WkBuff,(char*)MsName.c_str(),0x20,(char*)PackKeybuffer,mkLen,kvv_buf,DevRetInfo,0);
|
|
|
- }
|
|
|
-
|
|
|
- char str_kvv[32]={0};
|
|
|
- unpack_(kvv_buf,str_kvv,4);
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::ActiveWorkingKey(DWORD dwMkSN,DWORD dwWkSN)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- std::string str = "CGrgPinPadImpl::ActiveWorkingKey dwMkSN:"+int2str(dwMkSN)+" dwWkSN"+int2str(dwWkSN);
|
|
|
- LOG4VTM(INFO,str);
|
|
|
-
|
|
|
-
|
|
|
- m_bActiveMsKeyNum = dwMkSN;
|
|
|
- m_bActiveWkKeyNum = dwWkSN;
|
|
|
-
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- l_apcRet.m_p1 = &dwMkSN;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- if(CreateRunThread()!=Error_Succeed)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoTarget,Error_NoTarget,"CreateRunThread Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
- l_apcRet.m_iReturn = -1;
|
|
|
- APCSyncCall(ActiveWorkingKeyWrapper,&l_apcRet);
|
|
|
-
|
|
|
- if(l_apcRet.m_iReturn!=0)
|
|
|
- {
|
|
|
- UpdatalastErr(DevRetInfo[0].iLogicCode,DevRetInfo[0].iPhyCode,"LoadMasterKey::ActiveWorkingKey Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_Exception;
|
|
|
- }
|
|
|
-
|
|
|
- LOG4VTM(INFO,"ActiveWorkingKey success");
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-void CALLBACK CGrgPinPadImpl::ActiveWorkingKeyWrapper(void* dwPARAM)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- PAPCReturn pAPCRet = (PAPCReturn)dwPARAM;
|
|
|
- CGrgPinPadImpl *pPinPad = (CGrgPinPadImpl*)(pAPCRet->m_Object);
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- BYTE mode = *((BYTE*)(pAPCRet->m_p1));
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- int ret = 1;
|
|
|
- if(mode==0)
|
|
|
- { //3des
|
|
|
- BYTE SM4_B = 0x00;
|
|
|
- BYTE SM2_B = 0x00;
|
|
|
- BYTE SM3_B = 0x00;
|
|
|
- ret = pPinPad->m_EppDll->iSM_AlgorithmMode(SM4_B,SM2_B,SM3_B,DevRetInfo);//
|
|
|
- }else if(mode==1)
|
|
|
- { //国密
|
|
|
- BYTE SM4_B = 0x01;
|
|
|
- BYTE SM2_B = 0x01;
|
|
|
- BYTE SM3_B = 0x01;
|
|
|
- ret = pPinPad->m_EppDll->iSM_AlgorithmMode(SM4_B,SM2_B,SM3_B,DevRetInfo);//
|
|
|
- }
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::StartPinInput(BYTE byLen)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
- LOG4VTM(INFO,"Enter CGrgPinPadImpl::StartPinInput");
|
|
|
- if(byLen<4)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_Param,Error_Param,"byLen<4",__FUNCTION__,__LINE__);
|
|
|
- return Error_Param;
|
|
|
- }
|
|
|
- if(!mCreateThread())
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoDefine,Error_NoDefine,"mCreateThread Error",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoDefine;
|
|
|
- }
|
|
|
- m_keyVtrAll.clear(); //2022.12.07
|
|
|
- PinKeyLength = byLen;
|
|
|
- std::string Info = "byLen$1�7 "+int2str(byLen)+" AccountInfo.dwAccLen:"+int2str(m_tAccountInfo.dwAccLen);
|
|
|
-// LOG4VTM(INFO,LInfo.c_str());
|
|
|
- LOG4VTM(INFO,(Info));
|
|
|
-
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
-
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- l_apcRet.m_p1 = &byLen;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- if(CreateRunThread()!=Error_Succeed)
|
|
|
- {
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
- SetKeyValue(0x00);
|
|
|
- l_apcRet.m_iReturn = -1;
|
|
|
- APCSyncCall(StartPinInputWrapper,&l_apcRet);
|
|
|
-
|
|
|
- m_KeyReadMode = E_NULL_MODE;
|
|
|
- if(l_apcRet.m_iReturn!=0)
|
|
|
- {
|
|
|
- UpdatalastErr(DevRetInfo[0].iLogicCode,DevRetInfo[0].iPhyCode,"StartPinInput Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_Exception;
|
|
|
- }
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::StartPinInput success");
|
|
|
- m_KeyReadMode = E_PIN_MODE;
|
|
|
- nIskeyReadstatus_ = true;
|
|
|
- isPlaySound = true;
|
|
|
-
|
|
|
- //m_CUserIoDll.Open(m_PinPadDllPath,0,0);
|
|
|
-// m_CUserIoDll.SetLightStatus(20,3,1);
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-void CALLBACK CGrgPinPadImpl::StartPinInputWrapper(void* dwPARAM)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- PAPCReturn pAPCRet = (PAPCReturn)dwPARAM;
|
|
|
- CGrgPinPadImpl *pPinPad = (CGrgPinPadImpl*)(pAPCRet->m_Object);
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- BYTE byLen = *((BYTE*)(pAPCRet->m_p1));
|
|
|
- int ret = pPinPad->m_EppDll->iStartPinEntry(byLen,byLen,DevRetInfo);
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::StartPinInputConfirm(BYTE byLen)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
- LOG4VTM(INFO,"Enter CGrgPinPadImpl::StartPinInputConfirm");
|
|
|
- if(byLen<4)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_Param,Error_Param,"byLen<4",__FUNCTION__,__LINE__);
|
|
|
- return Error_Param;
|
|
|
- }
|
|
|
- if(!mCreateThread())
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoDefine,Error_NoDefine,"mCreateThread Error",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoDefine;
|
|
|
- }
|
|
|
- PinKeyLength = byLen;
|
|
|
- std::string Info = "byLen$1�7 "+int2str(byLen);
|
|
|
- LOG4VTM(INFO,(Info));
|
|
|
-
|
|
|
-// LOG4VTM(INFO,LInfo.c_str());
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
-
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- l_apcRet.m_p1 = &byLen;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- if(CreateRunThread()!=Error_Succeed)
|
|
|
- {
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
- SetKeyValue(0x00);
|
|
|
- l_apcRet.m_iReturn = -1;
|
|
|
- APCSyncCall(StartPinInputWrapper,&l_apcRet);
|
|
|
- //QueueUserAPC(StartPinInputWrapper,m_hTimerManagerThread,(DWORD)&l_apcRet);
|
|
|
- //WaitForSingleObject(l_apcRet.m_hEvent,INFINITE);
|
|
|
- //CloseRunThread();
|
|
|
- if(l_apcRet.m_iReturn!=0)
|
|
|
- {
|
|
|
- UpdatalastErr(DevRetInfo[0].iLogicCode,DevRetInfo[0].iPhyCode,"StartPinInputConfirm Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_Exception;
|
|
|
- }
|
|
|
- nIskeyReadstatus_ = true;
|
|
|
- m_KeyReadMode = E_PIN_MODE;
|
|
|
-// LOG4VTM(INFO,"Enter CGrgPinPadImpl::StartPinInputConfirm");
|
|
|
- isPlaySound = true;
|
|
|
- //m_CUserIoDll.Open(m_PinPadDllPath,0,0);
|
|
|
-// m_CUserIoDll.SetLightStatus(20,3,1);
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-void CALLBACK CGrgPinPadImpl::StartPinInputConfirmWrapper(void* dwPARAM)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- PAPCReturn pAPCRet = (PAPCReturn)dwPARAM;
|
|
|
- CGrgPinPadImpl *pPinPad = (CGrgPinPadImpl*)(pAPCRet->m_Object);
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- BYTE byLen = *((BYTE*)(pAPCRet->m_p1));
|
|
|
- int ret = pPinPad->m_EppDll->iStartPinEntry(byLen,byLen,DevRetInfo);
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::StartPlainInput()
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- LOG4VTM(INFO,"Enter CGrgPinPadImpl::StartPlainInput");
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- if(!mCreateThread())
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoDefine,Error_NoDefine,"mCreateThread Error",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoDefine;
|
|
|
- }
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- if(CreateRunThread()!=Error_Succeed)
|
|
|
- {
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
- SetKeyValue(0x00);
|
|
|
- l_apcRet.m_iReturn = -1;
|
|
|
- APCSyncCall(StartPlainInputWrapper,&l_apcRet);
|
|
|
- //QueueUserAPC(StartPlainInputWrapper,m_hTimerManagerThread,(DWORD)&l_apcRet);
|
|
|
- //WaitForSingleObject(l_apcRet.m_hEvent,INFINITE);
|
|
|
- //CloseRunThread();
|
|
|
- if(l_apcRet.m_iReturn!=0)
|
|
|
- {
|
|
|
- UpdatalastErr(DevRetInfo[0].iLogicCode,DevRetInfo[0].iPhyCode,"StartPlainInput Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_Exception;
|
|
|
- }
|
|
|
- m_KeyReadMode = E_PLAIN_MODE;
|
|
|
- nIskeyReadstatus_ = true;
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::StartPlainInput success");
|
|
|
-
|
|
|
- isPlaySound = true;
|
|
|
- //m_CUserIoDll.Open(m_PinPadDllPath,0,0);
|
|
|
-// m_CUserIoDll.SetLightStatus(20,3,1);
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-void CALLBACK CGrgPinPadImpl::StartPlainInputWrapper(void* dwPARAM)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- PAPCReturn pAPCRet = (PAPCReturn)dwPARAM;
|
|
|
- CGrgPinPadImpl *pPinPad = (CGrgPinPadImpl*)(pAPCRet->m_Object);
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- int ret = pPinPad->m_EppDll->iStartDataEntry(DevRetInfo);
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::StopInput()
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::StopInput");
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- if(!mCreateThread())
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoDefine,Error_NoDefine,"mCreateThread Error",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoDefine;
|
|
|
- }
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- if(CreateRunThread()!=Error_Succeed)
|
|
|
- {
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
- l_apcRet.m_iReturn = -1;
|
|
|
- APCSyncCall(StopInputWrapper,&l_apcRet);
|
|
|
- //QueueUserAPC(StopInputWrapper,m_hTimerManagerThread,(DWORD)&l_apcRet);
|
|
|
- //WaitForSingleObject(l_apcRet.m_hEvent,INFINITE);
|
|
|
- //CloseRunThread();
|
|
|
- if(l_apcRet.m_iReturn!=0)
|
|
|
- {
|
|
|
- UpdatalastErr(DevRetInfo[0].iLogicCode,DevRetInfo[0].iPhyCode,"StopInput Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_Exception;
|
|
|
- }
|
|
|
- m_KeyReadMode = E_NULL_MODE;
|
|
|
- nIskeyReadstatus_ = false;
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::StopInput success");
|
|
|
- //m_CUserIoDll.Open(m_PinPadDllPath,0,0);
|
|
|
-// m_CUserIoDll.SetLightStatus(20,3,0);
|
|
|
- isPlaySound = true;
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-void CALLBACK CGrgPinPadImpl::StopInputWrapper(void* dwPARAM)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- PAPCReturn pAPCRet = (PAPCReturn)dwPARAM;
|
|
|
- CGrgPinPadImpl *pPinPad = (CGrgPinPadImpl*)(pAPCRet->m_Object);
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- int ret = pPinPad->m_EppDll->iDisableKeyEntry(DevRetInfo);
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::GetPinBlock(PinBlock &block)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::GetPinBlock");
|
|
|
- memset(&block, 0, sizeof(block));
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
- if(!mCreateThread())
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoDefine,Error_NoDefine,"mCreateThread Error",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoDefine;
|
|
|
- }
|
|
|
- ErrorCodeEnum e = GrgGetpinBlock(PinKeyLength);
|
|
|
- if(e!=Error_Succeed)
|
|
|
- {
|
|
|
- return e;
|
|
|
- }
|
|
|
-
|
|
|
- LOG4VTM(INFO,"Enter CGrgPinPadImpl::GetPinBlock");
|
|
|
- if(m_tPinBlockInfo.mPinBlockLen == 0)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_InvalidState,Error_InvalidState,"mCreateThread Error",__FUNCTION__,__LINE__);
|
|
|
- LOG4VTM(ERROR,"GetPinBlock and Pinblock size=0");
|
|
|
- return Error_InvalidState;
|
|
|
- }
|
|
|
- memcpy(block.data,m_tPinBlockInfo.PinBlockBuff,m_tPinBlockInfo.mPinBlockLen);
|
|
|
- block.dwSize = m_tPinBlockInfo.mPinBlockLen;
|
|
|
- PinKeyLength = 0;
|
|
|
- m_tPinBlockInfo.Init();
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::GetPinBlock success");
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::EncryptData(EnDecryptInfo srcInfo, EnDecryptInfo &destInfo)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- LOG4VTM(INFO,"Enter CGrgPinPadImpl::EncryptData");
|
|
|
- memset(&destInfo,0,sizeof(destInfo));
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
- if(srcInfo.data==NULL||srcInfo.dwSize<1)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_Param,Error_Param,"srcInfo.data==NULL||srcInfo.dwSize<1",__FUNCTION__,__LINE__);
|
|
|
- return Error_Param;
|
|
|
- }
|
|
|
- if(!mCreateThread())
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoDefine,Error_NoDefine,"mCreateThread Error",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoDefine;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- std::string str1 = "EncryptData m_eEcbCbcMode:"+int2str(m_eEcbCbcMode);
|
|
|
- LOG4VTM(INFO,(str1));
|
|
|
-
|
|
|
-
|
|
|
- std::string str = "EncryptData dataLEn:"+int2str(srcInfo.dwSize);//+".data:"+ *byteToHexStr(srcInfo.data,srcInfo.dwSize);
|
|
|
- LOG4VTM(INFO,str);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- BYTE mode = 0x01;
|
|
|
- if(m_eEcbCbcMode==EPP_ALGO_MODE_ECB||m_eEcbCbcMode==EPP_ALGO_MODE_3DEC_ECB)
|
|
|
- {
|
|
|
- mode = 0x01;
|
|
|
-
|
|
|
- std::string str = "EncryptData mode:0x01";
|
|
|
- LOG4VTM(INFO,str);
|
|
|
-
|
|
|
- }else if(m_eEcbCbcMode==EPP_ALGO_MODE_CBC||m_eEcbCbcMode==EPP_ALGO_MODE_3DEC_CBC)
|
|
|
- {
|
|
|
- mode = 0x02;
|
|
|
- std::string str = "EncryptData mode:0x02";
|
|
|
- LOG4VTM(INFO,str);
|
|
|
-
|
|
|
-
|
|
|
- }else
|
|
|
- {
|
|
|
- std::string str = "--- err EncryptData out ";
|
|
|
- LOG4VTM(INFO,str);
|
|
|
- UpdatalastErr(Error_NotImpl,Error_NotImpl," err EncryptData out",__FUNCTION__,__LINE__);
|
|
|
- return Error_NotImpl;
|
|
|
- }
|
|
|
-
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- l_apcRet.m_p1 = &mode;
|
|
|
- l_apcRet.m_p2 = &srcInfo;
|
|
|
- l_apcRet.m_p3 = &destInfo;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- if(CreateRunThread()!=Error_Succeed)
|
|
|
- {
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
- l_apcRet.m_iReturn = -1;
|
|
|
- APCSyncCall(EncryptDataWrapper,&l_apcRet);
|
|
|
- //QueueUserAPC(EncryptDataWrapper,m_hTimerManagerThread,(DWORD)&l_apcRet);
|
|
|
- //WaitForSingleObject(l_apcRet.m_hEvent,INFINITE);
|
|
|
-// CloseRunThread();
|
|
|
- if(l_apcRet.m_iReturn!=0)
|
|
|
- {
|
|
|
- std::string str = "--- err EncryptData::iCrypt Error!----- ";
|
|
|
- LOG4VTM(INFO,str);
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::EncryptData fail");
|
|
|
- UpdatalastErr(DevRetInfo[0].iLogicCode,DevRetInfo[0].iPhyCode,"EncryptData::iCrypt Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_Exception;
|
|
|
- }
|
|
|
- std::string str2 = "return EncryptData destInfo dataLEn:"+int2str(destInfo.dwSize);//+".data:"+ *byteToHexStr(destInfo.data,destInfo.dwSize);
|
|
|
- LOG4VTM(INFO,(str2));
|
|
|
-
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::EncryptData success");
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-void CALLBACK CGrgPinPadImpl::EncryptDataWrapper(void* dwPARAM)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- PAPCReturn pAPCRet = (PAPCReturn)dwPARAM;
|
|
|
- CGrgPinPadImpl *pPinPad = (CGrgPinPadImpl*)(pAPCRet->m_Object);
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
-
|
|
|
- short lenOut = 0;
|
|
|
- BYTE mode = *((BYTE*)pAPCRet->m_p1);
|
|
|
- EnDecryptInfo *srcInfo = (EnDecryptInfo*)pAPCRet->m_p2;
|
|
|
- EnDecryptInfo *destInfo = (EnDecryptInfo*)pAPCRet->m_p3;
|
|
|
- //
|
|
|
- char pInitData[16] = {0};
|
|
|
- BYTE buffOut[MAX_EN_DECRYPT_DATA_SIZE] = {0};
|
|
|
- int ret = -1;
|
|
|
-
|
|
|
- char sreBuffer[MAX_EN_DECRYPT_DATA_SIZE*2] = {0};
|
|
|
- pack_((char*)srcInfo->data,sreBuffer,srcInfo->dwSize);
|
|
|
- int DataLen = (srcInfo->dwSize)/2;
|
|
|
- char workName[8] = {0};
|
|
|
- int addDataLen = 0;
|
|
|
- if(pPinPad->m_bActiveMsKeyNum == 0)
|
|
|
- {
|
|
|
- //3des
|
|
|
- if(pPinPad->m_bActiveWkKeyNum==0)
|
|
|
- {
|
|
|
- //PIN
|
|
|
- sprintf(workName, "W%02d", pPinPad->m_bActiveWkKeyNum+20);
|
|
|
- }else
|
|
|
- {
|
|
|
- sprintf(workName, "W%02d", pPinPad->m_bActiveWkKeyNum);
|
|
|
- }
|
|
|
- char pInitData[8] = {0};
|
|
|
- memset(pInitData, 0, sizeof(pInitData));
|
|
|
-
|
|
|
- ret = pPinPad->m_EppDll->iCrypt((char*)workName,mode,(char*)"",pInitData,sizeof(pInitData),sreBuffer,DataLen,(char*)buffOut,lenOut,DevRetInfo);
|
|
|
- }else if(pPinPad->m_bActiveMsKeyNum == 1)
|
|
|
- {//sm4
|
|
|
- if(pPinPad->m_bActiveWkKeyNum==0)
|
|
|
- {
|
|
|
- //PIN
|
|
|
- if(DataLen<16)
|
|
|
- {
|
|
|
- addDataLen = 16 - DataLen;
|
|
|
- DataLen = 16;
|
|
|
- }
|
|
|
- sprintf(workName, "W%02d", pPinPad->m_bActiveWkKeyNum+30);
|
|
|
- //ret = pPinPad->m_EppDll->iSafeGetKVV(workName,8,(char*)buffOut,DevRetInfo);
|
|
|
- }else
|
|
|
- {
|
|
|
- sprintf(workName, "W%02d", pPinPad->m_bActiveWkKeyNum+10);
|
|
|
- char pInitData[16] = {0};
|
|
|
- memset(pInitData, 0, sizeof(pInitData));
|
|
|
- ret = pPinPad->m_EppDll->iCrypt((char*)workName,mode,(char*)"",pInitData,sizeof(pInitData),sreBuffer,DataLen,(char*)buffOut,lenOut,DevRetInfo);
|
|
|
- }
|
|
|
- char pInitData[16] = {0};
|
|
|
- memset(pInitData, 0, sizeof(pInitData));
|
|
|
- ret = pPinPad->m_EppDll->iCrypt((char*)workName,mode,(char*)"",pInitData,sizeof(pInitData),sreBuffer,DataLen,(char*)buffOut,lenOut,DevRetInfo);
|
|
|
- }
|
|
|
-
|
|
|
- if(ret!=0)
|
|
|
- {
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
- }
|
|
|
- //C7326C5FD87D7DC64D49CA387F0DE082
|
|
|
- //addDataLen 8
|
|
|
- memset(sreBuffer,0,sizeof(sreBuffer));
|
|
|
- unpack_((char*)buffOut,sreBuffer,lenOut);
|
|
|
- memset(destInfo,0,sizeof(EnDecryptInfo));
|
|
|
- memcpy(destInfo->data,sreBuffer,lenOut*2);
|
|
|
- destInfo->dwSize = lenOut*2;
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::MacEncrypt(EnDecryptInfo srcInfo, EnDecryptInfo &destInfo)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- LOG4VTM(INFO,"enter CGrgPinPadImpl::MacEncrypt");
|
|
|
- memset(&destInfo,0,sizeof(destInfo));
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
- if(srcInfo.data==NULL||srcInfo.dwSize<1)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_Param,Error_Param,"srcInfo.data==NULL||srcInfo.dwSize<1",__FUNCTION__,__LINE__);
|
|
|
- return Error_Param;
|
|
|
- }
|
|
|
- if(!mCreateThread())
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoDefine,Error_NoDefine,"mCreateThread Error",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoDefine;
|
|
|
- }
|
|
|
-
|
|
|
- std::string str = "MacEncrypt dataLEn:"+int2str(srcInfo.dwSize);
|
|
|
-
|
|
|
- LOG4VTM(INFO,str);
|
|
|
-
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
-
|
|
|
- BYTE mode = 0x04;
|
|
|
- if(m_eMacAlgorithm == EPP_MAC_ALGO_ASNIX99)
|
|
|
- {
|
|
|
- mode = 0x04;
|
|
|
- }else if(m_eEcbCbcMode == EPP_MAC_ALGO_PBOC)
|
|
|
- {
|
|
|
- return Error_NotImpl;
|
|
|
- }else if(m_eEcbCbcMode == EPP_PIN_ALGO_ISO9564_1_ANSI)
|
|
|
- {
|
|
|
- mode = 0x08;
|
|
|
- }else
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NotImpl,Error_NotImpl," err EncryptData out",__FUNCTION__,__LINE__);
|
|
|
- return Error_NotImpl;
|
|
|
- }
|
|
|
-
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- l_apcRet.m_p1 = &mode;
|
|
|
- l_apcRet.m_p2 = &srcInfo;
|
|
|
- l_apcRet.m_p3 = &destInfo;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- if(CreateRunThread()!=Error_Succeed)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoTarget,Error_NoTarget," err CreateRunThread",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
- l_apcRet.m_iReturn = -1;
|
|
|
- APCSyncCall(EncryptDataWrapper,&l_apcRet);
|
|
|
- //QueueUserAPC(EncryptDataWrapper,m_hTimerManagerThread,(DWORD)&l_apcRet);
|
|
|
- //WaitForSingleObject(l_apcRet.m_hEvent,INFINITE);
|
|
|
-// CloseRunThread();
|
|
|
- //int ret = m_EppDll->iCrypt((char*)m_ActiveWkKey.c_str(),mode,"SV1",pInitData,strlen(pInitData),(char*)srcInfo.data,srcInfo.dwSize,(char*)buffOut,lenOut,DevRetInfo);
|
|
|
- if(l_apcRet.m_iReturn!=0)
|
|
|
- {
|
|
|
- UpdatalastErr(DevRetInfo[0].iLogicCode,DevRetInfo[0].iPhyCode,"EncryptData::iCrypt Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_Exception;
|
|
|
- }
|
|
|
- std::string str2 = "return MacEncrypt destInfo dataLEn:"+int2str(destInfo.dwSize);
|
|
|
- LOG4VTM(INFO,(str2));
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::MacEncrypt success");
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-int CGrgPinPadImpl::GetEncryptFunc()
|
|
|
-{
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
- return 0x03;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::GetDevCategory(DevCategoryInfo &devCategory)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- LOG4VTM(INFO,"Enter CGrgPinPadImpl::GetDevCategory");
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
-
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- l_apcRet.m_p1 = &devCategory;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- if(CreateRunThread()!=Error_Succeed)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoTarget,Error_NoTarget,"CreateRunThread error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
- l_apcRet.m_iReturn = -1;
|
|
|
- APCSyncCall(GetDevCategoryWrapper,&l_apcRet);
|
|
|
-
|
|
|
- if(l_apcRet.m_iReturn!=0)
|
|
|
- {
|
|
|
- UpdatalastErr(DevRetInfo[0].iLogicCode,DevRetInfo[0].iPhyCode,"GetDevCategory::GetDevCategory Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_Exception;
|
|
|
- }
|
|
|
- if(nIsConnecting)
|
|
|
- {
|
|
|
- devCategory.eState = DEVICE_STATUS_CONNECTING;
|
|
|
- }else
|
|
|
- {
|
|
|
- devCategory.eState = DEVICE_STATUS_NOT_READY;
|
|
|
- }
|
|
|
- //char *pMode= "PM=V2.0#PID=3445345345345";
|
|
|
-
|
|
|
- //memcpy(devCategory.szModel,version,strlen(version));
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::GetDevCategory secc");
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-void CALLBACK CGrgPinPadImpl::GetDevCategoryWrapper(void* dwPARAM)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- PAPCReturn pAPCRet = (PAPCReturn)dwPARAM;
|
|
|
- CGrgPinPadImpl *pPinPad = (CGrgPinPadImpl*)(pAPCRet->m_Object);
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
-
|
|
|
- DevCategoryInfo* devCategory = (DevCategoryInfo*)pAPCRet->m_p1;
|
|
|
- memset(devCategory, 0, sizeof(DevCategoryInfo));
|
|
|
-
|
|
|
- char version[100] = {0};
|
|
|
- LOG4VTM(INFO,"Before iGetDevInfo");
|
|
|
- int ret = pPinPad->m_EppDll->iGetDevInfo(version,DevRetInfo);
|
|
|
- LOG4VTM(INFO,"After iGetDevInfo");
|
|
|
- if (ret==0)
|
|
|
- {
|
|
|
- const char *pMode= "PM=V2.0#PID=";
|
|
|
- //bhj
|
|
|
- std::string strversion;
|
|
|
- std::string mid_info;
|
|
|
- strversion = version;
|
|
|
- LOG4VTM(INFO,strversion.c_str());
|
|
|
- int nPos = strversion.find(";");
|
|
|
- int lnpos = strversion.find_last_of(";");
|
|
|
- mid_info = strversion.substr(nPos+1,lnpos-nPos-1);
|
|
|
- LOG4VTM(INFO,mid_info.c_str());
|
|
|
- if(nPos != -1)
|
|
|
- {
|
|
|
- strversion = strversion.substr(nPos+1, strversion.size());
|
|
|
- nPos = strversion.find(";");
|
|
|
- if(nPos != -1)
|
|
|
- {
|
|
|
- strversion = strversion.substr(nPos+1, strversion.size());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- memcpy(devCategory->szModel,pMode,strlen(pMode));
|
|
|
- strcat(devCategory->szModel,strversion.c_str());
|
|
|
-
|
|
|
-
|
|
|
- std::string mid;
|
|
|
- std::string fmid;
|
|
|
- mid = "#MID=";
|
|
|
- fmid = "#FMID=";
|
|
|
- mid.append(strversion.c_str());
|
|
|
- fmid.append(mid_info.c_str());
|
|
|
- strcat(devCategory->szModel,mid.c_str());
|
|
|
- strcat(devCategory->szModel,fmid.c_str());
|
|
|
-
|
|
|
- const char *pType = "CMB.PinPad.Grg-EPP-004A";
|
|
|
-
|
|
|
- const char *pVendor= "grg";
|
|
|
- memcpy(devCategory->szType,pType,strlen(pType));
|
|
|
-
|
|
|
- memcpy(devCategory->szVendor,pVendor,strlen(pVendor));
|
|
|
-
|
|
|
- devCategory->version.wMajor = 1;
|
|
|
- devCategory->version.wMinor = 1;
|
|
|
- devCategory->version.wRevision = 65535;
|
|
|
- devCategory->version.wBuild = 1;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::Reset()
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::Reset");
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- if(!mCreateThread())
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoDefine,Error_NoDefine,"mCreateThread Error",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoDefine;
|
|
|
- }
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- if(CreateRunThread()!=Error_Succeed)
|
|
|
- {
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
- l_apcRet.m_iReturn = -1;
|
|
|
- APCSyncCall(ResetWrapper,&l_apcRet);
|
|
|
- //QueueUserAPC(DevCloseWrapper,m_hTimerManagerThread,(DWORD)&l_apcRet);
|
|
|
- //WaitForSingleObject(l_apcRet.m_hEvent,INFINITE);
|
|
|
-// CloseRunThread();
|
|
|
- if(l_apcRet.m_iReturn!=0)
|
|
|
- {
|
|
|
- UpdatalastErr(DevRetInfo[0].iLogicCode,DevRetInfo[0].iPhyCode,"Reset::iInit",__FUNCTION__,__LINE__);
|
|
|
- return Error_Exception;
|
|
|
- }
|
|
|
- Sleep(1000);
|
|
|
- ErrorCodeEnum openRet = DevOpen(0,0);
|
|
|
- if(openRet!=Error_Succeed)
|
|
|
- {
|
|
|
- return openRet;
|
|
|
- }
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::Reset Succeed");
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-void CALLBACK CGrgPinPadImpl::ResetWrapper(void* dwPARAM)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- PAPCReturn pAPCRet = (PAPCReturn)dwPARAM;
|
|
|
- CGrgPinPadImpl *pPinPad = (CGrgPinPadImpl*)(pAPCRet->m_Object);
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
-
|
|
|
- int ret = pPinPad->m_EppDll->iInit(DevRetInfo);
|
|
|
-
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
-}
|
|
|
-
|
|
|
-bool CGrgPinPadImpl::mCreateThread()
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- /*if (NULL == m_hTimerManagerThread)
|
|
|
- {
|
|
|
- m_hTimerManagerThread = CreateThread(NULL, 0, OnProThreadEnter, this, 0, NULL);
|
|
|
- Sleep(100);
|
|
|
- }
|
|
|
- if(m_hTimerManagerThread==NULL)return false;*/
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::DevClose()
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- LOG4VTM(INFO,"Enter CGrgPinPadImpl::DevClose");
|
|
|
- if(!nIsConnecting)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_DevNotAvailable,Error_DevNotAvailable,"Dev Not open!",__FUNCTION__,__LINE__);
|
|
|
- LOG4VTM(INFO,"Dev Not open!");
|
|
|
- return Error_DevNotAvailable;
|
|
|
- }
|
|
|
- //m_CUserIoDll.Open(m_PinPadDllPath,0,0);
|
|
|
-// m_CUserIoDll.SetLightStatus(20,3,0);
|
|
|
-// m_CUserIoDll.Close();
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- if(!mCreateThread()) //这里是因为线程� KILL,重新启动一个线稄1�7
|
|
|
- {
|
|
|
- UpdatalastErr(Error_NoDefine,Error_NoDefine,"mCreateThread Error",__FUNCTION__,__LINE__);
|
|
|
- return Error_NoDefine;
|
|
|
- }
|
|
|
- l_apcRet.m_iReturn = -1;
|
|
|
-
|
|
|
- APCSyncCall(DevCloseWrapper,&l_apcRet);
|
|
|
- //QueueUserAPC(DevCloseWrapper,m_hTimerManagerThread,(DWORD)&l_apcRet);
|
|
|
- //WaitForSingleObject(l_apcRet.m_hEvent,INFINITE);
|
|
|
-// CloseRunThread();
|
|
|
- int ret = l_apcRet.m_iReturn;
|
|
|
- if(ret!=0)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_Exception,ret,"CGrgPinPadImpl::DevClose Error",__FUNCTION__,__LINE__);
|
|
|
- }
|
|
|
- LOG4VTM(INFO,"CGrgPinPadImpl::DevClose Succeed");
|
|
|
- nIsConnecting = false;
|
|
|
- isPlaySound = false;
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-void CALLBACK CGrgPinPadImpl::DevCloseWrapper(void* dwPARAM)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- PAPCReturn pAPCRet = (PAPCReturn)dwPARAM;
|
|
|
- CGrgPinPadImpl *pPinPad = (CGrgPinPadImpl*)(pAPCRet->m_Object);
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- //LOG4VTM(INFO,"begin iCloseComm");
|
|
|
- int ret = pPinPad->m_EppDll->iCloseComm2();
|
|
|
- // LOG4VTM(INFO,"end iCloseComm");
|
|
|
-
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::GetLastErr(DevErrorInfo &devErrInfo)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- devErrInfo.dwErrMsgLen = m_tDevErrorInfo.dwErrMsgLen;
|
|
|
- memcpy(devErrInfo.szErrMsg,m_tDevErrorInfo.szErrMsg,m_tDevErrorInfo.dwErrMsgLen & 0xFFFF);
|
|
|
-
|
|
|
- memset(&m_tDevErrorInfo,0,sizeof(m_tDevErrorInfo));
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-void CGrgPinPadImpl::UpdataProFun(int p_iType, void* p_pData, int p_iLen)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- unsigned char val = *(unsigned char*)p_pData;
|
|
|
- if(val==0xAA)return;
|
|
|
- if(pCGrgPinPadImpl==NULL)return;
|
|
|
- switch(p_iType)
|
|
|
- {
|
|
|
- case 40000:
|
|
|
- {
|
|
|
- //string keySta= "UpdataProFun: "+int2str(val);
|
|
|
- //pCGrgPinPadImpl->LOG4VTM(INFO,LkeySta.c_str());
|
|
|
- //printf("input:%d(%c)\n",val,val);
|
|
|
- pCGrgPinPadImpl->SetDataKey(val);
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- //printf("input p_iType:%d p_iLen:%d :%d(%c)\n",p_iType,p_iLen,val,val);
|
|
|
- break;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-void CGrgPinPadImpl::SetPinDataKey(BYTE ch)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- switch(ch)
|
|
|
- {
|
|
|
- case 'P':
|
|
|
- SetKeyValue(0x1b);
|
|
|
- break;
|
|
|
- case 'L':
|
|
|
- SetKeyValue(0x08);
|
|
|
- break;
|
|
|
- case 'H':
|
|
|
- SetKeyValue(0x20);
|
|
|
- break;
|
|
|
- case 'D':
|
|
|
- SetKeyValue(0x0d);
|
|
|
- break;
|
|
|
- case 'C':
|
|
|
- SetKeyValue(0x3d);
|
|
|
- break;
|
|
|
- case 'B':
|
|
|
- SetKeyValue(0x3d);
|
|
|
- break;
|
|
|
- case '1':
|
|
|
- SetKeyValue(0x3f);
|
|
|
- break;
|
|
|
- }
|
|
|
- std::string str1 = "SetPinDataKey---m_bKeyValue:"+int2str(m_bKeyValue);
|
|
|
- LOG4VTM(INFO,(str1));
|
|
|
-
|
|
|
- //LOG4VTM(INFO,Lstr.c_str());
|
|
|
-}
|
|
|
-
|
|
|
-void CGrgPinPadImpl::SetPlainDataKey(BYTE ch)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- switch(ch)
|
|
|
- {
|
|
|
- case 'A':
|
|
|
- SetKeyValue(0x30);
|
|
|
- break;
|
|
|
- case 'E':
|
|
|
- SetKeyValue(0x31);
|
|
|
- break;
|
|
|
- case 'F':
|
|
|
- SetKeyValue(0x32);
|
|
|
- break;
|
|
|
- case 'G':
|
|
|
- SetKeyValue(0x33);
|
|
|
- break;
|
|
|
- case 'I':
|
|
|
- SetKeyValue(0x34);
|
|
|
- break;
|
|
|
- case 'J':
|
|
|
- SetKeyValue(0x35);
|
|
|
- break;
|
|
|
- case 'K':
|
|
|
- SetKeyValue(0x36);
|
|
|
- break;
|
|
|
- case 'M':
|
|
|
- SetKeyValue(0x37);
|
|
|
- break;
|
|
|
- case 'N':
|
|
|
- SetKeyValue(0x38);
|
|
|
- break;
|
|
|
- case 'O':
|
|
|
- SetKeyValue(0x39);
|
|
|
- break;
|
|
|
- case 'P':
|
|
|
- SetKeyValue(0x1b);
|
|
|
- break;
|
|
|
- case 'L':
|
|
|
- SetKeyValue(0x08);
|
|
|
- break;
|
|
|
- case 'H':
|
|
|
- SetKeyValue(0x20);
|
|
|
- break;
|
|
|
- case 'D':
|
|
|
- SetKeyValue(0x0d);
|
|
|
- break;
|
|
|
- case 'C':
|
|
|
- SetKeyValue(0x4f);
|
|
|
- break;
|
|
|
- case 'B':
|
|
|
- SetKeyValue(0x2e);
|
|
|
- break;
|
|
|
- case '1':
|
|
|
- SetKeyValue(0x2a);
|
|
|
- m_tInputPinKeySta.m_nKeyCount++;
|
|
|
- break;
|
|
|
- }
|
|
|
- std::string str1 = "SetPlainDataKey--m_bKeyValue:"+int2str(m_bKeyValue);
|
|
|
- LOG4VTM(INFO,(str1));
|
|
|
-
|
|
|
- //LOG4VTM(INFO,Lstr.c_str());
|
|
|
-}
|
|
|
-
|
|
|
-void CGrgPinPadImpl::SetDataKey(BYTE ch)
|
|
|
-{
|
|
|
- // LOG4VTM(INFO,"Rev key data: *");
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- //mPlaySound();
|
|
|
- if(m_KeyReadMode==E_PIN_MODE)
|
|
|
- {
|
|
|
- SetPinDataKey(ch);
|
|
|
- }else if(m_KeyReadMode==E_PLAIN_MODE)
|
|
|
- {
|
|
|
- SetPlainDataKey(ch);
|
|
|
- }
|
|
|
-
|
|
|
- //mPlaySound();
|
|
|
-
|
|
|
- if(0 == fork())
|
|
|
- {
|
|
|
- mPlaySound();
|
|
|
- _exit(0);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void CGrgPinPadImpl::UpdatalastErr(DWORD logicCode,DWORD phyCode,std::string msg,const char* func,int line)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- memset(&m_tDevErrorInfo,0,sizeof(m_tDevErrorInfo));
|
|
|
- std::string lCode = int2str(logicCode);
|
|
|
- std::string pCode = int2str(phyCode);
|
|
|
- std::string sline = int2str(line);
|
|
|
- //std::string msgError = "ErrCode: "+ pCode + "," + "Descprition: " + "Func:"+ func +"," + "Line:" + sline + "," + "msg:" + msg; //bhj
|
|
|
- std::string msgError = "{\"ErrCode\": "+ pCode + "," + "\"Description\": " + "\"Func:"+func+"," + "Line:" + sline + "," + "msg:" + msg + "\"}";
|
|
|
- LOG4VTM(ERROR,msgError.c_str()); //新增厂商日志输出
|
|
|
- //防止溢出
|
|
|
- if (msgError.length() > sizeof(m_tDevErrorInfo.szErrMsg))
|
|
|
- {
|
|
|
- msgError.resize(sizeof(m_tDevErrorInfo.szErrMsg));
|
|
|
- }
|
|
|
- m_tDevErrorInfo.dwErrMsgLen = msgError.length();
|
|
|
- memcpy(m_tDevErrorInfo.szErrMsg,msgError.c_str(),msgError.length());
|
|
|
-
|
|
|
-// LOG4VTM(ERROR,msgError.c_str());
|
|
|
-}
|
|
|
-
|
|
|
-void CGrgPinPadImpl::SetKeyValue(BYTE ch)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- std::unique_lock<std::mutex> lock(m_lockObj);
|
|
|
- //CGrgAutoLock lock(&m_lockObj);
|
|
|
- if(ch == 0x00)
|
|
|
- {
|
|
|
- m_keyVtr.clear();
|
|
|
- }else
|
|
|
- {
|
|
|
- m_keyVtr.push_back(ch);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::GetKeyValue(BYTE &ch)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- LOG4VTM(INFO,"start GetKeyValue");
|
|
|
- std::unique_lock<std::mutex> lock(m_lockObj);
|
|
|
- //CGrgAutoLock lock(&m_lockObj);
|
|
|
- if(m_keyVtr.size()==0)return Error_DevCommFailed;
|
|
|
- int keyVal = m_keyVtr[0];
|
|
|
- m_keyVtr.erase(m_keyVtr.begin());
|
|
|
- if(keyVal==0x00)
|
|
|
- {
|
|
|
- return Error_DevCommFailed;
|
|
|
- }
|
|
|
- ch = keyVal;
|
|
|
-
|
|
|
- //bhj
|
|
|
- m_keyVtrAll.push_back(ch);
|
|
|
-
|
|
|
- if (ch != 0x3f)
|
|
|
- {
|
|
|
- m_keyVtrAll.clear();
|
|
|
- LOG4VTM(INFO,"---- GetKeyValue m_keyVtrAll clear");
|
|
|
- }
|
|
|
-
|
|
|
- if (m_keyVtrAll.size() == 6)
|
|
|
- {
|
|
|
- //bhj
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- APCSyncCall(InputStopWrapper,&l_apcRet);
|
|
|
- if(l_apcRet.m_iReturn!=0)
|
|
|
- {
|
|
|
- UpdatalastErr(DevRetInfo[0].iLogicCode,DevRetInfo[0].iPhyCode,"StopInput Error!",__FUNCTION__,__LINE__);
|
|
|
- return Error_Exception;
|
|
|
- }
|
|
|
- m_keyVtrAll.clear();
|
|
|
- }
|
|
|
- LOG4VTM(INFO,"End GetKeyValue");
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CGrgPinPadImpl::GrgGetpinBlock(BYTE byLen)
|
|
|
-{
|
|
|
- //getPinBlock
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- LOG4VTM(INFO,"begin getPinblock!");
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- if(m_tAccountInfo.dwAccLen == 0)
|
|
|
- {
|
|
|
- UpdatalastErr(Error_Null,Error_Null,"Account is null!",__FUNCTION__,__LINE__);
|
|
|
- return Error_Null;
|
|
|
- }
|
|
|
- m_tPinBlockInfo.Init();
|
|
|
-
|
|
|
- TAPCReturn l_apcRet;
|
|
|
- memset(&l_apcRet,0x00,sizeof(l_apcRet));
|
|
|
- l_apcRet.m_Object = this;
|
|
|
- l_apcRet.m_hEvent = m_hEvent;
|
|
|
- l_apcRet.m_p1 = &byLen;
|
|
|
- ResetEvent(l_apcRet.m_hEvent);
|
|
|
- if(CreateRunThread()!=Error_Succeed)
|
|
|
- {
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
- l_apcRet.m_iReturn = -1;
|
|
|
- APCSyncCall(GetPinBlockWrapper,&l_apcRet);
|
|
|
- //QueueUserAPC(GetPinBlockWrapper,m_hTimerManagerThread,(DWORD)&l_apcRet);
|
|
|
- //WaitForSingleObject(l_apcRet.m_hEvent,INFINITE);
|
|
|
- //CloseRunThread();
|
|
|
- int rets = l_apcRet.m_iReturn;
|
|
|
- if(rets!=0)
|
|
|
- {
|
|
|
- UpdatalastErr(DevRetInfo[0].iLogicCode,DevRetInfo[0].iPhyCode,"iGetPinBlock Error",__FUNCTION__,__LINE__);
|
|
|
- return Error_Exception;
|
|
|
- }
|
|
|
-
|
|
|
- LOG4VTM(INFO,"StartPinInput and getPinblock success!");
|
|
|
-
|
|
|
- memset(&m_tAccountInfo,0,sizeof(m_tAccountInfo));
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-void CALLBACK CGrgPinPadImpl::GetPinBlockWrapper(void* dwPARAM)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- PAPCReturn pAPCRet = (PAPCReturn)dwPARAM;
|
|
|
- CGrgPinPadImpl *pPinPad = (CGrgPinPadImpl*)(pAPCRet->m_Object);
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
-
|
|
|
- std::string MsName = "MK0";
|
|
|
- char workName[8]={0};
|
|
|
- int pinBlockLen = 8;
|
|
|
- if(pPinPad->m_bActiveMsKeyNum == 0)
|
|
|
- {
|
|
|
- MsName = "MK0";
|
|
|
- pinBlockLen = 8;
|
|
|
- sprintf(workName, "W%02d", pPinPad->m_bActiveWkKeyNum);
|
|
|
- }else if(pPinPad->m_bActiveMsKeyNum == 1)
|
|
|
- {
|
|
|
- MsName = "MK1";
|
|
|
- pinBlockLen = 16;
|
|
|
- sprintf(workName, "W%02d", pPinPad->m_bActiveWkKeyNum+10);
|
|
|
- }
|
|
|
-
|
|
|
- BYTE byLen = *((BYTE*)pAPCRet->m_p1);
|
|
|
- char bufOut[128] = {0};
|
|
|
- char cPINFormat = '1';
|
|
|
- if(pPinPad->m_ePinAlgorithm == EPP_PIN_ALGO_IBM3624 || pPinPad->m_ePinAlgorithm==EPP_PIN_ALGO_SM4)
|
|
|
- {
|
|
|
- cPINFormat = '7';
|
|
|
- }if(pPinPad->m_ePinAlgorithm == EPP_PIN_ALGO_ISO9564_1_ANSI)
|
|
|
- {
|
|
|
- cPINFormat = '1';
|
|
|
- }
|
|
|
- int rets = pPinPad->m_EppDll->iGetPinBlock((char*)workName,byLen,cPINFormat,'0',(char*)pPinPad->m_tAccountInfo.account,bufOut,DevRetInfo);
|
|
|
- if(rets!=0)
|
|
|
- {
|
|
|
- pAPCRet->m_iReturn = rets;
|
|
|
-
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
- }
|
|
|
- char buff[128] = {0};
|
|
|
- unpack_(bufOut,buff,pinBlockLen);
|
|
|
- std::string str = "pinblock size:"+int2str(strlen(buff))+" len:"+int2str(pinBlockLen*2);
|
|
|
- LOG4VTM(INFO,str);
|
|
|
-
|
|
|
-// LOG4VTM(INFO,Lstr.c_str());
|
|
|
-
|
|
|
- memcpy(pPinPad->m_tPinBlockInfo.PinBlockBuff,buff,pinBlockLen*2);
|
|
|
- pPinPad->m_tPinBlockInfo.mPinBlockLen = pinBlockLen*2;
|
|
|
-
|
|
|
-
|
|
|
- pAPCRet->m_iReturn = rets;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
-}
|
|
|
-
|
|
|
-DWORD CGrgPinPadImpl::OnProThreadEnter(LPVOID lpParameter)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- /*CGrgPinPadImpl *pObj = (CGrgPinPadImpl*)lpParameter;
|
|
|
- DWORD l_dwRet = 0;
|
|
|
- while(!pObj->isRunExit)
|
|
|
- {
|
|
|
- l_dwRet = WaitForSingleObjectEx(pObj->m_eventExit,INFINITE,TRUE);
|
|
|
-
|
|
|
- if(WAIT_OBJECT_0 == l_dwRet)
|
|
|
- {
|
|
|
- ResetEvent(pObj->m_eventExit);
|
|
|
- break;
|
|
|
- }
|
|
|
- }*/
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-/*void CGrgPinPadImpl::AddThreadRunFun(ThreadRunFun fun,HANDLE han_,DWORD dwPARAM)
|
|
|
-{
|
|
|
- m_tThreadRunFunInfo.m_ThreadRunFun = fun;
|
|
|
- m_tThreadRunFunInfo.m_data = dwPARAM;
|
|
|
-}*/
|
|
|
-
|
|
|
-int CGrgPinPadImpl::strToHex(char *ch, char *hex)
|
|
|
-{
|
|
|
- int high,low;
|
|
|
- int tmp = 0;
|
|
|
- if(ch == NULL || hex == NULL){
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if(strlen(ch) == 0){
|
|
|
- return -2;
|
|
|
- }
|
|
|
-
|
|
|
- while(*ch){
|
|
|
- tmp = (int)*ch;
|
|
|
- high = tmp >> 4;
|
|
|
- low = tmp & 15;
|
|
|
- *hex++ = valueToHexCh(high); //先写高字芄1�7
|
|
|
- *hex++ = valueToHexCh(low); //其次写低字节
|
|
|
- ch++; }
|
|
|
- *hex = '\0';
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-char CGrgPinPadImpl::valueToHexCh(const int value)
|
|
|
-{
|
|
|
- char result = '\0';
|
|
|
- if(value >= 0 && value <= 9){
|
|
|
- result = (char)(value + 48); //48为ascii编码的��1�7�1�70’字符编码��1�7�1�7
|
|
|
- }
|
|
|
- else if(value >= 10 && value <= 15){
|
|
|
- result = (char)(value - 10 + 65); //减去10则找出其圄1�716进制的偏移量$1�765为ascii的1�7'A'的字符编码��1�7�1�7
|
|
|
- }
|
|
|
- else{}
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-void CGrgPinPadImpl::mPlaySound()
|
|
|
-{
|
|
|
- if(isPlaySound)
|
|
|
- {
|
|
|
- //PlaySound(LPWSTR(IDR_WAVE1), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC | SND_LOOP);
|
|
|
- // std::wstring path = m_PinPadDllPath + "keypress.wav";
|
|
|
-
|
|
|
- //std::string l_szDllFile = GetLibPath(GetSelfModuleHandle());
|
|
|
-
|
|
|
- //l_szDllFile = l_szDllFile + "/home/grg/grg/lib/grgkeypress.wav";
|
|
|
-
|
|
|
- //std::string l_szDllFile = "/home/grg/grg/lib/grgkeypress.wav"; bhj 密码键盘增加物理按键声,去除音频文件调用。
|
|
|
-
|
|
|
- //std::wstring path = s2ws(l_szDllFile);
|
|
|
- //BOOL l_bRet = sndPlaySound(path.c_str(), SND_FILENAME | SND_ASYNC);
|
|
|
- //char buff[MAX_PATH];
|
|
|
- //snprintf(buff, MAX_PATH, "aplay %s", l_szDllFile.c_str());
|
|
|
- //system(buff);
|
|
|
- //l_szDllFile = "aplay " + l_szDllFile + " > /dev/null 2>&1 ";
|
|
|
- //printf("aplay cmd:^%s$\n", l_szDllFile.c_str());
|
|
|
- //system(l_szDllFile.c_str());
|
|
|
-
|
|
|
- //PlaySound("IDR_WAVE1", GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
|
|
|
- }
|
|
|
-}
|
|
|
-/*
|
|
|
-std::wstring CGrgPinPadImpl::s2ws(const std::string& s)
|
|
|
-{
|
|
|
- int len;
|
|
|
- int slength = (int)s.length() + 1;
|
|
|
- len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
|
|
|
- wchar_t* buf = new wchar_t[len];
|
|
|
- MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
|
|
|
- std::wstring r(buf);
|
|
|
- delete[] buf;
|
|
|
- return r;
|
|
|
-}*/
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-void CALLBACK CGrgPinPadImpl::InputStopWrapper(void* dwPARAM)
|
|
|
-{
|
|
|
- LOG4VTM_FUNCTION();
|
|
|
- PAPCReturn pAPCRet = (PAPCReturn)dwPARAM;
|
|
|
- CGrgPinPadImpl *pPinPad = (CGrgPinPadImpl*)(pAPCRet->m_Object);
|
|
|
- memset(&DevRetInfo,0,sizeof(DevRetInfo));
|
|
|
- int ret = pPinPad->m_EppDll->iStopPinEntry(DevRetInfo);
|
|
|
- pAPCRet->m_iReturn = ret;
|
|
|
- SetEvent(pPinPad->m_hEvent);
|
|
|
-}
|