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