Эх сурвалжийг харах

Merge branch 'cjl_uos_CenterSettingSyn_0818' of http://gitee.itc.cmbchina.cn/QD_RemoteBankArea/LR04.02_RVCTerminalPlus into cjl_uos_CenterSettingSyn_0818

陈纪林80310970 2 жил өмнө
parent
commit
ae02f65639

+ 1 - 1
CMakeLists.txt

@@ -284,7 +284,7 @@ if(CONAN_CACHE_CLEAR)
 	conan_local_remove()
 endif(CONAN_CACHE_CLEAR)
 
-conan_cmake_run(REQUIRES RvcFramework/1.2.0.13@LR04.02_FrameworkLib/dev
+conan_cmake_run(REQUIRES RvcFramework/1.2.0.15@LR04.02_FrameworkLib/dev
 	Audio/2023.0509.01@LR04.02_MediaRes/testing
 BASIC_SETUP CMAKE_TARGETS)
 include(DependencyConanFiles)

+ 0 - 1
Module/mod_guiconsole/mod_GuiConsole.h

@@ -46,7 +46,6 @@ public:
 	ErrorCodeEnum SubscribeEntitysEvents();
 	ErrorCodeEnum UnsubscribeEntitysEvents();
 	CSimpleStringA GetCurMaintainer(){ return m_strUserID;}
-	bool refreshToken();
 	ErrorCodeEnum GetCurrentMaintainer(CSimpleStringA &strUserID,	CSimpleStringA &strUserName, CSimpleStringA &strCurRight,
 		CSimpleStringA &strAuthorizer, unsigned int &dwBeginTime);
 	ErrorCodeEnum Empower(const char *pszUserID);

+ 10 - 117
Module/mod_guiconsole/mod_guiconsole.cpp

@@ -22,12 +22,21 @@ static void HTTPLogCallback(const char* msg) {
 DWORD tokenUpdate(void* param)
 {
 	CGUIConsoleEntity* t_entity = (CGUIConsoleEntity*)param;
+	CSimpleString token;
+	if (t_entity->GetFunction()->GetPrivilegeFunction()->GetToken(token) == ErrorCodeEnum::Error_Succeed)
+		Sleep(t_entity->m_refreshWaitSec / 4 * 1000);
 	while (true)
 	{
-		if (t_entity->refreshToken())
+		CSimpleString oldToken, newToken;
+		auto ret = t_entity->GetFunction()->GetPrivilegeFunction()->TryUpdateToken(oldToken, newToken);
+		if (ret == Error_Succeed)
 			Sleep(t_entity->m_refreshWaitSec * 1000);
 		else
+		{
+			LogWarn(Severity_Middle, ret, ret == Error_NotConfig ? TOKEN_GETURL_ERR : GET_TOKEN_ERR,
+				ret == Error_NotConfig ? "can not get CommonLaunchUrl from shell" : "total getToken failed");
 			Sleep(20 * 1000);
+		}
 	}
 	return 0;
 }
@@ -159,122 +168,6 @@ void CGUIConsoleEntity::printCfg()
 	}
 }
 
-bool CGUIConsoleEntity::refreshToken()
-{
-	static std::string commonUrl = "";
-	if (commonUrl.length() == 0)
-	{
-		CSmartPointer<IConfigInfo> shellConfig;
-		GetFunction()->OpenConfig(Config_Shell, shellConfig);
-		CSimpleStringA strMicroServiceURLSection = "MicroServiceURL";
-
-#ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
-		strMicroServiceURLSection = "MicroServiceURL-ST";
-		m_channelId = "5fdd82e3b90a4de69f9da4738e5f1216";
-		m_tokenSecret = "eca829c78067c686561bd844129321c8a78af3";
-#elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
-		strMicroServiceURLSection = "MicroServiceURL-UAT";
-		m_channelId = "7eb748cb71744c87b5c126e05af8cce7";
-		m_tokenSecret = "eca529c78967c640561bd844229391c8a78af3";
-#elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
-		//strMicroServiceURLSection = "MicroServiceURL-PRD";
-		m_channelId = "572f7577fa9f425c8475a8d77db4ae31";
-		m_tokenSecret = "eca129c78767c670561bd844629361c8a78af3";
-#elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/
-		strMicroServiceURLSection = "MicroServiceURL-Dev";
-		m_channelId = "572f7577fa9f425c8475a8d77db4ae31";
-		m_tokenSecret = "eca129c78767c670561bd844629361c8a78af3";
-#else/*本地编译等非DevOps环境编译的版本*/
-		strMicroServiceURLSection = "MicroServiceURL-Dev";
-		m_channelId = "5fdd82e3b90a4de69f9da4738e5f1216";
-		m_tokenSecret = "eca829c78067c686561bd844129321c8a78af3";
-#endif
-
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Section name:%s", strMicroServiceURLSection.GetData());
-		CAutoArray<CSimpleStringA> m_arrKeys;
-		shellConfig->ReadAllKeys(strMicroServiceURLSection, m_arrKeys);
-
-		CSimpleStringA strUrl;
-		for (int i = 0; i < m_arrKeys.GetCount(); i++)
-		{
-			if (m_arrKeys[i].IsStartWith("CommonLaunchUrl"))
-			{
-				shellConfig->ReadConfigValue(strMicroServiceURLSection, m_arrKeys[i].GetData(), strUrl);
-				break;
-			}
-
-		}
-
-		if (strUrl.IsNullOrEmpty())
-		{
-			LogWarn(Severity_Middle, Error_Bug, TOKEN_GETURL_ERR, "can not get CommonLaunchUrl from shell.ini");
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI("refreshToken").setLogCode("QLR0402Z10A00001")("can not get CommonLaunchUrl from shell.ini");
-			return false;
-		}
-		else
-			commonUrl = strUrl.GetData();
-	}
-
-	static std::string terminalNo;
-	if (terminalNo.length() == 0)
-	{
-		CSystemStaticInfo info;
-		GetFunction()->GetSystemStaticInfo(info);
-		terminalNo = info.strTerminalID;
-	}
-
-	//只要调用这个借口,就会获取新的token
-	//判断是否应该刷新,在其他逻辑中判断
-	CSimpleString tmpUrl = commonUrl.c_str();
-	auto urlArr = tmpUrl.Split('|');
-	static std::vector<QueryTokenHTTPReq> reqArr;//避免函数结束被析构
-	reqArr.clear();
-	for (int i = 0; i < urlArr.GetCount(); i++)
-	{
-		auto curUrl = urlArr[i];
-		if (curUrl.GetLength() == 0)
-		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("QueryToken error, pos:%d, %s", i, tmpUrl.GetData());
-			continue;
-		}
-		QueryTokenHTTPReq req;
-		req.channelId = m_channelId;
-		req.tokenSecret = m_tokenSecret;
-		req.businessId = terminalNo;
-		req.m_url = curUrl.GetData();
-		req.m_url.append("/api/auth/v2/token");
-		req.m_headers.emplace(std::make_pair("Content-Type", "application/json"));
-		reqArr.emplace_back(req);
-	}
-	std::vector<HANDLE> threadArr;//创建多个线程获取token
-	for (int i = 0; i < reqArr.size(); i++)
-		threadArr.push_back(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&getTokenThread, &(reqArr[i]), 0, NULL));
-
-	bool t_isGetTokenSuccess = false;
-	auto tokenRet = WaitForMultipleObjects(threadArr.size(), threadArr.data(), false, 10000);
-	if (tokenRet >= WAIT_OBJECT_0 && tokenRet <= WAIT_OBJECT_0 + threadArr.size())
-	{
-		DWORD exitCode = INT_MAX;
-		GetExitCodeThread(threadArr[tokenRet - WAIT_OBJECT_0], &exitCode);
-		if (exitCode == 0)
-		{
-			t_isGetTokenSuccess = true;
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("total getToken success from url %s", reqArr[tokenRet - WAIT_OBJECT_0].m_url.c_str());
-			CSimpleString t_channelId = m_channelId.c_str();
-			CSimpleString t_token = m_httpToken.c_str();
-			GetFunction()->SetSysVar("shell_channelId", t_channelId);
-			GetFunction()->SetSysVar("shell_token", t_token);
-			//GetFunction()->GetPrivilegeFunction()->SetHttpToken(m_channelId.c_str(), m_httpToken.c_str());
-			return true;
-		}
-	}
-	LogWarn(Severity_Low, Error_Bug, GET_TOKEN_ERR, "total getToken failed");
-	DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("refreshToken").setLogCode("QLR0402Z10A00003")("total getToken failed");
-	return false;
-}
-
-
-
 
 void CGUIConsoleEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
 {

+ 3 - 1
Module/mod_pinpad/CMakeLists.txt

@@ -4,7 +4,9 @@ set(${MODULE_PREFIX}_SRCS
 	mod_pinpad.cpp
 	mod_PinPad.h
 	PinPadFSM.cpp
-	PinPadFSM.h)
+	PinPadFSM.h
+	sm4.cpp
+	sm4.h)
 
 set(MOD_VERSION_STRING "1.0.0-dev1")
 add_module_libraries(${MODULE_PREFIX} ${MODULE_NAME} ${MOD_VERSION_STRING})

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 306 - 359
Module/mod_pinpad/PinPadFSM.cpp


+ 71 - 196
Module/mod_pinpad/PinPadFSM.h

@@ -7,7 +7,9 @@
 #include "toolkit.h"
 #include "SpUtility.h"
 #include "DevFSMCommBase.hpp"
-#include "DeviceBaseHelper.h"
+#include "CommEntityUtil.hpp"
+#include "PinPad_UserErrorCode.h"
+#include "json/json.h"
 enum EvtType
 {
 	USER_EVT_TEST =	EVT_USER+1,
@@ -15,17 +17,11 @@ enum EvtType
 	USER_EVT_QUIT,
 	USER_EVT_INIT,
 	USER_EVT_INITFINISHED,
-	USER_EVT_GETINPUT,
-	USER_EVT_GETINPUTFINISHED,
 	USER_EVT_SETACCOUNT,
 	USER_EVT_SETACCOUNTFINISHED,
 	USER_EVT_INPUTCANCEL,
 	USER_EVT_INPUTWAITINGMORE,
 	USER_EVT_EXIT,
-	USER_EVT_LOADKEY,
-	USER_EVT_LOADKEYFINISHED,
-	USER_EVT_ENCRYPT,
-	USER_EVT_ENCRYPTFINISHED,
 	USER_EVT_GETINPUT_SM,
 	USER_EVT_GETINPUT_SM_FINISHED,
 	USER_EVT_LOADKEY_SM,
@@ -34,22 +30,19 @@ enum EvtType
 	USER_EVT_ENCRYPT_SM_FINISHED,
 	USER_EVT_GET_CHECKCODE,
 	USER_EVT_GET_CHECKCODE_FINISHED,
+	USER_EVT_TODO_INIT,
+	USER_EVT_TODO_INIT_FINISHED,
 };
 #include "PinPad_server_g.h"
 #include "PinPad_msg_g.h"
 
 #include "PinPadClass.h"
-#include "DeviceCrossHelper.h"
+#include "DeviceBaseHelper.h"
+
 //using namespace PinPad;
-using PinPad::PinPadService_GetInput_Req;
-using PinPad::PinPadService_GetInput_Ans;
 using PinPad::PinPadService_InputWaitMore_Info;
 using PinPad::PinPadService_InputCancel_Info;
 using PinPad::PinPadService_Exit_Info;
-using PinPad::PinPadService_LoadKeys_Req;
-using PinPad::PinPadService_LoadKeys_Ans;
-using PinPad::PinPadService_EncryptData_Req;
-using PinPad::PinPadService_EncryptData_Ans;
 using PinPad::PinPadService_GetInputSM_Req;
 using PinPad::PinPadService_GetInputSM_Ans;
 using PinPad::PinPadService_LoadKeysSM_Req;
@@ -60,17 +53,15 @@ using PinPad::PinPadService_QueryFunc_Req;
 using PinPad::PinPadService_QueryFunc_Ans;
 using PinPad::PinPadService_GetCheckCode_Req;
 using PinPad::PinPadService_GetCheckCode_Ans;
-using PinPad::PinPadService_CrossTermCall_Req;
-using PinPad::PinPadService_CrossTermCall_Ans;
-using PinPad::PinPadService_CrossTermInvokeInfo_Info;
 using PinPad::PinPadService_GetDevInfo_Req;
 using PinPad::PinPadService_GetDevInfo_Ans;
 using PinPad::InputContent;
-#include "HeartBeat_client_g.h"
-using namespace HeartBeat;
+
 #include <map>
 using namespace std;
 
+#include "DeviceBaseHelper.h"
+
 struct CtxInfo
 {
 	int dataSize;
@@ -80,6 +71,8 @@ struct CtxInfo
 class CPinPadEntity;
 class CPinPadFSM;
 
+unsigned int __stdcall DoWork(void* pData);
+
 class PinPadInitFinishedEvent : public FSMEvent
 {
 public:
@@ -99,42 +92,6 @@ public:
 	~InputWaitingMoreEvent(){}
 };
 
-class GetInputEvent : public FSMEvent
-{
-public:
-	GetInputEvent() : FSMEvent(USER_EVT_GETINPUT){}
-	~GetInputEvent(){}
-	SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx;
-	virtual void OnUnhandled() 
-	{
-		if (ctx != NULL)
-			ctx->Answer(Error_InvalidState);
-	}
-};
-class LoadKeyEvent : public FSMEvent
-{
-public:
-	LoadKeyEvent() : FSMEvent(USER_EVT_LOADKEY){}
-	~LoadKeyEvent(){}
-	SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx;
-	virtual void OnUnhandled() 
-	{
-		if (ctx != NULL)
-			ctx->Answer(Error_InvalidState);
-	}
-};
-class EncryptEvent : public FSMEvent
-{
-public:
-	EncryptEvent() : FSMEvent(USER_EVT_ENCRYPT){}
-	~EncryptEvent(){}
-	SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx;
-	virtual void OnUnhandled() 
-	{
-		if (ctx != NULL)
-			ctx->Answer(Error_InvalidState);
-	}
-};
 class GetInputSMEvent : public FSMEvent
 {
 public:
@@ -187,7 +144,7 @@ public:
 class CPinPadFSM : public CCommDevFSM<CPinPadFSM, PinPadClass>
 {
 public:
-	enum {s0,s1,s2,s3,s4,s5};
+	enum {s0,s1,s2,s3,s4,s5,s6};
 	BEGIN_FSM_STATE(CPinPadFSM)
 		FSM_STATE_ENTRY(s0, "Init", s0_on_entry, s0_on_exit, s0_on_event)
 		FSM_STATE_ENTRY(s1, "Initializing", s1_on_entry, s1_on_exit, s1_on_event)
@@ -195,49 +152,42 @@ public:
 		FSM_STATE_ENTRY(s3, "Input", s3_on_entry, s3_on_exit, s3_on_event)
 		FSM_STATE_ENTRY(s4, "AccessAuth", s4_on_entry, s4_on_exit, s4_on_event)
 		FSM_STATE_ENTRY(s5, "Failed", s5_on_entry, s5_on_exit, s5_on_event)
+		FSM_STATE_ENTRY(s6, "InitFailed", s6_on_entry, s6_on_exit, s6_on_event)
 		END_FSM_STATE()
 
 		BEGIN_FSM_RULE(CPinPadFSM, s0)
 		FSM_RULE_ENTRY(s0, s1, USER_EVT_INIT, 0)
 		FSM_RULE_ENTRY(s1, s2, USER_EVT_INITFINISHED, 0)
-		FSM_RULE_ENTRY(s1, s5, USER_EVT_INITFINISHED, 1)
-		FSM_RULE_ENTRY(s2, s3, USER_EVT_GETINPUT, 0)
+		FSM_RULE_ENTRY(s1, s6, USER_EVT_INITFINISHED, 1)
 		FSM_RULE_ENTRY(s2, s3, USER_EVT_GETINPUT_SM, 0)
-		FSM_RULE_ENTRY(s2, s4, USER_EVT_LOADKEY, 2)
-		FSM_RULE_ENTRY(s2, s4, USER_EVT_ENCRYPT, 2)
 		FSM_RULE_ENTRY(s2, s4, USER_EVT_LOADKEY_SM, 2)
 		FSM_RULE_ENTRY(s2, s4, USER_EVT_ENCRYPT_SM, 2)
-		//FSM_RULE_ENTRY(s2,s2,USER_EVT_ANY_INPUT_TIMER,0)
-		//FSM_RULE_ENTRY(s2,s4,USER_EVT_GETINPUT,0)
-		FSM_RULE_ENTRY(s3, s2, USER_EVT_GETINPUTFINISHED, 0)
-		FSM_RULE_ENTRY(s3, s5, USER_EVT_GETINPUTFINISHED, 1)
-		FSM_RULE_ENTRY(s4, s2, USER_EVT_LOADKEYFINISHED, 0)
-		FSM_RULE_ENTRY(s4, s2, USER_EVT_ENCRYPTFINISHED, 0)
+		FSM_RULE_ENTRY(s2, s0, USER_EVT_TODO_INIT_FINISHED, 0)
+		FSM_RULE_ENTRY(s3, s2, USER_EVT_GETINPUT_SM_FINISHED, 0)
+		FSM_RULE_ENTRY(s3, s2, USER_EVT_EXIT, 0)
 		FSM_RULE_ENTRY(s4, s2, USER_EVT_LOADKEY_SM_FINISHED, 0)
 		FSM_RULE_ENTRY(s4, s2, USER_EVT_ENCRYPT_SM_FINISHED, 0)
-		FSM_RULE_ENTRY(s5, s0, USER_EVT_GETINPUT, 0)
-		FSM_RULE_ENTRY(s5, s0, USER_EVT_LOADKEY, 0)
+		FSM_RULE_ENTRY(s5, s0, USER_EVT_TODO_INIT_FINISHED, 0)
+		FSM_RULE_ENTRY(s6, s0, USER_EVT_TODO_INIT_FINISHED, 0)
 		END_FSM_RULE()
 
-		CPinPadFSM() : m_bDevInit(false), m_bFrontCancel(false),
-		m_bWaitingMore(false), m_bExit(false), m_bPlainPin(true), m_ctx(NULL),
-		m_bEntityExit(false), m_bPinInput(false), m_bPlainOpen(false), m_bLoadKey(false), m_bEncrypt(false)
+		CPinPadFSM() : m_bFrontCancel(false),
+		m_bWaitingMore(false), m_bExit(false), m_bPlainPin(true),
+		m_bEntityExit(false), m_bPinInput(false), m_bLoadKey(false), m_bEncrypt(false)
 		, m_dwDevCommFailCount(0), m_dwPinPadRunCount(0), m_eDevState(DEVICE_STATUS_NOT_READY), m_encryptkey(1)
-		, m_bSM(false), m_b3DESLoaded(false), m_bSMLoaded(false), m_bInMainPage(true), m_szModel(""), m_szType(""), m_devSN("")
-		, m_szVendor(""),m_csMachineType(true), m_csSite(true), m_terminalNo(true), m_bPinPadNeedless(FALSE)
-		, m_csAlarmMsg("NO more information"), m_bRVCIL(false), m_keySN(""),m_keySNSM(""){
+		, m_bSM(false), m_b3DESLoaded(false), m_bSMLoaded(false), m_iInWhatPage(PageType_Other), m_szModel(""), m_szType("")
+		, m_szVendor(""),m_csMachineType(true), m_csSite(true), m_terminalNo(true), m_port(true), m_Baudrate(true)
+		, m_devSN(""){
 			HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x206);
-			m_FirstStart = TRUE;
 			ZeroMemory(&m_adapterInfo, sizeof(m_adapterInfo));
 	}
 	~CPinPadFSM(){
 		m_bEntityExit = true;
-		m_hInputConVar.Broadcast();
 	}
 	virtual ErrorCodeEnum OnInit();
 	virtual ErrorCodeEnum OnExit();
 
-	void DoWork();
+	//void DoWork();
 
 
 	void s0_on_entry();
@@ -258,63 +208,37 @@ public:
 	void s5_on_entry();
 	void s5_on_exit();
 	unsigned int s5_on_event(FSMEvent* event);
+	void s6_on_entry();
+	void s6_on_exit();
+	unsigned int s6_on_event(FSMEvent* event);
 
 	int Initial();
-	int GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
-		,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
 	void push_char(char *buf, int *len, int c);
 	void PushInputChar(char *buf, int c);
 	void pop_char(char *buf, int *len,bool bClear=true);
 	void clear_char(char *buf, int *len);
 	bool Get12Account(char *szAcc);
-	void OpenInputText(void *pUserdata);
-	ErrorCodeEnum GetText(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
-		,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
-	ErrorCodeEnum GetEncryptText(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
-		,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
-	bool GetDevInitFlag(){ return m_bDevInit;}
-	bool IsRVCIL() { /*return m_bRVCIL; */ return false;}//oilyang@20190123 方案改了,这里暂时不需要了 
+	int GetInput(SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM);
+	ErrorCodeEnum GetEncryptText(SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM);
+	bool GetDevInitFlag(){ return m_bOpened;}
+	void ResetDevInitFlag() { m_bOpened = false; }
 	void SetExitFlag(){m_bExit = true;}
 	bool GetEntityExit() { return m_bEntityExit;}
-	void SetCtx(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
-		,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSMCtx=false)
+	void SetCtx(SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM)
 	{
-		LOG_FUNCTION();
-		if (!bSMCtx)
-		{
-			m_inputSMCtx = NULL;
-			m_ctx = ctx;
-			if (!ctx->Req.encrypt)
-				m_inputCtx = ctx;
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("confirm,encrypt,len,timeout:%d,%d,%d,%d", m_ctx->Req.confirm, m_ctx->Req.encrypt, m_ctx->Req.length, m_ctx->Req.timeout);
-		}
-		else
-		{
-			m_ctx = NULL;
-			m_inputSMCtx = ctxSM;
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("sm ctx,confirm,encrypt,len,timeout:%d,%d,%d,%d", m_inputSMCtx->Req.confirm, m_inputSMCtx->Req.encrypt, m_inputSMCtx->Req.length, m_inputSMCtx->Req.timeout);
-		}
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("setpininput true");
+		m_inputSMCtx = ctxSM;
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("sm ctx,confirm,encrypt,len,timeout:%d,%d,%d,%d,smflag:%d", ctxSM->Req.confirm
+			, ctxSM->Req.encrypt, ctxSM->Req.length, ctxSM->Req.timeout, ctxSM->Req.smflag);
 		m_bPinInput = true;
 	}
-	bool GetCtx(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer &ctx
-		,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer &ctxSM,bool &smFlag)
+	bool GetCtx(SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer& ctxSM)
 	{
-		if (m_ctx == NULL && m_inputSMCtx == NULL)
+		if (m_inputSMCtx == NULL)
 		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("both ctx is null");
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("ctxSM is null");
 			return false;
 		}
-		if (m_inputSMCtx != NULL)
-		{
-			ctxSM = m_inputSMCtx;
-			smFlag = true;
-		}
-		else
-		{
-			ctx = m_ctx;
-			smFlag = false;
-		}
+		ctxSM = m_inputSMCtx;
 		return true;
 	}
 	template <class TReq, class TAns>
@@ -329,14 +253,10 @@ public:
 		else
 			return NULL;
 	}
-	//HANDLE GetInputEvtHandle(){return m_hInputEvt;}
-	
 	bool GetDevInfo(DevCategoryInfo &devInfo);
-	int LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx);
-	int Encrypt(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx);
 	int LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx);
 	int EncryptSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx);
-	int GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx);
+	ErrorCodeEnum GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx);
 	int GetEncryptKey(int &devFunc,int &loadFunc)
 	{
 		devFunc = loadFunc = 0;
@@ -346,47 +266,43 @@ public:
 			tmp = 1;
 		if (m_bSMLoaded)
 			tmp += 2;
-		loadFunc = tmp;
+		
+		if (m_bSMLoaded)
+			loadFunc = 2;
+		else
+			loadFunc = tmp;
 		//20161216 oilyang add 为了兼容密钥更新有问题的设备
 		if (loadFunc == 0)
 			loadFunc = 1;
 		return 0;
 	}
-	BOOL IsNeedPinPad()
-	{
-		return (!m_bPinPadNeedless);
-	}
-	void SetEnterMainPage(bool bValue);
-	int LocalCallHeartBeat(int method, CBlob &bbSend, bool bTwoWay=false);
-	void CrossTermCall(SpReqAnsContext<PinPadService_CrossTermCall_Req, PinPadService_CrossTermCall_Ans>::Pointer ctx);
-	void CrossTermInvokeInfo(SpOnewayCallContext<PinPadService_CrossTermInvokeInfo_Info>::Pointer ctx);
+
+	void SetInWhatPage(int iPageType);
 	void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
+	void ToLogWarnInfoAboutTermCustom();
+	int ProcFWBReConn();
 public:
 	SP::Toolkit::CConditionVarPlus m_hInputConVar;
 	SP::Toolkit::CConditionVarPlus m_hInitConVar;
 private:
 
-	SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer m_ctx;
-	SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer m_inputCtx;
 	SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer m_inputSMCtx;
 	char m_szAccount[MAX_ACCOUNT_LEN];
-	bool m_bDevInit,m_bFrontCancel,m_bWaitingMore,m_bExit,m_bPlainPin,m_bEntityExit
-		,m_bPinInput,m_bPlainOpen,m_bLoadKey,m_bEncrypt,m_bSM,m_b3DESLoaded,m_bSMLoaded,m_bInMainPage
-		, m_bRVCIL;
-
-	CSimpleStringA m_deviceNo,m_devCheckData,m_keySN,m_keySNSM,m_szModel,m_szType,m_szVendor, m_devSN;
+	bool m_bFrontCancel,m_bWaitingMore,m_bExit,m_bPlainPin,m_bEntityExit
+		,m_bPinInput,m_bLoadKey,m_bEncrypt,m_bSM,m_b3DESLoaded,m_bSMLoaded;
+	ULLINT m_ullBeginTime, m_ullEndTime;
+	CSimpleStringA m_deviceNo, m_port, m_Baudrate, m_devCheckData,m_keySN,m_keySNSM,m_szModel,m_szType,m_szVendor,m_devSN/*fwb SN*/;
 	char m_buf[4];
 	ErrorCodeEnum m_testResult;
 	DWORD m_dwDevCommFailCount,m_dwPinPadRunCount;
 	DevStateEnum m_eDevState;
 	int m_encryptkey;
-	CSimpleStringA m_csMachineType, m_csSite, m_terminalNo;
-	BOOL m_bPinPadNeedless;
+	int m_iInWhatPage/*在哪个页面,区分首页,用户桌面,其他页*/;
+	CSimpleStringA m_csMachineType, m_csSite, m_terminalNo,m_lastCheckCode;
 
 	CSimpleStringA m_csAlarmMsg;
 	map<int, CtxInfo> m_mapCtx;
-
-	bool GetAttachedTerminal(CSimpleStringA &csTerm);
+	bool IsInBusiness() { return (m_iInWhatPage == PageType_Other); }
 };
 
 struct InitTask : public ITaskSp
@@ -402,58 +318,7 @@ struct InitTask : public ITaskSp
 		fsm->PostEventFIFO(e);
 	}
 };
-//struct GetInputTask : public ITaskSp
-//{
-//	CPinPadFSM* fsm;
-//	SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx;
-//	GetInputTask(CPinPadFSM* f) : fsm(f) {}
-//	void Process()
-//	{
-//		LOG_FUNCTION();
-//		FSMEvent *e = new FSMEvent(USER_EVT_GETINPUTFINISHED);
-//		e->param1 = fsm->GetInput(ctx);
-//		fsm->PostEventFIFO(e);
-//	}
-//};
-struct LoadKeyTask : public ITaskSp
-{
-	CPinPadFSM* fsm;
-	SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx;
-	LoadKeyTask(CPinPadFSM* f) : fsm(f) {}
-	void Process()
-	{
-		LOG_FUNCTION();
-		FSMEvent *e = new FSMEvent(USER_EVT_LOADKEYFINISHED);
-		e->param1 = fsm->LoadKey(ctx);
-		fsm->PostEventFIFO(e);
-	}
-};
-struct EncryptTask : public ITaskSp
-{
-	CPinPadFSM* fsm;
-	SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx;
-	EncryptTask(CPinPadFSM* f) : fsm(f) {}
-	void Process()
-	{
-		LOG_FUNCTION();
-		FSMEvent *e = new FSMEvent(USER_EVT_ENCRYPTFINISHED);
-		e->param1 = fsm->Encrypt(ctx);
-		fsm->PostEventFIFO(e);
-	}
-};
-//struct GetInputSMTask : public ITaskSp
-//{
-//	CPinPadFSM* fsm;
-//	SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx;
-//	GetInputSMTask(CPinPadFSM* f) : fsm(f) {}
-//	void Process()
-//	{
-//		LOG_FUNCTION();
-//		FSMEvent *e = new FSMEvent(USER_EVT_GETINPUT_SM_FINISHED);
-//		e->param1 = fsm->GetInput(ctx);
-//		fsm->PostEventFIFO(e);
-//	}
-//};
+
 struct LoadKeySMTask : public ITaskSp
 {
 	CPinPadFSM* fsm;
@@ -487,12 +352,22 @@ struct GetCheckCodeTask : public ITaskSp
 	GetCheckCodeTask(CPinPadFSM* f) : fsm(f) {}
 	void Process()
 	{
-		LOG_FUNCTION();
 		FSMEvent *e = new FSMEvent(USER_EVT_GET_CHECKCODE_FINISHED);
 		e->param1 = fsm->GetCheckCode(ctx);
 		fsm->PostEventFIFO(e);
 	}
 };
+struct ProcFWBReConnTask : public ITaskSp
+{
+	CPinPadFSM* fsm;
+	ProcFWBReConnTask(CPinPadFSM* f) : fsm(f) {}
+	void Process()
+	{
+		FSMEvent* e = new FSMEvent(USER_EVT_TODO_INIT_FINISHED);
+		e->param1 = fsm->ProcFWBReConn();
+		fsm->PostEventFIFO(e);
+	}
+};
 template<class T>
 class TimerOutHelper : public ITimerListener
 {

+ 2 - 1
Module/mod_pinpad/PinPad_UserErrorCode.h

@@ -41,5 +41,6 @@
 //LogWarn real root config
 #define PinPad_UserErrorCode_PinPad_Real_Root_Config				(PinPad_UserErrorCode_Start + 31)
 #define PinPad_UserErrorCode_PinPad_GetPinBlock_Call				(PinPad_UserErrorCode_Start + 32)
-
+#define PinPad_UserErrorCode_Unexpected_Exit						(PinPad_UserErrorCode_Start + 33)
+#define PinPad_UserErrorCode_UnknownSMFlag							(PinPad_UserErrorCode_Start + 34)
 #endif //_PINPAD_USER_ERROR_CODE_H

+ 0 - 64
Module/mod_pinpad/PinPad_client_g.h

@@ -493,70 +493,6 @@ public:
 		return Error;
 	}
 
-	ErrorCodeEnum CrossTermCall(PinPadService_CrossTermCall_Req &Req, CSmartPointer<IAsynWaitSp> &spAsyncWait, DWORD dwTimeout)
-	{
-		CSmartPointer<IClientSessionFunction> pFunc = GetFunction();
-		CAutoBuffer Buf = SpObject2Buffer(Req);
-		if (m_context.checkEmpty())
-		{
-			m_context.AutoGenerate();
-			DbgToBeidou(m_context, m_pEntityBase != NULL ? m_pEntityBase->GetEntityName() : "")();
-			m_context = m_context.upgradeLink();
-		}
-		auto ret = pFunc->AsyncRequest(PinPadService_Method_CrossTermCall, PinPadService_MethodSignature_CrossTermCall, Buf, spAsyncWait, m_context, dwTimeout);
-		m_context.clear();
-		return ret;
-	}
-	ErrorCodeEnum CrossTermCall(PinPadService_CrossTermCall_Req &Req, PinPadService_CrossTermCall_Ans &Ans, DWORD dwTimeout)
-	{
-		CSmartPointer<IAsynWaitSp> spAsyncWait;
-		ErrorCodeEnum Error = CrossTermCall(Req, spAsyncWait, dwTimeout);
-		if (Error == Error_Succeed) {
-			bool bEnd = false;
-			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwTimeout);
-			LOG_ASSERT(Error || bEnd);
-		}
-		return Error;
-	}
-	ErrorCodeEnum CrossTermCall(PinPadService_CrossTermCall_Req &Req, PinPadService_CrossTermCall_Ans &Ans, DWORD dwTimeout, DWORD &dwUserError, CSimpleString &str)
-	{
-		CSmartPointer<IAsynWaitSp> spAsyncWait;
-		ErrorCodeEnum Error = CrossTermCall(Req, spAsyncWait, dwTimeout);
-		if (Error == Error_Succeed) {
-			bool bEnd = false;
-			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
-			LOG_ASSERT(Error || bEnd);
-		}
-		return Error;
-	}
-	ErrorCodeEnum CrossTermCall(PinPadService_CrossTermCall_Req &Req, PinPadService_CrossTermCall_Ans &Ans, DWORD dwTimeout, DWORD &dwUserError)
-	{
-		CSmartPointer<IAsynWaitSp> spAsyncWait;
-		ErrorCodeEnum Error = CrossTermCall(Req, spAsyncWait, dwTimeout);
-		if (Error == Error_Succeed) {
-			bool bEnd = false;
-			CSimpleString str;
-			Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd, dwUserError, str, dwTimeout);
-			LOG_ASSERT(Error || bEnd);
-		}
-		return Error;
-	}
-
-	ErrorCodeEnum CrossTermInvokeInfo(PinPadService_CrossTermInvokeInfo_Info &Info)
-	{
-		CSmartPointer<IClientSessionFunction> pFunc = GetFunction();
-		if (m_context.checkEmpty())
-		{
-			m_context.AutoGenerate();
-			DbgToBeidou(m_context, m_pEntityBase != NULL ? m_pEntityBase->GetEntityName() : "")();
-			m_context = m_context.upgradeLink();
-		}
-		CAutoBuffer Buf = SpObject2Buffer(Info);
-		auto ret = pFunc->OnewayCall(PinPadService_Method_CrossTermInvokeInfo, PinPadService_MethodSignature_CrossTermInvokeInfo, Buf, m_context);
-		m_context.clear();
-		return ret;
-	}
-
 	ErrorCodeEnum GetDevInfo(PinPadService_GetDevInfo_Req &Req, CSmartPointer<IAsynWaitSp> &spAsyncWait, DWORD dwTimeout)
 	{
 		CSmartPointer<IClientSessionFunction> pFunc = GetFunction();

+ 13 - 68
Module/mod_pinpad/PinPad_def_g.h

@@ -23,8 +23,6 @@ namespace PinPad {
 #define PinPadService_Method_EncryptDataSM 8
 #define PinPadService_Method_QueryFunc 9
 #define PinPadService_Method_GetCheckCode 10
-#define PinPadService_Method_CrossTermCall 11
-#define PinPadService_Method_CrossTermInvokeInfo 12
 #define PinPadService_Method_GetDevInfo 65535
 
 #define PinPadService_MethodSignature_GetInput 90833662
@@ -38,10 +36,21 @@ namespace PinPad {
 #define PinPadService_MethodSignature_EncryptDataSM 1251510330
 #define PinPadService_MethodSignature_QueryFunc -775927908
 #define PinPadService_MethodSignature_GetCheckCode -1480133527
-#define PinPadService_MethodSignature_CrossTermCall -2042776719
-#define PinPadService_MethodSignature_CrossTermInvokeInfo 54854091
 #define PinPadService_MethodSignature_GetDevInfo 296205965
 
+#define PinPadService_LogCode_GetInput "QLR040220600"
+#define PinPadService_LogCode_InputWaitMore "QLR040220601"
+#define PinPadService_LogCode_InputCancel "QLR040220602"
+#define PinPadService_LogCode_Exit "QLR040220603"
+#define PinPadService_LogCode_LoadKeys "QLR040220604"
+#define PinPadService_LogCode_EncryptData "QLR040220605"
+#define PinPadService_LogCode_GetInputSM "QLR040220606"
+#define PinPadService_LogCode_LoadKeysSM "QLR040220607"
+#define PinPadService_LogCode_EncryptDataSM "QLR040220608"
+#define PinPadService_LogCode_QueryFunc "QLR040220609"
+#define PinPadService_LogCode_GetCheckCode "QLR040220610"
+#define PinPadService_LogCode_GetDevInfo "QLR040220699"
+
 struct PinPadService_GetInput_Req
 {
 	int timeout;
@@ -303,70 +312,6 @@ struct PinPadService_GetCheckCode_Ans
 
 };
 
-struct PinPadService_CrossTermCall_Req
-{
-	int type;
-	CSimpleStringA fromTerminalNo;
-	CSimpleStringA toTerminalNo;
-	int nEntityID;
-	CSimpleStringA param1;
-	CSimpleStringA param2;
-	int param3;
-	int param4;
-	CBlob paramX;
-	CAutoArray<int> reserved1;
-	CAutoArray<CSimpleStringA> reserved2;
-	CAutoArray<CBlob> reservedX;
-
-	void Serialize(SpBuffer &Buf)
-	{
-		auto & buf = Buf & type & fromTerminalNo & toTerminalNo & nEntityID & param1 & param2 & param3 & param4 & paramX & reserved1 & reserved2 & reservedX;
-	}
-
-};
-
-struct PinPadService_CrossTermCall_Ans
-{
-	int retCode;
-	CSimpleStringA retParam1;
-	CSimpleStringA retParam2;
-	int retParam3;
-	int retParam4;
-	CBlob retParamX;
-	CAutoArray<int> reserved1;
-	CAutoArray<CSimpleStringA> reserved2;
-	CAutoArray<CBlob> reservedX;
-
-	void Serialize(SpBuffer &Buf)
-	{
-		auto & buf = Buf & retCode & retParam1 & retParam2 & retParam3 & retParam4 & retParamX & reserved1 & reserved2 & reservedX;
-	}
-
-};
-
-struct PinPadService_CrossTermInvokeInfo_Info
-{
-	int type;
-	int result;
-	CSimpleStringA fromTerminalNo;
-	CSimpleStringA toTerminalNo;
-	int nEntityID;
-	CSimpleStringA param1;
-	CSimpleStringA param2;
-	int param3;
-	int param4;
-	CBlob paramX;
-	CAutoArray<int> reserved1;
-	CAutoArray<CSimpleStringA> reserved2;
-	CAutoArray<CBlob> reservedX;
-
-	void Serialize(SpBuffer &Buf)
-	{
-		auto & buf = Buf & type & result & fromTerminalNo & toTerminalNo & nEntityID & param1 & param2 & param3 & param4 & paramX & reserved1 & reserved2 & reservedX;
-	}
-
-};
-
 struct PinPadService_GetDevInfo_Req
 {
 

+ 0 - 54
Module/mod_pinpad/PinPad_server_g.h

@@ -107,20 +107,6 @@ public:
 				Error = Error_MethodSignatureFailed;
 			}
 			break;
-		case PinPadService_Method_CrossTermCall:
-			if (dwSignature == PinPadService_MethodSignature_CrossTermCall) {
-				bOverlap = true;
-			} else {
-				Error = Error_MethodSignatureFailed;
-			}
-			break;
-		case PinPadService_Method_CrossTermInvokeInfo:
-			if (dwSignature == PinPadService_MethodSignature_CrossTermInvokeInfo) {
-				bOverlap = true;
-			} else {
-				Error = Error_MethodSignatureFailed;
-			}
-			break;
 		case PinPadService_Method_GetDevInfo:
 			if (dwSignature == PinPadService_MethodSignature_GetDevInfo) {
 				bOverlap = true;
@@ -194,16 +180,6 @@ public:
 				Error = Error_MethodSignatureFailed;
 			}
 			break;
-		case PinPadService_Method_CrossTermCall:
-			if (dwSignature != PinPadService_MethodSignature_CrossTermCall) {
-				Error = Error_MethodSignatureFailed;
-			}
-			break;
-		case PinPadService_Method_CrossTermInvokeInfo:
-			if (dwSignature != PinPadService_MethodSignature_CrossTermInvokeInfo) {
-				Error = Error_MethodSignatureFailed;
-			}
-			break;
 		case PinPadService_Method_GetDevInfo:
 			if (dwSignature != PinPadService_MethodSignature_GetDevInfo) {
 				Error = Error_MethodSignatureFailed;
@@ -271,16 +247,6 @@ public:
 	/// override by user
 	}
 
-	virtual void Handle_CrossTermCall(SpReqAnsContext<PinPadService_CrossTermCall_Req, PinPadService_CrossTermCall_Ans>::Pointer ctx)
-	{
-	/// override by user
-	}
-
-	virtual void Handle_CrossTermInvokeInfo(SpOnewayCallContext<PinPadService_CrossTermInvokeInfo_Info>::Pointer ctx)
-	{
-	/// override by user
-	}
-
 	virtual void Handle_GetDevInfo(SpReqAnsContext<PinPadService_GetDevInfo_Req, PinPadService_GetDevInfo_Ans>::Pointer ctx)
 	{
 	/// override by user
@@ -412,26 +378,6 @@ public:
 						Handle_GetCheckCode(ctx);
 					}
 					break;
-				case PinPadService_Method_CrossTermCall:
-					{
-						SpReqAnsContext<PinPadService_CrossTermCall_Req,PinPadService_CrossTermCall_Ans>::Pointer ctx;
-						ctx.Attach(new SpReqAnsContext<PinPadService_CrossTermCall_Req,PinPadService_CrossTermCall_Ans>(pTransactionContext));
-						SpBuffer2Object(Buf, ctx->Req);
-						pTransactionContext->GetLinkContext(ctx->link);
-						EntityResource::setLink(ctx->link);
-						Handle_CrossTermCall(ctx);
-					}
-					break;
-				case PinPadService_Method_CrossTermInvokeInfo:
-					{
-						SpOnewayCallContext<PinPadService_CrossTermInvokeInfo_Info>::Pointer ctx;
-						ctx.Attach(new SpOnewayCallContext<PinPadService_CrossTermInvokeInfo_Info>());
-						SpBuffer2Object(Buf, ctx->Info);
-						pTransactionContext->GetLinkContext(ctx->link);
-						EntityResource::setLink(ctx->link);
-						Handle_CrossTermInvokeInfo(ctx);
-					}
-					break;
 				case PinPadService_Method_GetDevInfo:
 					{
 						SpReqAnsContext<PinPadService_GetDevInfo_Req,PinPadService_GetDevInfo_Ans>::Pointer ctx;

+ 39 - 71
Module/mod_pinpad/mod_PinPad.h

@@ -10,20 +10,15 @@ class PinPadServerSession : public PinPad::PinPadService_ServerSessionBase
 public:
 	PinPadServerSession(CPinPadEntity* pEntity):m_pEntity(pEntity){}
 	virtual ~PinPadServerSession(){}
-	void Handle_GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx);
 	void Handle_InputWaitMore(SpOnewayCallContext<PinPadService_InputWaitMore_Info>::Pointer ctx);
 	void Handle_InputCancel(SpOnewayCallContext<PinPadService_InputCancel_Info>::Pointer ctx);
 	void Handle_Exit(SpOnewayCallContext<PinPadService_Exit_Info>::Pointer ctx);
-	void Handle_LoadKeys(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx);
-	void Handle_EncryptData(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx);
 	void Handle_GetDevInfo(SpReqAnsContext<PinPadService_GetDevInfo_Req, PinPadService_GetDevInfo_Ans>::Pointer ctx);
 	void Handle_GetInputSM(SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx);
 	void Handle_LoadKeysSM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx);
 	void Handle_EncryptDataSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx);
 	void Handle_QueryFunc(SpReqAnsContext<PinPadService_QueryFunc_Req, PinPadService_QueryFunc_Ans>::Pointer ctx);
 	void Handle_GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx);
-	void Handle_CrossTermCall(SpReqAnsContext<PinPadService_CrossTermCall_Req, PinPadService_CrossTermCall_Ans>::Pointer ctx);
-	void Handle_CrossTermInvokeInfo(SpOnewayCallContext<PinPadService_CrossTermInvokeInfo_Info>::Pointer ctx);
 private:
 	CPinPadEntity* m_pEntity;
 };
@@ -37,9 +32,11 @@ public:
 
 	virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext) 
 	{ 
-		GetVendorLibName();
 		ErrorCodeEnum Error = __OnStart(Error_Succeed);
 		GetFunction()->RegistSysVarEvent("UIState", this);
+#if defined(RVC_OS_WIN)
+		GetFunction()->RegistSysVarEvent("FWBReConn", this);
+#endif
 		pTransactionContext->SendAnswer(Error);
 	}
 
@@ -73,18 +70,9 @@ public:
 
 	virtual CServerSessionBase* OnNewSession(const char*,const char*)
 	{
-		LOG_FUNCTION();
 		return new PinPadServerSession(this);
 	}
 
-	void GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx)
-	{
-		LOG_FUNCTION();
-		GetInputEvent *e = new GetInputEvent();
-		e->ctx = ctx;
-		m_fsm.SetCtx(ctx,NULL);
-		m_fsm.PostEventFIFO(e);
-	}
 	void InputWaitMore(SpOnewayCallContext<PinPadService_InputWaitMore_Info>::Pointer ctx)
 	{
 		LOG_FUNCTION();
@@ -104,99 +92,79 @@ public:
 		FSMEvent *evt = new FSMEvent(USER_EVT_EXIT);
 		m_fsm.PostEventFIFO(evt);
 	}
-	void LoadKeys(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx)
-	{
-		LOG_FUNCTION();
-		LoadKeyEvent *evt = new LoadKeyEvent();
-		evt->ctx = ctx;
-		m_fsm.PostEventFIFO(evt);
-	}
 
-	void EncryptData(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx)
-	{
-		LOG_FUNCTION();
-		EncryptEvent *evt = new EncryptEvent();
-		evt->ctx = ctx;
-		m_fsm.PostEventFIFO(evt);
-	}
 	void GetInputSM(SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx)
 	{
-		LOG_FUNCTION();
-		m_fsm.SetCtx(NULL, ctx, true);
-		if (m_fsm.IsRVCIL())
+		if (!m_fsm.GetDevInitFlag())
 		{
-			CBlob bbSend;
-			SpObject2Blob(ctx->Req, bbSend);
-			//m_fsm.SaveCtx(PinPadService_Method_GetInputSM, ctx);
-			//ctx.AddRef();
-			m_fsm.LocalCallHeartBeat(PinPadService_Method_GetInputSM, bbSend,true);
-		}
-		else
-		{
-			GetInputSMEvent *e = new GetInputSMEvent();
+			ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
+			LogWarn(Severity_Middle, Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed, "Open PinPad failed(GetInputSM)");
+		}else{
+			m_fsm.SetCtx(ctx);
+			GetInputSMEvent* e = new GetInputSMEvent();
 			e->ctx = ctx;
 			m_fsm.PostEventFIFO(e);
-		}
+		}	
 	}
 	void LoadKeysSM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx)
 	{
 		LOG_FUNCTION();
-		LoadKeySMEvent *evt = new LoadKeySMEvent();
-		evt->ctx = ctx;
-		m_fsm.PostEventFIFO(evt);
+		if(!m_fsm.GetDevInitFlag())
+			ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
+		else{
+			LoadKeySMEvent *evt = new LoadKeySMEvent();
+			evt->ctx = ctx;
+			m_fsm.PostEventFIFO(evt);
+		}
 	}
 	void EncryptDataSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx)
 	{
 		LOG_FUNCTION();
-		EncryptSMEvent *evt = new EncryptSMEvent();
-		evt->ctx = ctx;
-		m_fsm.PostEventFIFO(evt);
+		if(!m_fsm.GetDevInitFlag())
+			ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
+		else{
+			EncryptSMEvent *evt = new EncryptSMEvent();
+			evt->ctx = ctx;
+			m_fsm.PostEventFIFO(evt);
+		}
 	}
 	void QueryFunc(SpReqAnsContext<PinPadService_QueryFunc_Req, PinPadService_QueryFunc_Ans>::Pointer ctx)
 	{
-		LOG_FUNCTION();
 		if (m_fsm.GetDevInitFlag())
 		{
 			m_fsm.GetEncryptKey(ctx->Ans.encryptkey, ctx->Ans.reserved1);
 			ctx->Answer(Error_Succeed);
 		}
-		else
-			ctx->Answer(Error_DevNotAvailable);
+		else{
+			ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
+		}
 	}
 	void GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx)
 	{
-		GetCheckCodeEvent *evt = new GetCheckCodeEvent();
-		evt->ctx = ctx;
-		m_fsm.PostEventFIFO(evt);
-	}
-	void CrossTermCall(SpReqAnsContext<PinPadService_CrossTermCall_Req, PinPadService_CrossTermCall_Ans>::Pointer ctx)
-	{
-		m_fsm.CrossTermCall(ctx);
-	}
-	void CrossTermInvokeInfo(SpOnewayCallContext<PinPadService_CrossTermInvokeInfo_Info>::Pointer ctx)
-	{
-		m_fsm.CrossTermInvokeInfo(ctx);
+		if(!m_fsm.GetDevInitFlag())
+			ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
+		else{
+			GetCheckCodeEvent *evt = new GetCheckCodeEvent();
+			evt->ctx = ctx;
+			m_fsm.PostEventFIFO(evt);
+		}
 	}
 	void GetDevInfo(SpReqAnsContext<PinPadService_GetDevInfo_Req, PinPadService_GetDevInfo_Ans>::Pointer ctx)
 	{
-		if(m_fsm.IsNeedPinPad())
+		if (m_fsm.GetDevInitFlag())
 		{
 			DevCategoryInfo devInfo;
+			memset(&devInfo, 0, sizeof(devInfo));
 			if (m_fsm.GetDevInfo(devInfo))
 			{
 				ctx->Ans.model = devInfo.szModel;
 				ctx->Ans.type = devInfo.szType;
-				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("szModel:%s", (const char*)ctx->Ans.model);
 			}
 			ctx->Ans.state = devInfo.eState;
+			ctx->Answer(Error_Succeed);
 		}
-		else // 回单打印设备 --Josephus at 8:08:22 201746
-		{
-			ctx->Ans.model = "";
-			ctx->Ans.type = "";
-			ctx->Ans.state = DEVICE_STATUS_NORMAL;
-		}
-		ctx->Answer(Error_Succeed);
+		else
+			ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
 	}
 	bool GetDevInitInfo() { return m_fsm.GetDevInitFlag(); }
 	virtual void OnSysVarEvent(const char *pszKey,

+ 32 - 41
Module/mod_pinpad/mod_pinpad.cpp

@@ -4,76 +4,60 @@
 #include "stdafx.h"
 #include "mod_PinPad.h"
 
-void PinPadServerSession::Handle_GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx)
-{
-	LOG_FUNCTION();
-	m_pEntity->GetInput(ctx);
-}
 void PinPadServerSession::Handle_InputWaitMore(SpOnewayCallContext<PinPadService_InputWaitMore_Info>::Pointer ctx)
 {
-	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setAPI("InputWaitMore")("InputWaitMore something u want to know...");
 	m_pEntity->InputWaitMore(ctx);
 }
 
 void PinPadServerSession::Handle_InputCancel(SpOnewayCallContext<PinPadService_InputCancel_Info>::Pointer ctx)
 {
-	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->InputCancel(ctx);
-	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("handle front cancel");
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setAPI("InputCancel")("handle front cancel");
 }
 void PinPadServerSession::Handle_Exit(SpOnewayCallContext<PinPadService_Exit_Info>::Pointer ctx)
 {
-	//LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setAPI("Exit")("handle exit");
 	m_pEntity->Exit(ctx);
 }
-void PinPadServerSession::Handle_LoadKeys(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx)
-{
-	LOG_FUNCTION();
-	m_pEntity->LoadKeys(ctx);
-}
-void PinPadServerSession::Handle_EncryptData(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx)
-{
-	LOG_FUNCTION();
-	m_pEntity->EncryptData(ctx);
-}
+
 void PinPadServerSession::Handle_GetInputSM(SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx)
 {
-	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setAPI("GetInputSM")("timeout:%d,length:%d,confirm:%d", ctx->Req.timeout,ctx->Req.length,ctx->Req.confirm);
 	m_pEntity->GetInputSM(ctx);
 }
 void PinPadServerSession::Handle_LoadKeysSM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx)
 {
-	LOG_FUNCTION();
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setAPI("LoadKeysSM")("LoadKeysSM,initializeflag:%d,smflag:%d", ctx->Req.initializeflag, ctx->Req.smflag);
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->LoadKeysSM(ctx);
 }
 void PinPadServerSession::Handle_EncryptDataSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx)
 {
-	LOG_FUNCTION();
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setAPI("EncryptDataSM")("EncryptDataSM,smflag:%d", ctx->Req.smflag);
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->EncryptDataSM(ctx);
 }
 void PinPadServerSession::Handle_QueryFunc(SpReqAnsContext<PinPadService_QueryFunc_Req, PinPadService_QueryFunc_Ans>::Pointer ctx)
 {
-	LOG_FUNCTION();
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setAPI("QueryFunc")();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->QueryFunc(ctx);
 }
 void PinPadServerSession::Handle_GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx)
 {
-	LOG_FUNCTION();
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setAPI("GetCheckCode")();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->GetCheckCode(ctx);
 }
-void PinPadServerSession::Handle_CrossTermCall(SpReqAnsContext<PinPadService_CrossTermCall_Req, PinPadService_CrossTermCall_Ans>::Pointer ctx)
-{
-	LOG_FUNCTION();
-	m_pEntity->CrossTermCall(ctx);
-}
-void PinPadServerSession::Handle_CrossTermInvokeInfo(SpOnewayCallContext<PinPadService_CrossTermInvokeInfo_Info>::Pointer ctx)
-{
-	LOG_FUNCTION();
-	m_pEntity->CrossTermInvokeInfo(ctx);
-}
 void PinPadServerSession::Handle_GetDevInfo(SpReqAnsContext<PinPadService_GetDevInfo_Req, PinPadService_GetDevInfo_Ans>::Pointer ctx)
 {
-	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setAPI("GetDevInfo")();
 	m_pEntity->GetDevInfo(ctx);
 }
 void CPinPadEntity::OnSysVarEvent(const char *pszKey,
@@ -82,15 +66,22 @@ void CPinPadEntity::OnSysVarEvent(const char *pszKey,
 	if ((_strnicmp(pszKey, "UIState", strlen("UIState")) == 0))
 	{
 		if (_strnicmp(pszValue, "M", strlen("M")) == 0)
-		{
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("enter main page");
-			m_fsm.SetEnterMainPage(true);
-		}
+			m_fsm.SetInWhatPage(PageType_MainPage);
+		else if (_strnicmp(pszValue, "U", strlen("U")) == 0)
+			m_fsm.SetInWhatPage(PageType_UserDesktop);
 		else
+			m_fsm.SetInWhatPage(PageType_Other);
+	}
+	if ((_strnicmp(pszKey, "FWBReConn", strlen("FWBReConn")) == 0))
+	{
+		//"Y":open suc "U":unbind
+		if (_strnicmp(pszValue, "Y", strlen("Y")) == 0 || _strnicmp(pszValue, "U", strlen("U")) == 0)
 		{
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("not main page[%s]", pszValue);
-			m_fsm.SetEnterMainPage(false);
+			FSMEvent* e = new FSMEvent(USER_EVT_TODO_INIT);
+			m_fsm.PostEventFIFO(e);
 		}
+		else if (_strnicmp(pszValue, "D", strlen("D")) == 0)
+			m_fsm.ResetDevInitFlag();
 	}
 }
 SP_BEGIN_ENTITY_MAP()

+ 1 - 43
Module/mod_pinpad/pinpad.xml

@@ -128,49 +128,7 @@
 			<res>
 				<param name="checkcode" type="array_string" />
 			</res>			
-		</twoway>
-		<twoway name="CrossTermCall" overlap="true">
-			<req>
-				<param name="type" type="int"/>
-				<param name="fromTerminalNo" type="string"/>
-				<param name="toTerminalNo" type="string"/>
-				<param name="nEntityID" type="int"/>
-				<param name="param1" type="string"/>
-				<param name="param2" type="string"/>
-				<param name="param3" type="int"/>
-				<param name="param4" type="int"/>
-				<param name="paramX" type="blob"/>
-				<param name="reserved1" type="array_int"/>
-				<param name="reserved2" type="array_string"/>
-				<param name="reservedX" type="array_blob"/>					
-			</req>
-			<res>
-				<param name="retCode" type="int"/>
-				<param name="retParam1" type="string"/>
-				<param name="retParam2" type="string"/>
-				<param name="retParam3" type="int"/>
-				<param name="retParam4" type="int"/>
-				<param name="retParamX" type="blob"/>
-				<param name="reserved1" type="array_int"/>
-				<param name="reserved2" type="array_string"/>
-				<param name="reservedX" type="array_blob"/>
-			</res>				
-		</twoway>
-		<oneway name="CrossTermInvokeInfo" overlap="true">
-				<param name="type" type="int"/>
-				<param name="result" type="int"/>
-				<param name="fromTerminalNo" type="string"/>
-				<param name="toTerminalNo" type="string"/>
-				<param name="nEntityID" type="int"/>
-				<param name="param1" type="string"/>
-				<param name="param2" type="string"/>
-				<param name="param3" type="int"/>
-				<param name="param4" type="int"/>
-				<param name="paramX" type="blob"/>
-				<param name="reserved1" type="array_int"/>
-				<param name="reserved2" type="array_string"/>
-				<param name="reservedX" type="array_blob"/>	
-		</oneway>										
+		</twoway>										
 		<twoway name="GetDevInfo" overlap="true" method_id="65535">
 			<req>
 			</req>

+ 344 - 0
Module/mod_pinpad/sm4.cpp

@@ -0,0 +1,344 @@
+/*
+ * SM4 Encryption alogrithm (SMS4 algorithm)
+ * GM/T 0002-2012 Chinese National Standard ref:http://www.oscca.gov.cn/ 
+ * thanks to Xyssl
+ * thnaks and refers to http://hi.baidu.com/numax/blog/item/80addfefddfb93e4cf1b3e61.html
+ * author:goldboar
+ * email:goldboar@163.com
+ * 2012-4-20
+ */
+
+// Test vector 1
+// plain: 01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10
+// key:   01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10
+// 	   round key and temp computing result:
+// 	   rk[ 0] = f12186f9 X[ 0] = 27fad345
+// 		   rk[ 1] = 41662b61 X[ 1] = a18b4cb2
+// 		   rk[ 2] = 5a6ab19a X[ 2] = 11c1e22a
+// 		   rk[ 3] = 7ba92077 X[ 3] = cc13e2ee
+// 		   rk[ 4] = 367360f4 X[ 4] = f87c5bd5
+// 		   rk[ 5] = 776a0c61 X[ 5] = 33220757
+// 		   rk[ 6] = b6bb89b3 X[ 6] = 77f4c297
+// 		   rk[ 7] = 24763151 X[ 7] = 7a96f2eb
+// 		   rk[ 8] = a520307c X[ 8] = 27dac07f
+// 		   rk[ 9] = b7584dbd X[ 9] = 42dd0f19
+// 		   rk[10] = c30753ed X[10] = b8a5da02
+// 		   rk[11] = 7ee55b57 X[11] = 907127fa
+// 		   rk[12] = 6988608c X[12] = 8b952b83
+// 		   rk[13] = 30d895b7 X[13] = d42b7c59
+// 		   rk[14] = 44ba14af X[14] = 2ffc5831
+// 		   rk[15] = 104495a1 X[15] = f69e6888
+// 		   rk[16] = d120b428 X[16] = af2432c4
+// 		   rk[17] = 73b55fa3 X[17] = ed1ec85e
+// 		   rk[18] = cc874966 X[18] = 55a3ba22
+// 		   rk[19] = 92244439 X[19] = 124b18aa
+// 		   rk[20] = e89e641f X[20] = 6ae7725f
+// 		   rk[21] = 98ca015a X[21] = f4cba1f9
+// 		   rk[22] = c7159060 X[22] = 1dcdfa10
+// 		   rk[23] = 99e1fd2e X[23] = 2ff60603
+// 		   rk[24] = b79bd80c X[24] = eff24fdc
+// 		   rk[25] = 1d2115b0 X[25] = 6fe46b75
+// 		   rk[26] = 0e228aeb X[26] = 893450ad
+// 		   rk[27] = f1780c81 X[27] = 7b938f4c
+// 		   rk[28] = 428d3654 X[28] = 536e4246
+// 		   rk[29] = 62293496 X[29] = 86b3e94f
+// 		   rk[30] = 01cf72e5 X[30] = d206965e
+// 		   rk[31] = 9124a012 X[31] = 681edf34
+// cypher: 68 1e df 34 d2 06 96 5e 86 b3 e9 4f 53 6e 42 46
+// 		
+// test vector 2
+// the same key and plain 1000000 times coumpting 
+// plain:  01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10
+// key:    01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10
+// cypher: 59 52 98 c7 c6 fd 27 1f 04 02 f8 04 c3 3d 3f 66
+#include "stdafx.h"
+#include "sm4.h"
+#include <string.h>
+#include <stdio.h>
+
+/*
+ * 32-bit integer manipulation macros (big endian)
+ */
+#ifndef GET_ULONG_BE
+#define GET_ULONG_BE(n,b,i)                             \
+{                                                       \
+    (n) = ( (unsigned long) (b)[(i)    ] << 24 )        \
+        | ( (unsigned long) (b)[(i) + 1] << 16 )        \
+        | ( (unsigned long) (b)[(i) + 2] <<  8 )        \
+        | ( (unsigned long) (b)[(i) + 3]       );       \
+}
+#endif
+
+#ifndef PUT_ULONG_BE
+#define PUT_ULONG_BE(n,b,i)                             \
+{                                                       \
+    (b)[(i)    ] = (unsigned char) ( (n) >> 24 );       \
+    (b)[(i) + 1] = (unsigned char) ( (n) >> 16 );       \
+    (b)[(i) + 2] = (unsigned char) ( (n) >>  8 );       \
+    (b)[(i) + 3] = (unsigned char) ( (n)       );       \
+}
+#endif
+
+/*
+ *rotate shift left marco definition
+ *
+ */
+#define  SHL(x,n) (((x) & 0xFFFFFFFF) << n)
+#define ROTL(x,n) (SHL((x),n) | ((x) >> (32 - n)))
+
+#define SWAP(a,b) { unsigned long t = a; a = b; b = t; t = 0; }
+
+/*
+ * Expanded SM4 S-boxes
+ /* Sbox table: 8bits input convert to 8 bits output*/
+ 
+static const unsigned char SboxTable[16][16] = 
+{
+{0xd6,0x90,0xe9,0xfe,0xcc,0xe1,0x3d,0xb7,0x16,0xb6,0x14,0xc2,0x28,0xfb,0x2c,0x05},
+{0x2b,0x67,0x9a,0x76,0x2a,0xbe,0x04,0xc3,0xaa,0x44,0x13,0x26,0x49,0x86,0x06,0x99},
+{0x9c,0x42,0x50,0xf4,0x91,0xef,0x98,0x7a,0x33,0x54,0x0b,0x43,0xed,0xcf,0xac,0x62},
+{0xe4,0xb3,0x1c,0xa9,0xc9,0x08,0xe8,0x95,0x80,0xdf,0x94,0xfa,0x75,0x8f,0x3f,0xa6},
+{0x47,0x07,0xa7,0xfc,0xf3,0x73,0x17,0xba,0x83,0x59,0x3c,0x19,0xe6,0x85,0x4f,0xa8},
+{0x68,0x6b,0x81,0xb2,0x71,0x64,0xda,0x8b,0xf8,0xeb,0x0f,0x4b,0x70,0x56,0x9d,0x35},
+{0x1e,0x24,0x0e,0x5e,0x63,0x58,0xd1,0xa2,0x25,0x22,0x7c,0x3b,0x01,0x21,0x78,0x87},
+{0xd4,0x00,0x46,0x57,0x9f,0xd3,0x27,0x52,0x4c,0x36,0x02,0xe7,0xa0,0xc4,0xc8,0x9e},
+{0xea,0xbf,0x8a,0xd2,0x40,0xc7,0x38,0xb5,0xa3,0xf7,0xf2,0xce,0xf9,0x61,0x15,0xa1},
+{0xe0,0xae,0x5d,0xa4,0x9b,0x34,0x1a,0x55,0xad,0x93,0x32,0x30,0xf5,0x8c,0xb1,0xe3},
+{0x1d,0xf6,0xe2,0x2e,0x82,0x66,0xca,0x60,0xc0,0x29,0x23,0xab,0x0d,0x53,0x4e,0x6f},
+{0xd5,0xdb,0x37,0x45,0xde,0xfd,0x8e,0x2f,0x03,0xff,0x6a,0x72,0x6d,0x6c,0x5b,0x51},
+{0x8d,0x1b,0xaf,0x92,0xbb,0xdd,0xbc,0x7f,0x11,0xd9,0x5c,0x41,0x1f,0x10,0x5a,0xd8},
+{0x0a,0xc1,0x31,0x88,0xa5,0xcd,0x7b,0xbd,0x2d,0x74,0xd0,0x12,0xb8,0xe5,0xb4,0xb0},
+{0x89,0x69,0x97,0x4a,0x0c,0x96,0x77,0x7e,0x65,0xb9,0xf1,0x09,0xc5,0x6e,0xc6,0x84},
+{0x18,0xf0,0x7d,0xec,0x3a,0xdc,0x4d,0x20,0x79,0xee,0x5f,0x3e,0xd7,0xcb,0x39,0x48}
+};
+
+/* System parameter */
+static const unsigned long FK[4] = {0xa3b1bac6,0x56aa3350,0x677d9197,0xb27022dc};
+
+/* fixed parameter */
+static const unsigned long CK[32] =
+{
+0x00070e15,0x1c232a31,0x383f464d,0x545b6269,
+0x70777e85,0x8c939aa1,0xa8afb6bd,0xc4cbd2d9,
+0xe0e7eef5,0xfc030a11,0x181f262d,0x343b4249,
+0x50575e65,0x6c737a81,0x888f969d,0xa4abb2b9,
+0xc0c7ced5,0xdce3eaf1,0xf8ff060d,0x141b2229,
+0x30373e45,0x4c535a61,0x686f767d,0x848b9299,
+0xa0a7aeb5,0xbcc3cad1,0xd8dfe6ed,0xf4fb0209,
+0x10171e25,0x2c333a41,0x484f565d,0x646b7279
+};
+
+
+/*
+ * private function:
+ * look up in SboxTable and get the related value.
+ * args:    [in] inch: 0x00~0xFF (8 bits unsigned value).
+ */
+static unsigned char sm4Sbox(unsigned char inch)
+{
+    unsigned char *pTable = (unsigned char *)SboxTable;
+    unsigned char retVal = (unsigned char)(pTable[inch]);
+    return retVal;
+}
+
+/*
+ * private F(Lt) function:
+ * "T algorithm" == "L algorithm" + "t algorithm".
+ * args:    [in] a: a is a 32 bits unsigned value;
+ * return: c: c is calculated with line algorithm "L" and nonline algorithm "t"
+ */
+static unsigned long sm4Lt(unsigned long ka)
+{
+    unsigned long bb = 0;
+    unsigned long c = 0;
+    unsigned char a[4];
+	unsigned char b[4];
+    PUT_ULONG_BE(ka,a,0)
+    b[0] = sm4Sbox(a[0]);
+    b[1] = sm4Sbox(a[1]);
+    b[2] = sm4Sbox(a[2]);
+    b[3] = sm4Sbox(a[3]);
+	GET_ULONG_BE(bb,b,0)
+    c =bb^(ROTL(bb, 2))^(ROTL(bb, 10))^(ROTL(bb, 18))^(ROTL(bb, 24));
+    return c;
+}
+
+/*
+ * private F function:
+ * Calculating and getting encryption/decryption contents.
+ * args:    [in] x0: original contents;
+ * args:    [in] x1: original contents;
+ * args:    [in] x2: original contents;
+ * args:    [in] x3: original contents;
+ * args:    [in] rk: encryption/decryption key;
+ * return the contents of encryption/decryption contents.
+ */
+static unsigned long sm4F(unsigned long x0, unsigned long x1, unsigned long x2, unsigned long x3, unsigned long rk)
+{
+    return (x0^sm4Lt(x1^x2^x3^rk));
+}
+
+
+/* private function:
+ * Calculating round encryption key.
+ * args:    [in] a: a is a 32 bits unsigned value;
+ * return: sk[i]: i{0,1,2,3,...31}.
+ */
+static unsigned long sm4CalciRK(unsigned long ka)
+{
+    unsigned long bb = 0;
+    unsigned long rk = 0;
+    unsigned char a[4];
+    unsigned char b[4];
+    PUT_ULONG_BE(ka,a,0)
+    b[0] = sm4Sbox(a[0]);
+    b[1] = sm4Sbox(a[1]);
+    b[2] = sm4Sbox(a[2]);
+    b[3] = sm4Sbox(a[3]);
+	GET_ULONG_BE(bb,b,0)
+    rk = bb^(ROTL(bb, 13))^(ROTL(bb, 23));
+    return rk;
+}
+
+static void sm4_setkey( unsigned long SK[32], unsigned char key[16] )
+{
+    unsigned long MK[4];
+    unsigned long k[36];
+    unsigned long i = 0;
+
+    GET_ULONG_BE( MK[0], key, 0 );
+    GET_ULONG_BE( MK[1], key, 4 );
+    GET_ULONG_BE( MK[2], key, 8 );
+    GET_ULONG_BE( MK[3], key, 12 );
+    k[0] = MK[0]^FK[0];
+    k[1] = MK[1]^FK[1];
+    k[2] = MK[2]^FK[2];
+    k[3] = MK[3]^FK[3];
+    for(; i<32; i++)
+    {
+        k[i+4] = k[i] ^ (sm4CalciRK(k[i+1]^k[i+2]^k[i+3]^CK[i]));
+        SK[i] = k[i+4];
+	}
+
+}
+
+/*
+ * SM4 standard one round processing
+ *
+ */
+static void sm4_one_round( unsigned long sk[32],
+                    unsigned char input[16],
+                    unsigned char output[16] )
+{
+    unsigned long i = 0;
+    unsigned long ulbuf[36];
+
+    memset(ulbuf, 0, sizeof(ulbuf));
+    GET_ULONG_BE( ulbuf[0], input, 0 )
+    GET_ULONG_BE( ulbuf[1], input, 4 )
+    GET_ULONG_BE( ulbuf[2], input, 8 )
+    GET_ULONG_BE( ulbuf[3], input, 12 )
+    while(i<32)
+    {
+        ulbuf[i+4] = sm4F(ulbuf[i], ulbuf[i+1], ulbuf[i+2], ulbuf[i+3], sk[i]);
+// #ifdef _DEBUG
+//        	printf("rk(%02d) = 0x%08x,  X(%02d) = 0x%08x \n",i,sk[i], i, ulbuf[i+4] );
+// #endif
+	    i++;
+    }
+	PUT_ULONG_BE(ulbuf[35],output,0);
+	PUT_ULONG_BE(ulbuf[34],output,4);
+	PUT_ULONG_BE(ulbuf[33],output,8);
+	PUT_ULONG_BE(ulbuf[32],output,12);
+}
+
+/*
+ * SM4 key schedule (128-bit, encryption)
+ */
+void sm4_setkey_enc( sm4_context *ctx, unsigned char key[16] )
+{
+    ctx->mode = SM4_ENCRYPT;
+	sm4_setkey( ctx->sk, key );
+}
+
+/*
+ * SM4 key schedule (128-bit, decryption)
+ */
+void sm4_setkey_dec( sm4_context *ctx, unsigned char key[16] )
+{
+    int i;
+	ctx->mode = SM4_ENCRYPT;
+    sm4_setkey( ctx->sk, key );
+    for( i = 0; i < 16; i ++ )
+    {
+        SWAP( ctx->sk[ i ], ctx->sk[ 31-i] );
+    }
+}
+
+
+/*
+ * SM4-ECB block encryption/decryption
+ */
+
+void sm4_crypt_ecb( sm4_context *ctx,
+				   int mode,
+				   int length,
+				   unsigned char *input,
+                   unsigned char *output)
+{
+    while( length > 0 )
+    {
+        sm4_one_round( ctx->sk, input, output );
+        input  += 16;
+        output += 16;
+        length -= 16;
+    }
+
+}
+
+/*
+ * SM4-CBC buffer encryption/decryption
+ */
+void sm4_crypt_cbc( sm4_context *ctx,
+                    int mode,
+                    int length,
+                    unsigned char iv[16],
+                    unsigned char *input,
+                    unsigned char *output )
+{
+    int i;
+    unsigned char temp[16];
+
+    if( mode == SM4_ENCRYPT )
+    {
+        while( length > 0 )
+        {
+            for( i = 0; i < 16; i++ )
+                output[i] = (unsigned char)( input[i] ^ iv[i] );
+
+            sm4_one_round( ctx->sk, output, output );
+            memcpy( iv, output, 16 );
+
+            input  += 16;
+            output += 16;
+            length -= 16;
+        }
+    }
+    else /* SM4_DECRYPT */
+    {
+        while( length > 0 )
+        {
+            memcpy( temp, input, 16 );
+            sm4_one_round( ctx->sk, input, output );
+
+            for( i = 0; i < 16; i++ )
+                output[i] = (unsigned char)( output[i] ^ iv[i] );
+
+            memcpy( iv, temp, 16 );
+
+            input  += 16;
+            output += 16;
+            length -= 16;
+        }
+    }
+}

+ 75 - 0
Module/mod_pinpad/sm4.h

@@ -0,0 +1,75 @@
+/**
+ * \file sm4.h
+ */
+#ifndef XYSSL_SM4_H
+#define XYSSL_SM4_H
+
+#define SM4_ENCRYPT     1
+#define SM4_DECRYPT     0
+
+/**
+ * \brief          SM4 context structure
+ */
+typedef struct
+{
+    int mode;                   /*!<  encrypt/decrypt   */
+    unsigned long sk[32];       /*!<  SM4 subkeys       */
+}
+sm4_context;
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief          SM4 key schedule (128-bit, encryption)
+ *
+ * \param ctx      SM4 context to be initialized
+ * \param key      16-byte secret key
+ */
+void sm4_setkey_enc( sm4_context *ctx, unsigned char key[16] );
+
+/**
+ * \brief          SM4 key schedule (128-bit, decryption)
+ *
+ * \param ctx      SM4 context to be initialized
+ * \param key      16-byte secret key
+ */
+void sm4_setkey_dec( sm4_context *ctx, unsigned char key[16] );
+
+/**
+ * \brief          SM4-ECB block encryption/decryption
+ * \param ctx      SM4 context
+ * \param mode     SM4_ENCRYPT or SM4_DECRYPT
+ * \param length   length of the input data
+ * \param input    input block
+ * \param output   output block
+ */
+void sm4_crypt_ecb( sm4_context *ctx,
+				     int mode,
+					 int length,
+                     unsigned char *input,
+                     unsigned char *output);
+
+/**
+ * \brief          SM4-CBC buffer encryption/decryption
+ * \param ctx      SM4 context
+ * \param mode     SM4_ENCRYPT or SM4_DECRYPT
+ * \param length   length of the input data
+ * \param iv       initialization vector (updated after use)
+ * \param input    buffer holding the input data
+ * \param output   buffer holding the output data
+ */
+void sm4_crypt_cbc( sm4_context *ctx,
+                     int mode,
+                     int length,
+                     unsigned char iv[16],
+                     unsigned char *input,
+                     unsigned char *output );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* sm4.h */

+ 10 - 5
addin/cfg/UserCodeToMsgTip.ini

@@ -3,6 +3,7 @@
 0x20100215=[RTA2102] [HWC] 身份证模块未成功连接,请确认是否已连接蓝牙多合一
 0x20100216=[RTA2103] [HW] 蓝牙多合一断开,请确认蓝牙多合一连接正常后重试
 0x2010021A=[RTA2104] [HW] 读取身份证失败,请联系厂商检查硬件是否正常
+0x2010021B=[RTA2105] [HW] 读证件异常退出,请联系厂商检查硬件是否正常
 
 0x20200006=[RTA2201] [HW] 读卡失败,请拿起卡片重试
 0x2020000D=[RTA2202] [HW] 读卡失败,请拿起卡片重试
@@ -77,13 +78,17 @@
 0x203002E4=[RTA2394] [HW] 卡库读卡失败(BuildAppList),请联系卡库厂商排查或更换
 0x203002E5=[RTA2395] [HW] 卡库读卡失败(ICCommand),请联系卡库厂商排查或更换
 
-0x20600002=[RTA260B] [HW] 设置密码键盘参数失败,请联系厂商排查
+0x2060021B=[RTA2607] [HW] 获取账号失败,请联系行内开发人员排查
 0x20600003=[RTA2608] [HW] 设置账号失败,请联系厂商排查
-0x20600006=[RTA260C] [HW] 激活工作密钥失败,请联系厂商排查
 0x20600007=[RTA2609] [HW] 开启密文输入失败,请联系厂商排查
-0x2060000a=[RTA260A] [HW] 计算密文(GetPinBlock)输入失败,请联系厂商排查
-0x2060000b=[RTA260D] [HW] 加密数据失败失败,请联系厂商排查
-0x20600201=[RTA26E9] [HW] 密码键盘故障,请重试或联系厂商排查
+0x2060000A=[RTA260A] [HW] 计算密文(GetPinBlock)输入失败,请联系厂商排查
+0x20600002=[RTA260B] [HW] 设置密码键盘参数失败,请联系厂商排查
+0x20600006=[RTA260C] [HW] 激活工作密钥失败,请联系厂商排查
+0x2060000B=[RTA260D] [HW] 加密数据失败失败,请联系厂商排查
+0x2060021C=[RTA260E] [HWC] 密码键盘未成功打开,请联系厂商排查
+0x20600221=[RTA260F] 密码输入时收到退出事件,请重试
+0x20600202=[RTA2610] 打开运行时文件失败,请联系行内开发人员排查
+0x20600222=[RTA2611] 不能识别的密钥标识,请联系行内开发人员排查
 
 0x2180000D=[RTA2O01] 连接高拍仪实体模块失败,请尝试重启应用或联系厂商排查
 0x2180000E=[RTA2O02] 操作频繁,请稍候重试

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно