Skip to content

Commit d17989a

Browse files
authored
Network: fix TCP retry counter handling (#128)
1 parent 9f04a88 commit d17989a

File tree

8 files changed

+53
-26
lines changed

8 files changed

+53
-26
lines changed

Components/Network/Include/rl_net.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*------------------------------------------------------------------------------
22
* MDK Middleware - Component ::Network
3-
* Copyright (c) 2004-2025 Arm Limited (or its affiliates). All rights reserved.
3+
* Copyright (c) 2004-2026 Arm Limited (or its affiliates). All rights reserved.
44
*------------------------------------------------------------------------------
55
* Name: rl_net.h
66
* Purpose: Network API
@@ -18,7 +18,7 @@
1818
/// Network component version
1919
#define MW_NET_VERSION_MAJOR 8
2020
#define MW_NET_VERSION_MINOR 2
21-
#define MW_NET_VERSION_PATCH 0
21+
#define MW_NET_VERSION_PATCH 1
2222

2323
#ifdef __cplusplus
2424
extern "C" {

Components/Network/Network.scvd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

33
<component_viewer schemaVersion="0.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="Component_Viewer.xsd">
4-
<component name="Network" shortname="NET" version="8.2.0"/> <!-- name and version of the component -->
4+
<component name="Network" shortname="NET" version="8.2.1"/> <!-- name and version of the component -->
55

66
<typedefs>
77
<!-- Network Library variant -->

Components/Network/Source/net_lib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*------------------------------------------------------------------------------
22
* MDK Middleware - Component ::Network
3-
* Copyright (c) 2004-2025 Arm Limited (or its affiliates). All rights reserved.
3+
* Copyright (c) 2004-2026 Arm Limited (or its affiliates). All rights reserved.
44
*------------------------------------------------------------------------------
55
* Name: net_lib.h
66
* Purpose: Network Library Definitions
@@ -225,7 +225,7 @@ typedef struct net_udp_info {
225225
typedef struct net_tcp_info {
226226
uint8_t State; ///< Socket state
227227
uint8_t Type; ///< Socket type
228-
uint8_t Flags; ///< State flags
228+
uint16_t Flags; ///< State flags
229229
uint16_t LocPort; ///< Local TCP port
230230
uint8_t Tos; ///< Type of Service for IPv4
231231
uint8_t TClass; ///< Traffic class/packet priority for IPv6

Components/Network/Source/net_tcp.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*------------------------------------------------------------------------------
22
* MDK Middleware - Component ::Network
3-
* Copyright (c) 2004-2025 Arm Limited (or its affiliates). All rights reserved.
3+
* Copyright (c) 2004-2026 Arm Limited (or its affiliates). All rights reserved.
44
*------------------------------------------------------------------------------
55
* Name: net_tcp.c
66
* Purpose: Transmission Control Protocol
@@ -490,14 +490,18 @@ netStatus net_tcp_send (int32_t socket, uint8_t *buf, uint32_t len) {
490490

491491
net_mem_shrink (frame, TCP_DATA_OFFS + len);
492492
tcp_s->Flags |= TCP_IFLAG_DACK;
493+
/* Check queue retransmit status */
493494
if (!(tcp_s->Flags & TCP_IFLAG_RESEND)) {
494-
/* Not in retransmit, send a frame now */
495+
/* Not active, send a frame now */
495496
tcp_s->Flags |= TCP_IFLAG_PUSH;
496497
tcp_s->Flags &= ~TCP_IFLAG_KALIVE;
497498
tcp_send_data (tcp_s, frame, len);
498-
/* Calculate RTO and set a retransmit timer */
499-
tcp_s->RetryTimer = (uint16_t)((tcp_s->RttSa >> 3) + tcp_s->RttSv);
500-
tcp_s->Retries = tcp->MaxRetry;
499+
/* Check timeout recovery status */
500+
if (!(tcp_s->Flags & TCP_IFLAG_TIMEOUT)) {
501+
/* Inactive, set retry timer and counter */
502+
tcp_s->RetryTimer = (uint16_t)((tcp_s->RttSa >> 3) + tcp_s->RttSv);
503+
tcp_s->Retries = tcp->MaxRetry;
504+
}
501505
tcp_s->AliveTimer = tcp_s->ConnTout;
502506
}
503507
else {
@@ -1207,8 +1211,9 @@ void net_tcp_socket_run (void) {
12071211
}
12081212
/* Make sure fast recovery mode is not active */
12091213
tcp_s->DupAcks = 0;
1210-
/* Retransmit all frames from the queue */
12111214
tcp_s->Flags &= ~TCP_IFLAG_FAST;
1215+
/* Initialize the queue for timeout recovery */
1216+
tcp_s->Flags |= TCP_IFLAG_TIMEOUT;
12121217
tcp_que_init (tcp_s);
12131218
tcp_que_resend (tcp_s);
12141219
return;
@@ -2453,7 +2458,7 @@ static void tcp_proc_acknr (NET_TCP_INFO *tcp_s, uint32_t acknr) {
24532458
tcp_s->SendChk = acknr;
24542459
}
24552460

2456-
/* Release the acked data from the queue */
2461+
/* Calculate RTT estimation */
24572462
next = tcp_s->unack_list;
24582463
if (TCP_QUE(next)->ticks) {
24592464
/* Timestamp exists, do RTT estimation calculations. This */
@@ -2470,12 +2475,17 @@ static void tcp_proc_acknr (NET_TCP_INFO *tcp_s, uint32_t acknr) {
24702475
DEBUG_INFO (tcp_s);
24712476
EvrNetTCP_ShowRttVariables (tcp_s->Id, tcp_s->RttSa, tcp_s->RttSv);
24722477
}
2473-
tcp_s->unack_list = NULL;
24742478
if (frame != NULL) {
2475-
/* Markup the release edge (next = NULL) */
2479+
/* Mark the release edge (next = NULL) */
24762480
tcp_s->unack_list = TCP_QUE(frame)->next;
2477-
TCP_QUE(frame)->next= NULL;
2481+
TCP_QUE(frame)->next = NULL;
24782482
}
2483+
else {
2484+
/* All data in the queue is acked */
2485+
tcp_s->unack_list = NULL;
2486+
tcp_s->Flags &= ~TCP_IFLAG_TIMEOUT;
2487+
}
2488+
/* Release the acked data from the queue */
24792489
for (frame = next; frame; frame = next) {
24802490
next = TCP_QUE(frame)->next;
24812491
net_mem_free (frame);

Components/Network/Source/net_tcp.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*------------------------------------------------------------------------------
22
* MDK Middleware - Component ::Network
3-
* Copyright (c) 2004-2024 Arm Limited (or its affiliates). All rights reserved.
3+
* Copyright (c) 2004-2026 Arm Limited (or its affiliates). All rights reserved.
44
*------------------------------------------------------------------------------
55
* Name: net_tcp.h
66
* Purpose: Transmission Control Protocol Definitions
@@ -44,14 +44,15 @@
4444
#define TCP_FLAG_URG 0x20 // Urgent Pointer Field significant
4545

4646
/* TCP Internal Flags */
47-
#define TCP_IFLAG_CLOSING 0x01 // Socket Close pending
48-
#define TCP_IFLAG_KALIVE 0x02 // Keep alive recovery state
49-
#define TCP_IFLAG_RESEND 0x04 // Resend the buffered data
50-
#define TCP_IFLAG_FAST 0x08 // Fast Recovery active
51-
#define TCP_IFLAG_CBACK 0x10 // Callback context active
52-
#define TCP_IFLAG_DACK 0x20 // Callback ACK notification pending
53-
#define TCP_IFLAG_KSEG 0x40 // Send Keep Alive segment
54-
#define TCP_IFLAG_PUSH 0x80 // Push the data (set PSH flag)
47+
#define TCP_IFLAG_CLOSING 0x0001 // Socket Close pending
48+
#define TCP_IFLAG_KALIVE 0x0002 // Keep alive recovery state
49+
#define TCP_IFLAG_RESEND 0x0004 // Resend the buffered data
50+
#define TCP_IFLAG_FAST 0x0008 // Fast Recovery active
51+
#define TCP_IFLAG_CBACK 0x0010 // Callback context active
52+
#define TCP_IFLAG_DACK 0x0020 // Callback ACK notification pending
53+
#define TCP_IFLAG_KSEG 0x0040 // Send Keep Alive segment
54+
#define TCP_IFLAG_PUSH 0x0080 // Push the data (set PSH flag)
55+
#define TCP_IFLAG_TIMEOUT 0x0100 // Timeout Recovery active
5556

5657
/* TCP Socket Types */
5758
#define TCP_TYPE_DELAY_ACK 0x01 // Delayed Acknowledge enabled

Documentation/Doxygen/General/src/revision_history.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
<th>Version</th>
1010
<th>Description</th>
1111
</tr>
12+
<tr>
13+
<td>V8.2.1</td>
14+
<td>
15+
- Network Component Version 8.2.1
16+
- FileSystem Component Version 8.0.2 (unchanged)
17+
- USB Component Version 8.0.1 (unchanged)
18+
</td>
19+
</tr>
1220
<tr>
1321
<td>V8.2.0</td>
1422
<td>

Documentation/Doxygen/Network/src/revision_history.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
<th>Version</th>
66
<th>Description</th>
77
</tr>
8+
<tr>
9+
<td>V8.2.1</td>
10+
<td>
11+
- fixed TCP retry counter handling during timeout recovery in \ref netTCP_Send
12+
</td>
13+
</tr>
814
<tr>
915
<td>V8.2.0</td>
1016
<td>

Keil.MDK-Middleware.pdsc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<package schemaVersion="1.7.36" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="https://raw.githubusercontent.com/Open-CMSIS-Pack/Open-CMSIS-Pack-Spec/v1.7.36/schema/PACK.xsd">
2+
<package schemaVersion="1.7.45" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="https://raw.githubusercontent.com/Open-CMSIS-Pack/Open-CMSIS-Pack-Spec/v1.7.45/schema/PACK.xsd">
33
<vendor>Keil</vendor>
44
<name>MDK-Middleware</name>
55
<description overview="Documentation/README.md">Middleware for Arm based processors</description>
@@ -14,6 +14,8 @@
1414
<releases>
1515
<release version="8.2.1-dev">
1616
Active development ...
17+
Network Component Version 8.2.1
18+
- fixed TCP retry counter handling during timeout recovery in netTCP_Send
1719
</release>
1820
<release version="7.17.0" date="2024-01-17">
1921
Network Component Version 7.19.0
@@ -681,7 +683,7 @@
681683
<components>
682684

683685
<!-- Network (MDK) -->
684-
<bundle Cbundle="MDK" Cclass="Network" Cversion="8.2.0">
686+
<bundle Cbundle="MDK" Cclass="Network" Cversion="8.2.1">
685687
<description>IPv4/IPv6 Networking using Ethernet or Serial protocols</description>
686688
<doc>Documentation/html/Network/index.html</doc>
687689
<component Cgroup="CORE" condition="CMSIS Core with RTOS">

0 commit comments

Comments
 (0)