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 /**   Packet Pool Management (Packet)                                     */
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_packet.h"
29 
30 
31 #ifdef NX_ENABLE_PACKET_DEBUG_INFO
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_packet_debug_info_get                           PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function returns status of packet for specified index          */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    pool_ptr                              Pool to packet pool           */
49 /*    packet_index                          Index of packet in pool       */
50 /*    packet_pptr                           Pointer to packet for output  */
51 /*    packet_status                         Status of packet for output   */
52 /*    thread_info                           Thread of packet for output   */
53 /*    file_info                             File of packet for output     */
54 /*    line                                  Line of packet for output     */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    status                                Completion status             */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Application Code                                                    */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
72 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_nx_packet_debug_info_get(NX_PACKET_POOL * pool_ptr,UINT packet_index,NX_PACKET ** packet_pptr,ULONG * packet_status,CHAR ** thread_info,CHAR ** file_info,ULONG * line)76 UINT  _nx_packet_debug_info_get(NX_PACKET_POOL *pool_ptr, UINT packet_index, NX_PACKET **packet_pptr,
77                                 ULONG *packet_status, CHAR **thread_info, CHAR **file_info, ULONG *line)
78 {
79 ULONG      payload_size;    /* Rounded payload size       */
80 ULONG      header_size;     /* Rounded header size        */
81 NX_PACKET *packet_ptr;
82 
83     /* Get the first packet. */
84     packet_ptr = (NX_PACKET *)(pool_ptr -> nx_packet_pool_start);
85 
86     /* Calculate header size. */
87     header_size = (ULONG)((ALIGN_TYPE)(packet_ptr -> nx_packet_data_start) - (ALIGN_TYPE)packet_ptr);
88 
89     /* Round the packet size up to something that helps guarantee proper alignment for header and payload.  */
90     payload_size = (ULONG)(((pool_ptr -> nx_packet_pool_payload_size + header_size + NX_PACKET_ALIGNMENT  - 1) / NX_PACKET_ALIGNMENT) * NX_PACKET_ALIGNMENT - header_size);
91 
92     /* Calculate packet pointer. */
93     packet_ptr = (NX_PACKET *)(pool_ptr -> nx_packet_pool_start + packet_index * (header_size + payload_size));
94 
95     /* Get packet pointer. */
96     if (packet_pptr)
97     {
98         *packet_pptr = packet_ptr;
99     }
100 
101     /* Get packet status. */
102     if (packet_status)
103     {
104         *packet_status = (ULONG)(ALIGN_TYPE)packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next;
105     }
106 
107     /* Get thread info. */
108     if (thread_info)
109     {
110         *thread_info = packet_ptr -> nx_packet_debug_thread;
111     }
112 
113     /* Get file info. */
114     if (file_info)
115     {
116         *file_info = packet_ptr -> nx_packet_debug_file;
117     }
118 
119     /* Get line. */
120     if (line)
121     {
122         *line = packet_ptr -> nx_packet_debug_line;
123     }
124 
125     /* Return success. */
126     return(NX_SUCCESS);
127 }
128 #endif /* NX_ENABLE_PACKET_DEBUG_INFO */
129 
130