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