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