2 Implementation of reading the MAC address of a network adapter.
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 Call UNDI to read the MAC address of the NIC and update the mode structure
15 @param Snp Pointer to snp driver structure.
17 @retval EFI_SUCCESS The MAC address of the NIC is read successfully.
18 @retval EFI_DEVICE_ERROR Failed to read the MAC address of the NIC.
26 PXE_DB_STATION_ADDRESS
*Db
;
29 Snp
->Cdb
.OpCode
= PXE_OPCODE_STATION_ADDRESS
;
30 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_READ
;
32 Snp
->Cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
33 Snp
->Cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
35 Snp
->Cdb
.DBsize
= (UINT16
)sizeof (PXE_DB_STATION_ADDRESS
);
36 Snp
->Cdb
.DBaddr
= (UINT64
)(UINTN
)Db
;
38 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
39 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
40 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
41 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
44 // Issue UNDI command and check result.
46 DEBUG ((DEBUG_NET
, "\nsnp->undi.station_addr() "));
48 (*Snp
->IssueUndi32Command
)((UINT64
)(UINTN
)&Snp
->Cdb
);
50 if (Snp
->Cdb
.StatCode
!= PXE_STATCODE_SUCCESS
) {
53 "\nsnp->undi.station_addr() %xh:%xh\n",
58 return EFI_DEVICE_ERROR
;
62 // Set new station address in SNP->Mode structure and return success.
65 &(Snp
->Mode
.CurrentAddress
),
67 Snp
->Mode
.HwAddressSize
71 &Snp
->Mode
.BroadcastAddress
,
73 Snp
->Mode
.HwAddressSize
77 &Snp
->Mode
.PermanentAddress
,
79 Snp
->Mode
.HwAddressSize
86 Call UNDI to set a new MAC address for the NIC.
88 @param Snp Pointer to Snp driver structure.
89 @param NewMacAddr Pointer to a MAC address to be set for the NIC, if this is
90 NULL then this routine resets the mac address to the NIC's
98 EFI_MAC_ADDRESS
*NewMacAddr
101 PXE_CPB_STATION_ADDRESS
*Cpb
;
102 PXE_DB_STATION_ADDRESS
*Db
;
106 Snp
->Cdb
.OpCode
= PXE_OPCODE_STATION_ADDRESS
;
108 if (NewMacAddr
== NULL
) {
109 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_RESET
;
110 Snp
->Cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
111 Snp
->Cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
113 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_WRITE
;
115 // Supplying a new address in the CPB will make undi change the mac address to the new one.
117 CopyMem (&Cpb
->StationAddr
, NewMacAddr
, Snp
->Mode
.HwAddressSize
);
119 Snp
->Cdb
.CPBsize
= (UINT16
)sizeof (PXE_CPB_STATION_ADDRESS
);
120 Snp
->Cdb
.CPBaddr
= (UINT64
)(UINTN
)Cpb
;
123 Snp
->Cdb
.DBsize
= (UINT16
)sizeof (PXE_DB_STATION_ADDRESS
);
124 Snp
->Cdb
.DBaddr
= (UINT64
)(UINTN
)Db
;
126 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
127 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
128 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
129 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
132 // Issue UNDI command and check result.
134 DEBUG ((DEBUG_NET
, "\nsnp->undi.station_addr() "));
136 (*Snp
->IssueUndi32Command
)((UINT64
)(UINTN
)&Snp
->Cdb
);
138 if (Snp
->Cdb
.StatCode
!= PXE_STATCODE_SUCCESS
) {
141 "\nsnp->undi.station_addr() %xh:%xh\n",
147 // UNDI command failed. Return UNDI status to caller.
149 return EFI_DEVICE_ERROR
;
153 // read the changed address and save it in SNP->Mode structure
161 Modifies or resets the current station address, if supported.
163 This function modifies or resets the current station address of a network
164 interface, if supported. If Reset is TRUE, then the current station address is
165 set to the network interface's permanent address. If Reset is FALSE, and the
166 network interface allows its station address to be modified, then the current
167 station address is changed to the address specified by New. If the network
168 interface does not allow its station address to be modified, then
169 EFI_INVALID_PARAMETER will be returned. If the station address is successfully
170 updated on the network interface, EFI_SUCCESS will be returned. If the driver
171 has not been initialized, EFI_DEVICE_ERROR will be returned.
173 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
174 @param Reset Flag used to reset the station address to the network interface's
176 @param New New station address to be used for the network interface.
179 @retval EFI_SUCCESS The network interface's station address was updated.
180 @retval EFI_NOT_STARTED The Simple Network Protocol interface has not been
181 started by calling Start().
182 @retval EFI_INVALID_PARAMETER The New station address was not accepted by the NIC.
183 @retval EFI_INVALID_PARAMETER Reset is FALSE and New is NULL.
184 @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not
185 been initialized by calling Initialize().
186 @retval EFI_DEVICE_ERROR An error occurred attempting to set the new
188 @retval EFI_UNSUPPORTED The NIC does not support changing the network
189 interface's station address.
194 SnpUndi32StationAddress (
195 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
197 IN EFI_MAC_ADDRESS
*New OPTIONAL
205 // Check for invalid parameter combinations.
207 if ((This
== NULL
) ||
208 (!Reset
&& (New
== NULL
)))
210 return EFI_INVALID_PARAMETER
;
213 Snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
215 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
218 // Return error if the SNP is not initialized.
220 switch (Snp
->Mode
.State
) {
221 case EfiSimpleNetworkInitialized
:
224 case EfiSimpleNetworkStopped
:
225 Status
= EFI_NOT_STARTED
;
229 Status
= EFI_DEVICE_ERROR
;
234 Status
= PxeSetStnAddr (Snp
, NULL
);
236 Status
= PxeSetStnAddr (Snp
, New
);
240 gBS
->RestoreTPL (OldTpl
);