]>
Commit | Line | Data |
---|---|---|
dc361cc5 | 1 | /** @file\r |
f737cfb9 | 2 | Interface routines for PxeBc.\r |
e2851998 | 3 | \r |
60de3c19 | 4 | Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 5 | This program and the accompanying materials\r |
dc361cc5 | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
dc361cc5 | 13 | **/\r |
14 | \r | |
15 | \r | |
16 | #include "PxeBcImpl.h"\r | |
17 | \r | |
434ce3fe | 18 | UINT32 mPxeDhcpTimeout[4] = { 4, 8, 16, 32 };\r |
f737cfb9 | 19 | \r |
982a9eae | 20 | /**\r |
f737cfb9 | 21 | Get and record the arp cache.\r |
982a9eae | 22 | \r |
23 | @param This Pointer to EFI_PXE_BC_PROTOCOL\r | |
24 | \r | |
25 | @retval EFI_SUCCESS Arp cache updated successfully\r | |
f737cfb9 | 26 | @retval others If error occurs when getting arp cache\r |
982a9eae | 27 | \r |
28 | **/\r | |
982a9eae | 29 | EFI_STATUS\r |
30 | UpdateArpCache (\r | |
31 | IN EFI_PXE_BASE_CODE_PROTOCOL * This\r | |
32 | )\r | |
33 | {\r | |
34 | PXEBC_PRIVATE_DATA *Private;\r | |
35 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
36 | EFI_STATUS Status;\r | |
37 | UINT32 EntryLength;\r | |
38 | UINT32 EntryCount;\r | |
39 | EFI_ARP_FIND_DATA *Entries;\r | |
40 | UINT32 Index;\r | |
41 | \r | |
42 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
43 | Mode = Private->PxeBc.Mode;\r | |
44 | \r | |
f737cfb9 | 45 | Status = Private->Arp->Find (\r |
46 | Private->Arp,\r | |
47 | TRUE,\r | |
48 | NULL,\r | |
49 | &EntryLength,\r | |
50 | &EntryCount,\r | |
51 | &Entries,\r | |
52 | TRUE\r | |
53 | );\r | |
982a9eae | 54 | if (EFI_ERROR (Status)) {\r |
55 | return Status;\r | |
56 | }\r | |
57 | \r | |
f737cfb9 | 58 | Mode->ArpCacheEntries = MIN (\r |
59 | EntryCount,\r | |
60 | EFI_PXE_BASE_CODE_MAX_ARP_ENTRIES\r | |
61 | );\r | |
982a9eae | 62 | for (Index = 0; Index < Mode->ArpCacheEntries; Index ++) {\r |
f737cfb9 | 63 | CopyMem (\r |
e2851998 | 64 | &Mode->ArpCache[Index].IpAddr,\r |
65 | Entries + 1,\r | |
f737cfb9 | 66 | Entries->SwAddressLength\r |
67 | );\r | |
68 | CopyMem (\r | |
69 | &Mode->ArpCache[Index].MacAddr,\r | |
70 | (UINT8 *) (Entries + 1) + Entries->SwAddressLength,\r | |
71 | Entries->HwAddressLength\r | |
72 | );\r | |
982a9eae | 73 | //\r |
74 | // Slip to the next FindData.\r | |
75 | //\r | |
f737cfb9 | 76 | Entries = (EFI_ARP_FIND_DATA *) ((UINT8 *) Entries + EntryLength);\r |
982a9eae | 77 | }\r |
78 | \r | |
79 | return EFI_SUCCESS;\r | |
80 | }\r | |
81 | \r | |
82 | /**\r | |
f737cfb9 | 83 | Timeout routine to update arp cache.\r |
982a9eae | 84 | \r |
85 | @param Event Pointer to EFI_PXE_BC_PROTOCOL\r | |
86 | @param Context Context of the timer event\r | |
87 | \r | |
88 | **/\r | |
982a9eae | 89 | VOID\r |
90 | EFIAPI\r | |
91 | ArpCacheUpdateTimeout (\r | |
92 | IN EFI_EVENT Event,\r | |
93 | IN VOID *Context\r | |
94 | )\r | |
95 | {\r | |
96 | UpdateArpCache ((EFI_PXE_BASE_CODE_PROTOCOL *) Context);\r | |
97 | }\r | |
98 | \r | |
99 | /**\r | |
f737cfb9 | 100 | Do arp resolution from arp cache in PxeBcMode.\r |
e2851998 | 101 | \r |
f737cfb9 | 102 | @param PxeBcMode The PXE BC mode to look into.\r |
103 | @param Ip4Addr The Ip4 address for resolution.\r | |
104 | @param MacAddress The resoluted MAC address if the resolution is successful.\r | |
105 | The value is undefined if resolution fails.\r | |
e2851998 | 106 | \r |
f737cfb9 | 107 | @retval TRUE The resolution is successful.\r |
108 | @retval FALSE Otherwise.\r | |
982a9eae | 109 | \r |
110 | **/\r | |
982a9eae | 111 | BOOLEAN\r |
112 | FindInArpCache (\r | |
f737cfb9 | 113 | IN EFI_PXE_BASE_CODE_MODE *PxeBcMode,\r |
114 | IN EFI_IPv4_ADDRESS *Ip4Addr,\r | |
115 | OUT EFI_MAC_ADDRESS *MacAddress\r | |
982a9eae | 116 | )\r |
117 | {\r | |
118 | UINT32 Index;\r | |
119 | \r | |
120 | for (Index = 0; Index < PxeBcMode->ArpCacheEntries; Index ++) {\r | |
121 | if (EFI_IP4_EQUAL (&PxeBcMode->ArpCache[Index].IpAddr.v4, Ip4Addr)) {\r | |
f737cfb9 | 122 | CopyMem (\r |
123 | MacAddress,\r | |
124 | &PxeBcMode->ArpCache[Index].MacAddr,\r | |
125 | sizeof (EFI_MAC_ADDRESS)\r | |
126 | );\r | |
982a9eae | 127 | return TRUE;\r |
128 | }\r | |
129 | }\r | |
130 | \r | |
131 | return FALSE;\r | |
132 | }\r | |
133 | \r | |
134 | /**\r | |
135 | Notify function for the ICMP receive token, used to process\r | |
136 | the received ICMP packets.\r | |
137 | \r | |
f737cfb9 | 138 | @param Context The PXEBC private data.\r |
982a9eae | 139 | \r |
982a9eae | 140 | **/\r |
982a9eae | 141 | VOID\r |
142 | EFIAPI\r | |
143 | IcmpErrorListenHandlerDpc (\r | |
144 | IN VOID *Context\r | |
145 | )\r | |
146 | {\r | |
147 | EFI_STATUS Status;\r | |
148 | EFI_IP4_RECEIVE_DATA *RxData;\r | |
149 | EFI_IP4_PROTOCOL *Ip4;\r | |
150 | PXEBC_PRIVATE_DATA *Private;\r | |
151 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
152 | UINTN Index;\r | |
153 | UINT32 CopiedLen;\r | |
154 | UINT8 *CopiedPointer;\r | |
155 | \r | |
156 | Private = (PXEBC_PRIVATE_DATA *) Context;\r | |
157 | Mode = &Private->Mode;\r | |
158 | Status = Private->IcmpErrorRcvToken.Status;\r | |
159 | RxData = Private->IcmpErrorRcvToken.Packet.RxData;\r | |
160 | Ip4 = Private->Ip4;\r | |
161 | \r | |
f737cfb9 | 162 | if (Status == EFI_ABORTED) {\r |
982a9eae | 163 | //\r |
164 | // The reception is actively aborted by the consumer, directly return.\r | |
165 | //\r | |
166 | return;\r | |
167 | }\r | |
168 | \r | |
f737cfb9 | 169 | if (EFI_ERROR (Status) || (RxData == NULL)) {\r |
982a9eae | 170 | //\r |
171 | // Only process the normal packets and the icmp error packets, if RxData is NULL\r | |
172 | // with Status == EFI_SUCCESS or EFI_ICMP_ERROR, just resume the receive although\r | |
173 | // this should be a bug of the low layer (IP).\r | |
174 | //\r | |
175 | goto Resume;\r | |
176 | }\r | |
177 | \r | |
f737cfb9 | 178 | if (EFI_IP4 (RxData->Header->SourceAddress) != 0 &&\r |
01b5ac88 FS |
179 | (NTOHL (Mode->SubnetMask.Addr[0]) != 0) &&\r |
180 | IP4_NET_EQUAL (NTOHL(Mode->StationIp.Addr[0]), EFI_NTOHL (RxData->Header->SourceAddress), NTOHL (Mode->SubnetMask.Addr[0])) &&\r | |
181 | !NetIp4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress), NTOHL (Mode->SubnetMask.Addr[0]))) {\r | |
982a9eae | 182 | //\r |
183 | // The source address is not zero and it's not a unicast IP address, discard it.\r | |
184 | //\r | |
185 | goto CleanUp;\r | |
186 | }\r | |
187 | \r | |
188 | if (!EFI_IP4_EQUAL (&RxData->Header->DestinationAddress, &Mode->StationIp.v4)) {\r | |
189 | //\r | |
190 | // The dest address is not equal to Station Ip address, discard it.\r | |
191 | //\r | |
192 | goto CleanUp;\r | |
193 | }\r | |
194 | \r | |
195 | //\r | |
196 | // Constructor ICMP error packet\r | |
197 | //\r | |
198 | CopiedLen = 0;\r | |
199 | CopiedPointer = (UINT8 *) &Mode->IcmpError;\r | |
200 | \r | |
201 | for (Index = 0; Index < RxData->FragmentCount; Index ++) {\r | |
202 | CopiedLen += RxData->FragmentTable[Index].FragmentLength;\r | |
203 | if (CopiedLen <= sizeof (EFI_PXE_BASE_CODE_ICMP_ERROR)) {\r | |
f737cfb9 | 204 | CopyMem (\r |
205 | CopiedPointer,\r | |
206 | RxData->FragmentTable[Index].FragmentBuffer,\r | |
207 | RxData->FragmentTable[Index].FragmentLength\r | |
208 | );\r | |
982a9eae | 209 | } else {\r |
f737cfb9 | 210 | CopyMem (\r |
211 | CopiedPointer,\r | |
212 | RxData->FragmentTable[Index].FragmentBuffer,\r | |
213 | CopiedLen - sizeof (EFI_PXE_BASE_CODE_ICMP_ERROR)\r | |
214 | );\r | |
982a9eae | 215 | }\r |
216 | CopiedPointer += CopiedLen;\r | |
217 | }\r | |
218 | \r | |
219 | goto Resume;\r | |
220 | \r | |
221 | CleanUp:\r | |
222 | gBS->SignalEvent (RxData->RecycleSignal);\r | |
223 | \r | |
224 | Resume:\r | |
225 | Ip4->Receive (Ip4, &(Private->IcmpErrorRcvToken));\r | |
226 | }\r | |
227 | \r | |
228 | /**\r | |
229 | Request IcmpErrorListenHandlerDpc as a DPC at TPL_CALLBACK\r | |
230 | \r | |
231 | @param Event The event signaled.\r | |
232 | @param Context The context passed in by the event notifier.\r | |
233 | \r | |
982a9eae | 234 | **/\r |
982a9eae | 235 | VOID\r |
236 | EFIAPI\r | |
237 | IcmpErrorListenHandler (\r | |
238 | IN EFI_EVENT Event,\r | |
239 | IN VOID *Context\r | |
240 | )\r | |
241 | {\r | |
242 | //\r | |
243 | // Request IpIoListenHandlerDpc as a DPC at TPL_CALLBACK\r | |
244 | //\r | |
d8d26fb2 | 245 | QueueDpc (TPL_CALLBACK, IcmpErrorListenHandlerDpc, Context);\r |
982a9eae | 246 | }\r |
dc361cc5 | 247 | \r |
e2851998 | 248 | /**\r |
f737cfb9 | 249 | Enables the use of the PXE Base Code Protocol functions.\r |
250 | \r | |
251 | This function enables the use of the PXE Base Code Protocol functions. If the\r | |
252 | Started field of the EFI_PXE_BASE_CODE_MODE structure is already TRUE, then\r | |
253 | EFI_ALREADY_STARTED will be returned. If UseIpv6 is TRUE, then IPv6 formatted\r | |
254 | addresses will be used in this session. If UseIpv6 is FALSE, then IPv4 formatted\r | |
255 | addresses will be used in this session. If UseIpv6 is TRUE, and the Ipv6Supported\r | |
256 | field of the EFI_PXE_BASE_CODE_MODE structure is FALSE, then EFI_UNSUPPORTED will\r | |
257 | be returned. If there is not enough memory or other resources to start the PXE\r | |
258 | Base Code Protocol, then EFI_OUT_OF_RESOURCES will be returned. Otherwise, the\r | |
259 | PXE Base Code Protocol will be started, and all of the fields of the EFI_PXE_BASE_CODE_MODE\r | |
260 | structure will be initialized as follows:\r | |
261 | StartedSet to TRUE.\r | |
262 | Ipv6SupportedUnchanged.\r | |
263 | Ipv6AvailableUnchanged.\r | |
264 | UsingIpv6Set to UseIpv6.\r | |
265 | BisSupportedUnchanged.\r | |
266 | BisDetectedUnchanged.\r | |
267 | AutoArpSet to TRUE.\r | |
268 | SendGUIDSet to FALSE.\r | |
269 | TTLSet to DEFAULT_TTL.\r | |
270 | ToSSet to DEFAULT_ToS.\r | |
271 | DhcpCompletedSet to FALSE.\r | |
272 | ProxyOfferReceivedSet to FALSE.\r | |
273 | StationIpSet to an address of all zeros.\r | |
274 | SubnetMaskSet to a subnet mask of all zeros.\r | |
275 | DhcpDiscoverZero-filled.\r | |
276 | DhcpAckZero-filled.\r | |
277 | ProxyOfferZero-filled.\r | |
278 | PxeDiscoverValidSet to FALSE.\r | |
279 | PxeDiscoverZero-filled.\r | |
280 | PxeReplyValidSet to FALSE.\r | |
281 | PxeReplyZero-filled.\r | |
282 | PxeBisReplyValidSet to FALSE.\r | |
283 | PxeBisReplyZero-filled.\r | |
284 | IpFilterSet the Filters field to 0 and the IpCnt field to 0.\r | |
285 | ArpCacheEntriesSet to 0.\r | |
286 | ArpCacheZero-filled.\r | |
287 | RouteTableEntriesSet to 0.\r | |
288 | RouteTableZero-filled.\r | |
289 | IcmpErrorReceivedSet to FALSE.\r | |
290 | IcmpErrorZero-filled.\r | |
291 | TftpErroReceivedSet to FALSE.\r | |
292 | TftpErrorZero-filled.\r | |
293 | MakeCallbacksSet to TRUE if the PXE Base Code Callback Protocol is available.\r | |
294 | Set to FALSE if the PXE Base Code Callback Protocol is not available.\r | |
e2851998 | 295 | \r |
f737cfb9 | 296 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r |
297 | @param UseIpv6 Specifies the type of IP addresses that are to be used during the session\r | |
e2851998 | 298 | that is being started. Set to TRUE for IPv6 addresses, and FALSE for\r |
299 | IPv4 addresses.\r | |
300 | \r | |
f737cfb9 | 301 | @retval EFI_SUCCESS The PXE Base Code Protocol was started.\r |
e2851998 | 302 | @retval EFI_DEVICE_ERROR The network device encountered an error during this oper\r |
f737cfb9 | 303 | @retval EFI_UNSUPPORTED UseIpv6 is TRUE, but the Ipv6Supported field of the\r |
e2851998 | 304 | EFI_PXE_BASE_CODE_MODE structure is FALSE.\r |
305 | @retval EFI_ALREADY_STARTED The PXE Base Code Protocol is already in the started state.\r | |
f737cfb9 | 306 | @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid\r |
e2851998 | 307 | EFI_PXE_BASE_CODE_PROTOCOL structure.\r |
308 | @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory or other resources to start the\r | |
309 | PXE Base Code Protocol.\r | |
310 | \r | |
dc361cc5 | 311 | **/\r |
312 | EFI_STATUS\r | |
313 | EFIAPI\r | |
314 | EfiPxeBcStart (\r | |
315 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r | |
316 | IN BOOLEAN UseIpv6\r | |
317 | )\r | |
318 | {\r | |
319 | PXEBC_PRIVATE_DATA *Private;\r | |
320 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
321 | EFI_STATUS Status;\r | |
322 | \r | |
323 | if (This == NULL) {\r | |
324 | return EFI_INVALID_PARAMETER;\r | |
325 | }\r | |
326 | \r | |
327 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
328 | Mode = Private->PxeBc.Mode;\r | |
329 | \r | |
330 | if (Mode->Started) {\r | |
331 | return EFI_ALREADY_STARTED;\r | |
332 | }\r | |
333 | \r | |
334 | if (UseIpv6) {\r | |
335 | //\r | |
336 | // IPv6 is not supported now.\r | |
337 | //\r | |
338 | return EFI_UNSUPPORTED;\r | |
339 | }\r | |
340 | \r | |
341 | //\r | |
342 | // Configure the udp4 instance to let it receive data\r | |
343 | //\r | |
f737cfb9 | 344 | Status = Private->Udp4Read->Configure (\r |
e2851998 | 345 | Private->Udp4Read,\r |
f737cfb9 | 346 | &Private->Udp4CfgData\r |
347 | );\r | |
dc361cc5 | 348 | if (EFI_ERROR (Status)) {\r |
349 | return Status;\r | |
350 | }\r | |
351 | \r | |
cfbc1a75 | 352 | \r |
353 | //\r | |
354 | // Configure block size for TFTP as a default value to handle all link layers.\r | |
355 | // \r | |
356 | Private->BlockSize = (UINTN) (MIN (Private->Ip4MaxPacketSize, PXEBC_DEFAULT_PACKET_SIZE) - \r | |
357 | PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE);\r | |
358 | //\r | |
359 | // If PcdTftpBlockSize is set to non-zero, override the default value.\r | |
360 | //\r | |
361 | if (PcdGet64 (PcdTftpBlockSize) != 0) {\r | |
362 | Private->BlockSize = (UINTN) PcdGet64 (PcdTftpBlockSize);\r | |
363 | }\r | |
364 | \r | |
dc361cc5 | 365 | Private->AddressIsOk = FALSE;\r |
366 | \r | |
367 | ZeroMem (Mode, sizeof (EFI_PXE_BASE_CODE_MODE));\r | |
368 | \r | |
369 | Mode->Started = TRUE;\r | |
370 | Mode->TTL = DEFAULT_TTL;\r | |
371 | Mode->ToS = DEFAULT_ToS;\r | |
372 | Mode->AutoArp = TRUE;\r | |
373 | \r | |
982a9eae | 374 | //\r |
375 | // Create the event for Arp Cache checking.\r | |
376 | //\r | |
377 | Status = gBS->CreateEvent (\r | |
378 | EVT_TIMER | EVT_NOTIFY_SIGNAL,\r | |
379 | TPL_CALLBACK,\r | |
380 | ArpCacheUpdateTimeout,\r | |
381 | This,\r | |
382 | &Private->GetArpCacheEvent\r | |
383 | );\r | |
384 | if (EFI_ERROR (Status)) {\r | |
385 | goto ON_EXIT;\r | |
386 | }\r | |
387 | \r | |
388 | //\r | |
389 | // Start the timeout timer event.\r | |
390 | //\r | |
391 | Status = gBS->SetTimer (\r | |
392 | Private->GetArpCacheEvent,\r | |
393 | TimerPeriodic,\r | |
394 | TICKS_PER_SECOND\r | |
395 | );\r | |
396 | \r | |
397 | if (EFI_ERROR (Status)) {\r | |
398 | goto ON_EXIT;\r | |
399 | }\r | |
400 | \r | |
401 | //\r | |
402 | // Create ICMP error receiving event\r | |
403 | //\r | |
404 | Status = gBS->CreateEvent (\r | |
405 | EVT_NOTIFY_SIGNAL,\r | |
406 | TPL_NOTIFY,\r | |
407 | IcmpErrorListenHandler,\r | |
408 | Private,\r | |
409 | &(Private->IcmpErrorRcvToken.Event)\r | |
410 | );\r | |
411 | if (EFI_ERROR (Status)) {\r | |
412 | goto ON_EXIT;\r | |
413 | }\r | |
414 | \r | |
14e84fd8 ZL |
415 | //\r |
416 | //DHCP4 service allows only one of its children to be configured in \r | |
417 | //the active state, If the DHCP4 D.O.R.A started by IP4 auto \r | |
418 | //configuration and has not been completed, the Dhcp4 state machine \r | |
419 | //will not be in the right state for the PXE to start a new round D.O.R.A. \r | |
420 | //so we need to switch it's policy to static.\r | |
421 | //\r | |
422 | Status = PxeBcSetIp4Policy (Private);\r | |
423 | if (EFI_ERROR (Status)) {\r | |
424 | goto ON_EXIT;\r | |
425 | }\r | |
426 | \r | |
982a9eae | 427 | Status = Private->Ip4->Configure (Private->Ip4, &Private->Ip4ConfigData);\r |
428 | if (EFI_ERROR (Status)) {\r | |
429 | goto ON_EXIT;\r | |
430 | }\r | |
431 | \r | |
432 | //\r | |
433 | // start to listen incoming packet\r | |
434 | //\r | |
435 | Status = Private->Ip4->Receive (Private->Ip4, &Private->IcmpErrorRcvToken);\r | |
436 | if (!EFI_ERROR (Status)) {\r | |
437 | return Status;\r | |
438 | }\r | |
439 | \r | |
440 | ON_EXIT:\r | |
441 | Private->Ip4->Configure (Private->Ip4, NULL);\r | |
442 | \r | |
443 | if (Private->IcmpErrorRcvToken.Event != NULL) {\r | |
444 | gBS->CloseEvent (Private->IcmpErrorRcvToken.Event);\r | |
445 | }\r | |
446 | \r | |
447 | if (Private->GetArpCacheEvent != NULL) {\r | |
448 | gBS->SetTimer (Private->GetArpCacheEvent, TimerCancel, 0);\r | |
449 | gBS->CloseEvent (Private->GetArpCacheEvent);\r | |
450 | }\r | |
451 | \r | |
452 | Mode->Started = FALSE;\r | |
453 | Mode->TTL = 0;\r | |
454 | Mode->ToS = 0;\r | |
455 | Mode->AutoArp = FALSE;\r | |
456 | \r | |
457 | return Status;\r | |
dc361cc5 | 458 | }\r |
459 | \r | |
460 | \r | |
e2851998 | 461 | /**\r |
f737cfb9 | 462 | Disables the use of the PXE Base Code Protocol functions.\r |
463 | \r | |
464 | This function stops all activity on the network device. All the resources allocated\r | |
465 | in Start() are released, the Started field of the EFI_PXE_BASE_CODE_MODE structure is\r | |
466 | set to FALSE and EFI_SUCCESS is returned. If the Started field of the EFI_PXE_BASE_CODE_MODE\r | |
467 | structure is already FALSE, then EFI_NOT_STARTED will be returned.\r | |
e2851998 | 468 | \r |
f737cfb9 | 469 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r |
e2851998 | 470 | \r |
f737cfb9 | 471 | @retval EFI_SUCCESS The PXE Base Code Protocol was stopped.\r |
e2851998 | 472 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is already in the stopped state.\r |
f737cfb9 | 473 | @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid\r |
e2851998 | 474 | EFI_PXE_BASE_CODE_PROTOCOL structure.\r |
475 | @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r | |
476 | \r | |
dc361cc5 | 477 | **/\r |
478 | EFI_STATUS\r | |
479 | EFIAPI\r | |
480 | EfiPxeBcStop (\r | |
481 | IN EFI_PXE_BASE_CODE_PROTOCOL *This\r | |
482 | )\r | |
483 | {\r | |
484 | PXEBC_PRIVATE_DATA *Private;\r | |
485 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
486 | \r | |
487 | if (This == NULL) {\r | |
488 | return EFI_INVALID_PARAMETER;\r | |
489 | }\r | |
490 | \r | |
491 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
492 | Mode = Private->PxeBc.Mode;\r | |
493 | \r | |
494 | if (!Mode->Started) {\r | |
495 | return EFI_NOT_STARTED;\r | |
496 | }\r | |
497 | \r | |
982a9eae | 498 | Private->Ip4->Cancel (Private->Ip4, NULL);\r |
499 | //\r | |
500 | // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's\r | |
501 | // events.\r | |
502 | //\r | |
d8d26fb2 | 503 | DispatchDpc ();\r |
982a9eae | 504 | \r |
505 | Private->Ip4->Configure (Private->Ip4, NULL);\r | |
506 | \r | |
507 | //\r | |
508 | // Close the ICMP error receiving event.\r | |
509 | //\r | |
510 | gBS->CloseEvent (Private->IcmpErrorRcvToken.Event);\r | |
511 | \r | |
512 | //\r | |
513 | // Cancel the TimeoutEvent timer.\r | |
514 | //\r | |
515 | gBS->SetTimer (Private->GetArpCacheEvent, TimerCancel, 0);\r | |
516 | \r | |
517 | //\r | |
518 | // Close the TimeoutEvent event.\r | |
519 | //\r | |
520 | gBS->CloseEvent (Private->GetArpCacheEvent);\r | |
521 | \r | |
dc361cc5 | 522 | Mode->Started = FALSE;\r |
523 | \r | |
8792362f | 524 | Private->CurrentUdpSrcPort = 0;\r |
525 | Private->Udp4Write->Configure (Private->Udp4Write, NULL);\r | |
434ce3fe | 526 | Private->Udp4Read->Groups (Private->Udp4Read, FALSE, NULL);\r |
8792362f | 527 | Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r |
dc361cc5 | 528 | \r |
529 | Private->Dhcp4->Stop (Private->Dhcp4);\r | |
530 | Private->Dhcp4->Configure (Private->Dhcp4, NULL);\r | |
531 | \r | |
532 | Private->FileSize = 0;\r | |
533 | \r | |
534 | return EFI_SUCCESS;\r | |
535 | }\r | |
536 | \r | |
537 | \r | |
e2851998 | 538 | /**\r |
f737cfb9 | 539 | Attempts to complete a DHCPv4 D.O.R.A. (discover / offer / request / acknowledge) or DHCPv6\r |
540 | S.A.R.R (solicit / advertise / request / reply) sequence.\r | |
541 | \r | |
542 | This function attempts to complete the DHCP sequence. If this sequence is completed,\r | |
543 | then EFI_SUCCESS is returned, and the DhcpCompleted, ProxyOfferReceived, StationIp,\r | |
544 | SubnetMask, DhcpDiscover, DhcpAck, and ProxyOffer fields of the EFI_PXE_BASE_CODE_MODE\r | |
545 | structure are filled in.\r | |
546 | If SortOffers is TRUE, then the cached DHCP offer packets will be sorted before\r | |
547 | they are tried. If SortOffers is FALSE, then the cached DHCP offer packets will\r | |
548 | be tried in the order in which they are received. Please see the Preboot Execution\r | |
549 | Environment (PXE) Specification for additional details on the implementation of DHCP.\r | |
550 | This function can take at least 31 seconds to timeout and return control to the\r | |
551 | caller. If the DHCP sequence does not complete, then EFI_TIMEOUT will be returned.\r | |
552 | If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,\r | |
553 | then the DHCP sequence will be stopped and EFI_ABORTED will be returned.\r | |
e2851998 | 554 | \r |
f737cfb9 | 555 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r |
556 | @param SortOffers TRUE if the offers received should be sorted. Set to FALSE to try the\r | |
e2851998 | 557 | offers in the order that they are received.\r |
558 | \r | |
f737cfb9 | 559 | @retval EFI_SUCCESS Valid DHCP has completed.\r |
560 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
561 | @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid\r | |
e2851998 | 562 | EFI_PXE_BASE_CODE_PROTOCOL structure.\r |
563 | @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r | |
f737cfb9 | 564 | @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete the DHCP Protocol.\r |
565 | @retval EFI_ABORTED The callback function aborted the DHCP Protocol.\r | |
566 | @retval EFI_TIMEOUT The DHCP Protocol timed out.\r | |
567 | @retval EFI_ICMP_ERROR An ICMP error packet was received during the DHCP session.\r | |
568 | @retval EFI_NO_RESPONSE Valid PXE offer was not received.\r | |
e2851998 | 569 | \r |
dc361cc5 | 570 | **/\r |
571 | EFI_STATUS\r | |
572 | EFIAPI\r | |
573 | EfiPxeBcDhcp (\r | |
574 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r | |
575 | IN BOOLEAN SortOffers\r | |
576 | )\r | |
577 | {\r | |
8730386e | 578 | PXEBC_PRIVATE_DATA *Private;\r |
579 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
580 | EFI_DHCP4_PROTOCOL *Dhcp4;\r | |
581 | EFI_DHCP4_CONFIG_DATA Dhcp4CfgData;\r | |
582 | EFI_DHCP4_MODE_DATA Dhcp4Mode;\r | |
583 | EFI_DHCP4_PACKET_OPTION *OptList[PXEBC_DHCP4_MAX_OPTION_NUM];\r | |
584 | UINT32 OptCount;\r | |
585 | EFI_STATUS Status;\r | |
586 | EFI_ARP_CONFIG_DATA ArpConfigData;\r | |
587 | EFI_PXE_BASE_CODE_IP_FILTER IpFilter;\r | |
dc361cc5 | 588 | \r |
589 | if (This == NULL) {\r | |
590 | return EFI_INVALID_PARAMETER;\r | |
591 | }\r | |
592 | \r | |
593 | Status = EFI_SUCCESS;\r | |
594 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
595 | Mode = Private->PxeBc.Mode;\r | |
596 | Dhcp4 = Private->Dhcp4;\r | |
597 | Private->Function = EFI_PXE_BASE_CODE_FUNCTION_DHCP;\r | |
598 | Private->SortOffers = SortOffers;\r | |
599 | \r | |
600 | if (!Mode->Started) {\r | |
601 | return EFI_NOT_STARTED;\r | |
602 | }\r | |
982a9eae | 603 | \r |
604 | Mode->IcmpErrorReceived = FALSE;\r | |
605 | \r | |
8730386e | 606 | //\r |
607 | // Stop Udp4Read instance\r | |
608 | //\r | |
609 | Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r | |
610 | \r | |
dc361cc5 | 611 | //\r |
612 | // Initialize the DHCP options and build the option list\r | |
613 | //\r | |
614 | OptCount = PxeBcBuildDhcpOptions (Private, OptList, TRUE);\r | |
615 | \r | |
616 | //\r | |
617 | // Set the DHCP4 config data.\r | |
434ce3fe | 618 | // The four discovery timeouts are 4, 8, 16, 32 seconds respectively.\r |
dc361cc5 | 619 | //\r |
e48e37fc | 620 | ZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA));\r |
dc361cc5 | 621 | Dhcp4CfgData.OptionCount = OptCount;\r |
622 | Dhcp4CfgData.OptionList = OptList;\r | |
623 | Dhcp4CfgData.Dhcp4Callback = PxeBcDhcpCallBack;\r | |
624 | Dhcp4CfgData.CallbackContext = Private;\r | |
434ce3fe | 625 | Dhcp4CfgData.DiscoverTryCount = 4;\r |
626 | Dhcp4CfgData.DiscoverTimeout = mPxeDhcpTimeout;\r | |
dc361cc5 | 627 | \r |
434ce3fe | 628 | Status = Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);\r |
629 | if (EFI_ERROR (Status)) {\r | |
630 | goto ON_EXIT;\r | |
631 | }\r | |
e2851998 | 632 | \r |
434ce3fe | 633 | //\r |
634 | // Zero those arrays to record the varies numbers of DHCP OFFERS.\r | |
635 | //\r | |
636 | Private->GotProxyOffer = FALSE;\r | |
637 | Private->NumOffers = 0;\r | |
638 | Private->BootpIndex = 0;\r | |
639 | ZeroMem (Private->ServerCount, sizeof (Private->ServerCount));\r | |
640 | ZeroMem (Private->ProxyIndex, sizeof (Private->ProxyIndex));\r | |
dc361cc5 | 641 | \r |
434ce3fe | 642 | Status = Dhcp4->Start (Dhcp4, NULL);\r |
cbfb9e5e | 643 | if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r |
434ce3fe | 644 | if (Status == EFI_ICMP_ERROR) {\r |
645 | Mode->IcmpErrorReceived = TRUE;\r | |
dc361cc5 | 646 | }\r |
434ce3fe | 647 | goto ON_EXIT;\r |
648 | }\r | |
dc361cc5 | 649 | \r |
434ce3fe | 650 | Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4Mode);\r |
651 | if (EFI_ERROR (Status)) {\r | |
652 | goto ON_EXIT;\r | |
653 | }\r | |
dc361cc5 | 654 | \r |
434ce3fe | 655 | ASSERT (Dhcp4Mode.State == Dhcp4Bound);\r |
dc361cc5 | 656 | \r |
434ce3fe | 657 | CopyMem (&Private->StationIp, &Dhcp4Mode.ClientAddress, sizeof (EFI_IPv4_ADDRESS));\r |
658 | CopyMem (&Private->SubnetMask, &Dhcp4Mode.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r | |
659 | CopyMem (&Private->GatewayIp, &Dhcp4Mode.RouterAddress, sizeof (EFI_IPv4_ADDRESS));\r | |
319075ff | 660 | \r |
434ce3fe | 661 | CopyMem (&Mode->StationIp, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r |
662 | CopyMem (&Mode->SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r | |
dc361cc5 | 663 | \r |
434ce3fe | 664 | //\r |
665 | // Check the selected offer to see whether BINL is required, if no or BINL is\r | |
666 | // finished, set the various Mode members.\r | |
667 | //\r | |
668 | Status = PxeBcCheckSelectedOffer (Private);\r | |
dc361cc5 | 669 | \r |
434ce3fe | 670 | ON_EXIT:\r |
dc361cc5 | 671 | if (EFI_ERROR (Status)) {\r |
672 | Dhcp4->Stop (Dhcp4);\r | |
673 | Dhcp4->Configure (Dhcp4, NULL);\r | |
674 | } else {\r | |
675 | //\r | |
676 | // Remove the previously configured option list and callback function\r | |
677 | //\r | |
e48e37fc | 678 | ZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA));\r |
dc361cc5 | 679 | Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);\r |
680 | \r | |
681 | Private->AddressIsOk = TRUE;\r | |
8d285ec0 | 682 | \r |
683 | if (!Mode->UsingIpv6) {\r | |
684 | //\r | |
685 | // If in IPv4 mode, configure the corresponding ARP with this new\r | |
686 | // station IP address.\r | |
687 | //\r | |
688 | ZeroMem (&ArpConfigData, sizeof (EFI_ARP_CONFIG_DATA));\r | |
689 | \r | |
690 | ArpConfigData.SwAddressType = 0x0800;\r | |
c9325700 | 691 | ArpConfigData.SwAddressLength = (UINT8) sizeof (EFI_IPv4_ADDRESS);\r |
8d285ec0 | 692 | ArpConfigData.StationAddress = &Private->StationIp.v4;\r |
693 | \r | |
694 | Private->Arp->Configure (Private->Arp, NULL);\r | |
695 | Private->Arp->Configure (Private->Arp, &ArpConfigData);\r | |
982a9eae | 696 | \r |
697 | //\r | |
698 | // Updated the route table. Fill the first entry.\r | |
699 | //\r | |
700 | Mode->RouteTableEntries = 1;\r | |
701 | Mode->RouteTable[0].IpAddr.Addr[0] = Private->StationIp.Addr[0] & Private->SubnetMask.Addr[0];\r | |
702 | Mode->RouteTable[0].SubnetMask.Addr[0] = Private->SubnetMask.Addr[0];\r | |
703 | Mode->RouteTable[0].GwAddr.Addr[0] = 0;\r | |
704 | \r | |
705 | //\r | |
706 | // Create the default route entry if there is a default router.\r | |
707 | //\r | |
708 | if (Private->GatewayIp.Addr[0] != 0) {\r | |
709 | Mode->RouteTableEntries = 2;\r | |
710 | Mode->RouteTable[1].IpAddr.Addr[0] = 0;\r | |
711 | Mode->RouteTable[1].SubnetMask.Addr[0] = 0;\r | |
712 | Mode->RouteTable[1].GwAddr.Addr[0] = Private->GatewayIp.Addr[0];\r | |
713 | }\r | |
8730386e | 714 | \r |
715 | //\r | |
716 | // Flush new station IP address into Udp4CfgData and Ip4ConfigData\r | |
717 | //\r | |
718 | CopyMem (&Private->Udp4CfgData.StationAddress, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r | |
719 | CopyMem (&Private->Udp4CfgData.SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r | |
720 | CopyMem (&Private->Ip4ConfigData.StationAddress, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r | |
721 | CopyMem (&Private->Ip4ConfigData.SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r | |
722 | \r | |
723 | //\r | |
724 | // Reconfigure the Ip4 instance to capture background ICMP packets with new station Ip address.\r | |
725 | //\r | |
726 | Private->Ip4->Cancel (Private->Ip4, &Private->IcmpErrorRcvToken);\r | |
727 | Private->Ip4->Configure (Private->Ip4, NULL);\r | |
728 | \r | |
729 | Status = Private->Ip4->Configure (Private->Ip4, &Private->Ip4ConfigData);\r | |
730 | if (EFI_ERROR (Status)) {\r | |
731 | goto ON_EXIT;\r | |
732 | }\r | |
733 | \r | |
734 | Status = Private->Ip4->Receive (Private->Ip4, &Private->IcmpErrorRcvToken);\r | |
735 | if (EFI_ERROR (Status)) {\r | |
736 | goto ON_EXIT;\r | |
737 | } \r | |
8d285ec0 | 738 | }\r |
dc361cc5 | 739 | }\r |
740 | \r | |
357af285 | 741 | Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r |
c82291bc | 742 | \r |
8730386e | 743 | //\r |
744 | // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP \r | |
745 | // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.\r | |
746 | //\r | |
747 | ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));\r | |
748 | IpFilter.Filters = EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP;\r | |
749 | This->SetIpFilter (This, &IpFilter);\r | |
750 | \r | |
dc361cc5 | 751 | return Status;\r |
752 | }\r | |
753 | \r | |
754 | \r | |
e2851998 | 755 | /**\r |
f737cfb9 | 756 | Attempts to complete the PXE Boot Server and/or boot image discovery sequence.\r |
757 | \r | |
758 | This function attempts to complete the PXE Boot Server and/or boot image discovery\r | |
759 | sequence. If this sequence is completed, then EFI_SUCCESS is returned, and the\r | |
760 | PxeDiscoverValid, PxeDiscover, PxeReplyReceived, and PxeReply fields of the\r | |
761 | EFI_PXE_BASE_CODE_MODE structure are filled in. If UseBis is TRUE, then the\r | |
762 | PxeBisReplyReceived and PxeBisReply fields of the EFI_PXE_BASE_CODE_MODE structure\r | |
763 | will also be filled in. If UseBis is FALSE, then PxeBisReplyValid will be set to FALSE.\r | |
764 | In the structure referenced by parameter Info, the PXE Boot Server list, SrvList[],\r | |
765 | has two uses: It is the Boot Server IP address list used for unicast discovery\r | |
766 | (if the UseUCast field is TRUE), and it is the list used for Boot Server verification\r | |
767 | (if the MustUseList field is TRUE). Also, if the MustUseList field in that structure\r | |
768 | is TRUE and the AcceptAnyResponse field in the SrvList[] array is TRUE, any Boot\r | |
769 | Server reply of that type will be accepted. If the AcceptAnyResponse field is\r | |
770 | FALSE, only responses from Boot Servers with matching IP addresses will be accepted.\r | |
771 | This function can take at least 10 seconds to timeout and return control to the\r | |
772 | caller. If the Discovery sequence does not complete, then EFI_TIMEOUT will be\r | |
773 | returned. Please see the Preboot Execution Environment (PXE) Specification for\r | |
774 | additional details on the implementation of the Discovery sequence.\r | |
775 | If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,\r | |
776 | then the Discovery sequence is stopped and EFI_ABORTED will be returned.\r | |
e2851998 | 777 | \r |
f737cfb9 | 778 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r |
779 | @param Type The type of bootstrap to perform.\r | |
780 | @param Layer Pointer to the boot server layer number to discover, which must be\r | |
e2851998 | 781 | PXE_BOOT_LAYER_INITIAL when a new server type is being\r |
782 | discovered.\r | |
783 | @param UseBis TRUE if Boot Integrity Services are to be used. FALSE otherwise.\r | |
f737cfb9 | 784 | @param Info Pointer to a data structure that contains additional information on the\r |
e2851998 | 785 | type of discovery operation that is to be performed.\r |
786 | \r | |
f737cfb9 | 787 | @retval EFI_SUCCESS The Discovery sequence has been completed.\r |
788 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
e2851998 | 789 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r |
790 | @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r | |
f737cfb9 | 791 | @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete Discovery.\r |
792 | @retval EFI_ABORTED The callback function aborted the Discovery sequence.\r | |
793 | @retval EFI_TIMEOUT The Discovery sequence timed out.\r | |
794 | @retval EFI_ICMP_ERROR An ICMP error packet was received during the PXE discovery\r | |
e2851998 | 795 | session.\r |
796 | \r | |
dc361cc5 | 797 | **/\r |
798 | EFI_STATUS\r | |
799 | EFIAPI\r | |
800 | EfiPxeBcDiscover (\r | |
801 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r | |
802 | IN UINT16 Type,\r | |
803 | IN UINT16 *Layer,\r | |
804 | IN BOOLEAN UseBis,\r | |
805 | IN EFI_PXE_BASE_CODE_DISCOVER_INFO *Info OPTIONAL\r | |
806 | )\r | |
807 | {\r | |
808 | PXEBC_PRIVATE_DATA *Private;\r | |
809 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
810 | EFI_PXE_BASE_CODE_DISCOVER_INFO DefaultInfo;\r | |
29a4f92d | 811 | EFI_PXE_BASE_CODE_DISCOVER_INFO *CreatedInfo;\r |
dc361cc5 | 812 | EFI_PXE_BASE_CODE_SRVLIST *SrvList;\r |
813 | EFI_PXE_BASE_CODE_SRVLIST DefaultSrvList;\r | |
814 | PXEBC_CACHED_DHCP4_PACKET *Packet;\r | |
f737cfb9 | 815 | PXEBC_VENDOR_OPTION *VendorOpt;\r |
dc361cc5 | 816 | UINT16 Index;\r |
817 | EFI_STATUS Status;\r | |
818 | PXEBC_BOOT_SVR_ENTRY *BootSvrEntry;\r | |
8730386e | 819 | EFI_PXE_BASE_CODE_IP_FILTER IpFilter;\r |
dc361cc5 | 820 | \r |
821 | if (This == NULL) {\r | |
822 | return EFI_INVALID_PARAMETER;\r | |
823 | }\r | |
824 | \r | |
825 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
826 | Mode = Private->PxeBc.Mode;\r | |
827 | BootSvrEntry = NULL;\r | |
828 | SrvList = NULL;\r | |
29a4f92d | 829 | CreatedInfo = NULL;\r |
dc361cc5 | 830 | Status = EFI_DEVICE_ERROR;\r |
831 | Private->Function = EFI_PXE_BASE_CODE_FUNCTION_DISCOVER;\r | |
832 | \r | |
833 | if (!Private->AddressIsOk) {\r | |
834 | return EFI_INVALID_PARAMETER;\r | |
835 | }\r | |
836 | \r | |
837 | if (!Mode->Started) {\r | |
838 | return EFI_NOT_STARTED;\r | |
839 | }\r | |
840 | \r | |
8730386e | 841 | //\r |
842 | // Stop Udp4Read instance\r | |
843 | //\r | |
844 | Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r | |
845 | \r | |
982a9eae | 846 | Mode->IcmpErrorReceived = FALSE;\r |
847 | \r | |
dc361cc5 | 848 | //\r |
849 | // If layer isn't EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL,\r | |
850 | // use the previous setting;\r | |
851 | // If info isn't offered,\r | |
852 | // use the cached DhcpAck and ProxyOffer packets.\r | |
853 | //\r | |
f402291b | 854 | ZeroMem (&DefaultInfo, sizeof (EFI_PXE_BASE_CODE_DISCOVER_INFO));\r |
dc361cc5 | 855 | if (*Layer != EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL) {\r |
856 | \r | |
857 | if (!Mode->PxeDiscoverValid || !Mode->PxeReplyReceived || (!Mode->PxeBisReplyReceived && UseBis)) {\r | |
858 | \r | |
8730386e | 859 | Status = EFI_INVALID_PARAMETER;\r |
860 | goto ON_EXIT; \r | |
dc361cc5 | 861 | }\r |
862 | \r | |
863 | DefaultInfo.IpCnt = 1;\r | |
864 | DefaultInfo.UseUCast = TRUE;\r | |
865 | \r | |
866 | DefaultSrvList.Type = Type;\r | |
867 | DefaultSrvList.AcceptAnyResponse = FALSE;\r | |
868 | DefaultSrvList.IpAddr.Addr[0] = Private->ServerIp.Addr[0];\r | |
869 | \r | |
870 | SrvList = &DefaultSrvList;\r | |
871 | Info = &DefaultInfo;\r | |
872 | } else if (Info == NULL) {\r | |
873 | //\r | |
874 | // Create info by the cached packet before\r | |
875 | //\r | |
876 | Packet = (Mode->ProxyOfferReceived) ? &Private->ProxyOffer : &Private->Dhcp4Ack;\r | |
877 | VendorOpt = &Packet->PxeVendorOption;\r | |
878 | \r | |
879 | if (!Mode->DhcpAckReceived || !IS_VALID_DISCOVER_VENDOR_OPTION (VendorOpt->BitMap)) {\r | |
880 | //\r | |
881 | // Address is not acquired or no discovery options.\r | |
882 | //\r | |
8730386e | 883 | Status = EFI_INVALID_PARAMETER;\r |
884 | goto ON_EXIT; \r | |
dc361cc5 | 885 | }\r |
886 | \r | |
887 | DefaultInfo.UseMCast = (BOOLEAN)!IS_DISABLE_MCAST_DISCOVER (VendorOpt->DiscoverCtrl);\r | |
888 | DefaultInfo.UseBCast = (BOOLEAN)!IS_DISABLE_BCAST_DISCOVER (VendorOpt->DiscoverCtrl);\r | |
889 | DefaultInfo.MustUseList = (BOOLEAN) IS_ENABLE_USE_SERVER_LIST (VendorOpt->DiscoverCtrl);\r | |
890 | DefaultInfo.UseUCast = DefaultInfo.MustUseList;\r | |
891 | \r | |
892 | if (DefaultInfo.UseMCast) {\r | |
893 | //\r | |
894 | // Get the multicast discover ip address from vendor option.\r | |
895 | //\r | |
f737cfb9 | 896 | CopyMem (\r |
e2851998 | 897 | &DefaultInfo.ServerMCastIp.Addr,\r |
898 | &VendorOpt->DiscoverMcastIp,\r | |
f737cfb9 | 899 | sizeof (EFI_IPv4_ADDRESS)\r |
900 | );\r | |
dc361cc5 | 901 | }\r |
902 | \r | |
903 | DefaultInfo.IpCnt = 0;\r | |
29a4f92d | 904 | Info = &DefaultInfo;\r |
905 | SrvList = Info->SrvList;\r | |
dc361cc5 | 906 | \r |
907 | if (DefaultInfo.MustUseList) {\r | |
908 | BootSvrEntry = VendorOpt->BootSvr;\r | |
909 | Status = EFI_INVALID_PARAMETER;\r | |
910 | \r | |
911 | while (((UINT8) (BootSvrEntry - VendorOpt->BootSvr)) < VendorOpt->BootSvrLen) {\r | |
912 | \r | |
913 | if (BootSvrEntry->Type == HTONS (Type)) {\r | |
914 | Status = EFI_SUCCESS;\r | |
915 | break;\r | |
916 | }\r | |
917 | \r | |
918 | BootSvrEntry = GET_NEXT_BOOT_SVR_ENTRY (BootSvrEntry);\r | |
919 | }\r | |
920 | \r | |
921 | if (EFI_ERROR (Status)) {\r | |
8730386e | 922 | goto ON_EXIT;\r |
dc361cc5 | 923 | }\r |
924 | \r | |
925 | DefaultInfo.IpCnt = BootSvrEntry->IpCnt;\r | |
29a4f92d | 926 | \r |
927 | if (DefaultInfo.IpCnt >= 1) {\r | |
928 | CreatedInfo = AllocatePool (sizeof (DefaultInfo) + (DefaultInfo.IpCnt - 1) * sizeof (*SrvList));\r | |
929 | if (CreatedInfo == NULL) {\r | |
8730386e | 930 | Status = EFI_OUT_OF_RESOURCES;\r |
931 | goto ON_EXIT;\r | |
932 | \r | |
29a4f92d | 933 | } \r |
934 | \r | |
935 | CopyMem (CreatedInfo, &DefaultInfo, sizeof (DefaultInfo));\r | |
936 | Info = CreatedInfo;\r | |
937 | SrvList = Info->SrvList;\r | |
938 | }\r | |
939 | \r | |
940 | for (Index = 0; Index < DefaultInfo.IpCnt; Index++) {\r | |
941 | CopyMem (&SrvList[Index].IpAddr, &BootSvrEntry->IpAddr[Index], sizeof (EFI_IPv4_ADDRESS));\r | |
942 | SrvList[Index].AcceptAnyResponse = FALSE;\r | |
943 | SrvList[Index].Type = BootSvrEntry->Type;\r | |
944 | }\r | |
dc361cc5 | 945 | }\r |
946 | \r | |
dc361cc5 | 947 | } else {\r |
948 | \r | |
949 | SrvList = Info->SrvList;\r | |
950 | \r | |
951 | if (!SrvList[0].AcceptAnyResponse) {\r | |
952 | \r | |
953 | for (Index = 1; Index < Info->IpCnt; Index++) {\r | |
954 | if (SrvList[Index].AcceptAnyResponse) {\r | |
955 | break;\r | |
956 | }\r | |
957 | }\r | |
958 | \r | |
959 | if (Index != Info->IpCnt) {\r | |
8730386e | 960 | Status = EFI_INVALID_PARAMETER;\r |
961 | goto ON_EXIT; \r | |
dc361cc5 | 962 | }\r |
963 | }\r | |
964 | }\r | |
965 | \r | |
966 | if ((!Info->UseUCast && !Info->UseBCast && !Info->UseMCast) || (Info->MustUseList && Info->IpCnt == 0)) {\r | |
967 | \r | |
8730386e | 968 | Status = EFI_INVALID_PARAMETER;\r |
969 | goto ON_EXIT;\r | |
dc361cc5 | 970 | }\r |
971 | //\r | |
972 | // Execute discover by UniCast/BroadCast/MultiCast\r | |
973 | //\r | |
974 | if (Info->UseUCast) {\r | |
975 | \r | |
976 | for (Index = 0; Index < Info->IpCnt; Index++) {\r | |
977 | \r | |
978 | if (BootSvrEntry == NULL) {\r | |
979 | Private->ServerIp.Addr[0] = SrvList[Index].IpAddr.Addr[0];\r | |
980 | } else {\r | |
f737cfb9 | 981 | CopyMem (\r |
e2851998 | 982 | &Private->ServerIp,\r |
983 | &BootSvrEntry->IpAddr[Index],\r | |
f737cfb9 | 984 | sizeof (EFI_IPv4_ADDRESS)\r |
985 | );\r | |
dc361cc5 | 986 | }\r |
987 | \r | |
988 | Status = PxeBcDiscvBootService (\r | |
989 | Private,\r | |
990 | Type,\r | |
991 | Layer,\r | |
992 | UseBis,\r | |
993 | &SrvList[Index].IpAddr,\r | |
994 | 0,\r | |
995 | NULL,\r | |
996 | TRUE,\r | |
997 | &Private->PxeReply.Packet.Ack\r | |
998 | );\r | |
29a4f92d | 999 | if (!EFI_ERROR (Status)) {\r |
1000 | break;\r | |
1001 | } \r | |
dc361cc5 | 1002 | }\r |
1003 | \r | |
1004 | } else if (Info->UseMCast) {\r | |
1005 | \r | |
1006 | Status = PxeBcDiscvBootService (\r | |
1007 | Private,\r | |
1008 | Type,\r | |
1009 | Layer,\r | |
1010 | UseBis,\r | |
1011 | &Info->ServerMCastIp,\r | |
1012 | 0,\r | |
1013 | NULL,\r | |
1014 | TRUE,\r | |
1015 | &Private->PxeReply.Packet.Ack\r | |
1016 | );\r | |
1017 | \r | |
1018 | } else if (Info->UseBCast) {\r | |
1019 | \r | |
1020 | Status = PxeBcDiscvBootService (\r | |
1021 | Private,\r | |
1022 | Type,\r | |
1023 | Layer,\r | |
1024 | UseBis,\r | |
1025 | NULL,\r | |
1026 | Info->IpCnt,\r | |
1027 | SrvList,\r | |
1028 | TRUE,\r | |
1029 | &Private->PxeReply.Packet.Ack\r | |
1030 | );\r | |
1031 | }\r | |
1032 | \r | |
1033 | if (EFI_ERROR (Status) || !Mode->PxeReplyReceived || (!Mode->PxeBisReplyReceived && UseBis)) {\r | |
982a9eae | 1034 | if (Status == EFI_ICMP_ERROR) {\r |
1035 | Mode->IcmpErrorReceived = TRUE;\r | |
1036 | } else {\r | |
1037 | Status = EFI_DEVICE_ERROR;\r | |
1038 | }\r | |
357af285 | 1039 | goto ON_EXIT;\r |
dc361cc5 | 1040 | } else {\r |
1041 | PxeBcParseCachedDhcpPacket (&Private->PxeReply);\r | |
1042 | }\r | |
1043 | \r | |
1044 | if (Mode->PxeBisReplyReceived) {\r | |
f737cfb9 | 1045 | CopyMem (\r |
e2851998 | 1046 | &Private->ServerIp,\r |
1047 | &Mode->PxeReply.Dhcpv4.BootpSiAddr,\r | |
f737cfb9 | 1048 | sizeof (EFI_IPv4_ADDRESS)\r |
1049 | );\r | |
dc361cc5 | 1050 | }\r |
1051 | \r | |
29a4f92d | 1052 | if (CreatedInfo != NULL) {\r |
1053 | FreePool (CreatedInfo);\r | |
1054 | }\r | |
8730386e | 1055 | \r |
1056 | ON_EXIT:\r | |
1057 | \r | |
357af285 | 1058 | Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r |
c82291bc | 1059 | \r |
8730386e | 1060 | //\r |
1061 | // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP \r | |
1062 | // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.\r | |
1063 | //\r | |
1064 | ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));\r | |
1065 | IpFilter.Filters = EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP;\r | |
1066 | This->SetIpFilter (This, &IpFilter);\r | |
29a4f92d | 1067 | \r |
dc361cc5 | 1068 | return Status;\r |
1069 | }\r | |
1070 | \r | |
1071 | \r | |
e2851998 | 1072 | /**\r |
f737cfb9 | 1073 | Used to perform TFTP and MTFTP services.\r |
1074 | \r | |
1075 | This function is used to perform TFTP and MTFTP services. This includes the\r | |
1076 | TFTP operations to get the size of a file, read a directory, read a file, and\r | |
1077 | write a file. It also includes the MTFTP operations to get the size of a file,\r | |
1078 | read a directory, and read a file. The type of operation is specified by Operation.\r | |
1079 | If the callback function that is invoked during the TFTP/MTFTP operation does\r | |
1080 | not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will\r | |
1081 | be returned.\r | |
1082 | For read operations, the return data will be placed in the buffer specified by\r | |
1083 | BufferPtr. If BufferSize is too small to contain the entire downloaded file,\r | |
1084 | then EFI_BUFFER_TOO_SMALL will be returned and BufferSize will be set to zero\r | |
1085 | or the size of the requested file (the size of the requested file is only returned\r | |
1086 | if the TFTP server supports TFTP options). If BufferSize is large enough for the\r | |
1087 | read operation, then BufferSize will be set to the size of the downloaded file,\r | |
1088 | and EFI_SUCCESS will be returned. Applications using the PxeBc.Mtftp() services\r | |
1089 | should use the get-file-size operations to determine the size of the downloaded\r | |
1090 | file prior to using the read-file operations-especially when downloading large\r | |
1091 | (greater than 64 MB) files-instead of making two calls to the read-file operation.\r | |
1092 | Following this recommendation will save time if the file is larger than expected\r | |
1093 | and the TFTP server does not support TFTP option extensions. Without TFTP option\r | |
1094 | extension support, the client has to download the entire file, counting and discarding\r | |
1095 | the received packets, to determine the file size.\r | |
1096 | For write operations, the data to be sent is in the buffer specified by BufferPtr.\r | |
1097 | BufferSize specifies the number of bytes to send. If the write operation completes\r | |
1098 | successfully, then EFI_SUCCESS will be returned.\r | |
1099 | For TFTP "get file size" operations, the size of the requested file or directory\r | |
1100 | is returned in BufferSize, and EFI_SUCCESS will be returned. If the TFTP server\r | |
1101 | does not support options, the file will be downloaded into a bit bucket and the\r | |
1102 | length of the downloaded file will be returned. For MTFTP "get file size" operations,\r | |
1103 | if the MTFTP server does not support the "get file size" option, EFI_UNSUPPORTED\r | |
1104 | will be returned.\r | |
1105 | This function can take up to 10 seconds to timeout and return control to the caller.\r | |
1106 | If the TFTP sequence does not complete, EFI_TIMEOUT will be returned.\r | |
1107 | If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,\r | |
1108 | then the TFTP sequence is stopped and EFI_ABORTED will be returned.\r | |
1109 | The format of the data returned from a TFTP read directory operation is a null-terminated\r | |
1110 | filename followed by a null-terminated information string, of the form\r | |
1111 | "size year-month-day hour:minute:second" (i.e. %d %d-%d-%d %d:%d:%f - note that\r | |
1112 | the seconds field can be a decimal number), where the date and time are UTC. For\r | |
1113 | an MTFTP read directory command, there is additionally a null-terminated multicast\r | |
1114 | IP address preceding the filename of the form %d.%d.%d.%d for IP v4. The final\r | |
1115 | entry is itself null-terminated, so that the final information string is terminated\r | |
1116 | with two null octets.\r | |
e2851998 | 1117 | \r |
f737cfb9 | 1118 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r |
1119 | @param Operation The type of operation to perform.\r | |
e2851998 | 1120 | @param BufferPtr A pointer to the data buffer.\r |
f737cfb9 | 1121 | @param Overwrite Only used on write file operations. TRUE if a file on a remote server can\r |
e2851998 | 1122 | be overwritten.\r |
f737cfb9 | 1123 | @param BufferSize For get-file-size operations, *BufferSize returns the size of the\r |
e2851998 | 1124 | requested file.\r |
f737cfb9 | 1125 | @param BlockSize The requested block size to be used during a TFTP transfer.\r |
1126 | @param ServerIp The TFTP / MTFTP server IP address.\r | |
1127 | @param Filename A Null-terminated ASCII string that specifies a directory name or a file\r | |
e2851998 | 1128 | name.\r |
f737cfb9 | 1129 | @param Info Pointer to the MTFTP information.\r |
e2851998 | 1130 | @param DontUseBuffer Set to FALSE for normal TFTP and MTFTP read file operation.\r |
1131 | \r | |
f737cfb9 | 1132 | @retval EFI_SUCCESS The TFTP/MTFTP operation was completed.\r |
1133 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
e2851998 | 1134 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r |
1135 | @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r | |
1136 | @retval EFI_BUFFER_TOO_SMALL The buffer is not large enough to complete the read operation.\r | |
f737cfb9 | 1137 | @retval EFI_ABORTED The callback function aborted the TFTP/MTFTP operation.\r |
1138 | @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.\r | |
1139 | @retval EFI_ICMP_ERROR An ICMP error packet was received during the MTFTP session.\r | |
1140 | @retval EFI_TFTP_ERROR A TFTP error packet was received during the MTFTP session.\r | |
e2851998 | 1141 | \r |
dc361cc5 | 1142 | **/\r |
1143 | EFI_STATUS\r | |
1144 | EFIAPI\r | |
1145 | EfiPxeBcMtftp (\r | |
1146 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r | |
1147 | IN EFI_PXE_BASE_CODE_TFTP_OPCODE Operation,\r | |
1148 | IN OUT VOID *BufferPtr,\r | |
1149 | IN BOOLEAN Overwrite,\r | |
1150 | IN OUT UINT64 *BufferSize,\r | |
1151 | IN UINTN *BlockSize OPTIONAL,\r | |
1152 | IN EFI_IP_ADDRESS *ServerIp,\r | |
1153 | IN UINT8 *Filename,\r | |
1154 | IN EFI_PXE_BASE_CODE_MTFTP_INFO *Info OPTIONAL,\r | |
1155 | IN BOOLEAN DontUseBuffer\r | |
1156 | )\r | |
1157 | {\r | |
8730386e | 1158 | PXEBC_PRIVATE_DATA *Private;\r |
1159 | EFI_MTFTP4_CONFIG_DATA Mtftp4Config;\r | |
1160 | EFI_STATUS Status;\r | |
1161 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
1162 | EFI_MAC_ADDRESS TempMacAddr;\r | |
1163 | EFI_PXE_BASE_CODE_IP_FILTER IpFilter;\r | |
dc361cc5 | 1164 | \r |
f6b7393c | 1165 | if ((This == NULL) ||\r |
1166 | (Filename == NULL) ||\r | |
1167 | (BufferSize == NULL) ||\r | |
01b5ac88 FS |
1168 | ((ServerIp == NULL) || \r |
1169 | (IP4_IS_UNSPECIFIED (NTOHL (ServerIp->Addr[0])) || \r | |
1170 | IP4_IS_LOCAL_BROADCAST (NTOHL (ServerIp->Addr[0])))) ||\r | |
f6b7393c | 1171 | ((BufferPtr == NULL) && DontUseBuffer) ||\r |
dc361cc5 | 1172 | ((BlockSize != NULL) && (*BlockSize < 512))) {\r |
1173 | \r | |
1174 | return EFI_INVALID_PARAMETER;\r | |
1175 | }\r | |
1176 | \r | |
1177 | Status = EFI_DEVICE_ERROR;\r | |
1178 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
982a9eae | 1179 | Mode = &Private->Mode;\r |
1180 | \r | |
1181 | if (!Mode->AutoArp) {\r | |
1182 | //\r | |
1183 | // If AutoArp is set false, check arp cache\r | |
1184 | //\r | |
1185 | UpdateArpCache (This);\r | |
1186 | if (!FindInArpCache (Mode, &ServerIp->v4, &TempMacAddr)) {\r | |
1187 | return EFI_DEVICE_ERROR;\r | |
1188 | }\r | |
1189 | }\r | |
1190 | \r | |
8730386e | 1191 | //\r |
1192 | // Stop Udp4Read instance\r | |
1193 | //\r | |
1194 | Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r | |
1195 | \r | |
982a9eae | 1196 | Mode->TftpErrorReceived = FALSE;\r |
1197 | Mode->IcmpErrorReceived = FALSE;\r | |
dc361cc5 | 1198 | \r |
1199 | Mtftp4Config.UseDefaultSetting = FALSE;\r | |
1200 | Mtftp4Config.TimeoutValue = PXEBC_MTFTP_TIMEOUT;\r | |
1201 | Mtftp4Config.TryCount = PXEBC_MTFTP_RETRIES;\r | |
1202 | \r | |
f737cfb9 | 1203 | CopyMem (\r |
e2851998 | 1204 | &Mtftp4Config.StationIp,\r |
1205 | &Private->StationIp,\r | |
f737cfb9 | 1206 | sizeof (EFI_IPv4_ADDRESS)\r |
1207 | );\r | |
1208 | CopyMem (\r | |
e2851998 | 1209 | &Mtftp4Config.SubnetMask,\r |
1210 | &Private->SubnetMask,\r | |
f737cfb9 | 1211 | sizeof (EFI_IPv4_ADDRESS)\r |
1212 | );\r | |
1213 | CopyMem (\r | |
e2851998 | 1214 | &Mtftp4Config.GatewayIp,\r |
1215 | &Private->GatewayIp,\r | |
f737cfb9 | 1216 | sizeof (EFI_IPv4_ADDRESS)\r |
1217 | );\r | |
1218 | CopyMem (\r | |
e2851998 | 1219 | &Mtftp4Config.ServerIp,\r |
1220 | ServerIp,\r | |
f737cfb9 | 1221 | sizeof (EFI_IPv4_ADDRESS)\r |
1222 | );\r | |
dc361cc5 | 1223 | \r |
1224 | switch (Operation) {\r | |
1225 | \r | |
1226 | case EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE:\r | |
1227 | \r | |
1228 | Status = PxeBcTftpGetFileSize (\r | |
1229 | Private,\r | |
1230 | &Mtftp4Config,\r | |
1231 | Filename,\r | |
1232 | BlockSize,\r | |
1233 | BufferSize\r | |
1234 | );\r | |
1235 | \r | |
dc361cc5 | 1236 | break;\r |
1237 | \r | |
1238 | case EFI_PXE_BASE_CODE_TFTP_READ_FILE:\r | |
1239 | \r | |
1240 | Status = PxeBcTftpReadFile (\r | |
1241 | Private,\r | |
1242 | &Mtftp4Config,\r | |
1243 | Filename,\r | |
1244 | BlockSize,\r | |
1245 | BufferPtr,\r | |
1246 | BufferSize,\r | |
1247 | DontUseBuffer\r | |
1248 | );\r | |
1249 | \r | |
1250 | break;\r | |
1251 | \r | |
1252 | case EFI_PXE_BASE_CODE_TFTP_WRITE_FILE:\r | |
1253 | \r | |
1254 | Status = PxeBcTftpWriteFile (\r | |
1255 | Private,\r | |
1256 | &Mtftp4Config,\r | |
1257 | Filename,\r | |
1258 | Overwrite,\r | |
1259 | BlockSize,\r | |
1260 | BufferPtr,\r | |
1261 | BufferSize\r | |
1262 | );\r | |
1263 | \r | |
1264 | break;\r | |
1265 | \r | |
1266 | case EFI_PXE_BASE_CODE_TFTP_READ_DIRECTORY:\r | |
1267 | \r | |
1268 | Status = PxeBcTftpReadDirectory (\r | |
1269 | Private,\r | |
1270 | &Mtftp4Config,\r | |
1271 | Filename,\r | |
1272 | BlockSize,\r | |
1273 | BufferPtr,\r | |
1274 | BufferSize,\r | |
1275 | DontUseBuffer\r | |
1276 | );\r | |
1277 | \r | |
1278 | break;\r | |
1279 | \r | |
1280 | case EFI_PXE_BASE_CODE_MTFTP_GET_FILE_SIZE:\r | |
1281 | case EFI_PXE_BASE_CODE_MTFTP_READ_FILE:\r | |
1282 | case EFI_PXE_BASE_CODE_MTFTP_READ_DIRECTORY:\r | |
1283 | Status = EFI_UNSUPPORTED;\r | |
1284 | break;\r | |
1285 | \r | |
1286 | default:\r | |
1287 | \r | |
1288 | Status = EFI_INVALID_PARAMETER;\r | |
1289 | break;\r | |
1290 | }\r | |
1291 | \r | |
982a9eae | 1292 | if (Status == EFI_ICMP_ERROR) {\r |
1293 | Mode->IcmpErrorReceived = TRUE;\r | |
1294 | }\r | |
1295 | \r | |
0bc17488 | 1296 | if (EFI_ERROR (Status)) {\r |
357af285 | 1297 | goto ON_EXIT;\r |
0bc17488 | 1298 | }\r |
1299 | \r | |
357af285 | 1300 | ON_EXIT:\r |
1301 | Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r | |
8730386e | 1302 | //\r |
1303 | // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP \r | |
1304 | // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.\r | |
1305 | //\r | |
1306 | ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));\r | |
1307 | IpFilter.Filters = EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP;\r | |
1308 | This->SetIpFilter (This, &IpFilter);\r | |
1309 | \r | |
dc361cc5 | 1310 | return Status;\r |
1311 | }\r | |
1312 | \r | |
1313 | \r | |
e2851998 | 1314 | /**\r |
f737cfb9 | 1315 | Writes a UDP packet to the network interface.\r |
1316 | \r | |
1317 | This function writes a UDP packet specified by the (optional HeaderPtr and)\r | |
1318 | BufferPtr parameters to the network interface. The UDP header is automatically\r | |
1319 | built by this routine. It uses the parameters OpFlags, DestIp, DestPort, GatewayIp,\r | |
1320 | SrcIp, and SrcPort to build this header. If the packet is successfully built and\r | |
1321 | transmitted through the network interface, then EFI_SUCCESS will be returned.\r | |
1322 | If a timeout occurs during the transmission of the packet, then EFI_TIMEOUT will\r | |
1323 | be returned. If an ICMP error occurs during the transmission of the packet, then\r | |
1324 | the IcmpErrorReceived field is set to TRUE, the IcmpError field is filled in and\r | |
1325 | EFI_ICMP_ERROR will be returned. If the Callback Protocol does not return\r | |
1326 | EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will be returned.\r | |
e2851998 | 1327 | \r |
f737cfb9 | 1328 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r |
e2851998 | 1329 | @param OpFlags The UDP operation flags.\r |
f737cfb9 | 1330 | @param DestIp The destination IP address.\r |
e2851998 | 1331 | @param DestPort The destination UDP port number.\r |
1332 | @param GatewayIp The gateway IP address.\r | |
f737cfb9 | 1333 | @param SrcIp The source IP address.\r |
1334 | @param SrcPort The source UDP port number.\r | |
1335 | @param HeaderSize An optional field which may be set to the length of a header at\r | |
e2851998 | 1336 | HeaderPtr to be prefixed to the data at BufferPtr.\r |
f737cfb9 | 1337 | @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the\r |
e2851998 | 1338 | data at BufferPtr.\r |
f737cfb9 | 1339 | @param BufferSize A pointer to the size of the data at BufferPtr.\r |
1340 | @param BufferPtr A pointer to the data to be written.\r | |
e2851998 | 1341 | \r |
f737cfb9 | 1342 | @retval EFI_SUCCESS The UDP Write operation was completed.\r |
1343 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
e2851998 | 1344 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r |
1345 | @retval EFI_BAD_BUFFER_SIZE The buffer is too long to be transmitted.\r | |
f737cfb9 | 1346 | @retval EFI_ABORTED The callback function aborted the UDP Write operation.\r |
1347 | @retval EFI_TIMEOUT The UDP Write operation timed out.\r | |
e2851998 | 1348 | @retval EFI_ICMP_ERROR An ICMP error packet was received during the UDP write session.\r |
1349 | \r | |
dc361cc5 | 1350 | **/\r |
1351 | EFI_STATUS\r | |
1352 | EFIAPI\r | |
1353 | EfiPxeBcUdpWrite (\r | |
1354 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r | |
1355 | IN UINT16 OpFlags,\r | |
1356 | IN EFI_IP_ADDRESS *DestIp,\r | |
1357 | IN EFI_PXE_BASE_CODE_UDP_PORT *DestPort,\r | |
1358 | IN EFI_IP_ADDRESS *GatewayIp OPTIONAL,\r | |
1359 | IN EFI_IP_ADDRESS *SrcIp OPTIONAL,\r | |
1360 | IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,\r | |
1361 | IN UINTN *HeaderSize OPTIONAL,\r | |
1362 | IN VOID *HeaderPtr OPTIONAL,\r | |
1363 | IN UINTN *BufferSize,\r | |
1364 | IN VOID *BufferPtr\r | |
1365 | )\r | |
1366 | {\r | |
1367 | PXEBC_PRIVATE_DATA *Private;\r | |
1368 | EFI_UDP4_PROTOCOL *Udp4;\r | |
1369 | EFI_UDP4_COMPLETION_TOKEN Token;\r | |
1370 | EFI_UDP4_TRANSMIT_DATA *Udp4TxData;\r | |
1371 | UINT32 FragCount;\r | |
1372 | UINT32 DataLength;\r | |
1373 | EFI_UDP4_SESSION_DATA Udp4Session;\r | |
1374 | EFI_STATUS Status;\r | |
1375 | BOOLEAN IsDone;\r | |
982a9eae | 1376 | EFI_PXE_BASE_CODE_MODE *Mode;\r |
1377 | EFI_MAC_ADDRESS TempMacAddr;\r | |
dc361cc5 | 1378 | \r |
1379 | IsDone = FALSE;\r | |
1380 | \r | |
1381 | if ((This == NULL) || (DestIp == NULL) || (DestPort == NULL)) {\r | |
1382 | return EFI_INVALID_PARAMETER;\r | |
1383 | }\r | |
1384 | \r | |
01b5ac88 | 1385 | if ((GatewayIp != NULL) && (IP4_IS_UNSPECIFIED (NTOHL (GatewayIp->Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (GatewayIp->Addr[0])))) {\r |
dc361cc5 | 1386 | //\r |
1387 | // Gateway is provided but it's not a unicast IP address.\r | |
1388 | //\r | |
1389 | return EFI_INVALID_PARAMETER;\r | |
1390 | }\r | |
1391 | \r | |
1392 | if ((HeaderSize != NULL) && ((*HeaderSize == 0) || (HeaderPtr == NULL))) {\r | |
1393 | //\r | |
1394 | // The HeaderSize ptr isn't NULL and: 1. the value is zero; or 2. the HeaderPtr\r | |
1395 | // is NULL.\r | |
1396 | //\r | |
1397 | return EFI_INVALID_PARAMETER;\r | |
1398 | }\r | |
1399 | \r | |
1400 | if ((BufferSize == NULL) || ((*BufferSize != 0) && (BufferPtr == NULL))) {\r | |
1401 | return EFI_INVALID_PARAMETER;\r | |
1402 | }\r | |
1403 | \r | |
1404 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
8792362f | 1405 | Udp4 = Private->Udp4Write;\r |
982a9eae | 1406 | Mode = &Private->Mode;\r |
8792362f | 1407 | if (!Mode->Started) {\r |
1408 | return EFI_NOT_STARTED;\r | |
1409 | }\r | |
dc361cc5 | 1410 | \r |
1411 | if (!Private->AddressIsOk && (SrcIp == NULL)) {\r | |
1412 | return EFI_INVALID_PARAMETER;\r | |
1413 | }\r | |
1414 | \r | |
982a9eae | 1415 | if (!Mode->AutoArp) {\r |
1416 | //\r | |
1417 | // If AutoArp is set false, check arp cache\r | |
1418 | //\r | |
1419 | UpdateArpCache (This);\r | |
1420 | if (!FindInArpCache (Mode, &DestIp->v4, &TempMacAddr)) {\r | |
1421 | return EFI_DEVICE_ERROR;\r | |
1422 | }\r | |
1423 | }\r | |
1424 | \r | |
1425 | Mode->IcmpErrorReceived = FALSE;\r | |
1426 | \r | |
8792362f | 1427 | if ((Private->CurrentUdpSrcPort == 0) ||\r |
f737cfb9 | 1428 | ((SrcPort != NULL) && (*SrcPort != Private->CurrentUdpSrcPort))) {\r |
8792362f | 1429 | //\r |
1430 | // Port is changed, (re)configure the Udp4Write instance\r | |
1431 | //\r | |
1432 | if (SrcPort != NULL) {\r | |
1433 | Private->CurrentUdpSrcPort = *SrcPort;\r | |
dc361cc5 | 1434 | }\r |
dc361cc5 | 1435 | }\r |
1436 | \r | |
2e4c2a04 | 1437 | Status = PxeBcConfigureUdpWriteInstance (\r |
1438 | Udp4,\r | |
1439 | &Private->StationIp.v4,\r | |
1440 | &Private->SubnetMask.v4,\r | |
1441 | &Private->GatewayIp.v4,\r | |
60de3c19 FS |
1442 | &Private->CurrentUdpSrcPort,\r |
1443 | Private->Mode.TTL,\r | |
1444 | Private->Mode.ToS\r | |
2e4c2a04 | 1445 | );\r |
1446 | if (EFI_ERROR (Status)) {\r | |
1447 | Private->CurrentUdpSrcPort = 0;\r | |
1448 | return EFI_INVALID_PARAMETER;\r | |
1449 | }\r | |
1450 | \r | |
dc361cc5 | 1451 | ZeroMem (&Token, sizeof (EFI_UDP4_COMPLETION_TOKEN));\r |
1452 | ZeroMem (&Udp4Session, sizeof (EFI_UDP4_SESSION_DATA));\r | |
1453 | \r | |
e48e37fc | 1454 | CopyMem (&Udp4Session.DestinationAddress, DestIp, sizeof (EFI_IPv4_ADDRESS));\r |
dc361cc5 | 1455 | Udp4Session.DestinationPort = *DestPort;\r |
8792362f | 1456 | if (SrcIp != NULL) {\r |
1457 | CopyMem (&Udp4Session.SourceAddress, SrcIp, sizeof (EFI_IPv4_ADDRESS));\r | |
1458 | }\r | |
1459 | if (SrcPort != NULL) {\r | |
1460 | Udp4Session.SourcePort = *SrcPort;\r | |
1461 | }\r | |
dc361cc5 | 1462 | \r |
1463 | FragCount = (HeaderSize != NULL) ? 2 : 1;\r | |
05c0e3cb | 1464 | Udp4TxData = (EFI_UDP4_TRANSMIT_DATA *) AllocateZeroPool (sizeof (EFI_UDP4_TRANSMIT_DATA) + (FragCount - 1) * sizeof (EFI_UDP4_FRAGMENT_DATA));\r |
dc361cc5 | 1465 | if (Udp4TxData == NULL) {\r |
1466 | return EFI_OUT_OF_RESOURCES;\r | |
1467 | }\r | |
1468 | \r | |
1469 | Udp4TxData->FragmentCount = FragCount;\r | |
1470 | Udp4TxData->FragmentTable[FragCount - 1].FragmentLength = (UINT32) *BufferSize;\r | |
1471 | Udp4TxData->FragmentTable[FragCount - 1].FragmentBuffer = BufferPtr;\r | |
1472 | DataLength = (UINT32) *BufferSize;\r | |
1473 | \r | |
1474 | if (FragCount == 2) {\r | |
1475 | \r | |
1476 | Udp4TxData->FragmentTable[0].FragmentLength = (UINT32) *HeaderSize;\r | |
1477 | Udp4TxData->FragmentTable[0].FragmentBuffer = HeaderPtr;\r | |
1478 | DataLength += (UINT32) *HeaderSize;\r | |
1479 | }\r | |
1480 | \r | |
8792362f | 1481 | if (GatewayIp != NULL) {\r |
1482 | Udp4TxData->GatewayAddress = (EFI_IPv4_ADDRESS *) GatewayIp;\r | |
1483 | }\r | |
dc361cc5 | 1484 | Udp4TxData->UdpSessionData = &Udp4Session;\r |
1485 | Udp4TxData->DataLength = DataLength;\r | |
1486 | Token.Packet.TxData = Udp4TxData;\r | |
1487 | \r | |
1488 | Status = gBS->CreateEvent (\r | |
1489 | EVT_NOTIFY_SIGNAL,\r | |
e48e37fc | 1490 | TPL_NOTIFY,\r |
dc361cc5 | 1491 | PxeBcCommonNotify,\r |
1492 | &IsDone,\r | |
1493 | &Token.Event\r | |
1494 | );\r | |
1495 | if (EFI_ERROR (Status)) {\r | |
1496 | goto ON_EXIT;\r | |
1497 | }\r | |
1498 | \r | |
1499 | Status = Udp4->Transmit (Udp4, &Token);\r | |
1500 | if (EFI_ERROR (Status)) {\r | |
982a9eae | 1501 | if (Status == EFI_ICMP_ERROR) {\r |
1502 | Mode->IcmpErrorReceived = TRUE;\r | |
1503 | }\r | |
dc361cc5 | 1504 | goto ON_EXIT;\r |
1505 | }\r | |
1506 | \r | |
1507 | while (!IsDone) {\r | |
1508 | \r | |
1509 | Udp4->Poll (Udp4);\r | |
1510 | }\r | |
1511 | \r | |
1512 | Status = Token.Status;\r | |
1513 | \r | |
1514 | ON_EXIT:\r | |
1515 | \r | |
1516 | if (Token.Event != NULL) {\r | |
1517 | gBS->CloseEvent (Token.Event);\r | |
1518 | }\r | |
1519 | \r | |
766c7483 | 1520 | FreePool (Udp4TxData);\r |
dc361cc5 | 1521 | \r |
2e4c2a04 | 1522 | //\r |
1523 | // Reset the instance.\r | |
1524 | //\r | |
1525 | Udp4->Configure (Udp4, NULL);\r | |
dc361cc5 | 1526 | return Status;\r |
1527 | }\r | |
1528 | \r | |
8d285ec0 | 1529 | /**\r |
f737cfb9 | 1530 | Decide whether the incoming UDP packet is acceptable per IP filter settings\r |
1531 | in provided PxeBcMode.\r | |
8d285ec0 | 1532 | \r |
f737cfb9 | 1533 | @param PxeBcMode Pointer to EFI_PXE_BASE_CODE_MODE.\r |
1534 | @param Session Received UDP session.\r | |
8d285ec0 | 1535 | \r |
f737cfb9 | 1536 | @retval TRUE The UDP package matches IP filters.\r |
1537 | @retval FALSE The UDP package doesn't matches IP filters.\r | |
8d285ec0 | 1538 | \r |
1539 | **/\r | |
8d285ec0 | 1540 | BOOLEAN\r |
1541 | CheckIpByFilter (\r | |
f737cfb9 | 1542 | IN EFI_PXE_BASE_CODE_MODE *PxeBcMode,\r |
1543 | IN EFI_UDP4_SESSION_DATA *Session\r | |
8d285ec0 | 1544 | )\r |
1545 | {\r | |
1546 | UINTN Index;\r | |
1547 | EFI_IPv4_ADDRESS Ip4Address;\r | |
1548 | EFI_IPv4_ADDRESS DestIp4Address;\r | |
1549 | \r | |
f737cfb9 | 1550 | if ((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS) != 0) {\r |
8d285ec0 | 1551 | return TRUE;\r |
1552 | }\r | |
1553 | \r | |
1554 | CopyMem (&DestIp4Address, &Session->DestinationAddress, sizeof (DestIp4Address));\r | |
e2851998 | 1555 | if (((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST) != 0) &&\r |
982a9eae | 1556 | IP4_IS_MULTICAST (EFI_NTOHL (DestIp4Address))\r |
8d285ec0 | 1557 | ) {\r |
1558 | return TRUE;\r | |
1559 | }\r | |
1560 | \r | |
e2851998 | 1561 | if (((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST) != 0) &&\r |
8d285ec0 | 1562 | IP4_IS_LOCAL_BROADCAST (EFI_NTOHL (DestIp4Address))\r |
1563 | ) {\r | |
1564 | return TRUE;\r | |
1565 | }\r | |
1566 | \r | |
1567 | CopyMem (&Ip4Address, &PxeBcMode->StationIp.v4, sizeof (Ip4Address));\r | |
e2851998 | 1568 | if (((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0) &&\r |
982a9eae | 1569 | EFI_IP4_EQUAL (&Ip4Address, &DestIp4Address)\r |
8d285ec0 | 1570 | ) {\r |
1571 | return TRUE;\r | |
1572 | }\r | |
1573 | \r | |
894d038a | 1574 | ASSERT (PxeBcMode->IpFilter.IpCnt < EFI_PXE_BASE_CODE_MAX_IPCNT);\r |
1575 | \r | |
f737cfb9 | 1576 | for (Index = 0; Index < PxeBcMode->IpFilter.IpCnt; Index++) {\r |
1577 | CopyMem (\r | |
e2851998 | 1578 | &Ip4Address,\r |
1579 | &PxeBcMode->IpFilter.IpList[Index].v4,\r | |
f737cfb9 | 1580 | sizeof (Ip4Address)\r |
1581 | );\r | |
8d285ec0 | 1582 | if (EFI_IP4_EQUAL (&Ip4Address, &DestIp4Address)) {\r |
1583 | return TRUE;\r | |
1584 | }\r | |
1585 | }\r | |
1586 | \r | |
1587 | return FALSE;\r | |
1588 | }\r | |
dc361cc5 | 1589 | \r |
e2851998 | 1590 | /**\r |
f737cfb9 | 1591 | Reads a UDP packet from the network interface.\r |
1592 | \r | |
1593 | This function reads a UDP packet from a network interface. The data contents\r | |
1594 | are returned in (the optional HeaderPtr and) BufferPtr, and the size of the\r | |
1595 | buffer received is returned in BufferSize . If the input BufferSize is smaller\r | |
1596 | than the UDP packet received (less optional HeaderSize), it will be set to the\r | |
1597 | required size, and EFI_BUFFER_TOO_SMALL will be returned. In this case, the\r | |
1598 | contents of BufferPtr are undefined, and the packet is lost. If a UDP packet is\r | |
1599 | successfully received, then EFI_SUCCESS will be returned, and the information\r | |
1600 | from the UDP header will be returned in DestIp, DestPort, SrcIp, and SrcPort if\r | |
e2851998 | 1601 | they are not NULL. Depending on the values of OpFlags and the DestIp, DestPort,\r |
1602 | SrcIp, and SrcPort input values, different types of UDP packet receive filtering\r | |
f737cfb9 | 1603 | will be performed. The following tables summarize these receive filter operations.\r |
e2851998 | 1604 | \r |
f737cfb9 | 1605 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r |
e2851998 | 1606 | @param OpFlags The UDP operation flags.\r |
f737cfb9 | 1607 | @param DestIp The destination IP address.\r |
1608 | @param DestPort The destination UDP port number.\r | |
1609 | @param SrcIp The source IP address.\r | |
1610 | @param SrcPort The source UDP port number.\r | |
1611 | @param HeaderSize An optional field which may be set to the length of a header at\r | |
e2851998 | 1612 | HeaderPtr to be prefixed to the data at BufferPtr.\r |
f737cfb9 | 1613 | @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the\r |
e2851998 | 1614 | data at BufferPtr.\r |
f737cfb9 | 1615 | @param BufferSize A pointer to the size of the data at BufferPtr.\r |
1616 | @param BufferPtr A pointer to the data to be read.\r | |
e2851998 | 1617 | \r |
f737cfb9 | 1618 | @retval EFI_SUCCESS The UDP Read operation was completed.\r |
1619 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
e2851998 | 1620 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r |
f737cfb9 | 1621 | @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r |
1622 | @retval EFI_BUFFER_TOO_SMALL The packet is larger than Buffer can hold.\r | |
1623 | @retval EFI_ABORTED The callback function aborted the UDP Read operation.\r | |
e2851998 | 1624 | @retval EFI_TIMEOUT The UDP Read operation timed out.\r |
1625 | \r | |
dc361cc5 | 1626 | **/\r |
1627 | EFI_STATUS\r | |
1628 | EFIAPI\r | |
1629 | EfiPxeBcUdpRead (\r | |
f737cfb9 | 1630 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r |
1631 | IN UINT16 OpFlags,\r | |
1632 | IN OUT EFI_IP_ADDRESS *DestIp OPTIONAL,\r | |
1633 | IN OUT EFI_PXE_BASE_CODE_UDP_PORT *DestPort OPTIONAL,\r | |
1634 | IN OUT EFI_IP_ADDRESS *SrcIp OPTIONAL,\r | |
1635 | IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,\r | |
1636 | IN UINTN *HeaderSize OPTIONAL,\r | |
1637 | IN VOID *HeaderPtr OPTIONAL,\r | |
1638 | IN OUT UINTN *BufferSize,\r | |
1639 | IN VOID *BufferPtr\r | |
dc361cc5 | 1640 | )\r |
1641 | {\r | |
1642 | PXEBC_PRIVATE_DATA *Private;\r | |
1643 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
1644 | EFI_UDP4_PROTOCOL *Udp4;\r | |
1645 | EFI_UDP4_COMPLETION_TOKEN Token;\r | |
1646 | EFI_UDP4_RECEIVE_DATA *RxData;\r | |
1647 | EFI_UDP4_SESSION_DATA *Session;\r | |
1648 | EFI_STATUS Status;\r | |
1649 | BOOLEAN IsDone;\r | |
1650 | BOOLEAN Matched;\r | |
c3cd46d4 | 1651 | UINTN CopiedLen;\r |
1652 | UINTN HeaderLen;\r | |
1653 | UINTN HeaderCopiedLen;\r | |
1654 | UINTN BufferCopiedLen;\r | |
1655 | UINT32 FragmentLength;\r | |
1656 | UINTN FragmentIndex;\r | |
1657 | UINT8 *FragmentBuffer;\r | |
dc361cc5 | 1658 | \r |
1659 | if (This == NULL || DestIp == NULL || DestPort == NULL) {\r | |
1660 | return EFI_INVALID_PARAMETER;\r | |
1661 | }\r | |
1662 | \r | |
f737cfb9 | 1663 | if (((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) == 0 && (DestPort == NULL)) ||\r |
1664 | ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) == 0 && (SrcIp == NULL)) ||\r | |
1665 | ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) == 0 && (SrcPort == NULL))) {\r | |
dc361cc5 | 1666 | return EFI_INVALID_PARAMETER;\r |
1667 | }\r | |
1668 | \r | |
8792362f | 1669 | if (((HeaderSize != NULL) && (*HeaderSize == 0)) || ((HeaderSize != NULL) && (HeaderPtr == NULL))) {\r |
dc361cc5 | 1670 | return EFI_INVALID_PARAMETER;\r |
1671 | }\r | |
1672 | \r | |
29a4f92d | 1673 | if ((BufferSize == NULL) || (BufferPtr == NULL)) {\r |
dc361cc5 | 1674 | return EFI_INVALID_PARAMETER;\r |
1675 | }\r | |
1676 | \r | |
1677 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
1678 | Mode = Private->PxeBc.Mode;\r | |
8792362f | 1679 | Udp4 = Private->Udp4Read;\r |
dc361cc5 | 1680 | \r |
1681 | if (!Mode->Started) {\r | |
1682 | return EFI_NOT_STARTED;\r | |
1683 | }\r | |
1684 | \r | |
982a9eae | 1685 | Mode->IcmpErrorReceived = FALSE;\r |
1686 | \r | |
dc361cc5 | 1687 | Status = gBS->CreateEvent (\r |
1688 | EVT_NOTIFY_SIGNAL,\r | |
e48e37fc | 1689 | TPL_NOTIFY,\r |
dc361cc5 | 1690 | PxeBcCommonNotify,\r |
1691 | &IsDone,\r | |
1692 | &Token.Event\r | |
1693 | );\r | |
1694 | if (EFI_ERROR (Status)) {\r | |
1695 | return EFI_OUT_OF_RESOURCES;\r | |
1696 | }\r | |
1697 | \r | |
8792362f | 1698 | TRY_AGAIN:\r |
1699 | \r | |
dc361cc5 | 1700 | IsDone = FALSE;\r |
1701 | Status = Udp4->Receive (Udp4, &Token);\r | |
1702 | if (EFI_ERROR (Status)) {\r | |
982a9eae | 1703 | if (Status == EFI_ICMP_ERROR) {\r |
1704 | Mode->IcmpErrorReceived = TRUE;\r | |
1705 | }\r | |
dc361cc5 | 1706 | goto ON_EXIT;\r |
1707 | }\r | |
1708 | \r | |
1709 | Udp4->Poll (Udp4);\r | |
1710 | \r | |
1711 | if (!IsDone) {\r | |
1712 | Status = EFI_TIMEOUT;\r | |
1713 | } else {\r | |
1714 | \r | |
1715 | //\r | |
1716 | // check whether this packet matches the filters\r | |
1717 | //\r | |
1718 | if (EFI_ERROR (Token.Status)){\r | |
1719 | goto ON_EXIT;\r | |
1720 | }\r | |
1721 | \r | |
1722 | RxData = Token.Packet.RxData;\r | |
1723 | Session = &RxData->UdpSession;\r | |
1724 | \r | |
319075ff | 1725 | Matched = TRUE;\r |
dc361cc5 | 1726 | \r |
f737cfb9 | 1727 | if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_USE_FILTER) != 0) {\r |
319075ff | 1728 | Matched = FALSE;\r |
8d285ec0 | 1729 | //\r |
1730 | // Check UDP package by IP filter settings\r | |
1731 | //\r | |
1732 | if (CheckIpByFilter (Mode, Session)) {\r | |
1733 | Matched = TRUE;\r | |
dc361cc5 | 1734 | }\r |
8d285ec0 | 1735 | }\r |
1736 | \r | |
1737 | if (Matched) {\r | |
8792362f | 1738 | Matched = FALSE;\r |
1739 | \r | |
8d285ec0 | 1740 | //\r |
1741 | // Match the destination ip of the received udp dgram\r | |
1742 | //\r | |
f737cfb9 | 1743 | if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_IP) != 0) {\r |
8d285ec0 | 1744 | Matched = TRUE;\r |
1745 | \r | |
1746 | if (DestIp != NULL) {\r | |
1747 | CopyMem (DestIp, &Session->DestinationAddress, sizeof (EFI_IPv4_ADDRESS));\r | |
dc361cc5 | 1748 | }\r |
1749 | } else {\r | |
8d285ec0 | 1750 | if (DestIp != NULL) {\r |
1751 | if (EFI_IP4_EQUAL (DestIp, &Session->DestinationAddress)) {\r | |
1752 | Matched = TRUE;\r | |
1753 | }\r | |
1754 | } else {\r | |
1755 | if (EFI_IP4_EQUAL (&Private->StationIp, &Session->DestinationAddress)) {\r | |
1756 | Matched = TRUE;\r | |
1757 | }\r | |
dc361cc5 | 1758 | }\r |
1759 | }\r | |
1760 | }\r | |
1761 | \r | |
1762 | if (Matched) {\r | |
1763 | //\r | |
1764 | // Match the destination port of the received udp dgram\r | |
1765 | //\r | |
f737cfb9 | 1766 | if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) != 0) {\r |
dc361cc5 | 1767 | \r |
1768 | if (DestPort != NULL) {\r | |
1769 | *DestPort = Session->DestinationPort;\r | |
1770 | }\r | |
1771 | } else {\r | |
1772 | \r | |
1773 | if (*DestPort != Session->DestinationPort) {\r | |
1774 | Matched = FALSE;\r | |
1775 | }\r | |
1776 | }\r | |
1777 | }\r | |
1778 | \r | |
1779 | if (Matched) {\r | |
1780 | //\r | |
1781 | // Match the source ip of the received udp dgram\r | |
1782 | //\r | |
f737cfb9 | 1783 | if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP) != 0) {\r |
dc361cc5 | 1784 | \r |
1785 | if (SrcIp != NULL) {\r | |
e48e37fc | 1786 | CopyMem (SrcIp, &Session->SourceAddress, sizeof (EFI_IPv4_ADDRESS));\r |
dc361cc5 | 1787 | }\r |
1788 | } else {\r | |
1789 | \r | |
1790 | if (!EFI_IP4_EQUAL (SrcIp, &Session->SourceAddress)) {\r | |
1791 | Matched = FALSE;\r | |
1792 | }\r | |
1793 | }\r | |
1794 | }\r | |
1795 | \r | |
1796 | if (Matched) {\r | |
1797 | //\r | |
1798 | // Match the source port of the received udp dgram\r | |
1799 | //\r | |
f737cfb9 | 1800 | if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) != 0) {\r |
dc361cc5 | 1801 | \r |
1802 | if (SrcPort != NULL) {\r | |
1803 | *SrcPort = Session->SourcePort;\r | |
1804 | }\r | |
1805 | } else {\r | |
1806 | \r | |
1807 | if (*SrcPort != Session->SourcePort) {\r | |
1808 | Matched = FALSE;\r | |
1809 | }\r | |
1810 | }\r | |
1811 | }\r | |
1812 | \r | |
1813 | if (Matched) {\r | |
c3cd46d4 | 1814 | ASSERT (RxData != NULL);\r |
dc361cc5 | 1815 | \r |
c3cd46d4 | 1816 | HeaderLen = 0;\r |
dc361cc5 | 1817 | if (HeaderSize != NULL) {\r |
c3cd46d4 | 1818 | HeaderLen = MIN (*HeaderSize, RxData->DataLength);\r |
dc361cc5 | 1819 | }\r |
1820 | \r | |
c3cd46d4 | 1821 | if (RxData->DataLength - HeaderLen > *BufferSize) {\r |
dc361cc5 | 1822 | Status = EFI_BUFFER_TOO_SMALL;\r |
1823 | } else {\r | |
c3cd46d4 | 1824 | *HeaderSize = HeaderLen;\r |
1825 | *BufferSize = RxData->DataLength - HeaderLen;\r | |
1826 | \r | |
1827 | HeaderCopiedLen = 0;\r | |
1828 | BufferCopiedLen = 0;\r | |
1829 | for (FragmentIndex = 0; FragmentIndex < RxData->FragmentCount; FragmentIndex++) {\r | |
1830 | FragmentLength = RxData->FragmentTable[FragmentIndex].FragmentLength;\r | |
1831 | FragmentBuffer = RxData->FragmentTable[FragmentIndex].FragmentBuffer;\r | |
1832 | if (HeaderCopiedLen + FragmentLength < HeaderLen) {\r | |
1833 | //\r | |
1834 | // Copy the header part of received data.\r | |
1835 | //\r | |
1836 | CopyMem ((UINT8 *) HeaderPtr + HeaderCopiedLen, FragmentBuffer, FragmentLength);\r | |
1837 | HeaderCopiedLen += FragmentLength;\r | |
1838 | } else if (HeaderCopiedLen < HeaderLen) {\r | |
1839 | //\r | |
1840 | // Copy the header part of received data.\r | |
1841 | //\r | |
1842 | CopiedLen = HeaderLen - HeaderCopiedLen;\r | |
1843 | CopyMem ((UINT8 *) HeaderPtr + HeaderCopiedLen, FragmentBuffer, CopiedLen);\r | |
1844 | HeaderCopiedLen += CopiedLen;\r | |
1845 | \r | |
1846 | //\r | |
1847 | // Copy the other part of received data.\r | |
1848 | //\r | |
1849 | CopyMem ((UINT8 *) BufferPtr + BufferCopiedLen, FragmentBuffer + CopiedLen, FragmentLength - CopiedLen);\r | |
1850 | BufferCopiedLen += (FragmentLength - CopiedLen);\r | |
1851 | } else {\r | |
1852 | //\r | |
1853 | // Copy the other part of received data.\r | |
1854 | //\r | |
1855 | CopyMem ((UINT8 *) BufferPtr + BufferCopiedLen, FragmentBuffer, FragmentLength);\r | |
1856 | BufferCopiedLen += FragmentLength;\r | |
1857 | }\r | |
1858 | }\r | |
dc361cc5 | 1859 | }\r |
1860 | } else {\r | |
1861 | \r | |
1862 | Status = EFI_TIMEOUT;\r | |
1863 | }\r | |
1864 | \r | |
1865 | //\r | |
1866 | // Recycle the RxData\r | |
1867 | //\r | |
1868 | gBS->SignalEvent (RxData->RecycleSignal);\r | |
8792362f | 1869 | \r |
1870 | if (!Matched) {\r | |
1871 | goto TRY_AGAIN;\r | |
1872 | }\r | |
dc361cc5 | 1873 | }\r |
1874 | \r | |
1875 | ON_EXIT:\r | |
1876 | \r | |
1877 | Udp4->Cancel (Udp4, &Token);\r | |
1878 | \r | |
1879 | gBS->CloseEvent (Token.Event);\r | |
1880 | \r | |
1881 | return Status;\r | |
1882 | }\r | |
1883 | \r | |
e2851998 | 1884 | /**\r |
f737cfb9 | 1885 | Updates the IP receive filters of a network device and enables software filtering.\r |
e2851998 | 1886 | \r |
f737cfb9 | 1887 | The NewFilter field is used to modify the network device's current IP receive\r |
1888 | filter settings and to enable a software filter. This function updates the IpFilter\r | |
1889 | field of the EFI_PXE_BASE_CODE_MODE structure with the contents of NewIpFilter.\r | |
1890 | The software filter is used when the USE_FILTER in OpFlags is set to UdpRead().\r | |
1891 | The current hardware filter remains in effect no matter what the settings of OpFlags\r | |
1892 | are, so that the meaning of ANY_DEST_IP set in OpFlags to UdpRead() is from those\r | |
1893 | packets whose reception is enabled in hardware-physical NIC address (unicast),\r | |
1894 | broadcast address, logical address or addresses (multicast), or all (promiscuous).\r | |
1895 | UdpRead() does not modify the IP filter settings.\r | |
1896 | Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP receive\r | |
1897 | filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.\r | |
1898 | If an application or driver wishes to preserve the IP receive filter settings,\r | |
1899 | it will have to preserve the IP receive filter settings before these calls, and\r | |
1900 | use SetIpFilter() to restore them after the calls. If incompatible filtering is\r | |
1901 | requested (for example, PROMISCUOUS with anything else) or if the device does not\r | |
1902 | support a requested filter setting and it cannot be accommodated in software\r | |
1903 | (for example, PROMISCUOUS not supported), EFI_INVALID_PARAMETER will be returned.\r | |
1904 | The IPlist field is used to enable IPs other than the StationIP. They may be\r | |
1905 | multicast or unicast. If IPcnt is set as well as EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP,\r | |
1906 | then both the StationIP and the IPs from the IPlist will be used.\r | |
e2851998 | 1907 | \r |
f737cfb9 | 1908 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r |
1909 | @param NewFilter Pointer to the new set of IP receive filters.\r | |
e2851998 | 1910 | \r |
f737cfb9 | 1911 | @retval EFI_SUCCESS The IP receive filter settings were updated.\r |
1912 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
e2851998 | 1913 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r |
1914 | \r | |
dc361cc5 | 1915 | **/\r |
1916 | EFI_STATUS\r | |
1917 | EFIAPI\r | |
1918 | EfiPxeBcSetIpFilter (\r | |
1919 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r | |
1920 | IN EFI_PXE_BASE_CODE_IP_FILTER *NewFilter\r | |
1921 | )\r | |
1922 | {\r | |
8d285ec0 | 1923 | EFI_STATUS Status;\r |
1924 | PXEBC_PRIVATE_DATA *Private;\r | |
1925 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
1926 | UINTN Index;\r | |
c82291bc | 1927 | EFI_UDP4_CONFIG_DATA *Udp4Cfg;\r |
8d285ec0 | 1928 | BOOLEAN PromiscuousNeed;\r |
c82291bc | 1929 | BOOLEAN AcceptPromiscuous;\r |
1930 | BOOLEAN AcceptBroadcast;\r | |
1931 | BOOLEAN MultiCastUpdate;\r | |
8d285ec0 | 1932 | \r |
1933 | if (This == NULL) {\r | |
894d038a | 1934 | DEBUG ((EFI_D_ERROR, "This == NULL.\n"));\r |
8d285ec0 | 1935 | return EFI_INVALID_PARAMETER;\r |
1936 | }\r | |
1937 | \r | |
1938 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
1939 | Mode = Private->PxeBc.Mode;\r | |
1940 | \r | |
894d038a | 1941 | if (NewFilter == NULL) {\r |
1942 | DEBUG ((EFI_D_ERROR, "NewFilter == NULL.\n"));\r | |
8d285ec0 | 1943 | return EFI_INVALID_PARAMETER;\r |
1944 | }\r | |
1945 | \r | |
894d038a | 1946 | if (NewFilter->IpCnt > EFI_PXE_BASE_CODE_MAX_IPCNT) {\r |
1947 | DEBUG ((EFI_D_ERROR, "NewFilter->IpCnt > %d.\n", EFI_PXE_BASE_CODE_MAX_IPCNT));\r | |
8d285ec0 | 1948 | return EFI_INVALID_PARAMETER;\r |
1949 | }\r | |
1950 | \r | |
1951 | if (!Mode->Started) {\r | |
1952 | DEBUG ((EFI_D_ERROR, "BC was not started.\n"));\r | |
1953 | return EFI_NOT_STARTED;\r | |
1954 | }\r | |
1955 | \r | |
c82291bc | 1956 | if (Mode->UsingIpv6) {\r |
1957 | DEBUG ((EFI_D_ERROR, "This driver is PXE for IPv4 Only.\n"));\r | |
1958 | return EFI_INVALID_PARAMETER;\r | |
1959 | }\r | |
1960 | \r | |
8d285ec0 | 1961 | PromiscuousNeed = FALSE;\r |
894d038a | 1962 | \r |
8d285ec0 | 1963 | for (Index = 0; Index < NewFilter->IpCnt; ++Index) {\r |
1964 | if (IP4_IS_LOCAL_BROADCAST (EFI_IP4 (NewFilter->IpList[Index].v4))) {\r | |
1965 | //\r | |
1966 | // The IP is a broadcast address.\r | |
1967 | //\r | |
1968 | DEBUG ((EFI_D_ERROR, "There is broadcast address in NewFilter.\n"));\r | |
1969 | return EFI_INVALID_PARAMETER;\r | |
1970 | }\r | |
01b5ac88 FS |
1971 | if ((EFI_NTOHL(Mode->StationIp) != 0) &&\r |
1972 | (EFI_NTOHL(Mode->SubnetMask) != 0) &&\r | |
1973 | IP4_NET_EQUAL(EFI_NTOHL(Mode->StationIp), EFI_NTOHL(NewFilter->IpList[Index].v4), EFI_NTOHL(Mode->SubnetMask)) &&\r | |
1974 | NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), EFI_NTOHL(Mode->SubnetMask)) &&\r | |
1975 | ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0)) {\r | |
8d285ec0 | 1976 | //\r |
1977 | // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IP4 address is in IpList,\r | |
1978 | // promiscuous mode is needed.\r | |
1979 | //\r | |
1980 | PromiscuousNeed = TRUE;\r | |
1981 | }\r | |
1982 | }\r | |
1983 | \r | |
c82291bc | 1984 | AcceptPromiscuous = FALSE;\r |
1985 | AcceptBroadcast = FALSE;\r | |
1986 | MultiCastUpdate = FALSE;\r | |
8d285ec0 | 1987 | \r |
1988 | if (PromiscuousNeed ||\r | |
e2851998 | 1989 | ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS) != 0) ||\r |
1990 | ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST) != 0)\r | |
8d285ec0 | 1991 | ) {\r |
1992 | //\r | |
c82291bc | 1993 | // Configure the udp4 filter to receive all packages.\r |
8d285ec0 | 1994 | //\r |
c82291bc | 1995 | AcceptPromiscuous = TRUE;\r |
1996 | } else if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST) != 0) {\r | |
8d285ec0 | 1997 | //\r |
c82291bc | 1998 | // Configure the udp4 filter to receive all broadcast packages.\r |
8d285ec0 | 1999 | //\r |
c82291bc | 2000 | AcceptBroadcast = TRUE;\r |
2001 | }\r | |
8d285ec0 | 2002 | \r |
c82291bc | 2003 | //\r |
2004 | // In multicast condition when Promiscuous FALSE and IpCnt no-zero.\r | |
2005 | // Here check if there is any update of the multicast ip address. If yes,\r | |
2006 | // we need leave the old multicast group (by Config UDP instance to NULL),\r | |
2007 | // and join the new multicast group.\r | |
2008 | //\r | |
2009 | if (!AcceptPromiscuous) {\r | |
2010 | if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0) {\r | |
2011 | if (Mode->IpFilter.IpCnt != NewFilter->IpCnt) {\r | |
2012 | MultiCastUpdate = TRUE;\r | |
2013 | } else if (CompareMem (Mode->IpFilter.IpList, NewFilter->IpList, NewFilter->IpCnt * sizeof (EFI_IP_ADDRESS)) != 0 ) {\r | |
2014 | MultiCastUpdate = TRUE;\r | |
2015 | }\r | |
8d285ec0 | 2016 | }\r |
c82291bc | 2017 | }\r |
2018 | \r | |
2019 | //\r | |
2020 | // Check whether we need reconfigure the UDP instance.\r | |
2021 | //\r | |
2022 | Udp4Cfg = &Private->Udp4CfgData;\r | |
2023 | if ((AcceptPromiscuous != Udp4Cfg->AcceptPromiscuous) ||\r | |
2024 | (AcceptBroadcast != Udp4Cfg->AcceptBroadcast) || MultiCastUpdate) {\r | |
2025 | //\r | |
2026 | // Clear the UDP instance configuration, all joined groups will be left\r | |
2027 | // during the operation.\r | |
2028 | //\r | |
2029 | Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r | |
8d285ec0 | 2030 | \r |
2031 | //\r | |
2032 | // Configure the UDP instance with the new configuration.\r | |
2033 | //\r | |
c82291bc | 2034 | Udp4Cfg->AcceptPromiscuous = AcceptPromiscuous;\r |
2035 | Udp4Cfg->AcceptBroadcast = AcceptBroadcast;\r | |
2036 | Status = Private->Udp4Read->Configure (Private->Udp4Read, Udp4Cfg);\r | |
8d285ec0 | 2037 | if (EFI_ERROR (Status)) {\r |
2038 | return Status;\r | |
2039 | }\r | |
2040 | \r | |
c82291bc | 2041 | //\r |
2042 | // In not Promiscuous mode, need to join the new multicast group.\r | |
2043 | //\r | |
2044 | if (!AcceptPromiscuous) {\r | |
8d285ec0 | 2045 | for (Index = 0; Index < NewFilter->IpCnt; ++Index) {\r |
2046 | if (IP4_IS_MULTICAST (EFI_NTOHL (NewFilter->IpList[Index].v4))) {\r | |
2047 | //\r | |
c82291bc | 2048 | // Join the mutilcast group.\r |
8d285ec0 | 2049 | //\r |
8792362f | 2050 | Status = Private->Udp4Read->Groups (Private->Udp4Read, TRUE, &NewFilter->IpList[Index].v4);\r |
8d285ec0 | 2051 | if (EFI_ERROR (Status)) {\r |
2052 | return Status;\r | |
2053 | }\r | |
2054 | }\r | |
2055 | }\r | |
2056 | }\r | |
2057 | }\r | |
2058 | \r | |
2059 | \r | |
2060 | //\r | |
2061 | // Save the new filter.\r | |
2062 | //\r | |
2063 | CopyMem (&Mode->IpFilter, NewFilter, sizeof (Mode->IpFilter));\r | |
2064 | \r | |
2065 | return EFI_SUCCESS;\r | |
dc361cc5 | 2066 | }\r |
2067 | \r | |
2068 | \r | |
e2851998 | 2069 | /**\r |
f737cfb9 | 2070 | Uses the ARP protocol to resolve a MAC address.\r |
e2851998 | 2071 | \r |
f737cfb9 | 2072 | This function uses the ARP protocol to resolve a MAC address. The UsingIpv6 field\r |
2073 | of the EFI_PXE_BASE_CODE_MODE structure is used to determine if IPv4 or IPv6\r | |
2074 | addresses are being used. The IP address specified by IpAddr is used to resolve\r | |
2075 | a MAC address. If the ARP protocol succeeds in resolving the specified address,\r | |
2076 | then the ArpCacheEntries and ArpCache fields of the EFI_PXE_BASE_CODE_MODE structure\r | |
2077 | are updated, and EFI_SUCCESS is returned. If MacAddr is not NULL, the resolved\r | |
e2851998 | 2078 | MAC address is placed there as well. If the PXE Base Code protocol is in the\r |
2079 | stopped state, then EFI_NOT_STARTED is returned. If the ARP protocol encounters\r | |
2080 | a timeout condition while attempting to resolve an address, then EFI_TIMEOUT is\r | |
2081 | returned. If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,\r | |
f737cfb9 | 2082 | then EFI_ABORTED is returned.\r |
e2851998 | 2083 | \r |
f737cfb9 | 2084 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r |
2085 | @param IpAddr Pointer to the IP address that is used to resolve a MAC address.\r | |
2086 | @param MacAddr If not NULL, a pointer to the MAC address that was resolved with the\r | |
e2851998 | 2087 | ARP protocol.\r |
2088 | \r | |
f737cfb9 | 2089 | @retval EFI_SUCCESS The IP or MAC address was resolved.\r |
2090 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
e2851998 | 2091 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r |
2092 | @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r | |
2093 | @retval EFI_ICMP_ERROR Something error occur with the ICMP packet message.\r | |
2094 | \r | |
dc361cc5 | 2095 | **/\r |
2096 | EFI_STATUS\r | |
2097 | EFIAPI\r | |
2098 | EfiPxeBcArp (\r | |
2099 | IN EFI_PXE_BASE_CODE_PROTOCOL * This,\r | |
2100 | IN EFI_IP_ADDRESS * IpAddr,\r | |
2101 | IN EFI_MAC_ADDRESS * MacAddr OPTIONAL\r | |
2102 | )\r | |
2103 | {\r | |
8d285ec0 | 2104 | PXEBC_PRIVATE_DATA *Private;\r |
2105 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
2106 | EFI_STATUS Status;\r | |
2107 | EFI_MAC_ADDRESS TempMacAddr;\r | |
2108 | \r | |
2109 | if (This == NULL || IpAddr == NULL) {\r | |
2110 | return EFI_INVALID_PARAMETER;\r | |
2111 | }\r | |
2112 | \r | |
2113 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
2114 | Mode = Private->PxeBc.Mode;\r | |
2115 | \r | |
2116 | if (!Mode->Started) {\r | |
2117 | return EFI_NOT_STARTED;\r | |
2118 | }\r | |
2119 | \r | |
2120 | if (!Private->AddressIsOk || Mode->UsingIpv6) {\r | |
2121 | //\r | |
2122 | // We can't resolve the IP address if we don't have a local address now.\r | |
2123 | // Don't have ARP for IPv6.\r | |
2124 | //\r | |
2125 | return EFI_INVALID_PARAMETER;\r | |
2126 | }\r | |
2127 | \r | |
982a9eae | 2128 | Mode->IcmpErrorReceived = FALSE;\r |
2129 | \r | |
2130 | if (!Mode->AutoArp) {\r | |
2131 | //\r | |
2132 | // If AutoArp is set false, check arp cache\r | |
2133 | //\r | |
2134 | UpdateArpCache (This);\r | |
2135 | if (!FindInArpCache (Mode, &IpAddr->v4, &TempMacAddr)) {\r | |
2136 | return EFI_DEVICE_ERROR;\r | |
2137 | }\r | |
2138 | } else {\r | |
2139 | Status = Private->Arp->Request (Private->Arp, &IpAddr->v4, NULL, &TempMacAddr);\r | |
2140 | if (EFI_ERROR (Status)) {\r | |
2141 | if (Status == EFI_ICMP_ERROR) {\r | |
2142 | Mode->IcmpErrorReceived = TRUE;\r | |
2143 | }\r | |
2144 | return Status;\r | |
2145 | }\r | |
8d285ec0 | 2146 | }\r |
2147 | \r | |
2148 | if (MacAddr != NULL) {\r | |
2149 | CopyMem (MacAddr, &TempMacAddr, sizeof (EFI_MAC_ADDRESS));\r | |
2150 | }\r | |
2151 | \r | |
2152 | return EFI_SUCCESS;\r | |
dc361cc5 | 2153 | }\r |
2154 | \r | |
e2851998 | 2155 | /**\r |
f737cfb9 | 2156 | Updates the parameters that affect the operation of the PXE Base Code Protocol.\r |
e2851998 | 2157 | \r |
f737cfb9 | 2158 | This function sets parameters that affect the operation of the PXE Base Code Protocol.\r |
2159 | The parameter specified by NewAutoArp is used to control the generation of ARP\r | |
2160 | protocol packets. If NewAutoArp is TRUE, then ARP Protocol packets will be generated\r | |
2161 | as required by the PXE Base Code Protocol. If NewAutoArp is FALSE, then no ARP\r | |
2162 | Protocol packets will be generated. In this case, the only mappings that are\r | |
2163 | available are those stored in the ArpCache of the EFI_PXE_BASE_CODE_MODE structure.\r | |
2164 | If there are not enough mappings in the ArpCache to perform a PXE Base Code Protocol\r | |
2165 | service, then the service will fail. This function updates the AutoArp field of\r | |
2166 | the EFI_PXE_BASE_CODE_MODE structure to NewAutoArp.\r | |
2167 | The SetParameters() call must be invoked after a Callback Protocol is installed\r | |
2168 | to enable the use of callbacks.\r | |
e2851998 | 2169 | \r |
f737cfb9 | 2170 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r |
2171 | @param NewAutoArp If not NULL, a pointer to a value that specifies whether to replace the\r | |
e2851998 | 2172 | current value of AutoARP.\r |
f737cfb9 | 2173 | @param NewSendGUID If not NULL, a pointer to a value that specifies whether to replace the\r |
e2851998 | 2174 | current value of SendGUID.\r |
f737cfb9 | 2175 | @param NewTTL If not NULL, a pointer to be used in place of the current value of TTL,\r |
e2851998 | 2176 | the "time to live" field of the IP header.\r |
f737cfb9 | 2177 | @param NewToS If not NULL, a pointer to be used in place of the current value of ToS,\r |
e2851998 | 2178 | the "type of service" field of the IP header.\r |
f737cfb9 | 2179 | @param NewMakeCallback If not NULL, a pointer to a value that specifies whether to replace the\r |
e2851998 | 2180 | current value of the MakeCallback field of the Mode structure.\r |
2181 | \r | |
f737cfb9 | 2182 | @retval EFI_SUCCESS The new parameters values were updated.\r |
2183 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
e2851998 | 2184 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r |
2185 | \r | |
dc361cc5 | 2186 | **/\r |
2187 | EFI_STATUS\r | |
2188 | EFIAPI\r | |
2189 | EfiPxeBcSetParameters (\r | |
2190 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r | |
f737cfb9 | 2191 | IN BOOLEAN *NewAutoArp OPTIONAL,\r |
2192 | IN BOOLEAN *NewSendGUID OPTIONAL,\r | |
2193 | IN UINT8 *NewTTL OPTIONAL,\r | |
2194 | IN UINT8 *NewToS OPTIONAL,\r | |
dc361cc5 | 2195 | IN BOOLEAN *NewMakeCallback // OPTIONAL\r |
2196 | )\r | |
2197 | {\r | |
2198 | PXEBC_PRIVATE_DATA *Private;\r | |
2199 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
2200 | EFI_STATUS Status;\r | |
2201 | \r | |
2202 | Status = EFI_SUCCESS;\r | |
2203 | \r | |
2204 | if (This == NULL) {\r | |
2205 | Status = EFI_INVALID_PARAMETER;\r | |
2206 | goto ON_EXIT;\r | |
2207 | }\r | |
2208 | \r | |
2209 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
2210 | Mode = Private->PxeBc.Mode;\r | |
2211 | \r | |
f737cfb9 | 2212 | if (NewSendGUID != NULL && *NewSendGUID) {\r |
dc361cc5 | 2213 | //\r |
2214 | // FixMe, cann't locate SendGuid\r | |
2215 | //\r | |
2216 | }\r | |
2217 | \r | |
f737cfb9 | 2218 | if (NewMakeCallback != NULL && *NewMakeCallback) {\r |
dc361cc5 | 2219 | \r |
2220 | Status = gBS->HandleProtocol (\r | |
2221 | Private->Controller,\r | |
2222 | &gEfiPxeBaseCodeCallbackProtocolGuid,\r | |
2223 | (VOID **) &Private->PxeBcCallback\r | |
2224 | );\r | |
2225 | if (EFI_ERROR (Status) || (Private->PxeBcCallback->Callback == NULL)) {\r | |
2226 | \r | |
2227 | Status = EFI_INVALID_PARAMETER;\r | |
2228 | goto ON_EXIT;\r | |
2229 | }\r | |
2230 | }\r | |
2231 | \r | |
2232 | if (!Mode->Started) {\r | |
2233 | Status = EFI_NOT_STARTED;\r | |
2234 | goto ON_EXIT;\r | |
2235 | }\r | |
2236 | \r | |
2237 | if (NewMakeCallback != NULL) {\r | |
2238 | \r | |
2239 | if (*NewMakeCallback) {\r | |
2240 | //\r | |
2241 | // Update the Callback protocol.\r | |
2242 | //\r | |
2243 | Status = gBS->HandleProtocol (\r | |
2244 | Private->Controller,\r | |
2245 | &gEfiPxeBaseCodeCallbackProtocolGuid,\r | |
2246 | (VOID **) &Private->PxeBcCallback\r | |
2247 | );\r | |
2248 | \r | |
2249 | if (EFI_ERROR (Status) || (Private->PxeBcCallback->Callback == NULL)) {\r | |
2250 | Status = EFI_INVALID_PARAMETER;\r | |
2251 | goto ON_EXIT;\r | |
2252 | }\r | |
2253 | } else {\r | |
2254 | Private->PxeBcCallback = NULL;\r | |
2255 | }\r | |
2256 | \r | |
2257 | Mode->MakeCallbacks = *NewMakeCallback;\r | |
2258 | }\r | |
2259 | \r | |
2260 | if (NewAutoArp != NULL) {\r | |
2261 | Mode->AutoArp = *NewAutoArp;\r | |
2262 | }\r | |
2263 | \r | |
2264 | if (NewSendGUID != NULL) {\r | |
2265 | Mode->SendGUID = *NewSendGUID;\r | |
2266 | }\r | |
2267 | \r | |
2268 | if (NewTTL != NULL) {\r | |
2269 | Mode->TTL = *NewTTL;\r | |
2270 | }\r | |
2271 | \r | |
2272 | if (NewToS != NULL) {\r | |
2273 | Mode->ToS = *NewToS;\r | |
2274 | }\r | |
2275 | \r | |
2276 | ON_EXIT:\r | |
2277 | return Status;\r | |
2278 | }\r | |
2279 | \r | |
e2851998 | 2280 | /**\r |
f737cfb9 | 2281 | Updates the station IP address and/or subnet mask values of a network device.\r |
e2851998 | 2282 | \r |
f737cfb9 | 2283 | This function updates the station IP address and/or subnet mask values of a network\r |
2284 | device. The NewStationIp field is used to modify the network device's current IP address.\r | |
2285 | If NewStationIP is NULL, then the current IP address will not be modified. Otherwise,\r | |
2286 | this function updates the StationIp field of the EFI_PXE_BASE_CODE_MODE structure\r | |
2287 | with NewStationIp. The NewSubnetMask field is used to modify the network device's current subnet\r | |
2288 | mask. If NewSubnetMask is NULL, then the current subnet mask will not be modified.\r | |
2289 | Otherwise, this function updates the SubnetMask field of the EFI_PXE_BASE_CODE_MODE\r | |
2290 | structure with NewSubnetMask.\r | |
e2851998 | 2291 | \r |
f737cfb9 | 2292 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r |
e2851998 | 2293 | @param NewStationIp Pointer to the new IP address to be used by the network device.\r |
2294 | @param NewSubnetMask Pointer to the new subnet mask to be used by the network device.\r | |
2295 | \r | |
f737cfb9 | 2296 | @retval EFI_SUCCESS The new station IP address and/or subnet mask were updated.\r |
2297 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
e2851998 | 2298 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r |
2299 | \r | |
dc361cc5 | 2300 | **/\r |
2301 | EFI_STATUS\r | |
2302 | EFIAPI\r | |
2303 | EfiPxeBcSetStationIP (\r | |
2304 | IN EFI_PXE_BASE_CODE_PROTOCOL * This,\r | |
f737cfb9 | 2305 | IN EFI_IP_ADDRESS * NewStationIp OPTIONAL,\r |
dc361cc5 | 2306 | IN EFI_IP_ADDRESS * NewSubnetMask OPTIONAL\r |
2307 | )\r | |
2308 | {\r | |
2309 | PXEBC_PRIVATE_DATA *Private;\r | |
2310 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
8d285ec0 | 2311 | EFI_ARP_CONFIG_DATA ArpConfigData;\r |
dc361cc5 | 2312 | \r |
2313 | if (This == NULL) {\r | |
2314 | return EFI_INVALID_PARAMETER;\r | |
2315 | }\r | |
2316 | \r | |
01b5ac88 | 2317 | if (NewSubnetMask != NULL && !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask->Addr[0]))) {\r |
dc361cc5 | 2318 | return EFI_INVALID_PARAMETER;\r |
2319 | }\r | |
dc361cc5 | 2320 | \r |
e86f3635 FS |
2321 | if (NewStationIp != NULL) {\r |
2322 | if (IP4_IS_UNSPECIFIED(NTOHL (NewStationIp->Addr[0])) || \r | |
2323 | IP4_IS_LOCAL_BROADCAST(NTOHL (NewStationIp->Addr[0])) ||\r | |
2324 | (NewSubnetMask != NULL && !NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), NTOHL (NewSubnetMask->Addr[0])))) {\r | |
2325 | return EFI_INVALID_PARAMETER;\r | |
2326 | }\r | |
2327 | }\r | |
2328 | \r | |
dc361cc5 | 2329 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r |
2330 | Mode = Private->PxeBc.Mode;\r | |
2331 | \r | |
2332 | if (!Mode->Started) {\r | |
2333 | return EFI_NOT_STARTED;\r | |
2334 | }\r | |
2335 | \r | |
2336 | if (NewStationIp != NULL) {\r | |
555e76f8 | 2337 | CopyMem (&Mode->StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));\r |
2338 | CopyMem (&Private->StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));\r | |
dc361cc5 | 2339 | }\r |
2340 | \r | |
2341 | if (NewSubnetMask != NULL) {\r | |
555e76f8 | 2342 | CopyMem (&Mode->SubnetMask, NewSubnetMask, sizeof (EFI_IP_ADDRESS));\r |
2343 | CopyMem (&Private->SubnetMask ,NewSubnetMask, sizeof (EFI_IP_ADDRESS));\r | |
dc361cc5 | 2344 | }\r |
2345 | \r | |
2346 | Private->AddressIsOk = TRUE;\r | |
2347 | \r | |
8d285ec0 | 2348 | if (!Mode->UsingIpv6) {\r |
2349 | //\r | |
2350 | // If in IPv4 mode, configure the corresponding ARP with this new\r | |
2351 | // station IP address.\r | |
2352 | //\r | |
2353 | ZeroMem (&ArpConfigData, sizeof (EFI_ARP_CONFIG_DATA));\r | |
2354 | \r | |
2355 | ArpConfigData.SwAddressType = 0x0800;\r | |
c9325700 | 2356 | ArpConfigData.SwAddressLength = (UINT8) sizeof (EFI_IPv4_ADDRESS);\r |
8d285ec0 | 2357 | ArpConfigData.StationAddress = &Private->StationIp.v4;\r |
2358 | \r | |
2359 | Private->Arp->Configure (Private->Arp, NULL);\r | |
2360 | Private->Arp->Configure (Private->Arp, &ArpConfigData);\r | |
982a9eae | 2361 | \r |
2362 | //\r | |
2363 | // Update the route table.\r | |
2364 | //\r | |
2365 | Mode->RouteTableEntries = 1;\r | |
2366 | Mode->RouteTable[0].IpAddr.Addr[0] = Private->StationIp.Addr[0] & Private->SubnetMask.Addr[0];\r | |
2367 | Mode->RouteTable[0].SubnetMask.Addr[0] = Private->SubnetMask.Addr[0];\r | |
2368 | Mode->RouteTable[0].GwAddr.Addr[0] = 0;\r | |
8d285ec0 | 2369 | }\r |
2370 | \r | |
dc361cc5 | 2371 | return EFI_SUCCESS;\r |
2372 | }\r | |
2373 | \r | |
e2851998 | 2374 | /**\r |
f737cfb9 | 2375 | Updates the contents of the cached DHCP and Discover packets.\r |
e2851998 | 2376 | \r |
f737cfb9 | 2377 | The pointers to the new packets are used to update the contents of the cached\r |
2378 | packets in the EFI_PXE_BASE_CODE_MODE structure.\r | |
e2851998 | 2379 | \r |
f737cfb9 | 2380 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r |
2381 | @param NewDhcpDiscoverValid Pointer to a value that will replace the current\r | |
e2851998 | 2382 | DhcpDiscoverValid field.\r |
f737cfb9 | 2383 | @param NewDhcpAckReceived Pointer to a value that will replace the current\r |
e2851998 | 2384 | DhcpAckReceived field.\r |
f737cfb9 | 2385 | @param NewProxyOfferReceived Pointer to a value that will replace the current\r |
e2851998 | 2386 | ProxyOfferReceived field.\r |
2387 | @param NewPxeDiscoverValid Pointer to a value that will replace the current\r | |
2388 | ProxyOfferReceived field.\r | |
f737cfb9 | 2389 | @param NewPxeReplyReceived Pointer to a value that will replace the current\r |
e2851998 | 2390 | PxeReplyReceived field.\r |
f737cfb9 | 2391 | @param NewPxeBisReplyReceived Pointer to a value that will replace the current\r |
e2851998 | 2392 | PxeBisReplyReceived field.\r |
2393 | @param NewDhcpDiscover Pointer to the new cached DHCP Discover packet contents.\r | |
f737cfb9 | 2394 | @param NewDhcpAck Pointer to the new cached DHCP Ack packet contents.\r |
2395 | @param NewProxyOffer Pointer to the new cached Proxy Offer packet contents.\r | |
2396 | @param NewPxeDiscover Pointer to the new cached PXE Discover packet contents.\r | |
2397 | @param NewPxeReply Pointer to the new cached PXE Reply packet contents.\r | |
2398 | @param NewPxeBisReply Pointer to the new cached PXE BIS Reply packet contents.\r | |
e2851998 | 2399 | \r |
f737cfb9 | 2400 | @retval EFI_SUCCESS The cached packet contents were updated.\r |
2401 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
2402 | @retval EFI_INVALID_PARAMETER This is NULL or not point to a valid EFI_PXE_BASE_CODE_PROTOCOL structure.\r | |
e2851998 | 2403 | \r |
dc361cc5 | 2404 | **/\r |
2405 | EFI_STATUS\r | |
2406 | EFIAPI\r | |
2407 | EfiPxeBcSetPackets (\r | |
2408 | IN EFI_PXE_BASE_CODE_PROTOCOL * This,\r | |
f737cfb9 | 2409 | IN BOOLEAN * NewDhcpDiscoverValid OPTIONAL,\r |
2410 | IN BOOLEAN * NewDhcpAckReceived OPTIONAL,\r | |
2411 | IN BOOLEAN * NewProxyOfferReceived OPTIONAL,\r | |
2412 | IN BOOLEAN * NewPxeDiscoverValid OPTIONAL,\r | |
2413 | IN BOOLEAN * NewPxeReplyReceived OPTIONAL,\r | |
2414 | IN BOOLEAN * NewPxeBisReplyReceived OPTIONAL,\r | |
2415 | IN EFI_PXE_BASE_CODE_PACKET * NewDhcpDiscover OPTIONAL,\r | |
2416 | IN EFI_PXE_BASE_CODE_PACKET * NewDhcpAck OPTIONAL,\r | |
2417 | IN EFI_PXE_BASE_CODE_PACKET * NewProxyOffer OPTIONAL,\r | |
2418 | IN EFI_PXE_BASE_CODE_PACKET * NewPxeDiscover OPTIONAL,\r | |
2419 | IN EFI_PXE_BASE_CODE_PACKET * NewPxeReply OPTIONAL,\r | |
dc361cc5 | 2420 | IN EFI_PXE_BASE_CODE_PACKET * NewPxeBisReply OPTIONAL\r |
2421 | )\r | |
2422 | {\r | |
2423 | PXEBC_PRIVATE_DATA *Private;\r | |
2424 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
2425 | \r | |
2426 | if (This == NULL) {\r | |
2427 | return EFI_INVALID_PARAMETER;\r | |
2428 | }\r | |
2429 | \r | |
2430 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
2431 | Mode = Private->PxeBc.Mode;\r | |
2432 | \r | |
2433 | if (!Mode->Started) {\r | |
2434 | return EFI_NOT_STARTED;\r | |
2435 | }\r | |
2436 | \r | |
dc361cc5 | 2437 | if (NewDhcpDiscoverValid != NULL) {\r |
2438 | Mode->DhcpDiscoverValid = *NewDhcpDiscoverValid;\r | |
2439 | }\r | |
2440 | \r | |
2441 | if (NewDhcpAckReceived != NULL) {\r | |
2442 | Mode->DhcpAckReceived = *NewDhcpAckReceived;\r | |
2443 | }\r | |
2444 | \r | |
2445 | if (NewProxyOfferReceived != NULL) {\r | |
2446 | Mode->ProxyOfferReceived = *NewProxyOfferReceived;\r | |
2447 | }\r | |
2448 | \r | |
2449 | if (NewPxeDiscoverValid != NULL) {\r | |
2450 | Mode->PxeDiscoverValid = *NewPxeDiscoverValid;\r | |
2451 | }\r | |
2452 | \r | |
2453 | if (NewPxeReplyReceived != NULL) {\r | |
2454 | Mode->PxeReplyReceived = *NewPxeReplyReceived;\r | |
2455 | }\r | |
2456 | \r | |
2457 | if (NewPxeBisReplyReceived != NULL) {\r | |
2458 | Mode->PxeBisReplyReceived = *NewPxeBisReplyReceived;\r | |
2459 | }\r | |
2460 | \r | |
2461 | if (NewDhcpDiscover != NULL) {\r | |
e48e37fc | 2462 | CopyMem (&Mode->DhcpDiscover, NewDhcpDiscover, sizeof (EFI_PXE_BASE_CODE_PACKET));\r |
dc361cc5 | 2463 | }\r |
2464 | \r | |
2465 | if (NewDhcpAck != NULL) {\r | |
e48e37fc | 2466 | CopyMem (&Mode->DhcpAck, NewDhcpAck, sizeof (EFI_PXE_BASE_CODE_PACKET));\r |
dc361cc5 | 2467 | }\r |
2468 | \r | |
2469 | if (NewProxyOffer != NULL) {\r | |
e48e37fc | 2470 | CopyMem (&Mode->ProxyOffer, NewProxyOffer, sizeof (EFI_PXE_BASE_CODE_PACKET));\r |
dc361cc5 | 2471 | }\r |
2472 | \r | |
2473 | if (NewPxeDiscover != NULL) {\r | |
e48e37fc | 2474 | CopyMem (&Mode->PxeDiscover, NewPxeDiscover, sizeof (EFI_PXE_BASE_CODE_PACKET));\r |
dc361cc5 | 2475 | }\r |
2476 | \r | |
2477 | if (NewPxeReply != NULL) {\r | |
e48e37fc | 2478 | CopyMem (&Mode->PxeReply, NewPxeReply, sizeof (EFI_PXE_BASE_CODE_PACKET));\r |
dc361cc5 | 2479 | }\r |
2480 | \r | |
2481 | if (NewPxeBisReply != NULL) {\r | |
e48e37fc | 2482 | CopyMem (&Mode->PxeBisReply, NewPxeBisReply, sizeof (EFI_PXE_BASE_CODE_PACKET));\r |
dc361cc5 | 2483 | }\r |
2484 | \r | |
2485 | return EFI_SUCCESS;\r | |
2486 | }\r | |
2487 | \r | |
2488 | EFI_PXE_BASE_CODE_PROTOCOL mPxeBcProtocolTemplate = {\r | |
2489 | EFI_PXE_BASE_CODE_PROTOCOL_REVISION,\r | |
2490 | EfiPxeBcStart,\r | |
2491 | EfiPxeBcStop,\r | |
2492 | EfiPxeBcDhcp,\r | |
2493 | EfiPxeBcDiscover,\r | |
2494 | EfiPxeBcMtftp,\r | |
2495 | EfiPxeBcUdpWrite,\r | |
2496 | EfiPxeBcUdpRead,\r | |
2497 | EfiPxeBcSetIpFilter,\r | |
2498 | EfiPxeBcArp,\r | |
2499 | EfiPxeBcSetParameters,\r | |
2500 | EfiPxeBcSetStationIP,\r | |
2501 | EfiPxeBcSetPackets,\r | |
2502 | NULL\r | |
2503 | };\r | |
2504 | \r | |
e2851998 | 2505 | /**\r |
f737cfb9 | 2506 | Callback function that is invoked when the PXE Base Code Protocol is about to transmit, has\r |
e2851998 | 2507 | received, or is waiting to receive a packet.\r |
2508 | \r | |
f737cfb9 | 2509 | This function is invoked when the PXE Base Code Protocol is about to transmit, has received,\r |
2510 | or is waiting to receive a packet. Parameters Function and Received specify the type of event.\r | |
2511 | Parameters PacketLen and Packet specify the packet that generated the event. If these fields\r | |
2512 | are zero and NULL respectively, then this is a status update callback. If the operation specified\r | |
2513 | by Function is to continue, then CALLBACK_STATUS_CONTINUE should be returned. If the operation\r | |
2514 | specified by Function should be aborted, then CALLBACK_STATUS_ABORT should be returned. Due to\r | |
2515 | the polling nature of UEFI device drivers, a callback function should not execute for more than 5 ms.\r | |
2516 | The SetParameters() function must be called after a Callback Protocol is installed to enable the\r | |
2517 | use of callbacks.\r | |
e2851998 | 2518 | \r |
f737cfb9 | 2519 | @param This Pointer to the EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL instance.\r |
e2851998 | 2520 | @param Function The PXE Base Code Protocol function that is waiting for an event.\r |
f737cfb9 | 2521 | @param Received TRUE if the callback is being invoked due to a receive event. FALSE if\r |
e2851998 | 2522 | the callback is being invoked due to a transmit event.\r |
f737cfb9 | 2523 | @param PacketLength The length, in bytes, of Packet. This field will have a value of zero if\r |
e2851998 | 2524 | this is a wait for receive event.\r |
f737cfb9 | 2525 | @param PacketPtr If Received is TRUE, a pointer to the packet that was just received;\r |
e2851998 | 2526 | otherwise a pointer to the packet that is about to be transmitted.\r |
2527 | \r | |
2528 | @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE if Function specifies a continue operation\r | |
f737cfb9 | 2529 | @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT if Function specifies an abort operation\r |
e2851998 | 2530 | \r |
dc361cc5 | 2531 | **/\r |
2532 | EFI_PXE_BASE_CODE_CALLBACK_STATUS\r | |
2533 | EFIAPI\r | |
2534 | EfiPxeLoadFileCallback (\r | |
2535 | IN EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL * This,\r | |
2536 | IN EFI_PXE_BASE_CODE_FUNCTION Function,\r | |
2537 | IN BOOLEAN Received,\r | |
2538 | IN UINT32 PacketLength,\r | |
2539 | IN EFI_PXE_BASE_CODE_PACKET * PacketPtr OPTIONAL\r | |
2540 | )\r | |
2541 | {\r | |
2542 | EFI_INPUT_KEY Key;\r | |
2543 | EFI_STATUS Status;\r | |
2544 | \r | |
2545 | //\r | |
2546 | // Catch Ctrl-C or ESC to abort.\r | |
2547 | //\r | |
2548 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
2549 | \r | |
2550 | if (!EFI_ERROR (Status)) {\r | |
2551 | \r | |
2552 | if (Key.ScanCode == SCAN_ESC || Key.UnicodeChar == (0x1F & 'c')) {\r | |
2553 | \r | |
2554 | return EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT;\r | |
2555 | }\r | |
2556 | }\r | |
2557 | //\r | |
2558 | // No print if receive packet\r | |
2559 | //\r | |
2560 | if (Received) {\r | |
2561 | return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;\r | |
2562 | }\r | |
2563 | //\r | |
2564 | // Print only for three functions\r | |
2565 | //\r | |
2566 | switch (Function) {\r | |
2567 | \r | |
2568 | case EFI_PXE_BASE_CODE_FUNCTION_MTFTP:\r | |
2569 | //\r | |
2570 | // Print only for open MTFTP packets, not every MTFTP packets\r | |
2571 | //\r | |
2572 | if (PacketLength != 0 && PacketPtr != NULL) {\r | |
2573 | if (PacketPtr->Raw[0x1C] != 0x00 || PacketPtr->Raw[0x1D] != 0x01) {\r | |
2574 | return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;\r | |
2575 | }\r | |
2576 | }\r | |
2577 | break;\r | |
2578 | \r | |
2579 | case EFI_PXE_BASE_CODE_FUNCTION_DHCP:\r | |
2580 | case EFI_PXE_BASE_CODE_FUNCTION_DISCOVER:\r | |
2581 | break;\r | |
2582 | \r | |
2583 | default:\r | |
2584 | return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;\r | |
2585 | }\r | |
2586 | \r | |
2587 | if (PacketLength != 0 && PacketPtr != NULL) {\r | |
2588 | //\r | |
2589 | // Print '.' when transmit a packet\r | |
2590 | //\r | |
2591 | AsciiPrint (".");\r | |
2592 | \r | |
2593 | }\r | |
2594 | \r | |
2595 | return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;\r | |
2596 | }\r | |
2597 | \r | |
2598 | EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL mPxeBcCallBackTemplate = {\r | |
2599 | EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL_REVISION,\r | |
2600 | EfiPxeLoadFileCallback\r | |
2601 | };\r | |
2602 | \r | |
2603 | \r | |
2604 | /**\r | |
f737cfb9 | 2605 | Find the boot file.\r |
dc361cc5 | 2606 | \r |
e2851998 | 2607 | @param Private Pointer to PxeBc private data.\r |
2608 | @param BufferSize Pointer to buffer size.\r | |
2609 | @param Buffer Pointer to buffer.\r | |
dc361cc5 | 2610 | \r |
f737cfb9 | 2611 | @retval EFI_SUCCESS Discover the boot file successfully.\r |
2612 | @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.\r | |
2613 | @retval EFI_ABORTED PXE bootstrap server, so local boot need abort.\r | |
2614 | @retval EFI_BUFFER_TOO_SMALL The buffer is too small to load the boot file.\r | |
e2851998 | 2615 | \r |
dc361cc5 | 2616 | **/\r |
2617 | EFI_STATUS\r | |
2618 | DiscoverBootFile (\r | |
2619 | IN PXEBC_PRIVATE_DATA *Private,\r | |
2620 | IN OUT UINT64 *BufferSize,\r | |
2621 | IN VOID *Buffer\r | |
2622 | )\r | |
2623 | {\r | |
2624 | EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r | |
2625 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
2626 | EFI_STATUS Status;\r | |
2627 | UINT16 Type;\r | |
2628 | UINT16 Layer;\r | |
2629 | BOOLEAN UseBis;\r | |
dc361cc5 | 2630 | PXEBC_CACHED_DHCP4_PACKET *Packet;\r |
2631 | UINT16 Value;\r | |
2632 | \r | |
2633 | PxeBc = &Private->PxeBc;\r | |
2634 | Mode = PxeBc->Mode;\r | |
2635 | Type = EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP;\r | |
2636 | Layer = EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL;\r | |
2637 | \r | |
2638 | //\r | |
2639 | // do DHCP.\r | |
2640 | //\r | |
2641 | Status = PxeBc->Dhcp (PxeBc, TRUE);\r | |
2642 | if (EFI_ERROR (Status)) {\r | |
2643 | return Status;\r | |
2644 | }\r | |
2645 | \r | |
2646 | //\r | |
2647 | // Select a boot server\r | |
2648 | //\r | |
2649 | Status = PxeBcSelectBootPrompt (Private);\r | |
2650 | \r | |
2651 | if (Status == EFI_SUCCESS) {\r | |
2652 | Status = PxeBcSelectBootMenu (Private, &Type, TRUE);\r | |
2653 | } else if (Status == EFI_TIMEOUT) {\r | |
2654 | Status = PxeBcSelectBootMenu (Private, &Type, FALSE);\r | |
2655 | }\r | |
2656 | \r | |
2657 | if (!EFI_ERROR (Status)) {\r | |
2658 | \r | |
2659 | if (Type == EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP) {\r | |
2660 | //\r | |
2661 | // Local boot(PXE bootstrap server) need abort\r | |
2662 | //\r | |
2663 | return EFI_ABORTED;\r | |
2664 | }\r | |
2665 | \r | |
2666 | UseBis = (BOOLEAN) (Mode->BisSupported && Mode->BisDetected);\r | |
2667 | Status = PxeBc->Discover (PxeBc, Type, &Layer, UseBis, NULL);\r | |
2668 | if (EFI_ERROR (Status)) {\r | |
2669 | return Status;\r | |
2670 | }\r | |
2671 | }\r | |
2672 | \r | |
2673 | *BufferSize = 0;\r | |
dc361cc5 | 2674 | \r |
2675 | //\r | |
2676 | // Get bootfile name and (m)tftp server ip addresss\r | |
2677 | //\r | |
2678 | if (Mode->PxeReplyReceived) {\r | |
2679 | Packet = &Private->PxeReply;\r | |
2680 | } else if (Mode->ProxyOfferReceived) {\r | |
2681 | Packet = &Private->ProxyOffer;\r | |
2682 | } else {\r | |
2683 | Packet = &Private->Dhcp4Ack;\r | |
2684 | }\r | |
2685 | \r | |
319075ff | 2686 | //\r |
2ce5c88a | 2687 | // Use siaddr(next server) in DHCPOFFER packet header, if zero, use option 54(server identifier)\r |
2688 | // in DHCPOFFER packet.\r | |
2689 | // (It does not comply with PXE Spec, Ver2.1)\r | |
319075ff | 2690 | //\r |
2ce5c88a | 2691 | if (EFI_IP4_EQUAL (&Packet->Packet.Offer.Dhcp4.Header.ServerAddr, &mZeroIp4Addr)) {\r |
e48e37fc | 2692 | CopyMem (\r |
dc361cc5 | 2693 | &Private->ServerIp,\r |
2694 | Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_SERVER_ID]->Data,\r | |
2695 | sizeof (EFI_IPv4_ADDRESS)\r | |
2696 | );\r | |
319075ff | 2697 | } else {\r |
2698 | CopyMem (\r | |
e2851998 | 2699 | &Private->ServerIp,\r |
2700 | &Packet->Packet.Offer.Dhcp4.Header.ServerAddr,\r | |
319075ff | 2701 | sizeof (EFI_IPv4_ADDRESS)\r |
2702 | );\r | |
2703 | }\r | |
2704 | if (Private->ServerIp.Addr[0] == 0) {\r | |
2705 | return EFI_DEVICE_ERROR;\r | |
dc361cc5 | 2706 | }\r |
2707 | \r | |
2708 | ASSERT (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL);\r | |
2709 | \r | |
2710 | //\r | |
2711 | // bootlfile name\r | |
2712 | //\r | |
2713 | Private->BootFileName = (CHAR8 *) (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Data);\r | |
2714 | \r | |
2715 | if (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN] != NULL) {\r | |
2716 | //\r | |
2717 | // Already have the bootfile length option, compute the file size\r | |
2718 | //\r | |
e48e37fc | 2719 | CopyMem (&Value, Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN]->Data, sizeof (Value));\r |
dc361cc5 | 2720 | Value = NTOHS (Value);\r |
2721 | *BufferSize = 512 * Value;\r | |
2722 | Status = EFI_BUFFER_TOO_SMALL;\r | |
2723 | } else {\r | |
2724 | //\r | |
2725 | // Get the bootfile size from tftp\r | |
2726 | //\r | |
2727 | Status = PxeBc->Mtftp (\r | |
2728 | PxeBc,\r | |
2729 | EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,\r | |
2730 | Buffer,\r | |
2731 | FALSE,\r | |
2732 | BufferSize,\r | |
fa6d3ee4 | 2733 | &Private->BlockSize,\r |
dc361cc5 | 2734 | &Private->ServerIp,\r |
2735 | (UINT8 *) Private->BootFileName,\r | |
2736 | NULL,\r | |
2737 | FALSE\r | |
2738 | );\r | |
2739 | }\r | |
2740 | \r | |
2741 | Private->FileSize = (UINTN) *BufferSize;\r | |
2742 | \r | |
2743 | return Status;\r | |
2744 | }\r | |
2745 | \r | |
dc361cc5 | 2746 | /**\r |
f737cfb9 | 2747 | Causes the driver to load a specified file.\r |
2748 | \r | |
2749 | @param This Protocol instance pointer.\r | |
2750 | @param FilePath The device specific path of the file to load.\r | |
e2851998 | 2751 | @param BootPolicy If TRUE, indicates that the request originates from the\r |
f737cfb9 | 2752 | boot manager is attempting to load FilePath as a boot\r |
2753 | selection. If FALSE, then FilePath must match as exact file\r | |
2754 | to be loaded.\r | |
2755 | @param BufferSize On input the size of Buffer in bytes. On output with a return\r | |
e2851998 | 2756 | code of EFI_SUCCESS, the amount of data transferred to\r |
f737cfb9 | 2757 | Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,\r |
2758 | the size of Buffer required to retrieve the requested file.\r | |
2759 | @param Buffer The memory buffer to transfer the file to. IF Buffer is NULL,\r | |
e2851998 | 2760 | then no the size of the requested file is returned in\r |
f737cfb9 | 2761 | BufferSize.\r |
2762 | \r | |
2763 | @retval EFI_SUCCESS The file was loaded.\r | |
2764 | @retval EFI_UNSUPPORTED The device does not support the provided BootPolicy\r | |
e2851998 | 2765 | @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or\r |
f737cfb9 | 2766 | BufferSize is NULL.\r |
2767 | @retval EFI_NO_MEDIA No medium was present to load the file.\r | |
2768 | @retval EFI_DEVICE_ERROR The file was not loaded due to a device error.\r | |
2769 | @retval EFI_NO_RESPONSE The remote system did not respond.\r | |
2770 | @retval EFI_NOT_FOUND The file was not found.\r | |
2771 | @retval EFI_ABORTED The file load process was manually cancelled.\r | |
dc361cc5 | 2772 | \r |
2773 | **/\r | |
2774 | EFI_STATUS\r | |
2775 | EFIAPI\r | |
2776 | EfiPxeLoadFile (\r | |
2777 | IN EFI_LOAD_FILE_PROTOCOL * This,\r | |
2778 | IN EFI_DEVICE_PATH_PROTOCOL * FilePath,\r | |
2779 | IN BOOLEAN BootPolicy,\r | |
2780 | IN OUT UINTN *BufferSize,\r | |
2781 | IN VOID *Buffer OPTIONAL\r | |
2782 | )\r | |
2783 | {\r | |
2784 | PXEBC_PRIVATE_DATA *Private;\r | |
2785 | EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r | |
2786 | BOOLEAN NewMakeCallback;\r | |
dc361cc5 | 2787 | EFI_STATUS Status;\r |
2788 | UINT64 TmpBufSize;\r | |
dd29f3ed | 2789 | BOOLEAN MediaPresent;\r |
dc361cc5 | 2790 | \r |
6758032d ZL |
2791 | if (FilePath == NULL || !IsDevicePathEnd (FilePath)) {\r |
2792 | return EFI_INVALID_PARAMETER;\r | |
2793 | }\r | |
2794 | \r | |
dc361cc5 | 2795 | Private = PXEBC_PRIVATE_DATA_FROM_LOADFILE (This);\r |
2796 | PxeBc = &Private->PxeBc;\r | |
2797 | NewMakeCallback = FALSE;\r | |
dc361cc5 | 2798 | Status = EFI_DEVICE_ERROR;\r |
2799 | \r | |
2800 | if (This == NULL || BufferSize == NULL) {\r | |
2801 | \r | |
2802 | return EFI_INVALID_PARAMETER;\r | |
2803 | }\r | |
2804 | \r | |
2805 | //\r | |
2806 | // Only support BootPolicy\r | |
2807 | //\r | |
2808 | if (!BootPolicy) {\r | |
2809 | return EFI_UNSUPPORTED;\r | |
2810 | }\r | |
2811 | \r | |
dd29f3ed | 2812 | //\r |
2813 | // Check media status before PXE start\r | |
2814 | //\r | |
2815 | MediaPresent = TRUE;\r | |
2816 | NetLibDetectMedia (Private->Controller, &MediaPresent);\r | |
2817 | if (!MediaPresent) {\r | |
2818 | return EFI_NO_MEDIA;\r | |
2819 | }\r | |
2820 | \r | |
dc361cc5 | 2821 | Status = PxeBc->Start (PxeBc, FALSE);\r |
2822 | if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {\r | |
2823 | return Status;\r | |
2824 | }\r | |
2825 | \r | |
2826 | Status = gBS->HandleProtocol (\r | |
2827 | Private->Controller,\r | |
2828 | &gEfiPxeBaseCodeCallbackProtocolGuid,\r | |
2829 | (VOID **) &Private->PxeBcCallback\r | |
2830 | );\r | |
2831 | if (Status == EFI_UNSUPPORTED) {\r | |
2832 | \r | |
2833 | CopyMem (&Private->LoadFileCallback, &mPxeBcCallBackTemplate, sizeof (Private->LoadFileCallback));\r | |
2834 | \r | |
2835 | Status = gBS->InstallProtocolInterface (\r | |
2836 | &Private->Controller,\r | |
2837 | &gEfiPxeBaseCodeCallbackProtocolGuid,\r | |
2838 | EFI_NATIVE_INTERFACE,\r | |
2839 | &Private->LoadFileCallback\r | |
2840 | );\r | |
2841 | \r | |
2842 | NewMakeCallback = (BOOLEAN) (Status == EFI_SUCCESS);\r | |
2843 | \r | |
2844 | Status = PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, &NewMakeCallback);\r | |
2845 | if (EFI_ERROR (Status)) {\r | |
2846 | PxeBc->Stop (PxeBc);\r | |
2847 | return Status;\r | |
2848 | }\r | |
2849 | }\r | |
2850 | \r | |
2851 | if (Private->FileSize == 0) {\r | |
2852 | TmpBufSize = 0;\r | |
2853 | Status = DiscoverBootFile (Private, &TmpBufSize, Buffer);\r | |
2854 | \r | |
2855 | if (sizeof (UINTN) < sizeof (UINT64) && (TmpBufSize > 0xFFFFFFFF)) {\r | |
2856 | Status = EFI_DEVICE_ERROR;\r | |
39941daf | 2857 | } else if (TmpBufSize > 0 && *BufferSize >= (UINTN) TmpBufSize && Buffer != NULL) {\r |
319075ff | 2858 | *BufferSize = (UINTN) TmpBufSize;\r |
2859 | Status = PxeBc->Mtftp (\r | |
2860 | PxeBc,\r | |
2861 | EFI_PXE_BASE_CODE_TFTP_READ_FILE,\r | |
2862 | Buffer,\r | |
2863 | FALSE,\r | |
2864 | &TmpBufSize,\r | |
fa6d3ee4 | 2865 | &Private->BlockSize,\r |
319075ff | 2866 | &Private->ServerIp,\r |
2867 | (UINT8 *) Private->BootFileName,\r | |
2868 | NULL,\r | |
2869 | FALSE\r | |
2870 | );\r | |
39941daf | 2871 | } else if (TmpBufSize > 0) {\r |
dc361cc5 | 2872 | *BufferSize = (UINTN) TmpBufSize;\r |
319075ff | 2873 | Status = EFI_BUFFER_TOO_SMALL;\r |
dc361cc5 | 2874 | }\r |
319075ff | 2875 | } else if (Buffer == NULL || Private->FileSize > *BufferSize) {\r |
dc361cc5 | 2876 | *BufferSize = Private->FileSize;\r |
2877 | Status = EFI_BUFFER_TOO_SMALL;\r | |
2878 | } else {\r | |
2879 | //\r | |
2880 | // Download the file.\r | |
2881 | //\r | |
2882 | TmpBufSize = (UINT64) (*BufferSize);\r | |
2883 | Status = PxeBc->Mtftp (\r | |
2884 | PxeBc,\r | |
2885 | EFI_PXE_BASE_CODE_TFTP_READ_FILE,\r | |
2886 | Buffer,\r | |
2887 | FALSE,\r | |
2888 | &TmpBufSize,\r | |
fa6d3ee4 | 2889 | &Private->BlockSize,\r |
dc361cc5 | 2890 | &Private->ServerIp,\r |
2891 | (UINT8 *) Private->BootFileName,\r | |
2892 | NULL,\r | |
2893 | FALSE\r | |
2894 | );\r | |
2895 | }\r | |
2896 | //\r | |
2897 | // If we added a callback protocol, now is the time to remove it.\r | |
2898 | //\r | |
2899 | if (NewMakeCallback) {\r | |
2900 | \r | |
2901 | NewMakeCallback = FALSE;\r | |
2902 | \r | |
2903 | PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, &NewMakeCallback);\r | |
2904 | \r | |
2905 | gBS->UninstallProtocolInterface (\r | |
2906 | Private->Controller,\r | |
2907 | &gEfiPxeBaseCodeCallbackProtocolGuid,\r | |
2908 | &Private->LoadFileCallback\r | |
2909 | );\r | |
2910 | }\r | |
619eff3f | 2911 | \r |
dc361cc5 | 2912 | //\r |
2913 | // Check download status\r | |
2914 | //\r | |
619eff3f | 2915 | if (Status == EFI_SUCCESS) {\r |
6ee21b60 | 2916 | //\r |
30268f29 FS |
2917 | // The DHCP4 can have only one configured child instance so we need to stop\r |
2918 | // reset the DHCP4 child before we return. Otherwise the other programs which \r | |
2919 | // also need to use DHCP4 will be impacted.\r | |
6ee21b60 | 2920 | // The functionality of PXE Base Code protocol will not be stopped,\r |
2921 | // when downloading is successfully.\r | |
2922 | //\r | |
30268f29 FS |
2923 | Private->Dhcp4->Stop (Private->Dhcp4);\r |
2924 | Private->Dhcp4->Configure (Private->Dhcp4, NULL);\r | |
8792362f | 2925 | return EFI_SUCCESS;\r |
dc361cc5 | 2926 | \r |
619eff3f | 2927 | } else if (Status == EFI_BUFFER_TOO_SMALL) {\r |
dc361cc5 | 2928 | if (Buffer != NULL) {\r |
2929 | AsciiPrint ("PXE-E05: Download buffer is smaller than requested file.\n");\r | |
2930 | } else {\r | |
ee6e8714 | 2931 | //\r |
2932 | // The functionality of PXE Base Code protocol will not be stopped.\r | |
2933 | //\r | |
dc361cc5 | 2934 | return Status;\r |
2935 | }\r | |
dc361cc5 | 2936 | \r |
619eff3f | 2937 | } else if (Status == EFI_DEVICE_ERROR) {\r |
dc361cc5 | 2938 | AsciiPrint ("PXE-E07: Network device error.\n");\r |
dc361cc5 | 2939 | \r |
619eff3f | 2940 | } else if (Status == EFI_OUT_OF_RESOURCES) {\r |
dc361cc5 | 2941 | AsciiPrint ("PXE-E09: Could not allocate I/O buffers.\n");\r |
dc361cc5 | 2942 | \r |
619eff3f | 2943 | } else if (Status == EFI_NO_MEDIA) {\r |
dc361cc5 | 2944 | AsciiPrint ("PXE-E12: Could not detect network connection.\n");\r |
dc361cc5 | 2945 | \r |
619eff3f | 2946 | } else if (Status == EFI_NO_RESPONSE) {\r |
dc361cc5 | 2947 | AsciiPrint ("PXE-E16: No offer received.\n");\r |
dc361cc5 | 2948 | \r |
619eff3f | 2949 | } else if (Status == EFI_TIMEOUT) {\r |
dc361cc5 | 2950 | AsciiPrint ("PXE-E18: Server response timeout.\n");\r |
dc361cc5 | 2951 | \r |
619eff3f | 2952 | } else if (Status == EFI_ABORTED) {\r |
dc361cc5 | 2953 | AsciiPrint ("PXE-E21: Remote boot cancelled.\n");\r |
dc361cc5 | 2954 | \r |
619eff3f | 2955 | } else if (Status == EFI_ICMP_ERROR) {\r |
dc361cc5 | 2956 | AsciiPrint ("PXE-E22: Client received ICMP error from server.\n");\r |
dc361cc5 | 2957 | \r |
619eff3f | 2958 | } else if (Status == EFI_TFTP_ERROR) {\r |
dc361cc5 | 2959 | AsciiPrint ("PXE-E23: Client received TFTP error from server.\n");\r |
dc361cc5 | 2960 | \r |
619eff3f | 2961 | } else {\r |
dc361cc5 | 2962 | AsciiPrint ("PXE-E99: Unexpected network error.\n");\r |
dc361cc5 | 2963 | }\r |
2964 | \r | |
2965 | PxeBc->Stop (PxeBc);\r | |
2966 | \r | |
2967 | return Status;\r | |
2968 | }\r | |
2969 | \r | |
434ce3fe | 2970 | EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate = { EfiPxeLoadFile };\r |
2971 | \r |