1 | /** @file
|
---|
2 |
|
---|
3 | Implementation of the SNP.McastIpToMac() function and its private helpers if
|
---|
4 | any.
|
---|
5 |
|
---|
6 | Copyright (C) 2013, Red Hat, Inc.
|
---|
7 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
---|
8 |
|
---|
9 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
10 |
|
---|
11 | **/
|
---|
12 |
|
---|
13 | #include <Library/UefiBootServicesTableLib.h>
|
---|
14 |
|
---|
15 | #include "VirtioNet.h"
|
---|
16 |
|
---|
17 | /**
|
---|
18 | Converts a multicast IP address to a multicast HW MAC address.
|
---|
19 |
|
---|
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
|
---|
24 | HW MAC address.
|
---|
25 | @param MAC The multicast HW MAC address that is to be generated from IP.
|
---|
26 |
|
---|
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
|
---|
34 | unsupported value.
|
---|
35 | @retval EFI_DEVICE_ERROR The command could not be sent to the network
|
---|
36 | interface.
|
---|
37 | @retval EFI_UNSUPPORTED This function is not supported by the network
|
---|
38 | interface.
|
---|
39 |
|
---|
40 | **/
|
---|
41 | EFI_STATUS
|
---|
42 | EFIAPI
|
---|
43 | VirtioNetMcastIpToMac (
|
---|
44 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
---|
45 | IN BOOLEAN IPv6,
|
---|
46 | IN EFI_IP_ADDRESS *Ip,
|
---|
47 | OUT EFI_MAC_ADDRESS *Mac
|
---|
48 | )
|
---|
49 | {
|
---|
50 | VNET_DEV *Dev;
|
---|
51 | EFI_TPL OldTpl;
|
---|
52 | EFI_STATUS Status;
|
---|
53 |
|
---|
54 | //
|
---|
55 | // http://en.wikipedia.org/wiki/Multicast_address
|
---|
56 | //
|
---|
57 | if ((This == NULL) || (Ip == NULL) || (Mac == NULL) ||
|
---|
58 | (IPv6 && ((Ip->v6.Addr[0]) != 0xFF)) || // invalid IPv6 mcast addr
|
---|
59 | (!IPv6 && ((Ip->v4.Addr[0] & 0xF0) != 0xE0)) // invalid IPv4 mcast addr
|
---|
60 | )
|
---|
61 | {
|
---|
62 | return EFI_INVALID_PARAMETER;
|
---|
63 | }
|
---|
64 |
|
---|
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;
|
---|
70 | goto Exit;
|
---|
71 | case EfiSimpleNetworkStarted:
|
---|
72 | Status = EFI_DEVICE_ERROR;
|
---|
73 | goto Exit;
|
---|
74 | default:
|
---|
75 | break;
|
---|
76 | }
|
---|
77 |
|
---|
78 | //
|
---|
79 | // http://en.wikipedia.org/wiki/IP_multicast#Layer_2_delivery
|
---|
80 | //
|
---|
81 | if (IPv6) {
|
---|
82 | Mac->Addr[0] = 0x33;
|
---|
83 | Mac->Addr[1] = 0x33;
|
---|
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];
|
---|
88 | } else {
|
---|
89 | Mac->Addr[0] = 0x01;
|
---|
90 | Mac->Addr[1] = 0x00;
|
---|
91 | Mac->Addr[2] = 0x5E;
|
---|
92 | Mac->Addr[3] = Ip->v4.Addr[1] & 0x7F;
|
---|
93 | Mac->Addr[4] = Ip->v4.Addr[2];
|
---|
94 | Mac->Addr[5] = Ip->v4.Addr[3];
|
---|
95 | }
|
---|
96 |
|
---|
97 | Status = EFI_SUCCESS;
|
---|
98 |
|
---|
99 | Exit:
|
---|
100 | gBS->RestoreTPL (OldTpl);
|
---|
101 | return Status;
|
---|
102 | }
|
---|