]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
1. Add EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName() support.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Impl.c
1 /** @file
2
3 Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 **/
13
14 #include "Ip4Impl.h"
15
16 EFI_IPSEC2_PROTOCOL *mIpSec = NULL;
17
18 /**
19 Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.
20
21 The GetModeData() function returns the current operational mode data for this
22 driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This
23 function is used optionally to retrieve the operational mode data of underlying
24 networks or drivers.
25
26 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
27 @param[out] Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.
28 @param[out] MnpConfigData Pointer to the managed network configuration data structure.
29 @param[out] SnpModeData Pointer to the simple network mode data structure.
30
31 @retval EFI_SUCCESS The operation completed successfully.
32 @retval EFI_INVALID_PARAMETER This is NULL.
33 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
34
35 **/
36 EFI_STATUS
37 EFIAPI
38 EfiIp4GetModeData (
39 IN CONST EFI_IP4_PROTOCOL *This,
40 OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL,
41 OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
42 OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
43 );
44
45 /**
46 Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
47
48 The Configure() function is used to set, change, or reset the operational
49 parameters and filter settings for this EFI IPv4 Protocol instance. Until these
50 parameters have been set, no network traffic can be sent or received by this
51 instance. Once the parameters have been reset (by calling this function with
52 IpConfigData set to NULL), no more traffic can be sent or received until these
53 parameters have been set again. Each EFI IPv4 Protocol instance can be started
54 and stopped independently of each other by enabling or disabling their receive
55 filter settings with the Configure() function.
56
57 When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will
58 be appended as an alias address into the addresses list in the EFI IPv4 Protocol
59 driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL
60 to retrieve the default IPv4 address if it is not available yet. Clients could
61 frequently call GetModeData() to check the status to ensure that the default IPv4
62 address is ready.
63
64 If operational parameters are reset or changed, any pending transmit and receive
65 requests will be cancelled. Their completion token status will be set to EFI_ABORTED
66 and their events will be signaled.
67
68 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
69 @param[in] IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.
70
71 @retval EFI_SUCCESS The driver instance was successfully opened.
72 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
73 RARP, etc.) is not finished yet.
74 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
75 @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:
76 A configuration protocol (DHCP, BOOTP, RARP, etc.) could
77 not be located when clients choose to use the default IPv4
78 address. This EFI IPv4 Protocol implementation does not
79 support this requested filter or timeout setting.
80 @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.
81 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the
82 IPv4 address or subnet mask can be changed. The interface must
83 also be stopped when switching to/from raw packet mode.
84 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4
85 Protocol driver instance is not opened.
86
87 **/
88 EFI_STATUS
89 EFIAPI
90 EfiIp4Configure (
91 IN EFI_IP4_PROTOCOL *This,
92 IN EFI_IP4_CONFIG_DATA *IpConfigData OPTIONAL
93 );
94
95 /**
96 Joins and leaves multicast groups.
97
98 The Groups() function is used to join and leave multicast group sessions. Joining
99 a group will enable reception of matching multicast packets. Leaving a group will
100 disable the multicast packet reception.
101
102 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
103
104 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
105 @param[in] JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.
106 @param[in] GroupAddress Pointer to the IPv4 multicast address.
107
108 @retval EFI_SUCCESS The operation completed successfully.
109 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
110 - This is NULL.
111 - JoinFlag is TRUE and GroupAddress is NULL.
112 - GroupAddress is not NULL and *GroupAddress is
113 not a multicast IPv4 address.
114 @retval EFI_NOT_STARTED This instance has not been started.
115 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
116 RARP, etc.) is not finished yet.
117 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
118 @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.
119 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
120 JoinFlag is TRUE).
121 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
122 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
123
124 **/
125 EFI_STATUS
126 EFIAPI
127 EfiIp4Groups (
128 IN EFI_IP4_PROTOCOL *This,
129 IN BOOLEAN JoinFlag,
130 IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL
131 );
132
133 /**
134 Adds and deletes routing table entries.
135
136 The Routes() function adds a route to or deletes a route from the routing table.
137
138 Routes are determined by comparing the SubnetAddress with the destination IPv4
139 address arithmetically AND-ed with the SubnetMask. The gateway address must be
140 on the same subnet as the configured station address.
141
142 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
143 The default route matches all destination IPv4 addresses that do not match any
144 other routes.
145
146 A GatewayAddress that is zero is a nonroute. Packets are sent to the destination
147 IP address if it can be found in the ARP cache or on the local subnet. One automatic
148 nonroute entry will be inserted into the routing table for outgoing packets that
149 are addressed to a local subnet (gateway address of 0.0.0.0).
150
151 Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI
152 IPv4 Protocol instances that use the default IPv4 address will also have copies
153 of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these
154 copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its
155 instances. As a result, client modification to the routing table will be lost.
156
157 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
158 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
159 FALSE to add this route to the routing table. SubnetAddress
160 and SubnetMask are used as the key to each route entry.
161 @param[in] SubnetAddress The address of the subnet that needs to be routed.
162 @param[in] SubnetMask The subnet mask of SubnetAddress.
163 @param[in] GatewayAddress The unicast gateway IPv4 address for this route.
164
165 @retval EFI_SUCCESS The operation completed successfully.
166 @retval EFI_NOT_STARTED The driver instance has not been started.
167 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
168 RARP, etc.) is not finished yet.
169 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
170 - This is NULL.
171 - SubnetAddress is NULL.
172 - SubnetMask is NULL.
173 - GatewayAddress is NULL.
174 - *SubnetAddress is not a valid subnet address.
175 - *SubnetMask is not a valid subnet mask.
176 - *GatewayAddress is not a valid unicast IPv4 address.
177 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
178 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
179 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
180 DeleteRoute is FALSE).
181
182 **/
183 EFI_STATUS
184 EFIAPI
185 EfiIp4Routes (
186 IN EFI_IP4_PROTOCOL *This,
187 IN BOOLEAN DeleteRoute,
188 IN EFI_IPv4_ADDRESS *SubnetAddress,
189 IN EFI_IPv4_ADDRESS *SubnetMask,
190 IN EFI_IPv4_ADDRESS *GatewayAddress
191 );
192
193 /**
194 Places outgoing data packets into the transmit queue.
195
196 The Transmit() function places a sending request in the transmit queue of this
197 EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some
198 errors occur, the event in the token will be signaled and the status is updated.
199
200 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
201 @param[in] Token Pointer to the transmit token.
202
203 @retval EFI_SUCCESS The data has been queued for transmission.
204 @retval EFI_NOT_STARTED This instance has not been started.
205 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
206 RARP, etc.) is not finished yet.
207 @retval EFI_INVALID_PARAMETER One or more pameters are invalid.
208 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event
209 was already in the transmit queue.
210 @retval EFI_NOT_READY The completion token could not be queued because the transmit
211 queue is full.
212 @retval EFI_NOT_FOUND Not route is found to destination address.
213 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
214 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
215 short to transmit.
216 @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is
217 greater than MTU (or greater than the maximum packet size if
218 Token.Packet.TxData.OverrideData.
219 DoNotFragment is TRUE.)
220
221 **/
222 EFI_STATUS
223 EFIAPI
224 EfiIp4Transmit (
225 IN EFI_IP4_PROTOCOL *This,
226 IN EFI_IP4_COMPLETION_TOKEN *Token
227 );
228
229 /**
230 Places a receiving request into the receiving queue.
231
232 The Receive() function places a completion token into the receive packet queue.
233 This function is always asynchronous.
234
235 The Token.Event field in the completion token must be filled in by the caller
236 and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol
237 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
238 is signaled.
239
240 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
241 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
242
243 @retval EFI_SUCCESS The receive completion token was cached.
244 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
245 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)
246 is not finished yet.
247 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
248 - This is NULL.
249 - Token is NULL.
250 - Token.Event is NULL.
251 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
252 resources (usually memory).
253 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
254 The EFI IPv4 Protocol instance has been reset to startup defaults.
255 EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
256 in the receive queue.
257 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
258 @retval EFI_ICMP_ERROR An ICMP error packet was received.
259
260 **/
261 EFI_STATUS
262 EFIAPI
263 EfiIp4Receive (
264 IN EFI_IP4_PROTOCOL *This,
265 IN EFI_IP4_COMPLETION_TOKEN *Token
266 );
267
268 /**
269 Abort an asynchronous transmit or receive request.
270
271 The Cancel() function is used to abort a pending transmit or receive request.
272 If the token is in the transmit or receive request queues, after calling this
273 function, Token->Status will be set to EFI_ABORTED and then Token->Event will
274 be signaled. If the token is not in one of the queues, which usually means the
275 asynchronous operation has completed, this function will not signal the token
276 and EFI_NOT_FOUND is returned.
277
278 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
279 @param[in] Token Pointer to a token that has been issued by
280 EFI_IP4_PROTOCOL.Transmit() or
281 EFI_IP4_PROTOCOL.Receive(). If NULL, all pending
282 tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is
283 defined in EFI_IP4_PROTOCOL.Transmit().
284
285 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
286 Token.->Event was signaled. When Token is NULL, all
287 pending requests were aborted and their events were signaled.
288 @retval EFI_INVALID_PARAMETER This is NULL.
289 @retval EFI_NOT_STARTED This instance has not been started.
290 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
291 RARP, etc.) is not finished yet.
292 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
293 not found in the transmit or receive queue. It has either completed
294 or was not issued by Transmit() and Receive().
295
296 **/
297 EFI_STATUS
298 EFIAPI
299 EfiIp4Cancel (
300 IN EFI_IP4_PROTOCOL *This,
301 IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL
302 );
303
304 /**
305 Polls for incoming data packets and processes outgoing data packets.
306
307 The Poll() function polls for incoming data packets and processes outgoing data
308 packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()
309 function to increase the rate that data packets are moved between the communications
310 device and the transmit and receive queues.
311
312 In some systems the periodic timer event may not poll the underlying communications
313 device fast enough to transmit and/or receive all data packets without missing
314 incoming packets or dropping outgoing packets. Drivers and applications that are
315 experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function
316 more often.
317
318 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
319
320 @retval EFI_SUCCESS Incoming or outgoing data was processed.
321 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
322 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
323 RARP, etc.) is not finished yet.
324 @retval EFI_INVALID_PARAMETER This is NULL.
325 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
326 @retval EFI_NOT_READY No incoming or outgoing data is processed.
327 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
328 Consider increasing the polling rate.
329
330 **/
331 EFI_STATUS
332 EFIAPI
333 EfiIp4Poll (
334 IN EFI_IP4_PROTOCOL *This
335 );
336
337 EFI_IP4_PROTOCOL
338 mEfiIp4ProtocolTemplete = {
339 EfiIp4GetModeData,
340 EfiIp4Configure,
341 EfiIp4Groups,
342 EfiIp4Routes,
343 EfiIp4Transmit,
344 EfiIp4Receive,
345 EfiIp4Cancel,
346 EfiIp4Poll
347 };
348
349 /**
350 Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.
351
352 The GetModeData() function returns the current operational mode data for this
353 driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This
354 function is used optionally to retrieve the operational mode data of underlying
355 networks or drivers.
356
357 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
358 @param[out] Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.
359 @param[out] MnpConfigData Pointer to the managed network configuration data structure.
360 @param[out] SnpModeData Pointer to the simple network mode data structure.
361
362 @retval EFI_SUCCESS The operation completed successfully.
363 @retval EFI_INVALID_PARAMETER This is NULL.
364 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
365
366 **/
367 EFI_STATUS
368 EFIAPI
369 EfiIp4GetModeData (
370 IN CONST EFI_IP4_PROTOCOL *This,
371 OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL,
372 OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
373 OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
374 )
375 {
376 IP4_PROTOCOL *IpInstance;
377 IP4_SERVICE *IpSb;
378 EFI_IP4_CONFIG_DATA *Config;
379 EFI_STATUS Status;
380 EFI_TPL OldTpl;
381 IP4_ADDR Ip;
382
383 if (This == NULL) {
384 return EFI_INVALID_PARAMETER;
385 }
386
387 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
388 IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);
389 IpSb = IpInstance->Service;
390
391 if (Ip4ModeData != NULL) {
392 //
393 // IsStarted is "whether the EfiIp4Configure has been called".
394 // IsConfigured is "whether the station address has been configured"
395 //
396 Ip4ModeData->IsStarted = (BOOLEAN)(IpInstance->State == IP4_STATE_CONFIGED);
397 CopyMem (&Ip4ModeData->ConfigData, &IpInstance->ConfigData, sizeof (Ip4ModeData->ConfigData));
398 Ip4ModeData->IsConfigured = FALSE;
399
400 Ip4ModeData->GroupCount = IpInstance->GroupCount;
401 Ip4ModeData->GroupTable = (EFI_IPv4_ADDRESS *) IpInstance->Groups;
402
403 Ip4ModeData->IcmpTypeCount = 23;
404 Ip4ModeData->IcmpTypeList = mIp4SupportedIcmp;
405
406 Ip4ModeData->RouteTable = NULL;
407 Ip4ModeData->RouteCount = 0;
408
409 Ip4ModeData->MaxPacketSize = IpSb->MaxPacketSize;
410
411 //
412 // return the current station address for this IP child. So,
413 // the user can get the default address through this. Some
414 // application wants to know it station address even it is
415 // using the default one, such as a ftp server.
416 //
417 if (Ip4ModeData->IsStarted) {
418 Config = &Ip4ModeData->ConfigData;
419
420 Ip = HTONL (IpInstance->Interface->Ip);
421 CopyMem (&Config->StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));
422
423 Ip = HTONL (IpInstance->Interface->SubnetMask);
424 CopyMem (&Config->SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS));
425
426 Ip4ModeData->IsConfigured = IpInstance->Interface->Configured;
427
428 //
429 // Build a EFI route table for user from the internal route table.
430 //
431 Status = Ip4BuildEfiRouteTable (IpInstance);
432
433 if (EFI_ERROR (Status)) {
434 gBS->RestoreTPL (OldTpl);
435 return Status;
436 }
437
438 Ip4ModeData->RouteTable = IpInstance->EfiRouteTable;
439 Ip4ModeData->RouteCount = IpInstance->EfiRouteCount;
440 }
441 }
442
443 //
444 // Get fresh mode data from MNP, since underlying media status may change
445 //
446 Status = IpSb->Mnp->GetModeData (IpSb->Mnp, MnpConfigData, SnpModeData);
447
448 gBS->RestoreTPL (OldTpl);
449 return Status;
450 }
451
452
453 /**
454 Config the MNP parameter used by IP. The IP driver use one MNP
455 child to transmit/receive frames. By default, it configures MNP
456 to receive unicast/multicast/broadcast. And it will enable/disable
457 the promiscous receive according to whether there is IP child
458 enable that or not. If Force is FALSE, it will iterate through
459 all the IP children to check whether the promiscuous receive
460 setting has been changed. If it hasn't been changed, it won't
461 reconfigure the MNP. If Force is TRUE, the MNP is configured no
462 matter whether that is changed or not.
463
464 @param[in] IpSb The IP4 service instance that is to be changed.
465 @param[in] Force Force the configuration or not.
466
467 @retval EFI_SUCCESS The MNP is successfully configured/reconfigured.
468 @retval Others Configuration failed.
469
470 **/
471 EFI_STATUS
472 Ip4ServiceConfigMnp (
473 IN IP4_SERVICE *IpSb,
474 IN BOOLEAN Force
475 )
476 {
477 LIST_ENTRY *Entry;
478 LIST_ENTRY *ProtoEntry;
479 IP4_INTERFACE *IpIf;
480 IP4_PROTOCOL *IpInstance;
481 BOOLEAN Reconfig;
482 BOOLEAN PromiscReceive;
483 EFI_STATUS Status;
484
485 Reconfig = FALSE;
486 PromiscReceive = FALSE;
487
488 if (!Force) {
489 //
490 // Iterate through the IP children to check whether promiscuous
491 // receive setting has been changed. Update the interface's receive
492 // filter also.
493 //
494 NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
495
496 IpIf = NET_LIST_USER_STRUCT (Entry, IP4_INTERFACE, Link);
497 IpIf->PromiscRecv = FALSE;
498
499 NET_LIST_FOR_EACH (ProtoEntry, &IpIf->IpInstances) {
500 IpInstance = NET_LIST_USER_STRUCT (ProtoEntry, IP4_PROTOCOL, AddrLink);
501
502 if (IpInstance->ConfigData.AcceptPromiscuous) {
503 IpIf->PromiscRecv = TRUE;
504 PromiscReceive = TRUE;
505 }
506 }
507 }
508
509 //
510 // If promiscuous receive isn't changed, it isn't necessary to reconfigure.
511 //
512 if (PromiscReceive == IpSb->MnpConfigData.EnablePromiscuousReceive) {
513 return EFI_SUCCESS;
514 }
515
516 Reconfig = TRUE;
517 IpSb->MnpConfigData.EnablePromiscuousReceive = PromiscReceive;
518 }
519
520 Status = IpSb->Mnp->Configure (IpSb->Mnp, &IpSb->MnpConfigData);
521
522 //
523 // recover the original configuration if failed to set the configure.
524 //
525 if (EFI_ERROR (Status) && Reconfig) {
526 IpSb->MnpConfigData.EnablePromiscuousReceive = (BOOLEAN) !PromiscReceive;
527 }
528
529 return Status;
530 }
531
532
533 /**
534 The event handle for IP4 auto configuration. If IP is asked
535 to reconfigure the default address. The original default
536 interface and route table are removed as the default. If there
537 is active IP children using the default address, the interface
538 will remain valid until all the children have freed their
539 references. If IP is signalled when auto configuration is done,
540 it will configure the default interface and default route table
541 with the configuration information retrieved by IP4_CONFIGURE.
542
543 @param[in] Context The IP4 service binding instance.
544
545 **/
546 VOID
547 EFIAPI
548 Ip4AutoConfigCallBackDpc (
549 IN VOID *Context
550 )
551 {
552 EFI_IP4_CONFIG_PROTOCOL *Ip4Config;
553 EFI_IP4_IPCONFIG_DATA *Data;
554 EFI_IP4_ROUTE_TABLE *RouteEntry;
555 IP4_SERVICE *IpSb;
556 IP4_ROUTE_TABLE *RouteTable;
557 IP4_INTERFACE *IpIf;
558 EFI_STATUS Status;
559 UINTN Len;
560 UINT32 Index;
561 IP4_ADDR StationAddress;
562 IP4_ADDR SubnetMask;
563 IP4_ADDR SubnetAddress;
564 IP4_ADDR GatewayAddress;
565
566 IpSb = (IP4_SERVICE *) Context;
567 NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE);
568
569 Ip4Config = IpSb->Ip4Config;
570
571 //
572 // IP is asked to do the reconfiguration. If the default interface
573 // has been configured, release the default interface and route
574 // table, then create a new one. If there are some IP children
575 // using it, the interface won't be physically freed until all the
576 // children have released their reference to it. Also remember to
577 // restart the receive on the default address. IP4 driver only receive
578 // frames on the default address, and when the default interface is
579 // freed, Ip4AcceptFrame won't be informed.
580 //
581 if (IpSb->ActiveEvent == IpSb->ReconfigEvent) {
582
583 if (IpSb->DefaultInterface->Configured) {
584 IpIf = Ip4CreateInterface (IpSb->Mnp, IpSb->Controller, IpSb->Image);
585
586 if (IpIf == NULL) {
587 return;
588 }
589
590 RouteTable = Ip4CreateRouteTable ();
591
592 if (RouteTable == NULL) {
593 Ip4FreeInterface (IpIf, NULL);
594 return;
595 }
596
597 Ip4CancelReceive (IpSb->DefaultInterface);
598 Ip4FreeInterface (IpSb->DefaultInterface, NULL);
599 Ip4FreeRouteTable (IpSb->DefaultRouteTable);
600
601 IpSb->DefaultInterface = IpIf;
602 InsertHeadList (&IpSb->Interfaces, &IpIf->Link);
603
604 IpSb->DefaultRouteTable = RouteTable;
605 Ip4ReceiveFrame (IpIf, NULL, Ip4AccpetFrame, IpSb);
606 }
607
608 Ip4Config->Stop (Ip4Config);
609 Ip4Config->Start (Ip4Config, IpSb->DoneEvent, IpSb->ReconfigEvent);
610 return ;
611 }
612
613 //
614 // Get the configure data in two steps: get the length then the data.
615 //
616 Len = 0;
617
618 if (Ip4Config->GetData (Ip4Config, &Len, NULL) != EFI_BUFFER_TOO_SMALL) {
619 return ;
620 }
621
622 Data = AllocatePool (Len);
623
624 if (Data == NULL) {
625 return ;
626 }
627
628 Status = Ip4Config->GetData (Ip4Config, &Len, Data);
629
630 if (EFI_ERROR (Status)) {
631 goto ON_EXIT;
632 }
633
634 IpIf = IpSb->DefaultInterface;
635
636 //
637 // If the default address has been configured don't change it.
638 // This is unlikely to happen if EFI_IP4_CONFIG protocol has
639 // informed us to reconfigure each time it wants to change the
640 // configuration parameters.
641 //
642 if (IpIf->Configured) {
643 goto ON_EXIT;
644 }
645
646 //
647 // Set the default interface's address, then add a directed
648 // route for it, that is, the route whose nexthop is zero.
649 //
650 StationAddress = EFI_NTOHL (Data->StationAddress);
651 SubnetMask = EFI_NTOHL (Data->SubnetMask);
652 Status = Ip4SetAddress (IpIf, StationAddress, SubnetMask);
653
654 if (EFI_ERROR (Status)) {
655 goto ON_EXIT;
656 }
657
658 Ip4AddRoute (
659 IpSb->DefaultRouteTable,
660 StationAddress,
661 SubnetMask,
662 IP4_ALLZERO_ADDRESS
663 );
664
665 //
666 // Add routes returned by EFI_IP4_CONFIG protocol.
667 //
668 for (Index = 0; Index < Data->RouteTableSize; Index++) {
669 RouteEntry = &Data->RouteTable[Index];
670
671 SubnetAddress = EFI_NTOHL (RouteEntry->SubnetAddress);
672 SubnetMask = EFI_NTOHL (RouteEntry->SubnetMask);
673 GatewayAddress = EFI_NTOHL (RouteEntry->GatewayAddress);
674 Ip4AddRoute (IpSb->DefaultRouteTable, SubnetAddress, SubnetMask, GatewayAddress);
675 }
676
677 IpSb->State = IP4_SERVICE_CONFIGED;
678
679 Ip4SetVariableData (IpSb);
680
681 ON_EXIT:
682 FreePool (Data);
683 }
684
685 /**
686 Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK.
687
688 @param Event The event that is signalled.
689 @param Context The IP4 service binding instance.
690
691 **/
692 VOID
693 EFIAPI
694 Ip4AutoConfigCallBack (
695 IN EFI_EVENT Event,
696 IN VOID *Context
697 )
698 {
699 IP4_SERVICE *IpSb;
700
701 IpSb = (IP4_SERVICE *) Context;
702 IpSb->ActiveEvent = Event;
703
704 //
705 // Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK
706 //
707 QueueDpc (TPL_CALLBACK, Ip4AutoConfigCallBackDpc, Context);
708 }
709
710
711 /**
712 Start the auto configuration for this IP service instance.
713 It will locates the EFI_IP4_CONFIG_PROTOCOL, then start the
714 auto configuration.
715
716 @param[in] IpSb The IP4 service instance to configure
717
718 @retval EFI_SUCCESS The auto configuration is successfull started
719 @retval Others Failed to start auto configuration.
720
721 **/
722 EFI_STATUS
723 Ip4StartAutoConfig (
724 IN IP4_SERVICE *IpSb
725 )
726 {
727 EFI_IP4_CONFIG_PROTOCOL *Ip4Config;
728 EFI_STATUS Status;
729
730 if (IpSb->State > IP4_SERVICE_UNSTARTED) {
731 return EFI_SUCCESS;
732 }
733
734 //
735 // Create the DoneEvent and ReconfigEvent to call EFI_IP4_CONFIG
736 //
737 Status = gBS->CreateEvent (
738 EVT_NOTIFY_SIGNAL,
739 TPL_CALLBACK,
740 Ip4AutoConfigCallBack,
741 IpSb,
742 &IpSb->DoneEvent
743 );
744
745 if (EFI_ERROR (Status)) {
746 return Status;
747 }
748
749 Status = gBS->CreateEvent (
750 EVT_NOTIFY_SIGNAL,
751 TPL_NOTIFY,
752 Ip4AutoConfigCallBack,
753 IpSb,
754 &IpSb->ReconfigEvent
755 );
756
757 if (EFI_ERROR (Status)) {
758 goto CLOSE_DONE_EVENT;
759 }
760
761 //
762 // Open the EFI_IP4_CONFIG protocol then start auto configure
763 //
764 Status = gBS->OpenProtocol (
765 IpSb->Controller,
766 &gEfiIp4ConfigProtocolGuid,
767 (VOID **) &Ip4Config,
768 IpSb->Image,
769 IpSb->Controller,
770 EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE
771 );
772
773 if (EFI_ERROR (Status)) {
774 Status = EFI_UNSUPPORTED;
775 goto CLOSE_RECONFIG_EVENT;
776 }
777
778 Status = Ip4Config->Start (Ip4Config, IpSb->DoneEvent, IpSb->ReconfigEvent);
779
780 if (EFI_ERROR (Status)) {
781 gBS->CloseProtocol (
782 IpSb->Controller,
783 &gEfiIp4ConfigProtocolGuid,
784 IpSb->Image,
785 IpSb->Controller
786 );
787
788 goto CLOSE_RECONFIG_EVENT;
789 }
790
791 IpSb->Ip4Config = Ip4Config;
792 IpSb->State = IP4_SERVICE_STARTED;
793 return Status;
794
795 CLOSE_RECONFIG_EVENT:
796 gBS->CloseEvent (IpSb->ReconfigEvent);
797 IpSb->ReconfigEvent = NULL;
798
799 CLOSE_DONE_EVENT:
800 gBS->CloseEvent (IpSb->DoneEvent);
801 IpSb->DoneEvent = NULL;
802
803 return Status;
804 }
805
806
807 /**
808 Intiialize the IP4_PROTOCOL structure to the unconfigured states.
809
810 @param IpSb The IP4 service instance.
811 @param IpInstance The IP4 child instance.
812
813 **/
814 VOID
815 Ip4InitProtocol (
816 IN IP4_SERVICE *IpSb,
817 IN OUT IP4_PROTOCOL *IpInstance
818 )
819 {
820 ASSERT ((IpSb != NULL) && (IpInstance != NULL));
821
822 ZeroMem (IpInstance, sizeof (IP4_PROTOCOL));
823
824 IpInstance->Signature = IP4_PROTOCOL_SIGNATURE;
825 CopyMem (&IpInstance->Ip4Proto, &mEfiIp4ProtocolTemplete, sizeof (IpInstance->Ip4Proto));
826 IpInstance->State = IP4_STATE_UNCONFIGED;
827 IpInstance->Service = IpSb;
828
829 InitializeListHead (&IpInstance->Link);
830 NetMapInit (&IpInstance->RxTokens);
831 NetMapInit (&IpInstance->TxTokens);
832 InitializeListHead (&IpInstance->Received);
833 InitializeListHead (&IpInstance->Delivered);
834 InitializeListHead (&IpInstance->AddrLink);
835
836 EfiInitializeLock (&IpInstance->RecycleLock, TPL_NOTIFY);
837 }
838
839
840 /**
841 Configure the IP4 child. If the child is already configured,
842 change the configuration parameter. Otherwise configure it
843 for the first time. The caller should validate the configuration
844 before deliver them to it. It also don't do configure NULL.
845
846 @param[in, out] IpInstance The IP4 child to configure.
847 @param[in] Config The configure data.
848
849 @retval EFI_SUCCESS The IP4 child is successfully configured.
850 @retval EFI_DEVICE_ERROR Failed to free the pending transive or to
851 configure underlying MNP or other errors.
852 @retval EFI_NO_MAPPING The IP4 child is configured to use default
853 address, but the default address hasn't been
854 configured. The IP4 child doesn't need to be
855 reconfigured when default address is configured.
856 @retval EFI_OUT_OF_RESOURCES No more memory space is available.
857 @retval other Other error occurs.
858
859 **/
860 EFI_STATUS
861 Ip4ConfigProtocol (
862 IN OUT IP4_PROTOCOL *IpInstance,
863 IN EFI_IP4_CONFIG_DATA *Config
864 )
865 {
866 IP4_SERVICE *IpSb;
867 IP4_INTERFACE *IpIf;
868 EFI_STATUS Status;
869 IP4_ADDR Ip;
870 IP4_ADDR Netmask;
871 EFI_ARP_PROTOCOL *Arp;
872
873 IpSb = IpInstance->Service;
874
875 //
876 // User is changing packet filters. It must be stopped
877 // before the station address can be changed.
878 //
879 if (IpInstance->State == IP4_STATE_CONFIGED) {
880 //
881 // Cancel all the pending transmit/receive from upper layer
882 //
883 Status = Ip4Cancel (IpInstance, NULL);
884
885 if (EFI_ERROR (Status)) {
886 return EFI_DEVICE_ERROR;
887 }
888
889 CopyMem (&IpInstance->ConfigData, Config, sizeof (IpInstance->ConfigData));
890 return EFI_SUCCESS;
891 }
892
893 //
894 // Configure a fresh IP4 protocol instance. Create a route table.
895 // Each IP child has its own route table, which may point to the
896 // default table if it is using default address.
897 //
898 Status = EFI_OUT_OF_RESOURCES;
899 IpInstance->RouteTable = Ip4CreateRouteTable ();
900
901 if (IpInstance->RouteTable == NULL) {
902 return Status;
903 }
904
905 //
906 // Set up the interface.
907 //
908 CopyMem (&Ip, &Config->StationAddress, sizeof (IP4_ADDR));
909 CopyMem (&Netmask, &Config->SubnetMask, sizeof (IP4_ADDR));
910
911 Ip = NTOHL (Ip);
912 Netmask = NTOHL (Netmask);
913
914 if (!Config->UseDefaultAddress) {
915 //
916 // Find whether there is already an interface with the same
917 // station address. All the instances with the same station
918 // address shares one interface.
919 //
920 IpIf = Ip4FindStationAddress (IpSb, Ip, Netmask);
921
922 if (IpIf != NULL) {
923 NET_GET_REF (IpIf);
924
925 } else {
926 IpIf = Ip4CreateInterface (IpSb->Mnp, IpSb->Controller, IpSb->Image);
927
928 if (IpIf == NULL) {
929 goto ON_ERROR;
930 }
931
932 Status = Ip4SetAddress (IpIf, Ip, Netmask);
933
934 if (EFI_ERROR (Status)) {
935 Status = EFI_DEVICE_ERROR;
936 Ip4FreeInterface (IpIf, IpInstance);
937 goto ON_ERROR;
938 }
939
940 InsertTailList (&IpSb->Interfaces, &IpIf->Link);
941 }
942
943 //
944 // Add a route to this connected network in the route table
945 //
946 Ip4AddRoute (IpInstance->RouteTable, Ip, Netmask, IP4_ALLZERO_ADDRESS);
947
948 } else {
949 //
950 // Use the default address. If the default configuration hasn't
951 // been started, start it.
952 //
953 if (IpSb->State == IP4_SERVICE_UNSTARTED) {
954 Status = Ip4StartAutoConfig (IpSb);
955
956 if (EFI_ERROR (Status)) {
957 goto ON_ERROR;
958 }
959 }
960
961 IpIf = IpSb->DefaultInterface;
962 NET_GET_REF (IpSb->DefaultInterface);
963
964 //
965 // If default address is used, so is the default route table.
966 // Any route set by the instance has the precedence over the
967 // routes in the default route table. Link the default table
968 // after the instance's table. Routing will search the local
969 // table first.
970 //
971 NET_GET_REF (IpSb->DefaultRouteTable);
972 IpInstance->RouteTable->Next = IpSb->DefaultRouteTable;
973 }
974
975 IpInstance->Interface = IpIf;
976 if (IpIf->Arp != NULL) {
977 Arp = NULL;
978 Status = gBS->OpenProtocol (
979 IpIf->ArpHandle,
980 &gEfiArpProtocolGuid,
981 (VOID **) &Arp,
982 gIp4DriverBinding.DriverBindingHandle,
983 IpInstance->Handle,
984 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
985 );
986 if (EFI_ERROR (Status)) {
987 goto ON_ERROR;
988 }
989 }
990 InsertTailList (&IpIf->IpInstances, &IpInstance->AddrLink);
991
992 CopyMem (&IpInstance->ConfigData, Config, sizeof (IpInstance->ConfigData));
993 IpInstance->State = IP4_STATE_CONFIGED;
994
995 //
996 // Although EFI_NO_MAPPING is an error code, the IP child has been
997 // successfully configured and doesn't need reconfiguration when
998 // default address is acquired.
999 //
1000 if (Config->UseDefaultAddress && IP4_NO_MAPPING (IpInstance)) {
1001 return EFI_NO_MAPPING;
1002 }
1003
1004 return EFI_SUCCESS;
1005
1006 ON_ERROR:
1007 Ip4FreeRouteTable (IpInstance->RouteTable);
1008 IpInstance->RouteTable = NULL;
1009 return Status;
1010 }
1011
1012
1013 /**
1014 Clean up the IP4 child, release all the resources used by it.
1015
1016 @param[in] IpInstance The IP4 child to clean up.
1017
1018 @retval EFI_SUCCESS The IP4 child is cleaned up
1019 @retval EFI_DEVICE_ERROR Some resources failed to be released
1020
1021 **/
1022 EFI_STATUS
1023 Ip4CleanProtocol (
1024 IN IP4_PROTOCOL *IpInstance
1025 )
1026 {
1027 if (EFI_ERROR (Ip4Cancel (IpInstance, NULL))) {
1028 return EFI_DEVICE_ERROR;
1029 }
1030
1031 if (EFI_ERROR (Ip4Groups (IpInstance, FALSE, NULL))) {
1032 return EFI_DEVICE_ERROR;
1033 }
1034
1035 //
1036 // Some packets haven't been recycled. It is because either the
1037 // user forgets to recycle the packets, or because the callback
1038 // hasn't been called. Just leave it alone.
1039 //
1040 if (!IsListEmpty (&IpInstance->Delivered)) {
1041 ;
1042 }
1043
1044 if (IpInstance->Interface != NULL) {
1045 RemoveEntryList (&IpInstance->AddrLink);
1046 if (IpInstance->Interface->Arp != NULL) {
1047 gBS->CloseProtocol (
1048 IpInstance->Interface->ArpHandle,
1049 &gEfiArpProtocolGuid,
1050 gIp4DriverBinding.DriverBindingHandle,
1051 IpInstance->Handle
1052 );
1053 }
1054 Ip4FreeInterface (IpInstance->Interface, IpInstance);
1055 IpInstance->Interface = NULL;
1056 }
1057
1058 if (IpInstance->RouteTable != NULL) {
1059 if (IpInstance->RouteTable->Next != NULL) {
1060 Ip4FreeRouteTable (IpInstance->RouteTable->Next);
1061 }
1062
1063 Ip4FreeRouteTable (IpInstance->RouteTable);
1064 IpInstance->RouteTable = NULL;
1065 }
1066
1067 if (IpInstance->EfiRouteTable != NULL) {
1068 FreePool (IpInstance->EfiRouteTable);
1069 IpInstance->EfiRouteTable = NULL;
1070 IpInstance->EfiRouteCount = 0;
1071 }
1072
1073 if (IpInstance->Groups != NULL) {
1074 FreePool (IpInstance->Groups);
1075 IpInstance->Groups = NULL;
1076 IpInstance->GroupCount = 0;
1077 }
1078
1079 NetMapClean (&IpInstance->TxTokens);
1080
1081 NetMapClean (&IpInstance->RxTokens);
1082
1083 return EFI_SUCCESS;
1084 }
1085
1086
1087 /**
1088 Validate that Ip/Netmask pair is OK to be used as station
1089 address. Only continuous netmasks are supported. and check
1090 that StationAddress is a unicast address on the newtwork.
1091
1092 @param[in] Ip The IP address to validate
1093 @param[in] Netmask The netmaks of the IP
1094
1095 @retval TRUE The Ip/Netmask pair is valid
1096 @retval FALSE The Ip/Netmask pair is invalid
1097
1098 **/
1099 BOOLEAN
1100 Ip4StationAddressValid (
1101 IN IP4_ADDR Ip,
1102 IN IP4_ADDR Netmask
1103 )
1104 {
1105 IP4_ADDR NetBrdcastMask;
1106 INTN Len;
1107 INTN Type;
1108
1109 //
1110 // Only support the station address with 0.0.0.0/0 to enable DHCP client.
1111 //
1112 if (Netmask == IP4_ALLZERO_ADDRESS) {
1113 return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);
1114 }
1115
1116 //
1117 // Only support the continuous net masks
1118 //
1119 if ((Len = NetGetMaskLength (Netmask)) == IP4_MASK_NUM) {
1120 return FALSE;
1121 }
1122
1123 //
1124 // Station address can't be class D or class E address
1125 //
1126 if ((Type = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {
1127 return FALSE;
1128 }
1129
1130 //
1131 // Station address can't be subnet broadcast/net broadcast address
1132 //
1133 if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
1134 return FALSE;
1135 }
1136
1137 NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
1138
1139 if (Ip == (Ip | ~NetBrdcastMask)) {
1140 return FALSE;
1141 }
1142
1143 return TRUE;
1144 }
1145
1146
1147 /**
1148 Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
1149
1150 The Configure() function is used to set, change, or reset the operational
1151 parameters and filter settings for this EFI IPv4 Protocol instance. Until these
1152 parameters have been set, no network traffic can be sent or received by this
1153 instance. Once the parameters have been reset (by calling this function with
1154 IpConfigData set to NULL), no more traffic can be sent or received until these
1155 parameters have been set again. Each EFI IPv4 Protocol instance can be started
1156 and stopped independently of each other by enabling or disabling their receive
1157 filter settings with the Configure() function.
1158
1159 When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will
1160 be appended as an alias address into the addresses list in the EFI IPv4 Protocol
1161 driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL
1162 to retrieve the default IPv4 address if it is not available yet. Clients could
1163 frequently call GetModeData() to check the status to ensure that the default IPv4
1164 address is ready.
1165
1166 If operational parameters are reset or changed, any pending transmit and receive
1167 requests will be cancelled. Their completion token status will be set to EFI_ABORTED
1168 and their events will be signaled.
1169
1170 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1171 @param[in] IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.
1172
1173 @retval EFI_SUCCESS The driver instance was successfully opened.
1174 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1175 RARP, etc.) is not finished yet.
1176 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1177 @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:
1178 A configuration protocol (DHCP, BOOTP, RARP, etc.) could
1179 not be located when clients choose to use the default IPv4
1180 address. This EFI IPv4 Protocol implementation does not
1181 support this requested filter or timeout setting.
1182 @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.
1183 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the
1184 IPv4 address or subnet mask can be changed. The interface must
1185 also be stopped when switching to/from raw packet mode.
1186 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4
1187 Protocol driver instance is not opened.
1188
1189 **/
1190 EFI_STATUS
1191 EFIAPI
1192 EfiIp4Configure (
1193 IN EFI_IP4_PROTOCOL *This,
1194 IN EFI_IP4_CONFIG_DATA *IpConfigData OPTIONAL
1195 )
1196 {
1197 IP4_PROTOCOL *IpInstance;
1198 EFI_IP4_CONFIG_DATA *Current;
1199 EFI_TPL OldTpl;
1200 EFI_STATUS Status;
1201 BOOLEAN AddrOk;
1202 IP4_ADDR IpAddress;
1203 IP4_ADDR SubnetMask;
1204
1205 //
1206 // First, validate the parameters
1207 //
1208 if (This == NULL) {
1209 return EFI_INVALID_PARAMETER;
1210 }
1211
1212 IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);
1213 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1214
1215 //
1216 // Validate the configuration first.
1217 //
1218 if (IpConfigData != NULL) {
1219
1220 CopyMem (&IpAddress, &IpConfigData->StationAddress, sizeof (IP4_ADDR));
1221 CopyMem (&SubnetMask, &IpConfigData->SubnetMask, sizeof (IP4_ADDR));
1222
1223 IpAddress = NTOHL (IpAddress);
1224 SubnetMask = NTOHL (SubnetMask);
1225
1226 //
1227 // Check whether the station address is a valid unicast address
1228 //
1229 if (!IpConfigData->UseDefaultAddress) {
1230 AddrOk = Ip4StationAddressValid (IpAddress, SubnetMask);
1231
1232 if (!AddrOk) {
1233 Status = EFI_INVALID_PARAMETER;
1234 goto ON_EXIT;
1235 }
1236 }
1237
1238 //
1239 // User can only update packet filters when already configured.
1240 // If it wants to change the station address, it must configure(NULL)
1241 // the instance first.
1242 //
1243 if (IpInstance->State == IP4_STATE_CONFIGED) {
1244 Current = &IpInstance->ConfigData;
1245
1246 if (Current->UseDefaultAddress != IpConfigData->UseDefaultAddress) {
1247 Status = EFI_ALREADY_STARTED;
1248 goto ON_EXIT;
1249 }
1250
1251 if (!Current->UseDefaultAddress &&
1252 (!EFI_IP4_EQUAL (&Current->StationAddress, &IpConfigData->StationAddress) ||
1253 !EFI_IP4_EQUAL (&Current->SubnetMask, &IpConfigData->SubnetMask))) {
1254 Status = EFI_ALREADY_STARTED;
1255 goto ON_EXIT;
1256 }
1257
1258 if (Current->UseDefaultAddress && IP4_NO_MAPPING (IpInstance)) {
1259 Status = EFI_NO_MAPPING;
1260 goto ON_EXIT;
1261 }
1262 }
1263 }
1264
1265 //
1266 // Configure the instance or clean it up.
1267 //
1268 if (IpConfigData != NULL) {
1269 Status = Ip4ConfigProtocol (IpInstance, IpConfigData);
1270 } else {
1271 Status = Ip4CleanProtocol (IpInstance);
1272
1273 //
1274 // Don't change the state if it is DESTROY, consider the following
1275 // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,
1276 // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,
1277 // the unload fails miserably.
1278 //
1279 if (IpInstance->State == IP4_STATE_CONFIGED) {
1280 IpInstance->State = IP4_STATE_UNCONFIGED;
1281 }
1282 }
1283
1284 //
1285 // Update the MNP's configure data. Ip4ServiceConfigMnp will check
1286 // whether it is necessary to reconfigure the MNP.
1287 //
1288 Ip4ServiceConfigMnp (IpInstance->Service, FALSE);
1289
1290 //
1291 // Update the variable data.
1292 //
1293 Ip4SetVariableData (IpInstance->Service);
1294
1295 ON_EXIT:
1296 gBS->RestoreTPL (OldTpl);
1297 return Status;
1298
1299 }
1300
1301
1302 /**
1303 Change the IP4 child's multicast setting. The caller
1304 should make sure that the parameters is valid.
1305
1306 @param[in] IpInstance The IP4 child to change the setting.
1307 @param[in] JoinFlag TRUE to join the group, otherwise leave it
1308 @param[in] GroupAddress The target group address
1309
1310 @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it
1311 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
1312 @retval EFI_DEVICE_ERROR Failed to set the group configuraton
1313 @retval EFI_SUCCESS Successfully updated the group setting.
1314 @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.
1315
1316 **/
1317 EFI_STATUS
1318 Ip4Groups (
1319 IN IP4_PROTOCOL *IpInstance,
1320 IN BOOLEAN JoinFlag,
1321 IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL
1322 )
1323 {
1324 IP4_ADDR *Members;
1325 IP4_ADDR Group;
1326 UINT32 Index;
1327
1328 //
1329 // Add it to the instance's Groups, and join the group by IGMP.
1330 // IpInstance->Groups is in network byte order. IGMP operates in
1331 // host byte order
1332 //
1333 if (JoinFlag) {
1334 //
1335 // When JoinFlag is TRUE, GroupAddress shouldn't be NULL.
1336 //
1337 ASSERT (GroupAddress != NULL);
1338 CopyMem (&Group, GroupAddress, sizeof (IP4_ADDR));
1339
1340 for (Index = 0; Index < IpInstance->GroupCount; Index++) {
1341 if (IpInstance->Groups[Index] == Group) {
1342 return EFI_ALREADY_STARTED;
1343 }
1344 }
1345
1346 Members = Ip4CombineGroups (IpInstance->Groups, IpInstance->GroupCount, Group);
1347
1348 if (Members == NULL) {
1349 return EFI_OUT_OF_RESOURCES;
1350 }
1351
1352 if (EFI_ERROR (Ip4JoinGroup (IpInstance, NTOHL (Group)))) {
1353 FreePool (Members);
1354 return EFI_DEVICE_ERROR;
1355 }
1356
1357 if (IpInstance->Groups != NULL) {
1358 FreePool (IpInstance->Groups);
1359 }
1360
1361 IpInstance->Groups = Members;
1362 IpInstance->GroupCount++;
1363
1364 return EFI_SUCCESS;
1365 }
1366
1367 //
1368 // Leave the group. Leave all the groups if GroupAddress is NULL.
1369 // Must iterate from the end to the beginning because the GroupCount
1370 // is decreamented each time an address is removed..
1371 //
1372 for (Index = IpInstance->GroupCount; Index > 0 ; Index--) {
1373 Group = IpInstance->Groups[Index - 1];
1374
1375 if ((GroupAddress == NULL) || EFI_IP4_EQUAL (&Group, GroupAddress)) {
1376 if (EFI_ERROR (Ip4LeaveGroup (IpInstance, NTOHL (Group)))) {
1377 return EFI_DEVICE_ERROR;
1378 }
1379
1380 Ip4RemoveGroupAddr (IpInstance->Groups, IpInstance->GroupCount, Group);
1381 IpInstance->GroupCount--;
1382
1383 if (IpInstance->GroupCount == 0) {
1384 ASSERT (Index == 1);
1385
1386 FreePool (IpInstance->Groups);
1387 IpInstance->Groups = NULL;
1388 }
1389
1390 if (GroupAddress != NULL) {
1391 return EFI_SUCCESS;
1392 }
1393 }
1394 }
1395
1396 return ((GroupAddress != NULL) ? EFI_NOT_FOUND : EFI_SUCCESS);
1397 }
1398
1399
1400 /**
1401 Joins and leaves multicast groups.
1402
1403 The Groups() function is used to join and leave multicast group sessions. Joining
1404 a group will enable reception of matching multicast packets. Leaving a group will
1405 disable the multicast packet reception.
1406
1407 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
1408
1409 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1410 @param[in] JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.
1411 @param[in] GroupAddress Pointer to the IPv4 multicast address.
1412
1413 @retval EFI_SUCCESS The operation completed successfully.
1414 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
1415 - This is NULL.
1416 - JoinFlag is TRUE and GroupAddress is NULL.
1417 - GroupAddress is not NULL and *GroupAddress is
1418 not a multicast IPv4 address.
1419 @retval EFI_NOT_STARTED This instance has not been started.
1420 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1421 RARP, etc.) is not finished yet.
1422 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
1423 @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.
1424 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
1425 JoinFlag is TRUE).
1426 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
1427 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1428
1429 **/
1430 EFI_STATUS
1431 EFIAPI
1432 EfiIp4Groups (
1433 IN EFI_IP4_PROTOCOL *This,
1434 IN BOOLEAN JoinFlag,
1435 IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL
1436 )
1437 {
1438 IP4_PROTOCOL *IpInstance;
1439 EFI_STATUS Status;
1440 EFI_TPL OldTpl;
1441 IP4_ADDR McastIp;
1442
1443 if ((This == NULL) || (JoinFlag && (GroupAddress == NULL))) {
1444 return EFI_INVALID_PARAMETER;
1445 }
1446
1447 if (GroupAddress != NULL) {
1448 CopyMem (&McastIp, GroupAddress, sizeof (IP4_ADDR));
1449
1450 if (!IP4_IS_MULTICAST (NTOHL (McastIp))) {
1451 return EFI_INVALID_PARAMETER;
1452 }
1453 }
1454
1455 IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);
1456 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1457
1458 if (IpInstance->State != IP4_STATE_CONFIGED) {
1459 Status = EFI_NOT_STARTED;
1460 goto ON_EXIT;
1461 }
1462
1463 if (IpInstance->ConfigData.UseDefaultAddress && IP4_NO_MAPPING (IpInstance)) {
1464 Status = EFI_NO_MAPPING;
1465 goto ON_EXIT;
1466 }
1467
1468 Status = Ip4Groups (IpInstance, JoinFlag, GroupAddress);
1469
1470 ON_EXIT:
1471 gBS->RestoreTPL (OldTpl);
1472 return Status;
1473 }
1474
1475
1476 /**
1477 Adds and deletes routing table entries.
1478
1479 The Routes() function adds a route to or deletes a route from the routing table.
1480
1481 Routes are determined by comparing the SubnetAddress with the destination IPv4
1482 address arithmetically AND-ed with the SubnetMask. The gateway address must be
1483 on the same subnet as the configured station address.
1484
1485 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
1486 The default route matches all destination IPv4 addresses that do not match any
1487 other routes.
1488
1489 A GatewayAddress that is zero is a nonroute. Packets are sent to the destination
1490 IP address if it can be found in the ARP cache or on the local subnet. One automatic
1491 nonroute entry will be inserted into the routing table for outgoing packets that
1492 are addressed to a local subnet (gateway address of 0.0.0.0).
1493
1494 Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI
1495 IPv4 Protocol instances that use the default IPv4 address will also have copies
1496 of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these
1497 copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its
1498 instances. As a result, client modification to the routing table will be lost.
1499
1500 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1501 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
1502 FALSE to add this route to the routing table. SubnetAddress
1503 and SubnetMask are used as the key to each route entry.
1504 @param[in] SubnetAddress The address of the subnet that needs to be routed.
1505 @param[in] SubnetMask The subnet mask of SubnetAddress.
1506 @param[in] GatewayAddress The unicast gateway IPv4 address for this route.
1507
1508 @retval EFI_SUCCESS The operation completed successfully.
1509 @retval EFI_NOT_STARTED The driver instance has not been started.
1510 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1511 RARP, etc.) is not finished yet.
1512 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1513 - This is NULL.
1514 - SubnetAddress is NULL.
1515 - SubnetMask is NULL.
1516 - GatewayAddress is NULL.
1517 - *SubnetAddress is not a valid subnet address.
1518 - *SubnetMask is not a valid subnet mask.
1519 - *GatewayAddress is not a valid unicast IPv4 address.
1520 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
1521 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
1522 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
1523 DeleteRoute is FALSE).
1524
1525 **/
1526 EFI_STATUS
1527 EFIAPI
1528 EfiIp4Routes (
1529 IN EFI_IP4_PROTOCOL *This,
1530 IN BOOLEAN DeleteRoute,
1531 IN EFI_IPv4_ADDRESS *SubnetAddress,
1532 IN EFI_IPv4_ADDRESS *SubnetMask,
1533 IN EFI_IPv4_ADDRESS *GatewayAddress
1534 )
1535 {
1536 IP4_PROTOCOL *IpInstance;
1537 IP4_INTERFACE *IpIf;
1538 IP4_ADDR Dest;
1539 IP4_ADDR Netmask;
1540 IP4_ADDR Nexthop;
1541 EFI_STATUS Status;
1542 EFI_TPL OldTpl;
1543
1544 //
1545 // First, validate the parameters
1546 //
1547 if ((This == NULL) || (SubnetAddress == NULL) ||
1548 (SubnetMask == NULL) || (GatewayAddress == NULL)) {
1549 return EFI_INVALID_PARAMETER;
1550 }
1551
1552 IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);
1553 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1554
1555 if (IpInstance->State != IP4_STATE_CONFIGED) {
1556 Status = EFI_NOT_STARTED;
1557 goto ON_EXIT;
1558 }
1559
1560 if (IpInstance->ConfigData.UseDefaultAddress && IP4_NO_MAPPING (IpInstance)) {
1561 Status = EFI_NO_MAPPING;
1562 goto ON_EXIT;
1563 }
1564
1565 CopyMem (&Dest, SubnetAddress, sizeof (IP4_ADDR));
1566 CopyMem (&Netmask, SubnetMask, sizeof (IP4_ADDR));
1567 CopyMem (&Nexthop, GatewayAddress, sizeof (IP4_ADDR));
1568
1569 Dest = NTOHL (Dest);
1570 Netmask = NTOHL (Netmask);
1571 Nexthop = NTOHL (Nexthop);
1572
1573 IpIf = IpInstance->Interface;
1574
1575 if (!IP4_IS_VALID_NETMASK (Netmask)) {
1576 Status = EFI_INVALID_PARAMETER;
1577 goto ON_EXIT;
1578 }
1579
1580 //
1581 // the gateway address must be a unicast on the connected network if not zero.
1582 //
1583 if ((Nexthop != IP4_ALLZERO_ADDRESS) &&
1584 (!IP4_NET_EQUAL (Nexthop, IpIf->Ip, IpIf->SubnetMask) ||
1585 IP4_IS_BROADCAST (Ip4GetNetCast (Nexthop, IpIf)))) {
1586
1587 Status = EFI_INVALID_PARAMETER;
1588 goto ON_EXIT;
1589 }
1590
1591 if (DeleteRoute) {
1592 Status = Ip4DelRoute (IpInstance->RouteTable, Dest, Netmask, Nexthop);
1593 } else {
1594 Status = Ip4AddRoute (IpInstance->RouteTable, Dest, Netmask, Nexthop);
1595 }
1596
1597 ON_EXIT:
1598 gBS->RestoreTPL (OldTpl);
1599 return Status;
1600 }
1601
1602
1603 /**
1604 Check whether the user's token or event has already
1605 been enqueued on IP4's list.
1606
1607 @param[in] Map The container of either user's transmit or receive
1608 token.
1609 @param[in] Item Current item to check against
1610 @param[in] Context The Token to check againist.
1611
1612 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
1613 @retval EFI_SUCCESS The current item isn't the same token/event as the
1614 context.
1615
1616 **/
1617 EFI_STATUS
1618 EFIAPI
1619 Ip4TokenExist (
1620 IN NET_MAP *Map,
1621 IN NET_MAP_ITEM *Item,
1622 IN VOID *Context
1623 )
1624 {
1625 EFI_IP4_COMPLETION_TOKEN *Token;
1626 EFI_IP4_COMPLETION_TOKEN *TokenInItem;
1627
1628 Token = (EFI_IP4_COMPLETION_TOKEN *) Context;
1629 TokenInItem = (EFI_IP4_COMPLETION_TOKEN *) Item->Key;
1630
1631 if ((Token == TokenInItem) || (Token->Event == TokenInItem->Event)) {
1632 return EFI_ACCESS_DENIED;
1633 }
1634
1635 return EFI_SUCCESS;
1636 }
1637
1638 /**
1639 Validate the user's token against current station address.
1640
1641 @param[in] Token User's token to validate.
1642 @param[in] IpIf The IP4 child's interface.
1643 @param[in] RawData Set to TRUE to send unformatted packets.
1644
1645 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
1646 @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.
1647 @retval EFI_SUCCESS The token is valid.
1648
1649 **/
1650 EFI_STATUS
1651 Ip4TxTokenValid (
1652 IN EFI_IP4_COMPLETION_TOKEN *Token,
1653 IN IP4_INTERFACE *IpIf,
1654 IN BOOLEAN RawData
1655 )
1656 {
1657 EFI_IP4_TRANSMIT_DATA *TxData;
1658 EFI_IP4_OVERRIDE_DATA *Override;
1659 IP4_ADDR Src;
1660 IP4_ADDR Gateway;
1661 UINT32 Offset;
1662 UINT32 Index;
1663 UINT32 HeadLen;
1664
1665 if ((Token == NULL) || (Token->Event == NULL) || (Token->Packet.TxData == NULL)) {
1666 return EFI_INVALID_PARAMETER;
1667 }
1668
1669 TxData = Token->Packet.TxData;
1670
1671 //
1672 // Check the fragment table: no empty fragment, and length isn't bogus.
1673 //
1674 if ((TxData->TotalDataLength == 0) || (TxData->FragmentCount == 0)) {
1675 return EFI_INVALID_PARAMETER;
1676 }
1677
1678 Offset = TxData->TotalDataLength;
1679
1680 if (Offset > IP4_MAX_PACKET_SIZE) {
1681 return EFI_BAD_BUFFER_SIZE;
1682 }
1683
1684 for (Index = 0; Index < TxData->FragmentCount; Index++) {
1685 if ((TxData->FragmentTable[Index].FragmentBuffer == NULL) ||
1686 (TxData->FragmentTable[Index].FragmentLength == 0)) {
1687
1688 return EFI_INVALID_PARAMETER;
1689 }
1690
1691 Offset -= TxData->FragmentTable[Index].FragmentLength;
1692 }
1693
1694 if (Offset != 0) {
1695 return EFI_INVALID_PARAMETER;
1696 }
1697
1698 //
1699 // NOTE that OptionsLength/OptionsBuffer/OverrideData are ignored if RawData
1700 // is TRUE.
1701 //
1702 if (RawData) {
1703 return EFI_SUCCESS;
1704 }
1705
1706 //
1707 // Check the IP options: no more than 40 bytes and format is OK
1708 //
1709 if (TxData->OptionsLength != 0) {
1710 if ((TxData->OptionsLength > 40) || (TxData->OptionsBuffer == NULL)) {
1711 return EFI_INVALID_PARAMETER;
1712 }
1713
1714 if (!Ip4OptionIsValid (TxData->OptionsBuffer, TxData->OptionsLength, FALSE)) {
1715 return EFI_INVALID_PARAMETER;
1716 }
1717 }
1718
1719 //
1720 // Check the source and gateway: they must be a valid unicast.
1721 // Gateway must also be on the connected network.
1722 //
1723 if (TxData->OverrideData != NULL) {
1724 Override = TxData->OverrideData;
1725
1726 CopyMem (&Src, &Override->SourceAddress, sizeof (IP4_ADDR));
1727 CopyMem (&Gateway, &Override->GatewayAddress, sizeof (IP4_ADDR));
1728
1729 Src = NTOHL (Src);
1730 Gateway = NTOHL (Gateway);
1731
1732 if ((NetGetIpClass (Src) > IP4_ADDR_CLASSC) ||
1733 (Src == IP4_ALLONE_ADDRESS) ||
1734 IP4_IS_BROADCAST (Ip4GetNetCast (Src, IpIf))) {
1735
1736 return EFI_INVALID_PARAMETER;
1737 }
1738
1739 //
1740 // If gateway isn't zero, it must be a unicast address, and
1741 // on the connected network.
1742 //
1743 if ((Gateway != IP4_ALLZERO_ADDRESS) &&
1744 ((NetGetIpClass (Gateway) > IP4_ADDR_CLASSC) ||
1745 !IP4_NET_EQUAL (Gateway, IpIf->Ip, IpIf->SubnetMask) ||
1746 IP4_IS_BROADCAST (Ip4GetNetCast (Gateway, IpIf)))) {
1747
1748 return EFI_INVALID_PARAMETER;
1749 }
1750 }
1751
1752 //
1753 // Check the packet length: Head length and packet length all has a limit
1754 //
1755 HeadLen = sizeof (IP4_HEAD) + ((TxData->OptionsLength + 3) &~0x03);
1756
1757 if ((HeadLen > IP4_MAX_HEADLEN) ||
1758 (TxData->TotalDataLength + HeadLen > IP4_MAX_PACKET_SIZE)) {
1759
1760 return EFI_BAD_BUFFER_SIZE;
1761 }
1762
1763 return EFI_SUCCESS;
1764 }
1765
1766
1767 /**
1768 The callback function for the net buffer which wraps the user's
1769 transmit token. Although it seems this function is pretty simple,
1770 there are some subtle things.
1771 When user requests the IP to transmit a packet by passing it a
1772 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data
1773 is wrapped in an net buffer. the net buffer's Free function is
1774 set to Ip4FreeTxToken. The Token and token wrap are added to the
1775 IP child's TxToken map. Then the buffer is passed to Ip4Output for
1776 transmission. If something error happened before that, the buffer
1777 is freed, which in turn will free the token wrap. The wrap may
1778 have been added to the TxToken map or not, and the user's event
1779 shouldn't be fired because we are still in the EfiIp4Transmit. If
1780 the buffer has been sent by Ip4Output, it should be removed from
1781 the TxToken map and user's event signaled. The token wrap and buffer
1782 are bound together. Check the comments in Ip4Output for information
1783 about IP fragmentation.
1784
1785 @param[in] Context The token's wrap
1786
1787 **/
1788 VOID
1789 EFIAPI
1790 Ip4FreeTxToken (
1791 IN VOID *Context
1792 )
1793 {
1794 IP4_TXTOKEN_WRAP *Wrap;
1795 NET_MAP_ITEM *Item;
1796
1797 Wrap = (IP4_TXTOKEN_WRAP *) Context;
1798
1799 //
1800 // Signal IpSecRecycleEvent to inform IPsec free the memory
1801 //
1802 if (Wrap->IpSecRecycleSignal != NULL) {
1803 gBS->SignalEvent (Wrap->IpSecRecycleSignal);
1804 }
1805
1806 //
1807 // Find the token in the instance's map. EfiIp4Transmit put the
1808 // token to the map. If that failed, NetMapFindKey will return NULL.
1809 //
1810 Item = NetMapFindKey (&Wrap->IpInstance->TxTokens, Wrap->Token);
1811
1812 if (Item != NULL) {
1813 NetMapRemoveItem (&Wrap->IpInstance->TxTokens, Item, NULL);
1814 }
1815
1816 if (Wrap->Sent) {
1817 gBS->SignalEvent (Wrap->Token->Event);
1818
1819 //
1820 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
1821 //
1822 DispatchDpc ();
1823 }
1824
1825 FreePool (Wrap);
1826 }
1827
1828
1829 /**
1830 The callback function to Ip4Output to update the transmit status.
1831
1832 @param Ip4Instance The Ip4Instance that request the transmit.
1833 @param Packet The user's transmit request
1834 @param IoStatus The result of the transmission
1835 @param Flag Not used during transmission
1836 @param Context The token's wrap.
1837
1838 **/
1839 VOID
1840 Ip4OnPacketSent (
1841 IP4_PROTOCOL *Ip4Instance,
1842 NET_BUF *Packet,
1843 EFI_STATUS IoStatus,
1844 UINT32 Flag,
1845 VOID *Context
1846 )
1847 {
1848 IP4_TXTOKEN_WRAP *Wrap;
1849
1850 //
1851 // This is the transmission request from upper layer,
1852 // not the IP4 driver itself.
1853 //
1854 ASSERT (Ip4Instance != NULL);
1855
1856 //
1857 // The first fragment of the packet has been sent. Update
1858 // the token's status. That is, if fragmented, the transmit's
1859 // status is the first fragment's status. The Wrap will be
1860 // release when all the fragments are release. Check the comments
1861 // in Ip4FreeTxToken and Ip4Output for information.
1862 //
1863 Wrap = (IP4_TXTOKEN_WRAP *) Context;
1864 Wrap->Token->Status = IoStatus;
1865
1866 NetbufFree (Wrap->Packet);
1867 }
1868
1869
1870 /**
1871 Places outgoing data packets into the transmit queue.
1872
1873 The Transmit() function places a sending request in the transmit queue of this
1874 EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some
1875 errors occur, the event in the token will be signaled and the status is updated.
1876
1877 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1878 @param[in] Token Pointer to the transmit token.
1879
1880 @retval EFI_SUCCESS The data has been queued for transmission.
1881 @retval EFI_NOT_STARTED This instance has not been started.
1882 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1883 RARP, etc.) is not finished yet.
1884 @retval EFI_INVALID_PARAMETER One or more pameters are invalid.
1885 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event
1886 was already in the transmit queue.
1887 @retval EFI_NOT_READY The completion token could not be queued because the transmit
1888 queue is full.
1889 @retval EFI_NOT_FOUND Not route is found to destination address.
1890 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
1891 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
1892 short to transmit.
1893 @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is
1894 greater than MTU (or greater than the maximum packet size if
1895 Token.Packet.TxData.OverrideData.
1896 DoNotFragment is TRUE.)
1897
1898 **/
1899 EFI_STATUS
1900 EFIAPI
1901 EfiIp4Transmit (
1902 IN EFI_IP4_PROTOCOL *This,
1903 IN EFI_IP4_COMPLETION_TOKEN *Token
1904 )
1905 {
1906 IP4_SERVICE *IpSb;
1907 IP4_PROTOCOL *IpInstance;
1908 IP4_INTERFACE *IpIf;
1909 IP4_TXTOKEN_WRAP *Wrap;
1910 EFI_IP4_TRANSMIT_DATA *TxData;
1911 EFI_IP4_CONFIG_DATA *Config;
1912 EFI_IP4_OVERRIDE_DATA *Override;
1913 IP4_HEAD Head;
1914 IP4_ADDR GateWay;
1915 EFI_STATUS Status;
1916 EFI_TPL OldTpl;
1917 BOOLEAN DontFragment;
1918 UINT32 HeadLen;
1919 UINT8 RawHdrLen;
1920 UINT32 OptionsLength;
1921 UINT8 *OptionsBuffer;
1922 VOID *FirstFragment;
1923
1924 if (This == NULL) {
1925 return EFI_INVALID_PARAMETER;
1926 }
1927
1928 IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);
1929
1930 if (IpInstance->State != IP4_STATE_CONFIGED) {
1931 return EFI_NOT_STARTED;
1932 }
1933
1934 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1935
1936 IpSb = IpInstance->Service;
1937 IpIf = IpInstance->Interface;
1938 Config = &IpInstance->ConfigData;
1939
1940 if (Config->UseDefaultAddress && IP4_NO_MAPPING (IpInstance)) {
1941 Status = EFI_NO_MAPPING;
1942 goto ON_EXIT;
1943 }
1944
1945 //
1946 // make sure that token is properly formated
1947 //
1948 Status = Ip4TxTokenValid (Token, IpIf, Config->RawData);
1949
1950 if (EFI_ERROR (Status)) {
1951 goto ON_EXIT;
1952 }
1953
1954 //
1955 // Check whether the token or signal already existed.
1956 //
1957 if (EFI_ERROR (NetMapIterate (&IpInstance->TxTokens, Ip4TokenExist, Token))) {
1958 Status = EFI_ACCESS_DENIED;
1959 goto ON_EXIT;
1960 }
1961
1962 //
1963 // Build the IP header, need to fill in the Tos, TotalLen, Id,
1964 // fragment, Ttl, protocol, Src, and Dst.
1965 //
1966 TxData = Token->Packet.TxData;
1967
1968 FirstFragment = NULL;
1969
1970 if (Config->RawData) {
1971 //
1972 // When RawData is TRUE, first buffer in FragmentTable points to a raw
1973 // IPv4 fragment including IPv4 header and options.
1974 //
1975 FirstFragment = TxData->FragmentTable[0].FragmentBuffer;
1976 CopyMem (&RawHdrLen, FirstFragment, sizeof (UINT8));
1977
1978 RawHdrLen = (UINT8) (RawHdrLen & 0x0f);
1979 if (RawHdrLen < 5) {
1980 return EFI_INVALID_PARAMETER;
1981 }
1982
1983 RawHdrLen = (UINT8) (RawHdrLen << 2);
1984
1985 CopyMem (&Head, FirstFragment, IP4_MIN_HEADLEN);
1986
1987 Ip4NtohHead (&Head);
1988 HeadLen = 0;
1989 DontFragment = IP4_DO_NOT_FRAGMENT (Head.Fragment);
1990
1991 if (!DontFragment) {
1992 return EFI_INVALID_PARAMETER;
1993 }
1994
1995 GateWay = IP4_ALLZERO_ADDRESS;
1996
1997 //
1998 // Get IPv4 options from first fragment.
1999 //
2000 if (RawHdrLen == IP4_MIN_HEADLEN) {
2001 OptionsLength = 0;
2002 OptionsBuffer = NULL;
2003 } else {
2004 OptionsLength = RawHdrLen - IP4_MIN_HEADLEN;
2005 OptionsBuffer = (UINT8 *) FirstFragment + IP4_MIN_HEADLEN;
2006 }
2007
2008 //
2009 // Trim off IPv4 header and options from first fragment.
2010 //
2011 TxData->FragmentTable[0].FragmentBuffer = (UINT8 *) FirstFragment + RawHdrLen;
2012 TxData->FragmentTable[0].FragmentLength = TxData->FragmentTable[0].FragmentLength - RawHdrLen;
2013 } else {
2014 CopyMem (&Head.Dst, &TxData->DestinationAddress, sizeof (IP4_ADDR));
2015 Head.Dst = NTOHL (Head.Dst);
2016
2017 if (TxData->OverrideData != NULL) {
2018 Override = TxData->OverrideData;
2019 Head.Protocol = Override->Protocol;
2020 Head.Tos = Override->TypeOfService;
2021 Head.Ttl = Override->TimeToLive;
2022 DontFragment = Override->DoNotFragment;
2023
2024 CopyMem (&Head.Src, &Override->SourceAddress, sizeof (IP4_ADDR));
2025 CopyMem (&GateWay, &Override->GatewayAddress, sizeof (IP4_ADDR));
2026
2027 Head.Src = NTOHL (Head.Src);
2028 GateWay = NTOHL (GateWay);
2029 } else {
2030 Head.Src = IpIf->Ip;
2031 GateWay = IP4_ALLZERO_ADDRESS;
2032 Head.Protocol = Config->DefaultProtocol;
2033 Head.Tos = Config->TypeOfService;
2034 Head.Ttl = Config->TimeToLive;
2035 DontFragment = Config->DoNotFragment;
2036 }
2037
2038 Head.Fragment = IP4_HEAD_FRAGMENT_FIELD (DontFragment, FALSE, 0);
2039 HeadLen = (TxData->OptionsLength + 3) & (~0x03);
2040
2041 OptionsLength = TxData->OptionsLength;
2042 OptionsBuffer = (UINT8 *) (TxData->OptionsBuffer);
2043 }
2044
2045 //
2046 // If don't fragment and fragment needed, return error
2047 //
2048 if (DontFragment && (TxData->TotalDataLength + HeadLen > IpSb->MaxPacketSize)) {
2049 Status = EFI_BAD_BUFFER_SIZE;
2050 goto ON_EXIT;
2051 }
2052
2053 //
2054 // OK, it survives all the validation check. Wrap the token in
2055 // a IP4_TXTOKEN_WRAP and the data in a netbuf
2056 //
2057 Status = EFI_OUT_OF_RESOURCES;
2058 Wrap = AllocateZeroPool (sizeof (IP4_TXTOKEN_WRAP));
2059 if (Wrap == NULL) {
2060 goto ON_EXIT;
2061 }
2062
2063 Wrap->IpInstance = IpInstance;
2064 Wrap->Token = Token;
2065 Wrap->Sent = FALSE;
2066 Wrap->Life = IP4_US_TO_SEC (Config->TransmitTimeout);
2067 Wrap->Packet = NetbufFromExt (
2068 (NET_FRAGMENT *) TxData->FragmentTable,
2069 TxData->FragmentCount,
2070 IP4_MAX_HEADLEN,
2071 0,
2072 Ip4FreeTxToken,
2073 Wrap
2074 );
2075
2076 if (Wrap->Packet == NULL) {
2077 FreePool (Wrap);
2078 goto ON_EXIT;
2079 }
2080
2081 Token->Status = EFI_NOT_READY;
2082
2083 if (EFI_ERROR (NetMapInsertTail (&IpInstance->TxTokens, Token, Wrap))) {
2084 //
2085 // NetbufFree will call Ip4FreeTxToken, which in turn will
2086 // free the IP4_TXTOKEN_WRAP. Now, the token wrap hasn't been
2087 // enqueued.
2088 //
2089 if (Config->RawData) {
2090 //
2091 // Restore pointer of first fragment in RawData mode.
2092 //
2093 TxData->FragmentTable[0].FragmentBuffer = (UINT8 *) FirstFragment;
2094 }
2095
2096 NetbufFree (Wrap->Packet);
2097 goto ON_EXIT;
2098 }
2099
2100 //
2101 // Mark the packet sent before output it. Mark it not sent again if the
2102 // returned status is not EFI_SUCCESS;
2103 //
2104 Wrap->Sent = TRUE;
2105
2106 Status = Ip4Output (
2107 IpSb,
2108 IpInstance,
2109 Wrap->Packet,
2110 &Head,
2111 OptionsBuffer,
2112 OptionsLength,
2113 GateWay,
2114 Ip4OnPacketSent,
2115 Wrap
2116 );
2117
2118 if (EFI_ERROR (Status)) {
2119 Wrap->Sent = FALSE;
2120
2121 if (Config->RawData) {
2122 //
2123 // Restore pointer of first fragment in RawData mode.
2124 //
2125 TxData->FragmentTable[0].FragmentBuffer = (UINT8 *) FirstFragment;
2126 }
2127
2128 NetbufFree (Wrap->Packet);
2129 }
2130
2131 if (Config->RawData) {
2132 //
2133 // Restore pointer of first fragment in RawData mode.
2134 //
2135 TxData->FragmentTable[0].FragmentBuffer = (UINT8 *) FirstFragment;
2136 }
2137
2138 ON_EXIT:
2139 gBS->RestoreTPL (OldTpl);
2140 return Status;
2141 }
2142
2143
2144 /**
2145 Places a receiving request into the receiving queue.
2146
2147 The Receive() function places a completion token into the receive packet queue.
2148 This function is always asynchronous.
2149
2150 The Token.Event field in the completion token must be filled in by the caller
2151 and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol
2152 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
2153 is signaled.
2154
2155 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2156 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
2157
2158 @retval EFI_SUCCESS The receive completion token was cached.
2159 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2160 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)
2161 is not finished yet.
2162 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2163 - This is NULL.
2164 - Token is NULL.
2165 - Token.Event is NULL.
2166 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
2167 resources (usually memory).
2168 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2169 The EFI IPv4 Protocol instance has been reset to startup defaults.
2170 EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
2171 in the receive queue.
2172 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
2173 @retval EFI_ICMP_ERROR An ICMP error packet was received.
2174
2175 **/
2176 EFI_STATUS
2177 EFIAPI
2178 EfiIp4Receive (
2179 IN EFI_IP4_PROTOCOL *This,
2180 IN EFI_IP4_COMPLETION_TOKEN *Token
2181 )
2182 {
2183 IP4_PROTOCOL *IpInstance;
2184 EFI_STATUS Status;
2185 EFI_TPL OldTpl;
2186
2187 //
2188 // First validate the parameters
2189 //
2190 if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {
2191 return EFI_INVALID_PARAMETER;
2192 }
2193
2194 IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);
2195
2196 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
2197
2198 if (IpInstance->State != IP4_STATE_CONFIGED) {
2199 Status = EFI_NOT_STARTED;
2200 goto ON_EXIT;
2201 }
2202
2203 //
2204 // Check whether the toke is already on the receive queue.
2205 //
2206 Status = NetMapIterate (&IpInstance->RxTokens, Ip4TokenExist, Token);
2207
2208 if (EFI_ERROR (Status)) {
2209 Status = EFI_ACCESS_DENIED;
2210 goto ON_EXIT;
2211 }
2212
2213 //
2214 // Queue the token then check whether there is pending received packet.
2215 //
2216 Status = NetMapInsertTail (&IpInstance->RxTokens, Token, NULL);
2217
2218 if (EFI_ERROR (Status)) {
2219 goto ON_EXIT;
2220 }
2221
2222 Status = Ip4InstanceDeliverPacket (IpInstance);
2223
2224 //
2225 // Dispatch the DPC queued by the NotifyFunction of this instane's receive
2226 // event.
2227 //
2228 DispatchDpc ();
2229
2230 ON_EXIT:
2231 gBS->RestoreTPL (OldTpl);
2232 return Status;
2233 }
2234
2235
2236 /**
2237 Cancel the transmitted but not recycled packet. If a matching
2238 token is found, it will call Ip4CancelPacket to cancel the
2239 packet. Ip4CancelPacket will cancel all the fragments of the
2240 packet. When all the fragments are freed, the IP4_TXTOKEN_WRAP
2241 will be deleted from the Map, and user's event signalled.
2242 Because Ip4CancelPacket and other functions are all called in
2243 line, so, after Ip4CancelPacket returns, the Item has been freed.
2244
2245 @param[in] Map The IP4 child's transmit queue
2246 @param[in] Item The current transmitted packet to test.
2247 @param[in] Context The user's token to cancel.
2248
2249 @retval EFI_SUCCESS Continue to check the next Item.
2250 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
2251
2252 **/
2253 EFI_STATUS
2254 EFIAPI
2255 Ip4CancelTxTokens (
2256 IN NET_MAP *Map,
2257 IN NET_MAP_ITEM *Item,
2258 IN VOID *Context
2259 )
2260 {
2261 EFI_IP4_COMPLETION_TOKEN *Token;
2262 IP4_TXTOKEN_WRAP *Wrap;
2263
2264 Token = (EFI_IP4_COMPLETION_TOKEN *) Context;
2265
2266 //
2267 // Return EFI_SUCCESS to check the next item in the map if
2268 // this one doesn't match.
2269 //
2270 if ((Token != NULL) && (Token != Item->Key)) {
2271 return EFI_SUCCESS;
2272 }
2273
2274 Wrap = (IP4_TXTOKEN_WRAP *) Item->Value;
2275 ASSERT (Wrap != NULL);
2276
2277 //
2278 // Don't access the Item, Wrap and Token's members after this point.
2279 // Item and wrap has been freed. And we no longer own the Token.
2280 //
2281 Ip4CancelPacket (Wrap->IpInstance->Interface, Wrap->Packet, EFI_ABORTED);
2282
2283 //
2284 // If only one item is to be cancel, return EFI_ABORTED to stop
2285 // iterating the map any more.
2286 //
2287 if (Token != NULL) {
2288 return EFI_ABORTED;
2289 }
2290
2291 return EFI_SUCCESS;
2292 }
2293
2294
2295 /**
2296 Cancel the receive request. This is quiet simple, because
2297 it is only enqueued in our local receive map.
2298
2299 @param[in] Map The IP4 child's receive queue
2300 @param[in] Item Current receive request to cancel.
2301 @param[in] Context The user's token to cancel
2302
2303 @retval EFI_SUCCESS Continue to check the next receive request on the
2304 queue.
2305 @retval EFI_ABORTED The user's token (token != NULL) has been
2306 cancelled.
2307
2308 **/
2309 EFI_STATUS
2310 EFIAPI
2311 Ip4CancelRxTokens (
2312 IN NET_MAP *Map,
2313 IN NET_MAP_ITEM *Item,
2314 IN VOID *Context
2315 )
2316 {
2317 EFI_IP4_COMPLETION_TOKEN *Token;
2318 EFI_IP4_COMPLETION_TOKEN *This;
2319
2320 Token = (EFI_IP4_COMPLETION_TOKEN *) Context;
2321 This = Item->Key;
2322
2323 if ((Token != NULL) && (Token != This)) {
2324 return EFI_SUCCESS;
2325 }
2326
2327 NetMapRemoveItem (Map, Item, NULL);
2328
2329 This->Status = EFI_ABORTED;
2330 This->Packet.RxData = NULL;
2331 gBS->SignalEvent (This->Event);
2332
2333 if (Token != NULL) {
2334 return EFI_ABORTED;
2335 }
2336
2337 return EFI_SUCCESS;
2338 }
2339
2340
2341 /**
2342 Cancel the user's receive/transmit request.
2343
2344 @param[in] IpInstance The IP4 child
2345 @param[in] Token The token to cancel. If NULL, all token will be
2346 cancelled.
2347
2348 @retval EFI_SUCCESS The token is cancelled
2349 @retval EFI_NOT_FOUND The token isn't found on either the
2350 transmit/receive queue
2351 @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.
2352
2353 **/
2354 EFI_STATUS
2355 Ip4Cancel (
2356 IN IP4_PROTOCOL *IpInstance,
2357 IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL
2358 )
2359 {
2360 EFI_STATUS Status;
2361
2362 //
2363 // First check the transmitted packet. Ip4CancelTxTokens returns
2364 // EFI_ABORTED to mean that the token has been cancelled when
2365 // token != NULL. So, return EFI_SUCCESS for this condition.
2366 //
2367 Status = NetMapIterate (&IpInstance->TxTokens, Ip4CancelTxTokens, Token);
2368
2369 if (EFI_ERROR (Status)) {
2370 if ((Token != NULL) && (Status == EFI_ABORTED)) {
2371 return EFI_SUCCESS;
2372 }
2373
2374 return Status;
2375 }
2376
2377 //
2378 // Check the receive queue. Ip4CancelRxTokens also returns EFI_ABORT
2379 // for Token!=NULL and it is cancelled.
2380 //
2381 Status = NetMapIterate (&IpInstance->RxTokens, Ip4CancelRxTokens, Token);
2382 //
2383 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
2384 // events.
2385 //
2386 DispatchDpc ();
2387 if (EFI_ERROR (Status)) {
2388 if ((Token != NULL) && (Status == EFI_ABORTED)) {
2389 return EFI_SUCCESS;
2390 }
2391
2392 return Status;
2393 }
2394
2395 //
2396 // OK, if the Token is found when Token != NULL, the NetMapIterate
2397 // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.
2398 //
2399 if (Token != NULL) {
2400 return EFI_NOT_FOUND;
2401 }
2402
2403 //
2404 // If Token == NULL, cancel all the tokens. return error if no
2405 // all of them are cancelled.
2406 //
2407 if (!NetMapIsEmpty (&IpInstance->TxTokens) ||
2408 !NetMapIsEmpty (&IpInstance->RxTokens)) {
2409
2410 return EFI_DEVICE_ERROR;
2411 }
2412
2413 return EFI_SUCCESS;
2414 }
2415
2416
2417 /**
2418 Abort an asynchronous transmit or receive request.
2419
2420 The Cancel() function is used to abort a pending transmit or receive request.
2421 If the token is in the transmit or receive request queues, after calling this
2422 function, Token->Status will be set to EFI_ABORTED and then Token->Event will
2423 be signaled. If the token is not in one of the queues, which usually means the
2424 asynchronous operation has completed, this function will not signal the token
2425 and EFI_NOT_FOUND is returned.
2426
2427 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2428 @param[in] Token Pointer to a token that has been issued by
2429 EFI_IP4_PROTOCOL.Transmit() or
2430 EFI_IP4_PROTOCOL.Receive(). If NULL, all pending
2431 tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is
2432 defined in EFI_IP4_PROTOCOL.Transmit().
2433
2434 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
2435 Token.->Event was signaled. When Token is NULL, all
2436 pending requests were aborted and their events were signaled.
2437 @retval EFI_INVALID_PARAMETER This is NULL.
2438 @retval EFI_NOT_STARTED This instance has not been started.
2439 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2440 RARP, etc.) is not finished yet.
2441 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
2442 not found in the transmit or receive queue. It has either completed
2443 or was not issued by Transmit() and Receive().
2444
2445 **/
2446 EFI_STATUS
2447 EFIAPI
2448 EfiIp4Cancel (
2449 IN EFI_IP4_PROTOCOL *This,
2450 IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL
2451 )
2452 {
2453 IP4_PROTOCOL *IpInstance;
2454 EFI_STATUS Status;
2455 EFI_TPL OldTpl;
2456
2457 if (This == NULL) {
2458 return EFI_INVALID_PARAMETER;
2459 }
2460
2461 IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);
2462
2463 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
2464
2465 if (IpInstance->State != IP4_STATE_CONFIGED) {
2466 Status = EFI_NOT_STARTED;
2467 goto ON_EXIT;
2468 }
2469
2470 if (IpInstance->ConfigData.UseDefaultAddress && IP4_NO_MAPPING (IpInstance)) {
2471 Status = EFI_NO_MAPPING;
2472 goto ON_EXIT;
2473 }
2474
2475 Status = Ip4Cancel (IpInstance, Token);
2476
2477 ON_EXIT:
2478 gBS->RestoreTPL (OldTpl);
2479 return Status;
2480 }
2481
2482
2483 /**
2484 Polls for incoming data packets and processes outgoing data packets.
2485
2486 The Poll() function polls for incoming data packets and processes outgoing data
2487 packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()
2488 function to increase the rate that data packets are moved between the communications
2489 device and the transmit and receive queues.
2490
2491 In some systems the periodic timer event may not poll the underlying communications
2492 device fast enough to transmit and/or receive all data packets without missing
2493 incoming packets or dropping outgoing packets. Drivers and applications that are
2494 experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function
2495 more often.
2496
2497 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2498
2499 @retval EFI_SUCCESS Incoming or outgoing data was processed.
2500 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2501 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2502 RARP, etc.) is not finished yet.
2503 @retval EFI_INVALID_PARAMETER This is NULL.
2504 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2505 @retval EFI_NOT_READY No incoming or outgoing data is processed.
2506 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
2507 Consider increasing the polling rate.
2508
2509 **/
2510 EFI_STATUS
2511 EFIAPI
2512 EfiIp4Poll (
2513 IN EFI_IP4_PROTOCOL *This
2514 )
2515 {
2516 IP4_PROTOCOL *IpInstance;
2517 EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
2518
2519 if (This == NULL) {
2520 return EFI_INVALID_PARAMETER;
2521 }
2522
2523 IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);
2524
2525 if (IpInstance->State == IP4_STATE_UNCONFIGED) {
2526 return EFI_NOT_STARTED;
2527 }
2528
2529 Mnp = IpInstance->Service->Mnp;
2530
2531 //
2532 // Don't lock the Poll function to enable the deliver of
2533 // the packet polled up.
2534 //
2535 return Mnp->Poll (Mnp);
2536 }
2537
2538 /**
2539 Decrease the life of the transmitted packets. If it is
2540 decreased to zero, cancel the packet. This function is
2541 called by Ip4PacketTimerTicking which time out both the
2542 received-but-not-delivered and transmitted-but-not-recycle
2543 packets.
2544
2545 @param[in] Map The IP4 child's transmit map.
2546 @param[in] Item Current transmitted packet
2547 @param[in] Context Not used.
2548
2549 @retval EFI_SUCCESS Always returns EFI_SUCCESS
2550
2551 **/
2552 EFI_STATUS
2553 EFIAPI
2554 Ip4SentPacketTicking (
2555 IN NET_MAP *Map,
2556 IN NET_MAP_ITEM *Item,
2557 IN VOID *Context
2558 )
2559 {
2560 IP4_TXTOKEN_WRAP *Wrap;
2561
2562 Wrap = (IP4_TXTOKEN_WRAP *) Item->Value;
2563 ASSERT (Wrap != NULL);
2564
2565 if ((Wrap->Life > 0) && (--Wrap->Life == 0)) {
2566 Ip4CancelPacket (Wrap->IpInstance->Interface, Wrap->Packet, EFI_ABORTED);
2567 }
2568
2569 return EFI_SUCCESS;
2570 }
2571
2572
2573 /**
2574 The heart beat timer of IP4 service instance. It times out
2575 all of its IP4 children's received-but-not-delivered and
2576 transmitted-but-not-recycle packets, and provides time input
2577 for its IGMP protocol.
2578
2579 @param[in] Event The IP4 service instance's heart beat timer.
2580 @param[in] Context The IP4 service instance.
2581
2582 **/
2583 VOID
2584 EFIAPI
2585 Ip4TimerTicking (
2586 IN EFI_EVENT Event,
2587 IN VOID *Context
2588 )
2589 {
2590 IP4_SERVICE *IpSb;
2591
2592 IpSb = (IP4_SERVICE *) Context;
2593 NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE);
2594
2595 Ip4PacketTimerTicking (IpSb);
2596 Ip4IgmpTicking (IpSb);
2597 }