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_ip.h"
30 #include "nx_tcp.h"
31 #include "nx_ipv6.h"
32 
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _nx_tcp_socket_mss_set                              PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Yuxin Zhou, Microsoft Corporation                                   */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function sets the TCP Maximum Segment Size (MSS) for the       */
47 /*    specified TCP socket.                                               */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    socket_ptr                            Pointer to the TCP socket     */
52 /*    mss                                   New value for the MSS         */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    status                                Completion status             */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    tx_mutex_get                          Obtain protection             */
61 /*    tx_mutex_put                          Release protection            */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Application Code                                                    */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
72 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_nx_tcp_socket_mss_set(NX_TCP_SOCKET * socket_ptr,ULONG mss)76 UINT  _nx_tcp_socket_mss_set(NX_TCP_SOCKET *socket_ptr, ULONG mss)
77 {
78 
79 NX_IP *ip_ptr;
80 UINT status;
81 
82     /* Setup IP pointer.  */
83     ip_ptr =  socket_ptr -> nx_tcp_socket_ip_ptr;
84 
85     if (mss == 0)
86     {
87 
88         /* Invalid MSS, return an error.  */
89         return(NX_SIZE_ERROR);
90     }
91 
92     /* Obtain the IP mutex so we can examine the bound port.  */
93     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
94 
95     if (socket_ptr -> nx_tcp_socket_state < NX_TCP_SYN_SENT)
96     {
97 
98         /* Set the socket's MSS value.  */
99         socket_ptr -> nx_tcp_socket_mss =  mss;
100         status = NX_SUCCESS;
101     }
102     else
103     {
104 
105         /* MSS can not be modified when connection is started. */
106         status = NX_NOT_SUCCESSFUL;
107     }
108 
109     /* Release protection.  */
110     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
111 
112     /* Return successful completion status.  */
113     return(status);
114 }
115 
116