|
@@ -7,6 +7,9 @@
|
|
|
#include "PinPad_UserErrorCode.h"
|
|
|
#include "CommDevEntityErrorCode.h"
|
|
|
#include <map>
|
|
|
+#include <thread>
|
|
|
+#include <chrono>
|
|
|
+
|
|
|
using namespace std;
|
|
|
|
|
|
const int PINPAD_INIT_TRIES = 3;
|
|
@@ -30,13 +33,12 @@ bool isnostr(const char *str)
|
|
|
ErrorCodeEnum CPinPadFSM::OnInit()
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
- /*------2020-02-13-------*/
|
|
|
- //modify by LZM
|
|
|
- if (VendorLogControler(this,"PinPad")!=Error_Succeed)
|
|
|
+
|
|
|
{
|
|
|
- Dbg("VendorLogControler Failed...");
|
|
|
+ auto devEntity = dynamic_cast<CDevAdptEntityBase*>(GetEntityBase());
|
|
|
+ devEntity->InitializeVendorLogSwitch();
|
|
|
}
|
|
|
- /*-----------------------*/
|
|
|
+
|
|
|
CSystemStaticInfo sysInfo;
|
|
|
|
|
|
m_csMachineType = m_csSite = m_terminalNo = "";
|
|
@@ -50,30 +52,9 @@ ErrorCodeEnum CPinPadFSM::OnInit()
|
|
|
m_bPinPadNeedless = TRUE;
|
|
|
if (_strnicmp((const char*)m_csMachineType, "RVC.IL", strlen("RVC.IL")) == 0)
|
|
|
m_bRVCIL = true;
|
|
|
- CEntityStaticInfo esi = {0};
|
|
|
- ErrorCodeEnum ec = GetEntityBase()->GetFunction()->GetEntityStaticInfo(
|
|
|
- GetEntityBase()->GetEntityName(), esi);
|
|
|
- if(ec == Error_Succeed)
|
|
|
- {
|
|
|
- Dbg("wEntityDevelopID: 0x%X", esi.wEntityDevelopID);
|
|
|
- HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, esi.wEntityDevelopID);
|
|
|
- }
|
|
|
|
|
|
- //CEntityRunInfo eri = {0};
|
|
|
- //ec = GetEntityBase()->GetFunction()->GetSelfEntityRunInfo(eri);
|
|
|
- //if(ec == Error_Succeed)
|
|
|
- //{
|
|
|
- // Dbg("dwEntityInstanceID: 0x%X", eri.dwEntityInstanceID);
|
|
|
- //}
|
|
|
-
|
|
|
- m_hInputEvt = CreateEventA(NULL,FALSE,FALSE,NULL);
|
|
|
- if (m_hInputEvt == NULL)
|
|
|
- {
|
|
|
- Dbg("CreateEvent failed(%d).",GetLastError());
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, AlarmDEC(MEC_CREATE_EVENT_FAILED), "OnInit:CreateEventA failed.");
|
|
|
- return Error_Resource;
|
|
|
- }
|
|
|
- _beginthreadex(NULL,0,DoWork,(void*)this,0,NULL);
|
|
|
+ std::thread tmp_thread(&CPinPadFSM::DoWork, this);
|
|
|
+ tmp_thread.detach();
|
|
|
|
|
|
return Error_Succeed;
|
|
|
}
|
|
@@ -81,18 +62,13 @@ ErrorCodeEnum CPinPadFSM::OnExit()
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
m_bEntityExit = true;
|
|
|
- SetEvent(m_hInputEvt);
|
|
|
+ //SetEvent(m_hInputEvt);
|
|
|
+ m_hInputConVar.Broadcast();
|
|
|
ErrorCodeEnum eErr = Error_Succeed;
|
|
|
- if (m_pPinPad != NULL)
|
|
|
+ if (m_hDevHelper)
|
|
|
{
|
|
|
- m_pPinPad->StopInput();
|
|
|
- eErr = ReleaseDevComponent((DeviceBaseClass*&)m_pPinPad);
|
|
|
- if (eErr != Error_Succeed)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, AlarmDECToBusiness(MEC_DEV_OBJECT_RELEASE_FAILED), "OnExit:ReleaseDevComponent failed.");
|
|
|
- Dbg("ReleaseDevComponent failed(%d).",eErr);
|
|
|
- }
|
|
|
- m_pPinPad = NULL;
|
|
|
+ m_hDevHelper->StopInput();
|
|
|
+ m_hDevHelper.TearDown();
|
|
|
}
|
|
|
return eErr;
|
|
|
}
|
|
@@ -109,7 +85,8 @@ unsigned int CPinPadFSM::s0_on_event(FSMEvent* evt)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
if (evt->iEvt == USER_EVT_INIT) {
|
|
|
- SetEvent(m_hInputEvt);
|
|
|
+ //SetEvent(m_hInputEvt);
|
|
|
+ m_hInputConVar.Broadcast();
|
|
|
evt->SetHandled();
|
|
|
return 0;
|
|
|
}else if (evt->iEvt == USER_EVT_QUIT) {
|
|
@@ -178,7 +155,8 @@ unsigned int CPinPadFSM::s2_on_event(FSMEvent* pEvt)
|
|
|
{
|
|
|
case USER_EVT_GETINPUT:
|
|
|
{
|
|
|
- SetEvent(m_hInputEvt);
|
|
|
+ //SetEvent(m_hInputEvt);
|
|
|
+ m_hInputConVar.Broadcast();
|
|
|
pEvt->SetHandled();
|
|
|
return 0;
|
|
|
}
|
|
@@ -220,7 +198,8 @@ unsigned int CPinPadFSM::s2_on_event(FSMEvent* pEvt)
|
|
|
}
|
|
|
case USER_EVT_GETINPUT_SM:
|
|
|
{
|
|
|
- SetEvent(m_hInputEvt);
|
|
|
+ //SetEvent(m_hInputEvt);
|
|
|
+ m_hInputConVar.Broadcast();
|
|
|
pEvt->SetHandled();
|
|
|
return 0;
|
|
|
}
|
|
@@ -394,8 +373,10 @@ int CPinPadFSM::Initial()
|
|
|
Dbg("is RVC.IL.");
|
|
|
return 0;
|
|
|
}
|
|
|
+#ifdef _WIN32
|
|
|
DWORD dwCurrThId = GetCurrentThreadId();
|
|
|
- Dbg("Initial thread id:%d",dwCurrThId);
|
|
|
+ Dbg("Initial thread id:%d", dwCurrThId);
|
|
|
+#endif //_WIN32
|
|
|
ErrorCodeEnum eErrDev;
|
|
|
|
|
|
CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
|
|
@@ -408,7 +389,7 @@ int CPinPadFSM::Initial()
|
|
|
}
|
|
|
|
|
|
|
|
|
- CSimpleStringA dllName,tmpVendor(""), tmpDevSN(""), tmpDLLVersion(""), csDepPath(""), csBackslash("\\");
|
|
|
+ CSimpleStringA dllName,tmpVendor(""), tmpDevSN(""), tmpDLLVersion(""), csDepPath(""), csBackslash(SPLIT_SLASH_STR);
|
|
|
GetEntityBase()->GetFunction()->GetSysVar("FWBVendor", tmpVendor);
|
|
|
GetEntityBase()->GetFunction()->GetSysVar("FWBDevSN", tmpDevSN);
|
|
|
GetEntityBase()->GetFunction()->GetSysVar("FWBVersion", tmpDLLVersion);
|
|
@@ -418,21 +399,28 @@ int CPinPadFSM::Initial()
|
|
|
{
|
|
|
Dbg("This is fwb device.");
|
|
|
GetEntityBase()->GetFunction()->GetPath("Dep", csDepPath);
|
|
|
+#ifdef _WIN32
|
|
|
dllName = csDepPath + csBackslash + "PinPad." + tmpVendor + "." + tmpDLLVersion + ".dll";//oiltmp
|
|
|
+#else
|
|
|
+ dllName = csDepPath + csBackslash + "libPinPad." + tmpVendor + "." + tmpDLLVersion + ".so";
|
|
|
+#endif //_WIN32
|
|
|
Dbg("%s", (const char*)dllName);
|
|
|
HARDWARE_ENTITY_SET_VENDOR_NAME(m_entCode, tmpVendor);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Dbg("This is normal AllInOne device.");
|
|
|
- eErrDev = SpGetDevAdaptorPath(m_pEntity, GetEntityBase()->GetEntityName(), dllName);
|
|
|
- if (eErrDev != Error_Succeed)
|
|
|
- {
|
|
|
- Dbg("SpGetDevAdaptorPath(%d) failed.", eErrDev);
|
|
|
- LogWarn(Severity_Middle, eErrDev, AlarmDEC(MEC_DLL_GET_PATH_FAILED), "Initial:SpGetDevAdaptorPath");
|
|
|
- return Error_DevLoadFileFailed;
|
|
|
- }
|
|
|
- Dbg("%s", (LPCTSTR)dllName);
|
|
|
+ auto pEntity = GET_DEV_ENTITY_BASE_POINTER();
|
|
|
+ pEntity->ExtractVendorLibFullPath(dllName);
|
|
|
+
|
|
|
+ //eErrDev = SpGetDevAdaptorPath(m_pEntity, GetEntityBase()->GetEntityName(), dllName);
|
|
|
+ //if (eErrDev != Error_Succeed)
|
|
|
+ //{
|
|
|
+ // Dbg("SpGetDevAdaptorPath(%d) failed.", eErrDev);
|
|
|
+ // LogWarn(Severity_Middle, eErrDev, AlarmDECToBusiness(MEC_DLL_GET_PATH_FAILED), "Initial:SpGetDevAdaptorPath");
|
|
|
+ // return Error_DevLoadFileFailed;
|
|
|
+ //}
|
|
|
+ //Dbg("%s", (LPCTSTR)dllName);
|
|
|
|
|
|
CSimpleStringA strSection = CSimpleStringA("Device.") + GetEntityBase()->GetEntityName();
|
|
|
CSimpleStringA str;
|
|
@@ -446,48 +434,12 @@ int CPinPadFSM::Initial()
|
|
|
spConfig->ReadConfigValueInt("Device.PinPad", "Port", port);
|
|
|
spConfig->ReadConfigValue("Terminal", "TerminalNo", m_deviceNo);
|
|
|
spConfig->ReadConfigValue("Device.PinPad", "Checkdata", m_devCheckData);
|
|
|
- spConfig->ReadConfigValue("Device.PinPad", "Keysn", m_keySN);
|
|
|
- spConfig->ReadConfigValue("Device.PinPad", "KeysnSM", m_keySNSM);
|
|
|
+ //spConfig->ReadConfigValue("Device.PinPad", "Keysn", m_keySN);
|
|
|
+ //spConfig->ReadConfigValue("Device.PinPad", "KeysnSM", m_keySNSM);
|
|
|
Dbg("to load vendor dll.");
|
|
|
- //ErrorCodeEnum Error;
|
|
|
- //CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
|
|
|
- //CSmartPointer<IConfigInfo> spConfig;
|
|
|
- //Error = spEntityFunction->OpenConfig(Config_Root, spConfig);
|
|
|
- //if (Error != Error_Succeed) {
|
|
|
- // LOG_TRACE("open cfg file failed!");
|
|
|
- // return Error;
|
|
|
- //}
|
|
|
- //CSimpleStringA dllName,devName,devVendor,devVer,devBatch,dllSuffix;
|
|
|
- //dllName = devName = "PinPad";
|
|
|
- //dllSuffix = ".dll";
|
|
|
- //devVendor = devVer = devBatch = "";
|
|
|
- //spConfig->ReadConfigValue("Device.PinPad","Vendor",devVendor);
|
|
|
- //spConfig->ReadConfigValue("Device.PinPad","Version",devVer);
|
|
|
- //spConfig->ReadConfigValue("Device.PinPad","Batch",devBatch);
|
|
|
-
|
|
|
- //Dbg("[%s],[%s],[%s]",(LPCSTR)devVendor,(LPCSTR)devVer,(LPCSTR)devBatch);
|
|
|
- //CSimpleStringA csDepPath,csBackslash("\\");
|
|
|
- //ErrorCodeEnum eErrDep = GetEntityBase()->GetFunction()->GetPath("Dep", csDepPath);
|
|
|
- //if (eErrDep != Error_Succeed)
|
|
|
- //{
|
|
|
- // Dbg("GetBasePath failed (%d).",eErrDep);
|
|
|
- // return Error_Param;
|
|
|
- //}
|
|
|
- //dllName = csDepPath + csBackslash + dllName;
|
|
|
- //if (!isnostr(devVendor.GetData()))
|
|
|
- // dllName = dllName + "." + devVendor;
|
|
|
- //if (!isnostr(devVer.GetData()))
|
|
|
- // dllName = dllName + "." + devVer;
|
|
|
- //if (!isnostr(devBatch.GetData()))
|
|
|
- // dllName = dllName + "." + devBatch;
|
|
|
- //dllName += dllSuffix;
|
|
|
- //Dbg("dllName:[%s]",dllName);
|
|
|
- m_hVerdorDll = LoadLibraryA(dllName);
|
|
|
- if (m_hVerdorDll == NULL)
|
|
|
- {
|
|
|
- Dbg("load %s failed(%d).",(const char*)dllName,GetLastError());
|
|
|
- if(!m_bPinPadNeedless)
|
|
|
- {
|
|
|
+ if (Error_Succeed != m_hDevHelper.LoadLibAddress(dllName)) {
|
|
|
+ Dbg("load %s failed.", (const char*)dllName);
|
|
|
+ if (!m_bPinPadNeedless) {
|
|
|
if (tmpDevSN.GetLength() < 10 || tmpDevSN.IndexOf("FWB") < 1)
|
|
|
GetEntityBase()->GetFunction()->ShowFatalError("密码键盘加载厂商适配器失败!请检查root.ini配置是否正确。");
|
|
|
//LogWarn(Severity_Middle,Error_NotInit,LOG_ERR_PINPAD_FAILED,"PinPad init failed.");
|
|
@@ -495,35 +447,20 @@ int CPinPadFSM::Initial()
|
|
|
}
|
|
|
return Error_DevLoadFileFailed;
|
|
|
}
|
|
|
+
|
|
|
Dbg("load vendor dll suc.");
|
|
|
//MAKEINTRESOURCE
|
|
|
|
|
|
- if ((CreateDevComponent = (lpCreateDevCom)GetProcAddress(m_hVerdorDll,"CreateDevComponent")) == NULL)
|
|
|
- {
|
|
|
- //char * xx = MAKEINTRESOURCE(1);
|
|
|
- DWORD dwErr = GetLastError();
|
|
|
- Dbg("Get CreateDevComponent failed(%d).",dwErr);
|
|
|
- //LogWarn(Severity_Middle,Error_NotInit,LOG_ERR_PINPAD_FAILED,"PinPad init failed.");
|
|
|
- LogWarn(Severity_Middle,Error_NotInit, AlarmDEC(MEC_DEV_GET_CDC_ADDR_FAILED), "PinPad init failed.");
|
|
|
- return Error_DevLoadFileFailed;
|
|
|
- }
|
|
|
- if ((ReleaseDevComponent = (lpReleaseDevCom)GetProcAddress(m_hVerdorDll,"ReleaseDevComponent")) == NULL)
|
|
|
- {
|
|
|
- Dbg("Get ReleaseDevComponent failed.");
|
|
|
- LogWarn(Severity_Middle, Error_NotInit, AlarmDEC(MEC_DEV_GET_RDC_ADDR_FAILED), "PinPad init failed.");
|
|
|
- return Error_DevLoadFileFailed;
|
|
|
- }
|
|
|
int initTries = 0;
|
|
|
ErrorCodeEnum hr;
|
|
|
ErrorCodeEnum eErrCode;
|
|
|
do
|
|
|
{
|
|
|
Dbg("dodo");
|
|
|
- if (m_pPinPad == NULL)
|
|
|
- {
|
|
|
- if (CreateDevComponent((DeviceBaseClass *&)m_pPinPad) != Error_Succeed)
|
|
|
- {
|
|
|
- Dbg("create pinpad module failed.");
|
|
|
+ if (!m_hDevHelper) {
|
|
|
+ eErrCode = m_hDevHelper.CreateDevAdptObject();
|
|
|
+ if(eErrCode != Error_Succeed) {
|
|
|
+ Dbg("create pinpad module failed %s", SpStrError(eErrCode));
|
|
|
LogWarn(Severity_Middle, eErrDev, AlarmDEC(MEC_DEV_OBJECT_CREATE_FAILED), "Initial:CreateDevComponent");
|
|
|
initTries++;
|
|
|
continue;
|
|
@@ -533,16 +470,16 @@ int CPinPadFSM::Initial()
|
|
|
|
|
|
|
|
|
Dbg("%d,%d",port,baudRate);
|
|
|
- hr = m_pPinPad->DevOpen(port,baudRate);
|
|
|
+ hr = m_hDevHelper->DevOpen(port,baudRate);
|
|
|
|
|
|
if (hr == Error_Succeed)
|
|
|
{
|
|
|
initTries = 0;
|
|
|
ErrorCodeEnum errCode1,errCode2,errCode3,errCode4;
|
|
|
- errCode1 = m_pPinPad->SetParam(EPP_PT_SET_ENCRYPT_METHOD,EPP_ALGO_METHOD_3DES);
|
|
|
- errCode2 = m_pPinPad->SetParam(EPP_PT_SET_MAC_ALGORITH,EPP_MAC_ALGO_ASNIX99);
|
|
|
- errCode3 = m_pPinPad->SetParam(EPP_PT_SET_PIN_ALGORITH,EPP_PIN_ALGO_ISO9564_1_ANSI);
|
|
|
- errCode4 = m_pPinPad->SetParam(EPP_PT_SET_ECB_CBC_MODE,EPP_ALGO_MODE_3DEC_CBC);
|
|
|
+ errCode1 = m_hDevHelper->SetParam(EPP_PT_SET_ENCRYPT_METHOD,EPP_ALGO_METHOD_3DES);
|
|
|
+ errCode2 = m_hDevHelper->SetParam(EPP_PT_SET_MAC_ALGORITH,EPP_MAC_ALGO_ASNIX99);
|
|
|
+ errCode3 = m_hDevHelper->SetParam(EPP_PT_SET_PIN_ALGORITH,EPP_PIN_ALGO_ISO9564_1_ANSI);
|
|
|
+ errCode4 = m_hDevHelper->SetParam(EPP_PT_SET_ECB_CBC_MODE,EPP_ALGO_MODE_3DEC_CBC);
|
|
|
if(errCode1 != Error_Succeed || errCode2 != Error_Succeed
|
|
|
|| errCode3 != Error_Succeed || errCode4 != Error_Succeed)
|
|
|
{
|
|
@@ -568,15 +505,13 @@ int CPinPadFSM::Initial()
|
|
|
Dbg("Open pinpad failed.%s",(const char*)tmpDevSN);
|
|
|
if (tmpDevSN.GetLength() < 10 || tmpDevSN.IndexOf("FWB") < 1)
|
|
|
GetEntityBase()->GetFunction()->ShowFatalError("密码键盘打开失败!请检查键盘是否连接,配置是否正确。");
|
|
|
- //LogWarn(Severity_Middle,Error_NotInit,LOG_ERR_PINPAD_FAILED,"PinPad init failed.");
|
|
|
- //LogWarn(Severity_Middle,Error_NotInit,AlarmDECToBusiness(),"PinPad init failed.");
|
|
|
return 1;
|
|
|
}
|
|
|
m_bDevInit = true;
|
|
|
LOG_TRACE("Open pinpad suc.");
|
|
|
//oiltmp comment the following 20160406
|
|
|
//update with the version 1.7.1
|
|
|
- m_encryptkey = m_pPinPad->GetEncryptFunc();
|
|
|
+ m_encryptkey = m_hDevHelper->GetEncryptFunc();
|
|
|
//m_encryptkey = 1;
|
|
|
eErrDev = spEntityFunction->OpenConfig(Config_Run, spConfig);
|
|
|
if (eErrDev != Error_Succeed)
|
|
@@ -595,13 +530,16 @@ int CPinPadFSM::Initial()
|
|
|
eErrDev = spConfig->ReadConfigValueInt("Load", "SM", tmpLoad);
|
|
|
if (eErrDev == Error_Succeed)
|
|
|
m_bSMLoaded = tmpLoad;
|
|
|
+ //oilyang@20201026 from kmc micro service
|
|
|
+ spConfig->ReadConfigValue("Load", "SN_3DES", m_keySN);
|
|
|
+ spConfig->ReadConfigValue("Load", "SN_SM", m_keySNSM);
|
|
|
}
|
|
|
Dbg("encrypt key :%d,load key :%d,%d", m_encryptkey,m_b3DESLoaded,m_bSMLoaded);
|
|
|
DevCategoryInfo devInfo;
|
|
|
ZeroMemory(devInfo.szModel, MAX_DEV_MODEL_LEN);
|
|
|
ZeroMemory(devInfo.szType, MAX_DEV_TYPE_LEN);
|
|
|
ZeroMemory(devInfo.szVendor, MAX_DEV_VENDOR_LEN);
|
|
|
- eErrDev = m_pPinPad->GetDevCategory(devInfo);
|
|
|
+ eErrDev = m_hDevHelper->GetDevCategory(devInfo);
|
|
|
if (eErrDev == Error_Succeed)
|
|
|
{
|
|
|
m_szModel = devInfo.szModel;
|
|
@@ -616,19 +554,22 @@ int CPinPadFSM::Initial()
|
|
|
Dbg("model:%s,type:%s,vendor:%s", (const char*)m_szModel, (const char*)m_szType, (const char*)m_szVendor);
|
|
|
return 0;
|
|
|
}
|
|
|
-unsigned int __stdcall DoWork(void *pData)
|
|
|
+
|
|
|
+void CPinPadFSM::DoWork()
|
|
|
{
|
|
|
+ LOG_FUNCTION();
|
|
|
while(1)
|
|
|
{
|
|
|
- CPinPadFSM *pFsm = (CPinPadFSM*)pData;
|
|
|
- WaitForSingleObject(pFsm->GetInputEvtHandle(),INFINITE);
|
|
|
- if (pFsm->GetEntityExit())
|
|
|
+ //std::this_thread::sleep_for(std::chrono::milliseconds(60 * 1000));
|
|
|
+ this->m_hInputConVar.Wait();
|
|
|
+ //WaitForSingleObject(this->GetInputEvtHandle(),INFINITE);
|
|
|
+ if (this->GetEntityExit())
|
|
|
break;
|
|
|
FSMEvent *evt;
|
|
|
int ret;
|
|
|
- if (!pFsm->GetDevInitFlag())
|
|
|
+ if (!this->GetDevInitFlag())
|
|
|
{
|
|
|
- ret = pFsm->Initial();
|
|
|
+ ret = this->Initial();
|
|
|
evt = new FSMEvent(USER_EVT_INITFINISHED);
|
|
|
}
|
|
|
else
|
|
@@ -637,14 +578,14 @@ unsigned int __stdcall DoWork(void *pData)
|
|
|
SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx;
|
|
|
SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM;
|
|
|
bool smFlag = false;
|
|
|
- bool bRet = pFsm->GetCtx(ctx,ctxSM,smFlag);
|
|
|
+ bool bRet = this->GetCtx(ctx,ctxSM,smFlag);
|
|
|
Dbg("sm ctx or not[%d]",smFlag);
|
|
|
if (!bRet)
|
|
|
{
|
|
|
Dbg("get ctx failed.doing nothing");
|
|
|
continue;
|
|
|
}
|
|
|
- ret = pFsm->GetInput(ctx,ctxSM,smFlag);
|
|
|
+ ret = this->GetInput(ctx,ctxSM,smFlag);
|
|
|
evt = new FSMEvent(USER_EVT_GETINPUTFINISHED);
|
|
|
Dbg("getinput in thread end");
|
|
|
}
|
|
@@ -652,10 +593,10 @@ unsigned int __stdcall DoWork(void *pData)
|
|
|
evt->param1 = 0;
|
|
|
else
|
|
|
evt->param1 = 1;
|
|
|
- pFsm->PostEventFIFO(evt);
|
|
|
+ this->PostEventFIFO(evt);
|
|
|
}
|
|
|
- _endthreadex(0);
|
|
|
- return 0;
|
|
|
+
|
|
|
+ return;
|
|
|
}
|
|
|
static char hexCh2decCh(char c)
|
|
|
{
|
|
@@ -852,7 +793,7 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
//memcpy(accInfo.account,"588571006555",12);
|
|
|
accInfo.dwAccLen = 12;
|
|
|
Dbg("acc(%s)",accInfo.account);
|
|
|
- errCode = m_pPinPad->SetAccNo(accInfo);
|
|
|
+ errCode = m_hDevHelper->SetAccNo(accInfo);
|
|
|
if (errCode != Error_Succeed)
|
|
|
{
|
|
|
if (!bSM)
|
|
@@ -863,9 +804,9 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
return Error_DevCommFailed;
|
|
|
}
|
|
|
if (!bSMFlag)
|
|
|
- errCode = m_pPinPad->ActiveWorkingKey(0,0);
|
|
|
+ errCode = m_hDevHelper->ActiveWorkingKey(0,0);
|
|
|
else
|
|
|
- errCode = m_pPinPad->ActiveWorkingKey(1,0);
|
|
|
+ errCode = m_hDevHelper->ActiveWorkingKey(1,0);
|
|
|
if (errCode != Error_Succeed)
|
|
|
{
|
|
|
LOG_PINPAD_ERROR_MSG_MACRO(errCode, ActiveWorkingKey);
|
|
@@ -874,13 +815,13 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
}
|
|
|
if (!bSMFlag)
|
|
|
{
|
|
|
- //errCode = m_pPinPad->SetParam(EPP_PT_SET_ENCRYPT_METHOD, EPP_ALGO_METHOD_3DES);
|
|
|
- errCode = m_pPinPad->SetParam(EPP_PT_SET_PIN_ALGORITH, EPP_PIN_ALGO_ISO9564_1_ANSI);
|
|
|
+ //errCode = m_hDevHelper->SetParam(EPP_PT_SET_ENCRYPT_METHOD, EPP_ALGO_METHOD_3DES);
|
|
|
+ errCode = m_hDevHelper->SetParam(EPP_PT_SET_PIN_ALGORITH, EPP_PIN_ALGO_ISO9564_1_ANSI);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //errCode = m_pPinPad->SetParam(EPP_PT_SET_ENCRYPT_METHOD, EPP_ALGO_METHOD_SM4);
|
|
|
- errCode = m_pPinPad->SetParam(EPP_PT_SET_PIN_ALGORITH, EPP_PIN_ALGO_SM4);
|
|
|
+ //errCode = m_hDevHelper->SetParam(EPP_PT_SET_ENCRYPT_METHOD, EPP_ALGO_METHOD_SM4);
|
|
|
+ errCode = m_hDevHelper->SetParam(EPP_PT_SET_PIN_ALGORITH, EPP_PIN_ALGO_SM4);
|
|
|
}
|
|
|
if (errCode != Error_Succeed)
|
|
|
{
|
|
@@ -889,7 +830,7 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
return Error_DevCommFailed;
|
|
|
}
|
|
|
Dbg("to start");
|
|
|
- errCode = m_pPinPad->StartPinInput(len);
|
|
|
+ errCode = m_hDevHelper->StartPinInput(len);
|
|
|
if (errCode != Error_Succeed)
|
|
|
{
|
|
|
LOG_PINPAD_ERROR_MSG_MACRO(errCode, StartPinInput);
|
|
@@ -900,8 +841,8 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
memset(buf,0,len+1);
|
|
|
int readed = 0;
|
|
|
DWORD elapsed = 0;
|
|
|
- DWORD dwStart = GetTickCount();
|
|
|
- DWORD dwEnd = GetTickCount();
|
|
|
+ DWORD dwStart = get_tick_count();
|
|
|
+ DWORD dwEnd = get_tick_count();
|
|
|
bool bCancelInput = false;
|
|
|
Dbg("reqqqq(pin)[%d][%d][%d]",len,timeout,confirm);
|
|
|
Dbg("bExit(%d)",m_bExit);
|
|
@@ -912,7 +853,7 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
break;
|
|
|
if (m_bWaitingMore)
|
|
|
{
|
|
|
- dwStart = GetTickCount();
|
|
|
+ dwStart = get_tick_count();
|
|
|
elapsed = 0;
|
|
|
m_bWaitingMore = false;
|
|
|
continue;
|
|
@@ -925,7 +866,7 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
//char ch[4] = {0};
|
|
|
BYTE btCh;
|
|
|
Sleep(100);
|
|
|
- errCode = m_pPinPad->KeyRead(btCh);
|
|
|
+ errCode = m_hDevHelper->KeyRead(btCh);
|
|
|
if (errCode == Error_Succeed) {
|
|
|
LogEvent(Severity_Middle,LOG_EVT_PINPAD_OP,"PinPad op.");
|
|
|
if (btCh == 0x0d) {
|
|
@@ -939,14 +880,14 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- dwEnd = GetTickCount();
|
|
|
+ dwEnd = get_tick_count();
|
|
|
elapsed = dwEnd - dwStart;
|
|
|
continue;
|
|
|
}
|
|
|
} else if (btCh == 0x08) { // back
|
|
|
if (confirm)
|
|
|
{
|
|
|
- dwEnd = GetTickCount();
|
|
|
+ dwEnd = get_tick_count();
|
|
|
elapsed = dwEnd - dwStart;
|
|
|
continue;
|
|
|
}
|
|
@@ -969,7 +910,7 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
} else if (btCh == 0x3f){
|
|
|
if (confirm)
|
|
|
{
|
|
|
- dwEnd = GetTickCount();
|
|
|
+ dwEnd = get_tick_count();
|
|
|
elapsed = dwEnd - dwStart;
|
|
|
continue;
|
|
|
}
|
|
@@ -981,14 +922,14 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
|
|
|
|
|
|
} else {
|
|
|
}
|
|
|
- dwEnd = GetTickCount();
|
|
|
+ dwEnd = get_tick_count();
|
|
|
elapsed = dwEnd - dwStart;
|
|
|
}
|
|
|
buf[readed] = 0;
|
|
|
//strOutput = buf;
|
|
|
Err:
|
|
|
//oilyang 20131017 commented
|
|
|
- //errCode = m_pPinPad->StopInput();
|
|
|
+ //errCode = m_hDevHelper->StopInput();
|
|
|
//if (errCode != Error_Succeed)
|
|
|
// Dbg("StopInput failed(%d).",errCode);
|
|
|
//else
|
|
@@ -1017,7 +958,7 @@ Err:
|
|
|
PinBlock pinBlk;
|
|
|
Dbg("to getpinblk");
|
|
|
Sleep(500);//nantian
|
|
|
- errCode = m_pPinPad->GetPinBlock(pinBlk);
|
|
|
+ errCode = m_hDevHelper->GetPinBlock(pinBlk);
|
|
|
Dbg("getpinblock(%d),size:%d",errCode,pinBlk.dwSize);
|
|
|
if (errCode == Error_Succeed)
|
|
|
{
|
|
@@ -1052,11 +993,11 @@ Err:
|
|
|
memset(dstInfo.data,0,MAX_EN_DECRYPT_DATA_SIZE);
|
|
|
//set param
|
|
|
if (!bSMFlag)
|
|
|
- errCode = m_pPinPad->SetParam(EPP_PT_SET_ENCRYPT_METHOD, EPP_ALGO_METHOD_3DES);
|
|
|
+ errCode = m_hDevHelper->SetParam(EPP_PT_SET_ENCRYPT_METHOD, EPP_ALGO_METHOD_3DES);
|
|
|
else
|
|
|
- errCode = m_pPinPad->SetParam(EPP_PT_SET_ENCRYPT_METHOD, EPP_ALGO_METHOD_SM4);
|
|
|
+ errCode = m_hDevHelper->SetParam(EPP_PT_SET_ENCRYPT_METHOD, EPP_ALGO_METHOD_SM4);
|
|
|
if (errCode == Error_Succeed)
|
|
|
- errCode = m_pPinPad->SetParam(EPP_PT_SET_ECB_CBC_MODE, EPP_ALGO_MODE_CBC);
|
|
|
+ errCode = m_hDevHelper->SetParam(EPP_PT_SET_ECB_CBC_MODE, EPP_ALGO_MODE_CBC);
|
|
|
|
|
|
if (errCode != Error_Succeed)
|
|
|
{
|
|
@@ -1064,7 +1005,7 @@ Err:
|
|
|
LOG_PINPAD_ERROR_MSG_MACRO(errCode, SetParam);
|
|
|
return Error_Param;
|
|
|
}
|
|
|
- errCode = m_pPinPad->EncryptData(srcInfo,dstInfo);
|
|
|
+ errCode = m_hDevHelper->EncryptData(srcInfo,dstInfo);
|
|
|
//if (tmpCheckData != NULL)
|
|
|
//{
|
|
|
// delete []tmpCheckData;
|
|
@@ -1109,10 +1050,7 @@ Err:
|
|
|
ctxSM->Ans.keyseq = m_keySN;
|
|
|
else
|
|
|
{
|
|
|
- if (m_keySNSM.GetLength() < 2)//如果忘记配置
|
|
|
- ctxSM->Ans.keyseq = "001";
|
|
|
- else
|
|
|
- ctxSM->Ans.keyseq = m_keySNSM;
|
|
|
+ ctxSM->Ans.keyseq = m_keySNSM;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1144,7 +1082,7 @@ void CPinPadFSM::OpenInputText(void *pUserdata)
|
|
|
|
|
|
if (!m_bPlainOpen)
|
|
|
{
|
|
|
- err = m_pPinPad->StartPlainInput();
|
|
|
+ err = m_hDevHelper->StartPlainInput();
|
|
|
if (err == Error_Succeed)
|
|
|
{
|
|
|
Dbg("start any input");
|
|
@@ -1175,15 +1113,15 @@ void CPinPadFSM::OpenInputText(void *pUserdata)
|
|
|
//{
|
|
|
// m_dwPinPadRunCount = 0;
|
|
|
// Dbg("stop input in period");
|
|
|
- // m_pPinPad->StopInput();
|
|
|
+ // m_hDevHelper->StopInput();
|
|
|
// m_bPlainOpen = false;
|
|
|
//}
|
|
|
|
|
|
|
|
|
BYTE btCh;
|
|
|
- INT64 i64Start = GetTickCount64();
|
|
|
- err = m_pPinPad->KeyRead(btCh);
|
|
|
- INT64 i64End = GetTickCount64();
|
|
|
+ INT64 i64Start = get_tick_count();
|
|
|
+ err = m_hDevHelper->KeyRead(btCh);
|
|
|
+ INT64 i64End = get_tick_count();
|
|
|
if ((i64End - i64Start) > 3000)//more than 3 seconds
|
|
|
Dbg("KeyRead cost more than %d seconds.", (i64End - i64Start)/1000);
|
|
|
if (err == Error_Succeed) {
|
|
@@ -1225,14 +1163,14 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
|
|
|
memset(buf,0,len+1);
|
|
|
int readed = 0;
|
|
|
DWORD elapsed = 0;
|
|
|
- DWORD dwStart = GetTickCount();
|
|
|
- DWORD dwEnd = GetTickCount();
|
|
|
+ DWORD dwStart = get_tick_count();
|
|
|
+ DWORD dwEnd = get_tick_count();
|
|
|
bool bCancelInput = false;
|
|
|
//Dbg("reqqqq[%d][%d][%d]",len,timeout,confirm);
|
|
|
//bool bPlainOpen = false;
|
|
|
ErrorCodeEnum err;
|
|
|
//the following several lines just for Nantian as they close pinpad while mag encrypted improve. oilyang 20150513
|
|
|
- err = m_pPinPad->StopInput();
|
|
|
+ err = m_hDevHelper->StopInput();
|
|
|
m_bPlainOpen = false;
|
|
|
Dbg("plain input for nt.%d",err);
|
|
|
Sleep(100);
|
|
@@ -1249,7 +1187,7 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
|
|
|
if (m_bWaitingMore)
|
|
|
{
|
|
|
Dbg("WaitMore");
|
|
|
- dwStart = GetTickCount();
|
|
|
+ dwStart = get_tick_count();
|
|
|
elapsed = 0;
|
|
|
m_bWaitingMore = false;
|
|
|
continue;
|
|
@@ -1263,7 +1201,7 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
|
|
|
if (!m_bPlainOpen)
|
|
|
{
|
|
|
Dbg("start plain input");
|
|
|
- err = m_pPinPad->StartPlainInput();
|
|
|
+ err = m_hDevHelper->StartPlainInput();
|
|
|
if (err == Error_Succeed)
|
|
|
m_bPlainOpen = true;
|
|
|
else
|
|
@@ -1275,11 +1213,11 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
|
|
|
BYTE btCh;
|
|
|
Sleep(100);//oiltest
|
|
|
//Dbg("start plain KeyRead");
|
|
|
- err = m_pPinPad->KeyRead(btCh);
|
|
|
+ err = m_hDevHelper->KeyRead(btCh);
|
|
|
//Dbg("end plain KeyRead");
|
|
|
if (err == Error_Succeed) {
|
|
|
//DevErrorInfo devErrInfo;
|
|
|
- //m_pPinPad->GetLastErr(devErrInfo);
|
|
|
+ //m_hDevHelper->GetLastErr(devErrInfo);
|
|
|
//Dbg("[%s]",devErrInfo.szErrMsg);
|
|
|
LogEvent(Severity_Middle,LOG_EVT_PINPAD_OP,"PinPad op(T).");
|
|
|
if (btCh == 0x0d) {
|
|
@@ -1293,14 +1231,14 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- dwEnd = GetTickCount();
|
|
|
+ dwEnd = get_tick_count();
|
|
|
elapsed = dwEnd - dwStart;
|
|
|
continue;
|
|
|
}
|
|
|
} else if (btCh == 0x08) { // back
|
|
|
if (confirm)
|
|
|
{
|
|
|
- dwEnd = GetTickCount();
|
|
|
+ dwEnd = get_tick_count();
|
|
|
elapsed = dwEnd - dwStart;
|
|
|
continue;
|
|
|
}
|
|
@@ -1323,7 +1261,7 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
|
|
|
} else {
|
|
|
if (confirm)
|
|
|
{
|
|
|
- dwEnd = GetTickCount();
|
|
|
+ dwEnd = get_tick_count();
|
|
|
elapsed = dwEnd - dwStart;
|
|
|
continue;
|
|
|
}
|
|
@@ -1350,7 +1288,7 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
|
|
|
} else {
|
|
|
//Dbg("else[%s]", buf);
|
|
|
}
|
|
|
- dwEnd = GetTickCount();
|
|
|
+ dwEnd = get_tick_count();
|
|
|
elapsed = dwEnd - dwStart;
|
|
|
}
|
|
|
|
|
@@ -1397,7 +1335,7 @@ int CPinPadFSM::GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadServi
|
|
|
m_bExit = false;
|
|
|
LogEvent(Severity_Middle,LOG_EVT_PINPAD_GREEN_ON,"PinPad light on.");
|
|
|
//LogEvent(Severity_Middle,LOG_EVT_PINPAD_GREEN_ON,"PinPad green light on.");
|
|
|
- if (m_pPinPad == NULL)
|
|
|
+ if (!m_hDevHelper)
|
|
|
{
|
|
|
LOG_TRACE("PinPad is not available!");
|
|
|
if (!bSM)
|
|
@@ -1431,7 +1369,7 @@ int CPinPadFSM::GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadServi
|
|
|
//oilyang@20200428 call StopInput
|
|
|
//if (m_bPlainOpen)
|
|
|
{
|
|
|
- ErrorCodeEnum errClosePinPad = m_pPinPad->StopInput();
|
|
|
+ ErrorCodeEnum errClosePinPad = m_hDevHelper->StopInput();
|
|
|
Dbg("close pinpad(%d).",errClosePinPad);
|
|
|
Sleep(100);
|
|
|
m_bPlainOpen = false;
|
|
@@ -1485,7 +1423,7 @@ int CPinPadFSM::LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadServic
|
|
|
spConfig = NULL;
|
|
|
}
|
|
|
if (m_bPlainOpen)
|
|
|
- m_pPinPad->StopInput();
|
|
|
+ m_hDevHelper->StopInput();
|
|
|
//initialization need load master key
|
|
|
if (ctx->Req.initializeflag)
|
|
|
{
|
|
@@ -1495,7 +1433,7 @@ int CPinPadFSM::LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadServic
|
|
|
memset(mkParam.key,0,MAX_MASTER_KEY_SIZE);
|
|
|
memcpy(mkParam.key,ctx->Req.masterkey,strlen(ctx->Req.masterkey));
|
|
|
//Dbg("%s,%d",mkParam.key,mkParam.dwSN);
|
|
|
- eErr = m_pPinPad->LoadMasterKey(mkParam);
|
|
|
+ eErr = m_hDevHelper->LoadMasterKey(mkParam);
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
|
Dbg("Load master key failed(%d).",eErr);
|
|
@@ -1520,7 +1458,7 @@ int CPinPadFSM::LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadServic
|
|
|
memcpy(wkParam1.key,ctx->Req.workingkey1,strlen(ctx->Req.workingkey1));
|
|
|
memcpy(wkParam2.key,ctx->Req.workingkey2,strlen(ctx->Req.workingkey2));
|
|
|
wkParam1.smFlag = 0;
|
|
|
- eErr = m_pPinPad->LoadWorkingKey(wkParam1);
|
|
|
+ eErr = m_hDevHelper->LoadWorkingKey(wkParam1);
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
|
Dbg("load working key 1 failed(%d).",eErr);
|
|
@@ -1533,7 +1471,7 @@ int CPinPadFSM::LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadServic
|
|
|
}
|
|
|
Dbg("Load working key1 suc.");
|
|
|
wkParam2.smFlag = 0;
|
|
|
- eErr = m_pPinPad->LoadWorkingKey(wkParam2);
|
|
|
+ eErr = m_hDevHelper->LoadWorkingKey(wkParam2);
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
|
Dbg("load working key 2 failed(%d).",eErr);
|
|
@@ -1565,9 +1503,9 @@ int CPinPadFSM::Encrypt(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadSer
|
|
|
LOG_FUNCTION();
|
|
|
ErrorCodeEnum eErr;
|
|
|
//set param
|
|
|
- eErr = m_pPinPad->SetParam(EPP_PT_SET_ENCRYPT_METHOD,EPP_ALGO_METHOD_3DES);
|
|
|
+ eErr = m_hDevHelper->SetParam(EPP_PT_SET_ENCRYPT_METHOD,EPP_ALGO_METHOD_3DES);
|
|
|
if (eErr == Error_Succeed)
|
|
|
- eErr = m_pPinPad->SetParam(EPP_PT_SET_ECB_CBC_MODE,EPP_ALGO_MODE_3DEC_CBC);
|
|
|
+ eErr = m_hDevHelper->SetParam(EPP_PT_SET_ECB_CBC_MODE,EPP_ALGO_MODE_3DEC_CBC);
|
|
|
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
@@ -1579,7 +1517,7 @@ int CPinPadFSM::Encrypt(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadSer
|
|
|
return 0;
|
|
|
}
|
|
|
Dbg("SetParam ok.");
|
|
|
- eErr = m_pPinPad->ActiveWorkingKey(0, 1);
|
|
|
+ eErr = m_hDevHelper->ActiveWorkingKey(0, 1);
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
|
//Dbg("pinpad activate WK error,(%d)",eErr);
|
|
@@ -1597,7 +1535,7 @@ int CPinPadFSM::Encrypt(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadSer
|
|
|
srcData.dwSize = strlen(ctx->Req.data);
|
|
|
memcpy(srcData.data,ctx->Req.data,srcData.dwSize);
|
|
|
|
|
|
- eErr = m_pPinPad->EncryptData(srcData,dstData);
|
|
|
+ eErr = m_hDevHelper->EncryptData(srcData,dstData);
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
|
//Dbg("Encrypt data failed(%d).",eErr);
|
|
@@ -1630,7 +1568,7 @@ int CPinPadFSM::LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadSe
|
|
|
spConfig = NULL;
|
|
|
}
|
|
|
if (m_bPlainOpen)
|
|
|
- m_pPinPad->StopInput();
|
|
|
+ m_hDevHelper->StopInput();
|
|
|
bool bSM = false;
|
|
|
if (ctx->Req.smflag == 1)
|
|
|
bSM = true;
|
|
@@ -1647,7 +1585,7 @@ int CPinPadFSM::LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadSe
|
|
|
Dbg("mkey len:%d", strlen(ctx->Req.masterkey));
|
|
|
memcpy(mkParam.key,ctx->Req.masterkey,strlen(ctx->Req.masterkey));
|
|
|
//Dbg("%s,%d",mkParam.key,mkParam.dwSN);
|
|
|
- eErr = m_pPinPad->LoadMasterKey(mkParam);
|
|
|
+ eErr = m_hDevHelper->LoadMasterKey(mkParam);
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
|
Dbg("Load master key(%d),mkeysn:%d failed(%d).",bSM,mkParam.dwSN,eErr);
|
|
@@ -1681,7 +1619,7 @@ int CPinPadFSM::LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadSe
|
|
|
wkParam2.smFlag = ctx->Req.smflag;
|
|
|
memcpy(wkParam1.key,ctx->Req.workingkey1,strlen(ctx->Req.workingkey1));
|
|
|
memcpy(wkParam2.key,ctx->Req.workingkey2,strlen(ctx->Req.workingkey2));
|
|
|
- eErr = m_pPinPad->LoadWorkingKey(wkParam1);
|
|
|
+ eErr = m_hDevHelper->LoadWorkingKey(wkParam1);
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
|
Dbg("load working key 1(%d) failed(%d).",bSM,eErr);
|
|
@@ -1694,7 +1632,7 @@ int CPinPadFSM::LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadSe
|
|
|
}
|
|
|
Dbg("Load working key1(%d) suc.",bSM);
|
|
|
|
|
|
- eErr = m_pPinPad->LoadWorkingKey(wkParam2);
|
|
|
+ eErr = m_hDevHelper->LoadWorkingKey(wkParam2);
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
|
Dbg("load working key 2(%d) failed(%d).",bSM,eErr);
|
|
@@ -1711,7 +1649,15 @@ int CPinPadFSM::LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadSe
|
|
|
if (!bSM)
|
|
|
eErr = spConfig->WriteConfigValueInt("Load", "3DES", 1);
|
|
|
else
|
|
|
+ {
|
|
|
eErr = spConfig->WriteConfigValueInt("Load", "SM", 1);
|
|
|
+ if (!ctx->Req.reserved3.IsNullOrEmpty())
|
|
|
+ {
|
|
|
+ spConfig->WriteConfigValue("Load", "SN_SM", ctx->Req.reserved3);
|
|
|
+ m_keySNSM = ctx->Req.reserved3;
|
|
|
+ Dbg("sm key sn:%s",(const char*)m_keySNSM);
|
|
|
+ }
|
|
|
+ }
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
|
Dbg("after load key suc,write run cfg failed.");
|
|
@@ -1736,12 +1682,12 @@ int CPinPadFSM::EncryptSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPa
|
|
|
bSM = true;
|
|
|
//set param
|
|
|
if (!bSM)
|
|
|
- eErr = m_pPinPad->SetParam(EPP_PT_SET_ENCRYPT_METHOD,EPP_ALGO_METHOD_3DES);
|
|
|
+ eErr = m_hDevHelper->SetParam(EPP_PT_SET_ENCRYPT_METHOD,EPP_ALGO_METHOD_3DES);
|
|
|
else
|
|
|
- eErr = m_pPinPad->SetParam(EPP_PT_SET_ENCRYPT_METHOD,EPP_ALGO_METHOD_SM4);
|
|
|
+ eErr = m_hDevHelper->SetParam(EPP_PT_SET_ENCRYPT_METHOD,EPP_ALGO_METHOD_SM4);
|
|
|
|
|
|
if (eErr == Error_Succeed)
|
|
|
- eErr = m_pPinPad->SetParam(EPP_PT_SET_ECB_CBC_MODE,EPP_ALGO_MODE_CBC);
|
|
|
+ eErr = m_hDevHelper->SetParam(EPP_PT_SET_ECB_CBC_MODE,EPP_ALGO_MODE_CBC);
|
|
|
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
@@ -1754,9 +1700,9 @@ int CPinPadFSM::EncryptSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPa
|
|
|
}
|
|
|
Dbg("SetParam ok.");
|
|
|
if (!bSM)
|
|
|
- eErr = m_pPinPad->ActiveWorkingKey(0, 1);
|
|
|
+ eErr = m_hDevHelper->ActiveWorkingKey(0, 1);
|
|
|
else
|
|
|
- eErr = m_pPinPad->ActiveWorkingKey(1, 1);
|
|
|
+ eErr = m_hDevHelper->ActiveWorkingKey(1, 1);
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
|
Dbg("pinpad activate WK error,(%d)",eErr);
|
|
@@ -1773,7 +1719,7 @@ int CPinPadFSM::EncryptSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPa
|
|
|
srcData.dwSize = strlen(ctx->Req.data);
|
|
|
memcpy(srcData.data,ctx->Req.data,srcData.dwSize);
|
|
|
|
|
|
- eErr = m_pPinPad->EncryptData(srcData,dstData);
|
|
|
+ eErr = m_hDevHelper->EncryptData(srcData,dstData);
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
|
Dbg("Encrypt data failed(%d).",eErr);
|
|
@@ -1803,16 +1749,16 @@ int CPinPadFSM::GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, Pin
|
|
|
Dbg("mSN:%d,wSN:%d", ctx->Req.mSN[i], ctx->Req.wSN[i]);
|
|
|
//set param
|
|
|
if (ctx->Req.mSN[i] == 1)
|
|
|
- eErr = m_pPinPad->SetParam(EPP_PT_SET_ENCRYPT_METHOD, EPP_ALGO_METHOD_SM4);
|
|
|
+ eErr = m_hDevHelper->SetParam(EPP_PT_SET_ENCRYPT_METHOD, EPP_ALGO_METHOD_SM4);
|
|
|
else
|
|
|
- eErr = m_pPinPad->SetParam(EPP_PT_SET_ENCRYPT_METHOD, EPP_ALGO_METHOD_3DES);
|
|
|
+ eErr = m_hDevHelper->SetParam(EPP_PT_SET_ENCRYPT_METHOD, EPP_ALGO_METHOD_3DES);
|
|
|
if (eErr == Error_Succeed)
|
|
|
- eErr = m_pPinPad->SetParam(EPP_PT_SET_ECB_CBC_MODE, EPP_ALGO_MODE_CBC);
|
|
|
+ eErr = m_hDevHelper->SetParam(EPP_PT_SET_ECB_CBC_MODE, EPP_ALGO_MODE_CBC);
|
|
|
else
|
|
|
{
|
|
|
LOG_PINPAD_ERROR_MSG_MACRO(eErr, SetParam);
|
|
|
}
|
|
|
- eErr = m_pPinPad->ActiveWorkingKey(ctx->Req.mSN[i], ctx->Req.wSN[i]);
|
|
|
+ eErr = m_hDevHelper->ActiveWorkingKey(ctx->Req.mSN[i], ctx->Req.wSN[i]);
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
|
LOG_PINPAD_ERROR_MSG_MACRO(eErr, ActiveWorkingKey);
|
|
@@ -1827,7 +1773,7 @@ int CPinPadFSM::GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, Pin
|
|
|
srcInfo.dwSize = m_devCheckData.GetLength();
|
|
|
memset(dstInfo.data, 0, MAX_EN_DECRYPT_DATA_SIZE);
|
|
|
|
|
|
- eErr = m_pPinPad->EncryptData(srcInfo, dstInfo);
|
|
|
+ eErr = m_hDevHelper->EncryptData(srcInfo, dstInfo);
|
|
|
|
|
|
if (eErr != Error_Succeed)
|
|
|
{
|
|
@@ -1852,7 +1798,7 @@ bool CPinPadFSM::GetDevInfo(DevCategoryInfo &devInfo)
|
|
|
ZeroMemory(info.szModel, MAX_DEV_MODEL_LEN);
|
|
|
ZeroMemory(info.szType, MAX_DEV_TYPE_LEN);
|
|
|
ZeroMemory(info.szVendor, MAX_DEV_VENDOR_LEN);
|
|
|
- ErrorCodeEnum eErrDev = m_pPinPad->GetDevCategory(info);
|
|
|
+ ErrorCodeEnum eErrDev = m_hDevHelper->GetDevCategory(info);
|
|
|
if (eErrDev == Error_Succeed)
|
|
|
{
|
|
|
m_szModel = info.szModel;
|
|
@@ -1923,7 +1869,7 @@ void CPinPadFSM::LogErrMsg(const char *pMsgHead, ErrorCodeEnum eErrCode, DWORD d
|
|
|
{
|
|
|
WORD wdErrCode = 0;
|
|
|
CSimpleStringA csErrMsg(true);
|
|
|
- ErrorCodeEnum ec = DeviceBaseHelper::GetAndSplitDevErrInfo(m_pPinPad, csErrMsg, wdErrCode,
|
|
|
+ ErrorCodeEnum ec = DeviceBaseHelper::GetAndSplitDevErrInfo(m_hDevHelper.GetDevPointer(), csErrMsg, wdErrCode,
|
|
|
bAlarm ? NULL : pMsgHead);
|
|
|
if(ec == Error_Succeed && wdErrCode != 0) {
|
|
|
//oilyang@20200525 if have been set ErrorCode of entity defined (not device),use it directly
|