iso14229 0.9.0
ISO14229-1 (UDS) C Library
|
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 <assert.h>
#include <stddef.h>
Go to the source code of this file.
Classes | |
struct | Msg |
Macros | |
#define | STATE_IDLE 0 |
#define | STATE_SENDING 1 |
#define | STATE_AWAIT_SEND_COMPLETE 2 |
#define | STATE_AWAIT_RESPONSE 3 |
#define | MAX_NUM_TP 16 |
#define | NUM_MSGS 8 |
Typedefs | |
typedef UDSErr_t(* | UDSService) (UDSServer_t *srv, UDSReq_t *r) |
Functions | |
UDSErr_t | UDSClientInit (UDSClient_t *client) |
UDSErr_t | UDSSendBytes (UDSClient_t *client, const uint8_t *data, uint16_t size) |
UDSErr_t | UDSSendECUReset (UDSClient_t *client, uint8_t type) |
UDSErr_t | UDSSendDiagSessCtrl (UDSClient_t *client, uint8_t mode) |
UDSErr_t | UDSSendCommCtrl (UDSClient_t *client, uint8_t ctrl, uint8_t comm) |
UDSErr_t | UDSSendTesterPresent (UDSClient_t *client) |
UDSErr_t | UDSSendRDBI (UDSClient_t *client, const uint16_t *didList, const uint16_t numDataIdentifiers) |
UDSErr_t | UDSSendWDBI (UDSClient_t *client, uint16_t dataIdentifier, const uint8_t *data, uint16_t size) |
UDSErr_t | UDSSendRoutineCtrl (UDSClient_t *client, uint8_t type, uint16_t routineIdentifier, const uint8_t *data, uint16_t size) |
UDSErr_t | UDSSendRequestDownload (UDSClient_t *client, uint8_t dataFormatIdentifier, uint8_t addressAndLengthFormatIdentifier, size_t memoryAddress, size_t memorySize) |
UDSErr_t | UDSSendRequestUpload (UDSClient_t *client, uint8_t dataFormatIdentifier, uint8_t addressAndLengthFormatIdentifier, size_t memoryAddress, size_t memorySize) |
UDSErr_t | UDSSendTransferData (UDSClient_t *client, uint8_t blockSequenceCounter, const uint16_t blockLength, const uint8_t *data, uint16_t size) |
UDSErr_t | UDSSendTransferDataStream (UDSClient_t *client, uint8_t blockSequenceCounter, const uint16_t blockLength, FILE *fd) |
UDSErr_t | UDSSendRequestTransferExit (UDSClient_t *client) |
UDSErr_t | UDSSendRequestFileTransfer (UDSClient_t *client, uint8_t mode, const char *filePath, uint8_t dataFormatIdentifier, uint8_t fileSizeParameterLength, size_t fileSizeUncompressed, size_t fileSizeCompressed) |
UDSErr_t | UDSCtrlDTCSetting (UDSClient_t *client, uint8_t dtcSettingType, uint8_t *data, uint16_t size) |
UDSErr_t | UDSSendSecurityAccess (UDSClient_t *client, uint8_t level, uint8_t *data, uint16_t size) |
UDSErr_t | UDSUnpackSecurityAccessResponse (const UDSClient_t *client, struct SecurityAccessResponse *resp) |
UDSErr_t | UDSUnpackRoutineControlResponse (const UDSClient_t *client, struct RoutineControlResponse *resp) |
UDSErr_t | UDSUnpackRequestDownloadResponse (const UDSClient_t *client, struct RequestDownloadResponse *resp) |
UDSErr_t | UDSClientPoll (UDSClient_t *client) |
UDSErr_t | UDSUnpackRDBIResponse (UDSClient_t *client, UDSRDBIVar_t *vars, uint16_t numVars) |
UDSErr_t | UDSServerInit (UDSServer_t *srv) |
void | UDSServerPoll (UDSServer_t *srv) |
ssize_t | UDSTpSend (struct UDSTp *hdl, const uint8_t *buf, ssize_t len, UDSSDU_t *info) |
ssize_t | UDSTpRecv (struct UDSTp *hdl, uint8_t *buf, size_t bufsize, UDSSDU_t *info) |
UDSTpStatus_t | UDSTpPoll (struct UDSTp *hdl) |
uint32_t | UDSMillis (void) |
Get time in milliseconds. | |
bool | UDSSecurityAccessLevelIsReserved (uint8_t subFunction) |
Check if a security level is reserved per ISO14229-1:2020 Table 42. | |
const char * | UDSErrToStr (UDSErr_t err) |
const char * | UDSEventToStr (UDSEvent_t evt) |
bool | UDSErrIsNRC (UDSErr_t err) |
UDSErr_t | UDSISOTpCInit (UDSISOTpC_t *tp, const UDSISOTpCConfig_t *cfg) |
uint32_t | isotp_user_get_us (void) |
user implemented, gets the amount of time passed since the last call in microseconds | |
__attribute__ ((format(printf, 1, 2))) | |
int | isotp_user_send_can (const uint32_t arbitration_id, const uint8_t *data, const uint8_t size, void *user_data) |
user implemented, send can message. should return ISOTP_RET_OK when success. | |
UDSErr_t | UDSTpISOTpCInit (UDSTpISOTpC_t *tp, const char *ifname, uint32_t source_addr, uint32_t target_addr, uint32_t source_addr_func, uint32_t target_addr_func) |
void | UDSTpISOTpCDeinit (UDSTpISOTpC_t *tp) |
UDSErr_t | UDSTpIsoTpSockInitServer (UDSTpIsoTpSock_t *tp, const char *ifname, uint32_t source_addr, uint32_t target_addr, uint32_t source_addr_func) |
UDSErr_t | UDSTpIsoTpSockInitClient (UDSTpIsoTpSock_t *tp, const char *ifname, uint32_t source_addr, uint32_t target_addr, uint32_t target_addr_func) |
void | UDSTpIsoTpSockDeinit (UDSTpIsoTpSock_t *tp) |
UDSTp_t * | ISOTPMockNew (const char *name, ISOTPMockArgs_t *args) |
Create a mock transport. It is connected by default to a broadcast network of all other mock transports in the same process. | |
void | ISOTPMockConnect (UDSTp_t *tp1, UDSTp_t *tp2) |
void | ISOTPMockLogToFile (const char *filename) |
write all messages to a file | |
void | ISOTPMockLogToStdout (void) |
void | ISOTPMockReset (void) |
clear all transports and close the log file | |
void | ISOTPMockFree (UDSTp_t *tp) |
int | isotp_send (IsoTpLink *link, const uint8_t payload[], uint16_t size) |
PUBLIC FUNCTIONS ///. | |
int | isotp_send_with_id (IsoTpLink *link, uint32_t id, const uint8_t payload[], uint16_t size) |
See isotp_send, with the exception that this function is used only for functional addressing. | |
void | isotp_on_can_message (IsoTpLink *link, const uint8_t *data, uint8_t len) |
Handles incoming CAN messages. Determines whether an incoming message is a valid ISO-TP frame or not and handles it accordingly. | |
int | isotp_receive (IsoTpLink *link, uint8_t *payload, const uint16_t payload_size, uint16_t *out_size) |
Receives and parses the received data and copies the parsed data in to the internal buffer. | |
void | isotp_init_link (IsoTpLink *link, uint32_t sendid, uint8_t *sendbuf, uint16_t sendbufsize, uint8_t *recvbuf, uint16_t recvbufsize) |
Initialises the ISO-TP library. | |
void | isotp_poll (IsoTpLink *link) |
Polling function; call this function periodically to handle timeouts, send consecutive frames, etc. | |
#define MAX_NUM_TP 16 |
Definition at line 3505 of file iso14229.c.
#define NUM_MSGS 8 |
Definition at line 3506 of file iso14229.c.
#define STATE_AWAIT_RESPONSE 3 |
Definition at line 18 of file iso14229.c.
#define STATE_AWAIT_SEND_COMPLETE 2 |
Definition at line 17 of file iso14229.c.
#define STATE_IDLE 0 |
Definition at line 15 of file iso14229.c.
#define STATE_SENDING 1 |
Definition at line 16 of file iso14229.c.
typedef UDSErr_t(* UDSService) (UDSServer_t *srv, UDSReq_t *r) |
Definition at line 2219 of file iso14229.c.
__attribute__ | ( | (format(printf, 1, 2)) | ) |
Definition at line 3031 of file iso14229.c.
void isotp_init_link | ( | IsoTpLink * | link, |
uint32_t | sendid, | ||
uint8_t * | sendbuf, | ||
uint16_t | sendbufsize, | ||
uint8_t * | recvbuf, | ||
uint16_t | recvbufsize | ||
) |
Initialises the ISO-TP library.
link | The Struct containing the data for linking an application to a CAN instance. The data stored in this stru... Definition iso14229.h:1504 |
sendid | The ID used to send data to other CAN nodes. |
sendbuf | A pointer to an area in memory which can be used as a buffer for data to be sent. |
sendbufsize | The size of the buffer area. |
recvbuf | A pointer to an area in memory which can be used as a buffer for data to be received. |
recvbufsize | The size of the buffer area. |
Definition at line 4205 of file iso14229.c.
void isotp_on_can_message | ( | IsoTpLink * | link, |
const uint8_t * | data, | ||
uint8_t | len | ||
) |
Handles incoming CAN messages. Determines whether an incoming message is a valid ISO-TP frame or not and handles it accordingly.
link | The instance used for transceiving data. |
data | The data received via CAN. |
len | The length of the data received. |
Definition at line 4036 of file iso14229.c.
void isotp_poll | ( | IsoTpLink * | link | ) |
Polling function; call this function periodically to handle timeouts, send consecutive frames, etc.
link | The instance used. |
Definition at line 4218 of file iso14229.c.
int isotp_receive | ( | IsoTpLink * | link, |
uint8_t * | payload, | ||
const uint16_t | payload_size, | ||
uint16_t * | out_size | ||
) |
Receives and parses the received data and copies the parsed data in to the internal buffer.
link | The IsoTpLink instance used to transceive data. |
payload | A pointer to an area in memory where the raw data is copied from. |
payload_size | The size of the received (raw) CAN data. |
out_size | A reference to a variable which will contain the size of the actual (parsed) data. |
Definition at line 4185 of file iso14229.c.
int isotp_send | ( | IsoTpLink * | link, |
const uint8_t | payload[], | ||
uint16_t | size | ||
) |
PUBLIC FUNCTIONS ///.
Sends ISO-TP frames via CAN, using the ID set in the initialising function.
Definition at line 3979 of file iso14229.c.
int isotp_send_with_id | ( | IsoTpLink * | link, |
uint32_t | id, | ||
const uint8_t | payload[], | ||
uint16_t | size | ||
) |
See isotp_send, with the exception that this function is used only for functional addressing.
Definition at line 3983 of file iso14229.c.
uint32_t isotp_user_get_us | ( | void | ) |
user implemented, gets the amount of time passed since the last call in microseconds
Definition at line 3029 of file iso14229.c.
int isotp_user_send_can | ( | const uint32_t | arbitration_id, |
const uint8_t * | data, | ||
const uint8_t | size, | ||
void * | arg | ||
) |
user implemented, send can message. should return ISOTP_RET_OK when success.
Definition at line 3041 of file iso14229.c.
void ISOTPMockFree | ( | UDSTp_t * | tp | ) |
Definition at line 3711 of file iso14229.c.
void ISOTPMockLogToFile | ( | const char * | filename | ) |
write all messages to a file
filename | log file name (will be overwritten) |
Definition at line 3680 of file iso14229.c.
void ISOTPMockLogToStdout | ( | void | ) |
Definition at line 3697 of file iso14229.c.
UDSTp_t * ISOTPMockNew | ( | const char * | name, |
ISOTPMockArgs_t * | args | ||
) |
Create a mock transport. It is connected by default to a broadcast network of all other mock transports in the same process.
name | optional name of the transport (can be NULL) |
Definition at line 3660 of file iso14229.c.
void ISOTPMockReset | ( | void | ) |
clear all transports and close the log file
Definition at line 3704 of file iso14229.c.
UDSErr_t UDSClientInit | ( | UDSClient_t * | client | ) |
Definition at line 20 of file iso14229.c.
UDSErr_t UDSClientPoll | ( | UDSClient_t * | client | ) |
Definition at line 827 of file iso14229.c.
UDSErr_t UDSCtrlDTCSetting | ( | UDSClient_t * | client, |
uint8_t | dtcSettingType, | ||
uint8_t * | data, | ||
uint16_t | size | ||
) |
Definition at line 667 of file iso14229.c.
bool UDSErrIsNRC | ( | UDSErr_t | err | ) |
Definition at line 2777 of file iso14229.c.
const char * UDSErrToStr | ( | UDSErr_t | err | ) |
Definition at line 2574 of file iso14229.c.
const char * UDSEventToStr | ( | UDSEvent_t | evt | ) |
Definition at line 2723 of file iso14229.c.
UDSErr_t UDSISOTpCInit | ( | UDSISOTpC_t * | tp, |
const UDSISOTpCConfig_t * | cfg | ||
) |
Definition at line 2962 of file iso14229.c.
uint32_t UDSMillis | ( | void | ) |
Get time in milliseconds.
Definition at line 2532 of file iso14229.c.
bool UDSSecurityAccessLevelIsReserved | ( | uint8_t | subFunction | ) |
Check if a security level is reserved per ISO14229-1:2020 Table 42.
securityLevel |
Definition at line 2560 of file iso14229.c.
UDSErr_t UDSSendBytes | ( | UDSClient_t * | client, |
const uint8_t * | data, | ||
uint16_t | size | ||
) |
Definition at line 306 of file iso14229.c.
UDSErr_t UDSSendCommCtrl | ( | UDSClient_t * | client, |
uint8_t | ctrl, | ||
uint8_t | comm | ||
) |
Definition at line 341 of file iso14229.c.
UDSErr_t UDSSendDiagSessCtrl | ( | UDSClient_t * | client, |
uint8_t | mode | ||
) |
Definition at line 330 of file iso14229.c.
UDSErr_t UDSSendECUReset | ( | UDSClient_t * | client, |
uint8_t | type | ||
) |
Definition at line 319 of file iso14229.c.
UDSErr_t UDSSendRDBI | ( | UDSClient_t * | client, |
const uint16_t * | didList, | ||
const uint16_t | numDataIdentifiers | ||
) |
Definition at line 364 of file iso14229.c.
UDSErr_t UDSSendRequestDownload | ( | UDSClient_t * | client, |
uint8_t | dataFormatIdentifier, | ||
uint8_t | addressAndLengthFormatIdentifier, | ||
size_t | memoryAddress, | ||
size_t | memorySize | ||
) |
Definition at line 456 of file iso14229.c.
UDSErr_t UDSSendRequestFileTransfer | ( | UDSClient_t * | client, |
uint8_t | mode, | ||
const char * | filePath, | ||
uint8_t | dataFormatIdentifier, | ||
uint8_t | fileSizeParameterLength, | ||
size_t | fileSizeUncompressed, | ||
size_t | fileSizeCompressed | ||
) |
Definition at line 599 of file iso14229.c.
UDSErr_t UDSSendRequestTransferExit | ( | UDSClient_t * | client | ) |
Definition at line 589 of file iso14229.c.
UDSErr_t UDSSendRequestUpload | ( | UDSClient_t * | client, |
uint8_t | dataFormatIdentifier, | ||
uint8_t | addressAndLengthFormatIdentifier, | ||
size_t | memoryAddress, | ||
size_t | memorySize | ||
) |
Definition at line 497 of file iso14229.c.
UDSErr_t UDSSendRoutineCtrl | ( | UDSClient_t * | client, |
uint8_t | type, | ||
uint16_t | routineIdentifier, | ||
const uint8_t * | data, | ||
uint16_t | size | ||
) |
Definition at line 418 of file iso14229.c.
UDSErr_t UDSSendSecurityAccess | ( | UDSClient_t * | client, |
uint8_t | level, | ||
uint8_t * | data, | ||
uint16_t | size | ||
) |
Definition at line 710 of file iso14229.c.
UDSErr_t UDSSendTesterPresent | ( | UDSClient_t * | client | ) |
Definition at line 353 of file iso14229.c.
UDSErr_t UDSSendTransferData | ( | UDSClient_t * | client, |
uint8_t | blockSequenceCounter, | ||
const uint16_t | blockLength, | ||
const uint8_t * | data, | ||
uint16_t | size | ||
) |
Definition at line 537 of file iso14229.c.
UDSErr_t UDSSendTransferDataStream | ( | UDSClient_t * | client, |
uint8_t | blockSequenceCounter, | ||
const uint16_t | blockLength, | ||
FILE * | fd | ||
) |
Definition at line 561 of file iso14229.c.
UDSErr_t UDSSendWDBI | ( | UDSClient_t * | client, |
uint16_t | dataIdentifier, | ||
const uint8_t * | data, | ||
uint16_t | size | ||
) |
Definition at line 387 of file iso14229.c.
UDSErr_t UDSServerInit | ( | UDSServer_t * | srv | ) |
Definition at line 2404 of file iso14229.c.
void UDSServerPoll | ( | UDSServer_t * | srv | ) |
Definition at line 2421 of file iso14229.c.
void UDSTpISOTpCDeinit | ( | UDSTpISOTpC_t * | tp | ) |
Definition at line 3205 of file iso14229.c.
UDSErr_t UDSTpISOTpCInit | ( | UDSTpISOTpC_t * | tp, |
const char * | ifname, | ||
uint32_t | source_addr, | ||
uint32_t | target_addr, | ||
uint32_t | source_addr_func, | ||
uint32_t | target_addr_func | ||
) |
Definition at line 3180 of file iso14229.c.
void UDSTpIsoTpSockDeinit | ( | UDSTpIsoTpSock_t * | tp | ) |
Definition at line 3480 of file iso14229.c.
UDSErr_t UDSTpIsoTpSockInitClient | ( | UDSTpIsoTpSock_t * | tp, |
const char * | ifname, | ||
uint32_t | source_addr, | ||
uint32_t | target_addr, | ||
uint32_t | target_addr_func | ||
) |
Definition at line 3454 of file iso14229.c.
UDSErr_t UDSTpIsoTpSockInitServer | ( | UDSTpIsoTpSock_t * | tp, |
const char * | ifname, | ||
uint32_t | source_addr, | ||
uint32_t | target_addr, | ||
uint32_t | source_addr_func | ||
) |
Definition at line 3428 of file iso14229.c.
UDSTpStatus_t UDSTpPoll | ( | struct UDSTp * | hdl | ) |
Definition at line 2520 of file iso14229.c.
ssize_t UDSTpRecv | ( | struct UDSTp * | hdl, |
uint8_t * | buf, | ||
size_t | bufsize, | ||
UDSSDU_t * | info | ||
) |
Definition at line 2514 of file iso14229.c.
ssize_t UDSTpSend | ( | struct UDSTp * | hdl, |
const uint8_t * | buf, | ||
ssize_t | len, | ||
UDSSDU_t * | info | ||
) |
Definition at line 2508 of file iso14229.c.
UDSErr_t UDSUnpackRDBIResponse | ( | UDSClient_t * | client, |
UDSRDBIVar_t * | vars, | ||
uint16_t | numVars | ||
) |
Definition at line 845 of file iso14229.c.
UDSErr_t UDSUnpackRequestDownloadResponse | ( | const UDSClient_t * | client, |
struct RequestDownloadResponse * | resp | ||
) |
Definition at line 801 of file iso14229.c.
UDSErr_t UDSUnpackRoutineControlResponse | ( | const UDSClient_t * | client, |
struct RoutineControlResponse * | resp | ||
) |
Definition at line 773 of file iso14229.c.
UDSErr_t UDSUnpackSecurityAccessResponse | ( | const UDSClient_t * | client, |
struct SecurityAccessResponse * | resp | ||
) |
Definition at line 748 of file iso14229.c.