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