17 { DHCP4_TAG_NETMASK, DHCP_OPTION_IP, 1, 1,
TRUE },
18 { DHCP4_TAG_TIME_OFFSET, DHCP_OPTION_INT32, 1, 1,
FALSE },
19 { DHCP4_TAG_ROUTER, DHCP_OPTION_IP, 1, -1,
TRUE },
20 { DHCP4_TAG_TIME_SERVER, DHCP_OPTION_IP, 1, -1,
FALSE },
21 { DHCP4_TAG_NAME_SERVER, DHCP_OPTION_IP, 1, -1,
FALSE },
22 { DHCP4_TAG_DNS_SERVER, DHCP_OPTION_IP, 1, -1,
FALSE },
23 { DHCP4_TAG_LOG_SERVER, DHCP_OPTION_IP, 1, -1,
FALSE },
24 { DHCP4_TAG_COOKIE_SERVER, DHCP_OPTION_IP, 1, -1,
FALSE },
25 { DHCP4_TAG_LPR_SERVER, DHCP_OPTION_IP, 1, -1,
FALSE },
26 { DHCP4_TAG_IMPRESS_SERVER, DHCP_OPTION_IP, 1, -1,
FALSE },
27 { DHCP4_TAG_RL_SERVER, DHCP_OPTION_IP, 1, -1,
FALSE },
28 { DHCP4_TAG_HOSTNAME, DHCP_OPTION_INT8, 1, -1,
FALSE },
29 { DHCP4_TAG_BOOTFILE_LEN, DHCP_OPTION_INT16, 1, 1,
FALSE },
30 { DHCP4_TAG_DUMP, DHCP_OPTION_INT8, 1, -1,
FALSE },
31 { DHCP4_TAG_DOMAINNAME, DHCP_OPTION_INT8, 1, -1,
FALSE },
32 { DHCP4_TAG_SWAP_SERVER, DHCP_OPTION_IP, 1, 1,
FALSE },
33 { DHCP4_TAG_ROOTPATH, DHCP_OPTION_INT8, 1, -1,
FALSE },
34 { DHCP4_TAG_EXTEND_PATH, DHCP_OPTION_INT8, 1, -1,
FALSE },
36 { DHCP4_TAG_IPFORWARD, DHCP_OPTION_SWITCH, 1, 1,
FALSE },
37 { DHCP4_TAG_NONLOCAL_SRR, DHCP_OPTION_SWITCH, 1, 1,
FALSE },
38 { DHCP4_TAG_POLICY_SRR, DHCP_OPTION_IPPAIR, 1, -1,
FALSE },
39 { DHCP4_TAG_EMTU, DHCP_OPTION_INT16, 1, 1,
FALSE },
40 { DHCP4_TAG_TTL, DHCP_OPTION_INT8, 1, 1,
FALSE },
41 { DHCP4_TAG_PATHMTU_AGE, DHCP_OPTION_INT32, 1, 1,
FALSE },
42 { DHCP4_TAG_PATHMTU_PLATEAU, DHCP_OPTION_INT16, 1, -1,
FALSE },
44 { DHCP4_TAG_IFMTU, DHCP_OPTION_INT16, 1, 1,
FALSE },
45 { DHCP4_TAG_SUBNET_LOCAL, DHCP_OPTION_SWITCH, 1, 1,
FALSE },
46 { DHCP4_TAG_BROADCAST, DHCP_OPTION_IP, 1, 1,
FALSE },
47 { DHCP4_TAG_DISCOVER_MASK, DHCP_OPTION_SWITCH, 1, 1,
FALSE },
48 { DHCP4_TAG_SUPPLY_MASK, DHCP_OPTION_SWITCH, 1, 1,
FALSE },
49 { DHCP4_TAG_DISCOVER_ROUTE, DHCP_OPTION_SWITCH, 1, 1,
FALSE },
50 { DHCP4_TAG_ROUTER_SOLICIT, DHCP_OPTION_IP, 1, 1,
FALSE },
51 { DHCP4_TAG_STATIC_ROUTE, DHCP_OPTION_IPPAIR, 1, -1,
FALSE },
53 { DHCP4_TAG_TRAILER, DHCP_OPTION_SWITCH, 1, 1,
FALSE },
54 { DHCP4_TAG_ARPAGE, DHCP_OPTION_INT32, 1, 1,
FALSE },
55 { DHCP4_TAG_ETHER_ENCAP, DHCP_OPTION_SWITCH, 1, 1,
FALSE },
57 { DHCP4_TAG_TCP_TTL, DHCP_OPTION_INT8, 1, 1,
FALSE },
58 { DHCP4_TAG_KEEP_INTERVAL, DHCP_OPTION_INT32, 1, 1,
FALSE },
59 { DHCP4_TAG_KEEP_GARBAGE, DHCP_OPTION_SWITCH, 1, 1,
FALSE },
61 { DHCP4_TAG_NIS_DOMAIN, DHCP_OPTION_INT8, 1, -1,
FALSE },
62 { DHCP4_TAG_NIS_SERVER, DHCP_OPTION_IP, 1, -1,
FALSE },
63 { DHCP4_TAG_NTP_SERVER, DHCP_OPTION_IP, 1, -1,
FALSE },
64 { DHCP4_TAG_VENDOR, DHCP_OPTION_INT8, 1, -1,
FALSE },
65 { DHCP4_TAG_NBNS, DHCP_OPTION_IP, 1, -1,
FALSE },
66 { DHCP4_TAG_NBDD, DHCP_OPTION_IP, 1, -1,
FALSE },
67 { DHCP4_TAG_NBTYPE, DHCP_OPTION_INT8, 1, 1,
FALSE },
68 { DHCP4_TAG_NBSCOPE, DHCP_OPTION_INT8, 1, -1,
FALSE },
69 { DHCP4_TAG_XFONT, DHCP_OPTION_IP, 1, -1,
FALSE },
70 { DHCP4_TAG_XDM, DHCP_OPTION_IP, 1, -1,
FALSE },
72 { DHCP4_TAG_REQUEST_IP, DHCP_OPTION_IP, 1, 1,
FALSE },
73 { DHCP4_TAG_LEASE, DHCP_OPTION_INT32, 1, 1,
TRUE },
74 { DHCP4_TAG_OVERLOAD, DHCP_OPTION_INT8, 1, 1,
TRUE },
75 { DHCP4_TAG_MSG_TYPE, DHCP_OPTION_INT8, 1, 1,
TRUE },
76 { DHCP4_TAG_SERVER_ID, DHCP_OPTION_IP, 1, 1,
TRUE },
77 { DHCP4_TAG_PARA_LIST, DHCP_OPTION_INT8, 1, -1,
FALSE },
78 { DHCP4_TAG_MESSAGE, DHCP_OPTION_INT8, 1, -1,
FALSE },
79 { DHCP4_TAG_MAXMSG, DHCP_OPTION_INT16, 1, 1,
FALSE },
80 { DHCP4_TAG_T1, DHCP_OPTION_INT32, 1, 1,
TRUE },
81 { DHCP4_TAG_T2, DHCP_OPTION_INT32, 1, 1,
TRUE },
82 { DHCP4_TAG_VENDOR_CLASS_ID, DHCP_OPTION_INT8, 1, -1,
FALSE },
83 { DHCP4_TAG_CLIENT_ID, DHCP_OPTION_INT8, 2, -1,
FALSE },
85 { DHCP4_TAG_NISPLUS, DHCP_OPTION_INT8, 1, -1,
FALSE },
86 { DHCP4_TAG_NISPLUS_SERVER, DHCP_OPTION_IP, 1, -1,
FALSE },
88 { DHCP4_TAG_TFTP, DHCP_OPTION_INT8, 1, -1,
FALSE },
89 { DHCP4_TAG_BOOTFILE, DHCP_OPTION_INT8, 1, -1,
FALSE },
91 { DHCP4_TAG_MOBILEIP, DHCP_OPTION_IP, 0, -1,
FALSE },
92 { DHCP4_TAG_SMTP, DHCP_OPTION_IP, 1, -1,
FALSE },
93 { DHCP4_TAG_POP3, DHCP_OPTION_IP, 1, -1,
FALSE },
94 { DHCP4_TAG_NNTP, DHCP_OPTION_IP, 1, -1,
FALSE },
95 { DHCP4_TAG_WWW, DHCP_OPTION_IP, 1, -1,
FALSE },
96 { DHCP4_TAG_FINGER, DHCP_OPTION_IP, 1, -1,
FALSE },
97 { DHCP4_TAG_IRC, DHCP_OPTION_IP, 1, -1,
FALSE },
98 { DHCP4_TAG_STTALK, DHCP_OPTION_IP, 1, -1,
FALSE },
99 { DHCP4_TAG_STDA, DHCP_OPTION_IP, 1, -1,
FALSE },
101 { DHCP4_TAG_CLASSLESS_ROUTE, DHCP_OPTION_INT8, 5, -1,
FALSE },
125 while (Right >= Left) {
126 Middle = (Left + Right) / 2;
166 switch (Format->Type) {
167 case DHCP_OPTION_SWITCH:
168 case DHCP_OPTION_INT8:
172 case DHCP_OPTION_INT16:
176 case DHCP_OPTION_INT32:
181 case DHCP_OPTION_IPPAIR:
191 if ((Len % Unit) != 0) {
200 if (((Format->MinOccur != -1) && (Occur < Format->MinOccur)) ||
201 ((Format->MaxOccur != -1) && (Occur > Format->MaxOccur))
210 if (Format->Type == DHCP_OPTION_SWITCH) {
211 for (Index = 0; Index < Occur; Index++) {
212 if ((OptValue[Index] != 0) && (OptValue[Index] != 1)) {
243 case DHCP4_TAG_NETMASK:
247 case DHCP4_TAG_ROUTER:
254 case DHCP4_TAG_LEASE:
258 case DHCP4_TAG_OVERLOAD:
259 Para->Overload = *Data;
261 if ((Para->Overload < 1) || (Para->Overload > 3)) {
262 return EFI_INVALID_PARAMETER;
267 case DHCP4_TAG_MSG_TYPE:
268 Para->DhcpType = *Data;
270 if ((Para->DhcpType < 1) || (Para->DhcpType > 9)) {
271 return EFI_INVALID_PARAMETER;
276 case DHCP4_TAG_SERVER_ID:
312 IN DHCP_CHECK_OPTION Check OPTIONAL,
314 OUT UINT8 *Overload OPTIONAL
323 while (Cur < BufLen) {
329 }
else if (Tag == DHCP4_TAG_EOP) {
336 return EFI_INVALID_PARAMETER;
341 if (Cur + Len > BufLen) {
342 return EFI_INVALID_PARAMETER;
345 if ((Tag == DHCP4_TAG_OVERLOAD) && (Overload !=
NULL)) {
347 return EFI_INVALID_PARAMETER;
350 *Overload = Buffer[Cur];
353 if ((Check !=
NULL) && EFI_ERROR (Check (Tag, Len, Buffer + Cur, Context))) {
354 return EFI_INVALID_PARAMETER;
363 return EFI_INVALID_PARAMETER;
384 IN DHCP_CHECK_OPTION Check OPTIONAL,
394 Packet->Dhcp4.Option,
401 if (EFI_ERROR (Status)) {
405 if ((Overload == DHCP_OVERLOAD_FILENAME) || (Overload == DHCP_OVERLOAD_BOTH)) {
407 (UINT8 *)Packet->Dhcp4.Header.BootFileName,
414 if (EFI_ERROR (Status)) {
419 if ((Overload == DHCP_OVERLOAD_SVRNAME) || (Overload == DHCP_OVERLOAD_BOTH)) {
421 (UINT8 *)Packet->Dhcp4.Header.ServerName,
428 if (EFI_ERROR (Status)) {
461 OpCount[Tag].Offset = (UINT16)(OpCount[Tag].Offset + Len);
495 OptCount = OptContext->OpCount;
496 Index = OptCount[Tag].Index;
497 Options = OptContext->Options;
498 Buf = OptContext->Buf;
500 if (Options[Index].Data ==
NULL) {
501 Options[Index].Tag = Tag;
502 Options[Index].Data = Buf + OptCount[Tag].Offset;
505 CopyMem (Buf + OptCount[Tag].Offset, Data, Len);
507 OptCount[Tag].Offset = (UINT16)(OptCount[Tag].Offset + Len);
508 Options[Index].Len = (UINT16)(Options[Index].Len + Len);
555 ASSERT ((Count !=
NULL) && (OptionPoint !=
NULL));
563 if (OptCount ==
NULL) {
564 return EFI_OUT_OF_RESOURCES;
569 if (EFI_ERROR (Status)) {
581 for (Index = 0; Index < DHCP_MAX_OPTIONS; Index++) {
582 if (OptCount[Index].Offset != 0) {
583 OptCount[Index].Index = (UINT8)OptNum;
585 TotalLen = (UINT16)(TotalLen + OptCount[Index].Offset);
586 OptCount[Index].Offset = (UINT16)(TotalLen - OptCount[Index].Offset);
605 if (Options ==
NULL) {
606 Status = EFI_OUT_OF_RESOURCES;
610 Context.OpCount = OptCount;
611 Context.Options = Options;
612 Context.Buf = (UINT8 *)(Options + OptNum);
616 if (EFI_ERROR (Status)) {
621 *OptionPoint = Options;
662 if (EFI_ERROR (Status) || (Count == 0)) {
666 ASSERT (AllOption !=
NULL);
669 ZeroMem (&Parameter,
sizeof (Parameter));
671 for (Index = 0; Index < Count; Index++) {
672 Option = &AllOption[Index];
679 if (Format ==
NULL) {
684 Status = EFI_INVALID_PARAMETER;
691 if (Format->Alert && (Para !=
NULL)) {
693 Status =
DhcpGetParameter (Option->Tag, Option->Len, Option->Data, &Parameter);
695 if (EFI_ERROR (Status)) {
701 if (Updated && (Para !=
NULL)) {
704 Status = EFI_OUT_OF_RESOURCES;
737 ASSERT (DataLen != 0);
739 for (Index = 0; Index < (DataLen + 254) / 255; Index++) {
740 Len =
MIN (255, DataLen - Index * 255);
743 *(Buf++) = (UINT8)Len;
772 IN UINT32 DeleteCount,
773 IN UINT8 *DeleteList OPTIONAL,
774 IN UINT32 AppendCount,
795 return EFI_OUT_OF_RESOURCES;
798 for (Index = 0; Index < DHCP_MAX_OPTIONS; Index++) {
799 Mark[Index].Tag = (UINT8)Index;
810 if (EFI_ERROR (Status)) {
814 if (SeedOptions !=
NULL) {
815 for (Index = 0; Index < (UINT32)Count; Index++) {
816 Mark[SeedOptions[Index].Tag] = SeedOptions[Index];
823 for (Index = 0; Index < DeleteCount; Index++) {
824 Mark[DeleteList[Index]].Len = 0;
830 for (Index = 0; Index < AppendCount; Index++) {
831 Mark[AppendList[Index]->OpCode].Len = AppendList[Index]->Length;
832 Mark[AppendList[Index]->OpCode].Data = AppendList[Index]->Data;
843 for (Index = 0; Index < DHCP_MAX_OPTIONS; Index++) {
844 if (Mark[Index].Len != 0) {
845 Len += ((Mark[Index].Len + 254) / 255) * 2 + Mark[Index].Len;
849 Status = EFI_OUT_OF_RESOURCES;
852 if (Packet ==
NULL) {
860 Buf = Packet->Dhcp4.
Option;
862 for (Index = 0; Index < DHCP_MAX_OPTIONS; Index++) {
863 if (Mark[Index].Len != 0) {
864 Buf =
DhcpAppendOption (Buf, Mark[Index].Tag, Mark[Index].Len, Mark[Index].Data);
868 *(Buf++) = DHCP4_TAG_EOP;
870 + (UINT32)(Buf - Packet->Dhcp4.
Option);
876 if (SeedOptions !=
NULL) {
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS DhcpParseOption(IN EFI_DHCP4_PACKET *Packet, OUT INTN *Count, OUT DHCP_OPTION **OptionPoint)
EFI_STATUS DhcpFillOption(IN UINT8 Tag, IN UINT8 Len, IN UINT8 *Data, IN VOID *Context)
EFI_STATUS DhcpGetParameter(IN UINT8 Tag, IN INTN Len, IN UINT8 *Data, OUT DHCP_PARAMETER *Para)
EFI_STATUS DhcpIterateBufferOptions(IN UINT8 *Buffer, IN INTN BufLen, IN DHCP_CHECK_OPTION Check OPTIONAL, IN VOID *Context, OUT UINT8 *Overload OPTIONAL)
EFI_STATUS DhcpBuild(IN EFI_DHCP4_PACKET *SeedPacket, IN UINT32 DeleteCount, IN UINT8 *DeleteList OPTIONAL, IN UINT32 AppendCount, IN EFI_DHCP4_PACKET_OPTION *AppendList[] OPTIONAL, OUT EFI_DHCP4_PACKET **NewPacket)
DHCP_OPTION_FORMAT * DhcpFindOptionFormat(IN UINT8 Tag)
BOOLEAN DhcpOptionIsValid(IN DHCP_OPTION_FORMAT *Format, IN UINT8 *OptValue, IN INTN Len)
EFI_STATUS DhcpGetOptionLen(IN UINT8 Tag, IN UINT8 Len, IN UINT8 *Data, IN VOID *Context)
EFI_STATUS DhcpIterateOptions(IN EFI_DHCP4_PACKET *Packet, IN DHCP_CHECK_OPTION Check OPTIONAL, IN VOID *Context)
DHCP_OPTION_FORMAT DhcpOptionFormats[]
EFI_STATUS DhcpValidateOptions(IN EFI_DHCP4_PACKET *Packet, OUT DHCP_PARAMETER **Para OPTIONAL)
UINT8 * DhcpAppendOption(OUT UINT8 *Buf, IN UINT8 Tag, IN UINT16 DataLen, IN UINT8 *Data)
#define DHCP_OPTION_MAGIC
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
UINT32 EFIAPI NetGetUint32(IN UINT8 *Buf)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)