3 Copyright (c) 2005 - 2009, Intel Corporation.<BR>
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.
19 The GetModeData() function returns the current operational mode data for this
20 driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This
21 function is used optionally to retrieve the operational mode data of underlying
24 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
25 @param[out] Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.
26 @param[out] MnpConfigData Pointer to the managed network configuration data structure.
27 @param[out] SnpModeData Pointer to the simple network mode data structure.
29 @retval EFI_SUCCESS The operation completed successfully.
30 @retval EFI_INVALID_PARAMETER This is NULL.
31 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
37 IN CONST EFI_IP4_PROTOCOL
*This
,
38 OUT EFI_IP4_MODE_DATA
*Ip4ModeData OPTIONAL
,
39 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
40 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
44 Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
46 The Configure() function is used to set, change, or reset the operational
47 parameters and filter settings for this EFI IPv4 Protocol instance. Until these
48 parameters have been set, no network traffic can be sent or received by this
49 instance. Once the parameters have been reset (by calling this function with
50 IpConfigData set to NULL), no more traffic can be sent or received until these
51 parameters have been set again. Each EFI IPv4 Protocol instance can be started
52 and stopped independently of each other by enabling or disabling their receive
53 filter settings with the Configure() function.
55 When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will
56 be appended as an alias address into the addresses list in the EFI IPv4 Protocol
57 driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL
58 to retrieve the default IPv4 address if it is not available yet. Clients could
59 frequently call GetModeData() to check the status to ensure that the default IPv4
62 If operational parameters are reset or changed, any pending transmit and receive
63 requests will be cancelled. Their completion token status will be set to EFI_ABORTED
64 and their events will be signaled.
66 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
67 @param[in] IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.
69 @retval EFI_SUCCESS The driver instance was successfully opened.
70 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
71 RARP, etc.) is not finished yet.
72 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
73 @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:
74 A configuration protocol (DHCP, BOOTP, RARP, etc.) could
75 not be located when clients choose to use the default IPv4
76 address. This EFI IPv4 Protocol implementation does not
77 support this requested filter or timeout setting.
78 @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.
79 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the
80 IPv4 address or subnet mask can be changed. The interface must
81 also be stopped when switching to/from raw packet mode.
82 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4
83 Protocol driver instance is not opened.
89 IN EFI_IP4_PROTOCOL
*This
,
90 IN EFI_IP4_CONFIG_DATA
*IpConfigData OPTIONAL
94 Joins and leaves multicast groups.
96 The Groups() function is used to join and leave multicast group sessions. Joining
97 a group will enable reception of matching multicast packets. Leaving a group will
98 disable the multicast packet reception.
100 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
102 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
103 @param[in] JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.
104 @param[in] GroupAddress Pointer to the IPv4 multicast address.
106 @retval EFI_SUCCESS The operation completed successfully.
107 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
109 - JoinFlag is TRUE and GroupAddress is NULL.
110 - GroupAddress is not NULL and *GroupAddress is
111 not a multicast IPv4 address.
112 @retval EFI_NOT_STARTED This instance has not been started.
113 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
114 RARP, etc.) is not finished yet.
115 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
116 @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.
117 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
119 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
120 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
126 IN EFI_IP4_PROTOCOL
*This
,
128 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
132 Adds and deletes routing table entries.
134 The Routes() function adds a route to or deletes a route from the routing table.
136 Routes are determined by comparing the SubnetAddress with the destination IPv4
137 address arithmetically AND-ed with the SubnetMask. The gateway address must be
138 on the same subnet as the configured station address.
140 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
141 The default route matches all destination IPv4 addresses that do not match any
144 A GatewayAddress that is zero is a nonroute. Packets are sent to the destination
145 IP address if it can be found in the ARP cache or on the local subnet. One automatic
146 nonroute entry will be inserted into the routing table for outgoing packets that
147 are addressed to a local subnet (gateway address of 0.0.0.0).
149 Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI
150 IPv4 Protocol instances that use the default IPv4 address will also have copies
151 of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these
152 copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its
153 instances. As a result, client modification to the routing table will be lost.
155 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
156 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
157 FALSE to add this route to the routing table. SubnetAddress
158 and SubnetMask are used as the key to each route entry.
159 @param[in] SubnetAddress The address of the subnet that needs to be routed.
160 @param[in] SubnetMask The subnet mask of SubnetAddress.
161 @param[in] GatewayAddress The unicast gateway IPv4 address for this route.
163 @retval EFI_SUCCESS The operation completed successfully.
164 @retval EFI_NOT_STARTED The driver instance has not been started.
165 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
166 RARP, etc.) is not finished yet.
167 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
169 - SubnetAddress is NULL.
170 - SubnetMask is NULL.
171 - GatewayAddress is NULL.
172 - *SubnetAddress is not a valid subnet address.
173 - *SubnetMask is not a valid subnet mask.
174 - *GatewayAddress is not a valid unicast IPv4 address.
175 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
176 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
177 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
178 DeleteRoute is FALSE).
184 IN EFI_IP4_PROTOCOL
*This
,
185 IN BOOLEAN DeleteRoute
,
186 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
187 IN EFI_IPv4_ADDRESS
*SubnetMask
,
188 IN EFI_IPv4_ADDRESS
*GatewayAddress
192 Places outgoing data packets into the transmit queue.
194 The Transmit() function places a sending request in the transmit queue of this
195 EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some
196 errors occur, the event in the token will be signaled and the status is updated.
198 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
199 @param[in] Token Pointer to the transmit token.
201 @retval EFI_SUCCESS The data has been queued for transmission.
202 @retval EFI_NOT_STARTED This instance has not been started.
203 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
204 RARP, etc.) is not finished yet.
205 @retval EFI_INVALID_PARAMETER One or more pameters are invalid.
206 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event
207 was already in the transmit queue.
208 @retval EFI_NOT_READY The completion token could not be queued because the transmit
210 @retval EFI_NOT_FOUND Not route is found to destination address.
211 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
212 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
214 @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is
215 greater than MTU (or greater than the maximum packet size if
216 Token.Packet.TxData.OverrideData.
217 DoNotFragment is TRUE.)
223 IN EFI_IP4_PROTOCOL
*This
,
224 IN EFI_IP4_COMPLETION_TOKEN
*Token
228 Places a receiving request into the receiving queue.
230 The Receive() function places a completion token into the receive packet queue.
231 This function is always asynchronous.
233 The Token.Event field in the completion token must be filled in by the caller
234 and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol
235 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
238 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
239 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
241 @retval EFI_SUCCESS The receive completion token was cached.
242 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
243 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)
245 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
248 - Token.Event is NULL.
249 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
250 resources (usually memory).
251 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
252 The EFI IPv4 Protocol instance has been reset to startup defaults.
253 EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
254 in the receive queue.
255 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
256 @retval EFI_ICMP_ERROR An ICMP error packet was received.
262 IN EFI_IP4_PROTOCOL
*This
,
263 IN EFI_IP4_COMPLETION_TOKEN
*Token
267 Abort an asynchronous transmit or receive request.
269 The Cancel() function is used to abort a pending transmit or receive request.
270 If the token is in the transmit or receive request queues, after calling this
271 function, Token->Status will be set to EFI_ABORTED and then Token->Event will
272 be signaled. If the token is not in one of the queues, which usually means the
273 asynchronous operation has completed, this function will not signal the token
274 and EFI_NOT_FOUND is returned.
276 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
277 @param[in] Token Pointer to a token that has been issued by
278 EFI_IP4_PROTOCOL.Transmit() or
279 EFI_IP4_PROTOCOL.Receive(). If NULL, all pending
280 tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is
281 defined in EFI_IP4_PROTOCOL.Transmit().
283 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
284 Token.->Event was signaled. When Token is NULL, all
285 pending requests were aborted and their events were signaled.
286 @retval EFI_INVALID_PARAMETER This is NULL.
287 @retval EFI_NOT_STARTED This instance has not been started.
288 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
289 RARP, etc.) is not finished yet.
290 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
291 not found in the transmit or receive queue. It has either completed
292 or was not issued by Transmit() and Receive().
298 IN EFI_IP4_PROTOCOL
*This
,
299 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
303 Polls for incoming data packets and processes outgoing data packets.
305 The Poll() function polls for incoming data packets and processes outgoing data
306 packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()
307 function to increase the rate that data packets are moved between the communications
308 device and the transmit and receive queues.
310 In some systems the periodic timer event may not poll the underlying communications
311 device fast enough to transmit and/or receive all data packets without missing
312 incoming packets or dropping outgoing packets. Drivers and applications that are
313 experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function
316 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
318 @retval EFI_SUCCESS Incoming or outgoing data was processed.
319 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
320 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
321 RARP, etc.) is not finished yet.
322 @retval EFI_INVALID_PARAMETER This is NULL.
323 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
324 @retval EFI_NOT_READY No incoming or outgoing data is processed.
325 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
326 Consider increasing the polling rate.
332 IN EFI_IP4_PROTOCOL
*This
336 mEfiIp4ProtocolTemplete
= {
348 Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.
350 The GetModeData() function returns the current operational mode data for this
351 driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This
352 function is used optionally to retrieve the operational mode data of underlying
355 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
356 @param[out] Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.
357 @param[out] MnpConfigData Pointer to the managed network configuration data structure.
358 @param[out] SnpModeData Pointer to the simple network mode data structure.
360 @retval EFI_SUCCESS The operation completed successfully.
361 @retval EFI_INVALID_PARAMETER This is NULL.
362 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
368 IN CONST EFI_IP4_PROTOCOL
*This
,
369 OUT EFI_IP4_MODE_DATA
*Ip4ModeData OPTIONAL
,
370 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
371 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
374 IP4_PROTOCOL
*IpInstance
;
376 EFI_IP4_CONFIG_DATA
*Config
;
382 return EFI_INVALID_PARAMETER
;
385 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
386 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
387 IpSb
= IpInstance
->Service
;
389 if (Ip4ModeData
!= NULL
) {
391 // IsStarted is "whether the EfiIp4Configure has been called".
392 // IsConfigured is "whether the station address has been configured"
394 Ip4ModeData
->IsStarted
= (BOOLEAN
)(IpInstance
->State
== IP4_STATE_CONFIGED
);
395 CopyMem (&Ip4ModeData
->ConfigData
, &IpInstance
->ConfigData
, sizeof (Ip4ModeData
->ConfigData
));
396 Ip4ModeData
->IsConfigured
= FALSE
;
398 Ip4ModeData
->GroupCount
= IpInstance
->GroupCount
;
399 Ip4ModeData
->GroupTable
= (EFI_IPv4_ADDRESS
*) IpInstance
->Groups
;
401 Ip4ModeData
->IcmpTypeCount
= 23;
402 Ip4ModeData
->IcmpTypeList
= mIp4SupportedIcmp
;
404 Ip4ModeData
->RouteTable
= NULL
;
405 Ip4ModeData
->RouteCount
= 0;
408 // return the current station address for this IP child. So,
409 // the user can get the default address through this. Some
410 // application wants to know it station address even it is
411 // using the default one, such as a ftp server.
413 if (Ip4ModeData
->IsStarted
) {
414 Config
= &Ip4ModeData
->ConfigData
;
416 Ip
= HTONL (IpInstance
->Interface
->Ip
);
417 CopyMem (&Config
->StationAddress
, &Ip
, sizeof (EFI_IPv4_ADDRESS
));
419 Ip
= HTONL (IpInstance
->Interface
->SubnetMask
);
420 CopyMem (&Config
->SubnetMask
, &Ip
, sizeof (EFI_IPv4_ADDRESS
));
422 Ip4ModeData
->IsConfigured
= IpInstance
->Interface
->Configured
;
425 // Build a EFI route table for user from the internal route table.
427 Status
= Ip4BuildEfiRouteTable (IpInstance
);
429 if (EFI_ERROR (Status
)) {
430 gBS
->RestoreTPL (OldTpl
);
434 Ip4ModeData
->RouteTable
= IpInstance
->EfiRouteTable
;
435 Ip4ModeData
->RouteCount
= IpInstance
->EfiRouteCount
;
439 if (MnpConfigData
!= NULL
) {
440 CopyMem (MnpConfigData
, &IpSb
->MnpConfigData
, sizeof (*MnpConfigData
));
443 if (SnpModeData
!= NULL
) {
444 CopyMem (SnpModeData
, &IpSb
->SnpMode
, sizeof (*SnpModeData
));
447 gBS
->RestoreTPL (OldTpl
);
453 Config the MNP parameter used by IP. The IP driver use one MNP
454 child to transmit/receive frames. By default, it configures MNP
455 to receive unicast/multicast/broadcast. And it will enable/disable
456 the promiscous receive according to whether there is IP child
457 enable that or not. If Force is FALSE, it will iterate through
458 all the IP children to check whether the promiscuous receive
459 setting has been changed. If it hasn't been changed, it won't
460 reconfigure the MNP. If Force is TRUE, the MNP is configured no
461 matter whether that is changed or not.
463 @param[in] IpSb The IP4 service instance that is to be changed.
464 @param[in] Force Force the configuration or not.
466 @retval EFI_SUCCESS The MNP is successfully configured/reconfigured.
467 @retval Others Configuration failed.
471 Ip4ServiceConfigMnp (
472 IN IP4_SERVICE
*IpSb
,
477 LIST_ENTRY
*ProtoEntry
;
479 IP4_PROTOCOL
*IpInstance
;
481 BOOLEAN PromiscReceive
;
485 PromiscReceive
= FALSE
;
489 // Iterate through the IP children to check whether promiscuous
490 // receive setting has been changed. Update the interface's receive
493 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
495 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP4_INTERFACE
, Link
);
496 IpIf
->PromiscRecv
= FALSE
;
498 NET_LIST_FOR_EACH (ProtoEntry
, &IpIf
->IpInstances
) {
499 IpInstance
= NET_LIST_USER_STRUCT (ProtoEntry
, IP4_PROTOCOL
, AddrLink
);
501 if (IpInstance
->ConfigData
.AcceptPromiscuous
) {
502 IpIf
->PromiscRecv
= TRUE
;
503 PromiscReceive
= TRUE
;
509 // If promiscuous receive isn't changed, it isn't necessary to reconfigure.
511 if (PromiscReceive
== IpSb
->MnpConfigData
.EnablePromiscuousReceive
) {
516 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= PromiscReceive
;
519 Status
= IpSb
->Mnp
->Configure (IpSb
->Mnp
, &IpSb
->MnpConfigData
);
522 // recover the original configuration if failed to set the configure.
524 if (EFI_ERROR (Status
) && Reconfig
) {
525 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= (BOOLEAN
) !PromiscReceive
;
533 The event handle for IP4 auto configuration. If IP is asked
534 to reconfigure the default address. The original default
535 interface and route table are removed as the default. If there
536 is active IP children using the default address, the interface
537 will remain valid until all the children have freed their
538 references. If IP is signalled when auto configuration is done,
539 it will configure the default interface and default route table
540 with the configuration information retrieved by IP4_CONFIGURE.
542 @param[in] Context The IP4 service binding instance.
547 Ip4AutoConfigCallBackDpc (
551 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
552 EFI_IP4_IPCONFIG_DATA
*Data
;
553 EFI_IP4_ROUTE_TABLE
*RouteEntry
;
555 IP4_ROUTE_TABLE
*RouteTable
;
561 IpSb
= (IP4_SERVICE
*) Context
;
562 NET_CHECK_SIGNATURE (IpSb
, IP4_SERVICE_SIGNATURE
);
564 Ip4Config
= IpSb
->Ip4Config
;
567 // IP is asked to do the reconfiguration. If the default interface
568 // has been configured, release the default interface and route
569 // table, then create a new one. If there are some IP children
570 // using it, the interface won't be physically freed until all the
571 // children have released their reference to it. Also remember to
572 // restart the receive on the default address. IP4 driver only receive
573 // frames on the default address, and when the default interface is
574 // freed, Ip4AcceptFrame won't be informed.
576 if (IpSb
->ActiveEvent
== IpSb
->ReconfigEvent
) {
578 if (IpSb
->DefaultInterface
->Configured
) {
579 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
585 RouteTable
= Ip4CreateRouteTable ();
587 if (RouteTable
== NULL
) {
588 Ip4FreeInterface (IpIf
, NULL
);
592 Ip4CancelReceive (IpSb
->DefaultInterface
);
593 Ip4FreeInterface (IpSb
->DefaultInterface
, NULL
);
594 Ip4FreeRouteTable (IpSb
->DefaultRouteTable
);
596 IpSb
->DefaultInterface
= IpIf
;
597 InsertHeadList (&IpSb
->Interfaces
, &IpIf
->Link
);
599 IpSb
->DefaultRouteTable
= RouteTable
;
600 Ip4ReceiveFrame (IpIf
, NULL
, Ip4AccpetFrame
, IpSb
);
603 Ip4Config
->Stop (Ip4Config
);
604 Ip4Config
->Start (Ip4Config
, IpSb
->DoneEvent
, IpSb
->ReconfigEvent
);
609 // Get the configure data in two steps: get the length then the data.
613 if (Ip4Config
->GetData (Ip4Config
, &Len
, NULL
) != EFI_BUFFER_TOO_SMALL
) {
617 Data
= AllocatePool (Len
);
623 Status
= Ip4Config
->GetData (Ip4Config
, &Len
, Data
);
625 if (EFI_ERROR (Status
)) {
629 IpIf
= IpSb
->DefaultInterface
;
632 // If the default address has been configured don't change it.
633 // This is unlikely to happen if EFI_IP4_CONFIG protocol has
634 // informed us to reconfigure each time it wants to change the
635 // configuration parameters.
637 if (IpIf
->Configured
) {
642 // Set the default interface's address, then add a directed
643 // route for it, that is, the route whose nexthop is zero.
645 Status
= Ip4SetAddress (
647 EFI_NTOHL (Data
->StationAddress
),
648 EFI_NTOHL (Data
->SubnetMask
)
651 if (EFI_ERROR (Status
)) {
656 IpSb
->DefaultRouteTable
,
657 EFI_NTOHL (Data
->StationAddress
),
658 EFI_NTOHL (Data
->SubnetMask
),
663 // Add routes returned by EFI_IP4_CONFIG protocol.
665 for (Index
= 0; Index
< Data
->RouteTableSize
; Index
++) {
666 RouteEntry
= &Data
->RouteTable
[Index
];
669 IpSb
->DefaultRouteTable
,
670 EFI_NTOHL (RouteEntry
->SubnetAddress
),
671 EFI_NTOHL (RouteEntry
->SubnetMask
),
672 EFI_NTOHL (RouteEntry
->GatewayAddress
)
676 IpSb
->State
= IP4_SERVICE_CONFIGED
;
678 Ip4SetVariableData (IpSb
);
681 gBS
->FreePool (Data
);
685 Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK.
687 @param Event The event that is signalled.
688 @param Context The IP4 service binding instance.
693 Ip4AutoConfigCallBack (
700 IpSb
= (IP4_SERVICE
*) Context
;
701 IpSb
->ActiveEvent
= Event
;
704 // Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK
706 QueueDpc (TPL_CALLBACK
, Ip4AutoConfigCallBackDpc
, Context
);
711 Start the auto configuration for this IP service instance.
712 It will locates the EFI_IP4_CONFIG_PROTOCOL, then start the
715 @param[in] IpSb The IP4 service instance to configure
717 @retval EFI_SUCCESS The auto configuration is successfull started
718 @retval Others Failed to start auto configuration.
726 EFI_IP4_CONFIG_PROTOCOL
*Ip4Config
;
729 if (IpSb
->State
> IP4_SERVICE_UNSTARTED
) {
734 // Create the DoneEvent and ReconfigEvent to call EFI_IP4_CONFIG
736 Status
= gBS
->CreateEvent (
739 Ip4AutoConfigCallBack
,
744 if (EFI_ERROR (Status
)) {
748 Status
= gBS
->CreateEvent (
751 Ip4AutoConfigCallBack
,
756 if (EFI_ERROR (Status
)) {
757 goto CLOSE_DONE_EVENT
;
761 // Open the EFI_IP4_CONFIG protocol then start auto configure
763 Status
= gBS
->OpenProtocol (
765 &gEfiIp4ConfigProtocolGuid
,
766 (VOID
**) &Ip4Config
,
769 EFI_OPEN_PROTOCOL_BY_DRIVER
| EFI_OPEN_PROTOCOL_EXCLUSIVE
772 if (EFI_ERROR (Status
)) {
773 Status
= EFI_UNSUPPORTED
;
774 goto CLOSE_RECONFIG_EVENT
;
777 Status
= Ip4Config
->Start (Ip4Config
, IpSb
->DoneEvent
, IpSb
->ReconfigEvent
);
779 if (EFI_ERROR (Status
)) {
782 &gEfiIp4ConfigProtocolGuid
,
787 goto CLOSE_RECONFIG_EVENT
;
790 IpSb
->Ip4Config
= Ip4Config
;
791 IpSb
->State
= IP4_SERVICE_STARTED
;
794 CLOSE_RECONFIG_EVENT
:
795 gBS
->CloseEvent (IpSb
->ReconfigEvent
);
796 IpSb
->ReconfigEvent
= NULL
;
799 gBS
->CloseEvent (IpSb
->DoneEvent
);
800 IpSb
->DoneEvent
= NULL
;
807 Intiialize the IP4_PROTOCOL structure to the unconfigured states.
809 @param IpSb The IP4 service instance.
810 @param IpInstance The IP4 child instance.
815 IN IP4_SERVICE
*IpSb
,
816 IN OUT IP4_PROTOCOL
*IpInstance
819 ASSERT ((IpSb
!= NULL
) && (IpInstance
!= NULL
));
821 ZeroMem (IpInstance
, sizeof (IP4_PROTOCOL
));
823 IpInstance
->Signature
= IP4_PROTOCOL_SIGNATURE
;
824 CopyMem (&IpInstance
->Ip4Proto
, &mEfiIp4ProtocolTemplete
, sizeof (IpInstance
->Ip4Proto
));
825 IpInstance
->State
= IP4_STATE_UNCONFIGED
;
826 IpInstance
->Service
= IpSb
;
828 InitializeListHead (&IpInstance
->Link
);
829 NetMapInit (&IpInstance
->RxTokens
);
830 NetMapInit (&IpInstance
->TxTokens
);
831 InitializeListHead (&IpInstance
->Received
);
832 InitializeListHead (&IpInstance
->Delivered
);
833 InitializeListHead (&IpInstance
->AddrLink
);
835 EfiInitializeLock (&IpInstance
->RecycleLock
, TPL_NOTIFY
);
840 Configure the IP4 child. If the child is already configured,
841 change the configuration parameter. Otherwise configure it
842 for the first time. The caller should validate the configuration
843 before deliver them to it. It also don't do configure NULL.
845 @param[in, out] IpInstance The IP4 child to configure.
846 @param[in] Config The configure data.
848 @retval EFI_SUCCESS The IP4 child is successfully configured.
849 @retval EFI_DEVICE_ERROR Failed to free the pending transive or to
850 configure underlying MNP or other errors.
851 @retval EFI_NO_MAPPING The IP4 child is configured to use default
852 address, but the default address hasn't been
853 configured. The IP4 child doesn't need to be
854 reconfigured when default address is configured.
855 @retval EFI_OUT_OF_RESOURCES No more memory space is available.
856 @retval other Other error occurs.
861 IN OUT IP4_PROTOCOL
*IpInstance
,
862 IN EFI_IP4_CONFIG_DATA
*Config
871 IpSb
= IpInstance
->Service
;
874 // User is changing packet filters. It must be stopped
875 // before the station address can be changed.
877 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
879 // Cancel all the pending transmit/receive from upper layer
881 Status
= Ip4Cancel (IpInstance
, NULL
);
883 if (EFI_ERROR (Status
)) {
884 return EFI_DEVICE_ERROR
;
887 CopyMem (&IpInstance
->ConfigData
, Config
, sizeof (IpInstance
->ConfigData
));
892 // Configure a fresh IP4 protocol instance. Create a route table.
893 // Each IP child has its own route table, which may point to the
894 // default table if it is using default address.
896 Status
= EFI_OUT_OF_RESOURCES
;
897 IpInstance
->RouteTable
= Ip4CreateRouteTable ();
899 if (IpInstance
->RouteTable
== NULL
) {
904 // Set up the interface.
906 CopyMem (&Ip
, &Config
->StationAddress
, sizeof (IP4_ADDR
));
907 CopyMem (&Netmask
, &Config
->SubnetMask
, sizeof (IP4_ADDR
));
910 Netmask
= NTOHL (Netmask
);
912 if (!Config
->UseDefaultAddress
) {
914 // Find whether there is already an interface with the same
915 // station address. All the instances with the same station
916 // address shares one interface.
918 IpIf
= Ip4FindStationAddress (IpSb
, Ip
, Netmask
);
924 IpIf
= Ip4CreateInterface (IpSb
->Mnp
, IpSb
->Controller
, IpSb
->Image
);
930 Status
= Ip4SetAddress (IpIf
, Ip
, Netmask
);
932 if (EFI_ERROR (Status
)) {
933 Status
= EFI_DEVICE_ERROR
;
934 Ip4FreeInterface (IpIf
, IpInstance
);
938 InsertTailList (&IpSb
->Interfaces
, &IpIf
->Link
);
942 // Add a route to this connected network in the route table
944 Ip4AddRoute (IpInstance
->RouteTable
, Ip
, Netmask
, IP4_ALLZERO_ADDRESS
);
948 // Use the default address. If the default configuration hasn't
949 // been started, start it.
951 if (IpSb
->State
== IP4_SERVICE_UNSTARTED
) {
952 Status
= Ip4StartAutoConfig (IpSb
);
954 if (EFI_ERROR (Status
)) {
959 IpIf
= IpSb
->DefaultInterface
;
960 NET_GET_REF (IpSb
->DefaultInterface
);
963 // If default address is used, so is the default route table.
964 // Any route set by the instance has the precedence over the
965 // routes in the default route table. Link the default table
966 // after the instance's table. Routing will search the local
969 NET_GET_REF (IpSb
->DefaultRouteTable
);
970 IpInstance
->RouteTable
->Next
= IpSb
->DefaultRouteTable
;
973 IpInstance
->Interface
= IpIf
;
974 InsertTailList (&IpIf
->IpInstances
, &IpInstance
->AddrLink
);
976 CopyMem (&IpInstance
->ConfigData
, Config
, sizeof (IpInstance
->ConfigData
));
977 IpInstance
->State
= IP4_STATE_CONFIGED
;
980 // Although EFI_NO_MAPPING is an error code, the IP child has been
981 // successfully configured and doesn't need reconfiguration when
982 // default address is acquired.
984 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
985 return EFI_NO_MAPPING
;
991 Ip4FreeRouteTable (IpInstance
->RouteTable
);
992 IpInstance
->RouteTable
= NULL
;
998 Clean up the IP4 child, release all the resources used by it.
1000 @param[in] IpInstance The IP4 child to clean up.
1002 @retval EFI_SUCCESS The IP4 child is cleaned up
1003 @retval EFI_DEVICE_ERROR Some resources failed to be released
1008 IN IP4_PROTOCOL
*IpInstance
1011 if (EFI_ERROR (Ip4Cancel (IpInstance
, NULL
))) {
1012 return EFI_DEVICE_ERROR
;
1015 if (EFI_ERROR (Ip4Groups (IpInstance
, FALSE
, NULL
))) {
1016 return EFI_DEVICE_ERROR
;
1020 // Some packets haven't been recycled. It is because either the
1021 // user forgets to recycle the packets, or because the callback
1022 // hasn't been called. Just leave it alone.
1024 if (!IsListEmpty (&IpInstance
->Delivered
)) {
1028 if (IpInstance
->Interface
!= NULL
) {
1029 RemoveEntryList (&IpInstance
->AddrLink
);
1030 Ip4FreeInterface (IpInstance
->Interface
, IpInstance
);
1031 IpInstance
->Interface
= NULL
;
1034 if (IpInstance
->RouteTable
!= NULL
) {
1035 if (IpInstance
->RouteTable
->Next
!= NULL
) {
1036 Ip4FreeRouteTable (IpInstance
->RouteTable
->Next
);
1039 Ip4FreeRouteTable (IpInstance
->RouteTable
);
1040 IpInstance
->RouteTable
= NULL
;
1043 if (IpInstance
->EfiRouteTable
!= NULL
) {
1044 gBS
->FreePool (IpInstance
->EfiRouteTable
);
1045 IpInstance
->EfiRouteTable
= NULL
;
1046 IpInstance
->EfiRouteCount
= 0;
1049 if (IpInstance
->Groups
!= NULL
) {
1050 gBS
->FreePool (IpInstance
->Groups
);
1051 IpInstance
->Groups
= NULL
;
1052 IpInstance
->GroupCount
= 0;
1055 NetMapClean (&IpInstance
->TxTokens
);
1057 NetMapClean (&IpInstance
->RxTokens
);
1064 Validate that Ip/Netmask pair is OK to be used as station
1065 address. Only continuous netmasks are supported. and check
1066 that StationAddress is a unicast address on the newtwork.
1068 @param[in] Ip The IP address to validate
1069 @param[in] Netmask The netmaks of the IP
1071 @retval TRUE The Ip/Netmask pair is valid
1072 @retval FALSE The Ip/Netmask pair is invalid
1076 Ip4StationAddressValid (
1081 IP4_ADDR NetBrdcastMask
;
1086 // Only support the station address with 0.0.0.0/0 to enable DHCP client.
1088 if (Netmask
== IP4_ALLZERO_ADDRESS
) {
1089 return (BOOLEAN
) (Ip
== IP4_ALLZERO_ADDRESS
);
1093 // Only support the continuous net masks
1095 if ((Len
= NetGetMaskLength (Netmask
)) == IP4_MASK_NUM
) {
1100 // Station address can't be class D or class E address
1102 if ((Type
= NetGetIpClass (Ip
)) > IP4_ADDR_CLASSC
) {
1107 // Station address can't be subnet broadcast/net broadcast address
1109 if ((Ip
== (Ip
& Netmask
)) || (Ip
== (Ip
| ~Netmask
))) {
1113 NetBrdcastMask
= gIp4AllMasks
[MIN (Len
, Type
<< 3)];
1115 if (Ip
== (Ip
| ~NetBrdcastMask
)) {
1124 Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
1126 The Configure() function is used to set, change, or reset the operational
1127 parameters and filter settings for this EFI IPv4 Protocol instance. Until these
1128 parameters have been set, no network traffic can be sent or received by this
1129 instance. Once the parameters have been reset (by calling this function with
1130 IpConfigData set to NULL), no more traffic can be sent or received until these
1131 parameters have been set again. Each EFI IPv4 Protocol instance can be started
1132 and stopped independently of each other by enabling or disabling their receive
1133 filter settings with the Configure() function.
1135 When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will
1136 be appended as an alias address into the addresses list in the EFI IPv4 Protocol
1137 driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL
1138 to retrieve the default IPv4 address if it is not available yet. Clients could
1139 frequently call GetModeData() to check the status to ensure that the default IPv4
1142 If operational parameters are reset or changed, any pending transmit and receive
1143 requests will be cancelled. Their completion token status will be set to EFI_ABORTED
1144 and their events will be signaled.
1146 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1147 @param[in] IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.
1149 @retval EFI_SUCCESS The driver instance was successfully opened.
1150 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1151 RARP, etc.) is not finished yet.
1152 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1153 @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:
1154 A configuration protocol (DHCP, BOOTP, RARP, etc.) could
1155 not be located when clients choose to use the default IPv4
1156 address. This EFI IPv4 Protocol implementation does not
1157 support this requested filter or timeout setting.
1158 @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.
1159 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the
1160 IPv4 address or subnet mask can be changed. The interface must
1161 also be stopped when switching to/from raw packet mode.
1162 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4
1163 Protocol driver instance is not opened.
1169 IN EFI_IP4_PROTOCOL
*This
,
1170 IN EFI_IP4_CONFIG_DATA
*IpConfigData OPTIONAL
1173 IP4_PROTOCOL
*IpInstance
;
1174 EFI_IP4_CONFIG_DATA
*Current
;
1179 IP4_ADDR SubnetMask
;
1182 // First, validate the parameters
1185 return EFI_INVALID_PARAMETER
;
1188 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1189 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1192 // Validate the configuration first.
1194 if (IpConfigData
!= NULL
) {
1196 // This implementation doesn't support RawData
1198 if (IpConfigData
->RawData
) {
1199 Status
= EFI_UNSUPPORTED
;
1204 CopyMem (&IpAddress
, &IpConfigData
->StationAddress
, sizeof (IP4_ADDR
));
1205 CopyMem (&SubnetMask
, &IpConfigData
->SubnetMask
, sizeof (IP4_ADDR
));
1207 IpAddress
= NTOHL (IpAddress
);
1208 SubnetMask
= NTOHL (SubnetMask
);
1211 // Check whether the station address is a valid unicast address
1213 if (!IpConfigData
->UseDefaultAddress
) {
1214 AddrOk
= Ip4StationAddressValid (IpAddress
, SubnetMask
);
1217 Status
= EFI_INVALID_PARAMETER
;
1223 // User can only update packet filters when already configured.
1224 // If it wants to change the station address, it must configure(NULL)
1225 // the instance first.
1227 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
1228 Current
= &IpInstance
->ConfigData
;
1230 if (Current
->UseDefaultAddress
!= IpConfigData
->UseDefaultAddress
) {
1231 Status
= EFI_ALREADY_STARTED
;
1235 if (!Current
->UseDefaultAddress
&&
1236 (!EFI_IP4_EQUAL (&Current
->StationAddress
, &IpConfigData
->StationAddress
) ||
1237 !EFI_IP4_EQUAL (&Current
->SubnetMask
, &IpConfigData
->SubnetMask
))) {
1238 Status
= EFI_ALREADY_STARTED
;
1242 if (Current
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1243 return EFI_NO_MAPPING
;
1249 // Configure the instance or clean it up.
1251 if (IpConfigData
!= NULL
) {
1252 Status
= Ip4ConfigProtocol (IpInstance
, IpConfigData
);
1254 Status
= Ip4CleanProtocol (IpInstance
);
1257 // Don't change the state if it is DESTORY, consider the following
1258 // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,
1259 // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,
1260 // the unload fails miserably.
1262 if (IpInstance
->State
== IP4_STATE_CONFIGED
) {
1263 IpInstance
->State
= IP4_STATE_UNCONFIGED
;
1268 // Update the MNP's configure data. Ip4ServiceConfigMnp will check
1269 // whether it is necessary to reconfigure the MNP.
1271 Ip4ServiceConfigMnp (IpInstance
->Service
, FALSE
);
1274 // Update the variable data.
1276 Ip4SetVariableData (IpInstance
->Service
);
1279 gBS
->RestoreTPL (OldTpl
);
1286 Change the IP4 child's multicast setting. The caller
1287 should make sure that the parameters is valid.
1289 @param[in] IpInstance The IP4 child to change the setting.
1290 @param[in] JoinFlag TRUE to join the group, otherwise leave it
1291 @param[in] GroupAddress The target group address
1293 @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it
1294 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
1295 @retval EFI_DEVICE_ERROR Failed to set the group configuraton
1296 @retval EFI_SUCCESS Successfully updated the group setting.
1297 @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.
1302 IN IP4_PROTOCOL
*IpInstance
,
1303 IN BOOLEAN JoinFlag
,
1304 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
1312 // Add it to the instance's Groups, and join the group by IGMP.
1313 // IpInstance->Groups is in network byte order. IGMP operates in
1318 // When JoinFlag is TRUE, GroupAddress shouldn't be NULL.
1320 ASSERT (GroupAddress
!= NULL
);
1321 CopyMem (&Group
, GroupAddress
, sizeof (IP4_ADDR
));
1323 for (Index
= 0; Index
< IpInstance
->GroupCount
; Index
++) {
1324 if (IpInstance
->Groups
[Index
] == Group
) {
1325 return EFI_ALREADY_STARTED
;
1329 Members
= Ip4CombineGroups (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1331 if (Members
== NULL
) {
1332 return EFI_OUT_OF_RESOURCES
;
1335 if (EFI_ERROR (Ip4JoinGroup (IpInstance
, NTOHL (Group
)))) {
1336 gBS
->FreePool (Members
);
1337 return EFI_DEVICE_ERROR
;
1340 if (IpInstance
->Groups
!= NULL
) {
1341 gBS
->FreePool (IpInstance
->Groups
);
1344 IpInstance
->Groups
= Members
;
1345 IpInstance
->GroupCount
++;
1351 // Leave the group. Leave all the groups if GroupAddress is NULL.
1352 // Must iterate from the end to the beginning because the GroupCount
1353 // is decreamented each time an address is removed..
1355 for (Index
= IpInstance
->GroupCount
; Index
> 0 ; Index
--) {
1356 Group
= IpInstance
->Groups
[Index
- 1];
1358 if ((GroupAddress
== NULL
) || EFI_IP4_EQUAL (&Group
, GroupAddress
)) {
1359 if (EFI_ERROR (Ip4LeaveGroup (IpInstance
, NTOHL (Group
)))) {
1360 return EFI_DEVICE_ERROR
;
1363 Ip4RemoveGroupAddr (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1364 IpInstance
->GroupCount
--;
1366 if (IpInstance
->GroupCount
== 0) {
1367 ASSERT (Index
== 1);
1369 gBS
->FreePool (IpInstance
->Groups
);
1370 IpInstance
->Groups
= NULL
;
1373 if (GroupAddress
!= NULL
) {
1379 return ((GroupAddress
!= NULL
) ? EFI_NOT_FOUND
: EFI_SUCCESS
);
1384 Joins and leaves multicast groups.
1386 The Groups() function is used to join and leave multicast group sessions. Joining
1387 a group will enable reception of matching multicast packets. Leaving a group will
1388 disable the multicast packet reception.
1390 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
1392 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1393 @param[in] JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.
1394 @param[in] GroupAddress Pointer to the IPv4 multicast address.
1396 @retval EFI_SUCCESS The operation completed successfully.
1397 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
1399 - JoinFlag is TRUE and GroupAddress is NULL.
1400 - GroupAddress is not NULL and *GroupAddress is
1401 not a multicast IPv4 address.
1402 @retval EFI_NOT_STARTED This instance has not been started.
1403 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1404 RARP, etc.) is not finished yet.
1405 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
1406 @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.
1407 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
1409 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
1410 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1416 IN EFI_IP4_PROTOCOL
*This
,
1417 IN BOOLEAN JoinFlag
,
1418 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
1421 IP4_PROTOCOL
*IpInstance
;
1426 if ((This
== NULL
) || (JoinFlag
&& (GroupAddress
== NULL
))) {
1427 return EFI_INVALID_PARAMETER
;
1430 if (GroupAddress
!= NULL
) {
1431 CopyMem (&McastIp
, GroupAddress
, sizeof (IP4_ADDR
));
1433 if (!IP4_IS_MULTICAST (NTOHL (McastIp
))) {
1434 return EFI_INVALID_PARAMETER
;
1438 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1439 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1441 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1442 Status
= EFI_NOT_STARTED
;
1446 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1447 Status
= EFI_NO_MAPPING
;
1451 Status
= Ip4Groups (IpInstance
, JoinFlag
, GroupAddress
);
1454 gBS
->RestoreTPL (OldTpl
);
1460 Adds and deletes routing table entries.
1462 The Routes() function adds a route to or deletes a route from the routing table.
1464 Routes are determined by comparing the SubnetAddress with the destination IPv4
1465 address arithmetically AND-ed with the SubnetMask. The gateway address must be
1466 on the same subnet as the configured station address.
1468 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
1469 The default route matches all destination IPv4 addresses that do not match any
1472 A GatewayAddress that is zero is a nonroute. Packets are sent to the destination
1473 IP address if it can be found in the ARP cache or on the local subnet. One automatic
1474 nonroute entry will be inserted into the routing table for outgoing packets that
1475 are addressed to a local subnet (gateway address of 0.0.0.0).
1477 Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI
1478 IPv4 Protocol instances that use the default IPv4 address will also have copies
1479 of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these
1480 copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its
1481 instances. As a result, client modification to the routing table will be lost.
1483 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1484 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
1485 FALSE to add this route to the routing table. SubnetAddress
1486 and SubnetMask are used as the key to each route entry.
1487 @param[in] SubnetAddress The address of the subnet that needs to be routed.
1488 @param[in] SubnetMask The subnet mask of SubnetAddress.
1489 @param[in] GatewayAddress The unicast gateway IPv4 address for this route.
1491 @retval EFI_SUCCESS The operation completed successfully.
1492 @retval EFI_NOT_STARTED The driver instance has not been started.
1493 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1494 RARP, etc.) is not finished yet.
1495 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1497 - SubnetAddress is NULL.
1498 - SubnetMask is NULL.
1499 - GatewayAddress is NULL.
1500 - *SubnetAddress is not a valid subnet address.
1501 - *SubnetMask is not a valid subnet mask.
1502 - *GatewayAddress is not a valid unicast IPv4 address.
1503 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
1504 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
1505 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
1506 DeleteRoute is FALSE).
1512 IN EFI_IP4_PROTOCOL
*This
,
1513 IN BOOLEAN DeleteRoute
,
1514 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
1515 IN EFI_IPv4_ADDRESS
*SubnetMask
,
1516 IN EFI_IPv4_ADDRESS
*GatewayAddress
1519 IP4_PROTOCOL
*IpInstance
;
1520 IP4_INTERFACE
*IpIf
;
1528 // First, validate the parameters
1530 if ((This
== NULL
) || (SubnetAddress
== NULL
) ||
1531 (SubnetMask
== NULL
) || (GatewayAddress
== NULL
)) {
1532 return EFI_INVALID_PARAMETER
;
1535 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1536 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1538 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1539 Status
= EFI_NOT_STARTED
;
1543 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1544 Status
= EFI_NO_MAPPING
;
1548 CopyMem (&Dest
, SubnetAddress
, sizeof (IP4_ADDR
));
1549 CopyMem (&Netmask
, SubnetMask
, sizeof (IP4_ADDR
));
1550 CopyMem (&Nexthop
, GatewayAddress
, sizeof (IP4_ADDR
));
1552 Dest
= NTOHL (Dest
);
1553 Netmask
= NTOHL (Netmask
);
1554 Nexthop
= NTOHL (Nexthop
);
1556 IpIf
= IpInstance
->Interface
;
1558 if (!IP4_IS_VALID_NETMASK (Netmask
)) {
1559 Status
= EFI_INVALID_PARAMETER
;
1564 // the gateway address must be a unicast on the connected network if not zero.
1566 if ((Nexthop
!= IP4_ALLZERO_ADDRESS
) &&
1567 (!IP4_NET_EQUAL (Nexthop
, IpIf
->Ip
, IpIf
->SubnetMask
) ||
1568 IP4_IS_BROADCAST (Ip4GetNetCast (Nexthop
, IpIf
)))) {
1570 Status
= EFI_INVALID_PARAMETER
;
1575 Status
= Ip4DelRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1577 Status
= Ip4AddRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1581 gBS
->RestoreTPL (OldTpl
);
1587 Check whether the user's token or event has already
1588 been enqueued on IP4's list.
1590 @param[in] Map The container of either user's transmit or receive
1592 @param[in] Item Current item to check against
1593 @param[in] Context The Token to check againist.
1595 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
1596 @retval EFI_SUCCESS The current item isn't the same token/event as the
1603 IN NET_MAP_ITEM
*Item
,
1607 EFI_IP4_COMPLETION_TOKEN
*Token
;
1608 EFI_IP4_COMPLETION_TOKEN
*TokenInItem
;
1610 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
1611 TokenInItem
= (EFI_IP4_COMPLETION_TOKEN
*) Item
->Key
;
1613 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
1614 return EFI_ACCESS_DENIED
;
1622 Validate the user's token against current station address.
1624 @param[in] Token User's token to validate
1625 @param[in] IpIf The IP4 child's interface.
1627 @retval EFI_INVALID_PARAMETER Some parameters are invalid
1628 @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.
1629 @retval EFI_SUCCESS The token is OK
1634 IN EFI_IP4_COMPLETION_TOKEN
*Token
,
1635 IN IP4_INTERFACE
*IpIf
1638 EFI_IP4_TRANSMIT_DATA
*TxData
;
1639 EFI_IP4_OVERRIDE_DATA
*Override
;
1646 if ((Token
== NULL
) || (Token
->Event
== NULL
) || (Token
->Packet
.TxData
== NULL
)) {
1647 return EFI_INVALID_PARAMETER
;
1650 TxData
= Token
->Packet
.TxData
;
1653 // Check the IP options: no more than 40 bytes and format is OK
1655 if (TxData
->OptionsLength
!= 0) {
1656 if ((TxData
->OptionsLength
> 40) || (TxData
->OptionsBuffer
== NULL
)) {
1657 return EFI_INVALID_PARAMETER
;
1660 if (!Ip4OptionIsValid (TxData
->OptionsBuffer
, TxData
->OptionsLength
, FALSE
)) {
1661 return EFI_INVALID_PARAMETER
;
1666 // Check the fragment table: no empty fragment, and length isn't bogus
1668 if ((TxData
->TotalDataLength
== 0) || (TxData
->FragmentCount
== 0)) {
1669 return EFI_INVALID_PARAMETER
;
1672 Offset
= TxData
->TotalDataLength
;
1674 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
1675 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
1676 (TxData
->FragmentTable
[Index
].FragmentLength
== 0)) {
1678 return EFI_INVALID_PARAMETER
;
1681 Offset
-= TxData
->FragmentTable
[Index
].FragmentLength
;
1685 return EFI_INVALID_PARAMETER
;
1689 // Check the source and gateway: they must be a valid unicast.
1690 // Gateway must also be on the connected network.
1692 if (TxData
->OverrideData
) {
1693 Override
= TxData
->OverrideData
;
1695 CopyMem (&Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1696 CopyMem (&Gateway
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1699 Gateway
= NTOHL (Gateway
);
1701 if ((NetGetIpClass (Src
) > IP4_ADDR_CLASSC
) ||
1702 (Src
== IP4_ALLONE_ADDRESS
) ||
1703 IP4_IS_BROADCAST (Ip4GetNetCast (Src
, IpIf
))) {
1705 return EFI_INVALID_PARAMETER
;
1709 // If gateway isn't zero, it must be a unicast address, and
1710 // on the connected network.
1712 if ((Gateway
!= IP4_ALLZERO_ADDRESS
) &&
1713 ((NetGetIpClass (Gateway
) > IP4_ADDR_CLASSC
) ||
1714 !IP4_NET_EQUAL (Gateway
, IpIf
->Ip
, IpIf
->SubnetMask
) ||
1715 IP4_IS_BROADCAST (Ip4GetNetCast (Gateway
, IpIf
)))) {
1717 return EFI_INVALID_PARAMETER
;
1722 // Check the packet length: Head length and packet length all has a limit
1724 HeadLen
= sizeof (IP4_HEAD
) + ((TxData
->OptionsLength
+ 3) &~0x03);
1726 if ((HeadLen
> IP4_MAX_HEADLEN
) ||
1727 (TxData
->TotalDataLength
+ HeadLen
> IP4_MAX_PACKET_SIZE
)) {
1729 return EFI_BAD_BUFFER_SIZE
;
1737 The callback function for the net buffer which wraps the user's
1738 transmit token. Although it seems this function is pretty simple,
1739 there are some subtle things.
1740 When user requests the IP to transmit a packet by passing it a
1741 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data
1742 is wrapped in an net buffer. the net buffer's Free function is
1743 set to Ip4FreeTxToken. The Token and token wrap are added to the
1744 IP child's TxToken map. Then the buffer is passed to Ip4Output for
1745 transmission. If something error happened before that, the buffer
1746 is freed, which in turn will free the token wrap. The wrap may
1747 have been added to the TxToken map or not, and the user's event
1748 shouldn't be fired because we are still in the EfiIp4Transmit. If
1749 the buffer has been sent by Ip4Output, it should be removed from
1750 the TxToken map and user's event signaled. The token wrap and buffer
1751 are bound together. Check the comments in Ip4Output for information
1752 about IP fragmentation.
1754 @param[in] Context The token's wrap
1762 IP4_TXTOKEN_WRAP
*Wrap
;
1765 Wrap
= (IP4_TXTOKEN_WRAP
*) Context
;
1768 // Find the token in the instance's map. EfiIp4Transmit put the
1769 // token to the map. If that failed, NetMapFindKey will return NULL.
1771 Item
= NetMapFindKey (&Wrap
->IpInstance
->TxTokens
, Wrap
->Token
);
1774 NetMapRemoveItem (&Wrap
->IpInstance
->TxTokens
, Item
, NULL
);
1778 gBS
->SignalEvent (Wrap
->Token
->Event
);
1781 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
1786 gBS
->FreePool (Wrap
);
1791 The callback function to Ip4Output to update the transmit status.
1793 @param Ip4Instance The Ip4Instance that request the transmit.
1794 @param Packet The user's transmit request
1795 @param IoStatus The result of the transmission
1796 @param Flag Not used during transmission
1797 @param Context The token's wrap.
1802 IP4_PROTOCOL
*Ip4Instance
,
1804 EFI_STATUS IoStatus
,
1809 IP4_TXTOKEN_WRAP
*Wrap
;
1812 // This is the transmission request from upper layer,
1813 // not the IP4 driver itself.
1815 ASSERT (Ip4Instance
!= NULL
);
1818 // The first fragment of the packet has been sent. Update
1819 // the token's status. That is, if fragmented, the transmit's
1820 // status is the first fragment's status. The Wrap will be
1821 // release when all the fragments are release. Check the comments
1822 // in Ip4FreeTxToken and Ip4Output for information.
1824 Wrap
= (IP4_TXTOKEN_WRAP
*) Context
;
1825 Wrap
->Token
->Status
= IoStatus
;
1827 NetbufFree (Wrap
->Packet
);
1832 Places outgoing data packets into the transmit queue.
1834 The Transmit() function places a sending request in the transmit queue of this
1835 EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some
1836 errors occur, the event in the token will be signaled and the status is updated.
1838 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1839 @param[in] Token Pointer to the transmit token.
1841 @retval EFI_SUCCESS The data has been queued for transmission.
1842 @retval EFI_NOT_STARTED This instance has not been started.
1843 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1844 RARP, etc.) is not finished yet.
1845 @retval EFI_INVALID_PARAMETER One or more pameters are invalid.
1846 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event
1847 was already in the transmit queue.
1848 @retval EFI_NOT_READY The completion token could not be queued because the transmit
1850 @retval EFI_NOT_FOUND Not route is found to destination address.
1851 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
1852 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
1854 @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is
1855 greater than MTU (or greater than the maximum packet size if
1856 Token.Packet.TxData.OverrideData.
1857 DoNotFragment is TRUE.)
1863 IN EFI_IP4_PROTOCOL
*This
,
1864 IN EFI_IP4_COMPLETION_TOKEN
*Token
1868 IP4_PROTOCOL
*IpInstance
;
1869 IP4_INTERFACE
*IpIf
;
1870 IP4_TXTOKEN_WRAP
*Wrap
;
1871 EFI_IP4_TRANSMIT_DATA
*TxData
;
1872 EFI_IP4_CONFIG_DATA
*Config
;
1873 EFI_IP4_OVERRIDE_DATA
*Override
;
1878 BOOLEAN DontFragment
;
1882 return EFI_INVALID_PARAMETER
;
1885 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1887 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1888 return EFI_NOT_STARTED
;
1891 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1893 IpSb
= IpInstance
->Service
;
1894 IpIf
= IpInstance
->Interface
;
1895 Config
= &IpInstance
->ConfigData
;
1897 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1898 Status
= EFI_NO_MAPPING
;
1903 // make sure that token is properly formated
1905 Status
= Ip4TxTokenValid (Token
, IpIf
);
1907 if (EFI_ERROR (Status
)) {
1912 // Check whether the token or signal already existed.
1914 if (EFI_ERROR (NetMapIterate (&IpInstance
->TxTokens
, Ip4TokenExist
, Token
))) {
1915 Status
= EFI_ACCESS_DENIED
;
1920 // Build the IP header, need to fill in the Tos, TotalLen, Id,
1921 // fragment, Ttl, protocol, Src, and Dst.
1923 TxData
= Token
->Packet
.TxData
;
1925 CopyMem (&Head
.Dst
, &TxData
->DestinationAddress
, sizeof (IP4_ADDR
));
1926 Head
.Dst
= NTOHL (Head
.Dst
);
1928 if (TxData
->OverrideData
) {
1929 Override
= TxData
->OverrideData
;
1930 Head
.Protocol
= Override
->Protocol
;
1931 Head
.Tos
= Override
->TypeOfService
;
1932 Head
.Ttl
= Override
->TimeToLive
;
1933 DontFragment
= Override
->DoNotFragment
;
1935 CopyMem (&Head
.Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1936 CopyMem (&GateWay
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1938 Head
.Src
= NTOHL (Head
.Src
);
1939 GateWay
= NTOHL (GateWay
);
1941 Head
.Src
= IpIf
->Ip
;
1942 GateWay
= IP4_ALLZERO_ADDRESS
;
1943 Head
.Protocol
= Config
->DefaultProtocol
;
1944 Head
.Tos
= Config
->TypeOfService
;
1945 Head
.Ttl
= Config
->TimeToLive
;
1946 DontFragment
= Config
->DoNotFragment
;
1949 Head
.Fragment
= IP4_HEAD_FRAGMENT_FIELD (DontFragment
, FALSE
, 0);
1950 HeadLen
= sizeof (IP4_HEAD
) + ((TxData
->OptionsLength
+ 3) &~0x03);
1953 // If don't fragment and fragment needed, return error
1955 if (DontFragment
&& (TxData
->TotalDataLength
+ HeadLen
> IpSb
->SnpMode
.MaxPacketSize
)) {
1956 Status
= EFI_BAD_BUFFER_SIZE
;
1961 // OK, it survives all the validation check. Wrap the token in
1962 // a IP4_TXTOKEN_WRAP and the data in a netbuf
1964 Status
= EFI_OUT_OF_RESOURCES
;
1965 Wrap
= AllocateZeroPool (sizeof (IP4_TXTOKEN_WRAP
));
1970 Wrap
->IpInstance
= IpInstance
;
1971 Wrap
->Token
= Token
;
1973 Wrap
->Life
= IP4_US_TO_SEC (Config
->TransmitTimeout
);
1974 Wrap
->Packet
= NetbufFromExt (
1975 (NET_FRAGMENT
*) TxData
->FragmentTable
,
1976 TxData
->FragmentCount
,
1983 if (Wrap
->Packet
== NULL
) {
1984 gBS
->FreePool (Wrap
);
1988 Token
->Status
= EFI_NOT_READY
;
1990 if (EFI_ERROR (NetMapInsertTail (&IpInstance
->TxTokens
, Token
, Wrap
))) {
1992 // NetbufFree will call Ip4FreeTxToken, which in turn will
1993 // free the IP4_TXTOKEN_WRAP. Now, the token wrap hasn't been
1996 NetbufFree (Wrap
->Packet
);
2001 // Mark the packet sent before output it. Mark it not sent again if the
2002 // returned status is not EFI_SUCCESS;
2006 Status
= Ip4Output (
2011 TxData
->OptionsBuffer
,
2012 TxData
->OptionsLength
,
2018 if (EFI_ERROR (Status
)) {
2020 NetbufFree (Wrap
->Packet
);
2024 gBS
->RestoreTPL (OldTpl
);
2030 Places a receiving request into the receiving queue.
2032 The Receive() function places a completion token into the receive packet queue.
2033 This function is always asynchronous.
2035 The Token.Event field in the completion token must be filled in by the caller
2036 and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol
2037 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
2040 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2041 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
2043 @retval EFI_SUCCESS The receive completion token was cached.
2044 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2045 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)
2046 is not finished yet.
2047 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2050 - Token.Event is NULL.
2051 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
2052 resources (usually memory).
2053 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2054 The EFI IPv4 Protocol instance has been reset to startup defaults.
2055 EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
2056 in the receive queue.
2057 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
2058 @retval EFI_ICMP_ERROR An ICMP error packet was received.
2064 IN EFI_IP4_PROTOCOL
*This
,
2065 IN EFI_IP4_COMPLETION_TOKEN
*Token
2068 IP4_PROTOCOL
*IpInstance
;
2073 // First validate the parameters
2075 if ((This
== NULL
) || (Token
== NULL
) || (Token
->Event
== NULL
)) {
2076 return EFI_INVALID_PARAMETER
;
2079 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2081 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2083 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
2084 Status
= EFI_NOT_STARTED
;
2089 // Check whether the toke is already on the receive queue.
2091 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4TokenExist
, Token
);
2093 if (EFI_ERROR (Status
)) {
2094 Status
= EFI_ACCESS_DENIED
;
2099 // Queue the token then check whether there is pending received packet.
2101 Status
= NetMapInsertTail (&IpInstance
->RxTokens
, Token
, NULL
);
2103 if (EFI_ERROR (Status
)) {
2107 Status
= Ip4InstanceDeliverPacket (IpInstance
);
2110 // Dispatch the DPC queued by the NotifyFunction of this instane's receive
2116 gBS
->RestoreTPL (OldTpl
);
2122 Cancel the transmitted but not recycled packet. If a matching
2123 token is found, it will call Ip4CancelPacket to cancel the
2124 packet. Ip4CancelPacket will cancel all the fragments of the
2125 packet. When all the fragments are freed, the IP4_TXTOKEN_WRAP
2126 will be deleted from the Map, and user's event signalled.
2127 Because Ip4CancelPacket and other functions are all called in
2128 line, so, after Ip4CancelPacket returns, the Item has been freed.
2130 @param[in] Map The IP4 child's transmit queue
2131 @param[in] Item The current transmitted packet to test.
2132 @param[in] Context The user's token to cancel.
2134 @retval EFI_SUCCESS Continue to check the next Item.
2135 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
2141 IN NET_MAP_ITEM
*Item
,
2145 EFI_IP4_COMPLETION_TOKEN
*Token
;
2146 IP4_TXTOKEN_WRAP
*Wrap
;
2148 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
2151 // Return EFI_SUCCESS to check the next item in the map if
2152 // this one doesn't match.
2154 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
2158 Wrap
= (IP4_TXTOKEN_WRAP
*) Item
->Value
;
2159 ASSERT (Wrap
!= NULL
);
2162 // Don't access the Item, Wrap and Token's members after this point.
2163 // Item and wrap has been freed. And we no longer own the Token.
2165 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
2168 // If only one item is to be cancel, return EFI_ABORTED to stop
2169 // iterating the map any more.
2171 if (Token
!= NULL
) {
2180 Cancel the receive request. This is quiet simple, because
2181 it is only enqueued in our local receive map.
2183 @param[in] Map The IP4 child's receive queue
2184 @param[in] Item Current receive request to cancel.
2185 @param[in] Context The user's token to cancel
2187 @retval EFI_SUCCESS Continue to check the next receive request on the
2189 @retval EFI_ABORTED The user's token (token != NULL) has been
2196 IN NET_MAP_ITEM
*Item
,
2200 EFI_IP4_COMPLETION_TOKEN
*Token
;
2201 EFI_IP4_COMPLETION_TOKEN
*This
;
2203 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
2206 if ((Token
!= NULL
) && (Token
!= This
)) {
2210 NetMapRemoveItem (Map
, Item
, NULL
);
2212 This
->Status
= EFI_ABORTED
;
2213 This
->Packet
.RxData
= NULL
;
2214 gBS
->SignalEvent (This
->Event
);
2216 if (Token
!= NULL
) {
2225 Cancel the user's receive/transmit request.
2227 @param[in] IpInstance The IP4 child
2228 @param[in] Token The token to cancel. If NULL, all token will be
2231 @retval EFI_SUCCESS The token is cancelled
2232 @retval EFI_NOT_FOUND The token isn't found on either the
2233 transmit/receive queue
2234 @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.
2239 IN IP4_PROTOCOL
*IpInstance
,
2240 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2246 // First check the transmitted packet. Ip4CancelTxTokens returns
2247 // EFI_ABORTED to mean that the token has been cancelled when
2248 // token != NULL. So, return EFI_SUCCESS for this condition.
2250 Status
= NetMapIterate (&IpInstance
->TxTokens
, Ip4CancelTxTokens
, Token
);
2252 if (EFI_ERROR (Status
)) {
2253 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2261 // Check the receive queue. Ip4CancelRxTokens also returns EFI_ABORT
2262 // for Token!=NULL and it is cancelled.
2264 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4CancelRxTokens
, Token
);
2266 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
2270 if (EFI_ERROR (Status
)) {
2271 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2279 // OK, if the Token is found when Token != NULL, the NetMapIterate
2280 // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.
2282 if (Token
!= NULL
) {
2283 return EFI_NOT_FOUND
;
2287 // If Token == NULL, cancel all the tokens. return error if no
2288 // all of them are cancelled.
2290 if (!NetMapIsEmpty (&IpInstance
->TxTokens
) ||
2291 !NetMapIsEmpty (&IpInstance
->RxTokens
)) {
2293 return EFI_DEVICE_ERROR
;
2301 Abort an asynchronous transmit or receive request.
2303 The Cancel() function is used to abort a pending transmit or receive request.
2304 If the token is in the transmit or receive request queues, after calling this
2305 function, Token->Status will be set to EFI_ABORTED and then Token->Event will
2306 be signaled. If the token is not in one of the queues, which usually means the
2307 asynchronous operation has completed, this function will not signal the token
2308 and EFI_NOT_FOUND is returned.
2310 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2311 @param[in] Token Pointer to a token that has been issued by
2312 EFI_IP4_PROTOCOL.Transmit() or
2313 EFI_IP4_PROTOCOL.Receive(). If NULL, all pending
2314 tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is
2315 defined in EFI_IP4_PROTOCOL.Transmit().
2317 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
2318 Token.->Event was signaled. When Token is NULL, all
2319 pending requests were aborted and their events were signaled.
2320 @retval EFI_INVALID_PARAMETER This is NULL.
2321 @retval EFI_NOT_STARTED This instance has not been started.
2322 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2323 RARP, etc.) is not finished yet.
2324 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
2325 not found in the transmit or receive queue. It has either completed
2326 or was not issued by Transmit() and Receive().
2332 IN EFI_IP4_PROTOCOL
*This
,
2333 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2336 IP4_PROTOCOL
*IpInstance
;
2341 return EFI_INVALID_PARAMETER
;
2344 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2346 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2348 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
2349 Status
= EFI_NOT_STARTED
;
2353 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
2354 Status
= EFI_NO_MAPPING
;
2358 Status
= Ip4Cancel (IpInstance
, Token
);
2361 gBS
->RestoreTPL (OldTpl
);
2367 Polls for incoming data packets and processes outgoing data packets.
2369 The Poll() function polls for incoming data packets and processes outgoing data
2370 packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()
2371 function to increase the rate that data packets are moved between the communications
2372 device and the transmit and receive queues.
2374 In some systems the periodic timer event may not poll the underlying communications
2375 device fast enough to transmit and/or receive all data packets without missing
2376 incoming packets or dropping outgoing packets. Drivers and applications that are
2377 experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function
2380 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2382 @retval EFI_SUCCESS Incoming or outgoing data was processed.
2383 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2384 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2385 RARP, etc.) is not finished yet.
2386 @retval EFI_INVALID_PARAMETER This is NULL.
2387 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2388 @retval EFI_NOT_READY No incoming or outgoing data is processed.
2389 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
2390 Consider increasing the polling rate.
2396 IN EFI_IP4_PROTOCOL
*This
2399 IP4_PROTOCOL
*IpInstance
;
2400 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
2403 return EFI_INVALID_PARAMETER
;
2406 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2408 if (IpInstance
->State
== IP4_STATE_UNCONFIGED
) {
2409 return EFI_NOT_STARTED
;
2412 Mnp
= IpInstance
->Service
->Mnp
;
2415 // Don't lock the Poll function to enable the deliver of
2416 // the packet polled up.
2418 return Mnp
->Poll (Mnp
);
2422 Decrease the life of the transmitted packets. If it is
2423 decreased to zero, cancel the packet. This function is
2424 called by Ip4PacketTimerTicking which time out both the
2425 received-but-not-delivered and transmitted-but-not-recycle
2428 @param[in] Map The IP4 child's transmit map.
2429 @param[in] Item Current transmitted packet
2430 @param[in] Context Not used.
2432 @retval EFI_SUCCESS Always returns EFI_SUCCESS
2436 Ip4SentPacketTicking (
2438 IN NET_MAP_ITEM
*Item
,
2442 IP4_TXTOKEN_WRAP
*Wrap
;
2444 Wrap
= (IP4_TXTOKEN_WRAP
*) Item
->Value
;
2445 ASSERT (Wrap
!= NULL
);
2447 if ((Wrap
->Life
> 0) && (--Wrap
->Life
== 0)) {
2448 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
2456 The heart beat timer of IP4 service instance. It times out
2457 all of its IP4 children's received-but-not-delivered and
2458 transmitted-but-not-recycle packets, and provides time input
2459 for its IGMP protocol.
2461 @param[in] Event The IP4 service instance's heart beat timer.
2462 @param[in] Context The IP4 service instance.
2474 IpSb
= (IP4_SERVICE
*) Context
;
2475 NET_CHECK_SIGNATURE (IpSb
, IP4_SERVICE_SIGNATURE
);
2477 Ip4PacketTimerTicking (IpSb
);
2478 Ip4IgmpTicking (IpSb
);