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
101 EFI_MAC_ADDRESS
*NewMacAddr
106 this routine calls undi to set a new MAC address for the NIC,
109 snp - pointer to snp driver structure
110 NewMacAddr - pointer to a mac address to be set for the nic, if this is NULL
111 then this routine resets the mac address to the NIC's original
118 PXE_CPB_STATION_ADDRESS
*cpb
;
119 PXE_DB_STATION_ADDRESS
*db
;
123 snp
->cdb
.OpCode
= PXE_OPCODE_STATION_ADDRESS
;
125 if (NewMacAddr
== NULL
) {
126 snp
->cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_RESET
;
127 snp
->cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
128 snp
->cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
130 snp
->cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_READ
;
132 // even though the OPFLAGS are set to READ, supplying a new address
133 // in the CPB will make undi change the mac address to the new one.
135 CopyMem (&cpb
->StationAddr
, NewMacAddr
, snp
->mode
.HwAddressSize
);
137 snp
->cdb
.CPBsize
= sizeof (PXE_CPB_STATION_ADDRESS
);
138 snp
->cdb
.CPBaddr
= (UINT64
) (UINTN
) cpb
;
141 snp
->cdb
.DBsize
= sizeof (PXE_DB_STATION_ADDRESS
);
142 snp
->cdb
.DBaddr
= (UINT64
) (UINTN
) db
;
144 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
145 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
146 snp
->cdb
.IFnum
= snp
->if_num
;
147 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
150 // Issue UNDI command and check result.
152 DEBUG ((EFI_D_NET
, "\nsnp->undi.station_addr() "));
154 (*snp
->issue_undi32_command
) ((UINT64
) (UINTN
) &snp
->cdb
);
156 if (snp
->cdb
.StatCode
!= PXE_STATCODE_SUCCESS
) {
159 "\nsnp->undi.station_addr() %xh:%xh\n",
165 // UNDI command failed. Return UNDI status to caller.
167 return EFI_DEVICE_ERROR
;
170 // read the changed address and save it in SNP->Mode structure
172 pxe_get_stn_addr (snp
);
179 snp_undi32_station_address (
180 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
181 IN BOOLEAN ResetFlag
,
182 IN EFI_MAC_ADDRESS
* NewMacAddr OPTIONAL
187 This is the SNP interface routine for changing the NIC's mac address.
188 This routine basically retrieves snp structure, checks the SNP state and
189 calls the above routines to actually do the work
192 this - context pointer
193 NewMacAddr - pointer to a mac address to be set for the nic, if this is NULL
194 then this routine resets the mac address to the NIC's original
196 ResetFlag - If true, the mac address will change to NIC's original address
206 // Get pointer to SNP driver instance for *this.
209 return EFI_INVALID_PARAMETER
;
212 snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
215 return EFI_DEVICE_ERROR
;
218 // Return error if the SNP is not initialized.
220 switch (snp
->mode
.State
) {
221 case EfiSimpleNetworkInitialized
:
224 case EfiSimpleNetworkStopped
:
225 return EFI_NOT_STARTED
;
227 case EfiSimpleNetworkStarted
:
228 return EFI_DEVICE_ERROR
;
231 return EFI_DEVICE_ERROR
;
234 // Check for invalid parameter combinations.
236 if (!ResetFlag
&& NewMacAddr
== NULL
) {
237 return EFI_INVALID_PARAMETER
;
241 Status
= pxe_set_stn_addr (snp
, NULL
);
243 Status
= pxe_set_stn_addr (snp
, NewMacAddr
);