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