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