1 | /** @file
|
---|
2 | Functions implementation related with DHCPv6 for UefiPxeBc Driver.
|
---|
3 |
|
---|
4 | Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
|
---|
5 |
|
---|
6 | This program and the accompanying materials
|
---|
7 | are licensed and made available under the terms and conditions of the BSD License
|
---|
8 | which accompanies this distribution. The full text of the license may be found at
|
---|
9 | http://opensource.org/licenses/bsd-license.php.
|
---|
10 |
|
---|
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
13 |
|
---|
14 | **/
|
---|
15 |
|
---|
16 | #include "PxeBcImpl.h"
|
---|
17 |
|
---|
18 | //
|
---|
19 | // Well-known multi-cast address defined in section-24.1 of rfc-3315
|
---|
20 | //
|
---|
21 | // ALL_DHCP_Relay_Agents_and_Servers address: FF02::1:2
|
---|
22 | //
|
---|
23 | EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress = {{0xFF, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2}};
|
---|
24 |
|
---|
25 | /**
|
---|
26 | Parse out a DHCPv6 option by OptTag, and find the position in buffer.
|
---|
27 |
|
---|
28 | @param[in] Buffer The pointer to the option buffer.
|
---|
29 | @param[in] Length Length of the option buffer.
|
---|
30 | @param[in] OptTag The required option tag.
|
---|
31 |
|
---|
32 | @retval NULL Failed to parse the required option.
|
---|
33 | @retval Others The postion of the required option in buffer.
|
---|
34 |
|
---|
35 | **/
|
---|
36 | EFI_DHCP6_PACKET_OPTION *
|
---|
37 | PxeBcParseDhcp6Options (
|
---|
38 | IN UINT8 *Buffer,
|
---|
39 | IN UINT32 Length,
|
---|
40 | IN UINT16 OptTag
|
---|
41 | )
|
---|
42 | {
|
---|
43 | EFI_DHCP6_PACKET_OPTION *Option;
|
---|
44 | UINT32 Offset;
|
---|
45 |
|
---|
46 | Option = (EFI_DHCP6_PACKET_OPTION *) Buffer;
|
---|
47 | Offset = 0;
|
---|
48 |
|
---|
49 | //
|
---|
50 | // OpLen and OpCode here are both stored in network order.
|
---|
51 | //
|
---|
52 | while (Offset < Length) {
|
---|
53 |
|
---|
54 | if (NTOHS (Option->OpCode) == OptTag) {
|
---|
55 |
|
---|
56 | return Option;
|
---|
57 | }
|
---|
58 |
|
---|
59 | Offset += (NTOHS(Option->OpLen) + 4);
|
---|
60 | Option = (EFI_DHCP6_PACKET_OPTION *) (Buffer + Offset);
|
---|
61 | }
|
---|
62 |
|
---|
63 | return NULL;
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | /**
|
---|
68 | Build the options buffer for the DHCPv6 request packet.
|
---|
69 |
|
---|
70 | @param[in] Private The pointer to PxeBc private data.
|
---|
71 | @param[out] OptList The pointer to the option pointer array.
|
---|
72 | @param[in] Buffer The pointer to the buffer to contain the option list.
|
---|
73 |
|
---|
74 | @return Index The count of the built-in options.
|
---|
75 |
|
---|
76 | **/
|
---|
77 | UINT32
|
---|
78 | PxeBcBuildDhcp6Options (
|
---|
79 | IN PXEBC_PRIVATE_DATA *Private,
|
---|
80 | OUT EFI_DHCP6_PACKET_OPTION **OptList,
|
---|
81 | IN UINT8 *Buffer
|
---|
82 | )
|
---|
83 | {
|
---|
84 | PXEBC_DHCP6_OPTION_ENTRY OptEnt;
|
---|
85 | UINT32 Index;
|
---|
86 | UINT16 Value;
|
---|
87 |
|
---|
88 | Index = 0;
|
---|
89 | OptList[0] = (EFI_DHCP6_PACKET_OPTION *) Buffer;
|
---|
90 |
|
---|
91 | //
|
---|
92 | // Append client option request option
|
---|
93 | //
|
---|
94 | OptList[Index]->OpCode = HTONS (PXEBC_DHCP6_OPT_ORO);
|
---|
95 | OptList[Index]->OpLen = HTONS (4);
|
---|
96 | OptEnt.Oro = (PXEBC_DHCP6_OPTION_ORO *) OptList[Index]->Data;
|
---|
97 | OptEnt.Oro->OpCode[0] = HTONS(PXEBC_DHCP6_OPT_BOOT_FILE_URL);
|
---|
98 | OptEnt.Oro->OpCode[1] = HTONS(PXEBC_DHCP6_OPT_BOOT_FILE_PARAM);
|
---|
99 | Index++;
|
---|
100 | OptList[Index] = GET_NEXT_DHCP6_OPTION (OptList[Index - 1]);
|
---|
101 |
|
---|
102 | //
|
---|
103 | // Append client network device interface option
|
---|
104 | //
|
---|
105 | OptList[Index]->OpCode = HTONS (PXEBC_DHCP6_OPT_UNDI);
|
---|
106 | OptList[Index]->OpLen = HTONS ((UINT16)3);
|
---|
107 | OptEnt.Undi = (PXEBC_DHCP6_OPTION_UNDI *) OptList[Index]->Data;
|
---|
108 |
|
---|
109 | if (Private->Nii != NULL) {
|
---|
110 | OptEnt.Undi->Type = Private->Nii->Type;
|
---|
111 | OptEnt.Undi->MajorVer = Private->Nii->MajorVer;
|
---|
112 | OptEnt.Undi->MinorVer = Private->Nii->MinorVer;
|
---|
113 | } else {
|
---|
114 | OptEnt.Undi->Type = DEFAULT_UNDI_TYPE;
|
---|
115 | OptEnt.Undi->MajorVer = DEFAULT_UNDI_MAJOR;
|
---|
116 | OptEnt.Undi->MinorVer = DEFAULT_UNDI_MINOR;
|
---|
117 | }
|
---|
118 |
|
---|
119 | Index++;
|
---|
120 | OptList[Index] = GET_NEXT_DHCP6_OPTION (OptList[Index - 1]);
|
---|
121 |
|
---|
122 | //
|
---|
123 | // Append client system architecture option
|
---|
124 | //
|
---|
125 | OptList[Index]->OpCode = HTONS (PXEBC_DHCP6_OPT_ARCH);
|
---|
126 | OptList[Index]->OpLen = HTONS ((UINT16) sizeof (PXEBC_DHCP6_OPTION_ARCH));
|
---|
127 | OptEnt.Arch = (PXEBC_DHCP6_OPTION_ARCH *) OptList[Index]->Data;
|
---|
128 | Value = HTONS (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE);
|
---|
129 | CopyMem (&OptEnt.Arch->Type, &Value, sizeof (UINT16));
|
---|
130 | Index++;
|
---|
131 | OptList[Index] = GET_NEXT_DHCP6_OPTION (OptList[Index - 1]);
|
---|
132 |
|
---|
133 | //
|
---|
134 | // Append vendor class option to store the PXE class identifier.
|
---|
135 | //
|
---|
136 | OptList[Index]->OpCode = HTONS (PXEBC_DHCP6_OPT_VENDOR_CLASS);
|
---|
137 | OptList[Index]->OpLen = HTONS ((UINT16) sizeof (PXEBC_DHCP6_OPTION_VENDOR_CLASS));
|
---|
138 | OptEnt.VendorClass = (PXEBC_DHCP6_OPTION_VENDOR_CLASS *) OptList[Index]->Data;
|
---|
139 | OptEnt.VendorClass->Vendor = HTONL (PXEBC_DHCP6_ENTERPRISE_NUM);
|
---|
140 | OptEnt.VendorClass->ClassLen = HTONS ((UINT16) sizeof (PXEBC_CLASS_ID));
|
---|
141 | CopyMem (
|
---|
142 | &OptEnt.VendorClass->ClassId,
|
---|
143 | DEFAULT_CLASS_ID_DATA,
|
---|
144 | sizeof (PXEBC_CLASS_ID)
|
---|
145 | );
|
---|
146 | PxeBcUintnToAscDecWithFormat (
|
---|
147 | EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE,
|
---|
148 | OptEnt.VendorClass->ClassId.ArchitectureType,
|
---|
149 | sizeof (OptEnt.VendorClass->ClassId.ArchitectureType)
|
---|
150 | );
|
---|
151 |
|
---|
152 | if (Private->Nii != NULL) {
|
---|
153 | CopyMem (
|
---|
154 | OptEnt.VendorClass->ClassId.InterfaceName,
|
---|
155 | Private->Nii->StringId,
|
---|
156 | sizeof (OptEnt.VendorClass->ClassId.InterfaceName)
|
---|
157 | );
|
---|
158 | PxeBcUintnToAscDecWithFormat (
|
---|
159 | Private->Nii->MajorVer,
|
---|
160 | OptEnt.VendorClass->ClassId.UndiMajor,
|
---|
161 | sizeof (OptEnt.VendorClass->ClassId.UndiMajor)
|
---|
162 | );
|
---|
163 | PxeBcUintnToAscDecWithFormat (
|
---|
164 | Private->Nii->MinorVer,
|
---|
165 | OptEnt.VendorClass->ClassId.UndiMinor,
|
---|
166 | sizeof (OptEnt.VendorClass->ClassId.UndiMinor)
|
---|
167 | );
|
---|
168 | }
|
---|
169 |
|
---|
170 | Index++;
|
---|
171 |
|
---|
172 | return Index;
|
---|
173 | }
|
---|
174 |
|
---|
175 |
|
---|
176 | /**
|
---|
177 | Cache the DHCPv6 packet.
|
---|
178 |
|
---|
179 | @param[in] Dst The pointer to the cache buffer for DHCPv6 packet.
|
---|
180 | @param[in] Src The pointer to the DHCPv6 packet to be cached.
|
---|
181 |
|
---|
182 | **/
|
---|
183 | VOID
|
---|
184 | PxeBcCacheDhcp6Packet (
|
---|
185 | IN EFI_DHCP6_PACKET *Dst,
|
---|
186 | IN EFI_DHCP6_PACKET *Src
|
---|
187 | )
|
---|
188 | {
|
---|
189 | ASSERT (Dst->Size >= Src->Length);
|
---|
190 |
|
---|
191 | CopyMem (&Dst->Dhcp6, &Src->Dhcp6, Src->Length);
|
---|
192 | Dst->Length = Src->Length;
|
---|
193 | }
|
---|
194 |
|
---|
195 |
|
---|
196 | /**
|
---|
197 | Free all the nodes in the list for boot file.
|
---|
198 |
|
---|
199 | @param[in] Head The pointer to the head of list.
|
---|
200 |
|
---|
201 | **/
|
---|
202 | VOID
|
---|
203 | PxeBcFreeBootFileOption (
|
---|
204 | IN LIST_ENTRY *Head
|
---|
205 | )
|
---|
206 | {
|
---|
207 | LIST_ENTRY *Entry;
|
---|
208 | LIST_ENTRY *NextEntry;
|
---|
209 | PXEBC_DHCP6_OPTION_NODE *Node;
|
---|
210 |
|
---|
211 | NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, Head) {
|
---|
212 | Node = NET_LIST_USER_STRUCT (Entry, PXEBC_DHCP6_OPTION_NODE, Link);
|
---|
213 | RemoveEntryList (Entry);
|
---|
214 | FreePool (Node);
|
---|
215 | }
|
---|
216 | }
|
---|
217 |
|
---|
218 |
|
---|
219 | /**
|
---|
220 | Parse the Boot File URL option.
|
---|
221 |
|
---|
222 | @param[out] FileName The pointer to the boot file name.
|
---|
223 | @param[in, out] SrvAddr The pointer to the boot server address.
|
---|
224 | @param[in] BootFile The pointer to the boot file URL option data.
|
---|
225 | @param[in] Length The length of the boot file URL option data.
|
---|
226 |
|
---|
227 | @retval EFI_ABORTED User cancel operation.
|
---|
228 | @retval EFI_SUCCESS Selected the boot menu successfully.
|
---|
229 | @retval EFI_NOT_READY Read the input key from the keybroad has not finish.
|
---|
230 |
|
---|
231 | **/
|
---|
232 | EFI_STATUS
|
---|
233 | PxeBcExtractBootFileUrl (
|
---|
234 | OUT UINT8 **FileName,
|
---|
235 | IN OUT EFI_IPv6_ADDRESS *SrvAddr,
|
---|
236 | IN CHAR8 *BootFile,
|
---|
237 | IN UINT16 Length
|
---|
238 | )
|
---|
239 | {
|
---|
240 | UINT16 PrefixLen;
|
---|
241 | CHAR8 *BootFileNamePtr;
|
---|
242 | CHAR8 *BootFileName;
|
---|
243 | UINT16 BootFileNameLen;
|
---|
244 | CHAR8 *TmpStr;
|
---|
245 | CHAR8 TmpChar;
|
---|
246 | CHAR8 *ServerAddressOption;
|
---|
247 | CHAR8 *ServerAddress;
|
---|
248 | CHAR8 *ModeStr;
|
---|
249 | EFI_STATUS Status;
|
---|
250 |
|
---|
251 | //
|
---|
252 | // The format of the Boot File URL option is:
|
---|
253 | //
|
---|
254 | // 0 1 2 3
|
---|
255 | // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
---|
256 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
---|
257 | // | OPT_BOOTFILE_URL | option-len |
|
---|
258 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
---|
259 | // | |
|
---|
260 | // . bootfile-url (variable length) .
|
---|
261 | // | |
|
---|
262 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
---|
263 | //
|
---|
264 |
|
---|
265 | //
|
---|
266 | // Based upon RFC 5970 and UEFI 2.3 Errata D specification, bootfile-url format
|
---|
267 | // is tftp://[SERVER_ADDRESS]/BOOTFILE_NAME
|
---|
268 | // As an example where the BOOTFILE_NAME is the EFI loader and
|
---|
269 | // SERVER_ADDRESS is the ASCII encoding of an IPV6 address.
|
---|
270 | //
|
---|
271 | PrefixLen = (UINT16) AsciiStrLen (PXEBC_DHCP6_BOOT_FILE_URL_PREFIX);
|
---|
272 |
|
---|
273 | if (Length <= PrefixLen ||
|
---|
274 | CompareMem (BootFile, PXEBC_DHCP6_BOOT_FILE_URL_PREFIX, PrefixLen) != 0) {
|
---|
275 | return EFI_NOT_FOUND;
|
---|
276 | }
|
---|
277 |
|
---|
278 | BootFile = BootFile + PrefixLen;
|
---|
279 | Length = (UINT16) (Length - PrefixLen);
|
---|
280 |
|
---|
281 | TmpStr = (CHAR8 *) AllocateZeroPool (Length + 1);
|
---|
282 | if (TmpStr == NULL) {
|
---|
283 | return EFI_OUT_OF_RESOURCES;
|
---|
284 | }
|
---|
285 |
|
---|
286 | CopyMem (TmpStr, BootFile, Length);
|
---|
287 | TmpStr[Length] = '\0';
|
---|
288 |
|
---|
289 | //
|
---|
290 | // Get the part of SERVER_ADDRESS string.
|
---|
291 | //
|
---|
292 | ServerAddressOption = TmpStr;
|
---|
293 | if (*ServerAddressOption != PXEBC_ADDR_START_DELIMITER) {
|
---|
294 | FreePool (TmpStr);
|
---|
295 | return EFI_INVALID_PARAMETER;
|
---|
296 | }
|
---|
297 |
|
---|
298 | ServerAddressOption ++;
|
---|
299 | ServerAddress = ServerAddressOption;
|
---|
300 | while (*ServerAddress != '\0' && *ServerAddress != PXEBC_ADDR_END_DELIMITER) {
|
---|
301 | ServerAddress++;
|
---|
302 | }
|
---|
303 |
|
---|
304 | if (*ServerAddress != PXEBC_ADDR_END_DELIMITER) {
|
---|
305 | FreePool (TmpStr);
|
---|
306 | return EFI_INVALID_PARAMETER;
|
---|
307 | }
|
---|
308 |
|
---|
309 | *ServerAddress = '\0';
|
---|
310 |
|
---|
311 | //
|
---|
312 | // Convert the string of server address to Ipv6 address format and store it.
|
---|
313 | //
|
---|
314 | Status = NetLibAsciiStrToIp6 (ServerAddressOption, SrvAddr);
|
---|
315 | if (EFI_ERROR (Status)) {
|
---|
316 | FreePool (TmpStr);
|
---|
317 | return Status;
|
---|
318 | }
|
---|
319 |
|
---|
320 | //
|
---|
321 | // Get the part of BOOTFILE_NAME string.
|
---|
322 | //
|
---|
323 | BootFileNamePtr = (CHAR8*)((UINTN)ServerAddress + 1);
|
---|
324 | if (*BootFileNamePtr != PXEBC_TFTP_URL_SEPARATOR) {
|
---|
325 | FreePool (TmpStr);
|
---|
326 | return EFI_INVALID_PARAMETER;
|
---|
327 | }
|
---|
328 |
|
---|
329 | ++BootFileNamePtr;
|
---|
330 | BootFileNameLen = (UINT16)(Length - (UINT16) ((UINTN)BootFileNamePtr - (UINTN)TmpStr) + 1);
|
---|
331 | if (BootFileNameLen != 0 || FileName != NULL) {
|
---|
332 | //
|
---|
333 | // Remove trailing mode=octet if present and ignore. All other modes are
|
---|
334 | // invalid for netboot6, so reject them.
|
---|
335 | //
|
---|
336 | ModeStr = AsciiStrStr (BootFileNamePtr, ";mode=octet");
|
---|
337 | if (ModeStr != NULL && *(ModeStr + AsciiStrLen (";mode=octet")) == '\0') {
|
---|
338 | *ModeStr = '\0';
|
---|
339 | } else if (AsciiStrStr (BootFileNamePtr, ";mode=") != NULL) {
|
---|
340 | return EFI_INVALID_PARAMETER;
|
---|
341 | }
|
---|
342 |
|
---|
343 | //
|
---|
344 | // Extract boot file name from URL.
|
---|
345 | //
|
---|
346 | BootFileName = (CHAR8 *) AllocateZeroPool (BootFileNameLen);
|
---|
347 | if (BootFileName == NULL) {
|
---|
348 | FreePool (TmpStr);
|
---|
349 | return EFI_OUT_OF_RESOURCES;
|
---|
350 | }
|
---|
351 | *FileName = (UINT8*) BootFileName;
|
---|
352 |
|
---|
353 | //
|
---|
354 | // Decode percent-encoding in boot file name.
|
---|
355 | //
|
---|
356 | while (*BootFileNamePtr != '\0') {
|
---|
357 | if (*BootFileNamePtr == '%') {
|
---|
358 | TmpChar = *(BootFileNamePtr+ 3);
|
---|
359 | *(BootFileNamePtr+ 3) = '\0';
|
---|
360 | *BootFileName = (UINT8) AsciiStrHexToUintn ((CHAR8*)(BootFileNamePtr + 1));
|
---|
361 | BootFileName++;
|
---|
362 | *(BootFileNamePtr+ 3) = TmpChar;
|
---|
363 | BootFileNamePtr += 3;
|
---|
364 | } else {
|
---|
365 | *BootFileName = *BootFileNamePtr;
|
---|
366 | BootFileName++;
|
---|
367 | BootFileNamePtr++;
|
---|
368 | }
|
---|
369 | }
|
---|
370 | *BootFileName = '\0';
|
---|
371 | }
|
---|
372 |
|
---|
373 | FreePool (TmpStr);
|
---|
374 |
|
---|
375 | return EFI_SUCCESS;
|
---|
376 | }
|
---|
377 |
|
---|
378 |
|
---|
379 | /**
|
---|
380 | Parse the Boot File Parameter option.
|
---|
381 |
|
---|
382 | @param[in] BootFilePara The pointer to boot file parameter option data.
|
---|
383 | @param[out] BootFileSize The pointer to the parsed boot file size.
|
---|
384 |
|
---|
385 | @retval EFI_SUCCESS Successfully obtained the boot file size from parameter option.
|
---|
386 | @retval EFI_NOT_FOUND Failed to extract the boot file size from parameter option.
|
---|
387 |
|
---|
388 | **/
|
---|
389 | EFI_STATUS
|
---|
390 | PxeBcExtractBootFileParam (
|
---|
391 | IN CHAR8 *BootFilePara,
|
---|
392 | OUT UINT16 *BootFileSize
|
---|
393 | )
|
---|
394 | {
|
---|
395 | UINT16 Length;
|
---|
396 | UINT8 Index;
|
---|
397 | UINT8 Digit;
|
---|
398 | UINT32 Size;
|
---|
399 |
|
---|
400 | CopyMem (&Length, BootFilePara, sizeof (UINT16));
|
---|
401 | Length = NTOHS (Length);
|
---|
402 |
|
---|
403 | //
|
---|
404 | // The BootFile Size should be 1~5 byte ASCII strings
|
---|
405 | //
|
---|
406 | if (Length < 1 || Length > 5) {
|
---|
407 | return EFI_NOT_FOUND;
|
---|
408 | }
|
---|
409 |
|
---|
410 | //
|
---|
411 | // Extract the value of BootFile Size.
|
---|
412 | //
|
---|
413 | BootFilePara = BootFilePara + sizeof (UINT16);
|
---|
414 | Size = 0;
|
---|
415 | for (Index = 0; Index < Length; Index++) {
|
---|
416 | if (EFI_ERROR (PxeBcUniHexToUint8 (&Digit, *(BootFilePara + Index)))) {
|
---|
417 | return EFI_NOT_FOUND;
|
---|
418 | }
|
---|
419 |
|
---|
420 | Size = (Size + Digit) * 10;
|
---|
421 | }
|
---|
422 |
|
---|
423 | Size = Size / 10;
|
---|
424 | if (Size > PXEBC_DHCP6_MAX_BOOT_FILE_SIZE) {
|
---|
425 | return EFI_NOT_FOUND;
|
---|
426 | }
|
---|
427 |
|
---|
428 | *BootFileSize = (UINT16) Size;
|
---|
429 | return EFI_SUCCESS;
|
---|
430 | }
|
---|
431 |
|
---|
432 |
|
---|
433 | /**
|
---|
434 | Parse the cached DHCPv6 packet, including all the options.
|
---|
435 |
|
---|
436 | @param[in] Cache6 The pointer to a cached DHCPv6 packet.
|
---|
437 |
|
---|
438 | @retval EFI_SUCCESS Parsed the DHCPv6 packet successfully.
|
---|
439 | @retval EFI_DEVICE_ERROR Failed to parse and invalid the packet.
|
---|
440 |
|
---|
441 | **/
|
---|
442 | EFI_STATUS
|
---|
443 | PxeBcParseDhcp6Packet (
|
---|
444 | IN PXEBC_DHCP6_PACKET_CACHE *Cache6
|
---|
445 | )
|
---|
446 | {
|
---|
447 | EFI_DHCP6_PACKET *Offer;
|
---|
448 | EFI_DHCP6_PACKET_OPTION **Options;
|
---|
449 | EFI_DHCP6_PACKET_OPTION *Option;
|
---|
450 | PXEBC_OFFER_TYPE OfferType;
|
---|
451 | BOOLEAN IsProxyOffer;
|
---|
452 | BOOLEAN IsPxeOffer;
|
---|
453 | UINT32 Offset;
|
---|
454 | UINT32 Length;
|
---|
455 | UINT32 EnterpriseNum;
|
---|
456 |
|
---|
457 | IsProxyOffer = TRUE;
|
---|
458 | IsPxeOffer = FALSE;
|
---|
459 | Offer = &Cache6->Packet.Offer;
|
---|
460 | Options = Cache6->OptList;
|
---|
461 |
|
---|
462 | ZeroMem (Cache6->OptList, sizeof (Cache6->OptList));
|
---|
463 |
|
---|
464 | Option = (EFI_DHCP6_PACKET_OPTION *) (Offer->Dhcp6.Option);
|
---|
465 | Offset = 0;
|
---|
466 | Length = GET_DHCP6_OPTION_SIZE (Offer);
|
---|
467 |
|
---|
468 | //
|
---|
469 | // OpLen and OpCode here are both stored in network order, since they are from original packet.
|
---|
470 | //
|
---|
471 | while (Offset < Length) {
|
---|
472 |
|
---|
473 | if (NTOHS (Option->OpCode) == PXEBC_DHCP6_OPT_IA_NA) {
|
---|
474 | Options[PXEBC_DHCP6_IDX_IA_NA] = Option;
|
---|
475 | } else if (NTOHS (Option->OpCode) == PXEBC_DHCP6_OPT_BOOT_FILE_URL) {
|
---|
476 | //
|
---|
477 | // The server sends this option to inform the client about an URL to a boot file.
|
---|
478 | //
|
---|
479 | Options[PXEBC_DHCP6_IDX_BOOT_FILE_URL] = Option;
|
---|
480 | } else if (NTOHS (Option->OpCode) == PXEBC_DHCP6_OPT_BOOT_FILE_PARAM) {
|
---|
481 | Options[PXEBC_DHCP6_IDX_BOOT_FILE_PARAM] = Option;
|
---|
482 | } else if (NTOHS (Option->OpCode) == PXEBC_DHCP6_OPT_VENDOR_CLASS) {
|
---|
483 | Options[PXEBC_DHCP6_IDX_VENDOR_CLASS] = Option;
|
---|
484 | }
|
---|
485 |
|
---|
486 | Offset += (NTOHS (Option->OpLen) + 4);
|
---|
487 | Option = (EFI_DHCP6_PACKET_OPTION *) (Offer->Dhcp6.Option + Offset);
|
---|
488 | }
|
---|
489 |
|
---|
490 | //
|
---|
491 | // The offer with assigned client address is a proxy offer.
|
---|
492 | // An ia_na option, embeded with valid ia_addr option and a status_code of success.
|
---|
493 | //
|
---|
494 | Option = Options[PXEBC_DHCP6_IDX_IA_NA];
|
---|
495 | if (Option != NULL) {
|
---|
496 | Option = PxeBcParseDhcp6Options (
|
---|
497 | Option->Data + 12,
|
---|
498 | NTOHS (Option->OpLen),
|
---|
499 | PXEBC_DHCP6_OPT_STATUS_CODE
|
---|
500 | );
|
---|
501 | if ((Option != NULL && Option->Data[0] == 0) || (Option == NULL)) {
|
---|
502 | IsProxyOffer = FALSE;
|
---|
503 | }
|
---|
504 | }
|
---|
505 |
|
---|
506 | //
|
---|
507 | // The offer with "PXEClient" is a pxe offer.
|
---|
508 | //
|
---|
509 | Option = Options[PXEBC_DHCP6_IDX_VENDOR_CLASS];
|
---|
510 | EnterpriseNum = HTONL(PXEBC_DHCP6_ENTERPRISE_NUM);
|
---|
511 |
|
---|
512 | if (Option != NULL &&
|
---|
513 | NTOHS(Option->OpLen) >= 13 &&
|
---|
514 | CompareMem (Option->Data, &EnterpriseNum, sizeof (UINT32)) == 0 &&
|
---|
515 | CompareMem (&Option->Data[6], DEFAULT_CLASS_ID_DATA, 9) == 0) {
|
---|
516 | IsPxeOffer = TRUE;
|
---|
517 | }
|
---|
518 |
|
---|
519 | //
|
---|
520 | // Determine offer type of the dhcp6 packet.
|
---|
521 | //
|
---|
522 | if (IsPxeOffer) {
|
---|
523 | //
|
---|
524 | // It's a binl offer only with PXEClient.
|
---|
525 | //
|
---|
526 | OfferType = IsProxyOffer ? PxeOfferTypeProxyBinl : PxeOfferTypeDhcpBinl;
|
---|
527 | } else {
|
---|
528 | //
|
---|
529 | // It's a dhcp only offer, which is a pure dhcp6 offer packet.
|
---|
530 | //
|
---|
531 | OfferType = PxeOfferTypeDhcpOnly;
|
---|
532 | }
|
---|
533 |
|
---|
534 | Cache6->OfferType = OfferType;
|
---|
535 |
|
---|
536 | return EFI_SUCCESS;
|
---|
537 | }
|
---|
538 |
|
---|
539 |
|
---|
540 | /**
|
---|
541 | Cache the DHCPv6 ack packet, and parse it on demand.
|
---|
542 |
|
---|
543 | @param[in] Private The pointer to PxeBc private data.
|
---|
544 | @param[in] Ack The pointer to the DHCPv6 ack packet.
|
---|
545 | @param[in] Verified If TRUE, parse the ACK packet and store info into mode data.
|
---|
546 |
|
---|
547 | **/
|
---|
548 | VOID
|
---|
549 | PxeBcCopyDhcp6Ack (
|
---|
550 | IN PXEBC_PRIVATE_DATA *Private,
|
---|
551 | IN EFI_DHCP6_PACKET *Ack,
|
---|
552 | IN BOOLEAN Verified
|
---|
553 | )
|
---|
554 | {
|
---|
555 | EFI_PXE_BASE_CODE_MODE *Mode;
|
---|
556 |
|
---|
557 | Mode = Private->PxeBc.Mode;
|
---|
558 |
|
---|
559 | PxeBcCacheDhcp6Packet (&Private->DhcpAck.Dhcp6.Packet.Ack, Ack);
|
---|
560 |
|
---|
561 | if (Verified) {
|
---|
562 | //
|
---|
563 | // Parse the ack packet and store it into mode data if needed.
|
---|
564 | //
|
---|
565 | PxeBcParseDhcp6Packet (&Private->DhcpAck.Dhcp6);
|
---|
566 | CopyMem (&Mode->DhcpAck.Dhcpv6, &Ack->Dhcp6, Ack->Length);
|
---|
567 | Mode->DhcpAckReceived = TRUE;
|
---|
568 | }
|
---|
569 | }
|
---|
570 |
|
---|
571 |
|
---|
572 | /**
|
---|
573 | Cache the DHCPv6 proxy offer packet according to the received order.
|
---|
574 |
|
---|
575 | @param[in] Private The pointer to PxeBc private data.
|
---|
576 | @param[in] OfferIndex The received order of offer packets.
|
---|
577 |
|
---|
578 | **/
|
---|
579 | VOID
|
---|
580 | PxeBcCopyDhcp6Proxy (
|
---|
581 | IN PXEBC_PRIVATE_DATA *Private,
|
---|
582 | IN UINT32 OfferIndex
|
---|
583 | )
|
---|
584 | {
|
---|
585 | EFI_PXE_BASE_CODE_MODE *Mode;
|
---|
586 | EFI_DHCP6_PACKET *Offer;
|
---|
587 |
|
---|
588 | ASSERT (OfferIndex < Private->OfferNum);
|
---|
589 | ASSERT (OfferIndex < PXEBC_OFFER_MAX_NUM);
|
---|
590 |
|
---|
591 | Mode = Private->PxeBc.Mode;
|
---|
592 | Offer = &Private->OfferBuffer[OfferIndex].Dhcp6.Packet.Offer;
|
---|
593 |
|
---|
594 | //
|
---|
595 | // Cache the proxy offer packet and parse it.
|
---|
596 | //
|
---|
597 | PxeBcCacheDhcp6Packet (&Private->ProxyOffer.Dhcp6.Packet.Offer, Offer);
|
---|
598 | PxeBcParseDhcp6Packet (&Private->ProxyOffer.Dhcp6);
|
---|
599 |
|
---|
600 | //
|
---|
601 | // Store this packet into mode data.
|
---|
602 | //
|
---|
603 | CopyMem (&Mode->ProxyOffer.Dhcpv6, &Offer->Dhcp6, Offer->Length);
|
---|
604 | Mode->ProxyOfferReceived = TRUE;
|
---|
605 | }
|
---|
606 |
|
---|
607 | /**
|
---|
608 | Seek the address of the first byte of the option header.
|
---|
609 |
|
---|
610 | @param[in] Buf The pointer to the buffer.
|
---|
611 | @param[in] SeekLen The length to seek.
|
---|
612 | @param[in] OptType The option type.
|
---|
613 |
|
---|
614 | @retval NULL If it failed to seek the option.
|
---|
615 | @retval others The position to the option.
|
---|
616 |
|
---|
617 | **/
|
---|
618 | UINT8 *
|
---|
619 | PxeBcDhcp6SeekOption (
|
---|
620 | IN UINT8 *Buf,
|
---|
621 | IN UINT32 SeekLen,
|
---|
622 | IN UINT16 OptType
|
---|
623 | )
|
---|
624 | {
|
---|
625 | UINT8 *Cursor;
|
---|
626 | UINT8 *Option;
|
---|
627 | UINT16 DataLen;
|
---|
628 | UINT16 OpCode;
|
---|
629 |
|
---|
630 | Option = NULL;
|
---|
631 | Cursor = Buf;
|
---|
632 |
|
---|
633 | while (Cursor < Buf + SeekLen) {
|
---|
634 | OpCode = ReadUnaligned16 ((UINT16 *) Cursor);
|
---|
635 | if (OpCode == HTONS (OptType)) {
|
---|
636 | Option = Cursor;
|
---|
637 | break;
|
---|
638 | }
|
---|
639 | DataLen = NTOHS (ReadUnaligned16 ((UINT16 *) (Cursor + 2)));
|
---|
640 | Cursor += (DataLen + 4);
|
---|
641 | }
|
---|
642 |
|
---|
643 | return Option;
|
---|
644 | }
|
---|
645 |
|
---|
646 |
|
---|
647 | /**
|
---|
648 | Build and send out the request packet for the bootfile, and parse the reply.
|
---|
649 |
|
---|
650 | @param[in] Private The pointer to PxeBc private data.
|
---|
651 | @param[in] Index PxeBc option boot item type.
|
---|
652 |
|
---|
653 | @retval EFI_SUCCESS Successfully discovered the boot file.
|
---|
654 | @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
|
---|
655 | @retval EFI_NOT_FOUND Can't get the PXE reply packet.
|
---|
656 | @retval Others Failed to discover the boot file.
|
---|
657 |
|
---|
658 | **/
|
---|
659 | EFI_STATUS
|
---|
660 | PxeBcRequestBootService (
|
---|
661 | IN PXEBC_PRIVATE_DATA *Private,
|
---|
662 | IN UINT32 Index
|
---|
663 | )
|
---|
664 | {
|
---|
665 | EFI_PXE_BASE_CODE_UDP_PORT SrcPort;
|
---|
666 | EFI_PXE_BASE_CODE_UDP_PORT DestPort;
|
---|
667 | EFI_PXE_BASE_CODE_MODE *Mode;
|
---|
668 | EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
|
---|
669 | EFI_PXE_BASE_CODE_DHCPV6_PACKET *Discover;
|
---|
670 | UINTN DiscoverLen;
|
---|
671 | EFI_DHCP6_PACKET *Request;
|
---|
672 | UINTN RequestLen;
|
---|
673 | EFI_DHCP6_PACKET *Reply;
|
---|
674 | UINT8 *RequestOpt;
|
---|
675 | UINT8 *DiscoverOpt;
|
---|
676 | UINTN ReadSize;
|
---|
677 | UINT16 OpFlags;
|
---|
678 | UINT16 OpCode;
|
---|
679 | UINT16 OpLen;
|
---|
680 | EFI_STATUS Status;
|
---|
681 | EFI_DHCP6_PACKET *ProxyOffer;
|
---|
682 | UINT8 *Option;
|
---|
683 |
|
---|
684 | PxeBc = &Private->PxeBc;
|
---|
685 | Mode = PxeBc->Mode;
|
---|
686 | Request = Private->Dhcp6Request;
|
---|
687 | ProxyOffer = &Private->OfferBuffer[Index].Dhcp6.Packet.Offer;
|
---|
688 | SrcPort = PXEBC_BS_DISCOVER_PORT;
|
---|
689 | DestPort = PXEBC_BS_DISCOVER_PORT;
|
---|
690 | OpFlags = 0;
|
---|
691 |
|
---|
692 | if (Request == NULL) {
|
---|
693 | return EFI_DEVICE_ERROR;
|
---|
694 | }
|
---|
695 |
|
---|
696 | Discover = AllocateZeroPool (sizeof (EFI_PXE_BASE_CODE_DHCPV6_PACKET));
|
---|
697 | if (Discover == NULL) {
|
---|
698 | return EFI_OUT_OF_RESOURCES;
|
---|
699 | }
|
---|
700 |
|
---|
701 | //
|
---|
702 | // Build the request packet by the cached request packet before.
|
---|
703 | //
|
---|
704 | Discover->TransactionId = ProxyOffer->Dhcp6.Header.TransactionId;
|
---|
705 | Discover->MessageType = Request->Dhcp6.Header.MessageType;
|
---|
706 | RequestOpt = Request->Dhcp6.Option;
|
---|
707 | DiscoverOpt = Discover->DhcpOptions;
|
---|
708 | DiscoverLen = sizeof (EFI_DHCP6_HEADER);
|
---|
709 | RequestLen = DiscoverLen;
|
---|
710 |
|
---|
711 | //
|
---|
712 | // Find Server ID Option from ProxyOffer.
|
---|
713 | //
|
---|
714 | Option = PxeBcDhcp6SeekOption (
|
---|
715 | ProxyOffer->Dhcp6.Option,
|
---|
716 | ProxyOffer->Length - 4,
|
---|
717 | PXEBC_DHCP6_OPT_SERVER_ID
|
---|
718 | );
|
---|
719 | if (Option == NULL) {
|
---|
720 | return EFI_NOT_FOUND;
|
---|
721 | }
|
---|
722 |
|
---|
723 | //
|
---|
724 | // Add Server ID Option.
|
---|
725 | //
|
---|
726 | OpLen = NTOHS (((EFI_DHCP6_PACKET_OPTION *) Option)->OpLen);
|
---|
727 | CopyMem (DiscoverOpt, Option, OpLen + 4);
|
---|
728 | DiscoverOpt += (OpLen + 4);
|
---|
729 | DiscoverLen += (OpLen + 4);
|
---|
730 |
|
---|
731 | while (RequestLen < Request->Length) {
|
---|
732 | OpCode = NTOHS (((EFI_DHCP6_PACKET_OPTION *) RequestOpt)->OpCode);
|
---|
733 | OpLen = NTOHS (((EFI_DHCP6_PACKET_OPTION *) RequestOpt)->OpLen);
|
---|
734 | if (OpCode != EFI_DHCP6_IA_TYPE_NA &&
|
---|
735 | OpCode != EFI_DHCP6_IA_TYPE_TA &&
|
---|
736 | OpCode != PXEBC_DHCP6_OPT_SERVER_ID
|
---|
737 | ) {
|
---|
738 | //
|
---|
739 | // Copy all the options except IA option and Server ID
|
---|
740 | //
|
---|
741 | CopyMem (DiscoverOpt, RequestOpt, OpLen + 4);
|
---|
742 | DiscoverOpt += (OpLen + 4);
|
---|
743 | DiscoverLen += (OpLen + 4);
|
---|
744 | }
|
---|
745 | RequestOpt += (OpLen + 4);
|
---|
746 | RequestLen += (OpLen + 4);
|
---|
747 | }
|
---|
748 |
|
---|
749 | //
|
---|
750 | // Update Elapsed option in the package
|
---|
751 | //
|
---|
752 | Option = PxeBcDhcp6SeekOption (
|
---|
753 | Discover->DhcpOptions,
|
---|
754 | (UINT32)(RequestLen - 4),
|
---|
755 | PXEBC_DHCP6_OPT_ELAPSED_TIME
|
---|
756 | );
|
---|
757 | if (Option != NULL) {
|
---|
758 | CalcElapsedTime (Private);
|
---|
759 | WriteUnaligned16 ((UINT16*)(Option + 4), HTONS((UINT16) Private->ElapsedTime));
|
---|
760 | }
|
---|
761 |
|
---|
762 | Status = PxeBc->UdpWrite (
|
---|
763 | PxeBc,
|
---|
764 | OpFlags,
|
---|
765 | &Private->ServerIp,
|
---|
766 | &DestPort,
|
---|
767 | NULL,
|
---|
768 | &Private->StationIp,
|
---|
769 | &SrcPort,
|
---|
770 | NULL,
|
---|
771 | NULL,
|
---|
772 | &DiscoverLen,
|
---|
773 | (VOID *) Discover
|
---|
774 | );
|
---|
775 |
|
---|
776 | if (EFI_ERROR (Status)) {
|
---|
777 | return Status;
|
---|
778 | }
|
---|
779 |
|
---|
780 | //
|
---|
781 | // Cache the right PXE reply packet here, set valid flag later.
|
---|
782 | // Especially for PXE discover packet, store it into mode data here.
|
---|
783 | //
|
---|
784 | Reply = &Private->ProxyOffer.Dhcp6.Packet.Offer;
|
---|
785 | ReadSize = (UINTN) Reply->Size;
|
---|
786 |
|
---|
787 | //
|
---|
788 | // Start Udp6Read instance
|
---|
789 | //
|
---|
790 | Status = Private->Udp6Read->Configure (Private->Udp6Read, &Private->Udp6CfgData);
|
---|
791 | if (EFI_ERROR (Status)) {
|
---|
792 | return Status;
|
---|
793 | }
|
---|
794 |
|
---|
795 | Status = PxeBc->UdpRead (
|
---|
796 | PxeBc,
|
---|
797 | EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP,
|
---|
798 | &Private->StationIp,
|
---|
799 | &SrcPort,
|
---|
800 | &Private->ServerIp,
|
---|
801 | &DestPort,
|
---|
802 | NULL,
|
---|
803 | NULL,
|
---|
804 | &ReadSize,
|
---|
805 | (VOID *) &Reply->Dhcp6
|
---|
806 | );
|
---|
807 | //
|
---|
808 | // Stop Udp6Read instance
|
---|
809 | //
|
---|
810 | Private->Udp6Read->Configure (Private->Udp6Read, NULL);
|
---|
811 |
|
---|
812 | if (EFI_ERROR (Status)) {
|
---|
813 | return Status;
|
---|
814 | }
|
---|
815 |
|
---|
816 | //
|
---|
817 | // Update length
|
---|
818 | //
|
---|
819 | Reply->Length = (UINT32) ReadSize;
|
---|
820 |
|
---|
821 | return EFI_SUCCESS;
|
---|
822 | }
|
---|
823 |
|
---|
824 |
|
---|
825 | /**
|
---|
826 | Retry to request bootfile name by the BINL offer.
|
---|
827 |
|
---|
828 | @param[in] Private The pointer to PxeBc private data.
|
---|
829 | @param[in] Index The received order of offer packets.
|
---|
830 |
|
---|
831 | @retval EFI_SUCCESS Successfully retried a request for the bootfile name.
|
---|
832 | @retval EFI_DEVICE_ERROR Failed to retry the bootfile name.
|
---|
833 |
|
---|
834 | **/
|
---|
835 | EFI_STATUS
|
---|
836 | PxeBcRetryDhcp6Binl (
|
---|
837 | IN PXEBC_PRIVATE_DATA *Private,
|
---|
838 | IN UINT32 Index
|
---|
839 | )
|
---|
840 | {
|
---|
841 | EFI_PXE_BASE_CODE_MODE *Mode;
|
---|
842 | PXEBC_DHCP6_PACKET_CACHE *Offer;
|
---|
843 | PXEBC_DHCP6_PACKET_CACHE *Cache6;
|
---|
844 | EFI_STATUS Status;
|
---|
845 |
|
---|
846 | ASSERT (Index < PXEBC_OFFER_MAX_NUM);
|
---|
847 | ASSERT (Private->OfferBuffer[Index].Dhcp6.OfferType == PxeOfferTypeDhcpBinl ||
|
---|
848 | Private->OfferBuffer[Index].Dhcp6.OfferType == PxeOfferTypeProxyBinl);
|
---|
849 |
|
---|
850 | Mode = Private->PxeBc.Mode;
|
---|
851 | Private->IsDoDiscover = FALSE;
|
---|
852 | Offer = &Private->OfferBuffer[Index].Dhcp6;
|
---|
853 | if (Offer->OfferType == PxeOfferTypeDhcpBinl) {
|
---|
854 | //
|
---|
855 | // There is no BootFileUrl option in dhcp6 offer, so use servers multi-cast address instead.
|
---|
856 | //
|
---|
857 | CopyMem (
|
---|
858 | &Private->ServerIp.v6,
|
---|
859 | &mAllDhcpRelayAndServersAddress,
|
---|
860 | sizeof (EFI_IPv6_ADDRESS)
|
---|
861 | );
|
---|
862 | } else {
|
---|
863 | ASSERT (Offer->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL] != NULL);
|
---|
864 | //
|
---|
865 | // Parse out the next server address from the last offer, and store it
|
---|
866 | //
|
---|
867 | Status = PxeBcExtractBootFileUrl (
|
---|
868 | &Private->BootFileName,
|
---|
869 | &Private->ServerIp.v6,
|
---|
870 | (CHAR8 *) (Offer->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL]->Data),
|
---|
871 | NTOHS (Offer->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL]->OpLen)
|
---|
872 | );
|
---|
873 | if (EFI_ERROR (Status)) {
|
---|
874 | return Status;
|
---|
875 | }
|
---|
876 | }
|
---|
877 |
|
---|
878 | //
|
---|
879 | // Retry Dhcp6Binl again for the bootfile, and the reply cached into Private->ProxyOffer.
|
---|
880 | //
|
---|
881 | Status = PxeBcRequestBootService (Private, Index);
|
---|
882 |
|
---|
883 | if (EFI_ERROR (Status)) {
|
---|
884 | return Status;
|
---|
885 | }
|
---|
886 |
|
---|
887 | Cache6 = &Private->ProxyOffer.Dhcp6;
|
---|
888 | Status = PxeBcParseDhcp6Packet (Cache6);
|
---|
889 | if (EFI_ERROR (Status)) {
|
---|
890 | return Status;
|
---|
891 | }
|
---|
892 |
|
---|
893 | if (Cache6->OfferType != PxeOfferTypeProxyPxe10 &&
|
---|
894 | Cache6->OfferType != PxeOfferTypeProxyWfm11a &&
|
---|
895 | Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL] == NULL) {
|
---|
896 | //
|
---|
897 | // This BINL ack doesn't have discovery option set or multicast option set
|
---|
898 | // or bootfile name specified.
|
---|
899 | //
|
---|
900 | return EFI_DEVICE_ERROR;
|
---|
901 | }
|
---|
902 |
|
---|
903 | Mode->ProxyOfferReceived = TRUE;
|
---|
904 | CopyMem (
|
---|
905 | &Mode->ProxyOffer.Dhcpv6,
|
---|
906 | &Cache6->Packet.Offer.Dhcp6,
|
---|
907 | Cache6->Packet.Offer.Length
|
---|
908 | );
|
---|
909 |
|
---|
910 | return EFI_SUCCESS;
|
---|
911 | }
|
---|
912 |
|
---|
913 |
|
---|
914 | /**
|
---|
915 | Cache all the received DHCPv6 offers, and set OfferIndex and OfferCount.
|
---|
916 |
|
---|
917 | @param[in] Private The pointer to PXEBC_PRIVATE_DATA.
|
---|
918 | @param[in] RcvdOffer The pointer to the received offer packet.
|
---|
919 |
|
---|
920 | **/
|
---|
921 | VOID
|
---|
922 | PxeBcCacheDhcp6Offer (
|
---|
923 | IN PXEBC_PRIVATE_DATA *Private,
|
---|
924 | IN EFI_DHCP6_PACKET *RcvdOffer
|
---|
925 | )
|
---|
926 | {
|
---|
927 | PXEBC_DHCP6_PACKET_CACHE *Cache6;
|
---|
928 | EFI_DHCP6_PACKET *Offer;
|
---|
929 | PXEBC_OFFER_TYPE OfferType;
|
---|
930 |
|
---|
931 | Cache6 = &Private->OfferBuffer[Private->OfferNum].Dhcp6;
|
---|
932 | Offer = &Cache6->Packet.Offer;
|
---|
933 |
|
---|
934 | //
|
---|
935 | // Cache the content of DHCPv6 packet firstly.
|
---|
936 | //
|
---|
937 | PxeBcCacheDhcp6Packet (Offer, RcvdOffer);
|
---|
938 |
|
---|
939 | //
|
---|
940 | // Validate the DHCPv6 packet, and parse the options and offer type.
|
---|
941 | //
|
---|
942 | if (EFI_ERROR (PxeBcParseDhcp6Packet (Cache6))) {
|
---|
943 | return ;
|
---|
944 | }
|
---|
945 |
|
---|
946 | //
|
---|
947 | // Determine whether cache the current offer by type, and record OfferIndex and OfferCount.
|
---|
948 | //
|
---|
949 | OfferType = Cache6->OfferType;
|
---|
950 | ASSERT (OfferType < PxeOfferTypeMax);
|
---|
951 | ASSERT (Private->OfferCount[OfferType] < PXEBC_OFFER_MAX_NUM);
|
---|
952 |
|
---|
953 | if (IS_PROXY_OFFER (OfferType)) {
|
---|
954 | //
|
---|
955 | // It's a proxy offer without yiaddr, including PXE10, WFM11a or BINL offer.
|
---|
956 | //
|
---|
957 | Private->IsProxyRecved = TRUE;
|
---|
958 |
|
---|
959 | if (OfferType == PxeOfferTypeProxyBinl) {
|
---|
960 | //
|
---|
961 | // Cache all proxy BINL offers.
|
---|
962 | //
|
---|
963 | Private->OfferIndex[OfferType][Private->OfferCount[OfferType]] = Private->OfferNum;
|
---|
964 | Private->OfferCount[OfferType]++;
|
---|
965 | } else if (Private->OfferCount[OfferType] > 0) {
|
---|
966 | //
|
---|
967 | // Only cache the first PXE10/WFM11a offer, and discard the others.
|
---|
968 | //
|
---|
969 | Private->OfferIndex[OfferType][0] = Private->OfferNum;
|
---|
970 | Private->OfferCount[OfferType] = 1;
|
---|
971 | } else {
|
---|
972 | return;
|
---|
973 | }
|
---|
974 | } else {
|
---|
975 | //
|
---|
976 | // It's a DHCPv6 offer with yiaddr, and cache them all.
|
---|
977 | //
|
---|
978 | Private->OfferIndex[OfferType][Private->OfferCount[OfferType]] = Private->OfferNum;
|
---|
979 | Private->OfferCount[OfferType]++;
|
---|
980 | }
|
---|
981 |
|
---|
982 | Private->OfferNum++;
|
---|
983 | }
|
---|
984 |
|
---|
985 |
|
---|
986 | /**
|
---|
987 | Select an DHCPv6 offer, and record SelectIndex and SelectProxyType.
|
---|
988 |
|
---|
989 | @param[in] Private The pointer to PXEBC_PRIVATE_DATA.
|
---|
990 |
|
---|
991 | **/
|
---|
992 | VOID
|
---|
993 | PxeBcSelectDhcp6Offer (
|
---|
994 | IN PXEBC_PRIVATE_DATA *Private
|
---|
995 | )
|
---|
996 | {
|
---|
997 | UINT32 Index;
|
---|
998 | UINT32 OfferIndex;
|
---|
999 | PXEBC_OFFER_TYPE OfferType;
|
---|
1000 |
|
---|
1001 | Private->SelectIndex = 0;
|
---|
1002 |
|
---|
1003 | if (Private->IsOfferSorted) {
|
---|
1004 | //
|
---|
1005 | // Select offer by default policy.
|
---|
1006 | //
|
---|
1007 | if (Private->OfferCount[PxeOfferTypeDhcpPxe10] > 0) {
|
---|
1008 | //
|
---|
1009 | // 1. DhcpPxe10 offer
|
---|
1010 | //
|
---|
1011 | Private->SelectIndex = Private->OfferIndex[PxeOfferTypeDhcpPxe10][0] + 1;
|
---|
1012 |
|
---|
1013 | } else if (Private->OfferCount[PxeOfferTypeDhcpWfm11a] > 0) {
|
---|
1014 | //
|
---|
1015 | // 2. DhcpWfm11a offer
|
---|
1016 | //
|
---|
1017 | Private->SelectIndex = Private->OfferIndex[PxeOfferTypeDhcpWfm11a][0] + 1;
|
---|
1018 |
|
---|
1019 | } else if (Private->OfferCount[PxeOfferTypeDhcpOnly] > 0 &&
|
---|
1020 | Private->OfferCount[PxeOfferTypeProxyPxe10] > 0) {
|
---|
1021 | //
|
---|
1022 | // 3. DhcpOnly offer and ProxyPxe10 offer.
|
---|
1023 | //
|
---|
1024 | Private->SelectIndex = Private->OfferIndex[PxeOfferTypeDhcpOnly][0] + 1;
|
---|
1025 | Private->SelectProxyType = PxeOfferTypeProxyPxe10;
|
---|
1026 |
|
---|
1027 | } else if (Private->OfferCount[PxeOfferTypeDhcpOnly] > 0 &&
|
---|
1028 | Private->OfferCount[PxeOfferTypeProxyWfm11a] > 0) {
|
---|
1029 | //
|
---|
1030 | // 4. DhcpOnly offer and ProxyWfm11a offer.
|
---|
1031 | //
|
---|
1032 | Private->SelectIndex = Private->OfferIndex[PxeOfferTypeDhcpOnly][0] + 1;
|
---|
1033 | Private->SelectProxyType = PxeOfferTypeProxyWfm11a;
|
---|
1034 |
|
---|
1035 | } else if (Private->OfferCount[PxeOfferTypeDhcpBinl] > 0) {
|
---|
1036 | //
|
---|
1037 | // 5. DhcpBinl offer.
|
---|
1038 | //
|
---|
1039 | Private->SelectIndex = Private->OfferIndex[PxeOfferTypeDhcpBinl][0] + 1;
|
---|
1040 |
|
---|
1041 | } else if (Private->OfferCount[PxeOfferTypeDhcpOnly] > 0 &&
|
---|
1042 | Private->OfferCount[PxeOfferTypeProxyBinl] > 0) {
|
---|
1043 | //
|
---|
1044 | // 6. DhcpOnly offer and ProxyBinl offer.
|
---|
1045 | //
|
---|
1046 | Private->SelectIndex = Private->OfferIndex[PxeOfferTypeDhcpOnly][0] + 1;
|
---|
1047 | Private->SelectProxyType = PxeOfferTypeProxyBinl;
|
---|
1048 |
|
---|
1049 | } else {
|
---|
1050 | //
|
---|
1051 | // 7. DhcpOnly offer with bootfilename.
|
---|
1052 | //
|
---|
1053 | for (Index = 0; Index < Private->OfferCount[PxeOfferTypeDhcpOnly]; Index++) {
|
---|
1054 | OfferIndex = Private->OfferIndex[PxeOfferTypeDhcpOnly][Index];
|
---|
1055 | if (Private->OfferBuffer[OfferIndex].Dhcp6.OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL] != NULL) {
|
---|
1056 | Private->SelectIndex = OfferIndex + 1;
|
---|
1057 | break;
|
---|
1058 | }
|
---|
1059 | }
|
---|
1060 | }
|
---|
1061 | } else {
|
---|
1062 | //
|
---|
1063 | // Select offer by received order.
|
---|
1064 | //
|
---|
1065 | for (Index = 0; Index < Private->OfferNum; Index++) {
|
---|
1066 |
|
---|
1067 | OfferType = Private->OfferBuffer[Index].Dhcp6.OfferType;
|
---|
1068 |
|
---|
1069 | if (IS_PROXY_OFFER (OfferType)) {
|
---|
1070 | //
|
---|
1071 | // Skip proxy offers
|
---|
1072 | //
|
---|
1073 | continue;
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | if (!Private->IsProxyRecved &&
|
---|
1077 | OfferType == PxeOfferTypeDhcpOnly &&
|
---|
1078 | Private->OfferBuffer[Index].Dhcp6.OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL] == NULL) {
|
---|
1079 | //
|
---|
1080 | // Skip if DhcpOnly offer without any other proxy offers or bootfilename.
|
---|
1081 | //
|
---|
1082 | continue;
|
---|
1083 | }
|
---|
1084 |
|
---|
1085 | Private->SelectIndex = Index + 1;
|
---|
1086 | break;
|
---|
1087 | }
|
---|
1088 | }
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 |
|
---|
1092 | /**
|
---|
1093 | Handle the DHCPv6 offer packet.
|
---|
1094 |
|
---|
1095 | @param[in] Private The pointer to PXEBC_PRIVATE_DATA.
|
---|
1096 |
|
---|
1097 | @retval EFI_SUCCESS Handled the DHCPv6 offer packet successfully.
|
---|
1098 | @retval EFI_NO_RESPONSE No response to the following request packet.
|
---|
1099 |
|
---|
1100 | **/
|
---|
1101 | EFI_STATUS
|
---|
1102 | PxeBcHandleDhcp6Offer (
|
---|
1103 | IN PXEBC_PRIVATE_DATA *Private
|
---|
1104 | )
|
---|
1105 | {
|
---|
1106 | PXEBC_DHCP6_PACKET_CACHE *Cache6;
|
---|
1107 | EFI_STATUS Status;
|
---|
1108 | PXEBC_OFFER_TYPE OfferType;
|
---|
1109 | UINT32 ProxyIndex;
|
---|
1110 | UINT32 SelectIndex;
|
---|
1111 | UINT32 Index;
|
---|
1112 |
|
---|
1113 | ASSERT (Private->SelectIndex > 0);
|
---|
1114 | SelectIndex = (UINT32) (Private->SelectIndex - 1);
|
---|
1115 | ASSERT (SelectIndex < PXEBC_OFFER_MAX_NUM);
|
---|
1116 | Cache6 = &Private->OfferBuffer[SelectIndex].Dhcp6;
|
---|
1117 | Status = EFI_SUCCESS;
|
---|
1118 |
|
---|
1119 | if (Cache6->OfferType == PxeOfferTypeDhcpBinl) {
|
---|
1120 | //
|
---|
1121 | // DhcpBinl offer is selected, so need try to request bootfilename by this offer.
|
---|
1122 | //
|
---|
1123 | if (EFI_ERROR (PxeBcRetryDhcp6Binl (Private, SelectIndex))) {
|
---|
1124 | Status = EFI_NO_RESPONSE;
|
---|
1125 | }
|
---|
1126 | } else if (Cache6->OfferType == PxeOfferTypeDhcpOnly) {
|
---|
1127 |
|
---|
1128 | if (Private->IsProxyRecved) {
|
---|
1129 | //
|
---|
1130 | // DhcpOnly offer is selected, so need try to request bootfilename.
|
---|
1131 | //
|
---|
1132 | ProxyIndex = 0;
|
---|
1133 | if (Private->IsOfferSorted) {
|
---|
1134 | //
|
---|
1135 | // The proxy offer should be determined if select by default policy.
|
---|
1136 | // IsOfferSorted means all offers are labeled by OfferIndex.
|
---|
1137 | //
|
---|
1138 | ASSERT (Private->OfferCount[Private->SelectProxyType] > 0);
|
---|
1139 |
|
---|
1140 | if (Private->SelectProxyType == PxeOfferTypeProxyBinl) {
|
---|
1141 | //
|
---|
1142 | // Try all the cached ProxyBinl offer one by one to request bootfilename.
|
---|
1143 | //
|
---|
1144 | for (Index = 0; Index < Private->OfferCount[Private->SelectProxyType]; Index++) {
|
---|
1145 |
|
---|
1146 | ProxyIndex = Private->OfferIndex[Private->SelectProxyType][Index];
|
---|
1147 | if (!EFI_ERROR (PxeBcRetryDhcp6Binl (Private, ProxyIndex))) {
|
---|
1148 | break;
|
---|
1149 | }
|
---|
1150 | }
|
---|
1151 | if (Index == Private->OfferCount[Private->SelectProxyType]) {
|
---|
1152 | Status = EFI_NO_RESPONSE;
|
---|
1153 | }
|
---|
1154 | } else {
|
---|
1155 | //
|
---|
1156 | // For other proxy offers (pxe10 or wfm11a), only one is buffered.
|
---|
1157 | //
|
---|
1158 | ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0];
|
---|
1159 | }
|
---|
1160 | } else {
|
---|
1161 | //
|
---|
1162 | // The proxy offer should not be determined if select by received order.
|
---|
1163 | //
|
---|
1164 | Status = EFI_NO_RESPONSE;
|
---|
1165 |
|
---|
1166 | for (Index = 0; Index < Private->OfferNum; Index++) {
|
---|
1167 |
|
---|
1168 | OfferType = Private->OfferBuffer[Index].Dhcp6.OfferType;
|
---|
1169 |
|
---|
1170 | if (!IS_PROXY_OFFER (OfferType)) {
|
---|
1171 | //
|
---|
1172 | // Skip non proxy dhcp offers.
|
---|
1173 | //
|
---|
1174 | continue;
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | if (OfferType == PxeOfferTypeProxyBinl) {
|
---|
1178 | //
|
---|
1179 | // Try all the cached ProxyBinl offer one by one to request bootfilename.
|
---|
1180 | //
|
---|
1181 | if (EFI_ERROR (PxeBcRetryDhcp6Binl (Private, Index))) {
|
---|
1182 | continue;
|
---|
1183 | }
|
---|
1184 | }
|
---|
1185 |
|
---|
1186 | Private->SelectProxyType = OfferType;
|
---|
1187 | ProxyIndex = Index;
|
---|
1188 | Status = EFI_SUCCESS;
|
---|
1189 | break;
|
---|
1190 | }
|
---|
1191 | }
|
---|
1192 |
|
---|
1193 | if (!EFI_ERROR (Status) && Private->SelectProxyType != PxeOfferTypeProxyBinl) {
|
---|
1194 | //
|
---|
1195 | // Success to try to request by a ProxyPxe10 or ProxyWfm11a offer, copy and parse it.
|
---|
1196 | //
|
---|
1197 | PxeBcCopyDhcp6Proxy (Private, ProxyIndex);
|
---|
1198 | }
|
---|
1199 | } else {
|
---|
1200 | //
|
---|
1201 | // Othewise, the bootfilename must be included in DhcpOnly offer.
|
---|
1202 | //
|
---|
1203 | ASSERT (Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL] != NULL);
|
---|
1204 | }
|
---|
1205 | }
|
---|
1206 |
|
---|
1207 | if (!EFI_ERROR (Status)) {
|
---|
1208 | //
|
---|
1209 | // All PXE boot information is ready by now.
|
---|
1210 | //
|
---|
1211 | PxeBcCopyDhcp6Ack (Private, &Private->DhcpAck.Dhcp6.Packet.Ack, TRUE);
|
---|
1212 | Private->PxeBc.Mode->DhcpDiscoverValid = TRUE;
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | return Status;
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 |
|
---|
1219 | /**
|
---|
1220 | Unregister the address by Ip6Config protocol.
|
---|
1221 |
|
---|
1222 | @param[in] Private The pointer to PXEBC_PRIVATE_DATA.
|
---|
1223 |
|
---|
1224 | **/
|
---|
1225 | VOID
|
---|
1226 | PxeBcUnregisterIp6Address (
|
---|
1227 | IN PXEBC_PRIVATE_DATA *Private
|
---|
1228 | )
|
---|
1229 | {
|
---|
1230 | if (Private->Ip6Policy != PXEBC_IP6_POLICY_MAX) {
|
---|
1231 | //
|
---|
1232 | // PXE driver change the policy of IP6 driver, it's a chance to recover.
|
---|
1233 | // Keep the point and there is no enough requirements to do recovery.
|
---|
1234 | //
|
---|
1235 | }
|
---|
1236 | }
|
---|
1237 |
|
---|
1238 |
|
---|
1239 | /**
|
---|
1240 | Register the ready address by Ip6Config protocol.
|
---|
1241 |
|
---|
1242 | @param[in] Private The pointer to PXEBC_PRIVATE_DATA.
|
---|
1243 | @param[in] Address The pointer to the ready address.
|
---|
1244 |
|
---|
1245 | @retval EFI_SUCCESS Registered the address succesfully.
|
---|
1246 | @retval Others Failed to register the address.
|
---|
1247 |
|
---|
1248 | **/
|
---|
1249 | EFI_STATUS
|
---|
1250 | PxeBcRegisterIp6Address (
|
---|
1251 | IN PXEBC_PRIVATE_DATA *Private,
|
---|
1252 | IN EFI_IPv6_ADDRESS *Address
|
---|
1253 | )
|
---|
1254 | {
|
---|
1255 | EFI_IP6_PROTOCOL *Ip6;
|
---|
1256 | EFI_IP6_CONFIG_PROTOCOL *Ip6Cfg;
|
---|
1257 | EFI_IP6_CONFIG_POLICY Policy;
|
---|
1258 | EFI_IP6_CONFIG_MANUAL_ADDRESS CfgAddr;
|
---|
1259 | UINTN DataSize;
|
---|
1260 | EFI_EVENT TimeOutEvt;
|
---|
1261 | EFI_EVENT MappedEvt;
|
---|
1262 | EFI_STATUS Status;
|
---|
1263 |
|
---|
1264 | Status = EFI_SUCCESS;
|
---|
1265 | TimeOutEvt = NULL;
|
---|
1266 | MappedEvt = NULL;
|
---|
1267 | DataSize = sizeof (EFI_IP6_CONFIG_POLICY);
|
---|
1268 | Ip6Cfg = Private->Ip6Cfg;
|
---|
1269 | Ip6 = Private->Ip6;
|
---|
1270 |
|
---|
1271 | ZeroMem (&CfgAddr, sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS));
|
---|
1272 | CopyMem (&CfgAddr.Address, Address, sizeof (EFI_IPv6_ADDRESS));
|
---|
1273 |
|
---|
1274 | //
|
---|
1275 | // Get and store the current policy of IP6 driver.
|
---|
1276 | //
|
---|
1277 | Status = Ip6Cfg->GetData (
|
---|
1278 | Ip6Cfg,
|
---|
1279 | Ip6ConfigDataTypePolicy,
|
---|
1280 | &DataSize,
|
---|
1281 | &Private->Ip6Policy
|
---|
1282 | );
|
---|
1283 | if (EFI_ERROR (Status)) {
|
---|
1284 | goto ON_EXIT;
|
---|
1285 | }
|
---|
1286 |
|
---|
1287 | //
|
---|
1288 | // There is no channel between IP6 and PXE driver about address setting,
|
---|
1289 | // so it has to set the new address by Ip6ConfigProtocol manually.
|
---|
1290 | //
|
---|
1291 | Policy = Ip6ConfigPolicyManual;
|
---|
1292 | Status = Ip6Cfg->SetData (
|
---|
1293 | Ip6Cfg,
|
---|
1294 | Ip6ConfigDataTypePolicy,
|
---|
1295 | sizeof(EFI_IP6_CONFIG_POLICY),
|
---|
1296 | &Policy
|
---|
1297 | );
|
---|
1298 | if (EFI_ERROR (Status)) {
|
---|
1299 | //
|
---|
1300 | // There is no need to recover later.
|
---|
1301 | //
|
---|
1302 | Private->Ip6Policy = PXEBC_IP6_POLICY_MAX;
|
---|
1303 | goto ON_EXIT;
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 | //
|
---|
1307 | // Create a timer as setting address timeout event since DAD in IP6 driver.
|
---|
1308 | //
|
---|
1309 | Status = gBS->CreateEvent (
|
---|
1310 | EVT_TIMER,
|
---|
1311 | TPL_CALLBACK,
|
---|
1312 | NULL,
|
---|
1313 | NULL,
|
---|
1314 | &TimeOutEvt
|
---|
1315 | );
|
---|
1316 | if (EFI_ERROR (Status)) {
|
---|
1317 | goto ON_EXIT;
|
---|
1318 | }
|
---|
1319 |
|
---|
1320 | //
|
---|
1321 | // Create a notify event to set address flag when DAD if IP6 driver succeeded.
|
---|
1322 | //
|
---|
1323 | Status = gBS->CreateEvent (
|
---|
1324 | EVT_NOTIFY_SIGNAL,
|
---|
1325 | TPL_NOTIFY,
|
---|
1326 | PxeBcCommonNotify,
|
---|
1327 | &Private->IsAddressOk,
|
---|
1328 | &MappedEvt
|
---|
1329 | );
|
---|
1330 | if (EFI_ERROR (Status)) {
|
---|
1331 | goto ON_EXIT;
|
---|
1332 | }
|
---|
1333 |
|
---|
1334 | Status = Ip6Cfg->RegisterDataNotify (
|
---|
1335 | Ip6Cfg,
|
---|
1336 | Ip6ConfigDataTypeManualAddress,
|
---|
1337 | MappedEvt
|
---|
1338 | );
|
---|
1339 | if (EFI_ERROR(Status)) {
|
---|
1340 | goto ON_EXIT;
|
---|
1341 | }
|
---|
1342 |
|
---|
1343 | Status = Ip6Cfg->SetData (
|
---|
1344 | Ip6Cfg,
|
---|
1345 | Ip6ConfigDataTypeManualAddress,
|
---|
1346 | sizeof(EFI_IP6_CONFIG_MANUAL_ADDRESS),
|
---|
1347 | &CfgAddr
|
---|
1348 | );
|
---|
1349 | if (EFI_ERROR(Status) && Status != EFI_NOT_READY) {
|
---|
1350 | goto ON_EXIT;
|
---|
1351 | }
|
---|
1352 |
|
---|
1353 | //
|
---|
1354 | // Start the 5 secondes timer to wait for setting address.
|
---|
1355 | //
|
---|
1356 | Status = EFI_NO_MAPPING;
|
---|
1357 | gBS->SetTimer (TimeOutEvt, TimerRelative, PXEBC_DHCP6_MAPPING_TIMEOUT);
|
---|
1358 |
|
---|
1359 | while (EFI_ERROR (gBS->CheckEvent (TimeOutEvt))) {
|
---|
1360 | Ip6->Poll (Ip6);
|
---|
1361 | if (Private->IsAddressOk) {
|
---|
1362 | Status = EFI_SUCCESS;
|
---|
1363 | break;
|
---|
1364 | }
|
---|
1365 | }
|
---|
1366 |
|
---|
1367 | ON_EXIT:
|
---|
1368 | if (MappedEvt != NULL) {
|
---|
1369 | Ip6Cfg->UnregisterDataNotify (
|
---|
1370 | Ip6Cfg,
|
---|
1371 | Ip6ConfigDataTypeManualAddress,
|
---|
1372 | MappedEvt
|
---|
1373 | );
|
---|
1374 | gBS->CloseEvent (MappedEvt);
|
---|
1375 | }
|
---|
1376 | if (TimeOutEvt != NULL) {
|
---|
1377 | gBS->CloseEvent (TimeOutEvt);
|
---|
1378 | }
|
---|
1379 | return Status;
|
---|
1380 | }
|
---|
1381 |
|
---|
1382 |
|
---|
1383 | /**
|
---|
1384 | EFI_DHCP6_CALLBACK is provided by the consumer of the EFI DHCPv6 Protocol driver
|
---|
1385 | to intercept events that occurred in the configuration process.
|
---|
1386 |
|
---|
1387 | @param[in] This The pointer to the EFI DHCPv6 Protocol.
|
---|
1388 | @param[in] Context The pointer to the context set by EFI_DHCP6_PROTOCOL.Configure().
|
---|
1389 | @param[in] CurrentState The current operational state of the EFI DHCPv Protocol driver.
|
---|
1390 | @param[in] Dhcp6Event The event that occurs in the current state, which usually means a
|
---|
1391 | state transition.
|
---|
1392 | @param[in] Packet The DHCPv6 packet that is going to be sent or was already received.
|
---|
1393 | @param[out] NewPacket The packet that is used to replace the Packet above.
|
---|
1394 |
|
---|
1395 | @retval EFI_SUCCESS Told the EFI DHCPv6 Protocol driver to continue the DHCP process.
|
---|
1396 | @retval EFI_NOT_READY Only used in the Dhcp6Selecting state. The EFI DHCPv6 Protocol
|
---|
1397 | driver will continue to wait for more packets.
|
---|
1398 | @retval EFI_ABORTED Told the EFI DHCPv6 Protocol driver to abort the current process.
|
---|
1399 |
|
---|
1400 | **/
|
---|
1401 | EFI_STATUS
|
---|
1402 | EFIAPI
|
---|
1403 | PxeBcDhcp6CallBack (
|
---|
1404 | IN EFI_DHCP6_PROTOCOL *This,
|
---|
1405 | IN VOID *Context,
|
---|
1406 | IN EFI_DHCP6_STATE CurrentState,
|
---|
1407 | IN EFI_DHCP6_EVENT Dhcp6Event,
|
---|
1408 | IN EFI_DHCP6_PACKET *Packet,
|
---|
1409 | OUT EFI_DHCP6_PACKET **NewPacket OPTIONAL
|
---|
1410 | )
|
---|
1411 | {
|
---|
1412 | PXEBC_PRIVATE_DATA *Private;
|
---|
1413 | EFI_PXE_BASE_CODE_MODE *Mode;
|
---|
1414 | EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *Callback;
|
---|
1415 | EFI_DHCP6_PACKET *SelectAd;
|
---|
1416 | EFI_STATUS Status;
|
---|
1417 | BOOLEAN Received;
|
---|
1418 |
|
---|
1419 | if ((Dhcp6Event != Dhcp6RcvdAdvertise) &&
|
---|
1420 | (Dhcp6Event != Dhcp6SelectAdvertise) &&
|
---|
1421 | (Dhcp6Event != Dhcp6SendSolicit) &&
|
---|
1422 | (Dhcp6Event != Dhcp6SendRequest) &&
|
---|
1423 | (Dhcp6Event != Dhcp6RcvdReply)) {
|
---|
1424 | return EFI_SUCCESS;
|
---|
1425 | }
|
---|
1426 |
|
---|
1427 | ASSERT (Packet != NULL);
|
---|
1428 |
|
---|
1429 | Private = (PXEBC_PRIVATE_DATA *) Context;
|
---|
1430 | Mode = Private->PxeBc.Mode;
|
---|
1431 | Callback = Private->PxeBcCallback;
|
---|
1432 |
|
---|
1433 | //
|
---|
1434 | // Callback to user when any traffic ocurred if has.
|
---|
1435 | //
|
---|
1436 | if (Dhcp6Event != Dhcp6SelectAdvertise && Callback != NULL) {
|
---|
1437 | Received = (BOOLEAN) (Dhcp6Event == Dhcp6RcvdAdvertise || Dhcp6Event == Dhcp6RcvdReply);
|
---|
1438 | Status = Callback->Callback (
|
---|
1439 | Callback,
|
---|
1440 | Private->Function,
|
---|
1441 | Received,
|
---|
1442 | Packet->Length,
|
---|
1443 | (EFI_PXE_BASE_CODE_PACKET *) &Packet->Dhcp6
|
---|
1444 | );
|
---|
1445 | if (Status != EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE) {
|
---|
1446 | return EFI_ABORTED;
|
---|
1447 | }
|
---|
1448 | }
|
---|
1449 |
|
---|
1450 | Status = EFI_SUCCESS;
|
---|
1451 |
|
---|
1452 | switch (Dhcp6Event) {
|
---|
1453 |
|
---|
1454 | case Dhcp6SendSolicit:
|
---|
1455 | //
|
---|
1456 | // Record the first Solicate msg time
|
---|
1457 | //
|
---|
1458 | if (Private->SolicitTimes == 0) {
|
---|
1459 | CalcElapsedTime (Private);
|
---|
1460 | Private->SolicitTimes++;
|
---|
1461 | }
|
---|
1462 | //
|
---|
1463 | // Cache the dhcp discover packet to mode data directly.
|
---|
1464 | //
|
---|
1465 | CopyMem (&Mode->DhcpDiscover.Dhcpv4, &Packet->Dhcp6, Packet->Length);
|
---|
1466 | break;
|
---|
1467 |
|
---|
1468 | case Dhcp6RcvdAdvertise:
|
---|
1469 | Status = EFI_NOT_READY;
|
---|
1470 | if (Private->OfferNum < PXEBC_OFFER_MAX_NUM) {
|
---|
1471 | //
|
---|
1472 | // Cache the dhcp offers to OfferBuffer[] for select later, and record
|
---|
1473 | // the OfferIndex and OfferCount.
|
---|
1474 | //
|
---|
1475 | PxeBcCacheDhcp6Offer (Private, Packet);
|
---|
1476 | }
|
---|
1477 | break;
|
---|
1478 |
|
---|
1479 | case Dhcp6SendRequest:
|
---|
1480 | //
|
---|
1481 | // Store the request packet as seed packet for discover.
|
---|
1482 | //
|
---|
1483 | if (Private->Dhcp6Request != NULL) {
|
---|
1484 | FreePool (Private->Dhcp6Request);
|
---|
1485 | }
|
---|
1486 | Private->Dhcp6Request = AllocateZeroPool (Packet->Size);
|
---|
1487 | if (Private->Dhcp6Request != NULL) {
|
---|
1488 | CopyMem (Private->Dhcp6Request, Packet, Packet->Size);
|
---|
1489 | }
|
---|
1490 | break;
|
---|
1491 |
|
---|
1492 | case Dhcp6SelectAdvertise:
|
---|
1493 | //
|
---|
1494 | // Select offer by the default policy or by order, and record the SelectIndex
|
---|
1495 | // and SelectProxyType.
|
---|
1496 | //
|
---|
1497 | PxeBcSelectDhcp6Offer (Private);
|
---|
1498 |
|
---|
1499 | if (Private->SelectIndex == 0) {
|
---|
1500 | Status = EFI_ABORTED;
|
---|
1501 | } else {
|
---|
1502 | ASSERT (NewPacket != NULL);
|
---|
1503 | SelectAd = &Private->OfferBuffer[Private->SelectIndex - 1].Dhcp6.Packet.Offer;
|
---|
1504 | *NewPacket = AllocateZeroPool (SelectAd->Size);
|
---|
1505 | ASSERT (*NewPacket != NULL);
|
---|
1506 | CopyMem (*NewPacket, SelectAd, SelectAd->Size);
|
---|
1507 | }
|
---|
1508 | break;
|
---|
1509 |
|
---|
1510 | case Dhcp6RcvdReply:
|
---|
1511 | //
|
---|
1512 | // Cache the dhcp ack to Private->Dhcp6Ack, but it's not the final ack in mode data
|
---|
1513 | // without verification.
|
---|
1514 | //
|
---|
1515 | ASSERT (Private->SelectIndex != 0);
|
---|
1516 | PxeBcCopyDhcp6Ack (Private, Packet, FALSE);
|
---|
1517 | break;
|
---|
1518 |
|
---|
1519 | default:
|
---|
1520 | ASSERT (0);
|
---|
1521 | }
|
---|
1522 |
|
---|
1523 | return Status;
|
---|
1524 | }
|
---|
1525 |
|
---|
1526 |
|
---|
1527 | /**
|
---|
1528 | Build and send out the request packet for the bootfile, and parse the reply.
|
---|
1529 |
|
---|
1530 | @param[in] Private The pointer to PxeBc private data.
|
---|
1531 | @param[in] Type PxeBc option boot item type.
|
---|
1532 | @param[in] Layer The pointer to option boot item layer.
|
---|
1533 | @param[in] UseBis Use BIS or not.
|
---|
1534 | @param[in] DestIp The pointer to the server address.
|
---|
1535 |
|
---|
1536 | @retval EFI_SUCCESS Successfully discovered the boot file.
|
---|
1537 | @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
|
---|
1538 | @retval EFI_NOT_FOUND Can't get the PXE reply packet.
|
---|
1539 | @retval Others Failed to discover the boot file.
|
---|
1540 |
|
---|
1541 | **/
|
---|
1542 | EFI_STATUS
|
---|
1543 | PxeBcDhcp6Discover (
|
---|
1544 | IN PXEBC_PRIVATE_DATA *Private,
|
---|
1545 | IN UINT16 Type,
|
---|
1546 | IN UINT16 *Layer,
|
---|
1547 | IN BOOLEAN UseBis,
|
---|
1548 | IN EFI_IP_ADDRESS *DestIp
|
---|
1549 | )
|
---|
1550 | {
|
---|
1551 | EFI_PXE_BASE_CODE_UDP_PORT SrcPort;
|
---|
1552 | EFI_PXE_BASE_CODE_UDP_PORT DestPort;
|
---|
1553 | EFI_PXE_BASE_CODE_MODE *Mode;
|
---|
1554 | EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
|
---|
1555 | EFI_PXE_BASE_CODE_DHCPV6_PACKET *Discover;
|
---|
1556 | UINTN DiscoverLen;
|
---|
1557 | EFI_DHCP6_PACKET *Request;
|
---|
1558 | UINTN RequestLen;
|
---|
1559 | EFI_DHCP6_PACKET *Reply;
|
---|
1560 | UINT8 *RequestOpt;
|
---|
1561 | UINT8 *DiscoverOpt;
|
---|
1562 | UINTN ReadSize;
|
---|
1563 | UINT16 OpFlags;
|
---|
1564 | UINT16 OpCode;
|
---|
1565 | UINT16 OpLen;
|
---|
1566 | UINT32 Xid;
|
---|
1567 | EFI_STATUS Status;
|
---|
1568 |
|
---|
1569 | PxeBc = &Private->PxeBc;
|
---|
1570 | Mode = PxeBc->Mode;
|
---|
1571 | Request = Private->Dhcp6Request;
|
---|
1572 | SrcPort = PXEBC_BS_DISCOVER_PORT;
|
---|
1573 | DestPort = PXEBC_BS_DISCOVER_PORT;
|
---|
1574 | OpFlags = 0;
|
---|
1575 |
|
---|
1576 | if (!UseBis && Layer != NULL) {
|
---|
1577 | *Layer &= EFI_PXE_BASE_CODE_BOOT_LAYER_MASK;
|
---|
1578 | }
|
---|
1579 |
|
---|
1580 | if (Request == NULL) {
|
---|
1581 | return EFI_DEVICE_ERROR;
|
---|
1582 | }
|
---|
1583 |
|
---|
1584 | Discover = AllocateZeroPool (sizeof (EFI_PXE_BASE_CODE_DHCPV6_PACKET));
|
---|
1585 | if (Discover == NULL) {
|
---|
1586 | return EFI_OUT_OF_RESOURCES;
|
---|
1587 | }
|
---|
1588 |
|
---|
1589 | //
|
---|
1590 | // Build the discover packet by the cached request packet before.
|
---|
1591 | //
|
---|
1592 | Xid = NET_RANDOM (NetRandomInitSeed ());
|
---|
1593 | Discover->TransactionId = HTONL (Xid);
|
---|
1594 | Discover->MessageType = Request->Dhcp6.Header.MessageType;
|
---|
1595 | RequestOpt = Request->Dhcp6.Option;
|
---|
1596 | DiscoverOpt = Discover->DhcpOptions;
|
---|
1597 | DiscoverLen = sizeof (EFI_DHCP6_HEADER);
|
---|
1598 | RequestLen = DiscoverLen;
|
---|
1599 |
|
---|
1600 | while (RequestLen < Request->Length) {
|
---|
1601 | OpCode = NTOHS (((EFI_DHCP6_PACKET_OPTION *) RequestOpt)->OpCode);
|
---|
1602 | OpLen = NTOHS (((EFI_DHCP6_PACKET_OPTION *) RequestOpt)->OpLen);
|
---|
1603 | if (OpCode != EFI_DHCP6_IA_TYPE_NA &&
|
---|
1604 | OpCode != EFI_DHCP6_IA_TYPE_TA) {
|
---|
1605 | //
|
---|
1606 | // Copy all the options except IA option.
|
---|
1607 | //
|
---|
1608 | CopyMem (DiscoverOpt, RequestOpt, OpLen + 4);
|
---|
1609 | DiscoverOpt += (OpLen + 4);
|
---|
1610 | DiscoverLen += (OpLen + 4);
|
---|
1611 | }
|
---|
1612 | RequestOpt += (OpLen + 4);
|
---|
1613 | RequestLen += (OpLen + 4);
|
---|
1614 | }
|
---|
1615 |
|
---|
1616 | Status = PxeBc->UdpWrite (
|
---|
1617 | PxeBc,
|
---|
1618 | OpFlags,
|
---|
1619 | &Private->ServerIp,
|
---|
1620 | &DestPort,
|
---|
1621 | NULL,
|
---|
1622 | &Private->StationIp,
|
---|
1623 | &SrcPort,
|
---|
1624 | NULL,
|
---|
1625 | NULL,
|
---|
1626 | &DiscoverLen,
|
---|
1627 | (VOID *) Discover
|
---|
1628 | );
|
---|
1629 | if (EFI_ERROR (Status)) {
|
---|
1630 | return Status;
|
---|
1631 | }
|
---|
1632 |
|
---|
1633 | //
|
---|
1634 | // Cache the right PXE reply packet here, set valid flag later.
|
---|
1635 | // Especially for PXE discover packet, store it into mode data here.
|
---|
1636 | //
|
---|
1637 | if (Private->IsDoDiscover) {
|
---|
1638 | CopyMem (&Mode->PxeDiscover.Dhcpv6, Discover, DiscoverLen);
|
---|
1639 | Reply = &Private->PxeReply.Dhcp6.Packet.Ack;
|
---|
1640 | } else {
|
---|
1641 | Reply = &Private->ProxyOffer.Dhcp6.Packet.Offer;
|
---|
1642 | }
|
---|
1643 | ReadSize = (UINTN) Reply->Size;
|
---|
1644 |
|
---|
1645 | //
|
---|
1646 | // Start Udp6Read instance
|
---|
1647 | //
|
---|
1648 | Status = Private->Udp6Read->Configure (Private->Udp6Read, &Private->Udp6CfgData);
|
---|
1649 | if (EFI_ERROR (Status)) {
|
---|
1650 | return Status;
|
---|
1651 | }
|
---|
1652 |
|
---|
1653 | Status = PxeBc->UdpRead (
|
---|
1654 | PxeBc,
|
---|
1655 | OpFlags,
|
---|
1656 | &Private->StationIp,
|
---|
1657 | &SrcPort,
|
---|
1658 | &Private->ServerIp,
|
---|
1659 | &DestPort,
|
---|
1660 | NULL,
|
---|
1661 | NULL,
|
---|
1662 | &ReadSize,
|
---|
1663 | (VOID *) &Reply->Dhcp6
|
---|
1664 | );
|
---|
1665 | //
|
---|
1666 | // Stop Udp6Read instance
|
---|
1667 | //
|
---|
1668 | Private->Udp6Read->Configure (Private->Udp6Read, NULL);
|
---|
1669 | if (EFI_ERROR (Status)) {
|
---|
1670 | return Status;
|
---|
1671 | }
|
---|
1672 |
|
---|
1673 | return EFI_SUCCESS;
|
---|
1674 | }
|
---|
1675 |
|
---|
1676 |
|
---|
1677 | /**
|
---|
1678 | Start the DHCPv6 S.A.R.R. process to acquire the IPv6 address and other PXE boot information.
|
---|
1679 |
|
---|
1680 | @param[in] Private The pointer to PxeBc private data.
|
---|
1681 | @param[in] Dhcp6 The pointer to the EFI_DHCP6_PROTOCOL
|
---|
1682 |
|
---|
1683 | @retval EFI_SUCCESS The S.A.R.R. process successfully finished.
|
---|
1684 | @retval Others Failed to finish the S.A.R.R. process.
|
---|
1685 |
|
---|
1686 | **/
|
---|
1687 | EFI_STATUS
|
---|
1688 | PxeBcDhcp6Sarr (
|
---|
1689 | IN PXEBC_PRIVATE_DATA *Private,
|
---|
1690 | IN EFI_DHCP6_PROTOCOL *Dhcp6
|
---|
1691 | )
|
---|
1692 | {
|
---|
1693 | EFI_PXE_BASE_CODE_MODE *PxeMode;
|
---|
1694 | EFI_DHCP6_CONFIG_DATA Config;
|
---|
1695 | EFI_DHCP6_MODE_DATA Mode;
|
---|
1696 | EFI_DHCP6_RETRANSMISSION *Retransmit;
|
---|
1697 | EFI_DHCP6_PACKET_OPTION *OptList[PXEBC_DHCP6_OPTION_MAX_NUM];
|
---|
1698 | UINT8 Buffer[PXEBC_DHCP6_OPTION_MAX_SIZE];
|
---|
1699 | UINT32 OptCount;
|
---|
1700 | EFI_STATUS Status;
|
---|
1701 |
|
---|
1702 | Status = EFI_SUCCESS;
|
---|
1703 | PxeMode = Private->PxeBc.Mode;
|
---|
1704 |
|
---|
1705 | //
|
---|
1706 | // Build option list for the request packet.
|
---|
1707 | //
|
---|
1708 | OptCount = PxeBcBuildDhcp6Options (Private, OptList, Buffer);
|
---|
1709 | ASSERT (OptCount> 0);
|
---|
1710 |
|
---|
1711 | Retransmit = AllocateZeroPool (sizeof (EFI_DHCP6_RETRANSMISSION));
|
---|
1712 | if (Retransmit == NULL) {
|
---|
1713 | return EFI_OUT_OF_RESOURCES;
|
---|
1714 | }
|
---|
1715 |
|
---|
1716 | ZeroMem (&Mode, sizeof (EFI_DHCP6_MODE_DATA));
|
---|
1717 | ZeroMem (&Config, sizeof (EFI_DHCP6_CONFIG_DATA));
|
---|
1718 |
|
---|
1719 | Config.OptionCount = OptCount;
|
---|
1720 | Config.OptionList = OptList;
|
---|
1721 | Config.Dhcp6Callback = PxeBcDhcp6CallBack;
|
---|
1722 | Config.CallbackContext = Private;
|
---|
1723 | Config.IaInfoEvent = NULL;
|
---|
1724 | Config.RapidCommit = FALSE;
|
---|
1725 | Config.ReconfigureAccept = FALSE;
|
---|
1726 | Config.IaDescriptor.IaId = 1;
|
---|
1727 | Config.IaDescriptor.Type = EFI_DHCP6_IA_TYPE_NA;
|
---|
1728 | Config.SolicitRetransmission = Retransmit;
|
---|
1729 | Retransmit->Irt = 4;
|
---|
1730 | Retransmit->Mrc = 4;
|
---|
1731 | Retransmit->Mrt = 32;
|
---|
1732 | Retransmit->Mrd = 60;
|
---|
1733 |
|
---|
1734 | //
|
---|
1735 | // Configure the DHCPv6 instance for PXE boot.
|
---|
1736 | //
|
---|
1737 | Status = Dhcp6->Configure (Dhcp6, &Config);
|
---|
1738 | if (EFI_ERROR (Status)) {
|
---|
1739 | FreePool (Retransmit);
|
---|
1740 | return Status;
|
---|
1741 | }
|
---|
1742 |
|
---|
1743 | //
|
---|
1744 | // Initialize the record fields for DHCPv6 offer in private data.
|
---|
1745 | //
|
---|
1746 | Private->IsProxyRecved = FALSE;
|
---|
1747 | Private->OfferNum = 0;
|
---|
1748 | Private->SelectIndex = 0;
|
---|
1749 | ZeroMem (Private->OfferCount, sizeof (Private->OfferCount));
|
---|
1750 | ZeroMem (Private->OfferIndex, sizeof (Private->OfferIndex));
|
---|
1751 |
|
---|
1752 |
|
---|
1753 | //
|
---|
1754 | // Start DHCPv6 S.A.R.R. process to acquire IPv6 address.
|
---|
1755 | //
|
---|
1756 | Status = Dhcp6->Start (Dhcp6);
|
---|
1757 | if (EFI_ERROR (Status)) {
|
---|
1758 | if (Status == EFI_ICMP_ERROR) {
|
---|
1759 | PxeMode->IcmpErrorReceived = TRUE;
|
---|
1760 | }
|
---|
1761 | Dhcp6->Configure (Dhcp6, NULL);
|
---|
1762 | return Status;
|
---|
1763 | }
|
---|
1764 |
|
---|
1765 | //
|
---|
1766 | // Get the acquired IPv6 address and store them.
|
---|
1767 | //
|
---|
1768 | Status = Dhcp6->GetModeData (Dhcp6, &Mode, NULL);
|
---|
1769 | if (EFI_ERROR (Status)) {
|
---|
1770 | Dhcp6->Stop (Dhcp6);
|
---|
1771 | return Status;
|
---|
1772 | }
|
---|
1773 |
|
---|
1774 | ASSERT (Mode.Ia->State == Dhcp6Bound);
|
---|
1775 | CopyMem (&Private->StationIp.v6, &Mode.Ia->IaAddress[0].IpAddress, sizeof (EFI_IPv6_ADDRESS));
|
---|
1776 | CopyMem (&PxeMode->StationIp.v6, &Private->StationIp.v6, sizeof (EFI_IPv6_ADDRESS));
|
---|
1777 |
|
---|
1778 | Status = PxeBcRegisterIp6Address (Private, &Private->StationIp.v6);
|
---|
1779 | if (EFI_ERROR (Status)) {
|
---|
1780 | Dhcp6->Stop (Dhcp6);
|
---|
1781 | return Status;
|
---|
1782 | }
|
---|
1783 |
|
---|
1784 | Status = PxeBcFlushStaionIp (Private, &Private->StationIp, NULL);
|
---|
1785 | if (EFI_ERROR (Status)) {
|
---|
1786 | PxeBcUnregisterIp6Address (Private);
|
---|
1787 | Dhcp6->Stop (Dhcp6);
|
---|
1788 | return Status;
|
---|
1789 | }
|
---|
1790 |
|
---|
1791 | //
|
---|
1792 | // Check the selected offer whether BINL retry is needed.
|
---|
1793 | //
|
---|
1794 | Status = PxeBcHandleDhcp6Offer (Private);
|
---|
1795 | if (EFI_ERROR (Status)) {
|
---|
1796 | PxeBcUnregisterIp6Address (Private);
|
---|
1797 | Dhcp6->Stop (Dhcp6);
|
---|
1798 | return Status;
|
---|
1799 | }
|
---|
1800 |
|
---|
1801 | AsciiPrint ("\n Station IP address is ");
|
---|
1802 |
|
---|
1803 | PxeBcShowIp6Addr (&Private->StationIp.v6);
|
---|
1804 |
|
---|
1805 | return EFI_SUCCESS;
|
---|
1806 | }
|
---|
1807 |
|
---|