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