kwp2000 manual
TRANSCRIPT
-
8/9/2019 KWP2000 Manual
1/20
User documentationKWP2000
Add-On for CANoe
Version 1.2
Vector Informatik GmbH, Ingersheimer Straß
e 24, 70499 Stuttgart Tel. (0711) 8 06 70-0, Fax (0711) 8 06 70-5 55
Email [email protected], Internet http://www.vector-informatik.de
mailto:[email protected]%22
-
8/9/2019 KWP2000 Manual
2/20
II
Version 1.2 KWP2000 User Manual © Vector Informatik GmbH
Table of contents
1 History ..................................................................................................................1
1.1 List of changes in version 1.1........................................................................1
1.2 List of changes in version 1.2........................................................................1
2 Introduction..........................................................................................................2
3 Description...........................................................................................................3
3.1 Configuration.................................................................................................3
3.2 Basic operation .............................................................................................3
3.3
Available services..........................................................................................3
3.4 TP Configuration ...........................................................................................4
4 Function description...........................................................................................5
4.1 General remarks ...........................................................................................5
4.1.1 Request function ................................................................................5
4.1.2 Request indication callback................................................................5
4.1.3 Answer function..................................................................................5
4.1.4 Answer indication callback .................................................................5
4.2
Diagnostics services......................................................................................6
4.2.1 StartDiagnosticSession ......................................................................6
4.2.2 StopDiagnosticSession.......................................................................6
4.2.3 SecurityAccess...................................................................................6
4.2.4 TesterPresent.....................................................................................7
4.2.5 EcuReset............................................................................................7
4.2.6 ReadEcuIdentification ........................................................................7
4.2.7 ReadDTCByStatus .............................................................................7
4.2.8 ClearDiagnosticInformation................................................................8
4.2.9
InputOutputCtrlByLocalId ...................................................................8
4.2.10 ReadMemoryByAddress ....................................................................8
4.2.11 WriteMemoryByAddress.....................................................................8
4.3 Support functions ..........................................................................................9
4.4 Troubleshooting.............................................................................................9
4.4.1 Callbacks are not called .....................................................................9
4.4.2 Service not available ..........................................................................9
5 Example programs ............................................................................................11
-
8/9/2019 KWP2000 Manual
3/20
1
© Vector Informatik GmbH KWP2000 User Manual Version 1.2
1 History
Author Version Date Changes:
Schmidt 1.0 2003-01-07 Document created
Schmidt 1.1 2003-02-10 Corrections (API, text)
Schmidt 1.2 2004-09-22 Extensions
1.1 List of changes in version 1.1
! Renamed function “KWP_SetResponseTO” to “KWP_SetTimeoutP2”
! Example using normal addressing mode! Description corrections and extensions
1.2 List of changes in version 1.2
! Added functions for KWP services ReadMemoryByAddress and WriteMemory-ByAddress (DLL version 1.4.25).
-
8/9/2019 KWP2000 Manual
4/20
2
Version 1.2 KWP2000 User Manual © Vector Informatik GmbH
2 Introduction
Diagnostics is used configure, maintain, support, control and extend an ECU before
or after it is installed in a system, e.g. a vehicle.Diagnostics is usually performed in a request – response scheme: a tester (client)sends a request to an ECU (or even more than one ECU) and the ECU(s) (server)respond(s) by sending a “positive response message” containing the requested in-formation, or a “negative response”.
The most widely used protocol is the ITU Keyword Protocol 2000 (KWP2000; cf. ISO15765-3, ISO 14230-3), although many OEMs define their own extensions. For thisdevelopment, ISO 14230-3 version 1.5 (1997-10-1) was used.
This DLL provides support for the basic KWP services, allowing nodes simulated inCANoe to interact with real testers or ECUs. It helps the user by providing direct ac-cess to the (standard) service parameters.
This document describes the usage of the DLL in CANoe. Knowledge of the underly-ing transport protocol (ISO/OSEK TP) and CAPL is expected; for the configuration ofthe TP please refer to the document OSEK_TP_e.pdf (distributed with CANoe) andsection 3.4 “TP Configuration”.
-
8/9/2019 KWP2000 Manual
5/20
3
© Vector Informatik GmbH KWP2000 User Manual Version 1.2
3 Description
3.1 Configuration
The KWP2000 add-on for CANoe consists of the files KWP2000.DLL andKWP2000.INI. The former works as a node layer module for CANoe simulationnodes. Please refer to the online help documentation, section “Search Sequence forNodelayer-DLLs”, for details of the placement of the DLLs. It is recommended toplace the DLL in a directory called “exec32” in the same folder as the configurationfile.
The INI file should be put in the same folder as the DLL file. It has the same formatas the OSEK_TP.INI file for the OSEK TP DLL, so please refer to the documentationthere for details.
3.2 Basic operation
For every KWP service , two functions and two callbacks are defined, one ofeach type for the client and the server:
Client Server
Function KWP_R (Request) KWP_A (Answer)
Callback KWP_AI (Answer indication) KWP_RI (request indication)
The client issues a request to the server, the server receives a callback and canprocess the request. Then the server sends the answer1 back to the client, where the
answer indication is called, providing the answer from the server.
3.3 Available services
In the current implementation, not all of the KWP2000 services are available in theDLL. The following services are represented; see function description in section 4 fordetails.
StartDiagnosticSession
StopDiagnosticSession
SecurityAccess
TesterPresent
EcuReset
ReadEcuIdentification
ReadDTCByStatus
ClearDiagnosticInformation
InputOutputCtrlByLocalId
ReadMemoryByAddress
1 According to the standard, an answer is called „response“. But since the term „request“ also starts with the
letter ‚r’, it was decided to use the term „answer“ here.
-
8/9/2019 KWP2000 Manual
6/20
4
Version 1.2 KWP2000 User Manual © Vector Informatik GmbH
WriteMemoryByAddress
3.4 TP Configuration
The KWP services rely on the transport protocol to transfer data between client andserver. The address information has to be entered in the database or set dynamicallyin CAPL via function calls. The document OSEK_TP_e.pdf contains a detailed de-scription of the TP setup.
Caveat Instead of „OSEKTL_ “, the prefix of all functions is „KWP_ “, e.g. instead of„OSEKTL_SetTgtAdr“, the function is called „KWP_SetTgtAdr“. This allowsthe usage of TP and KWP in parallel.The names of the database attributes remain unchanged.
-
8/9/2019 KWP2000 Manual
7/20
5
© Vector Informatik GmbH KWP2000 User Manual Version 1.2
4 Function description
4.1 General remarks
4.1.1 Request function
Every request function ends with a capital “R”. The call returns 0 (long) if the requestcould be sent without error. The remaining signature depends on the service.
Since the length of function names is limited, the standard names could not be used,instead they were shortened.
4.1.2 Request indication callback
When the server receives a request, the DLL calls the callback with postfix “RI”. The
signature depends on the service, i.e. the parameter the client sends with the requestare forwarded in the arguments.
The value this callback returns determines the behaviour of the KWP DLL:
Return value DLL behaviour
0 Success: the DLL will send a simple “standard” positive response, where the pa-rameters are derived from the received parameters (see service descriptions).
>0 The value will be used in a negative response message that the DLL sends to theclient.
-1 The CAPL program takes over the responsibility to send a response, i.e. the DLLwill not send anything to the client.
< -1 Reserved.
4.1.3 Answer function
The signature of every answer function starts with a (long) value that specifies if theanswer is a positive or negative response. If this argument is 0, a positive responseis sent and the remaining arguments will be put into the response primitive.
If the first argument is a value between 0x10 and 0xFF, a negative response is sent,see standard section 4.4 “Response code value summary table” for the code defini-tions.
4.1.4 Answer indication callback
After the client receives the answer from the server, the DLL calls the CAPL callbackwith the postfix “AI”. Depending on the type of response message received, the firstparameter contains the following values:
First argument DLL behaviour
0 Success. The answer arrived without timeout as a positive response.
>0 A negative response message was received, this value is the response code fromthe standard.
-1 Timeout indication: there was no response from the server.
< -1 Reserved.
-
8/9/2019 KWP2000 Manual
8/20
6
Version 1.2 KWP2000 User Manual © Vector Informatik GmbH
4.2 Diagnostics services
For each service the two functions (“R” and “A”) and the two indication callbacks (“RI” and “AI”) are listed. Please note that many of the arguments are transferred as bytevalues and that therefore only the lower 8 bits are used (cf. standard).
4.2.1 StartDiagnosticSession
Type Function/Callback Parameters Description
Long StartSessionR long DiagnosticMode,long BaudRate
Request the start of a diagnosticsession, choosing a mode andtransmission rate (use –1 if rateshould not be sent)
Long StartSessionRI long DiagnosticMode,long BaudRate
Requested mode and baud rate(-1 if not transmitted)
Long StartSessionA long code,long DiagnosticMode,long BaudRate
Return the mode and baud rateactually used. If rate = -1, it is notsent on the bus.
Void StartSessionAI long state,long DiagnosticModelong BaudRate
Incoming request or requeststate. Also returns the parametersent.
Note: The parameter “BaudRate” is normally only used on serial line interfaces,i.e. not in conjunction with CAN. Most users will set this value to –1.
4.2.2 StopDiagnosticSession
Type Function/Callback Parameters Description
Long StopSessionR Void …
Long StopSessionRI (none)
Long StopSessionA Long code …
Void StopSessionAI Long state …
4.2.3 SecurityAccess
Type Function/Callback Parameters Description
LongSecurityAccessR
Long AccessMode, bytedata[], dword datalen Request switch to a protectedmode. Server should send key orseed
Long SecurityAccessRI long AccessMode, byte da-ta[], dword datalen
mode and key/seed data, datalenmay be 0
Long SecurityAccessA Long code, long Access-Mode, byte data[], dworddatalen
Return key or seed.
Void SecurityAccessAI long state, long Access-Mode, byte data[], dworddatalen
Status and key/seed data.
-
8/9/2019 KWP2000 Manual
9/20
7
© Vector Informatik GmbH KWP2000 User Manual Version 1.2
4.2.4 TesterPresent
Type Function/Callback Parameters Description
Long TesterPresentR dword ResponseRequired Periodically sent by the tester(client) to make the ECU (server)stay in diagnostic mode. The pa-rameter indicates whether thetester expects a response (OEMspecific).
Long TesterPresentRI (none) Standard not clear here!
Long TesterPresentA Long code, dword Respon-seRequired
Respond if necessary.
Void TesterPresentAI Long state …
4.2.5 EcuReset
Type Function/Callback Parameters Description
Long EcuResetR Dword ResetMode
Long EcuResetRI Dword ResetMode
Long EcuResetA Long code, byte data[],dword datalen
Return the reset status. Datalenmay be 0.
Void EcuResetAI Long state, byte data[],dword datalen
…
4.2.6 ReadEcuIdentificationType Function/Callback Parameters Description
Long ReadEcuIdentR Dword option Which data?
Long ReadEcuIdentRI Dword option Requested information
Long ReadEcuIdentA Long code, Byte data[],dword datalen
Return the requested information.
Void ReadEcuIdentAI Long state, byte data[],dword datalen
Status and requested data, if suc-cessful.
4.2.7 ReadDTCByStatus
(Note the name change from „status“ to „state“.)
Type Function/Callback Parameters Description/remarks
Long ReadDTCByStateR dword statusOfDTC,dword groupOfDTC
Only 8, resp. 16 bit of the inputparameters are used
Long ReadDTCByStateRI Dword statusOfDTC,dword groupOfDTC
Only 8, resp. 16 bit of the inputparameters are used
Long ReadDTCByStateA Long code,byte data[], dword datalen
Return the requested DTC(s)
Void ReadDTCByStateAI Long state, byte data[],
dword datalen
-
8/9/2019 KWP2000 Manual
10/20
8
Version 1.2 KWP2000 User Manual © Vector Informatik GmbH
4.2.8 ClearDiagnosticInformation
Type Function/Callback Parameters Description/remarks
Long ClearDiagInfoR dword groupOfDTC Only 16 bit are usedLong ClearDiagInfoRI dword groupOfDTC Only 16 bit are used
Long ClearDiagInfoA Long code, dword grou-pOfDTC
Only 16 bit are used forgroupOfDTC
Void ClearDiagInfoAI Long code, dword grou-pOfDTC
Only 16 bit are used forgroupOfDTC
4.2.9 InputOutputCtrlByLocalId
Type Function/Callback Parameters Description/remarks
Long IOCtrlLocalIdR Dword localId, dword con-trol, byte data[], dworddatalen
Datalen may be 0
Long IOCtrlLocalIdRI Dword localId, dword con-trol, byte data[], dworddatalen
Long IOCtrlLocalIdA Long code, dword localId,dword control, byte data[],dword datalen
Datalen may be 0
Void IOCtrlLocalIdAI Long code, dword localId,dword control, byte data[],dword datalen
4.2.10 ReadMemoryByAddress
Type Function/Callback Parameters Description/remarks
Long ReadMemByAddrR Dword address, dword size 24 bit address
Long ReadMemByAddrRI Dword address, dword size
Long ReadMemByAddrA Long code, byte data[],dword datalen
Void ReadMemByAddrAI Long code, byte data[],dword datalen
4.2.11 WriteMemoryByAddress
Type Function/Callback Parameters Description/remarks
Long WriteMemByAddrR Dword address, byte data[],dword datalen
24 bit address
Long WriteMemByAddrRI Dword address, byte data[],dword datalen
Long WriteMemByAddrA Long code, dword address
Void WriteMemByAddrAI Long code, dword address
-
8/9/2019 KWP2000 Manual
11/20
9
© Vector Informatik GmbH KWP2000 User Manual Version 1.2
4.3 Support functions
These functions may be used in CAPL programs to query the state or set parame-ters, or for often used conversions.
Type Function Parameters Description
Long SetTimeoutP2 dword milliseconds Length of timeout when waiting forresponses, in ms.
Long ResponseCode Dword code,char lineout[],dword lineLength
Converts the response code into atext description. Text will be cut ifthe second argument is not largeenough to hold it.
Long ResponseCodeMne Dword code,char mnemonic[],dword mneLength
Converts the response code intothe official mnemonic given in thestandard.
Long MnemonicResCode char mnemonic[] Convert the mnemonic given inthe standard (ignoring case) to theresponse code. Returns –1 if notfound.
Long ServiceIdMne Dword code,char mnemonic[],dword mneLength
Convert the service id into itsmnemonic. Returns 0 if it wasfound, not 0 otherwise.
Long LastServiceId (void) Returns the id of the last servicerequest/answer received, or of thetimeout
4.4 Troubleshooting
This section lists some of the most common problems encountered when using theDLL and tries to offer solutions.
4.4.1 Callbacks are not called
Problem: Although the correct service primitive is transmitted, the callback is notcalled.
Possible causes and solutions:
! The callback signatures are not correct.
Compare the callback definitions (arguments and return value type) with the de-scription above and correct them. Look for DLL messages on measurementstart; you can increase the write level via the INI file (section [Intern], parameter“WriteLevel“).
! The addressing parameters are not consistent.Make sure that the addressing parameters, i.e. addressing mode and Rx- andTx IDs (normal mode) resp. ECU number and base address (other modes) arecorrect.
4.4.2 Service not available
At the moment, only the listed services are supported by the DLL. If you need addi-tional standard services, please contact Vector Informatik.
-
8/9/2019 KWP2000 Manual
12/20
10
Version 1.2 KWP2000 User Manual © Vector Informatik GmbH
Please note that a client may send data directly using the “KWP_DataReq” function(cf. “OSEKTL_DataReq”), which will lead to call of the “KWP_DataInd” callback func-tion (cf. “OSEKTL_DataInd”) in the server.
In this example, a non-standard service is implemented (without timeout check etc.):
// Tester side ------
MyKWPServiceR( DWORD parameter) {
byte data[5];
data[0] = 0x99; // non-standard ID
data[1] = 0x10; // argument
data[2] = parameter >> 16;
data[3] = parameter >> 8;
data[4] = parameter;
KWP_DataReq( data, 5); // transfer data to ECU
}
MyKWPServiceAI( byte buffer[], long count) {// process response data
}
KWP_DataInd( long count) {
Byte buffer[4095];
KWP_GetRxData(buffer, elcount(buffer));
if( buffer[0] == 0x99 + 0x40)
{
MyKWPServiceAI( buffer, count);
} // else ...
}
// ECU side ------KWP_DataInd( long count) {
Byte buffer[4095];
KWP_GetRxData(buffer, elcount(buffer));
if( buffer[0] == 0x99)
{
MyKWPServiceRI( buffer, count);
} // else ...
}
MyKWPServiceRI( byte buffer[], long count) {
long param;
byte data[3];
// process raw data, then send responsedata[0] = 0x99 + 0x40;
data[1] = 0x10;
data[2] = 0xEE;
KWP_DataReq( data, 3);
}
-
8/9/2019 KWP2000 Manual
13/20
11
© Vector Informatik GmbH KWP2000 User Manual Version 1.2
5 Example programs
A KWP demo is provided in the folder Demo_CAN_CN\KWP2000, please refer to the
documentation there.The following small example demonstrates the usage of the KWP2000 DLL. A data-base containing the nodes “Client” and “Server” and the following node attribute defi-nitions and values is necessary:
Node attribute Attribute type Attribute value
TpTxIdentifier Integer “Client”: 0x607 ”Server”: 0x60d
TpRxIdentifier Integer “Client”: 0x60d ”Server”: 0x607
NodeLayerModules String Default: “KWP2000.DLL”
TpAddressingMode Integer [0…3] Default: 0 (normal)
Usage: initiate the session by pressing the space bar and end the session by press-ing ‘x’. You can set the server state by pressing the keys ‘0’ to ‘4’. Then after pressingthe space bar, different server behaviour can be observed: immediate or delayed re-sponse/ negative response, and ignoring of the request to provoke a timeout.
Please note that this example does not implement realistic ECU or tester behaviour!
/* ----------------------------------------------------------------------
* File: client.can
* This file implements a simple tester that sends request to an ECU.
*/
variables {
char name[7] = "Tester";
int gServerOpen = 0;
BYTE gKey[20];
msTimer presentTimer;
int gIdent = 0;
}
on key ' ' {
KWP_StartSessionR( 0x01, -1);
}
void KWP_StartSessionAI (long result, long mode, long rate) {
write( "%s: StartSessionAI( %x, %x)", name, result, mode);
if( 0 == result) {
write( "%s: StartSession successful!", name);
// settimer( presentTimer, 1000);
}
else
ReportFailure( "StartSession", result);
}
-
8/9/2019 KWP2000 Manual
14/20
12
Version 1.2 KWP2000 User Manual © Vector Informatik GmbH
on key 'x' {
KWP_StopSessionR();
}
ReportFailure ( char service[], long result) {
char desc[20], mnemonic[10], serviceMne[10];
BYTE lastId;
lastId = KWP_LastServiceId();
KWP_ServiceIdMne( lastId, serviceMne, 10);
if( result < 0) {
write( "%s: %s request (0x%x %s) timed out!",
name, service, lastId, serviceMne);
return;
}
KWP_ResponseCode( result, desc, 20);
KWP_ResponseCodeMne( result, mnemonic, 10);
write( "%s: %s request (0x%x %s) fails: %s (%s)!",
name, service, lastId, serviceMne, mnemonic, desc);
}
on key 'o' {
BYTE mode;
if( !gServerOpen) {
mode = 1;
KWP_SecurityAccessR( 1, gKey, 0);
}
}
KWP_SecurityAccessAI (long code, long mode, BYTE data[], DWORD datalen) {
write( "%s: SecurityAccessAI( 0x%x, 0x%x, ..., %d)", name, code, mode,
datalen);
if( !code && (mode & 1) && datalen >= 8) {
// Seed is returned!
MakeKey( data);
KWP_SecurityAccessR( mode + 1, data, 8);
return;
}
if( !code && (mode & 1) == 0 && datalen > 0 && data[0] == 0x34) {
// Success!
gServerOpen = 1;
return;
}
if( code) {
ReportFailure( "SecurityAccess", code);
} else {
write( "%s: SecurityAccess - unknown error.", name);
}
}
MakeKey (BYTE seedKeyInOut[]) {
int i;
for( i = 0; i < 8; i ++)
seedKeyInOut[i] += 'a' - 'A';
}
-
8/9/2019 KWP2000 Manual
15/20
13
© Vector Informatik GmbH KWP2000 User Manual Version 1.2
on timer presentTimer {
KWP_TesterPresentR( 1); // Answer expected.
}
KWP_TesterPresentAI (long code) {
// Ignore answer;
// make sure another request is sent.
settimer( presentTimer, 1000);
}
on key 'r' {
KWP_EcuResetR( 27);
}
KWP_EcuResetAI (long code, byte data[], DWORD datalen) {
if( code) {
ReportFailure( "EcuReset", code);
return;
}
write( "%s: EcuReset answer of %d byte.", name, datalen);
}
KWP_ReadEcuIdentAI (long code, BYTE data[], DWORD datalen) {
char line[100];
if( code) {
ReportFailure( "ReadEcuIdent", code);
return;}
byteToChar( data, line, datalen);
write( "%s: ReadEcuIdent returned \"%s\"", name, line);
}
byteToChar (BYTE source[], char dest[], DWORD len) {
if( elCount(dest) < len-1) len = elCount(dest)-1;
dest[len] = 0;
while( len-- > 0)
dest[len] = source[len];}
on key 'i' {
KWP_ReadEcuIdentR( gIdent++);
gIdent &= 0x3; // 4 values, 0 is unknown!
}
on key 'd' {
KWP_ReadDTCByStateR( 1, 99);
}
on key 'c' {
KWP_ClearDiagInfoR( 99);
}
-
8/9/2019 KWP2000 Manual
16/20
14
Version 1.2 KWP2000 User Manual © Vector Informatik GmbH
on key 'l' {
BYTE buff[5];
KWP_IOCtrlLocalIdR(27, 1, buff, 5);
}
KWP_IOCtrlLocalIdAI (long state, DWORD localId, DWORD control, byte data[], DWORD
datalen) {
if( state) {
ReportFailure( "IOCtrlLocalIdAI", state);
return;
}
write( "%s: IOCtrlLocalIdAI returned Id %d, control %d and %d byte", name,
localId, control, datalen);
}
KWP_ClearDiagInfoAI (long state, DWORD group) {
if( state) {ReportFailure( "ClearDiagInfoAI", state);
return;
}
write( "%s: ClearDiagInfoAI returned for group %d", name, group);
}
KWP_ReadDTCByStateAI (long state, BYTE data[], DWORD datalen) {
if( state) {
ReportFailure( "ReadDTCByStateAI", state);
return;
}
write( "%s: ReadDTCByStateAI returned %d byte", name, datalen);
}
/* --------------------------------------------------------------------*/
/* ----------------------------------------------------------------------
* File: server.can
* This file implements a simple ECU that responds to tester requests.
*/
variables {
char name[7] = "Server";
mstimer mytimer;
int state = 0; // answer, delay, deny, delay+deny or ignore request.
int gLocked = -1; // -1: locked, 0: open
long gMode = -1;
}
long KWP_StartSessionRI (long mode, long baudrate) {
long code;
gMode = mode;
write( "%s: received StartSession request, mode %d ", name, mode);
switch( state) {
case 0:
write( "%s: answering immediately.", name);
return 0; // Let DLL handle response, returning same values.
case 1:
case 3:
-
8/9/2019 KWP2000 Manual
17/20
15
© Vector Informatik GmbH KWP2000 User Manual Version 1.2
write( "%s: delaying answer.", name);
settimer( mytimer, 200);
return -1; // "I will handle response myself."
case 2:
code = KWP_MnemonicResCode( "EnoA");
write( "%s: sending negative response EnoA (0x%x).", name, code);
return code; // "Send this negative response."
case 4:
write( "%s: ignoring to provoke timeout.", name);
// Do not use timer, i.e. ignore request.
return -1; // "I will handle response myself."
}
}
KWP_DataInd (long rxlength) {
write( "%s: got %d byte", name, rxlength);
}
on timer mytimer {
long code;
char desc[20];
if( state == 1) {
write( "%s: sending delayed positive answer to StartSession.", name);
KWP_StartSessionA( 0, gMode, -1);
} else {
code = KWP_MnemonicResCode( "b-RR");
KWP_ResponseCode( code, desc, 20);
write( "%s: sending delayed negative 0x%x answer (%s) to StartSes-sion.",
name, code, desc);
KWP_StartSessionA( code, -1, -1); // arguments are ignored.
}
}
on key '0' {
// switch server in state "answer immediately to request"
state = 0;
}
on key '1' {
// switch server in state "answer after delay to request"
state = 1;
}
on key '2' {
// switch server in state "answer with negative response"
state = 2;
}
on key '3' {
// switch server in state "delay then deny request"
state = 3;
}
on key '4' {
-
8/9/2019 KWP2000 Manual
18/20
16
Version 1.2 KWP2000 User Manual © Vector Informatik GmbH
// switch server in state "ignore request"
state = 4;
}
long KWP_SecurityAccessRI (long mode, BYTE data[], DWORD datalen) {
BYTE buff[20];
int count;
double number;
if( mode > 0x80 || mode = 8 && 0 == bytencmp( buff, data, 8)) {
state = 0; // answer immediately, if possible
gLocked = 0; // key valid, open server
buff[0] = 0x34;
KWP_SecurityAccessA( 0, mode, buff, 1);
return -1;} else {
state = 2; // deny requests
gLocked = -1;// lock server
return KWP_MnemonicResCode("IK"); // Invalid Key
}
}
MakeSeed (int seed, BYTE seedOut[]) {
int i;
for( i = 0; i < 8; i ++)
seedOut[i] = (i * i * seed - i + 43) % 26 + 'A';}
int bytencmp (BYTE a[], BYTE b[], long len) {
while( len-- > 0)
if( a[len] != b[len]) return a[len] - b[len];
return 0;
}
MakeKey (BYTE seedKeyInOut[]) {
int i;
for( i = 0; i < 8; i ++)
seedKeyInOut[i] += 'a' - 'A';
}
long KWP_TesterPresentRI () {
-
8/9/2019 KWP2000 Manual
19/20
17
© Vector Informatik GmbH KWP2000 User Manual Version 1.2
return 0; // let DLL answer.
// Here should be a timer monitoring, stopping diagnostics on timeout.
}
long KWP_EcuResetRI (DWORD mode) {
BYTE value[1];
value[0] = 43;
KWP_EcuResetA( 0, value, 1);
return -1;
}
long KWP_ReadEcuIdentRI(DWORD what) {
byte info[100];
int len;
switch( what) {
case 1:
len = charToByte( "KWP2000 Demo", info);
break;
case 2:
len = charToByte( "Vector Informatik", info);
break;
case 3:
len = charToByte( "Trs 2002-05-03", info);
break;
default:
len = charToByte( "???", info);
}
KWP_ReadEcuIdentA( 0, info, len);return -1;
}
int charToByte (char source[], byte dest[]) {
int i;
i = elCount(source);
while( i-- > 0) {
dest[i] = source[i];
}
return elCount(source) -1;
}
long KWP_StopSessionRI () {
write( "%s: Stopping diagnostics mode.", name);
gLocked = 1;
return -1; // Do not answer ...
}
long KWP_ReadDTCByStateRI( DWORD status, DWORD group) {
BYTE buff[5]; // dummy
write( "%s: ReadDTCByStateRI( %d, %d)", name, status, group);
KWP_ReadDTCByStateA( 0, buff, 5);
return -1;
}
long KWP_ClearDiagInfoRI ( DWORD group) {
write( "%s: ClearDiagInfoRI( %d)", name, group);
-
8/9/2019 KWP2000 Manual
20/20
18
return 0;
}
long KWP_IOCtrlLocalIdRI (DWORD localId, DWORD control, byte data[], DWORD datalen)
{
write( "%s: IOCtrlLocalIdRI( %d, %d, ..., %d)",
name, localId, control, datalen);
return 0;
}/* --------------------------------------------------------------------*/