3 Copyright (c) 2005 - 2007, Intel Corporation
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.
18 Implementation of Managed Network Protocol public services.
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/BaseLib.h>
30 Get configuration data of this instance.
32 @param This Pointer to the Managed Network Protocol.
33 @param MnpConfigData Pointer to strorage for MNP operational
35 @param SnpModeData Pointer to strorage for SNP operational
38 @retval EFI_SUCCESS The operation completed successfully.
39 @retval EFI_INVALID_PARAMETER This is NULL.
40 @retval EFI_NOT_STARTED This MNP child driver instance has not been
41 configured The default values are returned in
42 MnpConfigData if it is not NULL.
48 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
,
49 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
50 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
53 MNP_INSTANCE_DATA
*Instance
;
54 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
60 return EFI_INVALID_PARAMETER
;
63 Instance
= MNP_INSTANCE_DATA_FROM_THIS (This
);
65 OldTpl
= NET_RAISE_TPL (NET_TPL_LOCK
);
67 if (MnpConfigData
!= NULL
) {
69 // Copy the instance configuration data.
71 CopyMem (MnpConfigData
, &Instance
->ConfigData
, sizeof (*MnpConfigData
));
74 if (SnpModeData
!= NULL
) {
76 // Copy the underlayer Snp mode data.
78 Snp
= Instance
->MnpServiceData
->Snp
;
79 CopyMem (SnpModeData
, Snp
->Mode
, sizeof (*SnpModeData
));
82 if (!Instance
->Configured
) {
83 Status
= EFI_NOT_STARTED
;
88 NET_RESTORE_TPL (OldTpl
);
95 Set or clear the operational parameters for the MNP child driver.
97 @param This Pointer to the Managed Network Protocol.
98 @param MnpConfigData Pointer to the configuration data that will be
99 assigned to the MNP child driver instance. If
100 NULL, the MNP child driver instance is reset to
101 startup defaults and all pending transmit and
102 receive requests are flushed.
104 @retval EFI_SUCCESS The operation completed successfully.
105 @retval EFI_INVALID_PARAMETER One or more parameter is invalid.
106 @retval EFI_OUT_OF_RESOURCES Required system resources (usually memory) could
108 @retval EFI_UNSUPPORTED EnableReceiveTimestamps is TRUE, this
109 implementation doesn't support it.
110 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
111 @retval Other The MNP child driver instance has been reset to
118 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
,
119 IN EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
122 MNP_INSTANCE_DATA
*Instance
;
126 if ((This
== NULL
) ||
127 ((MnpConfigData
!= NULL
) &&
128 (MnpConfigData
->ProtocolTypeFilter
> 0) &&
129 (MnpConfigData
->ProtocolTypeFilter
<= 1500))) {
131 return EFI_INVALID_PARAMETER
;
134 Instance
= MNP_INSTANCE_DATA_FROM_THIS (This
);
136 OldTpl
= NET_RAISE_TPL (NET_TPL_LOCK
);
138 if ((MnpConfigData
== NULL
) && (!Instance
->Configured
)) {
140 // If the instance is not configured and a reset is requested, just return.
142 Status
= EFI_SUCCESS
;
147 // Configure the instance.
149 Status
= MnpConfigureInstance (Instance
, MnpConfigData
);
152 NET_RESTORE_TPL (OldTpl
);
159 Translate a multicast IP address to a multicast hardware (MAC) address.
161 @param This Pointer to the Managed Network Protocol.
162 @param Ipv6Flag Set to TRUE if IpAddress is an IPv6 multicast
163 address. Set to FALSE if IpAddress is an IPv4
165 @param IpAddress Pointer to the multicast IP address to convert.
166 @param MacAddress Pointer to the resulting multicast MAC address.
168 @retval EFI_SUCCESS The operation completed successfully.
169 @retval EFI_INVALID_PARAMETER One or more parameter is invalid.
170 @retval EFI_NOT_STARTED This MNP child driver instance has not been
172 @retval EFI_UNSUPPORTED Ipv6Flag is TRUE, this implementation doesn't
174 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
175 @retval Other The address could not be converted.
181 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
,
183 IN EFI_IP_ADDRESS
*IpAddress
,
184 OUT EFI_MAC_ADDRESS
*MacAddress
188 MNP_INSTANCE_DATA
*Instance
;
189 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
192 if ((This
== NULL
) || (IpAddress
== NULL
) || (MacAddress
== NULL
)) {
194 return EFI_INVALID_PARAMETER
;
199 // Currently IPv6 isn't supported.
201 return EFI_UNSUPPORTED
;
204 if (!IP4_IS_MULTICAST (EFI_NTOHL (*IpAddress
))) {
206 // The IPv4 address passed in is not a multicast address.
208 return EFI_INVALID_PARAMETER
;
211 Instance
= MNP_INSTANCE_DATA_FROM_THIS (This
);
213 OldTpl
= NET_RAISE_TPL (NET_TPL_LOCK
);
215 if (!Instance
->Configured
) {
217 Status
= EFI_NOT_STARTED
;
221 Snp
= Instance
->MnpServiceData
->Snp
;
222 ASSERT (Snp
!= NULL
);
224 if (Snp
->Mode
->IfType
== NET_IFTYPE_ETHERNET
) {
226 // Translate the IPv4 address into a multicast MAC address if the NIC is an
229 MacAddress
->Addr
[0] = 0x01;
230 MacAddress
->Addr
[1] = 0x00;
231 MacAddress
->Addr
[2] = 0x5E;
232 MacAddress
->Addr
[3] = (UINT8
) (IpAddress
->v4
.Addr
[1] & 0x7F);
233 MacAddress
->Addr
[4] = IpAddress
->v4
.Addr
[2];
234 MacAddress
->Addr
[5] = IpAddress
->v4
.Addr
[3];
236 Status
= EFI_SUCCESS
;
239 // Invoke Snp to translate the multicast IP address.
241 Status
= Snp
->MCastIpToMac (
250 NET_RESTORE_TPL (OldTpl
);
257 Enable or disable receie filters for multicast address.
259 @param This Pointer to the Managed Network Protocol.
260 @param JoinFlag Set to TRUE to join this multicast group. Set to
261 FALSE to leave this multicast group.
262 @param MacAddress Pointer to the multicast MAC group (address) to
265 @retval EFI_SUCCESS The operation completed successfully.
266 @retval EFI_INVALID_PARAMETER One or more parameter is invalid
267 @retval EFI_NOT_STARTED This MNP child driver instance has not been
269 @retval EFI_ALREADY_STARTED The supplied multicast group is already joined.
270 @retval EFI_NOT_FOUND The supplied multicast group is not joined.
271 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
272 @retval Other The requested operation could not be completed.
273 The MNP multicast group settings are unchanged.
279 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
,
281 IN EFI_MAC_ADDRESS
*MacAddress OPTIONAL
284 MNP_INSTANCE_DATA
*Instance
;
285 EFI_SIMPLE_NETWORK_MODE
*SnpMode
;
286 MNP_GROUP_CONTROL_BLOCK
*GroupCtrlBlk
;
287 MNP_GROUP_ADDRESS
*GroupAddress
;
288 NET_LIST_ENTRY
*ListEntry
;
289 BOOLEAN AddressExist
;
293 if (This
== NULL
|| (JoinFlag
&& (MacAddress
== NULL
))) {
295 // This is NULL, or it's a join operation but MacAddress is NULL.
297 return EFI_INVALID_PARAMETER
;
300 Instance
= MNP_INSTANCE_DATA_FROM_THIS (This
);
301 SnpMode
= Instance
->MnpServiceData
->Snp
->Mode
;
303 OldTpl
= NET_RAISE_TPL (NET_TPL_LOCK
);
305 if (!Instance
->Configured
) {
307 Status
= EFI_NOT_STARTED
;
311 if ((!Instance
->ConfigData
.EnableMulticastReceive
) ||
312 ((MacAddress
!= NULL
) && !NET_MAC_IS_MULTICAST (MacAddress
, &SnpMode
->BroadcastAddress
, SnpMode
->HwAddressSize
))) {
314 // The instance isn't configured to do mulitcast receive. OR
315 // the passed in MacAddress is not a mutlticast mac address.
317 Status
= EFI_INVALID_PARAMETER
;
321 Status
= EFI_SUCCESS
;
322 AddressExist
= FALSE
;
325 if (MacAddress
!= NULL
) {
327 // Search the instance's GroupCtrlBlkList to find the specific address.
329 NET_LIST_FOR_EACH (ListEntry
, &Instance
->GroupCtrlBlkList
) {
331 GroupCtrlBlk
= NET_LIST_USER_STRUCT (
333 MNP_GROUP_CONTROL_BLOCK
,
336 GroupAddress
= GroupCtrlBlk
->GroupAddress
;
337 if (0 == NetCompareMem (
339 &GroupAddress
->Address
,
340 SnpMode
->HwAddressSize
343 // There is already the same multicast mac address configured.
350 if (JoinFlag
&& AddressExist
) {
352 // The multicast mac address to join already exists.
354 Status
= EFI_ALREADY_STARTED
;
357 if (!JoinFlag
&& !AddressExist
) {
359 // The multicast mac address to leave doesn't exist in this instance.
361 Status
= EFI_NOT_FOUND
;
364 if (EFI_ERROR (Status
)) {
367 } else if (NetListIsEmpty (&Instance
->GroupCtrlBlkList
)) {
369 // The MacAddress is NULL and there is no configured multicast mac address,
376 // OK, it is time to take action.
378 Status
= MnpGroupOp (Instance
, JoinFlag
, MacAddress
, GroupCtrlBlk
);
381 NET_RESTORE_TPL (OldTpl
);
388 Place an outgoing packet into the transmit queue.
390 @param This Pointer to the Managed Network Protocol.
391 @param Token Pointer to a token associated with the transmit
394 @retval EFI_SUCCESS The operation completed successfully.
395 @retval EFI_INVALID_PARAMETER One or more parameter is invalid
396 @retval EFI_NOT_STARTED This MNP child driver instance has not been
398 @retval EFI_ACCESS_DENIED The transmit completion token is already in the
400 @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a
401 lack of system resources (usually memory).
402 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
403 The MNP child driver instance has been reset to
405 @retval EFI_NOT_READY The transmit request could not be queued because
406 the transmit queue is full.
412 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
,
413 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN
*Token
417 MNP_INSTANCE_DATA
*Instance
;
418 MNP_SERVICE_DATA
*MnpServiceData
;
423 if ((This
== NULL
) || (Token
== NULL
)) {
425 return EFI_INVALID_PARAMETER
;
428 Instance
= MNP_INSTANCE_DATA_FROM_THIS (This
);
430 OldTpl
= NET_RAISE_TPL (NET_TPL_LOCK
);
432 if (!Instance
->Configured
) {
434 Status
= EFI_NOT_STARTED
;
438 if (!MnpIsValidTxToken (Instance
, Token
)) {
440 // The Token is invalid.
442 Status
= EFI_INVALID_PARAMETER
;
446 MnpServiceData
= Instance
->MnpServiceData
;
447 NET_CHECK_SIGNATURE (MnpServiceData
, MNP_SERVICE_DATA_SIGNATURE
);
450 // Build the tx packet
452 MnpBuildTxPacket (MnpServiceData
, Token
->Packet
.TxData
, &PktBuf
, &PktLen
);
455 // OK, send the packet synchronously.
457 Status
= MnpSyncSendPacket (MnpServiceData
, PktBuf
, PktLen
, Token
);
460 NET_RESTORE_TPL (OldTpl
);
467 Place an asynchronous receiving request into the receiving queue.
469 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL
471 @param Token Pointer to a token associated with the receive
474 @retval EFI_SUCCESS The receive completion token was cached.
475 @retval EFI_NOT_STARTED This MNP child driver instance has not been
477 @retval EFI_INVALID_PARAMETER One or more parameter is invalid.
478 @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a
479 lack of system resources (usually memory).
480 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
481 The MNP child driver instance has been reset to
483 @retval EFI_ACCESS_DENIED The receive completion token was already in the
485 @retval EFI_NOT_READY The receive request could not be queued because
486 the receive queue is full.
492 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
,
493 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN
*Token
497 MNP_INSTANCE_DATA
*Instance
;
500 if ((This
== NULL
) || (Token
== NULL
) || (Token
->Event
== NULL
)) {
502 return EFI_INVALID_PARAMETER
;
505 Instance
= MNP_INSTANCE_DATA_FROM_THIS (This
);
507 OldTpl
= NET_RAISE_TPL (NET_TPL_LOCK
);
509 if (!Instance
->Configured
) {
511 Status
= EFI_NOT_STARTED
;
516 // Check whether this token(event) is already in the rx token queue.
518 Status
= NetMapIterate (&Instance
->RxTokenMap
, MnpTokenExist
, (VOID
*) Token
);
519 if (EFI_ERROR (Status
)) {
525 // Insert the Token into the RxTokenMap.
527 Status
= NetMapInsertTail (&Instance
->RxTokenMap
, (VOID
*) Token
, NULL
);
529 if (!EFI_ERROR (Status
)) {
531 // Try to deliver any buffered packets.
533 Status
= MnpInstanceDeliverPacket (Instance
);
536 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
538 NetLibDispatchDpc ();
542 NET_RESTORE_TPL (OldTpl
);
549 Abort a pending transmit or receive request.
551 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL
553 @param Token Pointer to a token that has been issued by
554 EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or
555 EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL,
556 all pending tokens are aborted.
558 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
559 Token->Event was signaled.
560 @retval EFI_NOT_STARTED This MNP child driver instance has not been
562 @retval EFI_INVALID_PARAMETER This is NULL.
563 @retval EFI_NOT_FOUND The asynchronous I/O request was not found in the
564 transmit or receive queue. It has either completed
565 or was not issued by Transmit() and Receive().
571 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
,
572 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN
*Token OPTIONAL
576 MNP_INSTANCE_DATA
*Instance
;
581 return EFI_INVALID_PARAMETER
;
584 Instance
= MNP_INSTANCE_DATA_FROM_THIS (This
);
586 OldTpl
= NET_RAISE_TPL (NET_TPL_LOCK
);
588 if (!Instance
->Configured
) {
590 Status
= EFI_NOT_STARTED
;
595 // Iterate the RxTokenMap to cancel the specified Token.
597 Status
= NetMapIterate (&Instance
->RxTokenMap
, MnpCancelTokens
, (VOID
*) Token
);
601 Status
= (Status
== EFI_ABORTED
) ? EFI_SUCCESS
: EFI_NOT_FOUND
;
605 // Dispatch the DPC queued by the NotifyFunction of the cancled token's events.
607 NetLibDispatchDpc ();
610 NET_RESTORE_TPL (OldTpl
);
617 Poll the network interface to do transmit/receive work.
619 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL
622 @retval EFI_SUCCESS Incoming or outgoing data was processed.
623 @retval EFI_NOT_STARTED This MNP child driver instance has not been
625 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
626 The MNP child driver instance has been reset to
628 @retval EFI_NOT_READY No incoming or outgoing data was processed.
629 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or
636 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
640 MNP_INSTANCE_DATA
*Instance
;
644 return EFI_INVALID_PARAMETER
;
647 Instance
= MNP_INSTANCE_DATA_FROM_THIS (This
);
649 OldTpl
= NET_RAISE_TPL (NET_TPL_LOCK
);
651 if (!Instance
->Configured
) {
652 Status
= EFI_NOT_STARTED
;
657 // Try to receive packets.
659 Status
= MnpReceivePacket (Instance
->MnpServiceData
);
661 NetLibDispatchDpc ();
664 NET_RESTORE_TPL (OldTpl
);