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_data_append                             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 data append           */
49 /*    function call.                                                      */
50 /*                                                                        */
51 /*  INPUT                                                                 */
52 /*                                                                        */
53 /*    packet_ptr                            Pointer to packet to append   */
54 /*    data_start                            Pointer to start of the data  */
55 /*    data_size                             Number of bytes to append     */
56 /*    pool_ptr                              Pool to allocate the packet   */
57 /*    wait_option                           Suspension option             */
58 /*                                                                        */
59 /*  OUTPUT                                                                */
60 /*                                                                        */
61 /*    status                                Completion status             */
62 /*                                                                        */
63 /*  CALLS                                                                 */
64 /*                                                                        */
65 /*    _nx_packet_data_append                Actual packet data append     */
66 /*                                            function                    */
67 /*                                                                        */
68 /*  CALLED BY                                                             */
69 /*                                                                        */
70 /*    Application Code                                                    */
71 /*                                                                        */
72 /*  RELEASE HISTORY                                                       */
73 /*                                                                        */
74 /*    DATE              NAME                      DESCRIPTION             */
75 /*                                                                        */
76 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
77 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
78 /*                                            resulting in version 6.1    */
79 /*                                                                        */
80 /**************************************************************************/
_nxe_packet_data_append(NX_PACKET * packet_ptr,VOID * data_start,ULONG data_size,NX_PACKET_POOL * pool_ptr,ULONG wait_option)81 UINT  _nxe_packet_data_append(NX_PACKET *packet_ptr, VOID *data_start, ULONG data_size,
82                               NX_PACKET_POOL *pool_ptr, ULONG wait_option)
83 {
84 
85 UINT status;
86 
87 
88     /* Check for invalid input pointers.  */
89     if ((pool_ptr == NX_NULL) || (pool_ptr -> nx_packet_pool_id != NX_PACKET_POOL_ID) ||
90         (packet_ptr == NX_NULL) || (data_start == NX_NULL))
91     {
92         return(NX_PTR_ERROR);
93     }
94 
95     /* Check for an invalid size of data to append.  */
96     if (!data_size)
97     {
98         return(NX_SIZE_ERROR);
99     }
100 
101     /* Check for an invalid packet prepend pointer.  */
102     /*lint -e{946} suppress pointer subtraction, since it is necessary. */
103     if (packet_ptr -> nx_packet_prepend_ptr < packet_ptr -> nx_packet_data_start)
104     {
105         return(NX_UNDERFLOW);
106     }
107 
108     /* Check for an invalid packet append pointer.  */
109     /*lint -e{946} suppress pointer subtraction, since it is necessary. */
110     if (packet_ptr -> nx_packet_append_ptr > packet_ptr -> nx_packet_data_end)
111     {
112         return(NX_OVERFLOW);
113     }
114 
115     /* Check for appropriate caller.  */
116     NX_THREAD_WAIT_CALLER_CHECKING
117 
118     /* Call actual packet data append function.  */
119     status =  _nx_packet_data_append(packet_ptr, data_start, data_size, pool_ptr, wait_option);
120 
121     /* Return completion status.  */
122     return(status);
123 }
124 
125