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