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
109 EFI_MAC_ADDRESS
*NewMacAddr
112 PXE_CPB_STATION_ADDRESS
*cpb
;
113 PXE_DB_STATION_ADDRESS
*db
;
117 snp
->cdb
.OpCode
= PXE_OPCODE_STATION_ADDRESS
;
119 if (NewMacAddr
== NULL
) {
120 snp
->cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_RESET
;
121 snp
->cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
122 snp
->cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
124 snp
->cdb
.OpFlags
= PXE_OPFLAGS_STATION_ADDRESS_READ
;
126 // even though the OPFLAGS are set to READ, supplying a new address
127 // in the CPB will make undi change the mac address to the new one.
129 CopyMem (&cpb
->StationAddr
, NewMacAddr
, snp
->mode
.HwAddressSize
);
131 snp
->cdb
.CPBsize
= sizeof (PXE_CPB_STATION_ADDRESS
);
132 snp
->cdb
.CPBaddr
= (UINT64
)(UINTN
) cpb
;
135 snp
->cdb
.DBsize
= sizeof (PXE_DB_STATION_ADDRESS
);
136 snp
->cdb
.DBaddr
= (UINT64
)(UINTN
) db
;
138 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
139 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
140 snp
->cdb
.IFnum
= snp
->if_num
;
141 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
144 // Issue UNDI command and check result.
146 DEBUG ((EFI_D_NET
, "\nsnp->undi.station_addr() "));
148 (*snp
->issue_undi32_command
) ((UINT64
)(UINTN
) &snp
->cdb
);
150 if (snp
->cdb
.StatCode
!= PXE_STATCODE_SUCCESS
) {
153 "\nsnp->undi.station_addr() %xh:%xh\n",
159 // UNDI command failed. Return UNDI status to caller.
161 return EFI_DEVICE_ERROR
;
164 // read the changed address and save it in SNP->Mode structure
166 pxe_get_stn_addr (snp
);
173 This is the SNP interface routine for changing the NIC's mac address.
174 This routine basically retrieves snp structure, checks the SNP state and
175 calls the above routines to actually do the work
177 @param this context pointer
178 @param NewMacAddr pointer to a mac address to be set for the nic, if this is
179 NULL then this routine resets the mac address to the NIC's
181 @param ResetFlag If true, the mac address will change to NIC's original
188 snp_undi32_station_address (
189 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
190 IN BOOLEAN ResetFlag
,
191 IN EFI_MAC_ADDRESS
* NewMacAddr OPTIONAL
199 // Check for invalid parameter combinations.
201 if ((this == NULL
) ||
202 (!ResetFlag
&& (NewMacAddr
== NULL
))) {
203 return EFI_INVALID_PARAMETER
;
206 snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
208 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
211 // Return error if the SNP is not initialized.
213 switch (snp
->mode
.State
) {
214 case EfiSimpleNetworkInitialized
:
217 case EfiSimpleNetworkStopped
:
218 Status
= EFI_NOT_STARTED
;
222 Status
= EFI_DEVICE_ERROR
;
227 Status
= pxe_set_stn_addr (snp
, NULL
);
229 Status
= pxe_set_stn_addr (snp
, NewMacAddr
);
233 gBS
->RestoreTPL (OldTpl
);