2 Copyright (c) 2006, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 2000-Feb-17 M(f)J Genesis.
30 this routine calls undi to read the MAC address of the NIC and updates the
31 mode structure with the address.
34 snp - pointer to snp driver structure
40 PXE_DB_STATION_ADDRESS
*db
;
43 snp
->cdb
.OpCode
= PXE_OPCODE_STATION_ADDRESS
;
44 snp
->cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_READ
;
46 snp
->cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
47 snp
->cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
49 snp
->cdb
.DBsize
= sizeof (PXE_DB_STATION_ADDRESS
);
50 snp
->cdb
.DBaddr
= (UINT64
) (UINTN
) db
;
52 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
53 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
54 snp
->cdb
.IFnum
= snp
->if_num
;
55 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
58 // Issue UNDI command and check result.
60 DEBUG ((EFI_D_NET
, "\nsnp->undi.station_addr() "));
62 (*snp
->issue_undi32_command
) ((UINT64
) (UINTN
) &snp
->cdb
);
64 if (snp
->cdb
.StatCode
!= PXE_STATCODE_SUCCESS
) {
67 "\nsnp->undi.station_addr() %xh:%xh\n",
72 return EFI_DEVICE_ERROR
;
75 // Set new station address in SNP->Mode structure and return success.
78 &(snp
->mode
.CurrentAddress
),
80 snp
->mode
.HwAddressSize
84 &snp
->mode
.BroadcastAddress
,
86 snp
->mode
.HwAddressSize
90 &snp
->mode
.PermanentAddress
,
92 snp
->mode
.HwAddressSize
102 EFI_MAC_ADDRESS
*NewMacAddr
107 this routine calls undi to set a new MAC address for the NIC,
110 snp - pointer to snp driver structure
111 NewMacAddr - pointer to a mac address to be set for the nic, if this is NULL
112 then this routine resets the mac address to the NIC's original
119 PXE_CPB_STATION_ADDRESS
*cpb
;
120 PXE_DB_STATION_ADDRESS
*db
;
124 snp
->cdb
.OpCode
= PXE_OPCODE_STATION_ADDRESS
;
126 if (NewMacAddr
== NULL
) {
127 snp
->cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_RESET
;
128 snp
->cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
129 snp
->cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
131 snp
->cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_READ
;
133 // even though the OPFLAGS are set to READ, supplying a new address
134 // in the CPB will make undi change the mac address to the new one.
136 CopyMem (&cpb
->StationAddr
, NewMacAddr
, snp
->mode
.HwAddressSize
);
138 snp
->cdb
.CPBsize
= sizeof (PXE_CPB_STATION_ADDRESS
);
139 snp
->cdb
.CPBaddr
= (UINT64
) (UINTN
) cpb
;
142 snp
->cdb
.DBsize
= sizeof (PXE_DB_STATION_ADDRESS
);
143 snp
->cdb
.DBaddr
= (UINT64
) (UINTN
) db
;
145 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
146 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
147 snp
->cdb
.IFnum
= snp
->if_num
;
148 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
151 // Issue UNDI command and check result.
153 DEBUG ((EFI_D_NET
, "\nsnp->undi.station_addr() "));
155 (*snp
->issue_undi32_command
) ((UINT64
) (UINTN
) &snp
->cdb
);
157 if (snp
->cdb
.StatCode
!= PXE_STATCODE_SUCCESS
) {
160 "\nsnp->undi.station_addr() %xh:%xh\n",
166 // UNDI command failed. Return UNDI status to caller.
168 return EFI_DEVICE_ERROR
;
171 // read the changed address and save it in SNP->Mode structure
173 pxe_get_stn_addr (snp
);
180 snp_undi32_station_address (
181 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
182 IN BOOLEAN ResetFlag
,
183 IN EFI_MAC_ADDRESS
* NewMacAddr OPTIONAL
188 This is the SNP interface routine for changing the NIC's mac address.
189 This routine basically retrieves snp structure, checks the SNP state and
190 calls the above routines to actually do the work
193 this - context pointer
194 NewMacAddr - pointer to a mac address to be set for the nic, if this is NULL
195 then this routine resets the mac address to the NIC's original
197 ResetFlag - If true, the mac address will change to NIC's original address
207 // Get pointer to SNP driver instance for *this.
210 return EFI_INVALID_PARAMETER
;
213 snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
216 return EFI_DEVICE_ERROR
;
219 // Return error if the SNP is not initialized.
221 switch (snp
->mode
.State
) {
222 case EfiSimpleNetworkInitialized
:
225 case EfiSimpleNetworkStopped
:
226 return EFI_NOT_STARTED
;
228 case EfiSimpleNetworkStarted
:
229 return EFI_DEVICE_ERROR
;
232 return EFI_DEVICE_ERROR
;
235 // Check for invalid parameter combinations.
237 if (!ResetFlag
&& NewMacAddr
== NULL
) {
238 return EFI_INVALID_PARAMETER
;
242 Status
= pxe_set_stn_addr (snp
, NULL
);
244 Status
= pxe_set_stn_addr (snp
, NewMacAddr
);