14UINT8 mInterestedDhcp4Tags[HTTP_BOOT_DHCP4_TAG_INDEX_MAX] = {
15 DHCP4_TAG_BOOTFILE_LEN,
19 DHCP4_TAG_VENDOR_CLASS_ID,
27UINT32 mHttpDhcpTimeout[4] = { 4, 8, 16, 32 };
56 OptList[Index]->OpCode = DHCP4_TAG_PARA_LIST;
57 OptList[Index]->Length = 27;
59 OptEnt.Para->ParaList[0] = DHCP4_TAG_NETMASK;
60 OptEnt.Para->ParaList[1] = DHCP4_TAG_TIME_OFFSET;
61 OptEnt.Para->ParaList[2] = DHCP4_TAG_ROUTER;
62 OptEnt.Para->ParaList[3] = DHCP4_TAG_TIME_SERVER;
63 OptEnt.Para->ParaList[4] = DHCP4_TAG_NAME_SERVER;
64 OptEnt.Para->ParaList[5] = DHCP4_TAG_DNS_SERVER;
65 OptEnt.Para->ParaList[6] = DHCP4_TAG_HOSTNAME;
66 OptEnt.Para->ParaList[7] = DHCP4_TAG_BOOTFILE_LEN;
67 OptEnt.Para->ParaList[8] = DHCP4_TAG_DOMAINNAME;
68 OptEnt.Para->ParaList[9] = DHCP4_TAG_ROOTPATH;
69 OptEnt.Para->ParaList[10] = DHCP4_TAG_EXTEND_PATH;
70 OptEnt.Para->ParaList[11] = DHCP4_TAG_EMTU;
71 OptEnt.Para->ParaList[12] = DHCP4_TAG_TTL;
72 OptEnt.Para->ParaList[13] = DHCP4_TAG_BROADCAST;
73 OptEnt.Para->ParaList[14] = DHCP4_TAG_NIS_DOMAIN;
74 OptEnt.Para->ParaList[15] = DHCP4_TAG_NIS_SERVER;
75 OptEnt.Para->ParaList[16] = DHCP4_TAG_NTP_SERVER;
76 OptEnt.Para->ParaList[17] = DHCP4_TAG_VENDOR;
77 OptEnt.Para->ParaList[18] = DHCP4_TAG_REQUEST_IP;
78 OptEnt.Para->ParaList[19] = DHCP4_TAG_LEASE;
79 OptEnt.Para->ParaList[20] = DHCP4_TAG_SERVER_ID;
80 OptEnt.Para->ParaList[21] = DHCP4_TAG_T1;
81 OptEnt.Para->ParaList[22] = DHCP4_TAG_T2;
82 OptEnt.Para->ParaList[23] = DHCP4_TAG_VENDOR_CLASS_ID;
83 OptEnt.Para->ParaList[25] = DHCP4_TAG_BOOTFILE;
84 OptEnt.Para->ParaList[26] = DHCP4_TAG_UUID;
86 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
91 OptList[Index]->OpCode = DHCP4_TAG_UUID;
94 OptEnt.Uuid->Type = 0;
103 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
108 OptList[Index]->OpCode = DHCP4_TAG_UNDI;
112 if (Private->Nii !=
NULL) {
113 OptEnt.Undi->Type = Private->Nii->Type;
114 OptEnt.Undi->MajorVer = Private->Nii->MajorVer;
115 OptEnt.Undi->MinorVer = Private->Nii->MinorVer;
117 OptEnt.Undi->Type = DEFAULT_UNDI_TYPE;
118 OptEnt.Undi->MajorVer = DEFAULT_UNDI_MAJOR;
119 OptEnt.Undi->MinorVer = DEFAULT_UNDI_MINOR;
123 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
128 OptList[Index]->OpCode = DHCP4_TAG_ARCH;
131 Value = HTONS (EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE);
132 CopyMem (&OptEnt.Arch->Type, &Value, sizeof (UINT16));
134 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
139 OptList[Index]->OpCode = DHCP4_TAG_VENDOR_CLASS_ID;
144 DEFAULT_CLASS_ID_DATA,
148 EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE,
149 OptEnt.Clid->ArchitectureType,
150 sizeof (OptEnt.Clid->ArchitectureType)
153 if (Private->Nii !=
NULL) {
154 CopyMem (OptEnt.Clid->InterfaceName, Private->Nii->StringId, sizeof (OptEnt.Clid->InterfaceName));
188 while (Offset < Length && Option->OpCode != DHCP4_TAG_EOP) {
189 if (Option->
OpCode == OptTag) {
202 Offset += Option->
Length + 2;
227 if (Dst->Size < Src->Length) {
228 return EFI_BUFFER_TOO_SMALL;
231 CopyMem (&Dst->Dhcp4, &Src->Dhcp4, Src->Length);
232 Dst->Length = Src->Length;
255 BOOLEAN IsProxyOffer;
258 BOOLEAN IpExpressedUri;
263 BOOLEAN FileFieldOverloaded;
266 IpExpressedUri =
FALSE;
267 IsProxyOffer =
FALSE;
269 FileFieldOverloaded =
FALSE;
271 ZeroMem (Cache4->OptList, sizeof (Cache4->OptList));
273 Offer = &Cache4->Packet.Offer;
274 Options = Cache4->OptList;
280 for (Index = 0; Index < HTTP_BOOT_DHCP4_TAG_INDEX_MAX; Index++) {
283 GET_OPTION_BUFFER_LEN (Offer),
284 mInterestedDhcp4Tags[Index]
292 Option = Options[HTTP_BOOT_DHCP4_TAG_INDEX_OVERLOAD];
293 if (Option !=
NULL) {
294 if ((Option->
Data[0] & HTTP_BOOT_DHCP4_OVERLOAD_FILE) != 0) {
295 FileFieldOverloaded =
TRUE;
296 for (Index = 0; Index < HTTP_BOOT_DHCP4_TAG_INDEX_MAX; Index++) {
297 if (Options[Index] ==
NULL) {
299 (UINT8 *)Offer->Dhcp4.
Header.BootFileName,
300 sizeof (Offer->Dhcp4.
Header.BootFileName),
301 mInterestedDhcp4Tags[Index]
307 if ((Option->
Data[0] & HTTP_BOOT_DHCP4_OVERLOAD_SERVER_NAME) != 0) {
308 for (Index = 0; Index < HTTP_BOOT_DHCP4_TAG_INDEX_MAX; Index++) {
309 if (Options[Index] ==
NULL) {
311 (UINT8 *)Offer->Dhcp4.
Header.ServerName,
312 sizeof (Offer->Dhcp4.
Header.ServerName),
313 mInterestedDhcp4Tags[Index]
330 Option = Options[HTTP_BOOT_DHCP4_TAG_INDEX_CLASS_ID];
331 if ((Option !=
NULL) && (Option->
Length >= 10) &&
340 Option = Options[HTTP_BOOT_DHCP4_TAG_INDEX_DNS_SERVER];
341 if (Option !=
NULL) {
351 if (Options[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE] !=
NULL) {
356 Ptr8 = (UINT8 *)&Options[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data[0];
357 Ptr8 += Options[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Length;
358 if (*(Ptr8 - 1) !=
'\0') {
361 }
else if (!FileFieldOverloaded && (Offer->Dhcp4.
Header.BootFileName[0] != 0)) {
367 (&Offer->Dhcp4.
Header.BootFileName[0] -
374 if (IsHttpOffer && (Options[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE] ==
NULL)) {
375 return EFI_DEVICE_ERROR;
383 (CHAR8 *)Options[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data,
384 (UINT32)
AsciiStrLen ((CHAR8 *)Options[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data),
388 if (EFI_ERROR (Status)) {
389 return EFI_DEVICE_ERROR;
393 (CHAR8 *)Options[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data,
397 IpExpressedUri = !EFI_ERROR (Status);
404 if (IpExpressedUri) {
406 OfferType = HttpOfferTypeProxyIpUri;
408 OfferType = IsDnsOffer ? HttpOfferTypeDhcpIpUriDns : HttpOfferTypeDhcpIpUri;
412 OfferType = IsDnsOffer ? HttpOfferTypeDhcpNameUriDns : HttpOfferTypeDhcpNameUri;
414 OfferType = HttpOfferTypeProxyNameUri;
419 OfferType = IsDnsOffer ? HttpOfferTypeDhcpDns : HttpOfferTypeDhcpOnly;
421 if (Cache4->UriParser !=
NULL) {
425 return EFI_DEVICE_ERROR;
429 Cache4->OfferType = OfferType;
453 ASSERT (Private->OfferNum < HTTP_BOOT_OFFER_MAX_NUM);
454 Cache4 = &Private->OfferBuffer[Private->OfferNum].Dhcp4;
455 Offer = &Cache4->Packet.Offer;
461 if (EFI_ERROR (Status)) {
475 OfferType = Cache4->OfferType;
476 ASSERT (OfferType < HttpOfferTypeMax);
477 ASSERT (Private->OfferCount[OfferType] < HTTP_BOOT_OFFER_MAX_NUM);
478 Private->OfferIndex[OfferType][Private->OfferCount[OfferType]] = Private->OfferNum;
479 Private->OfferCount[OfferType]++;
496 Private->SelectIndex = 0;
497 Private->SelectProxyType = HttpOfferTypeMax;
499 if (Private->FilePathUri !=
NULL) {
505 if (Private->OfferCount[HttpOfferTypeDhcpDns] > 0) {
506 Private->SelectIndex = Private->OfferIndex[HttpOfferTypeDhcpDns][0] + 1;
507 }
else if (Private->OfferCount[HttpOfferTypeDhcpIpUriDns] > 0) {
508 Private->SelectIndex = Private->OfferIndex[HttpOfferTypeDhcpIpUriDns][0] + 1;
509 }
else if (Private->OfferCount[HttpOfferTypeDhcpNameUriDns] > 0) {
510 Private->SelectIndex = Private->OfferIndex[HttpOfferTypeDhcpNameUriDns][0] + 1;
511 }
else if (Private->OfferCount[HttpOfferTypeDhcpOnly] > 0) {
512 Private->SelectIndex = Private->OfferIndex[HttpOfferTypeDhcpOnly][0] + 1;
513 }
else if (Private->OfferCount[HttpOfferTypeDhcpIpUri] > 0) {
514 Private->SelectIndex = Private->OfferIndex[HttpOfferTypeDhcpIpUri][0] + 1;
527 if (Private->OfferCount[HttpOfferTypeDhcpIpUri] > 0) {
528 Private->SelectIndex = Private->OfferIndex[HttpOfferTypeDhcpIpUri][0] + 1;
529 }
else if (Private->OfferCount[HttpOfferTypeDhcpIpUriDns] > 0) {
530 Private->SelectIndex = Private->OfferIndex[HttpOfferTypeDhcpIpUriDns][0] + 1;
531 }
else if (Private->OfferCount[HttpOfferTypeDhcpNameUriDns] > 0) {
532 Private->SelectIndex = Private->OfferIndex[HttpOfferTypeDhcpNameUriDns][0] + 1;
533 }
else if ((Private->OfferCount[HttpOfferTypeDhcpOnly] > 0) &&
534 (Private->OfferCount[HttpOfferTypeProxyIpUri] > 0))
536 Private->SelectIndex = Private->OfferIndex[HttpOfferTypeDhcpOnly][0] + 1;
537 Private->SelectProxyType = HttpOfferTypeProxyIpUri;
538 }
else if ((Private->OfferCount[HttpOfferTypeDhcpDns] > 0) &&
539 (Private->OfferCount[HttpOfferTypeProxyIpUri] > 0))
541 Private->SelectIndex = Private->OfferIndex[HttpOfferTypeDhcpDns][0] + 1;
542 Private->SelectProxyType = HttpOfferTypeProxyIpUri;
543 }
else if ((Private->OfferCount[HttpOfferTypeDhcpDns] > 0) &&
544 (Private->OfferCount[HttpOfferTypeProxyNameUri] > 0))
546 Private->SelectIndex = Private->OfferIndex[HttpOfferTypeDhcpDns][0] + 1;
547 Private->SelectProxyType = HttpOfferTypeProxyNameUri;
548 }
else if ((Private->OfferCount[HttpOfferTypeDhcpDns] > 0) &&
549 (Private->OfferCount[HttpOfferTypeDhcpNameUri] > 0))
551 Private->SelectIndex = Private->OfferIndex[HttpOfferTypeDhcpDns][0] + 1;
552 Private->SelectProxyType = HttpOfferTypeDhcpNameUri;
609 Packet->Dhcp4.Option,
610 GET_OPTION_BUFFER_LEN (Packet),
613 if (MaxMsgSize !=
NULL) {
614 Value = HTONS (HTTP_BOOT_DHCP4_PACKET_MAX_SIZE);
615 CopyMem (MaxMsgSize->
Data, &Value, sizeof (Value));
623 Status = Private->HttpBootCallback->Callback (
624 Private->HttpBootCallback,
630 if (EFI_ERROR (Status)) {
636 switch (Dhcp4Event) {
638 Status = EFI_NOT_READY;
639 if (Packet->Length > HTTP_BOOT_DHCP4_PACKET_MAX_SIZE) {
646 if (Private->OfferNum < HTTP_BOOT_OFFER_MAX_NUM) {
664 if (Private->SelectIndex == 0) {
665 Status = EFI_ABORTED;
667 *NewPacket = &Private->OfferBuffer[Private->SelectIndex - 1].Dhcp4.Packet.Offer;
696 ASSERT (!Private->UsingIpv6);
698 Ip4Config2 = Private->Ip4Config2;
703 if (!EFI_IP4_EQUAL (&Private->GatewayIp, &mZeroIp4Addr)) {
704 Status = Ip4Config2->SetData (
710 if (EFI_ERROR (Status)) {
734 IN VOID *DnsServerData
739 ASSERT (!Private->UsingIpv6);
741 Ip4Config2 = Private->Ip4Config2;
743 return Ip4Config2->SetData (
770 Ip4Config2 = Private->Ip4Config2;
773 Status = Ip4Config2->GetData (
779 if (EFI_ERROR (Status)) {
785 Status = Ip4Config2->SetData (
791 if (EFI_ERROR (Status)) {
816 UINT8 Buffer[HTTP_BOOT_DHCP4_OPTION_MAX_SIZE];
821 Dhcp4 = Private->Dhcp4;
822 ASSERT (Dhcp4 !=
NULL);
825 if (EFI_ERROR (Status)) {
833 ASSERT (OptCount > 0);
835 ZeroMem (&Config,
sizeof (Config));
846 Status = Dhcp4->Configure (Dhcp4, &Config);
847 if (EFI_ERROR (Status)) {
854 Private->OfferNum = 0;
855 ZeroMem (Private->OfferCount, sizeof (Private->OfferCount));
856 ZeroMem (Private->OfferIndex, sizeof (Private->OfferIndex));
861 Status = Dhcp4->Start (Dhcp4,
NULL);
862 if (EFI_ERROR (Status)) {
869 Status = Dhcp4->GetModeData (Dhcp4, &Mode);
870 if (EFI_ERROR (Status)) {
880 if (EFI_ERROR (Status)) {
889 if (EFI_ERROR (Status)) {
891 Dhcp4->Configure (Dhcp4,
NULL);
894 Dhcp4->Configure (Dhcp4, &Config);
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS HttpBootParseDhcp4Packet(IN HTTP_BOOT_DHCP4_PACKET_CACHE *Cache4)
EFI_STATUS HttpBootSetIp4Policy(IN HTTP_BOOT_PRIVATE_DATA *Private)
EFI_STATUS HttpBootRegisterIp4Gateway(IN HTTP_BOOT_PRIVATE_DATA *Private)
EFI_DHCP4_PACKET_OPTION * HttpBootParseDhcp4Options(IN UINT8 *Buffer, IN UINT32 Length, IN UINT8 OptTag)
VOID HttpBootSelectDhcpOffer(IN HTTP_BOOT_PRIVATE_DATA *Private)
EFI_STATUS HttpBootDhcp4Dora(IN HTTP_BOOT_PRIVATE_DATA *Private)
EFI_STATUS HttpBootRegisterIp4Dns(IN HTTP_BOOT_PRIVATE_DATA *Private, IN UINTN DataLength, IN VOID *DnsServerData)
EFI_STATUS EFIAPI HttpBootDhcp4CallBack(IN EFI_DHCP4_PROTOCOL *This, IN VOID *Context, IN EFI_DHCP4_STATE CurrentState, IN EFI_DHCP4_EVENT Dhcp4Event, IN EFI_DHCP4_PACKET *Packet OPTIONAL, OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL)
EFI_STATUS HttpBootCacheDhcp4Packet(IN EFI_DHCP4_PACKET *Dst, IN EFI_DHCP4_PACKET *Src)
EFI_STATUS HttpBootCacheDhcp4Offer(IN HTTP_BOOT_PRIVATE_DATA *Private, IN EFI_DHCP4_PACKET *RcvdOffer)
UINT32 HttpBootBuildDhcp4Options(IN HTTP_BOOT_PRIVATE_DATA *Private, OUT EFI_DHCP4_PACKET_OPTION **OptList, IN UINT8 *Buffer)
VOID HttpBootUintnToAscDecWithFormat(IN UINTN Number, IN UINT8 *Buffer, IN INTN Length)
VOID HttpBootShowIp4Addr(IN EFI_IPv4_ADDRESS *Ip)
EFI_STATUS EFIAPI HttpUrlGetIp4(IN CHAR8 *Url, IN VOID *UrlParser, OUT EFI_IPv4_ADDRESS *Ip4Address)
EFI_STATUS EFIAPI HttpParseUrl(IN CHAR8 *Url, IN UINT32 Length, IN BOOLEAN IsConnectMethod, OUT VOID **UrlParser)
@ Ip4Config2DataTypeGateway
@ Ip4Config2DataTypePolicy
@ Ip4Config2DataTypeDnsServer
#define OFFSET_OF(TYPE, Field)
EFI_STATUS EFIAPI NetLibGetSystemGuid(OUT EFI_GUID *SystemGuid)
UINTN EFIAPI AsciiPrint(IN CONST CHAR8 *Format,...)
EFI_DHCP4_PACKET_OPTION ** OptionList
EFI_DHCP4_CALLBACK Dhcp4Callback
EFI_IPv4_ADDRESS YourAddr
Client IP address from server.
EFI_IPv4_ADDRESS SubnetMask
EFI_IPv4_ADDRESS RouterAddress
EFI_IPv4_ADDRESS ClientAddress