]>
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 | |
9 | This program and the accompanying materials are licensed and made available\r | |
10 | under the terms and conditions of the BSD License which accompanies this\r | |
11 | distribution. The full text of the license may be found at\r | |
12 | http://opensource.org/licenses/bsd-license.php\r | |
13 | \r | |
14 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r | |
15 | WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
16 | \r | |
17 | **/\r | |
18 | \r | |
19 | #include <Library/UefiBootServicesTableLib.h>\r | |
20 | \r | |
21 | #include "VirtioNet.h"\r | |
22 | \r | |
23 | /**\r | |
24 | Converts a multicast IP address to a multicast HW MAC address.\r | |
25 | \r | |
26 | @param This The protocol instance pointer.\r | |
27 | @param IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set\r | |
28 | to FALSE if the multicast IP address is IPv4 [RFC 791].\r | |
29 | @param IP The multicast IP address that is to be converted to a multicast\r | |
30 | HW MAC address.\r | |
31 | @param MAC The multicast HW MAC address that is to be generated from IP.\r | |
32 | \r | |
33 | @retval EFI_SUCCESS The multicast IP address was mapped to the\r | |
34 | multicast HW MAC address.\r | |
35 | @retval EFI_NOT_STARTED The network interface has not been started.\r | |
36 | @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The\r | |
37 | current buffer size needed to hold the\r | |
38 | statistics is returned in StatisticsSize.\r | |
39 | @retval EFI_INVALID_PARAMETER One or more of the parameters has an\r | |
40 | unsupported value.\r | |
41 | @retval EFI_DEVICE_ERROR The command could not be sent to the network\r | |
42 | interface.\r | |
43 | @retval EFI_UNSUPPORTED This function is not supported by the network\r | |
44 | interface.\r | |
45 | \r | |
46 | **/\r | |
47 | \r | |
48 | EFI_STATUS\r | |
49 | EFIAPI\r | |
50 | VirtioNetMcastIpToMac (\r | |
51 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
52 | IN BOOLEAN IPv6,\r | |
53 | IN EFI_IP_ADDRESS *Ip,\r | |
54 | OUT EFI_MAC_ADDRESS *Mac\r | |
55 | )\r | |
56 | {\r | |
57 | VNET_DEV *Dev;\r | |
58 | EFI_TPL OldTpl;\r | |
59 | EFI_STATUS Status;\r | |
60 | \r | |
61 | //\r | |
62 | // http://en.wikipedia.org/wiki/Multicast_address\r | |
63 | //\r | |
64 | if (This == NULL || Ip == NULL || Mac == NULL ||\r | |
65 | ( IPv6 && (Ip->v6.Addr[0] ) != 0xFF) || // invalid IPv6 mcast addr\r | |
66 | (!IPv6 && (Ip->v4.Addr[0] & 0xF0) != 0xE0) // invalid IPv4 mcast addr\r | |
67 | ) {\r | |
68 | return EFI_INVALID_PARAMETER;\r | |
69 | }\r | |
70 | \r | |
71 | Dev = VIRTIO_NET_FROM_SNP (This);\r | |
72 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
73 | switch (Dev->Snm.State) {\r | |
74 | case EfiSimpleNetworkStopped:\r | |
75 | Status = EFI_NOT_STARTED;\r | |
76 | goto Exit;\r | |
77 | case EfiSimpleNetworkStarted:\r | |
78 | Status = EFI_DEVICE_ERROR;\r | |
79 | goto Exit;\r | |
80 | default:\r | |
81 | break;\r | |
82 | }\r | |
83 | \r | |
84 | //\r | |
85 | // http://en.wikipedia.org/wiki/IP_multicast#Layer_2_delivery\r | |
86 | //\r | |
87 | if (IPv6) {\r | |
88 | Mac->Addr[0] = 0x33;\r | |
89 | Mac->Addr[1] = 0x33;\r | |
90 | Mac->Addr[2] = Ip->v6.Addr[12];\r | |
91 | Mac->Addr[3] = Ip->v6.Addr[13];\r | |
92 | Mac->Addr[4] = Ip->v6.Addr[14];\r | |
93 | Mac->Addr[5] = Ip->v6.Addr[15];\r | |
94 | }\r | |
95 | else {\r | |
96 | Mac->Addr[0] = 0x01;\r | |
97 | Mac->Addr[1] = 0x00;\r | |
98 | Mac->Addr[2] = 0x5E;\r | |
99 | Mac->Addr[3] = Ip->v4.Addr[1] & 0x7F;\r | |
100 | Mac->Addr[4] = Ip->v4.Addr[2];\r | |
101 | Mac->Addr[5] = Ip->v4.Addr[3];\r | |
102 | }\r | |
103 | Status = EFI_SUCCESS;\r | |
104 | \r | |
105 | Exit:\r | |
106 | gBS->RestoreTPL (OldTpl);\r | |
107 | return Status;\r | |
108 | }\r |