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