]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/HttpBootDxe/HttpBootDhcp4.h
NetworkPkg: Refine codes related to Dhcpv4 and Dhcpv6 configuration.
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootDhcp4.h
1 /** @file
2 Functions declaration related with DHCPv4 for HTTP boot driver.
3
4 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef __EFI_UEFI_HTTP_BOOT_DHCP4_H__
16 #define __EFI_UEFI_HTTP_BOOT_DHCP4_H__
17
18 #define HTTP_BOOT_DHCP4_OPTION_MAX_NUM 16
19 #define HTTP_BOOT_DHCP4_OPTION_MAX_SIZE 312
20 #define HTTP_BOOT_DHCP4_PACKET_MAX_SIZE 1472
21
22 #define HTTP_BOOT_DHCP4_OPCODE_REQUEST 1
23 #define HTTP_BOOT_DHCP4_OPCODE_REPLY 2
24 #define HTTP_BOOT_DHCP4_MSG_TYPE_REQUEST 3
25 #define HTTP_BOOT_DHCP4_MAGIC 0x63538263 // network byte order
26
27 #define HTTP_BOOT_DHCP4_OVERLOAD_FILE 1
28 #define HTTP_BOOT_DHCP4_OVERLOAD_SERVER_NAME 2
29
30 ///
31 /// HTTP Tag definition that identifies the processor
32 /// and programming environment of the client system.
33 /// These identifiers are defined by IETF:
34 /// http://www.ietf.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml
35 ///
36 #if defined (MDE_CPU_IA32)
37 #define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE HTTP_CLIENT_ARCH_IA32
38 #elif defined (MDE_CPU_X64)
39 #define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE HTTP_CLIENT_ARCH_X64
40 #elif defined (MDE_CPU_ARM)
41 #define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE HTTP_CLIENT_ARCH_ARM
42 #elif defined (MDE_CPU_AARCH64)
43 #define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE HTTP_CLIENT_ARCH_AARCH64
44 #elif defined (MDE_CPU_EBC)
45 #define EFI_HTTP_BOOT_CLIENT_SYSTEM_ARCHITECTURE HTTP_CLIENT_ARCH_EBC
46 #endif
47
48 /// DHCP offer types among HTTP boot.
49 /// Dhcp4 and Dhcp6 share this definition, and corresponding
50 /// relatioinship is as follows:
51 /// Dhcp4Discover <> Dhcp6Solicit
52 /// Dhcp4Offer <> Dhcp6Advertise
53 /// Dhcp4Request <> Dhcp6Request
54 /// Dhcp4Ack <> DHcp6Reply
55 ///
56 typedef enum {
57 //
58 // <IP address, IP expressed URI>
59 //
60 HttpOfferTypeDhcpIpUri,
61 //
62 // <IP address, IP expressed URI, Name-server>
63 //
64 HttpOfferTypeDhcpIpUriDns,
65 //
66 // <IP address, Domain-name expressed URI, Name-server>
67 //
68 HttpOfferTypeDhcpNameUriDns,
69 //
70 // <IP address, Name-server>
71 //
72 HttpOfferTypeDhcpDns,
73 //
74 // <IP address>
75 //
76 HttpOfferTypeDhcpOnly,
77 //
78 // <Domain-name expressed URI> or
79 // <Domain-name expressed URI, Name-server (will be ignored)>
80 //
81 HttpOfferTypeProxyNameUri,
82 //
83 // <IP expressed URI> or
84 // <IP expressed URI, Name-server (will be ignored)>
85 //
86 HttpOfferTypeProxyIpUri,
87 //
88 // <IP address, Domain-name expressed URI>
89 //
90 HttpOfferTypeDhcpNameUri,
91 HttpOfferTypeMax
92 } HTTP_BOOT_OFFER_TYPE;
93
94 #define HTTP_BOOT_DHCP_RETRIES 4
95 #define HTTP_BOOT_OFFER_MAX_NUM 16
96
97 // The array index of the DHCP4 option tag interested
98 //
99 #define HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE_LEN 0
100 #define HTTP_BOOT_DHCP4_TAG_INDEX_OVERLOAD 1
101 #define HTTP_BOOT_DHCP4_TAG_INDEX_MSG_TYPE 2
102 #define HTTP_BOOT_DHCP4_TAG_INDEX_SERVER_ID 3
103 #define HTTP_BOOT_DHCP4_TAG_INDEX_CLASS_ID 4
104 #define HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE 5
105 #define HTTP_BOOT_DHCP4_TAG_INDEX_DNS_SERVER 6
106 #define HTTP_BOOT_DHCP4_TAG_INDEX_MAX 7
107
108 #pragma pack(1)
109
110 typedef struct {
111 UINT8 ParaList[135];
112 } HTTP_BOOT_DHCP4_OPTION_PARA;
113
114 typedef struct {
115 UINT16 Size;
116 } HTTP_BOOT_DHCP4_OPTION_MAX_MESG_SIZE;
117
118 typedef struct {
119 UINT8 Type;
120 UINT8 MajorVer;
121 UINT8 MinorVer;
122 } HTTP_BOOT_DHCP4_OPTION_UNDI;
123
124 typedef struct {
125 UINT8 Type;
126 } HTTP_BOOT_DHCP4_OPTION_MESG;
127
128 typedef struct {
129 UINT16 Type;
130 } HTTP_BOOT_DHCP4_OPTION_ARCH;
131
132 typedef struct {
133 UINT8 ClassIdentifier[11];
134 UINT8 ArchitecturePrefix[5];
135 UINT8 ArchitectureType[5];
136 UINT8 Lit3[1];
137 UINT8 InterfaceName[4];
138 UINT8 Lit4[1];
139 UINT8 UndiMajor[3];
140 UINT8 UndiMinor[3];
141 } HTTP_BOOT_DHCP4_OPTION_CLID;
142
143 typedef struct {
144 UINT8 Type;
145 UINT8 Guid[16];
146 } HTTP_BOOT_DHCP4_OPTION_UUID;
147
148 typedef struct {
149 UINT16 Type;
150 UINT16 Layer;
151 } HTTP_BOOT_OPTION_BOOT_ITEM;
152
153 #pragma pack()
154
155 typedef union {
156 HTTP_BOOT_DHCP4_OPTION_PARA *Para;
157 HTTP_BOOT_DHCP4_OPTION_UNDI *Undi;
158 HTTP_BOOT_DHCP4_OPTION_ARCH *Arch;
159 HTTP_BOOT_DHCP4_OPTION_CLID *Clid;
160 HTTP_BOOT_DHCP4_OPTION_UUID *Uuid;
161 HTTP_BOOT_DHCP4_OPTION_MESG *Mesg;
162 HTTP_BOOT_DHCP4_OPTION_MAX_MESG_SIZE *MaxMesgSize;
163 } HTTP_BOOT_DHCP4_OPTION_ENTRY;
164
165 #define GET_NEXT_DHCP_OPTION(Opt) \
166 (EFI_DHCP4_PACKET_OPTION *) ((UINT8 *) (Opt) + \
167 sizeof (EFI_DHCP4_PACKET_OPTION) + (Opt)->Length - 1)
168
169 #define GET_OPTION_BUFFER_LEN(Pkt) \
170 ((Pkt)->Length - sizeof (EFI_DHCP4_HEADER) - 4)
171
172 #define DEFAULT_CLASS_ID_DATA "HTTPClient:Arch:xxxxx:UNDI:003000"
173 #define DEFAULT_UNDI_TYPE 1
174 #define DEFAULT_UNDI_MAJOR 3
175 #define DEFAULT_UNDI_MINOR 0
176
177 typedef struct {
178 UINT32 Reserved;
179 } HTTP_BOOT_VENDOR_OPTION;
180
181 typedef union {
182 EFI_DHCP4_PACKET Offer;
183 EFI_DHCP4_PACKET Ack;
184 UINT8 Buffer[HTTP_BOOT_DHCP4_PACKET_MAX_SIZE];
185 } HTTP_BOOT_DHCP4_PACKET;
186
187 typedef struct {
188 //
189 // URI component
190 //
191 CHAR8 *Scheme;
192 CHAR8 *Authority;
193 CHAR8 *Path;
194 CHAR8 *Query;
195 CHAR8 *Fragment; /// TODO: may not required in HTTP URL
196
197 CHAR8 *RegName; /// Point to somewhere in Authority
198 BOOLEAN AddrIsOk;
199 EFI_IP_ADDRESS Address;
200 UINT16 Port;
201 } HTTP_BOOT_URI_CONTENT;
202
203 typedef struct {
204 HTTP_BOOT_DHCP4_PACKET Packet;
205 HTTP_BOOT_OFFER_TYPE OfferType;
206 VOID *UriParser;
207 EFI_DHCP4_PACKET_OPTION *OptList[HTTP_BOOT_DHCP4_TAG_INDEX_MAX];
208 } HTTP_BOOT_DHCP4_PACKET_CACHE;
209
210 /**
211 Select an DHCPv4 or DHCP6 offer, and record SelectIndex and SelectProxyType.
212
213 @param[in] Private Pointer to HTTP boot driver private data.
214
215 **/
216 VOID
217 HttpBootSelectDhcpOffer (
218 IN HTTP_BOOT_PRIVATE_DATA *Private
219 );
220
221 /**
222 Start the D.O.R.A DHCPv4 process to acquire the IPv4 address and other Http boot information.
223
224 @param[in] Private Pointer to HTTP_BOOT private data.
225
226 @retval EFI_SUCCESS The D.O.R.A process successfully finished.
227 @retval Others Failed to finish the D.O.R.A process.
228
229 **/
230 EFI_STATUS
231 HttpBootDhcp4Dora (
232 IN HTTP_BOOT_PRIVATE_DATA *Private
233 );
234
235 /**
236 This function will register the default DNS addresses to the network device.
237
238 @param[in] Private The pointer to HTTP_BOOT_PRIVATE_DATA.
239 @param[in] DataLength Size of the buffer pointed to by DnsServerData in bytes.
240 @param[in] DnsServerData Point a list of DNS server address in an array
241 of EFI_IPv4_ADDRESS instances.
242
243 @retval EFI_SUCCESS The DNS configuration has been configured successfully.
244 @retval Others Failed to configure the address.
245
246 **/
247 EFI_STATUS
248 HttpBootRegisterIp4Dns (
249 IN HTTP_BOOT_PRIVATE_DATA *Private,
250 IN UINTN DataLength,
251 IN VOID *DnsServerData
252 );
253
254 #endif