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