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