]>
Commit | Line | Data |
---|---|---|
a3bcde70 HT |
1 | /** @file\r |
2 | Contains all EFI_UDP6_PROTOCOL interfaces.\r | |
3 | \r | |
2c4a45b3 | 4 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r |
a3bcde70 | 5 | \r |
ecf98fbc | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a3bcde70 HT |
7 | \r |
8 | **/\r | |
9 | \r | |
10 | #include "Udp6Impl.h"\r | |
11 | \r | |
12 | EFI_UDP6_PROTOCOL mUdp6Protocol = {\r | |
13 | Udp6GetModeData,\r | |
14 | Udp6Configure,\r | |
15 | Udp6Groups,\r | |
16 | Udp6Transmit,\r | |
17 | Udp6Receive,\r | |
18 | Udp6Cancel,\r | |
19 | Udp6Poll\r | |
20 | };\r | |
21 | \r | |
a3bcde70 HT |
22 | /**\r |
23 | This function copies the current operational settings of this EFI UDPv6 Protocol\r | |
24 | instance into user-supplied buffers. This function is used optionally to retrieve\r | |
25 | the operational mode data of underlying networks or drivers.\r | |
26 | \r | |
27 | @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.\r | |
28 | @param[out] Udp6ConfigData The buffer in which the current UDP configuration\r | |
29 | data is returned. This parameter is optional and\r | |
30 | may be NULL.\r | |
31 | @param[out] Ip6ModeData The buffer in which the current EFI IPv6 Protocol\r | |
32 | mode data is returned. This parameter is optional\r | |
33 | and may be NULL.\r | |
34 | @param[out] MnpConfigData The buffer in which the current managed network\r | |
35 | configuration data is returned. This parameter is\r | |
36 | optional and may be NULL.\r | |
37 | @param[out] SnpModeData The buffer in which the simple network mode data\r | |
38 | is returned. This parameter is optional and may be NULL.\r | |
39 | \r | |
40 | @retval EFI_SUCCESS The mode data was read.\r | |
41 | @retval EFI_NOT_STARTED When Udp6ConfigData is queried, no configuration\r | |
42 | data is available because this instance has not\r | |
43 | been started.\r | |
44 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
45 | \r | |
46 | **/\r | |
47 | EFI_STATUS\r | |
48 | EFIAPI\r | |
49 | Udp6GetModeData (\r | |
50 | IN EFI_UDP6_PROTOCOL *This,\r | |
51 | OUT EFI_UDP6_CONFIG_DATA *Udp6ConfigData OPTIONAL,\r | |
52 | OUT EFI_IP6_MODE_DATA *Ip6ModeData OPTIONAL,\r | |
53 | OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,\r | |
54 | OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL\r | |
55 | )\r | |
56 | {\r | |
57 | UDP6_INSTANCE_DATA *Instance;\r | |
58 | EFI_IP6_PROTOCOL *Ip;\r | |
59 | EFI_TPL OldTpl;\r | |
60 | EFI_STATUS Status;\r | |
61 | \r | |
62 | if (This == NULL) {\r | |
63 | return EFI_INVALID_PARAMETER;\r | |
64 | }\r | |
65 | \r | |
66 | Instance = UDP6_INSTANCE_DATA_FROM_THIS (This);\r | |
67 | \r | |
68 | if (!Instance->Configured && (Udp6ConfigData != NULL)) {\r | |
69 | return EFI_NOT_STARTED;\r | |
70 | }\r | |
71 | \r | |
72 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
73 | \r | |
74 | if (Udp6ConfigData != NULL) {\r | |
75 | //\r | |
76 | // Set the Udp6ConfigData.\r | |
77 | //\r | |
78 | CopyMem (Udp6ConfigData, &Instance->ConfigData, sizeof (EFI_UDP6_CONFIG_DATA));\r | |
79 | }\r | |
80 | \r | |
81 | Ip = Instance->IpInfo->Ip.Ip6;\r | |
82 | \r | |
83 | //\r | |
84 | // Get the underlying Ip6ModeData, MnpConfigData and SnpModeData.\r | |
85 | //\r | |
86 | Status = Ip->GetModeData (Ip, Ip6ModeData, MnpConfigData, SnpModeData);\r | |
87 | \r | |
88 | gBS->RestoreTPL (OldTpl);\r | |
89 | \r | |
90 | return Status;\r | |
91 | }\r | |
92 | \r | |
a3bcde70 HT |
93 | /**\r |
94 | This function is used to do the following:\r | |
95 | Initialize and start this instance of the EFI UDPv6 Protocol.\r | |
96 | Change the filtering rules and operational parameters.\r | |
97 | Reset this instance of the EFI UDPv6 Protocol.\r | |
98 | \r | |
99 | @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.\r | |
100 | @param[in] UdpConfigData Pointer to the buffer to set the configuration\r | |
101 | data. This parameter is optional and may be NULL.\r | |
102 | \r | |
103 | @retval EFI_SUCCESS The configuration settings were set, changed, or\r | |
104 | reset successfully.\r | |
ff821675 | 105 | @retval EFI_NO_MAPPING When the UdpConfigData.UseAnyStationAddress is set\r |
a3bcde70 HT |
106 | to true and there is no address available for the IP6\r |
107 | driver to bind a source address to this instance.\r | |
108 | @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:\r | |
109 | This is NULL.\r | |
110 | UdpConfigData.StationAddress is not a valid\r | |
111 | unicast IPv6 address.\r | |
112 | UdpConfigData.RemoteAddress is not a valid unicast\r | |
113 | IPv6 address if it is not zero.\r | |
114 | @retval EFI_ALREADY_STARTED The EFI UDPv6 Protocol instance is already\r | |
115 | started/configured and must be stopped/reset\r | |
116 | before it can be reconfigured. Only TrafficClass,\r | |
117 | HopLimit, ReceiveTimeout, and TransmitTimeout can\r | |
118 | be reconfigured without stopping the current\r | |
119 | instance of the EFI UDPv6 Protocol.\r | |
120 | @retval EFI_ACCESS_DENIED UdpConfigData.AllowDuplicatePort is FALSE and\r | |
121 | UdpConfigData.StationPort is already used by another\r | |
122 | instance.\r | |
123 | @retval EFI_OUT_OF_RESOURCES The EFI UDPv6 Protocol driver cannot allocate\r | |
124 | memory for this EFI UDPv6 Protocol instance.\r | |
125 | @retval EFI_DEVICE_ERROR An unexpected network or system error occurred, and\r | |
126 | this instance was not opened.\r | |
127 | \r | |
128 | **/\r | |
129 | EFI_STATUS\r | |
130 | EFIAPI\r | |
131 | Udp6Configure (\r | |
132 | IN EFI_UDP6_PROTOCOL *This,\r | |
133 | IN EFI_UDP6_CONFIG_DATA *UdpConfigData OPTIONAL\r | |
134 | )\r | |
135 | {\r | |
136 | EFI_STATUS Status;\r | |
137 | UDP6_INSTANCE_DATA *Instance;\r | |
138 | UDP6_SERVICE_DATA *Udp6Service;\r | |
139 | EFI_TPL OldTpl;\r | |
140 | EFI_IPv6_ADDRESS StationAddress;\r | |
141 | EFI_IPv6_ADDRESS RemoteAddress;\r | |
142 | EFI_IP6_CONFIG_DATA Ip6ConfigData;\r | |
143 | EFI_IPv6_ADDRESS LocalAddr;\r | |
144 | EFI_IPv6_ADDRESS RemoteAddr;\r | |
145 | \r | |
146 | if (This == NULL) {\r | |
147 | return EFI_INVALID_PARAMETER;\r | |
148 | }\r | |
149 | \r | |
150 | Instance = UDP6_INSTANCE_DATA_FROM_THIS (This);\r | |
151 | \r | |
152 | if (!Instance->Configured && (UdpConfigData == NULL)) {\r | |
153 | return EFI_SUCCESS;\r | |
154 | }\r | |
155 | \r | |
156 | Udp6Service = Instance->Udp6Service;\r | |
157 | Status = EFI_SUCCESS;\r | |
158 | ASSERT (Udp6Service != NULL);\r | |
159 | \r | |
d1050b9d | 160 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
a3bcde70 HT |
161 | \r |
162 | if (UdpConfigData != NULL) {\r | |
a3bcde70 HT |
163 | IP6_COPY_ADDRESS (&StationAddress, &UdpConfigData->StationAddress);\r |
164 | IP6_COPY_ADDRESS (&RemoteAddress, &UdpConfigData->RemoteAddress);\r | |
165 | \r | |
166 | if ((!NetIp6IsUnspecifiedAddr (&StationAddress) && !NetIp6IsValidUnicast (&StationAddress)) ||\r | |
167 | (!NetIp6IsUnspecifiedAddr (&RemoteAddress) && !NetIp6IsValidUnicast (&RemoteAddress))\r | |
d1050b9d MK |
168 | )\r |
169 | {\r | |
a3bcde70 HT |
170 | //\r |
171 | // If not use default address, and StationAddress is not a valid unicast\r | |
172 | // if it is not IPv6 address or RemoteAddress is not a valid unicast IPv6\r | |
173 | // address if it is not 0.\r | |
174 | //\r | |
175 | Status = EFI_INVALID_PARAMETER;\r | |
176 | goto ON_EXIT;\r | |
177 | }\r | |
178 | \r | |
179 | if (Instance->Configured) {\r | |
180 | //\r | |
181 | // The instance is already configured, try to do the re-configuration.\r | |
182 | //\r | |
183 | if (!Udp6IsReconfigurable (&Instance->ConfigData, UdpConfigData)) {\r | |
184 | //\r | |
185 | // If the new configuration data wants to change some unreconfigurable\r | |
186 | // settings, return EFI_ALREADY_STARTED.\r | |
187 | //\r | |
188 | Status = EFI_ALREADY_STARTED;\r | |
189 | goto ON_EXIT;\r | |
190 | }\r | |
191 | \r | |
192 | //\r | |
193 | // Save the reconfigurable parameters.\r | |
194 | //\r | |
195 | Instance->ConfigData.TrafficClass = UdpConfigData->TrafficClass;\r | |
196 | Instance->ConfigData.HopLimit = UdpConfigData->HopLimit;\r | |
197 | Instance->ConfigData.ReceiveTimeout = UdpConfigData->ReceiveTimeout;\r | |
198 | Instance->ConfigData.TransmitTimeout = UdpConfigData->TransmitTimeout;\r | |
199 | } else {\r | |
200 | //\r | |
201 | // Construct the Ip configuration data from the UdpConfigData.\r | |
202 | //\r | |
203 | Udp6BuildIp6ConfigData (UdpConfigData, &Ip6ConfigData);\r | |
204 | \r | |
205 | //\r | |
206 | // Configure the Ip instance wrapped in the IpInfo.\r | |
207 | //\r | |
208 | Status = IpIoConfigIp (Instance->IpInfo, &Ip6ConfigData);\r | |
209 | if (EFI_ERROR (Status)) {\r | |
210 | if (Status == EFI_NO_MAPPING) {\r | |
211 | Instance->IsNoMapping = TRUE;\r | |
212 | }\r | |
213 | \r | |
214 | goto ON_EXIT;\r | |
215 | }\r | |
216 | \r | |
217 | Instance->IsNoMapping = FALSE;\r | |
218 | \r | |
219 | //\r | |
220 | // Save the configuration data.\r | |
221 | //\r | |
222 | CopyMem (\r | |
223 | &Instance->ConfigData,\r | |
224 | UdpConfigData,\r | |
225 | sizeof (EFI_UDP6_CONFIG_DATA)\r | |
226 | );\r | |
227 | IP6_COPY_ADDRESS (&Instance->ConfigData.StationAddress, &Ip6ConfigData.StationAddress);\r | |
228 | //\r | |
229 | // Try to allocate the required port resource.\r | |
230 | //\r | |
231 | Status = Udp6Bind (&Udp6Service->ChildrenList, &Instance->ConfigData);\r | |
232 | if (EFI_ERROR (Status)) {\r | |
233 | //\r | |
234 | // Reset the ip instance if bind fails.\r | |
235 | //\r | |
236 | IpIoConfigIp (Instance->IpInfo, NULL);\r | |
237 | goto ON_EXIT;\r | |
238 | }\r | |
239 | \r | |
240 | //\r | |
241 | // Pre calculate the checksum for the pseudo head, ignore the UDP length first.\r | |
242 | //\r | |
243 | IP6_COPY_ADDRESS (&LocalAddr, &Instance->ConfigData.StationAddress);\r | |
244 | IP6_COPY_ADDRESS (&RemoteAddr, &Instance->ConfigData.RemoteAddress);\r | |
245 | \r | |
246 | Instance->HeadSum = NetIp6PseudoHeadChecksum (\r | |
247 | &LocalAddr,\r | |
248 | &RemoteAddr,\r | |
249 | EFI_IP_PROTO_UDP,\r | |
250 | 0\r | |
251 | );\r | |
252 | \r | |
253 | Instance->Configured = TRUE;\r | |
254 | }\r | |
255 | } else {\r | |
256 | //\r | |
257 | // UdpConfigData is NULL, reset the instance.\r | |
258 | //\r | |
259 | Instance->Configured = FALSE;\r | |
260 | Instance->IsNoMapping = FALSE;\r | |
261 | \r | |
262 | //\r | |
263 | // Reset the Ip instance wrapped in the IpInfo.\r | |
264 | //\r | |
265 | IpIoConfigIp (Instance->IpInfo, NULL);\r | |
266 | \r | |
267 | //\r | |
268 | // Cancel all the user tokens.\r | |
269 | //\r | |
d551cc64 | 270 | Instance->Udp6Proto.Cancel (&Instance->Udp6Proto, NULL);\r |
a3bcde70 HT |
271 | \r |
272 | //\r | |
273 | // Remove the buffered RxData for this instance.\r | |
274 | //\r | |
275 | Udp6FlushRcvdDgram (Instance);\r | |
276 | \r | |
277 | ASSERT (IsListEmpty (&Instance->DeliveredDgramQue));\r | |
278 | }\r | |
f75a7f56 | 279 | \r |
a3bcde70 HT |
280 | ON_EXIT:\r |
281 | \r | |
282 | gBS->RestoreTPL (OldTpl);\r | |
283 | \r | |
284 | return Status;\r | |
285 | }\r | |
286 | \r | |
a3bcde70 HT |
287 | /**\r |
288 | This function is used to enable and disable the multicast group filtering.\r | |
289 | \r | |
290 | @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.\r | |
291 | @param[in] JoinFlag Set to TRUE to join a multicast group. Set to\r | |
292 | FALSE to leave one or all multicast groups.\r | |
293 | @param[in] MulticastAddress Pointer to multicast group address to join or\r | |
294 | leave. This parameter is optional and may be NULL.\r | |
295 | \r | |
296 | @retval EFI_SUCCESS The operation completed successfully.\r | |
297 | @retval EFI_NOT_STARTED The EFI UDPv6 Protocol instance has not been\r | |
298 | started.\r | |
299 | @retval EFI_OUT_OF_RESOURCES Could not allocate resources to join the group.\r | |
300 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
301 | This is NULL.\r | |
302 | JoinFlag is TRUE and MulticastAddress is NULL.\r | |
303 | JoinFlag is TRUE and *MulticastAddress is not a\r | |
304 | valid multicast address.\r | |
305 | @retval EFI_ALREADY_STARTED The group address is already in the group table\r | |
306 | (when JoinFlag is TRUE).\r | |
307 | @retval EFI_NOT_FOUND The group address is not in the group table (when\r | |
308 | JoinFlag is FALSE).\r | |
309 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
310 | \r | |
311 | **/\r | |
312 | EFI_STATUS\r | |
313 | EFIAPI\r | |
314 | Udp6Groups (\r | |
315 | IN EFI_UDP6_PROTOCOL *This,\r | |
316 | IN BOOLEAN JoinFlag,\r | |
317 | IN EFI_IPv6_ADDRESS *MulticastAddress OPTIONAL\r | |
318 | )\r | |
319 | {\r | |
320 | EFI_STATUS Status;\r | |
321 | UDP6_INSTANCE_DATA *Instance;\r | |
322 | EFI_IP6_PROTOCOL *Ip;\r | |
323 | EFI_TPL OldTpl;\r | |
324 | EFI_IPv6_ADDRESS *McastIp;\r | |
325 | \r | |
326 | if ((This == NULL) || (JoinFlag && (MulticastAddress == NULL))) {\r | |
327 | return EFI_INVALID_PARAMETER;\r | |
328 | }\r | |
329 | \r | |
330 | McastIp = NULL;\r | |
331 | \r | |
332 | if (JoinFlag) {\r | |
333 | if (!IP6_IS_MULTICAST (MulticastAddress)) {\r | |
334 | return EFI_INVALID_PARAMETER;\r | |
335 | }\r | |
336 | \r | |
337 | McastIp = AllocateCopyPool (sizeof (EFI_IPv6_ADDRESS), MulticastAddress);\r | |
338 | if (McastIp == NULL) {\r | |
339 | return EFI_OUT_OF_RESOURCES;\r | |
340 | }\r | |
341 | }\r | |
342 | \r | |
343 | Instance = UDP6_INSTANCE_DATA_FROM_THIS (This);\r | |
344 | if (!Instance->Configured) {\r | |
24ed9cfd WF |
345 | if (McastIp != NULL) {\r |
346 | FreePool (McastIp);\r | |
347 | }\r | |
d1050b9d | 348 | \r |
a3bcde70 HT |
349 | return EFI_NOT_STARTED;\r |
350 | }\r | |
351 | \r | |
d1050b9d | 352 | Ip = Instance->IpInfo->Ip.Ip6;\r |
a3bcde70 | 353 | \r |
d1050b9d | 354 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
a3bcde70 HT |
355 | \r |
356 | //\r | |
357 | // Invoke the Ip instance the Udp6 instance consumes to do the group operation.\r | |
358 | //\r | |
359 | Status = Ip->Groups (Ip, JoinFlag, MulticastAddress);\r | |
360 | \r | |
361 | if (EFI_ERROR (Status)) {\r | |
362 | goto ON_EXIT;\r | |
363 | }\r | |
364 | \r | |
365 | //\r | |
366 | // Keep a local copy of the configured multicast IPs because IpIo receives\r | |
367 | // datagrams from the 0 station address IP instance and then UDP delivers to\r | |
368 | // the matched instance. This copy of multicast IPs is used to avoid receive\r | |
ff821675 | 369 | // the multicast datagrams destinated to multicast IPs the other instances configured.\r |
a3bcde70 HT |
370 | //\r |
371 | if (JoinFlag) {\r | |
d1050b9d | 372 | Status = NetMapInsertTail (&Instance->McastIps, (VOID *)McastIp, NULL);\r |
a3bcde70 | 373 | } else {\r |
ceec3638 | 374 | Status = NetMapIterate (&Instance->McastIps, Udp6LeaveGroup, MulticastAddress);\r |
db79f801 JW |
375 | if ((MulticastAddress != NULL) && (Status == EFI_ABORTED)) {\r |
376 | Status = EFI_SUCCESS;\r | |
f75a7f56 | 377 | }\r |
a3bcde70 HT |
378 | }\r |
379 | \r | |
380 | ON_EXIT:\r | |
381 | \r | |
382 | gBS->RestoreTPL (OldTpl);\r | |
383 | \r | |
384 | if (EFI_ERROR (Status)) {\r | |
385 | if (McastIp != NULL) {\r | |
386 | FreePool (McastIp);\r | |
387 | }\r | |
388 | }\r | |
389 | \r | |
390 | return Status;\r | |
391 | }\r | |
392 | \r | |
a3bcde70 HT |
393 | /**\r |
394 | This function places a sending request to this instance of the EFI UDPv6 Protocol,\r | |
395 | alongside the transmit data that was filled by the user.\r | |
396 | \r | |
397 | @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.\r | |
398 | @param[in] Token Pointer to the completion token that will be\r | |
399 | placed into the transmit queue.\r | |
400 | \r | |
401 | @retval EFI_SUCCESS The data was queued for transmission.\r | |
402 | @retval EFI_NOT_STARTED This EFI UDPv6 Protocol instance has not been\r | |
403 | started.\r | |
404 | @retval EFI_NO_MAPPING The under-layer IPv6 driver was responsible for\r | |
405 | choosing a source address for this instance, but\r | |
406 | no source address was available for use.\r | |
407 | @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:\r | |
408 | This is NULL.\r | |
409 | Token is NULL. Token.Event is NULL.\r | |
410 | Token.Packet.TxData is NULL.\r | |
411 | Token.Packet.TxData.FragmentCount is zero.\r | |
412 | Token.Packet.TxData.DataLength is not equal to the\r | |
413 | sum of fragment lengths.\r | |
414 | One or more of the\r | |
415 | Token.Packet.TxData.FragmentTable[].FragmentLength\r | |
416 | fields is zero.\r | |
417 | One or more of the\r | |
418 | Token.Packet.TxData.FragmentTable[].FragmentBuffer\r | |
419 | fields is NULL. One or more of the\r | |
ff821675 | 420 | Token.Packet.TxData.UdpSessionData.DestinationAddress\r |
a3bcde70 HT |
421 | are not valid unicast IPv6\r |
422 | addresses if the UdpSessionData is not NULL.\r | |
423 | Token.Packet.TxData.UdpSessionData.\r | |
424 | DestinationAddress is NULL\r | |
425 | Token.Packet.TxData.UdpSessionData.\r | |
ff821675 | 426 | DestinationPort\r |
a3bcde70 HT |
427 | is zero.\r |
428 | Token.Packet.TxData.UdpSessionData is NULL and this\r | |
429 | instance's UdpConfigData.RemoteAddress is unspecified.\r | |
430 | @retval EFI_ACCESS_DENIED The transmit completion token with the same\r | |
431 | Token.Event is already in the transmit queue.\r | |
432 | @retval EFI_NOT_READY The completion token could not be queued because\r | |
433 | the transmit queue is full.\r | |
434 | @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.\r | |
435 | @retval EFI_NOT_FOUND There is no route to the destination network or\r | |
436 | address.\r | |
437 | @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP\r | |
438 | packet size. Or, the length of the IP header + UDP\r | |
439 | header + data length is greater than MTU if\r | |
440 | DoNotFragment is TRUE.\r | |
441 | \r | |
442 | **/\r | |
443 | EFI_STATUS\r | |
444 | EFIAPI\r | |
445 | Udp6Transmit (\r | |
446 | IN EFI_UDP6_PROTOCOL *This,\r | |
447 | IN EFI_UDP6_COMPLETION_TOKEN *Token\r | |
448 | )\r | |
449 | {\r | |
450 | EFI_STATUS Status;\r | |
451 | UDP6_INSTANCE_DATA *Instance;\r | |
452 | EFI_TPL OldTpl;\r | |
453 | NET_BUF *Packet;\r | |
454 | EFI_UDP_HEADER *Udp6Header;\r | |
455 | EFI_UDP6_CONFIG_DATA *ConfigData;\r | |
456 | EFI_IPv6_ADDRESS Source;\r | |
457 | EFI_IPv6_ADDRESS Destination;\r | |
458 | EFI_UDP6_TRANSMIT_DATA *TxData;\r | |
459 | EFI_UDP6_SESSION_DATA *UdpSessionData;\r | |
460 | UDP6_SERVICE_DATA *Udp6Service;\r | |
461 | IP_IO_OVERRIDE Override;\r | |
462 | UINT16 HeadSum;\r | |
463 | EFI_IP_ADDRESS IpDestAddr;\r | |
464 | \r | |
465 | if ((This == NULL) || (Token == NULL)) {\r | |
466 | return EFI_INVALID_PARAMETER;\r | |
467 | }\r | |
468 | \r | |
469 | Instance = UDP6_INSTANCE_DATA_FROM_THIS (This);\r | |
470 | \r | |
471 | if (!Instance->Configured) {\r | |
472 | return EFI_NOT_STARTED;\r | |
473 | }\r | |
474 | \r | |
475 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
476 | \r | |
477 | //\r | |
478 | // Validate the Token, if the token is invalid return the error code.\r | |
479 | //\r | |
480 | Status = Udp6ValidateTxToken (Instance, Token);\r | |
481 | if (EFI_ERROR (Status)) {\r | |
482 | goto ON_EXIT;\r | |
483 | }\r | |
484 | \r | |
485 | if (EFI_ERROR (NetMapIterate (&Instance->TxTokens, Udp6TokenExist, Token)) ||\r | |
486 | EFI_ERROR (NetMapIterate (&Instance->RxTokens, Udp6TokenExist, Token))\r | |
d1050b9d MK |
487 | )\r |
488 | {\r | |
a3bcde70 HT |
489 | //\r |
490 | // Try to find a duplicate token in the two token maps, if found, return\r | |
491 | // EFI_ACCESS_DENIED.\r | |
492 | //\r | |
493 | Status = EFI_ACCESS_DENIED;\r | |
494 | goto ON_EXIT;\r | |
495 | }\r | |
496 | \r | |
497 | TxData = Token->Packet.TxData;\r | |
498 | \r | |
499 | //\r | |
500 | // Create a net buffer to hold the user buffer and the udp header.\r | |
501 | //\r | |
502 | Packet = NetbufFromExt (\r | |
d1050b9d | 503 | (NET_FRAGMENT *)TxData->FragmentTable,\r |
a3bcde70 HT |
504 | TxData->FragmentCount,\r |
505 | UDP6_HEADER_SIZE,\r | |
506 | 0,\r | |
507 | Udp6NetVectorExtFree,\r | |
508 | NULL\r | |
509 | );\r | |
510 | if (Packet == NULL) {\r | |
511 | Status = EFI_OUT_OF_RESOURCES;\r | |
512 | goto ON_EXIT;\r | |
513 | }\r | |
514 | \r | |
515 | //\r | |
516 | // Store the IpIo in ProtoData.\r | |
517 | //\r | |
d1050b9d MK |
518 | Udp6Service = Instance->Udp6Service;\r |
519 | *((UINTN *)&Packet->ProtoData[0]) = (UINTN)(Udp6Service->IpIo);\r | |
a3bcde70 | 520 | \r |
d1050b9d | 521 | Udp6Header = (EFI_UDP_HEADER *)NetbufAllocSpace (Packet, UDP6_HEADER_SIZE, TRUE);\r |
a3bcde70 | 522 | ASSERT (Udp6Header != NULL);\r |
2c4a45b3 WF |
523 | if (Udp6Header == NULL) {\r |
524 | Status = EFI_OUT_OF_RESOURCES;\r | |
525 | goto ON_EXIT;\r | |
526 | }\r | |
f75a7f56 | 527 | \r |
a3bcde70 HT |
528 | ConfigData = &Instance->ConfigData;\r |
529 | \r | |
530 | //\r | |
531 | // Fill the udp header.\r | |
532 | //\r | |
d1050b9d MK |
533 | Udp6Header->SrcPort = HTONS (ConfigData->StationPort);\r |
534 | Udp6Header->DstPort = HTONS (ConfigData->RemotePort);\r | |
535 | Udp6Header->Length = HTONS ((UINT16)Packet->TotalSize);\r | |
536 | Udp6Header->Checksum = 0;\r | |
a3bcde70 HT |
537 | //\r |
538 | // Set the UDP Header in NET_BUF, this UDP header is for IP6 can fast get the\r | |
539 | // Udp header for pseudoHeadCheckSum.\r | |
540 | //\r | |
541 | Packet->Udp = Udp6Header;\r | |
542 | UdpSessionData = TxData->UdpSessionData;\r | |
543 | \r | |
544 | if (UdpSessionData != NULL) {\r | |
545 | //\r | |
546 | // Set the Destination according to the specified\r | |
547 | // UdpSessionData.\r | |
548 | //\r | |
549 | \r | |
550 | if (UdpSessionData->DestinationPort != 0) {\r | |
551 | Udp6Header->DstPort = HTONS (UdpSessionData->DestinationPort);\r | |
552 | }\r | |
553 | \r | |
554 | IP6_COPY_ADDRESS (&Source, &ConfigData->StationAddress);\r | |
555 | if (!NetIp6IsUnspecifiedAddr (&UdpSessionData->DestinationAddress)) {\r | |
556 | IP6_COPY_ADDRESS (&Destination, &UdpSessionData->DestinationAddress);\r | |
557 | } else {\r | |
558 | IP6_COPY_ADDRESS (&Destination, &ConfigData->RemoteAddress);\r | |
559 | }\r | |
560 | \r | |
561 | //\r | |
d1050b9d | 562 | // Calculate the pseudo head checksum using the overridden parameters.\r |
a3bcde70 HT |
563 | //\r |
564 | if (!NetIp6IsUnspecifiedAddr (&ConfigData->StationAddress)) {\r | |
565 | HeadSum = NetIp6PseudoHeadChecksum (\r | |
566 | &Source,\r | |
567 | &Destination,\r | |
568 | EFI_IP_PROTO_UDP,\r | |
569 | 0\r | |
570 | );\r | |
571 | \r | |
572 | //\r | |
573 | // calculate the checksum.\r | |
574 | //\r | |
575 | Udp6Header->Checksum = Udp6Checksum (Packet, HeadSum);\r | |
576 | if (Udp6Header->Checksum == 0) {\r | |
577 | //\r | |
578 | // If the calculated checksum is 0, fill the Checksum field with all ones.\r | |
579 | //\r | |
0f333664 | 580 | Udp6Header->Checksum = 0xffff;\r |
a3bcde70 HT |
581 | }\r |
582 | } else {\r | |
583 | //\r | |
ff821675 | 584 | // Set the checksum is zero if the ConfigData->StationAddress is unspecified\r |
a3bcde70 HT |
585 | // and the Ipv6 will fill the correct value of this checksum.\r |
586 | //\r | |
587 | Udp6Header->Checksum = 0;\r | |
a3bcde70 HT |
588 | }\r |
589 | } else {\r | |
590 | //\r | |
591 | // UdpSessionData is NULL, use the address and port information previously configured.\r | |
592 | //\r | |
593 | IP6_COPY_ADDRESS (&Destination, &ConfigData->RemoteAddress);\r | |
594 | \r | |
595 | HeadSum = Instance->HeadSum;\r | |
596 | //\r | |
597 | // calculate the checksum.\r | |
598 | //\r | |
599 | Udp6Header->Checksum = Udp6Checksum (Packet, HeadSum);\r | |
600 | if (Udp6Header->Checksum == 0) {\r | |
601 | //\r | |
602 | // If the calculated checksum is 0, fill the Checksum field with all ones.\r | |
603 | //\r | |
604 | Udp6Header->Checksum = 0xffff;\r | |
605 | }\r | |
606 | }\r | |
607 | \r | |
a3bcde70 HT |
608 | //\r |
609 | // Fill the IpIo Override data.\r | |
610 | //\r | |
611 | Override.Ip6OverrideData.Protocol = EFI_IP_PROTO_UDP;\r | |
612 | Override.Ip6OverrideData.HopLimit = ConfigData->HopLimit;\r | |
613 | Override.Ip6OverrideData.FlowLabel = 0;\r | |
614 | \r | |
615 | //\r | |
616 | // Save the token into the TxToken map.\r | |
617 | //\r | |
618 | Status = NetMapInsertTail (&Instance->TxTokens, Token, Packet);\r | |
619 | if (EFI_ERROR (Status)) {\r | |
620 | goto FREE_PACKET;\r | |
621 | }\r | |
622 | \r | |
623 | //\r | |
624 | // Send out this datagram through IpIo.\r | |
625 | //\r | |
d1050b9d | 626 | if (UdpSessionData != NULL) {\r |
a3bcde70 HT |
627 | IP6_COPY_ADDRESS (&(IpDestAddr.v6), &Destination);\r |
628 | } else {\r | |
629 | ZeroMem (&IpDestAddr.v6, sizeof (EFI_IPv6_ADDRESS));\r | |
630 | }\r | |
631 | \r | |
632 | Status = IpIoSend (\r | |
633 | Udp6Service->IpIo,\r | |
634 | Packet,\r | |
635 | Instance->IpInfo,\r | |
636 | Instance,\r | |
637 | Token,\r | |
638 | &IpDestAddr,\r | |
639 | &Override\r | |
640 | );\r | |
641 | if (EFI_ERROR (Status)) {\r | |
642 | //\r | |
643 | // Remove this token from the TxTokens.\r | |
644 | //\r | |
645 | Udp6RemoveToken (&Instance->TxTokens, Token);\r | |
646 | }\r | |
647 | \r | |
648 | FREE_PACKET:\r | |
649 | \r | |
650 | NetbufFree (Packet);\r | |
651 | \r | |
652 | ON_EXIT:\r | |
653 | \r | |
654 | gBS->RestoreTPL (OldTpl);\r | |
655 | \r | |
656 | return Status;\r | |
657 | }\r | |
658 | \r | |
a3bcde70 HT |
659 | /**\r |
660 | This function places a completion token into the receive packet queue. This function\r | |
661 | is always asynchronous.\r | |
662 | \r | |
663 | @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.\r | |
664 | @param[in] Token Pointer to a token that is associated with the\r | |
665 | receive data descriptor.\r | |
666 | \r | |
667 | @retval EFI_SUCCESS The receive completion token was cached.\r | |
668 | @retval EFI_NOT_STARTED This EFI UDPv6 Protocol instance has not been\r | |
669 | started.\r | |
670 | @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,\r | |
671 | BOOTP, RARP, etc.) is not finished yet.\r | |
672 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
673 | This is NULL. Token is NULL. Token.Event is NULL.\r | |
674 | @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued\r | |
675 | due to a lack of system resources (usually\r | |
676 | memory).\r | |
677 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
678 | The EFI UDPv6 Protocol instance has been reset to\r | |
679 | startup defaults.\r | |
680 | @retval EFI_ACCESS_DENIED A receive completion token with the same\r | |
681 | Token.Event is already in the receive queue.\r | |
682 | @retval EFI_NOT_READY The receive request could not be queued because\r | |
683 | the receive queue is full.\r | |
684 | \r | |
685 | **/\r | |
686 | EFI_STATUS\r | |
687 | EFIAPI\r | |
688 | Udp6Receive (\r | |
689 | IN EFI_UDP6_PROTOCOL *This,\r | |
690 | IN EFI_UDP6_COMPLETION_TOKEN *Token\r | |
691 | )\r | |
692 | {\r | |
693 | EFI_STATUS Status;\r | |
694 | UDP6_INSTANCE_DATA *Instance;\r | |
695 | EFI_TPL OldTpl;\r | |
696 | \r | |
697 | if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {\r | |
698 | return EFI_INVALID_PARAMETER;\r | |
699 | }\r | |
700 | \r | |
701 | Instance = UDP6_INSTANCE_DATA_FROM_THIS (This);\r | |
702 | \r | |
703 | if (!Instance->Configured) {\r | |
704 | return EFI_NOT_STARTED;\r | |
705 | }\r | |
706 | \r | |
707 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
708 | \r | |
709 | if (EFI_ERROR (NetMapIterate (&Instance->RxTokens, Udp6TokenExist, Token)) ||\r | |
710 | EFI_ERROR (NetMapIterate (&Instance->TxTokens, Udp6TokenExist, Token))\r | |
d1050b9d MK |
711 | )\r |
712 | {\r | |
a3bcde70 HT |
713 | //\r |
714 | // Return EFI_ACCESS_DENIED if the specified token is already in the TxTokens or\r | |
715 | // RxTokens map.\r | |
716 | //\r | |
717 | Status = EFI_ACCESS_DENIED;\r | |
718 | goto ON_EXIT;\r | |
719 | }\r | |
720 | \r | |
721 | Token->Packet.RxData = NULL;\r | |
722 | \r | |
723 | //\r | |
724 | // Save the token into the RxTokens map.\r | |
725 | //\r | |
726 | Status = NetMapInsertTail (&Instance->RxTokens, Token, NULL);\r | |
727 | if (EFI_ERROR (Status)) {\r | |
728 | Status = EFI_NOT_READY;\r | |
729 | goto ON_EXIT;\r | |
730 | }\r | |
731 | \r | |
732 | //\r | |
733 | // If there is an icmp error, report it.\r | |
734 | //\r | |
735 | Udp6ReportIcmpError (Instance);\r | |
736 | \r | |
737 | //\r | |
738 | // Try to delivered the received datagrams.\r | |
739 | //\r | |
740 | Udp6InstanceDeliverDgram (Instance);\r | |
741 | \r | |
742 | //\r | |
743 | // Dispatch the DPC queued by the NotifyFunction of Token->Event.\r | |
744 | //\r | |
745 | DispatchDpc ();\r | |
746 | \r | |
747 | ON_EXIT:\r | |
748 | \r | |
749 | gBS->RestoreTPL (OldTpl);\r | |
750 | \r | |
751 | return Status;\r | |
752 | }\r | |
753 | \r | |
a3bcde70 HT |
754 | /**\r |
755 | This function is used to abort a pending transmit or receive request.\r | |
756 | \r | |
757 | @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.\r | |
758 | @param[in] Token Pointer to a token that has been issued by\r | |
759 | EFI_UDP6_PROTOCOL.Transmit() or\r | |
760 | EFI_UDP6_PROTOCOL.Receive(). This parameter is\r | |
761 | optional and may be NULL.\r | |
762 | \r | |
763 | @retval EFI_SUCCESS The asynchronous I/O request was aborted, and\r | |
764 | Token.Event was signaled. When Token is NULL, all\r | |
765 | pending requests are aborted and their events are\r | |
766 | signaled.\r | |
767 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
768 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
769 | @retval EFI_NO_MAPPING When using the default address, configuration\r | |
770 | (DHCP, BOOTP, RARP, etc.) is not finished yet.\r | |
771 | @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O\r | |
772 | request is not found in the transmit or receive\r | |
773 | queue. It is either completed or not issued by\r | |
774 | Transmit() or Receive().\r | |
775 | \r | |
776 | **/\r | |
777 | EFI_STATUS\r | |
778 | EFIAPI\r | |
779 | Udp6Cancel (\r | |
780 | IN EFI_UDP6_PROTOCOL *This,\r | |
781 | IN EFI_UDP6_COMPLETION_TOKEN *Token OPTIONAL\r | |
782 | )\r | |
783 | {\r | |
784 | EFI_STATUS Status;\r | |
785 | UDP6_INSTANCE_DATA *Instance;\r | |
786 | EFI_TPL OldTpl;\r | |
787 | \r | |
788 | if (This == NULL) {\r | |
789 | return EFI_INVALID_PARAMETER;\r | |
790 | }\r | |
791 | \r | |
792 | Instance = UDP6_INSTANCE_DATA_FROM_THIS (This);\r | |
793 | \r | |
794 | if (!Instance->Configured) {\r | |
795 | return EFI_NOT_STARTED;\r | |
796 | }\r | |
797 | \r | |
798 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
799 | \r | |
800 | //\r | |
ff821675 | 801 | // Cancel the tokens specified by Token for this instance.\r |
a3bcde70 HT |
802 | //\r |
803 | Status = Udp6InstanceCancelToken (Instance, Token);\r | |
804 | \r | |
805 | //\r | |
806 | // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.\r | |
807 | //\r | |
808 | DispatchDpc ();\r | |
809 | \r | |
810 | gBS->RestoreTPL (OldTpl);\r | |
811 | \r | |
812 | return Status;\r | |
813 | }\r | |
814 | \r | |
a3bcde70 HT |
815 | /**\r |
816 | This function can be used by network drivers and applications to increase the rate that\r | |
817 | data packets are moved between the communications device and the transmit/receive queues.\r | |
818 | \r | |
819 | @param[in] This Pointer to the EFI_UDP6_PROTOCOL instance.\r | |
820 | \r | |
821 | @retval EFI_SUCCESS Incoming or outgoing data was processed.\r | |
822 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
823 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
824 | @retval EFI_TIMEOUT Data was dropped out of the transmit and/or\r | |
825 | receive queue.\r | |
826 | \r | |
827 | **/\r | |
828 | EFI_STATUS\r | |
829 | EFIAPI\r | |
830 | Udp6Poll (\r | |
831 | IN EFI_UDP6_PROTOCOL *This\r | |
832 | )\r | |
833 | {\r | |
834 | UDP6_INSTANCE_DATA *Instance;\r | |
835 | EFI_IP6_PROTOCOL *Ip;\r | |
836 | \r | |
837 | if (This == NULL) {\r | |
838 | return EFI_INVALID_PARAMETER;\r | |
839 | }\r | |
840 | \r | |
841 | Instance = UDP6_INSTANCE_DATA_FROM_THIS (This);\r | |
842 | Ip = Instance->IpInfo->Ip.Ip6;\r | |
843 | \r | |
844 | //\r | |
845 | // Invode the Ip instance consumed by the udp instance to do the poll operation.\r | |
846 | //\r | |
847 | return Ip->Poll (Ip);\r | |
848 | }\r |