1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** NetX Component */
16 /** */
17 /** Transmission Control Protocol (TCP) */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define NX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "nx_api.h"
28 #include "nx_tcp.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _nx_tcp_socket_mss_get PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* Yuxin Zhou, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function retrieves local TCP Maximum Segment Size (MSS) for */
44 /* for specified TCP socket. */
45 /* */
46 /* INPUT */
47 /* */
48 /* socket_ptr Pointer to the TCP socket */
49 /* mss Destination for the MSS */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* status Completion status */
54 /* */
55 /* CALLS */
56 /* */
57 /* tx_mutex_get Obtain protection */
58 /* tx_mutex_put Release protection */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* Application Code */
63 /* */
64 /* RELEASE HISTORY */
65 /* */
66 /* DATE NAME DESCRIPTION */
67 /* */
68 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
69 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
70 /* resulting in version 6.1 */
71 /* */
72 /**************************************************************************/
_nx_tcp_socket_mss_get(NX_TCP_SOCKET * socket_ptr,ULONG * mss)73 UINT _nx_tcp_socket_mss_get(NX_TCP_SOCKET *socket_ptr, ULONG *mss)
74 {
75
76 NX_IP *ip_ptr;
77
78
79 /* Setup IP pointer. */
80 ip_ptr = socket_ptr -> nx_tcp_socket_ip_ptr;
81
82 /* Obtain the IP mutex so we can examine the bound port. */
83 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
84
85 if (socket_ptr -> nx_tcp_socket_state < NX_TCP_ESTABLISHED)
86 {
87
88 /* The socket is not connected. */
89 if (socket_ptr -> nx_tcp_socket_mss)
90 {
91
92 /* Return custom MSS. */
93 *mss = socket_ptr -> nx_tcp_socket_mss;
94 }
95 else
96 {
97
98 /* Return default MSS. */
99 *mss = NX_TCP_MSS_SIZE;
100 }
101 }
102 else
103 {
104
105 /* Pickup SMSS value. */
106 *mss = socket_ptr -> nx_tcp_socket_connect_mss;
107 }
108
109 /* Release protection. */
110 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
111
112 /* If trace is enabled, insert this event into the trace buffer. */
113 NX_TRACE_IN_LINE_INSERT(NX_TRACE_TCP_SOCKET_MSS_GET, ip_ptr, socket_ptr, *mss, socket_ptr -> nx_tcp_socket_state, NX_TRACE_TCP_EVENTS, 0, 0);
114
115 /* Return successful completion status. */
116 return(NX_SUCCESS);
117 }
118
119