iso14229 0.10.0
ISO14229-1 (UDS) C Library
Loading...
Searching...
No Matches
iso14229.c File Reference

ISO14229-1 (UDS) library. More...

#include "iso14229.h"
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include <net/if.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <linux/can/isotp.h>
#include <poll.h>
#include <sys/socket.h>
#include <sys/types.h>
Include dependency graph for iso14229.c:

Go to the source code of this file.

Macros

#define STATE_IDLE   0
#define STATE_SENDING   1
#define STATE_AWAIT_SEND_COMPLETE   2
#define STATE_AWAIT_RESPONSE   3

Typedefs

typedef UDSErr_t(*) UDSService(UDSServer_t *srv, UDSReq_t *r)
 signature of internal service handlers

Functions

bool UDSSecurityAccessLevelIsReserved (uint8_t securityLevel)
 returns true if a security level is reserved per ISO14229-1:2020 Table 42
bool UDSErrIsNRC (UDSErr_t err)
 returns true if err is defined in ISO14229-1:2020 as an NRC
UDSErr_t UDSClientInit (UDSClient_t *client)
 Call this once.
UDSErr_t UDSSendBytes (UDSClient_t *client, const uint8_t *data, uint16_t size)
 Send user-defined bytes to a UDS server.
UDSErr_t UDSSendECUReset (UDSClient_t *client, uint8_t type)
 Request ECUReset.
UDSErr_t UDSSendDiagSessCtrl (UDSClient_t *client, uint8_t mode)
 Change the diagnostic session.
UDSErr_t UDSSendCommCtrl (UDSClient_t *client, uint8_t ctrl, uint8_t comm)
 Change communication settings.
UDSErr_t UDSSendTesterPresent (UDSClient_t *client)
 What's up?
UDSErr_t UDSSendRDBI (UDSClient_t *client, const uint16_t *didList, const uint16_t numDataIdentifiers)
 Read Data By Identifier.
UDSErr_t UDSSendWDBI (UDSClient_t *client, uint16_t dataIdentifier, const uint8_t *data, uint16_t size)
 Write Data By Identifier.
UDSErr_t UDSSendRoutineCtrl (UDSClient_t *client, uint8_t type, uint16_t routineIdentifier, const uint8_t *data, uint16_t size)
 Request to Twiddle Routines.
UDSErr_t UDSSendRequestDownload (UDSClient_t *client, uint8_t dataFormatIdentifier, uint8_t addressAndLengthFormatIdentifier, size_t memoryAddress, size_t memorySize)
 Request to Download via TransferData.
UDSErr_t UDSSendRequestUpload (UDSClient_t *client, uint8_t dataFormatIdentifier, uint8_t addressAndLengthFormatIdentifier, size_t memoryAddress, size_t memorySize)
 Request to Upload via TransferData.
UDSErr_t UDSSendTransferData (UDSClient_t *client, uint8_t blockSequenceCounter, const uint16_t blockLength, const uint8_t *data, uint16_t size)
 Transfer Data to/from a buffer.
UDSErr_t UDSSendTransferDataStream (UDSClient_t *client, uint8_t blockSequenceCounter, const uint16_t blockLength, FILE *fd)
 Transfer Data to/from a file.
UDSErr_t UDSSendRequestTransferExit (UDSClient_t *client)
 Call this when finished with TransferData.
UDSErr_t UDSSendRequestFileTransfer (UDSClient_t *client, uint8_t mode, const char *filePath, size_t fileSizeUncompressed, size_t fileSizeCompressed)
 filesystem-based frontend to TransferData
UDSErr_t UDSCtrlDTCSetting (UDSClient_t *client, uint8_t dtcSettingType, uint8_t *data, uint16_t size)
 control DTC setting
UDSErr_t UDSSendSecurityAccess (UDSClient_t *client, uint8_t level, uint8_t *data, uint16_t size)
 Get Security Access.
UDSErr_t UDSUnpackSecurityAccessResponse (const UDSClient_t *client, struct SecurityAccessResponse *resp)
 Parse server's response to SecurityAccess.
UDSErr_t UDSUnpackRoutineControlResponse (const UDSClient_t *client, struct RoutineControlResponse *resp)
 Parse server's response to RoutineControl.
UDSErr_t UDSUnpackRequestDownloadResponse (const UDSClient_t *client, struct RequestDownloadResponse *resp)
 Parse server's response to RequestDownload.
UDSErr_t UDSClientPoll (UDSClient_t *client)
 Call at <5ms intervals.
UDSErr_t UDSUnpackRDBIResponse (UDSClient_t *client, UDSRDBIVar_t *vars, uint16_t numVars)
 Parse server's response to RDBI.
UDSErr_t UDSServerInit (UDSServer_t *srv)
 call this once
void UDSServerPoll (UDSServer_t *srv)
 Call this at <5ms intervals.
UDSTpSize_t UDSTpSend (UDSTp_t *hdl, const uint8_t *buf, UDSTpSize_t len, const UDSSDU_t *info)
 Send to transport.
UDSTpSize_t UDSTpRecv (UDSTp_t *hdl, uint8_t *buf, size_t bufsize, UDSSDU_t *info)
 Receive from transport.
UDSTpStatus_t UDSTpPoll (UDSTp_t *hdl)
 call this at <5ms intervals
UDSErr_t UDSServerTpISOTpCInit (UDSTpISOTpC_t *tp, uint32_t source_addr, uint32_t target_addr, uint32_t source_addr_func)
 Initialize isotp-c transport for UDSServer_t.
UDSErr_t UDSClientTpISOTpCInit (UDSTpISOTpC_t *tp, uint32_t target_addr, uint32_t source_addr, uint32_t target_addr_func)
 Initialize isotp-c transport for UDSClient_t.
UDSErr_t UDSTpISOTpCSocketCANInit (UDSTpISOTpCSocketCAN_t *tp, const char *ifname, uint32_t source_addr, uint32_t target_addr, uint32_t source_addr_func, uint32_t target_addr_func)
 Initialize the transport.
void UDSTpISOTpCSocketCANDeinit (UDSTpISOTpCSocketCAN_t *tp)
 release socket
UDSErr_t UDSServerTpIsoTpSockInit (UDSTpIsoTpSock_t *tp, const char *ifname, uint32_t source_addr, uint32_t target_addr, uint32_t source_addr_func)
 for UDSServer_t
UDSErr_t UDSClientTpIsoTpSockInit (UDSTpIsoTpSock_t *tp, const char *ifname, uint32_t source_addr, uint32_t target_addr, uint32_t target_addr_func)
 for UDSClient_t
void UDSTpIsoTpSockDeinit (UDSTpIsoTpSock_t *tp)
 release sockets

Detailed Description

See also
https://github.com/driftregion/iso14229

Definition in file iso14229.c.

Typedef Documentation

◆ UDSService

typedef UDSErr_t(*) UDSService(UDSServer_t *srv, UDSReq_t *r)

Definition at line 2373 of file iso14229.c.

Function Documentation

◆ UDSClientInit()

UDSErr_t UDSClientInit ( UDSClient_t * client)

Definition at line 55 of file iso14229.c.

◆ UDSClientPoll()

UDSErr_t UDSClientPoll ( UDSClient_t * client)

Definition at line 922 of file iso14229.c.

◆ UDSClientTpISOTpCInit()

UDSErr_t UDSClientTpISOTpCInit ( UDSTpISOTpC_t * tp,
uint32_t target_addr,
uint32_t source_addr,
uint32_t target_addr_func )
Parameters
tpUDSTpISOTpC_t instance.
target_addrClient sends physical requests to this address.
source_addrClient listens for responses at this address.
target_addr_funcClient sends functional transmissions to this address.

Definition at line 3136 of file iso14229.c.

◆ UDSClientTpIsoTpSockInit()

UDSErr_t UDSClientTpIsoTpSockInit ( UDSTpIsoTpSock_t * tp,
const char * ifname,
uint32_t source_addr,
uint32_t target_addr,
uint32_t target_addr_func )

Definition at line 3616 of file iso14229.c.

◆ UDSCtrlDTCSetting()

UDSErr_t UDSCtrlDTCSetting ( UDSClient_t * client,
uint8_t dtcSettingType,
uint8_t * data,
uint16_t size )

Definition at line 762 of file iso14229.c.

◆ UDSErrIsNRC()

bool UDSErrIsNRC ( UDSErr_t err)

Definition at line 2925 of file iso14229.c.

◆ UDSSecurityAccessLevelIsReserved()

bool UDSSecurityAccessLevelIsReserved ( uint8_t securityLevel)

Definition at line 2708 of file iso14229.c.

◆ UDSSendBytes()

UDSErr_t UDSSendBytes ( UDSClient_t * client,
const uint8_t * data,
uint16_t size )

Definition at line 344 of file iso14229.c.

◆ UDSSendCommCtrl()

UDSErr_t UDSSendCommCtrl ( UDSClient_t * client,
uint8_t ctrl,
uint8_t comm )

Definition at line 379 of file iso14229.c.

◆ UDSSendDiagSessCtrl()

UDSErr_t UDSSendDiagSessCtrl ( UDSClient_t * client,
uint8_t mode )

Definition at line 368 of file iso14229.c.

◆ UDSSendECUReset()

UDSErr_t UDSSendECUReset ( UDSClient_t * client,
uint8_t type )

Definition at line 357 of file iso14229.c.

◆ UDSSendRDBI()

UDSErr_t UDSSendRDBI ( UDSClient_t * client,
const uint16_t * didList,
const uint16_t numDataIdentifiers )

Definition at line 402 of file iso14229.c.

◆ UDSSendRequestDownload()

UDSErr_t UDSSendRequestDownload ( UDSClient_t * client,
uint8_t dataFormatIdentifier,
uint8_t addressAndLengthFormatIdentifier,
size_t memoryAddress,
size_t memorySize )

Definition at line 494 of file iso14229.c.

◆ UDSSendRequestFileTransfer()

UDSErr_t UDSSendRequestFileTransfer ( UDSClient_t * client,
uint8_t mode,
const char * filePath,
size_t fileSizeUncompressed,
size_t fileSizeCompressed )

Definition at line 637 of file iso14229.c.

◆ UDSSendRequestTransferExit()

UDSErr_t UDSSendRequestTransferExit ( UDSClient_t * client)

Definition at line 627 of file iso14229.c.

◆ UDSSendRequestUpload()

UDSErr_t UDSSendRequestUpload ( UDSClient_t * client,
uint8_t dataFormatIdentifier,
uint8_t addressAndLengthFormatIdentifier,
size_t memoryAddress,
size_t memorySize )

Definition at line 535 of file iso14229.c.

◆ UDSSendRoutineCtrl()

UDSErr_t UDSSendRoutineCtrl ( UDSClient_t * client,
uint8_t type,
uint16_t routineIdentifier,
const uint8_t * data,
uint16_t size )

Definition at line 456 of file iso14229.c.

◆ UDSSendSecurityAccess()

UDSErr_t UDSSendSecurityAccess ( UDSClient_t * client,
uint8_t level,
uint8_t * data,
uint16_t size )

Definition at line 805 of file iso14229.c.

◆ UDSSendTesterPresent()

UDSErr_t UDSSendTesterPresent ( UDSClient_t * client)

Definition at line 391 of file iso14229.c.

◆ UDSSendTransferData()

UDSErr_t UDSSendTransferData ( UDSClient_t * client,
uint8_t blockSequenceCounter,
const uint16_t blockLength,
const uint8_t * data,
uint16_t size )

Definition at line 575 of file iso14229.c.

◆ UDSSendTransferDataStream()

UDSErr_t UDSSendTransferDataStream ( UDSClient_t * client,
uint8_t blockSequenceCounter,
const uint16_t blockLength,
FILE * fd )

Definition at line 599 of file iso14229.c.

◆ UDSSendWDBI()

UDSErr_t UDSSendWDBI ( UDSClient_t * client,
uint16_t dataIdentifier,
const uint8_t * data,
uint16_t size )

Definition at line 425 of file iso14229.c.

◆ UDSServerInit()

UDSErr_t UDSServerInit ( UDSServer_t * srv)

Definition at line 2558 of file iso14229.c.

◆ UDSServerPoll()

void UDSServerPoll ( UDSServer_t * srv)

Definition at line 2575 of file iso14229.c.

◆ UDSServerTpISOTpCInit()

UDSErr_t UDSServerTpISOTpCInit ( UDSTpISOTpC_t * tp,
uint32_t source_addr,
uint32_t target_addr,
uint32_t source_addr_func )
Parameters
tpUDSTpISOTpC_t instance.
source_addrServer listens for physical transmissions on this address.
target_addrServer sends responses to this address.
source_addr_funcServer listens for functional transmissions on this address.

Definition at line 3131 of file iso14229.c.

◆ UDSServerTpIsoTpSockInit()

UDSErr_t UDSServerTpIsoTpSockInit ( UDSTpIsoTpSock_t * tp,
const char * ifname,
uint32_t source_addr,
uint32_t target_addr,
uint32_t source_addr_func )

Definition at line 3589 of file iso14229.c.

◆ UDSTpISOTpCSocketCANDeinit()

void UDSTpISOTpCSocketCANDeinit ( UDSTpISOTpCSocketCAN_t * tp)

Definition at line 3366 of file iso14229.c.

◆ UDSTpISOTpCSocketCANInit()

UDSErr_t UDSTpISOTpCSocketCANInit ( UDSTpISOTpCSocketCAN_t * tp,
const char * ifname,
uint32_t source_addr,
uint32_t target_addr,
uint32_t source_addr_func,
uint32_t target_addr_func )
Parameters
tptransport
ifnamecan0, vcan0
source_addr
target_addr
source_addr_func
target_addr_func

Definition at line 3341 of file iso14229.c.

◆ UDSTpIsoTpSockDeinit()

void UDSTpIsoTpSockDeinit ( UDSTpIsoTpSock_t * tp)

Definition at line 3642 of file iso14229.c.

◆ UDSTpPoll()

UDSTpStatus_t UDSTpPoll ( UDSTp_t * hdl)

Definition at line 2674 of file iso14229.c.

◆ UDSTpRecv()

UDSTpSize_t UDSTpRecv ( UDSTp_t * hdl,
uint8_t * buf,
size_t bufsize,
UDSSDU_t * info )

Definition at line 2668 of file iso14229.c.

◆ UDSTpSend()

UDSTpSize_t UDSTpSend ( UDSTp_t * hdl,
const uint8_t * buf,
UDSTpSize_t len,
const UDSSDU_t * info )

Definition at line 2662 of file iso14229.c.

◆ UDSUnpackRDBIResponse()

UDSErr_t UDSUnpackRDBIResponse ( UDSClient_t * client,
UDSRDBIVar_t * vars,
uint16_t numVars )

Definition at line 940 of file iso14229.c.

◆ UDSUnpackRequestDownloadResponse()

UDSErr_t UDSUnpackRequestDownloadResponse ( const UDSClient_t * client,
struct RequestDownloadResponse * resp )

Definition at line 896 of file iso14229.c.

◆ UDSUnpackRoutineControlResponse()

UDSErr_t UDSUnpackRoutineControlResponse ( const UDSClient_t * client,
struct RoutineControlResponse * resp )

Definition at line 868 of file iso14229.c.

◆ UDSUnpackSecurityAccessResponse()

UDSErr_t UDSUnpackSecurityAccessResponse ( const UDSClient_t * client,
struct SecurityAccessResponse * resp )

Definition at line 843 of file iso14229.c.