VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c@ 77599

Last change on this file since 77599 was 58466, checked in by vboxsync, 9 years ago

EFI/Firmware: Merged in the svn:eol-style, svn:mime-type and trailing whitespace cleanup that was done after the initial UDK2014.SP1 import: svn merge /vendor/edk2/UDK2014.SP1 /vendor/edk2/current .

  • Property svn:eol-style set to native
File size: 83.7 KB
Line 
1/** @file
2 This implementation of EFI_PXE_BASE_CODE_PROTOCOL and EFI_LOAD_FILE_PROTOCOL.
3
4 Copyright (c) 2007 - 2014, 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/**
20 Enables the use of the PXE Base Code Protocol functions.
21
22 This function enables the use of the PXE Base Code Protocol functions. If the
23 Started field of the EFI_PXE_BASE_CODE_MODE structure is already TRUE, then
24 EFI_ALREADY_STARTED will be returned. If UseIpv6 is TRUE, then IPv6 formatted
25 addresses will be used in this session. If UseIpv6 is FALSE, then IPv4 formatted
26 addresses will be used in this session. If UseIpv6 is TRUE, and the Ipv6Supported
27 field of the EFI_PXE_BASE_CODE_MODE structure is FALSE, then EFI_UNSUPPORTED will
28 be returned. If there is not enough memory or other resources to start the PXE
29 Base Code Protocol, then EFI_OUT_OF_RESOURCES will be returned. Otherwise, the
30 PXE Base Code Protocol will be started.
31
32 @param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
33 @param[in] UseIpv6 Specifies the type of IP addresses that are to be
34 used during the session that is being started.
35 Set to TRUE for IPv6, and FALSE for IPv4.
36
37 @retval EFI_SUCCESS The PXE Base Code Protocol was started.
38 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
39 @retval EFI_UNSUPPORTED UseIpv6 is TRUE, but the Ipv6Supported field of the
40 EFI_PXE_BASE_CODE_MODE structure is FALSE.
41 @retval EFI_ALREADY_STARTED The PXE Base Code Protocol is already in the started state.
42 @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
43 EFI_PXE_BASE_CODE_PROTOCOL structure.
44 @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory or other resources to start the
45 PXE Base Code Protocol.
46
47**/
48EFI_STATUS
49EFIAPI
50EfiPxeBcStart (
51 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
52 IN BOOLEAN UseIpv6
53 )
54{
55 PXEBC_PRIVATE_DATA *Private;
56 EFI_PXE_BASE_CODE_MODE *Mode;
57 UINTN Index;
58 EFI_STATUS Status;
59
60 if (This == NULL) {
61 return EFI_INVALID_PARAMETER;
62 }
63
64 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
65 Mode = Private->PxeBc.Mode;
66
67 if (Mode->Started) {
68 return EFI_ALREADY_STARTED;
69 }
70
71 //
72 // Detect whether using IPv6 or not, and set it into mode data.
73 //
74 if (UseIpv6 && Mode->Ipv6Available && Mode->Ipv6Supported && Private->Ip6Nic != NULL) {
75 Mode->UsingIpv6 = TRUE;
76 } else if (!UseIpv6 && Private->Ip4Nic != NULL) {
77 Mode->UsingIpv6 = FALSE;
78 } else {
79 return EFI_UNSUPPORTED;
80 }
81
82 if (Mode->UsingIpv6) {
83 AsciiPrint ("\n>>Start PXE over IPv6");
84 //
85 // Configure udp6 instance to receive data.
86 //
87 Status = Private->Udp6Read->Configure (
88 Private->Udp6Read,
89 &Private->Udp6CfgData
90 );
91 if (EFI_ERROR (Status)) {
92 goto ON_ERROR;
93 }
94
95 //
96 // Configure block size for TFTP as a default value to handle all link layers.
97 //
98 Private->BlockSize = (UINTN) (Private->Ip6MaxPacketSize -
99 PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE);
100
101 //
102 // PXE over IPv6 starts here, initialize the fields and list header.
103 //
104 Private->Ip6Policy = PXEBC_IP6_POLICY_MAX;
105 Private->ProxyOffer.Dhcp6.Packet.Offer.Size = PXEBC_DHCP6_PACKET_MAX_SIZE;
106 Private->DhcpAck.Dhcp6.Packet.Ack.Size = PXEBC_DHCP6_PACKET_MAX_SIZE;
107 Private->PxeReply.Dhcp6.Packet.Ack.Size = PXEBC_DHCP6_PACKET_MAX_SIZE;
108
109 for (Index = 0; Index < PXEBC_OFFER_MAX_NUM; Index++) {
110 Private->OfferBuffer[Index].Dhcp6.Packet.Offer.Size = PXEBC_DHCP6_PACKET_MAX_SIZE;
111 }
112
113 //
114 // Create event and set status for token to capture ICMP6 error message.
115 //
116 Private->Icmp6Token.Status = EFI_NOT_READY;
117 Status = gBS->CreateEvent (
118 EVT_NOTIFY_SIGNAL,
119 TPL_NOTIFY,
120 PxeBcIcmp6ErrorUpdate,
121 Private,
122 &Private->Icmp6Token.Event
123 );
124 if (EFI_ERROR (Status)) {
125 goto ON_ERROR;
126 }
127 } else {
128 AsciiPrint ("\n>>Start PXE over IPv4");
129 //
130 // Configure udp4 instance to receive data.
131 //
132 Status = Private->Udp4Read->Configure (
133 Private->Udp4Read,
134 &Private->Udp4CfgData
135 );
136 if (EFI_ERROR (Status)) {
137 goto ON_ERROR;
138 }
139
140 //
141 // Configure block size for TFTP as a default value to handle all link layers.
142 //
143 Private->BlockSize = (UINTN) (Private->Ip4MaxPacketSize -
144 PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE);
145
146 //
147 // PXE over IPv4 starts here, initialize the fields.
148 //
149 Private->ProxyOffer.Dhcp4.Packet.Offer.Size = PXEBC_DHCP4_PACKET_MAX_SIZE;
150 Private->DhcpAck.Dhcp4.Packet.Ack.Size = PXEBC_DHCP4_PACKET_MAX_SIZE;
151 Private->PxeReply.Dhcp4.Packet.Ack.Size = PXEBC_DHCP4_PACKET_MAX_SIZE;
152
153 for (Index = 0; Index < PXEBC_OFFER_MAX_NUM; Index++) {
154 Private->OfferBuffer[Index].Dhcp4.Packet.Offer.Size = PXEBC_DHCP4_PACKET_MAX_SIZE;
155 }
156
157 PxeBcSeedDhcp4Packet (&Private->SeedPacket, Private->Udp4Read);
158
159 //
160 // Create the event for Arp cache update.
161 //
162 Status = gBS->CreateEvent (
163 EVT_TIMER | EVT_NOTIFY_SIGNAL,
164 TPL_CALLBACK,
165 PxeBcArpCacheUpdate,
166 Private,
167 &Private->ArpUpdateEvent
168 );
169 if (EFI_ERROR (Status)) {
170 goto ON_ERROR;
171 }
172
173 //
174 // Start a periodic timer by second to update Arp cache.
175 //
176 Status = gBS->SetTimer (
177 Private->ArpUpdateEvent,
178 TimerPeriodic,
179 TICKS_PER_SECOND
180 );
181 if (EFI_ERROR (Status)) {
182 goto ON_ERROR;
183 }
184
185 //
186 // Create event and set status for token to capture ICMP error message.
187 //
188 Private->Icmp6Token.Status = EFI_NOT_READY;
189 Status = gBS->CreateEvent (
190 EVT_NOTIFY_SIGNAL,
191 TPL_NOTIFY,
192 PxeBcIcmpErrorUpdate,
193 Private,
194 &Private->IcmpToken.Event
195 );
196 if (EFI_ERROR (Status)) {
197 goto ON_ERROR;
198 }
199 }
200
201 //
202 // If PcdTftpBlockSize is set to non-zero, override the default value.
203 //
204 if (PcdGet64 (PcdTftpBlockSize) != 0) {
205 Private->BlockSize = (UINTN) PcdGet64 (PcdTftpBlockSize);
206 }
207
208 //
209 // Create event for UdpRead/UdpWrite timeout since they are both blocking API.
210 //
211 Status = gBS->CreateEvent (
212 EVT_TIMER,
213 TPL_CALLBACK,
214 NULL,
215 NULL,
216 &Private->UdpTimeOutEvent
217 );
218 if (EFI_ERROR (Status)) {
219 goto ON_ERROR;
220 }
221
222 Private->IsAddressOk = FALSE;
223 Mode->Started = TRUE;
224
225 return EFI_SUCCESS;
226
227ON_ERROR:
228 if (Mode->UsingIpv6) {
229 if (Private->Icmp6Token.Event != NULL) {
230 gBS->CloseEvent (Private->Icmp6Token.Event);
231 Private->Icmp6Token.Event = NULL;
232 }
233 Private->Udp6Read->Configure (Private->Udp6Read, NULL);
234 Private->Ip6->Configure (Private->Ip6, NULL);
235 } else {
236 if (Private->ArpUpdateEvent != NULL) {
237 gBS->CloseEvent (Private->ArpUpdateEvent);
238 Private->ArpUpdateEvent = NULL;
239 }
240 if (Private->IcmpToken.Event != NULL) {
241 gBS->CloseEvent (Private->IcmpToken.Event);
242 Private->IcmpToken.Event = NULL;
243 }
244 Private->Udp4Read->Configure (Private->Udp4Read, NULL);
245 Private->Ip4->Configure (Private->Ip4, NULL);
246 }
247 return Status;
248}
249
250
251/**
252 Disable the use of the PXE Base Code Protocol functions.
253
254 This function stops all activity on the network device. All the resources allocated
255 in Start() are released, the Started field of the EFI_PXE_BASE_CODE_MODE structure is
256 set to FALSE, and EFI_SUCCESS is returned. If the Started field of the EFI_PXE_BASE_CODE_MODE
257 structure is already FALSE, then EFI_NOT_STARTED will be returned.
258
259 @param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
260
261 @retval EFI_SUCCESS The PXE Base Code Protocol was stopped.
262 @retval EFI_NOT_STARTED The PXE Base Code Protocol is already in the stopped state.
263 @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
264 EFI_PXE_BASE_CODE_PROTOCOL structure.
265 @retval Others
266
267**/
268EFI_STATUS
269EFIAPI
270EfiPxeBcStop (
271 IN EFI_PXE_BASE_CODE_PROTOCOL *This
272 )
273{
274 PXEBC_PRIVATE_DATA *Private;
275 EFI_PXE_BASE_CODE_MODE *Mode;
276 BOOLEAN Ipv6Supported;
277 BOOLEAN Ipv6Available;
278
279 if (This == NULL) {
280 return EFI_INVALID_PARAMETER;
281 }
282
283 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
284 Mode = Private->PxeBc.Mode;
285 Ipv6Supported = Mode->Ipv6Supported;
286 Ipv6Available = Mode->Ipv6Available;
287
288 if (!Mode->Started) {
289 return EFI_NOT_STARTED;
290 }
291
292 if (Mode->UsingIpv6) {
293 //
294 // Configure all the instances for IPv6 as NULL.
295 //
296 ZeroMem (&Private->Udp6CfgData.StationAddress, sizeof (EFI_IPv6_ADDRESS));
297 ZeroMem (&Private->Ip6CfgData.StationAddress, sizeof (EFI_IPv6_ADDRESS));
298 Private->Dhcp6->Stop (Private->Dhcp6);
299 Private->Dhcp6->Configure (Private->Dhcp6, NULL);
300 Private->Udp6Write->Configure (Private->Udp6Write, NULL);
301 Private->Udp6Read->Groups (Private->Udp6Read, FALSE, NULL);
302 Private->Udp6Read->Configure (Private->Udp6Read, NULL);
303 Private->Ip6->Cancel (Private->Ip6, &Private->Icmp6Token);
304 Private->Ip6->Configure (Private->Ip6, NULL);
305 PxeBcUnregisterIp6Address (Private);
306 if (Private->Icmp6Token.Event != NULL) {
307 gBS->CloseEvent (Private->Icmp6Token.Event);
308 Private->Icmp6Token.Event = NULL;
309 }
310 if (Private->Dhcp6Request != NULL) {
311 FreePool (Private->Dhcp6Request);
312 Private->Dhcp6Request = NULL;
313 }
314 if (Private->BootFileName != NULL) {
315 FreePool (Private->BootFileName);
316 Private->BootFileName = NULL;
317 }
318 } else {
319 //
320 // Configure all the instances for IPv4 as NULL.
321 //
322 ZeroMem (&Private->Udp4CfgData.StationAddress, sizeof (EFI_IPv4_ADDRESS));
323 ZeroMem (&Private->Udp4CfgData.SubnetMask, sizeof (EFI_IPv4_ADDRESS));
324 ZeroMem (&Private->Ip4CfgData.StationAddress, sizeof (EFI_IPv4_ADDRESS));
325 ZeroMem (&Private->Ip4CfgData.SubnetMask, sizeof (EFI_IPv4_ADDRESS));
326 Private->Dhcp4->Stop (Private->Dhcp4);
327 Private->Dhcp4->Configure (Private->Dhcp4, NULL);
328 Private->Udp4Write->Configure (Private->Udp4Write, NULL);
329 Private->Udp4Read->Groups (Private->Udp4Read, FALSE, NULL);
330 Private->Udp4Read->Configure (Private->Udp4Read, NULL);
331 Private->Ip4->Cancel (Private->Ip4, &Private->IcmpToken);
332 Private->Ip4->Configure (Private->Ip4, NULL);
333 if (Private->ArpUpdateEvent != NULL) {
334 gBS->CloseEvent (Private->ArpUpdateEvent);
335 Private->ArpUpdateEvent = NULL;
336 }
337 if (Private->IcmpToken.Event != NULL) {
338 gBS->CloseEvent (Private->IcmpToken.Event);
339 Private->IcmpToken.Event = NULL;
340 }
341 }
342
343 gBS->CloseEvent (Private->UdpTimeOutEvent);
344 Private->CurSrcPort = 0;
345 Private->BootFileSize = 0;
346 Private->SolicitTimes = 0;
347 Private->ElapsedTime = 0;
348 ZeroMem (&Private->StationIp, sizeof (EFI_IP_ADDRESS));
349 ZeroMem (&Private->SubnetMask, sizeof (EFI_IP_ADDRESS));
350 ZeroMem (&Private->GatewayIp, sizeof (EFI_IP_ADDRESS));
351 ZeroMem (&Private->ServerIp, sizeof (EFI_IP_ADDRESS));
352
353 //
354 // Reset the mode data.
355 //
356 ZeroMem (Mode, sizeof (EFI_PXE_BASE_CODE_MODE));
357 Mode->Ipv6Available = Ipv6Available;
358 Mode->Ipv6Supported = Ipv6Supported;
359 Mode->AutoArp = TRUE;
360 Mode->TTL = DEFAULT_TTL;
361 Mode->ToS = DEFAULT_ToS;
362
363 return EFI_SUCCESS;
364}
365
366
367/**
368 Attempts to complete a DHCPv4 D.O.R.A. (discover / offer / request / acknowledge) or DHCPv6
369 S.A.R.R (solicit / advertise / request / reply) sequence.
370
371 If SortOffers is TRUE, then the cached DHCP offer packets will be sorted before
372 they are tried. If SortOffers is FALSE, then the cached DHCP offer packets will
373 be tried in the order in which they are received. Please see the Preboot Execution
374 Environment (PXE) Specification and Unified Extensible Firmware Interface (UEFI)
375 Specification for additional details on the implementation of DHCP.
376 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
377 then the DHCP sequence will be stopped and EFI_ABORTED will be returned.
378
379 @param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
380 @param[in] SortOffers TRUE if the offers received should be sorted. Set to FALSE to
381 try the offers in the order that they are received.
382
383 @retval EFI_SUCCESS Valid DHCP has completed.
384 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
385 @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
386 EFI_PXE_BASE_CODE_PROTOCOL structure.
387 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
388 @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete the DHCP Protocol.
389 @retval EFI_ABORTED The callback function aborted the DHCP Protocol.
390 @retval EFI_TIMEOUT The DHCP Protocol timed out.
391 @retval EFI_ICMP_ERROR An ICMP error packet was received during the DHCP session.
392 @retval EFI_NO_RESPONSE Valid PXE offer was not received.
393
394**/
395EFI_STATUS
396EFIAPI
397EfiPxeBcDhcp (
398 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
399 IN BOOLEAN SortOffers
400 )
401{
402 PXEBC_PRIVATE_DATA *Private;
403 EFI_PXE_BASE_CODE_MODE *Mode;
404 EFI_STATUS Status;
405 EFI_PXE_BASE_CODE_IP_FILTER IpFilter;
406
407 if (This == NULL) {
408 return EFI_INVALID_PARAMETER;
409 }
410
411 Status = EFI_SUCCESS;
412 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
413 Mode = Private->PxeBc.Mode;
414 Mode->IcmpErrorReceived = FALSE;
415 Private->Function = EFI_PXE_BASE_CODE_FUNCTION_DHCP;
416 Private->IsOfferSorted = SortOffers;
417 Private->SolicitTimes = 0;
418 Private->ElapsedTime = 0;
419
420 if (!Mode->Started) {
421 return EFI_NOT_STARTED;
422 }
423
424 if (Mode->UsingIpv6) {
425
426 //
427 // Stop Udp6Read instance
428 //
429 Private->Udp6Read->Configure (Private->Udp6Read, NULL);
430
431 //
432 // Start S.A.R.R. process to get a IPv6 address and other boot information.
433 //
434 Status = PxeBcDhcp6Sarr (Private, Private->Dhcp6);
435 } else {
436
437 //
438 // Stop Udp4Read instance
439 //
440 Private->Udp4Read->Configure (Private->Udp4Read, NULL);
441
442 //
443 // Start D.O.R.A. process to get a IPv4 address and other boot information.
444 //
445 Status = PxeBcDhcp4Dora (Private, Private->Dhcp4);
446 }
447
448 //
449 // Reconfigure the UDP instance with the default configuration.
450 //
451 if (Mode->UsingIpv6) {
452 Private->Udp6Read->Configure (Private->Udp6Read, &Private->Udp6CfgData);
453 } else {
454 Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);
455 }
456 //
457 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
458 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
459 //
460 ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));
461 IpFilter.Filters = EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP;
462 This->SetIpFilter (This, &IpFilter);
463
464 return Status;
465}
466
467
468/**
469 Attempts to complete the PXE Boot Server and/or boot image discovery sequence.
470
471 This function attempts to complete the PXE Boot Server and/or boot image discovery
472 sequence. If this sequence is completed, then EFI_SUCCESS is returned, and the
473 PxeDiscoverValid, PxeDiscover, PxeReplyReceived, and PxeReply fields of the
474 EFI_PXE_BASE_CODE_MODE structure are filled in. If UseBis is TRUE, then the
475 PxeBisReplyReceived and PxeBisReply fields of the EFI_PXE_BASE_CODE_MODE structure
476 will also be filled in. If UseBis is FALSE, then PxeBisReplyValid will be set to FALSE.
477 In the structure referenced by parameter Info, the PXE Boot Server list, SrvList[],
478 has two uses: It is the Boot Server IP address list used for unicast discovery
479 (if the UseUCast field is TRUE), and it is the list used for Boot Server verification
480 (if the MustUseList field is TRUE). Also, if the MustUseList field in that structure
481 is TRUE and the AcceptAnyResponse field in the SrvList[] array is TRUE, any Boot
482 Server reply of that type will be accepted. If the AcceptAnyResponse field is
483 FALSE, only responses from Boot Servers with matching IP addresses will be accepted.
484 This function can take at least 10 seconds to timeout and return control to the
485 caller. If the Discovery sequence does not complete, then EFI_TIMEOUT will be
486 returned. Please see the Preboot Execution Environment (PXE) Specification for
487 additional details on the implementation of the Discovery sequence.
488 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
489 then the Discovery sequence is stopped and EFI_ABORTED will be returned.
490
491 @param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
492 @param[in] Type The type of bootstrap to perform.
493 @param[in] Layer Pointer to the boot server layer number to discover, which must be
494 PXE_BOOT_LAYER_INITIAL when a new server type is being
495 discovered.
496 @param[in] UseBis TRUE if Boot Integrity Services are to be used. FALSE otherwise.
497 @param[in] Info Pointer to a data structure that contains additional information
498 on the type of discovery operation that is to be performed.
499 It is optional.
500
501 @retval EFI_SUCCESS The Discovery sequence has been completed.
502 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
503 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
504 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
505 @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete Discovery.
506 @retval EFI_ABORTED The callback function aborted the Discovery sequence.
507 @retval EFI_TIMEOUT The Discovery sequence timed out.
508 @retval EFI_ICMP_ERROR An ICMP error packet was received during the PXE discovery
509 session.
510
511**/
512EFI_STATUS
513EFIAPI
514EfiPxeBcDiscover (
515 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
516 IN UINT16 Type,
517 IN UINT16 *Layer,
518 IN BOOLEAN UseBis,
519 IN EFI_PXE_BASE_CODE_DISCOVER_INFO *Info OPTIONAL
520 )
521{
522 PXEBC_PRIVATE_DATA *Private;
523 EFI_PXE_BASE_CODE_MODE *Mode;
524 EFI_PXE_BASE_CODE_DISCOVER_INFO DefaultInfo;
525 EFI_PXE_BASE_CODE_SRVLIST *SrvList;
526 PXEBC_BOOT_SVR_ENTRY *BootSvrEntry;
527 UINT16 Index;
528 EFI_STATUS Status;
529 EFI_PXE_BASE_CODE_IP_FILTER IpFilter;
530 EFI_PXE_BASE_CODE_DISCOVER_INFO *NewCreatedInfo;
531
532 if (This == NULL) {
533 return EFI_INVALID_PARAMETER;
534 }
535
536 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
537 Mode = Private->PxeBc.Mode;
538 Mode->IcmpErrorReceived = FALSE;
539 BootSvrEntry = NULL;
540 SrvList = NULL;
541 Status = EFI_DEVICE_ERROR;
542 Private->Function = EFI_PXE_BASE_CODE_FUNCTION_DISCOVER;
543 NewCreatedInfo = NULL;
544
545 if (!Mode->Started) {
546 return EFI_NOT_STARTED;
547 }
548
549 //
550 // Station address should be ready before do discover.
551 //
552 if (!Private->IsAddressOk) {
553 return EFI_INVALID_PARAMETER;
554 }
555
556 if (Mode->UsingIpv6) {
557
558 //
559 // Stop Udp6Read instance
560 //
561 Private->Udp6Read->Configure (Private->Udp6Read, NULL);
562 } else {
563
564 //
565 // Stop Udp4Read instance
566 //
567 Private->Udp4Read->Configure (Private->Udp4Read, NULL);
568 }
569
570 //
571 // There are 3 methods to get the information for discover.
572 //
573 ZeroMem (&DefaultInfo, sizeof (EFI_PXE_BASE_CODE_DISCOVER_INFO));
574 if (*Layer != EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL) {
575 //
576 // 1. Take the previous setting as the discover info.
577 //
578 if (!Mode->PxeDiscoverValid ||
579 !Mode->PxeReplyReceived ||
580 (!Mode->PxeBisReplyReceived && UseBis)) {
581 Status = EFI_INVALID_PARAMETER;
582 goto ON_EXIT;
583 }
584
585 Info = &DefaultInfo;
586 Info->IpCnt = 1;
587 Info->UseUCast = TRUE;
588 SrvList = Info->SrvList;
589 SrvList[0].Type = Type;
590 SrvList[0].AcceptAnyResponse = FALSE;
591
592 CopyMem (&SrvList->IpAddr, &Private->ServerIp, sizeof (EFI_IP_ADDRESS));
593
594 } else if (Info == NULL) {
595 //
596 // 2. Extract the discover information from the cached packets if unspecified.
597 //
598 NewCreatedInfo = &DefaultInfo;
599 Status = PxeBcExtractDiscoverInfo (Private, Type, &NewCreatedInfo, &BootSvrEntry, &SrvList);
600 if (EFI_ERROR (Status)) {
601 goto ON_EXIT;
602 }
603 ASSERT (NewCreatedInfo != NULL);
604 Info = NewCreatedInfo;
605 } else {
606 //
607 // 3. Take the pass-in information as the discover info, and validate the server list.
608 //
609 SrvList = Info->SrvList;
610
611 if (!SrvList[0].AcceptAnyResponse) {
612 for (Index = 1; Index < Info->IpCnt; Index++) {
613 if (SrvList[Index].AcceptAnyResponse) {
614 break;
615 }
616 }
617 if (Index != Info->IpCnt) {
618 //
619 // It's invalid if the first server doesn't accecpt any response
620 // but any of the other servers does accept any response.
621 //
622 Status = EFI_INVALID_PARAMETER;
623 goto ON_EXIT;
624 }
625 }
626 }
627
628 //
629 // Info and BootSvrEntry/SrvList are all ready by now, so execute discover by UniCast/BroadCast/MultiCast.
630 //
631 if ((!Info->UseUCast && !Info->UseBCast && !Info->UseMCast) ||
632 (Info->MustUseList && Info->IpCnt == 0)) {
633 Status = EFI_INVALID_PARAMETER;
634 goto ON_EXIT;
635 }
636
637 Private->IsDoDiscover = TRUE;
638
639 if (Info->UseMCast) {
640 //
641 // Do discover by multicast.
642 //
643 Status = PxeBcDiscoverBootServer (
644 Private,
645 Type,
646 Layer,
647 UseBis,
648 &Info->ServerMCastIp,
649 Info->IpCnt,
650 SrvList
651 );
652
653 } else if (Info->UseBCast) {
654 //
655 // Do discover by broadcast, but only valid for IPv4.
656 //
657 ASSERT (!Mode->UsingIpv6);
658 Status = PxeBcDiscoverBootServer (
659 Private,
660 Type,
661 Layer,
662 UseBis,
663 NULL,
664 Info->IpCnt,
665 SrvList
666 );
667
668 } else if (Info->UseUCast) {
669 //
670 // Do discover by unicast.
671 //
672 for (Index = 0; Index < Info->IpCnt; Index++) {
673 if (BootSvrEntry == NULL) {
674 CopyMem (&Private->ServerIp, &SrvList[Index].IpAddr, sizeof (EFI_IP_ADDRESS));
675 } else {
676 ASSERT (!Mode->UsingIpv6);
677 ZeroMem (&Private->ServerIp, sizeof (EFI_IP_ADDRESS));
678 CopyMem (&Private->ServerIp, &BootSvrEntry->IpAddr[Index], sizeof (EFI_IPv4_ADDRESS));
679 }
680
681 Status = PxeBcDiscoverBootServer (
682 Private,
683 Type,
684 Layer,
685 UseBis,
686 &Private->ServerIp,
687 Info->IpCnt,
688 SrvList
689 );
690 }
691 }
692
693 if (!EFI_ERROR (Status)) {
694 //
695 // Parse the cached PXE reply packet, and store it into mode data if valid.
696 //
697 if (Mode->UsingIpv6) {
698 Status = PxeBcParseDhcp6Packet (&Private->PxeReply.Dhcp6);
699 if (!EFI_ERROR (Status)) {
700 CopyMem (
701 &Mode->PxeReply.Dhcpv6,
702 &Private->PxeReply.Dhcp6.Packet.Ack.Dhcp6,
703 Private->PxeReply.Dhcp6.Packet.Ack.Length
704 );
705 Mode->PxeReplyReceived = TRUE;
706 Mode->PxeDiscoverValid = TRUE;
707 }
708 } else {
709 Status = PxeBcParseDhcp4Packet (&Private->PxeReply.Dhcp4);
710 if (!EFI_ERROR (Status)) {
711 CopyMem (
712 &Mode->PxeReply.Dhcpv4,
713 &Private->PxeReply.Dhcp4.Packet.Ack.Dhcp4,
714 Private->PxeReply.Dhcp4.Packet.Ack.Length
715 );
716 Mode->PxeReplyReceived = TRUE;
717 Mode->PxeDiscoverValid = TRUE;
718 }
719 }
720 }
721
722ON_EXIT:
723
724 if (NewCreatedInfo != NULL && NewCreatedInfo != &DefaultInfo) {
725 FreePool (NewCreatedInfo);
726 }
727
728 if (Mode->UsingIpv6) {
729 Private->Udp6Read->Configure (Private->Udp6Read, &Private->Udp6CfgData);
730 } else {
731 Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);
732 }
733
734 //
735 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
736 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
737 //
738 ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));
739 IpFilter.Filters = EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP;
740 This->SetIpFilter (This, &IpFilter);
741
742 return Status;
743}
744
745
746/**
747 Used to perform TFTP and MTFTP services.
748
749 This function is used to perform TFTP and MTFTP services. This includes the
750 TFTP operations to get the size of a file, read a directory, read a file, and
751 write a file. It also includes the MTFTP operations to get the size of a file,
752 read a directory, and read a file. The type of operation is specified by Operation.
753 If the callback function that is invoked during the TFTP/MTFTP operation does
754 not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will
755 be returned.
756 For read operations, the return data will be placed in the buffer specified by
757 BufferPtr. If BufferSize is too small to contain the entire downloaded file,
758 then EFI_BUFFER_TOO_SMALL will be returned and BufferSize will be set to zero,
759 or the size of the requested file. (NOTE: the size of the requested file is only returned
760 if the TFTP server supports TFTP options). If BufferSize is large enough for the
761 read operation, then BufferSize will be set to the size of the downloaded file,
762 and EFI_SUCCESS will be returned. Applications using the PxeBc.Mtftp() services
763 should use the get-file-size operations to determine the size of the downloaded
764 file prior to using the read-file operations-especially when downloading large
765 (greater than 64 MB) files-instead of making two calls to the read-file operation.
766 Following this recommendation will save time if the file is larger than expected
767 and the TFTP server does not support TFTP option extensions. Without TFTP option
768 extension support, the client must download the entire file, counting and discarding
769 the received packets, to determine the file size.
770 For write operations, the data to be sent is in the buffer specified by BufferPtr.
771 BufferSize specifies the number of bytes to send. If the write operation completes
772 successfully, then EFI_SUCCESS will be returned.
773 For TFTP "get file size" operations, the size of the requested file or directory
774 is returned in BufferSize, and EFI_SUCCESS will be returned. If the TFTP server
775 does not support options, the file will be downloaded into a bit bucket and the
776 length of the downloaded file will be returned. For MTFTP "get file size" operations,
777 if the MTFTP server does not support the "get file size" option, EFI_UNSUPPORTED
778 will be returned.
779 This function can take up to 10 seconds to timeout and return control to the caller.
780 If the TFTP sequence does not complete, EFI_TIMEOUT will be returned.
781 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
782 then the TFTP sequence is stopped and EFI_ABORTED will be returned.
783
784 @param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
785 @param[in] Operation The type of operation to perform.
786 @param[in, out] BufferPtr A pointer to the data buffer.
787 @param[in] Overwrite Only used on write file operations. TRUE if a file on a remote
788 server can be overwritten.
789 @param[in, out] BufferSize For get-file-size operations, *BufferSize returns the size of the
790 requested file.
791 @param[in] BlockSize The requested block size to be used during a TFTP transfer.
792 @param[in] ServerIp The TFTP / MTFTP server IP address.
793 @param[in] Filename A Null-terminated ASCII string that specifies a directory name
794 or a file name.
795 @param[in] Info Pointer to the MTFTP information.
796 @param[in] DontUseBuffer Set to FALSE for normal TFTP and MTFTP read file operation.
797
798 @retval EFI_SUCCESS The TFTP/MTFTP operation was completed.
799 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
800 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
801 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
802 @retval EFI_BUFFER_TOO_SMALL The buffer is not large enough to complete the read operation.
803 @retval EFI_ABORTED The callback function aborted the TFTP/MTFTP operation.
804 @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.
805 @retval EFI_ICMP_ERROR An ICMP error packet was received during the MTFTP session.
806 @retval EFI_TFTP_ERROR A TFTP error packet was received during the MTFTP session.
807
808**/
809EFI_STATUS
810EFIAPI
811EfiPxeBcMtftp (
812 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
813 IN EFI_PXE_BASE_CODE_TFTP_OPCODE Operation,
814 IN OUT VOID *BufferPtr OPTIONAL,
815 IN BOOLEAN Overwrite,
816 IN OUT UINT64 *BufferSize,
817 IN UINTN *BlockSize OPTIONAL,
818 IN EFI_IP_ADDRESS *ServerIp,
819 IN UINT8 *Filename,
820 IN EFI_PXE_BASE_CODE_MTFTP_INFO *Info OPTIONAL,
821 IN BOOLEAN DontUseBuffer
822 )
823{
824 PXEBC_PRIVATE_DATA *Private;
825 EFI_PXE_BASE_CODE_MODE *Mode;
826 EFI_MTFTP4_CONFIG_DATA Mtftp4Config;
827 EFI_MTFTP6_CONFIG_DATA Mtftp6Config;
828 VOID *Config;
829 EFI_STATUS Status;
830 EFI_PXE_BASE_CODE_IP_FILTER IpFilter;
831
832
833 if ((This == NULL) ||
834 (Filename == NULL) ||
835 (BufferSize == NULL) ||
836 (ServerIp == NULL) ||
837 ((BufferPtr == NULL) && DontUseBuffer) ||
838 ((BlockSize != NULL) && (*BlockSize < PXE_MTFTP_DEFAULT_BLOCK_SIZE)) ||
839 (!NetIp4IsUnicast (NTOHL (ServerIp->Addr[0]), 0) && !NetIp6IsValidUnicast (&ServerIp->v6))) {
840 return EFI_INVALID_PARAMETER;
841 }
842
843 Config = NULL;
844 Status = EFI_DEVICE_ERROR;
845 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
846 Mode = Private->PxeBc.Mode;
847
848 if (Mode->UsingIpv6) {
849 //
850 // Set configuration data for Mtftp6 instance.
851 //
852 ZeroMem (&Mtftp6Config, sizeof (EFI_MTFTP6_CONFIG_DATA));
853 Config = &Mtftp6Config;
854 Mtftp6Config.TimeoutValue = PXEBC_MTFTP_TIMEOUT;
855 Mtftp6Config.TryCount = PXEBC_MTFTP_RETRIES;
856 CopyMem (&Mtftp6Config.StationIp, &Private->StationIp.v6, sizeof (EFI_IPv6_ADDRESS));
857 CopyMem (&Mtftp6Config.ServerIp, &ServerIp->v6, sizeof (EFI_IPv6_ADDRESS));
858 //
859 // Stop Udp6Read instance
860 //
861 Private->Udp6Read->Configure (Private->Udp6Read, NULL);
862 } else {
863 //
864 // Set configuration data for Mtftp4 instance.
865 //
866 ZeroMem (&Mtftp4Config, sizeof (EFI_MTFTP4_CONFIG_DATA));
867 Config = &Mtftp4Config;
868 Mtftp4Config.UseDefaultSetting = FALSE;
869 Mtftp4Config.TimeoutValue = PXEBC_MTFTP_TIMEOUT;
870 Mtftp4Config.TryCount = PXEBC_MTFTP_RETRIES;
871 CopyMem (&Mtftp4Config.StationIp, &Private->StationIp.v4, sizeof (EFI_IPv4_ADDRESS));
872 CopyMem (&Mtftp4Config.SubnetMask, &Private->SubnetMask.v4, sizeof (EFI_IPv4_ADDRESS));
873 CopyMem (&Mtftp4Config.GatewayIp, &Private->GatewayIp.v4, sizeof (EFI_IPv4_ADDRESS));
874 CopyMem (&Mtftp4Config.ServerIp, &ServerIp->v4, sizeof (EFI_IPv4_ADDRESS));
875 //
876 // Stop Udp4Read instance
877 //
878 Private->Udp4Read->Configure (Private->Udp4Read, NULL);
879 }
880
881 Mode->TftpErrorReceived = FALSE;
882 Mode->IcmpErrorReceived = FALSE;
883
884 switch (Operation) {
885
886 case EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE:
887 //
888 // Send TFTP request to get file size.
889 //
890 Status = PxeBcTftpGetFileSize (
891 Private,
892 Config,
893 Filename,
894 BlockSize,
895 BufferSize
896 );
897
898 break;
899
900 case EFI_PXE_BASE_CODE_TFTP_READ_FILE:
901 //
902 // Send TFTP request to read file.
903 //
904 Status = PxeBcTftpReadFile (
905 Private,
906 Config,
907 Filename,
908 BlockSize,
909 BufferPtr,
910 BufferSize,
911 DontUseBuffer
912 );
913
914 break;
915
916 case EFI_PXE_BASE_CODE_TFTP_WRITE_FILE:
917 //
918 // Send TFTP request to write file.
919 //
920 Status = PxeBcTftpWriteFile (
921 Private,
922 Config,
923 Filename,
924 Overwrite,
925 BlockSize,
926 BufferPtr,
927 BufferSize
928 );
929
930 break;
931
932 case EFI_PXE_BASE_CODE_TFTP_READ_DIRECTORY:
933 //
934 // Send TFTP request to read directory.
935 //
936 Status = PxeBcTftpReadDirectory (
937 Private,
938 Config,
939 Filename,
940 BlockSize,
941 BufferPtr,
942 BufferSize,
943 DontUseBuffer
944 );
945
946 break;
947
948 case EFI_PXE_BASE_CODE_MTFTP_GET_FILE_SIZE:
949 case EFI_PXE_BASE_CODE_MTFTP_READ_FILE:
950 case EFI_PXE_BASE_CODE_MTFTP_READ_DIRECTORY:
951 Status = EFI_UNSUPPORTED;
952
953 break;
954
955 default:
956 Status = EFI_INVALID_PARAMETER;
957
958 break;
959 }
960
961 if (Status == EFI_ICMP_ERROR) {
962 Mode->IcmpErrorReceived = TRUE;
963 }
964
965 //
966 // Reconfigure the UDP instance with the default configuration.
967 //
968 if (Mode->UsingIpv6) {
969 Private->Udp6Read->Configure (Private->Udp6Read, &Private->Udp6CfgData);
970 } else {
971 Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);
972 }
973 //
974 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
975 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
976 //
977 ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));
978 IpFilter.Filters = EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP;
979 This->SetIpFilter (This, &IpFilter);
980
981 return Status;
982}
983
984
985/**
986 Writes a UDP packet to the network interface.
987
988 This function writes a UDP packet specified by the (optional HeaderPtr and)
989 BufferPtr parameters to the network interface. The UDP header is automatically
990 built by this routine. It uses the parameters OpFlags, DestIp, DestPort, GatewayIp,
991 SrcIp, and SrcPort to build this header. If the packet is successfully built and
992 transmitted through the network interface, then EFI_SUCCESS will be returned.
993 If a timeout occurs during the transmission of the packet, then EFI_TIMEOUT will
994 be returned. If an ICMP error occurs during the transmission of the packet, then
995 the IcmpErrorReceived field is set to TRUE, the IcmpError field is filled in and
996 EFI_ICMP_ERROR will be returned. If the Callback Protocol does not return
997 EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will be returned.
998
999 @param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1000 @param[in] OpFlags The UDP operation flags.
1001 @param[in] DestIp The destination IP address.
1002 @param[in] DestPort The destination UDP port number.
1003 @param[in] GatewayIp The gateway IP address.
1004 @param[in] SrcIp The source IP address.
1005 @param[in, out] SrcPort The source UDP port number.
1006 @param[in] HeaderSize An optional field which may be set to the length of a header
1007 at HeaderPtr to be prefixed to the data at BufferPtr.
1008 @param[in] HeaderPtr If HeaderSize is not NULL, a pointer to a header to be
1009 prefixed to the data at BufferPtr.
1010 @param[in] BufferSize A pointer to the size of the data at BufferPtr.
1011 @param[in] BufferPtr A pointer to the data to be written.
1012
1013 @retval EFI_SUCCESS The UDP Write operation completed.
1014 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1015 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1016 @retval EFI_BAD_BUFFER_SIZE The buffer is too long to be transmitted.
1017 @retval EFI_ABORTED The callback function aborted the UDP Write operation.
1018 @retval EFI_TIMEOUT The UDP Write operation timed out.
1019 @retval EFI_ICMP_ERROR An ICMP error packet was received during the UDP write session.
1020
1021**/
1022EFI_STATUS
1023EFIAPI
1024EfiPxeBcUdpWrite (
1025 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
1026 IN UINT16 OpFlags,
1027 IN EFI_IP_ADDRESS *DestIp,
1028 IN EFI_PXE_BASE_CODE_UDP_PORT *DestPort,
1029 IN EFI_IP_ADDRESS *GatewayIp OPTIONAL,
1030 IN EFI_IP_ADDRESS *SrcIp OPTIONAL,
1031 IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,
1032 IN UINTN *HeaderSize OPTIONAL,
1033 IN VOID *HeaderPtr OPTIONAL,
1034 IN UINTN *BufferSize,
1035 IN VOID *BufferPtr
1036 )
1037{
1038 PXEBC_PRIVATE_DATA *Private;
1039 EFI_PXE_BASE_CODE_MODE *Mode;
1040 EFI_UDP4_SESSION_DATA Udp4Session;
1041 EFI_UDP6_SESSION_DATA Udp6Session;
1042 EFI_STATUS Status;
1043 BOOLEAN DoNotFragment;
1044
1045 if (This == NULL || DestIp == NULL || DestPort == NULL) {
1046 return EFI_INVALID_PARAMETER;
1047 }
1048
1049 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
1050 Mode = Private->PxeBc.Mode;
1051
1052 if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_MAY_FRAGMENT) != 0) {
1053 DoNotFragment = FALSE;
1054 } else {
1055 DoNotFragment = TRUE;
1056 }
1057
1058 if (!Mode->UsingIpv6 && GatewayIp != NULL && !NetIp4IsUnicast (NTOHL (GatewayIp->Addr[0]), 0)) {
1059 //
1060 // Gateway is provided but it's not a unicast IPv4 address, while it will be ignored for IPv6.
1061 //
1062 return EFI_INVALID_PARAMETER;
1063 }
1064
1065 if (HeaderSize != NULL && (*HeaderSize == 0 || HeaderPtr == NULL)) {
1066 return EFI_INVALID_PARAMETER;
1067 }
1068
1069 if (BufferSize == NULL || (*BufferSize != 0 && BufferPtr == NULL)) {
1070 return EFI_INVALID_PARAMETER;
1071 }
1072
1073 if (!Mode->Started) {
1074 return EFI_NOT_STARTED;
1075 }
1076
1077 if (!Private->IsAddressOk && SrcIp == NULL) {
1078 return EFI_INVALID_PARAMETER;
1079 }
1080
1081 if (Private->CurSrcPort == 0 ||
1082 (SrcPort != NULL && *SrcPort != Private->CurSrcPort)) {
1083 //
1084 // Reconfigure UDPv4/UDPv6 for UdpWrite if the source port changed.
1085 //
1086 if (SrcPort != NULL) {
1087 Private->CurSrcPort = *SrcPort;
1088 }
1089 }
1090
1091 if (Mode->UsingIpv6) {
1092 Status = PxeBcConfigUdp6Write (
1093 Private->Udp6Write,
1094 &Private->StationIp.v6,
1095 &Private->CurSrcPort
1096 );
1097 } else {
1098 //
1099 // Configure the UDPv4 instance with gateway information from DHCP server as default.
1100 //
1101 Status = PxeBcConfigUdp4Write (
1102 Private->Udp4Write,
1103 &Private->StationIp.v4,
1104 &Private->SubnetMask.v4,
1105 &Private->GatewayIp.v4,
1106 &Private->CurSrcPort,
1107 DoNotFragment
1108 );
1109 }
1110
1111 if (EFI_ERROR (Status)) {
1112 Private->CurSrcPort = 0;
1113 return EFI_INVALID_PARAMETER;
1114 } else if (SrcPort != NULL) {
1115 *SrcPort = Private->CurSrcPort;
1116 }
1117
1118 //
1119 // Start a timer as timeout event for this blocking API.
1120 //
1121 gBS->SetTimer (Private->UdpTimeOutEvent, TimerRelative, PXEBC_UDP_TIMEOUT);
1122
1123 if (Mode->UsingIpv6) {
1124 //
1125 // Construct UDPv6 session data.
1126 //
1127 ZeroMem (&Udp6Session, sizeof (EFI_UDP6_SESSION_DATA));
1128 CopyMem (&Udp6Session.DestinationAddress, DestIp, sizeof (EFI_IPv6_ADDRESS));
1129 Udp6Session.DestinationPort = *DestPort;
1130 if (SrcIp != NULL) {
1131 CopyMem (&Udp6Session.SourceAddress, SrcIp, sizeof (EFI_IPv6_ADDRESS));
1132 }
1133 if (SrcPort != NULL) {
1134 Udp6Session.SourcePort = *SrcPort;
1135 }
1136
1137 Status = PxeBcUdp6Write (
1138 Private->Udp6Write,
1139 &Udp6Session,
1140 Private->UdpTimeOutEvent,
1141 HeaderSize,
1142 HeaderPtr,
1143 BufferSize,
1144 BufferPtr
1145 );
1146 } else {
1147 //
1148 // Construct UDPv4 session data.
1149 //
1150 ZeroMem (&Udp4Session, sizeof (EFI_UDP4_SESSION_DATA));
1151 CopyMem (&Udp4Session.DestinationAddress, DestIp, sizeof (EFI_IPv4_ADDRESS));
1152 Udp4Session.DestinationPort = *DestPort;
1153 if (SrcIp != NULL) {
1154 CopyMem (&Udp4Session.SourceAddress, SrcIp, sizeof (EFI_IPv4_ADDRESS));
1155 }
1156 if (SrcPort != NULL) {
1157 Udp4Session.SourcePort = *SrcPort;
1158 }
1159 //
1160 // Override the gateway information if user specified.
1161 //
1162 Status = PxeBcUdp4Write (
1163 Private->Udp4Write,
1164 &Udp4Session,
1165 Private->UdpTimeOutEvent,
1166 (EFI_IPv4_ADDRESS *) GatewayIp,
1167 HeaderSize,
1168 HeaderPtr,
1169 BufferSize,
1170 BufferPtr
1171 );
1172 }
1173
1174 gBS->SetTimer (Private->UdpTimeOutEvent, TimerCancel, 0);
1175
1176
1177 //
1178 // Reset the UdpWrite instance.
1179 //
1180 if (Mode->UsingIpv6) {
1181 Private->Udp6Write->Configure (Private->Udp6Write, NULL);
1182 } else {
1183 Private->Udp4Write->Configure (Private->Udp4Write, NULL);
1184 }
1185
1186 return Status;
1187}
1188
1189
1190/**
1191 Reads a UDP packet from the network interface.
1192+
1193 This function reads a UDP packet from a network interface. The data contents
1194 are returned in (the optional HeaderPtr and) BufferPtr, and the size of the
1195 buffer received is returned in BufferSize . If the input BufferSize is smaller
1196 than the UDP packet received (less optional HeaderSize), it will be set to the
1197 required size, and EFI_BUFFER_TOO_SMALL will be returned. In this case, the
1198 contents of BufferPtr are undefined, and the packet is lost. If a UDP packet is
1199 successfully received, then EFI_SUCCESS will be returned, and the information
1200 from the UDP header will be returned in DestIp, DestPort, SrcIp, and SrcPort if
1201 they are not NULL. Depending on the values of OpFlags and the DestIp, DestPort,
1202 SrcIp, and SrcPort input values, different types of UDP packet receive filtering
1203 will be performed. The following tables summarize these receive filter operations.
1204
1205 @param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1206 @param[in] OpFlags The UDP operation flags.
1207 @param[in, out] DestIp The destination IP address.
1208 @param[in, out] DestPort The destination UDP port number.
1209 @param[in, out] SrcIp The source IP address.
1210 @param[in, out] SrcPort The source UDP port number.
1211 @param[in] HeaderSize An optional field which may be set to the length of a
1212 header at HeaderPtr to be prefixed to the data at BufferPtr.
1213 @param[in] HeaderPtr If HeaderSize is not NULL, a pointer to a header to be
1214 prefixed to the data at BufferPtr.
1215 @param[in, out] BufferSize A pointer to the size of the data at BufferPtr.
1216 @param[in] BufferPtr A pointer to the data to be read.
1217
1218 @retval EFI_SUCCESS The UDP Read operation was completed.
1219 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1220 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1221 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1222 @retval EFI_BUFFER_TOO_SMALL The packet is larger than Buffer can hold.
1223 @retval EFI_ABORTED The callback function aborted the UDP Read operation.
1224 @retval EFI_TIMEOUT The UDP Read operation timed out.
1225
1226**/
1227EFI_STATUS
1228EFIAPI
1229EfiPxeBcUdpRead (
1230 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
1231 IN UINT16 OpFlags,
1232 IN OUT EFI_IP_ADDRESS *DestIp OPTIONAL,
1233 IN OUT EFI_PXE_BASE_CODE_UDP_PORT *DestPort OPTIONAL,
1234 IN OUT EFI_IP_ADDRESS *SrcIp OPTIONAL,
1235 IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,
1236 IN UINTN *HeaderSize OPTIONAL,
1237 IN VOID *HeaderPtr OPTIONAL,
1238 IN OUT UINTN *BufferSize,
1239 IN VOID *BufferPtr
1240 )
1241{
1242 PXEBC_PRIVATE_DATA *Private;
1243 EFI_PXE_BASE_CODE_MODE *Mode;
1244 EFI_UDP4_COMPLETION_TOKEN Udp4Token;
1245 EFI_UDP6_COMPLETION_TOKEN Udp6Token;
1246 EFI_UDP4_RECEIVE_DATA *Udp4Rx;
1247 EFI_UDP6_RECEIVE_DATA *Udp6Rx;
1248 EFI_STATUS Status;
1249 BOOLEAN IsDone;
1250 BOOLEAN IsMatched;
1251 UINTN CopiedLen;
1252 UINTN HeaderLen;
1253 UINTN HeaderCopiedLen;
1254 UINTN BufferCopiedLen;
1255 UINT32 FragmentLength;
1256 UINTN FragmentIndex;
1257 UINT8 *FragmentBuffer;
1258
1259 if (This == NULL || DestIp == NULL || DestPort == NULL) {
1260 return EFI_INVALID_PARAMETER;
1261 }
1262
1263 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
1264 Mode = Private->PxeBc.Mode;
1265 IsDone = FALSE;
1266 IsMatched = FALSE;
1267 Udp4Rx = NULL;
1268 Udp6Rx = NULL;
1269
1270 if (((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) != 0 && DestPort == NULL) ||
1271 ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP) != 0 && SrcIp == NULL) ||
1272 ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) != 0 && SrcPort == NULL)) {
1273 return EFI_INVALID_PARAMETER;
1274 }
1275
1276 if ((HeaderSize != NULL && *HeaderSize == 0) || (HeaderSize != NULL && HeaderPtr == NULL)) {
1277 return EFI_INVALID_PARAMETER;
1278 }
1279
1280 if ((BufferSize == NULL) || (BufferPtr == NULL)) {
1281 return EFI_INVALID_PARAMETER;
1282 }
1283
1284 if (!Mode->Started) {
1285 return EFI_NOT_STARTED;
1286 }
1287
1288 ZeroMem (&Udp6Token, sizeof (EFI_UDP6_COMPLETION_TOKEN));
1289 ZeroMem (&Udp4Token, sizeof (EFI_UDP4_COMPLETION_TOKEN));
1290
1291 if (Mode->UsingIpv6) {
1292 Status = gBS->CreateEvent (
1293 EVT_NOTIFY_SIGNAL,
1294 TPL_NOTIFY,
1295 PxeBcCommonNotify,
1296 &IsDone,
1297 &Udp6Token.Event
1298 );
1299 if (EFI_ERROR (Status)) {
1300 return EFI_OUT_OF_RESOURCES;
1301 }
1302 } else {
1303 Status = gBS->CreateEvent (
1304 EVT_NOTIFY_SIGNAL,
1305 TPL_NOTIFY,
1306 PxeBcCommonNotify,
1307 &IsDone,
1308 &Udp4Token.Event
1309 );
1310 if (EFI_ERROR (Status)) {
1311 return EFI_OUT_OF_RESOURCES;
1312 }
1313 }
1314
1315 //
1316 // Start a timer as timeout event for this blocking API.
1317 //
1318 gBS->SetTimer (Private->UdpTimeOutEvent, TimerRelative, PXEBC_UDP_TIMEOUT);
1319 Mode->IcmpErrorReceived = FALSE;
1320
1321 //
1322 // Read packet by Udp4Read/Udp6Read until matched or timeout.
1323 //
1324 while (!IsMatched && !EFI_ERROR (Status)) {
1325 if (Mode->UsingIpv6) {
1326 Status = PxeBcUdp6Read (
1327 Private->Udp6Read,
1328 &Udp6Token,
1329 Mode,
1330 Private->UdpTimeOutEvent,
1331 OpFlags,
1332 &IsDone,
1333 &IsMatched,
1334 DestIp,
1335 DestPort,
1336 SrcIp,
1337 SrcPort
1338 );
1339 } else {
1340 Status = PxeBcUdp4Read (
1341 Private->Udp4Read,
1342 &Udp4Token,
1343 Mode,
1344 Private->UdpTimeOutEvent,
1345 OpFlags,
1346 &IsDone,
1347 &IsMatched,
1348 DestIp,
1349 DestPort,
1350 SrcIp,
1351 SrcPort
1352 );
1353 }
1354 }
1355
1356 if (Status == EFI_ICMP_ERROR ||
1357 Status == EFI_NETWORK_UNREACHABLE ||
1358 Status == EFI_HOST_UNREACHABLE ||
1359 Status == EFI_PROTOCOL_UNREACHABLE ||
1360 Status == EFI_PORT_UNREACHABLE) {
1361 //
1362 // Get different return status for icmp error from Udp, refers to UEFI spec.
1363 //
1364 Mode->IcmpErrorReceived = TRUE;
1365 }
1366 gBS->SetTimer (Private->UdpTimeOutEvent, TimerCancel, 0);
1367
1368 if (IsMatched) {
1369 //
1370 // Copy the rececived packet to user if matched by filter.
1371 //
1372 if (Mode->UsingIpv6) {
1373 Udp6Rx = Udp6Token.Packet.RxData;
1374 ASSERT (Udp6Rx != NULL);
1375
1376 HeaderLen = 0;
1377 if (HeaderSize != NULL) {
1378 HeaderLen = MIN (*HeaderSize, Udp6Rx->DataLength);
1379 }
1380
1381 if (Udp6Rx->DataLength - HeaderLen > *BufferSize) {
1382 Status = EFI_BUFFER_TOO_SMALL;
1383 } else {
1384 if (HeaderSize != NULL) {
1385 *HeaderSize = HeaderLen;
1386 }
1387 *BufferSize = Udp6Rx->DataLength - HeaderLen;
1388
1389 HeaderCopiedLen = 0;
1390 BufferCopiedLen = 0;
1391 for (FragmentIndex = 0; FragmentIndex < Udp6Rx->FragmentCount; FragmentIndex++) {
1392 FragmentLength = Udp6Rx->FragmentTable[FragmentIndex].FragmentLength;
1393 FragmentBuffer = Udp6Rx->FragmentTable[FragmentIndex].FragmentBuffer;
1394 if (HeaderCopiedLen + FragmentLength < HeaderLen) {
1395 //
1396 // Copy the header part of received data.
1397 //
1398 CopyMem ((UINT8 *) HeaderPtr + HeaderCopiedLen, FragmentBuffer, FragmentLength);
1399 HeaderCopiedLen += FragmentLength;
1400 } else if (HeaderCopiedLen < HeaderLen) {
1401 //
1402 // Copy the header part of received data.
1403 //
1404 CopiedLen = HeaderLen - HeaderCopiedLen;
1405 CopyMem ((UINT8 *) HeaderPtr + HeaderCopiedLen, FragmentBuffer, CopiedLen);
1406 HeaderCopiedLen += CopiedLen;
1407
1408 //
1409 // Copy the other part of received data.
1410 //
1411 CopyMem ((UINT8 *) BufferPtr + BufferCopiedLen, FragmentBuffer + CopiedLen, FragmentLength - CopiedLen);
1412 BufferCopiedLen += (FragmentLength - CopiedLen);
1413 } else {
1414 //
1415 // Copy the other part of received data.
1416 //
1417 CopyMem ((UINT8 *) BufferPtr + BufferCopiedLen, FragmentBuffer, FragmentLength);
1418 BufferCopiedLen += FragmentLength;
1419 }
1420 }
1421 }
1422 //
1423 // Recycle the receiving buffer after copy to user.
1424 //
1425 gBS->SignalEvent (Udp6Rx->RecycleSignal);
1426 } else {
1427 Udp4Rx = Udp4Token.Packet.RxData;
1428 ASSERT (Udp4Rx != NULL);
1429
1430 HeaderLen = 0;
1431 if (HeaderSize != NULL) {
1432 HeaderLen = MIN (*HeaderSize, Udp4Rx->DataLength);
1433 }
1434
1435 if (Udp4Rx->DataLength - HeaderLen > *BufferSize) {
1436 Status = EFI_BUFFER_TOO_SMALL;
1437 } else {
1438 if (HeaderSize != NULL) {
1439 *HeaderSize = HeaderLen;
1440 }
1441 *BufferSize = Udp4Rx->DataLength - HeaderLen;
1442
1443 HeaderCopiedLen = 0;
1444 BufferCopiedLen = 0;
1445 for (FragmentIndex = 0; FragmentIndex < Udp4Rx->FragmentCount; FragmentIndex++) {
1446 FragmentLength = Udp4Rx->FragmentTable[FragmentIndex].FragmentLength;
1447 FragmentBuffer = Udp4Rx->FragmentTable[FragmentIndex].FragmentBuffer;
1448 if (HeaderCopiedLen + FragmentLength < HeaderLen) {
1449 //
1450 // Copy the header part of received data.
1451 //
1452 CopyMem ((UINT8 *) HeaderPtr + HeaderCopiedLen, FragmentBuffer, FragmentLength);
1453 HeaderCopiedLen += FragmentLength;
1454 } else if (HeaderCopiedLen < HeaderLen) {
1455 //
1456 // Copy the header part of received data.
1457 //
1458 CopiedLen = HeaderLen - HeaderCopiedLen;
1459 CopyMem ((UINT8 *) HeaderPtr + HeaderCopiedLen, FragmentBuffer, CopiedLen);
1460 HeaderCopiedLen += CopiedLen;
1461
1462 //
1463 // Copy the other part of received data.
1464 //
1465 CopyMem ((UINT8 *) BufferPtr + BufferCopiedLen, FragmentBuffer + CopiedLen, FragmentLength - CopiedLen);
1466 BufferCopiedLen += (FragmentLength - CopiedLen);
1467 } else {
1468 //
1469 // Copy the other part of received data.
1470 //
1471 CopyMem ((UINT8 *) BufferPtr + BufferCopiedLen, FragmentBuffer, FragmentLength);
1472 BufferCopiedLen += FragmentLength;
1473 }
1474 }
1475 }
1476 //
1477 // Recycle the receiving buffer after copy to user.
1478 //
1479 gBS->SignalEvent (Udp4Rx->RecycleSignal);
1480 }
1481 }
1482
1483 if (Mode->UsingIpv6) {
1484 Private->Udp6Read->Cancel (Private->Udp6Read, &Udp6Token);
1485 gBS->CloseEvent (Udp6Token.Event);
1486 } else {
1487 Private->Udp4Read->Cancel (Private->Udp4Read, &Udp4Token);
1488 gBS->CloseEvent (Udp4Token.Event);
1489 }
1490
1491 return Status;
1492}
1493
1494
1495/**
1496 Updates the IP receive filters of a network device and enables software filtering.
1497
1498 The NewFilter field is used to modify the network device's current IP receive
1499 filter settings and to enable a software filter. This function updates the IpFilter
1500 field of the EFI_PXE_BASE_CODE_MODE structure with the contents of NewIpFilter.
1501 The software filter is used when the USE_FILTER in OpFlags is set to UdpRead().
1502 The current hardware filter remains in effect no matter what the settings of OpFlags.
1503 This is so that the meaning of ANY_DEST_IP set in OpFlags to UdpRead() is from those
1504 packets whose reception is enabled in hardware-physical NIC address (unicast),
1505 broadcast address, logical address or addresses (multicast), or all (promiscuous).
1506 UdpRead() does not modify the IP filter settings.
1507 Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP receive
1508 filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
1509 If an application or driver wishes to preserve the IP receive filter settings,
1510 it will have to preserve the IP receive filter settings before these calls, and
1511 use SetIpFilter() to restore them after the calls. If incompatible filtering is
1512 requested (for example, PROMISCUOUS with anything else), or if the device does not
1513 support a requested filter setting and it cannot be accommodated in software
1514 (for example, PROMISCUOUS not supported), EFI_INVALID_PARAMETER will be returned.
1515 The IPlist field is used to enable IPs other than the StationIP. They may be
1516 multicast or unicast. If IPcnt is set as well as EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP,
1517 then both the StationIP and the IPs from the IPlist will be used.
1518
1519 @param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1520 @param[in] NewFilter Pointer to the new set of IP receive filters.
1521
1522 @retval EFI_SUCCESS The IP receive filter settings were updated.
1523 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1524 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1525
1526**/
1527EFI_STATUS
1528EFIAPI
1529EfiPxeBcSetIpFilter (
1530 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
1531 IN EFI_PXE_BASE_CODE_IP_FILTER *NewFilter
1532 )
1533{
1534 EFI_STATUS Status;
1535 PXEBC_PRIVATE_DATA *Private;
1536 EFI_PXE_BASE_CODE_MODE *Mode;
1537 EFI_UDP4_CONFIG_DATA *Udp4Cfg;
1538 EFI_UDP6_CONFIG_DATA *Udp6Cfg;
1539 UINTN Index;
1540 BOOLEAN NeedPromiscuous;
1541 BOOLEAN AcceptPromiscuous;
1542 BOOLEAN AcceptBroadcast;
1543 BOOLEAN MultiCastUpdate;
1544
1545 if (This == NULL || NewFilter == NULL) {
1546 return EFI_INVALID_PARAMETER;
1547 }
1548
1549 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
1550 Mode = Private->PxeBc.Mode;
1551 Status = EFI_SUCCESS;
1552 NeedPromiscuous = FALSE;
1553
1554 if (!Mode->Started) {
1555 return EFI_NOT_STARTED;
1556 }
1557
1558 for (Index = 0; Index < NewFilter->IpCnt; Index++) {
1559 ASSERT (Index < EFI_PXE_BASE_CODE_MAX_IPCNT);
1560 if (!Mode->UsingIpv6 &&
1561 IP4_IS_LOCAL_BROADCAST (EFI_IP4 (NewFilter->IpList[Index].v4))) {
1562 //
1563 // IPv4 broadcast address should not be in IP filter.
1564 //
1565 return EFI_INVALID_PARAMETER;
1566 }
1567 if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0 &&
1568 (NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), 0) ||
1569 NetIp6IsValidUnicast (&NewFilter->IpList[Index].v6))) {
1570 //
1571 // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IPv4/IPv6 address
1572 // is in IpList, promiscuous mode is needed.
1573 //
1574 NeedPromiscuous = TRUE;
1575 }
1576 }
1577
1578 AcceptPromiscuous = FALSE;
1579 AcceptBroadcast = FALSE;
1580 MultiCastUpdate = FALSE;
1581
1582 if (NeedPromiscuous ||
1583 (NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS) != 0 ||
1584 (NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST) != 0) {
1585 //
1586 // Configure UDPv4/UDPv6 as promiscuous mode to receive all packets.
1587 //
1588 AcceptPromiscuous = TRUE;
1589 } else if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST) != 0) {
1590 //
1591 // Configure UDPv4 to receive all broadcast packets.
1592 //
1593 AcceptBroadcast = TRUE;
1594 }
1595
1596 //
1597 // In multicast condition when Promiscuous FALSE and IpCnt no-zero.
1598 // Here check if there is any update of the multicast ip address. If yes,
1599 // we need leave the old multicast group (by Config UDP instance to NULL),
1600 // and join the new multicast group.
1601 //
1602 if (!AcceptPromiscuous) {
1603 if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0) {
1604 if (Mode->IpFilter.IpCnt != NewFilter->IpCnt) {
1605 MultiCastUpdate = TRUE;
1606 } else if (CompareMem (Mode->IpFilter.IpList, NewFilter->IpList, NewFilter->IpCnt * sizeof (EFI_IP_ADDRESS)) != 0 ) {
1607 MultiCastUpdate = TRUE;
1608 }
1609 }
1610 }
1611
1612 if (!Mode->UsingIpv6) {
1613 //
1614 // Check whether we need reconfigure the UDP4 instance.
1615 //
1616 Udp4Cfg = &Private->Udp4CfgData;
1617 if ((AcceptPromiscuous != Udp4Cfg->AcceptPromiscuous) ||
1618 (AcceptBroadcast != Udp4Cfg->AcceptBroadcast) || MultiCastUpdate) {
1619 //
1620 // Clear the UDP4 instance configuration, all joined groups will be left
1621 // during the operation.
1622 //
1623 Private->Udp4Read->Configure (Private->Udp4Read, NULL);
1624
1625 //
1626 // Configure the UDP instance with the new configuration.
1627 //
1628 Udp4Cfg->AcceptPromiscuous = AcceptPromiscuous;
1629 Udp4Cfg->AcceptBroadcast = AcceptBroadcast;
1630 Status = Private->Udp4Read->Configure (Private->Udp4Read, Udp4Cfg);
1631 if (EFI_ERROR (Status)) {
1632 return Status;
1633 }
1634
1635 //
1636 // In not Promiscuous mode, need to join the new multicast group.
1637 //
1638 if (!AcceptPromiscuous) {
1639 for (Index = 0; Index < NewFilter->IpCnt; ++Index) {
1640 if (IP4_IS_MULTICAST (EFI_NTOHL (NewFilter->IpList[Index].v4))) {
1641 //
1642 // Join the mutilcast group.
1643 //
1644 Status = Private->Udp4Read->Groups (Private->Udp4Read, TRUE, &NewFilter->IpList[Index].v4);
1645 if (EFI_ERROR (Status)) {
1646 return Status;
1647 }
1648 }
1649 }
1650 }
1651 }
1652 } else {
1653 //
1654 // Check whether we need reconfigure the UDP6 instance.
1655 //
1656 Udp6Cfg = &Private->Udp6CfgData;
1657 if ((AcceptPromiscuous != Udp6Cfg->AcceptPromiscuous) || MultiCastUpdate) {
1658 //
1659 // Clear the UDP6 instance configuration, all joined groups will be left
1660 // during the operation.
1661 //
1662 Private->Udp6Read->Configure (Private->Udp6Read, NULL);
1663
1664 //
1665 // Configure the UDP instance with the new configuration.
1666 //
1667 Udp6Cfg->AcceptPromiscuous = AcceptPromiscuous;
1668 Status = Private->Udp6Read->Configure (Private->Udp6Read, Udp6Cfg);
1669 if (EFI_ERROR (Status)) {
1670 return Status;
1671 }
1672
1673 //
1674 // In not Promiscuous mode, need to join the new multicast group.
1675 //
1676 if (!AcceptPromiscuous) {
1677 for (Index = 0; Index < NewFilter->IpCnt; ++Index) {
1678 if (IP6_IS_MULTICAST (&NewFilter->IpList[Index].v6)) {
1679 //
1680 // Join the mutilcast group.
1681 //
1682 Status = Private->Udp6Read->Groups (Private->Udp6Read, TRUE, &NewFilter->IpList[Index].v6);
1683 if (EFI_ERROR (Status)) {
1684 return Status;
1685 }
1686 }
1687 }
1688 }
1689 }
1690 }
1691
1692 //
1693 // Save the new IP filter into mode data.
1694 //
1695 CopyMem (&Mode->IpFilter, NewFilter, sizeof (Mode->IpFilter));
1696
1697 return Status;
1698}
1699
1700
1701/**
1702 Uses the ARP protocol to resolve a MAC address. It is not supported for IPv6.
1703
1704 This function uses the ARP protocol to resolve a MAC address. The IP address specified
1705 by IpAddr is used to resolve a MAC address. If the ARP protocol succeeds in resolving
1706 the specified address, then the ArpCacheEntries and ArpCache fields of the mode data
1707 are updated, and EFI_SUCCESS is returned. If MacAddr is not NULL, the resolved
1708 MAC address is placed there as well. If the PXE Base Code protocol is in the
1709 stopped state, then EFI_NOT_STARTED is returned. If the ARP protocol encounters
1710 a timeout condition while attempting to resolve an address, then EFI_TIMEOUT is
1711 returned. If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
1712 then EFI_ABORTED is returned.
1713
1714 @param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1715 @param[in] IpAddr Pointer to the IP address that is used to resolve a MAC address.
1716 @param[in] MacAddr If not NULL, a pointer to the MAC address that was resolved with the
1717 ARP protocol.
1718
1719 @retval EFI_SUCCESS The IP or MAC address was resolved.
1720 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1721 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1722 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1723 @retval EFI_ICMP_ERROR An error occur with the ICMP packet message.
1724
1725**/
1726EFI_STATUS
1727EFIAPI
1728EfiPxeBcArp (
1729 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
1730 IN EFI_IP_ADDRESS *IpAddr,
1731 IN EFI_MAC_ADDRESS *MacAddr OPTIONAL
1732 )
1733{
1734 PXEBC_PRIVATE_DATA *Private;
1735 EFI_PXE_BASE_CODE_MODE *Mode;
1736 EFI_EVENT ResolvedEvent;
1737 EFI_STATUS Status;
1738 EFI_MAC_ADDRESS TempMac;
1739 EFI_MAC_ADDRESS ZeroMac;
1740 BOOLEAN IsResolved;
1741
1742 if (This == NULL || IpAddr == NULL) {
1743 return EFI_INVALID_PARAMETER;
1744 }
1745
1746 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
1747 Mode = Private->PxeBc.Mode;
1748 ResolvedEvent = NULL;
1749 Status = EFI_SUCCESS;
1750 IsResolved = FALSE;
1751
1752 if (!Mode->Started) {
1753 return EFI_NOT_STARTED;
1754 }
1755
1756 if (Mode->UsingIpv6) {
1757 return EFI_UNSUPPORTED;
1758 }
1759
1760 //
1761 // Station address should be ready before do arp.
1762 //
1763 if (!Private->IsAddressOk) {
1764 return EFI_INVALID_PARAMETER;
1765 }
1766
1767 Mode->IcmpErrorReceived = FALSE;
1768 ZeroMem (&TempMac, sizeof (EFI_MAC_ADDRESS));
1769 ZeroMem (&ZeroMac, sizeof (EFI_MAC_ADDRESS));
1770
1771 if (!Mode->AutoArp) {
1772 //
1773 // If AutoArp is FALSE, only search in the current Arp cache.
1774 //
1775 PxeBcArpCacheUpdate (NULL, Private);
1776 if (!PxeBcCheckArpCache (Mode, &IpAddr->v4, &TempMac)) {
1777 Status = EFI_DEVICE_ERROR;
1778 goto ON_EXIT;
1779 }
1780 } else {
1781 Status = gBS->CreateEvent (
1782 EVT_NOTIFY_SIGNAL,
1783 TPL_NOTIFY,
1784 PxeBcCommonNotify,
1785 &IsResolved,
1786 &ResolvedEvent
1787 );
1788 if (EFI_ERROR (Status)) {
1789 goto ON_EXIT;
1790 }
1791
1792 //
1793 // If AutoArp is TRUE, try to send Arp request on initiative.
1794 //
1795 Status = Private->Arp->Request (Private->Arp, &IpAddr->v4, ResolvedEvent, &TempMac);
1796 if (EFI_ERROR (Status) && Status != EFI_NOT_READY) {
1797 goto ON_EXIT;
1798 }
1799
1800 while (!IsResolved) {
1801 if (CompareMem (&TempMac, &ZeroMac, sizeof (EFI_MAC_ADDRESS)) != 0) {
1802 break;
1803 }
1804 }
1805 if (CompareMem (&TempMac, &ZeroMac, sizeof (EFI_MAC_ADDRESS)) != 0) {
1806 Status = EFI_SUCCESS;
1807 } else {
1808 Status = EFI_TIMEOUT;
1809 }
1810 }
1811
1812 //
1813 // Copy the Mac address to user if needed.
1814 //
1815 if (MacAddr != NULL && !EFI_ERROR (Status)) {
1816 CopyMem (MacAddr, &TempMac, sizeof (EFI_MAC_ADDRESS));
1817 }
1818
1819ON_EXIT:
1820 if (ResolvedEvent != NULL) {
1821 gBS->CloseEvent (ResolvedEvent);
1822 }
1823 return Status;
1824}
1825
1826
1827/**
1828 Updates the parameters that affect the operation of the PXE Base Code Protocol.
1829
1830 This function sets parameters that affect the operation of the PXE Base Code Protocol.
1831 The parameter specified by NewAutoArp is used to control the generation of ARP
1832 protocol packets. If NewAutoArp is TRUE, then ARP Protocol packets will be generated
1833 as required by the PXE Base Code Protocol. If NewAutoArp is FALSE, then no ARP
1834 Protocol packets will be generated. In this case, the only mappings that are
1835 available are those stored in the ArpCache of the EFI_PXE_BASE_CODE_MODE structure.
1836 If there are not enough mappings in the ArpCache to perform a PXE Base Code Protocol
1837 service, then the service will fail. This function updates the AutoArp field of
1838 the EFI_PXE_BASE_CODE_MODE structure to NewAutoArp.
1839 The SetParameters() call must be invoked after a Callback Protocol is installed
1840 to enable the use of callbacks.
1841
1842 @param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1843 @param[in] NewAutoArp If not NULL, a pointer to a value that specifies whether to replace the
1844 current value of AutoARP.
1845 @param[in] NewSendGUID If not NULL, a pointer to a value that specifies whether to replace the
1846 current value of SendGUID.
1847 @param[in] NewTTL If not NULL, a pointer to be used in place of the current value of TTL,
1848 the "time to live" field of the IP header.
1849 @param[in] NewToS If not NULL, a pointer to be used in place of the current value of ToS,
1850 the "type of service" field of the IP header.
1851 @param[in] NewMakeCallback If not NULL, a pointer to a value that specifies whether to replace the
1852 current value of the MakeCallback field of the Mode structure.
1853
1854 @retval EFI_SUCCESS The new parameters values were updated.
1855 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1856 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1857
1858**/
1859EFI_STATUS
1860EFIAPI
1861EfiPxeBcSetParameters (
1862 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
1863 IN BOOLEAN *NewAutoArp OPTIONAL,
1864 IN BOOLEAN *NewSendGUID OPTIONAL,
1865 IN UINT8 *NewTTL OPTIONAL,
1866 IN UINT8 *NewToS OPTIONAL,
1867 IN BOOLEAN *NewMakeCallback OPTIONAL
1868 )
1869{
1870 PXEBC_PRIVATE_DATA *Private;
1871 EFI_PXE_BASE_CODE_MODE *Mode;
1872 EFI_GUID SystemGuid;
1873 EFI_STATUS Status;
1874
1875 if (This == NULL) {
1876 return EFI_INVALID_PARAMETER;
1877 }
1878
1879 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
1880 Mode = Private->PxeBc.Mode;
1881
1882 if (!Mode->Started) {
1883 return EFI_NOT_STARTED;
1884 }
1885
1886 if (NewMakeCallback != NULL) {
1887 if (*NewMakeCallback) {
1888 //
1889 // Update the previous PxeBcCallback protocol.
1890 //
1891 Status = gBS->HandleProtocol (
1892 Private->Controller,
1893 &gEfiPxeBaseCodeCallbackProtocolGuid,
1894 (VOID **) &Private->PxeBcCallback
1895 );
1896
1897 if (EFI_ERROR (Status) || (Private->PxeBcCallback->Callback == NULL)) {
1898 return EFI_INVALID_PARAMETER;
1899 }
1900 } else {
1901 Private->PxeBcCallback = NULL;
1902 }
1903 Mode->MakeCallbacks = *NewMakeCallback;
1904 }
1905
1906 if (NewSendGUID != NULL) {
1907 if (*NewSendGUID && EFI_ERROR (NetLibGetSystemGuid (&SystemGuid))) {
1908 return EFI_INVALID_PARAMETER;
1909 }
1910 Mode->SendGUID = *NewSendGUID;
1911 }
1912
1913 if (NewAutoArp != NULL) {
1914 Mode->AutoArp = *NewAutoArp;
1915 }
1916
1917 if (NewTTL != NULL) {
1918 Mode->TTL = *NewTTL;
1919 }
1920
1921 if (NewToS != NULL) {
1922 Mode->ToS = *NewToS;
1923 }
1924
1925 return EFI_SUCCESS;
1926}
1927
1928
1929/**
1930 Updates the station IP address and/or subnet mask values of a network device.
1931
1932 This function updates the station IP address and/or subnet mask values of a network
1933 device. The NewStationIp field is used to modify the network device's current IP address.
1934 If NewStationIP is NULL, then the current IP address will not be modified. Otherwise,
1935 this function updates the StationIp field of the EFI_PXE_BASE_CODE_MODE structure
1936 with NewStationIp. The NewSubnetMask field is used to modify the network device's current subnet
1937 mask. If NewSubnetMask is NULL, then the current subnet mask will not be modified.
1938 Otherwise, this function updates the SubnetMask field of the EFI_PXE_BASE_CODE_MODE
1939 structure with NewSubnetMask.
1940
1941 @param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1942 @param[in] NewStationIp Pointer to the new IP address to be used by the network device.
1943 @param[in] NewSubnetMask Pointer to the new subnet mask to be used by the network device.
1944
1945 @retval EFI_SUCCESS The new station IP address and/or subnet mask were updated.
1946 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1947 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1948
1949**/
1950EFI_STATUS
1951EFIAPI
1952EfiPxeBcSetStationIP (
1953 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
1954 IN EFI_IP_ADDRESS *NewStationIp OPTIONAL,
1955 IN EFI_IP_ADDRESS *NewSubnetMask OPTIONAL
1956 )
1957{
1958 EFI_STATUS Status;
1959 PXEBC_PRIVATE_DATA *Private;
1960 EFI_PXE_BASE_CODE_MODE *Mode;
1961 EFI_ARP_CONFIG_DATA ArpConfigData;
1962
1963 if (This == NULL) {
1964 return EFI_INVALID_PARAMETER;
1965 }
1966
1967 if (NewStationIp != NULL &&
1968 (!NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), 0) &&
1969 !NetIp6IsValidUnicast (&NewStationIp->v6))) {
1970 return EFI_INVALID_PARAMETER;
1971 }
1972
1973 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
1974 Mode = Private->PxeBc.Mode;
1975 Status = EFI_SUCCESS;
1976
1977 if (!Mode->UsingIpv6 &&
1978 NewSubnetMask != NULL &&
1979 !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask->Addr[0]))) {
1980 return EFI_INVALID_PARAMETER;
1981 }
1982
1983 if (!Mode->Started) {
1984 return EFI_NOT_STARTED;
1985 }
1986
1987 if (Mode->UsingIpv6 && NewStationIp != NULL) {
1988 //
1989 // Set the IPv6 address by Ip6Config protocol.
1990 //
1991 Status = PxeBcRegisterIp6Address (Private, &NewStationIp->v6);
1992 if (EFI_ERROR (Status)) {
1993 goto ON_EXIT;
1994 }
1995 } else if (!Mode->UsingIpv6 && NewStationIp != NULL) {
1996 //
1997 // Configure the corresponding ARP with the IPv4 address.
1998 //
1999 ZeroMem (&ArpConfigData, sizeof (EFI_ARP_CONFIG_DATA));
2000
2001 ArpConfigData.SwAddressType = 0x0800;
2002 ArpConfigData.SwAddressLength = (UINT8) sizeof (EFI_IPv4_ADDRESS);
2003 ArpConfigData.StationAddress = &NewStationIp->v4;
2004
2005 Private->Arp->Configure (Private->Arp, NULL);
2006 Private->Arp->Configure (Private->Arp, &ArpConfigData);
2007
2008 if (NewSubnetMask != NULL) {
2009 Mode->RouteTableEntries = 1;
2010 Mode->RouteTable[0].IpAddr.Addr[0] = NewStationIp->Addr[0] & NewSubnetMask->Addr[0];
2011 Mode->RouteTable[0].SubnetMask.Addr[0] = NewSubnetMask->Addr[0];
2012 Mode->RouteTable[0].GwAddr.Addr[0] = 0;
2013 }
2014
2015 Private->IsAddressOk = TRUE;
2016 }
2017
2018 if (NewStationIp != NULL) {
2019 CopyMem (&Mode->StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));
2020 CopyMem (&Private->StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));
2021 }
2022
2023 if (!Mode->UsingIpv6 && NewSubnetMask != NULL) {
2024 CopyMem (&Mode->SubnetMask, NewSubnetMask, sizeof (EFI_IP_ADDRESS));
2025 CopyMem (&Private->SubnetMask ,NewSubnetMask, sizeof (EFI_IP_ADDRESS));
2026 }
2027
2028 Status = PxeBcFlushStationIp (Private, NewStationIp, NewSubnetMask);
2029ON_EXIT:
2030 return Status;
2031}
2032
2033
2034/**
2035 Updates the contents of the cached DHCP and Discover packets.
2036
2037 The pointers to the new packets are used to update the contents of the cached
2038 packets in the EFI_PXE_BASE_CODE_MODE structure.
2039
2040 @param[in] This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2041 @param[in] NewDhcpDiscoverValid Pointer to a value that will replace the current
2042 DhcpDiscoverValid field.
2043 @param[in] NewDhcpAckReceived Pointer to a value that will replace the current
2044 DhcpAckReceived field.
2045 @param[in] NewProxyOfferReceived Pointer to a value that will replace the current
2046 ProxyOfferReceived field.
2047 @param[in] NewPxeDiscoverValid Pointer to a value that will replace the current
2048 ProxyOfferReceived field.
2049 @param[in] NewPxeReplyReceived Pointer to a value that will replace the current
2050 PxeReplyReceived field.
2051 @param[in] NewPxeBisReplyReceived Pointer to a value that will replace the current
2052 PxeBisReplyReceived field.
2053 @param[in] NewDhcpDiscover Pointer to the new cached DHCP Discover packet contents.
2054 @param[in] NewDhcpAck Pointer to the new cached DHCP Ack packet contents.
2055 @param[in] NewProxyOffer Pointer to the new cached Proxy Offer packet contents.
2056 @param[in] NewPxeDiscover Pointer to the new cached PXE Discover packet contents.
2057 @param[in] NewPxeReply Pointer to the new cached PXE Reply packet contents.
2058 @param[in] NewPxeBisReply Pointer to the new cached PXE BIS Reply packet contents.
2059
2060 @retval EFI_SUCCESS The cached packet contents were updated.
2061 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2062 @retval EFI_INVALID_PARAMETER This is NULL or does not point to a valid
2063 EFI_PXE_BASE_CODE_PROTOCOL structure.
2064
2065**/
2066EFI_STATUS
2067EFIAPI
2068EfiPxeBcSetPackets (
2069 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
2070 IN BOOLEAN *NewDhcpDiscoverValid OPTIONAL,
2071 IN BOOLEAN *NewDhcpAckReceived OPTIONAL,
2072 IN BOOLEAN *NewProxyOfferReceived OPTIONAL,
2073 IN BOOLEAN *NewPxeDiscoverValid OPTIONAL,
2074 IN BOOLEAN *NewPxeReplyReceived OPTIONAL,
2075 IN BOOLEAN *NewPxeBisReplyReceived OPTIONAL,
2076 IN EFI_PXE_BASE_CODE_PACKET *NewDhcpDiscover OPTIONAL,
2077 IN EFI_PXE_BASE_CODE_PACKET *NewDhcpAck OPTIONAL,
2078 IN EFI_PXE_BASE_CODE_PACKET *NewProxyOffer OPTIONAL,
2079 IN EFI_PXE_BASE_CODE_PACKET *NewPxeDiscover OPTIONAL,
2080 IN EFI_PXE_BASE_CODE_PACKET *NewPxeReply OPTIONAL,
2081 IN EFI_PXE_BASE_CODE_PACKET *NewPxeBisReply OPTIONAL
2082 )
2083{
2084 PXEBC_PRIVATE_DATA *Private;
2085 EFI_PXE_BASE_CODE_MODE *Mode;
2086
2087 if (This == NULL) {
2088 return EFI_INVALID_PARAMETER;
2089 }
2090
2091 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
2092 Mode = Private->PxeBc.Mode;
2093
2094 if (!Mode->Started) {
2095 return EFI_NOT_STARTED;
2096 }
2097
2098 if (NewDhcpDiscoverValid != NULL) {
2099 Mode->DhcpDiscoverValid = *NewDhcpDiscoverValid;
2100 }
2101
2102 if (NewDhcpAckReceived != NULL) {
2103 Mode->DhcpAckReceived = *NewDhcpAckReceived;
2104 }
2105
2106 if (NewProxyOfferReceived != NULL) {
2107 Mode->ProxyOfferReceived = *NewProxyOfferReceived;
2108 }
2109
2110 if (NewPxeDiscoverValid != NULL) {
2111 Mode->PxeDiscoverValid = *NewPxeDiscoverValid;
2112 }
2113
2114 if (NewPxeReplyReceived != NULL) {
2115 Mode->PxeReplyReceived = *NewPxeReplyReceived;
2116 }
2117
2118 if (NewPxeBisReplyReceived != NULL) {
2119 Mode->PxeBisReplyReceived = *NewPxeBisReplyReceived;
2120 }
2121
2122 if (NewDhcpDiscover != NULL) {
2123 CopyMem (&Mode->DhcpDiscover, NewDhcpDiscover, sizeof (EFI_PXE_BASE_CODE_PACKET));
2124 }
2125
2126 if (NewDhcpAck != NULL) {
2127 CopyMem (&Mode->DhcpAck, NewDhcpAck, sizeof (EFI_PXE_BASE_CODE_PACKET));
2128 }
2129
2130 if (NewProxyOffer != NULL) {
2131 CopyMem (&Mode->ProxyOffer, NewProxyOffer, sizeof (EFI_PXE_BASE_CODE_PACKET));
2132 }
2133
2134 if (NewPxeDiscover != NULL) {
2135 CopyMem (&Mode->PxeDiscover, NewPxeDiscover, sizeof (EFI_PXE_BASE_CODE_PACKET));
2136 }
2137
2138 if (NewPxeReply != NULL) {
2139 CopyMem (&Mode->PxeReply, NewPxeReply, sizeof (EFI_PXE_BASE_CODE_PACKET));
2140 }
2141
2142 if (NewPxeBisReply != NULL) {
2143 CopyMem (&Mode->PxeBisReply, NewPxeBisReply, sizeof (EFI_PXE_BASE_CODE_PACKET));
2144 }
2145
2146 return EFI_SUCCESS;
2147}
2148
2149EFI_PXE_BASE_CODE_PROTOCOL gPxeBcProtocolTemplate = {
2150 EFI_PXE_BASE_CODE_PROTOCOL_REVISION,
2151 EfiPxeBcStart,
2152 EfiPxeBcStop,
2153 EfiPxeBcDhcp,
2154 EfiPxeBcDiscover,
2155 EfiPxeBcMtftp,
2156 EfiPxeBcUdpWrite,
2157 EfiPxeBcUdpRead,
2158 EfiPxeBcSetIpFilter,
2159 EfiPxeBcArp,
2160 EfiPxeBcSetParameters,
2161 EfiPxeBcSetStationIP,
2162 EfiPxeBcSetPackets,
2163 NULL
2164};
2165
2166
2167/**
2168 Callback function that is invoked when the PXE Base Code Protocol is about to transmit, has
2169 received, or is waiting to receive a packet.
2170
2171 This function is invoked when the PXE Base Code Protocol is about to transmit, has received,
2172 or is waiting to receive a packet. Parameters Function and Received specify the type of event.
2173 Parameters PacketLen and Packet specify the packet that generated the event. If these fields
2174 are zero and NULL respectively, then this is a status update callback. If the operation specified
2175 by Function is to continue, then CALLBACK_STATUS_CONTINUE should be returned. If the operation
2176 specified by Function should be aborted, then CALLBACK_STATUS_ABORT should be returned. Due to
2177 the polling nature of UEFI device drivers, a callback function should not execute for more than 5 ms.
2178 The SetParameters() function must be called after a Callback Protocol is installed to enable the
2179 use of callbacks.
2180
2181 @param[in] This Pointer to the EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL instance.
2182 @param[in] Function The PXE Base Code Protocol function that is waiting for an event.
2183 @param[in] Received TRUE if the callback is being invoked due to a receive event. FALSE if
2184 the callback is being invoked due to a transmit event.
2185 @param[in] PacketLength The length, in bytes, of Packet. This field will have a value of zero if
2186 this is a wait for receive event.
2187 @param[in] PacketPtr If Received is TRUE, a pointer to the packet that was just received;
2188 otherwise a pointer to the packet that is about to be transmitted.
2189
2190 @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE If Function specifies a continue operation.
2191 @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT If Function specifies an abort operation.
2192
2193**/
2194EFI_PXE_BASE_CODE_CALLBACK_STATUS
2195EFIAPI
2196EfiPxeLoadFileCallback (
2197 IN EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *This,
2198 IN EFI_PXE_BASE_CODE_FUNCTION Function,
2199 IN BOOLEAN Received,
2200 IN UINT32 PacketLength,
2201 IN EFI_PXE_BASE_CODE_PACKET *PacketPtr OPTIONAL
2202 )
2203{
2204 EFI_INPUT_KEY Key;
2205 EFI_STATUS Status;
2206
2207 //
2208 // Catch Ctrl-C or ESC to abort.
2209 //
2210 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
2211
2212 if (!EFI_ERROR (Status)) {
2213
2214 if (Key.ScanCode == SCAN_ESC || Key.UnicodeChar == (0x1F & 'c')) {
2215
2216 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT;
2217 }
2218 }
2219 //
2220 // No print if receive packet
2221 //
2222 if (Received) {
2223 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;
2224 }
2225 //
2226 // Print only for three functions
2227 //
2228 switch (Function) {
2229
2230 case EFI_PXE_BASE_CODE_FUNCTION_MTFTP:
2231 //
2232 // Print only for open MTFTP packets, not every MTFTP packets
2233 //
2234 if (PacketLength != 0 && PacketPtr != NULL) {
2235 if (PacketPtr->Raw[0x1C] != 0x00 || PacketPtr->Raw[0x1D] != 0x01) {
2236 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;
2237 }
2238 }
2239 break;
2240
2241 case EFI_PXE_BASE_CODE_FUNCTION_DHCP:
2242 case EFI_PXE_BASE_CODE_FUNCTION_DISCOVER:
2243 break;
2244
2245 default:
2246 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;
2247 }
2248
2249 if (PacketLength != 0 && PacketPtr != NULL) {
2250 //
2251 // Print '.' when transmit a packet
2252 //
2253 AsciiPrint (".");
2254 }
2255
2256 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;
2257}
2258
2259EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL gPxeBcCallBackTemplate = {
2260 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL_REVISION,
2261 EfiPxeLoadFileCallback
2262};
2263
2264
2265/**
2266 Causes the driver to load a specified file.
2267
2268 @param[in] This Protocol instance pointer.
2269 @param[in] FilePath The device specific path of the file to load.
2270 @param[in] BootPolicy If TRUE, indicates that the request originates from the
2271 boot manager is attempting to load FilePath as a boot
2272 selection. If FALSE, then FilePath must match an exact file
2273 to be loaded.
2274 @param[in, out] BufferSize On input the size of Buffer in bytes. On output with a return
2275 code of EFI_SUCCESS, the amount of data transferred to
2276 Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
2277 the size of Buffer required to retrieve the requested file.
2278 @param[in] Buffer The memory buffer to transfer the file to. IF Buffer is NULL,
2279 then no the size of the requested file is returned in
2280 BufferSize.
2281
2282 @retval EFI_SUCCESS The file was loaded.
2283 @retval EFI_UNSUPPORTED The device does not support the provided BootPolicy.
2284 @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or
2285 BufferSize is NULL.
2286 @retval EFI_NO_MEDIA No medium was present to load the file.
2287 @retval EFI_DEVICE_ERROR The file was not loaded due to a device error.
2288 @retval EFI_NO_RESPONSE The remote system did not respond.
2289 @retval EFI_NOT_FOUND The file was not found.
2290 @retval EFI_ABORTED The file load process was manually cancelled.
2291
2292**/
2293EFI_STATUS
2294EFIAPI
2295EfiPxeLoadFile (
2296 IN EFI_LOAD_FILE_PROTOCOL *This,
2297 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
2298 IN BOOLEAN BootPolicy,
2299 IN OUT UINTN *BufferSize,
2300 IN VOID *Buffer OPTIONAL
2301 )
2302{
2303 PXEBC_PRIVATE_DATA *Private;
2304 PXEBC_VIRTUAL_NIC *VirtualNic;
2305 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
2306 BOOLEAN UsingIpv6;
2307 EFI_STATUS Status;
2308 BOOLEAN MediaPresent;
2309
2310 VirtualNic = PXEBC_VIRTUAL_NIC_FROM_LOADFILE (This);
2311 Private = VirtualNic->Private;
2312 PxeBc = &Private->PxeBc;
2313 UsingIpv6 = FALSE;
2314 Status = EFI_DEVICE_ERROR;
2315
2316 if (This == NULL || BufferSize == NULL) {
2317 return EFI_INVALID_PARAMETER;
2318 }
2319
2320 //
2321 // Only support BootPolicy
2322 //
2323 if (!BootPolicy) {
2324 return EFI_UNSUPPORTED;
2325 }
2326
2327 //
2328 // Check media status before PXE start
2329 //
2330 MediaPresent = TRUE;
2331 NetLibDetectMedia (Private->Controller, &MediaPresent);
2332 if (!MediaPresent) {
2333 return EFI_NO_MEDIA;
2334 }
2335
2336 //
2337 // Check whether the virtual nic is using IPv6 or not.
2338 //
2339 if (VirtualNic == Private->Ip6Nic) {
2340 UsingIpv6 = TRUE;
2341 }
2342
2343 //
2344 // Start Pxe Base Code to initialize PXE boot.
2345 //
2346 Status = PxeBc->Start (PxeBc, UsingIpv6);
2347 if (Status == EFI_ALREADY_STARTED && UsingIpv6 != PxeBc->Mode->UsingIpv6) {
2348 //
2349 // PxeBc protocol has already been started but not on the required IP version, restart it.
2350 //
2351 Status = PxeBc->Stop (PxeBc);
2352 if (!EFI_ERROR (Status)) {
2353 Status = PxeBc->Start (PxeBc, UsingIpv6);
2354 }
2355 }
2356 if (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED) {
2357 Status = PxeBcLoadBootFile (Private, BufferSize, Buffer);
2358 }
2359
2360 if (Status != EFI_SUCCESS &&
2361 Status != EFI_UNSUPPORTED &&
2362 Status != EFI_BUFFER_TOO_SMALL) {
2363 //
2364 // There are three cases, which needn't stop pxebc here.
2365 // 1. success to download file.
2366 // 2. success to get file size.
2367 // 3. unsupported.
2368 //
2369 PxeBc->Stop (PxeBc);
2370 }
2371
2372 return Status;
2373}
2374
2375EFI_LOAD_FILE_PROTOCOL gLoadFileProtocolTemplate = { EfiPxeLoadFile };
2376
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette