]>
Commit | Line | Data |
---|---|---|
f8ec2cc5 LE |
1 | /** @file\r |
2 | \r | |
3 | Implementation of the SNP.McastIpToMac() function and its private helpers if\r | |
4 | any.\r | |
5 | \r | |
6 | Copyright (C) 2013, Red Hat, Inc.\r | |
7 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r | |
8 | \r | |
b26f0cf9 | 9 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
f8ec2cc5 LE |
10 | \r |
11 | **/\r | |
12 | \r | |
13 | #include <Library/UefiBootServicesTableLib.h>\r | |
14 | \r | |
15 | #include "VirtioNet.h"\r | |
16 | \r | |
17 | /**\r | |
18 | Converts a multicast IP address to a multicast HW MAC address.\r | |
19 | \r | |
20 | @param This The protocol instance pointer.\r | |
21 | @param IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set\r | |
22 | to FALSE if the multicast IP address is IPv4 [RFC 791].\r | |
23 | @param IP The multicast IP address that is to be converted to a multicast\r | |
24 | HW MAC address.\r | |
25 | @param MAC The multicast HW MAC address that is to be generated from IP.\r | |
26 | \r | |
27 | @retval EFI_SUCCESS The multicast IP address was mapped to the\r | |
28 | multicast HW MAC address.\r | |
29 | @retval EFI_NOT_STARTED The network interface has not been started.\r | |
30 | @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The\r | |
31 | current buffer size needed to hold the\r | |
32 | statistics is returned in StatisticsSize.\r | |
33 | @retval EFI_INVALID_PARAMETER One or more of the parameters has an\r | |
34 | unsupported value.\r | |
35 | @retval EFI_DEVICE_ERROR The command could not be sent to the network\r | |
36 | interface.\r | |
37 | @retval EFI_UNSUPPORTED This function is not supported by the network\r | |
38 | interface.\r | |
39 | \r | |
40 | **/\r | |
f8ec2cc5 LE |
41 | EFI_STATUS\r |
42 | EFIAPI\r | |
43 | VirtioNetMcastIpToMac (\r | |
ac0a286f MK |
44 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r |
45 | IN BOOLEAN IPv6,\r | |
46 | IN EFI_IP_ADDRESS *Ip,\r | |
47 | OUT EFI_MAC_ADDRESS *Mac\r | |
f8ec2cc5 LE |
48 | )\r |
49 | {\r | |
ac0a286f MK |
50 | VNET_DEV *Dev;\r |
51 | EFI_TPL OldTpl;\r | |
52 | EFI_STATUS Status;\r | |
f8ec2cc5 LE |
53 | \r |
54 | //\r | |
55 | // http://en.wikipedia.org/wiki/Multicast_address\r | |
56 | //\r | |
ac0a286f MK |
57 | if ((This == NULL) || (Ip == NULL) || (Mac == NULL) ||\r |
58 | (IPv6 && ((Ip->v6.Addr[0]) != 0xFF)) || // invalid IPv6 mcast addr\r | |
59 | (!IPv6 && ((Ip->v4.Addr[0] & 0xF0) != 0xE0)) // invalid IPv4 mcast addr\r | |
60 | )\r | |
61 | {\r | |
f8ec2cc5 LE |
62 | return EFI_INVALID_PARAMETER;\r |
63 | }\r | |
64 | \r | |
ac0a286f | 65 | Dev = VIRTIO_NET_FROM_SNP (This);\r |
f8ec2cc5 LE |
66 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
67 | switch (Dev->Snm.State) {\r | |
ac0a286f MK |
68 | case EfiSimpleNetworkStopped:\r |
69 | Status = EFI_NOT_STARTED;\r | |
70 | goto Exit;\r | |
71 | case EfiSimpleNetworkStarted:\r | |
72 | Status = EFI_DEVICE_ERROR;\r | |
73 | goto Exit;\r | |
74 | default:\r | |
75 | break;\r | |
f8ec2cc5 LE |
76 | }\r |
77 | \r | |
78 | //\r | |
79 | // http://en.wikipedia.org/wiki/IP_multicast#Layer_2_delivery\r | |
80 | //\r | |
81 | if (IPv6) {\r | |
82 | Mac->Addr[0] = 0x33;\r | |
83 | Mac->Addr[1] = 0x33;\r | |
84 | Mac->Addr[2] = Ip->v6.Addr[12];\r | |
85 | Mac->Addr[3] = Ip->v6.Addr[13];\r | |
86 | Mac->Addr[4] = Ip->v6.Addr[14];\r | |
87 | Mac->Addr[5] = Ip->v6.Addr[15];\r | |
ac0a286f | 88 | } else {\r |
f8ec2cc5 LE |
89 | Mac->Addr[0] = 0x01;\r |
90 | Mac->Addr[1] = 0x00;\r | |
91 | Mac->Addr[2] = 0x5E;\r | |
92 | Mac->Addr[3] = Ip->v4.Addr[1] & 0x7F;\r | |
93 | Mac->Addr[4] = Ip->v4.Addr[2];\r | |
94 | Mac->Addr[5] = Ip->v4.Addr[3];\r | |
95 | }\r | |
ac0a286f | 96 | \r |
f8ec2cc5 LE |
97 | Status = EFI_SUCCESS;\r |
98 | \r | |
99 | Exit:\r | |
100 | gBS->RestoreTPL (OldTpl);\r | |
101 | return Status;\r | |
102 | }\r |