2 Implementation of reading the MAC address of a network adapter.
4 Copyright (c) 2004 - 2007, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials are licensed
6 and made available under the terms and conditions of the BSD License which
7 accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Call UNDI to read the MAC address of the NIC and update the mode structure
22 @param Snp Pointer to snp driver structure.
24 @retval EFI_SUCCESS The MAC address of the NIC is read successfully.
25 @retval EFI_DEVICE_ERROR Failed to read the MAC address of the NIC.
33 PXE_DB_STATION_ADDRESS
*Db
;
36 Snp
->Cdb
.OpCode
= PXE_OPCODE_STATION_ADDRESS
;
37 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_READ
;
39 Snp
->Cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
40 Snp
->Cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
42 Snp
->Cdb
.DBsize
= sizeof (PXE_DB_STATION_ADDRESS
);
43 Snp
->Cdb
.DBaddr
= (UINT64
)(UINTN
) Db
;
45 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
46 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
47 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
48 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
51 // Issue UNDI command and check result.
53 DEBUG ((EFI_D_NET
, "\nsnp->undi.station_addr() "));
55 (*Snp
->IssueUndi32Command
) ((UINT64
)(UINTN
) &Snp
->Cdb
);
57 if (Snp
->Cdb
.StatCode
!= PXE_STATCODE_SUCCESS
) {
60 "\nsnp->undi.station_addr() %xh:%xh\n",
65 return EFI_DEVICE_ERROR
;
68 // Set new station address in SNP->Mode structure and return success.
71 &(Snp
->Mode
.CurrentAddress
),
73 Snp
->Mode
.HwAddressSize
77 &Snp
->Mode
.BroadcastAddress
,
79 Snp
->Mode
.HwAddressSize
83 &Snp
->Mode
.PermanentAddress
,
85 Snp
->Mode
.HwAddressSize
93 Call UNDI to set a new MAC address for the NIC.
95 @param Snp Pointer to Snp driver structure.
96 @param NewMacAddr Pointer to a MAC address to be set for the NIC, if this is
97 NULL then this routine resets the mac address to the NIC's
105 EFI_MAC_ADDRESS
*NewMacAddr
108 PXE_CPB_STATION_ADDRESS
*Cpb
;
109 PXE_DB_STATION_ADDRESS
*Db
;
113 Snp
->Cdb
.OpCode
= PXE_OPCODE_STATION_ADDRESS
;
115 if (NewMacAddr
== NULL
) {
116 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_RESET
;
117 Snp
->Cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
118 Snp
->Cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
120 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_READ
;
122 // even though the OPFLAGS are set to READ, supplying a new address
123 // in the CPB will make undi change the mac address to the new one.
125 CopyMem (&Cpb
->StationAddr
, NewMacAddr
, Snp
->Mode
.HwAddressSize
);
127 Snp
->Cdb
.CPBsize
= sizeof (PXE_CPB_STATION_ADDRESS
);
128 Snp
->Cdb
.CPBaddr
= (UINT64
)(UINTN
) Cpb
;
131 Snp
->Cdb
.DBsize
= sizeof (PXE_DB_STATION_ADDRESS
);
132 Snp
->Cdb
.DBaddr
= (UINT64
)(UINTN
) Db
;
134 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
135 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
136 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
137 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
140 // Issue UNDI command and check result.
142 DEBUG ((EFI_D_NET
, "\nsnp->undi.station_addr() "));
144 (*Snp
->IssueUndi32Command
) ((UINT64
)(UINTN
) &Snp
->Cdb
);
146 if (Snp
->Cdb
.StatCode
!= PXE_STATCODE_SUCCESS
) {
149 "\nsnp->undi.station_addr() %xh:%xh\n",
155 // UNDI command failed. Return UNDI status to caller.
157 return EFI_DEVICE_ERROR
;
160 // read the changed address and save it in SNP->Mode structure
169 Modifies or resets the current station address, if supported.
171 This function modifies or resets the current station address of a network
172 interface, if supported. If Reset is TRUE, then the current station address is
173 set to the network interface's permanent address. If Reset is FALSE, and the
174 network interface allows its station address to be modified, then the current
175 station address is changed to the address specified by New. If the network
176 interface does not allow its station address to be modified, then
177 EFI_INVALID_PARAMETER will be returned. If the station address is successfully
178 updated on the network interface, EFI_SUCCESS will be returned. If the driver
179 has not been initialized, EFI_DEVICE_ERROR will be returned.
181 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
182 @param Reset Flag used to reset the station address to the network interface's
184 @param New New station address to be used for the network interface.
187 @retval EFI_SUCCESS The network interface's station address was updated.
188 @retval EFI_NOT_STARTED The Simple Network Protocol interface has not been
189 started by calling Start().
190 @retval EFI_INVALID_PARAMETER The New station address was not accepted by the NIC.
191 @retval EFI_INVALID_PARAMETER Reset is FALSE and New is NULL.
192 @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not
193 been initialized by calling Initialize().
194 @retval EFI_DEVICE_ERROR An error occurred attempting to set the new
196 @retval EFI_UNSUPPORTED The NIC does not support changing the network
197 interface's station address.
202 SnpUndi32StationAddress (
203 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
205 IN EFI_MAC_ADDRESS
*New OPTIONAL
213 // Check for invalid parameter combinations.
215 if ((This
== NULL
) ||
216 (!Reset
&& (New
== NULL
))) {
217 return EFI_INVALID_PARAMETER
;
220 Snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
222 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
225 // Return error if the SNP is not initialized.
227 switch (Snp
->Mode
.State
) {
228 case EfiSimpleNetworkInitialized
:
231 case EfiSimpleNetworkStopped
:
232 Status
= EFI_NOT_STARTED
;
236 Status
= EFI_DEVICE_ERROR
;
241 Status
= PxeSetStnAddr (Snp
, NULL
);
243 Status
= PxeSetStnAddr (Snp
, New
);
247 gBS
->RestoreTPL (OldTpl
);