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 pameters 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
);
448 Config the MNP parameter used by IP. The IP driver use one MNP
449 child to transmit/receive frames. By default, it configures MNP
450 to receive unicast/multicast/broadcast. And it will enable/disable
451 the promiscous receive according to whether there is IP child
452 enable that or not. If Force is FALSE, it will iterate through
453 all the IP children to check whether the promiscuous receive
454 setting has been changed. If it hasn't been changed, it won't
455 reconfigure the MNP. If Force is TRUE, the MNP is configured no
456 matter whether that is changed or not.
458 @param[in] IpSb The IP4 service instance that is to be changed.
459 @param[in] Force Force the configuration or not.
461 @retval EFI_SUCCESS The MNP is successfully configured/reconfigured.
462 @retval Others Configuration failed.
466 Ip4ServiceConfigMnp (
467 IN IP4_SERVICE
*IpSb
,
472 LIST_ENTRY
*ProtoEntry
;
474 IP4_PROTOCOL
*IpInstance
;
476 BOOLEAN PromiscReceive
;
480 PromiscReceive
= FALSE
;
484 // Iterate through the IP children to check whether promiscuous
485 // receive setting has been changed. Update the interface's receive
488 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
490 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP4_INTERFACE
, Link
);
491 IpIf
->PromiscRecv
= FALSE
;
493 NET_LIST_FOR_EACH (ProtoEntry
, &IpIf
->IpInstances
) {
494 IpInstance
= NET_LIST_USER_STRUCT (ProtoEntry
, IP4_PROTOCOL
, AddrLink
);
496 if (IpInstance
->ConfigData
.AcceptPromiscuous
) {
497 IpIf
->PromiscRecv
= TRUE
;
498 PromiscReceive
= TRUE
;
504 // If promiscuous receive isn't changed, it isn't necessary to reconfigure.
506 if (PromiscReceive
== IpSb
->MnpConfigData
.EnablePromiscuousReceive
) {
511 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= PromiscReceive
;
514 Status
= IpSb
->Mnp
->Configure (IpSb
->Mnp
, &IpSb
->MnpConfigData
);
517 // recover the original configuration if failed to set the configure.
519 if (EFI_ERROR (Status
) && Reconfig
) {
520 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= (BOOLEAN
) !PromiscReceive
;
528 Intiialize the IP4_PROTOCOL structure to the unconfigured states.
530 @param IpSb The IP4 service instance.
531 @param IpInstance The IP4 child instance.
536 IN IP4_SERVICE
*IpSb
,
537 IN OUT IP4_PROTOCOL
*IpInstance
540 ASSERT ((IpSb
!= NULL
) && (IpInstance
!= NULL
));
542 ZeroMem (IpInstance
, sizeof (IP4_PROTOCOL
));
544 IpInstance
->Signature
= IP4_PROTOCOL_SIGNATURE
;
545 CopyMem (&IpInstance
->Ip4Proto
, &mEfiIp4ProtocolTemplete
, sizeof (IpInstance
->Ip4Proto
));
546 IpInstance
->State
= IP4_STATE_UNCONFIGED
;
547 IpInstance
->InDestroy
= FALSE
;
548 IpInstance
->Service
= IpSb
;
550 InitializeListHead (&IpInstance
->Link
);
551 NetMapInit (&IpInstance
->RxTokens
);
552 NetMapInit (&IpInstance
->TxTokens
);
553 InitializeListHead (&IpInstance
->Received
);
554 InitializeListHead (&IpInstance
->Delivered
);
555 InitializeListHead (&IpInstance
->AddrLink
);
557 EfiInitializeLock (&IpInstance
->RecycleLock
, TPL_NOTIFY
);
562 Configure the IP4 child. If the child is already configured,
563 change the configuration parameter. Otherwise configure it
564 for the first time. The caller should validate the configuration
565 before deliver them to it. It also don't do configure NULL.
567 @param[in, out] IpInstance The IP4 child to configure.
568 @param[in] Config The configure data.
570 @retval EFI_SUCCESS The IP4 child is successfully configured.
571 @retval EFI_DEVICE_ERROR Failed to free the pending transive or to
572 configure underlying MNP or other errors.
573 @retval EFI_NO_MAPPING The IP4 child is configured to use default
574 address, but the default address hasn't been
575 configured. The IP4 child doesn't need to be
576 reconfigured when default address is configured.
577 @retval EFI_OUT_OF_RESOURCES No more memory space is available.
578 @retval other Other error occurs.
583 IN OUT IP4_PROTOCOL
*IpInstance
,
584 IN EFI_IP4_CONFIG_DATA
*Config
592 EFI_ARP_PROTOCOL
*Arp
;
593 EFI_IP4_CONFIG2_PROTOCOL
*Ip4Config2
;
594 EFI_IP4_CONFIG2_POLICY Policy
;
596 IpSb
= IpInstance
->Service
;
601 // User is changing packet filters. It must be stopped
602 // before the station address can be changed.
604 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
606 // Cancel all the pending transmit/receive from upper layer
608 Status
= Ip4Cancel (IpInstance
, NULL
);
610 if (EFI_ERROR (Status
)) {
611 return EFI_DEVICE_ERROR
;
614 CopyMem (&IpInstance
->ConfigData
, Config
, sizeof (IpInstance
->ConfigData
));
619 // Configure a fresh IP4 protocol instance. Create a route table.
620 // Each IP child has its own route table, which may point to the
621 // default table if it is using default address.
623 Status
= EFI_OUT_OF_RESOURCES
;
624 IpInstance
->RouteTable
= Ip4CreateRouteTable ();
626 if (IpInstance
->RouteTable
== NULL
) {
631 // Set up the interface.
633 CopyMem (&Ip
, &Config
->StationAddress
, sizeof (IP4_ADDR
));
634 CopyMem (&Netmask
, &Config
->SubnetMask
, sizeof (IP4_ADDR
));
637 Netmask
= NTOHL (Netmask
);
639 if (!Config
->UseDefaultAddress
) {
641 // Find whether there is already an interface with the same
642 // station address. All the instances with the same station
643 // address shares one interface.
645 IpIf
= Ip4FindStationAddress (IpSb
, Ip
, Netmask
);
651 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
657 Status
= Ip4SetAddress (IpIf
, Ip
, Netmask
);
659 if (EFI_ERROR (Status
)) {
660 Status
= EFI_DEVICE_ERROR
;
661 Ip4FreeInterface (IpIf
, IpInstance
);
665 InsertTailList (&IpSb
->Interfaces
, &IpIf
->Link
);
669 // Add a route to this connected network in the instance route table.
672 IpInstance
->RouteTable
,
679 // Use the default address. Check the state.
681 if (IpSb
->State
== IP4_SERVICE_UNSTARTED
) {
683 // Trigger the EFI_IP4_CONFIG2_PROTOCOL to retrieve the
684 // default IPv4 address if it is not available yet.
686 Policy
= IpSb
->Ip4Config2Instance
.Policy
;
687 if (Policy
!= Ip4Config2PolicyDhcp
) {
688 Ip4Config2
= &IpSb
->Ip4Config2Instance
.Ip4Config2
;
689 Policy
= Ip4Config2PolicyDhcp
;
690 Status
= Ip4Config2
->SetData (
692 Ip4Config2DataTypePolicy
,
693 sizeof (EFI_IP4_CONFIG2_POLICY
),
696 if (EFI_ERROR (Status
)) {
702 IpIf
= IpSb
->DefaultInterface
;
703 NET_GET_REF (IpSb
->DefaultInterface
);
706 // If default address is used, so is the default route table.
707 // Any route set by the instance has the precedence over the
708 // routes in the default route table. Link the default table
709 // after the instance's table. Routing will search the local
712 NET_GET_REF (IpSb
->DefaultRouteTable
);
713 IpInstance
->RouteTable
->Next
= IpSb
->DefaultRouteTable
;
716 IpInstance
->Interface
= IpIf
;
717 if (IpIf
->Arp
!= NULL
) {
719 Status
= gBS
->OpenProtocol (
721 &gEfiArpProtocolGuid
,
723 gIp4DriverBinding
.DriverBindingHandle
,
725 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
727 if (EFI_ERROR (Status
)) {
728 Ip4FreeInterface (IpIf
, IpInstance
);
732 InsertTailList (&IpIf
->IpInstances
, &IpInstance
->AddrLink
);
734 CopyMem (&IpInstance
->ConfigData
, Config
, sizeof (IpInstance
->ConfigData
));
735 IpInstance
->State
= IP4_STATE_CONFIGED
;
738 // Although EFI_NO_MAPPING is an error code, the IP child has been
739 // successfully configured and doesn't need reconfiguration when
740 // default address is acquired.
742 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
743 return EFI_NO_MAPPING
;
749 Ip4FreeRouteTable (IpInstance
->RouteTable
);
750 IpInstance
->RouteTable
= NULL
;
756 Clean up the IP4 child, release all the resources used by it.
758 @param[in] IpInstance The IP4 child to clean up.
760 @retval EFI_SUCCESS The IP4 child is cleaned up.
761 @retval EFI_DEVICE_ERROR Some resources failed to be released.
766 IN IP4_PROTOCOL
*IpInstance
769 if (EFI_ERROR (Ip4Cancel (IpInstance
, NULL
))) {
770 return EFI_DEVICE_ERROR
;
773 if (EFI_ERROR (Ip4Groups (IpInstance
, FALSE
, NULL
))) {
774 return EFI_DEVICE_ERROR
;
778 // Some packets haven't been recycled. It is because either the
779 // user forgets to recycle the packets, or because the callback
780 // hasn't been called. Just leave it alone.
782 if (!IsListEmpty (&IpInstance
->Delivered
)) {
786 if (IpInstance
->Interface
!= NULL
) {
787 RemoveEntryList (&IpInstance
->AddrLink
);
788 if (IpInstance
->Interface
->Arp
!= NULL
) {
790 IpInstance
->Interface
->ArpHandle
,
791 &gEfiArpProtocolGuid
,
792 gIp4DriverBinding
.DriverBindingHandle
,
796 Ip4FreeInterface (IpInstance
->Interface
, IpInstance
);
797 IpInstance
->Interface
= NULL
;
800 if (IpInstance
->RouteTable
!= NULL
) {
801 if (IpInstance
->RouteTable
->Next
!= NULL
) {
802 Ip4FreeRouteTable (IpInstance
->RouteTable
->Next
);
805 Ip4FreeRouteTable (IpInstance
->RouteTable
);
806 IpInstance
->RouteTable
= NULL
;
809 if (IpInstance
->EfiRouteTable
!= NULL
) {
810 FreePool (IpInstance
->EfiRouteTable
);
811 IpInstance
->EfiRouteTable
= NULL
;
812 IpInstance
->EfiRouteCount
= 0;
815 if (IpInstance
->Groups
!= NULL
) {
816 FreePool (IpInstance
->Groups
);
817 IpInstance
->Groups
= NULL
;
818 IpInstance
->GroupCount
= 0;
821 NetMapClean (&IpInstance
->TxTokens
);
823 NetMapClean (&IpInstance
->RxTokens
);
830 Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
832 The Configure() function is used to set, change, or reset the operational
833 parameters and filter settings for this EFI IPv4 Protocol instance. Until these
834 parameters have been set, no network traffic can be sent or received by this
835 instance. Once the parameters have been reset (by calling this function with
836 IpConfigData set to NULL), no more traffic can be sent or received until these
837 parameters have been set again. Each EFI IPv4 Protocol instance can be started
838 and stopped independently of each other by enabling or disabling their receive
839 filter settings with the Configure() function.
841 When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will
842 be appended as an alias address into the addresses list in the EFI IPv4 Protocol
843 driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL
844 to retrieve the default IPv4 address if it is not available yet. Clients could
845 frequently call GetModeData() to check the status to ensure that the default IPv4
848 If operational parameters are reset or changed, any pending transmit and receive
849 requests will be cancelled. Their completion token status will be set to EFI_ABORTED
850 and their events will be signaled.
852 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
853 @param[in] IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.
855 @retval EFI_SUCCESS The driver instance was successfully opened.
856 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
857 RARP, etc.) is not finished yet.
858 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
859 @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:
860 A configuration protocol (DHCP, BOOTP, RARP, etc.) could
861 not be located when clients choose to use the default IPv4
862 address. This EFI IPv4 Protocol implementation does not
863 support this requested filter or timeout setting.
864 @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.
865 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the
866 IPv4 address or subnet mask can be changed. The interface must
867 also be stopped when switching to/from raw packet mode.
868 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4
869 Protocol driver instance is not opened.
875 IN EFI_IP4_PROTOCOL
*This
,
876 IN EFI_IP4_CONFIG_DATA
*IpConfigData OPTIONAL
879 IP4_PROTOCOL
*IpInstance
;
880 EFI_IP4_CONFIG_DATA
*Current
;
888 // First, validate the parameters
891 return EFI_INVALID_PARAMETER
;
894 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
895 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
898 // Validate the configuration first.
900 if (IpConfigData
!= NULL
) {
902 CopyMem (&IpAddress
, &IpConfigData
->StationAddress
, sizeof (IP4_ADDR
));
903 CopyMem (&SubnetMask
, &IpConfigData
->SubnetMask
, sizeof (IP4_ADDR
));
905 IpAddress
= NTOHL (IpAddress
);
906 SubnetMask
= NTOHL (SubnetMask
);
909 // Check whether the station address is a valid unicast address
911 if (!IpConfigData
->UseDefaultAddress
) {
912 AddrOk
= Ip4StationAddressValid (IpAddress
, SubnetMask
);
915 Status
= EFI_INVALID_PARAMETER
;
921 // User can only update packet filters when already configured.
922 // If it wants to change the station address, it must configure(NULL)
923 // the instance first.
925 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
926 Current
= &IpInstance
->ConfigData
;
928 if (Current
->UseDefaultAddress
!= IpConfigData
->UseDefaultAddress
) {
929 Status
= EFI_ALREADY_STARTED
;
933 if (!Current
->UseDefaultAddress
&&
934 (!EFI_IP4_EQUAL (&Current
->StationAddress
, &IpConfigData
->StationAddress
) ||
935 !EFI_IP4_EQUAL (&Current
->SubnetMask
, &IpConfigData
->SubnetMask
))) {
936 Status
= EFI_ALREADY_STARTED
;
940 if (Current
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
941 Status
= EFI_NO_MAPPING
;
948 // Configure the instance or clean it up.
950 if (IpConfigData
!= NULL
) {
951 Status
= Ip4ConfigProtocol (IpInstance
, IpConfigData
);
953 Status
= Ip4CleanProtocol (IpInstance
);
956 // Consider the following valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,
957 // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,
958 // the unload fails miserably.
960 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
961 IpInstance
->State
= IP4_STATE_UNCONFIGED
;
966 // Update the MNP's configure data. Ip4ServiceConfigMnp will check
967 // whether it is necessary to reconfigure the MNP.
969 Ip4ServiceConfigMnp (IpInstance
->Service
, FALSE
);
972 gBS
->RestoreTPL (OldTpl
);
979 Change the IP4 child's multicast setting. The caller
980 should make sure that the parameters is valid.
982 @param[in] IpInstance The IP4 child to change the setting.
983 @param[in] JoinFlag TRUE to join the group, otherwise leave it.
984 @param[in] GroupAddress The target group address.
986 @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it.
987 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
988 @retval EFI_DEVICE_ERROR Failed to set the group configuraton.
989 @retval EFI_SUCCESS Successfully updated the group setting.
990 @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.
995 IN IP4_PROTOCOL
*IpInstance
,
997 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
1005 // Add it to the instance's Groups, and join the group by IGMP.
1006 // IpInstance->Groups is in network byte order. IGMP operates in
1011 // When JoinFlag is TRUE, GroupAddress shouldn't be NULL.
1013 ASSERT (GroupAddress
!= NULL
);
1014 CopyMem (&Group
, GroupAddress
, sizeof (IP4_ADDR
));
1016 for (Index
= 0; Index
< IpInstance
->GroupCount
; Index
++) {
1017 if (IpInstance
->Groups
[Index
] == Group
) {
1018 return EFI_ALREADY_STARTED
;
1022 Members
= Ip4CombineGroups (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1024 if (Members
== NULL
) {
1025 return EFI_OUT_OF_RESOURCES
;
1028 if (EFI_ERROR (Ip4JoinGroup (IpInstance
, NTOHL (Group
)))) {
1030 return EFI_DEVICE_ERROR
;
1033 if (IpInstance
->Groups
!= NULL
) {
1034 FreePool (IpInstance
->Groups
);
1037 IpInstance
->Groups
= Members
;
1038 IpInstance
->GroupCount
++;
1044 // Leave the group. Leave all the groups if GroupAddress is NULL.
1045 // Must iterate from the end to the beginning because the GroupCount
1046 // is decreamented each time an address is removed..
1048 for (Index
= IpInstance
->GroupCount
; Index
> 0 ; Index
--) {
1049 ASSERT (IpInstance
->Groups
!= NULL
);
1050 Group
= IpInstance
->Groups
[Index
- 1];
1051 if ((GroupAddress
== NULL
) || EFI_IP4_EQUAL (&Group
, GroupAddress
)) {
1052 if (EFI_ERROR (Ip4LeaveGroup (IpInstance
, NTOHL (Group
)))) {
1053 return EFI_DEVICE_ERROR
;
1056 Ip4RemoveGroupAddr (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1057 IpInstance
->GroupCount
--;
1059 if (IpInstance
->GroupCount
== 0) {
1060 ASSERT (Index
== 1);
1062 FreePool (IpInstance
->Groups
);
1063 IpInstance
->Groups
= NULL
;
1066 if (GroupAddress
!= NULL
) {
1072 return ((GroupAddress
!= NULL
) ? EFI_NOT_FOUND
: EFI_SUCCESS
);
1077 Joins and leaves multicast groups.
1079 The Groups() function is used to join and leave multicast group sessions. Joining
1080 a group will enable reception of matching multicast packets. Leaving a group will
1081 disable the multicast packet reception.
1083 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
1085 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1086 @param[in] JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.
1087 @param[in] GroupAddress Pointer to the IPv4 multicast address.
1089 @retval EFI_SUCCESS The operation completed successfully.
1090 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
1092 - JoinFlag is TRUE and GroupAddress is NULL.
1093 - GroupAddress is not NULL and *GroupAddress is
1094 not a multicast IPv4 address.
1095 @retval EFI_NOT_STARTED This instance has not been started.
1096 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1097 RARP, etc.) is not finished yet.
1098 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
1099 @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.
1100 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
1102 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
1103 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1109 IN EFI_IP4_PROTOCOL
*This
,
1110 IN BOOLEAN JoinFlag
,
1111 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
1114 IP4_PROTOCOL
*IpInstance
;
1119 if ((This
== NULL
) || (JoinFlag
&& (GroupAddress
== NULL
))) {
1120 return EFI_INVALID_PARAMETER
;
1123 if (GroupAddress
!= NULL
) {
1124 CopyMem (&McastIp
, GroupAddress
, sizeof (IP4_ADDR
));
1126 if (!IP4_IS_MULTICAST (NTOHL (McastIp
))) {
1127 return EFI_INVALID_PARAMETER
;
1131 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1132 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1134 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1135 Status
= EFI_NOT_STARTED
;
1139 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1140 Status
= EFI_NO_MAPPING
;
1144 Status
= Ip4Groups (IpInstance
, JoinFlag
, GroupAddress
);
1147 gBS
->RestoreTPL (OldTpl
);
1153 Adds and deletes routing table entries.
1155 The Routes() function adds a route to or deletes a route from the routing table.
1157 Routes are determined by comparing the SubnetAddress with the destination IPv4
1158 address arithmetically AND-ed with the SubnetMask. The gateway address must be
1159 on the same subnet as the configured station address.
1161 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
1162 The default route matches all destination IPv4 addresses that do not match any
1165 A GatewayAddress that is zero is a nonroute. Packets are sent to the destination
1166 IP address if it can be found in the ARP cache or on the local subnet. One automatic
1167 nonroute entry will be inserted into the routing table for outgoing packets that
1168 are addressed to a local subnet (gateway address of 0.0.0.0).
1170 Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI
1171 IPv4 Protocol instances that use the default IPv4 address will also have copies
1172 of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these
1173 copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its
1174 instances. As a result, client modification to the routing table will be lost.
1176 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1177 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
1178 FALSE to add this route to the routing table. SubnetAddress
1179 and SubnetMask are used as the key to each route entry.
1180 @param[in] SubnetAddress The address of the subnet that needs to be routed.
1181 @param[in] SubnetMask The subnet mask of SubnetAddress.
1182 @param[in] GatewayAddress The unicast gateway IPv4 address for this route.
1184 @retval EFI_SUCCESS The operation completed successfully.
1185 @retval EFI_NOT_STARTED The driver instance has not been started.
1186 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1187 RARP, etc.) is not finished yet.
1188 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1190 - SubnetAddress is NULL.
1191 - SubnetMask is NULL.
1192 - GatewayAddress is NULL.
1193 - *SubnetAddress is not a valid subnet address.
1194 - *SubnetMask is not a valid subnet mask.
1195 - *GatewayAddress is not a valid unicast IPv4 address.
1196 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
1197 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
1198 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
1199 DeleteRoute is FALSE).
1205 IN EFI_IP4_PROTOCOL
*This
,
1206 IN BOOLEAN DeleteRoute
,
1207 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
1208 IN EFI_IPv4_ADDRESS
*SubnetMask
,
1209 IN EFI_IPv4_ADDRESS
*GatewayAddress
1212 IP4_PROTOCOL
*IpInstance
;
1213 IP4_INTERFACE
*IpIf
;
1221 // First, validate the parameters
1223 if ((This
== NULL
) || (SubnetAddress
== NULL
) ||
1224 (SubnetMask
== NULL
) || (GatewayAddress
== NULL
)) {
1225 return EFI_INVALID_PARAMETER
;
1228 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1229 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1231 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1232 Status
= EFI_NOT_STARTED
;
1236 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1237 Status
= EFI_NO_MAPPING
;
1241 CopyMem (&Dest
, SubnetAddress
, sizeof (IP4_ADDR
));
1242 CopyMem (&Netmask
, SubnetMask
, sizeof (IP4_ADDR
));
1243 CopyMem (&Nexthop
, GatewayAddress
, sizeof (IP4_ADDR
));
1245 Dest
= NTOHL (Dest
);
1246 Netmask
= NTOHL (Netmask
);
1247 Nexthop
= NTOHL (Nexthop
);
1249 IpIf
= IpInstance
->Interface
;
1251 if (!IP4_IS_VALID_NETMASK (Netmask
)) {
1252 Status
= EFI_INVALID_PARAMETER
;
1257 // the gateway address must be a unicast on the connected network if not zero.
1259 if ((Nexthop
!= IP4_ALLZERO_ADDRESS
) &&
1260 ((IpIf
->SubnetMask
!= IP4_ALLONE_ADDRESS
&& !IP4_NET_EQUAL (Nexthop
, IpIf
->Ip
, IpIf
->SubnetMask
)) ||
1261 IP4_IS_BROADCAST (Ip4GetNetCast (Nexthop
, IpIf
)))) {
1263 Status
= EFI_INVALID_PARAMETER
;
1268 Status
= Ip4DelRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1270 Status
= Ip4AddRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1274 gBS
->RestoreTPL (OldTpl
);
1280 Check whether the user's token or event has already
1281 been enqueued on IP4's list.
1283 @param[in] Map The container of either user's transmit or receive
1285 @param[in] Item Current item to check against.
1286 @param[in] Context The Token to check againist.
1288 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP.
1289 @retval EFI_SUCCESS The current item isn't the same token/event as the
1297 IN NET_MAP_ITEM
*Item
,
1301 EFI_IP4_COMPLETION_TOKEN
*Token
;
1302 EFI_IP4_COMPLETION_TOKEN
*TokenInItem
;
1304 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
1305 TokenInItem
= (EFI_IP4_COMPLETION_TOKEN
*) Item
->Key
;
1307 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
1308 return EFI_ACCESS_DENIED
;
1315 Validate the user's token against current station address.
1317 @param[in] Token User's token to validate.
1318 @param[in] IpIf The IP4 child's interface.
1319 @param[in] RawData Set to TRUE to send unformatted packets.
1321 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
1322 @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.
1323 @retval EFI_SUCCESS The token is valid.
1328 IN EFI_IP4_COMPLETION_TOKEN
*Token
,
1329 IN IP4_INTERFACE
*IpIf
,
1333 EFI_IP4_TRANSMIT_DATA
*TxData
;
1334 EFI_IP4_OVERRIDE_DATA
*Override
;
1341 if ((Token
== NULL
) || (Token
->Event
== NULL
) || (Token
->Packet
.TxData
== NULL
)) {
1342 return EFI_INVALID_PARAMETER
;
1345 TxData
= Token
->Packet
.TxData
;
1348 // Check the fragment table: no empty fragment, and length isn't bogus.
1350 if ((TxData
->TotalDataLength
== 0) || (TxData
->FragmentCount
== 0)) {
1351 return EFI_INVALID_PARAMETER
;
1354 Offset
= TxData
->TotalDataLength
;
1356 if (Offset
> IP4_MAX_PACKET_SIZE
) {
1357 return EFI_BAD_BUFFER_SIZE
;
1360 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
1361 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
1362 (TxData
->FragmentTable
[Index
].FragmentLength
== 0)) {
1364 return EFI_INVALID_PARAMETER
;
1367 Offset
-= TxData
->FragmentTable
[Index
].FragmentLength
;
1371 return EFI_INVALID_PARAMETER
;
1375 // NOTE that OptionsLength/OptionsBuffer/OverrideData are ignored if RawData
1383 // Check the IP options: no more than 40 bytes and format is OK
1385 if (TxData
->OptionsLength
!= 0) {
1386 if ((TxData
->OptionsLength
> 40) || (TxData
->OptionsBuffer
== NULL
)) {
1387 return EFI_INVALID_PARAMETER
;
1390 if (!Ip4OptionIsValid (TxData
->OptionsBuffer
, TxData
->OptionsLength
, FALSE
)) {
1391 return EFI_INVALID_PARAMETER
;
1396 // Check the source and gateway: they must be a valid unicast.
1397 // Gateway must also be on the connected network.
1399 if (TxData
->OverrideData
!= NULL
) {
1400 Override
= TxData
->OverrideData
;
1402 CopyMem (&Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1403 CopyMem (&Gateway
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1406 Gateway
= NTOHL (Gateway
);
1408 if ((NetGetIpClass (Src
) > IP4_ADDR_CLASSC
) ||
1409 (Src
== IP4_ALLONE_ADDRESS
) ||
1410 IP4_IS_BROADCAST (Ip4GetNetCast (Src
, IpIf
))) {
1412 return EFI_INVALID_PARAMETER
;
1416 // If gateway isn't zero, it must be a unicast address, and
1417 // on the connected network.
1419 if ((Gateway
!= IP4_ALLZERO_ADDRESS
) &&
1420 ((NetGetIpClass (Gateway
) > IP4_ADDR_CLASSC
) ||
1421 !IP4_NET_EQUAL (Gateway
, IpIf
->Ip
, IpIf
->SubnetMask
) ||
1422 IP4_IS_BROADCAST (Ip4GetNetCast (Gateway
, IpIf
)))) {
1424 return EFI_INVALID_PARAMETER
;
1429 // Check the packet length: Head length and packet length all has a limit
1431 HeadLen
= sizeof (IP4_HEAD
) + ((TxData
->OptionsLength
+ 3) &~0x03);
1433 if ((HeadLen
> IP4_MAX_HEADLEN
) ||
1434 (TxData
->TotalDataLength
+ HeadLen
> IP4_MAX_PACKET_SIZE
)) {
1436 return EFI_BAD_BUFFER_SIZE
;
1444 The callback function for the net buffer which wraps the user's
1445 transmit token. Although it seems this function is pretty simple,
1446 there are some subtle things.
1447 When user requests the IP to transmit a packet by passing it a
1448 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data
1449 is wrapped in an net buffer. the net buffer's Free function is
1450 set to Ip4FreeTxToken. The Token and token wrap are added to the
1451 IP child's TxToken map. Then the buffer is passed to Ip4Output for
1452 transmission. If something error happened before that, the buffer
1453 is freed, which in turn will free the token wrap. The wrap may
1454 have been added to the TxToken map or not, and the user's event
1455 shouldn't be fired because we are still in the EfiIp4Transmit. If
1456 the buffer has been sent by Ip4Output, it should be removed from
1457 the TxToken map and user's event signaled. The token wrap and buffer
1458 are bound together. Check the comments in Ip4Output for information
1459 about IP fragmentation.
1461 @param[in] Context The token's wrap.
1470 IP4_TXTOKEN_WRAP
*Wrap
;
1473 Wrap
= (IP4_TXTOKEN_WRAP
*) Context
;
1476 // Signal IpSecRecycleEvent to inform IPsec free the memory
1478 if (Wrap
->IpSecRecycleSignal
!= NULL
) {
1479 gBS
->SignalEvent (Wrap
->IpSecRecycleSignal
);
1483 // Find the token in the instance's map. EfiIp4Transmit put the
1484 // token to the map. If that failed, NetMapFindKey will return NULL.
1486 Item
= NetMapFindKey (&Wrap
->IpInstance
->TxTokens
, Wrap
->Token
);
1489 NetMapRemoveItem (&Wrap
->IpInstance
->TxTokens
, Item
, NULL
);
1493 gBS
->SignalEvent (Wrap
->Token
->Event
);
1496 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
1506 The callback function to Ip4Output to update the transmit status.
1508 @param Ip4Instance The Ip4Instance that request the transmit.
1509 @param Packet The user's transmit request.
1510 @param IoStatus The result of the transmission.
1511 @param Flag Not used during transmission.
1512 @param Context The token's wrap.
1517 IP4_PROTOCOL
*Ip4Instance
,
1519 EFI_STATUS IoStatus
,
1524 IP4_TXTOKEN_WRAP
*Wrap
;
1527 // This is the transmission request from upper layer,
1528 // not the IP4 driver itself.
1530 ASSERT (Ip4Instance
!= NULL
);
1533 // The first fragment of the packet has been sent. Update
1534 // the token's status. That is, if fragmented, the transmit's
1535 // status is the first fragment's status. The Wrap will be
1536 // release when all the fragments are release. Check the comments
1537 // in Ip4FreeTxToken and Ip4Output for information.
1539 Wrap
= (IP4_TXTOKEN_WRAP
*) Context
;
1540 Wrap
->Token
->Status
= IoStatus
;
1542 NetbufFree (Wrap
->Packet
);
1547 Places outgoing data packets into the transmit queue.
1549 The Transmit() function places a sending request in the transmit queue of this
1550 EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some
1551 errors occur, the event in the token will be signaled and the status is updated.
1553 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1554 @param[in] Token Pointer to the transmit token.
1556 @retval EFI_SUCCESS The data has been queued for transmission.
1557 @retval EFI_NOT_STARTED This instance has not been started.
1558 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1559 RARP, etc.) is not finished yet.
1560 @retval EFI_INVALID_PARAMETER One or more pameters are invalid.
1561 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event
1562 was already in the transmit queue.
1563 @retval EFI_NOT_READY The completion token could not be queued because the transmit
1565 @retval EFI_NOT_FOUND Not route is found to destination address.
1566 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
1567 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
1569 @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is
1570 greater than MTU (or greater than the maximum packet size if
1571 Token.Packet.TxData.OverrideData.
1572 DoNotFragment is TRUE).
1578 IN EFI_IP4_PROTOCOL
*This
,
1579 IN EFI_IP4_COMPLETION_TOKEN
*Token
1583 IP4_PROTOCOL
*IpInstance
;
1584 IP4_INTERFACE
*IpIf
;
1585 IP4_TXTOKEN_WRAP
*Wrap
;
1586 EFI_IP4_TRANSMIT_DATA
*TxData
;
1587 EFI_IP4_CONFIG_DATA
*Config
;
1588 EFI_IP4_OVERRIDE_DATA
*Override
;
1593 BOOLEAN DontFragment
;
1596 UINT32 OptionsLength
;
1597 UINT8
*OptionsBuffer
;
1598 VOID
*FirstFragment
;
1601 return EFI_INVALID_PARAMETER
;
1604 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1606 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1607 return EFI_NOT_STARTED
;
1610 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1612 IpSb
= IpInstance
->Service
;
1613 IpIf
= IpInstance
->Interface
;
1614 Config
= &IpInstance
->ConfigData
;
1616 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1617 Status
= EFI_NO_MAPPING
;
1622 // make sure that token is properly formated
1624 Status
= Ip4TxTokenValid (Token
, IpIf
, Config
->RawData
);
1626 if (EFI_ERROR (Status
)) {
1631 // Check whether the token or signal already existed.
1633 if (EFI_ERROR (NetMapIterate (&IpInstance
->TxTokens
, Ip4TokenExist
, Token
))) {
1634 Status
= EFI_ACCESS_DENIED
;
1639 // Build the IP header, need to fill in the Tos, TotalLen, Id,
1640 // fragment, Ttl, protocol, Src, and Dst.
1642 TxData
= Token
->Packet
.TxData
;
1644 FirstFragment
= NULL
;
1646 if (Config
->RawData
) {
1648 // When RawData is TRUE, first buffer in FragmentTable points to a raw
1649 // IPv4 fragment including IPv4 header and options.
1651 FirstFragment
= TxData
->FragmentTable
[0].FragmentBuffer
;
1652 CopyMem (&RawHdrLen
, FirstFragment
, sizeof (UINT8
));
1654 RawHdrLen
= (UINT8
) (RawHdrLen
& 0x0f);
1655 if (RawHdrLen
< 5) {
1656 Status
= EFI_INVALID_PARAMETER
;
1660 RawHdrLen
= (UINT8
) (RawHdrLen
<< 2);
1662 CopyMem (&Head
, FirstFragment
, IP4_MIN_HEADLEN
);
1664 Ip4NtohHead (&Head
);
1666 DontFragment
= IP4_DO_NOT_FRAGMENT (Head
.Fragment
);
1668 if (!DontFragment
) {
1669 Status
= EFI_INVALID_PARAMETER
;
1673 GateWay
= IP4_ALLZERO_ADDRESS
;
1676 // Get IPv4 options from first fragment.
1678 if (RawHdrLen
== IP4_MIN_HEADLEN
) {
1680 OptionsBuffer
= NULL
;
1682 OptionsLength
= RawHdrLen
- IP4_MIN_HEADLEN
;
1683 OptionsBuffer
= (UINT8
*) FirstFragment
+ IP4_MIN_HEADLEN
;
1687 // Trim off IPv4 header and options from first fragment.
1689 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*) FirstFragment
+ RawHdrLen
;
1690 TxData
->FragmentTable
[0].FragmentLength
= TxData
->FragmentTable
[0].FragmentLength
- RawHdrLen
;
1692 CopyMem (&Head
.Dst
, &TxData
->DestinationAddress
, sizeof (IP4_ADDR
));
1693 Head
.Dst
= NTOHL (Head
.Dst
);
1695 if (TxData
->OverrideData
!= NULL
) {
1696 Override
= TxData
->OverrideData
;
1697 Head
.Protocol
= Override
->Protocol
;
1698 Head
.Tos
= Override
->TypeOfService
;
1699 Head
.Ttl
= Override
->TimeToLive
;
1700 DontFragment
= Override
->DoNotFragment
;
1702 CopyMem (&Head
.Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1703 CopyMem (&GateWay
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1705 Head
.Src
= NTOHL (Head
.Src
);
1706 GateWay
= NTOHL (GateWay
);
1708 Head
.Src
= IpIf
->Ip
;
1709 GateWay
= IP4_ALLZERO_ADDRESS
;
1710 Head
.Protocol
= Config
->DefaultProtocol
;
1711 Head
.Tos
= Config
->TypeOfService
;
1712 Head
.Ttl
= Config
->TimeToLive
;
1713 DontFragment
= Config
->DoNotFragment
;
1716 Head
.Fragment
= IP4_HEAD_FRAGMENT_FIELD (DontFragment
, FALSE
, 0);
1717 HeadLen
= (TxData
->OptionsLength
+ 3) & (~0x03);
1719 OptionsLength
= TxData
->OptionsLength
;
1720 OptionsBuffer
= (UINT8
*) (TxData
->OptionsBuffer
);
1724 // If don't fragment and fragment needed, return error
1726 if (DontFragment
&& (TxData
->TotalDataLength
+ HeadLen
> IpSb
->MaxPacketSize
)) {
1727 Status
= EFI_BAD_BUFFER_SIZE
;
1732 // OK, it survives all the validation check. Wrap the token in
1733 // a IP4_TXTOKEN_WRAP and the data in a netbuf
1735 Status
= EFI_OUT_OF_RESOURCES
;
1736 Wrap
= AllocateZeroPool (sizeof (IP4_TXTOKEN_WRAP
));
1741 Wrap
->IpInstance
= IpInstance
;
1742 Wrap
->Token
= Token
;
1744 Wrap
->Life
= IP4_US_TO_SEC (Config
->TransmitTimeout
);
1745 Wrap
->Packet
= NetbufFromExt (
1746 (NET_FRAGMENT
*) TxData
->FragmentTable
,
1747 TxData
->FragmentCount
,
1754 if (Wrap
->Packet
== NULL
) {
1759 Token
->Status
= EFI_NOT_READY
;
1761 if (EFI_ERROR (NetMapInsertTail (&IpInstance
->TxTokens
, Token
, Wrap
))) {
1763 // NetbufFree will call Ip4FreeTxToken, which in turn will
1764 // free the IP4_TXTOKEN_WRAP. Now, the token wrap hasn't been
1767 if (Config
->RawData
) {
1769 // Restore pointer of first fragment in RawData mode.
1771 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*) FirstFragment
;
1774 NetbufFree (Wrap
->Packet
);
1779 // Mark the packet sent before output it. Mark it not sent again if the
1780 // returned status is not EFI_SUCCESS;
1784 Status
= Ip4Output (
1796 if (EFI_ERROR (Status
)) {
1799 if (Config
->RawData
) {
1801 // Restore pointer of first fragment in RawData mode.
1803 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*) FirstFragment
;
1806 NetbufFree (Wrap
->Packet
);
1809 if (Config
->RawData
) {
1811 // Restore pointer of first fragment in RawData mode.
1813 TxData
->FragmentTable
[0].FragmentBuffer
= (UINT8
*) FirstFragment
;
1817 gBS
->RestoreTPL (OldTpl
);
1823 Places a receiving request into the receiving queue.
1825 The Receive() function places a completion token into the receive packet queue.
1826 This function is always asynchronous.
1828 The Token.Event field in the completion token must be filled in by the caller
1829 and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol
1830 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
1833 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1834 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
1836 @retval EFI_SUCCESS The receive completion token was cached.
1837 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
1838 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)
1839 is not finished yet.
1840 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1843 - Token.Event is NULL.
1844 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
1845 resources (usually memory).
1846 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1847 The EFI IPv4 Protocol instance has been reset to startup defaults.
1848 EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
1849 in the receive queue.
1850 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
1851 @retval EFI_ICMP_ERROR An ICMP error packet was received.
1857 IN EFI_IP4_PROTOCOL
*This
,
1858 IN EFI_IP4_COMPLETION_TOKEN
*Token
1861 IP4_PROTOCOL
*IpInstance
;
1866 // First validate the parameters
1868 if ((This
== NULL
) || (Token
== NULL
) || (Token
->Event
== NULL
)) {
1869 return EFI_INVALID_PARAMETER
;
1872 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1874 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1876 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1877 Status
= EFI_NOT_STARTED
;
1882 // Check whether the toke is already on the receive queue.
1884 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4TokenExist
, Token
);
1886 if (EFI_ERROR (Status
)) {
1887 Status
= EFI_ACCESS_DENIED
;
1892 // Queue the token then check whether there is pending received packet.
1894 Status
= NetMapInsertTail (&IpInstance
->RxTokens
, Token
, NULL
);
1896 if (EFI_ERROR (Status
)) {
1900 Status
= Ip4InstanceDeliverPacket (IpInstance
);
1903 // Dispatch the DPC queued by the NotifyFunction of this instane's receive
1909 gBS
->RestoreTPL (OldTpl
);
1915 Cancel the transmitted but not recycled packet. If a matching
1916 token is found, it will call Ip4CancelPacket to cancel the
1917 packet. Ip4CancelPacket will cancel all the fragments of the
1918 packet. When all the fragments are freed, the IP4_TXTOKEN_WRAP
1919 will be deleted from the Map, and user's event signalled.
1920 Because Ip4CancelPacket and other functions are all called in
1921 line, so, after Ip4CancelPacket returns, the Item has been freed.
1923 @param[in] Map The IP4 child's transmit queue.
1924 @param[in] Item The current transmitted packet to test.
1925 @param[in] Context The user's token to cancel.
1927 @retval EFI_SUCCESS Continue to check the next Item.
1928 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
1935 IN NET_MAP_ITEM
*Item
,
1939 EFI_IP4_COMPLETION_TOKEN
*Token
;
1940 IP4_TXTOKEN_WRAP
*Wrap
;
1942 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
1945 // Return EFI_SUCCESS to check the next item in the map if
1946 // this one doesn't match.
1948 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
1952 Wrap
= (IP4_TXTOKEN_WRAP
*) Item
->Value
;
1953 ASSERT (Wrap
!= NULL
);
1956 // Don't access the Item, Wrap and Token's members after this point.
1957 // Item and wrap has been freed. And we no longer own the Token.
1959 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
1962 // If only one item is to be cancel, return EFI_ABORTED to stop
1963 // iterating the map any more.
1965 if (Token
!= NULL
) {
1974 Cancel the receive request. This is quiet simple, because
1975 it is only enqueued in our local receive map.
1977 @param[in] Map The IP4 child's receive queue.
1978 @param[in] Item Current receive request to cancel.
1979 @param[in] Context The user's token to cancel.
1981 @retval EFI_SUCCESS Continue to check the next receive request on the
1983 @retval EFI_ABORTED The user's token (token != NULL) has been
1991 IN NET_MAP_ITEM
*Item
,
1995 EFI_IP4_COMPLETION_TOKEN
*Token
;
1996 EFI_IP4_COMPLETION_TOKEN
*This
;
1998 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
2001 if ((Token
!= NULL
) && (Token
!= This
)) {
2005 NetMapRemoveItem (Map
, Item
, NULL
);
2007 This
->Status
= EFI_ABORTED
;
2008 This
->Packet
.RxData
= NULL
;
2009 gBS
->SignalEvent (This
->Event
);
2011 if (Token
!= NULL
) {
2020 Cancel the user's receive/transmit request.
2022 @param[in] IpInstance The IP4 child.
2023 @param[in] Token The token to cancel. If NULL, all token will be
2026 @retval EFI_SUCCESS The token is cancelled.
2027 @retval EFI_NOT_FOUND The token isn't found on either the
2028 transmit/receive queue.
2029 @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.
2034 IN IP4_PROTOCOL
*IpInstance
,
2035 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2041 // First check the transmitted packet. Ip4CancelTxTokens returns
2042 // EFI_ABORTED to mean that the token has been cancelled when
2043 // token != NULL. So, return EFI_SUCCESS for this condition.
2045 Status
= NetMapIterate (&IpInstance
->TxTokens
, Ip4CancelTxTokens
, Token
);
2047 if (EFI_ERROR (Status
)) {
2048 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2056 // Check the receive queue. Ip4CancelRxTokens also returns EFI_ABORT
2057 // for Token!=NULL and it is cancelled.
2059 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4CancelRxTokens
, Token
);
2061 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
2065 if (EFI_ERROR (Status
)) {
2066 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2074 // OK, if the Token is found when Token != NULL, the NetMapIterate
2075 // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.
2077 if (Token
!= NULL
) {
2078 return EFI_NOT_FOUND
;
2082 // If Token == NULL, cancel all the tokens. return error if no
2083 // all of them are cancelled.
2085 if (!NetMapIsEmpty (&IpInstance
->TxTokens
) ||
2086 !NetMapIsEmpty (&IpInstance
->RxTokens
)) {
2088 return EFI_DEVICE_ERROR
;
2096 Abort an asynchronous transmit or receive request.
2098 The Cancel() function is used to abort a pending transmit or receive request.
2099 If the token is in the transmit or receive request queues, after calling this
2100 function, Token->Status will be set to EFI_ABORTED and then Token->Event will
2101 be signaled. If the token is not in one of the queues, which usually means the
2102 asynchronous operation has completed, this function will not signal the token
2103 and EFI_NOT_FOUND is returned.
2105 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2106 @param[in] Token Pointer to a token that has been issued by
2107 EFI_IP4_PROTOCOL.Transmit() or
2108 EFI_IP4_PROTOCOL.Receive(). If NULL, all pending
2109 tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is
2110 defined in EFI_IP4_PROTOCOL.Transmit().
2112 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
2113 Token.->Event was signaled. When Token is NULL, all
2114 pending requests were aborted and their events were signaled.
2115 @retval EFI_INVALID_PARAMETER This is NULL.
2116 @retval EFI_NOT_STARTED This instance has not been started.
2117 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2118 RARP, etc.) is not finished yet.
2119 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
2120 not found in the transmit or receive queue. It has either completed
2121 or was not issued by Transmit() and Receive().
2127 IN EFI_IP4_PROTOCOL
*This
,
2128 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2131 IP4_PROTOCOL
*IpInstance
;
2136 return EFI_INVALID_PARAMETER
;
2139 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2141 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2143 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
2144 Status
= EFI_NOT_STARTED
;
2148 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
2149 Status
= EFI_NO_MAPPING
;
2153 Status
= Ip4Cancel (IpInstance
, Token
);
2156 gBS
->RestoreTPL (OldTpl
);
2162 Polls for incoming data packets and processes outgoing data packets.
2164 The Poll() function polls for incoming data packets and processes outgoing data
2165 packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()
2166 function to increase the rate that data packets are moved between the communications
2167 device and the transmit and receive queues.
2169 In some systems the periodic timer event may not poll the underlying communications
2170 device fast enough to transmit and/or receive all data packets without missing
2171 incoming packets or dropping outgoing packets. Drivers and applications that are
2172 experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function
2175 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2177 @retval EFI_SUCCESS Incoming or outgoing data was processed.
2178 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2179 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2180 RARP, etc.) is not finished yet.
2181 @retval EFI_INVALID_PARAMETER This is NULL.
2182 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2183 @retval EFI_NOT_READY No incoming or outgoing data is processed.
2184 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
2185 Consider increasing the polling rate.
2191 IN EFI_IP4_PROTOCOL
*This
2194 IP4_PROTOCOL
*IpInstance
;
2195 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
2198 return EFI_INVALID_PARAMETER
;
2201 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2203 if (IpInstance
->State
== IP4_STATE_UNCONFIGED
) {
2204 return EFI_NOT_STARTED
;
2207 Mnp
= IpInstance
->Service
->Mnp
;
2210 // Don't lock the Poll function to enable the deliver of
2211 // the packet polled up.
2213 return Mnp
->Poll (Mnp
);
2217 Decrease the life of the transmitted packets. If it is
2218 decreased to zero, cancel the packet. This function is
2219 called by Ip4PacketTimerTicking which time out both the
2220 received-but-not-delivered and transmitted-but-not-recycle
2223 @param[in] Map The IP4 child's transmit map.
2224 @param[in] Item Current transmitted packet.
2225 @param[in] Context Not used.
2227 @retval EFI_SUCCESS Always returns EFI_SUCCESS.
2232 Ip4SentPacketTicking (
2234 IN NET_MAP_ITEM
*Item
,
2238 IP4_TXTOKEN_WRAP
*Wrap
;
2240 Wrap
= (IP4_TXTOKEN_WRAP
*) Item
->Value
;
2241 ASSERT (Wrap
!= NULL
);
2243 if ((Wrap
->Life
> 0) && (--Wrap
->Life
== 0)) {
2244 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
2251 This heart beat timer of IP4 service instance times out all of its IP4 children's
2252 received-but-not-delivered and transmitted-but-not-recycle packets, and provides
2253 time input for its IGMP protocol.
2255 @param[in] Event The IP4 service instance's heart beat timer.
2256 @param[in] Context The IP4 service instance.
2268 IpSb
= (IP4_SERVICE
*) Context
;
2269 NET_CHECK_SIGNATURE (IpSb
, IP4_SERVICE_SIGNATURE
);
2271 Ip4PacketTimerTicking (IpSb
);
2272 Ip4IgmpTicking (IpSb
);
2276 This dedicated timer is used to poll underlying network media status. In case
2277 of cable swap or wireless network switch, a new round auto configuration will
2278 be initiated. The timer will signal the IP4 to run DHCP configuration again.
2279 IP4 driver will free old IP address related resource, such as route table and
2280 Interface, then initiate a DHCP process to acquire new IP, eventually create
2281 route table for new IP address.
2283 @param[in] Event The IP4 service instance's heart beat timer.
2284 @param[in] Context The IP4 service instance.
2289 Ip4TimerReconfigChecking (
2295 BOOLEAN OldMediaPresent
;
2297 EFI_SIMPLE_NETWORK_MODE SnpModeData
;
2299 IpSb
= (IP4_SERVICE
*) Context
;
2300 NET_CHECK_SIGNATURE (IpSb
, IP4_SERVICE_SIGNATURE
);
2302 OldMediaPresent
= IpSb
->MediaPresent
;
2305 // Get fresh mode data from MNP, since underlying media status may change.
2306 // Here, it needs to mention that the MediaPresent can also be checked even if
2307 // EFI_NOT_STARTED returned while this MNP child driver instance isn't configured.
2309 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, NULL
, &SnpModeData
);
2310 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
2314 IpSb
->MediaPresent
= SnpModeData
.MediaPresent
;
2316 // Media transimit Unpresent to Present means new link movement is detected.
2318 if (!OldMediaPresent
&& IpSb
->MediaPresent
&& (IpSb
->Ip4Config2Instance
.Policy
== Ip4Config2PolicyDhcp
)) {
2320 // Signal the IP4 to run the dhcp configuration again. IP4 driver will free
2321 // old IP address related resource, such as route table and Interface, then
2322 // initiate a DHCP round to acquire new IP, eventually
2323 // create route table for new IP address.
2325 if (IpSb
->ReconfigEvent
!= NULL
) {
2326 Status
= gBS
->SignalEvent (IpSb
->ReconfigEvent
);