1、简介
在利用CANOE 进行测试时,需要用到dll库用于生成27服务需要的Key。因此本文主要介绍如何识别Vector 默认的dll接口,并根据自己需要生成dll
2、找到CANOE提供的Demo工程
安装CANOD时,会提供生成符合CANOE接口的Demo工程,路径如下
3、打开VS工程,修改代码
示例代码如下
//
///Example for a SeedKey.Dll used in CANoe.DiVa
///See also CANoe.DiVa help==>Proceedings/Entry masks/"General" entry mask
//
#include <windows.h>
#include "GenerateKeyEx.h"
// KeyGeneration.cpp : Defines the entry point for the DLL application.
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
const unsigned char APP_MASK[4] = { 0xD6, 0xD7, 0x98, 0xFA };
KEYGENALGO_API VKeyGenResultEx GenerateKeyEx(
const unsigned char* ipSeedArray, /* Array for the seed [in] */
unsigned int iSeedArraySize, /* Length of the array for the seed [in] */
const unsigned int iSecurityLevel, /* Security level [in] */
const char* ipVariant, /* Name of the active variant [in] */
unsigned char* iopKeyArray, /* Array for the key [in, out] */
unsigned int iMaxKeyArraySize, /* Maximum length of the array for the key [in] */
unsigned int& oActualKeyArraySize) /* Length of the key [out] */
{
//Copy seed from parameter to a integer
//Note: The byte order in the seed array is equal to the byte order in the bus message
//begin calculate key from seed------------------------------------------------------------
//for security access with Services 0x27 01 ->0x27 02
unsigned char tmpKey[4];
for (int i = 0; i<4; i++)
{
tmpKey[i] = ipSeedArray[i] ^ APP_MASK[i];
}
//end calculate key from seed------------------------------------------------------------
//Copy key to the output buffer
//Note: The first byte of the key array will be the first key byte of the bus message
iopKeyArray[0] = ((tmpKey[0] & 0x0F) << 4) | (tmpKey[1] & 0xF0);
iopKeyArray[1] = ((tmpKey[1] & 0x0F) << 4) | ((tmpKey[2] & 0xF0) >> 4);
iopKeyArray[2] = (tmpKey[2] & 0xF0) | ((tmpKey[3] & 0xF0) >> 4);
iopKeyArray[3] = ((tmpKey[3] & 0x0F) << 4) | (tmpKey[0] & 0xF0);
//setting length of key
oActualKeyArraySize = 4;
return KGRE_Ok;
}
4、 支持多个Level
为了便于在一个dll 中支持多个level, 可以使用接口参数 iSecurityLevel,如下代码
if (iSecurityLevel == 0x1)
{
/* calc seed key */
}
else if (iSecurityLevel == 0x09)
{
/* calc seed key*/
}