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 /**   Packet Pool Management (Packet)                                     */
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_packet.h"
31 
32 #ifdef FEATURE_NX_IPV6
33 #include "nx_ipv6.h"
34 #endif
35 
36 
37 /**************************************************************************/
38 /*                                                                        */
39 /*  FUNCTION                                               RELEASE        */
40 /*                                                                        */
41 /*    _nx_packet_transmit_release                         PORTABLE C      */
42 /*                                                           6.1          */
43 /*  AUTHOR                                                                */
44 /*                                                                        */
45 /*    Yuxin Zhou, Microsoft Corporation                                   */
46 /*                                                                        */
47 /*  DESCRIPTION                                                           */
48 /*                                                                        */
49 /*    This function releases a transmitted packet chain back to the       */
50 /*    appropriate packet pool.  If the packet is a TCP packet, it is      */
51 /*    simply marked as completed.  The actual release is deferred to      */
52 /*    the TCP component.                                                  */
53 /*                                                                        */
54 /*  INPUT                                                                 */
55 /*                                                                        */
56 /*    packet_ptr                            Pointer of packet to release  */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    status                                Completion status             */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    _nx_packet_release                    Release packet back to pool   */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    Application Code                                                    */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
75 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
76 /*                                            resulting in version 6.1    */
77 /*                                                                        */
78 /**************************************************************************/
_nx_packet_transmit_release(NX_PACKET * packet_ptr)79 UINT  _nx_packet_transmit_release(NX_PACKET *packet_ptr)
80 {
81 
82 TX_INTERRUPT_SAVE_AREA
83 
84 UINT status;
85 
86 
87     /* If trace is enabled, insert this event into the trace buffer.  */
88     NX_TRACE_IN_LINE_INSERT(NX_TRACE_PACKET_TRANSMIT_RELEASE, packet_ptr, packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next, (packet_ptr -> nx_packet_pool_owner) -> nx_packet_pool_available, 0, NX_TRACE_PACKET_EVENTS, 0, 0);
89 
90     /* Disable interrupts temporarily.  */
91     TX_DISABLE
92 
93     /* Add debug information. */
94     NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
95 
96     /* Determine if the packet is a queued TCP data packet.  Such packets cannot be released
97        immediately, since they may need to be resent.  */
98     /*lint -e{923} suppress cast of ULONG to pointer.  */
99     if ((packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next != ((NX_PACKET *)NX_PACKET_ALLOCATED)) &&
100         (packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next != ((NX_PACKET *)NX_PACKET_FREE)))
101     {
102 
103         /* Yes, this is indeed a TCP packet.  Just mark this with the NX_DRIVER_TX_DONE
104            value to let the TCP layer know it is no longer queued up.  */
105         /*lint -e{923} suppress cast of ULONG to pointer.  */
106         packet_ptr -> nx_packet_queue_next =  (NX_PACKET *)NX_DRIVER_TX_DONE;
107 
108         /* Remove the IP header and adjust the length.  */
109         packet_ptr -> nx_packet_prepend_ptr += packet_ptr -> nx_packet_ip_header_length;
110         packet_ptr -> nx_packet_length -= packet_ptr -> nx_packet_ip_header_length;
111 
112         /* Reset the IP header length. */
113         packet_ptr -> nx_packet_ip_header_length = 0;
114 
115         /* Restore interrupts.  */
116         TX_RESTORE
117 
118         /* Return success.  */
119         status =  NX_SUCCESS;
120     }
121     else
122     {
123 
124         /* Restore interrupts.  */
125         TX_RESTORE
126 
127         /* Call the actual packet release function.  */
128         status =  _nx_packet_release(packet_ptr);
129     }
130 
131     /* Return completion status.  */
132     return(status);
133 }
134 
135