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 /* Bring in externs for caller checking code. */
31
32 NX_CALLER_CHECKING_EXTERNS
33
34
35 /**************************************************************************/
36 /* */
37 /* FUNCTION RELEASE */
38 /* */
39 /* _nxe_packet_data_append PORTABLE C */
40 /* 6.1 */
41 /* AUTHOR */
42 /* */
43 /* Yuxin Zhou, Microsoft Corporation */
44 /* */
45 /* DESCRIPTION */
46 /* */
47 /* This function checks for errors in the packet data append */
48 /* function call. */
49 /* */
50 /* INPUT */
51 /* */
52 /* packet_ptr Pointer to packet to append */
53 /* data_start Pointer to start of the data */
54 /* data_size Number of bytes to append */
55 /* pool_ptr Pool to allocate the packet */
56 /* wait_option Suspension option */
57 /* */
58 /* OUTPUT */
59 /* */
60 /* status Completion status */
61 /* */
62 /* CALLS */
63 /* */
64 /* _nx_packet_data_append Actual packet data append */
65 /* 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_data_append(NX_PACKET * packet_ptr,VOID * data_start,ULONG data_size,NX_PACKET_POOL * pool_ptr,ULONG wait_option)80 UINT _nxe_packet_data_append(NX_PACKET *packet_ptr, VOID *data_start, ULONG data_size,
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) || (data_start == NX_NULL))
90 {
91 return(NX_PTR_ERROR);
92 }
93
94 /* Check for an invalid size of data to append. */
95 if (!data_size)
96 {
97 return(NX_SIZE_ERROR);
98 }
99
100 /* Check for an invalid packet prepend pointer. */
101 /*lint -e{946} suppress pointer subtraction, since it is necessary. */
102 if (packet_ptr -> nx_packet_prepend_ptr < packet_ptr -> nx_packet_data_start)
103 {
104 return(NX_UNDERFLOW);
105 }
106
107 /* Check for an invalid packet append pointer. */
108 /*lint -e{946} suppress pointer subtraction, since it is necessary. */
109 if (packet_ptr -> nx_packet_append_ptr > packet_ptr -> nx_packet_data_end)
110 {
111 return(NX_OVERFLOW);
112 }
113
114 /* Check for appropriate caller. */
115 NX_THREAD_WAIT_CALLER_CHECKING
116
117 /* Call actual packet data append function. */
118 status = _nx_packet_data_append(packet_ptr, data_start, data_size, pool_ptr, wait_option);
119
120 /* Return completion status. */
121 return(status);
122 }
123
124