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