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