]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Include/Library/UdpIoLib.h
temporary roll back changing on gEfiHotPlugDevice.
[mirror_edk2.git] / MdeModulePkg / Include / Library / UdpIoLib.h
CommitLineData
97b38d4e 1/** @file\r
2 The helper routines to access UDP service. It is used by both\r
3 DHCP and MTFTP.\r
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
172/**\r
cab450cc 173 Create a UDP_IO_PORT to access the UDP service. It will create and configure\r
174 a UDP child.\r
175 \r
176 The function will locate the UDP service binding prototype on the Controller\r
177 parameter and use it to create a UDP child (aka Udp instance). Then the UDP\r
178 child will be configured by calling Configure function prototype. Any failures\r
179 in creating or configure the UDP child will lead to the failure of UDP_IO_PORT\r
180 creation.\r
97b38d4e 181\r
3a1ab4bc 182 @param[in] Controller The controller that has the UDP service binding.\r
183 protocol installed.\r
184 @param[in] Image The image handle for the driver.\r
185 @param[in] Configure The function to configure the created UDP child.\r
186 @param[in] Context The opaque parameter for the Configure funtion.\r
97b38d4e 187\r
cab450cc 188 @return Newly-created UDP_IO_PORT or NULL if failed.\r
97b38d4e 189\r
190**/\r
191UDP_IO_PORT *\r
192EFIAPI\r
193UdpIoCreatePort (\r
194 IN EFI_HANDLE Controller,\r
c3a78fc8 195 IN EFI_HANDLE Image,\r
97b38d4e 196 IN UDP_IO_CONFIG Configure,\r
197 IN VOID *Context\r
198 );\r
199\r
200/**\r
cab450cc 201 Free the UDP_IO_PORT and all its related resources.\r
202 \r
203 The function will cancel all sent datagram and receive request.\r
97b38d4e 204\r
3a1ab4bc 205 @param[in] UdpIo The UDP_IO_PORT to free.\r
97b38d4e 206\r
cab450cc 207 @retval EFI_SUCCESS The UDP_IO_PORT is freed.\r
97b38d4e 208\r
209**/\r
210EFI_STATUS\r
211EFIAPI\r
212UdpIoFreePort (\r
213 IN UDP_IO_PORT *UdpIo\r
214 );\r
215\r
216/**\r
cab450cc 217 Clean up the UDP_IO_PORT without freeing it. The function is called when\r
218 user wants to re-use the UDP_IO_PORT later.\r
219 \r
220 It will release all the transmitted datagrams and receive request. It will\r
221 also configure NULL for the UDP instance.\r
97b38d4e 222\r
3a1ab4bc 223 @param[in] UdpIo The UDP_IO_PORT to clean up.\r
97b38d4e 224\r
97b38d4e 225**/\r
226VOID\r
227EFIAPI\r
228UdpIoCleanPort (\r
229 IN UDP_IO_PORT *UdpIo\r
230 );\r
231\r
232/**\r
cab450cc 233 Send a packet through the UDP_IO_PORT.\r
234 \r
235 The packet will be wrapped in UDP_TX_TOKEN. Function Callback will be called\r
236 when the packet is sent. The optional parameter EndPoint overrides the default\r
237 address pair if specified.\r
97b38d4e 238\r
3a1ab4bc 239 @param[in] UdpIo The UDP_IO_PORT to send the packet through.\r
240 @param[in] Packet The packet to send.\r
241 @param[in] EndPoint The local and remote access point. Override the\r
242 default address pair set during configuration.\r
243 @param[in] Gateway The gateway to use.\r
244 @param[in] CallBack The function being called when packet is\r
245 transmitted or failed.\r
246 @param[in] Context The opaque parameter passed to CallBack.\r
97b38d4e 247\r
3a1ab4bc 248 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the packet.\r
97b38d4e 249 @retval EFI_SUCCESS The packet is successfully delivered to UDP for\r
250 transmission.\r
251\r
252**/\r
253EFI_STATUS\r
254EFIAPI\r
255UdpIoSendDatagram (\r
256 IN UDP_IO_PORT *UdpIo,\r
257 IN NET_BUF *Packet,\r
3a1ab4bc 258 IN UDP_POINTS *EndPoint, OPTIONAL\r
97b38d4e 259 IN IP4_ADDR Gateway,\r
260 IN UDP_IO_CALLBACK CallBack,\r
261 IN VOID *Context\r
262 );\r
263\r
264/**\r
265 Cancel a single sent datagram.\r
266\r
3a1ab4bc 267 @param[in] UdpIo The UDP_IO_PORT to cancel the packet from\r
268 @param[in] Packet The packet to cancel\r
97b38d4e 269\r
97b38d4e 270**/\r
271VOID\r
272EFIAPI\r
273UdpIoCancelSentDatagram (\r
274 IN UDP_IO_PORT *UdpIo,\r
275 IN NET_BUF *Packet\r
276 );\r
277\r
278/**\r
cab450cc 279 Issue a receive request to the UDP_IO_PORT.\r
280 \r
281 This function is called when upper-layer needs packet from UDP for processing.\r
282 Only one receive request is acceptable at a time so a common usage model is\r
283 to invoke this function inside its Callback function when the former packet\r
284 is processed.\r
285\r
3a1ab4bc 286 @param[in] UdpIo The UDP_IO_PORT to receive the packet from.\r
287 @param[in] CallBack The call back function to execute when the packet\r
288 is received.\r
289 @param[in] Context The opaque context passed to Callback.\r
290 @param[in] HeadLen The length of the upper-layer's protocol header.\r
97b38d4e 291\r
292 @retval EFI_ALREADY_STARTED There is already a pending receive request. Only\r
cab450cc 293 one receive request is supported at a time.\r
294 @retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.\r
97b38d4e 295 @retval EFI_SUCCESS The receive request is issued successfully.\r
296\r
297**/\r
298EFI_STATUS\r
299EFIAPI\r
300UdpIoRecvDatagram (\r
301 IN UDP_IO_PORT *UdpIo,\r
302 IN UDP_IO_CALLBACK CallBack,\r
303 IN VOID *Context,\r
304 IN UINT32 HeadLen\r
305 );\r
306#endif\r