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