85 Status =
gBS->OpenProtocol (
87 &gEfiUdp4ServiceBindingProtocolGuid,
89 This->DriverBindingHandle,
91 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
117 UdpConfigData.AcceptBroadcast =
TRUE;
118 UdpConfigData.AcceptPromiscuous =
FALSE;
119 UdpConfigData.AcceptAnyPort =
FALSE;
120 UdpConfigData.AllowDuplicatePort =
TRUE;
121 UdpConfigData.TypeOfService = 0;
122 UdpConfigData.TimeToLive = 64;
123 UdpConfigData.DoNotFragment =
FALSE;
124 UdpConfigData.ReceiveTimeout = 0;
125 UdpConfigData.TransmitTimeout = 0;
127 UdpConfigData.UseDefaultAddress =
FALSE;
128 UdpConfigData.StationPort = DHCP_CLIENT_PORT;
129 UdpConfigData.RemotePort = DHCP_SERVER_PORT;
135 return UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, &UdpConfigData);
155 if (DhcpSb->UdpIo !=
NULL) {
157 DhcpSb->UdpIo =
NULL;
160 if (DhcpSb->Timer !=
NULL) {
162 gBS->CloseEvent (DhcpSb->Timer);
164 DhcpSb->Timer =
NULL;
196 if (EFI_ERROR (Status)) {
197 DEBUG ((DEBUG_ERROR,
"%a failed to generate random number: %r\n", __func__, Status));
204 if (DhcpSb ==
NULL) {
205 return EFI_OUT_OF_RESOURCES;
208 DhcpSb->Signature = DHCP_SERVICE_SIGNATURE;
209 DhcpSb->ServiceState = DHCP_UNCONFIGED;
210 DhcpSb->Controller = Controller;
211 DhcpSb->Image = ImageHandle;
214 DhcpSb->Xid = Random;
216 &DhcpSb->ServiceBinding,
217 &mDhcp4ServiceBindingTemplate,
223 Status =
gBS->CreateEvent (
224 EVT_NOTIFY_SIGNAL | EVT_TIMER,
231 if (EFI_ERROR (Status)) {
243 if (DhcpSb->UdpIo ==
NULL) {
244 Status = EFI_OUT_OF_RESOURCES;
249 DhcpSb->HwType = DhcpSb->UdpIo->SnpMode.
IfType;
294 Status =
gBS->OpenProtocol (
296 &gEfiDhcp4ServiceBindingProtocolGuid,
298 This->DriverBindingHandle,
300 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
304 return EFI_ALREADY_STARTED;
309 if (EFI_ERROR (Status)) {
313 ASSERT (DhcpSb !=
NULL);
320 if (EFI_ERROR (Status)) {
326 if (EFI_ERROR (Status)) {
333 Status =
gBS->InstallMultipleProtocolInterfaces (
335 &gEfiDhcp4ServiceBindingProtocolGuid,
336 &DhcpSb->ServiceBinding,
340 if (EFI_ERROR (Status)) {
372 if ((Entry ==
NULL) || (Context ==
NULL)) {
373 return EFI_INVALID_PARAMETER;
376 Instance = NET_LIST_USER_STRUCT_S (Entry,
DHCP_PROTOCOL, Link, DHCP_PROTOCOL_SIGNATURE);
379 return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
422 if (NicHandle ==
NULL) {
426 Status =
gBS->OpenProtocol (
428 &gEfiDhcp4ServiceBindingProtocolGuid,
429 (VOID **)&ServiceBinding,
430 This->DriverBindingHandle,
432 EFI_OPEN_PROTOCOL_GET_PROTOCOL
435 if (EFI_ERROR (Status)) {
436 return EFI_DEVICE_ERROR;
439 DhcpSb = DHCP_SERVICE_FROM_THIS (ServiceBinding);
444 List = &DhcpSb->Children;
451 if (EFI_ERROR (Status) || (ListLength != 0)) {
452 Status = EFI_DEVICE_ERROR;
456 if ((NumberOfChildren == 0) && !
IsListEmpty (&DhcpSb->Children)) {
457 Status = EFI_DEVICE_ERROR;
460 if ((NumberOfChildren == 0) &&
IsListEmpty (&DhcpSb->Children)) {
464 DhcpSb->ServiceState = DHCP_DESTROY;
466 gBS->UninstallProtocolInterface (
468 &gEfiDhcp4ServiceBindingProtocolGuid,
474 if (gDhcpControllerNameTable !=
NULL) {
476 gDhcpControllerNameTable =
NULL;
500 Instance->Signature = DHCP_PROTOCOL_SIGNATURE;
501 CopyMem (&Instance->Dhcp4Protocol, &mDhcp4ProtocolTemplate, sizeof (Instance->Dhcp4Protocol));
503 Instance->Handle =
NULL;
504 Instance->Service = DhcpSb;
505 Instance->InDestroy =
FALSE;
506 Instance->CompletionEvent =
NULL;
507 Instance->RenewRebindEvent =
NULL;
508 Instance->Token =
NULL;
509 Instance->UdpIo =
NULL;
510 Instance->ElaspedTime = 0;
546 if ((This ==
NULL) || (ChildHandle ==
NULL)) {
547 return EFI_INVALID_PARAMETER;
552 if (Instance ==
NULL) {
553 return EFI_OUT_OF_RESOURCES;
556 DhcpSb = DHCP_SERVICE_FROM_THIS (This);
562 Status =
gBS->InstallMultipleProtocolInterfaces (
564 &gEfiDhcp4ProtocolGuid,
565 &Instance->Dhcp4Protocol,
569 if (EFI_ERROR (Status)) {
574 Instance->Handle = *ChildHandle;
579 Status =
gBS->OpenProtocol (
580 DhcpSb->UdpIo->UdpHandle,
581 &gEfiUdp4ProtocolGuid,
585 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
587 if (EFI_ERROR (Status)) {
588 gBS->UninstallMultipleProtocolInterfaces (
590 &gEfiDhcp4ProtocolGuid,
591 &Instance->Dhcp4Protocol,
599 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
602 DhcpSb->NumChildren++;
604 gBS->RestoreTPL (OldTpl);
640 if ((This ==
NULL) || (ChildHandle ==
NULL)) {
641 return EFI_INVALID_PARAMETER;
647 Status =
gBS->OpenProtocol (
649 &gEfiDhcp4ProtocolGuid,
653 EFI_OPEN_PROTOCOL_GET_PROTOCOL
656 if (EFI_ERROR (Status)) {
657 return EFI_UNSUPPORTED;
660 Instance = DHCP_INSTANCE_FROM_THIS (Dhcp);
661 DhcpSb = DHCP_SERVICE_FROM_THIS (This);
663 if (Instance->Service != DhcpSb) {
664 return EFI_INVALID_PARAMETER;
673 if (Instance->InDestroy) {
677 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
678 Instance->InDestroy =
TRUE;
684 DhcpSb->UdpIo->UdpHandle,
685 &gEfiUdp4ProtocolGuid,
693 gBS->RestoreTPL (OldTpl);
694 Status =
gBS->UninstallProtocolInterface (
696 &gEfiDhcp4ProtocolGuid,
699 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
700 if (EFI_ERROR (Status)) {
701 Instance->InDestroy =
FALSE;
703 gBS->RestoreTPL (OldTpl);
707 if (DhcpSb->ActiveChild == Instance) {
712 DhcpSb->NumChildren--;
714 if (Instance->UdpIo !=
NULL) {
717 Instance->UdpIo->UdpHandle,
718 &gEfiUdp4ProtocolGuid,
719 Instance->Service->Image,
723 Instance->UdpIo =
NULL;
724 Instance->Token =
NULL;
727 gBS->RestoreTPL (OldTpl);
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI Dhcp4DriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
EFI_STATUS EFIAPI Dhcp4DriverEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI Dhcp4DriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
EFI_STATUS EFIAPI Dhcp4DriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
VOID DhcpInitProtocol(IN DHCP_SERVICE *DhcpSb, IN OUT DHCP_PROTOCOL *Instance)
EFI_STATUS Dhcp4CreateService(IN EFI_HANDLE Controller, IN EFI_HANDLE ImageHandle, OUT DHCP_SERVICE **Service)
EFI_STATUS EFIAPI Dhcp4ServiceBindingDestroyChild(IN EFI_SERVICE_BINDING_PROTOCOL *This, IN EFI_HANDLE ChildHandle)
EFI_STATUS EFIAPI Dhcp4ServiceBindingCreateChild(IN EFI_SERVICE_BINDING_PROTOCOL *This, IN EFI_HANDLE *ChildHandle)
EFI_STATUS EFIAPI Dhcp4DestroyChildEntry(IN LIST_ENTRY *Entry, IN VOID *Context)
EFI_STATUS EFIAPI DhcpConfigUdpIo(IN UDP_IO *UdpIo, IN VOID *Context)
EFI_STATUS Dhcp4CloseService(IN DHCP_SERVICE *DhcpSb)
VOID DhcpYieldControl(IN DHCP_SERVICE *DhcpSb)
VOID DhcpCleanLease(IN DHCP_SERVICE *DhcpSb)
VOID EFIAPI DhcpOnTimerTick(IN EFI_EVENT Event, IN VOID *Context)
VOID EFIAPI DhcpInput(NET_BUF *UdpPacket, UDP_END_POINT *EndPoint, EFI_STATUS IoStatus, VOID *Context)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define DEBUG(Expression)
VOID EFIAPI NetbufQueInit(IN OUT NET_BUF_QUEUE *NbufQue)
EFI_STATUS EFIAPI PseudoRandomU32(OUT UINT32 *Output)
EFI_HANDLE EFIAPI NetLibGetNicHandle(IN EFI_HANDLE Controller, IN EFI_GUID *ProtocolGuid)
EFI_STATUS EFIAPI NetDestroyLinkList(IN LIST_ENTRY *List, IN NET_DESTROY_LINK_LIST_CALLBACK CallBack, IN VOID *Context OPTIONAL, OUT UINTN *ListLength OPTIONAL)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
VOID EFIAPI UdpIoCleanIo(IN UDP_IO *UdpIo)
EFI_STATUS EFIAPI UdpIoRecvDatagram(IN UDP_IO *UdpIo, IN UDP_IO_CALLBACK CallBack, IN VOID *Context, IN UINT32 HeadLen)
EFI_STATUS EFIAPI UdpIoFreeIo(IN UDP_IO *UdpIo)
UDP_IO *EFIAPI UdpIoCreateIo(IN EFI_HANDLE Controller, IN EFI_HANDLE ImageHandle, IN UDP_IO_CONFIG Configure, IN UINT8 UdpVersion, IN VOID *Context)
EFI_STATUS EFIAPI EfiLibInstallDriverBindingComponentName2(IN CONST EFI_HANDLE ImageHandle, IN CONST EFI_SYSTEM_TABLE *SystemTable, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN EFI_HANDLE DriverBindingHandle, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
EFI_STATUS EFIAPI FreeUnicodeStringTable(IN EFI_UNICODE_STRING_TABLE *UnicodeStringTable)
EFI_HANDLE DriverBindingHandle
EFI_MAC_ADDRESS CurrentAddress