iso14229 0.10.0
ISO14229-1 (UDS) C Library
Loading...
Searching...
No Matches
iso14229.h
Go to the documentation of this file.
1#ifndef ISO14229_H
2#define ISO14229_H
3
4/**
5 * @file iso14229.h
6 * @brief ISO14229-1 (UDS) library
7 * @copyright Copyright (c) Nick Kirkby
8 * @see https://github.com/driftregion/iso14229
9 */
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15
16#define UDS_LIB_VERSION "0.10.0"
17
18
19
20/**
21 * @defgroup uds_sys_ valid values of UDS_SYS
22 * @brief iso14229 host system selection
23 * @see UDS_SYS
24 * @{
25 */
26#define UDS_SYS_CUSTOM 0 /**< bare metal or unsupported targets */
27#define UDS_SYS_UNIX 1
28#define UDS_SYS_WINDOWS 2
29#define UDS_SYS_ARDUINO 3
30#define UDS_SYS_ESP32 4
31/** @} */
32
33#if !defined(UDS_SYS)
34
35#if defined(__unix__) || defined(__APPLE__)
36#define UDS_SYS UDS_SYS_UNIX
37#elif defined(_WIN32)
38#define UDS_SYS UDS_SYS_WINDOWS
39#elif defined(ARDUINO)
40#define UDS_SYS UDS_SYS_ARDUINO
41#elif defined(ESP_PLATFORM)
42#define UDS_SYS UDS_SYS_ESP32
43#else
44#warning \
45 "UDS_SYS was not detected, defaulting to UDS_SYS_CUSTOM. Remove this warning by defining UDS_SYS=UDS_SYS_CUSTOM in your build configuration"
46#define UDS_SYS UDS_SYS_CUSTOM
47#endif
48
49#endif
50
51#include <assert.h>
52#include <inttypes.h>
53#include <stdbool.h>
54#include <stddef.h>
55#include <stdint.h>
56#include <stdio.h>
57#include <string.h>
58
59#if UDS_SYS == UDS_SYS_CUSTOM
60#define UDS_CUSTOM_MILLIS
61#endif // UDS_SYS == UDS_SYS_CUSTOM
62
63#if UDS_SYS == UDS_SYS_UNIX
64#include <sys/time.h>
65#include <sys/types.h>
66#include <time.h>
67#endif // if UDS_SYS == UDS_SYS_UNIX
68
69#if UDS_SYS == UDS_SYS_WINDOWS
70#include <stdlib.h>
71#include <time.h>
72#ifdef _MSC_VER
73#define strncasecmp _strnicmp
74#define strcasecmp _stricmp
75#endif // ifdef _MSC_VER
76#endif // if UDS_SYS == UDS_SYS_WINDOWS
77
78#if UDS_SYS == UDS_SYS_ARDUINO
79#include <Arduino.h>
80#define UDS_TP_ISOTP_C
81#endif // if UDS_SYS == UDS_SYS_ARDUINO
82
83#if UDS_SYS == UDS_SYS_ESP32
84#include <esp_timer.h>
85#define UDS_TP_ISOTP_C
86#endif // if UDS_SYS == UDS_SYS_ESP32
87
88
89
90/**
91 * @def UDS_SYS
92 * @brief Selects the host system iso14229 is compiled for.
93 * @see uds_sys_ for the list of valid values
94 */
95
96/**
97 * @def UDS_CUSTOM_MILLIS
98 * @brief bring your own UDSMillis implementation
99 * @details Bring your own UDSMillis implementation. Valid values:
100 * - `0` (default): iso14229 provides UDSMillis() for the detected @ref UDS_SYS platform
101 * - `1`: the user must provide their own UDSMillis() implementation
102 *
103 * @see UDSMillis
104 */
105
106#define UDS_ISOTP_MTU (4095) ///< ISO-TP Maximum Transmission Unit (ISO-15764-2-2004 section 5.3.3)
107
108#ifndef UDS_TP_MTU
109/// ISOTP is the only supported tp type, so UDS inherits its MTU
110#define UDS_TP_MTU UDS_ISOTP_MTU
111#endif
112
113/**
114 * @def UDS_SERVER_SEND_BUF_SIZE
115 * @brief reduce this at your own risk to save RAM. Fuzz testing is done with the default of @ref
116 * UDS_TP_MTU.
117 */
118#ifndef UDS_SERVER_SEND_BUF_SIZE
119#define UDS_SERVER_SEND_BUF_SIZE (UDS_TP_MTU)
120#endif
121
122/** @copydoc UDS_SERVER_SEND_BUF_SIZE */
123#ifndef UDS_SERVER_RECV_BUF_SIZE
124#define UDS_SERVER_RECV_BUF_SIZE (UDS_TP_MTU)
125#endif
126
127/** @copydoc UDS_SERVER_SEND_BUF_SIZE */
128#ifndef UDS_CLIENT_SEND_BUF_SIZE
129#define UDS_CLIENT_SEND_BUF_SIZE (UDS_TP_MTU)
130#endif
131
132/** @copydoc UDS_SERVER_SEND_BUF_SIZE */
133#ifndef UDS_CLIENT_RECV_BUF_SIZE
134#define UDS_CLIENT_RECV_BUF_SIZE (UDS_TP_MTU)
135#endif
136
137#ifndef UDS_CLIENT_DEFAULT_P2_MS
138#define UDS_CLIENT_DEFAULT_P2_MS (150U) ///< default P2 timeout
139#endif
140
141#ifndef UDS_CLIENT_DEFAULT_P2_STAR_MS
142#define UDS_CLIENT_DEFAULT_P2_STAR_MS (1500U) ///< default P2* timeout
143#endif
144
146
147#ifndef UDS_SERVER_DEFAULT_P2_MS
148#define UDS_SERVER_DEFAULT_P2_MS (50) ///< default P2 duration
149#endif
150
151#ifndef UDS_SERVER_DEFAULT_P2_STAR_MS
152#define UDS_SERVER_DEFAULT_P2_STAR_MS (5000) ///< default P2* duration
153#endif
154
155#ifndef UDS_SERVER_DEFAULT_S3_MS
156#define UDS_SERVER_DEFAULT_S3_MS \
157 (5100) ///< default S3 duration (ISO14229-2 2013 Table 5: 5000 -0/+200 ms)
158#endif
159
160static_assert((0 < UDS_SERVER_DEFAULT_P2_MS) &&
163 "");
164
165/// Duration between the server sending a positive response to an ECU reset request and the emission
166/// of a UDS_EVT_DoScheduledReset event. This should be set to a duration adequate for the server
167/// transport layer to finish responding to the ECU reset request.
168#ifndef UDS_SERVER_DEFAULT_POWER_DOWN_TIME_MS
169#define UDS_SERVER_DEFAULT_POWER_DOWN_TIME_MS (60)
170#endif
171
172#if (UDS_SERVER_DEFAULT_POWER_DOWN_TIME_MS < UDS_SERVER_DEFAULT_P2_MS)
173#error "The server shall have adequate time to respond before reset"
174#endif
175
176/// Amount of time to wait after boot before accepting 0x27 requests.
177#ifndef UDS_SERVER_0x27_BRUTE_FORCE_MITIGATION_BOOT_DELAY_MS
178#define UDS_SERVER_0x27_BRUTE_FORCE_MITIGATION_BOOT_DELAY_MS (1000)
179#endif
180
181/// Amount of time to wait after an authentication failure before accepting another 0x27 request.
182#ifndef UDS_SERVER_0x27_BRUTE_FORCE_MITIGATION_AUTH_FAIL_DELAY_MS
183#define UDS_SERVER_0x27_BRUTE_FORCE_MITIGATION_AUTH_FAIL_DELAY_MS (1000)
184#endif
185
186#ifndef UDS_SERVER_DEFAULT_XFER_DATA_MAX_BLOCKLENGTH
187/*! ISO14229-1:2013 Table 396. This parameter is used by the requestDownload positive response
188message to inform the client how many data bytes (maxNumberOfBlockLength) to include in each
189TransferData request message from the client. */
190#define UDS_SERVER_DEFAULT_XFER_DATA_MAX_BLOCKLENGTH (UDS_TP_MTU)
191#endif
192
193
194
195
196#if defined UDS_TP_ISOTP_C_SOCKETCAN
197#ifndef UDS_TP_ISOTP_C
198#define UDS_TP_ISOTP_C
199#endif
200#endif
201
202/** private: Status flags set by the transport implementation.
203 */
205 UDS_TP_IDLE = 0x0000,
206 UDS_TP_SEND_IN_PROGRESS = 0x0001,
207 UDS_TP_RECV_COMPLETE = 0x0002,
208 UDS_TP_ERR = 0x0004,
209};
210
211typedef uint32_t UDSTpStatus_t; ///< private: bitfield of @ref UDSTpStatusFlags
212
213/** private: transport message type
214 */
215typedef enum {
216 UDS_A_MTYPE_DIAG = 0,
217 UDS_A_MTYPE_REMOTE_DIAG,
218 UDS_A_MTYPE_SECURE_DIAG,
219 UDS_A_MTYPE_SECURE_REMOTE_DIAG,
221
222/** private: transmission type
223 */
224typedef enum {
225 UDS_A_TA_TYPE_PHYSICAL = 0, // unicast (1:1)
226 UDS_A_TA_TYPE_FUNCTIONAL, // multicast
228
229typedef uint8_t UDSTpAddr_t; ///< private: oneof @ref UDS_A_TA_Type_t
230
231/**
232 * @brief Service data unit (SDU)
233 * @details Service data unit (SDU): data interface between the application layer and the
234 * transport layer
235 */
236typedef struct {
237 UDS_A_Mtype_t A_Mtype; /**< message type (diagnostic, remote diagnostic, secure diagnostic,
238 secure remote diagnostic) */
239 uint32_t A_SA; /**< application source address */
240 uint32_t A_TA; /**< application target address */
241 UDS_A_TA_Type_t A_TA_Type; /**< application target address type (physical or functional) */
242 uint32_t A_AE; /**< application layer remote address */
243} UDSSDU_t;
244
245#define UDS_TP_NOOP_ADDR (0xFFFFFFFF) ///< flags A_SA / A_TA as unused
246
247/** @brief Signed size type used by the transport layer interface (byte count, or negative on
248 * error). */
249typedef int32_t UDSTpSize_t;
250
251/**
252 * @brief UDS Transport layer
253 * @note implementers should embed this struct at offset zero in their own transport layer handle
254 */
255typedef struct UDSTp {
256 /**
257 * @brief Send data to the transport
258 * @param hdl: pointer to transport handle
259 * @param buf: a pointer to the data to send
260 * @param len: length of data to send
261 * @param info: pointer to SDU info (may be NULL). If NULL, implementation should send with
262 * physical addressing
263 */
264 UDSTpSize_t (*send)(struct UDSTp *hdl, const uint8_t *buf, size_t len, const UDSSDU_t *info);
265
266 /**
267 * @brief Receive data from the transport
268 * @param hdl: transport handle
269 * @param buf: receive buffer
270 * @param bufsize: size of the receive buffer
271 * @param info: pointer to SDU info to be updated by transport implementation. May be NULL. If
272 * non-NULL, the transport implementation must populate it with valid values.
273 */
274 UDSTpSize_t (*recv)(struct UDSTp *hdl, uint8_t *buf, size_t bufsize, UDSSDU_t *info);
275
276 /**
277 * @brief Poll the transport layer.
278 * @param hdl: pointer to transport handle
279 * @note the transport layer user is responsible for calling this function periodically
280 * @note threaded implementations like linux isotp sockets don't need to do anything here.
281 * @return UDS_TP_IDLE if idle, otherwise UDS_TP_SEND_IN_PROGRESS or UDS_TP_RECV_COMPLETE
282 */
283 UDSTpStatus_t (*poll)(struct UDSTp *hdl);
284} UDSTp_t;
285
286UDSTpSize_t UDSTpSend(UDSTp_t *hdl, const uint8_t *buf, UDSTpSize_t len,
287 const UDSSDU_t *info); ///< Send to transport
288UDSTpSize_t UDSTpRecv(UDSTp_t *hdl, uint8_t *buf, size_t bufsize,
289 UDSSDU_t *info); ///< Receive from transport
290UDSTpStatus_t UDSTpPoll(UDSTp_t *hdl); ///< call this at <5ms intervals
291
292
293
294/** @file */
295
296/**
297 * @enum UDSEvent_t
298 * @brief UDS events
299 *
300 * Events are passed to the server or client callback function along with
301 * a pointer to the associated argument structure.
302 */
303typedef enum UDSEvent {
304 UDS_EVT_Err, /**< Common event. Argument type: UDSErr_t * */
305
306 UDS_EVT_DiagSessCtrl, /**< Server evt 0x10, argtype: UDSDiagSessCtrlArgs_t * */
307 UDS_EVT_EcuReset, /**< Server evt 0x11, argtype: UDSECUResetArgs_t * */
308 UDS_EVT_ClearDiagnosticInfo, /**< Server evt 0x14, argtype: UDSCDIArgs_t * */
309 UDS_EVT_ReadDTCInformation, /**< Server evt 0x19, argtype: UDSRDTCIArgs_t * */
310 UDS_EVT_ReadDataByIdent, /**< Server evt 0x22, argtype: UDSRDBIArgs_t * */
311 UDS_EVT_ReadMemByAddr, /**< Server evt 0x23, argtype: UDSReadMemByAddrArgs_t * */
312 UDS_EVT_CommCtrl, /**< Server evt 0x28, argtype: UDSCommCtrlArgs_t * */
313 UDS_EVT_SecAccessRequestSeed, /**< Server evt 0x27, argtype: UDSSecAccessRequestSeedArgs_t * */
314 UDS_EVT_SecAccessValidateKey, /**< Server evt 0x27, argtype: UDSSecAccessValidateKeyArgs_t * */
315 UDS_EVT_WriteDataByIdent, /**< Server evt 0x2E, argtype: UDSWDBIArgs_t * */
316 UDS_EVT_WriteMemByAddr, /**< Server evt 0x3D, argtype: UDSWriteMemByAddrArgs_t * */
317 UDS_EVT_DynamicDefineDataId, /**< Server evt 0x2C, argtype: UDSDDDIArgs_t * */
318 UDS_EVT_IOControl, /**< Server evt 0x2F, argtype: UDSIOCtrlArgs_t * */
319 UDS_EVT_RoutineCtrl, /**< Server evt 0x31, argtype: UDSRoutineCtrlArgs_t * */
320 UDS_EVT_RequestDownload, /**< Server evt 0x34, argtype: UDSRequestDownloadArgs_t * */
321 UDS_EVT_RequestUpload, /**< Server evt 0x35, argtype: UDSRequestUploadArgs_t * */
322 UDS_EVT_TransferData, /**< Server evt 0x36, argtype: UDSTransferDataArgs_t * */
323 UDS_EVT_RequestTransferExit, /**< Server evt 0x37, argtype: UDSRequestTransferExitArgs_t * */
324 UDS_EVT_SessionTimeout, /**< Server evt 0x38, argtype: NULL */
325 UDS_EVT_DoScheduledReset, /**< Server evt 0x39, argtype: uint8_t * */
326 UDS_EVT_RequestFileTransfer, /**< Server evt 0x38, argtype: UDSRequestFileTransferArgs_t * */
327 UDS_EVT_ControlDTCSetting, /**< Server evt 0x85, argtype: UDSControlDTCSettingArgs_t * */
328 UDS_EVT_LinkControl, /**< Server evt 0x87, argtype: UDSLinkCtrlArgs_t * */
329 UDS_EVT_Custom, /**< Server evt other, argtype: UDSCustomArgs_t * */
330
331 UDS_EVT_Poll, /**< Client evt: Poll. Argument type: NULL */
332 UDS_EVT_SendComplete, /**< Client evt: Send complete. Argument type: NULL */
333 UDS_EVT_ResponseReceived, /**< Client evt: Response received. Argument type: NULL */
334 UDS_EVT_Idle, /**< Client evt: Idle. Argument type: NULL */
335
336 UDS_EVT_MAX, /**< Unused sentinel value */
337} UDSEvent_t;
338
339/**
340 * @brief Error Codes, including NRCs defined by the standard.
341 * @see UDSErrToStr
342 */
343typedef enum {
344 UDS_FAIL = -1, // General error
345 UDS_OK = 0, // Success
346
347 // Negative Response Codes (NRCs) as defined in ISO14229-1:2020 Table A.1 - Negative Response
348 // Code (NRC) definition and values
349 UDS_PositiveResponse = 0,
350 // 0x01 to 0x0F are reserved by ISO14229-1:2020
351 UDS_NRC_GeneralReject = 0x10,
352 UDS_NRC_ServiceNotSupported = 0x11,
353 UDS_NRC_SubFunctionNotSupported = 0x12,
354 UDS_NRC_IncorrectMessageLengthOrInvalidFormat = 0x13,
355 UDS_NRC_ResponseTooLong = 0x14,
356 // 0x15 to 0x20 are reserved by ISO14229-1:2020
357 UDS_NRC_BusyRepeatRequest = 0x21,
358 UDS_NRC_ConditionsNotCorrect = 0x22,
359 UDS_NRC_RequestSequenceError = 0x24,
360 UDS_NRC_NoResponseFromSubnetComponent = 0x25,
361 UDS_NRC_FailurePreventsExecutionOfRequestedAction = 0x26,
362 // 0x27 to 0x30 are reserved by ISO14229-1:2020
363 UDS_NRC_RequestOutOfRange = 0x31,
364 // 0x32 is reserved by ISO14229-1:2020
365 UDS_NRC_SecurityAccessDenied = 0x33,
366 UDS_NRC_AuthenticationRequired = 0x34,
367 UDS_NRC_InvalidKey = 0x35,
368 UDS_NRC_ExceedNumberOfAttempts = 0x36,
369 UDS_NRC_RequiredTimeDelayNotExpired = 0x37,
370 UDS_NRC_SecureDataTransmissionRequired = 0x38,
371 UDS_NRC_SecureDataTransmissionNotAllowed = 0x39,
372 UDS_NRC_SecureDataVerificationFailed = 0x3A,
373 // 0x3B to 0x4F are reserved by ISO14229-1:2020
374 UDS_NRC_CertficateVerificationFailedInvalidTimePeriod = 0x50,
375 UDS_NRC_CertficateVerificationFailedInvalidSignature = 0x51,
376 UDS_NRC_CertficateVerificationFailedInvalidChainOfTrust = 0x52,
377 UDS_NRC_CertficateVerificationFailedInvalidType = 0x53,
378 UDS_NRC_CertficateVerificationFailedInvalidFormat = 0x54,
379 UDS_NRC_CertficateVerificationFailedInvalidContent = 0x55,
380 UDS_NRC_CertficateVerificationFailedInvalidScope = 0x56,
381 UDS_NRC_CertficateVerificationFailedInvalidCertificate = 0x57,
382 UDS_NRC_OwnershipVerificationFailed = 0x58,
383 UDS_NRC_ChallengeCalculationFailed = 0x59,
384 UDS_NRC_SettingAccessRightsFailed = 0x5A,
385 UDS_NRC_SessionKeyCreationOrDerivationFailed = 0x5B,
386 UDS_NRC_ConfigurationDataUsageFailed = 0x5C,
387 UDS_NRC_DeAuthenticationFailed = 0x5D,
388 // 0x5E to 0x6F are reserved by ISO14229-1:2020
389 UDS_NRC_UploadDownloadNotAccepted = 0x70,
390 UDS_NRC_TransferDataSuspended = 0x71,
391 UDS_NRC_GeneralProgrammingFailure = 0x72,
392 UDS_NRC_WrongBlockSequenceCounter = 0x73,
393 // 0x74 to 0x77 are reserved by ISO14229-1:2020
394 UDS_NRC_RequestCorrectlyReceived_ResponsePending = 0x78,
395 // 0x79 to 0x7D are reserved by ISO14229-1:2020
396 UDS_NRC_SubFunctionNotSupportedInActiveSession = 0x7E,
397 UDS_NRC_ServiceNotSupportedInActiveSession = 0x7F,
398 // 0x80 is reserved by ISO14229-1:2020
399 UDS_NRC_RpmTooHigh = 0x81,
400 UDS_NRC_RpmTooLow = 0x82,
401 UDS_NRC_EngineIsRunning = 0x83,
402 UDS_NRC_EngineIsNotRunning = 0x84,
403 UDS_NRC_EngineRunTimeTooLow = 0x85,
404 UDS_NRC_TemperatureTooHigh = 0x86,
405 UDS_NRC_TemperatureTooLow = 0x87,
406 UDS_NRC_VehicleSpeedTooHigh = 0x88,
407 UDS_NRC_VehicleSpeedTooLow = 0x89,
408 UDS_NRC_ThrottlePedalTooHigh = 0x8A,
409 UDS_NRC_ThrottlePedalTooLow = 0x8B,
410 UDS_NRC_TransmissionRangeNotInNeutral = 0x8C,
411 UDS_NRC_TransmissionRangeNotInGear = 0x8D,
412 // 0x8E is reserved by ISO14229-1:2020
413 UDS_NRC_BrakeSwitchNotClosed = 0x8F,
414 UDS_NRC_ShifterLeverNotInPark = 0x90,
415 UDS_NRC_TorqueConverterClutchLocked = 0x91,
416 UDS_NRC_VoltageTooHigh = 0x92,
417 UDS_NRC_VoltageTooLow = 0x93,
418 UDS_NRC_ResourceTemporarilyNotAvailable = 0x94,
419
420 /* 0x95 to 0xEF are reservedForSpecificConditionsNotCorrect */
421 /* 0xF0 to 0xFE are vehicleManufacturerSpecificConditionsNotCorrect */
422 /* 0xFF is ISOSAEReserved */
423
424 // The following values are not defined in ISO14229-1:2020
425 UDS_ERR_TIMEOUT = 0x100, // A request has timed out
426 UDS_ERR_DID_MISMATCH, // The response DID does not match the request DID
427 UDS_ERR_SID_MISMATCH, // The response SID does not match the request SID
428 UDS_ERR_SUBFUNCTION_MISMATCH, // The response SubFunction does not match the request SubFunction
429 UDS_ERR_TPORT, // Transport error. Check the transport layer for more information
430 UDS_ERR_RESP_TOO_SHORT, // The response is too short
431 UDS_ERR_BUFSIZ, // The buffer is not large enough
432 UDS_ERR_INVALID_ARG, // The function has been called with invalid arguments
433 UDS_ERR_BUSY, // The client is busy and cannot process the request
434 UDS_ERR_MISUSE, // The library is used incorrectly
435} UDSErr_t;
436
437/**
438 * @defgroup uds_lev_ds_ Diagnostic Session Levels
439 * @brief ISO14229-1:2020 Table 25
440 * @see UDSSendDiagSessCtrl UDS_EVT_DiagSessCtrl
441 * @{
442 */
443#define UDS_LEV_DS_DS 1 ///< Default Session
444#define UDS_LEV_DS_PRGS 2 ///< Programming Session
445#define UDS_LEV_DS_EXTDS 3 ///< Extended Diagnostic Session
446#define UDS_LEV_DS_SSDS 4 ///< Safety System Diagnostic Session
447/** @} */
448
449/**
450 * @defgroup uds_lev_rt_ Reset Types
451 * @brief ISO14229-1:2020 Table 34
452 * @see UDSSendECUReset UDS_EVT_ECUReset
453 * @{
454 */
455#define UDS_LEV_RT_HR 1 ///< Hard Reset
456#define UDS_LEV_RT_KOFFONR 2 ///< Key Off On Reset
457#define UDS_LEV_RT_SR 3 ///< Soft Reset
458#define UDS_LEV_RT_ERPSD 4 ///< Enable Rapid Power Shut Down
459#define UDS_LEV_RT_DRPSD 5 ///< Disable Rapid Power Shut Down
460/** @} */
461
462/**
463 * @defgroup uds_lev_ctrlp_ Communication Control Levels
464 * @brief ISO14229-1:2020 Table 54
465 * @see UDSSendCommCtrl UDS_EVT_CommCtrl
466 * @{
467 */
468#define UDS_LEV_CTRLTP_ERXTX 0 ///< EnableRxAndTx
469#define UDS_LEV_CTRLTP_ERXDTX 1 ///< EnableRxAndDisableTx
470#define UDS_LEV_CTRLTP_DRXETX 2 ///< DisableRxAndEnableTx
471#define UDS_LEV_CTRLTP_DRXTX 3 ///< DisableRxAndTx
472/** @} */
473
474/**
475 * @defgroup uds_ctp_ Communication Types
476 * @brief ISO14229-1:2020 Table B.1
477 * @see UDSSendCommCtrl UDS_EVT_CommCtrl
478 * @{
479 */
480#define UDS_CTP_NCM 1 ///< NormalCommunicationMessages
481#define UDS_CTP_NWMCM 2 ///< NetworkManagementCommunicationMessages
482#define UDS_CTP_NWMCM_NCM \
483 3 ///< NetworkManagementCommunicationMessagesAndNormalCommunicationMessages
484/** @} */
485
486/**
487 * @defgroup uds_lev_rctp_ Routine Control Levels
488 * @brief ISO14229-1:2020 Table 426
489 * @see UDSSendRoutineCtrl UDS_EVT_RoutineCtrl
490 * @{
491 */
492#define UDS_LEV_RCTP_STR 1 ///< StartRoutine
493#define UDS_LEV_RCTP_STPR 2 ///< StopRoutine
494#define UDS_LEV_RCTP_RRR 3 ///< RequestRoutineResults
495/** @} */
496
497/**
498 * @defgroup uds_moop_ Mode of Operation for RequestFileTransfer
499 * @brief ISO14229-1:2020 Table G.1
500 * @see UDSSendRequestFileTransfer UDS_EVT_RequestFileTransfer
501 * @{
502 */
503#define UDS_MOOP_ADDFILE 1 ///< AddFile
504#define UDS_MOOP_DELFILE 2 ///< DeleteFile
505#define UDS_MOOP_REPLFILE 3 ///< ReplaceFile
506#define UDS_MOOP_RDFILE 4 ///< ReadFile
507#define UDS_MOOP_RDDIR 5 ///< ReadDirectory
508#define UDS_MOOP_RSFILE 6 ///< ResumeFile
509/** @} */
510
511/**
512 * @defgroup uds_lev_dtcstp_ Diagnostic Trouble Code Control Level
513 * @brief ISO14229-1:2020 Table 128
514 * @see UDSSendControlDTCSetting UDS_EVT_ControlDTCSetting
515 * @{
516 */
517#define UDS_LEV_DTCSTP_ON 1 ///< Resume updating DTCs
518#define UDS_LEV_DTCSTP_OFF 2 ///< Stop updating DTCs
519/** @} */
520
521/**
522 * @defgroup uds_lev_lctp_ Link Control Level
523 * @brief ISO14229-1:2020 Table 171
524 * @see UDSSendLinkControl UDS_EVT_LinkControl
525 * @{
526 */
527#define UDS_LEV_LCTP_VMTWFP 1 ///< VerifyModeTransitionWithFixedParameter
528#define UDS_LEV_LCTP_VMTWSP 2 ///< VerifyModeTransitionWithSpecificParameter
529#define UDS_LEV_LCTP_TM 3 ///< TransitionMode
530/** @} */
531
532/// ISO-14229-1:2013 Table 2
533#define UDS_MAX_DIAGNOSTIC_SERVICES 0x7F
534
535#define UDS_RESPONSE_SID_OF(request_sid) \
536 ((request_sid) + 0x40) ///< Convert request SID to response SID
537#define UDS_REQUEST_SID_OF(response_sid) \
538 ((response_sid) - 0x40) ///< Convert response SID to request SID
539
540/// \cond DOXYGEN_SHOULD_SKIP_THIS
541#define UDS_NEG_RESP_LEN 3U
542#define UDS_0X10_REQ_LEN 2U
543#define UDS_0X10_RESP_LEN 6U
544#define UDS_0X11_REQ_MIN_LEN 2U
545#define UDS_0X11_RESP_BASE_LEN 2U
546#define UDS_0X14_REQ_MIN_LEN 4U
547#define UDS_0X14_RESP_BASE_LEN 1U
548#define UDS_0X19_REQ_MIN_LEN 2U
549#define UDS_0X19_RESP_BASE_LEN 2U
550#define UDS_0X23_REQ_MIN_LEN 4U
551#define UDS_0X23_RESP_BASE_LEN 1U
552#define UDS_0X22_RESP_BASE_LEN 1U
553#define UDS_0X27_REQ_BASE_LEN 2U
554#define UDS_0X27_RESP_BASE_LEN 2U
555#define UDS_0X28_REQ_BASE_LEN 3U
556#define UDS_0X28_RESP_LEN 2U
557#define UDS_0X2C_REQ_MIN_LEN 2U
558#define UDS_0X2C_RESP_BASE_LEN 2U
559#define UDS_0X2E_REQ_BASE_LEN 3U
560#define UDS_0X2E_REQ_MIN_LEN 4U
561#define UDS_0X2E_RESP_LEN 3U
562#define UDS_0X2F_REQ_MIN_LEN 4U
563#define UDS_0X2F_RESP_BASE_LEN 4U
564#define UDS_0X31_REQ_MIN_LEN 4U
565#define UDS_0X31_RESP_MIN_LEN 4U
566#define UDS_0X34_REQ_BASE_LEN 3U
567#define UDS_0X34_RESP_BASE_LEN 2U
568#define UDS_0X35_REQ_BASE_LEN 3U
569#define UDS_0X35_RESP_BASE_LEN 2U
570#define UDS_0X36_REQ_BASE_LEN 2U
571#define UDS_0X36_RESP_BASE_LEN 2U
572#define UDS_0X37_REQ_BASE_LEN 1U
573#define UDS_0X37_RESP_BASE_LEN 1U
574#define UDS_0X38_REQ_BASE_LEN 5U
575#define UDS_0X38_RESP_BASE_LEN 2U
576#define UDS_0X3D_REQ_MIN_LEN 5U
577#define UDS_0X3D_RESP_BASE_LEN 2U
578#define UDS_0X3E_REQ_MIN_LEN 2U
579#define UDS_0X3E_REQ_MAX_LEN 2U
580#define UDS_0X3E_RESP_LEN 2U
581#define UDS_0X85_REQ_BASE_LEN 2U
582#define UDS_0X85_RESP_LEN 2U
583#define UDS_0X87_REQ_BASE_LEN 2U
584#define UDS_0X87_RESP_LEN 2U
585
586enum UDSDiagnosticServiceId {
587 kSID_DIAGNOSTIC_SESSION_CONTROL = 0x10,
588 kSID_ECU_RESET = 0x11,
589 kSID_CLEAR_DIAGNOSTIC_INFORMATION = 0x14,
590 kSID_READ_DTC_INFORMATION = 0x19,
591 kSID_READ_DATA_BY_IDENTIFIER = 0x22,
592 kSID_READ_MEMORY_BY_ADDRESS = 0x23,
593 kSID_READ_SCALING_DATA_BY_IDENTIFIER = 0x24,
594 kSID_SECURITY_ACCESS = 0x27,
595 kSID_COMMUNICATION_CONTROL = 0x28,
596 kSID_READ_PERIODIC_DATA_BY_IDENTIFIER = 0x2A,
597 kSID_DYNAMICALLY_DEFINE_DATA_IDENTIFIER = 0x2C,
598 kSID_WRITE_DATA_BY_IDENTIFIER = 0x2E,
599 kSID_IO_CONTROL_BY_IDENTIFIER = 0x2F,
600 kSID_ROUTINE_CONTROL = 0x31,
601 kSID_REQUEST_DOWNLOAD = 0x34,
602 kSID_REQUEST_UPLOAD = 0x35,
603 kSID_TRANSFER_DATA = 0x36,
604 kSID_REQUEST_TRANSFER_EXIT = 0x37,
605 kSID_REQUEST_FILE_TRANSFER = 0x38,
606 kSID_WRITE_MEMORY_BY_ADDRESS = 0x3D,
607 kSID_TESTER_PRESENT = 0x3E,
608 kSID_ACCESS_TIMING_PARAMETER = 0x83,
609 kSID_SECURED_DATA_TRANSMISSION = 0x84,
610 kSID_CONTROL_DTC_SETTING = 0x85,
611 kSID_RESPONSE_ON_EVENT = 0x86,
612 kSID_LINK_CONTROL = 0x87,
613};
614/// \endcond
615
616
617
618
619/**
620 * @def UDS_ASSERT(x)
621 * @brief define this during library development.
622 * It is a no-op by default for library users.
623 * API misuse is expected to be covered by runtime checks, not by UDS_ASSERT
624 */
625#ifndef UDS_ASSERT
626#define UDS_ASSERT(x)
627#endif
628
629/**
630 * @brief Check whether one timestamp is after another, correctly handling wrap-around
631 * @param a: timestamp to check
632 * @param b: reference timestamp
633 * @return true if `a` is after `b`
634 */
635static inline bool UDSTimeAfter(uint32_t a, uint32_t b) { return (int32_t)(a - b) > 0; }
636
637/**
638 * @brief Get time in milliseconds
639 * @return current time in milliseconds
640 * @note implementers must ensure the return value is monotonically increasing between
641 * calls. The value must never go backwards.
642 * Wrap-around (overflow back to 0) is expected; this is handled by UDSTimeAfter.
643 */
644uint32_t UDSMillis(void);
645
646const char *UDSErrToStr(UDSErr_t err);
647const char *UDSEventToStr(UDSEvent_t evt);
648
649
650
651/**
652 * @brief logging for bring-up and unit tests.
653 * This interface was copied from ESP-IDF.
654 */
655
656
657/**
658 * @defgroup uds_log_level_ valid values for UDS_LOG_LEVEL
659 * @brief configures logging verbosity
660 * @{
661 */
662#define UDS_LOG_NONE 0 /**< No log output */
663#define UDS_LOG_ERROR 1 /**< Log errors only */
664#define UDS_LOG_WARN 2 /**< Log warnings and errors */
665#define UDS_LOG_INFO 3 /**< Log info, warnings, and errors */
666#define UDS_LOG_DEBUG 4 /**< Log debug, info, warnings, and errors */
667#define UDS_LOG_VERBOSE 5 /**< Log verbose, debug, info, warnings, and errors */
668/** @} */
669
670typedef int UDS_LogLevel_t; ///< one of @ref uds_log_level_
671
672/**
673 * @def UDS_LOG_LEVEL
674 * @brief sets the logging level
675 * @see uds_log_level_ for valid values
676 */
677#ifndef UDS_LOG_LEVEL
678#define UDS_LOG_LEVEL UDS_LOG_NONE
679#endif
680
681/// \cond DOXYGEN_SHOULD_SKIP_THIS
682#if UDS_CONFIG_LOG_COLORS
683#define UDS_LOG_COLOR_BLACK "30"
684#define UDS_LOG_COLOR_RED "31"
685#define UDS_LOG_COLOR_GREEN "32"
686#define UDS_LOG_COLOR_BROWN "33"
687#define UDS_LOG_COLOR_BLUE "34"
688#define UDS_LOG_COLOR_PURPLE "35"
689#define UDS_LOG_COLOR_CYAN "36"
690#define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
691#define LOG_BOLD(COLOR) "\033[1;" COLOR "m"
692#define UDS_LOG_RESET_COLOR "\033[0m"
693#define UDS_LOG_COLOR_E LOG_COLOR(UDS_LOG_COLOR_RED)
694#define UDS_LOG_COLOR_W LOG_COLOR(UDS_LOG_COLOR_BROWN)
695#define UDS_LOG_COLOR_I LOG_COLOR(UDS_LOG_COLOR_GREEN)
696#define UDS_LOG_COLOR_D
697#define UDS_LOG_COLOR_V
698#else // UDS_CONFIG_LOG_COLORS
699#define UDS_LOG_COLOR_E
700#define UDS_LOG_COLOR_W
701#define UDS_LOG_COLOR_I
702#define UDS_LOG_COLOR_D
703#define UDS_LOG_COLOR_V
704#define UDS_LOG_RESET_COLOR
705#endif // UDS_CONFIG_LOG_COLORS
706
707#define UDS_LOG_FORMAT(letter, format) \
708 UDS_LOG_COLOR_##letter #letter " (%" PRIu32 ") %s: " format UDS_LOG_RESET_COLOR "\n"
709
713 "unknown log level");
714
715#if UDS_LOG_LEVEL >= UDS_LOG_ERROR && UDS_LOG_LEVEL != UDS_LOG_NONE
716#define UDS_LOGE(tag, format, ...) \
717 UDS_LogWrite(UDS_LOG_ERROR, tag, UDS_LOG_FORMAT(E, format), UDSMillis(), tag, ##__VA_ARGS__)
718#else
719#define UDS_LOGE(tag, format, ...) UDS_LogDummy(tag, format, ##__VA_ARGS__)
720#endif
721
722#if UDS_LOG_LEVEL >= UDS_LOG_WARN && UDS_LOG_LEVEL != UDS_LOG_NONE
723#define UDS_LOGW(tag, format, ...) \
724 UDS_LogWrite(UDS_LOG_WARN, tag, UDS_LOG_FORMAT(W, format), UDSMillis(), tag, ##__VA_ARGS__)
725#else
726#define UDS_LOGW(tag, format, ...) UDS_LogDummy(tag, format, ##__VA_ARGS__)
727#endif
728
729#if UDS_LOG_LEVEL >= UDS_LOG_INFO && UDS_LOG_LEVEL != UDS_LOG_NONE
730#define UDS_LOGI(tag, format, ...) \
731 UDS_LogWrite(UDS_LOG_INFO, tag, UDS_LOG_FORMAT(I, format), UDSMillis(), tag, ##__VA_ARGS__)
732#else
733#define UDS_LOGI(tag, format, ...) UDS_LogDummy(tag, format, ##__VA_ARGS__)
734#endif
735
736#if UDS_LOG_LEVEL >= UDS_LOG_DEBUG && UDS_LOG_LEVEL != UDS_LOG_NONE
737#define UDS_LOGD(tag, format, ...) \
738 UDS_LogWrite(UDS_LOG_DEBUG, tag, UDS_LOG_FORMAT(D, format), UDSMillis(), tag, ##__VA_ARGS__)
739#else
740#define UDS_LOGD(tag, format, ...) UDS_LogDummy(tag, format, ##__VA_ARGS__)
741#endif
742
743#if UDS_LOG_LEVEL >= UDS_LOG_VERBOSE
744#define UDS_LOGV(tag, format, ...) \
745 UDS_LogWrite(UDS_LOG_VERBOSE, tag, UDS_LOG_FORMAT(V, format), UDSMillis(), tag, ##__VA_ARGS__)
746#define UDS_LOG_SDU(tag, buffer, buff_len, info) \
747 UDS_LogSDUInternal(UDS_LOG_DEBUG, tag, buffer, buff_len, info)
748#else
749#define UDS_LOGV(tag, format, ...) UDS_LogDummy(tag, format, ##__VA_ARGS__)
750#define UDS_LOG_SDU(tag, buffer, buff_len, info) UDS_LogSDUDummy(tag, buffer, buff_len, info)
751#endif
752
753#if defined(__GNUC__) || defined(__clang__)
754#define UDS_PRINTF_FORMAT(fmt_index, first_arg) \
755 __attribute__((format(printf, fmt_index, first_arg)))
756#else
757#define UDS_PRINTF_FORMAT(fmt_index, first_arg)
758#endif
759
760#if UDS_LOG_LEVEL > UDS_LOG_NONE
761void UDS_LogWrite(UDS_LogLevel_t level, const char *tag, const char *format, ...)
762 UDS_PRINTF_FORMAT(3, 4);
763void UDS_LogSDUInternal(UDS_LogLevel_t level, const char *tag, const uint8_t *buffer,
764 size_t buff_len, const UDSSDU_t *info);
765#endif
766
767// Dummy function that consumes arguments but does nothing
768static inline void UDS_LogDummy(const char *tag, const char *format, ...) {
769 (void)tag;
770 (void)format;
771}
772static inline void UDS_LogSDUDummy(const char *tag, const uint8_t *buffer, size_t buff_len,
773 const UDSSDU_t *info) {
774 (void)tag;
775 (void)buffer;
776 (void)buff_len;
777 (void)info;
778}
779/// \endcond
780
781
782
783
784#define UDS_SUPPRESS_POS_RESP 0x1 ///< set the suppress positive response bit
785#define UDS_FUNCTIONAL 0x2 ///< send the request as a functional request
786#define UDS_IGNORE_SRV_TIMINGS 0x8 ///< ignore the server-provided p2 and p2_star
787
788/**
789 * @brief UDS client structure
790 */
791typedef struct UDSClient {
792 uint16_t p2_ms; /**< p2 timeout in milliseconds */
793 uint32_t p2_star_ms; /**< p2* timeout in milliseconds (for 0x78 response) */
794 UDSTp_t *tp; /**< transport layer handle */
795
796 uint32_t p2_timer; /**< p2 timer value */
797 uint8_t state; /**< client request state, @see client_request_states */
798
799 uint8_t options; /**< current request options */
800 uint8_t defaultOptions; /**< default options for all requests */
801 uint8_t _options_copy; /**< copy of options at the time a request is made */
802 uint8_t cfg_data_format_identifier; /**< 0x38 RequestFileTransfer dataFormatIdentifier */
803 uint8_t cfg_file_size_parameter_length; /**< 0x38 RequestFileTransfer fileSizeParameterLength */
804
805 int (*fn)(struct UDSClient *client, UDSEvent_t evt, void *ev_data); /**< callback function */
806 void *fn_data; /**< user-specified function data */
807
808 uint16_t recv_size; /**< size of received data */
809 uint16_t send_size; /**< size of data to send */
810 uint8_t recv_buf[UDS_CLIENT_RECV_BUF_SIZE]; /**< receive buffer */
811 uint8_t send_buf[UDS_CLIENT_SEND_BUF_SIZE]; /**< send buffer */
813
814/**
815 * @brief Security access response structure
816 */
818 uint8_t securityAccessType; /**< security access type (subfunction) */
819 const uint8_t *securitySeed; /**< pointer to security seed data */
820 uint16_t securitySeedLength; /**< length of security seed */
821};
822
823/**
824 * @brief Request download response structure
825 */
827 size_t maxNumberOfBlockLength; /**< maximum number of block length */
828};
829
830/**
831 * @brief Routine control response structure
832 */
834 uint8_t routineControlType; /**< routine control type (subfunction) */
835 uint16_t routineIdentifier; /**< routine identifier */
836 const uint8_t *routineStatusRecord; /**< pointer to routine status record */
837 uint16_t routineStatusRecordLength; /**< length of routine status record */
838};
839
840/**
841 * @brief Read data by identifier variable structure
842 */
843typedef struct {
844 uint16_t did; /**< data identifier */
845 uint16_t len; /**< data length */
846 void *data; /**< pointer to data buffer */
847 void *(*UnpackFn)(void *dst, const void *src, size_t n); /**< optional unpack function */
849
850UDSErr_t UDSClientInit(UDSClient_t *client); ///< Call this once
851UDSErr_t UDSClientPoll(UDSClient_t *client); ///< Call at <5ms intervals
852UDSErr_t UDSSendBytes(UDSClient_t *client, const uint8_t *data,
853 uint16_t size); ///< Send user-defined bytes to a UDS server
854UDSErr_t UDSSendECUReset(UDSClient_t *client, uint8_t type); ///< Request ECUReset
855UDSErr_t UDSSendDiagSessCtrl(UDSClient_t *client, uint8_t mode); ///< Change the diagnostic session
856UDSErr_t UDSSendSecurityAccess(UDSClient_t *client, uint8_t level, uint8_t *data,
857 uint16_t size); ///< Get Security Access
858UDSErr_t UDSSendCommCtrl(UDSClient_t *client, uint8_t ctrl,
859 uint8_t comm); ///< Change communication settings
860UDSErr_t UDSSendRDBI(UDSClient_t *client, const uint16_t *didList,
861 const uint16_t numDataIdentifiers); ///< Read Data By Identifier
862UDSErr_t UDSSendWDBI(UDSClient_t *client, uint16_t dataIdentifier, const uint8_t *data,
863 uint16_t size); ///< Write Data By Identifier
864UDSErr_t UDSSendTesterPresent(UDSClient_t *client); ///< What's up?
865UDSErr_t UDSSendRoutineCtrl(UDSClient_t *client, uint8_t type, uint16_t routineIdentifier,
866 const uint8_t *data, uint16_t size); ///< Request to Twiddle Routines
867
868UDSErr_t UDSSendRequestDownload(UDSClient_t *client, uint8_t dataFormatIdentifier,
869 uint8_t addressAndLengthFormatIdentifier, size_t memoryAddress,
870 size_t memorySize); ///< Request to Download via TransferData
871
872UDSErr_t UDSSendRequestUpload(UDSClient_t *client, uint8_t dataFormatIdentifier,
873 uint8_t addressAndLengthFormatIdentifier, size_t memoryAddress,
874 size_t memorySize); ///< Request to Upload via TransferData
875UDSErr_t UDSSendTransferData(UDSClient_t *client, uint8_t blockSequenceCounter,
876 const uint16_t blockLength, const uint8_t *data,
877 uint16_t size); ///< Transfer Data to/from a buffer
878UDSErr_t UDSSendTransferDataStream(UDSClient_t *client, uint8_t blockSequenceCounter,
879 const uint16_t blockLength,
880 FILE *fd); ///< Transfer Data to/from a file
882UDSSendRequestTransferExit(UDSClient_t *client); ///< Call this when finished with TransferData
883
885 UDSClient_t *client, uint8_t mode, const char *filePath, size_t fileSizeUncompressed,
886 size_t fileSizeCompressed); ///< filesystem-based frontend to TransferData
887UDSErr_t UDSCtrlDTCSetting(UDSClient_t *client, uint8_t dtcSettingType,
888 uint8_t *dtcSettingControlOptionRecord,
889 uint16_t len); ///< control DTC setting
891 uint16_t numVars); ///< Parse server's response to RDBI
893 const UDSClient_t *client,
894 struct SecurityAccessResponse *resp); ///< Parse server's response to SecurityAccess
896 const UDSClient_t *client,
897 struct RequestDownloadResponse *resp); ///< Parse server's response to RequestDownload
899 const UDSClient_t *client,
900 struct RoutineControlResponse *resp); ///< Parse server's response to RoutineControl
901
902
903
904
905/**
906 * @brief Server request context
907 */
908typedef struct {
909 uint8_t recv_buf[UDS_SERVER_RECV_BUF_SIZE]; /**< receive buffer */
910 uint8_t send_buf[UDS_SERVER_SEND_BUF_SIZE]; /**< send buffer */
911 size_t recv_len; /**< received data length */
912 size_t send_len; /**< send data length */
913 size_t send_buf_size; /**< send buffer size */
914 UDSSDU_t info; /**< service data unit information */
915} UDSReq_t;
916
917/**
918 * @brief UDS server structure
919 */
920typedef struct UDSServer {
921 UDSTp_t *tp; /**< transport layer handle */
922 UDSErr_t (*fn)(struct UDSServer *srv, UDSEvent_t event, void *arg); /**< callback function */
923 void *fn_data; /**< user-specified function data */
924
925 /**
926 * @brief Server time constants (milliseconds)
927 */
928 uint16_t p2_ms; /**< Default P2_server_max timing supported by the server */
929 uint32_t p2_star_ms; /**< Enhanced (NRC 0x78) P2_server_max supported by the server */
930 uint16_t s3_ms; /**< Session timeout */
931
932 uint8_t ecuResetScheduled; /**< nonzero indicates that an ECUReset has been scheduled */
933 uint32_t ecuResetTimer; /**< for delaying resetting until a response has been sent */
934 uint32_t p2_timer; /**< for rate limiting server responses */
935 uint32_t s3_session_timeout_timer; /**< indicates that diagnostic session has timed out */
936 uint32_t sec_access_auth_fail_timer; /**< brute-force hardening: rate limit security access */
937 uint32_t sec_access_boot_delay_timer; /**< brute-force hardening: restrict security access until
938 timer expires */
939
940 /**
941 * @brief UDS-1-2013: Table 407 - 0x36 TransferData Supported negative
942 * response codes requires that the server keep track of whether the
943 * transfer is active
944 */
945 bool xferIsActive; /**< transfer is active */
946 uint8_t xferBlockSequenceCounter; /**< UDS-1-2013: 14.4.2.3, Table 404: block sequence counter
947 starts at 0x01 */
948 size_t xferTotalBytes; /**< total transfer size in bytes requested by the client */
949 size_t xferByteCounter; /**< total number of bytes transferred */
950 size_t xferBlockLength; /**< block length (convenience for the TransferData API) */
951
952 uint8_t sessionType; /**< diagnostic session type (0x10) */
953 uint8_t securityLevel; /**< SecurityAccess (0x27) level */
954
955 bool RCRRP; /**< set to true when user fn returns 0x78 and false otherwise */
956 bool requestInProgress; /**< set to true when a request has been processed but the response has
957 not yet been sent */
958
959 /**
960 * @brief UDS-1 2013 defines the following conditions under which the server does not
961 * process incoming requests:
962 * - not ready to receive (Table A.1 0x78)
963 * - not accepting request messages and not sending responses (9.3.1)
964 *
965 * when this variable is set to true, incoming ISO-TP data will not be processed.
966 */
967 bool notReadyToReceive; /**< incoming ISO-TP data will not be processed */
968
969 UDSReq_t r; /**< request context */
971
972/**
973 * @brief Diagnostic session control arguments
974 */
975typedef struct {
976 const uint8_t type; /**< requested diagnostic session type */
977 uint16_t p2_ms; /**< optional: p2 timing override */
978 uint32_t p2_star_ms; /**< optional: p2* timing override */
980
981/**
982 * @brief ECU reset arguments
983 */
984typedef struct {
985 const uint8_t type; /**< reset type requested by client */
986 uint32_t powerDownTimeMillis; /**< when this much time has elapsed after a UDS_PositiveResponse,
987 a UDS_EVT_DoScheduledReset will be issued */
989
990/**
991 * @brief Clear diagnostic information arguments
992 */
993typedef struct {
994 const uint32_t groupOfDTC; /**< lower 3 bytes describe the groupOfDTC */
995 const bool hasMemorySelection; /**< `true` when a memory selection byte is present */
996 const uint8_t memorySelection; /**< memorySelection byte (optional) */
998
999/**
1000 * @brief Read DTC information arguments
1001 */
1002typedef struct {
1003 const uint8_t type; /**< invoked subfunction */
1004 uint8_t (*copy)(UDSServer_t *srv, const void *src,
1005 uint16_t count); /**< function for copying data */
1006
1007 union {
1008 struct {
1009 uint8_t mask; /**< DTC status mask */
1010 } numOfDTCByStatusMaskArgs, /**< args for number of DTCs by status mask */
1011 dtcStatusByMaskArgs; /**< args for DTCs by status mask */
1012 struct {
1013 uint32_t dtc; /**< DTC Mask Record */
1014 uint8_t snapshotNum; /**< DTC Snaphot Record Number */
1015 uint8_t memory; /**< Memory Selection (only used when type == 0x18) */
1016 } dtcSnapshotRecordbyDTCNumArgs, /**< args for DTC snapshot record by DTC number */
1017 userDefMemDTCSnapshotRecordByDTCNumArgs; /**< args for user-defined-memory DTC snapshot
1018 record by DTC number */
1019 struct {
1020 uint8_t recordNum; /**< DTC Data Record Number */
1021 } dtcStoredDataByRecordNumArgs, /**< args for DTC stored data by record number */
1022 dtcExtDataRecordByRecordNumArgs, /**< args for DTC extended data record by record number
1023 */
1024 dtcExtDataRecordIdArgs; /**< args for supported DTC extended data record ID */
1025 struct {
1026 uint32_t dtc; /**< DTC Mask Record */
1027 uint8_t extDataRecNum; /**< DTC Extended Data Record Number */
1028 uint8_t memory; /**< Memory Selection (only used when type == 0x19) */
1029 } dtcExtDtaRecordByDTCNumArgs, /**< args for DTC extended data record by DTC number */
1030 userDefMemDTCExtDataRecordByDTCNumArgs; /**< args for user-defined-memory DTC extended
1031 data record by DTC number */
1032 struct {
1033 uint8_t
1034 functionalGroup; /**< Functional Group Identifier (only used when type == 0x42) */
1035 uint8_t severityMask; /**< DTC Severity Mask */
1036 uint8_t statusMask; /**< DTC Status Mask */
1037 } numOfDTCBySeverityMaskArgs, /**< args for number of DTCs by severity mask */
1038 dtcBySeverityMaskArgs, /**< args for DTCs by severity mask */
1039 wwhobdDTCByMaskArgs; /**< args for WWH-OBD DTCs by mask */
1040 struct {
1041 uint32_t dtc; /**< DTC Mask Record */
1042 } severityInfoOfDTCArgs; /**< args for severity information of a DTC */
1043 struct {
1044 uint8_t mask; /**< DTC status mask */
1045 uint8_t memory; /**< Memory Selection */
1046 } userDefMemoryDTCByStatusMaskArgs; /**< args for user-defined-memory DTCs by status mask */
1047 struct {
1048 uint8_t functionalGroup; /**< Functional Group Identifier */
1049 uint8_t
1050 readinessGroup; /**< DTC Readiness Group Identifier (only used when type == 0x56) */
1051 } wwhobdDTCWithPermStatusArgs, /**< args for WWH-OBD DTCs with permanent status */
1052 dtcInfoByDTCReadinessGroupIdArgs; /**< args for DTCs by readiness group */
1053 } subFuncArgs; /**< subfunction-specific arguments, selected by \ref type */
1055
1056/**
1057 * @brief Read data by identifier arguments
1058 */
1059typedef struct {
1060 const uint16_t dataId; /**< RDBI Data Identifier */
1061 uint8_t (*copy)(UDSServer_t *srv, const void *src,
1062 uint16_t count); /**< function for copying data */
1064
1065/**
1066 * @brief Read memory by address arguments
1067 */
1068typedef struct {
1069 const void *memAddr; /**< requested server memory address */
1070 const size_t memSize; /**< requested size */
1071 uint8_t (*copy)(UDSServer_t *srv, const void *src,
1072 uint16_t count); /**< function for copying data to response */
1074
1075/**
1076 * @brief Communication control arguments
1077 */
1078typedef struct {
1079 uint8_t ctrlType; /**< ControlType */
1080 uint8_t commType; /**< CommunicationType */
1081 uint16_t nodeId; /**< NodeIdentificationNumber (only used when ctrlType is 0x04 or 0x05) */
1083
1084/**
1085 * @brief Security access request seed arguments
1086 */
1087typedef struct {
1088 const uint8_t level; /**< requested security level */
1089 const uint8_t *const dataRecord; /**< pointer to request data */
1090 const uint16_t len; /**< size of request data */
1091 uint8_t (*copySeed)(UDSServer_t *srv, const void *src,
1092 uint16_t len); /**< function for copying data */
1094
1095/**
1096 * @brief Security access validate key arguments
1097 */
1098typedef struct {
1099 const uint8_t level; /**< security level to be validated */
1100 const uint8_t *const key; /**< key sent by client */
1101 const uint16_t len; /**< length of key */
1103
1104/**
1105 * @brief Write data by identifier arguments
1106 */
1107typedef struct {
1108 const uint16_t dataId; /**< WDBI Data Identifier */
1109 const uint8_t *const data; /**< pointer to data */
1110 const uint16_t len; /**< length of data */
1112
1113/**
1114 * @brief Write memory by address arguments
1115 */
1116typedef struct {
1117 const void *memAddr; /**< pointer to memory address */
1118 const size_t memSize; /**< size of memory */
1119 const uint8_t *const data; /**< pointer to data */
1121
1122/**
1123 * @brief Dynamically define data identifier arguments
1124 */
1125typedef struct {
1126 const uint8_t type; /**< invoked subfunction */
1127 bool allDataIds; /**< is true when request is for all data identifiers (only relevant for
1128 subFunc 0x03) */
1129 uint16_t dynamicDataId; /**< dynamicallyDefinedDataIdentifier */
1130
1131 union {
1132 struct {
1133 uint16_t sourceDataId; /**< source DataIdentifier */
1134 uint8_t position; /**< position in source data record */
1135 uint8_t size; /**< number of bytes to be copied */
1136 } defineById; /**< args when defining from an existing source data identifier */
1137 struct {
1138 void *memAddr; /**< memory address to read from */
1139 size_t memSize; /**< number of bytes to read */
1140 } defineByMemAddress; /**< args when defining from a memory address */
1141 } subFuncArgs; /**< subfunction-specific arguments, selected by \ref type */
1143
1144/**
1145 * @brief Input/output control by identifier arguments
1146 */
1147typedef struct {
1148 const uint16_t dataId; /**< Data Identifier */
1149 const uint8_t ioCtrlParam; /**< inputOutputControlParameter */
1150 const void *const ctrlStateAndMask; /**< controlState bytes and controlMask (optional) */
1151 const size_t ctrlStateAndMaskLen; /**< number of bytes in `ctrlStateAndMask` */
1152 uint8_t (*copy)(UDSServer_t *srv, const void *src,
1153 uint16_t count); /**< function for copying data */
1155
1156/**
1157 * @brief Routine control arguments
1158 */
1159typedef struct {
1160 const uint8_t ctrlType; /**< routineControlType */
1161 const uint16_t id; /**< routineIdentifier */
1162 const uint8_t *optionRecord; /**< optional data */
1163 const uint16_t len; /**< length of optional data */
1164 uint8_t (*copyStatusRecord)(UDSServer_t *srv, const void *src,
1165 uint16_t len); /**< function for copying response data */
1167
1168/**
1169 * @brief Request download arguments
1170 */
1171typedef struct {
1172 const void *addr; /**< requested address */
1173 const size_t size; /**< requested download size */
1174 const uint8_t dataFormatIdentifier; /**< optional specifier for format of data */
1175 uint16_t maxNumberOfBlockLength; /**< optional response: inform client how many data bytes to
1176 send in each `TransferData` request */
1178
1179/**
1180 * @brief Request upload arguments
1181 */
1182typedef struct {
1183 const void *addr; /**< requested address */
1184 const size_t size; /**< requested download size */
1185 const uint8_t dataFormatIdentifier; /**< optional specifier for format of data */
1186 uint16_t maxNumberOfBlockLength; /**< optional response: inform client how many data bytes to
1187 send in each `TransferData` request */
1189
1190/**
1191 * @brief Transfer data arguments
1192 */
1193typedef struct {
1194 const uint8_t *const data; /**< transfer data */
1195 const uint16_t len; /**< transfer data length */
1196 const uint16_t maxRespLen; /**< don't send more than this many bytes with copyResponse */
1197 uint8_t (*copyResponse)(
1198 UDSServer_t *srv, const void *src,
1199 uint16_t len); /**< function for copying transfer data response data (optional) */
1201
1202/**
1203 * @brief Request transfer exit arguments
1204 */
1205typedef struct {
1206 const uint8_t *const data; /**< request data */
1207 const uint16_t len; /**< request data length */
1208 uint8_t (*copyResponse)(UDSServer_t *srv, const void *src,
1209 uint16_t len); /**< function for copying response data (optional) */
1211
1212/**
1213 * @brief Request file transfer arguments
1214 */
1215typedef struct {
1216 /**
1217 * request:
1218 * @see @ref uds_moop_ "modeOfOperation values"
1219 */
1220 const uint8_t modeOfOperation;
1221 const uint16_t filePathLen; /**< request: data length. */
1222 const uint8_t *filePath; /**< request: file path or directory name (ReadDirectory). */
1223 const uint8_t dataFormatIdentifier; /**< request: specifier for format of data (does not apply
1224 to DeleteFile or ReadDir) */
1225
1226 // if MOOP is AddFile, ReplaceFile, or ResumeFile, these fields are **requests**.
1227 // if MOOP is ReadFile or ReadDirectory, these fields are **responses** -- the server must set
1228 // them. if MOOP is DelFile, these fields are unused.
1229 size_t fileSizeUnCompressed; /**< file size or directory info len (ReadDirectory) */
1230 size_t fileSizeCompressed; /**< compressed filesize (ReadFile), otherwise zero. */
1231
1232 uint16_t maxNumberOfBlockLength; /**< response: Defaults to UDS_TP_MTU. Informs client how many
1233 data bytes to send in each `TransferData` request. (unused
1234 by DelFile). */
1235 size_t filePosition; /**< response: byte position to resume from after suspended download
1236 (ResumeFile), otherwise zero. */
1238
1239/**
1240 * @brief Control DTC setting arguments
1241 */
1242typedef struct {
1243 uint8_t type; /**< invoked subfunction */
1244 size_t len; /**< length of data */
1245 void *data; /**< DTCSettingControlOptionRecord */
1247
1248/**
1249 * @brief Link control arguments
1250 */
1251typedef struct {
1252 const uint8_t type; /**< invoked subfunction */
1253 /* purposefully left generic to allow vehicle- and supplier specific data of different sizes */
1254 const size_t len; /**< length of data */
1255 const void *data; /**< data used in the subfunction. E.g. on SubFunction 0x01 this is the
1256 linkControlModelIdentifier, on SubFunction 0x02 this is the linkRecord */
1258
1259/**
1260 * @brief Custom service arguments
1261 */
1262typedef struct {
1263 const uint16_t sid; /**< serviceIdentifier */
1264 const uint8_t *optionRecord; /**< optional data */
1265 const uint16_t len; /**< length of optional data */
1266 uint8_t (*copyResponse)(UDSServer_t *srv, const void *src,
1267 uint16_t len); /**< function for copying response data (optional) */
1269
1270UDSErr_t UDSServerInit(UDSServer_t *srv); ///< call this once
1271void UDSServerPoll(UDSServer_t *srv); ///< Call this at <5ms intervals
1272
1273#if defined(UDS_TP_ISOTP_C)
1274/// \cond DOXYGEN_SHOULD_SKIP_THIS
1275
1276#define ISO_TP_USER_SEND_CAN_ARG 1
1277
1278#ifndef ISOTPC_CONFIG_H
1279#define ISOTPC_CONFIG_H
1280
1281/* Max number of messages the receiver can receive at one time, this value
1282 * is affected by can driver queue length
1283 */
1284#ifndef ISO_TP_DEFAULT_BLOCK_SIZE
1285#define ISO_TP_DEFAULT_BLOCK_SIZE 8
1286#endif
1287
1288/* The STmin parameter value specifies the minimum time gap allowed between
1289 * the transmission of consecutive frame network protocol data units
1290 */
1291#ifndef ISO_TP_DEFAULT_ST_MIN_US
1292#define ISO_TP_DEFAULT_ST_MIN_US 0
1293#endif
1294
1295/* This parameter indicate how many FC N_PDU WTs can be transmitted by the
1296 * receiver in a row.
1297 */
1298#ifndef ISO_TP_MAX_WFT_NUMBER
1299#define ISO_TP_MAX_WFT_NUMBER 1
1300#endif
1301
1302/* Private: The default timeout to use when waiting for a response during a
1303 * multi-frame send or receive.
1304 */
1305#ifndef ISO_TP_DEFAULT_RESPONSE_TIMEOUT_US
1306#define ISO_TP_DEFAULT_RESPONSE_TIMEOUT_US 100000
1307#endif
1308
1309/* Private: Determines if by default, padding is added to ISO-TP message frames.
1310 */
1311//#define ISO_TP_FRAME_PADDING
1312
1313/* Private: Value to use when padding frames if enabled by ISO_TP_FRAME_PADDING
1314 */
1315#ifndef ISO_TP_FRAME_PADDING_VALUE
1316#define ISO_TP_FRAME_PADDING_VALUE 0xAA
1317#endif
1318
1319/* Private: Determines if by default, an additional argument is present in the
1320 * definition of isotp_user_send_can.
1321 */
1322//#define ISO_TP_USER_SEND_CAN_ARG
1323
1324#endif // ISOTPC_CONFIG_H
1325
1326#ifndef ISOTPC_USER_DEFINITIONS_H
1327#define ISOTPC_USER_DEFINITIONS_H
1328
1329#include <stdint.h>
1330
1331/**************************************************************
1332 * compiler specific defines
1333 *************************************************************/
1334#ifdef __GNUC__
1335#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1336#define ISOTP_BYTE_ORDER_LITTLE_ENDIAN
1337#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
1338#else
1339#error "unsupported byte ordering"
1340#endif
1341#endif
1342
1343/**************************************************************
1344 * OS specific defines
1345 *************************************************************/
1346#ifdef _WIN32
1347#define snprintf _snprintf
1348#endif
1349
1350#ifdef _WIN32
1351#include <windows.h>
1352#define ISOTP_BYTE_ORDER_LITTLE_ENDIAN
1353#define __builtin_bswap8 _byteswap_uint8
1354#define __builtin_bswap16 _byteswap_uint16
1355#define __builtin_bswap32 _byteswap_uint32
1356#define __builtin_bswap64 _byteswap_uint64
1357#endif
1358
1359/**************************************************************
1360 * internal used defines
1361 *************************************************************/
1362#define ISOTP_RET_OK 0
1363#define ISOTP_RET_ERROR -1
1364#define ISOTP_RET_INPROGRESS -2
1365#define ISOTP_RET_OVERFLOW -3
1366#define ISOTP_RET_WRONG_SN -4
1367#define ISOTP_RET_NO_DATA -5
1368#define ISOTP_RET_TIMEOUT -6
1369#define ISOTP_RET_LENGTH -7
1370#define ISOTP_RET_NOSPACE -8
1371
1372/* return logic true if 'a' is after 'b' */
1373#define IsoTpTimeAfter(a,b) ((int32_t)((int32_t)(b) - (int32_t)(a)) < 0)
1374
1375/* invalid bs */
1376#define ISOTP_INVALID_BS 0xFFFF
1377
1378/* ISOTP sender status */
1379typedef enum {
1380 ISOTP_SEND_STATUS_IDLE,
1381 ISOTP_SEND_STATUS_INPROGRESS,
1382 ISOTP_SEND_STATUS_ERROR,
1383} IsoTpSendStatusTypes;
1384
1385/* ISOTP receiver status */
1386typedef enum {
1387 ISOTP_RECEIVE_STATUS_IDLE,
1388 ISOTP_RECEIVE_STATUS_INPROGRESS,
1389 ISOTP_RECEIVE_STATUS_FULL,
1390} IsoTpReceiveStatusTypes;
1391
1392/* can fram defination */
1393#if defined(ISOTP_BYTE_ORDER_LITTLE_ENDIAN)
1394typedef struct {
1395 uint8_t reserve_1:4;
1396 uint8_t type:4;
1397 uint8_t reserve_2[7];
1398} IsoTpPciType;
1399
1400typedef struct {
1401 uint8_t SF_DL:4;
1402 uint8_t type:4;
1403 uint8_t data[7];
1404} IsoTpSingleFrame;
1405
1406typedef struct {
1407 uint8_t FF_DL_high:4;
1408 uint8_t type:4;
1409 uint8_t FF_DL_low;
1410 uint8_t data[6];
1411} IsoTpFirstFrame;
1412
1413typedef struct {
1414 uint8_t SN:4;
1415 uint8_t type:4;
1416 uint8_t data[7];
1417} IsoTpConsecutiveFrame;
1418
1419typedef struct {
1420 uint8_t FS:4;
1421 uint8_t type:4;
1422 uint8_t BS;
1423 uint8_t STmin;
1424 uint8_t reserve[5];
1425} IsoTpFlowControl;
1426
1427#else
1428
1429typedef struct {
1430 uint8_t type:4;
1431 uint8_t reserve_1:4;
1432 uint8_t reserve_2[7];
1433} IsoTpPciType;
1434
1435/*
1436* single frame
1437* +-------------------------+-----+
1438* | byte #0 | ... |
1439* +-------------------------+-----+
1440* | nibble #0 | nibble #1 | ... |
1441* +-------------+-----------+ ... +
1442* | PCIType = 0 | SF_DL | ... |
1443* +-------------+-----------+-----+
1444*/
1445typedef struct {
1446 uint8_t type:4;
1447 uint8_t SF_DL:4;
1448 uint8_t data[7];
1449} IsoTpSingleFrame;
1450
1451/*
1452* first frame
1453* +-------------------------+-----------------------+-----+
1454* | byte #0 | byte #1 | ... |
1455* +-------------------------+-----------+-----------+-----+
1456* | nibble #0 | nibble #1 | nibble #2 | nibble #3 | ... |
1457* +-------------+-----------+-----------+-----------+-----+
1458* | PCIType = 1 | FF_DL | ... |
1459* +-------------+-----------+-----------------------+-----+
1460*/
1461typedef struct {
1462 uint8_t type:4;
1463 uint8_t FF_DL_high:4;
1464 uint8_t FF_DL_low;
1465 uint8_t data[6];
1466} IsoTpFirstFrame;
1467
1468/*
1469* consecutive frame
1470* +-------------------------+-----+
1471* | byte #0 | ... |
1472* +-------------------------+-----+
1473* | nibble #0 | nibble #1 | ... |
1474* +-------------+-----------+ ... +
1475* | PCIType = 0 | SN | ... |
1476* +-------------+-----------+-----+
1477*/
1478typedef struct {
1479 uint8_t type:4;
1480 uint8_t SN:4;
1481 uint8_t data[7];
1482} IsoTpConsecutiveFrame;
1483
1484/*
1485* flow control frame
1486* +-------------------------+-----------------------+-----------------------+-----+
1487* | byte #0 | byte #1 | byte #2 | ... |
1488* +-------------------------+-----------+-----------+-----------+-----------+-----+
1489* | nibble #0 | nibble #1 | nibble #2 | nibble #3 | nibble #4 | nibble #5 | ... |
1490* +-------------+-----------+-----------+-----------+-----------+-----------+-----+
1491* | PCIType = 1 | FS | BS | STmin | ... |
1492* +-------------+-----------+-----------------------+-----------------------+-----+
1493*/
1494typedef struct {
1495 uint8_t type:4;
1496 uint8_t FS:4;
1497 uint8_t BS;
1498 uint8_t STmin;
1499 uint8_t reserve[5];
1500} IsoTpFlowControl;
1501
1502#endif
1503
1504typedef struct {
1505 uint8_t ptr[8];
1506} IsoTpDataArray;
1507
1508typedef struct {
1509 union {
1510 IsoTpPciType common;
1511 IsoTpSingleFrame single_frame;
1512 IsoTpFirstFrame first_frame;
1513 IsoTpConsecutiveFrame consecutive_frame;
1514 IsoTpFlowControl flow_control;
1515 IsoTpDataArray data_array;
1516 } as;
1517} IsoTpCanMessage;
1518
1519/**************************************************************
1520 * protocol specific defines
1521 *************************************************************/
1522
1523/* Private: Protocol Control Information (PCI) types, for identifying each frame of an ISO-TP message.
1524 */
1525typedef enum {
1526 ISOTP_PCI_TYPE_SINGLE = 0x0,
1527 ISOTP_PCI_TYPE_FIRST_FRAME = 0x1,
1528 TSOTP_PCI_TYPE_CONSECUTIVE_FRAME = 0x2,
1529 ISOTP_PCI_TYPE_FLOW_CONTROL_FRAME = 0x3
1530} IsoTpProtocolControlInformation;
1531
1532/* Private: Protocol Control Information (PCI) flow control identifiers.
1533 */
1534typedef enum {
1535 PCI_FLOW_STATUS_CONTINUE = 0x0,
1536 PCI_FLOW_STATUS_WAIT = 0x1,
1537 PCI_FLOW_STATUS_OVERFLOW = 0x2
1538} IsoTpFlowStatus;
1539
1540/* Private: network layer resault code.
1541 */
1542#define ISOTP_PROTOCOL_RESULT_OK 0
1543#define ISOTP_PROTOCOL_RESULT_TIMEOUT_A -1
1544#define ISOTP_PROTOCOL_RESULT_TIMEOUT_BS -2
1545#define ISOTP_PROTOCOL_RESULT_TIMEOUT_CR -3
1546#define ISOTP_PROTOCOL_RESULT_WRONG_SN -4
1547#define ISOTP_PROTOCOL_RESULT_INVALID_FS -5
1548#define ISOTP_PROTOCOL_RESULT_UNEXP_PDU -6
1549#define ISOTP_PROTOCOL_RESULT_WFT_OVRN -7
1550#define ISOTP_PROTOCOL_RESULT_BUFFER_OVFLW -8
1551#define ISOTP_PROTOCOL_RESULT_ERROR -9
1552
1553#endif // ISOTPC_USER_DEFINITIONS_H
1554#ifndef ISOTPC_USER_H
1555#define ISOTPC_USER_H
1556
1557#include <stdint.h>
1558
1559#ifdef __cplusplus
1560extern "C" {
1561#endif
1562
1563/** @brief user implemented, print debug message */
1564void isotp_user_debug(const char* message, ...);
1565
1566/**
1567 * @brief user implemented, send can message. should return ISOTP_RET_OK when success.
1568 *
1569 * @return may return ISOTP_RET_NOSPACE if the CAN transfer should be retried later
1570 * or ISOTP_RET_ERROR if transmission couldn't be completed
1571 */
1572int isotp_user_send_can(const uint32_t arbitration_id,
1573 const uint8_t* data, const uint8_t size
1574#if ISO_TP_USER_SEND_CAN_ARG
1575,void *arg
1576#endif
1577 );
1578
1579/**
1580 * @brief user implemented, gets the amount of time passed since the last call in microseconds
1581 */
1582uint32_t isotp_user_get_us(void);
1583
1584#ifdef __cplusplus
1585}
1586#endif
1587
1588#endif // ISOTPC_USER_H
1589
1590
1591#ifndef ISOTPC_H
1592#define ISOTPC_H
1593
1594#include <stdio.h>
1595#include <string.h>
1596
1597#ifdef __cplusplus
1598#include <stdint.h>
1599
1600extern "C" {
1601#endif
1602
1603
1604/**
1605 * @brief Struct containing the data for linking an application to a CAN instance.
1606 * The data stored in this struct is used internally and may be used by software programs
1607 * using this library.
1608 */
1609typedef struct IsoTpLink {
1610 /* sender paramters */
1611 uint32_t send_arbitration_id; /* used to reply consecutive frame */
1612 /* message buffer */
1613 uint8_t* send_buffer;
1614 uint16_t send_buf_size;
1615 uint16_t send_size;
1616 uint16_t send_offset;
1617 /* multi-frame flags */
1618 uint8_t send_sn;
1619 uint16_t send_bs_remain; /* Remaining block size */
1620 uint32_t send_st_min_us; /* Separation Time between consecutive frames */
1621 uint8_t send_wtf_count; /* Maximum number of FC.Wait frame transmissions */
1622 uint32_t send_timer_st; /* Last time send consecutive frame */
1623 uint32_t send_timer_bs; /* Time until reception of the next FlowControl N_PDU
1624 start at sending FF, CF, receive FC
1625 end at receive FC */
1626 int send_protocol_result;
1627 uint8_t send_status;
1628 /* receiver paramters */
1629 uint32_t receive_arbitration_id;
1630 /* message buffer */
1631 uint8_t* receive_buffer;
1632 uint16_t receive_buf_size;
1633 uint16_t receive_size;
1634 uint16_t receive_offset;
1635 /* multi-frame control */
1636 uint8_t receive_sn;
1637 uint8_t receive_bs_count; /* Maximum number of FC.Wait frame transmissions */
1638 uint32_t receive_timer_cr; /* Time until transmission of the next ConsecutiveFrame N_PDU
1639 start at sending FC, receive CF
1640 end at receive FC */
1641 int receive_protocol_result;
1642 uint8_t receive_status;
1643
1644#if defined(ISO_TP_USER_SEND_CAN_ARG)
1645 void* user_send_can_arg;
1646#endif
1647} IsoTpLink;
1648
1649/**
1650 * @brief Initialises the ISO-TP library.
1651 *
1652 * @param link The @code IsoTpLink @endcode instance used for transceiving data.
1653 * @param sendid The ID used to send data to other CAN nodes.
1654 * @param sendbuf A pointer to an area in memory which can be used as a buffer for data to be sent.
1655 * @param sendbufsize The size of the buffer area.
1656 * @param recvbuf A pointer to an area in memory which can be used as a buffer for data to be received.
1657 * @param recvbufsize The size of the buffer area.
1658 */
1659void isotp_init_link(IsoTpLink *link, uint32_t sendid,
1660 uint8_t *sendbuf, uint16_t sendbufsize,
1661 uint8_t *recvbuf, uint16_t recvbufsize);
1662
1663/**
1664 * @brief Polling function; call this function periodically to handle timeouts, send consecutive frames, etc.
1665 *
1666 * @param link The @code IsoTpLink @endcode instance used.
1667 */
1668void isotp_poll(IsoTpLink *link);
1669
1670/**
1671 * @brief Handles incoming CAN messages.
1672 * Determines whether an incoming message is a valid ISO-TP frame or not and handles it accordingly.
1673 *
1674 * @param link The @code IsoTpLink @endcode instance used for transceiving data.
1675 * @param data The data received via CAN.
1676 * @param len The length of the data received.
1677 */
1678void isotp_on_can_message(IsoTpLink *link, const uint8_t *data, uint8_t len);
1679
1680/**
1681 * @brief Sends ISO-TP frames via CAN, using the ID set in the initialising function.
1682 *
1683 * Single-frame messages will be sent immediately when calling this function.
1684 * Multi-frame messages will be sent consecutively when calling isotp_poll.
1685 *
1686 * @param link The @code IsoTpLink @endcode instance used for transceiving data.
1687 * @param payload The payload to be sent. (Up to 4095 bytes).
1688 * @param size The size of the payload to be sent.
1689 *
1690 * @return Possible return values:
1691 * - @code ISOTP_RET_OVERFLOW @endcode
1692 * - @code ISOTP_RET_INPROGRESS @endcode
1693 * - @code ISOTP_RET_OK @endcode
1694 * - The return value of the user shim function isotp_user_send_can().
1695 */
1696int isotp_send(IsoTpLink *link, const uint8_t payload[], uint16_t size);
1697
1698/**
1699 * @brief See @link isotp_send @endlink, with the exception that this function is used only for functional addressing.
1700 */
1701int isotp_send_with_id(IsoTpLink *link, uint32_t id, const uint8_t payload[], uint16_t size);
1702
1703/**
1704 * @brief Receives and parses the received data and copies the parsed data in to the internal buffer.
1705 * @param link The @link IsoTpLink @endlink instance used to transceive data.
1706 * @param payload A pointer to an area in memory where the raw data is copied from.
1707 * @param payload_size The size of the received (raw) CAN data.
1708 * @param out_size A reference to a variable which will contain the size of the actual (parsed) data.
1709 *
1710 * @return Possible return values:
1711 * - @link ISOTP_RET_OK @endlink
1712 * - @link ISOTP_RET_NO_DATA @endlink
1713 */
1714int isotp_receive(IsoTpLink *link, uint8_t *payload, const uint16_t payload_size, uint16_t *out_size);
1715
1716#ifdef __cplusplus
1717}
1718#endif
1719
1720#endif // ISOTPC_H
1721
1722
1723/// \endcond
1724#endif // if defined(UDS_TP_ISOTP_C)
1725
1726#if defined(UDS_TP_ISOTP_C)
1727
1728
1729/**
1730 * @brief isotp-c implementation of \ref UDSTp_t
1731 */
1732typedef struct {
1733 /// \cond DOXYGEN_SHOULD_SKIP_THIS
1734 UDSTp_t hdl;
1735 IsoTpLink phys_link;
1736 IsoTpLink func_link;
1737 uint8_t send_buf[UDS_ISOTP_MTU];
1738 uint8_t recv_buf[UDS_ISOTP_MTU];
1739 uint8_t func_send_buf[8];
1740 uint8_t func_recv_buf[8];
1741 uint32_t phys_sa, phys_ta;
1742 uint32_t func_sa, func_ta;
1743 /// \endcond
1745
1746/**
1747 * @brief Initialize isotp-c transport for \ref UDSServer_t
1748 * @param tp \ref UDSTpISOTpC_t instance.
1749 * @param source_addr Server listens for physical transmissions on this address.
1750 * @param target_addr Server sends responses to this address.
1751 * @param source_addr_func Server listens for functional transmissions on this address.
1752 */
1753UDSErr_t UDSServerTpISOTpCInit(UDSTpISOTpC_t *tp, uint32_t source_addr, uint32_t target_addr,
1754 uint32_t source_addr_func);
1755
1756/**
1757 * @brief Initialize isotp-c transport for \ref UDSClient_t
1758 * @param tp \ref UDSTpISOTpC_t instance.
1759 * @param target_addr Client sends physical requests to this address.
1760 * @param source_addr Client listens for responses at this address.
1761 * @param target_addr_func Client sends functional transmissions to this address.
1762 */
1763UDSErr_t UDSClientTpISOTpCInit(UDSTpISOTpC_t *tp, uint32_t target_addr, uint32_t source_addr,
1764 uint32_t target_addr_func);
1765
1766#endif
1767
1768
1769
1770#if defined(UDS_TP_ISOTP_C_SOCKETCAN)
1771
1772
1773/**
1774 * @brief isotp-c over SocketCAN implementation of \ref UDSTp_t
1775 */
1776typedef struct {
1777 /// \cond DOXYGEN_SHOULD_SKIP_THIS
1778 UDSTp_t hdl;
1779 IsoTpLink phys_link;
1780 IsoTpLink func_link;
1781 uint8_t send_buf[UDS_ISOTP_MTU];
1782 uint8_t recv_buf[UDS_ISOTP_MTU];
1783 int fd;
1784 uint32_t phys_sa, phys_ta;
1785 uint32_t func_sa, func_ta;
1786 char tag[16];
1787 /// \endcond
1789
1790/**
1791 * @brief Initialize the transport
1792 * @param tp transport
1793 * @param ifname can0, vcan0
1794 * @param source_addr
1795 * @param target_addr
1796 * @param source_addr_func
1797 * @param target_addr_func
1798 */
1800 uint32_t source_addr, uint32_t target_addr,
1801 uint32_t source_addr_func, uint32_t target_addr_func);
1802void UDSTpISOTpCSocketCANDeinit(UDSTpISOTpCSocketCAN_t *tp); ///< release socket
1803
1804#endif
1805
1806
1807#if defined(UDS_TP_ISOTP_SOCK)
1808
1809
1810/**
1811 * @brief linux ISO-TP socket implementation of \ref UDSTp_t
1812 */
1813typedef struct {
1814 /// \cond DOXYGEN_SHOULD_SKIP_THIS
1815 UDSTp_t hdl;
1816 uint8_t recv_buf[UDS_ISOTP_MTU];
1817 uint8_t send_buf[UDS_ISOTP_MTU];
1818 size_t recv_len;
1819 UDSSDU_t recv_info;
1820 int phys_fd;
1821 int func_fd;
1822 uint32_t phys_sa, phys_ta;
1823 uint32_t func_sa, func_ta;
1824 char tag[16];
1825 /// \endcond
1827
1828UDSErr_t UDSServerTpIsoTpSockInit(UDSTpIsoTpSock_t *tp, const char *ifname, uint32_t source_addr,
1829 uint32_t target_addr,
1830 uint32_t source_addr_func); ///< for UDSServer_t
1831UDSErr_t UDSClientTpIsoTpSockInit(UDSTpIsoTpSock_t *tp, const char *ifname, uint32_t source_addr,
1832 uint32_t target_addr,
1833 uint32_t target_addr_func); ///< for UDSClient_t
1834void UDSTpIsoTpSockDeinit(UDSTpIsoTpSock_t *tp); ///< release sockets
1835
1836#endif
1837
1838
1839#if defined(UDS_TP_ISOTP_MOCK)
1840
1841
1842/// \cond INTERNAL_INTERFACE
1843
1844
1845typedef struct ISOTPMock {
1846 UDSTp_t hdl;
1847 uint8_t recv_buf[UDS_TP_MTU];
1848 uint8_t send_buf[UDS_TP_MTU];
1849 size_t recv_len;
1850 UDSSDU_t recv_info;
1851 uint32_t sa_phys; // source address - physical messages are sent from this address
1852 uint32_t ta_phys; // target address - physical messages are sent to this address
1853 uint32_t sa_func; // source address - functional messages are sent from this address
1854 uint32_t ta_func; // target address - functional messages are sent to this address
1855 uint32_t send_tx_delay_ms; // simulated delay
1856 uint32_t send_buf_size; // simulated size of the send buffer
1857 char name[32]; // name for logging
1858} ISOTPMock_t;
1859
1860typedef struct {
1861 uint32_t sa_phys; // source address - physical messages are sent from this address
1862 uint32_t ta_phys; // target address - physical messages are sent to this address
1863 uint32_t sa_func; // source address - functional messages are sent from this address
1864 uint32_t ta_func; // target address - functional messages are sent to this address
1865} ISOTPMockArgs_t;
1866
1867/**
1868 * @brief Create a mock transport. It is connected by default to a broadcast network of all other
1869 * mock transports in the same process.
1870 * @param name optional name of the transport (can be NULL)
1871 * @return UDSTp_t*
1872 */
1873UDSTp_t *ISOTPMockNew(const char *name, ISOTPMockArgs_t *args);
1874void ISOTPMockFree(UDSTp_t *tp);
1875
1876/**
1877 * @brief write all messages to a file
1878 * @note uses UDSMillis() to get the current time
1879 * @param filename log file name (will be overwritten)
1880 */
1881void ISOTPMockLogToFile(const char *filename);
1882void ISOTPMockLogToStdout(void);
1883
1884/**
1885 * @brief clear all transports and close the log file
1886 */
1887void ISOTPMockReset(void);
1888
1889/// \endcond INTERNAL_INTERFACE
1890
1891#endif
1892
1893
1894#ifdef __cplusplus
1895}
1896#endif
1897
1898#endif
#define UDS_LOG_VERBOSE
Definition iso14229.h:667
#define UDS_LOG_DEBUG
Definition iso14229.h:666
#define UDS_LOG_NONE
Definition iso14229.h:662
#define UDS_LOG_WARN
Definition iso14229.h:664
#define UDS_LOG_ERROR
Definition iso14229.h:663
#define UDS_LOG_INFO
Definition iso14229.h:665
#define UDS_CLIENT_DEFAULT_P2_MS
default P2 timeout
Definition iso14229.h:138
UDSErr_t UDSSendECUReset(UDSClient_t *client, uint8_t type)
Request ECUReset.
Definition iso14229.c:357
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.
Definition iso14229.c:3131
void UDSServerPoll(UDSServer_t *srv)
Call this at <5ms intervals.
Definition iso14229.c:2575
#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.
Definition iso14229.h:129
UDS_A_Mtype_t
Definition iso14229.h:215
UDSEvent_t
UDS events.
Definition iso14229.h:303
@ UDS_EVT_Custom
Definition iso14229.h:329
@ UDS_EVT_RequestFileTransfer
Definition iso14229.h:326
@ UDS_EVT_ReadDTCInformation
Definition iso14229.h:309
@ UDS_EVT_ClearDiagnosticInfo
Definition iso14229.h:308
@ UDS_EVT_DiagSessCtrl
Definition iso14229.h:306
@ UDS_EVT_DynamicDefineDataId
Definition iso14229.h:317
@ UDS_EVT_SecAccessRequestSeed
Definition iso14229.h:313
@ UDS_EVT_SessionTimeout
Definition iso14229.h:324
@ UDS_EVT_WriteMemByAddr
Definition iso14229.h:316
@ UDS_EVT_SecAccessValidateKey
Definition iso14229.h:314
@ UDS_EVT_TransferData
Definition iso14229.h:322
@ UDS_EVT_RequestDownload
Definition iso14229.h:320
@ UDS_EVT_RoutineCtrl
Definition iso14229.h:319
@ UDS_EVT_Poll
Definition iso14229.h:331
@ UDS_EVT_WriteDataByIdent
Definition iso14229.h:315
@ UDS_EVT_RequestTransferExit
Definition iso14229.h:323
@ UDS_EVT_ReadMemByAddr
Definition iso14229.h:311
@ UDS_EVT_CommCtrl
Definition iso14229.h:312
@ UDS_EVT_ResponseReceived
Definition iso14229.h:333
@ UDS_EVT_SendComplete
Definition iso14229.h:332
@ UDS_EVT_Idle
Definition iso14229.h:334
@ UDS_EVT_RequestUpload
Definition iso14229.h:321
@ UDS_EVT_LinkControl
Definition iso14229.h:328
@ UDS_EVT_ControlDTCSetting
Definition iso14229.h:327
@ UDS_EVT_IOControl
Definition iso14229.h:318
@ UDS_EVT_EcuReset
Definition iso14229.h:307
@ UDS_EVT_DoScheduledReset
Definition iso14229.h:325
@ UDS_EVT_Err
Definition iso14229.h:304
@ UDS_EVT_MAX
Definition iso14229.h:336
@ UDS_EVT_ReadDataByIdent
Definition iso14229.h:310
UDSErr_t UDSSendTesterPresent(UDSClient_t *client)
What's up?
Definition iso14229.c:391
UDS_A_TA_Type_t
Definition iso14229.h:224
#define UDS_SERVER_DEFAULT_P2_MS
default P2 duration
Definition iso14229.h:148
UDSErr_t UDSSendRequestFileTransfer(UDSClient_t *client, uint8_t mode, const char *filePath, size_t fileSizeUncompressed, size_t fileSizeCompressed)
filesystem-based frontend to TransferData
Definition iso14229.c:637
#define UDS_CLIENT_DEFAULT_P2_STAR_MS
default P2* timeout
Definition iso14229.h:142
UDSErr_t UDSSendRequestTransferExit(UDSClient_t *client)
Call this when finished with TransferData.
Definition iso14229.c:627
UDSTpStatus_t UDSTpPoll(UDSTp_t *hdl)
call this at <5ms intervals
Definition iso14229.c:2674
UDSErr_t UDSSendRequestDownload(UDSClient_t *client, uint8_t dataFormatIdentifier, uint8_t addressAndLengthFormatIdentifier, size_t memoryAddress, size_t memorySize)
Request to Download via TransferData.
Definition iso14229.c:494
#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.
Definition iso14229.h:119
void UDSTpIsoTpSockDeinit(UDSTpIsoTpSock_t *tp)
release sockets
Definition iso14229.c:3642
#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.
Definition iso14229.h:134
UDSErr_t UDSUnpackSecurityAccessResponse(const UDSClient_t *client, struct SecurityAccessResponse *resp)
Parse server's response to SecurityAccess.
Definition iso14229.c:843
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.
Definition iso14229.c:575
int UDS_LogLevel_t
one of valid values for UDS_LOG_LEVEL
Definition iso14229.h:670
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
Definition iso14229.c:3589
UDSErr_t UDSSendWDBI(UDSClient_t *client, uint16_t dataIdentifier, const uint8_t *data, uint16_t size)
Write Data By Identifier.
Definition iso14229.c:425
UDSTpSize_t UDSTpRecv(UDSTp_t *hdl, uint8_t *buf, size_t bufsize, UDSSDU_t *info)
Receive from transport.
Definition iso14229.c:2668
uint32_t UDSTpStatus_t
private: bitfield of UDSTpStatusFlags
Definition iso14229.h:211
UDSTpStatusFlags
Definition iso14229.h:204
UDSErr_t UDSSendCommCtrl(UDSClient_t *client, uint8_t ctrl, uint8_t comm)
Change communication settings.
Definition iso14229.c:379
#define UDS_TP_MTU
ISOTP is the only supported tp type, so UDS inherits its MTU.
Definition iso14229.h:110
UDSErr_t UDSSendSecurityAccess(UDSClient_t *client, uint8_t level, uint8_t *data, uint16_t size)
Get Security Access.
Definition iso14229.c:805
UDSErr_t UDSSendRequestUpload(UDSClient_t *client, uint8_t dataFormatIdentifier, uint8_t addressAndLengthFormatIdentifier, size_t memoryAddress, size_t memorySize)
Request to Upload via TransferData.
Definition iso14229.c:535
uint32_t UDSMillis(void)
Get time in milliseconds.
UDSErr_t UDSCtrlDTCSetting(UDSClient_t *client, uint8_t dtcSettingType, uint8_t *dtcSettingControlOptionRecord, uint16_t len)
control DTC setting
Definition iso14229.c:762
UDSErr_t UDSUnpackRDBIResponse(UDSClient_t *client, UDSRDBIVar_t *vars, uint16_t numVars)
Parse server's response to RDBI.
Definition iso14229.c:940
#define UDS_SERVER_DEFAULT_S3_MS
default S3 duration (ISO14229-2 2013 Table 5: 5000 -0/+200 ms)
Definition iso14229.h:156
UDSErr_t UDSUnpackRoutineControlResponse(const UDSClient_t *client, struct RoutineControlResponse *resp)
Parse server's response to RoutineControl.
Definition iso14229.c:868
#define UDS_SERVER_DEFAULT_P2_STAR_MS
default P2* duration
Definition iso14229.h:152
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
Definition iso14229.c:3616
#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.
Definition iso14229.h:124
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.
Definition iso14229.c:3136
UDSErr_t UDSSendRoutineCtrl(UDSClient_t *client, uint8_t type, uint16_t routineIdentifier, const uint8_t *data, uint16_t size)
Request to Twiddle Routines.
Definition iso14229.c:456
uint8_t UDSTpAddr_t
private: oneof UDS_A_TA_Type_t
Definition iso14229.h:229
UDSErr_t
Error Codes, including NRCs defined by the standard.
Definition iso14229.h:343
void UDSTpISOTpCSocketCANDeinit(UDSTpISOTpCSocketCAN_t *tp)
release socket
Definition iso14229.c:3366
UDSErr_t UDSSendTransferDataStream(UDSClient_t *client, uint8_t blockSequenceCounter, const uint16_t blockLength, FILE *fd)
Transfer Data to/from a file.
Definition iso14229.c:599
#define UDS_ISOTP_MTU
ISO-TP Maximum Transmission Unit (ISO-15764-2-2004 section 5.3.3).
Definition iso14229.h:106
UDSErr_t UDSUnpackRequestDownloadResponse(const UDSClient_t *client, struct RequestDownloadResponse *resp)
Parse server's response to RequestDownload.
Definition iso14229.c:896
int32_t UDSTpSize_t
Signed size type used by the transport layer interface (byte count, or negative on error).
Definition iso14229.h:249
UDSErr_t UDSClientInit(UDSClient_t *client)
Call this once.
Definition iso14229.c:55
#define UDS_LOG_LEVEL
sets the logging level
Definition iso14229.h:678
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.
Definition iso14229.c:3341
UDSErr_t UDSSendDiagSessCtrl(UDSClient_t *client, uint8_t mode)
Change the diagnostic session.
Definition iso14229.c:368
UDSErr_t UDSClientPoll(UDSClient_t *client)
Call at <5ms intervals.
Definition iso14229.c:922
UDSErr_t UDSSendBytes(UDSClient_t *client, const uint8_t *data, uint16_t size)
Send user-defined bytes to a UDS server.
Definition iso14229.c:344
UDSTpSize_t UDSTpSend(UDSTp_t *hdl, const uint8_t *buf, UDSTpSize_t len, const UDSSDU_t *info)
Send to transport.
Definition iso14229.c:2662
UDSErr_t UDSServerInit(UDSServer_t *srv)
call this once
Definition iso14229.c:2558
UDSErr_t UDSSendRDBI(UDSClient_t *client, const uint16_t *didList, const uint16_t numDataIdentifiers)
Read Data By Identifier.
Definition iso14229.c:402
Request download response structure.
Definition iso14229.h:826
Routine control response structure.
Definition iso14229.h:833
const uint8_t * routineStatusRecord
Definition iso14229.h:836
uint16_t routineIdentifier
Definition iso14229.h:835
uint16_t routineStatusRecordLength
Definition iso14229.h:837
Security access response structure.
Definition iso14229.h:817
uint16_t securitySeedLength
Definition iso14229.h:820
const uint8_t * securitySeed
Definition iso14229.h:819
Clear diagnostic information arguments.
Definition iso14229.h:993
const uint8_t memorySelection
Definition iso14229.h:996
const uint32_t groupOfDTC
Definition iso14229.h:994
const bool hasMemorySelection
Definition iso14229.h:995
UDS client structure.
Definition iso14229.h:791
uint8_t cfg_file_size_parameter_length
Definition iso14229.h:803
uint8_t cfg_data_format_identifier
Definition iso14229.h:802
uint16_t p2_ms
Definition iso14229.h:792
int(*) fn(struct UDSClient *client, UDSEvent_t evt, void *ev_data)
Definition iso14229.h:805
uint8_t defaultOptions
Definition iso14229.h:800
uint32_t p2_timer
Definition iso14229.h:796
uint8_t send_buf[UDS_CLIENT_SEND_BUF_SIZE]
Definition iso14229.h:811
uint8_t state
Definition iso14229.h:797
uint16_t send_size
Definition iso14229.h:809
uint32_t p2_star_ms
Definition iso14229.h:793
uint8_t _options_copy
Definition iso14229.h:801
uint8_t recv_buf[UDS_CLIENT_RECV_BUF_SIZE]
Definition iso14229.h:810
uint8_t options
Definition iso14229.h:799
void * fn_data
Definition iso14229.h:806
uint16_t recv_size
Definition iso14229.h:808
UDSTp_t * tp
Definition iso14229.h:794
Communication control arguments.
Definition iso14229.h:1078
Control DTC setting arguments.
Definition iso14229.h:1242
Custom service arguments.
Definition iso14229.h:1262
uint8_t(*) copyResponse(UDSServer_t *srv, const void *src, uint16_t len)
Definition iso14229.h:1266
const uint8_t * optionRecord
Definition iso14229.h:1264
const uint16_t sid
Definition iso14229.h:1263
const uint16_t len
Definition iso14229.h:1265
Dynamically define data identifier arguments.
Definition iso14229.h:1125
const uint8_t type
Definition iso14229.h:1126
uint16_t dynamicDataId
Definition iso14229.h:1129
Diagnostic session control arguments.
Definition iso14229.h:975
const uint8_t type
Definition iso14229.h:976
ECU reset arguments.
Definition iso14229.h:984
uint32_t powerDownTimeMillis
Definition iso14229.h:986
const uint8_t type
Definition iso14229.h:985
Input/output control by identifier arguments.
Definition iso14229.h:1147
const uint8_t ioCtrlParam
Definition iso14229.h:1149
const size_t ctrlStateAndMaskLen
Definition iso14229.h:1151
uint8_t(*) copy(UDSServer_t *srv, const void *src, uint16_t count)
Definition iso14229.h:1152
const void *const ctrlStateAndMask
Definition iso14229.h:1150
const uint16_t dataId
Definition iso14229.h:1148
Link control arguments.
Definition iso14229.h:1251
const void * data
Definition iso14229.h:1255
const size_t len
Definition iso14229.h:1254
const uint8_t type
Definition iso14229.h:1252
Read data by identifier arguments.
Definition iso14229.h:1059
const uint16_t dataId
Definition iso14229.h:1060
uint8_t(*) copy(UDSServer_t *srv, const void *src, uint16_t count)
Definition iso14229.h:1061
Read data by identifier variable structure.
Definition iso14229.h:843
uint16_t len
Definition iso14229.h:845
uint16_t did
Definition iso14229.h:844
void * data
Definition iso14229.h:846
Read DTC information arguments.
Definition iso14229.h:1002
uint8_t(*) copy(UDSServer_t *srv, const void *src, uint16_t count)
Definition iso14229.h:1004
const uint8_t type
Definition iso14229.h:1003
Read memory by address arguments.
Definition iso14229.h:1068
const void * memAddr
Definition iso14229.h:1069
uint8_t(*) copy(UDSServer_t *srv, const void *src, uint16_t count)
Definition iso14229.h:1071
const size_t memSize
Definition iso14229.h:1070
Server request context.
Definition iso14229.h:908
uint8_t send_buf[UDS_SERVER_SEND_BUF_SIZE]
Definition iso14229.h:910
size_t send_len
Definition iso14229.h:912
uint8_t recv_buf[UDS_SERVER_RECV_BUF_SIZE]
Definition iso14229.h:909
size_t recv_len
Definition iso14229.h:911
UDSSDU_t info
Definition iso14229.h:914
size_t send_buf_size
Definition iso14229.h:913
Request download arguments.
Definition iso14229.h:1171
const uint8_t dataFormatIdentifier
Definition iso14229.h:1174
uint16_t maxNumberOfBlockLength
Definition iso14229.h:1175
Request file transfer arguments.
Definition iso14229.h:1215
const uint8_t modeOfOperation
Definition iso14229.h:1220
const uint8_t dataFormatIdentifier
Definition iso14229.h:1223
Request transfer exit arguments.
Definition iso14229.h:1205
uint8_t(*) copyResponse(UDSServer_t *srv, const void *src, uint16_t len)
Definition iso14229.h:1208
const uint8_t *const data
Definition iso14229.h:1206
Request upload arguments.
Definition iso14229.h:1182
uint16_t maxNumberOfBlockLength
Definition iso14229.h:1186
const uint8_t dataFormatIdentifier
Definition iso14229.h:1185
Routine control arguments.
Definition iso14229.h:1159
const uint8_t * optionRecord
Definition iso14229.h:1162
const uint16_t id
Definition iso14229.h:1161
const uint16_t len
Definition iso14229.h:1163
const uint8_t ctrlType
Definition iso14229.h:1160
uint8_t(*) copyStatusRecord(UDSServer_t *srv, const void *src, uint16_t len)
Definition iso14229.h:1164
Service data unit (SDU).
Definition iso14229.h:236
uint32_t A_SA
Definition iso14229.h:239
uint32_t A_TA
Definition iso14229.h:240
uint32_t A_AE
Definition iso14229.h:242
UDS_A_Mtype_t A_Mtype
Definition iso14229.h:237
UDS_A_TA_Type_t A_TA_Type
Definition iso14229.h:241
Security access request seed arguments.
Definition iso14229.h:1087
const uint8_t *const dataRecord
Definition iso14229.h:1089
uint8_t(*) copySeed(UDSServer_t *srv, const void *src, uint16_t len)
Definition iso14229.h:1091
Security access validate key arguments.
Definition iso14229.h:1098
const uint8_t *const key
Definition iso14229.h:1100
UDS server structure.
Definition iso14229.h:920
size_t xferTotalBytes
Definition iso14229.h:948
uint32_t sec_access_auth_fail_timer
Definition iso14229.h:936
uint16_t p2_ms
Server time constants (milliseconds).
Definition iso14229.h:928
uint32_t p2_star_ms
Definition iso14229.h:929
bool notReadyToReceive
UDS-1 2013 defines the following conditions under which the server does not process incoming requests...
Definition iso14229.h:967
uint8_t securityLevel
Definition iso14229.h:953
uint32_t sec_access_boot_delay_timer
Definition iso14229.h:937
uint16_t s3_ms
Definition iso14229.h:930
UDSReq_t r
Definition iso14229.h:969
void * fn_data
Definition iso14229.h:923
UDSTp_t * tp
Definition iso14229.h:921
size_t xferBlockLength
Definition iso14229.h:950
UDSErr_t(*) fn(struct UDSServer *srv, UDSEvent_t event, void *arg)
Definition iso14229.h:922
uint32_t s3_session_timeout_timer
Definition iso14229.h:935
size_t xferByteCounter
Definition iso14229.h:949
uint8_t ecuResetScheduled
Definition iso14229.h:932
uint8_t xferBlockSequenceCounter
Definition iso14229.h:946
uint32_t p2_timer
Definition iso14229.h:934
uint8_t sessionType
Definition iso14229.h:952
bool xferIsActive
UDS-1-2013: Table 407 - 0x36 TransferData Supported negative response codes requires that the server ...
Definition iso14229.h:945
bool requestInProgress
Definition iso14229.h:956
uint32_t ecuResetTimer
Definition iso14229.h:933
isotp-c over SocketCAN implementation of UDSTp_t
Definition iso14229.h:1776
isotp-c implementation of UDSTp_t
Definition iso14229.h:1732
linux ISO-TP socket implementation of UDSTp_t
Definition iso14229.h:1813
UDS Transport layer.
Definition iso14229.h:255
UDSTpStatus_t(*) poll(struct UDSTp *hdl)
Poll the transport layer.
Definition iso14229.h:283
UDSTpSize_t(*) recv(struct UDSTp *hdl, uint8_t *buf, size_t bufsize, UDSSDU_t *info)
Receive data from the transport.
Definition iso14229.h:274
UDSTpSize_t(*) send(struct UDSTp *hdl, const uint8_t *buf, size_t len, const UDSSDU_t *info)
Send data to the transport.
Definition iso14229.h:264
Transfer data arguments.
Definition iso14229.h:1193
const uint16_t len
Definition iso14229.h:1195
uint8_t(*) copyResponse(UDSServer_t *srv, const void *src, uint16_t len)
Definition iso14229.h:1197
const uint8_t *const data
Definition iso14229.h:1194
const uint16_t maxRespLen
Definition iso14229.h:1196
Write data by identifier arguments.
Definition iso14229.h:1107
const uint16_t len
Definition iso14229.h:1110
const uint16_t dataId
Definition iso14229.h:1108
const uint8_t *const data
Definition iso14229.h:1109
Write memory by address arguments.
Definition iso14229.h:1116
const uint8_t *const data
Definition iso14229.h:1119
struct UDSDDDIArgs_t::@166357164257276222002146302270155120176057041273::@030077060352005266364046135253225021030163312237 defineById
struct UDSDDDIArgs_t::@166357164257276222002146302270155120176057041273::@122167075350102041255165217274110033054226235151 defineByMemAddress
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@154001327012172334201146116375304045171105172314 dtcExtDataRecordIdArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@316272062351030324211305365217344343316022275306 severityInfoOfDTCArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@257326070054040214361234214245165251024355111071 dtcExtDtaRecordByDTCNumArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@047012174113202206257152072274143133322231236121 numOfDTCBySeverityMaskArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@242172112264143020077310143126066111376236317004 dtcStatusByMaskArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@355231136245007054075200356211041150371252334044 userDefMemDTCSnapshotRecordByDTCNumArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@227353312111251376072016263157011107071271365150 dtcInfoByDTCReadinessGroupIdArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@047012174113202206257152072274143133322231236121 dtcBySeverityMaskArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@257326070054040214361234214245165251024355111071 userDefMemDTCExtDataRecordByDTCNumArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@355231136245007054075200356211041150371252334044 dtcSnapshotRecordbyDTCNumArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@154001327012172334201146116375304045171105172314 dtcStoredDataByRecordNumArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@047012174113202206257152072274143133322231236121 wwhobdDTCByMaskArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@251214024221351216066340166017235251143034105333 userDefMemoryDTCByStatusMaskArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@154001327012172334201146116375304045171105172314 dtcExtDataRecordByRecordNumArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@227353312111251376072016263157011107071271365150 wwhobdDTCWithPermStatusArgs
struct UDSRDTCIArgs_t::@362145371326305243133264240062265164011177277257::@242172112264143020077310143126066111376236317004 numOfDTCByStatusMaskArgs