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 #include "nx_ipv6.h" 30 31 /**************************************************************************/ 32 /* */ 33 /* FUNCTION RELEASE */ 34 /* */ 35 /* _nx_tcp_socket_state_last_ack PORTABLE C */ 36 /* 6.1 */ 37 /* AUTHOR */ 38 /* */ 39 /* Yuxin Zhou, Microsoft Corporation */ 40 /* */ 41 /* DESCRIPTION */ 42 /* */ 43 /* This function processes packets during the LAST ACK state, */ 44 /* which is the state at the end of a passive disconnect, i.e. a */ 45 /* disconnect issued by the other side of the connection. */ 46 /* */ 47 /* INPUT */ 48 /* */ 49 /* socket_ptr Pointer to owning socket */ 50 /* tcp_header_ptr Pointer to packet header */ 51 /* */ 52 /* OUTPUT */ 53 /* */ 54 /* None */ 55 /* */ 56 /* CALLS */ 57 /* */ 58 /* _nx_tcp_socket_thread_resume Resume suspended thread */ 59 /* _nx_tcp_socket_block_cleanup Cleanup the socket block */ 60 /* */ 61 /* CALLED BY */ 62 /* */ 63 /* _nx_tcp_socket_packet_process Process TCP packet for socket */ 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_state_last_ack(NX_TCP_SOCKET * socket_ptr,NX_TCP_HEADER * tcp_header_ptr)74VOID _nx_tcp_socket_state_last_ack(NX_TCP_SOCKET *socket_ptr, NX_TCP_HEADER *tcp_header_ptr) 75 { 76 77 /* Determine if the incoming message is an ACK message. */ 78 if (tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_ACK_BIT) 79 { 80 81 /* If it is proper, finish the disconnect. */ 82 if ((tcp_header_ptr -> nx_tcp_acknowledgment_number == socket_ptr -> nx_tcp_socket_tx_sequence) && 83 (tcp_header_ptr -> nx_tcp_sequence_number == socket_ptr -> nx_tcp_socket_rx_sequence)) 84 { 85 86 /* Cleanup the transmission control block. */ 87 _nx_tcp_socket_block_cleanup(socket_ptr); 88 89 /* Determine if we need to wake a thread suspended on the disconnection. */ 90 if (socket_ptr -> nx_tcp_socket_disconnect_suspended_thread) 91 { 92 93 /* Resume suspended thread. */ 94 _nx_tcp_socket_thread_resume(&(socket_ptr -> nx_tcp_socket_disconnect_suspended_thread), NX_SUCCESS); 95 } 96 97 #ifndef NX_DISABLE_EXTENDED_NOTIFY_SUPPORT 98 99 /* Is a disconnect callback registered with the TCP socket? */ 100 if (socket_ptr -> nx_tcp_disconnect_complete_notify) 101 { 102 103 /* Call the application's disconnect_complete callback function. */ 104 (socket_ptr -> nx_tcp_disconnect_complete_notify)(socket_ptr); 105 } 106 #endif 107 } 108 } 109 } 110 111