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