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