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