3 Copyright (c) 2005 - 2007, 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 NetLibQueueDpc (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
1317 CopyMem (&Group
, GroupAddress
, sizeof (IP4_ADDR
));
1319 for (Index
= 0; Index
< IpInstance
->GroupCount
; Index
++) {
1320 if (IpInstance
->Groups
[Index
] == Group
) {
1321 return EFI_ALREADY_STARTED
;
1325 Members
= Ip4CombineGroups (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1327 if (Members
== NULL
) {
1328 return EFI_OUT_OF_RESOURCES
;
1331 if (EFI_ERROR (Ip4JoinGroup (IpInstance
, NTOHL (Group
)))) {
1332 gBS
->FreePool (Members
);
1333 return EFI_DEVICE_ERROR
;
1336 if (IpInstance
->Groups
!= NULL
) {
1337 gBS
->FreePool (IpInstance
->Groups
);
1340 IpInstance
->Groups
= Members
;
1341 IpInstance
->GroupCount
++;
1347 // Leave the group. Leave all the groups if GroupAddress is NULL.
1348 // Must iterate from the end to the beginning because the GroupCount
1349 // is decreamented each time an address is removed..
1351 for (Index
= IpInstance
->GroupCount
; Index
> 0 ; Index
--) {
1352 Group
= IpInstance
->Groups
[Index
- 1];
1354 if ((GroupAddress
== NULL
) || EFI_IP4_EQUAL (&Group
, GroupAddress
)) {
1355 if (EFI_ERROR (Ip4LeaveGroup (IpInstance
, NTOHL (Group
)))) {
1356 return EFI_DEVICE_ERROR
;
1359 Ip4RemoveGroupAddr (IpInstance
->Groups
, IpInstance
->GroupCount
, Group
);
1360 IpInstance
->GroupCount
--;
1362 if (IpInstance
->GroupCount
== 0) {
1363 ASSERT (Index
== 1);
1365 gBS
->FreePool (IpInstance
->Groups
);
1366 IpInstance
->Groups
= NULL
;
1369 if (GroupAddress
!= NULL
) {
1375 return ((GroupAddress
!= NULL
) ? EFI_NOT_FOUND
: EFI_SUCCESS
);
1380 Joins and leaves multicast groups.
1382 The Groups() function is used to join and leave multicast group sessions. Joining
1383 a group will enable reception of matching multicast packets. Leaving a group will
1384 disable the multicast packet reception.
1386 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
1388 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1389 @param[in] JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.
1390 @param[in] GroupAddress Pointer to the IPv4 multicast address.
1392 @retval EFI_SUCCESS The operation completed successfully.
1393 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
1395 - JoinFlag is TRUE and GroupAddress is NULL.
1396 - GroupAddress is not NULL and *GroupAddress is
1397 not a multicast IPv4 address.
1398 @retval EFI_NOT_STARTED This instance has not been started.
1399 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1400 RARP, etc.) is not finished yet.
1401 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
1402 @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.
1403 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
1405 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
1406 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1412 IN EFI_IP4_PROTOCOL
*This
,
1413 IN BOOLEAN JoinFlag
,
1414 IN EFI_IPv4_ADDRESS
*GroupAddress OPTIONAL
1417 IP4_PROTOCOL
*IpInstance
;
1422 if ((This
== NULL
) || (JoinFlag
&& (GroupAddress
== NULL
))) {
1423 return EFI_INVALID_PARAMETER
;
1426 if (GroupAddress
!= NULL
) {
1427 CopyMem (&McastIp
, GroupAddress
, sizeof (IP4_ADDR
));
1429 if (!IP4_IS_MULTICAST (NTOHL (McastIp
))) {
1430 return EFI_INVALID_PARAMETER
;
1434 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1435 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1437 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1438 Status
= EFI_NOT_STARTED
;
1442 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1443 Status
= EFI_NO_MAPPING
;
1447 Status
= Ip4Groups (IpInstance
, JoinFlag
, GroupAddress
);
1450 gBS
->RestoreTPL (OldTpl
);
1456 Adds and deletes routing table entries.
1458 The Routes() function adds a route to or deletes a route from the routing table.
1460 Routes are determined by comparing the SubnetAddress with the destination IPv4
1461 address arithmetically AND-ed with the SubnetMask. The gateway address must be
1462 on the same subnet as the configured station address.
1464 The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
1465 The default route matches all destination IPv4 addresses that do not match any
1468 A GatewayAddress that is zero is a nonroute. Packets are sent to the destination
1469 IP address if it can be found in the ARP cache or on the local subnet. One automatic
1470 nonroute entry will be inserted into the routing table for outgoing packets that
1471 are addressed to a local subnet (gateway address of 0.0.0.0).
1473 Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI
1474 IPv4 Protocol instances that use the default IPv4 address will also have copies
1475 of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these
1476 copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its
1477 instances. As a result, client modification to the routing table will be lost.
1479 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1480 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
1481 FALSE to add this route to the routing table. SubnetAddress
1482 and SubnetMask are used as the key to each route entry.
1483 @param[in] SubnetAddress The address of the subnet that needs to be routed.
1484 @param[in] SubnetMask The subnet mask of SubnetAddress.
1485 @param[in] GatewayAddress The unicast gateway IPv4 address for this route.
1487 @retval EFI_SUCCESS The operation completed successfully.
1488 @retval EFI_NOT_STARTED The driver instance has not been started.
1489 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1490 RARP, etc.) is not finished yet.
1491 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1493 - SubnetAddress is NULL.
1494 - SubnetMask is NULL.
1495 - GatewayAddress is NULL.
1496 - *SubnetAddress is not a valid subnet address.
1497 - *SubnetMask is not a valid subnet mask.
1498 - *GatewayAddress is not a valid unicast IPv4 address.
1499 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
1500 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
1501 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
1502 DeleteRoute is FALSE).
1508 IN EFI_IP4_PROTOCOL
*This
,
1509 IN BOOLEAN DeleteRoute
,
1510 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
1511 IN EFI_IPv4_ADDRESS
*SubnetMask
,
1512 IN EFI_IPv4_ADDRESS
*GatewayAddress
1515 IP4_PROTOCOL
*IpInstance
;
1516 IP4_INTERFACE
*IpIf
;
1524 // First, validate the parameters
1526 if ((This
== NULL
) || (SubnetAddress
== NULL
) ||
1527 (SubnetMask
== NULL
) || (GatewayAddress
== NULL
)) {
1528 return EFI_INVALID_PARAMETER
;
1531 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1532 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1534 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1535 Status
= EFI_NOT_STARTED
;
1539 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1540 Status
= EFI_NO_MAPPING
;
1544 CopyMem (&Dest
, SubnetAddress
, sizeof (IP4_ADDR
));
1545 CopyMem (&Netmask
, SubnetMask
, sizeof (IP4_ADDR
));
1546 CopyMem (&Nexthop
, GatewayAddress
, sizeof (IP4_ADDR
));
1548 Dest
= NTOHL (Dest
);
1549 Netmask
= NTOHL (Netmask
);
1550 Nexthop
= NTOHL (Nexthop
);
1552 IpIf
= IpInstance
->Interface
;
1554 if (!IP4_IS_VALID_NETMASK (Netmask
)) {
1555 Status
= EFI_INVALID_PARAMETER
;
1560 // the gateway address must be a unicast on the connected network if not zero.
1562 if ((Nexthop
!= IP4_ALLZERO_ADDRESS
) &&
1563 (!IP4_NET_EQUAL (Nexthop
, IpIf
->Ip
, IpIf
->SubnetMask
) ||
1564 IP4_IS_BROADCAST (Ip4GetNetCast (Nexthop
, IpIf
)))) {
1566 Status
= EFI_INVALID_PARAMETER
;
1571 Status
= Ip4DelRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1573 Status
= Ip4AddRoute (IpInstance
->RouteTable
, Dest
, Netmask
, Nexthop
);
1577 gBS
->RestoreTPL (OldTpl
);
1583 Check whether the user's token or event has already
1584 been enqueued on IP4's list.
1586 @param[in] Map The container of either user's transmit or receive
1588 @param[in] Item Current item to check against
1589 @param[in] Context The Token to check againist.
1591 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
1592 @retval EFI_SUCCESS The current item isn't the same token/event as the
1599 IN NET_MAP_ITEM
*Item
,
1603 EFI_IP4_COMPLETION_TOKEN
*Token
;
1604 EFI_IP4_COMPLETION_TOKEN
*TokenInItem
;
1606 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
1607 TokenInItem
= (EFI_IP4_COMPLETION_TOKEN
*) Item
->Key
;
1609 if ((Token
== TokenInItem
) || (Token
->Event
== TokenInItem
->Event
)) {
1610 return EFI_ACCESS_DENIED
;
1618 Validate the user's token against current station address.
1620 @param[in] Token User's token to validate
1621 @param[in] IpIf The IP4 child's interface.
1623 @retval EFI_INVALID_PARAMETER Some parameters are invalid
1624 @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.
1625 @retval EFI_SUCCESS The token is OK
1630 IN EFI_IP4_COMPLETION_TOKEN
*Token
,
1631 IN IP4_INTERFACE
*IpIf
1634 EFI_IP4_TRANSMIT_DATA
*TxData
;
1635 EFI_IP4_OVERRIDE_DATA
*Override
;
1642 if ((Token
== NULL
) || (Token
->Event
== NULL
) || (Token
->Packet
.TxData
== NULL
)) {
1643 return EFI_INVALID_PARAMETER
;
1646 TxData
= Token
->Packet
.TxData
;
1649 // Check the IP options: no more than 40 bytes and format is OK
1651 if (TxData
->OptionsLength
!= 0) {
1652 if ((TxData
->OptionsLength
> 40) || (TxData
->OptionsBuffer
== NULL
)) {
1653 return EFI_INVALID_PARAMETER
;
1656 if (!Ip4OptionIsValid (TxData
->OptionsBuffer
, TxData
->OptionsLength
, FALSE
)) {
1657 return EFI_INVALID_PARAMETER
;
1662 // Check the fragment table: no empty fragment, and length isn't bogus
1664 if ((TxData
->TotalDataLength
== 0) || (TxData
->FragmentCount
== 0)) {
1665 return EFI_INVALID_PARAMETER
;
1668 Offset
= TxData
->TotalDataLength
;
1670 for (Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
1671 if ((TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) ||
1672 (TxData
->FragmentTable
[Index
].FragmentLength
== 0)) {
1674 return EFI_INVALID_PARAMETER
;
1677 Offset
-= TxData
->FragmentTable
[Index
].FragmentLength
;
1681 return EFI_INVALID_PARAMETER
;
1685 // Check the source and gateway: they must be a valid unicast.
1686 // Gateway must also be on the connected network.
1688 if (TxData
->OverrideData
) {
1689 Override
= TxData
->OverrideData
;
1691 CopyMem (&Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1692 CopyMem (&Gateway
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1695 Gateway
= NTOHL (Gateway
);
1697 if ((NetGetIpClass (Src
) > IP4_ADDR_CLASSC
) ||
1698 (Src
== IP4_ALLONE_ADDRESS
) ||
1699 IP4_IS_BROADCAST (Ip4GetNetCast (Src
, IpIf
))) {
1701 return EFI_INVALID_PARAMETER
;
1705 // If gateway isn't zero, it must be a unicast address, and
1706 // on the connected network.
1708 if ((Gateway
!= IP4_ALLZERO_ADDRESS
) &&
1709 ((NetGetIpClass (Gateway
) > IP4_ADDR_CLASSC
) ||
1710 !IP4_NET_EQUAL (Gateway
, IpIf
->Ip
, IpIf
->SubnetMask
) ||
1711 IP4_IS_BROADCAST (Ip4GetNetCast (Gateway
, IpIf
)))) {
1713 return EFI_INVALID_PARAMETER
;
1718 // Check the packet length: Head length and packet length all has a limit
1720 HeadLen
= sizeof (IP4_HEAD
) + ((TxData
->OptionsLength
+ 3) &~0x03);
1722 if ((HeadLen
> IP4_MAX_HEADLEN
) ||
1723 (TxData
->TotalDataLength
+ HeadLen
> IP4_MAX_PACKET_SIZE
)) {
1725 return EFI_BAD_BUFFER_SIZE
;
1733 The callback function for the net buffer which wraps the user's
1734 transmit token. Although it seems this function is pretty simple,
1735 there are some subtle things.
1736 When user requests the IP to transmit a packet by passing it a
1737 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data
1738 is wrapped in an net buffer. the net buffer's Free function is
1739 set to Ip4FreeTxToken. The Token and token wrap are added to the
1740 IP child's TxToken map. Then the buffer is passed to Ip4Output for
1741 transmission. If something error happened before that, the buffer
1742 is freed, which in turn will free the token wrap. The wrap may
1743 have been added to the TxToken map or not, and the user's event
1744 shouldn't be fired because we are still in the EfiIp4Transmit. If
1745 the buffer has been sent by Ip4Output, it should be removed from
1746 the TxToken map and user's event signaled. The token wrap and buffer
1747 are bound together. Check the comments in Ip4Output for information
1748 about IP fragmentation.
1750 @param[in] Context The token's wrap
1758 IP4_TXTOKEN_WRAP
*Wrap
;
1761 Wrap
= (IP4_TXTOKEN_WRAP
*) Context
;
1764 // Find the token in the instance's map. EfiIp4Transmit put the
1765 // token to the map. If that failed, NetMapFindKey will return NULL.
1767 Item
= NetMapFindKey (&Wrap
->IpInstance
->TxTokens
, Wrap
->Token
);
1770 NetMapRemoveItem (&Wrap
->IpInstance
->TxTokens
, Item
, NULL
);
1774 gBS
->SignalEvent (Wrap
->Token
->Event
);
1777 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
1779 NetLibDispatchDpc ();
1782 gBS
->FreePool (Wrap
);
1787 The callback function to Ip4Output to update the transmit status.
1789 @param Ip4Instance The Ip4Instance that request the transmit.
1790 @param Packet The user's transmit request
1791 @param IoStatus The result of the transmission
1792 @param Flag Not used during transmission
1793 @param Context The token's wrap.
1798 IP4_PROTOCOL
*Ip4Instance
,
1800 EFI_STATUS IoStatus
,
1805 IP4_TXTOKEN_WRAP
*Wrap
;
1808 // This is the transmission request from upper layer,
1809 // not the IP4 driver itself.
1811 ASSERT (Ip4Instance
!= NULL
);
1814 // The first fragment of the packet has been sent. Update
1815 // the token's status. That is, if fragmented, the transmit's
1816 // status is the first fragment's status. The Wrap will be
1817 // release when all the fragments are release. Check the comments
1818 // in Ip4FreeTxToken and Ip4Output for information.
1820 Wrap
= (IP4_TXTOKEN_WRAP
*) Context
;
1821 Wrap
->Token
->Status
= IoStatus
;
1823 NetbufFree (Wrap
->Packet
);
1828 Places outgoing data packets into the transmit queue.
1830 The Transmit() function places a sending request in the transmit queue of this
1831 EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some
1832 errors occur, the event in the token will be signaled and the status is updated.
1834 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
1835 @param[in] Token Pointer to the transmit token.
1837 @retval EFI_SUCCESS The data has been queued for transmission.
1838 @retval EFI_NOT_STARTED This instance has not been started.
1839 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
1840 RARP, etc.) is not finished yet.
1841 @retval EFI_INVALID_PARAMETER One or more pameters are invalid.
1842 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event
1843 was already in the transmit queue.
1844 @retval EFI_NOT_READY The completion token could not be queued because the transmit
1846 @retval EFI_NOT_FOUND Not route is found to destination address.
1847 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
1848 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
1850 @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is
1851 greater than MTU (or greater than the maximum packet size if
1852 Token.Packet.TxData.OverrideData.
1853 DoNotFragment is TRUE.)
1859 IN EFI_IP4_PROTOCOL
*This
,
1860 IN EFI_IP4_COMPLETION_TOKEN
*Token
1864 IP4_PROTOCOL
*IpInstance
;
1865 IP4_INTERFACE
*IpIf
;
1866 IP4_TXTOKEN_WRAP
*Wrap
;
1867 EFI_IP4_TRANSMIT_DATA
*TxData
;
1868 EFI_IP4_CONFIG_DATA
*Config
;
1869 EFI_IP4_OVERRIDE_DATA
*Override
;
1874 BOOLEAN DontFragment
;
1878 return EFI_INVALID_PARAMETER
;
1881 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
1883 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
1884 return EFI_NOT_STARTED
;
1887 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1889 IpSb
= IpInstance
->Service
;
1890 IpIf
= IpInstance
->Interface
;
1891 Config
= &IpInstance
->ConfigData
;
1893 if (Config
->UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
1894 Status
= EFI_NO_MAPPING
;
1899 // make sure that token is properly formated
1901 Status
= Ip4TxTokenValid (Token
, IpIf
);
1903 if (EFI_ERROR (Status
)) {
1908 // Check whether the token or signal already existed.
1910 if (EFI_ERROR (NetMapIterate (&IpInstance
->TxTokens
, Ip4TokenExist
, Token
))) {
1911 Status
= EFI_ACCESS_DENIED
;
1916 // Build the IP header, need to fill in the Tos, TotalLen, Id,
1917 // fragment, Ttl, protocol, Src, and Dst.
1919 TxData
= Token
->Packet
.TxData
;
1921 CopyMem (&Head
.Dst
, &TxData
->DestinationAddress
, sizeof (IP4_ADDR
));
1922 Head
.Dst
= NTOHL (Head
.Dst
);
1924 if (TxData
->OverrideData
) {
1925 Override
= TxData
->OverrideData
;
1926 Head
.Protocol
= Override
->Protocol
;
1927 Head
.Tos
= Override
->TypeOfService
;
1928 Head
.Ttl
= Override
->TimeToLive
;
1929 DontFragment
= Override
->DoNotFragment
;
1931 CopyMem (&Head
.Src
, &Override
->SourceAddress
, sizeof (IP4_ADDR
));
1932 CopyMem (&GateWay
, &Override
->GatewayAddress
, sizeof (IP4_ADDR
));
1934 Head
.Src
= NTOHL (Head
.Src
);
1935 GateWay
= NTOHL (GateWay
);
1937 Head
.Src
= IpIf
->Ip
;
1938 GateWay
= IP4_ALLZERO_ADDRESS
;
1939 Head
.Protocol
= Config
->DefaultProtocol
;
1940 Head
.Tos
= Config
->TypeOfService
;
1941 Head
.Ttl
= Config
->TimeToLive
;
1942 DontFragment
= Config
->DoNotFragment
;
1945 Head
.Fragment
= IP4_HEAD_FRAGMENT_FIELD (DontFragment
, FALSE
, 0);
1946 HeadLen
= sizeof (IP4_HEAD
) + ((TxData
->OptionsLength
+ 3) &~0x03);
1949 // If don't fragment and fragment needed, return error
1951 if (DontFragment
&& (TxData
->TotalDataLength
+ HeadLen
> IpSb
->SnpMode
.MaxPacketSize
)) {
1952 Status
= EFI_BAD_BUFFER_SIZE
;
1957 // OK, it survives all the validation check. Wrap the token in
1958 // a IP4_TXTOKEN_WRAP and the data in a netbuf
1960 Status
= EFI_OUT_OF_RESOURCES
;
1961 Wrap
= AllocatePool (sizeof (IP4_TXTOKEN_WRAP
));
1966 Wrap
->IpInstance
= IpInstance
;
1967 Wrap
->Token
= Token
;
1969 Wrap
->Life
= IP4_US_TO_SEC (Config
->TransmitTimeout
);
1970 Wrap
->Packet
= NetbufFromExt (
1971 (NET_FRAGMENT
*) TxData
->FragmentTable
,
1972 TxData
->FragmentCount
,
1979 if (Wrap
->Packet
== NULL
) {
1980 gBS
->FreePool (Wrap
);
1984 Token
->Status
= EFI_NOT_READY
;
1986 if (EFI_ERROR (NetMapInsertTail (&IpInstance
->TxTokens
, Token
, Wrap
))) {
1988 // NetbufFree will call Ip4FreeTxToken, which in turn will
1989 // free the IP4_TXTOKEN_WRAP. Now, the token wrap hasn't been
1992 NetbufFree (Wrap
->Packet
);
1997 // Mark the packet sent before output it. Mark it not sent again if the
1998 // returned status is not EFI_SUCCESS;
2002 Status
= Ip4Output (
2007 TxData
->OptionsBuffer
,
2008 TxData
->OptionsLength
,
2014 if (EFI_ERROR (Status
)) {
2016 NetbufFree (Wrap
->Packet
);
2020 gBS
->RestoreTPL (OldTpl
);
2026 Places a receiving request into the receiving queue.
2028 The Receive() function places a completion token into the receive packet queue.
2029 This function is always asynchronous.
2031 The Token.Event field in the completion token must be filled in by the caller
2032 and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol
2033 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
2036 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2037 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
2039 @retval EFI_SUCCESS The receive completion token was cached.
2040 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2041 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)
2042 is not finished yet.
2043 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
2046 - Token.Event is NULL.
2047 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
2048 resources (usually memory).
2049 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2050 The EFI IPv4 Protocol instance has been reset to startup defaults.
2051 EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
2052 in the receive queue.
2053 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
2054 @retval EFI_ICMP_ERROR An ICMP error packet was received.
2060 IN EFI_IP4_PROTOCOL
*This
,
2061 IN EFI_IP4_COMPLETION_TOKEN
*Token
2064 IP4_PROTOCOL
*IpInstance
;
2069 // First validate the parameters
2071 if ((This
== NULL
) || (Token
== NULL
) || (Token
->Event
== NULL
)) {
2072 return EFI_INVALID_PARAMETER
;
2075 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2077 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2079 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
2080 Status
= EFI_NOT_STARTED
;
2085 // Check whether the toke is already on the receive queue.
2087 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4TokenExist
, Token
);
2089 if (EFI_ERROR (Status
)) {
2090 Status
= EFI_ACCESS_DENIED
;
2095 // Queue the token then check whether there is pending received packet.
2097 Status
= NetMapInsertTail (&IpInstance
->RxTokens
, Token
, NULL
);
2099 if (EFI_ERROR (Status
)) {
2103 Status
= Ip4InstanceDeliverPacket (IpInstance
);
2106 // Dispatch the DPC queued by the NotifyFunction of this instane's receive
2109 NetLibDispatchDpc ();
2112 gBS
->RestoreTPL (OldTpl
);
2118 Cancel the transmitted but not recycled packet. If a matching
2119 token is found, it will call Ip4CancelPacket to cancel the
2120 packet. Ip4CancelPacket will cancel all the fragments of the
2121 packet. When all the fragments are freed, the IP4_TXTOKEN_WRAP
2122 will be deleted from the Map, and user's event signalled.
2123 Because Ip4CancelPacket and other functions are all called in
2124 line, so, after Ip4CancelPacket returns, the Item has been freed.
2126 @param[in] Map The IP4 child's transmit queue
2127 @param[in] Item The current transmitted packet to test.
2128 @param[in] Context The user's token to cancel.
2130 @retval EFI_SUCCESS Continue to check the next Item.
2131 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
2137 IN NET_MAP_ITEM
*Item
,
2141 EFI_IP4_COMPLETION_TOKEN
*Token
;
2142 IP4_TXTOKEN_WRAP
*Wrap
;
2144 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
2147 // Return EFI_SUCCESS to check the next item in the map if
2148 // this one doesn't match.
2150 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
2154 Wrap
= (IP4_TXTOKEN_WRAP
*) Item
->Value
;
2155 ASSERT (Wrap
!= NULL
);
2158 // Don't access the Item, Wrap and Token's members after this point.
2159 // Item and wrap has been freed. And we no longer own the Token.
2161 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
2164 // If only one item is to be cancel, return EFI_ABORTED to stop
2165 // iterating the map any more.
2167 if (Token
!= NULL
) {
2176 Cancel the receive request. This is quiet simple, because
2177 it is only enqueued in our local receive map.
2179 @param[in] Map The IP4 child's receive queue
2180 @param[in] Item Current receive request to cancel.
2181 @param[in] Context The user's token to cancel
2183 @retval EFI_SUCCESS Continue to check the next receive request on the
2185 @retval EFI_ABORTED The user's token (token != NULL) has been
2192 IN NET_MAP_ITEM
*Item
,
2196 EFI_IP4_COMPLETION_TOKEN
*Token
;
2197 EFI_IP4_COMPLETION_TOKEN
*This
;
2199 Token
= (EFI_IP4_COMPLETION_TOKEN
*) Context
;
2202 if ((Token
!= NULL
) && (Token
!= This
)) {
2206 NetMapRemoveItem (Map
, Item
, NULL
);
2208 This
->Status
= EFI_ABORTED
;
2209 This
->Packet
.RxData
= NULL
;
2210 gBS
->SignalEvent (This
->Event
);
2212 if (Token
!= NULL
) {
2221 Cancel the user's receive/transmit request.
2223 @param[in] IpInstance The IP4 child
2224 @param[in] Token The token to cancel. If NULL, all token will be
2227 @retval EFI_SUCCESS The token is cancelled
2228 @retval EFI_NOT_FOUND The token isn't found on either the
2229 transmit/receive queue
2230 @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.
2235 IN IP4_PROTOCOL
*IpInstance
,
2236 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2242 // First check the transmitted packet. Ip4CancelTxTokens returns
2243 // EFI_ABORTED to mean that the token has been cancelled when
2244 // token != NULL. So, return EFI_SUCCESS for this condition.
2246 Status
= NetMapIterate (&IpInstance
->TxTokens
, Ip4CancelTxTokens
, Token
);
2248 if (EFI_ERROR (Status
)) {
2249 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2257 // Check the receive queue. Ip4CancelRxTokens also returns EFI_ABORT
2258 // for Token!=NULL and it is cancelled.
2260 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip4CancelRxTokens
, Token
);
2262 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
2265 NetLibDispatchDpc ();
2266 if (EFI_ERROR (Status
)) {
2267 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
2275 // OK, if the Token is found when Token != NULL, the NetMapIterate
2276 // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.
2278 if (Token
!= NULL
) {
2279 return EFI_NOT_FOUND
;
2283 // If Token == NULL, cancel all the tokens. return error if no
2284 // all of them are cancelled.
2286 if (!NetMapIsEmpty (&IpInstance
->TxTokens
) ||
2287 !NetMapIsEmpty (&IpInstance
->RxTokens
)) {
2289 return EFI_DEVICE_ERROR
;
2297 Abort an asynchronous transmit or receive request.
2299 The Cancel() function is used to abort a pending transmit or receive request.
2300 If the token is in the transmit or receive request queues, after calling this
2301 function, Token->Status will be set to EFI_ABORTED and then Token->Event will
2302 be signaled. If the token is not in one of the queues, which usually means the
2303 asynchronous operation has completed, this function will not signal the token
2304 and EFI_NOT_FOUND is returned.
2306 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2307 @param[in] Token Pointer to a token that has been issued by
2308 EFI_IP4_PROTOCOL.Transmit() or
2309 EFI_IP4_PROTOCOL.Receive(). If NULL, all pending
2310 tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is
2311 defined in EFI_IP4_PROTOCOL.Transmit().
2313 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
2314 Token.->Event was signaled. When Token is NULL, all
2315 pending requests were aborted and their events were signaled.
2316 @retval EFI_INVALID_PARAMETER This is NULL.
2317 @retval EFI_NOT_STARTED This instance has not been started.
2318 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2319 RARP, etc.) is not finished yet.
2320 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
2321 not found in the transmit or receive queue. It has either completed
2322 or was not issued by Transmit() and Receive().
2328 IN EFI_IP4_PROTOCOL
*This
,
2329 IN EFI_IP4_COMPLETION_TOKEN
*Token OPTIONAL
2332 IP4_PROTOCOL
*IpInstance
;
2337 return EFI_INVALID_PARAMETER
;
2340 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2342 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2344 if (IpInstance
->State
!= IP4_STATE_CONFIGED
) {
2345 Status
= EFI_NOT_STARTED
;
2349 if (IpInstance
->ConfigData
.UseDefaultAddress
&& IP4_NO_MAPPING (IpInstance
)) {
2350 Status
= EFI_NO_MAPPING
;
2354 Status
= Ip4Cancel (IpInstance
, Token
);
2357 gBS
->RestoreTPL (OldTpl
);
2363 Polls for incoming data packets and processes outgoing data packets.
2365 The Poll() function polls for incoming data packets and processes outgoing data
2366 packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()
2367 function to increase the rate that data packets are moved between the communications
2368 device and the transmit and receive queues.
2370 In some systems the periodic timer event may not poll the underlying communications
2371 device fast enough to transmit and/or receive all data packets without missing
2372 incoming packets or dropping outgoing packets. Drivers and applications that are
2373 experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function
2376 @param[in] This Pointer to the EFI_IP4_PROTOCOL instance.
2378 @retval EFI_SUCCESS Incoming or outgoing data was processed.
2379 @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.
2380 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
2381 RARP, etc.) is not finished yet.
2382 @retval EFI_INVALID_PARAMETER This is NULL.
2383 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
2384 @retval EFI_NOT_READY No incoming or outgoing data is processed.
2385 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
2386 Consider increasing the polling rate.
2392 IN EFI_IP4_PROTOCOL
*This
2395 IP4_PROTOCOL
*IpInstance
;
2396 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
2399 return EFI_INVALID_PARAMETER
;
2402 IpInstance
= IP4_INSTANCE_FROM_PROTOCOL (This
);
2404 if (IpInstance
->State
== IP4_STATE_UNCONFIGED
) {
2405 return EFI_NOT_STARTED
;
2408 Mnp
= IpInstance
->Service
->Mnp
;
2411 // Don't lock the Poll function to enable the deliver of
2412 // the packet polled up.
2414 return Mnp
->Poll (Mnp
);
2418 Decrease the life of the transmitted packets. If it is
2419 decreased to zero, cancel the packet. This function is
2420 called by Ip4PacketTimerTicking which time out both the
2421 received-but-not-delivered and transmitted-but-not-recycle
2424 @param[in] Map The IP4 child's transmit map.
2425 @param[in] Item Current transmitted packet
2426 @param[in] Context Not used.
2428 @retval EFI_SUCCESS Always returns EFI_SUCCESS
2432 Ip4SentPacketTicking (
2434 IN NET_MAP_ITEM
*Item
,
2438 IP4_TXTOKEN_WRAP
*Wrap
;
2440 Wrap
= (IP4_TXTOKEN_WRAP
*) Item
->Value
;
2441 ASSERT (Wrap
!= NULL
);
2443 if ((Wrap
->Life
> 0) && (--Wrap
->Life
== 0)) {
2444 Ip4CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
2452 The heart beat timer of IP4 service instance. It times out
2453 all of its IP4 children's received-but-not-delivered and
2454 transmitted-but-not-recycle packets, and provides time input
2455 for its IGMP protocol.
2457 @param[in] Event The IP4 service instance's heart beat timer.
2458 @param[in] Context The IP4 service instance.
2470 IpSb
= (IP4_SERVICE
*) Context
;
2471 NET_CHECK_SIGNATURE (IpSb
, IP4_SERVICE_SIGNATURE
);
2473 Ip4PacketTimerTicking (IpSb
);
2474 Ip4IgmpTicking (IpSb
);