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