From 9b3467318ce44327066b763c8f83b0cf7410aabf Mon Sep 17 00:00:00 2001 From: aidan garske Date: Wed, 15 Jul 2026 11:20:59 -0700 Subject: [PATCH] Retry the ISO TP flow control wait up to N_Bs --- src/wolfio.c | 14 +++++++++++++- wolfssl/wolfio.h | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/wolfio.c b/src/wolfio.c index f5b91bc5cee..eefdc7c76a3 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -3851,9 +3851,21 @@ static int isotp_send_flow_control(struct isotp_wolfssl_ctx *ctx, static int isotp_receive_flow_control(struct isotp_wolfssl_ctx *ctx) { int ret; + int waited; enum isotp_frame_type type; enum isotp_flow_control flow_control; - ret = ctx->recv_fn(&ctx->frame, ctx->arg, ISOTP_DEFAULT_TIMEOUT); + /* Wait up to N_Bs for flow control rather than a single 100ms poll: a peer + * that is momentarily late is normal, and every other ISO-TP receive here + * retries. Treating the first miss as fatal aborts healthy transfers. */ + waited = 0; + do { + ret = ctx->recv_fn(&ctx->frame, ctx->arg, ISOTP_DEFAULT_TIMEOUT); + if (ret != 0) { + break; + } + waited += ISOTP_DEFAULT_TIMEOUT; + } while (waited < ISOTP_FLOW_CONTROL_TIMEOUT); + if (ret == 0) { return WOLFSSL_CBIO_ERR_TIMEOUT; } else if (ret < 0) { diff --git a/wolfssl/wolfio.h b/wolfssl/wolfio.h index 4e5a80d5afb..7098e61c48a 100644 --- a/wolfssl/wolfio.h +++ b/wolfssl/wolfio.h @@ -906,6 +906,8 @@ WOLFSSL_API void wolfSSL_SetIOWriteFlags(WOLFSSL* ssl, int flags); #endif #ifdef WOLFSSL_ISOTP #define ISOTP_DEFAULT_TIMEOUT 100 + /* ISO 15765-2 N_Bs: how long a sender waits for flow control */ + #define ISOTP_FLOW_CONTROL_TIMEOUT 1000 #define ISOTP_DEFAULT_WAIT_COUNT 3 #define ISOTP_FIRST_FRAME_DATA_SIZE 6 #define ISOTP_SINGLE_FRAME_DATA_SIZE 7