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 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _nx_tcp_queue_process                               PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Yuxin Zhou, Microsoft Corporation                                   */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function processes the TCP receive packet queue.               */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    ip_ptr                                Pointer to IP control block   */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    None                                                                */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    _nx_tcp_packet_process                Process TCP packet            */
56 /*                                                                        */
57 /*  CALLED BY                                                             */
58 /*                                                                        */
59 /*    _nx_ip_thread_entry                   IP helper thread processing   */
60 /*                                                                        */
61 /*  RELEASE HISTORY                                                       */
62 /*                                                                        */
63 /*    DATE              NAME                      DESCRIPTION             */
64 /*                                                                        */
65 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
66 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
67 /*                                            resulting in version 6.1    */
68 /*                                                                        */
69 /**************************************************************************/
_nx_tcp_queue_process(NX_IP * ip_ptr)70 VOID  _nx_tcp_queue_process(NX_IP *ip_ptr)
71 {
72 
73 TX_INTERRUPT_SAVE_AREA
74 
75 NX_PACKET *queue_head;
76 NX_PACKET *packet_ptr;
77 
78 
79     /* Disable interrupts.  */
80     TX_DISABLE
81 
82     /* Remove the TCP message queue from the IP structure.  */
83     queue_head =  ip_ptr -> nx_ip_tcp_queue_head;
84     ip_ptr -> nx_ip_tcp_queue_head =  NX_NULL;
85     ip_ptr -> nx_ip_tcp_queue_tail =  NX_NULL;
86     ip_ptr -> nx_ip_tcp_received_packet_count =  0;
87 
88     /* Restore interrupts.  */
89     TX_RESTORE
90 
91     /* Walk through the entire TCP message queue and process packets
92        one by one.  */
93     while (queue_head)
94     {
95 
96         /* Pickup the first queue TCP message and remove it from the
97            TCP queue.  */
98         packet_ptr =  queue_head;
99         queue_head =  queue_head -> nx_packet_queue_next;
100         packet_ptr -> nx_packet_queue_next =  NX_NULL;
101 
102         /* Add debug information. */
103         NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
104 
105         /* Process the packet.  */
106         _nx_tcp_packet_process(ip_ptr, packet_ptr);
107     }
108 }
109 
110