1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/** @file
Implementation of converting an multicast IP address to multicast HW MAC
address.
Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed
and made available under the terms and conditions of the BSD License which
accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Snp.h"
/**
Call undi to convert an multicast IP address to a MAC address.
@param Snp Pointer to snp driver structure.
@param IPv6 Flag to indicate if this is an ipv6 address.
@param IP Multicast IP address.
@param MAC Pointer to hold the return MAC address.
@retval EFI_SUCCESS The multicast IP address was mapped to the
multicast HW MAC address.
@retval EFI_INVALID_PARAMETER Invalid UNDI command.
@retval EFI_UNSUPPORTED Command is not supported by UNDI.
@retval EFI_DEVICE_ERROR Fail to execute UNDI command.
**/
EFI_STATUS
PxeIp2Mac (
IN SNP_DRIVER *Snp,
IN BOOLEAN IPv6,
IN EFI_IP_ADDRESS *IP,
IN OUT EFI_MAC_ADDRESS *MAC
)
{
PXE_CPB_MCAST_IP_TO_MAC *Cpb;
PXE_DB_MCAST_IP_TO_MAC *Db;
Cpb = Snp->Cpb;
Db = Snp->Db;
Snp->Cdb.OpCode = PXE_OPCODE_MCAST_IP_TO_MAC;
Snp->Cdb.OpFlags = (UINT16) (IPv6 ? PXE_OPFLAGS_MCAST_IPV6_TO_MAC : PXE_OPFLAGS_MCAST_IPV4_TO_MAC);
Snp->Cdb.CPBsize = (UINT16) sizeof (PXE_CPB_MCAST_IP_TO_MAC);
Snp->Cdb.DBsize = (UINT16) sizeof (PXE_DB_MCAST_IP_TO_MAC);
Snp->Cdb.CPBaddr = (UINT64)(UINTN) Cpb;
Snp->Cdb.DBaddr = (UINT64)(UINTN) Db;
Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
Snp->Cdb.IFnum = Snp->IfNum;
Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
CopyMem (&Cpb->IP, IP, sizeof (PXE_IP_ADDR));
//
// Issue UNDI command and check result.
//
DEBUG ((EFI_D_NET, "\nSnp->undi.mcast_ip_to_mac() "));
(*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);
switch (Snp->Cdb.StatCode) {
case PXE_STATCODE_SUCCESS:
break;
case PXE_STATCODE_INVALID_CPB:
return EFI_INVALID_PARAMETER;
case PXE_STATCODE_UNSUPPORTED:
DEBUG (
(EFI_D_NET,
"\nSnp->undi.mcast_ip_to_mac() %xh:%xh\n",
Snp->Cdb.StatFlags,
Snp->Cdb.StatCode)
);
return EFI_UNSUPPORTED;
default:
//
// UNDI command failed. Return EFI_DEVICE_ERROR
// to caller.
//
DEBUG (
(EFI_D_NET,
"\nSnp->undi.mcast_ip_to_mac() %xh:%xh\n",
Snp->Cdb.StatFlags,
Snp->Cdb.StatCode)
);
return EFI_DEVICE_ERROR;
}
CopyMem (MAC, &Db->MAC, sizeof (PXE_MAC_ADDR));
return EFI_SUCCESS;
}
/**
Converts a multicast IP address to a multicast HW MAC address.
This function converts a multicast IP address to a multicast HW MAC address
for all packet transactions. If the mapping is accepted, then EFI_SUCCESS will
be returned.
@param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
@param IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460].
Set to FALSE if the multicast IP address is IPv4 [RFC 791].
@param IP The multicast IP address that is to be converted to a multicast
HW MAC address.
@param MAC The multicast HW MAC address that is to be generated from IP.
@retval EFI_SUCCESS The multicast IP address was mapped to the
multicast HW MAC address.
@retval EFI_NOT_STARTED The Simple Network Protocol interface has not
been started by calling Start().
@retval EFI_INVALID_PARAMETER IP is NULL.
@retval EFI_INVALID_PARAMETER MAC is NULL.
@retval EFI_INVALID_PARAMETER IP does not point to a valid IPv4 or IPv6
multicast address.
@retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not
been initialized by calling Initialize().
@retval EFI_UNSUPPORTED IPv6 is TRUE and the implementation does not
support IPv6 multicast to MAC address conversion.
**/
EFI_STATUS
EFIAPI
SnpUndi32McastIpToMac (
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN BOOLEAN IPv6,
IN EFI_IP_ADDRESS *IP,
OUT EFI_MAC_ADDRESS *MAC
)
{
SNP_DRIVER *Snp;
EFI_TPL OldTpl;
EFI_STATUS Status;
//
// Get pointer to SNP driver instance for *this.
//
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
if (IP == NULL || MAC == NULL) {
return EFI_INVALID_PARAMETER;
}
Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
switch (Snp->Mode.State) {
case EfiSimpleNetworkInitialized:
break;
case EfiSimpleNetworkStopped:
Status = EFI_NOT_STARTED;
goto ON_EXIT;
default:
Status = EFI_DEVICE_ERROR;
goto ON_EXIT;
}
Status = PxeIp2Mac (Snp, IPv6, IP, MAC);
ON_EXIT:
gBS->RestoreTPL (OldTpl);
return Status;
}
|