3 Copyright (c) 2005 - 2017, 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 Intiialize the IP4_PROTOCOL structure to the unconfigured states.
536 @param IpSb The IP4 service instance.
537 @param IpInstance The IP4 child instance.
542 IN IP4_SERVICE
*IpSb
,
543 IN OUT IP4_PROTOCOL
*IpInstance
546 ASSERT ((IpSb
!= NULL
) && (IpInstance
!= NULL
));
548 ZeroMem (IpInstance
, sizeof (IP4_PROTOCOL
));
550 IpInstance
->Signature
= IP4_PROTOCOL_SIGNATURE
;
551 CopyMem (&IpInstance
->Ip4Proto
, &mEfiIp4ProtocolTemplete
, sizeof (IpInstance
->Ip4Proto
));
552 IpInstance
->State
= IP4_STATE_UNCONFIGED
;
553 IpInstance
->InDestroy
= FALSE
;
554 IpInstance
->Service
= IpSb
;
556 InitializeListHead (&IpInstance
->Link
);
557 NetMapInit (&IpInstance
->RxTokens
);
558 NetMapInit (&IpInstance
->TxTokens
);
559 InitializeListHead (&IpInstance
->Received
);
560 InitializeListHead (&IpInstance
->Delivered
);
561 InitializeListHead (&IpInstance
->AddrLink
);
563 EfiInitializeLock (&IpInstance
->RecycleLock
, TPL_NOTIFY
);
568 Configure the IP4 child. If the child is already configured,
569 change the configuration parameter. Otherwise configure it
570 for the first time. The caller should validate the configuration
571 before deliver them to it. It also don't do configure NULL.
573 @param[in, out] IpInstance The IP4 child to configure.
574 @param[in] Config The configure data.
576 @retval EFI_SUCCESS The IP4 child is successfully configured.
577 @retval EFI_DEVICE_ERROR Failed to free the pending transive or to
578 configure underlying MNP or other errors.
579 @retval EFI_NO_MAPPING The IP4 child is configured to use default
580 address, but the default address hasn't been
581 configured. The IP4 child doesn't need to be
582 reconfigured when default address is configured.
583 @retval EFI_OUT_OF_RESOURCES No more memory space is available.
584 @retval other Other error occurs.
589 IN OUT IP4_PROTOCOL
*IpInstance
,
590 IN EFI_IP4_CONFIG_DATA
*Config
598 EFI_ARP_PROTOCOL
*Arp
;
600 IpSb
= IpInstance
->Service
;
603 // User is changing packet filters. It must be stopped
604 // before the station address can be changed.
606 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
608 // Cancel all the pending transmit/receive from upper layer
610 Status
= Ip4Cancel (IpInstance
, NULL
);
612 if (EFI_ERROR (Status
)) {
613 return EFI_DEVICE_ERROR
;
616 CopyMem (&IpInstance
->ConfigData
, Config
, sizeof (IpInstance
->ConfigData
));
621 // Configure a fresh IP4 protocol instance. Create a route table.
622 // Each IP child has its own route table, which may point to the
623 // default table if it is using default address.
625 Status
= EFI_OUT_OF_RESOURCES
;
626 IpInstance
->RouteTable
= Ip4CreateRouteTable ();
628 if (IpInstance
->RouteTable
== NULL
) {
633 // Set up the interface.
635 CopyMem (&Ip
, &Config
->StationAddress
, sizeof (IP4_ADDR
));
636 CopyMem (&Netmask
, &Config
->SubnetMask
, sizeof (IP4_ADDR
));
639 Netmask
= NTOHL (Netmask
);
641 if (!Config
->UseDefaultAddress
) {
643 // Find whether there is already an interface with the same
644 // station address. All the instances with the same station
645 // address shares one interface.
647 IpIf
= Ip4FindStationAddress (IpSb
, Ip
, Netmask
);
653 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
659 Status
= Ip4SetAddress (IpIf
, Ip
, Netmask
);
661 if (EFI_ERROR (Status
)) {
662 Status
= EFI_DEVICE_ERROR
;
663 Ip4FreeInterface (IpIf
, IpInstance
);
667 InsertTailList (&IpSb
->Interfaces
, &IpIf
->Link
);
671 // Add a route to this connected network in the route table
673 Ip4AddRoute (IpInstance
->RouteTable
, Ip
, Netmask
, IP4_ALLZERO_ADDRESS
);
677 // Use the default address. Check the state.
679 if (IpSb
->State
== IP4_SERVICE_UNSTARTED
) {
680 Status
= Ip4StartAutoConfig (&IpSb
->Ip4Config2Instance
);
682 if (EFI_ERROR (Status
)) {
687 IpIf
= IpSb
->DefaultInterface
;
688 NET_GET_REF (IpSb
->DefaultInterface
);
691 // If default address is used, so is the default route table.
692 // Any route set by the instance has the precedence over the
693 // routes in the default route table. Link the default table
694 // after the instance's table. Routing will search the local
697 NET_GET_REF (IpSb
->DefaultRouteTable
);
698 IpInstance
->RouteTable
->Next
= IpSb
->DefaultRouteTable
;
701 IpInstance
->Interface
= IpIf
;
702 if (IpIf
->Arp
!= NULL
) {
704 Status
= gBS
->OpenProtocol (
706 &gEfiArpProtocolGuid
,
708 gIp4DriverBinding
.DriverBindingHandle
,
710 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
712 if (EFI_ERROR (Status
)) {
716 InsertTailList (&IpIf
->IpInstances
, &IpInstance
->AddrLink
);
718 CopyMem (&IpInstance
->ConfigData
, Config
, sizeof (IpInstance
->ConfigData
));
719 IpInstance
->State
= IP4_STATE_CONFIGED
;
722 // Although EFI_NO_MAPPING is an error code, the IP child has been
723 // successfully configured and doesn't need reconfiguration when
724 // default address is acquired.
726 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
727 return EFI_NO_MAPPING
;
733 Ip4FreeRouteTable (IpInstance
->RouteTable
);
734 IpInstance
->RouteTable
= NULL
;
740 Clean up the IP4 child, release all the resources used by it.
742 @param[in] IpInstance The IP4 child to clean up.
744 @retval EFI_SUCCESS The IP4 child is cleaned up.
745 @retval EFI_DEVICE_ERROR Some resources failed to be released.
750 IN IP4_PROTOCOL
*IpInstance
753 if (EFI_ERROR (Ip4Cancel (IpInstance
, NULL
))) {
754 return EFI_DEVICE_ERROR
;
757 if (EFI_ERROR (Ip4Groups (IpInstance
, FALSE
, NULL
))) {
758 return EFI_DEVICE_ERROR
;
762 // Some packets haven't been recycled. It is because either the
763 // user forgets to recycle the packets, or because the callback
764 // hasn't been called. Just leave it alone.
766 if (!IsListEmpty (&IpInstance
->Delivered
)) {
770 if (IpInstance
->Interface
!= NULL
) {
771 RemoveEntryList (&IpInstance
->AddrLink
);
772 if (IpInstance
->Interface
->Arp
!= NULL
) {
774 IpInstance
->Interface
->ArpHandle
,
775 &gEfiArpProtocolGuid
,
776 gIp4DriverBinding
.DriverBindingHandle
,
780 Ip4FreeInterface (IpInstance
->Interface
, IpInstance
);
781 IpInstance
->Interface
= NULL
;
784 if (IpInstance
->RouteTable
!= NULL
) {
785 if (IpInstance
->RouteTable
->Next
!= NULL
) {
786 Ip4FreeRouteTable (IpInstance
->RouteTable
->Next
);
789 Ip4FreeRouteTable (IpInstance
->RouteTable
);
790 IpInstance
->RouteTable
= NULL
;
793 if (IpInstance
->EfiRouteTable
!= NULL
) {
794 FreePool (IpInstance
->EfiRouteTable
);
795 IpInstance
->EfiRouteTable
= NULL
;
796 IpInstance
->EfiRouteCount
= 0;
799 if (IpInstance
->Groups
!= NULL
) {
800 FreePool (IpInstance
->Groups
);
801 IpInstance
->Groups
= NULL
;
802 IpInstance
->GroupCount
= 0;
805 NetMapClean (&IpInstance
->TxTokens
);
807 NetMapClean (&IpInstance
->RxTokens
);
814 Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
816 The Configure() function is used to set, change, or reset the operational
817 parameters and filter settings for this EFI IPv4 Protocol instance. Until these
818 parameters have been set, no network traffic can be sent or received by this
819 instance. Once the parameters have been reset (by calling this function with
820 IpConfigData set to NULL), no more traffic can be sent or received until these
821 parameters have been set again. Each EFI IPv4 Protocol instance can be started
822 and stopped independently of each other by enabling or disabling their receive
823 filter settings with the Configure() function.
825 When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will
826 be appended as an alias address into the addresses list in the EFI IPv4 Protocol
827 driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL
828 to retrieve the default IPv4 address if it is not available yet. Clients could
829 frequently call GetModeData() to check the status to ensure that the default IPv4
832 If operational parameters are reset or changed, any pending transmit and receive
833 requests will be cancelled. Their completion token status will be set to EFI_ABORTED
834 and their events will be signaled.
836 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
837 @param[in] IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.
839 @retval EFI_SUCCESS The driver instance was successfully opened.
840 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
841 RARP, etc.) is not finished yet.
842 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
843 @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:
844 A configuration protocol (DHCP, BOOTP, RARP, etc.) could
845 not be located when clients choose to use the default IPv4
846 address. This EFI IPv4 Protocol implementation does not
847 support this requested filter or timeout setting.
848 @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.
849 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the
850 IPv4 address or subnet mask can be changed. The interface must
851 also be stopped when switching to/from raw packet mode.
852 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4
853 Protocol driver instance is not opened.
859 IN EFI_IP4_PROTOCOL
*This
,
860 IN EFI_IP4_CONFIG_DATA
*IpConfigData OPTIONAL
863 IP4_PROTOCOL
*IpInstance
;
864 EFI_IP4_CONFIG_DATA
*Current
;
872 // First, validate the parameters
875 return EFI_INVALID_PARAMETER
;
878 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
879 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
882 // Validate the configuration first.
884 if (IpConfigData
!= NULL
) {
886 CopyMem (&IpAddress
, &IpConfigData
->StationAddress
, sizeof (IP4_ADDR
));
887 CopyMem (&SubnetMask
, &IpConfigData
->SubnetMask
, sizeof (IP4_ADDR
));
889 IpAddress
= NTOHL (IpAddress
);
890 SubnetMask
= NTOHL (SubnetMask
);
893 // Check whether the station address is a valid unicast address
895 if (!IpConfigData
->UseDefaultAddress
) {
896 AddrOk
= Ip4StationAddressValid (IpAddress
, SubnetMask
);
899 Status
= EFI_INVALID_PARAMETER
;
905 // User can only update packet filters when already configured.
906 // If it wants to change the station address, it must configure(NULL)
907 // the instance first.
909 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
910 Current
= &IpInstance
->ConfigData
;
912 if (Current
->UseDefaultAddress
!= IpConfigData
->UseDefaultAddress
) {
913 Status
= EFI_ALREADY_STARTED
;
917 if (!Current
->UseDefaultAddress
&&
918 (!EFI_IP4_EQUAL (&Current
->StationAddress
, &IpConfigData
->StationAddress
) ||
919 !EFI_IP4_EQUAL (&Current
->SubnetMask
, &IpConfigData
->SubnetMask
))) {
920 Status
= EFI_ALREADY_STARTED
;
924 if (Current
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
925 Status
= EFI_NO_MAPPING
;
932 // Configure the instance or clean it up.
934 if (IpConfigData
!= NULL
) {
935 Status
= Ip4ConfigProtocol (IpInstance
, IpConfigData
);
937 Status
= Ip4CleanProtocol (IpInstance
);
940 // Consider the following valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,
941 // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,
942 // the unload fails miserably.
944 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
945 IpInstance
->State
= IP4_STATE_UNCONFIGED
;
950 // Update the MNP's configure data. Ip4ServiceConfigMnp will check
951 // whether it is necessary to reconfigure the MNP.
953 Ip4ServiceConfigMnp (IpInstance
->Service
, FALSE
);
956 gBS
->RestoreTPL (OldTpl
);
963 Change the IP4 child's multicast setting. The caller
964 should make sure that the parameters is valid.
966 @param[in] IpInstance The IP4 child to change the setting.
967 @param[in] JoinFlag TRUE to join the group, otherwise leave it.
968 @param[in] GroupAddress The target group address.
970 @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it.
971 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
972 @retval EFI_DEVICE_ERROR Failed to set the group configuraton.
973 @retval EFI_SUCCESS Successfully updated the group setting.
974 @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.
979 IN IP4_PROTOCOL
*IpInstance
,
981 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
989 // Add it to the instance's Groups, and join the group by IGMP.
990 // IpInstance->Groups is in network byte order. IGMP operates in
995 // When JoinFlag is TRUE, GroupAddress shouldn't be NULL.
997 ASSERT (GroupAddress
!= NULL
);
998 CopyMem (&Group
, GroupAddress
, sizeof (IP4_ADDR
));
1000 for (Index
= 0; Index
< IpInstance
->GroupCount
; Index
++) {
1001 if (IpInstance
->Groups
[Index
] == Group
) {
1002 return EFI_ALREADY_STARTED
;
1006 Members
= Ip4CombineGroups (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1008 if (Members
== NULL
) {
1009 return EFI_OUT_OF_RESOURCES
;
1012 if (EFI_ERROR (Ip4JoinGroup (IpInstance
, NTOHL (Group
)))) {
1014 return EFI_DEVICE_ERROR
;
1017 if (IpInstance
->Groups
!= NULL
) {
1018 FreePool (IpInstance
->Groups
);
1021 IpInstance
->Groups
= Members
;
1022 IpInstance
->GroupCount
++;
1028 // Leave the group. Leave all the groups if GroupAddress is NULL.
1029 // Must iterate from the end to the beginning because the GroupCount
1030 // is decreamented each time an address is removed..
1032 for (Index
= IpInstance
->GroupCount
; Index
> 0 ; Index
--) {
1033 Group
= IpInstance
->Groups
[Index
- 1];
1035 if ((GroupAddress
== NULL
) || EFI_IP4_EQUAL (&Group
, GroupAddress
)) {
1036 if (EFI_ERROR (Ip4LeaveGroup (IpInstance
, NTOHL (Group
)))) {
1037 return EFI_DEVICE_ERROR
;
1040 Ip4RemoveGroupAddr (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1041 IpInstance
->GroupCount
--;
1043 if (IpInstance
->GroupCount
== 0) {
1044 ASSERT (Index
== 1);
1046 FreePool (IpInstance
->Groups
);
1047 IpInstance
->Groups
= NULL
;
1050 if (GroupAddress
!= NULL
) {
1056 return ((GroupAddress
!= NULL
) ? EFI_NOT_FOUND
: EFI_SUCCESS
);
1061 Joins and leaves multicast groups.
1063 The Groups() function is used to join and leave multicast group sessions. Joining
1064 a group will enable reception of matching multicast packets. Leaving a group will
1065 disable the multicast packet reception.
1067 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
1069 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1070 @param[in] JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.
1071 @param[in] GroupAddress Pointer to the IPv4 multicast address.
1073 @retval EFI_SUCCESS The operation completed successfully.
1074 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
1076 - JoinFlag is TRUE and GroupAddress is NULL.
1077 - GroupAddress is not NULL and *GroupAddress is
1078 not a multicast IPv4 address.
1079 @retval EFI_NOT_STARTED This instance has not been started.
1080 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1081 RARP, etc.) is not finished yet.
1082 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
1083 @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.
1084 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
1086 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
1087 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1093 IN EFI_IP4_PROTOCOL
*This
,
1094 IN BOOLEAN JoinFlag
,
1095 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
1098 IP4_PROTOCOL
*IpInstance
;
1103 if ((This
== NULL
) || (JoinFlag
&& (GroupAddress
== NULL
))) {
1104 return EFI_INVALID_PARAMETER
;
1107 if (GroupAddress
!= NULL
) {
1108 CopyMem (&McastIp
, GroupAddress
, sizeof (IP4_ADDR
));
1110 if (!IP4_IS_MULTICAST (NTOHL (McastIp
))) {
1111 return EFI_INVALID_PARAMETER
;
1115 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1116 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1118 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1119 Status
= EFI_NOT_STARTED
;
1123 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1124 Status
= EFI_NO_MAPPING
;
1128 Status
= Ip4Groups (IpInstance
, JoinFlag
, GroupAddress
);
1131 gBS
->RestoreTPL (OldTpl
);
1137 Adds and deletes routing table entries.
1139 The Routes() function adds a route to or deletes a route from the routing table.
1141 Routes are determined by comparing the SubnetAddress with the destination IPv4
1142 address arithmetically AND-ed with the SubnetMask. The gateway address must be
1143 on the same subnet as the configured station address.
1145 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
1146 The default route matches all destination IPv4 addresses that do not match any
1149 A GatewayAddress that is zero is a nonroute. Packets are sent to the destination
1150 IP address if it can be found in the ARP cache or on the local subnet. One automatic
1151 nonroute entry will be inserted into the routing table for outgoing packets that
1152 are addressed to a local subnet (gateway address of 0.0.0.0).
1154 Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI
1155 IPv4 Protocol instances that use the default IPv4 address will also have copies
1156 of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these
1157 copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its
1158 instances. As a result, client modification to the routing table will be lost.
1160 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1161 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
1162 FALSE to add this route to the routing table. SubnetAddress
1163 and SubnetMask are used as the key to each route entry.
1164 @param[in] SubnetAddress The address of the subnet that needs to be routed.
1165 @param[in] SubnetMask The subnet mask of SubnetAddress.
1166 @param[in] GatewayAddress The unicast gateway IPv4 address for this route.
1168 @retval EFI_SUCCESS The operation completed successfully.
1169 @retval EFI_NOT_STARTED The driver instance has not been started.
1170 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1171 RARP, etc.) is not finished yet.
1172 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1174 - SubnetAddress is NULL.
1175 - SubnetMask is NULL.
1176 - GatewayAddress is NULL.
1177 - *SubnetAddress is not a valid subnet address.
1178 - *SubnetMask is not a valid subnet mask.
1179 - *GatewayAddress is not a valid unicast IPv4 address.
1180 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
1181 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
1182 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
1183 DeleteRoute is FALSE).
1189 IN EFI_IP4_PROTOCOL
*This
,
1190 IN BOOLEAN DeleteRoute
,
1191 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
1192 IN EFI_IPv4_ADDRESS
*SubnetMask
,
1193 IN EFI_IPv4_ADDRESS
*GatewayAddress
1196 IP4_PROTOCOL
*IpInstance
;
1197 IP4_INTERFACE
*IpIf
;
1205 // First, validate the parameters
1207 if ((This
== NULL
) || (SubnetAddress
== NULL
) ||
1208 (SubnetMask
== NULL
) || (GatewayAddress
== NULL
)) {
1209 return EFI_INVALID_PARAMETER
;
1212 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1213 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1215 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1216 Status
= EFI_NOT_STARTED
;
1220 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1221 Status
= EFI_NO_MAPPING
;
1225 CopyMem (&Dest
, SubnetAddress
, sizeof (IP4_ADDR
));
1226 CopyMem (&Netmask
, SubnetMask
, sizeof (IP4_ADDR
));
1227 CopyMem (&Nexthop
, GatewayAddress
, sizeof (IP4_ADDR
));
1229 Dest
= NTOHL (Dest
);
1230 Netmask
= NTOHL (Netmask
);
1231 Nexthop
= NTOHL (Nexthop
);
1233 IpIf
= IpInstance
->Interface
;
1235 if (!IP4_IS_VALID_NETMASK (Netmask
)) {
1236 Status
= EFI_INVALID_PARAMETER
;
1241 // the gateway address must be a unicast on the connected network if not zero.
1243 if ((Nexthop
!= IP4_ALLZERO_ADDRESS
) &&
1244 (!IP4_NET_EQUAL (Nexthop
, IpIf
->Ip
, IpIf
->SubnetMask
) ||
1245 IP4_IS_BROADCAST (Ip4GetNetCast (Nexthop
, IpIf
)))) {
1247 Status
= EFI_INVALID_PARAMETER
;
1252 Status
= Ip4DelRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1254 Status
= Ip4AddRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1258 gBS
->RestoreTPL (OldTpl
);
1264 Check whether the user's token or event has already
1265 been enqueued on IP4's list.
1267 @param[in] Map The container of either user's transmit or receive
1269 @param[in] Item Current item to check against.
1270 @param[in] Context The Token to check againist.
1272 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP.
1273 @retval EFI_SUCCESS The current item isn't the same token/event as the
1281 IN NET_MAP_ITEM
*Item
,
1285 EFI_IP4_COMPLETION_TOKEN
*Token
;
1286 EFI_IP4_COMPLETION_TOKEN
*TokenInItem
;
1288 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
1289 TokenInItem
= (EFI_IP4_COMPLETION_TOKEN
*) Item
->Key
;
1291 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
1292 return EFI_ACCESS_DENIED
;
1299 Validate the user's token against current station address.
1301 @param[in] Token User's token to validate.
1302 @param[in] IpIf The IP4 child's interface.
1303 @param[in] RawData Set to TRUE to send unformatted packets.
1305 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
1306 @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.
1307 @retval EFI_SUCCESS The token is valid.
1312 IN EFI_IP4_COMPLETION_TOKEN
*Token
,
1313 IN IP4_INTERFACE
*IpIf
,
1317 EFI_IP4_TRANSMIT_DATA
*TxData
;
1318 EFI_IP4_OVERRIDE_DATA
*Override
;
1325 if ((Token
== NULL
) || (Token
->Event
== NULL
) || (Token
->Packet
.TxData
== NULL
)) {
1326 return EFI_INVALID_PARAMETER
;
1329 TxData
= Token
->Packet
.TxData
;
1332 // Check the fragment table: no empty fragment, and length isn't bogus.
1334 if ((TxData
->TotalDataLength
== 0) || (TxData
->FragmentCount
== 0)) {
1335 return EFI_INVALID_PARAMETER
;
1338 Offset
= TxData
->TotalDataLength
;
1340 if (Offset
> IP4_MAX_PACKET_SIZE
) {
1341 return EFI_BAD_BUFFER_SIZE
;
1344 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
1345 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
1346 (TxData
->FragmentTable
[Index
].FragmentLength
== 0)) {
1348 return EFI_INVALID_PARAMETER
;
1351 Offset
-= TxData
->FragmentTable
[Index
].FragmentLength
;
1355 return EFI_INVALID_PARAMETER
;
1359 // NOTE that OptionsLength/OptionsBuffer/OverrideData are ignored if RawData
1367 // Check the IP options: no more than 40 bytes and format is OK
1369 if (TxData
->OptionsLength
!= 0) {
1370 if ((TxData
->OptionsLength
> 40) || (TxData
->OptionsBuffer
== NULL
)) {
1371 return EFI_INVALID_PARAMETER
;
1374 if (!Ip4OptionIsValid (TxData
->OptionsBuffer
, TxData
->OptionsLength
, FALSE
)) {
1375 return EFI_INVALID_PARAMETER
;
1380 // Check the source and gateway: they must be a valid unicast.
1381 // Gateway must also be on the connected network.
1383 if (TxData
->OverrideData
!= NULL
) {
1384 Override
= TxData
->OverrideData
;
1386 CopyMem (&Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1387 CopyMem (&Gateway
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1390 Gateway
= NTOHL (Gateway
);
1392 if ((NetGetIpClass (Src
) > IP4_ADDR_CLASSC
) ||
1393 (Src
== IP4_ALLONE_ADDRESS
) ||
1394 IP4_IS_BROADCAST (Ip4GetNetCast (Src
, IpIf
))) {
1396 return EFI_INVALID_PARAMETER
;
1400 // If gateway isn't zero, it must be a unicast address, and
1401 // on the connected network.
1403 if ((Gateway
!= IP4_ALLZERO_ADDRESS
) &&
1404 ((NetGetIpClass (Gateway
) > IP4_ADDR_CLASSC
) ||
1405 !IP4_NET_EQUAL (Gateway
, IpIf
->Ip
, IpIf
->SubnetMask
) ||
1406 IP4_IS_BROADCAST (Ip4GetNetCast (Gateway
, IpIf
)))) {
1408 return EFI_INVALID_PARAMETER
;
1413 // Check the packet length: Head length and packet length all has a limit
1415 HeadLen
= sizeof (IP4_HEAD
) + ((TxData
->OptionsLength
+ 3) &~0x03);
1417 if ((HeadLen
> IP4_MAX_HEADLEN
) ||
1418 (TxData
->TotalDataLength
+ HeadLen
> IP4_MAX_PACKET_SIZE
)) {
1420 return EFI_BAD_BUFFER_SIZE
;
1428 The callback function for the net buffer which wraps the user's
1429 transmit token. Although it seems this function is pretty simple,
1430 there are some subtle things.
1431 When user requests the IP to transmit a packet by passing it a
1432 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data
1433 is wrapped in an net buffer. the net buffer's Free function is
1434 set to Ip4FreeTxToken. The Token and token wrap are added to the
1435 IP child's TxToken map. Then the buffer is passed to Ip4Output for
1436 transmission. If something error happened before that, the buffer
1437 is freed, which in turn will free the token wrap. The wrap may
1438 have been added to the TxToken map or not, and the user's event
1439 shouldn't be fired because we are still in the EfiIp4Transmit. If
1440 the buffer has been sent by Ip4Output, it should be removed from
1441 the TxToken map and user's event signaled. The token wrap and buffer
1442 are bound together. Check the comments in Ip4Output for information
1443 about IP fragmentation.
1445 @param[in] Context The token's wrap.
1454 IP4_TXTOKEN_WRAP
*Wrap
;
1457 Wrap
= (IP4_TXTOKEN_WRAP
*) Context
;
1460 // Signal IpSecRecycleEvent to inform IPsec free the memory
1462 if (Wrap
->IpSecRecycleSignal
!= NULL
) {
1463 gBS
->SignalEvent (Wrap
->IpSecRecycleSignal
);
1467 // Find the token in the instance's map. EfiIp4Transmit put the
1468 // token to the map. If that failed, NetMapFindKey will return NULL.
1470 Item
= NetMapFindKey (&Wrap
->IpInstance
->TxTokens
, Wrap
->Token
);
1473 NetMapRemoveItem (&Wrap
->IpInstance
->TxTokens
, Item
, NULL
);
1477 gBS
->SignalEvent (Wrap
->Token
->Event
);
1480 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
1490 The callback function to Ip4Output to update the transmit status.
1492 @param Ip4Instance The Ip4Instance that request the transmit.
1493 @param Packet The user's transmit request.
1494 @param IoStatus The result of the transmission.
1495 @param Flag Not used during transmission.
1496 @param Context The token's wrap.
1501 IP4_PROTOCOL
*Ip4Instance
,
1503 EFI_STATUS IoStatus
,
1508 IP4_TXTOKEN_WRAP
*Wrap
;
1511 // This is the transmission request from upper layer,
1512 // not the IP4 driver itself.
1514 ASSERT (Ip4Instance
!= NULL
);
1517 // The first fragment of the packet has been sent. Update
1518 // the token's status. That is, if fragmented, the transmit's
1519 // status is the first fragment's status. The Wrap will be
1520 // release when all the fragments are release. Check the comments
1521 // in Ip4FreeTxToken and Ip4Output for information.
1523 Wrap
= (IP4_TXTOKEN_WRAP
*) Context
;
1524 Wrap
->Token
->Status
= IoStatus
;
1526 NetbufFree (Wrap
->Packet
);
1531 Places outgoing data packets into the transmit queue.
1533 The Transmit() function places a sending request in the transmit queue of this
1534 EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some
1535 errors occur, the event in the token will be signaled and the status is updated.
1537 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1538 @param[in] Token Pointer to the transmit token.
1540 @retval EFI_SUCCESS The data has been queued for transmission.
1541 @retval EFI_NOT_STARTED This instance has not been started.
1542 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1543 RARP, etc.) is not finished yet.
1544 @retval EFI_INVALID_PARAMETER One or more pameters are invalid.
1545 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event
1546 was already in the transmit queue.
1547 @retval EFI_NOT_READY The completion token could not be queued because the transmit
1549 @retval EFI_NOT_FOUND Not route is found to destination address.
1550 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
1551 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
1553 @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is
1554 greater than MTU (or greater than the maximum packet size if
1555 Token.Packet.TxData.OverrideData.
1556 DoNotFragment is TRUE).
1562 IN EFI_IP4_PROTOCOL
*This
,
1563 IN EFI_IP4_COMPLETION_TOKEN
*Token
1567 IP4_PROTOCOL
*IpInstance
;
1568 IP4_INTERFACE
*IpIf
;
1569 IP4_TXTOKEN_WRAP
*Wrap
;
1570 EFI_IP4_TRANSMIT_DATA
*TxData
;
1571 EFI_IP4_CONFIG_DATA
*Config
;
1572 EFI_IP4_OVERRIDE_DATA
*Override
;
1577 BOOLEAN DontFragment
;
1580 UINT32 OptionsLength
;
1581 UINT8
*OptionsBuffer
;
1582 VOID
*FirstFragment
;
1585 return EFI_INVALID_PARAMETER
;
1588 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1590 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1591 return EFI_NOT_STARTED
;
1594 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1596 IpSb
= IpInstance
->Service
;
1597 IpIf
= IpInstance
->Interface
;
1598 Config
= &IpInstance
->ConfigData
;
1600 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1601 Status
= EFI_NO_MAPPING
;
1606 // make sure that token is properly formated
1608 Status
= Ip4TxTokenValid (Token
, IpIf
, Config
->RawData
);
1610 if (EFI_ERROR (Status
)) {
1615 // Check whether the token or signal already existed.
1617 if (EFI_ERROR (NetMapIterate (&IpInstance
->TxTokens
, Ip4TokenExist
, Token
))) {
1618 Status
= EFI_ACCESS_DENIED
;
1623 // Build the IP header, need to fill in the Tos, TotalLen, Id,
1624 // fragment, Ttl, protocol, Src, and Dst.
1626 TxData
= Token
->Packet
.TxData
;
1628 FirstFragment
= NULL
;
1630 if (Config
->RawData
) {
1632 // When RawData is TRUE, first buffer in FragmentTable points to a raw
1633 // IPv4 fragment including IPv4 header and options.
1635 FirstFragment
= TxData
->FragmentTable
[0].FragmentBuffer
;
1636 CopyMem (&RawHdrLen
, FirstFragment
, sizeof (UINT8
));
1638 RawHdrLen
= (UINT8
) (RawHdrLen
& 0x0f);
1639 if (RawHdrLen
< 5) {
1640 Status
= EFI_INVALID_PARAMETER
;
1644 RawHdrLen
= (UINT8
) (RawHdrLen
<< 2);
1646 CopyMem (&Head
, FirstFragment
, IP4_MIN_HEADLEN
);
1648 Ip4NtohHead (&Head
);
1650 DontFragment
= IP4_DO_NOT_FRAGMENT (Head
.Fragment
);
1652 if (!DontFragment
) {
1653 Status
= EFI_INVALID_PARAMETER
;
1657 GateWay
= IP4_ALLZERO_ADDRESS
;
1660 // Get IPv4 options from first fragment.
1662 if (RawHdrLen
== IP4_MIN_HEADLEN
) {
1664 OptionsBuffer
= NULL
;
1666 OptionsLength
= RawHdrLen
- IP4_MIN_HEADLEN
;
1667 OptionsBuffer
= (UINT8
*) FirstFragment
+ IP4_MIN_HEADLEN
;
1671 // Trim off IPv4 header and options from first fragment.
1673 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*) FirstFragment
+ RawHdrLen
;
1674 TxData
->FragmentTable
[0].FragmentLength
= TxData
->FragmentTable
[0].FragmentLength
- RawHdrLen
;
1676 CopyMem (&Head
.Dst
, &TxData
->DestinationAddress
, sizeof (IP4_ADDR
));
1677 Head
.Dst
= NTOHL (Head
.Dst
);
1679 if (TxData
->OverrideData
!= NULL
) {
1680 Override
= TxData
->OverrideData
;
1681 Head
.Protocol
= Override
->Protocol
;
1682 Head
.Tos
= Override
->TypeOfService
;
1683 Head
.Ttl
= Override
->TimeToLive
;
1684 DontFragment
= Override
->DoNotFragment
;
1686 CopyMem (&Head
.Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1687 CopyMem (&GateWay
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1689 Head
.Src
= NTOHL (Head
.Src
);
1690 GateWay
= NTOHL (GateWay
);
1692 Head
.Src
= IpIf
->Ip
;
1693 GateWay
= IP4_ALLZERO_ADDRESS
;
1694 Head
.Protocol
= Config
->DefaultProtocol
;
1695 Head
.Tos
= Config
->TypeOfService
;
1696 Head
.Ttl
= Config
->TimeToLive
;
1697 DontFragment
= Config
->DoNotFragment
;
1700 Head
.Fragment
= IP4_HEAD_FRAGMENT_FIELD (DontFragment
, FALSE
, 0);
1701 HeadLen
= (TxData
->OptionsLength
+ 3) & (~0x03);
1703 OptionsLength
= TxData
->OptionsLength
;
1704 OptionsBuffer
= (UINT8
*) (TxData
->OptionsBuffer
);
1708 // If don't fragment and fragment needed, return error
1710 if (DontFragment
&& (TxData
->TotalDataLength
+ HeadLen
> IpSb
->MaxPacketSize
)) {
1711 Status
= EFI_BAD_BUFFER_SIZE
;
1716 // OK, it survives all the validation check. Wrap the token in
1717 // a IP4_TXTOKEN_WRAP and the data in a netbuf
1719 Status
= EFI_OUT_OF_RESOURCES
;
1720 Wrap
= AllocateZeroPool (sizeof (IP4_TXTOKEN_WRAP
));
1725 Wrap
->IpInstance
= IpInstance
;
1726 Wrap
->Token
= Token
;
1728 Wrap
->Life
= IP4_US_TO_SEC (Config
->TransmitTimeout
);
1729 Wrap
->Packet
= NetbufFromExt (
1730 (NET_FRAGMENT
*) TxData
->FragmentTable
,
1731 TxData
->FragmentCount
,
1738 if (Wrap
->Packet
== NULL
) {
1743 Token
->Status
= EFI_NOT_READY
;
1745 if (EFI_ERROR (NetMapInsertTail (&IpInstance
->TxTokens
, Token
, Wrap
))) {
1747 // NetbufFree will call Ip4FreeTxToken, which in turn will
1748 // free the IP4_TXTOKEN_WRAP. Now, the token wrap hasn't been
1751 if (Config
->RawData
) {
1753 // Restore pointer of first fragment in RawData mode.
1755 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*) FirstFragment
;
1758 NetbufFree (Wrap
->Packet
);
1763 // Mark the packet sent before output it. Mark it not sent again if the
1764 // returned status is not EFI_SUCCESS;
1768 Status
= Ip4Output (
1780 if (EFI_ERROR (Status
)) {
1783 if (Config
->RawData
) {
1785 // Restore pointer of first fragment in RawData mode.
1787 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*) FirstFragment
;
1790 NetbufFree (Wrap
->Packet
);
1793 if (Config
->RawData
) {
1795 // Restore pointer of first fragment in RawData mode.
1797 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*) FirstFragment
;
1801 gBS
->RestoreTPL (OldTpl
);
1807 Places a receiving request into the receiving queue.
1809 The Receive() function places a completion token into the receive packet queue.
1810 This function is always asynchronous.
1812 The Token.Event field in the completion token must be filled in by the caller
1813 and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol
1814 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
1817 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1818 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
1820 @retval EFI_SUCCESS The receive completion token was cached.
1821 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
1822 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)
1823 is not finished yet.
1824 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1827 - Token.Event is NULL.
1828 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
1829 resources (usually memory).
1830 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1831 The EFI IPv4 Protocol instance has been reset to startup defaults.
1832 EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
1833 in the receive queue.
1834 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
1835 @retval EFI_ICMP_ERROR An ICMP error packet was received.
1841 IN EFI_IP4_PROTOCOL
*This
,
1842 IN EFI_IP4_COMPLETION_TOKEN
*Token
1845 IP4_PROTOCOL
*IpInstance
;
1850 // First validate the parameters
1852 if ((This
== NULL
) || (Token
== NULL
) || (Token
->Event
== NULL
)) {
1853 return EFI_INVALID_PARAMETER
;
1856 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1858 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1860 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1861 Status
= EFI_NOT_STARTED
;
1866 // Check whether the toke is already on the receive queue.
1868 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4TokenExist
, Token
);
1870 if (EFI_ERROR (Status
)) {
1871 Status
= EFI_ACCESS_DENIED
;
1876 // Queue the token then check whether there is pending received packet.
1878 Status
= NetMapInsertTail (&IpInstance
->RxTokens
, Token
, NULL
);
1880 if (EFI_ERROR (Status
)) {
1884 Status
= Ip4InstanceDeliverPacket (IpInstance
);
1887 // Dispatch the DPC queued by the NotifyFunction of this instane's receive
1893 gBS
->RestoreTPL (OldTpl
);
1899 Cancel the transmitted but not recycled packet. If a matching
1900 token is found, it will call Ip4CancelPacket to cancel the
1901 packet. Ip4CancelPacket will cancel all the fragments of the
1902 packet. When all the fragments are freed, the IP4_TXTOKEN_WRAP
1903 will be deleted from the Map, and user's event signalled.
1904 Because Ip4CancelPacket and other functions are all called in
1905 line, so, after Ip4CancelPacket returns, the Item has been freed.
1907 @param[in] Map The IP4 child's transmit queue.
1908 @param[in] Item The current transmitted packet to test.
1909 @param[in] Context The user's token to cancel.
1911 @retval EFI_SUCCESS Continue to check the next Item.
1912 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
1919 IN NET_MAP_ITEM
*Item
,
1923 EFI_IP4_COMPLETION_TOKEN
*Token
;
1924 IP4_TXTOKEN_WRAP
*Wrap
;
1926 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
1929 // Return EFI_SUCCESS to check the next item in the map if
1930 // this one doesn't match.
1932 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
1936 Wrap
= (IP4_TXTOKEN_WRAP
*) Item
->Value
;
1937 ASSERT (Wrap
!= NULL
);
1940 // Don't access the Item, Wrap and Token's members after this point.
1941 // Item and wrap has been freed. And we no longer own the Token.
1943 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
1946 // If only one item is to be cancel, return EFI_ABORTED to stop
1947 // iterating the map any more.
1949 if (Token
!= NULL
) {
1958 Cancel the receive request. This is quiet simple, because
1959 it is only enqueued in our local receive map.
1961 @param[in] Map The IP4 child's receive queue.
1962 @param[in] Item Current receive request to cancel.
1963 @param[in] Context The user's token to cancel.
1965 @retval EFI_SUCCESS Continue to check the next receive request on the
1967 @retval EFI_ABORTED The user's token (token != NULL) has been
1975 IN NET_MAP_ITEM
*Item
,
1979 EFI_IP4_COMPLETION_TOKEN
*Token
;
1980 EFI_IP4_COMPLETION_TOKEN
*This
;
1982 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
1985 if ((Token
!= NULL
) && (Token
!= This
)) {
1989 NetMapRemoveItem (Map
, Item
, NULL
);
1991 This
->Status
= EFI_ABORTED
;
1992 This
->Packet
.RxData
= NULL
;
1993 gBS
->SignalEvent (This
->Event
);
1995 if (Token
!= NULL
) {
2004 Cancel the user's receive/transmit request.
2006 @param[in] IpInstance The IP4 child.
2007 @param[in] Token The token to cancel. If NULL, all token will be
2010 @retval EFI_SUCCESS The token is cancelled.
2011 @retval EFI_NOT_FOUND The token isn't found on either the
2012 transmit/receive queue.
2013 @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.
2018 IN IP4_PROTOCOL
*IpInstance
,
2019 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2025 // First check the transmitted packet. Ip4CancelTxTokens returns
2026 // EFI_ABORTED to mean that the token has been cancelled when
2027 // token != NULL. So, return EFI_SUCCESS for this condition.
2029 Status
= NetMapIterate (&IpInstance
->TxTokens
, Ip4CancelTxTokens
, Token
);
2031 if (EFI_ERROR (Status
)) {
2032 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2040 // Check the receive queue. Ip4CancelRxTokens also returns EFI_ABORT
2041 // for Token!=NULL and it is cancelled.
2043 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4CancelRxTokens
, Token
);
2045 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
2049 if (EFI_ERROR (Status
)) {
2050 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2058 // OK, if the Token is found when Token != NULL, the NetMapIterate
2059 // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.
2061 if (Token
!= NULL
) {
2062 return EFI_NOT_FOUND
;
2066 // If Token == NULL, cancel all the tokens. return error if no
2067 // all of them are cancelled.
2069 if (!NetMapIsEmpty (&IpInstance
->TxTokens
) ||
2070 !NetMapIsEmpty (&IpInstance
->RxTokens
)) {
2072 return EFI_DEVICE_ERROR
;
2080 Abort an asynchronous transmit or receive request.
2082 The Cancel() function is used to abort a pending transmit or receive request.
2083 If the token is in the transmit or receive request queues, after calling this
2084 function, Token->Status will be set to EFI_ABORTED and then Token->Event will
2085 be signaled. If the token is not in one of the queues, which usually means the
2086 asynchronous operation has completed, this function will not signal the token
2087 and EFI_NOT_FOUND is returned.
2089 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2090 @param[in] Token Pointer to a token that has been issued by
2091 EFI_IP4_PROTOCOL.Transmit() or
2092 EFI_IP4_PROTOCOL.Receive(). If NULL, all pending
2093 tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is
2094 defined in EFI_IP4_PROTOCOL.Transmit().
2096 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
2097 Token.->Event was signaled. When Token is NULL, all
2098 pending requests were aborted and their events were signaled.
2099 @retval EFI_INVALID_PARAMETER This is NULL.
2100 @retval EFI_NOT_STARTED This instance has not been started.
2101 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2102 RARP, etc.) is not finished yet.
2103 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
2104 not found in the transmit or receive queue. It has either completed
2105 or was not issued by Transmit() and Receive().
2111 IN EFI_IP4_PROTOCOL
*This
,
2112 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2115 IP4_PROTOCOL
*IpInstance
;
2120 return EFI_INVALID_PARAMETER
;
2123 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2125 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2127 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
2128 Status
= EFI_NOT_STARTED
;
2132 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
2133 Status
= EFI_NO_MAPPING
;
2137 Status
= Ip4Cancel (IpInstance
, Token
);
2140 gBS
->RestoreTPL (OldTpl
);
2146 Polls for incoming data packets and processes outgoing data packets.
2148 The Poll() function polls for incoming data packets and processes outgoing data
2149 packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()
2150 function to increase the rate that data packets are moved between the communications
2151 device and the transmit and receive queues.
2153 In some systems the periodic timer event may not poll the underlying communications
2154 device fast enough to transmit and/or receive all data packets without missing
2155 incoming packets or dropping outgoing packets. Drivers and applications that are
2156 experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function
2159 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2161 @retval EFI_SUCCESS Incoming or outgoing data was processed.
2162 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2163 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2164 RARP, etc.) is not finished yet.
2165 @retval EFI_INVALID_PARAMETER This is NULL.
2166 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2167 @retval EFI_NOT_READY No incoming or outgoing data is processed.
2168 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
2169 Consider increasing the polling rate.
2175 IN EFI_IP4_PROTOCOL
*This
2178 IP4_PROTOCOL
*IpInstance
;
2179 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
2182 return EFI_INVALID_PARAMETER
;
2185 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2187 if (IpInstance
->State
== IP4_STATE_UNCONFIGED
) {
2188 return EFI_NOT_STARTED
;
2191 Mnp
= IpInstance
->Service
->Mnp
;
2194 // Don't lock the Poll function to enable the deliver of
2195 // the packet polled up.
2197 return Mnp
->Poll (Mnp
);
2201 Decrease the life of the transmitted packets. If it is
2202 decreased to zero, cancel the packet. This function is
2203 called by Ip4PacketTimerTicking which time out both the
2204 received-but-not-delivered and transmitted-but-not-recycle
2207 @param[in] Map The IP4 child's transmit map.
2208 @param[in] Item Current transmitted packet.
2209 @param[in] Context Not used.
2211 @retval EFI_SUCCESS Always returns EFI_SUCCESS.
2216 Ip4SentPacketTicking (
2218 IN NET_MAP_ITEM
*Item
,
2222 IP4_TXTOKEN_WRAP
*Wrap
;
2224 Wrap
= (IP4_TXTOKEN_WRAP
*) Item
->Value
;
2225 ASSERT (Wrap
!= NULL
);
2227 if ((Wrap
->Life
> 0) && (--Wrap
->Life
== 0)) {
2228 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
2236 There are two steps for this the heart beat timer of IP4 service instance.
2237 First, it times out all of its IP4 children's received-but-not-delivered
2238 and transmitted-but-not-recycle packets, and provides time input for its
2240 Second, a dedicated timer is used to poll underlying media status. In case
2241 of cable swap, a new round auto configuration will be initiated. The timer
2242 will signal the IP4 to run DHCP configuration again. IP4 driver will free
2243 old IP address related resource, such as route table and Interface, then
2244 initiate a DHCP process to acquire new IP, eventually create route table
2247 @param[in] Event The IP4 service instance's heart beat timer.
2248 @param[in] Context The IP4 service instance.
2259 BOOLEAN OldMediaPresent
;
2261 EFI_SIMPLE_NETWORK_MODE SnpModeData
;
2263 IpSb
= (IP4_SERVICE
*) Context
;
2264 NET_CHECK_SIGNATURE (IpSb
, IP4_SERVICE_SIGNATURE
);
2266 OldMediaPresent
= IpSb
->MediaPresent
;
2268 Ip4PacketTimerTicking (IpSb
);
2269 Ip4IgmpTicking (IpSb
);
2272 // Get fresh mode data from MNP, since underlying media status may change.
2273 // Here, it needs to mention that the MediaPresent can also be checked even if
2274 // EFI_NOT_STARTED returned while this MNP child driver instance isn't configured.
2276 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, NULL
, &SnpModeData
);
2277 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
2281 IpSb
->MediaPresent
= SnpModeData
.MediaPresent
;
2283 // Media transimit Unpresent to Present means new link movement is detected.
2285 if (!OldMediaPresent
&& IpSb
->MediaPresent
&& (IpSb
->Ip4Config2Instance
.Policy
== Ip4Config2PolicyDhcp
)) {
2287 // Signal the IP4 to run the dhcp configuration again. IP4 driver will free
2288 // old IP address related resource, such as route table and Interface, then
2289 // initiate a DHCP round to acquire new IP, eventually
2290 // create route table for new IP address.
2292 if (IpSb
->ReconfigEvent
!= NULL
) {
2293 Status
= gBS
->SignalEvent (IpSb
->ReconfigEvent
);