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