]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/Dhcp6Dxe/Dhcp6Impl.c
BaseTools: Eot failed when enable python3
[mirror_edk2.git] / NetworkPkg / Dhcp6Dxe / Dhcp6Impl.c
1 /** @file
2 This EFI_DHCP6_PROTOCOL interface implementation.
3
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "Dhcp6Impl.h"
17
18 //
19 // Well-known multi-cast address defined in section-24.1 of rfc-3315
20 //
21 // ALL_DHCP_Relay_Agents_and_Servers address: FF02::1:2
22 //
23 EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress = {{0xFF, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2}};
24
25 EFI_DHCP6_PROTOCOL gDhcp6ProtocolTemplate = {
26 EfiDhcp6GetModeData,
27 EfiDhcp6Configure,
28 EfiDhcp6Start,
29 EfiDhcp6InfoRequest,
30 EfiDhcp6RenewRebind,
31 EfiDhcp6Decline,
32 EfiDhcp6Release,
33 EfiDhcp6Stop,
34 EfiDhcp6Parse
35 };
36
37 /**
38 Starts the DHCPv6 standard S.A.R.R. process.
39
40 The Start() function starts the DHCPv6 standard process. This function can
41 be called only when the state of Dhcp6 instance is in the Dhcp6Init state.
42 If the DHCP process completes successfully, the state of the Dhcp6 instance
43 will be transferred through Dhcp6Selecting and Dhcp6Requesting to the
44 Dhcp6Bound state.
45 Refer to rfc-3315 for precise state transitions during this process. At the
46 time when each event occurs in this process, the callback function that was set
47 by EFI_DHCP6_PROTOCOL.Configure() will be called, and the user can take this
48 opportunity to control the process.
49
50 @param[in] This The pointer to Dhcp6 protocol.
51
52 @retval EFI_SUCCESS The DHCPv6 standard process has started, or it has
53 completed when CompletionEvent is NULL.
54 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Child instance hasn't been configured.
55 @retval EFI_INVALID_PARAMETER This is NULL.
56 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
57 @retval EFI_TIMEOUT The DHCPv6 configuration process failed because no
58 response was received from the server within the
59 specified timeout value.
60 @retval EFI_ABORTED The user aborted the DHCPv6 process.
61 @retval EFI_ALREADY_STARTED Some other Dhcp6 instance already started the DHCPv6
62 standard process.
63 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
64 @retval EFI_NO_MEDIA There was a media error.
65
66 **/
67 EFI_STATUS
68 EFIAPI
69 EfiDhcp6Start (
70 IN EFI_DHCP6_PROTOCOL *This
71 )
72 {
73 EFI_STATUS Status;
74 EFI_TPL OldTpl;
75 DHCP6_INSTANCE *Instance;
76 DHCP6_SERVICE *Service;
77 EFI_STATUS MediaStatus;
78
79 if (This == NULL) {
80 return EFI_INVALID_PARAMETER;
81 }
82
83 Instance = DHCP6_INSTANCE_FROM_THIS (This);
84 Service = Instance->Service;
85
86 //
87 // The instance hasn't been configured.
88 //
89 if (Instance->Config == NULL) {
90 return EFI_ACCESS_DENIED;
91 }
92
93 ASSERT (Instance->IaCb.Ia != NULL);
94
95 //
96 // The instance has already been started.
97 //
98 if (Instance->IaCb.Ia->State != Dhcp6Init) {
99 return EFI_ALREADY_STARTED;
100 }
101
102 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
103
104 //
105 // Check Media Satus.
106 //
107 MediaStatus = EFI_SUCCESS;
108 NetLibDetectMediaWaitTimeout (Service->Controller, DHCP_CHECK_MEDIA_WAITING_TIME, &MediaStatus);
109 if (MediaStatus != EFI_SUCCESS) {
110 Status = EFI_NO_MEDIA;
111 goto ON_ERROR;
112 }
113
114 Instance->UdpSts = EFI_ALREADY_STARTED;
115
116 //
117 // Send the solicit message to start S.A.R.R process.
118 //
119 Status = Dhcp6SendSolicitMsg (Instance);
120
121 if (EFI_ERROR (Status)) {
122 goto ON_ERROR;
123 }
124
125 //
126 // Register receive callback for the stateful exchange process.
127 //
128 Status = UdpIoRecvDatagram(
129 Service->UdpIo,
130 Dhcp6ReceivePacket,
131 Service,
132 0
133 );
134
135 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
136 goto ON_ERROR;
137 }
138
139 gBS->RestoreTPL (OldTpl);
140
141 //
142 // Poll udp out of the net tpl if synchronous call.
143 //
144 if (Instance->Config->IaInfoEvent == NULL) {
145
146 while (Instance->UdpSts == EFI_ALREADY_STARTED) {
147 Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);
148 }
149 return Instance->UdpSts;
150 }
151
152 return EFI_SUCCESS;
153
154 ON_ERROR:
155
156 gBS->RestoreTPL (OldTpl);
157 return Status;
158 }
159
160
161 /**
162 Stops the DHCPv6 standard S.A.R.R. process.
163
164 The Stop() function is used to stop the DHCPv6 standard process. After this
165 function is called successfully, the state of Dhcp6 instance is transferred
166 into Dhcp6Init. EFI_DHCP6_PROTOCOL.Configure() needs to be called
167 before DHCPv6 standard process can be started again. This function can be
168 called when the Dhcp6 instance is in any state.
169
170 @param[in] This The pointer to the Dhcp6 protocol.
171
172 @retval EFI_SUCCESS The Dhcp6 instance is now in the Dhcp6Init state.
173 @retval EFI_INVALID_PARAMETER This is NULL.
174
175 **/
176 EFI_STATUS
177 EFIAPI
178 EfiDhcp6Stop (
179 IN EFI_DHCP6_PROTOCOL *This
180 )
181 {
182 EFI_TPL OldTpl;
183 EFI_STATUS Status;
184 EFI_UDP6_PROTOCOL *Udp6;
185 DHCP6_INSTANCE *Instance;
186 DHCP6_SERVICE *Service;
187
188 if (This == NULL) {
189 return EFI_INVALID_PARAMETER;
190 }
191
192 Instance = DHCP6_INSTANCE_FROM_THIS (This);
193 Service = Instance->Service;
194 Udp6 = Service->UdpIo->Protocol.Udp6;
195 Status = EFI_SUCCESS;
196
197 //
198 // The instance hasn't been configured.
199 //
200 if (Instance->Config == NULL) {
201 return Status;
202 }
203
204 ASSERT (Instance->IaCb.Ia != NULL);
205
206 //
207 // No valid REPLY message received yet, cleanup this instance directly.
208 //
209 if (Instance->IaCb.Ia->State == Dhcp6Init ||
210 Instance->IaCb.Ia->State == Dhcp6Selecting ||
211 Instance->IaCb.Ia->State == Dhcp6Requesting
212 ) {
213 goto ON_EXIT;
214 }
215
216 //
217 // Release the current ready Ia.
218 //
219 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
220
221 Instance->UdpSts = EFI_ALREADY_STARTED;
222 Status = Dhcp6SendReleaseMsg (Instance, Instance->IaCb.Ia);
223 gBS->RestoreTPL (OldTpl);
224 if (EFI_ERROR (Status)) {
225 goto ON_EXIT;
226 }
227
228 //
229 // Poll udp out of the net tpl if synchoronus call.
230 //
231 if (Instance->Config->IaInfoEvent == NULL) {
232 ASSERT (Udp6 != NULL);
233 while (Instance->UdpSts == EFI_ALREADY_STARTED) {
234 Udp6->Poll (Udp6);
235 }
236 Status = Instance->UdpSts;
237 }
238
239 ON_EXIT:
240 //
241 // Clean up the session data for the released Ia.
242 //
243 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
244 Dhcp6CleanupSession (Instance, EFI_SUCCESS);
245 gBS->RestoreTPL (OldTpl);
246
247 return Status;
248 }
249
250
251 /**
252 Returns the current operating mode data for the Dhcp6 instance.
253
254 The GetModeData() function returns the current operating mode and
255 cached data packet for the Dhcp6 instance.
256
257 @param[in] This The pointer to the Dhcp6 protocol.
258 @param[out] Dhcp6ModeData The pointer to the Dhcp6 mode data.
259 @param[out] Dhcp6ConfigData The pointer to the Dhcp6 configure data.
260
261 @retval EFI_SUCCESS The mode data was returned.
262 @retval EFI_INVALID_PARAMETER This is NULL.
263 @retval EFI_ACCESS_DENIED The EFI DHCPv6 Protocol instance was not
264 configured.
265 **/
266 EFI_STATUS
267 EFIAPI
268 EfiDhcp6GetModeData (
269 IN EFI_DHCP6_PROTOCOL *This,
270 OUT EFI_DHCP6_MODE_DATA *Dhcp6ModeData OPTIONAL,
271 OUT EFI_DHCP6_CONFIG_DATA *Dhcp6ConfigData OPTIONAL
272 )
273 {
274 EFI_TPL OldTpl;
275 EFI_DHCP6_IA *Ia;
276 DHCP6_INSTANCE *Instance;
277 DHCP6_SERVICE *Service;
278 UINT32 IaSize;
279 UINT32 IdSize;
280
281 if (This == NULL || (Dhcp6ModeData == NULL && Dhcp6ConfigData == NULL)) {
282 return EFI_INVALID_PARAMETER;
283 }
284
285 Instance = DHCP6_INSTANCE_FROM_THIS (This);
286 Service = Instance->Service;
287
288 if (Instance->Config == NULL && Dhcp6ConfigData != NULL) {
289 return EFI_ACCESS_DENIED;
290 }
291
292 ASSERT (Service->ClientId != NULL);
293
294 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
295
296 //
297 // User needs a copy of instance config data.
298 //
299 if (Dhcp6ConfigData != NULL) {
300 ZeroMem (Dhcp6ConfigData, sizeof(EFI_DHCP6_CONFIG_DATA));
301 //
302 // Duplicate config data, including all reference buffers.
303 //
304 if (EFI_ERROR (Dhcp6CopyConfigData (Dhcp6ConfigData, Instance->Config))) {
305 goto ON_ERROR;
306 }
307 }
308
309 //
310 // User need a copy of instance mode data.
311 //
312 if (Dhcp6ModeData != NULL) {
313 ZeroMem (Dhcp6ModeData, sizeof (EFI_DHCP6_MODE_DATA));
314 //
315 // Duplicate a copy of EFI_DHCP6_DUID for client Id.
316 //
317 IdSize = Service->ClientId->Length + sizeof (Service->ClientId->Length);
318
319 Dhcp6ModeData->ClientId = AllocateZeroPool (IdSize);
320 if (Dhcp6ModeData->ClientId == NULL) {
321 goto ON_ERROR;
322 }
323
324 CopyMem (
325 Dhcp6ModeData->ClientId,
326 Service->ClientId,
327 IdSize
328 );
329
330 Ia = Instance->IaCb.Ia;
331 if (Ia != NULL) {
332 //
333 // Duplicate a copy of EFI_DHCP6_IA for configured Ia.
334 //
335 IaSize = sizeof (EFI_DHCP6_IA) + (Ia->IaAddressCount -1) * sizeof (EFI_DHCP6_IA_ADDRESS);
336
337 Dhcp6ModeData->Ia = AllocateZeroPool (IaSize);
338 if (Dhcp6ModeData->Ia == NULL) {
339 goto ON_ERROR;
340 }
341
342 CopyMem (
343 Dhcp6ModeData->Ia,
344 Ia,
345 IaSize
346 );
347
348 //
349 // Duplicate a copy of reply packet if has.
350 //
351 if (Ia->ReplyPacket != NULL) {
352 Dhcp6ModeData->Ia->ReplyPacket = AllocateZeroPool (Ia->ReplyPacket->Size);
353 if (Dhcp6ModeData->Ia->ReplyPacket == NULL) {
354 goto ON_ERROR;
355 }
356 CopyMem (
357 Dhcp6ModeData->Ia->ReplyPacket,
358 Ia->ReplyPacket,
359 Ia->ReplyPacket->Size
360 );
361 }
362 }
363 }
364
365 gBS->RestoreTPL (OldTpl);
366
367 return EFI_SUCCESS;
368
369 ON_ERROR:
370
371 if (Dhcp6ConfigData != NULL) {
372 Dhcp6CleanupConfigData (Dhcp6ConfigData);
373 }
374 if (Dhcp6ModeData != NULL) {
375 Dhcp6CleanupModeData (Dhcp6ModeData);
376 }
377 gBS->RestoreTPL (OldTpl);
378
379 return EFI_OUT_OF_RESOURCES;
380 }
381
382
383 /**
384 Initializes, changes, or resets the operational settings for the Dhcp6 instance.
385
386 The Configure() function is used to initialize or clean up the configuration
387 data of the Dhcp6 instance:
388 - When Dhcp6CfgData is not NULL and Configure() is called successfully, the
389 configuration data will be initialized in the Dhcp6 instance, and the state
390 of the configured IA will be transferred into Dhcp6Init.
391 - When Dhcp6CfgData is NULL and Configure() is called successfully, the
392 configuration data will be cleaned up and no IA will be associated with
393 the Dhcp6 instance.
394 To update the configuration data for an Dhcp6 instance, the original data
395 must be cleaned up before setting the new configuration data.
396
397 @param[in] This The pointer to the Dhcp6 protocol
398 @param[in] Dhcp6CfgData The pointer to the EFI_DHCP6_CONFIG_DATA.
399
400 @retval EFI_SUCCESS The Dhcp6 is configured successfully with the
401 Dhcp6Init state, or cleaned up the original
402 configuration setting.
403 @retval EFI_ACCESS_DENIED The Dhcp6 instance was already configured.
404 The Dhcp6 instance has already started the
405 DHCPv6 S.A.R.R when Dhcp6CfgData is NULL.
406 @retval EFI_INVALID_PARAMETER Some of the parameter is invalid.
407 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
408 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
409
410 **/
411 EFI_STATUS
412 EFIAPI
413 EfiDhcp6Configure (
414 IN EFI_DHCP6_PROTOCOL *This,
415 IN EFI_DHCP6_CONFIG_DATA *Dhcp6CfgData OPTIONAL
416 )
417 {
418 EFI_TPL OldTpl;
419 EFI_STATUS Status;
420 LIST_ENTRY *Entry;
421 DHCP6_INSTANCE *Other;
422 DHCP6_INSTANCE *Instance;
423 DHCP6_SERVICE *Service;
424 UINTN Index;
425
426 if (This == NULL) {
427 return EFI_INVALID_PARAMETER;
428 }
429
430 Instance = DHCP6_INSTANCE_FROM_THIS (This);
431 Service = Instance->Service;
432
433 //
434 // Check the parameter of configure data.
435 //
436 if (Dhcp6CfgData != NULL) {
437 if (Dhcp6CfgData->OptionCount > 0 && Dhcp6CfgData->OptionList == NULL) {
438 return EFI_INVALID_PARAMETER;
439 }
440 if (Dhcp6CfgData->OptionList != NULL) {
441 for (Index = 0; Index < Dhcp6CfgData->OptionCount; Index++) {
442 if (Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptClientId ||
443 Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptRapidCommit ||
444 Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptReconfigureAccept ||
445 Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptIana ||
446 Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptIata
447 ) {
448 return EFI_INVALID_PARAMETER;
449 }
450 }
451 }
452
453 if (Dhcp6CfgData->IaDescriptor.Type != EFI_DHCP6_IA_TYPE_NA &&
454 Dhcp6CfgData->IaDescriptor.Type != EFI_DHCP6_IA_TYPE_TA
455 ) {
456 return EFI_INVALID_PARAMETER;
457 }
458
459 if (Dhcp6CfgData->IaInfoEvent == NULL && Dhcp6CfgData->SolicitRetransmission == NULL) {
460 return EFI_INVALID_PARAMETER;
461 }
462
463 if (Dhcp6CfgData->SolicitRetransmission != NULL &&
464 Dhcp6CfgData->SolicitRetransmission->Mrc == 0 &&
465 Dhcp6CfgData->SolicitRetransmission->Mrd == 0
466 ) {
467 return EFI_INVALID_PARAMETER;
468 }
469
470 //
471 // Make sure the (IaId, IaType) is unique over all the instances.
472 //
473 NET_LIST_FOR_EACH (Entry, &Service->Child) {
474 Other = NET_LIST_USER_STRUCT (Entry, DHCP6_INSTANCE, Link);
475 if (Other->IaCb.Ia != NULL &&
476 Other->IaCb.Ia->Descriptor.Type == Dhcp6CfgData->IaDescriptor.Type &&
477 Other->IaCb.Ia->Descriptor.IaId == Dhcp6CfgData->IaDescriptor.IaId
478 ) {
479 return EFI_INVALID_PARAMETER;
480 }
481 }
482 }
483
484 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
485
486 if (Dhcp6CfgData != NULL) {
487 //
488 // It's not allowed to configure one instance twice without configure null.
489 //
490 if (Instance->Config != NULL) {
491 gBS->RestoreTPL (OldTpl);
492 return EFI_ACCESS_DENIED;
493 }
494
495 //
496 // Duplicate config data including all reference buffers.
497 //
498 Instance->Config = AllocateZeroPool (sizeof (EFI_DHCP6_CONFIG_DATA));
499 if (Instance->Config == NULL) {
500 gBS->RestoreTPL (OldTpl);
501 return EFI_OUT_OF_RESOURCES;
502 }
503
504 Status = Dhcp6CopyConfigData (Instance->Config, Dhcp6CfgData);
505 if (EFI_ERROR(Status)) {
506 FreePool (Instance->Config);
507 gBS->RestoreTPL (OldTpl);
508 return EFI_OUT_OF_RESOURCES;
509 }
510
511 //
512 // Initialize the Ia descriptor from the config data, and leave the other
513 // fields of the Ia as default value 0.
514 //
515 Instance->IaCb.Ia = AllocateZeroPool (sizeof(EFI_DHCP6_IA));
516 if (Instance->IaCb.Ia == NULL) {
517 Dhcp6CleanupConfigData (Instance->Config);
518 FreePool (Instance->Config);
519 gBS->RestoreTPL (OldTpl);
520 return EFI_OUT_OF_RESOURCES;
521 }
522 CopyMem (
523 &Instance->IaCb.Ia->Descriptor,
524 &Dhcp6CfgData->IaDescriptor,
525 sizeof(EFI_DHCP6_IA_DESCRIPTOR)
526 );
527
528 } else {
529
530 if (Instance->Config == NULL) {
531 ASSERT (Instance->IaCb.Ia == NULL);
532 gBS->RestoreTPL (OldTpl);
533 return EFI_SUCCESS;
534 }
535
536 //
537 // It's not allowed to configure a started instance as null.
538 //
539 if (Instance->IaCb.Ia->State != Dhcp6Init) {
540 gBS->RestoreTPL (OldTpl);
541 return EFI_ACCESS_DENIED;
542 }
543
544 Dhcp6CleanupConfigData (Instance->Config);
545 FreePool (Instance->Config);
546 Instance->Config = NULL;
547
548 FreePool (Instance->IaCb.Ia);
549 Instance->IaCb.Ia = NULL;
550 }
551
552 gBS->RestoreTPL (OldTpl);
553
554 return EFI_SUCCESS;
555 }
556
557
558 /**
559 Request configuration information without the assignment of any
560 Ia addresses of the client.
561
562 The InfoRequest() function is used to request configuration information
563 without the assignment of any IPv6 address of the client. The client sends
564 out an Information Request packet to obtain the required configuration
565 information, and DHCPv6 server responds with a Reply packet containing
566 the information for the client. The received Reply packet will be passed
567 to the user by ReplyCallback function. If the user returns EFI_NOT_READY from
568 ReplyCallback, the Dhcp6 instance will continue to receive other Reply
569 packets unless timeout according to the Retransmission parameter.
570 Otherwise, the Information Request exchange process will be finished
571 successfully if user returns EFI_SUCCESS from ReplyCallback.
572
573 @param[in] This The pointer to the Dhcp6 protocol.
574 @param[in] SendClientId If TRUE, the DHCPv6 protocol instance will build Client
575 Identifier option and include it into Information Request
576 packet. Otherwise, Client Identifier option will not be included.
577 @param[in] OptionRequest The pointer to the buffer of option request options.
578 @param[in] OptionCount The option number in the OptionList.
579 @param[in] OptionList The list of appended options.
580 @param[in] Retransmission The pointer to the retransmission of the message.
581 @param[in] TimeoutEvent The event of timeout.
582 @param[in] ReplyCallback The callback function when the reply was received.
583 @param[in] CallbackContext The pointer to the parameter passed to the callback.
584
585 @retval EFI_SUCCESS The DHCPv6 information request exchange process
586 completed when TimeoutEvent is NULL. Information
587 Request packet has been sent to DHCPv6 server when
588 TimeoutEvent is not NULL.
589 @retval EFI_NO_RESPONSE The DHCPv6 information request exchange process failed
590 because of no response, or not all requested-options
591 are responded by DHCPv6 servers when Timeout happened.
592 @retval EFI_ABORTED The DHCPv6 information request exchange process was aborted
593 by user.
594 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
595 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
596 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
597
598 **/
599 EFI_STATUS
600 EFIAPI
601 EfiDhcp6InfoRequest (
602 IN EFI_DHCP6_PROTOCOL *This,
603 IN BOOLEAN SendClientId,
604 IN EFI_DHCP6_PACKET_OPTION *OptionRequest,
605 IN UINT32 OptionCount,
606 IN EFI_DHCP6_PACKET_OPTION *OptionList[] OPTIONAL,
607 IN EFI_DHCP6_RETRANSMISSION *Retransmission,
608 IN EFI_EVENT TimeoutEvent OPTIONAL,
609 IN EFI_DHCP6_INFO_CALLBACK ReplyCallback,
610 IN VOID *CallbackContext OPTIONAL
611 )
612 {
613 EFI_STATUS Status;
614 DHCP6_INSTANCE *Instance;
615 DHCP6_SERVICE *Service;
616 UINTN Index;
617 EFI_EVENT Timer;
618 EFI_STATUS TimerStatus;
619 UINTN GetMappingTimeOut;
620
621 if (This == NULL || OptionRequest == NULL || Retransmission == NULL || ReplyCallback == NULL) {
622 return EFI_INVALID_PARAMETER;
623 }
624
625 if (Retransmission != NULL && Retransmission->Mrc == 0 && Retransmission->Mrd == 0) {
626 return EFI_INVALID_PARAMETER;
627 }
628
629 if (OptionCount > 0 && OptionList == NULL) {
630 return EFI_INVALID_PARAMETER;
631 }
632
633 if (OptionList != NULL) {
634 for (Index = 0; Index < OptionCount; Index++) {
635 if (OptionList[Index]->OpCode == Dhcp6OptClientId || OptionList[Index]->OpCode == Dhcp6OptRequestOption) {
636 return EFI_INVALID_PARAMETER;
637 }
638 }
639 }
640
641 Instance = DHCP6_INSTANCE_FROM_THIS (This);
642 Service = Instance->Service;
643
644 Status = Dhcp6StartInfoRequest (
645 Instance,
646 SendClientId,
647 OptionRequest,
648 OptionCount,
649 OptionList,
650 Retransmission,
651 TimeoutEvent,
652 ReplyCallback,
653 CallbackContext
654 );
655 if (Status == EFI_NO_MAPPING) {
656 //
657 // The link local address is not ready, wait for some time and restart
658 // the DHCP6 information request process.
659 //
660 Status = Dhcp6GetMappingTimeOut(Service->Ip6Cfg, &GetMappingTimeOut);
661 if (EFI_ERROR(Status)) {
662 return Status;
663 }
664
665 Status = gBS->CreateEvent (EVT_TIMER, TPL_CALLBACK, NULL, NULL, &Timer);
666 if (EFI_ERROR (Status)) {
667 return Status;
668 }
669
670 //
671 // Start the timer, wait for link local address DAD to finish.
672 //
673 Status = gBS->SetTimer (Timer, TimerRelative, GetMappingTimeOut);
674 if (EFI_ERROR (Status)) {
675 gBS->CloseEvent (Timer);
676 return Status;
677 }
678
679 do {
680 TimerStatus = gBS->CheckEvent (Timer);
681 if (!EFI_ERROR (TimerStatus)) {
682 Status = Dhcp6StartInfoRequest (
683 Instance,
684 SendClientId,
685 OptionRequest,
686 OptionCount,
687 OptionList,
688 Retransmission,
689 TimeoutEvent,
690 ReplyCallback,
691 CallbackContext
692 );
693 }
694 } while (TimerStatus == EFI_NOT_READY);
695
696 gBS->CloseEvent (Timer);
697 }
698 if (EFI_ERROR (Status)) {
699 return Status;
700 }
701
702 //
703 // Poll udp out of the net tpl if synchoronus call.
704 //
705 if (TimeoutEvent == NULL) {
706
707 while (Instance->UdpSts == EFI_ALREADY_STARTED) {
708 Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);
709 }
710 return Instance->UdpSts;
711 }
712
713 return EFI_SUCCESS;
714 }
715
716
717 /**
718 Manually extend the valid and preferred lifetimes for the IPv6 addresses
719 of the configured IA and update other configuration parameters by sending a
720 Renew or Rebind packet.
721
722 The RenewRebind() function is used to manually extend the valid and preferred
723 lifetimes for the IPv6 addresses of the configured IA, and update other
724 configuration parameters by sending Renew or Rebind packet.
725 - When RebindRequest is FALSE and the state of the configured IA is Dhcp6Bound,
726 it sends Renew packet to the previously DHCPv6 server and transfer the
727 state of the configured IA to Dhcp6Renewing. If valid Reply packet received,
728 the state transfers to Dhcp6Bound and the valid and preferred timer restarts.
729 If fails, the state transfers to Dhcp6Bound, but the timer continues.
730 - When RebindRequest is TRUE and the state of the configured IA is Dhcp6Bound,
731 it will send a Rebind packet. If valid Reply packet is received, the state transfers
732 to Dhcp6Bound and the valid and preferred timer restarts. If it fails, the state
733 transfers to Dhcp6Init, and the IA can't be used.
734
735 @param[in] This The pointer to the Dhcp6 protocol.
736 @param[in] RebindRequest If TRUE, Rebind packet will be sent and enter Dhcp6Rebinding state.
737 Otherwise, Renew packet will be sent and enter Dhcp6Renewing state.
738
739 @retval EFI_SUCCESS The DHCPv6 renew/rebind exchange process has
740 completed and at least one IPv6 address of the
741 configured IA has been bound again when
742 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL.
743 The EFI DHCPv6 Protocol instance has sent Renew
744 or Rebind packet when
745 EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
746 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
747 state of the configured IA is not in Dhcp6Bound.
748 @retval EFI_ALREADY_STARTED The state of the configured IA has already entered
749 Dhcp6Renewing when RebindRequest is FALSE.
750 The state of the configured IA has already entered
751 Dhcp6Rebinding when RebindRequest is TRUE.
752 @retval EFI_ABORTED The DHCPv6 renew/rebind exchange process aborted
753 by the user.
754 @retval EFI_NO_RESPONSE The DHCPv6 renew/rebind exchange process failed
755 because of no response.
756 @retval EFI_NO_MAPPING No IPv6 address has been bound to the configured
757 IA after the DHCPv6 renew/rebind exchange process.
758 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
759 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
760
761 **/
762 EFI_STATUS
763 EFIAPI
764 EfiDhcp6RenewRebind (
765 IN EFI_DHCP6_PROTOCOL *This,
766 IN BOOLEAN RebindRequest
767 )
768 {
769 EFI_STATUS Status;
770 EFI_TPL OldTpl;
771 DHCP6_INSTANCE *Instance;
772 DHCP6_SERVICE *Service;
773
774 if (This == NULL) {
775 return EFI_INVALID_PARAMETER;
776 }
777
778 Instance = DHCP6_INSTANCE_FROM_THIS (This);
779 Service = Instance->Service;
780
781 //
782 // The instance hasn't been configured.
783 //
784 if (Instance->Config == NULL) {
785 return EFI_ACCESS_DENIED;
786 }
787
788 ASSERT (Instance->IaCb.Ia != NULL);
789
790 //
791 // The instance has already entered renewing or rebinding state.
792 //
793 if ((Instance->IaCb.Ia->State == Dhcp6Rebinding && RebindRequest) ||
794 (Instance->IaCb.Ia->State == Dhcp6Renewing && !RebindRequest)
795 ) {
796 return EFI_ALREADY_STARTED;
797 }
798
799 if (Instance->IaCb.Ia->State != Dhcp6Bound) {
800 return EFI_ACCESS_DENIED;
801 }
802
803 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
804 Instance->UdpSts = EFI_ALREADY_STARTED;
805
806 //
807 // Send renew/rebind message to start exchange process.
808 //
809 Status = Dhcp6SendRenewRebindMsg (Instance, RebindRequest);
810
811 if (EFI_ERROR (Status)) {
812 goto ON_ERROR;
813 }
814
815 //
816 // Register receive callback for the stateful exchange process.
817 //
818 Status = UdpIoRecvDatagram(
819 Service->UdpIo,
820 Dhcp6ReceivePacket,
821 Service,
822 0
823 );
824
825 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
826 goto ON_ERROR;
827 }
828
829 gBS->RestoreTPL (OldTpl);
830
831 //
832 // Poll udp out of the net tpl if synchoronus call.
833 //
834 if (Instance->Config->IaInfoEvent == NULL) {
835
836 while (Instance->UdpSts == EFI_ALREADY_STARTED) {
837 Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);
838 }
839 return Instance->UdpSts;
840 }
841
842 return EFI_SUCCESS;
843
844 ON_ERROR:
845
846 gBS->RestoreTPL (OldTpl);
847 return Status;
848 }
849
850
851 /**
852 Inform that one or more addresses assigned by a server are already
853 in use by another node.
854
855 The Decline() function is used to manually decline the assignment of
856 IPv6 addresses, which have been already used by another node. If all
857 IPv6 addresses of the configured IA are declined through this function,
858 the state of the IA will switch through Dhcp6Declining to Dhcp6Init.
859 Otherwise, the state of the IA will restore to Dhcp6Bound after the
860 declining process. The Decline() can only be called when the IA is in
861 Dhcp6Bound state. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL,
862 this function is a blocking operation. It will return after the
863 declining process finishes, or aborted by user.
864
865 @param[in] This The pointer to EFI_DHCP6_PROTOCOL.
866 @param[in] AddressCount The number of declining addresses.
867 @param[in] Addresses The pointer to the buffer stored the declining
868 addresses.
869
870 @retval EFI_SUCCESS The DHCPv6 decline exchange process completed
871 when EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
872 The Dhcp6 instance sent Decline packet when
873 EFI_DHCP6_CONFIG_DATA.IaInfoEvent was not NULL.
874 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
875 state of the configured IA is not in Dhcp6Bound.
876 @retval EFI_ABORTED The DHCPv6 decline exchange process aborted by user.
877 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
878 the configured IA for this instance.
879 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
880 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
881
882 **/
883 EFI_STATUS
884 EFIAPI
885 EfiDhcp6Decline (
886 IN EFI_DHCP6_PROTOCOL *This,
887 IN UINT32 AddressCount,
888 IN EFI_IPv6_ADDRESS *Addresses
889 )
890 {
891 EFI_STATUS Status;
892 EFI_TPL OldTpl;
893 EFI_DHCP6_IA *DecIa;
894 DHCP6_INSTANCE *Instance;
895 DHCP6_SERVICE *Service;
896
897 if (This == NULL || AddressCount == 0 || Addresses == NULL) {
898 return EFI_INVALID_PARAMETER;
899 }
900
901 Instance = DHCP6_INSTANCE_FROM_THIS (This);
902 Service = Instance->Service;
903
904 //
905 // The instance hasn't been configured.
906 //
907 if (Instance->Config == NULL) {
908 return EFI_ACCESS_DENIED;
909 }
910
911 ASSERT (Instance->IaCb.Ia != NULL);
912
913 if (Instance->IaCb.Ia->State != Dhcp6Bound) {
914 return EFI_ACCESS_DENIED;
915 }
916
917 //
918 // Check whether all the declined addresses belongs to the configured Ia.
919 //
920 Status = Dhcp6CheckAddress (Instance->IaCb.Ia, AddressCount, Addresses);
921
922 if (EFI_ERROR(Status)) {
923 return Status;
924 }
925
926 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
927 Instance->UdpSts = EFI_ALREADY_STARTED;
928
929 //
930 // Deprive of all the declined addresses from the configured Ia, and create a
931 // DeclineIa used to create decline message.
932 //
933 DecIa = Dhcp6DepriveAddress (Instance->IaCb.Ia, AddressCount, Addresses);
934
935 if (DecIa == NULL) {
936 Status = EFI_OUT_OF_RESOURCES;
937 goto ON_ERROR;
938 }
939
940 //
941 // Send the decline message to start exchange process.
942 //
943 Status = Dhcp6SendDeclineMsg (Instance, DecIa);
944
945 if (EFI_ERROR (Status)) {
946 goto ON_ERROR;
947 }
948
949 //
950 // Register receive callback for the stateful exchange process.
951 //
952 Status = UdpIoRecvDatagram(
953 Service->UdpIo,
954 Dhcp6ReceivePacket,
955 Service,
956 0
957 );
958
959 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
960 goto ON_ERROR;
961 }
962
963 FreePool (DecIa);
964 gBS->RestoreTPL (OldTpl);
965
966 //
967 // Poll udp out of the net tpl if synchoronus call.
968 //
969 if (Instance->Config->IaInfoEvent == NULL) {
970
971 while (Instance->UdpSts == EFI_ALREADY_STARTED) {
972 Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);
973 }
974 return Instance->UdpSts;
975 }
976
977 return EFI_SUCCESS;
978
979 ON_ERROR:
980
981 if (DecIa != NULL) {
982 FreePool (DecIa);
983 }
984 gBS->RestoreTPL (OldTpl);
985
986 return Status;
987 }
988
989
990 /**
991 Release one or more addresses associated with the configured Ia
992 for current instance.
993
994 The Release() function is used to manually release one or more
995 IPv6 addresses. If AddressCount is zero, it will release all IPv6
996 addresses of the configured IA. If all IPv6 addresses of the IA are
997 released through this function, the state of the IA will switch
998 through Dhcp6Releasing to Dhcp6Init, otherwise, the state of the
999 IA will restore to Dhcp6Bound after the releasing process.
1000 The Release() can only be called when the IA is in Dhcp6Bound state.
1001 If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL, the function is
1002 a blocking operation. It will return after the releasing process
1003 finishes, or is aborted by user.
1004
1005 @param[in] This The pointer to the Dhcp6 protocol.
1006 @param[in] AddressCount The number of releasing addresses.
1007 @param[in] Addresses The pointer to the buffer stored the releasing
1008 addresses.
1009
1010 @retval EFI_SUCCESS The DHCPv6 release exchange process
1011 completed when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
1012 was NULL. The Dhcp6 instance was sent Release
1013 packet when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
1014 was not NULL.
1015 @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
1016 state of the configured IA is not in Dhcp6Bound.
1017 @retval EFI_ABORTED The DHCPv6 release exchange process aborted by user.
1018 @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
1019 the configured IA for this instance.
1020 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
1021 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1022
1023 **/
1024 EFI_STATUS
1025 EFIAPI
1026 EfiDhcp6Release (
1027 IN EFI_DHCP6_PROTOCOL *This,
1028 IN UINT32 AddressCount,
1029 IN EFI_IPv6_ADDRESS *Addresses
1030 )
1031 {
1032 EFI_STATUS Status;
1033 EFI_TPL OldTpl;
1034 EFI_DHCP6_IA *RelIa;
1035 DHCP6_INSTANCE *Instance;
1036 DHCP6_SERVICE *Service;
1037
1038 if (This == NULL || (AddressCount != 0 && Addresses == NULL)) {
1039 return EFI_INVALID_PARAMETER;
1040 }
1041
1042 Instance = DHCP6_INSTANCE_FROM_THIS (This);
1043 Service = Instance->Service;
1044
1045 //
1046 // The instance hasn't been configured.
1047 //
1048 if (Instance->Config == NULL) {
1049 return EFI_ACCESS_DENIED;
1050 }
1051
1052 ASSERT (Instance->IaCb.Ia != NULL);
1053
1054 if (Instance->IaCb.Ia->State != Dhcp6Bound) {
1055 return EFI_ACCESS_DENIED;
1056 }
1057
1058 //
1059 // Check whether all the released addresses belongs to the configured Ia.
1060 //
1061 Status = Dhcp6CheckAddress (Instance->IaCb.Ia, AddressCount, Addresses);
1062
1063 if (EFI_ERROR(Status)) {
1064 return Status;
1065 }
1066
1067 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1068 Instance->UdpSts = EFI_ALREADY_STARTED;
1069
1070 //
1071 // Deprive of all the released addresses from the configured Ia, and create a
1072 // ReleaseIa used to create release message.
1073 //
1074 RelIa = Dhcp6DepriveAddress (Instance->IaCb.Ia, AddressCount, Addresses);
1075
1076 if (RelIa == NULL) {
1077 Status = EFI_OUT_OF_RESOURCES;
1078 goto ON_ERROR;
1079 }
1080
1081 //
1082 // Send the release message to start exchange process.
1083 //
1084 Status = Dhcp6SendReleaseMsg (Instance, RelIa);
1085
1086 if (EFI_ERROR (Status)) {
1087 goto ON_ERROR;
1088 }
1089
1090 //
1091 // Register receive callback for the stateful exchange process.
1092 //
1093 Status = UdpIoRecvDatagram(
1094 Service->UdpIo,
1095 Dhcp6ReceivePacket,
1096 Service,
1097 0
1098 );
1099
1100 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
1101 goto ON_ERROR;
1102 }
1103
1104 FreePool (RelIa);
1105 gBS->RestoreTPL (OldTpl);
1106
1107 //
1108 // Poll udp out of the net tpl if synchoronus call.
1109 //
1110 if (Instance->Config->IaInfoEvent == NULL) {
1111 while (Instance->UdpSts == EFI_ALREADY_STARTED) {
1112 Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);
1113 }
1114 return Instance->UdpSts;
1115 }
1116
1117 return EFI_SUCCESS;
1118
1119 ON_ERROR:
1120
1121 if (RelIa != NULL) {
1122 FreePool (RelIa);
1123 }
1124 gBS->RestoreTPL (OldTpl);
1125
1126 return Status;
1127 }
1128
1129
1130 /**
1131 Parse the option data in the Dhcp6 packet.
1132
1133 The Parse() function is used to retrieve the option list in the DHCPv6 packet.
1134
1135 @param[in] This The pointer to the Dhcp6 protocol.
1136 @param[in] Packet The pointer to the Dhcp6 packet.
1137 @param[in, out] OptionCount The number of option in the packet.
1138 @param[out] PacketOptionList The array of pointers to each option in the packet.
1139
1140 @retval EFI_SUCCESS The packet was successfully parsed.
1141 @retval EFI_INVALID_PARAMETER Some parameter is NULL.
1142 @retval EFI_BUFFER_TOO_SMALL *OptionCount is smaller than the number of options
1143 that were found in the Packet.
1144
1145 **/
1146 EFI_STATUS
1147 EFIAPI
1148 EfiDhcp6Parse (
1149 IN EFI_DHCP6_PROTOCOL *This,
1150 IN EFI_DHCP6_PACKET *Packet,
1151 IN OUT UINT32 *OptionCount,
1152 OUT EFI_DHCP6_PACKET_OPTION *PacketOptionList[] OPTIONAL
1153 )
1154 {
1155 UINT32 OptCnt;
1156 UINT32 OptLen;
1157 UINT16 DataLen;
1158 UINT8 *Start;
1159 UINT8 *End;
1160
1161 if (This == NULL || Packet == NULL || OptionCount == NULL) {
1162 return EFI_INVALID_PARAMETER;
1163 }
1164
1165 if (*OptionCount != 0 && PacketOptionList == NULL) {
1166 return EFI_INVALID_PARAMETER;
1167 }
1168
1169 if (Packet->Length > Packet->Size || Packet->Length < sizeof (EFI_DHCP6_HEADER)) {
1170 return EFI_INVALID_PARAMETER;
1171 }
1172
1173 //
1174 // The format of Dhcp6 option:
1175 //
1176 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1177 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1178 // | option-code | option-len (option data) |
1179 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1180 // | option-data |
1181 // | (option-len octets) |
1182 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1183 //
1184
1185 OptCnt = 0;
1186 OptLen = Packet->Length - sizeof (EFI_DHCP6_HEADER);
1187 Start = Packet->Dhcp6.Option;
1188 End = Start + OptLen;
1189
1190 //
1191 // Calculate the number of option in the packet.
1192 //
1193 while (Start < End) {
1194 DataLen = ((EFI_DHCP6_PACKET_OPTION *) Start)->OpLen;
1195 Start += (NTOHS (DataLen) + 4);
1196 OptCnt++;
1197 }
1198
1199 //
1200 // It will return buffer too small if pass-in option count is smaller than the
1201 // actual count of options in the packet.
1202 //
1203 if (OptCnt > *OptionCount) {
1204 *OptionCount = OptCnt;
1205 return EFI_BUFFER_TOO_SMALL;
1206 }
1207
1208 ZeroMem (
1209 PacketOptionList,
1210 (*OptionCount * sizeof (EFI_DHCP6_PACKET_OPTION *))
1211 );
1212
1213 OptCnt = 0;
1214 Start = Packet->Dhcp6.Option;
1215
1216 while (Start < End) {
1217
1218 PacketOptionList[OptCnt] = (EFI_DHCP6_PACKET_OPTION *) Start;
1219 DataLen = ((EFI_DHCP6_PACKET_OPTION *) Start)->OpLen;
1220 Start += (NTOHS (DataLen) + 4);
1221 OptCnt++;
1222 }
1223
1224 return EFI_SUCCESS;
1225 }
1226