VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/E1kNetDxe/SnpMcastIpToMac.c@ 108198

Last change on this file since 108198 was 106066, checked in by vboxsync, 5 months ago

Manual copyright year updates.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette