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