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