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