3 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
10 EFI_IPSEC2_PROTOCOL
*mIpSec
= NULL
;
13 Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.
15 The GetModeData() function returns the current operational mode data for this
16 driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This
17 function is used optionally to retrieve the operational mode data of underlying
20 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
21 @param[out] Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.
22 @param[out] MnpConfigData Pointer to the managed network configuration data structure.
23 @param[out] SnpModeData Pointer to the simple network mode data structure.
25 @retval EFI_SUCCESS The operation completed successfully.
26 @retval EFI_INVALID_PARAMETER This is NULL.
27 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
33 IN CONST EFI_IP4_PROTOCOL
*This
,
34 OUT EFI_IP4_MODE_DATA
*Ip4ModeData OPTIONAL
,
35 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
36 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
40 Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
42 The Configure() function is used to set, change, or reset the operational
43 parameters and filter settings for this EFI IPv4 Protocol instance. Until these
44 parameters have been set, no network traffic can be sent or received by this
45 instance. Once the parameters have been reset (by calling this function with
46 IpConfigData set to NULL), no more traffic can be sent or received until these
47 parameters have been set again. Each EFI IPv4 Protocol instance can be started
48 and stopped independently of each other by enabling or disabling their receive
49 filter settings with the Configure() function.
51 When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will
52 be appended as an alias address into the addresses list in the EFI IPv4 Protocol
53 driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL
54 to retrieve the default IPv4 address if it is not available yet. Clients could
55 frequently call GetModeData() to check the status to ensure that the default IPv4
58 If operational parameters are reset or changed, any pending transmit and receive
59 requests will be cancelled. Their completion token status will be set to EFI_ABORTED
60 and their events will be signaled.
62 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
63 @param[in] IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.
65 @retval EFI_SUCCESS The driver instance was successfully opened.
66 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
67 RARP, etc.) is not finished yet.
68 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
69 @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:
70 A configuration protocol (DHCP, BOOTP, RARP, etc.) could
71 not be located when clients choose to use the default IPv4
72 address. This EFI IPv4 Protocol implementation does not
73 support this requested filter or timeout setting.
74 @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.
75 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the
76 IPv4 address or subnet mask can be changed. The interface must
77 also be stopped when switching to/from raw packet mode.
78 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4
79 Protocol driver instance is not opened.
85 IN EFI_IP4_PROTOCOL
*This
,
86 IN EFI_IP4_CONFIG_DATA
*IpConfigData OPTIONAL
90 Joins and leaves multicast groups.
92 The Groups() function is used to join and leave multicast group sessions. Joining
93 a group will enable reception of matching multicast packets. Leaving a group will
94 disable the multicast packet reception.
96 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
98 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
99 @param[in] JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.
100 @param[in] GroupAddress Pointer to the IPv4 multicast address.
102 @retval EFI_SUCCESS The operation completed successfully.
103 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
105 - JoinFlag is TRUE and GroupAddress is NULL.
106 - GroupAddress is not NULL and *GroupAddress is
107 not a multicast IPv4 address.
108 @retval EFI_NOT_STARTED This instance has not been started.
109 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
110 RARP, etc.) is not finished yet.
111 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
112 @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.
113 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
115 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
116 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
122 IN EFI_IP4_PROTOCOL
*This
,
124 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
128 Adds and deletes routing table entries.
130 The Routes() function adds a route to or deletes a route from the routing table.
132 Routes are determined by comparing the SubnetAddress with the destination IPv4
133 address arithmetically AND-ed with the SubnetMask. The gateway address must be
134 on the same subnet as the configured station address.
136 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
137 The default route matches all destination IPv4 addresses that do not match any
140 A GatewayAddress that is zero is a nonroute. Packets are sent to the destination
141 IP address if it can be found in the ARP cache or on the local subnet. One automatic
142 nonroute entry will be inserted into the routing table for outgoing packets that
143 are addressed to a local subnet (gateway address of 0.0.0.0).
145 Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI
146 IPv4 Protocol instances that use the default IPv4 address will also have copies
147 of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these
148 copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its
149 instances. As a result, client modification to the routing table will be lost.
151 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
152 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
153 FALSE to add this route to the routing table. SubnetAddress
154 and SubnetMask are used as the key to each route entry.
155 @param[in] SubnetAddress The address of the subnet that needs to be routed.
156 @param[in] SubnetMask The subnet mask of SubnetAddress.
157 @param[in] GatewayAddress The unicast gateway IPv4 address for this route.
159 @retval EFI_SUCCESS The operation completed successfully.
160 @retval EFI_NOT_STARTED The driver instance has not been started.
161 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
162 RARP, etc.) is not finished yet.
163 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
165 - SubnetAddress is NULL.
166 - SubnetMask is NULL.
167 - GatewayAddress is NULL.
168 - *SubnetAddress is not a valid subnet address.
169 - *SubnetMask is not a valid subnet mask.
170 - *GatewayAddress is not a valid unicast IPv4 address.
171 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
172 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
173 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
174 DeleteRoute is FALSE).
180 IN EFI_IP4_PROTOCOL
*This
,
181 IN BOOLEAN DeleteRoute
,
182 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
183 IN EFI_IPv4_ADDRESS
*SubnetMask
,
184 IN EFI_IPv4_ADDRESS
*GatewayAddress
188 Places outgoing data packets into the transmit queue.
190 The Transmit() function places a sending request in the transmit queue of this
191 EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some
192 errors occur, the event in the token will be signaled and the status is updated.
194 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
195 @param[in] Token Pointer to the transmit token.
197 @retval EFI_SUCCESS The data has been queued for transmission.
198 @retval EFI_NOT_STARTED This instance has not been started.
199 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
200 RARP, etc.) is not finished yet.
201 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
202 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event
203 was already in the transmit queue.
204 @retval EFI_NOT_READY The completion token could not be queued because the transmit
206 @retval EFI_NOT_FOUND Not route is found to destination address.
207 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
208 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
210 @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is
211 greater than MTU (or greater than the maximum packet size if
212 Token.Packet.TxData.OverrideData.
213 DoNotFragment is TRUE.)
219 IN EFI_IP4_PROTOCOL
*This
,
220 IN EFI_IP4_COMPLETION_TOKEN
*Token
224 Places a receiving request into the receiving queue.
226 The Receive() function places a completion token into the receive packet queue.
227 This function is always asynchronous.
229 The Token.Event field in the completion token must be filled in by the caller
230 and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol
231 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
234 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
235 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
237 @retval EFI_SUCCESS The receive completion token was cached.
238 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
239 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)
241 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
244 - Token.Event is NULL.
245 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
246 resources (usually memory).
247 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
248 The EFI IPv4 Protocol instance has been reset to startup defaults.
249 EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
250 in the receive queue.
251 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
252 @retval EFI_ICMP_ERROR An ICMP error packet was received.
258 IN EFI_IP4_PROTOCOL
*This
,
259 IN EFI_IP4_COMPLETION_TOKEN
*Token
263 Abort an asynchronous transmit or receive request.
265 The Cancel() function is used to abort a pending transmit or receive request.
266 If the token is in the transmit or receive request queues, after calling this
267 function, Token->Status will be set to EFI_ABORTED and then Token->Event will
268 be signaled. If the token is not in one of the queues, which usually means the
269 asynchronous operation has completed, this function will not signal the token
270 and EFI_NOT_FOUND is returned.
272 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
273 @param[in] Token Pointer to a token that has been issued by
274 EFI_IP4_PROTOCOL.Transmit() or
275 EFI_IP4_PROTOCOL.Receive(). If NULL, all pending
276 tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is
277 defined in EFI_IP4_PROTOCOL.Transmit().
279 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
280 Token.->Event was signaled. When Token is NULL, all
281 pending requests were aborted and their events were signaled.
282 @retval EFI_INVALID_PARAMETER This is NULL.
283 @retval EFI_NOT_STARTED This instance has not been started.
284 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
285 RARP, etc.) is not finished yet.
286 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
287 not found in the transmit or receive queue. It has either completed
288 or was not issued by Transmit() and Receive().
294 IN EFI_IP4_PROTOCOL
*This
,
295 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
299 Polls for incoming data packets and processes outgoing data packets.
301 The Poll() function polls for incoming data packets and processes outgoing data
302 packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()
303 function to increase the rate that data packets are moved between the communications
304 device and the transmit and receive queues.
306 In some systems the periodic timer event may not poll the underlying communications
307 device fast enough to transmit and/or receive all data packets without missing
308 incoming packets or dropping outgoing packets. Drivers and applications that are
309 experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function
312 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
314 @retval EFI_SUCCESS Incoming or outgoing data was processed.
315 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
316 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
317 RARP, etc.) is not finished yet.
318 @retval EFI_INVALID_PARAMETER This is NULL.
319 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
320 @retval EFI_NOT_READY No incoming or outgoing data is processed.
321 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
322 Consider increasing the polling rate.
328 IN EFI_IP4_PROTOCOL
*This
332 mEfiIp4ProtocolTemplete
= {
344 Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.
346 The GetModeData() function returns the current operational mode data for this
347 driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This
348 function is used optionally to retrieve the operational mode data of underlying
351 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
352 @param[out] Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.
353 @param[out] MnpConfigData Pointer to the managed network configuration data structure.
354 @param[out] SnpModeData Pointer to the simple network mode data structure.
356 @retval EFI_SUCCESS The operation completed successfully.
357 @retval EFI_INVALID_PARAMETER This is NULL.
358 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
364 IN CONST EFI_IP4_PROTOCOL
*This
,
365 OUT EFI_IP4_MODE_DATA
*Ip4ModeData OPTIONAL
,
366 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
367 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
370 IP4_PROTOCOL
*IpInstance
;
372 EFI_IP4_CONFIG_DATA
*Config
;
378 return EFI_INVALID_PARAMETER
;
381 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
382 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
383 IpSb
= IpInstance
->Service
;
385 if (Ip4ModeData
!= NULL
) {
387 // IsStarted is "whether the EfiIp4Configure has been called".
388 // IsConfigured is "whether the station address has been configured"
390 Ip4ModeData
->IsStarted
= (BOOLEAN
)(IpInstance
->State
== IP4_STATE_CONFIGED
);
391 CopyMem (&Ip4ModeData
->ConfigData
, &IpInstance
->ConfigData
, sizeof (Ip4ModeData
->ConfigData
));
392 Ip4ModeData
->IsConfigured
= FALSE
;
394 Ip4ModeData
->GroupCount
= IpInstance
->GroupCount
;
395 Ip4ModeData
->GroupTable
= (EFI_IPv4_ADDRESS
*)IpInstance
->Groups
;
397 Ip4ModeData
->IcmpTypeCount
= 23;
398 Ip4ModeData
->IcmpTypeList
= mIp4SupportedIcmp
;
400 Ip4ModeData
->RouteTable
= NULL
;
401 Ip4ModeData
->RouteCount
= 0;
403 Ip4ModeData
->MaxPacketSize
= IpSb
->MaxPacketSize
;
406 // return the current station address for this IP child. So,
407 // the user can get the default address through this. Some
408 // application wants to know it station address even it is
409 // using the default one, such as a ftp server.
411 if (Ip4ModeData
->IsStarted
) {
412 Config
= &Ip4ModeData
->ConfigData
;
414 Ip
= HTONL (IpInstance
->Interface
->Ip
);
415 CopyMem (&Config
->StationAddress
, &Ip
, sizeof (EFI_IPv4_ADDRESS
));
417 Ip
= HTONL (IpInstance
->Interface
->SubnetMask
);
418 CopyMem (&Config
->SubnetMask
, &Ip
, sizeof (EFI_IPv4_ADDRESS
));
420 Ip4ModeData
->IsConfigured
= IpInstance
->Interface
->Configured
;
423 // Build a EFI route table for user from the internal route table.
425 Status
= Ip4BuildEfiRouteTable (IpInstance
);
427 if (EFI_ERROR (Status
)) {
428 gBS
->RestoreTPL (OldTpl
);
432 Ip4ModeData
->RouteTable
= IpInstance
->EfiRouteTable
;
433 Ip4ModeData
->RouteCount
= IpInstance
->EfiRouteCount
;
438 // Get fresh mode data from MNP, since underlying media status may change
440 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, MnpConfigData
, SnpModeData
);
442 gBS
->RestoreTPL (OldTpl
);
447 Config the MNP parameter used by IP. The IP driver use one MNP
448 child to transmit/receive frames. By default, it configures MNP
449 to receive unicast/multicast/broadcast. And it will enable/disable
450 the promiscous receive according to whether there is IP child
451 enable that or not. If Force is FALSE, it will iterate through
452 all the IP children to check whether the promiscuous receive
453 setting has been changed. If it hasn't been changed, it won't
454 reconfigure the MNP. If Force is TRUE, the MNP is configured no
455 matter whether that is changed or not.
457 @param[in] IpSb The IP4 service instance that is to be changed.
458 @param[in] Force Force the configuration or not.
460 @retval EFI_SUCCESS The MNP is successfully configured/reconfigured.
461 @retval Others Configuration failed.
465 Ip4ServiceConfigMnp (
466 IN IP4_SERVICE
*IpSb
,
471 LIST_ENTRY
*ProtoEntry
;
473 IP4_PROTOCOL
*IpInstance
;
475 BOOLEAN PromiscReceive
;
479 PromiscReceive
= FALSE
;
483 // Iterate through the IP children to check whether promiscuous
484 // receive setting has been changed. Update the interface's receive
487 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
488 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP4_INTERFACE
, Link
);
489 IpIf
->PromiscRecv
= FALSE
;
491 NET_LIST_FOR_EACH (ProtoEntry
, &IpIf
->IpInstances
) {
492 IpInstance
= NET_LIST_USER_STRUCT (ProtoEntry
, IP4_PROTOCOL
, AddrLink
);
494 if (IpInstance
->ConfigData
.AcceptPromiscuous
) {
495 IpIf
->PromiscRecv
= TRUE
;
496 PromiscReceive
= TRUE
;
502 // If promiscuous receive isn't changed, it isn't necessary to reconfigure.
504 if (PromiscReceive
== IpSb
->MnpConfigData
.EnablePromiscuousReceive
) {
509 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= PromiscReceive
;
512 Status
= IpSb
->Mnp
->Configure (IpSb
->Mnp
, &IpSb
->MnpConfigData
);
515 // recover the original configuration if failed to set the configure.
517 if (EFI_ERROR (Status
) && Reconfig
) {
518 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= (BOOLEAN
) !PromiscReceive
;
525 Initialize the IP4_PROTOCOL structure to the unconfigured states.
527 @param IpSb The IP4 service instance.
528 @param IpInstance The IP4 child instance.
533 IN IP4_SERVICE
*IpSb
,
534 IN OUT IP4_PROTOCOL
*IpInstance
537 ASSERT ((IpSb
!= NULL
) && (IpInstance
!= NULL
));
539 ZeroMem (IpInstance
, sizeof (IP4_PROTOCOL
));
541 IpInstance
->Signature
= IP4_PROTOCOL_SIGNATURE
;
542 CopyMem (&IpInstance
->Ip4Proto
, &mEfiIp4ProtocolTemplete
, sizeof (IpInstance
->Ip4Proto
));
543 IpInstance
->State
= IP4_STATE_UNCONFIGED
;
544 IpInstance
->InDestroy
= FALSE
;
545 IpInstance
->Service
= IpSb
;
547 InitializeListHead (&IpInstance
->Link
);
548 NetMapInit (&IpInstance
->RxTokens
);
549 NetMapInit (&IpInstance
->TxTokens
);
550 InitializeListHead (&IpInstance
->Received
);
551 InitializeListHead (&IpInstance
->Delivered
);
552 InitializeListHead (&IpInstance
->AddrLink
);
554 EfiInitializeLock (&IpInstance
->RecycleLock
, TPL_NOTIFY
);
558 Configure the IP4 child. If the child is already configured,
559 change the configuration parameter. Otherwise configure it
560 for the first time. The caller should validate the configuration
561 before deliver them to it. It also don't do configure NULL.
563 @param[in, out] IpInstance The IP4 child to configure.
564 @param[in] Config The configure data.
566 @retval EFI_SUCCESS The IP4 child is successfully configured.
567 @retval EFI_DEVICE_ERROR Failed to free the pending transive or to
568 configure underlying MNP or other errors.
569 @retval EFI_NO_MAPPING The IP4 child is configured to use default
570 address, but the default address hasn't been
571 configured. The IP4 child doesn't need to be
572 reconfigured when default address is configured.
573 @retval EFI_OUT_OF_RESOURCES No more memory space is available.
574 @retval other Other error occurs.
579 IN OUT IP4_PROTOCOL
*IpInstance
,
580 IN EFI_IP4_CONFIG_DATA
*Config
588 EFI_ARP_PROTOCOL
*Arp
;
589 EFI_IP4_CONFIG2_PROTOCOL
*Ip4Config2
;
590 EFI_IP4_CONFIG2_POLICY Policy
;
592 IpSb
= IpInstance
->Service
;
597 // User is changing packet filters. It must be stopped
598 // before the station address can be changed.
600 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
602 // Cancel all the pending transmit/receive from upper layer
604 Status
= Ip4Cancel (IpInstance
, NULL
);
606 if (EFI_ERROR (Status
)) {
607 return EFI_DEVICE_ERROR
;
610 CopyMem (&IpInstance
->ConfigData
, Config
, sizeof (IpInstance
->ConfigData
));
615 // Configure a fresh IP4 protocol instance. Create a route table.
616 // Each IP child has its own route table, which may point to the
617 // default table if it is using default address.
619 Status
= EFI_OUT_OF_RESOURCES
;
620 IpInstance
->RouteTable
= Ip4CreateRouteTable ();
622 if (IpInstance
->RouteTable
== NULL
) {
627 // Set up the interface.
629 CopyMem (&Ip
, &Config
->StationAddress
, sizeof (IP4_ADDR
));
630 CopyMem (&Netmask
, &Config
->SubnetMask
, sizeof (IP4_ADDR
));
633 Netmask
= NTOHL (Netmask
);
635 if (!Config
->UseDefaultAddress
) {
637 // Find whether there is already an interface with the same
638 // station address. All the instances with the same station
639 // address shares one interface.
641 IpIf
= Ip4FindStationAddress (IpSb
, Ip
, Netmask
);
646 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
652 Status
= Ip4SetAddress (IpIf
, Ip
, Netmask
);
654 if (EFI_ERROR (Status
)) {
655 Status
= EFI_DEVICE_ERROR
;
656 Ip4FreeInterface (IpIf
, IpInstance
);
660 InsertTailList (&IpSb
->Interfaces
, &IpIf
->Link
);
664 // Add a route to this connected network in the instance route table.
667 IpInstance
->RouteTable
,
674 // Use the default address. Check the state.
676 if (IpSb
->State
== IP4_SERVICE_UNSTARTED
) {
678 // Trigger the EFI_IP4_CONFIG2_PROTOCOL to retrieve the
679 // default IPv4 address if it is not available yet.
681 Policy
= IpSb
->Ip4Config2Instance
.Policy
;
682 if (Policy
!= Ip4Config2PolicyDhcp
) {
683 Ip4Config2
= &IpSb
->Ip4Config2Instance
.Ip4Config2
;
684 Policy
= Ip4Config2PolicyDhcp
;
685 Status
= Ip4Config2
->SetData (
687 Ip4Config2DataTypePolicy
,
688 sizeof (EFI_IP4_CONFIG2_POLICY
),
691 if (EFI_ERROR (Status
)) {
697 IpIf
= IpSb
->DefaultInterface
;
698 NET_GET_REF (IpSb
->DefaultInterface
);
701 // If default address is used, so is the default route table.
702 // Any route set by the instance has the precedence over the
703 // routes in the default route table. Link the default table
704 // after the instance's table. Routing will search the local
707 NET_GET_REF (IpSb
->DefaultRouteTable
);
708 IpInstance
->RouteTable
->Next
= IpSb
->DefaultRouteTable
;
711 IpInstance
->Interface
= IpIf
;
712 if (IpIf
->Arp
!= NULL
) {
714 Status
= gBS
->OpenProtocol (
716 &gEfiArpProtocolGuid
,
718 gIp4DriverBinding
.DriverBindingHandle
,
720 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
722 if (EFI_ERROR (Status
)) {
723 Ip4FreeInterface (IpIf
, IpInstance
);
728 InsertTailList (&IpIf
->IpInstances
, &IpInstance
->AddrLink
);
730 CopyMem (&IpInstance
->ConfigData
, Config
, sizeof (IpInstance
->ConfigData
));
731 IpInstance
->State
= IP4_STATE_CONFIGED
;
734 // Although EFI_NO_MAPPING is an error code, the IP child has been
735 // successfully configured and doesn't need reconfiguration when
736 // default address is acquired.
738 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
739 return EFI_NO_MAPPING
;
745 Ip4FreeRouteTable (IpInstance
->RouteTable
);
746 IpInstance
->RouteTable
= NULL
;
751 Clean up the IP4 child, release all the resources used by it.
753 @param[in] IpInstance The IP4 child to clean up.
755 @retval EFI_SUCCESS The IP4 child is cleaned up.
756 @retval EFI_DEVICE_ERROR Some resources failed to be released.
761 IN IP4_PROTOCOL
*IpInstance
764 if (EFI_ERROR (Ip4Cancel (IpInstance
, NULL
))) {
765 return EFI_DEVICE_ERROR
;
768 if (EFI_ERROR (Ip4Groups (IpInstance
, FALSE
, NULL
))) {
769 return EFI_DEVICE_ERROR
;
773 // Some packets haven't been recycled. It is because either the
774 // user forgets to recycle the packets, or because the callback
775 // hasn't been called. Just leave it alone.
777 if (!IsListEmpty (&IpInstance
->Delivered
)) {
780 if (IpInstance
->Interface
!= NULL
) {
781 RemoveEntryList (&IpInstance
->AddrLink
);
782 if (IpInstance
->Interface
->Arp
!= NULL
) {
784 IpInstance
->Interface
->ArpHandle
,
785 &gEfiArpProtocolGuid
,
786 gIp4DriverBinding
.DriverBindingHandle
,
791 Ip4FreeInterface (IpInstance
->Interface
, IpInstance
);
792 IpInstance
->Interface
= NULL
;
795 if (IpInstance
->RouteTable
!= NULL
) {
796 if (IpInstance
->RouteTable
->Next
!= NULL
) {
797 Ip4FreeRouteTable (IpInstance
->RouteTable
->Next
);
800 Ip4FreeRouteTable (IpInstance
->RouteTable
);
801 IpInstance
->RouteTable
= NULL
;
804 if (IpInstance
->EfiRouteTable
!= NULL
) {
805 FreePool (IpInstance
->EfiRouteTable
);
806 IpInstance
->EfiRouteTable
= NULL
;
807 IpInstance
->EfiRouteCount
= 0;
810 if (IpInstance
->Groups
!= NULL
) {
811 FreePool (IpInstance
->Groups
);
812 IpInstance
->Groups
= NULL
;
813 IpInstance
->GroupCount
= 0;
816 NetMapClean (&IpInstance
->TxTokens
);
818 NetMapClean (&IpInstance
->RxTokens
);
824 Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
826 The Configure() function is used to set, change, or reset the operational
827 parameters and filter settings for this EFI IPv4 Protocol instance. Until these
828 parameters have been set, no network traffic can be sent or received by this
829 instance. Once the parameters have been reset (by calling this function with
830 IpConfigData set to NULL), no more traffic can be sent or received until these
831 parameters have been set again. Each EFI IPv4 Protocol instance can be started
832 and stopped independently of each other by enabling or disabling their receive
833 filter settings with the Configure() function.
835 When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will
836 be appended as an alias address into the addresses list in the EFI IPv4 Protocol
837 driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL
838 to retrieve the default IPv4 address if it is not available yet. Clients could
839 frequently call GetModeData() to check the status to ensure that the default IPv4
842 If operational parameters are reset or changed, any pending transmit and receive
843 requests will be cancelled. Their completion token status will be set to EFI_ABORTED
844 and their events will be signaled.
846 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
847 @param[in] IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.
849 @retval EFI_SUCCESS The driver instance was successfully opened.
850 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
851 RARP, etc.) is not finished yet.
852 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
853 @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:
854 A configuration protocol (DHCP, BOOTP, RARP, etc.) could
855 not be located when clients choose to use the default IPv4
856 address. This EFI IPv4 Protocol implementation does not
857 support this requested filter or timeout setting.
858 @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.
859 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the
860 IPv4 address or subnet mask can be changed. The interface must
861 also be stopped when switching to/from raw packet mode.
862 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4
863 Protocol driver instance is not opened.
869 IN EFI_IP4_PROTOCOL
*This
,
870 IN EFI_IP4_CONFIG_DATA
*IpConfigData OPTIONAL
873 IP4_PROTOCOL
*IpInstance
;
874 EFI_IP4_CONFIG_DATA
*Current
;
882 // First, validate the parameters
885 return EFI_INVALID_PARAMETER
;
888 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
889 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
892 // Validate the configuration first.
894 if (IpConfigData
!= NULL
) {
895 CopyMem (&IpAddress
, &IpConfigData
->StationAddress
, sizeof (IP4_ADDR
));
896 CopyMem (&SubnetMask
, &IpConfigData
->SubnetMask
, sizeof (IP4_ADDR
));
898 IpAddress
= NTOHL (IpAddress
);
899 SubnetMask
= NTOHL (SubnetMask
);
902 // Check whether the station address is a valid unicast address
904 if (!IpConfigData
->UseDefaultAddress
) {
905 AddrOk
= Ip4StationAddressValid (IpAddress
, SubnetMask
);
908 Status
= EFI_INVALID_PARAMETER
;
914 // User can only update packet filters when already configured.
915 // If it wants to change the station address, it must configure(NULL)
916 // the instance first.
918 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
919 Current
= &IpInstance
->ConfigData
;
921 if (Current
->UseDefaultAddress
!= IpConfigData
->UseDefaultAddress
) {
922 Status
= EFI_ALREADY_STARTED
;
926 if (!Current
->UseDefaultAddress
&&
927 (!EFI_IP4_EQUAL (&Current
->StationAddress
, &IpConfigData
->StationAddress
) ||
928 !EFI_IP4_EQUAL (&Current
->SubnetMask
, &IpConfigData
->SubnetMask
)))
930 Status
= EFI_ALREADY_STARTED
;
934 if (Current
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
935 Status
= EFI_NO_MAPPING
;
942 // Configure the instance or clean it up.
944 if (IpConfigData
!= NULL
) {
945 Status
= Ip4ConfigProtocol (IpInstance
, IpConfigData
);
947 Status
= Ip4CleanProtocol (IpInstance
);
950 // Consider the following valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,
951 // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,
952 // the unload fails miserably.
954 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
955 IpInstance
->State
= IP4_STATE_UNCONFIGED
;
960 // Update the MNP's configure data. Ip4ServiceConfigMnp will check
961 // whether it is necessary to reconfigure the MNP.
963 Ip4ServiceConfigMnp (IpInstance
->Service
, FALSE
);
966 gBS
->RestoreTPL (OldTpl
);
971 Change the IP4 child's multicast setting. The caller
972 should make sure that the parameters is valid.
974 @param[in] IpInstance The IP4 child to change the setting.
975 @param[in] JoinFlag TRUE to join the group, otherwise leave it.
976 @param[in] GroupAddress The target group address.
978 @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it.
979 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
980 @retval EFI_DEVICE_ERROR Failed to set the group configuration.
981 @retval EFI_SUCCESS Successfully updated the group setting.
982 @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.
987 IN IP4_PROTOCOL
*IpInstance
,
989 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
997 // Add it to the instance's Groups, and join the group by IGMP.
998 // IpInstance->Groups is in network byte order. IGMP operates in
1003 // When JoinFlag is TRUE, GroupAddress shouldn't be NULL.
1005 ASSERT (GroupAddress
!= NULL
);
1006 CopyMem (&Group
, GroupAddress
, sizeof (IP4_ADDR
));
1008 for (Index
= 0; Index
< IpInstance
->GroupCount
; Index
++) {
1009 if (IpInstance
->Groups
[Index
] == Group
) {
1010 return EFI_ALREADY_STARTED
;
1014 Members
= Ip4CombineGroups (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1016 if (Members
== NULL
) {
1017 return EFI_OUT_OF_RESOURCES
;
1020 if (EFI_ERROR (Ip4JoinGroup (IpInstance
, NTOHL (Group
)))) {
1022 return EFI_DEVICE_ERROR
;
1025 if (IpInstance
->Groups
!= NULL
) {
1026 FreePool (IpInstance
->Groups
);
1029 IpInstance
->Groups
= Members
;
1030 IpInstance
->GroupCount
++;
1036 // Leave the group. Leave all the groups if GroupAddress is NULL.
1037 // Must iterate from the end to the beginning because the GroupCount
1038 // is decremented each time an address is removed..
1040 for (Index
= IpInstance
->GroupCount
; Index
> 0; Index
--) {
1041 ASSERT (IpInstance
->Groups
!= NULL
);
1042 Group
= IpInstance
->Groups
[Index
- 1];
1043 if ((GroupAddress
== NULL
) || EFI_IP4_EQUAL (&Group
, GroupAddress
)) {
1044 if (EFI_ERROR (Ip4LeaveGroup (IpInstance
, NTOHL (Group
)))) {
1045 return EFI_DEVICE_ERROR
;
1048 Ip4RemoveGroupAddr (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1049 IpInstance
->GroupCount
--;
1051 if (IpInstance
->GroupCount
== 0) {
1052 ASSERT (Index
== 1);
1054 FreePool (IpInstance
->Groups
);
1055 IpInstance
->Groups
= NULL
;
1058 if (GroupAddress
!= NULL
) {
1064 return ((GroupAddress
!= NULL
) ? EFI_NOT_FOUND
: EFI_SUCCESS
);
1068 Joins and leaves multicast groups.
1070 The Groups() function is used to join and leave multicast group sessions. Joining
1071 a group will enable reception of matching multicast packets. Leaving a group will
1072 disable the multicast packet reception.
1074 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
1076 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1077 @param[in] JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.
1078 @param[in] GroupAddress Pointer to the IPv4 multicast address.
1080 @retval EFI_SUCCESS The operation completed successfully.
1081 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
1083 - JoinFlag is TRUE and GroupAddress is NULL.
1084 - GroupAddress is not NULL and *GroupAddress is
1085 not a multicast IPv4 address.
1086 @retval EFI_NOT_STARTED This instance has not been started.
1087 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1088 RARP, etc.) is not finished yet.
1089 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
1090 @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.
1091 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
1093 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
1094 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1100 IN EFI_IP4_PROTOCOL
*This
,
1101 IN BOOLEAN JoinFlag
,
1102 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
1105 IP4_PROTOCOL
*IpInstance
;
1110 if ((This
== NULL
) || (JoinFlag
&& (GroupAddress
== NULL
))) {
1111 return EFI_INVALID_PARAMETER
;
1114 if (GroupAddress
!= NULL
) {
1115 CopyMem (&McastIp
, GroupAddress
, sizeof (IP4_ADDR
));
1117 if (!IP4_IS_MULTICAST (NTOHL (McastIp
))) {
1118 return EFI_INVALID_PARAMETER
;
1122 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1123 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1125 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1126 Status
= EFI_NOT_STARTED
;
1130 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1131 Status
= EFI_NO_MAPPING
;
1135 Status
= Ip4Groups (IpInstance
, JoinFlag
, GroupAddress
);
1138 gBS
->RestoreTPL (OldTpl
);
1143 Adds and deletes routing table entries.
1145 The Routes() function adds a route to or deletes a route from the routing table.
1147 Routes are determined by comparing the SubnetAddress with the destination IPv4
1148 address arithmetically AND-ed with the SubnetMask. The gateway address must be
1149 on the same subnet as the configured station address.
1151 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
1152 The default route matches all destination IPv4 addresses that do not match any
1155 A GatewayAddress that is zero is a nonroute. Packets are sent to the destination
1156 IP address if it can be found in the ARP cache or on the local subnet. One automatic
1157 nonroute entry will be inserted into the routing table for outgoing packets that
1158 are addressed to a local subnet (gateway address of 0.0.0.0).
1160 Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI
1161 IPv4 Protocol instances that use the default IPv4 address will also have copies
1162 of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these
1163 copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its
1164 instances. As a result, client modification to the routing table will be lost.
1166 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1167 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
1168 FALSE to add this route to the routing table. SubnetAddress
1169 and SubnetMask are used as the key to each route entry.
1170 @param[in] SubnetAddress The address of the subnet that needs to be routed.
1171 @param[in] SubnetMask The subnet mask of SubnetAddress.
1172 @param[in] GatewayAddress The unicast gateway IPv4 address for this route.
1174 @retval EFI_SUCCESS The operation completed successfully.
1175 @retval EFI_NOT_STARTED The driver instance has not been started.
1176 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1177 RARP, etc.) is not finished yet.
1178 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1180 - SubnetAddress is NULL.
1181 - SubnetMask is NULL.
1182 - GatewayAddress is NULL.
1183 - *SubnetAddress is not a valid subnet address.
1184 - *SubnetMask is not a valid subnet mask.
1185 - *GatewayAddress is not a valid unicast IPv4 address.
1186 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
1187 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
1188 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
1189 DeleteRoute is FALSE).
1195 IN EFI_IP4_PROTOCOL
*This
,
1196 IN BOOLEAN DeleteRoute
,
1197 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
1198 IN EFI_IPv4_ADDRESS
*SubnetMask
,
1199 IN EFI_IPv4_ADDRESS
*GatewayAddress
1202 IP4_PROTOCOL
*IpInstance
;
1203 IP4_INTERFACE
*IpIf
;
1211 // First, validate the parameters
1213 if ((This
== NULL
) || (SubnetAddress
== NULL
) ||
1214 (SubnetMask
== NULL
) || (GatewayAddress
== NULL
))
1216 return EFI_INVALID_PARAMETER
;
1219 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1220 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1222 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1223 Status
= EFI_NOT_STARTED
;
1227 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1228 Status
= EFI_NO_MAPPING
;
1232 CopyMem (&Dest
, SubnetAddress
, sizeof (IP4_ADDR
));
1233 CopyMem (&Netmask
, SubnetMask
, sizeof (IP4_ADDR
));
1234 CopyMem (&Nexthop
, GatewayAddress
, sizeof (IP4_ADDR
));
1236 Dest
= NTOHL (Dest
);
1237 Netmask
= NTOHL (Netmask
);
1238 Nexthop
= NTOHL (Nexthop
);
1240 IpIf
= IpInstance
->Interface
;
1242 if (!IP4_IS_VALID_NETMASK (Netmask
)) {
1243 Status
= EFI_INVALID_PARAMETER
;
1248 // the gateway address must be a unicast on the connected network if not zero.
1250 if ((Nexthop
!= IP4_ALLZERO_ADDRESS
) &&
1251 (((IpIf
->SubnetMask
!= IP4_ALLONE_ADDRESS
) && !IP4_NET_EQUAL (Nexthop
, IpIf
->Ip
, IpIf
->SubnetMask
)) ||
1252 IP4_IS_BROADCAST (Ip4GetNetCast (Nexthop
, IpIf
))))
1254 Status
= EFI_INVALID_PARAMETER
;
1259 Status
= Ip4DelRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1261 Status
= Ip4AddRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1265 gBS
->RestoreTPL (OldTpl
);
1270 Check whether the user's token or event has already
1271 been enqueued on IP4's list.
1273 @param[in] Map The container of either user's transmit or receive
1275 @param[in] Item Current item to check against.
1276 @param[in] Context The Token to check against.
1278 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP.
1279 @retval EFI_SUCCESS The current item isn't the same token/event as the
1287 IN NET_MAP_ITEM
*Item
,
1291 EFI_IP4_COMPLETION_TOKEN
*Token
;
1292 EFI_IP4_COMPLETION_TOKEN
*TokenInItem
;
1294 Token
= (EFI_IP4_COMPLETION_TOKEN
*)Context
;
1295 TokenInItem
= (EFI_IP4_COMPLETION_TOKEN
*)Item
->Key
;
1297 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
1298 return EFI_ACCESS_DENIED
;
1305 Validate the user's token against current station address.
1307 @param[in] Token User's token to validate.
1308 @param[in] IpIf The IP4 child's interface.
1309 @param[in] RawData Set to TRUE to send unformatted packets.
1311 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
1312 @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.
1313 @retval EFI_SUCCESS The token is valid.
1318 IN EFI_IP4_COMPLETION_TOKEN
*Token
,
1319 IN IP4_INTERFACE
*IpIf
,
1323 EFI_IP4_TRANSMIT_DATA
*TxData
;
1324 EFI_IP4_OVERRIDE_DATA
*Override
;
1331 if ((Token
== NULL
) || (Token
->Event
== NULL
) || (Token
->Packet
.TxData
== NULL
)) {
1332 return EFI_INVALID_PARAMETER
;
1335 TxData
= Token
->Packet
.TxData
;
1338 // Check the fragment table: no empty fragment, and length isn't bogus.
1340 if ((TxData
->TotalDataLength
== 0) || (TxData
->FragmentCount
== 0)) {
1341 return EFI_INVALID_PARAMETER
;
1344 Offset
= TxData
->TotalDataLength
;
1346 if (Offset
> IP4_MAX_PACKET_SIZE
) {
1347 return EFI_BAD_BUFFER_SIZE
;
1350 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
1351 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
1352 (TxData
->FragmentTable
[Index
].FragmentLength
== 0))
1354 return EFI_INVALID_PARAMETER
;
1357 Offset
-= TxData
->FragmentTable
[Index
].FragmentLength
;
1361 return EFI_INVALID_PARAMETER
;
1365 // NOTE that OptionsLength/OptionsBuffer/OverrideData are ignored if RawData
1373 // Check the IP options: no more than 40 bytes and format is OK
1375 if (TxData
->OptionsLength
!= 0) {
1376 if ((TxData
->OptionsLength
> 40) || (TxData
->OptionsBuffer
== NULL
)) {
1377 return EFI_INVALID_PARAMETER
;
1380 if (!Ip4OptionIsValid (TxData
->OptionsBuffer
, TxData
->OptionsLength
, FALSE
)) {
1381 return EFI_INVALID_PARAMETER
;
1386 // Check the source and gateway: they must be a valid unicast.
1387 // Gateway must also be on the connected network.
1389 if (TxData
->OverrideData
!= NULL
) {
1390 Override
= TxData
->OverrideData
;
1392 CopyMem (&Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1393 CopyMem (&Gateway
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1396 Gateway
= NTOHL (Gateway
);
1398 if ((NetGetIpClass (Src
) > IP4_ADDR_CLASSC
) ||
1399 (Src
== IP4_ALLONE_ADDRESS
) ||
1400 IP4_IS_BROADCAST (Ip4GetNetCast (Src
, IpIf
)))
1402 return EFI_INVALID_PARAMETER
;
1406 // If gateway isn't zero, it must be a unicast address, and
1407 // on the connected network.
1409 if ((Gateway
!= IP4_ALLZERO_ADDRESS
) &&
1410 ((NetGetIpClass (Gateway
) > IP4_ADDR_CLASSC
) ||
1411 !IP4_NET_EQUAL (Gateway
, IpIf
->Ip
, IpIf
->SubnetMask
) ||
1412 IP4_IS_BROADCAST (Ip4GetNetCast (Gateway
, IpIf
))))
1414 return EFI_INVALID_PARAMETER
;
1419 // Check the packet length: Head length and packet length all has a limit
1421 HeadLen
= sizeof (IP4_HEAD
) + ((TxData
->OptionsLength
+ 3) &~0x03);
1423 if ((HeadLen
> IP4_MAX_HEADLEN
) ||
1424 (TxData
->TotalDataLength
+ HeadLen
> IP4_MAX_PACKET_SIZE
))
1426 return EFI_BAD_BUFFER_SIZE
;
1433 The callback function for the net buffer which wraps the user's
1434 transmit token. Although it seems this function is pretty simple,
1435 there are some subtle things.
1436 When user requests the IP to transmit a packet by passing it a
1437 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data
1438 is wrapped in an net buffer. the net buffer's Free function is
1439 set to Ip4FreeTxToken. The Token and token wrap are added to the
1440 IP child's TxToken map. Then the buffer is passed to Ip4Output for
1441 transmission. If something error happened before that, the buffer
1442 is freed, which in turn will free the token wrap. The wrap may
1443 have been added to the TxToken map or not, and the user's event
1444 shouldn't be fired because we are still in the EfiIp4Transmit. If
1445 the buffer has been sent by Ip4Output, it should be removed from
1446 the TxToken map and user's event signaled. The token wrap and buffer
1447 are bound together. Check the comments in Ip4Output for information
1448 about IP fragmentation.
1450 @param[in] Context The token's wrap.
1459 IP4_TXTOKEN_WRAP
*Wrap
;
1462 Wrap
= (IP4_TXTOKEN_WRAP
*)Context
;
1465 // Signal IpSecRecycleEvent to inform IPsec free the memory
1467 if (Wrap
->IpSecRecycleSignal
!= NULL
) {
1468 gBS
->SignalEvent (Wrap
->IpSecRecycleSignal
);
1472 // Find the token in the instance's map. EfiIp4Transmit put the
1473 // token to the map. If that failed, NetMapFindKey will return NULL.
1475 Item
= NetMapFindKey (&Wrap
->IpInstance
->TxTokens
, Wrap
->Token
);
1478 NetMapRemoveItem (&Wrap
->IpInstance
->TxTokens
, Item
, NULL
);
1482 gBS
->SignalEvent (Wrap
->Token
->Event
);
1485 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
1494 The callback function to Ip4Output to update the transmit status.
1496 @param Ip4Instance The Ip4Instance that request the transmit.
1497 @param Packet The user's transmit request.
1498 @param IoStatus The result of the transmission.
1499 @param Flag Not used during transmission.
1500 @param Context The token's wrap.
1505 IP4_PROTOCOL
*Ip4Instance
,
1507 EFI_STATUS IoStatus
,
1512 IP4_TXTOKEN_WRAP
*Wrap
;
1515 // This is the transmission request from upper layer,
1516 // not the IP4 driver itself.
1518 ASSERT (Ip4Instance
!= NULL
);
1521 // The first fragment of the packet has been sent. Update
1522 // the token's status. That is, if fragmented, the transmit's
1523 // status is the first fragment's status. The Wrap will be
1524 // release when all the fragments are release. Check the comments
1525 // in Ip4FreeTxToken and Ip4Output for information.
1527 Wrap
= (IP4_TXTOKEN_WRAP
*)Context
;
1528 Wrap
->Token
->Status
= IoStatus
;
1530 NetbufFree (Wrap
->Packet
);
1534 Places outgoing data packets into the transmit queue.
1536 The Transmit() function places a sending request in the transmit queue of this
1537 EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some
1538 errors occur, the event in the token will be signaled and the status is updated.
1540 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1541 @param[in] Token Pointer to the transmit token.
1543 @retval EFI_SUCCESS The data has been queued for transmission.
1544 @retval EFI_NOT_STARTED This instance has not been started.
1545 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1546 RARP, etc.) is not finished yet.
1547 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1548 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event
1549 was already in the transmit queue.
1550 @retval EFI_NOT_READY The completion token could not be queued because the transmit
1552 @retval EFI_NOT_FOUND Not route is found to destination address.
1553 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
1554 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
1556 @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is
1557 greater than MTU (or greater than the maximum packet size if
1558 Token.Packet.TxData.OverrideData.
1559 DoNotFragment is TRUE).
1565 IN EFI_IP4_PROTOCOL
*This
,
1566 IN EFI_IP4_COMPLETION_TOKEN
*Token
1570 IP4_PROTOCOL
*IpInstance
;
1571 IP4_INTERFACE
*IpIf
;
1572 IP4_TXTOKEN_WRAP
*Wrap
;
1573 EFI_IP4_TRANSMIT_DATA
*TxData
;
1574 EFI_IP4_CONFIG_DATA
*Config
;
1575 EFI_IP4_OVERRIDE_DATA
*Override
;
1580 BOOLEAN DontFragment
;
1583 UINT32 OptionsLength
;
1584 UINT8
*OptionsBuffer
;
1585 VOID
*FirstFragment
;
1588 return EFI_INVALID_PARAMETER
;
1591 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1593 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1594 return EFI_NOT_STARTED
;
1597 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1599 IpSb
= IpInstance
->Service
;
1600 IpIf
= IpInstance
->Interface
;
1601 Config
= &IpInstance
->ConfigData
;
1603 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1604 Status
= EFI_NO_MAPPING
;
1609 // make sure that token is properly formatted
1611 Status
= Ip4TxTokenValid (Token
, IpIf
, Config
->RawData
);
1613 if (EFI_ERROR (Status
)) {
1618 // Check whether the token or signal already existed.
1620 if (EFI_ERROR (NetMapIterate (&IpInstance
->TxTokens
, Ip4TokenExist
, Token
))) {
1621 Status
= EFI_ACCESS_DENIED
;
1626 // Build the IP header, need to fill in the Tos, TotalLen, Id,
1627 // fragment, Ttl, protocol, Src, and Dst.
1629 TxData
= Token
->Packet
.TxData
;
1631 FirstFragment
= NULL
;
1633 if (Config
->RawData
) {
1635 // When RawData is TRUE, first buffer in FragmentTable points to a raw
1636 // IPv4 fragment including IPv4 header and options.
1638 FirstFragment
= TxData
->FragmentTable
[0].FragmentBuffer
;
1639 CopyMem (&RawHdrLen
, FirstFragment
, sizeof (UINT8
));
1641 RawHdrLen
= (UINT8
)(RawHdrLen
& 0x0f);
1642 if (RawHdrLen
< 5) {
1643 Status
= EFI_INVALID_PARAMETER
;
1647 RawHdrLen
= (UINT8
)(RawHdrLen
<< 2);
1649 CopyMem (&Head
, FirstFragment
, IP4_MIN_HEADLEN
);
1651 Ip4NtohHead (&Head
);
1653 DontFragment
= IP4_DO_NOT_FRAGMENT (Head
.Fragment
);
1655 if (!DontFragment
) {
1656 Status
= EFI_INVALID_PARAMETER
;
1660 GateWay
= IP4_ALLZERO_ADDRESS
;
1663 // Get IPv4 options from first fragment.
1665 if (RawHdrLen
== IP4_MIN_HEADLEN
) {
1667 OptionsBuffer
= NULL
;
1669 OptionsLength
= RawHdrLen
- IP4_MIN_HEADLEN
;
1670 OptionsBuffer
= (UINT8
*)FirstFragment
+ IP4_MIN_HEADLEN
;
1674 // Trim off IPv4 header and options from first fragment.
1676 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*)FirstFragment
+ RawHdrLen
;
1677 TxData
->FragmentTable
[0].FragmentLength
= TxData
->FragmentTable
[0].FragmentLength
- RawHdrLen
;
1679 CopyMem (&Head
.Dst
, &TxData
->DestinationAddress
, sizeof (IP4_ADDR
));
1680 Head
.Dst
= NTOHL (Head
.Dst
);
1682 if (TxData
->OverrideData
!= NULL
) {
1683 Override
= TxData
->OverrideData
;
1684 Head
.Protocol
= Override
->Protocol
;
1685 Head
.Tos
= Override
->TypeOfService
;
1686 Head
.Ttl
= Override
->TimeToLive
;
1687 DontFragment
= Override
->DoNotFragment
;
1689 CopyMem (&Head
.Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1690 CopyMem (&GateWay
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1692 Head
.Src
= NTOHL (Head
.Src
);
1693 GateWay
= NTOHL (GateWay
);
1695 Head
.Src
= IpIf
->Ip
;
1696 GateWay
= IP4_ALLZERO_ADDRESS
;
1697 Head
.Protocol
= Config
->DefaultProtocol
;
1698 Head
.Tos
= Config
->TypeOfService
;
1699 Head
.Ttl
= Config
->TimeToLive
;
1700 DontFragment
= Config
->DoNotFragment
;
1703 Head
.Fragment
= IP4_HEAD_FRAGMENT_FIELD (DontFragment
, FALSE
, 0);
1704 HeadLen
= (TxData
->OptionsLength
+ 3) & (~0x03);
1706 OptionsLength
= TxData
->OptionsLength
;
1707 OptionsBuffer
= (UINT8
*)(TxData
->OptionsBuffer
);
1711 // If don't fragment and fragment needed, return error
1713 if (DontFragment
&& (TxData
->TotalDataLength
+ HeadLen
> IpSb
->MaxPacketSize
)) {
1714 Status
= EFI_BAD_BUFFER_SIZE
;
1719 // OK, it survives all the validation check. Wrap the token in
1720 // a IP4_TXTOKEN_WRAP and the data in a netbuf
1722 Status
= EFI_OUT_OF_RESOURCES
;
1723 Wrap
= AllocateZeroPool (sizeof (IP4_TXTOKEN_WRAP
));
1728 Wrap
->IpInstance
= IpInstance
;
1729 Wrap
->Token
= Token
;
1731 Wrap
->Life
= IP4_US_TO_SEC (Config
->TransmitTimeout
);
1732 Wrap
->Packet
= NetbufFromExt (
1733 (NET_FRAGMENT
*)TxData
->FragmentTable
,
1734 TxData
->FragmentCount
,
1741 if (Wrap
->Packet
== NULL
) {
1746 Token
->Status
= EFI_NOT_READY
;
1748 if (EFI_ERROR (NetMapInsertTail (&IpInstance
->TxTokens
, Token
, Wrap
))) {
1750 // NetbufFree will call Ip4FreeTxToken, which in turn will
1751 // free the IP4_TXTOKEN_WRAP. Now, the token wrap hasn't been
1754 if (Config
->RawData
) {
1756 // Restore pointer of first fragment in RawData mode.
1758 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*)FirstFragment
;
1761 NetbufFree (Wrap
->Packet
);
1766 // Mark the packet sent before output it. Mark it not sent again if the
1767 // returned status is not EFI_SUCCESS;
1771 Status
= Ip4Output (
1783 if (EFI_ERROR (Status
)) {
1786 if (Config
->RawData
) {
1788 // Restore pointer of first fragment in RawData mode.
1790 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*)FirstFragment
;
1793 NetbufFree (Wrap
->Packet
);
1796 if (Config
->RawData
) {
1798 // Restore pointer of first fragment in RawData mode.
1800 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*)FirstFragment
;
1804 gBS
->RestoreTPL (OldTpl
);
1809 Places a receiving request into the receiving queue.
1811 The Receive() function places a completion token into the receive packet queue.
1812 This function is always asynchronous.
1814 The Token.Event field in the completion token must be filled in by the caller
1815 and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol
1816 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
1819 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1820 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
1822 @retval EFI_SUCCESS The receive completion token was cached.
1823 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
1824 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)
1825 is not finished yet.
1826 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1829 - Token.Event is NULL.
1830 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
1831 resources (usually memory).
1832 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1833 The EFI IPv4 Protocol instance has been reset to startup defaults.
1834 EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
1835 in the receive queue.
1836 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
1837 @retval EFI_ICMP_ERROR An ICMP error packet was received.
1843 IN EFI_IP4_PROTOCOL
*This
,
1844 IN EFI_IP4_COMPLETION_TOKEN
*Token
1847 IP4_PROTOCOL
*IpInstance
;
1852 // First validate the parameters
1854 if ((This
== NULL
) || (Token
== NULL
) || (Token
->Event
== NULL
)) {
1855 return EFI_INVALID_PARAMETER
;
1858 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1860 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1862 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1863 Status
= EFI_NOT_STARTED
;
1868 // Check whether the toke is already on the receive queue.
1870 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4TokenExist
, Token
);
1872 if (EFI_ERROR (Status
)) {
1873 Status
= EFI_ACCESS_DENIED
;
1878 // Queue the token then check whether there is pending received packet.
1880 Status
= NetMapInsertTail (&IpInstance
->RxTokens
, Token
, NULL
);
1882 if (EFI_ERROR (Status
)) {
1886 Status
= Ip4InstanceDeliverPacket (IpInstance
);
1889 // Dispatch the DPC queued by the NotifyFunction of this instane's receive
1895 gBS
->RestoreTPL (OldTpl
);
1900 Cancel the transmitted but not recycled packet. If a matching
1901 token is found, it will call Ip4CancelPacket to cancel the
1902 packet. Ip4CancelPacket will cancel all the fragments of the
1903 packet. When all the fragments are freed, the IP4_TXTOKEN_WRAP
1904 will be deleted from the Map, and user's event signalled.
1905 Because Ip4CancelPacket and other functions are all called in
1906 line, so, after Ip4CancelPacket returns, the Item has been freed.
1908 @param[in] Map The IP4 child's transmit queue.
1909 @param[in] Item The current transmitted packet to test.
1910 @param[in] Context The user's token to cancel.
1912 @retval EFI_SUCCESS Continue to check the next Item.
1913 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
1920 IN NET_MAP_ITEM
*Item
,
1924 EFI_IP4_COMPLETION_TOKEN
*Token
;
1925 IP4_TXTOKEN_WRAP
*Wrap
;
1927 Token
= (EFI_IP4_COMPLETION_TOKEN
*)Context
;
1930 // Return EFI_SUCCESS to check the next item in the map if
1931 // this one doesn't match.
1933 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
1937 Wrap
= (IP4_TXTOKEN_WRAP
*)Item
->Value
;
1938 ASSERT (Wrap
!= NULL
);
1941 // Don't access the Item, Wrap and Token's members after this point.
1942 // Item and wrap has been freed. And we no longer own the Token.
1944 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
1947 // If only one item is to be cancel, return EFI_ABORTED to stop
1948 // iterating the map any more.
1950 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
) {
2003 Cancel the user's receive/transmit request.
2005 @param[in] IpInstance The IP4 child.
2006 @param[in] Token The token to cancel. If NULL, all token will be
2009 @retval EFI_SUCCESS The token is cancelled.
2010 @retval EFI_NOT_FOUND The token isn't found on either the
2011 transmit/receive queue.
2012 @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.
2017 IN IP4_PROTOCOL
*IpInstance
,
2018 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2024 // First check the transmitted packet. Ip4CancelTxTokens returns
2025 // EFI_ABORTED to mean that the token has been cancelled when
2026 // token != NULL. So, return EFI_SUCCESS for this condition.
2028 Status
= NetMapIterate (&IpInstance
->TxTokens
, Ip4CancelTxTokens
, Token
);
2030 if (EFI_ERROR (Status
)) {
2031 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2039 // Check the receive queue. Ip4CancelRxTokens also returns EFI_ABORT
2040 // for Token!=NULL and it is cancelled.
2042 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4CancelRxTokens
, Token
);
2044 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
2048 if (EFI_ERROR (Status
)) {
2049 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2057 // OK, if the Token is found when Token != NULL, the NetMapIterate
2058 // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.
2060 if (Token
!= NULL
) {
2061 return EFI_NOT_FOUND
;
2065 // If Token == NULL, cancel all the tokens. return error if no
2066 // all of them are cancelled.
2068 if (!NetMapIsEmpty (&IpInstance
->TxTokens
) ||
2069 !NetMapIsEmpty (&IpInstance
->RxTokens
))
2071 return EFI_DEVICE_ERROR
;
2078 Abort an asynchronous transmit or receive request.
2080 The Cancel() function is used to abort a pending transmit or receive request.
2081 If the token is in the transmit or receive request queues, after calling this
2082 function, Token->Status will be set to EFI_ABORTED and then Token->Event will
2083 be signaled. If the token is not in one of the queues, which usually means the
2084 asynchronous operation has completed, this function will not signal the token
2085 and EFI_NOT_FOUND is returned.
2087 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2088 @param[in] Token Pointer to a token that has been issued by
2089 EFI_IP4_PROTOCOL.Transmit() or
2090 EFI_IP4_PROTOCOL.Receive(). If NULL, all pending
2091 tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is
2092 defined in EFI_IP4_PROTOCOL.Transmit().
2094 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
2095 Token.->Event was signaled. When Token is NULL, all
2096 pending requests were aborted and their events were signaled.
2097 @retval EFI_INVALID_PARAMETER This is NULL.
2098 @retval EFI_NOT_STARTED This instance has not been started.
2099 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2100 RARP, etc.) is not finished yet.
2101 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
2102 not found in the transmit or receive queue. It has either completed
2103 or was not issued by Transmit() and Receive().
2109 IN EFI_IP4_PROTOCOL
*This
,
2110 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2113 IP4_PROTOCOL
*IpInstance
;
2118 return EFI_INVALID_PARAMETER
;
2121 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2123 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2125 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
2126 Status
= EFI_NOT_STARTED
;
2130 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
2131 Status
= EFI_NO_MAPPING
;
2135 Status
= Ip4Cancel (IpInstance
, Token
);
2138 gBS
->RestoreTPL (OldTpl
);
2143 Polls for incoming data packets and processes outgoing data packets.
2145 The Poll() function polls for incoming data packets and processes outgoing data
2146 packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()
2147 function to increase the rate that data packets are moved between the communications
2148 device and the transmit and receive queues.
2150 In some systems the periodic timer event may not poll the underlying communications
2151 device fast enough to transmit and/or receive all data packets without missing
2152 incoming packets or dropping outgoing packets. Drivers and applications that are
2153 experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function
2156 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2158 @retval EFI_SUCCESS Incoming or outgoing data was processed.
2159 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2160 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2161 RARP, etc.) is not finished yet.
2162 @retval EFI_INVALID_PARAMETER This is NULL.
2163 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2164 @retval EFI_NOT_READY No incoming or outgoing data is processed.
2165 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
2166 Consider increasing the polling rate.
2172 IN EFI_IP4_PROTOCOL
*This
2175 IP4_PROTOCOL
*IpInstance
;
2176 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
2179 return EFI_INVALID_PARAMETER
;
2182 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2184 if (IpInstance
->State
== IP4_STATE_UNCONFIGED
) {
2185 return EFI_NOT_STARTED
;
2188 Mnp
= IpInstance
->Service
->Mnp
;
2191 // Don't lock the Poll function to enable the deliver of
2192 // the packet polled up.
2194 return Mnp
->Poll (Mnp
);
2198 Decrease the life of the transmitted packets. If it is
2199 decreased to zero, cancel the packet. This function is
2200 called by Ip4PacketTimerTicking which time out both the
2201 received-but-not-delivered and transmitted-but-not-recycle
2204 @param[in] Map The IP4 child's transmit map.
2205 @param[in] Item Current transmitted packet.
2206 @param[in] Context Not used.
2208 @retval EFI_SUCCESS Always returns EFI_SUCCESS.
2213 Ip4SentPacketTicking (
2215 IN NET_MAP_ITEM
*Item
,
2219 IP4_TXTOKEN_WRAP
*Wrap
;
2221 Wrap
= (IP4_TXTOKEN_WRAP
*)Item
->Value
;
2222 ASSERT (Wrap
!= NULL
);
2224 if ((Wrap
->Life
> 0) && (--Wrap
->Life
== 0)) {
2225 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
2232 This heart beat timer of IP4 service instance times out all of its IP4 children's
2233 received-but-not-delivered and transmitted-but-not-recycle packets, and provides
2234 time input for its IGMP protocol.
2236 @param[in] Event The IP4 service instance's heart beat timer.
2237 @param[in] Context The IP4 service instance.
2249 IpSb
= (IP4_SERVICE
*)Context
;
2250 NET_CHECK_SIGNATURE (IpSb
, IP4_SERVICE_SIGNATURE
);
2252 Ip4PacketTimerTicking (IpSb
);
2253 Ip4IgmpTicking (IpSb
);
2257 This dedicated timer is used to poll underlying network media status. In case
2258 of cable swap or wireless network switch, a new round auto configuration will
2259 be initiated. The timer will signal the IP4 to run DHCP configuration again.
2260 IP4 driver will free old IP address related resource, such as route table and
2261 Interface, then initiate a DHCP process to acquire new IP, eventually create
2262 route table for new IP address.
2264 @param[in] Event The IP4 service instance's heart beat timer.
2265 @param[in] Context The IP4 service instance.
2270 Ip4TimerReconfigChecking (
2276 BOOLEAN OldMediaPresent
;
2278 EFI_SIMPLE_NETWORK_MODE SnpModeData
;
2280 IpSb
= (IP4_SERVICE
*)Context
;
2281 NET_CHECK_SIGNATURE (IpSb
, IP4_SERVICE_SIGNATURE
);
2283 OldMediaPresent
= IpSb
->MediaPresent
;
2286 // Get fresh mode data from MNP, since underlying media status may change.
2287 // Here, it needs to mention that the MediaPresent can also be checked even if
2288 // EFI_NOT_STARTED returned while this MNP child driver instance isn't configured.
2290 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, NULL
, &SnpModeData
);
2291 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
2295 IpSb
->MediaPresent
= SnpModeData
.MediaPresent
;
2297 // Media transimit Unpresent to Present means new link movement is detected.
2299 if (!OldMediaPresent
&& IpSb
->MediaPresent
&& (IpSb
->Ip4Config2Instance
.Policy
== Ip4Config2PolicyDhcp
)) {
2301 // Signal the IP4 to run the dhcp configuration again. IP4 driver will free
2302 // old IP address related resource, such as route table and Interface, then
2303 // initiate a DHCP round to acquire new IP, eventually
2304 // create route table for new IP address.
2306 if (IpSb
->ReconfigEvent
!= NULL
) {
2307 Status
= gBS
->SignalEvent (IpSb
->ReconfigEvent
);