ndSendKey
- Updated2025-10-07
- 1 minute(s) read
Purpose
Executes the SecurityAccess service to send a key to the ECU.
Format
long ndSendKey(
TD1 *diagRef,
unsigned char accessMode,
unsigned char keyIn[],
long len,
LVBoolean *success);
Input
diagRef
Specifies the diagnostic session handle, obtained from ndOpenDiagnosticOnCANFD or ndOpenDiagnosticOnIPStack and passed to subsequent diagnostic functions. Normally, it is not necessary to manually manipulate the elements of this struct.
accessMode
Indicates the security level to be granted. The values are application specific. This is an even number, usually 2.
keyIn
Defines the key data to be sent to the ECU.
len
Must contain the number of valid data bytes in keyIn. Output
success
Indicates successful receipt of a positive response message for this diagnostic service.
Return Value
The return value indicates the function call status as a signed 32-bit integer. Zero means the function executed successfully. A negative value specifies an error, which means the function did not perform the expected behavior. A positive value specifies a warning, which means the function performed as expected, but a condition arose that may require attention.
Use the ndStatusToString function to obtain a descriptive string for the return value.
DescriptionThe usual procedure for getting a security access to the ECU is as follows:
- Request a seed from the ECU using ndRequestSeed with access mode = n.
- From the seed, compute a key for the ECU on the host.
- Send the key to the ECU using ndSendKey with access mode = n + 1.
- The security access is granted if the ECU validates the key sent. Otherwise, an error is returned.