]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Include/Library/UdpIoLib.h
NetworkPkg: Apply uncrustify changes
[mirror_edk2.git] / NetworkPkg / Include / Library / UdpIoLib.h
CommitLineData
97b38d4e 1/** @file\r
e9b67286 2 This library is used to share code between UEFI network stack modules.\r
e4b99ad9 3 It provides the helper routines to access UDP service. It is used by both DHCP and MTFTP.\r
97b38d4e 4\r
6d88babb 5Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 6SPDX-License-Identifier: BSD-2-Clause-Patent\r
97b38d4e 7\r
8**/\r
9\r
b45b45b2 10#ifndef _UDP_IO_H_\r
11#define _UDP_IO_H_\r
97b38d4e 12\r
13#include <Protocol/Udp4.h>\r
b45b45b2 14#include <Protocol/Udp6.h>\r
97b38d4e 15\r
97b38d4e 16#include <Library/NetLib.h>\r
17\r
b45b45b2 18typedef struct _UDP_IO UDP_IO;\r
97b38d4e 19\r
cab450cc 20///\r
21/// Signatures used by UdpIo Library.\r
22///\r
b45b45b2 23\r
24#define UDP_IO_RX_SIGNATURE SIGNATURE_32 ('U', 'D', 'P', 'R')\r
25#define UDP_IO_TX_SIGNATURE SIGNATURE_32 ('U', 'D', 'P', 'T')\r
26#define UDP_IO_SIGNATURE SIGNATURE_32 ('U', 'D', 'P', 'I')\r
27\r
28#define UDP_IO_UDP4_VERSION 4\r
29#define UDP_IO_UDP6_VERSION 6\r
97b38d4e 30\r
cab450cc 31///\r
b45b45b2 32/// The UDP address pair.\r
cab450cc 33///\r
97b38d4e 34typedef struct {\r
d1050b9d
MK
35 EFI_IP_ADDRESS LocalAddr;\r
36 UINT16 LocalPort;\r
37 EFI_IP_ADDRESS RemoteAddr;\r
38 UINT16 RemotePort;\r
b45b45b2 39} UDP_END_POINT;\r
97b38d4e 40\r
cab450cc 41/**\r
e9b67286 42 Prototype called when receiving or sending packets to or from a UDP point.\r
cab450cc 43\r
44 This prototype is used by both receive and sending when calling\r
e9b67286 45 UdpIoRecvDatagram() or UdpIoSendDatagram(). When receiving, Netbuf is allocated by the\r
6deb4baa 46 UDP access point and released by the user. When sending, the user allocates the NetBuf,\r
64a80549 47 which is then provided to the callback as a reference.\r
48\r
49 @param[in] Packet The packet received or sent.\r
50 @param[in] EndPoint The UDP address pair corresponds to the UDP IO.\r
51 @param[in] IoStatus The packet receiving or sending status.\r
52 @param[in] Context The user-defined data when calling UdpIoRecvDatagram() or\r
53 UdpIoSendDatagram().\r
cab450cc 54**/\r
97b38d4e 55typedef\r
56VOID\r
d1050b9d 57(EFIAPI *UDP_IO_CALLBACK)(\r
97b38d4e 58 IN NET_BUF *Packet,\r
b45b45b2 59 IN UDP_END_POINT *EndPoint,\r
97b38d4e 60 IN EFI_STATUS IoStatus,\r
61 IN VOID *Context\r
62 );\r
63\r
cab450cc 64///\r
e9b67286 65/// This structure is used internally by the UdpIo Library.\r
cab450cc 66///\r
67/// Each receive request is wrapped in an UDP_RX_TOKEN. Upon completion,\r
68/// the CallBack will be called. Only one receive request is sent to UDP at a\r
69/// time. HeadLen gives the length of the application's header. UDP_IO will\r
70/// make the application's header continuous before delivering up.\r
71///\r
b45b45b2 72typedef union {\r
d1050b9d
MK
73 EFI_UDP4_COMPLETION_TOKEN Udp4;\r
74 EFI_UDP6_COMPLETION_TOKEN Udp6;\r
b45b45b2 75} UDP_COMPLETION_TOKEN;\r
76\r
97b38d4e 77typedef struct {\r
d1050b9d
MK
78 UINT32 Signature;\r
79 UDP_IO *UdpIo;\r
97b38d4e 80\r
d1050b9d
MK
81 UDP_IO_CALLBACK CallBack;\r
82 VOID *Context;\r
83 UINT32 HeadLen;\r
97b38d4e 84\r
d1050b9d 85 UDP_COMPLETION_TOKEN Token;\r
97b38d4e 86} UDP_RX_TOKEN;\r
87\r
cab450cc 88///\r
89/// This structure is used internally by UdpIo Library.\r
90///\r
91/// Each transmit request is wrapped in an UDP_TX_TOKEN. Upon completion,\r
d1102dba 92/// the CallBack will be called. There can be several transmit requests. All transmit\r
64a80549 93/// requests are linked in a list.\r
cab450cc 94///\r
97b38d4e 95\r
b45b45b2 96typedef union {\r
d1050b9d
MK
97 EFI_UDP4_SESSION_DATA Udp4;\r
98 EFI_UDP6_SESSION_DATA Udp6;\r
b45b45b2 99} UDP_SESSION_DATA;\r
97b38d4e 100\r
b45b45b2 101typedef union {\r
d1050b9d
MK
102 EFI_UDP4_TRANSMIT_DATA Udp4;\r
103 EFI_UDP6_TRANSMIT_DATA Udp6;\r
b45b45b2 104} UDP_TRANSMIT_DATA;\r
97b38d4e 105\r
b45b45b2 106typedef struct {\r
d1050b9d
MK
107 UINT32 Signature;\r
108 LIST_ENTRY Link;\r
109 UDP_IO *UdpIo;\r
110 UDP_IO_CALLBACK CallBack;\r
111 NET_BUF *Packet;\r
112 VOID *Context;\r
113 EFI_IPv4_ADDRESS Gateway;\r
114 UDP_SESSION_DATA Session;\r
115 UDP_COMPLETION_TOKEN Token;\r
116 UDP_TRANSMIT_DATA Data;\r
97b38d4e 117} UDP_TX_TOKEN;\r
118\r
cab450cc 119///\r
b45b45b2 120/// Type defined as UDP_IO.\r
cab450cc 121///\r
e2851998 122/// This data structure wraps the UDP instance and configuration.\r
b45b45b2 123/// UdpIo Library uses this structure for all Udp4 or Udp6 operations.\r
cab450cc 124///\r
b45b45b2 125struct _UDP_IO {\r
d1050b9d
MK
126 UINT32 Signature;\r
127 LIST_ENTRY Link;\r
128 INTN RefCnt;\r
129 UINT8 UdpVersion;\r
97b38d4e 130\r
131 //\r
75dce340 132 // Handle used to create/destroy UDP child\r
97b38d4e 133 //\r
d1050b9d
MK
134 EFI_HANDLE Controller;\r
135 EFI_HANDLE Image;\r
136 EFI_HANDLE UdpHandle;\r
97b38d4e 137\r
d1050b9d 138 EFI_SIMPLE_NETWORK_MODE SnpMode;\r
97b38d4e 139\r
d1050b9d
MK
140 LIST_ENTRY SentDatagram; ///< A list of UDP_TX_TOKEN.\r
141 UDP_RX_TOKEN *RecvRequest;\r
b45b45b2 142\r
143 union {\r
d1050b9d
MK
144 EFI_UDP4_PROTOCOL *Udp4;\r
145 EFI_UDP6_PROTOCOL *Udp6;\r
e2851998 146 } Protocol;\r
b45b45b2 147\r
148 union {\r
149 EFI_UDP4_CONFIG_DATA Udp4;\r
150 EFI_UDP6_CONFIG_DATA Udp6;\r
151 } Config;\r
97b38d4e 152};\r
153\r
cab450cc 154/**\r
64a80549 155 The prototype called when UdpIo Library configures a UDP instance.\r
e2851998 156\r
b45b45b2 157 The prototype is set and called when creating a UDP_IO in UdpIoCreatePort().\r
e2851998 158\r
64a80549 159 @param[in] UdpIo The UDP_IO to configure.\r
160 @param[in] Context The user-defined data when calling UdpIoCreatePort().\r
e2851998 161\r
64a80549 162 @retval EFI_SUCCESS The configuration succeeded.\r
b45b45b2 163 @retval Others The UDP_IO fails to configure indicating\r
64a80549 164 UdpIoCreatePort() should fail.\r
cab450cc 165**/\r
97b38d4e 166typedef\r
167EFI_STATUS\r
d1050b9d 168(EFIAPI *UDP_IO_CONFIG)(\r
b45b45b2 169 IN UDP_IO *UdpIo,\r
97b38d4e 170 IN VOID *Context\r
171 );\r
172\r
cab450cc 173/**\r
e2851998 174 The select function to decide whether to cancel the UDP_TX_TOKEN.\r
175\r
64a80549 176 @param[in] Token The UDP_TX_TOKEN to decide whether to cancel.\r
177 @param[in] Context User-defined data in UdpIoCancelDgrams().\r
e2851998 178\r
64a80549 179 @retval TRUE Cancel the UDP_TX_TOKEN.\r
180 @retval FALSE Do not cancel this UDP_TX_TOKEN.\r
cab450cc 181\r
182**/\r
97b38d4e 183typedef\r
184BOOLEAN\r
d1050b9d 185(EFIAPI *UDP_IO_TO_CANCEL)(\r
97b38d4e 186 IN UDP_TX_TOKEN *Token,\r
187 IN VOID *Context\r
188 );\r
189\r
e4b99ad9 190/**\r
e2851998 191 Cancel all the sent datagram that pass the selection criteria of ToCancel.\r
6d88babb 192\r
e4b99ad9 193 If ToCancel is NULL, all the datagrams are cancelled.\r
6d88babb 194 If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT().\r
e4b99ad9 195\r
b45b45b2 196 @param[in] UdpIo The UDP_IO to cancel packet.\r
e4b99ad9 197 @param[in] IoStatus The IoStatus to return to the packet owners.\r
6deb4baa 198 @param[in] ToCancel The select function to test whether to cancel this\r
e2851998 199 packet or not.\r
e4b99ad9
LG
200 @param[in] Context The opaque parameter to the ToCancel.\r
201\r
202**/\r
203VOID\r
204EFIAPI\r
205UdpIoCancelDgrams (\r
d1050b9d
MK
206 IN UDP_IO *UdpIo,\r
207 IN EFI_STATUS IoStatus,\r
208 IN UDP_IO_TO_CANCEL ToCancel OPTIONAL,\r
209 IN VOID *Context OPTIONAL\r
e4b99ad9
LG
210 );\r
211\r
97b38d4e 212/**\r
b45b45b2 213 Creates a UDP_IO to access the UDP service. It creates and configures\r
cab450cc 214 a UDP child.\r
e2851998 215\r
6d88babb
WF
216 If Configure is NULL, then ASSERT().\r
217 If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT().\r
218\r
e2851998 219 It locates the UDP service binding prototype on the Controller parameter\r
220 uses the UDP service binding prototype to create a UDP child (also known as\r
221 a UDP instance) configures the UDP child by calling Configure function prototype.\r
222 Any failures in creating or configuring the UDP child return NULL for failure.\r
97b38d4e 223\r
3a1ab4bc 224 @param[in] Controller The controller that has the UDP service binding.\r
225 protocol installed.\r
b45b45b2 226 @param[in] ImageHandle The image handle for the driver.\r
3a1ab4bc 227 @param[in] Configure The function to configure the created UDP child.\r
b45b45b2 228 @param[in] UdpVersion The UDP protocol version, UDP4 or UDP6.\r
6deb4baa 229 @param[in] Context The opaque parameter for the Configure function.\r
97b38d4e 230\r
64a80549 231 @return The newly-created UDP_IO, or NULL if failed.\r
97b38d4e 232\r
233**/\r
b45b45b2 234UDP_IO *\r
97b38d4e 235EFIAPI\r
b45b45b2 236UdpIoCreateIo (\r
d1050b9d
MK
237 IN EFI_HANDLE Controller,\r
238 IN EFI_HANDLE ImageHandle,\r
239 IN UDP_IO_CONFIG Configure,\r
240 IN UINT8 UdpVersion,\r
241 IN VOID *Context\r
97b38d4e 242 );\r
243\r
244/**\r
b45b45b2 245 Free the UDP_IO and all its related resources.\r
e2851998 246\r
6d88babb
WF
247 If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT().\r
248\r
e9b67286 249 The function cancels all sent datagrams and receive requests.\r
97b38d4e 250\r
b45b45b2 251 @param[in] UdpIo The UDP_IO to free.\r
97b38d4e 252\r
b45b45b2 253 @retval EFI_SUCCESS The UDP_IO is freed.\r
6d88babb 254 @retval Others Failed to free UDP_IO.\r
97b38d4e 255\r
256**/\r
257EFI_STATUS\r
258EFIAPI\r
b45b45b2 259UdpIoFreeIo (\r
d1050b9d 260 IN UDP_IO *UdpIo\r
97b38d4e 261 );\r
262\r
263/**\r
e2851998 264 Cleans up the UDP_IO without freeing it. Call this function\r
b45b45b2 265 if you intend to later re-use the UDP_IO.\r
e2851998 266\r
6d88babb
WF
267 If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT().\r
268\r
e9b67286 269 This function releases all transmitted datagrams and receive requests and configures NULL for the UDP instance.\r
97b38d4e 270\r
b45b45b2 271 @param[in] UdpIo The UDP_IO to clean up.\r
97b38d4e 272\r
97b38d4e 273**/\r
274VOID\r
275EFIAPI\r
b45b45b2 276UdpIoCleanIo (\r
d1050b9d 277 IN UDP_IO *UdpIo\r
97b38d4e 278 );\r
279\r
280/**\r
b45b45b2 281 Send a packet through the UDP_IO.\r
e2851998 282\r
6d88babb
WF
283 If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT().\r
284\r
b45b45b2 285 The packet will be wrapped in UDP_TX_TOKEN. Function Callback will be called\r
286 when the packet is sent. The optional parameter EndPoint overrides the default\r
287 address pair if specified.\r
97b38d4e 288\r
b45b45b2 289 @param[in] UdpIo The UDP_IO to send the packet through.\r
3a1ab4bc 290 @param[in] Packet The packet to send.\r
b45b45b2 291 @param[in] EndPoint The local and remote access point. Override the\r
3a1ab4bc 292 default address pair set during configuration.\r
e2851998 293 @param[in] Gateway The gateway to use.\r
3a1ab4bc 294 @param[in] CallBack The function being called when packet is\r
295 transmitted or failed.\r
296 @param[in] Context The opaque parameter passed to CallBack.\r
97b38d4e 297\r
3a1ab4bc 298 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the packet.\r
64a80549 299 @retval EFI_SUCCESS The packet is successfully delivered to UDP for\r
97b38d4e 300 transmission.\r
301\r
302**/\r
303EFI_STATUS\r
304EFIAPI\r
305UdpIoSendDatagram (\r
d1050b9d
MK
306 IN UDP_IO *UdpIo,\r
307 IN NET_BUF *Packet,\r
308 IN UDP_END_POINT *EndPoint OPTIONAL,\r
309 IN EFI_IP_ADDRESS *Gateway OPTIONAL,\r
310 IN UDP_IO_CALLBACK CallBack,\r
311 IN VOID *Context\r
97b38d4e 312 );\r
313\r
314/**\r
315 Cancel a single sent datagram.\r
316\r
e2851998 317 @param[in] UdpIo The UDP_IO from which to cancel the packet\r
3a1ab4bc 318 @param[in] Packet The packet to cancel\r
97b38d4e 319\r
97b38d4e 320**/\r
321VOID\r
322EFIAPI\r
323UdpIoCancelSentDatagram (\r
d1050b9d
MK
324 IN UDP_IO *UdpIo,\r
325 IN NET_BUF *Packet\r
97b38d4e 326 );\r
327\r
328/**\r
b45b45b2 329 Issue a receive request to the UDP_IO.\r
e2851998 330\r
6d88babb
WF
331 If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT().\r
332\r
cab450cc 333 This function is called when upper-layer needs packet from UDP for processing.\r
e9b67286 334 Only one receive request is acceptable at a time. Therefore, one common usage model is\r
cab450cc 335 to invoke this function inside its Callback function when the former packet\r
336 is processed.\r
337\r
b45b45b2 338 @param[in] UdpIo The UDP_IO to receive the packet from.\r
3a1ab4bc 339 @param[in] CallBack The call back function to execute when the packet\r
340 is received.\r
341 @param[in] Context The opaque context passed to Callback.\r
b45b45b2 342 @param[in] HeadLen The length of the upper-layer's protocol header.\r
97b38d4e 343\r
344 @retval EFI_ALREADY_STARTED There is already a pending receive request. Only\r
cab450cc 345 one receive request is supported at a time.\r
346 @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.\r
64a80549 347 @retval EFI_SUCCESS The receive request was issued successfully.\r
b45b45b2 348 @retval EFI_UNSUPPORTED The UDP version in UDP_IO is not supported.\r
97b38d4e 349\r
350**/\r
351EFI_STATUS\r
352EFIAPI\r
353UdpIoRecvDatagram (\r
d1050b9d
MK
354 IN UDP_IO *UdpIo,\r
355 IN UDP_IO_CALLBACK CallBack,\r
356 IN VOID *Context,\r
357 IN UINT32 HeadLen\r
97b38d4e 358 );\r
b45b45b2 359\r
97b38d4e 360#endif\r