Skip to content

File syn_kwp2000.h

FileList > proto > syn_kwp2000.h

Go to the source code of this file

ISO 14230-3 Key Word Protocol 2000 (KWP2000) Server Implementation. More...

  • #include "../common/syn_defs.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_KWP2000_CID
Registered Common Identifier (CID) descriptor.
struct SYN_KWP2000_LID
Registered Local Identifier (LID) descriptor.
struct SYN_KWP2000_Server
KWP2000 Server instance state.

Public Types

Type Name
typedef bool(* SYN_KWP2000_KeyHandler
Security Access key verification callback.
typedef bool(* SYN_KWP2000_MemoryHandler
Memory access callback for 0x34 RequestDownload & 0x36 TransferData.
typedef void(* SYN_KWP2000_ResetHandler
ECU reset callback function pointer.
typedef bool(* SYN_KWP2000_RoutineHandler
Routine control callback.
typedef bool(* SYN_KWP2000_SeedHandler
Security Access seed request callback.
typedef uint8_t SYN_KWP2000_Session
KWP2000 session type.
typedef bool(* SYN_KWP2000_SessionHandler
Session transition callback function pointer.

Public Functions

Type Name
SYN_Status syn_kwp2000_init (SYN_KWP2000_Server * server)
Initialize a KWP2000 diagnostic server instance.
SYN_Status syn_kwp2000_process_request (SYN_KWP2000_Server * server, const uint8_t * req_buf, uint16_t req_len, uint8_t * resp_buf, uint16_t max_resp_len, uint16_t * resp_len)
Process an incoming KWP2000 request message PDU and generate response.
SYN_Status syn_kwp2000_register_cid (SYN_KWP2000_Server * server, uint16_t cid, const void * data, uint16_t len, bool writable)
Register a Common Identifier (CID, 2-byte) for Service 0x22 reading.
SYN_Status syn_kwp2000_register_lid (SYN_KWP2000_Server * server, uint8_t lid, const void * data, uint16_t len, bool writable)
Register a Local Identifier (LID, 1-byte) for Service 0x21 reading.
SYN_Status syn_kwp2000_set_memory_handler (SYN_KWP2000_Server * server, SYN_KWP2000_MemoryHandler cb, void * user_ctx)
Register memory access handler for 0x34 RequestDownload & 0x36 TransferData.
SYN_Status syn_kwp2000_set_reset_handler (SYN_KWP2000_Server * server, SYN_KWP2000_ResetHandler cb, void * user_ctx)
Set ECU reset callback handler and deferred wait delay.
SYN_Status syn_kwp2000_set_routine_handler (SYN_KWP2000_Server * server, SYN_KWP2000_RoutineHandler cb, void * user_ctx)
Register RoutineControl handler.
SYN_Status syn_kwp2000_set_security_handler (SYN_KWP2000_Server * server, SYN_KWP2000_SeedHandler seed_cb, SYN_KWP2000_KeyHandler key_cb, void * user_ctx)
Set security access seed and key callbacks.
SYN_Status syn_kwp2000_set_session_handler (SYN_KWP2000_Server * server, SYN_KWP2000_SessionHandler cb, void * user_ctx)
Set session transition callback handler.
void syn_kwp2000_tick (SYN_KWP2000_Server * server, uint32_t dt_ms)
Tick KWP2000 server S3 timer and deferred reset state.

Macros

Type Name
define SYN_KWP2000_MAX_CIDS 16U
define SYN_KWP2000_MAX_LIDS 16U
define SYN_KWP2000_NRC_CONDITIONS_NOT_CORRECT 0x22U
define SYN_KWP2000_NRC_EXCEEDED_NUMBER_OF_ATTEMPTS 0x36U
define SYN_KWP2000_NRC_INCORRECT_MESSAGE_LENGTH 0x13U
define SYN_KWP2000_NRC_INVALID_KEY 0x35U
define SYN_KWP2000_NRC_REQUEST_OUT_OF_RANGE 0x31U
define SYN_KWP2000_NRC_REQUIRED_TIME_DELAY_NOT_EXPIRED 0x37U
define SYN_KWP2000_NRC_RESPONSE_PENDING 0x78U
define SYN_KWP2000_NRC_SECURITY_ACCESS_DENIED 0x33U
define SYN_KWP2000_NRC_SERVICE_NOT_SUPPORTED 0x11U
define SYN_KWP2000_NRC_SUBFUNCTION_NOT_SUPPORTED 0x12U
define SYN_KWP2000_S3_TIMEOUT_MS 5000U
define SYN_KWP2000_SESSION_DEFAULT 0x81U
define SYN_KWP2000_SESSION_EXTENDED 0x86U
define SYN_KWP2000_SESSION_PROGRAMMING 0x85U
define SYN_KWP2000_SID_CLEAR_DIAGNOSTIC_INFORMATION 0x14U
define SYN_KWP2000_SID_ECU_RESET 0x11U
define SYN_KWP2000_SID_NEGATIVE_RESPONSE 0x7FU
define SYN_KWP2000_SID_READ_DATA_BY_COMMON_IDENTIFIER 0x22U
define SYN_KWP2000_SID_READ_DATA_BY_LOCAL_IDENTIFIER 0x21U
define SYN_KWP2000_SID_READ_DTC_BY_STATUS 0x18U
define SYN_KWP2000_SID_READ_ECU_IDENTIFICATION 0x1AU
define SYN_KWP2000_SID_REQUEST_DOWNLOAD 0x34U
define SYN_KWP2000_SID_REQUEST_TRANSFER_EXIT 0x37U
define SYN_KWP2000_SID_SECURITY_ACCESS 0x27U
define SYN_KWP2000_SID_START_DIAGNOSTIC_SESSION 0x10U
define SYN_KWP2000_SID_START_ROUTINE_BY_LOCAL_IDENTIFIER 0x31U
define SYN_KWP2000_SID_TESTER_PRESENT 0x3EU
define SYN_KWP2000_SID_TRANSFER_DATA 0x36U
define SYN_KWP2000_SID_WRITE_DATA_BY_COMMON_IDENTIFIER 0x2EU

Detailed Description

Provides a zero-allocation, lightweight KWP2000 server protocol stack over ISO 15765-2 ISO-TP for automotive diagnostic session management, Local/Common Identifier (LID/CID) read/write, security access seed/key unlocks, routine control, memory transfer, and ECU reset.

Public Types Documentation

typedef SYN_KWP2000_KeyHandler

Security Access key verification callback.

typedef bool(* SYN_KWP2000_KeyHandler) (uint8_t level, const uint8_t *key, uint16_t key_len, void *user_ctx);


typedef SYN_KWP2000_MemoryHandler

Memory access callback for 0x34 RequestDownload & 0x36 TransferData.

typedef bool(* SYN_KWP2000_MemoryHandler) (bool is_write, uint32_t address, uint32_t size, uint8_t *data_buf, void *user_ctx);


typedef SYN_KWP2000_ResetHandler

ECU reset callback function pointer.

typedef void(* SYN_KWP2000_ResetHandler) (uint8_t reset_type, void *user_ctx);


typedef SYN_KWP2000_RoutineHandler

Routine control callback.

typedef bool(* SYN_KWP2000_RoutineHandler) (uint8_t routine_id, const uint8_t *in_data, uint16_t in_len, uint8_t *out_buf, uint16_t max_out_len, uint16_t *out_len, void *user_ctx);


typedef SYN_KWP2000_SeedHandler

Security Access seed request callback.

typedef bool(* SYN_KWP2000_SeedHandler) (uint8_t level, uint8_t *seed_buf, uint16_t *seed_len, void *user_ctx);


typedef SYN_KWP2000_Session

KWP2000 session type.

typedef uint8_t SYN_KWP2000_Session;


typedef SYN_KWP2000_SessionHandler

Session transition callback function pointer.

typedef bool(* SYN_KWP2000_SessionHandler) (SYN_KWP2000_Session from_session, SYN_KWP2000_Session to_session, void *user_ctx);


Public Functions Documentation

function syn_kwp2000_init

Initialize a KWP2000 diagnostic server instance.

SYN_Status syn_kwp2000_init (
    SYN_KWP2000_Server * server
) 

Parameters:

  • server Pointer to server instance.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if server is NULL.


function syn_kwp2000_process_request

Process an incoming KWP2000 request message PDU and generate response.

SYN_Status syn_kwp2000_process_request (
    SYN_KWP2000_Server * server,
    const uint8_t * req_buf,
    uint16_t req_len,
    uint8_t * resp_buf,
    uint16_t max_resp_len,
    uint16_t * resp_len
) 

Parameters:

  • server Pointer to server instance.
  • req_buf Pointer to request payload buffer.
  • req_len Length of request payload in bytes.
  • resp_buf Pointer to output response buffer.
  • max_resp_len Capacity of output response buffer.
  • resp_len Pointer to store output response length.

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on failure.


function syn_kwp2000_register_cid

Register a Common Identifier (CID, 2-byte) for Service 0x22 reading.

SYN_Status syn_kwp2000_register_cid (
    SYN_KWP2000_Server * server,
    uint16_t cid,
    const void * data,
    uint16_t len,
    bool writable
) 

Parameters:

  • server Pointer to server instance.
  • cid 2-byte Common Identifier.
  • data Pointer to data buffer.
  • len Data length in bytes.
  • writable Is CID writable?

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on error.


function syn_kwp2000_register_lid

Register a Local Identifier (LID, 1-byte) for Service 0x21 reading.

SYN_Status syn_kwp2000_register_lid (
    SYN_KWP2000_Server * server,
    uint8_t lid,
    const void * data,
    uint16_t len,
    bool writable
) 

Parameters:

  • server Pointer to server instance.
  • lid 1-byte Local Identifier.
  • data Pointer to data buffer.
  • len Data length in bytes.
  • writable Is LID writable?

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on error.


function syn_kwp2000_set_memory_handler

Register memory access handler for 0x34 RequestDownload & 0x36 TransferData.

SYN_Status syn_kwp2000_set_memory_handler (
    SYN_KWP2000_Server * server,
    SYN_KWP2000_MemoryHandler cb,
    void * user_ctx
) 

Parameters:

  • server Pointer to server instance.
  • cb Memory handler callback.
  • user_ctx User context pointer.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if server is NULL.


function syn_kwp2000_set_reset_handler

Set ECU reset callback handler and deferred wait delay.

SYN_Status syn_kwp2000_set_reset_handler (
    SYN_KWP2000_Server * server,
    SYN_KWP2000_ResetHandler cb,
    void * user_ctx
) 

Parameters:

  • server Pointer to server instance.
  • cb Reset handler callback.
  • user_ctx User context pointer.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if server is NULL.


function syn_kwp2000_set_routine_handler

Register RoutineControl handler.

SYN_Status syn_kwp2000_set_routine_handler (
    SYN_KWP2000_Server * server,
    SYN_KWP2000_RoutineHandler cb,
    void * user_ctx
) 

Parameters:

  • server Pointer to server instance.
  • cb Routine handler callback.
  • user_ctx User context pointer.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if server is NULL.


function syn_kwp2000_set_security_handler

Set security access seed and key callbacks.

SYN_Status syn_kwp2000_set_security_handler (
    SYN_KWP2000_Server * server,
    SYN_KWP2000_SeedHandler seed_cb,
    SYN_KWP2000_KeyHandler key_cb,
    void * user_ctx
) 

Parameters:

  • server Pointer to server instance.
  • seed_cb Seed request callback.
  • key_cb Key verification callback.
  • user_ctx User context pointer.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if server is NULL.


function syn_kwp2000_set_session_handler

Set session transition callback handler.

SYN_Status syn_kwp2000_set_session_handler (
    SYN_KWP2000_Server * server,
    SYN_KWP2000_SessionHandler cb,
    void * user_ctx
) 

Parameters:

  • server Pointer to server instance.
  • cb Session handler callback.
  • user_ctx User context pointer.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if server is NULL.


function syn_kwp2000_tick

Tick KWP2000 server S3 timer and deferred reset state.

void syn_kwp2000_tick (
    SYN_KWP2000_Server * server,
    uint32_t dt_ms
) 

Parameters:

  • server Pointer to server instance.
  • dt_ms Elapsed time step in milliseconds.

Macro Definition Documentation

define SYN_KWP2000_MAX_CIDS

#define SYN_KWP2000_MAX_CIDS `16U`

Maximum registered Common Identifiers (CID)


define SYN_KWP2000_MAX_LIDS

#define SYN_KWP2000_MAX_LIDS `16U`

Maximum registered Local Identifiers (LID)


define SYN_KWP2000_NRC_CONDITIONS_NOT_CORRECT

#define SYN_KWP2000_NRC_CONDITIONS_NOT_CORRECT `0x22U`

Conditions not correct


define SYN_KWP2000_NRC_EXCEEDED_NUMBER_OF_ATTEMPTS

#define SYN_KWP2000_NRC_EXCEEDED_NUMBER_OF_ATTEMPTS `0x36U`

Exceeded number of attempts


define SYN_KWP2000_NRC_INCORRECT_MESSAGE_LENGTH

#define SYN_KWP2000_NRC_INCORRECT_MESSAGE_LENGTH `0x13U`

Incorrect message length or invalid format


define SYN_KWP2000_NRC_INVALID_KEY

#define SYN_KWP2000_NRC_INVALID_KEY `0x35U`

Invalid key


define SYN_KWP2000_NRC_REQUEST_OUT_OF_RANGE

#define SYN_KWP2000_NRC_REQUEST_OUT_OF_RANGE `0x31U`

Request out of range


define SYN_KWP2000_NRC_REQUIRED_TIME_DELAY_NOT_EXPIRED

#define SYN_KWP2000_NRC_REQUIRED_TIME_DELAY_NOT_EXPIRED `0x37U`

Required time delay not expired


define SYN_KWP2000_NRC_RESPONSE_PENDING

#define SYN_KWP2000_NRC_RESPONSE_PENDING `0x78U`

Request correctly received, response pending \


define SYN_KWP2000_NRC_SECURITY_ACCESS_DENIED

#define SYN_KWP2000_NRC_SECURITY_ACCESS_DENIED `0x33U`

Security access denied


define SYN_KWP2000_NRC_SERVICE_NOT_SUPPORTED

#define SYN_KWP2000_NRC_SERVICE_NOT_SUPPORTED `0x11U`

Service not supported


define SYN_KWP2000_NRC_SUBFUNCTION_NOT_SUPPORTED

#define SYN_KWP2000_NRC_SUBFUNCTION_NOT_SUPPORTED `0x12U`

Subfunction not supported


define SYN_KWP2000_S3_TIMEOUT_MS

#define SYN_KWP2000_S3_TIMEOUT_MS `5000U`

S3 server session timeout in ms


define SYN_KWP2000_SESSION_DEFAULT

#define SYN_KWP2000_SESSION_DEFAULT `0x81U`

Standard diagnostic session


define SYN_KWP2000_SESSION_EXTENDED

#define SYN_KWP2000_SESSION_EXTENDED `0x86U`

Extended diagnostic session


define SYN_KWP2000_SESSION_PROGRAMMING

#define SYN_KWP2000_SESSION_PROGRAMMING `0x85U`

ECU programming / bootloader session


define SYN_KWP2000_SID_CLEAR_DIAGNOSTIC_INFORMATION

#define SYN_KWP2000_SID_CLEAR_DIAGNOSTIC_INFORMATION `0x14U`

ClearDiagnosticInformation


define SYN_KWP2000_SID_ECU_RESET

#define SYN_KWP2000_SID_ECU_RESET `0x11U`

ECUReset


define SYN_KWP2000_SID_NEGATIVE_RESPONSE

#define SYN_KWP2000_SID_NEGATIVE_RESPONSE `0x7FU`

NegativeResponse


define SYN_KWP2000_SID_READ_DATA_BY_COMMON_IDENTIFIER

#define SYN_KWP2000_SID_READ_DATA_BY_COMMON_IDENTIFIER `0x22U`

ReadDataByCommonIdentifier


define SYN_KWP2000_SID_READ_DATA_BY_LOCAL_IDENTIFIER

#define SYN_KWP2000_SID_READ_DATA_BY_LOCAL_IDENTIFIER `0x21U`

ReadDataByLocalIdentifier


define SYN_KWP2000_SID_READ_DTC_BY_STATUS

#define SYN_KWP2000_SID_READ_DTC_BY_STATUS `0x18U`

ReadDiagnosticTroubleCodesByStatus


define SYN_KWP2000_SID_READ_ECU_IDENTIFICATION

#define SYN_KWP2000_SID_READ_ECU_IDENTIFICATION `0x1AU`

ReadECUIdentification


define SYN_KWP2000_SID_REQUEST_DOWNLOAD

#define SYN_KWP2000_SID_REQUEST_DOWNLOAD `0x34U`

RequestDownload


define SYN_KWP2000_SID_REQUEST_TRANSFER_EXIT

#define SYN_KWP2000_SID_REQUEST_TRANSFER_EXIT `0x37U`

RequestTransferExit


define SYN_KWP2000_SID_SECURITY_ACCESS

#define SYN_KWP2000_SID_SECURITY_ACCESS `0x27U`

SecurityAccess


define SYN_KWP2000_SID_START_DIAGNOSTIC_SESSION

#define SYN_KWP2000_SID_START_DIAGNOSTIC_SESSION `0x10U`

StartDiagnosticSession


define SYN_KWP2000_SID_START_ROUTINE_BY_LOCAL_IDENTIFIER

#define SYN_KWP2000_SID_START_ROUTINE_BY_LOCAL_IDENTIFIER `0x31U`

StartRoutineByLocalIdentifier


define SYN_KWP2000_SID_TESTER_PRESENT

#define SYN_KWP2000_SID_TESTER_PRESENT `0x3EU`

TesterPresent


define SYN_KWP2000_SID_TRANSFER_DATA

#define SYN_KWP2000_SID_TRANSFER_DATA `0x36U`

TransferData


define SYN_KWP2000_SID_WRITE_DATA_BY_COMMON_IDENTIFIER

#define SYN_KWP2000_SID_WRITE_DATA_BY_COMMON_IDENTIFIER `0x2EU`

WriteDataByCommonIdentifier



The documentation for this class was generated from the following file src/syntropic/proto/syn_kwp2000.h