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