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