3 Copyright (c) 2005 - 2007, Intel Corporation
4 All rights reserved. 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
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.
25 Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.
27 The GetModeData() function returns the current operational mode data for this
28 driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This
29 function is used optionally to retrieve the operational mode data of underlying
32 @param This Pointer to the EFI_IP4_PROTOCOL instance.
33 @param Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.
34 @param MnpConfigData Pointer to the managed network configuration data structure.
35 @param SnpModeData Pointer to the simple network mode data structure.
37 @retval EFI_SUCCESS The operation completed successfully.
38 @retval EFI_INVALID_PARAMETER This is NULL.
39 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
45 IN CONST EFI_IP4_PROTOCOL
*This
,
46 OUT EFI_IP4_MODE_DATA
*Ip4ModeData
, OPTIONAL
47 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData
, OPTIONAL
48 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
52 Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
54 The Configure() function is used to set, change, or reset the operational
55 parameters and filter settings for this EFI IPv4 Protocol instance. Until these
56 parameters have been set, no network traffic can be sent or received by this
57 instance. Once the parameters have been reset (by calling this function with
58 IpConfigData set to NULL), no more traffic can be sent or received until these
59 parameters have been set again. Each EFI IPv4 Protocol instance can be started
60 and stopped independently of each other by enabling or disabling their receive
61 filter settings with the Configure() function.
63 When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will
64 be appended as an alias address into the addresses list in the EFI IPv4 Protocol
65 driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL
66 to retrieve the default IPv4 address if it is not available yet. Clients could
67 frequently call GetModeData() to check the status to ensure that the default IPv4
70 If operational parameters are reset or changed, any pending transmit and receive
71 requests will be cancelled. Their completion token status will be set to EFI_ABORTED
72 and their events will be signaled.
74 @param This Pointer to the EFI_IP4_PROTOCOL instance.
75 @param IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.
77 @retval EFI_SUCCESS The driver instance was successfully opened.
78 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
79 RARP, etc.) is not finished yet.
80 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
81 @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:
82 A configuration protocol (DHCP, BOOTP, RARP, etc.) could
83 not be located when clients choose to use the default IPv4
84 address. This EFI IPv4 Protocol implementation does not
85 support this requested filter or timeout setting.
86 @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.
87 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the
88 IPv4 address or subnet mask can be changed. The interface must
89 also be stopped when switching to/from raw packet mode.
90 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4
91 Protocol driver instance is not opened.
97 IN EFI_IP4_PROTOCOL
*This
,
98 IN EFI_IP4_CONFIG_DATA
*IpConfigData OPTIONAL
102 Joins and leaves multicast groups.
104 The Groups() function is used to join and leave multicast group sessions. Joining
105 a group will enable reception of matching multicast packets. Leaving a group will
106 disable the multicast packet reception.
108 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
110 @param This Pointer to the EFI_IP4_PROTOCOL instance.
111 @param JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.
112 @param GroupAddress Pointer to the IPv4 multicast address.
114 @retval EFI_SUCCESS The operation completed successfully.
115 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
117 - JoinFlag is TRUE and GroupAddress is NULL.
118 - GroupAddress is not NULL and *GroupAddress is
119 not a multicast IPv4 address.
120 @retval EFI_NOT_STARTED This instance has not been started.
121 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
122 RARP, etc.) is not finished yet.
123 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
124 @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.
125 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
127 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
128 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
134 IN EFI_IP4_PROTOCOL
*This
,
136 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
140 Adds and deletes routing table entries.
142 The Routes() function adds a route to or deletes a route from the routing table.
144 Routes are determined by comparing the SubnetAddress with the destination IPv4
145 address arithmetically AND-ed with the SubnetMask. The gateway address must be
146 on the same subnet as the configured station address.
148 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
149 The default route matches all destination IPv4 addresses that do not match any
152 A GatewayAddress that is zero is a nonroute. Packets are sent to the destination
153 IP address if it can be found in the ARP cache or on the local subnet. One automatic
154 nonroute entry will be inserted into the routing table for outgoing packets that
155 are addressed to a local subnet (gateway address of 0.0.0.0).
157 Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI
158 IPv4 Protocol instances that use the default IPv4 address will also have copies
159 of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these
160 copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its
161 instances. As a result, client modification to the routing table will be lost.
163 @param This Pointer to the EFI_IP4_PROTOCOL instance.
164 @param DeleteRoute Set to TRUE to delete this route from the routing table. Set to
165 FALSE to add this route to the routing table. SubnetAddress
166 and SubnetMask are used as the key to each route entry.
167 @param SubnetAddress The address of the subnet that needs to be routed.
168 @param SubnetMask The subnet mask of SubnetAddress.
169 @param GatewayAddress The unicast gateway IPv4 address for this route.
171 @retval EFI_SUCCESS The operation completed successfully.
172 @retval EFI_NOT_STARTED The driver instance has not been started.
173 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
174 RARP, etc.) is not finished yet.
175 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
177 - SubnetAddress is NULL.
178 - SubnetMask is NULL.
179 - GatewayAddress is NULL.
180 - *SubnetAddress is not a valid subnet address.
181 - *SubnetMask is not a valid subnet mask.
182 - *GatewayAddress is not a valid unicast IPv4 address.
183 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
184 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
185 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
186 DeleteRoute is FALSE).
192 IN EFI_IP4_PROTOCOL
*This
,
193 IN BOOLEAN DeleteRoute
,
194 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
195 IN EFI_IPv4_ADDRESS
*SubnetMask
,
196 IN EFI_IPv4_ADDRESS
*GatewayAddress
200 Places outgoing data packets into the transmit queue.
202 The Transmit() function places a sending request in the transmit queue of this
203 EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some
204 errors occur, the event in the token will be signaled and the status is updated.
206 @param This Pointer to the EFI_IP4_PROTOCOL instance.
207 @param Token Pointer to the transmit token.
209 @retval EFI_SUCCESS The data has been queued for transmission.
210 @retval EFI_NOT_STARTED This instance has not been started.
211 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
212 RARP, etc.) is not finished yet.
213 @retval EFI_INVALID_PARAMETER One or more pameters are invalid.
214 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event
215 was already in the transmit queue.
216 @retval EFI_NOT_READY The completion token could not be queued because the transmit
218 @retval EFI_NOT_FOUND Not route is found to destination address.
219 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
220 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
222 @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is
223 greater than MTU (or greater than the maximum packet size if
224 Token.Packet.TxData.OverrideData.
225 DoNotFragment is TRUE.)
231 IN EFI_IP4_PROTOCOL
*This
,
232 IN EFI_IP4_COMPLETION_TOKEN
*Token
236 Places a receiving request into the receiving queue.
238 The Receive() function places a completion token into the receive packet queue.
239 This function is always asynchronous.
241 The Token.Event field in the completion token must be filled in by the caller
242 and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol
243 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
246 @param This Pointer to the EFI_IP4_PROTOCOL instance.
247 @param Token Pointer to a token that is associated with the receive data descriptor.
249 @retval EFI_SUCCESS The receive completion token was cached.
250 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
251 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)
253 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
256 - Token.Event is NULL.
257 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
258 resources (usually memory).
259 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
260 The EFI IPv4 Protocol instance has been reset to startup defaults.
261 EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
262 in the receive queue.
263 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
264 @retval EFI_ICMP_ERROR An ICMP error packet was received.
270 IN EFI_IP4_PROTOCOL
*This
,
271 IN EFI_IP4_COMPLETION_TOKEN
*Token
275 Abort an asynchronous transmit or receive request.
277 The Cancel() function is used to abort a pending transmit or receive request.
278 If the token is in the transmit or receive request queues, after calling this
279 function, Token->Status will be set to EFI_ABORTED and then Token->Event will
280 be signaled. If the token is not in one of the queues, which usually means the
281 asynchronous operation has completed, this function will not signal the token
282 and EFI_NOT_FOUND is returned.
284 @param This Pointer to the EFI_IP4_PROTOCOL instance.
285 @param Token Pointer to a token that has been issued by
286 EFI_IP4_PROTOCOL.Transmit() or
287 EFI_IP4_PROTOCOL.Receive(). If NULL, all pending
288 tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is
289 defined in EFI_IP4_PROTOCOL.Transmit().
291 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
292 Token.->Event was signaled. When Token is NULL, all
293 pending requests were aborted and their events were signaled.
294 @retval EFI_INVALID_PARAMETER This is NULL.
295 @retval EFI_NOT_STARTED This instance has not been started.
296 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
297 RARP, etc.) is not finished yet.
298 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
299 not found in the transmit or receive queue. It has either completed
300 or was not issued by Transmit() and Receive().
306 IN EFI_IP4_PROTOCOL
*This
,
307 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
311 Polls for incoming data packets and processes outgoing data packets.
313 The Poll() function polls for incoming data packets and processes outgoing data
314 packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()
315 function to increase the rate that data packets are moved between the communications
316 device and the transmit and receive queues.
318 In some systems the periodic timer event may not poll the underlying communications
319 device fast enough to transmit and/or receive all data packets without missing
320 incoming packets or dropping outgoing packets. Drivers and applications that are
321 experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function
324 @param This Pointer to the EFI_IP4_PROTOCOL instance.
326 @retval EFI_SUCCESS Incoming or outgoing data was processed.
327 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
328 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
329 RARP, etc.) is not finished yet.
330 @retval EFI_INVALID_PARAMETER This is NULL.
331 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
332 @retval EFI_NOT_READY No incoming or outgoing data is processed.
333 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
334 Consider increasing the polling rate.
340 IN EFI_IP4_PROTOCOL
*This
344 mEfiIp4ProtocolTemplete
= {
356 Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.
358 The GetModeData() function returns the current operational mode data for this
359 driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This
360 function is used optionally to retrieve the operational mode data of underlying
363 @param This Pointer to the EFI_IP4_PROTOCOL instance.
364 @param Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.
365 @param MnpConfigData Pointer to the managed network configuration data structure.
366 @param SnpModeData Pointer to the simple network mode data structure.
368 @retval EFI_SUCCESS The operation completed successfully.
369 @retval EFI_INVALID_PARAMETER This is NULL.
370 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
376 IN CONST EFI_IP4_PROTOCOL
*This
,
377 OUT EFI_IP4_MODE_DATA
*Ip4ModeData
, OPTIONAL
378 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData
, OPTIONAL
379 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
382 IP4_PROTOCOL
*IpInstance
;
384 EFI_IP4_CONFIG_DATA
*Config
;
390 return EFI_INVALID_PARAMETER
;
393 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
394 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
395 IpSb
= IpInstance
->Service
;
397 if (Ip4ModeData
!= NULL
) {
399 // IsStarted is "whether the EfiIp4Configure has been called".
400 // IsConfigured is "whether the station address has been configured"
402 Ip4ModeData
->IsStarted
= (BOOLEAN
)(IpInstance
->State
== IP4_STATE_CONFIGED
);
403 CopyMem (&Ip4ModeData
->ConfigData
, &IpInstance
->ConfigData
, sizeof (Ip4ModeData
->ConfigData
));
404 Ip4ModeData
->IsConfigured
= FALSE
;
406 Ip4ModeData
->GroupCount
= IpInstance
->GroupCount
;
407 Ip4ModeData
->GroupTable
= (EFI_IPv4_ADDRESS
*) IpInstance
->Groups
;
409 Ip4ModeData
->IcmpTypeCount
= 23;
410 Ip4ModeData
->IcmpTypeList
= mIp4SupportedIcmp
;
412 Ip4ModeData
->RouteTable
= NULL
;
413 Ip4ModeData
->RouteCount
= 0;
416 // return the current station address for this IP child. So,
417 // the user can get the default address through this. Some
418 // application wants to know it station address even it is
419 // using the default one, such as a ftp server.
421 if (Ip4ModeData
->IsStarted
) {
422 Config
= &Ip4ModeData
->ConfigData
;
424 Ip
= HTONL (IpInstance
->Interface
->Ip
);
425 CopyMem (&Config
->StationAddress
, &Ip
, sizeof (EFI_IPv4_ADDRESS
));
427 Ip
= HTONL (IpInstance
->Interface
->SubnetMask
);
428 CopyMem (&Config
->SubnetMask
, &Ip
, sizeof (EFI_IPv4_ADDRESS
));
430 Ip4ModeData
->IsConfigured
= IpInstance
->Interface
->Configured
;
433 // Build a EFI route table for user from the internal route table.
435 Status
= Ip4BuildEfiRouteTable (IpInstance
);
437 if (EFI_ERROR (Status
)) {
438 gBS
->RestoreTPL (OldTpl
);
442 Ip4ModeData
->RouteTable
= IpInstance
->EfiRouteTable
;
443 Ip4ModeData
->RouteCount
= IpInstance
->EfiRouteCount
;
447 if (MnpConfigData
!= NULL
) {
448 CopyMem (MnpConfigData
, &IpSb
->MnpConfigData
, sizeof (*MnpConfigData
));
451 if (SnpModeData
!= NULL
) {
452 CopyMem (SnpModeData
, &IpSb
->SnpMode
, sizeof (*SnpModeData
));
455 gBS
->RestoreTPL (OldTpl
);
461 Config the MNP parameter used by IP. The IP driver use one MNP
462 child to transmit/receive frames. By default, it configures MNP
463 to receive unicast/multicast/broadcast. And it will enable/disable
464 the promiscous receive according to whether there is IP child
465 enable that or not. If Force is FALSE, it will iterate through
466 all the IP children to check whether the promiscuous receive
467 setting has been changed. If it hasn't been changed, it won't
468 reconfigure the MNP. If Force is TRUE, the MNP is configured no
469 matter whether that is changed or not.
471 @param IpSb The IP4 service instance that is to be changed.
472 @param Force Force the configuration or not.
474 @retval EFI_SUCCESS The MNP is successfully configured/reconfigured.
475 @retval Others Configuration failed.
479 Ip4ServiceConfigMnp (
480 IN IP4_SERVICE
*IpSb
,
485 LIST_ENTRY
*ProtoEntry
;
487 IP4_PROTOCOL
*IpInstance
;
489 BOOLEAN PromiscReceive
;
493 PromiscReceive
= FALSE
;
497 // Iterate through the IP children to check whether promiscuous
498 // receive setting has been changed. Update the interface's receive
501 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
503 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP4_INTERFACE
, Link
);
504 IpIf
->PromiscRecv
= FALSE
;
506 NET_LIST_FOR_EACH (ProtoEntry
, &IpIf
->IpInstances
) {
507 IpInstance
= NET_LIST_USER_STRUCT (ProtoEntry
, IP4_PROTOCOL
, AddrLink
);
509 if (IpInstance
->ConfigData
.AcceptPromiscuous
) {
510 IpIf
->PromiscRecv
= TRUE
;
511 PromiscReceive
= TRUE
;
517 // If promiscuous receive isn't changed, it isn't necessary to reconfigure.
519 if (PromiscReceive
== IpSb
->MnpConfigData
.EnablePromiscuousReceive
) {
524 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= PromiscReceive
;
527 Status
= IpSb
->Mnp
->Configure (IpSb
->Mnp
, &IpSb
->MnpConfigData
);
530 // recover the original configuration if failed to set the configure.
532 if (EFI_ERROR (Status
) && Reconfig
) {
533 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= (BOOLEAN
) !PromiscReceive
;
541 The event handle for IP4 auto configuration. If IP is asked
542 to reconfigure the default address. The original default
543 interface and route table are removed as the default. If there
544 is active IP children using the default address, the interface
545 will remain valid until all the children have freed their
546 references. If IP is signalled when auto configuration is done,
547 it will configure the default interface and default route table
548 with the configuration information retrieved by IP4_CONFIGURE.
550 @param Context The IP4 service binding instance.
557 Ip4AutoConfigCallBackDpc (
561 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
562 EFI_IP4_IPCONFIG_DATA
*Data
;
563 EFI_IP4_ROUTE_TABLE
*RouteEntry
;
565 IP4_ROUTE_TABLE
*RouteTable
;
571 IpSb
= (IP4_SERVICE
*) Context
;
572 NET_CHECK_SIGNATURE (IpSb
, IP4_SERVICE_SIGNATURE
);
574 Ip4Config
= IpSb
->Ip4Config
;
577 // IP is asked to do the reconfiguration. If the default interface
578 // has been configured, release the default interface and route
579 // table, then create a new one. If there are some IP children
580 // using it, the interface won't be physically freed until all the
581 // children have released their reference to it. Also remember to
582 // restart the receive on the default address. IP4 driver only receive
583 // frames on the default address, and when the default interface is
584 // freed, Ip4AcceptFrame won't be informed.
586 if (IpSb
->ActiveEvent
== IpSb
->ReconfigEvent
) {
588 if (IpSb
->DefaultInterface
->Configured
) {
589 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
595 RouteTable
= Ip4CreateRouteTable ();
597 if (RouteTable
== NULL
) {
598 Ip4FreeInterface (IpIf
, NULL
);
602 Ip4CancelReceive (IpSb
->DefaultInterface
);
603 Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
604 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
606 IpSb
->DefaultInterface
= IpIf
;
607 InsertHeadList (&IpSb
->Interfaces
, &IpIf
->Link
);
609 IpSb
->DefaultRouteTable
= RouteTable
;
610 Ip4ReceiveFrame (IpIf
, NULL
, Ip4AccpetFrame
, IpSb
);
613 Ip4Config
->Stop (Ip4Config
);
614 Ip4Config
->Start (Ip4Config
, IpSb
->DoneEvent
, IpSb
->ReconfigEvent
);
619 // Get the configure data in two steps: get the length then the data.
623 if (Ip4Config
->GetData (Ip4Config
, &Len
, NULL
) != EFI_BUFFER_TOO_SMALL
) {
627 Data
= AllocatePool (Len
);
633 Status
= Ip4Config
->GetData (Ip4Config
, &Len
, Data
);
635 if (EFI_ERROR (Status
)) {
639 IpIf
= IpSb
->DefaultInterface
;
642 // If the default address has been configured don't change it.
643 // This is unlikely to happen if EFI_IP4_CONFIG protocol has
644 // informed us to reconfigure each time it wants to change the
645 // configuration parameters.
647 if (IpIf
->Configured
) {
652 // Set the default interface's address, then add a directed
653 // route for it, that is, the route whose nexthop is zero.
655 Status
= Ip4SetAddress (
657 EFI_NTOHL (Data
->StationAddress
),
658 EFI_NTOHL (Data
->SubnetMask
)
661 if (EFI_ERROR (Status
)) {
666 IpSb
->DefaultRouteTable
,
667 EFI_NTOHL (Data
->StationAddress
),
668 EFI_NTOHL (Data
->SubnetMask
),
673 // Add routes returned by EFI_IP4_CONFIG protocol.
675 for (Index
= 0; Index
< Data
->RouteTableSize
; Index
++) {
676 RouteEntry
= &Data
->RouteTable
[Index
];
679 IpSb
->DefaultRouteTable
,
680 EFI_NTOHL (RouteEntry
->SubnetAddress
),
681 EFI_NTOHL (RouteEntry
->SubnetMask
),
682 EFI_NTOHL (RouteEntry
->GatewayAddress
)
686 IpSb
->State
= IP4_SERVICE_CONFIGED
;
688 Ip4SetVariableData (IpSb
);
691 gBS
->FreePool (Data
);
695 Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK.
697 @param Event The event that is signalled.
698 @param Context The IP4 service binding instance.
705 Ip4AutoConfigCallBack (
712 IpSb
= (IP4_SERVICE
*) Context
;
713 IpSb
->ActiveEvent
= Event
;
716 // Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK
718 NetLibQueueDpc (TPL_CALLBACK
, Ip4AutoConfigCallBackDpc
, Context
);
723 Start the auto configuration for this IP service instance.
724 It will locates the EFI_IP4_CONFIG_PROTOCOL, then start the
727 @param IpSb The IP4 service instance to configure
729 @retval EFI_SUCCESS The auto configuration is successfull started
730 @retval Others Failed to start auto configuration.
738 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
741 if (IpSb
->State
> IP4_SERVICE_UNSTARTED
) {
746 // Create the DoneEvent and ReconfigEvent to call EFI_IP4_CONFIG
748 Status
= gBS
->CreateEvent (
751 Ip4AutoConfigCallBack
,
756 if (EFI_ERROR (Status
)) {
760 Status
= gBS
->CreateEvent (
763 Ip4AutoConfigCallBack
,
768 if (EFI_ERROR (Status
)) {
769 goto CLOSE_DONE_EVENT
;
773 // Open the EFI_IP4_CONFIG protocol then start auto configure
775 Status
= gBS
->OpenProtocol (
777 &gEfiIp4ConfigProtocolGuid
,
778 (VOID
**) &Ip4Config
,
781 EFI_OPEN_PROTOCOL_BY_DRIVER
| EFI_OPEN_PROTOCOL_EXCLUSIVE
784 if (EFI_ERROR (Status
)) {
785 Status
= EFI_UNSUPPORTED
;
786 goto CLOSE_RECONFIG_EVENT
;
789 Status
= Ip4Config
->Start (Ip4Config
, IpSb
->DoneEvent
, IpSb
->ReconfigEvent
);
791 if (EFI_ERROR (Status
)) {
794 &gEfiIp4ConfigProtocolGuid
,
799 goto CLOSE_RECONFIG_EVENT
;
802 IpSb
->Ip4Config
= Ip4Config
;
803 IpSb
->State
= IP4_SERVICE_STARTED
;
806 CLOSE_RECONFIG_EVENT
:
807 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
808 IpSb
->ReconfigEvent
= NULL
;
811 gBS
->CloseEvent (IpSb
->DoneEvent
);
812 IpSb
->DoneEvent
= NULL
;
819 Intiialize the IP4_PROTOCOL structure to the unconfigured states.
821 @param IpSb The IP4 service instance.
822 @param IpInstance The IP4 child instance.
829 IN IP4_SERVICE
*IpSb
,
830 IN OUT IP4_PROTOCOL
*IpInstance
833 ASSERT ((IpSb
!= NULL
) && (IpInstance
!= NULL
));
835 ZeroMem (IpInstance
, sizeof (IP4_PROTOCOL
));
837 IpInstance
->Signature
= IP4_PROTOCOL_SIGNATURE
;
838 CopyMem (&IpInstance
->Ip4Proto
, &mEfiIp4ProtocolTemplete
, sizeof (IpInstance
->Ip4Proto
));
839 IpInstance
->State
= IP4_STATE_UNCONFIGED
;
840 IpInstance
->Service
= IpSb
;
842 InitializeListHead (&IpInstance
->Link
);
843 NetMapInit (&IpInstance
->RxTokens
);
844 NetMapInit (&IpInstance
->TxTokens
);
845 InitializeListHead (&IpInstance
->Received
);
846 InitializeListHead (&IpInstance
->Delivered
);
847 InitializeListHead (&IpInstance
->AddrLink
);
849 EfiInitializeLock (&IpInstance
->RecycleLock
, TPL_NOTIFY
);
854 Configure the IP4 child. If the child is already configured,
855 change the configuration parameter. Otherwise configure it
856 for the first time. The caller should validate the configuration
857 before deliver them to it. It also don't do configure NULL.
859 @param IpInstance The IP4 child to configure.
860 @param Config The configure data.
862 @retval EFI_SUCCESS The IP4 child is successfully configured.
863 @retval EFI_DEVICE_ERROR Failed to free the pending transive or to
864 configure underlying MNP or other errors.
865 @retval EFI_NO_MAPPING The IP4 child is configured to use default
866 address, but the default address hasn't been
867 configured. The IP4 child doesn't need to be
868 reconfigured when default address is configured.
869 @retval EFI_OUT_OF_RESOURCES No more memory space is available.
870 @retval other Other error occurs.
875 IN OUT IP4_PROTOCOL
*IpInstance
,
876 IN EFI_IP4_CONFIG_DATA
*Config
885 IpSb
= IpInstance
->Service
;
888 // User is changing packet filters. It must be stopped
889 // before the station address can be changed.
891 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
893 // Cancel all the pending transmit/receive from upper layer
895 Status
= Ip4Cancel (IpInstance
, NULL
);
897 if (EFI_ERROR (Status
)) {
898 return EFI_DEVICE_ERROR
;
901 CopyMem (&IpInstance
->ConfigData
, Config
, sizeof (IpInstance
->ConfigData
));
906 // Configure a fresh IP4 protocol instance. Create a route table.
907 // Each IP child has its own route table, which may point to the
908 // default table if it is using default address.
910 Status
= EFI_OUT_OF_RESOURCES
;
911 IpInstance
->RouteTable
= Ip4CreateRouteTable ();
913 if (IpInstance
->RouteTable
== NULL
) {
918 // Set up the interface.
920 CopyMem (&Ip
, &Config
->StationAddress
, sizeof (IP4_ADDR
));
921 CopyMem (&Netmask
, &Config
->SubnetMask
, sizeof (IP4_ADDR
));
924 Netmask
= NTOHL (Netmask
);
926 if (!Config
->UseDefaultAddress
) {
928 // Find whether there is already an interface with the same
929 // station address. All the instances with the same station
930 // address shares one interface.
932 IpIf
= Ip4FindStationAddress (IpSb
, Ip
, Netmask
);
938 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
944 Status
= Ip4SetAddress (IpIf
, Ip
, Netmask
);
946 if (EFI_ERROR (Status
)) {
947 Status
= EFI_DEVICE_ERROR
;
948 Ip4FreeInterface (IpIf
, IpInstance
);
952 InsertTailList (&IpSb
->Interfaces
, &IpIf
->Link
);
956 // Add a route to this connected network in the route table
958 Ip4AddRoute (IpInstance
->RouteTable
, Ip
, Netmask
, IP4_ALLZERO_ADDRESS
);
962 // Use the default address. If the default configuration hasn't
963 // been started, start it.
965 if (IpSb
->State
== IP4_SERVICE_UNSTARTED
) {
966 Status
= Ip4StartAutoConfig (IpSb
);
968 if (EFI_ERROR (Status
)) {
973 IpIf
= IpSb
->DefaultInterface
;
974 NET_GET_REF (IpSb
->DefaultInterface
);
977 // If default address is used, so is the default route table.
978 // Any route set by the instance has the precedence over the
979 // routes in the default route table. Link the default table
980 // after the instance's table. Routing will search the local
983 NET_GET_REF (IpSb
->DefaultRouteTable
);
984 IpInstance
->RouteTable
->Next
= IpSb
->DefaultRouteTable
;
987 IpInstance
->Interface
= IpIf
;
988 InsertTailList (&IpIf
->IpInstances
, &IpInstance
->AddrLink
);
990 CopyMem (&IpInstance
->ConfigData
, Config
, sizeof (IpInstance
->ConfigData
));
991 IpInstance
->State
= IP4_STATE_CONFIGED
;
994 // Although EFI_NO_MAPPING is an error code, the IP child has been
995 // successfully configured and doesn't need reconfiguration when
996 // default address is acquired.
998 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
999 return EFI_NO_MAPPING
;
1005 Ip4FreeRouteTable (IpInstance
->RouteTable
);
1006 IpInstance
->RouteTable
= NULL
;
1012 Clean up the IP4 child, release all the resources used by it.
1014 @param IpInstance The IP4 child to clean up.
1016 @retval EFI_SUCCESS The IP4 child is cleaned up
1017 @retval EFI_DEVICE_ERROR Some resources failed to be released
1022 IN IP4_PROTOCOL
*IpInstance
1025 if (EFI_ERROR (Ip4Cancel (IpInstance
, NULL
))) {
1026 return EFI_DEVICE_ERROR
;
1029 if (EFI_ERROR (Ip4Groups (IpInstance
, FALSE
, NULL
))) {
1030 return EFI_DEVICE_ERROR
;
1034 // Some packets haven't been recycled. It is because either the
1035 // user forgets to recycle the packets, or because the callback
1036 // hasn't been called. Just leave it alone.
1038 if (!IsListEmpty (&IpInstance
->Delivered
)) {
1042 if (IpInstance
->Interface
!= NULL
) {
1043 RemoveEntryList (&IpInstance
->AddrLink
);
1044 Ip4FreeInterface (IpInstance
->Interface
, IpInstance
);
1045 IpInstance
->Interface
= NULL
;
1048 if (IpInstance
->RouteTable
!= NULL
) {
1049 if (IpInstance
->RouteTable
->Next
!= NULL
) {
1050 Ip4FreeRouteTable (IpInstance
->RouteTable
->Next
);
1053 Ip4FreeRouteTable (IpInstance
->RouteTable
);
1054 IpInstance
->RouteTable
= NULL
;
1057 if (IpInstance
->EfiRouteTable
!= NULL
) {
1058 gBS
->FreePool (IpInstance
->EfiRouteTable
);
1059 IpInstance
->EfiRouteTable
= NULL
;
1060 IpInstance
->EfiRouteCount
= 0;
1063 if (IpInstance
->Groups
!= NULL
) {
1064 gBS
->FreePool (IpInstance
->Groups
);
1065 IpInstance
->Groups
= NULL
;
1066 IpInstance
->GroupCount
= 0;
1069 NetMapClean (&IpInstance
->TxTokens
);
1071 NetMapClean (&IpInstance
->RxTokens
);
1078 Validate that Ip/Netmask pair is OK to be used as station
1079 address. Only continuous netmasks are supported. and check
1080 that StationAddress is a unicast address on the newtwork.
1082 @param Ip The IP address to validate
1083 @param Netmask The netmaks of the IP
1085 @retval TRUE The Ip/Netmask pair is valid
1086 @retval FALSE The Ip/Netmask pair is invalid
1090 Ip4StationAddressValid (
1095 IP4_ADDR NetBrdcastMask
;
1100 // Only support the station address with 0.0.0.0/0 to enable DHCP client.
1102 if (Netmask
== IP4_ALLZERO_ADDRESS
) {
1103 return (BOOLEAN
) (Ip
== IP4_ALLZERO_ADDRESS
);
1107 // Only support the continuous net masks
1109 if ((Len
= NetGetMaskLength (Netmask
)) == IP4_MASK_NUM
) {
1114 // Station address can't be class D or class E address
1116 if ((Type
= NetGetIpClass (Ip
)) > IP4_ADDR_CLASSC
) {
1121 // Station address can't be subnet broadcast/net broadcast address
1123 if ((Ip
== (Ip
& Netmask
)) || (Ip
== (Ip
| ~Netmask
))) {
1127 NetBrdcastMask
= gIp4AllMasks
[MIN (Len
, Type
<< 3)];
1129 if (Ip
== (Ip
| ~NetBrdcastMask
)) {
1138 Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
1140 The Configure() function is used to set, change, or reset the operational
1141 parameters and filter settings for this EFI IPv4 Protocol instance. Until these
1142 parameters have been set, no network traffic can be sent or received by this
1143 instance. Once the parameters have been reset (by calling this function with
1144 IpConfigData set to NULL), no more traffic can be sent or received until these
1145 parameters have been set again. Each EFI IPv4 Protocol instance can be started
1146 and stopped independently of each other by enabling or disabling their receive
1147 filter settings with the Configure() function.
1149 When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will
1150 be appended as an alias address into the addresses list in the EFI IPv4 Protocol
1151 driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL
1152 to retrieve the default IPv4 address if it is not available yet. Clients could
1153 frequently call GetModeData() to check the status to ensure that the default IPv4
1156 If operational parameters are reset or changed, any pending transmit and receive
1157 requests will be cancelled. Their completion token status will be set to EFI_ABORTED
1158 and their events will be signaled.
1160 @param This Pointer to the EFI_IP4_PROTOCOL instance.
1161 @param IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.
1163 @retval EFI_SUCCESS The driver instance was successfully opened.
1164 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1165 RARP, etc.) is not finished yet.
1166 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1167 @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:
1168 A configuration protocol (DHCP, BOOTP, RARP, etc.) could
1169 not be located when clients choose to use the default IPv4
1170 address. This EFI IPv4 Protocol implementation does not
1171 support this requested filter or timeout setting.
1172 @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.
1173 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the
1174 IPv4 address or subnet mask can be changed. The interface must
1175 also be stopped when switching to/from raw packet mode.
1176 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4
1177 Protocol driver instance is not opened.
1183 IN EFI_IP4_PROTOCOL
*This
,
1184 IN EFI_IP4_CONFIG_DATA
*IpConfigData OPTIONAL
1187 IP4_PROTOCOL
*IpInstance
;
1188 EFI_IP4_CONFIG_DATA
*Current
;
1193 IP4_ADDR SubnetMask
;
1196 // First, validate the parameters
1199 return EFI_INVALID_PARAMETER
;
1202 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1203 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1206 // Validate the configuration first.
1208 if (IpConfigData
!= NULL
) {
1210 // This implementation doesn't support RawData
1212 if (IpConfigData
->RawData
) {
1213 Status
= EFI_UNSUPPORTED
;
1218 CopyMem (&IpAddress
, &IpConfigData
->StationAddress
, sizeof (IP4_ADDR
));
1219 CopyMem (&SubnetMask
, &IpConfigData
->SubnetMask
, sizeof (IP4_ADDR
));
1221 IpAddress
= NTOHL (IpAddress
);
1222 SubnetMask
= NTOHL (SubnetMask
);
1225 // Check whether the station address is a valid unicast address
1227 if (!IpConfigData
->UseDefaultAddress
) {
1228 AddrOk
= Ip4StationAddressValid (IpAddress
, SubnetMask
);
1231 Status
= EFI_INVALID_PARAMETER
;
1237 // User can only update packet filters when already configured.
1238 // If it wants to change the station address, it must configure(NULL)
1239 // the instance first.
1241 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
1242 Current
= &IpInstance
->ConfigData
;
1244 if (Current
->UseDefaultAddress
!= IpConfigData
->UseDefaultAddress
) {
1245 Status
= EFI_ALREADY_STARTED
;
1249 if (!Current
->UseDefaultAddress
&&
1250 (!EFI_IP4_EQUAL (&Current
->StationAddress
, &IpConfigData
->StationAddress
) ||
1251 !EFI_IP4_EQUAL (&Current
->SubnetMask
, &IpConfigData
->SubnetMask
))) {
1252 Status
= EFI_ALREADY_STARTED
;
1256 if (Current
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1257 return EFI_NO_MAPPING
;
1263 // Configure the instance or clean it up.
1265 if (IpConfigData
!= NULL
) {
1266 Status
= Ip4ConfigProtocol (IpInstance
, IpConfigData
);
1268 Status
= Ip4CleanProtocol (IpInstance
);
1271 // Don't change the state if it is DESTORY, consider the following
1272 // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,
1273 // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,
1274 // the unload fails miserably.
1276 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
1277 IpInstance
->State
= IP4_STATE_UNCONFIGED
;
1282 // Update the MNP's configure data. Ip4ServiceConfigMnp will check
1283 // whether it is necessary to reconfigure the MNP.
1285 Ip4ServiceConfigMnp (IpInstance
->Service
, FALSE
);
1288 // Update the variable data.
1290 Ip4SetVariableData (IpInstance
->Service
);
1293 gBS
->RestoreTPL (OldTpl
);
1300 Change the IP4 child's multicast setting. The caller
1301 should make sure that the parameters is valid.
1303 @param IpInstance The IP4 child to change the setting.
1304 @param JoinFlag TRUE to join the group, otherwise leave it
1305 @param GroupAddress The target group address
1307 @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it
1308 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
1309 @retval EFI_DEVICE_ERROR Failed to set the group configuraton
1310 @retval EFI_SUCCESS Successfully updated the group setting.
1311 @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.
1316 IN IP4_PROTOCOL
*IpInstance
,
1317 IN BOOLEAN JoinFlag
,
1318 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
1326 // Add it to the instance's Groups, and join the group by IGMP.
1327 // IpInstance->Groups is in network byte order. IGMP operates in
1331 CopyMem (&Group
, GroupAddress
, sizeof (IP4_ADDR
));
1333 for (Index
= 0; Index
< IpInstance
->GroupCount
; Index
++) {
1334 if (IpInstance
->Groups
[Index
] == Group
) {
1335 return EFI_ALREADY_STARTED
;
1339 Members
= Ip4CombineGroups (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1341 if (Members
== NULL
) {
1342 return EFI_OUT_OF_RESOURCES
;
1345 if (EFI_ERROR (Ip4JoinGroup (IpInstance
, NTOHL (Group
)))) {
1346 gBS
->FreePool (Members
);
1347 return EFI_DEVICE_ERROR
;
1350 if (IpInstance
->Groups
!= NULL
) {
1351 gBS
->FreePool (IpInstance
->Groups
);
1354 IpInstance
->Groups
= Members
;
1355 IpInstance
->GroupCount
++;
1361 // Leave the group. Leave all the groups if GroupAddress is NULL.
1362 // Must iterate from the end to the beginning because the GroupCount
1363 // is decreamented each time an address is removed..
1365 for (Index
= IpInstance
->GroupCount
; Index
> 0 ; Index
--) {
1366 Group
= IpInstance
->Groups
[Index
- 1];
1368 if ((GroupAddress
== NULL
) || EFI_IP4_EQUAL (&Group
, GroupAddress
)) {
1369 if (EFI_ERROR (Ip4LeaveGroup (IpInstance
, NTOHL (Group
)))) {
1370 return EFI_DEVICE_ERROR
;
1373 Ip4RemoveGroupAddr (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1374 IpInstance
->GroupCount
--;
1376 if (IpInstance
->GroupCount
== 0) {
1377 ASSERT (Index
== 1);
1379 gBS
->FreePool (IpInstance
->Groups
);
1380 IpInstance
->Groups
= NULL
;
1383 if (GroupAddress
!= NULL
) {
1389 return ((GroupAddress
!= NULL
) ? EFI_NOT_FOUND
: EFI_SUCCESS
);
1394 Joins and leaves multicast groups.
1396 The Groups() function is used to join and leave multicast group sessions. Joining
1397 a group will enable reception of matching multicast packets. Leaving a group will
1398 disable the multicast packet reception.
1400 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
1402 @param This Pointer to the EFI_IP4_PROTOCOL instance.
1403 @param JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.
1404 @param GroupAddress Pointer to the IPv4 multicast address.
1406 @retval EFI_SUCCESS The operation completed successfully.
1407 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
1409 - JoinFlag is TRUE and GroupAddress is NULL.
1410 - GroupAddress is not NULL and *GroupAddress is
1411 not a multicast IPv4 address.
1412 @retval EFI_NOT_STARTED This instance has not been started.
1413 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1414 RARP, etc.) is not finished yet.
1415 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
1416 @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.
1417 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
1419 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
1420 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1426 IN EFI_IP4_PROTOCOL
*This
,
1427 IN BOOLEAN JoinFlag
,
1428 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
1431 IP4_PROTOCOL
*IpInstance
;
1436 if ((This
== NULL
) || (JoinFlag
&& (GroupAddress
== NULL
))) {
1437 return EFI_INVALID_PARAMETER
;
1440 if (GroupAddress
!= NULL
) {
1441 CopyMem (&McastIp
, GroupAddress
, sizeof (IP4_ADDR
));
1443 if (!IP4_IS_MULTICAST (NTOHL (McastIp
))) {
1444 return EFI_INVALID_PARAMETER
;
1448 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1449 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1451 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1452 Status
= EFI_NOT_STARTED
;
1456 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1457 Status
= EFI_NO_MAPPING
;
1461 Status
= Ip4Groups (IpInstance
, JoinFlag
, GroupAddress
);
1464 gBS
->RestoreTPL (OldTpl
);
1470 Adds and deletes routing table entries.
1472 The Routes() function adds a route to or deletes a route from the routing table.
1474 Routes are determined by comparing the SubnetAddress with the destination IPv4
1475 address arithmetically AND-ed with the SubnetMask. The gateway address must be
1476 on the same subnet as the configured station address.
1478 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
1479 The default route matches all destination IPv4 addresses that do not match any
1482 A GatewayAddress that is zero is a nonroute. Packets are sent to the destination
1483 IP address if it can be found in the ARP cache or on the local subnet. One automatic
1484 nonroute entry will be inserted into the routing table for outgoing packets that
1485 are addressed to a local subnet (gateway address of 0.0.0.0).
1487 Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI
1488 IPv4 Protocol instances that use the default IPv4 address will also have copies
1489 of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these
1490 copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its
1491 instances. As a result, client modification to the routing table will be lost.
1493 @param This Pointer to the EFI_IP4_PROTOCOL instance.
1494 @param DeleteRoute Set to TRUE to delete this route from the routing table. Set to
1495 FALSE to add this route to the routing table. SubnetAddress
1496 and SubnetMask are used as the key to each route entry.
1497 @param SubnetAddress The address of the subnet that needs to be routed.
1498 @param SubnetMask The subnet mask of SubnetAddress.
1499 @param GatewayAddress The unicast gateway IPv4 address for this route.
1501 @retval EFI_SUCCESS The operation completed successfully.
1502 @retval EFI_NOT_STARTED The driver instance has not been started.
1503 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1504 RARP, etc.) is not finished yet.
1505 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1507 - SubnetAddress is NULL.
1508 - SubnetMask is NULL.
1509 - GatewayAddress is NULL.
1510 - *SubnetAddress is not a valid subnet address.
1511 - *SubnetMask is not a valid subnet mask.
1512 - *GatewayAddress is not a valid unicast IPv4 address.
1513 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
1514 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
1515 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
1516 DeleteRoute is FALSE).
1522 IN EFI_IP4_PROTOCOL
*This
,
1523 IN BOOLEAN DeleteRoute
,
1524 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
1525 IN EFI_IPv4_ADDRESS
*SubnetMask
,
1526 IN EFI_IPv4_ADDRESS
*GatewayAddress
1529 IP4_PROTOCOL
*IpInstance
;
1530 IP4_INTERFACE
*IpIf
;
1538 // First, validate the parameters
1540 if ((This
== NULL
) || (SubnetAddress
== NULL
) ||
1541 (SubnetMask
== NULL
) || (GatewayAddress
== NULL
)) {
1542 return EFI_INVALID_PARAMETER
;
1545 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1546 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1548 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1549 Status
= EFI_NOT_STARTED
;
1553 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1554 Status
= EFI_NO_MAPPING
;
1558 CopyMem (&Dest
, SubnetAddress
, sizeof (IP4_ADDR
));
1559 CopyMem (&Netmask
, SubnetMask
, sizeof (IP4_ADDR
));
1560 CopyMem (&Nexthop
, GatewayAddress
, sizeof (IP4_ADDR
));
1562 Dest
= NTOHL (Dest
);
1563 Netmask
= NTOHL (Netmask
);
1564 Nexthop
= NTOHL (Nexthop
);
1566 IpIf
= IpInstance
->Interface
;
1568 if (!IP4_IS_VALID_NETMASK (Netmask
)) {
1569 Status
= EFI_INVALID_PARAMETER
;
1574 // the gateway address must be a unicast on the connected network if not zero.
1576 if ((Nexthop
!= IP4_ALLZERO_ADDRESS
) &&
1577 (!IP4_NET_EQUAL (Nexthop
, IpIf
->Ip
, IpIf
->SubnetMask
) ||
1578 IP4_IS_BROADCAST (Ip4GetNetCast (Nexthop
, IpIf
)))) {
1580 Status
= EFI_INVALID_PARAMETER
;
1585 Status
= Ip4DelRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1587 Status
= Ip4AddRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1591 gBS
->RestoreTPL (OldTpl
);
1597 Check whether the user's token or event has already
1598 been enqueued on IP4's list.
1600 @param Map The container of either user's transmit or receive
1602 @param Item Current item to check against
1603 @param Context The Token to check againist.
1605 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
1606 @retval EFI_SUCCESS The current item isn't the same token/event as the
1613 IN NET_MAP_ITEM
*Item
,
1617 EFI_IP4_COMPLETION_TOKEN
*Token
;
1618 EFI_IP4_COMPLETION_TOKEN
*TokenInItem
;
1620 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
1621 TokenInItem
= (EFI_IP4_COMPLETION_TOKEN
*) Item
->Key
;
1623 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
1624 return EFI_ACCESS_DENIED
;
1632 Validate the user's token against current station address.
1634 @param Token User's token to validate
1635 @param IpIf The IP4 child's interface.
1637 @retval EFI_INVALID_PARAMETER Some parameters are invalid
1638 @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.
1639 @retval EFI_SUCCESS The token is OK
1644 IN EFI_IP4_COMPLETION_TOKEN
*Token
,
1645 IN IP4_INTERFACE
*IpIf
1648 EFI_IP4_TRANSMIT_DATA
*TxData
;
1649 EFI_IP4_OVERRIDE_DATA
*Override
;
1656 if ((Token
== NULL
) || (Token
->Event
== NULL
) || (Token
->Packet
.TxData
== NULL
)) {
1657 return EFI_INVALID_PARAMETER
;
1660 TxData
= Token
->Packet
.TxData
;
1663 // Check the IP options: no more than 40 bytes and format is OK
1665 if (TxData
->OptionsLength
!= 0) {
1666 if ((TxData
->OptionsLength
> 40) || (TxData
->OptionsBuffer
== NULL
)) {
1667 return EFI_INVALID_PARAMETER
;
1670 if (!Ip4OptionIsValid (TxData
->OptionsBuffer
, TxData
->OptionsLength
, FALSE
)) {
1671 return EFI_INVALID_PARAMETER
;
1676 // Check the fragment table: no empty fragment, and length isn't bogus
1678 if ((TxData
->TotalDataLength
== 0) || (TxData
->FragmentCount
== 0)) {
1679 return EFI_INVALID_PARAMETER
;
1682 Offset
= TxData
->TotalDataLength
;
1684 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
1685 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
1686 (TxData
->FragmentTable
[Index
].FragmentLength
== 0)) {
1688 return EFI_INVALID_PARAMETER
;
1691 Offset
-= TxData
->FragmentTable
[Index
].FragmentLength
;
1695 return EFI_INVALID_PARAMETER
;
1699 // Check the source and gateway: they must be a valid unicast.
1700 // Gateway must also be on the connected network.
1702 if (TxData
->OverrideData
) {
1703 Override
= TxData
->OverrideData
;
1705 CopyMem (&Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1706 CopyMem (&Gateway
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1709 Gateway
= NTOHL (Gateway
);
1711 if ((NetGetIpClass (Src
) > IP4_ADDR_CLASSC
) ||
1712 (Src
== IP4_ALLONE_ADDRESS
) ||
1713 IP4_IS_BROADCAST (Ip4GetNetCast (Src
, IpIf
))) {
1715 return EFI_INVALID_PARAMETER
;
1719 // If gateway isn't zero, it must be a unicast address, and
1720 // on the connected network.
1722 if ((Gateway
!= IP4_ALLZERO_ADDRESS
) &&
1723 ((NetGetIpClass (Gateway
) > IP4_ADDR_CLASSC
) ||
1724 !IP4_NET_EQUAL (Gateway
, IpIf
->Ip
, IpIf
->SubnetMask
) ||
1725 IP4_IS_BROADCAST (Ip4GetNetCast (Gateway
, IpIf
)))) {
1727 return EFI_INVALID_PARAMETER
;
1732 // Check the packet length: Head length and packet length all has a limit
1734 HeadLen
= sizeof (IP4_HEAD
) + ((TxData
->OptionsLength
+ 3) &~0x03);
1736 if ((HeadLen
> IP4_MAX_HEADLEN
) ||
1737 (TxData
->TotalDataLength
+ HeadLen
> IP4_MAX_PACKET_SIZE
)) {
1739 return EFI_BAD_BUFFER_SIZE
;
1747 The callback function for the net buffer which wraps the user's
1748 transmit token. Although it seems this function is pretty simple,
1749 there are some subtle things.
1750 When user requests the IP to transmit a packet by passing it a
1751 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data
1752 is wrapped in an net buffer. the net buffer's Free function is
1753 set to Ip4FreeTxToken. The Token and token wrap are added to the
1754 IP child's TxToken map. Then the buffer is passed to Ip4Output for
1755 transmission. If something error happened before that, the buffer
1756 is freed, which in turn will free the token wrap. The wrap may
1757 have been added to the TxToken map or not, and the user's event
1758 shouldn't be fired because we are still in the EfiIp4Transmit. If
1759 the buffer has been sent by Ip4Output, it should be removed from
1760 the TxToken map and user's event signaled. The token wrap and buffer
1761 are bound together. Check the comments in Ip4Output for information
1762 about IP fragmentation.
1764 @param Context The token's wrap
1774 IP4_TXTOKEN_WRAP
*Wrap
;
1777 Wrap
= (IP4_TXTOKEN_WRAP
*) Context
;
1780 // Find the token in the instance's map. EfiIp4Transmit put the
1781 // token to the map. If that failed, NetMapFindKey will return NULL.
1783 Item
= NetMapFindKey (&Wrap
->IpInstance
->TxTokens
, Wrap
->Token
);
1786 NetMapRemoveItem (&Wrap
->IpInstance
->TxTokens
, Item
, NULL
);
1790 gBS
->SignalEvent (Wrap
->Token
->Event
);
1793 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
1795 NetLibDispatchDpc ();
1798 gBS
->FreePool (Wrap
);
1803 The callback function to Ip4Output to update the transmit status.
1805 @param Ip4Instance The Ip4Instance that request the transmit.
1806 @param Packet The user's transmit request
1807 @param IoStatus The result of the transmission
1808 @param Flag Not used during transmission
1809 @param Context The token's wrap.
1816 IP4_PROTOCOL
*Ip4Instance
,
1818 EFI_STATUS IoStatus
,
1823 IP4_TXTOKEN_WRAP
*Wrap
;
1826 // This is the transmission request from upper layer,
1827 // not the IP4 driver itself.
1829 ASSERT (Ip4Instance
!= NULL
);
1832 // The first fragment of the packet has been sent. Update
1833 // the token's status. That is, if fragmented, the transmit's
1834 // status is the first fragment's status. The Wrap will be
1835 // release when all the fragments are release. Check the comments
1836 // in Ip4FreeTxToken and Ip4Output for information.
1838 Wrap
= (IP4_TXTOKEN_WRAP
*) Context
;
1839 Wrap
->Token
->Status
= IoStatus
;
1841 NetbufFree (Wrap
->Packet
);
1846 Places outgoing data packets into the transmit queue.
1848 The Transmit() function places a sending request in the transmit queue of this
1849 EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some
1850 errors occur, the event in the token will be signaled and the status is updated.
1852 @param This Pointer to the EFI_IP4_PROTOCOL instance.
1853 @param Token Pointer to the transmit token.
1855 @retval EFI_SUCCESS The data has been queued for transmission.
1856 @retval EFI_NOT_STARTED This instance has not been started.
1857 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1858 RARP, etc.) is not finished yet.
1859 @retval EFI_INVALID_PARAMETER One or more pameters are invalid.
1860 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event
1861 was already in the transmit queue.
1862 @retval EFI_NOT_READY The completion token could not be queued because the transmit
1864 @retval EFI_NOT_FOUND Not route is found to destination address.
1865 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
1866 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
1868 @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is
1869 greater than MTU (or greater than the maximum packet size if
1870 Token.Packet.TxData.OverrideData.
1871 DoNotFragment is TRUE.)
1877 IN EFI_IP4_PROTOCOL
*This
,
1878 IN EFI_IP4_COMPLETION_TOKEN
*Token
1882 IP4_PROTOCOL
*IpInstance
;
1883 IP4_INTERFACE
*IpIf
;
1884 IP4_TXTOKEN_WRAP
*Wrap
;
1885 EFI_IP4_TRANSMIT_DATA
*TxData
;
1886 EFI_IP4_CONFIG_DATA
*Config
;
1887 EFI_IP4_OVERRIDE_DATA
*Override
;
1892 BOOLEAN DontFragment
;
1896 return EFI_INVALID_PARAMETER
;
1899 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1901 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1902 return EFI_NOT_STARTED
;
1905 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1907 IpSb
= IpInstance
->Service
;
1908 IpIf
= IpInstance
->Interface
;
1909 Config
= &IpInstance
->ConfigData
;
1911 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1912 Status
= EFI_NO_MAPPING
;
1917 // make sure that token is properly formated
1919 Status
= Ip4TxTokenValid (Token
, IpIf
);
1921 if (EFI_ERROR (Status
)) {
1926 // Check whether the token or signal already existed.
1928 if (EFI_ERROR (NetMapIterate (&IpInstance
->TxTokens
, Ip4TokenExist
, Token
))) {
1929 Status
= EFI_ACCESS_DENIED
;
1934 // Build the IP header, need to fill in the Tos, TotalLen, Id,
1935 // fragment, Ttl, protocol, Src, and Dst.
1937 TxData
= Token
->Packet
.TxData
;
1939 CopyMem (&Head
.Dst
, &TxData
->DestinationAddress
, sizeof (IP4_ADDR
));
1940 Head
.Dst
= NTOHL (Head
.Dst
);
1942 if (TxData
->OverrideData
) {
1943 Override
= TxData
->OverrideData
;
1944 Head
.Protocol
= Override
->Protocol
;
1945 Head
.Tos
= Override
->TypeOfService
;
1946 Head
.Ttl
= Override
->TimeToLive
;
1947 DontFragment
= Override
->DoNotFragment
;
1949 CopyMem (&Head
.Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1950 CopyMem (&GateWay
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1952 Head
.Src
= NTOHL (Head
.Src
);
1953 GateWay
= NTOHL (GateWay
);
1955 Head
.Src
= IpIf
->Ip
;
1956 GateWay
= IP4_ALLZERO_ADDRESS
;
1957 Head
.Protocol
= Config
->DefaultProtocol
;
1958 Head
.Tos
= Config
->TypeOfService
;
1959 Head
.Ttl
= Config
->TimeToLive
;
1960 DontFragment
= Config
->DoNotFragment
;
1963 Head
.Fragment
= IP4_HEAD_FRAGMENT_FIELD (DontFragment
, FALSE
, 0);
1964 HeadLen
= sizeof (IP4_HEAD
) + ((TxData
->OptionsLength
+ 3) &~0x03);
1967 // If don't fragment and fragment needed, return error
1969 if (DontFragment
&& (TxData
->TotalDataLength
+ HeadLen
> IpSb
->SnpMode
.MaxPacketSize
)) {
1970 Status
= EFI_BAD_BUFFER_SIZE
;
1975 // OK, it survives all the validation check. Wrap the token in
1976 // a IP4_TXTOKEN_WRAP and the data in a netbuf
1978 Status
= EFI_OUT_OF_RESOURCES
;
1979 Wrap
= AllocatePool (sizeof (IP4_TXTOKEN_WRAP
));
1984 Wrap
->IpInstance
= IpInstance
;
1985 Wrap
->Token
= Token
;
1987 Wrap
->Life
= IP4_US_TO_SEC (Config
->TransmitTimeout
);
1988 Wrap
->Packet
= NetbufFromExt (
1989 (NET_FRAGMENT
*) TxData
->FragmentTable
,
1990 TxData
->FragmentCount
,
1997 if (Wrap
->Packet
== NULL
) {
1998 gBS
->FreePool (Wrap
);
2002 Token
->Status
= EFI_NOT_READY
;
2004 if (EFI_ERROR (NetMapInsertTail (&IpInstance
->TxTokens
, Token
, Wrap
))) {
2006 // NetbufFree will call Ip4FreeTxToken, which in turn will
2007 // free the IP4_TXTOKEN_WRAP. Now, the token wrap hasn't been
2010 NetbufFree (Wrap
->Packet
);
2015 // Mark the packet sent before output it. Mark it not sent again if the
2016 // returned status is not EFI_SUCCESS;
2020 Status
= Ip4Output (
2025 TxData
->OptionsBuffer
,
2026 TxData
->OptionsLength
,
2032 if (EFI_ERROR (Status
)) {
2034 NetbufFree (Wrap
->Packet
);
2038 gBS
->RestoreTPL (OldTpl
);
2044 Places a receiving request into the receiving queue.
2046 The Receive() function places a completion token into the receive packet queue.
2047 This function is always asynchronous.
2049 The Token.Event field in the completion token must be filled in by the caller
2050 and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol
2051 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
2054 @param This Pointer to the EFI_IP4_PROTOCOL instance.
2055 @param Token Pointer to a token that is associated with the receive data descriptor.
2057 @retval EFI_SUCCESS The receive completion token was cached.
2058 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2059 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)
2060 is not finished yet.
2061 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2064 - Token.Event is NULL.
2065 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
2066 resources (usually memory).
2067 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2068 The EFI IPv4 Protocol instance has been reset to startup defaults.
2069 EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
2070 in the receive queue.
2071 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
2072 @retval EFI_ICMP_ERROR An ICMP error packet was received.
2078 IN EFI_IP4_PROTOCOL
*This
,
2079 IN EFI_IP4_COMPLETION_TOKEN
*Token
2082 IP4_PROTOCOL
*IpInstance
;
2087 // First validate the parameters
2089 if ((This
== NULL
) || (Token
== NULL
) || (Token
->Event
== NULL
)) {
2090 return EFI_INVALID_PARAMETER
;
2093 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2095 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2097 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
2098 Status
= EFI_NOT_STARTED
;
2103 // Check whether the toke is already on the receive queue.
2105 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4TokenExist
, Token
);
2107 if (EFI_ERROR (Status
)) {
2108 Status
= EFI_ACCESS_DENIED
;
2113 // Queue the token then check whether there is pending received packet.
2115 Status
= NetMapInsertTail (&IpInstance
->RxTokens
, Token
, NULL
);
2117 if (EFI_ERROR (Status
)) {
2121 Status
= Ip4InstanceDeliverPacket (IpInstance
);
2124 // Dispatch the DPC queued by the NotifyFunction of this instane's receive
2127 NetLibDispatchDpc ();
2130 gBS
->RestoreTPL (OldTpl
);
2136 Cancel the transmitted but not recycled packet. If a matching
2137 token is found, it will call Ip4CancelPacket to cancel the
2138 packet. Ip4CancelPacket will cancel all the fragments of the
2139 packet. When all the fragments are freed, the IP4_TXTOKEN_WRAP
2140 will be deleted from the Map, and user's event signalled.
2141 Because Ip4CancelPacket and other functions are all called in
2142 line, so, after Ip4CancelPacket returns, the Item has been freed.
2144 @param Map The IP4 child's transmit queue
2145 @param Item The current transmitted packet to test.
2146 @param Context The user's token to cancel.
2148 @retval EFI_SUCCESS Continue to check the next Item.
2149 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
2155 IN NET_MAP_ITEM
*Item
,
2159 EFI_IP4_COMPLETION_TOKEN
*Token
;
2160 IP4_TXTOKEN_WRAP
*Wrap
;
2162 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
2165 // Return EFI_SUCCESS to check the next item in the map if
2166 // this one doesn't match.
2168 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
2172 Wrap
= (IP4_TXTOKEN_WRAP
*) Item
->Value
;
2173 ASSERT (Wrap
!= NULL
);
2176 // Don't access the Item, Wrap and Token's members after this point.
2177 // Item and wrap has been freed. And we no longer own the Token.
2179 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
2182 // If only one item is to be cancel, return EFI_ABORTED to stop
2183 // iterating the map any more.
2185 if (Token
!= NULL
) {
2194 Cancel the receive request. This is quiet simple, because
2195 it is only enqueued in our local receive map.
2197 @param Map The IP4 child's receive queue
2198 @param Item Current receive request to cancel.
2199 @param Context The user's token to cancel
2201 @retval EFI_SUCCESS Continue to check the next receive request on the
2203 @retval EFI_ABORTED The user's token (token != NULL) has been
2210 IN NET_MAP_ITEM
*Item
,
2214 EFI_IP4_COMPLETION_TOKEN
*Token
;
2215 EFI_IP4_COMPLETION_TOKEN
*This
;
2217 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
2220 if ((Token
!= NULL
) && (Token
!= This
)) {
2224 NetMapRemoveItem (Map
, Item
, NULL
);
2226 This
->Status
= EFI_ABORTED
;
2227 This
->Packet
.RxData
= NULL
;
2228 gBS
->SignalEvent (This
->Event
);
2230 if (Token
!= NULL
) {
2239 Cancel the user's receive/transmit request.
2241 @param IpInstance The IP4 child
2242 @param Token The token to cancel. If NULL, all token will be
2245 @retval EFI_SUCCESS The token is cancelled
2246 @retval EFI_NOT_FOUND The token isn't found on either the
2247 transmit/receive queue
2248 @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.
2253 IN IP4_PROTOCOL
*IpInstance
,
2254 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2260 // First check the transmitted packet. Ip4CancelTxTokens returns
2261 // EFI_ABORTED to mean that the token has been cancelled when
2262 // token != NULL. So, return EFI_SUCCESS for this condition.
2264 Status
= NetMapIterate (&IpInstance
->TxTokens
, Ip4CancelTxTokens
, Token
);
2266 if (EFI_ERROR (Status
)) {
2267 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2275 // Check the receive queue. Ip4CancelRxTokens also returns EFI_ABORT
2276 // for Token!=NULL and it is cancelled.
2278 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4CancelRxTokens
, Token
);
2280 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
2283 NetLibDispatchDpc ();
2284 if (EFI_ERROR (Status
)) {
2285 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2293 // OK, if the Token is found when Token != NULL, the NetMapIterate
2294 // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.
2296 if (Token
!= NULL
) {
2297 return EFI_NOT_FOUND
;
2301 // If Token == NULL, cancel all the tokens. return error if no
2302 // all of them are cancelled.
2304 if (!NetMapIsEmpty (&IpInstance
->TxTokens
) ||
2305 !NetMapIsEmpty (&IpInstance
->RxTokens
)) {
2307 return EFI_DEVICE_ERROR
;
2315 Abort an asynchronous transmit or receive request.
2317 The Cancel() function is used to abort a pending transmit or receive request.
2318 If the token is in the transmit or receive request queues, after calling this
2319 function, Token->Status will be set to EFI_ABORTED and then Token->Event will
2320 be signaled. If the token is not in one of the queues, which usually means the
2321 asynchronous operation has completed, this function will not signal the token
2322 and EFI_NOT_FOUND is returned.
2324 @param This Pointer to the EFI_IP4_PROTOCOL instance.
2325 @param Token Pointer to a token that has been issued by
2326 EFI_IP4_PROTOCOL.Transmit() or
2327 EFI_IP4_PROTOCOL.Receive(). If NULL, all pending
2328 tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is
2329 defined in EFI_IP4_PROTOCOL.Transmit().
2331 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
2332 Token.->Event was signaled. When Token is NULL, all
2333 pending requests were aborted and their events were signaled.
2334 @retval EFI_INVALID_PARAMETER This is NULL.
2335 @retval EFI_NOT_STARTED This instance has not been started.
2336 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2337 RARP, etc.) is not finished yet.
2338 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
2339 not found in the transmit or receive queue. It has either completed
2340 or was not issued by Transmit() and Receive().
2346 IN EFI_IP4_PROTOCOL
*This
,
2347 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2350 IP4_PROTOCOL
*IpInstance
;
2355 return EFI_INVALID_PARAMETER
;
2358 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2360 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2362 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
2363 Status
= EFI_NOT_STARTED
;
2367 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
2368 Status
= EFI_NO_MAPPING
;
2372 Status
= Ip4Cancel (IpInstance
, Token
);
2375 gBS
->RestoreTPL (OldTpl
);
2381 Polls for incoming data packets and processes outgoing data packets.
2383 The Poll() function polls for incoming data packets and processes outgoing data
2384 packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()
2385 function to increase the rate that data packets are moved between the communications
2386 device and the transmit and receive queues.
2388 In some systems the periodic timer event may not poll the underlying communications
2389 device fast enough to transmit and/or receive all data packets without missing
2390 incoming packets or dropping outgoing packets. Drivers and applications that are
2391 experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function
2394 @param This Pointer to the EFI_IP4_PROTOCOL instance.
2396 @retval EFI_SUCCESS Incoming or outgoing data was processed.
2397 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2398 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2399 RARP, etc.) is not finished yet.
2400 @retval EFI_INVALID_PARAMETER This is NULL.
2401 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2402 @retval EFI_NOT_READY No incoming or outgoing data is processed.
2403 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
2404 Consider increasing the polling rate.
2410 IN EFI_IP4_PROTOCOL
*This
2413 IP4_PROTOCOL
*IpInstance
;
2414 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
2417 return EFI_INVALID_PARAMETER
;
2420 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2422 if (IpInstance
->State
== IP4_STATE_UNCONFIGED
) {
2423 return EFI_NOT_STARTED
;
2426 Mnp
= IpInstance
->Service
->Mnp
;
2429 // Don't lock the Poll function to enable the deliver of
2430 // the packet polled up.
2432 return Mnp
->Poll (Mnp
);
2436 Decrease the life of the transmitted packets. If it is
2437 decreased to zero, cancel the packet. This function is
2438 called by Ip4PacketTimerTicking which time out both the
2439 received-but-not-delivered and transmitted-but-not-recycle
2442 @param Map The IP4 child's transmit map.
2443 @param Item Current transmitted packet
2444 @param Context Not used.
2446 @retval EFI_SUCCESS Always returns EFI_SUCCESS
2450 Ip4SentPacketTicking (
2452 IN NET_MAP_ITEM
*Item
,
2456 IP4_TXTOKEN_WRAP
*Wrap
;
2458 Wrap
= (IP4_TXTOKEN_WRAP
*) Item
->Value
;
2459 ASSERT (Wrap
!= NULL
);
2461 if ((Wrap
->Life
> 0) && (--Wrap
->Life
== 0)) {
2462 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
2470 The heart beat timer of IP4 service instance. It times out
2471 all of its IP4 children's received-but-not-delivered and
2472 transmitted-but-not-recycle packets, and provides time input
2473 for its IGMP protocol.
2475 @param Event The IP4 service instance's heart beat timer.
2476 @param Context The IP4 service instance.
2490 IpSb
= (IP4_SERVICE
*) Context
;
2491 NET_CHECK_SIGNATURE (IpSb
, IP4_SERVICE_SIGNATURE
);
2493 Ip4PacketTimerTicking (IpSb
);
2494 Ip4IgmpTicking (IpSb
);