socket.h
Go to the documentation of this file.
1 /**
2  * @file socket.h
3  * @brief Socket API
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.2
29  **/
30 
31 #ifndef _SOCKET_H
32 #define _SOCKET_H
33 
34 //Forward declaration of Socket structure
35 struct _Socket;
36 #define Socket struct _Socket
37 
38 //Dependencies
39 #include "core/net.h"
40 #include "core/ethernet.h"
41 #include "core/ip.h"
42 #include "core/tcp.h"
43 
44 //Number of sockets that can be opened simultaneously
45 #ifndef SOCKET_MAX_COUNT
46  #define SOCKET_MAX_COUNT 16
47 #elif (SOCKET_MAX_COUNT < 1)
48  #error SOCKET_MAX_COUNT parameter is not valid
49 #endif
50 
51 //Maximum number of multicast groups joined
52 #ifndef SOCKET_MAX_MULTICAST_GROUPS
53  #define SOCKET_MAX_MULTICAST_GROUPS 1
54 #elif (SOCKET_MAX_MULTICAST_GROUPS < 1)
55  #error SOCKET_MAX_MULTICAST_GROUPS parameter is not valid
56 #endif
57 
58 //Dynamic port range (lower limit)
59 #ifndef SOCKET_EPHEMERAL_PORT_MIN
60  #define SOCKET_EPHEMERAL_PORT_MIN 49152
61 #elif (SOCKET_EPHEMERAL_PORT_MIN < 1024)
62  #error SOCKET_EPHEMERAL_PORT_MIN parameter is not valid
63 #endif
64 
65 //Dynamic port range (upper limit)
66 #ifndef SOCKET_EPHEMERAL_PORT_MAX
67  #define SOCKET_EPHEMERAL_PORT_MAX 65535
68 #elif (SOCKET_EPHEMERAL_PORT_MAX <= SOCKET_EPHEMERAL_PORT_MIN || SOCKET_EPHEMERAL_PORT_MAX > 65535)
69  #error SOCKET_EPHEMERAL_PORT_MAX parameter is not valid
70 #endif
71 
72 //C++ guard
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76 
77 
78 /**
79  * @brief Socket types
80  **/
81 
82 typedef enum
83 {
90 
91 
92 /**
93  * @brief IP protocols
94  **/
95 
96 typedef enum
97 {
104 
105 
106 /**
107  * @brief Ethernet protocols
108  **/
109 
110 typedef enum
111 {
119  SOCKET_ETH_PROTO_PTP = 0x88F7
121 
122 
123 /**
124  * @brief Flags used by I/O functions
125  **/
126 
127 typedef enum
128 {
137  SOCKET_FLAG_DELAY = 0x8000
139 
140 
141 //The SOCKET_FLAG_BREAK macro causes the I/O functions to stop reading
142 //data whenever the specified break character is encountered
143 #define SOCKET_FLAG_BREAK(c) (SOCKET_FLAG_BREAK_CHAR | LSB(c))
144 
145 
146 /**
147  * @brief Flags used by shutdown function
148  **/
149 
150 typedef enum
151 {
154  SOCKET_SD_BOTH = 2
156 
157 
158 /**
159  * @brief Socket events
160  **/
161 
162 typedef enum
163 {
175  SOCKET_EVENT_LINK_DOWN = 0x0400
177 
178 
179 /**
180  * @brief Socket options
181  **/
182 
183 typedef enum
184 {
200 
201 
202 /**
203  * @brief Host types
204  **/
205 
206 typedef enum
207 {
210  HOST_TYPE_IPV6 = 32
212 
213 
214 /**
215  * @brief Name resolution protocols
216  **/
217 
218 typedef enum
219 {
226 
227 
228 /**
229  * @brief Message and ancillary data
230  **/
231 
232 typedef struct
233 {
234  void *data; ///<Pointer to the payload
235  size_t size; ///<Size of the payload, in bytes
236  size_t length; ///<Actual length of the payload, in bytes
237  uint8_t ttl; ///<Time-to-live value
238  uint8_t tos; ///<Type-of-service value
239  bool_t dontFrag; ///<Do not fragment the IP packet
240  NetInterface *interface; ///<Underlying network interface
241  IpAddr srcIpAddr; ///<Source IP address
242  uint16_t srcPort; ///<Source port
243  IpAddr destIpAddr; ///<Destination IP address
244  uint16_t destPort; ///<Destination port
245 #if (ETH_SUPPORT == ENABLED)
246  MacAddr srcMacAddr; ///<Source MAC address
247  MacAddr destMacAddr; ///<Destination MAC address
248  uint16_t ethType; ///<Ethernet type field
249 #endif
250 #if (ETH_PORT_TAGGING_SUPPORT == ENABLED)
251  uint8_t switchPort; ///<Switch port identifier
252 #endif
253 #if (ETH_TIMESTAMP_SUPPORT == ENABLED)
254  int32_t timestampId; ///<Unique identifier for hardware time stamping
255  NetTimestamp timestamp; ///<Captured time stamp
256 #endif
257 } SocketMsg;
258 
259 
260 /**
261  * @brief Receive queue item
262  **/
263 
264 typedef struct _SocketQueueItem
265 {
269  uint16_t srcPort;
272  size_t offset;
275 
276 
277 /**
278  * @brief Structure describing a socket
279  **/
280 
281 struct _Socket
282 {
288  uint16_t localPort;
290  uint16_t remotePort;
291  uint32_t options; ///<Socket options
293  uint8_t tos; ///<Type-of-service value
294  uint8_t ttl; ///<Time-to-live value for unicast datagrams
295  uint8_t multicastTtl; ///<Time-to-live value for multicast datagrams
297 #if (ETH_VLAN_SUPPORT == ENABLED)
298  int8_t vlanPcp; ///<VLAN priority (802.1Q)
299  int8_t vlanDei; ///<Drop eligible indicator
300 #endif
301 #if (ETH_VMAN_SUPPORT == ENABLED)
302  int8_t vmanPcp; ///<VMAN priority (802.1ad)
303  int8_t vmanDei; ///<Drop eligible indicator
304 #endif
310 
311 //TCP specific variables
312 #if (TCP_SUPPORT == ENABLED)
313  TcpState state; ///<Current state of the TCP finite state machine
314  bool_t ownedFlag; ///<The user is the owner of the TCP socket
315  bool_t closedFlag; ///<The connection has been closed properly
316  bool_t resetFlag; ///<The connection has been reset
317 
318  uint16_t mss; ///<Maximum segment size
319  uint16_t smss; ///<Sender maximum segment size
320  uint16_t rmss; ///<Receiver maximum segment size
321  uint32_t iss; ///<Initial send sequence number
322  uint32_t irs; ///<Initial receive sequence number
323 
324  uint32_t sndUna; ///<Data that have been sent but not yet acknowledged
325  uint32_t sndNxt; ///<Sequence number of the next byte to be sent
326  uint16_t sndUser; ///<Amount of data buffered but not yet sent
327  uint16_t sndWnd; ///<Size of the send window
328  uint16_t maxSndWnd; ///<Maximum send window it has seen so far on the connection
329  uint32_t sndWl1; ///<Segment sequence number used for last window update
330  uint32_t sndWl2; ///<Segment acknowledgment number used for last window update
331 
332  uint32_t rcvNxt; ///<Receive next sequence number
333  uint16_t rcvUser; ///<Number of data received but not yet consumed
334  uint16_t rcvWnd; ///<Receive window
335 
336  bool_t rttBusy; ///<RTT measurement is being performed
337  uint32_t rttSeqNum; ///<Sequence number identifying a TCP segment
338  systime_t rttStartTime; ///<Round-trip start time
339  systime_t srtt; ///<Smoothed round-trip time
340  systime_t rttvar; ///<Round-trip time variation
341  systime_t rto; ///<Retransmission timeout
342 
343 #if (TCP_CONGEST_CONTROL_SUPPORT == ENABLED)
344  TcpCongestState congestState; ///<Congestion state
345  uint16_t cwnd; ///<Congestion window
346  uint16_t ssthresh; ///<Slow start threshold
347  uint_t dupAckCount; ///<Number of consecutive duplicate ACKs
348  uint_t n; ///<Number of bytes acknowledged during the whole round-trip
349  uint32_t recover; ///<NewReno modification to TCP's fast recovery algorithm
350 #endif
351 
352 #if (TCP_KEEP_ALIVE_SUPPORT == ENABLED)
353  bool_t keepAliveEnabled; ///<Specifies whether TCP keep-alive mechanism is enabled
354  systime_t keepAliveIdle; ///<Keep-alive idle time
355  systime_t keepAliveInterval; ///<Time interval between subsequent keep-alive probes
356  uint_t keepAliveMaxProbes; ///<Number of keep-alive probes
357  uint_t keepAliveProbeCount; ///<Keep-alive probe counter
358  systime_t keepAliveTimestamp; ///<Keep-alive timestamp
359 #endif
360 
361 #if (TCP_SACK_SUPPORT == ENABLED)
362  bool_t sackPermitted; ///<SACK Permitted option received
363 #endif
364 
365  TcpSackBlock sackBlock[TCP_MAX_SACK_BLOCKS]; ///<List of non-contiguous blocks that have been received
366  uint_t sackBlockCount; ///<Number of non-contiguous blocks that have been received
367 
368  TcpTxBuffer txBuffer; ///<Send buffer
369  size_t txBufferSize; ///<Size of the send buffer
370  TcpRxBuffer rxBuffer; ///<Receive buffer
371  size_t rxBufferSize; ///<Size of the receive buffer
372 
373  TcpQueueItem *retransmitQueue; ///<Retransmission queue
374  NetTimer retransmitTimer; ///<Retransmission timer
375  uint_t retransmitCount; ///<Number of retransmissions
376 
377  TcpSynQueueItem *synQueue; ///<SYN queue for listening sockets
378  uint_t synQueueSize; ///<Maximum number of pending connections for listening sockets
379 
380  uint_t wndProbeCount; ///<Zero window probe counter
381  systime_t wndProbeInterval; ///<Interval between successive probes
382 
383  NetTimer persistTimer; ///<Persist timer
384  NetTimer overrideTimer; ///<Override timer
385  NetTimer finWait2Timer; ///<FIN-WAIT-2 timer
386  NetTimer timeWaitTimer; ///<2MSL timer
387 #endif
388 
389 //UDP specific variables
390 #if (UDP_SUPPORT == ENABLED || RAW_SOCKET_SUPPORT == ENABLED)
392 #endif
393 };
394 
395 
396 /**
397  * @brief Structure describing socket events
398  **/
399 
400 typedef struct
401 {
402  Socket *socket; ///<Handle to a socket to monitor
403  uint_t eventMask; ///<Requested events
404  uint_t eventFlags; ///<Returned events
406 
407 
408 //Global constants
409 extern const SocketMsg SOCKET_DEFAULT_MSG;
410 
411 //Global variables
413 
414 //Socket related functions
415 error_t socketInit(void);
416 
418 
420 
423 
424 error_t socketSetDscp(Socket *socket, uint8_t dscp);
425 
426 error_t socketSetVlanPcp(Socket *socket, uint8_t pcp);
428 error_t socketSetVmanPcp(Socket *socket, uint8_t pcp);
430 
434 
436 
438  systime_t interval, uint_t maxProbes);
439 
441 
444 
447 
448 error_t socketBind(Socket *socket, const IpAddr *localIpAddr,
449  uint16_t localPort);
450 
451 error_t socketConnect(Socket *socket, const IpAddr *remoteIpAddr,
452  uint16_t remotePort);
453 
455 
456 Socket *socketAccept(Socket *socket, IpAddr *clientIpAddr,
457  uint16_t *clientPort);
458 
459 error_t socketSend(Socket *socket, const void *data, size_t length,
460  size_t *written, uint_t flags);
461 
463  const void *data, size_t length, size_t *written, uint_t flags);
464 
466 
468  size_t size, size_t *received, uint_t flags);
469 
470 error_t socketReceiveFrom(Socket *socket, IpAddr *srcIpAddr, uint16_t *srcPort,
471  void *data, size_t size, size_t *received, uint_t flags);
472 
473 error_t socketReceiveEx(Socket *socket, IpAddr *srcIpAddr, uint16_t *srcPort,
474  IpAddr *destIpAddr, void *data, size_t size, size_t *received, uint_t flags);
475 
477 
479  uint16_t *localPort);
480 
482  uint16_t *remotePort);
483 
485 void socketClose(Socket *socket);
486 
487 error_t socketPoll(SocketEventDesc *eventDesc, uint_t size, OsEvent *extEvent,
488  systime_t timeout);
489 
490 error_t getHostByName(NetInterface *interface, const char_t *name,
492 
493 //C++ guard
494 #ifdef __cplusplus
495 }
496 #endif
497 
498 #endif
SocketQueueItem * receiveQueue
Definition: socket.h:391
error_t socketConnect(Socket *socket, const IpAddr *remoteIpAddr, uint16_t remotePort)
Establish a connection to a specified socket.
Definition: socket.c:811
uint16_t maxSndWnd
Maximum send window it has seen so far on the connection.
Definition: socket.h:328
@ SOCKET_IP_PROTO_UDP
Definition: socket.h:101
HostType
Host types.
Definition: socket.h:207
Retransmission queue item.
Definition: tcp.h:386
@ SOCKET_ETH_PROTO_LLC
Definition: socket.h:113
uint32_t sndNxt
Sequence number of the next byte to be sent.
Definition: socket.h:325
HostnameResolver
Name resolution protocols.
Definition: socket.h:219
@ SOCKET_OPTION_IPV4_RECV_TOS
Definition: socket.h:190
int bool_t
Definition: compiler_port.h:53
error_t socketListen(Socket *socket, uint_t backlog)
Place a socket in the listening state.
Definition: socket.c:875
int8_t vmanPcp
VMAN priority (802.1ad)
Definition: socket.h:302
@ SOCKET_FLAG_WAIT_ALL
Definition: socket.h:131
uint32_t rcvNxt
Receive next sequence number.
Definition: socket.h:332
error_t socketLeaveMulticastGroup(Socket *socket, const IpAddr *groupAddr)
Leave the specified host group.
Definition: socket.c:496
struct _SocketQueueItem SocketQueueItem
Receive queue item.
uint8_t protocol
Definition: ipv4.h:296
@ HOST_NAME_RESOLVER_DNS
Definition: socket.h:221
signed int int_t
Definition: compiler_port.h:49
error_t socketEnableBroadcast(Socket *socket, bool_t enabled)
Enable reception of broadcast messages.
Definition: socket.c:392
IP network address.
Definition: ip.h:79
systime_t keepAliveIdle
Keep-alive idle time.
Definition: socket.h:354
uint16_t cwnd
Congestion window.
Definition: socket.h:345
TcpCongestState
TCP congestion states.
Definition: tcp.h:287
IpAddr remoteIpAddr
Definition: socket.h:289
uint8_t ttl
Time-to-live value for unicast datagrams.
Definition: socket.h:294
error_t socketJoinMulticastGroup(Socket *socket, const IpAddr *groupAddr)
Join the specified host group.
Definition: socket.c:426
OsEvent * userEvent
Definition: socket.h:309
@ SOCKET_FLAG_WAIT_ACK
Definition: socket.h:135
@ HOST_TYPE_ANY
Definition: socket.h:208
uint_t keepAliveProbeCount
Keep-alive probe counter.
Definition: socket.h:357
@ SOCKET_FLAG_DONT_ROUTE
Definition: socket.h:130
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t message[]
Definition: chap.h:154
@ SOCKET_IP_PROTO_ICMPV6
Definition: socket.h:102
@ SOCKET_OPTION_REUSE_ADDR
Definition: socket.h:185
uint_t wndProbeCount
Zero window probe counter.
Definition: socket.h:380
uint8_t data[]
Definition: ethernet.h:222
Message and ancillary data.
Definition: socket.h:233
#define SOCKET_MAX_MULTICAST_GROUPS
Definition: socket.h:53
SocketIpProtocol
IP protocols.
Definition: socket.h:97
Event object.
uint16_t sndUser
Amount of data buffered but not yet sent.
Definition: socket.h:326
uint16_t srcPort
Definition: socket.h:269
error_t socketBind(Socket *socket, const IpAddr *localIpAddr, uint16_t localPort)
Associate a local address with a socket.
Definition: socket.c:778
@ HOST_NAME_RESOLVER_LLMNR
Definition: socket.h:224
uint32_t irs
Initial receive sequence number.
Definition: socket.h:322
OsEvent event
Definition: socket.h:306
@ SOCKET_TYPE_DGRAM
Definition: socket.h:86
uint_t type
Definition: socket.h:284
@ SOCKET_OPTION_IPV6_ONLY
Definition: socket.h:193
uint32_t sndWl2
Segment acknowledgment number used for last window update.
Definition: socket.h:330
void * data
Pointer to the payload.
Definition: socket.h:234
size_t txBufferSize
Size of the send buffer.
Definition: socket.h:369
uint8_t type
Definition: coap_common.h:176
IpAddr srcIpAddr
Definition: socket.h:268
uint_t eventFlags
Definition: socket.h:308
uint8_t multicastTtl
Time-to-live value for multicast datagrams.
Definition: socket.h:295
error_t socketSendMsg(Socket *socket, const SocketMsg *message, uint_t flags)
Send a message to a connectionless socket.
Definition: socket.c:1094
uint16_t rmss
Receiver maximum segment size.
Definition: socket.h:320
char_t name[]
bool_t resetFlag
The connection has been reset.
Definition: socket.h:316
uint16_t destPort
Definition: tcp.h:340
NetTimestamp timestamp
Captured time stamp.
Definition: socket.h:255
uint32_t recover
NewReno modification to TCP's fast recovery algorithm.
Definition: socket.h:349
Ipv4Addr srcIpAddr
Definition: ipcp.h:79
struct _SocketQueueItem * next
Definition: socket.h:266
error_t socketSetTimeout(Socket *socket, systime_t timeout)
Set timeout value for blocking operations.
Definition: socket.c:148
@ SOCKET_OPTION_IPV6_DONT_FRAG
Definition: socket.h:194
systime_t srtt
Smoothed round-trip time.
Definition: socket.h:339
@ SOCKET_TYPE_STREAM
Definition: socket.h:85
SocketType
Socket types.
Definition: socket.h:83
uint_t descriptor
Definition: socket.h:283
Structure describing socket events.
Definition: socket.h:401
@ SOCKET_OPTION_IPV6_RECV_TRAFFIC_CLASS
Definition: socket.h:196
void socketClose(Socket *socket)
Close an existing socket.
Definition: socket.c:1517
int8_t vlanPcp
VLAN priority (802.1Q)
Definition: socket.h:298
Ethernet.
@ SOCKET_FLAG_PEEK
Definition: socket.h:129
NetTimer finWait2Timer
FIN-WAIT-2 timer.
Definition: socket.h:385
@ SOCKET_FLAG_DELAY
Definition: socket.h:137
error_t socketSetMulticastTtl(Socket *socket, uint8_t ttl)
Set TTL value for multicast datagrams.
Definition: socket.c:198
uint16_t ethType
Ethernet type field.
Definition: socket.h:248
@ HOST_TYPE_IPV6
Definition: socket.h:210
@ SOCKET_OPTION_IPV4_RECV_TTL
Definition: socket.h:191
error_t socketSend(Socket *socket, const void *data, size_t length, size_t *written, uint_t flags)
Send data to a connected socket.
Definition: socket.c:946
TcpRxBuffer rxBuffer
Receive buffer.
Definition: socket.h:370
TcpCongestState congestState
Congestion state.
Definition: socket.h:344
uint16_t destPort
Destination port.
Definition: socket.h:244
#define TCP_MAX_SACK_BLOCKS
Definition: tcp.h:243
@ SOCKET_SD_SEND
Definition: socket.h:153
systime_t rto
Retransmission timeout.
Definition: socket.h:341
NetRxAncillary ancillary
Definition: socket.h:273
NetInterface * interface
Underlying network interface.
Definition: socket.h:240
TcpState
TCP FSM states.
Definition: tcp.h:267
size_t length
Actual length of the payload, in bytes.
Definition: socket.h:236
error_t socketReceiveFrom(Socket *socket, IpAddr *srcIpAddr, uint16_t *srcPort, void *data, size_t size, size_t *received, uint_t flags)
Receive a datagram from a connectionless socket.
Definition: socket.c:1174
systime_t keepAliveInterval
Time interval between subsequent keep-alive probes.
Definition: socket.h:355
uint32_t options
Socket options.
Definition: socket.h:291
Timestamp.
Definition: net_misc.h:105
error_t
Error codes.
Definition: error.h:43
error_t socketSetMaxSegmentSize(Socket *socket, size_t mss)
Specify the maximum segment size for outgoing TCP packets.
Definition: socket.c:626
const SocketMsg SOCKET_DEFAULT_MSG
Definition: socket.c:52
IpAddr multicastGroups[SOCKET_MAX_MULTICAST_GROUPS]
Multicast groups.
Definition: socket.h:296
IpAddr localIpAddr
Definition: socket.h:287
@ SOCKET_ETH_PROTO_EAPOL
Definition: socket.h:117
uint16_t rcvWnd
Receive window.
Definition: socket.h:334
uint16_t rcvUser
Number of data received but not yet consumed.
Definition: socket.h:333
@ SOCKET_OPTION_IPV6_RECV_HOP_LIMIT
Definition: socket.h:197
error_t socketEnableKeepAlive(Socket *socket, bool_t enabled)
Enable TCP keep-alive.
Definition: socket.c:535
int_t socket(int_t family, int_t type, int_t protocol)
Create a socket that is bound to a specific transport service provider.
Definition: bsd_socket.c:65
@ HOST_NAME_RESOLVER_MDNS
Definition: socket.h:222
@ SOCKET_EVENT_TX_READY
Definition: socket.h:168
uint16_t remotePort
Definition: socket.h:290
uint16_t smss
Sender maximum segment size.
Definition: socket.h:319
@ SOCKET_EVENT_LINK_DOWN
Definition: socket.h:175
Timer.
Definition: net_misc.h:172
NetInterface * socketGetInterface(Socket *socket)
Retrieve the underlying interface.
Definition: socket.c:755
SocketShutdownFlags
Flags used by shutdown function.
Definition: socket.h:151
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:36
IpAddr srcIpAddr
Source IP address.
Definition: socket.h:241
TcpTxBuffer txBuffer
Send buffer.
Definition: socket.h:368
@ SOCKET_EVENT_ACCEPT
Definition: socket.h:165
NetTimer persistTimer
Persist timer.
Definition: socket.h:383
Socket * socketAccept(Socket *socket, IpAddr *clientIpAddr, uint16_t *clientPort)
Permit an incoming connection attempt on a socket.
Definition: socket.c:912
@ SOCKET_EVENT_RX_SHUTDOWN
Definition: socket.h:173
bool_t keepAliveEnabled
Specifies whether TCP keep-alive mechanism is enabled.
Definition: socket.h:353
uint16_t localPort
Definition: socket.h:288
uint8_t switchPort
Switch port identifier.
Definition: socket.h:251
@ SOCKET_OPTION_IPV4_DONT_FRAG
Definition: socket.h:188
@ SOCKET_OPTION_BROADCAST
Definition: socket.h:186
error_t socketSetVmanPcp(Socket *socket, uint8_t pcp)
Set VMAN priority.
Definition: socket.c:322
int32_t timestampId
Unique identifier for hardware time stamping.
Definition: socket.h:254
@ SOCKET_TYPE_RAW_IP
Definition: socket.h:87
IpAddr destIpAddr
Definition: socket.h:270
uint_t keepAliveMaxProbes
Number of keep-alive probes.
Definition: socket.h:356
uint8_t length
Definition: tcp.h:368
uint_t eventMask
Definition: socket.h:307
bool_t closedFlag
The connection has been closed properly.
Definition: socket.h:315
TcpSynQueueItem * synQueue
SYN queue for listening sockets.
Definition: socket.h:377
SocketOptions
Socket options.
Definition: socket.h:184
uint16_t ssthresh
Slow start threshold.
Definition: socket.h:346
systime_t keepAliveTimestamp
Keep-alive timestamp.
Definition: socket.h:358
NetTimer timeWaitTimer
2MSL timer
Definition: socket.h:386
@ HOST_TYPE_IPV4
Definition: socket.h:209
@ SOCKET_EVENT_TX_DONE
Definition: socket.h:169
uint_t eventFlags
Returned events.
Definition: socket.h:404
@ SOCKET_IP_PROTO_IGMP
Definition: socket.h:99
size_t rxBufferSize
Size of the receive buffer.
Definition: socket.h:371
uint_t retransmitCount
Number of retransmissions.
Definition: socket.h:375
error_t socketSetVmanDei(Socket *socket, bool_t dei)
Set VMAN DEI flag.
Definition: socket.c:359
@ SOCKET_EVENT_LINK_UP
Definition: socket.h:174
uint8_t tos
Type-of-service value.
Definition: socket.h:238
MacAddr
Definition: ethernet.h:195
MacAddr srcMacAddr
Source MAC address.
Definition: socket.h:246
error_t socketSetTxBufferSize(Socket *socket, size_t size)
Specify the size of the TCP send buffer.
Definition: socket.c:663
uint_t dupAckCount
Number of consecutive duplicate ACKs.
Definition: socket.h:347
bool_t sackPermitted
SACK Permitted option received.
Definition: socket.h:362
bool_t dontFrag
Do not fragment the IP packet.
Definition: socket.h:239
@ SOCKET_FLAG_BREAK_CHAR
Definition: socket.h:133
uint32_t systime_t
System time.
Socket socketTable[SOCKET_MAX_COUNT]
Definition: socket.c:49
Receive queue item.
Definition: socket.h:265
uint32_t iss
Initial send sequence number.
Definition: socket.h:321
NetInterface * interface
Definition: socket.h:286
IpAddr destIpAddr
Destination IP address.
Definition: socket.h:243
uint8_t flags
Definition: tcp.h:351
SocketFlags
Flags used by I/O functions.
Definition: socket.h:128
error_t socketSetTtl(Socket *socket, uint8_t ttl)
Set TTL value for unicast datagrams.
Definition: socket.c:173
MacAddr destMacAddr
Destination MAC address.
Definition: socket.h:247
char char_t
Definition: compiler_port.h:48
error_t socketSetVlanDei(Socket *socket, bool_t dei)
Set VLAN DEI flag.
Definition: socket.c:289
error_t socketSendTo(Socket *socket, const IpAddr *destIpAddr, uint16_t destPort, const void *data, size_t length, size_t *written, uint_t flags)
Send a datagram to a specific destination.
Definition: socket.c:967
SACK block.
Definition: tcp.h:419
@ SOCKET_EVENT_TX_ACKED
Definition: socket.h:170
uint_t synQueueSize
Maximum number of pending connections for listening sockets.
Definition: socket.h:378
@ SOCKET_EVENT_NONE
Definition: socket.h:164
error_t socketSetVlanPcp(Socket *socket, uint8_t pcp)
Set VLAN priority.
Definition: socket.c:252
uint32_t sndWl1
Segment sequence number used for last window update.
Definition: socket.h:329
Socket * socketOpen(uint_t type, uint_t protocol)
Create a socket (UDP or TCP)
Definition: socket.c:125
bool_t rttBusy
RTT measurement is being performed.
Definition: socket.h:336
@ SOCKET_ETH_PROTO_PTP
Definition: socket.h:119
@ SOCKET_OPTION_IPV4_MULTICAST_LOOP
Definition: socket.h:187
IPv4 and IPv6 common routines.
@ SOCKET_FLAG_NO_DELAY
Definition: socket.h:136
@ SOCKET_EVENT_RX_READY
Definition: socket.h:172
systime_t wndProbeInterval
Interval between successive probes.
Definition: socket.h:381
@ HOST_NAME_RESOLVER_ANY
Definition: socket.h:220
@ SOCKET_ETH_PROTO_IPV4
Definition: socket.h:114
int8_t vlanDei
Drop eligible indicator.
Definition: socket.h:299
@ SOCKET_IP_PROTO_ICMP
Definition: socket.h:98
TCP (Transmission Control Protocol)
@ SOCKET_EVENT_TX_SHUTDOWN
Definition: socket.h:171
error_t socketReceive(Socket *socket, void *data, size_t size, size_t *received, uint_t flags)
Receive data from a connected socket.
Definition: socket.c:1152
@ SOCKET_TYPE_UNUSED
Definition: socket.h:84
@ SOCKET_ETH_PROTO_IPV6
Definition: socket.h:116
error_t socketPoll(SocketEventDesc *eventDesc, uint_t size, OsEvent *extEvent, systime_t timeout)
Wait for one of a set of sockets to become ready to perform I/O.
Definition: socket.c:1592
Ipv4Addr groupAddr
Definition: igmp_common.h:171
@ SOCKET_SD_RECEIVE
Definition: socket.h:152
#define Socket
Definition: socket.h:36
@ SOCKET_ETH_PROTO_ARP
Definition: socket.h:115
@ HOST_NAME_RESOLVER_NBNS
Definition: socket.h:223
@ SOCKET_OPTION_IPV6_PKT_INFO
Definition: socket.h:195
error_t socketGetRemoteAddr(Socket *socket, IpAddr *remoteIpAddr, uint16_t *remotePort)
Retrieve the address of the peer to which a socket is connected.
Definition: socket.c:1445
int8_t vmanDei
Drop eligible indicator.
Definition: socket.h:303
size_t size
Size of the payload, in bytes.
Definition: socket.h:235
@ SOCKET_OPTION_IPV6_MULTICAST_LOOP
Definition: socket.h:192
uint16_t sndWnd
Size of the send window.
Definition: socket.h:327
@ SOCKET_TYPE_RAW_ETH
Definition: socket.h:88
error_t socketReceiveMsg(Socket *socket, SocketMsg *message, uint_t flags)
Receive a message from a connectionless socket.
Definition: socket.c:1354
SYN queue item.
Definition: tcp.h:400
error_t socketSetInterface(Socket *socket, NetInterface *interface)
Bind a socket to a particular network interface.
Definition: socket.c:735
uint32_t sndUna
Data that have been sent but not yet acknowledged.
Definition: socket.h:324
error_t socketInit(void)
Socket related initialization.
Definition: socket.c:85
NetInterface * interface
Definition: socket.h:267
Ipv4Addr ipAddr
Definition: ipcp.h:105
TcpSackBlock sackBlock[TCP_MAX_SACK_BLOCKS]
List of non-contiguous blocks that have been received.
Definition: socket.h:365
uint_t protocol
Definition: socket.h:285
error_t socketShutdown(Socket *socket, uint_t how)
Disable reception, transmission, or both.
Definition: socket.c:1480
systime_t timeout
Definition: socket.h:292
NetTimer retransmitTimer
Retransmission timer.
Definition: socket.h:374
error_t socketSetRxBufferSize(Socket *socket, size_t size)
Specify the size of the TCP receive buffer.
Definition: socket.c:699
bool_t ownedFlag
The user is the owner of the TCP socket.
Definition: socket.h:314
error_t socketGetLocalAddr(Socket *socket, IpAddr *localIpAddr, uint16_t *localPort)
Retrieve the local address for a given socket.
Definition: socket.c:1413
uint32_t ttl
Definition: dns_common.h:221
Structure describing a socket.
Definition: socket.h:282
Socket * socket
Handle to a socket to monitor.
Definition: socket.h:402
@ SOCKET_EVENT_CONNECTED
Definition: socket.h:166
SocketEthProtocol
Ethernet protocols.
Definition: socket.h:111
Receive buffer.
Definition: tcp.h:442
TcpQueueItem * retransmitQueue
Retransmission queue.
Definition: socket.h:373
Transmit buffer.
Definition: tcp.h:430
unsigned int uint_t
Definition: compiler_port.h:50
systime_t rttvar
Round-trip time variation.
Definition: socket.h:340
@ SOCKET_FLAG_DONT_WAIT
Definition: socket.h:132
TCP/IP stack core.
@ SOCKET_EVENT_CLOSED
Definition: socket.h:167
TcpState state
Current state of the TCP finite state machine.
Definition: socket.h:313
uint_t sackBlockCount
Number of non-contiguous blocks that have been received.
Definition: socket.h:366
uint8_t ttl
Time-to-live value.
Definition: socket.h:237
#define SOCKET_MAX_COUNT
Definition: socket.h:46
uint8_t tos
Type-of-service value.
Definition: socket.h:293
systime_t rttStartTime
Round-trip start time.
Definition: socket.h:338
@ SOCKET_SD_BOTH
Definition: socket.h:154
uint32_t rttSeqNum
Sequence number identifying a TCP segment.
Definition: socket.h:337
SocketEvent
Socket events.
Definition: socket.h:163
@ SOCKET_ETH_PROTO_ALL
Definition: socket.h:112
@ SOCKET_IP_PROTO_TCP
Definition: socket.h:100
uint16_t srcPort
Source port.
Definition: socket.h:242
@ SOCKET_FLAG_BREAK_CRLF
Definition: socket.h:134
error_t socketSetKeepAliveParams(Socket *socket, systime_t idle, systime_t interval, uint_t maxProbes)
Set TCP keep-alive parameters.
Definition: socket.c:584
uint_t n
Number of bytes acknowledged during the whole round-trip.
Definition: socket.h:348
NetBuffer * buffer
Definition: socket.h:271
uint_t eventMask
Requested events.
Definition: socket.h:403
error_t socketReceiveEx(Socket *socket, IpAddr *srcIpAddr, uint16_t *srcPort, IpAddr *destIpAddr, void *data, size_t size, size_t *received, uint_t flags)
Receive a datagram.
Definition: socket.c:1196
@ SOCKET_OPTION_TCP_NO_DELAY
Definition: socket.h:198
int_t errnoCode
Definition: socket.h:305
size_t offset
Definition: socket.h:272
@ SOCKET_ETH_PROTO_LLDP
Definition: socket.h:118
@ SOCKET_OPTION_IPV4_PKT_INFO
Definition: socket.h:189
error_t socketSetDscp(Socket *socket, uint8_t dscp)
Set DSCP field.
Definition: socket.c:223
error_t getHostByName(NetInterface *interface, const char_t *name, IpAddr *ipAddr, uint_t flags)
Resolve a host name into an IP address.
Definition: socket.c:1717
NetTimer overrideTimer
Override timer.
Definition: socket.h:384
uint16_t mss
Maximum segment size.
Definition: socket.h:318
Ipv4Addr destIpAddr
Definition: ipcp.h:80