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

Z991239-968 #comment 上传DeviceControl 的更改

gifur 5 жил өмнө
parent
commit
1785608476

+ 4 - 0
Module/mod_DeviceControl/ChangeLog

@@ -1,3 +1,7 @@
 
+* 通过宏定义注释掉了获取网卡信息的代码,需要在Linux下实现(廖桂发,2020年10月24日)
+
 ## V0.0.1-dev1
+* 合并了国密的版本
+
 * 首次适配跨平台版本(廖桂发,2020年10月12日)

+ 203 - 250
Module/mod_DeviceControl/DeviceControlFSM.cpp

@@ -2,166 +2,166 @@
 #include "DeviceControlFSM.h"
 #include "GetDevInfoHelper.h"
 #include "EventCode.h"
+#include "fileutil.h"
+
+#if defined(RVC_OS_WIN)
+static const char DEFAULT_ADAPTER_LIBRARY_NAME[] = "DeviceControl.cmbsz.1.1.dll";
+#else
+static const char DEFAULT_ADAPTER_LIBRARY_NAME[] = "libDeviceControl.cmbsz.1.1.so";
+#endif //RVC_OS_WIN
+
+namespace
+{
+bool IsNeedOpenUsb(CEntityBase* pCallerEntity)
+{
+	bool result = false;
+    ErrorCodeEnum errCode = Error_Unexpect;
+    CSystemStaticInfo sysDevInfo;
+    errCode = pCallerEntity->GetFunction()->GetSystemStaticInfo(sysDevInfo);
+    if (errCode != Error_Succeed) {
+        Dbg("get device info failed while judge open usb or not");
+    } else {
+        CSimpleStringA strMachineType;
+        strMachineType = sysDevInfo.strMachineType;
+        WORD majorVersion = sysDevInfo.MachineVersion.GetMajor();
+        WORD minorVersion = sysDevInfo.MachineVersion.GetMinor();
+        CSimpleStringA machineVersion = CSimpleStringA::Format("%d.%d", majorVersion, minorVersion);
+        Dbg("MachineType:%s, machineVersion:%s", strMachineType.GetData(), machineVersion.GetData());
+
+        if (!strMachineType.Compare("RVC.PAD", true)
+            || (!strMachineType.Compare("RVC.Desk2S", true) && !machineVersion.Compare("1.0"))) {
+			result = false;
+        } else if (!strMachineType.Compare("RVC.Stand2S", true) || !strMachineType.Compare("RVC.CardStore", true)
+                   || (!strMachineType.Compare("RVC.Desk2S", true) && !machineVersion.Compare("2.0"))
+                   || (!strMachineType.Compare("RVC.Desk2S", true) && !machineVersion.Compare("2.1"))
+                   || (!strMachineType.Compare("RVC.Desk1S", true) && !machineVersion.Compare("1.0"))) {
+			result = true;
+        } else {
+            //TODO:: if add new machine type
+			result = true;
+        }
+    }
+    return result;
+}
+}
 
 ErrorCodeEnum CDeviceControlFSM::OnInit()
 {
-	LOG_FUNCTION();
-	/*------2020-02-27------*/
-	//modify by LZM
-	VendorLogControler(this,"DeviceControl");
-	/*---------------------*/
-	HRESULT hr;
-	int initTries = 0;
-	bool bClosePort = false;
-	ErrorCodeEnum eErr;
+    LOG_FUNCTION();
+    ErrorCodeEnum eErr;
+    GET_DEV_ENTITY_BASE_POINTER()->InitializeVendorLogSwitch();
+    Dbg("Source Code complied at: %s %s", __DATE__, __TIME__);
 
 	m_csMachineType = "RVC.PAD";
+    CSmartPointer<IConfigInfo> spConfig;
 	CSystemStaticInfo sysInfo;
-	eErr = GetEntityBase()->GetFunction()->GetSystemStaticInfo(sysInfo);
-	if (eErr != Error_Succeed)
-	{
-		Dbg("Get System Static info failed(%d).", eErr);
+    CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
+	eErr = spEntityFunction->GetSystemStaticInfo(sysInfo);
+	if (eErr != Error_Succeed) {
+		Dbg("Get System Static info failed: %s.", SpStrError(eErr));
+		return eErr;
 	}
+    eErr = spEntityFunction->OpenConfig(Config_Root, spConfig);
+    if (eErr != Error_Succeed) {
+        Dbg("open cfg file failed: %s.", SpStrError(eErr));
+        return eErr;
+    }
+
 	m_csMachineType = sysInfo.strMachineType;
 	Dbg("machine type:%s",(LPCTSTR)m_csMachineType);
 	CSimpleStringA dllName, tmpDevSN("");
-	GetEntityBase()->GetFunction()->GetSysVar("FWBDevSN", tmpDevSN);
-	if (tmpDevSN.GetLength() > 12 && tmpDevSN.IndexOf("FWB") > 2)
-		m_bFWB = true;
-	CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
-	CSmartPointer<IConfigInfo> spConfig;
+	spEntityFunction->GetSysVar("FWBDevSN", tmpDevSN);
+	m_bFWB = (tmpDevSN.GetLength() > 12 && tmpDevSN.IndexOf("FWB") > 2);
 	if (strnicmp(m_csMachineType, "RVC.PAD", strlen("RVC.PAD")) != 0 || m_bFWB)
 	{
 		CSimpleStringA csDepPath("");
-		eErr = GetEntityBase()->GetFunction()->GetPath("Dep", csDepPath);
+		eErr = spEntityFunction->GetPath("Dep", csDepPath);
 		if (eErr == Error_Succeed)
 		{
 			Dbg("not RVC.PAD or is FWB(%d),to use default dll.", m_bFWB);
-			CSimpleStringA csBackslash("\\");
-			dllName = csDepPath + csBackslash + "DeviceControl.cc.1.1.dll";
+			dllName = csDepPath + SPLIT_SLASH_STR;
+			dllName += DEFAULT_ADAPTER_LIBRARY_NAME;
 		}
 	}
 	else
 	{
-		eErr = SpGetDevAdaptorPath(m_pEntity, GetEntityBase()->GetEntityName(), dllName);
+		auto pEntity = GET_DEV_ENTITY_BASE_POINTER();
+		eErr = pEntity->ExtractVendorLibFullPath(dllName);
 		if (eErr != Error_Succeed)
 		{
 			Dbg("load vendor dll(%s) failed.", (LPCTSTR)dllName);
 			return Error_DevLoadFileFailed;
 		}
 		Dbg("%s", (LPCTSTR)dllName);
-		eErr = spEntityFunction->OpenConfig(Config_Root, spConfig);
-		if (eErr != Error_Succeed) {
-			Dbg("open cfg file failed!");
-			return eErr;
-		}
 	}
-
-	m_hVerdorDll = LoadLibraryA(dllName);
-	if (m_hVerdorDll == NULL)
+	eErr = m_hDevHelper.LoadUp(dllName);
+	if (eErr != Error_Succeed)
 	{
-		Dbg("Load dll failed.%d",GetLastError());
+		Dbg("Load dll failed.%s", SpStrError(eErr));
 		return Error_DevLoadFileFailed;
 	}
-	else
+	else {
 		Dbg("load vendor dll suc.");
-	if ((CreateDevComponent = (lpCreateDevCom)GetProcAddress(m_hVerdorDll,"CreateDevComponent")) == NULL)
-	{
-		Dbg("Get CreateDevComponent failed.");
-		return Error_DevLoadFileFailed;
-	}
-	if ((ReleaseDevComponent = (lpReleaseDevCom)GetProcAddress(m_hVerdorDll,"ReleaseDevComponent")) == NULL)
-	{
-		Dbg("Get ReleaseDevComponent failed.");
-		return Error_DevLoadFileFailed;
 	}
-	CSimpleStringA csDepPath("");
-
-	eErr = GetEntityBase()->GetFunction()->GetPath("Dep", csDepPath);
-	if (eErr != Error_Succeed)
-	{
-		Dbg("Get dep Path failed (%d).",eErr);
-		//return Error_Param;
-	}
-	else
-	{
-		CSimpleStringA csAQUkeyDll,csBackslash("\\");
-		csAQUkeyDll = csDepPath + csBackslash + "token.dll";
-		m_hVerdorDll = LoadLibraryA(csAQUkeyDll);
-		if (m_hVerdorDll == NULL)
-		{
-			Dbg("Load aq dll failed.%d",GetLastError());
-			return Error_DevLoadFileFailed;
-		}
-		else
-		{
-			if ((AQGetUKeyID = (lpGetUKeyID)GetProcAddress(m_hVerdorDll,"GetUKeyID")) == NULL)
-			{
-				Dbg("Get GetUKeyID failed.");
-				return Error_DevLoadFileFailed;
-			}
-			if ((AQInitToken = (lpInitToken)GetProcAddress(m_hVerdorDll,"InitToken")) == NULL)
-			{
-				Dbg("Get InitToken failed.");
-				return Error_DevLoadFileFailed;
-			}
-			Dbg("Load aq suc.");
-		}
 
-	}
+	InitializeTokenLib();
 
 	if (strnicmp(m_csMachineType, "RVC.PAD", strlen("RVC.PAD")) == 0 && !m_bFWB)//RVC.PAD to read root.ini
 	{
 		int baudRate, port;
-
 		spConfig->ReadConfigValueInt("Device.DeviceControl", "Baudrate", baudRate);
 		spConfig->ReadConfigValueInt("Device.DeviceControl", "Port", port);
-		do{
-			if (m_pDevCtrl == NULL)
-			{
-				if (CreateDevComponent((DeviceBaseClass *&)m_pDevCtrl) != Error_Succeed)
-				{
-					LOG_TRACE("创建设备控制模块失败");
-					initTries++;
-					continue;
-				}
-			}
-			Dbg("%d,%d", port, baudRate);
-			eErr = m_pDevCtrl->DevOpen(port, baudRate);
-			if (eErr != Error_Succeed)
-			{
-				Dbg("打开设备失败");
-				return Error_DevConnFailed;
-			}
-			Dbg("打开设备成功.");
-			//m_pDevCtrl->PortControl(USB_PORT_ENABLE);
-			break;
-
-		} while (initTries < 3);
-	}
-
-	// 不是大机,打开USB 
-	// by XKM @20151112
-	//修改为:是PAD才打开USB  by oilyang 20160621
-	if (strnicmp(m_csMachineType, "RVC.PAD", strlen("RVC.PAD")) ==0 && !m_bFWB)
-	{
-		m_pDevCtrl->PortControl(USB_PORT_ENABLE);
+        eErr = m_hDevHelper->DevOpen(port, baudRate);
+        if (eErr != Error_Succeed) {
+            Dbg("打开设备失败");
+            return Error_DevConnFailed;
+        }
+		m_hDevHelper->PortControl(USB_PORT_ENABLE);
 	}
 	return Error_Succeed;
 }
-ErrorCodeEnum CDeviceControlFSM::OnExit()
-{
-	return Error_Succeed;
-}
 
-void CDeviceControlFSM::s0_on_entry()
+ErrorCodeEnum CDeviceControlFSM::InitializeTokenLib()
 {
+#if defined(RVC_OS_WIN)
+
+	CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
+    CSimpleStringA csDepPath("");
+	ErrorCodeEnum eErr = spEntityFunction->GetPath("Dep", csDepPath);
+    if (eErr == Error_Succeed) {
+        CSimpleStringA csAQUkeyDll, csBackslash("\\");
+        csAQUkeyDll = csDepPath + csBackslash + "token.dll";
+        m_hTokenDll = LoadLibraryA(csAQUkeyDll);
+        if (m_hTokenDll == NULL) {
+            Dbg("Load aq dll failed.%d", GetLastError());
+            return Error_DevLoadFileFailed;
+        } else {
+            if ((AQGetUKeyID = (lpGetUKeyID)GetProcAddress(m_hTokenDll, "GetUKeyID")) == NULL) {
+                Dbg("Get GetUKeyID failed.");
+                return Error_DevLoadFileFailed;
+            }
+            if ((AQInitToken = (lpInitToken)GetProcAddress(m_hTokenDll, "InitToken")) == NULL) {
+                Dbg("Get InitToken failed.");
+                return Error_DevLoadFileFailed;
+            }
+            Dbg("Load aq suc.");
+        }
+    }
+	return eErr;
+
+#else
+
+	return Error_NotSupport;
+
+#endif //RVC_OS_WIN
 
 }
-void CDeviceControlFSM::s0_on_exit()
-{
 
+ErrorCodeEnum CDeviceControlFSM::OnExit()
+{
+	return Error_Succeed;
 }
+
 unsigned int CDeviceControlFSM::s0_on_event(FSMEvent* pEvt)
 {
 	Dbg("s0 event %d,%d",pEvt->iEvt,pEvt->param1);
@@ -216,14 +216,6 @@ unsigned int CDeviceControlFSM::s0_on_event(FSMEvent* pEvt)
 	return 0;
 }
 
-void CDeviceControlFSM::s1_on_entry()
-{
-
-}
-void CDeviceControlFSM::s1_on_exit()
-{
-
-}
 unsigned int CDeviceControlFSM::s1_on_event(FSMEvent* pEvt)
 {
 	Dbg("s1 %d,%d",pEvt->iEvt,pEvt->param1);
@@ -241,27 +233,6 @@ unsigned int CDeviceControlFSM::s1_on_event(FSMEvent* pEvt)
 	return 0;
 }
 
-void CDeviceControlFSM::s2_on_entry()
-{
-
-}
-void CDeviceControlFSM::s2_on_exit()
-{
-
-}
-unsigned int CDeviceControlFSM::s2_on_event(FSMEvent* pEvt)
-{
-
-	return 0;
-}
-void CDeviceControlFSM::s3_on_entry()
-{
-
-}
-void CDeviceControlFSM::s3_on_exit()
-{
-
-}
 //GetUkeyID
 unsigned int CDeviceControlFSM::s3_on_event(FSMEvent* pEvt)
 {
@@ -276,15 +247,8 @@ unsigned int CDeviceControlFSM::s3_on_event(FSMEvent* pEvt)
 	}
 	return 0;
 }
-//InitToken
-void CDeviceControlFSM::s4_on_entry()
-{
-
-}
-void CDeviceControlFSM::s4_on_exit()
-{
 
-}
+//InitToken
 unsigned int CDeviceControlFSM::s4_on_event(FSMEvent* pEvt)
 {
 	Dbg("s4 %d,%d",pEvt->iEvt,pEvt->param1);
@@ -301,48 +265,27 @@ unsigned int CDeviceControlFSM::s4_on_event(FSMEvent* pEvt)
 int CDeviceControlFSM::UsbControl(SpReqAnsContext<DeviceControlService_USB_Req,DeviceControlService_USB_Ans>::Pointer ctx)
 {
 	Dbg("open %d",ctx->Req.open);
-	ControlType eType;
-	bool bIsNeedOpenUsb = true;
 
-	if(Error_Succeed != IsNeedOpenUsb(m_pEntity, bIsNeedOpenUsb)){
-		Dbg("usb control failed: get device info failed.");
-		return 1;
-	}
+	const bool bIsNeedOpenUsb = IsNeedOpenUsb(m_pEntity);
 	if(!bIsNeedOpenUsb){
 		Dbg("no need open/close usb, this machine's usb is always open.");
-		ctx->Answer(Error_Succeed);
-		return 0;
-	}
 
-	if (ctx->Req.open)
-	{
-		eType = USB_PORT_ENABLE;
-		LogEvent(Severity_Middle,LOG_EVT_USB_CONTROL_ON,"usb on");//control by gpio
-		LogEvent(Severity_Middle,LOG_EVT_USB_LIGHT_ON,"usb on");//control by gpio
-	}
-	else
-	{
-		eType = USB_PORT_DISABLE;
-		LogEvent(Severity_Middle,LOG_EVT_USB_CONTROL_OFF,"usb off");//control by gpio
-		LogEvent(Severity_Middle,LOG_EVT_USB_LIGHT_OFF,"usb off");//control by gpio
+	} else {
+
+        ControlType eType;
+        if (ctx->Req.open) {
+            eType = USB_PORT_ENABLE;
+            LogEvent(Severity_Middle, LOG_EVT_USB_CONTROL_ON, "usb on");//control by gpio
+            LogEvent(Severity_Middle, LOG_EVT_USB_LIGHT_ON, "usb on");//control by gpio
+        } else {
+            eType = USB_PORT_DISABLE;
+            LogEvent(Severity_Middle, LOG_EVT_USB_CONTROL_OFF, "usb off");//control by gpio
+            LogEvent(Severity_Middle, LOG_EVT_USB_LIGHT_OFF, "usb off");//control by gpio
+        }
 	}
-	ctx->Answer(Error_Succeed);
-	return 0;
 
-	/*if (_strnicmp(m_csMachineType,"RVC.PAD",strlen("RVC.PAD")) != 0 || m_bFWB)
-	{
-	Dbg("not rvc.pad");
 	ctx->Answer(Error_Succeed);
 	return 0;
-	}
-	ErrorCodeEnum eErr = m_pDevCtrl->PortControl(eType);
-	if (eErr != Error_Succeed)
-	{
-	Dbg("usb control failed %d.",eErr);
-	return 1;
-	}
-	ctx->Answer(Error_Succeed);
-	return 0;*/
 }
 
 int CDeviceControlFSM::GetUkeyIDx(SpReqAnsContext<DeviceControlService_GetUkeyID_Req, DeviceControlService_GetUkeyID_Ans>::Pointer ctx)
@@ -354,27 +297,30 @@ int CDeviceControlFSM::GetUkeyIDx(SpReqAnsContext<DeviceControlService_GetUkeyID
 		ctx->Answer(Error_Null);
 		return 1;
 	}
-	char pID[512];
-	ZeroMemory(pID,512);
-	int tmp = 512;
-	int ret = AQGetUKeyID(pID,tmp);
-	m_bWorkingOp = false;
-	if (ret == 0)
-	{
-		ctx->Ans.UkeyID = pID;
-		ctx->Ans.UkeyIDLen = strlen(pID);
-		Dbg("oiltest ukey id [%d][%s][%d]",tmp,(LPCTSTR)ctx->Ans.UkeyID,ctx->Ans.UkeyIDLen);
-		ctx->Ans.reserved1 = 999;
-		ctx->Answer(Error_Succeed);
-		return 0;
-	}
-	else
-	{
-		Dbg("GetUKey failed.%d,%d",ret,GetLastError());
-		ctx->Ans.reserved1 = ret;
-		ctx->Answer(Error_Succeed);
-		return 1;
-	}
+
+#if defined(RVC_OS_WIN)
+    char pID[512];
+    ZeroMemory(pID, 512);
+    int tmp = 512;
+    int ret = AQGetUKeyID(pID, tmp);
+    m_bWorkingOp = false;
+    if (ret == 0) {
+        ctx->Ans.UkeyID = pID;
+        ctx->Ans.UkeyIDLen = strlen(pID);
+        Dbg("oiltest ukey id [%d][%s][%d]", tmp, (LPCTSTR)ctx->Ans.UkeyID, ctx->Ans.UkeyIDLen);
+        ctx->Ans.reserved1 = 999;
+        ctx->Answer(Error_Succeed);
+        return 0;
+    } else {
+        Dbg("GetUKey failed.%d,%d", ret, GetLastError());
+        ctx->Ans.reserved1 = ret;
+        ctx->Answer(Error_Succeed);
+        return 1;
+    }
+#else
+	ctx->Answer(Error_NotSupport);
+	return 1;
+#endif //RVC_OS_WIN
 }
 int CDeviceControlFSM::InitTokenx(SpReqAnsContext<DeviceControlService_InitToken_Req, DeviceControlService_InitToken_Ans>::Pointer ctx)
 {
@@ -385,55 +331,60 @@ int CDeviceControlFSM::InitTokenx(SpReqAnsContext<DeviceControlService_InitToken
 		ctx->Answer(Error_Null);
 		return 1;
 	}
-	int tokensnlen,pkcs10len,msglen;
-	tokensnlen = 32;
-	pkcs10len = 2048;
-	msglen = 128;
-	char tokenSn[32],pkcs10[2048],msg[128];
-	ZeroMemory(tokenSn,tokensnlen);
-	ZeroMemory(pkcs10,pkcs10len);
-	ZeroMemory(msg,msglen);
+#if defined(RVC_OS_WIN)
+    int tokensnlen, pkcs10len, msglen;
+    tokensnlen = 32;
+    pkcs10len = 2048;
+    msglen = 128;
+    char tokenSn[32], pkcs10[2048], msg[128];
+    ZeroMemory(tokenSn, tokensnlen);
+    ZeroMemory(pkcs10, pkcs10len);
+    ZeroMemory(msg, msglen);
 
-	int ret = AQInitToken(const_cast<char*>(ctx->Req.CertType.GetData()),ctx->Ans.TokenType,const_cast<char*>(ctx->Req.OldSuperPwd.GetData()),const_cast<char*>(ctx->Req.UserName.GetData())
-		,const_cast<char*>(ctx->Req.UserIDType.GetData()),const_cast<char*>(ctx->Req.UserIDNo.GetData()),tokenSn
-		,tokensnlen,pkcs10,pkcs10len,msg,msglen);
-	m_bWorkingOp = false;
-	if (ret == 0)
-	{
-		Dbg("[%d][%s][%d][%s][%d]",tokensnlen,tokenSn,msglen,msg,pkcs10len);
-		char xx1[768],xx2[768];
-		ZeroMemory(xx1,768);
-		ZeroMemory(xx2,768);
-		if (pkcs10len > 600)
-		{
-			strncpy(xx1,pkcs10,600);
-			strncpy(xx2,pkcs10+600,pkcs10len-600+1);
-		}
-		else
-			strncpy(xx1,pkcs10,pkcs10len);
+    int ret = AQInitToken(const_cast<char*>(ctx->Req.CertType.GetData())
+                          , ctx->Ans.TokenType, const_cast<char*>(ctx->Req.OldSuperPwd.GetData())
+                          , const_cast<char*>(ctx->Req.UserName.GetData())
+                          , const_cast<char*>(ctx->Req.UserIDType.GetData())
+                          , const_cast<char*>(ctx->Req.UserIDNo.GetData())
+                          , tokenSn
+                          , tokensnlen, pkcs10, pkcs10len, msg, msglen);
+    m_bWorkingOp = false;
+    if (ret == 0) {
+        Dbg("[%d][%s][%d][%s][%d]", tokensnlen, tokenSn, msglen, msg, pkcs10len);
+        char xx1[768], xx2[768];
+        ZeroMemory(xx1, 768);
+        ZeroMemory(xx2, 768);
+        if (pkcs10len > 600) {
+            strncpy(xx1, pkcs10, 600);
+            strncpy(xx2, pkcs10 + 600, pkcs10len - 600 + 1);
+        } else
+            strncpy(xx1, pkcs10, pkcs10len);
 
-		Dbg("[%s]",xx1);
-		Dbg("[%s]",xx2);
-		ctx->Ans.TokenSn = tokenSn;
-		ctx->Ans.PKCS10 = pkcs10;
-		ctx->Ans.Msg = msg;
-		ctx->Ans.TokenSnLen = tokensnlen;
-		ctx->Ans.PKCS10Len = pkcs10len;
-		ctx->Ans.MsgLen = msglen;
-		ctx->Ans.reserved1 = 999;
-		ctx->Answer(Error_Succeed);
-		return 0;
-	}
-	else
-	{
-		Dbg("InitToken failed.%d,%d",ret,GetLastError());
-		ctx->Ans.reserved1 = ret;
-		ctx->Answer(Error_Succeed);
-		return 1;
-	}
+        Dbg("[%s]", xx1);
+        Dbg("[%s]", xx2);
+        ctx->Ans.TokenSn = tokenSn;
+        ctx->Ans.PKCS10 = pkcs10;
+        ctx->Ans.Msg = msg;
+        ctx->Ans.TokenSnLen = tokensnlen;
+        ctx->Ans.PKCS10Len = pkcs10len;
+        ctx->Ans.MsgLen = msglen;
+        ctx->Ans.reserved1 = 999;
+        ctx->Answer(Error_Succeed);
+        return 0;
+    } else {
+        Dbg("InitToken failed.%d,%d", ret, GetLastError());
+        ctx->Ans.reserved1 = ret;
+        ctx->Answer(Error_Succeed);
+        return 1;
+    }
+#else
+    ctx->Answer(Error_NotSupport);
+    return 1;
+#endif //RVC_OS_WIN
 	
 }
-int CDeviceControlFSM::QueryUSB(SpReqAnsContext<DeviceControlService_QueryUSBStatus_Req,DeviceControlService_QueryUSBStatus_Ans>::Pointer ctx)
+int CDeviceControlFSM::QueryUSB(SpReqAnsContext<DeviceControlService_QueryUSBStatus_Req
+	                                                    ,DeviceControlService_QueryUSBStatus_Ans>::Pointer ctx)
 {
 	ErrorCodeEnum eErr = Error_Unexpect;
 	GpioService_ClientBase *pGpio = new GpioService_ClientBase(this->GetEntityBase());
@@ -482,4 +433,6 @@ void CDeviceControlFSM::WorkingOp()
 			break;
 		}
 	}
-}
+}
+
+

+ 15 - 11
Module/mod_DeviceControl/DeviceControlFSM.h

@@ -121,23 +121,26 @@ public:
 	virtual ErrorCodeEnum OnInit();
 	virtual ErrorCodeEnum OnExit();
 
-	virtual void s0_on_entry();
-	virtual void s0_on_exit();
+	virtual void s0_on_entry() {}
+	virtual void s0_on_exit() {}
 	virtual unsigned int s0_on_event(FSMEvent* e);
 
-	virtual void s1_on_entry();
-	virtual void s1_on_exit();
+	virtual void s1_on_entry() {}
+	virtual void s1_on_exit() {}
 	virtual unsigned int s1_on_event(FSMEvent* e);
 
-	virtual void s2_on_entry();
-	virtual void s2_on_exit();
-	virtual unsigned int s2_on_event(FSMEvent* e);
-	virtual void s3_on_entry();
-	virtual void s3_on_exit();
+	virtual void s2_on_entry() {}
+	virtual void s2_on_exit() {}
+	virtual unsigned int s2_on_event(FSMEvent* e) { return 0; }
+
+	virtual void s3_on_entry() {}
+	virtual void s3_on_exit() {}
 	virtual unsigned int s3_on_event(FSMEvent* e);
-	virtual void s4_on_entry();
-	virtual void s4_on_exit();
+
+	virtual void s4_on_entry() {}
+	virtual void s4_on_exit() {}
 	virtual unsigned int s4_on_event(FSMEvent* e);
+
 	int UsbControl(SpReqAnsContext<DeviceControlService_USB_Req,DeviceControlService_USB_Ans>::Pointer ctx);
 	int GetUkeyIDx(SpReqAnsContext<DeviceControlService_GetUkeyID_Req, DeviceControlService_GetUkeyID_Ans>::Pointer ctx);
 	int InitTokenx(SpReqAnsContext<DeviceControlService_InitToken_Req, DeviceControlService_InitToken_Ans>::Pointer ctx);
@@ -147,6 +150,7 @@ public:
 	{
 		pTransactionContext->SendAnswer(Error_Succeed);
 	}
+	ErrorCodeEnum InitializeTokenLib();
 
 private:
 	ErrorCodeEnum m_testResult;

+ 1 - 1
Module/mod_DeviceControl/DeviceControl_def_g.h

@@ -5,7 +5,7 @@
 
 // This code is generated by spgen tool!
 
-#include "spHelper.h"
+#include "SpHelper.h"
 
 namespace DeviceControl {
 //

+ 0 - 48
Module/mod_DeviceControl/ReadMe.txt

@@ -1,48 +0,0 @@
-========================================================================
-    DYNAMIC LINK LIBRARY : mod_DeviceControl Project Overview
-========================================================================
-
-AppWizard has created this mod_DeviceControl DLL for you.
-
-This file contains a summary of what you will find in each of the files that
-make up your mod_DeviceControl application.
-
-
-mod_DeviceControl.vcxproj
-    This is the main project file for VC++ projects generated using an Application Wizard.
-    It contains information about the version of Visual C++ that generated the file, and
-    information about the platforms, configurations, and project features selected with the
-    Application Wizard.
-
-mod_DeviceControl.vcxproj.filters
-    This is the filters file for VC++ projects generated using an Application Wizard. 
-    It contains information about the association between the files in your project 
-    and the filters. This association is used in the IDE to show grouping of files with
-    similar extensions under a specific node (for e.g. ".cpp" files are associated with the
-    "Source Files" filter).
-
-mod_DeviceControl.cpp
-    This is the main DLL source file.
-
-	When created, this DLL does not export any symbols. As a result, it
-	will not produce a .lib file when it is built. If you wish this project
-	to be a project dependency of some other project, you will either need to
-	add code to export some symbols from the DLL so that an export library
-	will be produced, or you can set the Ignore Input Library property to Yes
-	on the General propert page of the Linker folder in the project's Property
-	Pages dialog box.
-
-/////////////////////////////////////////////////////////////////////////////
-Other standard files:
-
-StdAfx.h, StdAfx.cpp
-    These files are used to build a precompiled header (PCH) file
-    named mod_DeviceControl.pch and a precompiled types file named StdAfx.obj.
-
-/////////////////////////////////////////////////////////////////////////////
-Other notes:
-
-AppWizard uses "TODO:" comments to indicate parts of the source code you
-should add to or customize.
-
-/////////////////////////////////////////////////////////////////////////////

+ 82 - 84
Module/mod_DeviceControl/mod_DeviceControl.cpp

@@ -82,92 +82,90 @@ CSimpleStringA CDeviceControlEntity::__ReadCenterConfigStr(CSimpleStringA key, C
 	return str;
 }
 
-void CDeviceControlEntity::GetINETMacAddresses(NetworkAddressesList &macList, NetworkAddressesList &ipList)
+ErrorCodeEnum CDeviceControlEntity::GetINETMacAddresses(NetworkAddressesList &macList, NetworkAddressesList &ipList)
 {
-	PIP_ADAPTER_ADDRESSES pAddresses = NULL;
-	ULONG family = AF_INET;
-	ULONG flags = GAA_FLAG_INCLUDE_PREFIX;
-	ULONG outBufLen = sizeof( IP_ADAPTER_ADDRESSES );
-	Dbg("GetINETMacAddresses");
-
-	// Make an initial call to GetAdaptersAddresses to get the 
-	// size needed into the outBufLen variable
-	if ( GetAdaptersAddresses( family, flags, NULL, pAddresses, &outBufLen ) == ERROR_BUFFER_OVERFLOW )
-	{
-		pAddresses = static_cast<PIP_ADAPTER_ADDRESSES>( HeapAlloc( GetProcessHeap(), 0, outBufLen ) );
-	}
-
-	Dbg("GetAdaptersAddresses 1");
-
-	if (NULL == pAddresses)
-	{
-		Dbg("pAddresses = NULL");
-		return;
-	}
+#if defined(RVC_OS_WIN)
+
+    PIP_ADAPTER_ADDRESSES pAddresses = NULL;
+    ULONG family = AF_INET;
+    ULONG flags = GAA_FLAG_INCLUDE_PREFIX;
+    ULONG outBufLen = sizeof(IP_ADAPTER_ADDRESSES);
+    Dbg("GetINETMacAddresses");
+
+    // Make an initial call to GetAdaptersAddresses to get the 
+    // size needed into the outBufLen variable
+    if (GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen) == ERROR_BUFFER_OVERFLOW) {
+        pAddresses = static_cast<PIP_ADAPTER_ADDRESSES>(HeapAlloc(GetProcessHeap(), 0, outBufLen));
+    }
+
+    Dbg("GetAdaptersAddresses 1");
+
+    if (NULL == pAddresses) {
+        Dbg("pAddresses = NULL");
+        return Error_Unexpect;
+    }
+
+    DWORD dwRetVal = GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen);
+    Dbg("GetAdaptersAddresses 2");
+
+    /*		MACAddresses vAddress;*/
+    if (dwRetVal != ERROR_SUCCESS) {
+        Dbg("dwRetVal = %d", dwRetVal);
+        return Error_Unexpect;
+    }
+    PIP_ADAPTER_ADDRESSES pFirst = pAddresses;
+    while (pAddresses) {
+        if (pAddresses->FirstUnicastAddress->Address.lpSockaddr->sa_family == AF_INET &&
+            pAddresses->OperStatus == IfOperStatusUp &&
+            pAddresses->IfType != IF_TYPE_SOFTWARE_LOOPBACK) {
+            Dbg("in while if 1");
+            BYTE* pa = pAddresses->PhysicalAddress;
+            if (!pa) {
+                pAddresses = pAddresses->Next ? pAddresses->Next : NULL;
+                continue;
+            }
+            Dbg("in while if 2");
+            char bAddressBytes[MACSESION];
+            int bAddressInt[MACSESION];
+            memset(bAddressBytes, 0, MACSESION);
+            size_t nAddressSize = pAddresses->PhysicalAddressLength;
+            memcpy(bAddressBytes, pa, (nAddressSize < MACSESION ? nAddressSize : MACSESION));
+            char CommarSeperatedAddress[MACSESION * 3] = { 0 };
+            for (int i = 0; i < MACSESION; ++i) {
+                bAddressInt[i] = bAddressBytes[i];
+                bAddressInt[i] &= 0x000000ff; // avoid "ff" leading bytes when "char" is lager then 0x7f
+            }
+            Dbg("in while if 3");
+            sprintf(CommarSeperatedAddress, "%02x:%02x:%02x:%02x:%02x:%02x",
+                    bAddressInt[0],
+                    bAddressInt[1],
+                    bAddressInt[2],
+                    bAddressInt[3],
+                    bAddressInt[4],
+                    bAddressInt[5]); // Should use scl::FormatString inside 
+            CSimpleStringA tmpmac = CSimpleStringA(CommarSeperatedAddress);
+            Dbg("in while if 4");
+
+            macList.Append(&tmpmac, 0, 1);
+            Dbg("Description : %s", pAddresses->Description);
+            Dbg("OperStatus : %d, IfType = %d, mac = %s", pAddresses->OperStatus, pAddresses->IfType, CommarSeperatedAddress);
+            sockaddr_in* sa_in = (sockaddr_in*)pAddresses->FirstUnicastAddress->Address.lpSockaddr;
+            char buf_addr[100] = { 0 };
+            CSimpleStringA tmpip = CSimpleStringA(inet_ntop(AF_INET, &(sa_in->sin_addr), buf_addr, 100));
+            ipList.Append(&tmpip, 0, 1);
+        }
+        pAddresses = pAddresses->Next ? pAddresses->Next : NULL;
+    }
+    HeapFree(GetProcessHeap(), 0, pFirst);
+
+    return Error_Succeed;
+
+#else
+
+    return Error_NotImpl;
+
+#endif //RVC_OS_WIN
 
-//	_ASSERT( pAddresses );
-	// Make a second call to GetAdapters Addresses to get the
-	// actual data we want
-	DWORD dwRetVal = GetAdaptersAddresses( family, flags, NULL, pAddresses, &outBufLen );
-
-	Dbg("GetAdaptersAddresses 2");
-
-/*		MACAddresses vAddress;*/
-	if ( dwRetVal != ERROR_SUCCESS )
-	{
-		Dbg("dwRetVal = %d", dwRetVal);
-		return ;
-	}
-	PIP_ADAPTER_ADDRESSES pFirst = pAddresses;
-	while( pAddresses )
-	{
-		if (pAddresses->FirstUnicastAddress->Address.lpSockaddr->sa_family == AF_INET && 
-			pAddresses->OperStatus == IfOperStatusUp && 
-			pAddresses->IfType != IF_TYPE_SOFTWARE_LOOPBACK)
-		{
-			Dbg("in while if 1");
-			BYTE* pa = pAddresses->PhysicalAddress;
-			if ( ! pa  )
-			{
-				pAddresses = pAddresses->Next ? pAddresses->Next : NULL;
-				continue;
-			}
-			Dbg("in while if 2");
-			char bAddressBytes[ MACSESION ];
-			int bAddressInt [ MACSESION ];
-			memset( bAddressBytes, 0, MACSESION );
-			size_t nAddressSize = pAddresses->PhysicalAddressLength;
-			memcpy( bAddressBytes, pa, ( nAddressSize < MACSESION ? nAddressSize : MACSESION ));
-			char CommarSeperatedAddress[ MACSESION * 3 ]={0};
-			for( int i = 0; i < MACSESION; ++i )
-			{
-				bAddressInt[ i ] = bAddressBytes[ i ];
-				bAddressInt[ i ] &= 0x000000ff; // avoid "ff" leading bytes when "char" is lager then 0x7f
-			}
-			Dbg("in while if 3");
-			sprintf( CommarSeperatedAddress, "%02x:%02x:%02x:%02x:%02x:%02x",
-				bAddressInt[ 0 ],
-				bAddressInt[ 1 ],
-				bAddressInt[ 2 ],
-				bAddressInt[ 3 ],
-				bAddressInt[ 4 ],
-				bAddressInt[ 5 ]); // Should use scl::FormatString inside 
-			CSimpleStringA tmpmac = CSimpleStringA(CommarSeperatedAddress);
-			Dbg("in while if 4");
-			
-			macList.Append( &tmpmac, 0, 1 );
-//			macList.push_back( std::string( CommarSeperatedAddress ) );
-			Dbg("Description : %s", pAddresses->Description);
-			Dbg("OperStatus : %d, IfType = %d, mac = %s", pAddresses->OperStatus, pAddresses->IfType, CommarSeperatedAddress);
-			sockaddr_in *sa_in = (sockaddr_in *)pAddresses->FirstUnicastAddress->Address.lpSockaddr;
-			char buf_addr[100] = {0};
-			CSimpleStringA tmpip = CSimpleStringA(inet_ntop(AF_INET, &(sa_in->sin_addr), buf_addr, 100));
-			ipList.Append( &tmpip, 0, 1);
-		}
-		pAddresses = pAddresses->Next ? pAddresses->Next : NULL;
-	}
-	HeapFree( GetProcessHeap(), 0, pFirst );
-	return ;
 }
 
 SP_BEGIN_ENTITY_MAP()

+ 1 - 1
Module/mod_DeviceControl/mod_DeviceControl.h

@@ -121,7 +121,7 @@ public:
 	virtual bool IsService()const{return true;}
 	virtual bool IsMultiThread()const{return true;}
 private:
-	void GetINETMacAddresses(NetworkAddressesList &macList, NetworkAddressesList &ipList);
+	ErrorCodeEnum GetINETMacAddresses(NetworkAddressesList &macList, NetworkAddressesList &ipList);
 	CSimpleStringA __ReadCenterConfigStr(CSimpleStringA key, CSimpleStringA entityName);
 private:
 	CDeviceControlFSM m_fsm;

+ 0 - 107
Module/mod_DeviceControl/mod_DeviceControl.vcxproj

@@ -1,107 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{31C8B586-8E7A-4746-9D2D-5F647CD8BF2A}</ProjectGuid>
-    <Keyword>Win32Proj</Keyword>
-    <RootNamespace>mod_DeviceControl</RootNamespace>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>MultiByte</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>MultiByte</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <Import Project="..\modmake.setting" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <LinkIncremental>true</LinkIncremental>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <LinkIncremental>false</LinkIncremental>
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <PrecompiledHeader>Use</PrecompiledHeader>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_DEVICECONTROL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <CallingConvention>Cdecl</CallingConvention>
-      <AdditionalIncludeDirectories>$(DevHeadPath);$(FrameworkHeadRoot)\Common;$(ModuleCommonHeadPath)</AdditionalIncludeDirectories>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>$(FrameworkLib)\spbase.lib;ws2_32.lib</AdditionalDependencies>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-    	<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>    
-      <WarningLevel>Level3</WarningLevel>
-      <PrecompiledHeader>Use</PrecompiledHeader>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MOD_DEVICECONTROL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>$(DevHeadPath);$(FrameworkHeadRoot)\Common;$(ModuleCommonHeadPath)</AdditionalIncludeDirectories>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>$(FrameworkLib)\spbase.lib;ws2_32.lib</AdditionalDependencies>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <None Include="ReadMe.txt" />
-  </ItemGroup>
-  <ItemGroup>
-  <ClCompile Include="$(FrameworkHeadRoot)\Common\stdafx.cpp">
-      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
-      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
-    </ClCompile>
-    <ClCompile Include="DeviceControlFSM.cpp" />
-    <ClCompile Include="mod_DeviceControl.cpp" />
-  </ItemGroup>
-  <ItemGroup>
-    <ResourceCompile Include="..\..\Version.rc" />
-
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="$(FrameworkHeadRoot)\Common\stdafx.h" />
-    <ClInclude Include="DeviceControlFSM.h" />
-    <ClInclude Include="DeviceControl_def_g.h" />
-    <ClInclude Include="DeviceControl_server_g.h" />
-    <ClInclude Include="Interface.h" />
-    <ClInclude Include="mod_DeviceControl.h" />
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
-</Project>

+ 0 - 48
Module/mod_DeviceControl/mod_DeviceControl.vcxproj.filters

@@ -1,48 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup>
-    <Filter Include="Source Files">
-      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
-      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
-    </Filter>
-    <Filter Include="Header Files">
-      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
-      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
-    </Filter>
-    <Filter Include="Resource Files">
-      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
-      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
-    </Filter>
-  </ItemGroup>
-  <ItemGroup>
-    <None Include="ReadMe.txt" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="mod_DeviceControl.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\Framework\Common\stdafx.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="DeviceControlFSM.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="..\..\Framework\Common\stdafx.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="DeviceControl_def_g.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="DeviceControl_server_g.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="mod_DeviceControl.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="DeviceControlFSM.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-  </ItemGroup>
-</Project>