3 Implementation of the SNP.McastIpToMac() function and its private helpers if
6 Copyright (C) 2013, Red Hat, Inc.
7 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
9 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include <Library/UefiBootServicesTableLib.h>
15 #include "VirtioNet.h"
18 Converts a multicast IP address to a multicast HW MAC address.
20 @param This The protocol instance pointer.
21 @param IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
22 to FALSE if the multicast IP address is IPv4 [RFC 791].
23 @param IP The multicast IP address that is to be converted to a multicast
25 @param MAC The multicast HW MAC address that is to be generated from IP.
27 @retval EFI_SUCCESS The multicast IP address was mapped to the
28 multicast HW MAC address.
29 @retval EFI_NOT_STARTED The network interface has not been started.
30 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The
31 current buffer size needed to hold the
32 statistics is returned in StatisticsSize.
33 @retval EFI_INVALID_PARAMETER One or more of the parameters has an
35 @retval EFI_DEVICE_ERROR The command could not be sent to the network
37 @retval EFI_UNSUPPORTED This function is not supported by the network
44 VirtioNetMcastIpToMac (
45 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
47 IN EFI_IP_ADDRESS
*Ip
,
48 OUT EFI_MAC_ADDRESS
*Mac
56 // http://en.wikipedia.org/wiki/Multicast_address
58 if (This
== NULL
|| Ip
== NULL
|| Mac
== NULL
||
59 ( IPv6
&& (Ip
->v6
.Addr
[0] ) != 0xFF) || // invalid IPv6 mcast addr
60 (!IPv6
&& (Ip
->v4
.Addr
[0] & 0xF0) != 0xE0) // invalid IPv4 mcast addr
62 return EFI_INVALID_PARAMETER
;
65 Dev
= VIRTIO_NET_FROM_SNP (This
);
66 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
67 switch (Dev
->Snm
.State
) {
68 case EfiSimpleNetworkStopped
:
69 Status
= EFI_NOT_STARTED
;
71 case EfiSimpleNetworkStarted
:
72 Status
= EFI_DEVICE_ERROR
;
79 // http://en.wikipedia.org/wiki/IP_multicast#Layer_2_delivery
84 Mac
->Addr
[2] = Ip
->v6
.Addr
[12];
85 Mac
->Addr
[3] = Ip
->v6
.Addr
[13];
86 Mac
->Addr
[4] = Ip
->v6
.Addr
[14];
87 Mac
->Addr
[5] = Ip
->v6
.Addr
[15];
93 Mac
->Addr
[3] = Ip
->v4
.Addr
[1] & 0x7F;
94 Mac
->Addr
[4] = Ip
->v4
.Addr
[2];
95 Mac
->Addr
[5] = Ip
->v4
.Addr
[3];
100 gBS
->RestoreTPL (OldTpl
);