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