]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Include/Library/UdpIoLib.h
Fixing coding style issue.
[mirror_edk2.git] / MdeModulePkg / Include / Library / UdpIoLib.h
CommitLineData
97b38d4e 1/** @file\r
e4b99ad9
LG
2 Ihis library is only intended to be used by UEFI network stack modules.\r
3 It provides the helper routines to access UDP service. It is used by both DHCP and MTFTP.\r
97b38d4e 4\r
cab450cc 5Copyright (c) 2006 - 2008, Intel Corporation.<BR>\r
97b38d4e 6All rights reserved. This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
cab450cc 8which accompanies this distribution. The full text of the license may be found at<BR>\r
97b38d4e 9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#ifndef _UDP4IO_H_\r
17#define _UDP4IO_H_\r
18\r
19#include <Protocol/Udp4.h>\r
20\r
21#include <Library/UdpIoLib.h>\r
22#include <Library/NetLib.h>\r
23\r
24typedef struct _UDP_IO_PORT UDP_IO_PORT;\r
25\r
cab450cc 26///\r
27/// Signatures used by UdpIo Library.\r
28///\r
97b38d4e 29typedef enum {\r
f3f2e05d 30 UDP_IO_RX_SIGNATURE = SIGNATURE_32 ('U', 'D', 'P', 'R'),\r
31 UDP_IO_TX_SIGNATURE = SIGNATURE_32 ('U', 'D', 'P', 'T'),\r
32 UDP_IO_SIGNATURE = SIGNATURE_32 ('U', 'D', 'P', 'I')\r
97b38d4e 33} UDP_IO_SIGNATURE_TYPE;\r
34\r
cab450cc 35///\r
36/// The Udp4 address pair.\r
37///\r
97b38d4e 38typedef struct {\r
39 IP4_ADDR LocalAddr;\r
40 UINT16 LocalPort;\r
41 IP4_ADDR RemoteAddr;\r
42 UINT16 RemotePort;\r
43} UDP_POINTS;\r
44\r
cab450cc 45/**\r
46 Prototype called when receiving or sending packets from/to a UDP point.\r
47\r
48 This prototype is used by both receive and sending when calling\r
ca9d3a9d 49 UdpIoRecvDatagram() or UdpIoSendDatagram(). When receiving, Netbuf is allocated by\r
cab450cc 50 UDP access point, and released by user. When sending, the NetBuf is from user,\r
51 and provided to the callback as a reference.\r
52 \r
3a1ab4bc 53 @param[in] Packet Packet received or sent\r
54 @param[in] Points The Udp4 address pair corresponds to the Udp4 IO\r
55 @param[in] IoStatus Packet receiving or sending status\r
56 @param[in] Context User-defined data when calling UdpIoRecvDatagram() or\r
57 UdpIoSendDatagram()\r
cab450cc 58**/\r
97b38d4e 59typedef\r
60VOID\r
99fd6031 61(*UDP_IO_CALLBACK) (\r
97b38d4e 62 IN NET_BUF *Packet,\r
63 IN UDP_POINTS *Points,\r
64 IN EFI_STATUS IoStatus,\r
65 IN VOID *Context\r
66 );\r
67\r
cab450cc 68///\r
69/// This structure is used internally by UdpIo Library.\r
70///\r
71/// Each receive request is wrapped in an UDP_RX_TOKEN. Upon completion,\r
72/// the CallBack will be called. Only one receive request is sent to UDP at a\r
73/// time. HeadLen gives the length of the application's header. UDP_IO will\r
74/// make the application's header continuous before delivering up.\r
75///\r
97b38d4e 76typedef struct {\r
77 UINT32 Signature;\r
78 UDP_IO_PORT *UdpIo;\r
79\r
80 UDP_IO_CALLBACK CallBack;\r
81 VOID *Context;\r
82\r
83 UINT32 HeadLen;\r
84 EFI_UDP4_COMPLETION_TOKEN UdpToken;\r
85} UDP_RX_TOKEN;\r
86\r
cab450cc 87///\r
88/// This structure is used internally by UdpIo Library.\r
89///\r
90/// Each transmit request is wrapped in an UDP_TX_TOKEN. Upon completion,\r
91/// the CallBack will be called. There can be several transmit requests and they\r
92/// are linked in a list.\r
93///\r
97b38d4e 94typedef struct {\r
95 UINT32 Signature;\r
96 LIST_ENTRY Link;\r
97 UDP_IO_PORT *UdpIo;\r
98\r
99 UDP_IO_CALLBACK CallBack;\r
100 NET_BUF *Packet;\r
101 VOID *Context;\r
102\r
103 EFI_UDP4_SESSION_DATA UdpSession;\r
104 EFI_IPv4_ADDRESS Gateway;\r
105\r
106 EFI_UDP4_COMPLETION_TOKEN UdpToken;\r
107 EFI_UDP4_TRANSMIT_DATA UdpTxData;\r
108} UDP_TX_TOKEN;\r
109\r
cab450cc 110///\r
111/// Type defined as UDP_IO_PORT.\r
112///\r
113/// The data structure wraps Udp4 instance and its configuration. It is used by\r
114/// UdpIo Library to do all Udp4 operations.\r
115///\r
97b38d4e 116struct _UDP_IO_PORT {\r
117 UINT32 Signature;\r
118 LIST_ENTRY Link;\r
119 INTN RefCnt;\r
120\r
121 //\r
122 // Handle used to create/destory UDP child\r
123 //\r
124 EFI_HANDLE Controller;\r
125 EFI_HANDLE Image;\r
126 EFI_HANDLE UdpHandle;\r
127\r
cab450cc 128 EFI_UDP4_PROTOCOL *Udp; ///< The wrapped Udp4 instance.\r
97b38d4e 129 EFI_UDP4_CONFIG_DATA UdpConfig;\r
130 EFI_SIMPLE_NETWORK_MODE SnpMode;\r
131\r
cab450cc 132 LIST_ENTRY SentDatagram; ///< A list of UDP_TX_TOKEN.\r
97b38d4e 133 UDP_RX_TOKEN *RecvRequest;\r
134};\r
135\r
cab450cc 136/**\r
137 Prototype called when UdpIo Library configures a Udp4 instance.\r
138 \r
ca9d3a9d 139 The prototype is set and called when creating a UDP_IO_PORT in UdpIoCreatePort().\r
cab450cc 140 \r
3a1ab4bc 141 @param[in] UdpIo The UDP_IO_PORT to configure\r
142 @param[in] Context User-defined data when calling UdpIoCreatePort()\r
cab450cc 143 \r
144 @retval EFI_SUCCESS The configure process succeeds\r
145 @retval Others The UDP_IO_PORT fails to configure indicating\r
ca9d3a9d 146 UdpIoCreatePort() should fail\r
cab450cc 147**/\r
97b38d4e 148typedef\r
149EFI_STATUS\r
99fd6031 150(*UDP_IO_CONFIG) (\r
97b38d4e 151 IN UDP_IO_PORT *UdpIo,\r
152 IN VOID *Context\r
153 );\r
154\r
cab450cc 155/**\r
3a1ab4bc 156 The select function to decide whether to cancel the UDP_TX_TOKEN. \r
cab450cc 157 \r
3a1ab4bc 158 @param[in] Token The UDP_TX_TOKEN to decide whether to cancel\r
159 @param[in] Context User-defined data in UdpIoCancelDgrams()\r
cab450cc 160 \r
161 @retval TRUE To cancel the UDP_TX_TOKEN\r
162 @retval FALSE Do not cancel this UDP_TX_TOKEN\r
163\r
164**/\r
97b38d4e 165typedef\r
166BOOLEAN\r
167(*UDP_IO_TO_CANCEL) (\r
168 IN UDP_TX_TOKEN *Token,\r
169 IN VOID *Context\r
170 );\r
171\r
e4b99ad9
LG
172/**\r
173 Cancel all the sent datagram that pass the selection criteria of ToCancel.\r
174 If ToCancel is NULL, all the datagrams are cancelled.\r
175\r
176 @param[in] UdpIo The UDP_IO_PORT to cancel packet.\r
177 @param[in] IoStatus The IoStatus to return to the packet owners.\r
178 @param[in] ToCancel The select funtion to test whether to cancel this\r
179 packet or not.\r
180 @param[in] Context The opaque parameter to the ToCancel.\r
181\r
182**/\r
183VOID\r
184EFIAPI\r
185UdpIoCancelDgrams (\r
186 IN UDP_IO_PORT *UdpIo,\r
187 IN EFI_STATUS IoStatus,\r
188 IN UDP_IO_TO_CANCEL ToCancel, OPTIONAL\r
189 IN VOID *Context\r
190 );\r
191\r
97b38d4e 192/**\r
cab450cc 193 Create a UDP_IO_PORT to access the UDP service. It will create and configure\r
194 a UDP child.\r
195 \r
196 The function will locate the UDP service binding prototype on the Controller\r
197 parameter and use it to create a UDP child (aka Udp instance). Then the UDP\r
198 child will be configured by calling Configure function prototype. Any failures\r
199 in creating or configure the UDP child will lead to the failure of UDP_IO_PORT\r
200 creation.\r
97b38d4e 201\r
3a1ab4bc 202 @param[in] Controller The controller that has the UDP service binding.\r
203 protocol installed.\r
204 @param[in] Image The image handle for the driver.\r
205 @param[in] Configure The function to configure the created UDP child.\r
206 @param[in] Context The opaque parameter for the Configure funtion.\r
97b38d4e 207\r
cab450cc 208 @return Newly-created UDP_IO_PORT or NULL if failed.\r
97b38d4e 209\r
210**/\r
211UDP_IO_PORT *\r
212EFIAPI\r
213UdpIoCreatePort (\r
214 IN EFI_HANDLE Controller,\r
c3a78fc8 215 IN EFI_HANDLE Image,\r
97b38d4e 216 IN UDP_IO_CONFIG Configure,\r
217 IN VOID *Context\r
218 );\r
219\r
220/**\r
cab450cc 221 Free the UDP_IO_PORT and all its related resources.\r
222 \r
223 The function will cancel all sent datagram and receive request.\r
97b38d4e 224\r
3a1ab4bc 225 @param[in] UdpIo The UDP_IO_PORT to free.\r
97b38d4e 226\r
cab450cc 227 @retval EFI_SUCCESS The UDP_IO_PORT is freed.\r
97b38d4e 228\r
229**/\r
230EFI_STATUS\r
231EFIAPI\r
232UdpIoFreePort (\r
233 IN UDP_IO_PORT *UdpIo\r
234 );\r
235\r
236/**\r
cab450cc 237 Clean up the UDP_IO_PORT without freeing it. The function is called when\r
238 user wants to re-use the UDP_IO_PORT later.\r
239 \r
240 It will release all the transmitted datagrams and receive request. It will\r
241 also configure NULL for the UDP instance.\r
97b38d4e 242\r
3a1ab4bc 243 @param[in] UdpIo The UDP_IO_PORT to clean up.\r
97b38d4e 244\r
97b38d4e 245**/\r
246VOID\r
247EFIAPI\r
248UdpIoCleanPort (\r
249 IN UDP_IO_PORT *UdpIo\r
250 );\r
251\r
252/**\r
cab450cc 253 Send a packet through the UDP_IO_PORT.\r
254 \r
255 The packet will be wrapped in UDP_TX_TOKEN. Function Callback will be called\r
256 when the packet is sent. The optional parameter EndPoint overrides the default\r
257 address pair if specified.\r
97b38d4e 258\r
3a1ab4bc 259 @param[in] UdpIo The UDP_IO_PORT to send the packet through.\r
260 @param[in] Packet The packet to send.\r
261 @param[in] EndPoint The local and remote access point. Override the\r
262 default address pair set during configuration.\r
263 @param[in] Gateway The gateway to use.\r
264 @param[in] CallBack The function being called when packet is\r
265 transmitted or failed.\r
266 @param[in] Context The opaque parameter passed to CallBack.\r
97b38d4e 267\r
3a1ab4bc 268 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the packet.\r
97b38d4e 269 @retval EFI_SUCCESS The packet is successfully delivered to UDP for\r
270 transmission.\r
271\r
272**/\r
273EFI_STATUS\r
274EFIAPI\r
275UdpIoSendDatagram (\r
276 IN UDP_IO_PORT *UdpIo,\r
277 IN NET_BUF *Packet,\r
3a1ab4bc 278 IN UDP_POINTS *EndPoint, OPTIONAL\r
97b38d4e 279 IN IP4_ADDR Gateway,\r
280 IN UDP_IO_CALLBACK CallBack,\r
281 IN VOID *Context\r
282 );\r
283\r
284/**\r
285 Cancel a single sent datagram.\r
286\r
3a1ab4bc 287 @param[in] UdpIo The UDP_IO_PORT to cancel the packet from\r
288 @param[in] Packet The packet to cancel\r
97b38d4e 289\r
97b38d4e 290**/\r
291VOID\r
292EFIAPI\r
293UdpIoCancelSentDatagram (\r
294 IN UDP_IO_PORT *UdpIo,\r
295 IN NET_BUF *Packet\r
296 );\r
297\r
298/**\r
cab450cc 299 Issue a receive request to the UDP_IO_PORT.\r
300 \r
301 This function is called when upper-layer needs packet from UDP for processing.\r
302 Only one receive request is acceptable at a time so a common usage model is\r
303 to invoke this function inside its Callback function when the former packet\r
304 is processed.\r
305\r
3a1ab4bc 306 @param[in] UdpIo The UDP_IO_PORT to receive the packet from.\r
307 @param[in] CallBack The call back function to execute when the packet\r
308 is received.\r
309 @param[in] Context The opaque context passed to Callback.\r
310 @param[in] HeadLen The length of the upper-layer's protocol header.\r
97b38d4e 311\r
312 @retval EFI_ALREADY_STARTED There is already a pending receive request. Only\r
cab450cc 313 one receive request is supported at a time.\r
314 @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.\r
97b38d4e 315 @retval EFI_SUCCESS The receive request is issued successfully.\r
316\r
317**/\r
318EFI_STATUS\r
319EFIAPI\r
320UdpIoRecvDatagram (\r
321 IN UDP_IO_PORT *UdpIo,\r
322 IN UDP_IO_CALLBACK CallBack,\r
323 IN VOID *Context,\r
324 IN UINT32 HeadLen\r
325 );\r
326#endif\r