3 Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
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.
16 EFI_IPSEC2_PROTOCOL
*mIpSec
= NULL
;
19 Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.
21 The GetModeData() function returns the current operational mode data for this
22 driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This
23 function is used optionally to retrieve the operational mode data of underlying
26 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
27 @param[out] Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.
28 @param[out] MnpConfigData Pointer to the managed network configuration data structure.
29 @param[out] SnpModeData Pointer to the simple network mode data structure.
31 @retval EFI_SUCCESS The operation completed successfully.
32 @retval EFI_INVALID_PARAMETER This is NULL.
33 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
39 IN CONST EFI_IP4_PROTOCOL
*This
,
40 OUT EFI_IP4_MODE_DATA
*Ip4ModeData OPTIONAL
,
41 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
42 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
46 Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
48 The Configure() function is used to set, change, or reset the operational
49 parameters and filter settings for this EFI IPv4 Protocol instance. Until these
50 parameters have been set, no network traffic can be sent or received by this
51 instance. Once the parameters have been reset (by calling this function with
52 IpConfigData set to NULL), no more traffic can be sent or received until these
53 parameters have been set again. Each EFI IPv4 Protocol instance can be started
54 and stopped independently of each other by enabling or disabling their receive
55 filter settings with the Configure() function.
57 When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will
58 be appended as an alias address into the addresses list in the EFI IPv4 Protocol
59 driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL
60 to retrieve the default IPv4 address if it is not available yet. Clients could
61 frequently call GetModeData() to check the status to ensure that the default IPv4
64 If operational parameters are reset or changed, any pending transmit and receive
65 requests will be cancelled. Their completion token status will be set to EFI_ABORTED
66 and their events will be signaled.
68 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
69 @param[in] IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.
71 @retval EFI_SUCCESS The driver instance was successfully opened.
72 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
73 RARP, etc.) is not finished yet.
74 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
75 @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:
76 A configuration protocol (DHCP, BOOTP, RARP, etc.) could
77 not be located when clients choose to use the default IPv4
78 address. This EFI IPv4 Protocol implementation does not
79 support this requested filter or timeout setting.
80 @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.
81 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the
82 IPv4 address or subnet mask can be changed. The interface must
83 also be stopped when switching to/from raw packet mode.
84 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4
85 Protocol driver instance is not opened.
91 IN EFI_IP4_PROTOCOL
*This
,
92 IN EFI_IP4_CONFIG_DATA
*IpConfigData OPTIONAL
96 Joins and leaves multicast groups.
98 The Groups() function is used to join and leave multicast group sessions. Joining
99 a group will enable reception of matching multicast packets. Leaving a group will
100 disable the multicast packet reception.
102 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
104 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
105 @param[in] JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.
106 @param[in] GroupAddress Pointer to the IPv4 multicast address.
108 @retval EFI_SUCCESS The operation completed successfully.
109 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
111 - JoinFlag is TRUE and GroupAddress is NULL.
112 - GroupAddress is not NULL and *GroupAddress is
113 not a multicast IPv4 address.
114 @retval EFI_NOT_STARTED This instance has not been started.
115 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
116 RARP, etc.) is not finished yet.
117 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
118 @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.
119 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
121 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
122 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
128 IN EFI_IP4_PROTOCOL
*This
,
130 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
134 Adds and deletes routing table entries.
136 The Routes() function adds a route to or deletes a route from the routing table.
138 Routes are determined by comparing the SubnetAddress with the destination IPv4
139 address arithmetically AND-ed with the SubnetMask. The gateway address must be
140 on the same subnet as the configured station address.
142 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
143 The default route matches all destination IPv4 addresses that do not match any
146 A GatewayAddress that is zero is a nonroute. Packets are sent to the destination
147 IP address if it can be found in the ARP cache or on the local subnet. One automatic
148 nonroute entry will be inserted into the routing table for outgoing packets that
149 are addressed to a local subnet (gateway address of 0.0.0.0).
151 Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI
152 IPv4 Protocol instances that use the default IPv4 address will also have copies
153 of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these
154 copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its
155 instances. As a result, client modification to the routing table will be lost.
157 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
158 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
159 FALSE to add this route to the routing table. SubnetAddress
160 and SubnetMask are used as the key to each route entry.
161 @param[in] SubnetAddress The address of the subnet that needs to be routed.
162 @param[in] SubnetMask The subnet mask of SubnetAddress.
163 @param[in] GatewayAddress The unicast gateway IPv4 address for this route.
165 @retval EFI_SUCCESS The operation completed successfully.
166 @retval EFI_NOT_STARTED The driver instance has not been started.
167 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
168 RARP, etc.) is not finished yet.
169 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
171 - SubnetAddress is NULL.
172 - SubnetMask is NULL.
173 - GatewayAddress is NULL.
174 - *SubnetAddress is not a valid subnet address.
175 - *SubnetMask is not a valid subnet mask.
176 - *GatewayAddress is not a valid unicast IPv4 address.
177 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
178 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
179 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
180 DeleteRoute is FALSE).
186 IN EFI_IP4_PROTOCOL
*This
,
187 IN BOOLEAN DeleteRoute
,
188 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
189 IN EFI_IPv4_ADDRESS
*SubnetMask
,
190 IN EFI_IPv4_ADDRESS
*GatewayAddress
194 Places outgoing data packets into the transmit queue.
196 The Transmit() function places a sending request in the transmit queue of this
197 EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some
198 errors occur, the event in the token will be signaled and the status is updated.
200 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
201 @param[in] Token Pointer to the transmit token.
203 @retval EFI_SUCCESS The data has been queued for transmission.
204 @retval EFI_NOT_STARTED This instance has not been started.
205 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
206 RARP, etc.) is not finished yet.
207 @retval EFI_INVALID_PARAMETER One or more pameters are invalid.
208 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event
209 was already in the transmit queue.
210 @retval EFI_NOT_READY The completion token could not be queued because the transmit
212 @retval EFI_NOT_FOUND Not route is found to destination address.
213 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
214 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
216 @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is
217 greater than MTU (or greater than the maximum packet size if
218 Token.Packet.TxData.OverrideData.
219 DoNotFragment is TRUE.)
225 IN EFI_IP4_PROTOCOL
*This
,
226 IN EFI_IP4_COMPLETION_TOKEN
*Token
230 Places a receiving request into the receiving queue.
232 The Receive() function places a completion token into the receive packet queue.
233 This function is always asynchronous.
235 The Token.Event field in the completion token must be filled in by the caller
236 and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol
237 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
240 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
241 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
243 @retval EFI_SUCCESS The receive completion token was cached.
244 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
245 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)
247 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
250 - Token.Event is NULL.
251 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
252 resources (usually memory).
253 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
254 The EFI IPv4 Protocol instance has been reset to startup defaults.
255 EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
256 in the receive queue.
257 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
258 @retval EFI_ICMP_ERROR An ICMP error packet was received.
264 IN EFI_IP4_PROTOCOL
*This
,
265 IN EFI_IP4_COMPLETION_TOKEN
*Token
269 Abort an asynchronous transmit or receive request.
271 The Cancel() function is used to abort a pending transmit or receive request.
272 If the token is in the transmit or receive request queues, after calling this
273 function, Token->Status will be set to EFI_ABORTED and then Token->Event will
274 be signaled. If the token is not in one of the queues, which usually means the
275 asynchronous operation has completed, this function will not signal the token
276 and EFI_NOT_FOUND is returned.
278 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
279 @param[in] Token Pointer to a token that has been issued by
280 EFI_IP4_PROTOCOL.Transmit() or
281 EFI_IP4_PROTOCOL.Receive(). If NULL, all pending
282 tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is
283 defined in EFI_IP4_PROTOCOL.Transmit().
285 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
286 Token.->Event was signaled. When Token is NULL, all
287 pending requests were aborted and their events were signaled.
288 @retval EFI_INVALID_PARAMETER This is NULL.
289 @retval EFI_NOT_STARTED This instance has not been started.
290 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
291 RARP, etc.) is not finished yet.
292 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
293 not found in the transmit or receive queue. It has either completed
294 or was not issued by Transmit() and Receive().
300 IN EFI_IP4_PROTOCOL
*This
,
301 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
305 Polls for incoming data packets and processes outgoing data packets.
307 The Poll() function polls for incoming data packets and processes outgoing data
308 packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()
309 function to increase the rate that data packets are moved between the communications
310 device and the transmit and receive queues.
312 In some systems the periodic timer event may not poll the underlying communications
313 device fast enough to transmit and/or receive all data packets without missing
314 incoming packets or dropping outgoing packets. Drivers and applications that are
315 experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function
318 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
320 @retval EFI_SUCCESS Incoming or outgoing data was processed.
321 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
322 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
323 RARP, etc.) is not finished yet.
324 @retval EFI_INVALID_PARAMETER This is NULL.
325 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
326 @retval EFI_NOT_READY No incoming or outgoing data is processed.
327 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
328 Consider increasing the polling rate.
334 IN EFI_IP4_PROTOCOL
*This
338 mEfiIp4ProtocolTemplete
= {
350 Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.
352 The GetModeData() function returns the current operational mode data for this
353 driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This
354 function is used optionally to retrieve the operational mode data of underlying
357 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
358 @param[out] Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.
359 @param[out] MnpConfigData Pointer to the managed network configuration data structure.
360 @param[out] SnpModeData Pointer to the simple network mode data structure.
362 @retval EFI_SUCCESS The operation completed successfully.
363 @retval EFI_INVALID_PARAMETER This is NULL.
364 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
370 IN CONST EFI_IP4_PROTOCOL
*This
,
371 OUT EFI_IP4_MODE_DATA
*Ip4ModeData OPTIONAL
,
372 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
373 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
376 IP4_PROTOCOL
*IpInstance
;
378 EFI_IP4_CONFIG_DATA
*Config
;
384 return EFI_INVALID_PARAMETER
;
387 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
388 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
389 IpSb
= IpInstance
->Service
;
391 if (Ip4ModeData
!= NULL
) {
393 // IsStarted is "whether the EfiIp4Configure has been called".
394 // IsConfigured is "whether the station address has been configured"
396 Ip4ModeData
->IsStarted
= (BOOLEAN
)(IpInstance
->State
== IP4_STATE_CONFIGED
);
397 CopyMem (&Ip4ModeData
->ConfigData
, &IpInstance
->ConfigData
, sizeof (Ip4ModeData
->ConfigData
));
398 Ip4ModeData
->IsConfigured
= FALSE
;
400 Ip4ModeData
->GroupCount
= IpInstance
->GroupCount
;
401 Ip4ModeData
->GroupTable
= (EFI_IPv4_ADDRESS
*) IpInstance
->Groups
;
403 Ip4ModeData
->IcmpTypeCount
= 23;
404 Ip4ModeData
->IcmpTypeList
= mIp4SupportedIcmp
;
406 Ip4ModeData
->RouteTable
= NULL
;
407 Ip4ModeData
->RouteCount
= 0;
409 Ip4ModeData
->MaxPacketSize
= IpSb
->MaxPacketSize
;
412 // return the current station address for this IP child. So,
413 // the user can get the default address through this. Some
414 // application wants to know it station address even it is
415 // using the default one, such as a ftp server.
417 if (Ip4ModeData
->IsStarted
) {
418 Config
= &Ip4ModeData
->ConfigData
;
420 Ip
= HTONL (IpInstance
->Interface
->Ip
);
421 CopyMem (&Config
->StationAddress
, &Ip
, sizeof (EFI_IPv4_ADDRESS
));
423 Ip
= HTONL (IpInstance
->Interface
->SubnetMask
);
424 CopyMem (&Config
->SubnetMask
, &Ip
, sizeof (EFI_IPv4_ADDRESS
));
426 Ip4ModeData
->IsConfigured
= IpInstance
->Interface
->Configured
;
429 // Build a EFI route table for user from the internal route table.
431 Status
= Ip4BuildEfiRouteTable (IpInstance
);
433 if (EFI_ERROR (Status
)) {
434 gBS
->RestoreTPL (OldTpl
);
438 Ip4ModeData
->RouteTable
= IpInstance
->EfiRouteTable
;
439 Ip4ModeData
->RouteCount
= IpInstance
->EfiRouteCount
;
444 // Get fresh mode data from MNP, since underlying media status may change
446 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, MnpConfigData
, SnpModeData
);
448 gBS
->RestoreTPL (OldTpl
);
454 Config the MNP parameter used by IP. The IP driver use one MNP
455 child to transmit/receive frames. By default, it configures MNP
456 to receive unicast/multicast/broadcast. And it will enable/disable
457 the promiscous receive according to whether there is IP child
458 enable that or not. If Force is FALSE, it will iterate through
459 all the IP children to check whether the promiscuous receive
460 setting has been changed. If it hasn't been changed, it won't
461 reconfigure the MNP. If Force is TRUE, the MNP is configured no
462 matter whether that is changed or not.
464 @param[in] IpSb The IP4 service instance that is to be changed.
465 @param[in] Force Force the configuration or not.
467 @retval EFI_SUCCESS The MNP is successfully configured/reconfigured.
468 @retval Others Configuration failed.
472 Ip4ServiceConfigMnp (
473 IN IP4_SERVICE
*IpSb
,
478 LIST_ENTRY
*ProtoEntry
;
480 IP4_PROTOCOL
*IpInstance
;
482 BOOLEAN PromiscReceive
;
486 PromiscReceive
= FALSE
;
490 // Iterate through the IP children to check whether promiscuous
491 // receive setting has been changed. Update the interface's receive
494 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
496 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP4_INTERFACE
, Link
);
497 IpIf
->PromiscRecv
= FALSE
;
499 NET_LIST_FOR_EACH (ProtoEntry
, &IpIf
->IpInstances
) {
500 IpInstance
= NET_LIST_USER_STRUCT (ProtoEntry
, IP4_PROTOCOL
, AddrLink
);
502 if (IpInstance
->ConfigData
.AcceptPromiscuous
) {
503 IpIf
->PromiscRecv
= TRUE
;
504 PromiscReceive
= TRUE
;
510 // If promiscuous receive isn't changed, it isn't necessary to reconfigure.
512 if (PromiscReceive
== IpSb
->MnpConfigData
.EnablePromiscuousReceive
) {
517 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= PromiscReceive
;
520 Status
= IpSb
->Mnp
->Configure (IpSb
->Mnp
, &IpSb
->MnpConfigData
);
523 // recover the original configuration if failed to set the configure.
525 if (EFI_ERROR (Status
) && Reconfig
) {
526 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= (BOOLEAN
) !PromiscReceive
;
534 The event handle for IP4 auto configuration. If IP is asked
535 to reconfigure the default address. The original default
536 interface and route table are removed as the default. If there
537 is active IP children using the default address, the interface
538 will remain valid until all the children have freed their
539 references. If IP is signalled when auto configuration is done,
540 it will configure the default interface and default route table
541 with the configuration information retrieved by IP4_CONFIGURE.
543 @param[in] Context The IP4 service binding instance.
548 Ip4AutoConfigCallBackDpc (
552 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
553 EFI_IP4_IPCONFIG_DATA
*Data
;
554 EFI_IP4_ROUTE_TABLE
*RouteEntry
;
556 IP4_ROUTE_TABLE
*RouteTable
;
561 IP4_ADDR StationAddress
;
563 IP4_ADDR SubnetAddress
;
564 IP4_ADDR GatewayAddress
;
565 IP4_PROTOCOL
*Ip4Instance
;
566 EFI_ARP_PROTOCOL
*Arp
;
569 IpSb
= (IP4_SERVICE
*) Context
;
570 NET_CHECK_SIGNATURE (IpSb
, IP4_SERVICE_SIGNATURE
);
572 Ip4Config
= IpSb
->Ip4Config
;
575 // IP is asked to do the reconfiguration. If the default interface
576 // has been configured, release the default interface and route
577 // table, then create a new one. If there are some IP children
578 // using it, the interface won't be physically freed until all the
579 // children have released their reference to it. Also remember to
580 // restart the receive on the default address. IP4 driver only receive
581 // frames on the default address, and when the default interface is
582 // freed, Ip4AcceptFrame won't be informed.
584 if (IpSb
->ActiveEvent
== IpSb
->ReconfigEvent
) {
586 if (IpSb
->DefaultInterface
->Configured
) {
587 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
593 RouteTable
= Ip4CreateRouteTable ();
595 if (RouteTable
== NULL
) {
596 Ip4FreeInterface (IpIf
, NULL
);
600 Ip4CancelReceive (IpSb
->DefaultInterface
);
601 Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
602 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
604 IpSb
->DefaultInterface
= IpIf
;
605 InsertHeadList (&IpSb
->Interfaces
, &IpIf
->Link
);
607 IpSb
->DefaultRouteTable
= RouteTable
;
608 Ip4ReceiveFrame (IpIf
, NULL
, Ip4AccpetFrame
, IpSb
);
611 Ip4Config
->Stop (Ip4Config
);
612 Ip4Config
->Start (Ip4Config
, IpSb
->DoneEvent
, IpSb
->ReconfigEvent
);
617 // Get the configure data in two steps: get the length then the data.
621 if (Ip4Config
->GetData (Ip4Config
, &Len
, NULL
) != EFI_BUFFER_TOO_SMALL
) {
625 Data
= AllocatePool (Len
);
631 Status
= Ip4Config
->GetData (Ip4Config
, &Len
, Data
);
633 if (EFI_ERROR (Status
)) {
637 IpIf
= IpSb
->DefaultInterface
;
640 // If the default address has been configured don't change it.
641 // This is unlikely to happen if EFI_IP4_CONFIG protocol has
642 // informed us to reconfigure each time it wants to change the
643 // configuration parameters.
645 if (IpIf
->Configured
) {
650 // Set the default interface's address, then add a directed
651 // route for it, that is, the route whose nexthop is zero.
653 StationAddress
= EFI_NTOHL (Data
->StationAddress
);
654 SubnetMask
= EFI_NTOHL (Data
->SubnetMask
);
655 Status
= Ip4SetAddress (IpIf
, StationAddress
, SubnetMask
);
656 if (EFI_ERROR (Status
)) {
660 if (IpIf
->Arp
!= NULL
) {
662 // A non-NULL IpIf->Arp here means a new ARP child is created when setting default address,
663 // but some IP children may have referenced the default interface before it is configured,
664 // these IP instances also consume this ARP protocol so they need to open it BY_CHILD_CONTROLLER.
667 NET_LIST_FOR_EACH (Entry
, &IpIf
->IpInstances
) {
668 Ip4Instance
= NET_LIST_USER_STRUCT_S (Entry
, IP4_PROTOCOL
, AddrLink
, IP4_PROTOCOL_SIGNATURE
);
669 Status
= gBS
->OpenProtocol (
671 &gEfiArpProtocolGuid
,
673 gIp4DriverBinding
.DriverBindingHandle
,
675 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
677 if (EFI_ERROR (Status
)) {
684 IpSb
->DefaultRouteTable
,
691 // Add routes returned by EFI_IP4_CONFIG protocol.
693 for (Index
= 0; Index
< Data
->RouteTableSize
; Index
++) {
694 RouteEntry
= &Data
->RouteTable
[Index
];
696 SubnetAddress
= EFI_NTOHL (RouteEntry
->SubnetAddress
);
697 SubnetMask
= EFI_NTOHL (RouteEntry
->SubnetMask
);
698 GatewayAddress
= EFI_NTOHL (RouteEntry
->GatewayAddress
);
699 Ip4AddRoute (IpSb
->DefaultRouteTable
, SubnetAddress
, SubnetMask
, GatewayAddress
);
702 IpSb
->State
= IP4_SERVICE_CONFIGED
;
704 Ip4SetVariableData (IpSb
);
711 Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK.
713 @param Event The event that is signalled.
714 @param Context The IP4 service binding instance.
719 Ip4AutoConfigCallBack (
726 IpSb
= (IP4_SERVICE
*) Context
;
727 IpSb
->ActiveEvent
= Event
;
730 // Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK
732 QueueDpc (TPL_CALLBACK
, Ip4AutoConfigCallBackDpc
, Context
);
737 Start the auto configuration for this IP service instance.
738 It will locates the EFI_IP4_CONFIG_PROTOCOL, then start the
741 @param[in] IpSb The IP4 service instance to configure
743 @retval EFI_SUCCESS The auto configuration is successfull started
744 @retval Others Failed to start auto configuration.
752 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
755 if (IpSb
->State
> IP4_SERVICE_UNSTARTED
) {
760 // Create the DoneEvent and ReconfigEvent to call EFI_IP4_CONFIG
762 Status
= gBS
->CreateEvent (
765 Ip4AutoConfigCallBack
,
770 if (EFI_ERROR (Status
)) {
774 Status
= gBS
->CreateEvent (
777 Ip4AutoConfigCallBack
,
782 if (EFI_ERROR (Status
)) {
783 goto CLOSE_DONE_EVENT
;
787 // Open the EFI_IP4_CONFIG protocol then start auto configure
789 Status
= gBS
->OpenProtocol (
791 &gEfiIp4ConfigProtocolGuid
,
792 (VOID
**) &Ip4Config
,
795 EFI_OPEN_PROTOCOL_BY_DRIVER
| EFI_OPEN_PROTOCOL_EXCLUSIVE
798 if (EFI_ERROR (Status
)) {
799 Status
= EFI_UNSUPPORTED
;
800 goto CLOSE_RECONFIG_EVENT
;
803 Status
= Ip4Config
->Start (Ip4Config
, IpSb
->DoneEvent
, IpSb
->ReconfigEvent
);
805 if (EFI_ERROR (Status
)) {
808 &gEfiIp4ConfigProtocolGuid
,
813 goto CLOSE_RECONFIG_EVENT
;
816 IpSb
->Ip4Config
= Ip4Config
;
817 IpSb
->State
= IP4_SERVICE_STARTED
;
820 CLOSE_RECONFIG_EVENT
:
821 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
822 IpSb
->ReconfigEvent
= NULL
;
825 gBS
->CloseEvent (IpSb
->DoneEvent
);
826 IpSb
->DoneEvent
= NULL
;
833 Intiialize the IP4_PROTOCOL structure to the unconfigured states.
835 @param IpSb The IP4 service instance.
836 @param IpInstance The IP4 child instance.
841 IN IP4_SERVICE
*IpSb
,
842 IN OUT IP4_PROTOCOL
*IpInstance
845 ASSERT ((IpSb
!= NULL
) && (IpInstance
!= NULL
));
847 ZeroMem (IpInstance
, sizeof (IP4_PROTOCOL
));
849 IpInstance
->Signature
= IP4_PROTOCOL_SIGNATURE
;
850 CopyMem (&IpInstance
->Ip4Proto
, &mEfiIp4ProtocolTemplete
, sizeof (IpInstance
->Ip4Proto
));
851 IpInstance
->State
= IP4_STATE_UNCONFIGED
;
852 IpInstance
->Service
= IpSb
;
854 InitializeListHead (&IpInstance
->Link
);
855 NetMapInit (&IpInstance
->RxTokens
);
856 NetMapInit (&IpInstance
->TxTokens
);
857 InitializeListHead (&IpInstance
->Received
);
858 InitializeListHead (&IpInstance
->Delivered
);
859 InitializeListHead (&IpInstance
->AddrLink
);
861 EfiInitializeLock (&IpInstance
->RecycleLock
, TPL_NOTIFY
);
866 Configure the IP4 child. If the child is already configured,
867 change the configuration parameter. Otherwise configure it
868 for the first time. The caller should validate the configuration
869 before deliver them to it. It also don't do configure NULL.
871 @param[in, out] IpInstance The IP4 child to configure.
872 @param[in] Config The configure data.
874 @retval EFI_SUCCESS The IP4 child is successfully configured.
875 @retval EFI_DEVICE_ERROR Failed to free the pending transive or to
876 configure underlying MNP or other errors.
877 @retval EFI_NO_MAPPING The IP4 child is configured to use default
878 address, but the default address hasn't been
879 configured. The IP4 child doesn't need to be
880 reconfigured when default address is configured.
881 @retval EFI_OUT_OF_RESOURCES No more memory space is available.
882 @retval other Other error occurs.
887 IN OUT IP4_PROTOCOL
*IpInstance
,
888 IN EFI_IP4_CONFIG_DATA
*Config
896 EFI_ARP_PROTOCOL
*Arp
;
898 IpSb
= IpInstance
->Service
;
901 // User is changing packet filters. It must be stopped
902 // before the station address can be changed.
904 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
906 // Cancel all the pending transmit/receive from upper layer
908 Status
= Ip4Cancel (IpInstance
, NULL
);
910 if (EFI_ERROR (Status
)) {
911 return EFI_DEVICE_ERROR
;
914 CopyMem (&IpInstance
->ConfigData
, Config
, sizeof (IpInstance
->ConfigData
));
919 // Configure a fresh IP4 protocol instance. Create a route table.
920 // Each IP child has its own route table, which may point to the
921 // default table if it is using default address.
923 Status
= EFI_OUT_OF_RESOURCES
;
924 IpInstance
->RouteTable
= Ip4CreateRouteTable ();
926 if (IpInstance
->RouteTable
== NULL
) {
931 // Set up the interface.
933 CopyMem (&Ip
, &Config
->StationAddress
, sizeof (IP4_ADDR
));
934 CopyMem (&Netmask
, &Config
->SubnetMask
, sizeof (IP4_ADDR
));
937 Netmask
= NTOHL (Netmask
);
939 if (!Config
->UseDefaultAddress
) {
941 // Find whether there is already an interface with the same
942 // station address. All the instances with the same station
943 // address shares one interface.
945 IpIf
= Ip4FindStationAddress (IpSb
, Ip
, Netmask
);
951 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
957 Status
= Ip4SetAddress (IpIf
, Ip
, Netmask
);
959 if (EFI_ERROR (Status
)) {
960 Status
= EFI_DEVICE_ERROR
;
961 Ip4FreeInterface (IpIf
, IpInstance
);
965 InsertTailList (&IpSb
->Interfaces
, &IpIf
->Link
);
969 // Add a route to this connected network in the route table
971 Ip4AddRoute (IpInstance
->RouteTable
, Ip
, Netmask
, IP4_ALLZERO_ADDRESS
);
975 // Use the default address. If the default configuration hasn't
976 // been started, start it.
978 if (IpSb
->State
== IP4_SERVICE_UNSTARTED
) {
979 Status
= Ip4StartAutoConfig (IpSb
);
981 if (EFI_ERROR (Status
)) {
986 IpIf
= IpSb
->DefaultInterface
;
987 NET_GET_REF (IpSb
->DefaultInterface
);
990 // If default address is used, so is the default route table.
991 // Any route set by the instance has the precedence over the
992 // routes in the default route table. Link the default table
993 // after the instance's table. Routing will search the local
996 NET_GET_REF (IpSb
->DefaultRouteTable
);
997 IpInstance
->RouteTable
->Next
= IpSb
->DefaultRouteTable
;
1000 IpInstance
->Interface
= IpIf
;
1001 if (IpIf
->Arp
!= NULL
) {
1003 Status
= gBS
->OpenProtocol (
1005 &gEfiArpProtocolGuid
,
1007 gIp4DriverBinding
.DriverBindingHandle
,
1009 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1011 if (EFI_ERROR (Status
)) {
1015 InsertTailList (&IpIf
->IpInstances
, &IpInstance
->AddrLink
);
1017 CopyMem (&IpInstance
->ConfigData
, Config
, sizeof (IpInstance
->ConfigData
));
1018 IpInstance
->State
= IP4_STATE_CONFIGED
;
1021 // Although EFI_NO_MAPPING is an error code, the IP child has been
1022 // successfully configured and doesn't need reconfiguration when
1023 // default address is acquired.
1025 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1026 return EFI_NO_MAPPING
;
1032 Ip4FreeRouteTable (IpInstance
->RouteTable
);
1033 IpInstance
->RouteTable
= NULL
;
1039 Clean up the IP4 child, release all the resources used by it.
1041 @param[in] IpInstance The IP4 child to clean up.
1043 @retval EFI_SUCCESS The IP4 child is cleaned up
1044 @retval EFI_DEVICE_ERROR Some resources failed to be released
1049 IN IP4_PROTOCOL
*IpInstance
1052 if (EFI_ERROR (Ip4Cancel (IpInstance
, NULL
))) {
1053 return EFI_DEVICE_ERROR
;
1056 if (EFI_ERROR (Ip4Groups (IpInstance
, FALSE
, NULL
))) {
1057 return EFI_DEVICE_ERROR
;
1061 // Some packets haven't been recycled. It is because either the
1062 // user forgets to recycle the packets, or because the callback
1063 // hasn't been called. Just leave it alone.
1065 if (!IsListEmpty (&IpInstance
->Delivered
)) {
1069 if (IpInstance
->Interface
!= NULL
) {
1070 RemoveEntryList (&IpInstance
->AddrLink
);
1071 if (IpInstance
->Interface
->Arp
!= NULL
) {
1072 gBS
->CloseProtocol (
1073 IpInstance
->Interface
->ArpHandle
,
1074 &gEfiArpProtocolGuid
,
1075 gIp4DriverBinding
.DriverBindingHandle
,
1079 Ip4FreeInterface (IpInstance
->Interface
, IpInstance
);
1080 IpInstance
->Interface
= NULL
;
1083 if (IpInstance
->RouteTable
!= NULL
) {
1084 if (IpInstance
->RouteTable
->Next
!= NULL
) {
1085 Ip4FreeRouteTable (IpInstance
->RouteTable
->Next
);
1088 Ip4FreeRouteTable (IpInstance
->RouteTable
);
1089 IpInstance
->RouteTable
= NULL
;
1092 if (IpInstance
->EfiRouteTable
!= NULL
) {
1093 FreePool (IpInstance
->EfiRouteTable
);
1094 IpInstance
->EfiRouteTable
= NULL
;
1095 IpInstance
->EfiRouteCount
= 0;
1098 if (IpInstance
->Groups
!= NULL
) {
1099 FreePool (IpInstance
->Groups
);
1100 IpInstance
->Groups
= NULL
;
1101 IpInstance
->GroupCount
= 0;
1104 NetMapClean (&IpInstance
->TxTokens
);
1106 NetMapClean (&IpInstance
->RxTokens
);
1113 Validate that Ip/Netmask pair is OK to be used as station
1114 address. Only continuous netmasks are supported. and check
1115 that StationAddress is a unicast address on the newtwork.
1117 @param[in] Ip The IP address to validate
1118 @param[in] Netmask The netmaks of the IP
1120 @retval TRUE The Ip/Netmask pair is valid
1121 @retval FALSE The Ip/Netmask pair is invalid
1125 Ip4StationAddressValid (
1130 IP4_ADDR NetBrdcastMask
;
1135 // Only support the station address with 0.0.0.0/0 to enable DHCP client.
1137 if (Netmask
== IP4_ALLZERO_ADDRESS
) {
1138 return (BOOLEAN
) (Ip
== IP4_ALLZERO_ADDRESS
);
1142 // Only support the continuous net masks
1144 if ((Len
= NetGetMaskLength (Netmask
)) == IP4_MASK_NUM
) {
1149 // Station address can't be class D or class E address
1151 if ((Type
= NetGetIpClass (Ip
)) > IP4_ADDR_CLASSC
) {
1156 // Station address can't be subnet broadcast/net broadcast address
1158 if ((Ip
== (Ip
& Netmask
)) || (Ip
== (Ip
| ~Netmask
))) {
1162 NetBrdcastMask
= gIp4AllMasks
[MIN (Len
, Type
<< 3)];
1164 if (Ip
== (Ip
| ~NetBrdcastMask
)) {
1173 Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
1175 The Configure() function is used to set, change, or reset the operational
1176 parameters and filter settings for this EFI IPv4 Protocol instance. Until these
1177 parameters have been set, no network traffic can be sent or received by this
1178 instance. Once the parameters have been reset (by calling this function with
1179 IpConfigData set to NULL), no more traffic can be sent or received until these
1180 parameters have been set again. Each EFI IPv4 Protocol instance can be started
1181 and stopped independently of each other by enabling or disabling their receive
1182 filter settings with the Configure() function.
1184 When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will
1185 be appended as an alias address into the addresses list in the EFI IPv4 Protocol
1186 driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL
1187 to retrieve the default IPv4 address if it is not available yet. Clients could
1188 frequently call GetModeData() to check the status to ensure that the default IPv4
1191 If operational parameters are reset or changed, any pending transmit and receive
1192 requests will be cancelled. Their completion token status will be set to EFI_ABORTED
1193 and their events will be signaled.
1195 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1196 @param[in] IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.
1198 @retval EFI_SUCCESS The driver instance was successfully opened.
1199 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1200 RARP, etc.) is not finished yet.
1201 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1202 @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:
1203 A configuration protocol (DHCP, BOOTP, RARP, etc.) could
1204 not be located when clients choose to use the default IPv4
1205 address. This EFI IPv4 Protocol implementation does not
1206 support this requested filter or timeout setting.
1207 @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.
1208 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the
1209 IPv4 address or subnet mask can be changed. The interface must
1210 also be stopped when switching to/from raw packet mode.
1211 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4
1212 Protocol driver instance is not opened.
1218 IN EFI_IP4_PROTOCOL
*This
,
1219 IN EFI_IP4_CONFIG_DATA
*IpConfigData OPTIONAL
1222 IP4_PROTOCOL
*IpInstance
;
1223 EFI_IP4_CONFIG_DATA
*Current
;
1228 IP4_ADDR SubnetMask
;
1231 // First, validate the parameters
1234 return EFI_INVALID_PARAMETER
;
1237 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1238 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1241 // Validate the configuration first.
1243 if (IpConfigData
!= NULL
) {
1245 CopyMem (&IpAddress
, &IpConfigData
->StationAddress
, sizeof (IP4_ADDR
));
1246 CopyMem (&SubnetMask
, &IpConfigData
->SubnetMask
, sizeof (IP4_ADDR
));
1248 IpAddress
= NTOHL (IpAddress
);
1249 SubnetMask
= NTOHL (SubnetMask
);
1252 // Check whether the station address is a valid unicast address
1254 if (!IpConfigData
->UseDefaultAddress
) {
1255 AddrOk
= Ip4StationAddressValid (IpAddress
, SubnetMask
);
1258 Status
= EFI_INVALID_PARAMETER
;
1264 // User can only update packet filters when already configured.
1265 // If it wants to change the station address, it must configure(NULL)
1266 // the instance first.
1268 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
1269 Current
= &IpInstance
->ConfigData
;
1271 if (Current
->UseDefaultAddress
!= IpConfigData
->UseDefaultAddress
) {
1272 Status
= EFI_ALREADY_STARTED
;
1276 if (!Current
->UseDefaultAddress
&&
1277 (!EFI_IP4_EQUAL (&Current
->StationAddress
, &IpConfigData
->StationAddress
) ||
1278 !EFI_IP4_EQUAL (&Current
->SubnetMask
, &IpConfigData
->SubnetMask
))) {
1279 Status
= EFI_ALREADY_STARTED
;
1283 if (Current
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1284 Status
= EFI_NO_MAPPING
;
1291 // Configure the instance or clean it up.
1293 if (IpConfigData
!= NULL
) {
1294 Status
= Ip4ConfigProtocol (IpInstance
, IpConfigData
);
1296 Status
= Ip4CleanProtocol (IpInstance
);
1299 // Don't change the state if it is DESTROY, consider the following
1300 // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,
1301 // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,
1302 // the unload fails miserably.
1304 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
1305 IpInstance
->State
= IP4_STATE_UNCONFIGED
;
1310 // Update the MNP's configure data. Ip4ServiceConfigMnp will check
1311 // whether it is necessary to reconfigure the MNP.
1313 Ip4ServiceConfigMnp (IpInstance
->Service
, FALSE
);
1316 // Update the variable data.
1318 Ip4SetVariableData (IpInstance
->Service
);
1321 gBS
->RestoreTPL (OldTpl
);
1328 Change the IP4 child's multicast setting. The caller
1329 should make sure that the parameters is valid.
1331 @param[in] IpInstance The IP4 child to change the setting.
1332 @param[in] JoinFlag TRUE to join the group, otherwise leave it
1333 @param[in] GroupAddress The target group address
1335 @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it
1336 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
1337 @retval EFI_DEVICE_ERROR Failed to set the group configuraton
1338 @retval EFI_SUCCESS Successfully updated the group setting.
1339 @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.
1344 IN IP4_PROTOCOL
*IpInstance
,
1345 IN BOOLEAN JoinFlag
,
1346 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
1354 // Add it to the instance's Groups, and join the group by IGMP.
1355 // IpInstance->Groups is in network byte order. IGMP operates in
1360 // When JoinFlag is TRUE, GroupAddress shouldn't be NULL.
1362 ASSERT (GroupAddress
!= NULL
);
1363 CopyMem (&Group
, GroupAddress
, sizeof (IP4_ADDR
));
1365 for (Index
= 0; Index
< IpInstance
->GroupCount
; Index
++) {
1366 if (IpInstance
->Groups
[Index
] == Group
) {
1367 return EFI_ALREADY_STARTED
;
1371 Members
= Ip4CombineGroups (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1373 if (Members
== NULL
) {
1374 return EFI_OUT_OF_RESOURCES
;
1377 if (EFI_ERROR (Ip4JoinGroup (IpInstance
, NTOHL (Group
)))) {
1379 return EFI_DEVICE_ERROR
;
1382 if (IpInstance
->Groups
!= NULL
) {
1383 FreePool (IpInstance
->Groups
);
1386 IpInstance
->Groups
= Members
;
1387 IpInstance
->GroupCount
++;
1393 // Leave the group. Leave all the groups if GroupAddress is NULL.
1394 // Must iterate from the end to the beginning because the GroupCount
1395 // is decreamented each time an address is removed..
1397 for (Index
= IpInstance
->GroupCount
; Index
> 0 ; Index
--) {
1398 Group
= IpInstance
->Groups
[Index
- 1];
1400 if ((GroupAddress
== NULL
) || EFI_IP4_EQUAL (&Group
, GroupAddress
)) {
1401 if (EFI_ERROR (Ip4LeaveGroup (IpInstance
, NTOHL (Group
)))) {
1402 return EFI_DEVICE_ERROR
;
1405 Ip4RemoveGroupAddr (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1406 IpInstance
->GroupCount
--;
1408 if (IpInstance
->GroupCount
== 0) {
1409 ASSERT (Index
== 1);
1411 FreePool (IpInstance
->Groups
);
1412 IpInstance
->Groups
= NULL
;
1415 if (GroupAddress
!= NULL
) {
1421 return ((GroupAddress
!= NULL
) ? EFI_NOT_FOUND
: EFI_SUCCESS
);
1426 Joins and leaves multicast groups.
1428 The Groups() function is used to join and leave multicast group sessions. Joining
1429 a group will enable reception of matching multicast packets. Leaving a group will
1430 disable the multicast packet reception.
1432 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
1434 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1435 @param[in] JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.
1436 @param[in] GroupAddress Pointer to the IPv4 multicast address.
1438 @retval EFI_SUCCESS The operation completed successfully.
1439 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
1441 - JoinFlag is TRUE and GroupAddress is NULL.
1442 - GroupAddress is not NULL and *GroupAddress is
1443 not a multicast IPv4 address.
1444 @retval EFI_NOT_STARTED This instance has not been started.
1445 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1446 RARP, etc.) is not finished yet.
1447 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
1448 @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.
1449 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
1451 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
1452 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1458 IN EFI_IP4_PROTOCOL
*This
,
1459 IN BOOLEAN JoinFlag
,
1460 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
1463 IP4_PROTOCOL
*IpInstance
;
1468 if ((This
== NULL
) || (JoinFlag
&& (GroupAddress
== NULL
))) {
1469 return EFI_INVALID_PARAMETER
;
1472 if (GroupAddress
!= NULL
) {
1473 CopyMem (&McastIp
, GroupAddress
, sizeof (IP4_ADDR
));
1475 if (!IP4_IS_MULTICAST (NTOHL (McastIp
))) {
1476 return EFI_INVALID_PARAMETER
;
1480 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1481 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1483 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1484 Status
= EFI_NOT_STARTED
;
1488 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1489 Status
= EFI_NO_MAPPING
;
1493 Status
= Ip4Groups (IpInstance
, JoinFlag
, GroupAddress
);
1496 gBS
->RestoreTPL (OldTpl
);
1502 Adds and deletes routing table entries.
1504 The Routes() function adds a route to or deletes a route from the routing table.
1506 Routes are determined by comparing the SubnetAddress with the destination IPv4
1507 address arithmetically AND-ed with the SubnetMask. The gateway address must be
1508 on the same subnet as the configured station address.
1510 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
1511 The default route matches all destination IPv4 addresses that do not match any
1514 A GatewayAddress that is zero is a nonroute. Packets are sent to the destination
1515 IP address if it can be found in the ARP cache or on the local subnet. One automatic
1516 nonroute entry will be inserted into the routing table for outgoing packets that
1517 are addressed to a local subnet (gateway address of 0.0.0.0).
1519 Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI
1520 IPv4 Protocol instances that use the default IPv4 address will also have copies
1521 of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these
1522 copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its
1523 instances. As a result, client modification to the routing table will be lost.
1525 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1526 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
1527 FALSE to add this route to the routing table. SubnetAddress
1528 and SubnetMask are used as the key to each route entry.
1529 @param[in] SubnetAddress The address of the subnet that needs to be routed.
1530 @param[in] SubnetMask The subnet mask of SubnetAddress.
1531 @param[in] GatewayAddress The unicast gateway IPv4 address for this route.
1533 @retval EFI_SUCCESS The operation completed successfully.
1534 @retval EFI_NOT_STARTED The driver instance has not been started.
1535 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1536 RARP, etc.) is not finished yet.
1537 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1539 - SubnetAddress is NULL.
1540 - SubnetMask is NULL.
1541 - GatewayAddress is NULL.
1542 - *SubnetAddress is not a valid subnet address.
1543 - *SubnetMask is not a valid subnet mask.
1544 - *GatewayAddress is not a valid unicast IPv4 address.
1545 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
1546 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
1547 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
1548 DeleteRoute is FALSE).
1554 IN EFI_IP4_PROTOCOL
*This
,
1555 IN BOOLEAN DeleteRoute
,
1556 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
1557 IN EFI_IPv4_ADDRESS
*SubnetMask
,
1558 IN EFI_IPv4_ADDRESS
*GatewayAddress
1561 IP4_PROTOCOL
*IpInstance
;
1562 IP4_INTERFACE
*IpIf
;
1570 // First, validate the parameters
1572 if ((This
== NULL
) || (SubnetAddress
== NULL
) ||
1573 (SubnetMask
== NULL
) || (GatewayAddress
== NULL
)) {
1574 return EFI_INVALID_PARAMETER
;
1577 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1578 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1580 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1581 Status
= EFI_NOT_STARTED
;
1585 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1586 Status
= EFI_NO_MAPPING
;
1590 CopyMem (&Dest
, SubnetAddress
, sizeof (IP4_ADDR
));
1591 CopyMem (&Netmask
, SubnetMask
, sizeof (IP4_ADDR
));
1592 CopyMem (&Nexthop
, GatewayAddress
, sizeof (IP4_ADDR
));
1594 Dest
= NTOHL (Dest
);
1595 Netmask
= NTOHL (Netmask
);
1596 Nexthop
= NTOHL (Nexthop
);
1598 IpIf
= IpInstance
->Interface
;
1600 if (!IP4_IS_VALID_NETMASK (Netmask
)) {
1601 Status
= EFI_INVALID_PARAMETER
;
1606 // the gateway address must be a unicast on the connected network if not zero.
1608 if ((Nexthop
!= IP4_ALLZERO_ADDRESS
) &&
1609 (!IP4_NET_EQUAL (Nexthop
, IpIf
->Ip
, IpIf
->SubnetMask
) ||
1610 IP4_IS_BROADCAST (Ip4GetNetCast (Nexthop
, IpIf
)))) {
1612 Status
= EFI_INVALID_PARAMETER
;
1617 Status
= Ip4DelRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1619 Status
= Ip4AddRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1623 gBS
->RestoreTPL (OldTpl
);
1629 Check whether the user's token or event has already
1630 been enqueued on IP4's list.
1632 @param[in] Map The container of either user's transmit or receive
1634 @param[in] Item Current item to check against
1635 @param[in] Context The Token to check againist.
1637 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
1638 @retval EFI_SUCCESS The current item isn't the same token/event as the
1646 IN NET_MAP_ITEM
*Item
,
1650 EFI_IP4_COMPLETION_TOKEN
*Token
;
1651 EFI_IP4_COMPLETION_TOKEN
*TokenInItem
;
1653 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
1654 TokenInItem
= (EFI_IP4_COMPLETION_TOKEN
*) Item
->Key
;
1656 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
1657 return EFI_ACCESS_DENIED
;
1664 Validate the user's token against current station address.
1666 @param[in] Token User's token to validate.
1667 @param[in] IpIf The IP4 child's interface.
1668 @param[in] RawData Set to TRUE to send unformatted packets.
1670 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
1671 @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.
1672 @retval EFI_SUCCESS The token is valid.
1677 IN EFI_IP4_COMPLETION_TOKEN
*Token
,
1678 IN IP4_INTERFACE
*IpIf
,
1682 EFI_IP4_TRANSMIT_DATA
*TxData
;
1683 EFI_IP4_OVERRIDE_DATA
*Override
;
1690 if ((Token
== NULL
) || (Token
->Event
== NULL
) || (Token
->Packet
.TxData
== NULL
)) {
1691 return EFI_INVALID_PARAMETER
;
1694 TxData
= Token
->Packet
.TxData
;
1697 // Check the fragment table: no empty fragment, and length isn't bogus.
1699 if ((TxData
->TotalDataLength
== 0) || (TxData
->FragmentCount
== 0)) {
1700 return EFI_INVALID_PARAMETER
;
1703 Offset
= TxData
->TotalDataLength
;
1705 if (Offset
> IP4_MAX_PACKET_SIZE
) {
1706 return EFI_BAD_BUFFER_SIZE
;
1709 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
1710 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
1711 (TxData
->FragmentTable
[Index
].FragmentLength
== 0)) {
1713 return EFI_INVALID_PARAMETER
;
1716 Offset
-= TxData
->FragmentTable
[Index
].FragmentLength
;
1720 return EFI_INVALID_PARAMETER
;
1724 // NOTE that OptionsLength/OptionsBuffer/OverrideData are ignored if RawData
1732 // Check the IP options: no more than 40 bytes and format is OK
1734 if (TxData
->OptionsLength
!= 0) {
1735 if ((TxData
->OptionsLength
> 40) || (TxData
->OptionsBuffer
== NULL
)) {
1736 return EFI_INVALID_PARAMETER
;
1739 if (!Ip4OptionIsValid (TxData
->OptionsBuffer
, TxData
->OptionsLength
, FALSE
)) {
1740 return EFI_INVALID_PARAMETER
;
1745 // Check the source and gateway: they must be a valid unicast.
1746 // Gateway must also be on the connected network.
1748 if (TxData
->OverrideData
!= NULL
) {
1749 Override
= TxData
->OverrideData
;
1751 CopyMem (&Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1752 CopyMem (&Gateway
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1755 Gateway
= NTOHL (Gateway
);
1757 if ((NetGetIpClass (Src
) > IP4_ADDR_CLASSC
) ||
1758 (Src
== IP4_ALLONE_ADDRESS
) ||
1759 IP4_IS_BROADCAST (Ip4GetNetCast (Src
, IpIf
))) {
1761 return EFI_INVALID_PARAMETER
;
1765 // If gateway isn't zero, it must be a unicast address, and
1766 // on the connected network.
1768 if ((Gateway
!= IP4_ALLZERO_ADDRESS
) &&
1769 ((NetGetIpClass (Gateway
) > IP4_ADDR_CLASSC
) ||
1770 !IP4_NET_EQUAL (Gateway
, IpIf
->Ip
, IpIf
->SubnetMask
) ||
1771 IP4_IS_BROADCAST (Ip4GetNetCast (Gateway
, IpIf
)))) {
1773 return EFI_INVALID_PARAMETER
;
1778 // Check the packet length: Head length and packet length all has a limit
1780 HeadLen
= sizeof (IP4_HEAD
) + ((TxData
->OptionsLength
+ 3) &~0x03);
1782 if ((HeadLen
> IP4_MAX_HEADLEN
) ||
1783 (TxData
->TotalDataLength
+ HeadLen
> IP4_MAX_PACKET_SIZE
)) {
1785 return EFI_BAD_BUFFER_SIZE
;
1793 The callback function for the net buffer which wraps the user's
1794 transmit token. Although it seems this function is pretty simple,
1795 there are some subtle things.
1796 When user requests the IP to transmit a packet by passing it a
1797 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data
1798 is wrapped in an net buffer. the net buffer's Free function is
1799 set to Ip4FreeTxToken. The Token and token wrap are added to the
1800 IP child's TxToken map. Then the buffer is passed to Ip4Output for
1801 transmission. If something error happened before that, the buffer
1802 is freed, which in turn will free the token wrap. The wrap may
1803 have been added to the TxToken map or not, and the user's event
1804 shouldn't be fired because we are still in the EfiIp4Transmit. If
1805 the buffer has been sent by Ip4Output, it should be removed from
1806 the TxToken map and user's event signaled. The token wrap and buffer
1807 are bound together. Check the comments in Ip4Output for information
1808 about IP fragmentation.
1810 @param[in] Context The token's wrap
1819 IP4_TXTOKEN_WRAP
*Wrap
;
1822 Wrap
= (IP4_TXTOKEN_WRAP
*) Context
;
1825 // Signal IpSecRecycleEvent to inform IPsec free the memory
1827 if (Wrap
->IpSecRecycleSignal
!= NULL
) {
1828 gBS
->SignalEvent (Wrap
->IpSecRecycleSignal
);
1832 // Find the token in the instance's map. EfiIp4Transmit put the
1833 // token to the map. If that failed, NetMapFindKey will return NULL.
1835 Item
= NetMapFindKey (&Wrap
->IpInstance
->TxTokens
, Wrap
->Token
);
1838 NetMapRemoveItem (&Wrap
->IpInstance
->TxTokens
, Item
, NULL
);
1842 gBS
->SignalEvent (Wrap
->Token
->Event
);
1845 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
1855 The callback function to Ip4Output to update the transmit status.
1857 @param Ip4Instance The Ip4Instance that request the transmit.
1858 @param Packet The user's transmit request
1859 @param IoStatus The result of the transmission
1860 @param Flag Not used during transmission
1861 @param Context The token's wrap.
1866 IP4_PROTOCOL
*Ip4Instance
,
1868 EFI_STATUS IoStatus
,
1873 IP4_TXTOKEN_WRAP
*Wrap
;
1876 // This is the transmission request from upper layer,
1877 // not the IP4 driver itself.
1879 ASSERT (Ip4Instance
!= NULL
);
1882 // The first fragment of the packet has been sent. Update
1883 // the token's status. That is, if fragmented, the transmit's
1884 // status is the first fragment's status. The Wrap will be
1885 // release when all the fragments are release. Check the comments
1886 // in Ip4FreeTxToken and Ip4Output for information.
1888 Wrap
= (IP4_TXTOKEN_WRAP
*) Context
;
1889 Wrap
->Token
->Status
= IoStatus
;
1891 NetbufFree (Wrap
->Packet
);
1896 Places outgoing data packets into the transmit queue.
1898 The Transmit() function places a sending request in the transmit queue of this
1899 EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some
1900 errors occur, the event in the token will be signaled and the status is updated.
1902 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1903 @param[in] Token Pointer to the transmit token.
1905 @retval EFI_SUCCESS The data has been queued for transmission.
1906 @retval EFI_NOT_STARTED This instance has not been started.
1907 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1908 RARP, etc.) is not finished yet.
1909 @retval EFI_INVALID_PARAMETER One or more pameters are invalid.
1910 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event
1911 was already in the transmit queue.
1912 @retval EFI_NOT_READY The completion token could not be queued because the transmit
1914 @retval EFI_NOT_FOUND Not route is found to destination address.
1915 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
1916 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
1918 @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is
1919 greater than MTU (or greater than the maximum packet size if
1920 Token.Packet.TxData.OverrideData.
1921 DoNotFragment is TRUE.)
1927 IN EFI_IP4_PROTOCOL
*This
,
1928 IN EFI_IP4_COMPLETION_TOKEN
*Token
1932 IP4_PROTOCOL
*IpInstance
;
1933 IP4_INTERFACE
*IpIf
;
1934 IP4_TXTOKEN_WRAP
*Wrap
;
1935 EFI_IP4_TRANSMIT_DATA
*TxData
;
1936 EFI_IP4_CONFIG_DATA
*Config
;
1937 EFI_IP4_OVERRIDE_DATA
*Override
;
1942 BOOLEAN DontFragment
;
1945 UINT32 OptionsLength
;
1946 UINT8
*OptionsBuffer
;
1947 VOID
*FirstFragment
;
1950 return EFI_INVALID_PARAMETER
;
1953 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1955 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1956 return EFI_NOT_STARTED
;
1959 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1961 IpSb
= IpInstance
->Service
;
1962 IpIf
= IpInstance
->Interface
;
1963 Config
= &IpInstance
->ConfigData
;
1965 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1966 Status
= EFI_NO_MAPPING
;
1971 // make sure that token is properly formated
1973 Status
= Ip4TxTokenValid (Token
, IpIf
, Config
->RawData
);
1975 if (EFI_ERROR (Status
)) {
1980 // Check whether the token or signal already existed.
1982 if (EFI_ERROR (NetMapIterate (&IpInstance
->TxTokens
, Ip4TokenExist
, Token
))) {
1983 Status
= EFI_ACCESS_DENIED
;
1988 // Build the IP header, need to fill in the Tos, TotalLen, Id,
1989 // fragment, Ttl, protocol, Src, and Dst.
1991 TxData
= Token
->Packet
.TxData
;
1993 FirstFragment
= NULL
;
1995 if (Config
->RawData
) {
1997 // When RawData is TRUE, first buffer in FragmentTable points to a raw
1998 // IPv4 fragment including IPv4 header and options.
2000 FirstFragment
= TxData
->FragmentTable
[0].FragmentBuffer
;
2001 CopyMem (&RawHdrLen
, FirstFragment
, sizeof (UINT8
));
2003 RawHdrLen
= (UINT8
) (RawHdrLen
& 0x0f);
2004 if (RawHdrLen
< 5) {
2005 Status
= EFI_INVALID_PARAMETER
;
2009 RawHdrLen
= (UINT8
) (RawHdrLen
<< 2);
2011 CopyMem (&Head
, FirstFragment
, IP4_MIN_HEADLEN
);
2013 Ip4NtohHead (&Head
);
2015 DontFragment
= IP4_DO_NOT_FRAGMENT (Head
.Fragment
);
2017 if (!DontFragment
) {
2018 Status
= EFI_INVALID_PARAMETER
;
2022 GateWay
= IP4_ALLZERO_ADDRESS
;
2025 // Get IPv4 options from first fragment.
2027 if (RawHdrLen
== IP4_MIN_HEADLEN
) {
2029 OptionsBuffer
= NULL
;
2031 OptionsLength
= RawHdrLen
- IP4_MIN_HEADLEN
;
2032 OptionsBuffer
= (UINT8
*) FirstFragment
+ IP4_MIN_HEADLEN
;
2036 // Trim off IPv4 header and options from first fragment.
2038 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*) FirstFragment
+ RawHdrLen
;
2039 TxData
->FragmentTable
[0].FragmentLength
= TxData
->FragmentTable
[0].FragmentLength
- RawHdrLen
;
2041 CopyMem (&Head
.Dst
, &TxData
->DestinationAddress
, sizeof (IP4_ADDR
));
2042 Head
.Dst
= NTOHL (Head
.Dst
);
2044 if (TxData
->OverrideData
!= NULL
) {
2045 Override
= TxData
->OverrideData
;
2046 Head
.Protocol
= Override
->Protocol
;
2047 Head
.Tos
= Override
->TypeOfService
;
2048 Head
.Ttl
= Override
->TimeToLive
;
2049 DontFragment
= Override
->DoNotFragment
;
2051 CopyMem (&Head
.Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
2052 CopyMem (&GateWay
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
2054 Head
.Src
= NTOHL (Head
.Src
);
2055 GateWay
= NTOHL (GateWay
);
2057 Head
.Src
= IpIf
->Ip
;
2058 GateWay
= IP4_ALLZERO_ADDRESS
;
2059 Head
.Protocol
= Config
->DefaultProtocol
;
2060 Head
.Tos
= Config
->TypeOfService
;
2061 Head
.Ttl
= Config
->TimeToLive
;
2062 DontFragment
= Config
->DoNotFragment
;
2065 Head
.Fragment
= IP4_HEAD_FRAGMENT_FIELD (DontFragment
, FALSE
, 0);
2066 HeadLen
= (TxData
->OptionsLength
+ 3) & (~0x03);
2068 OptionsLength
= TxData
->OptionsLength
;
2069 OptionsBuffer
= (UINT8
*) (TxData
->OptionsBuffer
);
2073 // If don't fragment and fragment needed, return error
2075 if (DontFragment
&& (TxData
->TotalDataLength
+ HeadLen
> IpSb
->MaxPacketSize
)) {
2076 Status
= EFI_BAD_BUFFER_SIZE
;
2081 // OK, it survives all the validation check. Wrap the token in
2082 // a IP4_TXTOKEN_WRAP and the data in a netbuf
2084 Status
= EFI_OUT_OF_RESOURCES
;
2085 Wrap
= AllocateZeroPool (sizeof (IP4_TXTOKEN_WRAP
));
2090 Wrap
->IpInstance
= IpInstance
;
2091 Wrap
->Token
= Token
;
2093 Wrap
->Life
= IP4_US_TO_SEC (Config
->TransmitTimeout
);
2094 Wrap
->Packet
= NetbufFromExt (
2095 (NET_FRAGMENT
*) TxData
->FragmentTable
,
2096 TxData
->FragmentCount
,
2103 if (Wrap
->Packet
== NULL
) {
2108 Token
->Status
= EFI_NOT_READY
;
2110 if (EFI_ERROR (NetMapInsertTail (&IpInstance
->TxTokens
, Token
, Wrap
))) {
2112 // NetbufFree will call Ip4FreeTxToken, which in turn will
2113 // free the IP4_TXTOKEN_WRAP. Now, the token wrap hasn't been
2116 if (Config
->RawData
) {
2118 // Restore pointer of first fragment in RawData mode.
2120 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*) FirstFragment
;
2123 NetbufFree (Wrap
->Packet
);
2128 // Mark the packet sent before output it. Mark it not sent again if the
2129 // returned status is not EFI_SUCCESS;
2133 Status
= Ip4Output (
2145 if (EFI_ERROR (Status
)) {
2148 if (Config
->RawData
) {
2150 // Restore pointer of first fragment in RawData mode.
2152 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*) FirstFragment
;
2155 NetbufFree (Wrap
->Packet
);
2158 if (Config
->RawData
) {
2160 // Restore pointer of first fragment in RawData mode.
2162 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*) FirstFragment
;
2166 gBS
->RestoreTPL (OldTpl
);
2172 Places a receiving request into the receiving queue.
2174 The Receive() function places a completion token into the receive packet queue.
2175 This function is always asynchronous.
2177 The Token.Event field in the completion token must be filled in by the caller
2178 and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol
2179 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
2182 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2183 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
2185 @retval EFI_SUCCESS The receive completion token was cached.
2186 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2187 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)
2188 is not finished yet.
2189 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2192 - Token.Event is NULL.
2193 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
2194 resources (usually memory).
2195 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2196 The EFI IPv4 Protocol instance has been reset to startup defaults.
2197 EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
2198 in the receive queue.
2199 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
2200 @retval EFI_ICMP_ERROR An ICMP error packet was received.
2206 IN EFI_IP4_PROTOCOL
*This
,
2207 IN EFI_IP4_COMPLETION_TOKEN
*Token
2210 IP4_PROTOCOL
*IpInstance
;
2215 // First validate the parameters
2217 if ((This
== NULL
) || (Token
== NULL
) || (Token
->Event
== NULL
)) {
2218 return EFI_INVALID_PARAMETER
;
2221 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2223 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2225 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
2226 Status
= EFI_NOT_STARTED
;
2231 // Check whether the toke is already on the receive queue.
2233 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4TokenExist
, Token
);
2235 if (EFI_ERROR (Status
)) {
2236 Status
= EFI_ACCESS_DENIED
;
2241 // Queue the token then check whether there is pending received packet.
2243 Status
= NetMapInsertTail (&IpInstance
->RxTokens
, Token
, NULL
);
2245 if (EFI_ERROR (Status
)) {
2249 Status
= Ip4InstanceDeliverPacket (IpInstance
);
2252 // Dispatch the DPC queued by the NotifyFunction of this instane's receive
2258 gBS
->RestoreTPL (OldTpl
);
2264 Cancel the transmitted but not recycled packet. If a matching
2265 token is found, it will call Ip4CancelPacket to cancel the
2266 packet. Ip4CancelPacket will cancel all the fragments of the
2267 packet. When all the fragments are freed, the IP4_TXTOKEN_WRAP
2268 will be deleted from the Map, and user's event signalled.
2269 Because Ip4CancelPacket and other functions are all called in
2270 line, so, after Ip4CancelPacket returns, the Item has been freed.
2272 @param[in] Map The IP4 child's transmit queue
2273 @param[in] Item The current transmitted packet to test.
2274 @param[in] Context The user's token to cancel.
2276 @retval EFI_SUCCESS Continue to check the next Item.
2277 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
2284 IN NET_MAP_ITEM
*Item
,
2288 EFI_IP4_COMPLETION_TOKEN
*Token
;
2289 IP4_TXTOKEN_WRAP
*Wrap
;
2291 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
2294 // Return EFI_SUCCESS to check the next item in the map if
2295 // this one doesn't match.
2297 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
2301 Wrap
= (IP4_TXTOKEN_WRAP
*) Item
->Value
;
2302 ASSERT (Wrap
!= NULL
);
2305 // Don't access the Item, Wrap and Token's members after this point.
2306 // Item and wrap has been freed. And we no longer own the Token.
2308 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
2311 // If only one item is to be cancel, return EFI_ABORTED to stop
2312 // iterating the map any more.
2314 if (Token
!= NULL
) {
2323 Cancel the receive request. This is quiet simple, because
2324 it is only enqueued in our local receive map.
2326 @param[in] Map The IP4 child's receive queue
2327 @param[in] Item Current receive request to cancel.
2328 @param[in] Context The user's token to cancel
2330 @retval EFI_SUCCESS Continue to check the next receive request on the
2332 @retval EFI_ABORTED The user's token (token != NULL) has been
2340 IN NET_MAP_ITEM
*Item
,
2344 EFI_IP4_COMPLETION_TOKEN
*Token
;
2345 EFI_IP4_COMPLETION_TOKEN
*This
;
2347 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
2350 if ((Token
!= NULL
) && (Token
!= This
)) {
2354 NetMapRemoveItem (Map
, Item
, NULL
);
2356 This
->Status
= EFI_ABORTED
;
2357 This
->Packet
.RxData
= NULL
;
2358 gBS
->SignalEvent (This
->Event
);
2360 if (Token
!= NULL
) {
2369 Cancel the user's receive/transmit request.
2371 @param[in] IpInstance The IP4 child
2372 @param[in] Token The token to cancel. If NULL, all token will be
2375 @retval EFI_SUCCESS The token is cancelled
2376 @retval EFI_NOT_FOUND The token isn't found on either the
2377 transmit/receive queue
2378 @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.
2383 IN IP4_PROTOCOL
*IpInstance
,
2384 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2390 // First check the transmitted packet. Ip4CancelTxTokens returns
2391 // EFI_ABORTED to mean that the token has been cancelled when
2392 // token != NULL. So, return EFI_SUCCESS for this condition.
2394 Status
= NetMapIterate (&IpInstance
->TxTokens
, Ip4CancelTxTokens
, Token
);
2396 if (EFI_ERROR (Status
)) {
2397 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2405 // Check the receive queue. Ip4CancelRxTokens also returns EFI_ABORT
2406 // for Token!=NULL and it is cancelled.
2408 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4CancelRxTokens
, Token
);
2410 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
2414 if (EFI_ERROR (Status
)) {
2415 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2423 // OK, if the Token is found when Token != NULL, the NetMapIterate
2424 // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.
2426 if (Token
!= NULL
) {
2427 return EFI_NOT_FOUND
;
2431 // If Token == NULL, cancel all the tokens. return error if no
2432 // all of them are cancelled.
2434 if (!NetMapIsEmpty (&IpInstance
->TxTokens
) ||
2435 !NetMapIsEmpty (&IpInstance
->RxTokens
)) {
2437 return EFI_DEVICE_ERROR
;
2445 Abort an asynchronous transmit or receive request.
2447 The Cancel() function is used to abort a pending transmit or receive request.
2448 If the token is in the transmit or receive request queues, after calling this
2449 function, Token->Status will be set to EFI_ABORTED and then Token->Event will
2450 be signaled. If the token is not in one of the queues, which usually means the
2451 asynchronous operation has completed, this function will not signal the token
2452 and EFI_NOT_FOUND is returned.
2454 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2455 @param[in] Token Pointer to a token that has been issued by
2456 EFI_IP4_PROTOCOL.Transmit() or
2457 EFI_IP4_PROTOCOL.Receive(). If NULL, all pending
2458 tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is
2459 defined in EFI_IP4_PROTOCOL.Transmit().
2461 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
2462 Token.->Event was signaled. When Token is NULL, all
2463 pending requests were aborted and their events were signaled.
2464 @retval EFI_INVALID_PARAMETER This is NULL.
2465 @retval EFI_NOT_STARTED This instance has not been started.
2466 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2467 RARP, etc.) is not finished yet.
2468 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
2469 not found in the transmit or receive queue. It has either completed
2470 or was not issued by Transmit() and Receive().
2476 IN EFI_IP4_PROTOCOL
*This
,
2477 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2480 IP4_PROTOCOL
*IpInstance
;
2485 return EFI_INVALID_PARAMETER
;
2488 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2490 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2492 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
2493 Status
= EFI_NOT_STARTED
;
2497 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
2498 Status
= EFI_NO_MAPPING
;
2502 Status
= Ip4Cancel (IpInstance
, Token
);
2505 gBS
->RestoreTPL (OldTpl
);
2511 Polls for incoming data packets and processes outgoing data packets.
2513 The Poll() function polls for incoming data packets and processes outgoing data
2514 packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()
2515 function to increase the rate that data packets are moved between the communications
2516 device and the transmit and receive queues.
2518 In some systems the periodic timer event may not poll the underlying communications
2519 device fast enough to transmit and/or receive all data packets without missing
2520 incoming packets or dropping outgoing packets. Drivers and applications that are
2521 experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function
2524 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2526 @retval EFI_SUCCESS Incoming or outgoing data was processed.
2527 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2528 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2529 RARP, etc.) is not finished yet.
2530 @retval EFI_INVALID_PARAMETER This is NULL.
2531 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2532 @retval EFI_NOT_READY No incoming or outgoing data is processed.
2533 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
2534 Consider increasing the polling rate.
2540 IN EFI_IP4_PROTOCOL
*This
2543 IP4_PROTOCOL
*IpInstance
;
2544 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
2547 return EFI_INVALID_PARAMETER
;
2550 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2552 if (IpInstance
->State
== IP4_STATE_UNCONFIGED
) {
2553 return EFI_NOT_STARTED
;
2556 Mnp
= IpInstance
->Service
->Mnp
;
2559 // Don't lock the Poll function to enable the deliver of
2560 // the packet polled up.
2562 return Mnp
->Poll (Mnp
);
2566 Decrease the life of the transmitted packets. If it is
2567 decreased to zero, cancel the packet. This function is
2568 called by Ip4PacketTimerTicking which time out both the
2569 received-but-not-delivered and transmitted-but-not-recycle
2572 @param[in] Map The IP4 child's transmit map.
2573 @param[in] Item Current transmitted packet
2574 @param[in] Context Not used.
2576 @retval EFI_SUCCESS Always returns EFI_SUCCESS
2581 Ip4SentPacketTicking (
2583 IN NET_MAP_ITEM
*Item
,
2587 IP4_TXTOKEN_WRAP
*Wrap
;
2589 Wrap
= (IP4_TXTOKEN_WRAP
*) Item
->Value
;
2590 ASSERT (Wrap
!= NULL
);
2592 if ((Wrap
->Life
> 0) && (--Wrap
->Life
== 0)) {
2593 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
2601 The heart beat timer of IP4 service instance. It times out
2602 all of its IP4 children's received-but-not-delivered and
2603 transmitted-but-not-recycle packets, and provides time input
2604 for its IGMP protocol.
2606 @param[in] Event The IP4 service instance's heart beat timer.
2607 @param[in] Context The IP4 service instance.
2619 IpSb
= (IP4_SERVICE
*) Context
;
2620 NET_CHECK_SIGNATURE (IpSb
, IP4_SERVICE_SIGNATURE
);
2622 Ip4PacketTimerTicking (IpSb
);
2623 Ip4IgmpTicking (IpSb
);