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 /* Bring in externs for caller checking code. */
32
33 NX_CALLER_CHECKING_EXTERNS
34
35
36 /**************************************************************************/
37 /* */
38 /* FUNCTION RELEASE */
39 /* */
40 /* _nxe_packet_allocate 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 allocate function */
49 /* call. */
50 /* */
51 /* INPUT */
52 /* */
53 /* pool_ptr Pool to allocate the packet */
54 /* packet_ptr Pointer to place allocated */
55 /* packet pointer */
56 /* packet_type Type of packet to allocate */
57 /* wait_option Suspension option */
58 /* */
59 /* OUTPUT */
60 /* */
61 /* status Completion status */
62 /* */
63 /* CALLS */
64 /* */
65 /* _nx_packet_allocate Actual packet allocate service*/
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_allocate(NX_PACKET_POOL * pool_ptr,NX_PACKET ** packet_ptr,ULONG packet_type,ULONG wait_option)80 UINT _nxe_packet_allocate(NX_PACKET_POOL *pool_ptr, NX_PACKET **packet_ptr,
81 ULONG packet_type, 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) || (packet_ptr == NX_NULL))
89 {
90 return(NX_PTR_ERROR);
91 }
92
93 /* Check for an invalid packet type - for alignment purposes, it must be evenly divisible by the size
94 of a ULONG. */
95 if (packet_type % sizeof(ULONG))
96 {
97 return(NX_OPTION_ERROR);
98 }
99
100 /* Check for a thread caller if the wait option specifies suspension. */
101 NX_THREAD_WAIT_CALLER_CHECKING
102
103 /* Call actual packet allocate function. */
104 status = _nx_packet_allocate(pool_ptr, packet_ptr, packet_type, wait_option);
105
106 /* Return completion status. */
107 return(status);
108 }
109
110