18#line 1 "src/version.h"
20#define UDS_LIB_VERSION "0.11.0"
24#line 1 "src/include.h"
29#if !defined(__cplusplus) && ((!defined(__STDC_VERSION__)) || (__STDC_VERSION__ < 201112L))
33#define static_assert(expr, msg)
35#warning "using static_assert of unknown provenance; Please check that the signature is correct"
57#define UDS_SYS_CUSTOM 0
59#define UDS_SYS_WINDOWS 2
60#define UDS_SYS_ARDUINO 3
61#define UDS_SYS_ESP32 4
62#define UDS_SYS_ZEPHYR 5
67#define UDS_SYS UDS_SYS_ZEPHYR
68#elif defined(__unix__) || defined(__APPLE__)
69#define UDS_SYS UDS_SYS_UNIX
71#define UDS_SYS UDS_SYS_WINDOWS
73#define UDS_SYS UDS_SYS_ARDUINO
74#elif defined(ESP_PLATFORM)
75#define UDS_SYS UDS_SYS_ESP32
78 "UDS_SYS was not detected, defaulting to UDS_SYS_CUSTOM. Remove this warning by defining UDS_SYS=UDS_SYS_CUSTOM in your build configuration"
79#define UDS_SYS UDS_SYS_CUSTOM
111#define UDS_LOG_LEVEL 0U
114#define UDS_ISOTP_MTU (4095U)
118#define UDS_TP_MTU UDS_ISOTP_MTU
126#ifndef UDS_SERVER_SEND_BUF_SIZE
127#define UDS_SERVER_SEND_BUF_SIZE (UDS_TP_MTU)
131#ifndef UDS_SERVER_RECV_BUF_SIZE
132#define UDS_SERVER_RECV_BUF_SIZE (UDS_TP_MTU)
136#ifndef UDS_CLIENT_SEND_BUF_SIZE
137#define UDS_CLIENT_SEND_BUF_SIZE (UDS_TP_MTU)
141#ifndef UDS_CLIENT_RECV_BUF_SIZE
142#define UDS_CLIENT_RECV_BUF_SIZE (UDS_TP_MTU)
145#ifndef UDS_CLIENT_DEFAULT_P2_MS
146#define UDS_CLIENT_DEFAULT_P2_MS (150U)
149#ifndef UDS_CLIENT_DEFAULT_P2_STAR_MS
150#define UDS_CLIENT_DEFAULT_P2_STAR_MS (1500U)
155#ifndef UDS_SERVER_DEFAULT_P2_MS
156#define UDS_SERVER_DEFAULT_P2_MS (50)
159#ifndef UDS_SERVER_DEFAULT_P2_STAR_MS
160#define UDS_SERVER_DEFAULT_P2_STAR_MS (5000)
163#ifndef UDS_SERVER_DEFAULT_S3_MS
164#define UDS_SERVER_DEFAULT_S3_MS \
176#ifndef UDS_SERVER_DEFAULT_POWER_DOWN_TIME_MS
177#define UDS_SERVER_DEFAULT_POWER_DOWN_TIME_MS (60)
180#if (UDS_SERVER_DEFAULT_POWER_DOWN_TIME_MS < UDS_SERVER_DEFAULT_P2_MS)
181#error "The server shall have adequate time to respond before reset"
185#ifndef UDS_SERVER_0x27_BRUTE_FORCE_MITIGATION_BOOT_DELAY_MS
186#define UDS_SERVER_0x27_BRUTE_FORCE_MITIGATION_BOOT_DELAY_MS (1000U)
190#ifndef UDS_SERVER_0x27_BRUTE_FORCE_MITIGATION_AUTH_FAIL_DELAY_MS
191#define UDS_SERVER_0x27_BRUTE_FORCE_MITIGATION_AUTH_FAIL_DELAY_MS (1000U)
194#ifndef UDS_SERVER_DEFAULT_XFER_DATA_MAX_BLOCKLENGTH
198#define UDS_SERVER_DEFAULT_XFER_DATA_MAX_BLOCKLENGTH (UDS_TP_MTU)
201#ifndef UDS_AUTOSELECT_TP
203#define UDS_AUTOSELECT_TP 1
205#if ((UDS_SYS == UDS_SYS_CUSTOM) || (UDS_SYS == UDS_SYS_ARDUINO) || (UDS_SYS == UDS_SYS_ESP32) || \
206 (UDS_SYS == UDS_SYS_ZEPHYR))
207#ifndef UDS_TP_ISOTP_C
208#define UDS_TP_ISOTP_C
210#elif (UDS_SYS == UDS_SYS_UNIX)
211#ifndef UDS_TP_ISOTP_SOCK
212#define UDS_TP_ISOTP_SOCK
222#line 1 "src/config_internal.h"
226#if UDS_SYS == UDS_SYS_CUSTOM
227#ifndef UDS_CUSTOM_MILLIS
228#define UDS_CUSTOM_MILLIS
232#if UDS_SYS == UDS_SYS_WINDOWS
234#define strncasecmp _strnicmp
235#define strcasecmp _stricmp
239#ifdef UDS_TP_ISOTP_C_SOCKETCAN
240#ifndef UDS_TP_ISOTP_C
241#define UDS_TP_ISOTP_C
245#ifdef UDS_TP_ISOTP_C_SOCKETCAN
246#ifndef UDS_TP_ISOTP_C
247#error "UDS_TP_ISOTP_C must be defined to use UDS_TP_ISOTP_C_SOCKETCAN"
252#ifdef ISO_TP_USER_SEND_CAN_ARG
253#error "this flag is set by iso14229"
255#define ISO_TP_USER_SEND_CAN_ARG 1
257#ifdef ISO_TP_NO_FORMATTED_ERRORS
258#error "this flag is set by iso14229"
260#define ISO_TP_NO_FORMATTED_ERRORS 1
277typedef enum UDSEvent {
323 UDS_PositiveResponse = 0,
325 UDS_NRC_GeneralReject = 0x10,
326 UDS_NRC_ServiceNotSupported = 0x11,
327 UDS_NRC_SubFunctionNotSupported = 0x12,
328 UDS_NRC_IncorrectMessageLengthOrInvalidFormat = 0x13,
329 UDS_NRC_ResponseTooLong = 0x14,
331 UDS_NRC_BusyRepeatRequest = 0x21,
332 UDS_NRC_ConditionsNotCorrect = 0x22,
333 UDS_NRC_RequestSequenceError = 0x24,
334 UDS_NRC_NoResponseFromSubnetComponent = 0x25,
335 UDS_NRC_FailurePreventsExecutionOfRequestedAction = 0x26,
337 UDS_NRC_RequestOutOfRange = 0x31,
339 UDS_NRC_SecurityAccessDenied = 0x33,
340 UDS_NRC_AuthenticationRequired = 0x34,
341 UDS_NRC_InvalidKey = 0x35,
342 UDS_NRC_ExceedNumberOfAttempts = 0x36,
343 UDS_NRC_RequiredTimeDelayNotExpired = 0x37,
344 UDS_NRC_SecureDataTransmissionRequired = 0x38,
345 UDS_NRC_SecureDataTransmissionNotAllowed = 0x39,
346 UDS_NRC_SecureDataVerificationFailed = 0x3A,
348 UDS_NRC_CertficateVerificationFailedInvalidTimePeriod = 0x50,
349 UDS_NRC_CertficateVerificationFailedInvalidSignature = 0x51,
350 UDS_NRC_CertficateVerificationFailedInvalidChainOfTrust = 0x52,
351 UDS_NRC_CertficateVerificationFailedInvalidType = 0x53,
352 UDS_NRC_CertficateVerificationFailedInvalidFormat = 0x54,
353 UDS_NRC_CertficateVerificationFailedInvalidContent = 0x55,
354 UDS_NRC_CertficateVerificationFailedInvalidScope = 0x56,
355 UDS_NRC_CertficateVerificationFailedInvalidCertificate = 0x57,
356 UDS_NRC_OwnershipVerificationFailed = 0x58,
357 UDS_NRC_ChallengeCalculationFailed = 0x59,
358 UDS_NRC_SettingAccessRightsFailed = 0x5A,
359 UDS_NRC_SessionKeyCreationOrDerivationFailed = 0x5B,
360 UDS_NRC_ConfigurationDataUsageFailed = 0x5C,
361 UDS_NRC_DeAuthenticationFailed = 0x5D,
363 UDS_NRC_UploadDownloadNotAccepted = 0x70,
364 UDS_NRC_TransferDataSuspended = 0x71,
365 UDS_NRC_GeneralProgrammingFailure = 0x72,
366 UDS_NRC_WrongBlockSequenceCounter = 0x73,
368 UDS_NRC_RequestCorrectlyReceived_ResponsePending = 0x78,
370 UDS_NRC_SubFunctionNotSupportedInActiveSession = 0x7E,
371 UDS_NRC_ServiceNotSupportedInActiveSession = 0x7F,
373 UDS_NRC_RpmTooHigh = 0x81,
374 UDS_NRC_RpmTooLow = 0x82,
375 UDS_NRC_EngineIsRunning = 0x83,
376 UDS_NRC_EngineIsNotRunning = 0x84,
377 UDS_NRC_EngineRunTimeTooLow = 0x85,
378 UDS_NRC_TemperatureTooHigh = 0x86,
379 UDS_NRC_TemperatureTooLow = 0x87,
380 UDS_NRC_VehicleSpeedTooHigh = 0x88,
381 UDS_NRC_VehicleSpeedTooLow = 0x89,
382 UDS_NRC_ThrottlePedalTooHigh = 0x8A,
383 UDS_NRC_ThrottlePedalTooLow = 0x8B,
384 UDS_NRC_TransmissionRangeNotInNeutral = 0x8C,
385 UDS_NRC_TransmissionRangeNotInGear = 0x8D,
387 UDS_NRC_BrakeSwitchNotClosed = 0x8F,
388 UDS_NRC_ShifterLeverNotInPark = 0x90,
389 UDS_NRC_TorqueConverterClutchLocked = 0x91,
390 UDS_NRC_VoltageTooHigh = 0x92,
391 UDS_NRC_VoltageTooLow = 0x93,
392 UDS_NRC_ResourceTemporarilyNotAvailable = 0x94,
397 UDS_NRC_UNUSED_ISOSAEReserved = 0xFF,
400 UDS_ERR_TIMEOUT = 0x100,
401 UDS_ERR_DID_MISMATCH = 0x101,
402 UDS_ERR_SID_MISMATCH = 0x102,
403 UDS_ERR_SUBFUNCTION_MISMATCH =
405 UDS_ERR_RESP_TOO_SHORT = 0x104,
406 UDS_ERR_BUFSIZ = 0x105,
407 UDS_ERR_INVALID_ARG = 0x106,
408 UDS_ERR_BUSY = 0x107,
409 UDS_ERR_MISUSE = 0x108,
411 UDS_ERR_TPORT = 0x200,
420#define UDS_LEV_DS_DS 1U
421#define UDS_LEV_DS_PRGS 2U
422#define UDS_LEV_DS_EXTDS 3U
423#define UDS_LEV_DS_SSDS 4U
432#define UDS_LEV_RT_HR 1U
433#define UDS_LEV_RT_KOFFONR 2U
434#define UDS_LEV_RT_SR 3U
435#define UDS_LEV_RT_ERPSD 4U
436#define UDS_LEV_RT_DRPSD 5U
445#define UDS_LEV_CTRLTP_ERXTX 0U
446#define UDS_LEV_CTRLTP_ERXDTX 1U
447#define UDS_LEV_CTRLTP_DRXETX 2U
448#define UDS_LEV_CTRLTP_DRXTX 3U
457#define UDS_CTP_NCM 1U
458#define UDS_CTP_NWMCM 2U
459#define UDS_CTP_NWMCM_NCM \
469#define UDS_LEV_RCTP_STR 1U
470#define UDS_LEV_RCTP_STPR 2U
471#define UDS_LEV_RCTP_RRR 3U
480#define UDS_MOOP_ADDFILE 1U
481#define UDS_MOOP_DELFILE 2U
482#define UDS_MOOP_REPLFILE 3U
483#define UDS_MOOP_RDFILE 4U
484#define UDS_MOOP_RDDIR 5U
485#define UDS_MOOP_RSFILE 6U
494#define UDS_LEV_DTCSTP_ON 1U
495#define UDS_LEV_DTCSTP_OFF 2U
504#define UDS_LEV_LCTP_VMTWFP 1U
505#define UDS_LEV_LCTP_VMTWSP 2U
506#define UDS_LEV_LCTP_TM 3U
517#ifdef UDS_TP_ISOTP_C_SOCKETCAN
518#ifndef UDS_TP_ISOTP_C
519#define UDS_TP_ISOTP_C
526#define UDS_A_MTYPE_DIAG 0U
527#define UDS_A_MTYPE_REMOTE_DIAG 1U
528#define UDS_A_MTYPE_SECURE_DIAG 2U
529#define UDS_A_MTYPE_SECURE_REMOTE_DIAG 3U
536#define UDS_A_TA_TYPE_PHYSICAL 0U
537#define UDS_A_TA_TYPE_FUNCTIONAL 1U
555#define UDS_TP_NOOP_ADDR (0xFFFFFFFFU)
561typedef struct UDSTp {
583 UDSErr_t (*
recv)(
struct UDSTp *hdl, uint8_t *buf,
size_t bufsiz,
size_t *recvlen,
597 unsigned is_sending : 1;
622#define UDS_ASSERT(x) assert(x)
634const char *UDSErrToStr(
UDSErr_t err);
656#define UDS_LOG_NONE 0U
657#define UDS_LOG_ERROR 1U
658#define UDS_LOG_WARN 2U
659#define UDS_LOG_INFO 3U
660#define UDS_LOG_DEBUG 4U
661#define UDS_LOG_VERBOSE 5U
669 "unknown log level");
671#if UDS_LOG_LEVEL >= UDS_LOG_ERROR && UDS_LOG_LEVEL != UDS_LOG_NONE
672#define UDS_LOGE(tag, format, ...) \
673 UDS_LogWrite(UDS_LOG_ERROR, tag, UDS_LOG_FORMAT(E, format), UDSMillis(), tag, ##__VA_ARGS__)
675#define UDS_LOGE(tag, format, ...) UDS_LogDummy(UDS_LOG_NONE, tag, format, ##__VA_ARGS__)
678#if UDS_LOG_LEVEL >= UDS_LOG_WARN && UDS_LOG_LEVEL != UDS_LOG_NONE
679#define UDS_LOGW(tag, format, ...) \
680 UDS_LogWrite(UDS_LOG_WARN, tag, UDS_LOG_FORMAT(W, format), UDSMillis(), tag, ##__VA_ARGS__)
682#define UDS_LOGW(tag, format, ...) UDS_LogDummy(UDS_LOG_NONE, tag, format, ##__VA_ARGS__)
685#if UDS_LOG_LEVEL >= UDS_LOG_INFO && UDS_LOG_LEVEL != UDS_LOG_NONE
686#define UDS_LOGI(tag, format, ...) \
687 UDS_LogWrite(UDS_LOG_INFO, tag, UDS_LOG_FORMAT(I, format), UDSMillis(), tag, ##__VA_ARGS__)
689#define UDS_LOGI(tag, format, ...) UDS_LogDummy(UDS_LOG_NONE, tag, format, ##__VA_ARGS__)
692#if UDS_LOG_LEVEL >= UDS_LOG_DEBUG && UDS_LOG_LEVEL != UDS_LOG_NONE
693#define UDS_LOGD(tag, format, ...) \
694 UDS_LogWrite(UDS_LOG_DEBUG, tag, UDS_LOG_FORMAT(D, format), UDSMillis(), tag, ##__VA_ARGS__)
696#define UDS_LOGD(tag, format, ...) UDS_LogDummy(UDS_LOG_NONE, tag, format, ##__VA_ARGS__)
699#if UDS_LOG_LEVEL >= UDS_LOG_VERBOSE
700#define UDS_LOGV(tag, format, ...) \
701 UDS_LogWrite(UDS_LOG_VERBOSE, tag, UDS_LOG_FORMAT(V, format), UDSMillis(), tag, ##__VA_ARGS__)
702#define UDS_LOG_SDU(tag, buffer, buff_len, info) \
703 UDS_LogSDUInternal(UDS_LOG_DEBUG, tag, buffer, buff_len, info)
705#define UDS_LOGV(tag, format, ...) UDS_LogDummy(UDS_LOG_NONE, tag, format, ##__VA_ARGS__)
706#define UDS_LOG_SDU(tag, buffer, buff_len, info) \
707 UDS_LogSDUDummy(UDS_LOG_NONE, tag, buffer, buff_len, info)
710#if defined(__GNUC__) || defined(__clang__)
711#define UDS_PRINTF_FORMAT(fmt_index, first_arg) \
712 __attribute__((format(printf, fmt_index, first_arg)))
714#define UDS_PRINTF_FORMAT(fmt_index, first_arg)
717#if UDS_LOG_LEVEL > UDS_LOG_NONE
719#define UDS_LOG_FORMAT(letter, format) #letter " (%" PRIu32 ") %s: " format "\n"
720void UDS_LogWrite(
UDS_LogLevel_t level,
const char *tag,
const char *format, ...)
721 UDS_PRINTF_FORMAT(3, 4);
722void UDS_LogSDUInternal(
UDS_LogLevel_t level, const
char *tag, const uint8_t *buffer,
size_t buflen,
726static inline void UDS_LogDummy(
UDS_LogLevel_t level,
const char *tag,
const char *format, ...) {
731static inline void UDS_LogSDUDummy(
UDS_LogLevel_t level,
const char *tag,
const uint8_t *buffer,
732 size_t buflen,
const UDSSDU_t *info) {
743#line 1 "src/client.h"
753typedef struct UDSClient {
810 void *(*UnpackFn)(
void *dst,
const void *src,
size_t n);
824 uint16_t numDataIdentifiers);
829 const uint8_t *data, uint16_t size);
832 uint8_t addressAndLengthFormatIdentifier,
size_t memoryAddress,
836 uint8_t addressAndLengthFormatIdentifier,
size_t memoryAddress,
839 uint16_t blockLength,
const uint8_t *data,
845 UDSClient_t *client, uint8_t mode,
const char *filePath,
size_t filePathLen,
846 size_t fileSizeUncompressed,
847 size_t fileSizeCompressed);
849 const uint8_t *dtcSettingControlOptionRecord,
865#line 1 "src/server.h"
887typedef struct UDSServer {
1258#if defined(UDS_TP_ISOTP_C)
1262#line 1 "src/tp/isotp-c/isotp_config.h"
1276#ifndef ISOTPC_CONFIG_H
1277#define ISOTPC_CONFIG_H
1300#ifndef ISO_TP_MAX_CAN_FRAME_SIZE
1301 #define ISO_TP_MAX_CAN_FRAME_SIZE 8
1308#ifndef ISO_TP_DEFAULT_TX_DL
1309 #define ISO_TP_DEFAULT_TX_DL ISO_TP_MAX_CAN_FRAME_SIZE
1315#ifndef ISO_TP_DEFAULT_BLOCK_SIZE
1316 #define ISO_TP_DEFAULT_BLOCK_SIZE 8
1321#ifndef ISO_TP_DEFAULT_ST_MIN_US
1322 #define ISO_TP_DEFAULT_ST_MIN_US 0
1327#ifndef ISO_TP_MAX_WFT_NUMBER
1328 #define ISO_TP_MAX_WFT_NUMBER 1
1335#ifndef ISO_TP_DEFAULT_RESPONSE_TIMEOUT_US
1336 #define ISO_TP_DEFAULT_RESPONSE_TIMEOUT_US 100000
1344 #define ISO_TP_FRAME_PADDING
1358 #define ISO_TP_NO_FORMATTED_ERRORS
1363#ifndef ISO_TP_FRAME_PADDING_VALUE
1364 #define ISO_TP_FRAME_PADDING_VALUE 0xAA
1372 #define ISO_TP_USER_SEND_CAN_ARG
1382 #define ISO_TP_USER_SEND_CAN_FLAGS
1390 #define ISO_TP_CAN_FD_USE_BRS
1397 #define ISO_TP_TRANSMIT_COMPLETE_CALLBACK
1404 #define ISO_TP_RECEIVE_COMPLETE_CALLBACK
1412 #define ISO_TP_ENABLE_STREAMING
1419#ifndef ISOTPC_USER_DEFINITIONS_H
1421#line 1 "src/tp/isotp-c/isotp_defines.h"
1423#define ISOTPC_USER_DEFINITIONS_H
1438 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1439 #define ISOTP_BYTE_ORDER_LITTLE_ENDIAN
1440 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
1442 #error "unsupported byte ordering"
1451 #define ISOTP_BYTE_ORDER_LITTLE_ENDIAN
1454#if defined(_MSC_VER) && _MSC_VER < 1900
1455 #define ISOTP_SNPRINTF _snprintf
1457 #define ISOTP_SNPRINTF snprintf
1460#define LE32TOH(le) ((uint32_t)(((le) << 24) | (((le) & 0x0000FF00) << 8) | (((le) & 0x00FF0000) >> 8) | ((le) >> 24)))
1471#define ISOTP_CAN_DL_CLASSIC 8
1473#if (ISO_TP_MAX_CAN_FRAME_SIZE != 8) && (ISO_TP_MAX_CAN_FRAME_SIZE != 12) && (ISO_TP_MAX_CAN_FRAME_SIZE != 16) && (ISO_TP_MAX_CAN_FRAME_SIZE != 20) && \
1474 (ISO_TP_MAX_CAN_FRAME_SIZE != 24) && (ISO_TP_MAX_CAN_FRAME_SIZE != 32) && (ISO_TP_MAX_CAN_FRAME_SIZE != 48) && (ISO_TP_MAX_CAN_FRAME_SIZE != 64)
1475 #error "ISO_TP_MAX_CAN_FRAME_SIZE must be one of 8, 12, 16, 20, 24, 32, 48, 64"
1478#if (ISO_TP_DEFAULT_TX_DL > ISO_TP_MAX_CAN_FRAME_SIZE) || (ISO_TP_DEFAULT_TX_DL < ISOTP_CAN_DL_CLASSIC)
1479 #error "ISO_TP_DEFAULT_TX_DL must be at least 8 and must not exceed ISO_TP_MAX_CAN_FRAME_SIZE"
1483#define ISOTP_CAN_FRAME_FLAG_NONE 0x00
1485#define ISOTP_CAN_FRAME_FLAG_FD 0x01
1487#define ISOTP_CAN_FRAME_FLAG_BRS 0x02
1495#define ISOTP_SF_MAX_PAYLOAD(can_dl) ((can_dl) > ISOTP_CAN_DL_CLASSIC ? (uint32_t)((can_dl) - 2u) : (uint32_t)((can_dl) - 1u))
1507#define ISOTP_RET_OK 0
1509#define ISOTP_RET_ERROR -1
1511#define ISOTP_RET_INPROGRESS -2
1513#define ISOTP_RET_OVERFLOW -3
1515#define ISOTP_RET_WRONG_SN -4
1517#define ISOTP_RET_NO_DATA -5
1519#define ISOTP_RET_TIMEOUT -6
1521#define ISOTP_RET_LENGTH -7
1523#define ISOTP_RET_NOSPACE -8
1530#define IsoTpTimeAfter(a, b) ((int32_t)((int32_t)(b) - (int32_t)(a)) < 0)
1533#define ISOTP_INVALID_BS 0xFFFF
1536#define ISOTP_MAX_ERROR_MSG_SIZE 128
1546 ISOTP_SEND_STATUS_IDLE,
1547 ISOTP_SEND_STATUS_INPROGRESS,
1548 ISOTP_SEND_STATUS_ERROR,
1549} IsoTpSendStatusTypes;
1553 ISOTP_RECEIVE_STATUS_IDLE,
1554 ISOTP_RECEIVE_STATUS_INPROGRESS,
1555 ISOTP_RECEIVE_STATUS_FULL,
1556} IsoTpReceiveStatusTypes;
1563#if defined(ISOTP_BYTE_ORDER_LITTLE_ENDIAN)
1565 uint8_t reserve_1 : 4;
1567 uint8_t reserve_2[ISO_TP_MAX_CAN_FRAME_SIZE - 1];
1573 uint8_t data[ISO_TP_MAX_CAN_FRAME_SIZE - 1];
1577 uint8_t set_to_zero : 4;
1580 uint8_t data[ISO_TP_MAX_CAN_FRAME_SIZE - 2];
1581} IsoTpSingleFrameEscape;
1584 uint8_t FF_DL_high : 4;
1587 uint8_t data[ISO_TP_MAX_CAN_FRAME_SIZE - 2];
1588} IsoTpFirstFrameShort;
1590#pragma pack(push, 1)
1592 uint8_t set_to_zero_high : 4;
1594 uint8_t set_to_zero_low;
1596 uint8_t data[ISO_TP_MAX_CAN_FRAME_SIZE - 6];
1597} IsoTpFirstFrameLong;
1603 uint8_t data[ISO_TP_MAX_CAN_FRAME_SIZE - 1];
1604} IsoTpConsecutiveFrame;
1611 uint8_t reserve[ISO_TP_MAX_CAN_FRAME_SIZE - 3];
1618 uint8_t reserve_1 : 4;
1619 uint8_t reserve_2[ISO_TP_MAX_CAN_FRAME_SIZE - 1];
1635 uint8_t data[ISO_TP_MAX_CAN_FRAME_SIZE - 1];
1650 uint8_t set_to_zero : 4;
1652 uint8_t data[ISO_TP_MAX_CAN_FRAME_SIZE - 2];
1653} IsoTpSingleFrameEscape;
1667 uint8_t FF_DL_high : 4;
1669 uint8_t data[ISO_TP_MAX_CAN_FRAME_SIZE - 2];
1670} IsoTpFirstFrameShort;
1682#pragma pack(push, 1)
1685 uint8_t set_to_zero_high : 4;
1686 uint8_t set_to_zero_low;
1688 uint8_t data[ISO_TP_MAX_CAN_FRAME_SIZE - 6];
1689} IsoTpFirstFrameLong;
1705 uint8_t data[ISO_TP_MAX_CAN_FRAME_SIZE - 1];
1706} IsoTpConsecutiveFrame;
1723 uint8_t reserve[ISO_TP_MAX_CAN_FRAME_SIZE - 3];
1729 uint8_t ptr[ISO_TP_MAX_CAN_FRAME_SIZE];
1734 IsoTpPciType common;
1735 IsoTpSingleFrame single_frame;
1736 IsoTpSingleFrameEscape single_frame_escape;
1737 IsoTpFirstFrameShort first_frame_short;
1738 IsoTpFirstFrameLong first_frame_long;
1739 IsoTpConsecutiveFrame consecutive_frame;
1740 IsoTpFlowControl flow_control;
1741 IsoTpDataArray data_array;
1751#ifdef ISO_TP_TRANSMIT_COMPLETE_CALLBACK
1759typedef void (*isotp_tx_done_cb)(
void* link, uint32_t tx_size,
void* user_arg);
1762#ifdef ISO_TP_RECEIVE_COMPLETE_CALLBACK
1771typedef void (*isotp_rx_done_cb)(
void* link,
const uint8_t* data, uint32_t size,
void* user_arg);
1777 ISOTP_PCI_TYPE_SINGLE = 0x0,
1778 ISOTP_PCI_TYPE_FIRST_FRAME = 0x1,
1779 TSOTP_PCI_TYPE_CONSECUTIVE_FRAME = 0x2,
1780 ISOTP_PCI_TYPE_FLOW_CONTROL_FRAME = 0x3,
1782 ISOTP_PCI_TYPE_CONSECUTIVE_FRAME = 0x2,
1783} IsoTpProtocolControlInformation;
1787typedef enum { PCI_FLOW_STATUS_CONTINUE = 0x0, PCI_FLOW_STATUS_WAIT = 0x1, PCI_FLOW_STATUS_OVERFLOW = 0x2 } IsoTpFlowStatus;
1794#define ISOTP_PROTOCOL_RESULT_OK 0
1796#define ISOTP_PROTOCOL_RESULT_TIMEOUT_A -1
1798#define ISOTP_PROTOCOL_RESULT_TIMEOUT_BS -2
1800#define ISOTP_PROTOCOL_RESULT_TIMEOUT_CR -3
1802#define ISOTP_PROTOCOL_RESULT_WRONG_SN -4
1804#define ISOTP_PROTOCOL_RESULT_INVALID_FS -5
1806#define ISOTP_PROTOCOL_RESULT_UNEXP_PDU -6
1808#define ISOTP_PROTOCOL_RESULT_WFT_OVRN -7
1810#define ISOTP_PROTOCOL_RESULT_BUFFER_OVFLW -8
1812#define ISOTP_PROTOCOL_RESULT_ERROR -9
1820#line 1 "src/tp/isotp-c/isotp_user.h"
1829#ifndef ISOTPC_USER_H
1830#define ISOTPC_USER_H
1857void isotp_user_debug(
const char* message, ...);
1881int isotp_user_send_can(
const uint32_t arbitration_id,
const uint8_t* data,
const uint8_t size
1882#ifdef ISO_TP_USER_SEND_CAN_FLAGS
1883 ,
const uint8_t flags
1885#ifdef ISO_TP_USER_SEND_CAN_ARG
1898uint32_t isotp_user_get_us(
void);
1910#line 1 "src/tp/isotp-c/isotp.h"
1958typedef struct IsoTpLink {
1961 uint32_t send_arbitration_id;
1964 uint8_t* send_buffer;
1965 uint32_t send_buf_size;
1967 uint32_t send_offset;
1970 uint32_t send_bs_remain;
1971 uint32_t send_st_min_us;
1972 uint8_t send_wtf_count;
1973 uint32_t send_timer_st;
1974 uint32_t send_timer_bs;
1977 int32_t send_protocol_result;
1979 uint8_t send_status;
1983 uint32_t receive_arbitration_id;
1986 uint8_t* receive_buffer;
1987 uint32_t receive_buf_size;
1988 uint32_t receive_size;
1989 uint32_t receive_offset;
1992 uint8_t receive_bs_count;
1993 uint32_t receive_timer_cr;
1996 int receive_protocol_result;
1998 uint8_t receive_status;
2001#ifdef ISO_TP_ENABLE_STREAMING
2002 uint32_t receive_stream_size;
2003 uint8_t receive_streaming;
2004 uint8_t receive_stream_carry_size;
2005 uint8_t receive_stream_carry[ISO_TP_MAX_CAN_FRAME_SIZE - 1];
2009#if defined(ISO_TP_USER_SEND_CAN_ARG)
2016 void* user_send_can_arg;
2020#ifdef ISO_TP_TRANSMIT_COMPLETE_CALLBACK
2021 isotp_tx_done_cb tx_done_cb;
2022 void* tx_done_cb_arg;
2025#ifdef ISO_TP_RECEIVE_COMPLETE_CALLBACK
2026 isotp_rx_done_cb rx_done_cb;
2027 void* rx_done_cb_arg;
2054void isotp_init_link(IsoTpLink* link, uint32_t sendid, uint8_t* sendbuf, uint32_t sendbufsize, uint8_t* recvbuf, uint32_t recvbufsize);
2073int isotp_set_tx_dl(IsoTpLink* link, uint8_t tx_dl);
2082uint8_t isotp_get_tx_dl(
const IsoTpLink* link);
2092void isotp_destroy_link(IsoTpLink* link);
2105void isotp_poll(IsoTpLink* link);
2120void isotp_on_can_message(IsoTpLink* link,
const uint8_t* data, uint8_t len);
2142int isotp_send(IsoTpLink* link,
const uint8_t payload[], uint32_t size);
2162int isotp_send_with_id(IsoTpLink* link, uint32_t
id,
const uint8_t payload[], uint32_t size);
2179int isotp_receive(IsoTpLink* link, uint8_t* payload,
const uint32_t payload_size, uint32_t* out_size);
2181#ifdef ISO_TP_ENABLE_STREAMING
2201int isotp_receive_streaming(IsoTpLink* link, uint8_t* payload,
const uint32_t payload_size, uint32_t* out_size,
bool* is_complete);
2204#ifdef ISO_TP_TRANSMIT_COMPLETE_CALLBACK
2216void isotp_set_tx_done_cb(IsoTpLink* link, isotp_tx_done_cb cb,
void* arg);
2219#ifdef ISO_TP_RECEIVE_COMPLETE_CALLBACK
2234void isotp_set_rx_done_cb(IsoTpLink* link, isotp_rx_done_cb cb,
void* arg);
2250#line 1 "src/tp/isotp_c.h"
2252#ifdef UDS_TP_ISOTP_C
2266 IsoTpLink phys_link;
2267 IsoTpLink func_link;
2270 uint8_t func_send_buf[8];
2271 uint8_t func_recv_buf[8];
2279static_assert(offsetof(
UDSTpISOTpC_t, hdl) == 0U,
"hdl must be the first member");
2289 uint32_t source_addr_func);
2299 uint32_t target_addr_func);
2310#line 1 "src/tp/isotp_c_socketcan.h"
2313#ifdef UDS_TP_ISOTP_C_SOCKETCAN
2339 uint32_t source_addr, uint32_t target_addr,
2340 uint32_t source_addr_func);
2350 uint32_t source_addr, uint32_t target_addr,
2351 uint32_t target_addr_func);
2357#ifdef UDS_TP_ISOTP_SOCK
2359#line 1 "src/tp/isotp_sock.h"
2386static_assert(offsetof(
UDSTpIsoTpSock_t, hdl) == 0U,
"hdl must be the first member");
2389 uint32_t target_addr,
2390 uint32_t source_addr_func);
2392 uint32_t target_addr,
2393 uint32_t target_addr_func);
2398#ifdef UDS_TP_ISOTP_MOCK
2400#line 1 "src/tp/isotp_mock.h"
2410typedef struct ISOTPMock {
2420 uint32_t send_tx_delay_ms;
2421 uint32_t send_buf_size;
2425static_assert(offsetof(ISOTPMock_t, hdl) == 0U,
"ISOTPMock_t must not have any members before hdl");
2440UDSTp_t *ISOTPMockNew(
const char *name,
const ISOTPMockArgs_t *args);
2441void ISOTPMockFree(
UDSTp_t *tp);
2448void ISOTPMockLogToFile(
const char *filename);
2449void ISOTPMockLogToStdout(
void);
2454void ISOTPMockReset(
void);
#define UDS_CLIENT_DEFAULT_P2_MS
default P2 timeout
UDSErr_t UDSSendECUReset(UDSClient_t *client, uint8_t type)
Request ECUReset.
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.
void UDSServerPoll(UDSServer_t *srv)
Call this at <5ms intervals.
#define UDS_CLIENT_SEND_BUF_SIZE
reduce this at your own risk to save RAM. Fuzz testing is done with the default of UDS_TP_MTU.
UDSErr_t UDSClientTpISOTpCSocketCANInit(UDSTpISOTpCSocketCAN_t *tp, const char *ifname, uint32_t source_addr, uint32_t target_addr, uint32_t target_addr_func)
Initialize isotp-c over SocketCAN transport for UDSClient_t.
UDSErr_t UDSTpRecv(UDSTp_t *hdl, uint8_t *buf, size_t bufsiz, size_t *recvlen, UDSSDU_t *info)
Receive from transport.
@ UDS_EVT_RequestFileTransfer
@ UDS_EVT_ReadDTCInformation
@ UDS_EVT_ClearDiagnosticInfo
@ UDS_EVT_DynamicDefineDataId
@ UDS_EVT_SecAccessRequestSeed
@ UDS_EVT_SecAccessValidateKey
@ UDS_EVT_RequestDownload
@ UDS_EVT_WriteDataByIdent
@ UDS_EVT_RequestTransferExit
@ UDS_EVT_ResponseReceived
@ UDS_EVT_ControlDTCSetting
@ UDS_EVT_DoScheduledReset
@ UDS_EVT_ReadDataByIdent
UDSErr_t UDSSendTesterPresent(UDSClient_t *client)
What's up?
#define UDS_SERVER_DEFAULT_P2_MS
default P2 duration
#define UDS_CLIENT_DEFAULT_P2_STAR_MS
default P2* timeout
UDSErr_t UDSSendRequestTransferExit(UDSClient_t *client)
Call this when finished with TransferData.
UDSErr_t UDSTpPoll(UDSTp_t *hdl)
call this at <5ms intervals
UDSErr_t UDSSendRequestDownload(UDSClient_t *client, uint8_t dataFormatIdentifier, uint8_t addressAndLengthFormatIdentifier, size_t memoryAddress, size_t memorySize)
Request to Download via TransferData.
#define UDS_SERVER_SEND_BUF_SIZE
reduce this at your own risk to save RAM. Fuzz testing is done with the default of UDS_TP_MTU.
#define UDS_CLIENT_RECV_BUF_SIZE
reduce this at your own risk to save RAM. Fuzz testing is done with the default of UDS_TP_MTU.
UDSErr_t UDSUnpackSecurityAccessResponse(const UDSClient_t *client, struct SecurityAccessResponse *resp)
Parse server's response to SecurityAccess.
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 UDSSendWDBI(UDSClient_t *client, uint16_t dataIdentifier, const uint8_t *data, uint16_t size)
Write Data By Identifier.
UDSErr_t UDSSendCommCtrl(UDSClient_t *client, uint8_t ctrl, uint8_t comm)
Change communication settings.
#define UDS_TP_MTU
ISOTP is the only supported tp type, so UDS inherits its MTU.
UDSErr_t UDSSendRequestUpload(UDSClient_t *client, uint8_t dataFormatIdentifier, uint8_t addressAndLengthFormatIdentifier, size_t memoryAddress, size_t memorySize)
Request to Upload via TransferData.
uint32_t UDSMillis(void)
Get time in milliseconds.
UDSErr_t UDSUnpackRDBIResponse(UDSClient_t *client, UDSRDBIVar_t *vars, uint16_t numVars)
Parse server's response to RDBI.
#define UDS_SERVER_DEFAULT_S3_MS
default S3 duration (ISO14229-2 2013 Table 5: 5000 -0/+200 ms)
UDSErr_t UDSUnpackRoutineControlResponse(const UDSClient_t *client, struct RoutineControlResponse *resp)
Parse server's response to RoutineControl.
UDSErr_t UDSSendSecurityAccess(UDSClient_t *client, uint8_t level, const uint8_t *data, uint16_t size)
Get Security Access.
unsigned int UDS_LogLevel_t
one of valid values for UDS_LOG_LEVEL
#define UDS_SERVER_DEFAULT_P2_STAR_MS
default P2* duration
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
#define UDS_SERVER_RECV_BUF_SIZE
reduce this at your own risk to save RAM. Fuzz testing is done with the default of UDS_TP_MTU.
UDSErr_t UDSSendTransferData(UDSClient_t *client, uint8_t blockSequenceCounter, uint16_t blockLength, const uint8_t *data, uint16_t size)
Transfer Data to/from a buffer.
uint8_t UDS_A_TA_Type_t
private: oneof Uds_a_ta_type
UDSErr_t UDSSendRequestFileTransfer(UDSClient_t *client, uint8_t mode, const char *filePath, size_t filePathLen, size_t fileSizeUncompressed, size_t fileSizeCompressed)
filesystem-based frontend to TransferData
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 UDSClientTpISOTpCInit(UDSTpISOTpC_t *tp, uint32_t source_addr, uint32_t target_addr, uint32_t target_addr_func)
Initialize isotp-c transport for UDSClient_t.
UDSErr_t
Error Codes, including NRCs defined by the standard.
void UDSTpISOTpCSocketCANDeinit(UDSTpISOTpCSocketCAN_t *tp)
release socket
#define UDS_ISOTP_MTU
ISO-TP Maximum Transmission Unit (ISO-15764-2-2004 section 5.3.3).
UDSErr_t UDSUnpackRequestDownloadResponse(const UDSClient_t *client, struct RequestDownloadResponse *resp)
Parse server's response to RequestDownload.
uint8_t UDS_A_Mtype_t
private: oneof Uds_a_mtype
UDSErr_t UDSCtrlDTCSetting(UDSClient_t *client, uint8_t dtcSettingType, const uint8_t *dtcSettingControlOptionRecord, uint16_t len)
control DTC setting
UDSErr_t UDSClientInit(UDSClient_t *client)
Call this once.
#define UDS_LOG_LEVEL
sets the logging level
UDSErr_t UDSTpSend(UDSTp_t *hdl, const uint8_t *buf, size_t len, const UDSSDU_t *info)
Send to transport.
UDSErr_t UDSServerTpISOTpCSocketCANInit(UDSTpISOTpCSocketCAN_t *tp, const char *ifname, uint32_t source_addr, uint32_t target_addr, uint32_t source_addr_func)
Initialize isotp-c over SocketCAN transport for UDSServer_t.
UDSErr_t UDSSendDiagSessCtrl(UDSClient_t *client, uint8_t mode)
Change the diagnostic session.
UDSErr_t UDSClientPoll(UDSClient_t *client)
Call at <5ms intervals.
UDSErr_t UDSSendBytes(UDSClient_t *client, const uint8_t *data, uint16_t size)
Send user-defined bytes to a UDS server.
UDSErr_t UDSSendRDBI(UDSClient_t *client, const uint16_t *didList, uint16_t numDataIdentifiers)
Read Data By Identifier.
UDSErr_t UDSServerInit(UDSServer_t *srv)
call this once
void UDSTpIsoTpSockDeinit(const UDSTpIsoTpSock_t *tp)
release sockets
Request download response structure.
Routine control response structure.
const uint8_t * routineStatusRecord
size_t routineStatusRecordLength
uint16_t routineIdentifier
uint8_t routineControlType
Security access response structure.
uint8_t securityAccessType
size_t securitySeedLength
const uint8_t * securitySeed
Clear diagnostic information arguments.
const uint8_t memorySelection
const uint32_t groupOfDTC
const bool hasMemorySelection
uint8_t cfg_file_size_parameter_length
uint8_t cfg_data_format_identifier
unsigned cfg_ignore_srv_sess_timing
int(*) fn(struct UDSClient *client, UDSEvent_t evt, void *ev_data)
unsigned cfg_suppress_pos_resp
uint8_t send_buf[UDS_CLIENT_SEND_BUF_SIZE]
unsigned cfg_send_functional
uint8_t recv_buf[UDS_CLIENT_RECV_BUF_SIZE]
Communication control arguments.
Control DTC setting arguments.
Custom service arguments.
uint8_t(*) copyResponse(UDSServer_t *srv, const void *src, uint16_t len)
const uint8_t * optionRecord
Dynamically define data identifier arguments.
Diagnostic session control arguments.
uint32_t powerDownTimeMillis
Input/output control by identifier arguments.
const uint8_t ioCtrlParam
const size_t ctrlStateAndMaskLen
uint8_t(*) copy(UDSServer_t *srv, const void *src, uint16_t count)
const void *const ctrlStateAndMask
Read data by identifier arguments.
uint8_t(*) copy(UDSServer_t *srv, const void *src, uint16_t count)
Read data by identifier variable structure.
Read DTC information arguments.
uint8_t(*) copy(UDSServer_t *srv, const void *src, uint16_t count)
Read memory by address arguments.
uint8_t(*) copy(UDSServer_t *srv, const void *src, uint16_t count)
uint8_t send_buf[UDS_SERVER_SEND_BUF_SIZE]
uint8_t recv_buf[UDS_SERVER_RECV_BUF_SIZE]
Request download arguments.
const uint8_t dataFormatIdentifier
uint16_t maxNumberOfBlockLength
Request file transfer arguments.
size_t fileSizeUnCompressed
const uint8_t modeOfOperation
size_t fileSizeCompressed
uint16_t maxNumberOfBlockLength
const uint16_t filePathLen
const uint8_t dataFormatIdentifier
Request transfer exit arguments.
uint8_t(*) copyResponse(UDSServer_t *srv, const void *src, uint16_t len)
const uint8_t *const data
Request upload arguments.
uint16_t maxNumberOfBlockLength
const uint8_t dataFormatIdentifier
Routine control arguments.
const uint8_t * optionRecord
uint8_t(*) copyStatusRecord(UDSServer_t *srv, const void *src, uint16_t len)
UDS_A_TA_Type_t A_TA_Type
Security access request seed arguments.
const uint8_t *const dataRecord
uint8_t(*) copySeed(UDSServer_t *srv, const void *src, uint16_t len)
Security access validate key arguments.
uint32_t sec_access_auth_fail_timer
uint16_t p2_ms
Server time constants (milliseconds).
bool notReadyToReceive
UDS-1 2013 defines the following conditions under which the server does not process incoming requests...
uint32_t sec_access_boot_delay_timer
UDSErr_t(*) fn(struct UDSServer *srv, UDSEvent_t event, void *arg)
uint32_t s3_session_timeout_timer
uint8_t ecuResetScheduled
uint8_t xferBlockSequenceCounter
bool xferIsActive
UDS-1-2013: Table 407 - 0x36 TransferData Supported negative response codes requires that the server ...
isotp-c over SocketCAN implementation of UDSTp_t
isotp-c implementation of UDSTp_t
linux ISO-TP socket implementation of UDSTp_t
UDSErr_t(*) poll(struct UDSTp *hdl)
Poll the transport layer.
UDSErr_t(*) recv(struct UDSTp *hdl, uint8_t *buf, size_t bufsiz, size_t *recvlen, UDSSDU_t *info)
Receive data from the transport.
UDSErr_t(*) send(struct UDSTp *hdl, const uint8_t *buf, const size_t len, const UDSSDU_t *info)
Send data to the transport.
uint8_t(*) copyResponse(UDSServer_t *srv, const void *src, uint16_t len)
const uint8_t *const data
const uint16_t maxRespLen
Write data by identifier arguments.
const uint8_t *const data
Write memory by address arguments.
const uint8_t *const data
struct UDSDDDIArgs_t::@052263275324350175074117356122047100356070003133::@115243115226044153303170122340357141371034352066 defineByMemAddress
struct UDSDDDIArgs_t::@052263275324350175074117356122047100356070003133::@036062102371115341142264035315270072153132273147 defineById
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@355231136245007054075200356211041150371252334044 numOfDTCByStatusMaskArgs
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@047012174113202206257152072274143133322231236121 userDefMemDTCSnapshotRecordByDTCNumArgs
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@154001327012172334201146116375304045171105172314 dtcStatusByMaskArgs
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@202153233305101214231012246142343355313236156117 wwhobdDTCWithPermStatusArgs
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@305215343063121020063152330305364065023263302342 dtcInfoByDTCReadinessGroupIdArgs
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@316272062351030324211305365217344343316022275306 dtcStoredDataByRecordNumArgs
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@074254175135322041140372030214006246075071061263 wwhobdDTCByMaskArgs
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@251214024221351216066340166017235251143034105333 dtcExtDataRecordByRecordNumArgs
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@030077060352005266364046135253225021030163312237 userDefMemDTCExtDataRecordByDTCNumArgs
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@227353312111251376072016263157011107071271365150 dtcExtDataRecordIdArgs
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@122167075350102041255165217274110033054226235151 numOfDTCBySeverityMaskArgs
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@053011077231155331214107140362046363214010061172 userDefMemoryDTCByStatusMaskArgs
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@257326070054040214361234214245165251024355111071 dtcSnapshotRecordbyDTCNumArgs
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@370142040263172177333046321065146007342243043210 severityInfoOfDTCArgs
struct UDSRDTCIArgs_t::@242172112264143020077310143126066111376236317004::@166357164257276222002146302270155120176057041273 dtcExtDtaRecordByDTCNumArgs