TianoCore EDK2 master
Loading...
Searching...
No Matches
SnpMcastIpToMac.c
Go to the documentation of this file.
1
14
15#include "VirtioNet.h"
16
42EFIAPI
45 IN BOOLEAN IPv6,
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
99Exit:
100 gBS->RestoreTPL (OldTpl);
101 return Status;
102}
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS EFIAPI VirtioNetMcastIpToMac(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN IPv6, IN EFI_IP_ADDRESS *Ip, OUT EFI_MAC_ADDRESS *Mac)
VOID EFIAPI Exit(IN EFI_STATUS Status)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINTN EFI_TPL
Definition: UefiBaseType.h:41
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS