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 /* Bring in externs for caller checking code.  */
32 
33 NX_CALLER_CHECKING_EXTERNS
34 
35 
36 /**************************************************************************/
37 /*                                                                        */
38 /*  FUNCTION                                               RELEASE        */
39 /*                                                                        */
40 /*    _nxe_packet_copy                                    PORTABLE C      */
41 /*                                                           6.1          */
42 /*  AUTHOR                                                                */
43 /*                                                                        */
44 /*    Yuxin Zhou, Microsoft Corporation                                   */
45 /*                                                                        */
46 /*  DESCRIPTION                                                           */
47 /*                                                                        */
48 /*    This function checks for errors in the packet copy                  */
49 /*    function call.                                                      */
50 /*                                                                        */
51 /*  INPUT                                                                 */
52 /*                                                                        */
53 /*    packet_ptr                            Pointer to source packet      */
54 /*    new_packet_ptr                        Pointer to return packet      */
55 /*    pool_ptr                              Pointer to packet pool to use */
56 /*                                            for new packet(s)           */
57 /*    wait_option                           Suspension option             */
58 /*                                                                        */
59 /*  OUTPUT                                                                */
60 /*                                                                        */
61 /*    status                                Completion status             */
62 /*                                                                        */
63 /*  CALLS                                                                 */
64 /*                                                                        */
65 /*    _nx_packet_copy                       Actual packet copy function   */
66 /*                                                                        */
67 /*  CALLED BY                                                             */
68 /*                                                                        */
69 /*    Application Code                                                    */
70 /*                                                                        */
71 /*  RELEASE HISTORY                                                       */
72 /*                                                                        */
73 /*    DATE              NAME                      DESCRIPTION             */
74 /*                                                                        */
75 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
76 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
77 /*                                            resulting in version 6.1    */
78 /*                                                                        */
79 /**************************************************************************/
_nxe_packet_copy(NX_PACKET * packet_ptr,NX_PACKET ** new_packet_ptr,NX_PACKET_POOL * pool_ptr,ULONG wait_option)80 UINT  _nxe_packet_copy(NX_PACKET *packet_ptr, NX_PACKET **new_packet_ptr,
81                        NX_PACKET_POOL *pool_ptr, ULONG wait_option)
82 {
83 
84 UINT status;
85 
86 
87     /* Check for invalid input pointers.  */
88     if ((pool_ptr == NX_NULL) || (pool_ptr -> nx_packet_pool_id != NX_PACKET_POOL_ID) ||
89         (packet_ptr == NX_NULL) || (new_packet_ptr == NX_NULL))
90     {
91         return(NX_PTR_ERROR);
92     }
93 
94     /* Check for an invalid packet prepend pointer.  */
95     /*lint -e{946} suppress pointer subtraction, since it is necessary. */
96     if (packet_ptr -> nx_packet_prepend_ptr < packet_ptr -> nx_packet_data_start)
97     {
98         return(NX_UNDERFLOW);
99     }
100 
101     /* Check for an invalid packet append pointer.  */
102     /*lint -e{946} suppress pointer subtraction, since it is necessary. */
103     if (packet_ptr -> nx_packet_append_ptr > packet_ptr -> nx_packet_data_end)
104     {
105         return(NX_OVERFLOW);
106     }
107 
108     /* Check for appropriate caller.  */
109     NX_THREAD_WAIT_CALLER_CHECKING
110 
111     /* Call actual packet copy function.  */
112     status =  _nx_packet_copy(packet_ptr, new_packet_ptr, pool_ptr, wait_option);
113 
114     /* Return completion status.  */
115     return(status);
116 }
117 
118