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_peer_get                         PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function retrieves TCP Maximum Segment Size (MSS) of the       */
45 /*    peer connected to the specified TCP socket.                         */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    socket_ptr                            Pointer to the TCP socket     */
50 /*    peer_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_peer_get(NX_TCP_SOCKET * socket_ptr,ULONG * peer_mss)74 UINT  _nx_tcp_socket_mss_peer_get(NX_TCP_SOCKET *socket_ptr, ULONG *peer_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     /* If trace is enabled, insert this event into the trace buffer.  */
84     NX_TRACE_IN_LINE_INSERT(NX_TRACE_TCP_SOCKET_MSS_PEER_GET, ip_ptr, socket_ptr, socket_ptr -> nx_tcp_socket_peer_mss, socket_ptr -> nx_tcp_socket_state, NX_TRACE_TCP_EVENTS, 0, 0);
85 
86     /* Obtain the IP mutex so we can examine the bound port.  */
87     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
88 
89     /* Pickup socket's peer MSS value.  */
90     *peer_mss =  socket_ptr -> nx_tcp_socket_peer_mss;
91 
92     /* Release protection.  */
93     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
94 
95     /* Return successful completion status.  */
96     return(NX_SUCCESS);
97 }
98 
99