]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/Station_address.c
Patch to remove STATIC modifier. This is on longer recommended by EFI Framework codin...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Station_address.c
1 /** @file
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
7
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.
10
11 Module name:
12 station_address.c
13
14 Abstract:
15
16 Revision history:
17 2000-Feb-17 M(f)J Genesis.
18
19 **/
20
21 #include "Snp.h"
22
23
24 /**
25 this routine calls undi to read the MAC address of the NIC and updates the
26 mode structure with the address.
27
28 @param snp pointer to snp driver structure
29
30
31 **/
32 EFI_STATUS
33 pxe_get_stn_addr (
34 SNP_DRIVER *snp
35 )
36 {
37 PXE_DB_STATION_ADDRESS *db;
38
39 db = snp->db;
40 snp->cdb.OpCode = PXE_OPCODE_STATION_ADDRESS;
41 snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ;
42
43 snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
44 snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
45
46 snp->cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS);
47 snp->cdb.DBaddr = (UINT64)(UINTN) db;
48
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;
53
54 //
55 // Issue UNDI command and check result.
56 //
57 DEBUG ((EFI_D_NET, "\nsnp->undi.station_addr() "));
58
59 (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);
60
61 if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {
62 DEBUG (
63 (EFI_D_ERROR,
64 "\nsnp->undi.station_addr() %xh:%xh\n",
65 snp->cdb.StatFlags,
66 snp->cdb.StatCode)
67 );
68
69 return EFI_DEVICE_ERROR;
70 }
71 //
72 // Set new station address in SNP->Mode structure and return success.
73 //
74 CopyMem (
75 &(snp->mode.CurrentAddress),
76 &db->StationAddr,
77 snp->mode.HwAddressSize
78 );
79
80 CopyMem (
81 &snp->mode.BroadcastAddress,
82 &db->BroadcastAddr,
83 snp->mode.HwAddressSize
84 );
85
86 CopyMem (
87 &snp->mode.PermanentAddress,
88 &db->PermanentAddr,
89 snp->mode.HwAddressSize
90 );
91
92 return EFI_SUCCESS;
93 }
94
95
96 /**
97 this routine calls undi to set a new MAC address for the NIC,
98
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
102 original address.
103
104
105 **/
106 EFI_STATUS
107 pxe_set_stn_addr (
108 SNP_DRIVER *snp,
109 EFI_MAC_ADDRESS *NewMacAddr
110 )
111 {
112 PXE_CPB_STATION_ADDRESS *cpb;
113 PXE_DB_STATION_ADDRESS *db;
114
115 cpb = snp->cpb;
116 db = snp->db;
117 snp->cdb.OpCode = PXE_OPCODE_STATION_ADDRESS;
118
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;
123 } else {
124 snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ;
125 //
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.
128 //
129 CopyMem (&cpb->StationAddr, NewMacAddr, snp->mode.HwAddressSize);
130
131 snp->cdb.CPBsize = sizeof (PXE_CPB_STATION_ADDRESS);
132 snp->cdb.CPBaddr = (UINT64)(UINTN) cpb;
133 }
134
135 snp->cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS);
136 snp->cdb.DBaddr = (UINT64)(UINTN) db;
137
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;
142
143 //
144 // Issue UNDI command and check result.
145 //
146 DEBUG ((EFI_D_NET, "\nsnp->undi.station_addr() "));
147
148 (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);
149
150 if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {
151 DEBUG (
152 (EFI_D_ERROR,
153 "\nsnp->undi.station_addr() %xh:%xh\n",
154 snp->cdb.StatFlags,
155 snp->cdb.StatCode)
156 );
157
158 //
159 // UNDI command failed. Return UNDI status to caller.
160 //
161 return EFI_DEVICE_ERROR;
162 }
163 //
164 // read the changed address and save it in SNP->Mode structure
165 //
166 pxe_get_stn_addr (snp);
167
168 return EFI_SUCCESS;
169 }
170
171
172 /**
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
176
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
180 original address.
181 @param ResetFlag If true, the mac address will change to NIC's original
182 address
183
184
185 **/
186 EFI_STATUS
187 EFIAPI
188 snp_undi32_station_address (
189 IN EFI_SIMPLE_NETWORK_PROTOCOL * this,
190 IN BOOLEAN ResetFlag,
191 IN EFI_MAC_ADDRESS * NewMacAddr OPTIONAL
192 )
193 {
194 SNP_DRIVER *snp;
195 EFI_STATUS Status;
196 EFI_TPL OldTpl;
197
198 //
199 // Check for invalid parameter combinations.
200 //
201 if ((this == NULL) ||
202 (!ResetFlag && (NewMacAddr == NULL))) {
203 return EFI_INVALID_PARAMETER;
204 }
205
206 snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
207
208 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
209
210 //
211 // Return error if the SNP is not initialized.
212 //
213 switch (snp->mode.State) {
214 case EfiSimpleNetworkInitialized:
215 break;
216
217 case EfiSimpleNetworkStopped:
218 Status = EFI_NOT_STARTED;
219 goto ON_EXIT;
220
221 default:
222 Status = EFI_DEVICE_ERROR;
223 goto ON_EXIT;
224 }
225
226 if (ResetFlag) {
227 Status = pxe_set_stn_addr (snp, NULL);
228 } else {
229 Status = pxe_set_stn_addr (snp, NewMacAddr);
230 }
231
232 ON_EXIT:
233 gBS->RestoreTPL (OldTpl);
234
235 return Status;
236 }