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