Skip to content

Commit b6877d3

Browse files
committed
Added optional padding for ISO TP answers
1 parent d0bf328 commit b6877d3

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

firmware/RAMNV1/Core/Inc/ramn_config.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,15 @@
320320
// Maximum Security access attempts before locking device.
321321
#define SECURITY_ACCESS_MAX_ATTEMPTS 5
322322

323-
// Enable this flag to ignore ISO TP messages that are not padded (like real ECUs).
323+
// Enable this flag to ignore ISO TP messages that are not padded (like real ECUs do).
324+
// When this flag is enabled, the ECU only checks that ISO-TP CAN message size is 8, it does not check the value of the padding bytes.
325+
// This only applies to requests - see flag below for answers.
324326
// #define ISOTP_REQUIRE_PADDING
325327

328+
// Define this flag to make the ECU pad its ISO-TP answers with the defined byte (until ISO-TP CAN messages reach a size of 8).
329+
// This only applies to answers - see flag above for requests.
330+
// #define ISOTP_ANSWER_PADDING_BYTE 0x00
331+
326332
#ifdef ENABLE_CDC
327333
#define APP_RX_DATA_SIZE 2048
328334
#define APP_TX_DATA_SIZE 2048

firmware/RAMNV1/Core/Src/ramn_isotp.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void RAMN_ISOTP_ProcessRxMsg(RAMN_ISOTPHandler_t* handler, uint8_t dlc, const ui
251251
if (handler->rxMustSendCF == True)
252252
{
253253
uint8_t dlc;
254-
uint8_t data[3U];
254+
uint8_t data[8U];
255255
RAMN_ISOTP_GetFCFrame(handler,&dlc,data);
256256
handler->pFC_CANHeader->DataLength = UINT8toDLC(dlc);
257257
// Ignore potential error. If we miss the answer window, it is up to the diag tool to reduce speed.
@@ -268,7 +268,16 @@ RAMN_Bool_t RAMN_ISOTP_GetFCFrame(RAMN_ISOTPHandler_t* handler, uint8_t* dlc, ui
268268
data[0U] = 0x30 | handler->selfFCFlag;
269269
data[1U] = handler->selfBlockSize;
270270
data[2U] = handler->selfST;
271+
272+
#ifdef ISOTP_ANSWER_PADDING_BYTE
273+
*dlc = 8U;
274+
for (uint8_t i = 3U; i < 8U; i++)
275+
{
276+
data[i] = ISOTP_ANSWER_PADDING_BYTE;
277+
}
278+
#else
271279
*dlc = 3U;
280+
#endif
272281
wroteValidMessage = True;
273282
handler->rxMustSendCF = False;
274283
}
@@ -348,6 +357,20 @@ RAMN_Bool_t RAMN_ISOTP_GetNextTxMsg(RAMN_ISOTPHandler_t* handler, uint8_t* dlc,
348357
handler->txLastTimestamp = tick;
349358
}
350359
}
360+
#ifdef ISOTP_ANSWER_PADDING_BYTE
361+
// Add padding if required
362+
if(wroteValidMessage == True)
363+
{
364+
if (*dlc < 8U)
365+
{
366+
for (uint8_t i = *dlc; i < 8U; i++)
367+
{
368+
data[i] = ISOTP_ANSWER_PADDING_BYTE;
369+
}
370+
*dlc = 8U;
371+
}
372+
}
373+
#endif
351374
return wroteValidMessage;
352375
}
353376

0 commit comments

Comments
 (0)