2 Copyright (c) 2004 - 2007, 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.
25 this routine calls undi to read the MAC address of the NIC and updates the
26 mode structure with the address.
28 @param snp pointer to snp driver structure
37 PXE_DB_STATION_ADDRESS
*db
;
40 snp
->cdb
.OpCode
= PXE_OPCODE_STATION_ADDRESS
;
41 snp
->cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_READ
;
43 snp
->cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
44 snp
->cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
46 snp
->cdb
.DBsize
= sizeof (PXE_DB_STATION_ADDRESS
);
47 snp
->cdb
.DBaddr
= (UINT64
)(UINTN
) db
;
49 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
50 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
51 snp
->cdb
.IFnum
= snp
->if_num
;
52 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
55 // Issue UNDI command and check result.
57 DEBUG ((EFI_D_NET
, "\nsnp->undi.station_addr() "));
59 (*snp
->issue_undi32_command
) ((UINT64
)(UINTN
) &snp
->cdb
);
61 if (snp
->cdb
.StatCode
!= PXE_STATCODE_SUCCESS
) {
64 "\nsnp->undi.station_addr() %xh:%xh\n",
69 return EFI_DEVICE_ERROR
;
72 // Set new station address in SNP->Mode structure and return success.
75 &(snp
->mode
.CurrentAddress
),
77 snp
->mode
.HwAddressSize
81 &snp
->mode
.BroadcastAddress
,
83 snp
->mode
.HwAddressSize
87 &snp
->mode
.PermanentAddress
,
89 snp
->mode
.HwAddressSize
97 this routine calls undi to set a new MAC address for the NIC,
99 @param snp pointer to snp driver structure
100 @param NewMacAddr pointer to a mac address to be set for the nic, if this is
101 NULL then this routine resets the mac address to the NIC's
110 EFI_MAC_ADDRESS
*NewMacAddr
113 PXE_CPB_STATION_ADDRESS
*cpb
;
114 PXE_DB_STATION_ADDRESS
*db
;
118 snp
->cdb
.OpCode
= PXE_OPCODE_STATION_ADDRESS
;
120 if (NewMacAddr
== NULL
) {
121 snp
->cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_RESET
;
122 snp
->cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
123 snp
->cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
125 snp
->cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_READ
;
127 // even though the OPFLAGS are set to READ, supplying a new address
128 // in the CPB will make undi change the mac address to the new one.
130 CopyMem (&cpb
->StationAddr
, NewMacAddr
, snp
->mode
.HwAddressSize
);
132 snp
->cdb
.CPBsize
= sizeof (PXE_CPB_STATION_ADDRESS
);
133 snp
->cdb
.CPBaddr
= (UINT64
)(UINTN
) cpb
;
136 snp
->cdb
.DBsize
= sizeof (PXE_DB_STATION_ADDRESS
);
137 snp
->cdb
.DBaddr
= (UINT64
)(UINTN
) db
;
139 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
140 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
141 snp
->cdb
.IFnum
= snp
->if_num
;
142 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
145 // Issue UNDI command and check result.
147 DEBUG ((EFI_D_NET
, "\nsnp->undi.station_addr() "));
149 (*snp
->issue_undi32_command
) ((UINT64
)(UINTN
) &snp
->cdb
);
151 if (snp
->cdb
.StatCode
!= PXE_STATCODE_SUCCESS
) {
154 "\nsnp->undi.station_addr() %xh:%xh\n",
160 // UNDI command failed. Return UNDI status to caller.
162 return EFI_DEVICE_ERROR
;
165 // read the changed address and save it in SNP->Mode structure
167 pxe_get_stn_addr (snp
);
174 This is the SNP interface routine for changing the NIC's mac address.
175 This routine basically retrieves snp structure, checks the SNP state and
176 calls the above routines to actually do the work
178 @param this context pointer
179 @param NewMacAddr pointer to a mac address to be set for the nic, if this is
180 NULL then this routine resets the mac address to the NIC's
182 @param ResetFlag If true, the mac address will change to NIC's original
189 snp_undi32_station_address (
190 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
191 IN BOOLEAN ResetFlag
,
192 IN EFI_MAC_ADDRESS
* NewMacAddr OPTIONAL
200 // Check for invalid parameter combinations.
202 if ((this == NULL
) ||
203 (!ResetFlag
&& (NewMacAddr
== NULL
))) {
204 return EFI_INVALID_PARAMETER
;
207 snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
209 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
212 // Return error if the SNP is not initialized.
214 switch (snp
->mode
.State
) {
215 case EfiSimpleNetworkInitialized
:
218 case EfiSimpleNetworkStopped
:
219 Status
= EFI_NOT_STARTED
;
223 Status
= EFI_DEVICE_ERROR
;
228 Status
= pxe_set_stn_addr (snp
, NULL
);
230 Status
= pxe_set_stn_addr (snp
, NewMacAddr
);
234 gBS
->RestoreTPL (OldTpl
);