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
);
696 Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK.
698 @param Event The event that is signalled.
699 @param Context The IP4 service binding instance.
706 Ip4AutoConfigCallBack (
713 IpSb
= (IP4_SERVICE
*) Context
;
714 IpSb
->ActiveEvent
= Event
;
717 // Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK
719 NetLibQueueDpc (TPL_CALLBACK
, Ip4AutoConfigCallBackDpc
, Context
);
724 Start the auto configuration for this IP service instance.
725 It will locates the EFI_IP4_CONFIG_PROTOCOL, then start the
728 @param IpSb The IP4 service instance to configure
730 @retval EFI_SUCCESS The auto configuration is successfull started
731 @retval Others Failed to start auto configuration.
739 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
742 if (IpSb
->State
> IP4_SERVICE_UNSTARTED
) {
747 // Create the DoneEvent and ReconfigEvent to call EFI_IP4_CONFIG
749 Status
= gBS
->CreateEvent (
752 Ip4AutoConfigCallBack
,
757 if (EFI_ERROR (Status
)) {
761 Status
= gBS
->CreateEvent (
764 Ip4AutoConfigCallBack
,
769 if (EFI_ERROR (Status
)) {
770 goto CLOSE_DONE_EVENT
;
774 // Open the EFI_IP4_CONFIG protocol then start auto configure
776 Status
= gBS
->OpenProtocol (
778 &gEfiIp4ConfigProtocolGuid
,
779 (VOID
**) &Ip4Config
,
782 EFI_OPEN_PROTOCOL_BY_DRIVER
| EFI_OPEN_PROTOCOL_EXCLUSIVE
785 if (EFI_ERROR (Status
)) {
786 Status
= EFI_UNSUPPORTED
;
787 goto CLOSE_RECONFIG_EVENT
;
790 Status
= Ip4Config
->Start (Ip4Config
, IpSb
->DoneEvent
, IpSb
->ReconfigEvent
);
792 if (EFI_ERROR (Status
)) {
795 &gEfiIp4ConfigProtocolGuid
,
800 goto CLOSE_RECONFIG_EVENT
;
803 IpSb
->Ip4Config
= Ip4Config
;
804 IpSb
->State
= IP4_SERVICE_STARTED
;
807 CLOSE_RECONFIG_EVENT
:
808 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
809 IpSb
->ReconfigEvent
= NULL
;
812 gBS
->CloseEvent (IpSb
->DoneEvent
);
813 IpSb
->DoneEvent
= NULL
;
820 Intiialize the IP4_PROTOCOL structure to the unconfigured states.
822 @param IpSb The IP4 service instance.
823 @param IpInstance The IP4 child instance.
830 IN IP4_SERVICE
*IpSb
,
831 IN OUT IP4_PROTOCOL
*IpInstance
834 ASSERT ((IpSb
!= NULL
) && (IpInstance
!= NULL
));
836 ZeroMem (IpInstance
, sizeof (IP4_PROTOCOL
));
838 IpInstance
->Signature
= IP4_PROTOCOL_SIGNATURE
;
839 CopyMem (&IpInstance
->Ip4Proto
, &mEfiIp4ProtocolTemplete
, sizeof (IpInstance
->Ip4Proto
));
840 IpInstance
->State
= IP4_STATE_UNCONFIGED
;
841 IpInstance
->Service
= IpSb
;
843 InitializeListHead (&IpInstance
->Link
);
844 NetMapInit (&IpInstance
->RxTokens
);
845 NetMapInit (&IpInstance
->TxTokens
);
846 InitializeListHead (&IpInstance
->Received
);
847 InitializeListHead (&IpInstance
->Delivered
);
848 InitializeListHead (&IpInstance
->AddrLink
);
850 EfiInitializeLock (&IpInstance
->RecycleLock
, TPL_NOTIFY
);
855 Configure the IP4 child. If the child is already configured,
856 change the configuration parameter. Otherwise configure it
857 for the first time. The caller should validate the configuration
858 before deliver them to it. It also don't do configure NULL.
860 @param IpInstance The IP4 child to configure.
861 @param Config The configure data.
863 @retval EFI_SUCCESS The IP4 child is successfully configured.
864 @retval EFI_DEVICE_ERROR Failed to free the pending transive or to
865 configure underlying MNP or other errors.
866 @retval EFI_NO_MAPPING The IP4 child is configured to use default
867 address, but the default address hasn't been
868 configured. The IP4 child doesn't need to be
869 reconfigured when default address is configured.
870 @retval EFI_OUT_OF_RESOURCES No more memory space is available.
871 @retval other Other error occurs.
876 IN OUT IP4_PROTOCOL
*IpInstance
,
877 IN EFI_IP4_CONFIG_DATA
*Config
886 IpSb
= IpInstance
->Service
;
889 // User is changing packet filters. It must be stopped
890 // before the station address can be changed.
892 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
894 // Cancel all the pending transmit/receive from upper layer
896 Status
= Ip4Cancel (IpInstance
, NULL
);
898 if (EFI_ERROR (Status
)) {
899 return EFI_DEVICE_ERROR
;
902 CopyMem (&IpInstance
->ConfigData
, Config
, sizeof (IpInstance
->ConfigData
));
907 // Configure a fresh IP4 protocol instance. Create a route table.
908 // Each IP child has its own route table, which may point to the
909 // default table if it is using default address.
911 Status
= EFI_OUT_OF_RESOURCES
;
912 IpInstance
->RouteTable
= Ip4CreateRouteTable ();
914 if (IpInstance
->RouteTable
== NULL
) {
919 // Set up the interface.
921 CopyMem (&Ip
, &Config
->StationAddress
, sizeof (IP4_ADDR
));
922 CopyMem (&Netmask
, &Config
->SubnetMask
, sizeof (IP4_ADDR
));
925 Netmask
= NTOHL (Netmask
);
927 if (!Config
->UseDefaultAddress
) {
929 // Find whether there is already an interface with the same
930 // station address. All the instances with the same station
931 // address shares one interface.
933 IpIf
= Ip4FindStationAddress (IpSb
, Ip
, Netmask
);
939 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
945 Status
= Ip4SetAddress (IpIf
, Ip
, Netmask
);
947 if (EFI_ERROR (Status
)) {
948 Status
= EFI_DEVICE_ERROR
;
949 Ip4FreeInterface (IpIf
, IpInstance
);
953 InsertTailList (&IpSb
->Interfaces
, &IpIf
->Link
);
957 // Add a route to this connected network in the route table
959 Ip4AddRoute (IpInstance
->RouteTable
, Ip
, Netmask
, IP4_ALLZERO_ADDRESS
);
963 // Use the default address. If the default configuration hasn't
964 // been started, start it.
966 if (IpSb
->State
== IP4_SERVICE_UNSTARTED
) {
967 Status
= Ip4StartAutoConfig (IpSb
);
969 if (EFI_ERROR (Status
)) {
974 IpIf
= IpSb
->DefaultInterface
;
975 NET_GET_REF (IpSb
->DefaultInterface
);
978 // If default address is used, so is the default route table.
979 // Any route set by the instance has the precedence over the
980 // routes in the default route table. Link the default table
981 // after the instance's table. Routing will search the local
984 NET_GET_REF (IpSb
->DefaultRouteTable
);
985 IpInstance
->RouteTable
->Next
= IpSb
->DefaultRouteTable
;
988 IpInstance
->Interface
= IpIf
;
989 InsertTailList (&IpIf
->IpInstances
, &IpInstance
->AddrLink
);
991 CopyMem (&IpInstance
->ConfigData
, Config
, sizeof (IpInstance
->ConfigData
));
992 IpInstance
->State
= IP4_STATE_CONFIGED
;
995 // Although EFI_NO_MAPPING is an error code, the IP child has been
996 // successfully configured and doesn't need reconfiguration when
997 // default address is acquired.
999 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1000 return EFI_NO_MAPPING
;
1006 Ip4FreeRouteTable (IpInstance
->RouteTable
);
1007 IpInstance
->RouteTable
= NULL
;
1013 Clean up the IP4 child, release all the resources used by it.
1015 @param IpInstance The IP4 child to clean up.
1017 @retval EFI_SUCCESS The IP4 child is cleaned up
1018 @retval EFI_DEVICE_ERROR Some resources failed to be released
1023 IN IP4_PROTOCOL
*IpInstance
1026 if (EFI_ERROR (Ip4Cancel (IpInstance
, NULL
))) {
1027 return EFI_DEVICE_ERROR
;
1030 if (EFI_ERROR (Ip4Groups (IpInstance
, FALSE
, NULL
))) {
1031 return EFI_DEVICE_ERROR
;
1035 // Some packets haven't been recycled. It is because either the
1036 // user forgets to recycle the packets, or because the callback
1037 // hasn't been called. Just leave it alone.
1039 if (!IsListEmpty (&IpInstance
->Delivered
)) {
1043 if (IpInstance
->Interface
!= NULL
) {
1044 RemoveEntryList (&IpInstance
->AddrLink
);
1045 Ip4FreeInterface (IpInstance
->Interface
, IpInstance
);
1046 IpInstance
->Interface
= NULL
;
1049 if (IpInstance
->RouteTable
!= NULL
) {
1050 if (IpInstance
->RouteTable
->Next
!= NULL
) {
1051 Ip4FreeRouteTable (IpInstance
->RouteTable
->Next
);
1054 Ip4FreeRouteTable (IpInstance
->RouteTable
);
1055 IpInstance
->RouteTable
= NULL
;
1058 if (IpInstance
->EfiRouteTable
!= NULL
) {
1059 gBS
->FreePool (IpInstance
->EfiRouteTable
);
1060 IpInstance
->EfiRouteTable
= NULL
;
1061 IpInstance
->EfiRouteCount
= 0;
1064 if (IpInstance
->Groups
!= NULL
) {
1065 gBS
->FreePool (IpInstance
->Groups
);
1066 IpInstance
->Groups
= NULL
;
1067 IpInstance
->GroupCount
= 0;
1070 NetMapClean (&IpInstance
->TxTokens
);
1072 NetMapClean (&IpInstance
->RxTokens
);
1079 Validate that Ip/Netmask pair is OK to be used as station
1080 address. Only continuous netmasks are supported. and check
1081 that StationAddress is a unicast address on the newtwork.
1083 @param Ip The IP address to validate
1084 @param Netmask The netmaks of the IP
1086 @retval TRUE The Ip/Netmask pair is valid
1087 @retval FALSE The Ip/Netmask pair is invalid
1091 Ip4StationAddressValid (
1096 IP4_ADDR NetBrdcastMask
;
1101 // Only support the station address with 0.0.0.0/0 to enable DHCP client.
1103 if (Netmask
== IP4_ALLZERO_ADDRESS
) {
1104 return (BOOLEAN
) (Ip
== IP4_ALLZERO_ADDRESS
);
1108 // Only support the continuous net masks
1110 if ((Len
= NetGetMaskLength (Netmask
)) == IP4_MASK_NUM
) {
1115 // Station address can't be class D or class E address
1117 if ((Type
= NetGetIpClass (Ip
)) > IP4_ADDR_CLASSC
) {
1122 // Station address can't be subnet broadcast/net broadcast address
1124 if ((Ip
== (Ip
& Netmask
)) || (Ip
== (Ip
| ~Netmask
))) {
1128 NetBrdcastMask
= gIp4AllMasks
[MIN (Len
, Type
<< 3)];
1130 if (Ip
== (Ip
| ~NetBrdcastMask
)) {
1139 Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
1141 The Configure() function is used to set, change, or reset the operational
1142 parameters and filter settings for this EFI IPv4 Protocol instance. Until these
1143 parameters have been set, no network traffic can be sent or received by this
1144 instance. Once the parameters have been reset (by calling this function with
1145 IpConfigData set to NULL), no more traffic can be sent or received until these
1146 parameters have been set again. Each EFI IPv4 Protocol instance can be started
1147 and stopped independently of each other by enabling or disabling their receive
1148 filter settings with the Configure() function.
1150 When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will
1151 be appended as an alias address into the addresses list in the EFI IPv4 Protocol
1152 driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL
1153 to retrieve the default IPv4 address if it is not available yet. Clients could
1154 frequently call GetModeData() to check the status to ensure that the default IPv4
1157 If operational parameters are reset or changed, any pending transmit and receive
1158 requests will be cancelled. Their completion token status will be set to EFI_ABORTED
1159 and their events will be signaled.
1161 @param This Pointer to the EFI_IP4_PROTOCOL instance.
1162 @param IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.
1164 @retval EFI_SUCCESS The driver instance was successfully opened.
1165 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1166 RARP, etc.) is not finished yet.
1167 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1168 @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:
1169 A configuration protocol (DHCP, BOOTP, RARP, etc.) could
1170 not be located when clients choose to use the default IPv4
1171 address. This EFI IPv4 Protocol implementation does not
1172 support this requested filter or timeout setting.
1173 @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.
1174 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the
1175 IPv4 address or subnet mask can be changed. The interface must
1176 also be stopped when switching to/from raw packet mode.
1177 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4
1178 Protocol driver instance is not opened.
1184 IN EFI_IP4_PROTOCOL
*This
,
1185 IN EFI_IP4_CONFIG_DATA
*IpConfigData OPTIONAL
1188 IP4_PROTOCOL
*IpInstance
;
1189 EFI_IP4_CONFIG_DATA
*Current
;
1194 IP4_ADDR SubnetMask
;
1197 // First, validate the parameters
1200 return EFI_INVALID_PARAMETER
;
1203 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1204 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1207 // Validate the configuration first.
1209 if (IpConfigData
!= NULL
) {
1211 // This implementation doesn't support RawData
1213 if (IpConfigData
->RawData
) {
1214 Status
= EFI_UNSUPPORTED
;
1219 CopyMem (&IpAddress
, &IpConfigData
->StationAddress
, sizeof (IP4_ADDR
));
1220 CopyMem (&SubnetMask
, &IpConfigData
->SubnetMask
, sizeof (IP4_ADDR
));
1222 IpAddress
= NTOHL (IpAddress
);
1223 SubnetMask
= NTOHL (SubnetMask
);
1226 // Check whether the station address is a valid unicast address
1228 if (!IpConfigData
->UseDefaultAddress
) {
1229 AddrOk
= Ip4StationAddressValid (IpAddress
, SubnetMask
);
1232 Status
= EFI_INVALID_PARAMETER
;
1238 // User can only update packet filters when already configured.
1239 // If it wants to change the station address, it must configure(NULL)
1240 // the instance first.
1242 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
1243 Current
= &IpInstance
->ConfigData
;
1245 if (Current
->UseDefaultAddress
!= IpConfigData
->UseDefaultAddress
) {
1246 Status
= EFI_ALREADY_STARTED
;
1250 if (!Current
->UseDefaultAddress
&&
1251 (!EFI_IP4_EQUAL (&Current
->StationAddress
, &IpConfigData
->StationAddress
) ||
1252 !EFI_IP4_EQUAL (&Current
->SubnetMask
, &IpConfigData
->SubnetMask
))) {
1253 Status
= EFI_ALREADY_STARTED
;
1257 if (Current
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1258 return EFI_NO_MAPPING
;
1264 // Configure the instance or clean it up.
1266 if (IpConfigData
!= NULL
) {
1267 Status
= Ip4ConfigProtocol (IpInstance
, IpConfigData
);
1269 Status
= Ip4CleanProtocol (IpInstance
);
1272 // Don't change the state if it is DESTORY, consider the following
1273 // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,
1274 // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,
1275 // the unload fails miserably.
1277 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
1278 IpInstance
->State
= IP4_STATE_UNCONFIGED
;
1283 // Update the MNP's configure data. Ip4ServiceConfigMnp will check
1284 // whether it is necessary to reconfigure the MNP.
1286 Ip4ServiceConfigMnp (IpInstance
->Service
, FALSE
);
1289 // Update the variable data.
1291 Ip4SetVariableData (IpInstance
->Service
);
1294 gBS
->RestoreTPL (OldTpl
);
1301 Change the IP4 child's multicast setting. The caller
1302 should make sure that the parameters is valid.
1304 @param IpInstance The IP4 child to change the setting.
1305 @param JoinFlag TRUE to join the group, otherwise leave it
1306 @param GroupAddress The target group address
1308 @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it
1309 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
1310 @retval EFI_DEVICE_ERROR Failed to set the group configuraton
1311 @retval EFI_SUCCESS Successfully updated the group setting.
1312 @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.
1317 IN IP4_PROTOCOL
*IpInstance
,
1318 IN BOOLEAN JoinFlag
,
1319 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
1327 // Add it to the instance's Groups, and join the group by IGMP.
1328 // IpInstance->Groups is in network byte order. IGMP operates in
1332 CopyMem (&Group
, GroupAddress
, sizeof (IP4_ADDR
));
1334 for (Index
= 0; Index
< IpInstance
->GroupCount
; Index
++) {
1335 if (IpInstance
->Groups
[Index
] == Group
) {
1336 return EFI_ALREADY_STARTED
;
1340 Members
= Ip4CombineGroups (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1342 if (Members
== NULL
) {
1343 return EFI_OUT_OF_RESOURCES
;
1346 if (EFI_ERROR (Ip4JoinGroup (IpInstance
, NTOHL (Group
)))) {
1347 gBS
->FreePool (Members
);
1348 return EFI_DEVICE_ERROR
;
1351 if (IpInstance
->Groups
!= NULL
) {
1352 gBS
->FreePool (IpInstance
->Groups
);
1355 IpInstance
->Groups
= Members
;
1356 IpInstance
->GroupCount
++;
1362 // Leave the group. Leave all the groups if GroupAddress is NULL.
1363 // Must iterate from the end to the beginning because the GroupCount
1364 // is decreamented each time an address is removed..
1366 for (Index
= IpInstance
->GroupCount
; Index
> 0 ; Index
--) {
1367 Group
= IpInstance
->Groups
[Index
- 1];
1369 if ((GroupAddress
== NULL
) || EFI_IP4_EQUAL (&Group
, GroupAddress
)) {
1370 if (EFI_ERROR (Ip4LeaveGroup (IpInstance
, NTOHL (Group
)))) {
1371 return EFI_DEVICE_ERROR
;
1374 Ip4RemoveGroupAddr (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1375 IpInstance
->GroupCount
--;
1377 if (IpInstance
->GroupCount
== 0) {
1378 ASSERT (Index
== 1);
1380 gBS
->FreePool (IpInstance
->Groups
);
1381 IpInstance
->Groups
= NULL
;
1384 if (GroupAddress
!= NULL
) {
1390 return ((GroupAddress
!= NULL
) ? EFI_NOT_FOUND
: EFI_SUCCESS
);
1395 Joins and leaves multicast groups.
1397 The Groups() function is used to join and leave multicast group sessions. Joining
1398 a group will enable reception of matching multicast packets. Leaving a group will
1399 disable the multicast packet reception.
1401 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
1403 @param This Pointer to the EFI_IP4_PROTOCOL instance.
1404 @param JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.
1405 @param GroupAddress Pointer to the IPv4 multicast address.
1407 @retval EFI_SUCCESS The operation completed successfully.
1408 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
1410 - JoinFlag is TRUE and GroupAddress is NULL.
1411 - GroupAddress is not NULL and *GroupAddress is
1412 not a multicast IPv4 address.
1413 @retval EFI_NOT_STARTED This instance has not been started.
1414 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1415 RARP, etc.) is not finished yet.
1416 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
1417 @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.
1418 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
1420 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
1421 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1427 IN EFI_IP4_PROTOCOL
*This
,
1428 IN BOOLEAN JoinFlag
,
1429 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
1432 IP4_PROTOCOL
*IpInstance
;
1437 if ((This
== NULL
) || (JoinFlag
&& (GroupAddress
== NULL
))) {
1438 return EFI_INVALID_PARAMETER
;
1441 if (GroupAddress
!= NULL
) {
1442 CopyMem (&McastIp
, GroupAddress
, sizeof (IP4_ADDR
));
1444 if (!IP4_IS_MULTICAST (NTOHL (McastIp
))) {
1445 return EFI_INVALID_PARAMETER
;
1449 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1450 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1452 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1453 Status
= EFI_NOT_STARTED
;
1457 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1458 Status
= EFI_NO_MAPPING
;
1462 Status
= Ip4Groups (IpInstance
, JoinFlag
, GroupAddress
);
1465 gBS
->RestoreTPL (OldTpl
);
1471 Adds and deletes routing table entries.
1473 The Routes() function adds a route to or deletes a route from the routing table.
1475 Routes are determined by comparing the SubnetAddress with the destination IPv4
1476 address arithmetically AND-ed with the SubnetMask. The gateway address must be
1477 on the same subnet as the configured station address.
1479 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
1480 The default route matches all destination IPv4 addresses that do not match any
1483 A GatewayAddress that is zero is a nonroute. Packets are sent to the destination
1484 IP address if it can be found in the ARP cache or on the local subnet. One automatic
1485 nonroute entry will be inserted into the routing table for outgoing packets that
1486 are addressed to a local subnet (gateway address of 0.0.0.0).
1488 Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI
1489 IPv4 Protocol instances that use the default IPv4 address will also have copies
1490 of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these
1491 copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its
1492 instances. As a result, client modification to the routing table will be lost.
1494 @param This Pointer to the EFI_IP4_PROTOCOL instance.
1495 @param DeleteRoute Set to TRUE to delete this route from the routing table. Set to
1496 FALSE to add this route to the routing table. SubnetAddress
1497 and SubnetMask are used as the key to each route entry.
1498 @param SubnetAddress The address of the subnet that needs to be routed.
1499 @param SubnetMask The subnet mask of SubnetAddress.
1500 @param GatewayAddress The unicast gateway IPv4 address for this route.
1502 @retval EFI_SUCCESS The operation completed successfully.
1503 @retval EFI_NOT_STARTED The driver instance has not been started.
1504 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1505 RARP, etc.) is not finished yet.
1506 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1508 - SubnetAddress is NULL.
1509 - SubnetMask is NULL.
1510 - GatewayAddress is NULL.
1511 - *SubnetAddress is not a valid subnet address.
1512 - *SubnetMask is not a valid subnet mask.
1513 - *GatewayAddress is not a valid unicast IPv4 address.
1514 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
1515 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
1516 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
1517 DeleteRoute is FALSE).
1523 IN EFI_IP4_PROTOCOL
*This
,
1524 IN BOOLEAN DeleteRoute
,
1525 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
1526 IN EFI_IPv4_ADDRESS
*SubnetMask
,
1527 IN EFI_IPv4_ADDRESS
*GatewayAddress
1530 IP4_PROTOCOL
*IpInstance
;
1531 IP4_INTERFACE
*IpIf
;
1539 // First, validate the parameters
1541 if ((This
== NULL
) || (SubnetAddress
== NULL
) ||
1542 (SubnetMask
== NULL
) || (GatewayAddress
== NULL
)) {
1543 return EFI_INVALID_PARAMETER
;
1546 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1547 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1549 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1550 Status
= EFI_NOT_STARTED
;
1554 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1555 Status
= EFI_NO_MAPPING
;
1559 CopyMem (&Dest
, SubnetAddress
, sizeof (IP4_ADDR
));
1560 CopyMem (&Netmask
, SubnetMask
, sizeof (IP4_ADDR
));
1561 CopyMem (&Nexthop
, GatewayAddress
, sizeof (IP4_ADDR
));
1563 Dest
= NTOHL (Dest
);
1564 Netmask
= NTOHL (Netmask
);
1565 Nexthop
= NTOHL (Nexthop
);
1567 IpIf
= IpInstance
->Interface
;
1569 if (!IP4_IS_VALID_NETMASK (Netmask
)) {
1570 Status
= EFI_INVALID_PARAMETER
;
1575 // the gateway address must be a unicast on the connected network if not zero.
1577 if ((Nexthop
!= IP4_ALLZERO_ADDRESS
) &&
1578 (!IP4_NET_EQUAL (Nexthop
, IpIf
->Ip
, IpIf
->SubnetMask
) ||
1579 IP4_IS_BROADCAST (Ip4GetNetCast (Nexthop
, IpIf
)))) {
1581 Status
= EFI_INVALID_PARAMETER
;
1586 Status
= Ip4DelRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1588 Status
= Ip4AddRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1592 gBS
->RestoreTPL (OldTpl
);
1598 Check whether the user's token or event has already
1599 been enqueued on IP4's list.
1601 @param Map The container of either user's transmit or receive
1603 @param Item Current item to check against
1604 @param Context The Token to check againist.
1606 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
1607 @retval EFI_SUCCESS The current item isn't the same token/event as the
1614 IN NET_MAP_ITEM
*Item
,
1618 EFI_IP4_COMPLETION_TOKEN
*Token
;
1619 EFI_IP4_COMPLETION_TOKEN
*TokenInItem
;
1621 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
1622 TokenInItem
= (EFI_IP4_COMPLETION_TOKEN
*) Item
->Key
;
1624 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
1625 return EFI_ACCESS_DENIED
;
1633 Validate the user's token against current station address.
1635 @param Token User's token to validate
1636 @param IpIf The IP4 child's interface.
1638 @retval EFI_INVALID_PARAMETER Some parameters are invalid
1639 @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.
1640 @retval EFI_SUCCESS The token is OK
1645 IN EFI_IP4_COMPLETION_TOKEN
*Token
,
1646 IN IP4_INTERFACE
*IpIf
1649 EFI_IP4_TRANSMIT_DATA
*TxData
;
1650 EFI_IP4_OVERRIDE_DATA
*Override
;
1657 if ((Token
== NULL
) || (Token
->Event
== NULL
) || (Token
->Packet
.TxData
== NULL
)) {
1658 return EFI_INVALID_PARAMETER
;
1661 TxData
= Token
->Packet
.TxData
;
1664 // Check the IP options: no more than 40 bytes and format is OK
1666 if (TxData
->OptionsLength
!= 0) {
1667 if ((TxData
->OptionsLength
> 40) || (TxData
->OptionsBuffer
== NULL
)) {
1668 return EFI_INVALID_PARAMETER
;
1671 if (!Ip4OptionIsValid (TxData
->OptionsBuffer
, TxData
->OptionsLength
, FALSE
)) {
1672 return EFI_INVALID_PARAMETER
;
1677 // Check the fragment table: no empty fragment, and length isn't bogus
1679 if ((TxData
->TotalDataLength
== 0) || (TxData
->FragmentCount
== 0)) {
1680 return EFI_INVALID_PARAMETER
;
1683 Offset
= TxData
->TotalDataLength
;
1685 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
1686 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
1687 (TxData
->FragmentTable
[Index
].FragmentLength
== 0)) {
1689 return EFI_INVALID_PARAMETER
;
1692 Offset
-= TxData
->FragmentTable
[Index
].FragmentLength
;
1696 return EFI_INVALID_PARAMETER
;
1700 // Check the source and gateway: they must be a valid unicast.
1701 // Gateway must also be on the connected network.
1703 if (TxData
->OverrideData
) {
1704 Override
= TxData
->OverrideData
;
1706 CopyMem (&Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1707 CopyMem (&Gateway
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1710 Gateway
= NTOHL (Gateway
);
1712 if ((NetGetIpClass (Src
) > IP4_ADDR_CLASSC
) ||
1713 (Src
== IP4_ALLONE_ADDRESS
) ||
1714 IP4_IS_BROADCAST (Ip4GetNetCast (Src
, IpIf
))) {
1716 return EFI_INVALID_PARAMETER
;
1720 // If gateway isn't zero, it must be a unicast address, and
1721 // on the connected network.
1723 if ((Gateway
!= IP4_ALLZERO_ADDRESS
) &&
1724 ((NetGetIpClass (Gateway
) > IP4_ADDR_CLASSC
) ||
1725 !IP4_NET_EQUAL (Gateway
, IpIf
->Ip
, IpIf
->SubnetMask
) ||
1726 IP4_IS_BROADCAST (Ip4GetNetCast (Gateway
, IpIf
)))) {
1728 return EFI_INVALID_PARAMETER
;
1733 // Check the packet length: Head length and packet length all has a limit
1735 HeadLen
= sizeof (IP4_HEAD
) + ((TxData
->OptionsLength
+ 3) &~0x03);
1737 if ((HeadLen
> IP4_MAX_HEADLEN
) ||
1738 (TxData
->TotalDataLength
+ HeadLen
> IP4_MAX_PACKET_SIZE
)) {
1740 return EFI_BAD_BUFFER_SIZE
;
1748 The callback function for the net buffer which wraps the user's
1749 transmit token. Although it seems this function is pretty simple,
1750 there are some subtle things.
1751 When user requests the IP to transmit a packet by passing it a
1752 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data
1753 is wrapped in an net buffer. the net buffer's Free function is
1754 set to Ip4FreeTxToken. The Token and token wrap are added to the
1755 IP child's TxToken map. Then the buffer is passed to Ip4Output for
1756 transmission. If something error happened before that, the buffer
1757 is freed, which in turn will free the token wrap. The wrap may
1758 have been added to the TxToken map or not, and the user's event
1759 shouldn't be fired because we are still in the EfiIp4Transmit. If
1760 the buffer has been sent by Ip4Output, it should be removed from
1761 the TxToken map and user's event signaled. The token wrap and buffer
1762 are bound together. Check the comments in Ip4Output for information
1763 about IP fragmentation.
1765 @param Context The token's wrap
1775 IP4_TXTOKEN_WRAP
*Wrap
;
1778 Wrap
= (IP4_TXTOKEN_WRAP
*) Context
;
1781 // Find the token in the instance's map. EfiIp4Transmit put the
1782 // token to the map. If that failed, NetMapFindKey will return NULL.
1784 Item
= NetMapFindKey (&Wrap
->IpInstance
->TxTokens
, Wrap
->Token
);
1787 NetMapRemoveItem (&Wrap
->IpInstance
->TxTokens
, Item
, NULL
);
1791 gBS
->SignalEvent (Wrap
->Token
->Event
);
1794 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
1796 NetLibDispatchDpc ();
1799 gBS
->FreePool (Wrap
);
1804 The callback function to Ip4Output to update the transmit status.
1806 @param Ip4Instance The Ip4Instance that request the transmit.
1807 @param Packet The user's transmit request
1808 @param IoStatus The result of the transmission
1809 @param Flag Not used during transmission
1810 @param Context The token's wrap.
1817 IP4_PROTOCOL
*Ip4Instance
,
1819 EFI_STATUS IoStatus
,
1824 IP4_TXTOKEN_WRAP
*Wrap
;
1827 // This is the transmission request from upper layer,
1828 // not the IP4 driver itself.
1830 ASSERT (Ip4Instance
!= NULL
);
1833 // The first fragment of the packet has been sent. Update
1834 // the token's status. That is, if fragmented, the transmit's
1835 // status is the first fragment's status. The Wrap will be
1836 // release when all the fragments are release. Check the comments
1837 // in Ip4FreeTxToken and Ip4Output for information.
1839 Wrap
= (IP4_TXTOKEN_WRAP
*) Context
;
1840 Wrap
->Token
->Status
= IoStatus
;
1842 NetbufFree (Wrap
->Packet
);
1847 Places outgoing data packets into the transmit queue.
1849 The Transmit() function places a sending request in the transmit queue of this
1850 EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some
1851 errors occur, the event in the token will be signaled and the status is updated.
1853 @param This Pointer to the EFI_IP4_PROTOCOL instance.
1854 @param Token Pointer to the transmit token.
1856 @retval EFI_SUCCESS The data has been queued for transmission.
1857 @retval EFI_NOT_STARTED This instance has not been started.
1858 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1859 RARP, etc.) is not finished yet.
1860 @retval EFI_INVALID_PARAMETER One or more pameters are invalid.
1861 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event
1862 was already in the transmit queue.
1863 @retval EFI_NOT_READY The completion token could not be queued because the transmit
1865 @retval EFI_NOT_FOUND Not route is found to destination address.
1866 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
1867 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
1869 @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is
1870 greater than MTU (or greater than the maximum packet size if
1871 Token.Packet.TxData.OverrideData.
1872 DoNotFragment is TRUE.)
1878 IN EFI_IP4_PROTOCOL
*This
,
1879 IN EFI_IP4_COMPLETION_TOKEN
*Token
1883 IP4_PROTOCOL
*IpInstance
;
1884 IP4_INTERFACE
*IpIf
;
1885 IP4_TXTOKEN_WRAP
*Wrap
;
1886 EFI_IP4_TRANSMIT_DATA
*TxData
;
1887 EFI_IP4_CONFIG_DATA
*Config
;
1888 EFI_IP4_OVERRIDE_DATA
*Override
;
1893 BOOLEAN DontFragment
;
1897 return EFI_INVALID_PARAMETER
;
1900 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1902 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1903 return EFI_NOT_STARTED
;
1906 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1908 IpSb
= IpInstance
->Service
;
1909 IpIf
= IpInstance
->Interface
;
1910 Config
= &IpInstance
->ConfigData
;
1912 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1913 Status
= EFI_NO_MAPPING
;
1918 // make sure that token is properly formated
1920 Status
= Ip4TxTokenValid (Token
, IpIf
);
1922 if (EFI_ERROR (Status
)) {
1927 // Check whether the token or signal already existed.
1929 if (EFI_ERROR (NetMapIterate (&IpInstance
->TxTokens
, Ip4TokenExist
, Token
))) {
1930 Status
= EFI_ACCESS_DENIED
;
1935 // Build the IP header, need to fill in the Tos, TotalLen, Id,
1936 // fragment, Ttl, protocol, Src, and Dst.
1938 TxData
= Token
->Packet
.TxData
;
1940 CopyMem (&Head
.Dst
, &TxData
->DestinationAddress
, sizeof (IP4_ADDR
));
1941 Head
.Dst
= NTOHL (Head
.Dst
);
1943 if (TxData
->OverrideData
) {
1944 Override
= TxData
->OverrideData
;
1945 Head
.Protocol
= Override
->Protocol
;
1946 Head
.Tos
= Override
->TypeOfService
;
1947 Head
.Ttl
= Override
->TimeToLive
;
1948 DontFragment
= Override
->DoNotFragment
;
1950 CopyMem (&Head
.Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1951 CopyMem (&GateWay
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1953 Head
.Src
= NTOHL (Head
.Src
);
1954 GateWay
= NTOHL (GateWay
);
1956 Head
.Src
= IpIf
->Ip
;
1957 GateWay
= IP4_ALLZERO_ADDRESS
;
1958 Head
.Protocol
= Config
->DefaultProtocol
;
1959 Head
.Tos
= Config
->TypeOfService
;
1960 Head
.Ttl
= Config
->TimeToLive
;
1961 DontFragment
= Config
->DoNotFragment
;
1964 Head
.Fragment
= IP4_HEAD_FRAGMENT_FIELD (DontFragment
, FALSE
, 0);
1965 HeadLen
= sizeof (IP4_HEAD
) + ((TxData
->OptionsLength
+ 3) &~0x03);
1968 // If don't fragment and fragment needed, return error
1970 if (DontFragment
&& (TxData
->TotalDataLength
+ HeadLen
> IpSb
->SnpMode
.MaxPacketSize
)) {
1971 Status
= EFI_BAD_BUFFER_SIZE
;
1976 // OK, it survives all the validation check. Wrap the token in
1977 // a IP4_TXTOKEN_WRAP and the data in a netbuf
1979 Status
= EFI_OUT_OF_RESOURCES
;
1980 Wrap
= AllocatePool (sizeof (IP4_TXTOKEN_WRAP
));
1985 Wrap
->IpInstance
= IpInstance
;
1986 Wrap
->Token
= Token
;
1988 Wrap
->Life
= IP4_US_TO_SEC (Config
->TransmitTimeout
);
1989 Wrap
->Packet
= NetbufFromExt (
1990 (NET_FRAGMENT
*) TxData
->FragmentTable
,
1991 TxData
->FragmentCount
,
1998 if (Wrap
->Packet
== NULL
) {
1999 gBS
->FreePool (Wrap
);
2003 Token
->Status
= EFI_NOT_READY
;
2005 if (EFI_ERROR (NetMapInsertTail (&IpInstance
->TxTokens
, Token
, Wrap
))) {
2007 // NetbufFree will call Ip4FreeTxToken, which in turn will
2008 // free the IP4_TXTOKEN_WRAP. Now, the token wrap hasn't been
2011 NetbufFree (Wrap
->Packet
);
2016 // Mark the packet sent before output it. Mark it not sent again if the
2017 // returned status is not EFI_SUCCESS;
2021 Status
= Ip4Output (
2026 TxData
->OptionsBuffer
,
2027 TxData
->OptionsLength
,
2033 if (EFI_ERROR (Status
)) {
2035 NetbufFree (Wrap
->Packet
);
2039 gBS
->RestoreTPL (OldTpl
);
2045 Places a receiving request into the receiving queue.
2047 The Receive() function places a completion token into the receive packet queue.
2048 This function is always asynchronous.
2050 The Token.Event field in the completion token must be filled in by the caller
2051 and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol
2052 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
2055 @param This Pointer to the EFI_IP4_PROTOCOL instance.
2056 @param Token Pointer to a token that is associated with the receive data descriptor.
2058 @retval EFI_SUCCESS The receive completion token was cached.
2059 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2060 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)
2061 is not finished yet.
2062 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2065 - Token.Event is NULL.
2066 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
2067 resources (usually memory).
2068 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2069 The EFI IPv4 Protocol instance has been reset to startup defaults.
2070 EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
2071 in the receive queue.
2072 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
2073 @retval EFI_ICMP_ERROR An ICMP error packet was received.
2079 IN EFI_IP4_PROTOCOL
*This
,
2080 IN EFI_IP4_COMPLETION_TOKEN
*Token
2083 IP4_PROTOCOL
*IpInstance
;
2088 // First validate the parameters
2090 if ((This
== NULL
) || (Token
== NULL
) || (Token
->Event
== NULL
)) {
2091 return EFI_INVALID_PARAMETER
;
2094 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2096 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2098 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
2099 Status
= EFI_NOT_STARTED
;
2104 // Check whether the toke is already on the receive queue.
2106 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4TokenExist
, Token
);
2108 if (EFI_ERROR (Status
)) {
2109 Status
= EFI_ACCESS_DENIED
;
2114 // Queue the token then check whether there is pending received packet.
2116 Status
= NetMapInsertTail (&IpInstance
->RxTokens
, Token
, NULL
);
2118 if (EFI_ERROR (Status
)) {
2122 Status
= Ip4InstanceDeliverPacket (IpInstance
);
2125 // Dispatch the DPC queued by the NotifyFunction of this instane's receive
2128 NetLibDispatchDpc ();
2131 gBS
->RestoreTPL (OldTpl
);
2137 Cancel the transmitted but not recycled packet. If a matching
2138 token is found, it will call Ip4CancelPacket to cancel the
2139 packet. Ip4CancelPacket will cancel all the fragments of the
2140 packet. When all the fragments are freed, the IP4_TXTOKEN_WRAP
2141 will be deleted from the Map, and user's event signalled.
2142 Because Ip4CancelPacket and other functions are all called in
2143 line, so, after Ip4CancelPacket returns, the Item has been freed.
2145 @param Map The IP4 child's transmit queue
2146 @param Item The current transmitted packet to test.
2147 @param Context The user's token to cancel.
2149 @retval EFI_SUCCESS Continue to check the next Item.
2150 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
2156 IN NET_MAP_ITEM
*Item
,
2160 EFI_IP4_COMPLETION_TOKEN
*Token
;
2161 IP4_TXTOKEN_WRAP
*Wrap
;
2163 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
2166 // Return EFI_SUCCESS to check the next item in the map if
2167 // this one doesn't match.
2169 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
2173 Wrap
= (IP4_TXTOKEN_WRAP
*) Item
->Value
;
2174 ASSERT (Wrap
!= NULL
);
2177 // Don't access the Item, Wrap and Token's members after this point.
2178 // Item and wrap has been freed. And we no longer own the Token.
2180 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
2183 // If only one item is to be cancel, return EFI_ABORTED to stop
2184 // iterating the map any more.
2186 if (Token
!= NULL
) {
2195 Cancel the receive request. This is quiet simple, because
2196 it is only enqueued in our local receive map.
2198 @param Map The IP4 child's receive queue
2199 @param Item Current receive request to cancel.
2200 @param Context The user's token to cancel
2202 @retval EFI_SUCCESS Continue to check the next receive request on the
2204 @retval EFI_ABORTED The user's token (token != NULL) has been
2211 IN NET_MAP_ITEM
*Item
,
2215 EFI_IP4_COMPLETION_TOKEN
*Token
;
2216 EFI_IP4_COMPLETION_TOKEN
*This
;
2218 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
2221 if ((Token
!= NULL
) && (Token
!= This
)) {
2225 NetMapRemoveItem (Map
, Item
, NULL
);
2227 This
->Status
= EFI_ABORTED
;
2228 This
->Packet
.RxData
= NULL
;
2229 gBS
->SignalEvent (This
->Event
);
2231 if (Token
!= NULL
) {
2240 Cancel the user's receive/transmit request.
2242 @param IpInstance The IP4 child
2243 @param Token The token to cancel. If NULL, all token will be
2246 @retval EFI_SUCCESS The token is cancelled
2247 @retval EFI_NOT_FOUND The token isn't found on either the
2248 transmit/receive queue
2249 @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.
2254 IN IP4_PROTOCOL
*IpInstance
,
2255 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2261 // First check the transmitted packet. Ip4CancelTxTokens returns
2262 // EFI_ABORTED to mean that the token has been cancelled when
2263 // token != NULL. So, return EFI_SUCCESS for this condition.
2265 Status
= NetMapIterate (&IpInstance
->TxTokens
, Ip4CancelTxTokens
, Token
);
2267 if (EFI_ERROR (Status
)) {
2268 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2276 // Check the receive queue. Ip4CancelRxTokens also returns EFI_ABORT
2277 // for Token!=NULL and it is cancelled.
2279 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4CancelRxTokens
, Token
);
2281 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
2284 NetLibDispatchDpc ();
2285 if (EFI_ERROR (Status
)) {
2286 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2294 // OK, if the Token is found when Token != NULL, the NetMapIterate
2295 // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.
2297 if (Token
!= NULL
) {
2298 return EFI_NOT_FOUND
;
2302 // If Token == NULL, cancel all the tokens. return error if no
2303 // all of them are cancelled.
2305 if (!NetMapIsEmpty (&IpInstance
->TxTokens
) ||
2306 !NetMapIsEmpty (&IpInstance
->RxTokens
)) {
2308 return EFI_DEVICE_ERROR
;
2316 Abort an asynchronous transmit or receive request.
2318 The Cancel() function is used to abort a pending transmit or receive request.
2319 If the token is in the transmit or receive request queues, after calling this
2320 function, Token->Status will be set to EFI_ABORTED and then Token->Event will
2321 be signaled. If the token is not in one of the queues, which usually means the
2322 asynchronous operation has completed, this function will not signal the token
2323 and EFI_NOT_FOUND is returned.
2325 @param This Pointer to the EFI_IP4_PROTOCOL instance.
2326 @param Token Pointer to a token that has been issued by
2327 EFI_IP4_PROTOCOL.Transmit() or
2328 EFI_IP4_PROTOCOL.Receive(). If NULL, all pending
2329 tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is
2330 defined in EFI_IP4_PROTOCOL.Transmit().
2332 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
2333 Token.->Event was signaled. When Token is NULL, all
2334 pending requests were aborted and their events were signaled.
2335 @retval EFI_INVALID_PARAMETER This is NULL.
2336 @retval EFI_NOT_STARTED This instance has not been started.
2337 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2338 RARP, etc.) is not finished yet.
2339 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
2340 not found in the transmit or receive queue. It has either completed
2341 or was not issued by Transmit() and Receive().
2347 IN EFI_IP4_PROTOCOL
*This
,
2348 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2351 IP4_PROTOCOL
*IpInstance
;
2356 return EFI_INVALID_PARAMETER
;
2359 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2361 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2363 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
2364 Status
= EFI_NOT_STARTED
;
2368 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
2369 Status
= EFI_NO_MAPPING
;
2373 Status
= Ip4Cancel (IpInstance
, Token
);
2376 gBS
->RestoreTPL (OldTpl
);
2382 Polls for incoming data packets and processes outgoing data packets.
2384 The Poll() function polls for incoming data packets and processes outgoing data
2385 packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()
2386 function to increase the rate that data packets are moved between the communications
2387 device and the transmit and receive queues.
2389 In some systems the periodic timer event may not poll the underlying communications
2390 device fast enough to transmit and/or receive all data packets without missing
2391 incoming packets or dropping outgoing packets. Drivers and applications that are
2392 experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function
2395 @param This Pointer to the EFI_IP4_PROTOCOL instance.
2397 @retval EFI_SUCCESS Incoming or outgoing data was processed.
2398 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2399 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2400 RARP, etc.) is not finished yet.
2401 @retval EFI_INVALID_PARAMETER This is NULL.
2402 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2403 @retval EFI_NOT_READY No incoming or outgoing data is processed.
2404 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
2405 Consider increasing the polling rate.
2411 IN EFI_IP4_PROTOCOL
*This
2414 IP4_PROTOCOL
*IpInstance
;
2415 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
2418 return EFI_INVALID_PARAMETER
;
2421 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2423 if (IpInstance
->State
== IP4_STATE_UNCONFIGED
) {
2424 return EFI_NOT_STARTED
;
2427 Mnp
= IpInstance
->Service
->Mnp
;
2430 // Don't lock the Poll function to enable the deliver of
2431 // the packet polled up.
2433 return Mnp
->Poll (Mnp
);
2437 Decrease the life of the transmitted packets. If it is
2438 decreased to zero, cancel the packet. This function is
2439 called by Ip4PacketTimerTicking which time out both the
2440 received-but-not-delivered and transmitted-but-not-recycle
2443 @param Map The IP4 child's transmit map.
2444 @param Item Current transmitted packet
2445 @param Context Not used.
2447 @retval EFI_SUCCESS Always returns EFI_SUCCESS
2451 Ip4SentPacketTicking (
2453 IN NET_MAP_ITEM
*Item
,
2457 IP4_TXTOKEN_WRAP
*Wrap
;
2459 Wrap
= (IP4_TXTOKEN_WRAP
*) Item
->Value
;
2460 ASSERT (Wrap
!= NULL
);
2462 if ((Wrap
->Life
> 0) && (--Wrap
->Life
== 0)) {
2463 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
2471 The heart beat timer of IP4 service instance. It times out
2472 all of its IP4 children's received-but-not-delivered and
2473 transmitted-but-not-recycle packets, and provides time input
2474 for its IGMP protocol.
2476 @param Event The IP4 service instance's heart beat timer.
2477 @param Context The IP4 service instance.
2491 IpSb
= (IP4_SERVICE
*) Context
;
2492 NET_CHECK_SIGNATURE (IpSb
, IP4_SERVICE_SIGNATURE
);
2494 Ip4PacketTimerTicking (IpSb
);
2495 Ip4IgmpTicking (IpSb
);