Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_ip.h"
#include "nx_tcp.h"
...
...
_nx_tcp_socket_state_syn_received(NX_TCP_SOCKET *, NX_TCP_HEADER *)
Files
netxduo
addons
common
drivers
inc
src
crypto_libraries
nx_secure
ports
threadx
filex
usbx
HAL
CMSIS
lan8742
SourceVuSTM32 Libraries and Samplesnetxduocommon/src/nx_tcp_socket_state_syn_received.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Component */ /** */ /** Transmission Control Protocol (TCP) */ /** */... /**************************************************************************/ /**************************************************************************/ #define NX_SOURCE_CODE /* Include necessary system files. */ #include "nx_api.h" #include "nx_ip.h" #include "nx_tcp.h" ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_tcp_socket_state_syn_received PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function processes packets during the SYN RECEIVED state, */ /* which is the state after the initial SYN message was responded to */ /* with an SYN/ACK message. The expected value here is an ACK, which */ /* will move us into an ESTABLISHED state ready for sending and */ /* receiving of TCP data. */ /* */ /* INPUT */ /* */ /* socket_ptr Pointer to owning socket */ /* tcp_header_ptr Pointer to packet header */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* _nx_tcp_socket_thread_resume Resume suspended thread */ /* _nx_tcp_packet_send_rst Send RST packet */ /* */ /* CALLED BY */ /* */ /* _nx_tcp_socket_packet_process Process TCP packet for socket */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ VOID _nx_tcp_socket_state_syn_received(NX_TCP_SOCKET *socket_ptr, NX_TCP_HEADER *tcp_header_ptr) { /* Determine if the incoming message is an ACK message. If it is and if it is proper, move into the ESTABLISHED state. *//* ... */ if (tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_ACK_BIT) { if (tcp_header_ptr -> nx_tcp_acknowledgment_number == socket_ptr -> nx_tcp_socket_tx_sequence) { /* If trace is enabled, insert this event into the trace buffer. */ NX_TRACE_IN_LINE_INSERT(NX_TRACE_INTERNAL_TCP_STATE_CHANGE, socket_ptr -> nx_tcp_socket_ip_ptr, socket_ptr, socket_ptr -> nx_tcp_socket_state, NX_TCP_ESTABLISHED, NX_TRACE_INTERNAL_EVENTS, 0, 0); /* Save the window size. */ socket_ptr -> nx_tcp_socket_tx_window_advertised = tcp_header_ptr -> nx_tcp_header_word_3 & NX_LOWER_16_MASK; #ifdef NX_ENABLE_TCP_WINDOW_SCALING /* The window size advertised in the SYN packet is NEVER scaled. Therefore there is no need to apply the scale shift. However validate snd_win_scale and rcv_win_scale. *//* ... */ if (socket_ptr -> nx_tcp_snd_win_scale_value == 0xFF) { /* Peer does not support window scale option. */ socket_ptr -> nx_tcp_snd_win_scale_value = 0; socket_ptr -> nx_tcp_rcv_win_scale_value = 0; /* Since peer does not offer window scaling feature, make sure our default window size for this connection does not exceed 65535 bytes. *//* ... */ if (socket_ptr -> nx_tcp_socket_rx_window_maximum > 65535) { socket_ptr -> nx_tcp_socket_rx_window_default = 65535; socket_ptr -> nx_tcp_socket_rx_window_current = 65535; }if (socket_ptr -> nx_tcp_socket_rx_window_maximum > 65535) { ... } }if (socket_ptr -> nx_tcp_snd_win_scale_value == 0xFF) { ... } /* Updated the window size. */ socket_ptr -> nx_tcp_socket_tx_window_advertised <<= socket_ptr -> nx_tcp_snd_win_scale_value; /* ... */ #endif /* NX_ENABLE_TCP_WINDOW_SCALING */ /* Set the initial slow start threshold to be the advertised window size. */ socket_ptr -> nx_tcp_socket_tx_slow_start_threshold = socket_ptr -> nx_tcp_socket_tx_window_advertised; /* Set the initial congestion control window size. */ /* Section 3.1, Page 5, RFC5681. */ if (socket_ptr -> nx_tcp_socket_timeout_retries > 0) { /* Set the initial congestion control window size to be the mss. */ socket_ptr -> nx_tcp_socket_tx_window_congestion = socket_ptr -> nx_tcp_socket_connect_mss; }if (socket_ptr -> nx_tcp_socket_timeout_retries > 0) { ... } else { socket_ptr -> nx_tcp_socket_tx_window_congestion = (socket_ptr -> nx_tcp_socket_connect_mss << 2); if (socket_ptr -> nx_tcp_socket_connect_mss > 1095) { socket_ptr -> nx_tcp_socket_tx_window_congestion -= socket_ptr -> nx_tcp_socket_connect_mss; }if (socket_ptr -> nx_tcp_socket_connect_mss > 1095) { ... } if (socket_ptr -> nx_tcp_socket_connect_mss > 2190) { socket_ptr -> nx_tcp_socket_tx_window_congestion -= socket_ptr -> nx_tcp_socket_connect_mss; }if (socket_ptr -> nx_tcp_socket_connect_mss > 2190) { ... } }else { ... } /* Move into the ESTABLISHED state. */ socket_ptr -> nx_tcp_socket_state = NX_TCP_ESTABLISHED; #ifndef NX_DISABLE_EXTENDED_NOTIFY_SUPPORT /* If registered with the TCP socket, call the application's connection completion callback function. */ if (socket_ptr -> nx_tcp_establish_notify) { /* Call the application's establish callback function. */ (socket_ptr -> nx_tcp_establish_notify)(socket_ptr); }if (socket_ptr -> nx_tcp_establish_notify) { ... } /* ... */#endif #ifdef NX_ENABLE_TCP_KEEPALIVE /* Is the keepalive feature enabled on this socket? */ if (socket_ptr -> nx_tcp_socket_keepalive_enabled) { /* Setup the TCP Keepalive timer to initial values. */ socket_ptr -> nx_tcp_socket_keepalive_timeout = NX_TCP_KEEPALIVE_INITIAL; socket_ptr -> nx_tcp_socket_keepalive_retries = 0; }if (socket_ptr -> nx_tcp_socket_keepalive_enabled) { ... } /* ... */#endif /* Update the value of nx_tcp_socket_rx_sequence_acked */ socket_ptr -> nx_tcp_socket_rx_sequence_acked = socket_ptr -> nx_tcp_socket_rx_sequence; /* Determine if we need to wake a thread suspended on the connection. */ if (socket_ptr -> nx_tcp_socket_connect_suspended_thread) { /* Resume the suspended thread. */ _nx_tcp_socket_thread_resume(&(socket_ptr -> nx_tcp_socket_connect_suspended_thread), NX_SUCCESS); }if (socket_ptr -> nx_tcp_socket_connect_suspended_thread) { ... } }if (tcp_header_ptr -> nx_tcp_acknowledgment_number == socket_ptr -> nx_tcp_socket_tx_sequence) { ... } /* Check for an invalid ACK message that signals an error on the other side. */ else { /* Invalid response was received, it is likely that the other side still thinks a previous connection is active. Send a reset (RST) message to the other side to clear any previous connection. *//* ... */ /* Send the RST packet. */ _nx_tcp_packet_send_rst(socket_ptr, tcp_header_ptr); }else { ... } }if (tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_ACK_BIT) { ... } }{ ... }
Details