2 Implementation of reading the MAC address of a network adapter.
4 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
5 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
= (UINT16
) 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_WRITE
;
122 // Supplying a new address in the CPB will make undi change the mac address to the new one.
124 CopyMem (&Cpb
->StationAddr
, NewMacAddr
, Snp
->Mode
.HwAddressSize
);
126 Snp
->Cdb
.CPBsize
= (UINT16
) sizeof (PXE_CPB_STATION_ADDRESS
);
127 Snp
->Cdb
.CPBaddr
= (UINT64
)(UINTN
) Cpb
;
130 Snp
->Cdb
.DBsize
= (UINT16
) sizeof (PXE_DB_STATION_ADDRESS
);
131 Snp
->Cdb
.DBaddr
= (UINT64
)(UINTN
) Db
;
133 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
134 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
135 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
136 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
139 // Issue UNDI command and check result.
141 DEBUG ((EFI_D_NET
, "\nsnp->undi.station_addr() "));
143 (*Snp
->IssueUndi32Command
) ((UINT64
)(UINTN
) &Snp
->Cdb
);
145 if (Snp
->Cdb
.StatCode
!= PXE_STATCODE_SUCCESS
) {
148 "\nsnp->undi.station_addr() %xh:%xh\n",
154 // UNDI command failed. Return UNDI status to caller.
156 return EFI_DEVICE_ERROR
;
159 // read the changed address and save it in SNP->Mode structure
168 Modifies or resets the current station address, if supported.
170 This function modifies or resets the current station address of a network
171 interface, if supported. If Reset is TRUE, then the current station address is
172 set to the network interface's permanent address. If Reset is FALSE, and the
173 network interface allows its station address to be modified, then the current
174 station address is changed to the address specified by New. If the network
175 interface does not allow its station address to be modified, then
176 EFI_INVALID_PARAMETER will be returned. If the station address is successfully
177 updated on the network interface, EFI_SUCCESS will be returned. If the driver
178 has not been initialized, EFI_DEVICE_ERROR will be returned.
180 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
181 @param Reset Flag used to reset the station address to the network interface's
183 @param New New station address to be used for the network interface.
186 @retval EFI_SUCCESS The network interface's station address was updated.
187 @retval EFI_NOT_STARTED The Simple Network Protocol interface has not been
188 started by calling Start().
189 @retval EFI_INVALID_PARAMETER The New station address was not accepted by the NIC.
190 @retval EFI_INVALID_PARAMETER Reset is FALSE and New is NULL.
191 @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not
192 been initialized by calling Initialize().
193 @retval EFI_DEVICE_ERROR An error occurred attempting to set the new
195 @retval EFI_UNSUPPORTED The NIC does not support changing the network
196 interface's station address.
201 SnpUndi32StationAddress (
202 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
204 IN EFI_MAC_ADDRESS
*New OPTIONAL
212 // Check for invalid parameter combinations.
214 if ((This
== NULL
) ||
215 (!Reset
&& (New
== NULL
))) {
216 return EFI_INVALID_PARAMETER
;
219 Snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
221 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
224 // Return error if the SNP is not initialized.
226 switch (Snp
->Mode
.State
) {
227 case EfiSimpleNetworkInitialized
:
230 case EfiSimpleNetworkStopped
:
231 Status
= EFI_NOT_STARTED
;
235 Status
= EFI_DEVICE_ERROR
;
240 Status
= PxeSetStnAddr (Snp
, NULL
);
242 Status
= PxeSetStnAddr (Snp
, New
);
246 gBS
->RestoreTPL (OldTpl
);