]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/Network/Snp32_64/Dxe/station_address.c
Partially make EdkModulePkg pass intel IPF compiler with /W4 /WX switched on.
[mirror_edk2.git] / EdkModulePkg / Universal / Network / Snp32_64 / Dxe / station_address.c
1 /*++
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
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 EFI_STATUS
24 pxe_get_stn_addr (
25 SNP_DRIVER *snp
26 )
27 /*++
28
29 Routine Description:
30 this routine calls undi to read the MAC address of the NIC and updates the
31 mode structure with the address.
32
33 Arguments:
34 snp - pointer to snp driver structure
35
36 Returns:
37
38 --*/
39 {
40 PXE_DB_STATION_ADDRESS *db;
41
42 db = snp->db;
43 snp->cdb.OpCode = PXE_OPCODE_STATION_ADDRESS;
44 snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ;
45
46 snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
47 snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
48
49 snp->cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS);
50 snp->cdb.DBaddr = (UINT64) (UINTN) db;
51
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;
56
57 //
58 // Issue UNDI command and check result.
59 //
60 DEBUG ((EFI_D_NET, "\nsnp->undi.station_addr() "));
61
62 (*snp->issue_undi32_command) ((UINT64) (UINTN) &snp->cdb);
63
64 if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {
65 DEBUG (
66 (EFI_D_ERROR,
67 "\nsnp->undi.station_addr() %xh:%xh\n",
68 snp->cdb.StatFlags,
69 snp->cdb.StatCode)
70 );
71
72 return EFI_DEVICE_ERROR;
73 }
74 //
75 // Set new station address in SNP->Mode structure and return success.
76 //
77 CopyMem (
78 &(snp->mode.CurrentAddress),
79 &db->StationAddr,
80 snp->mode.HwAddressSize
81 );
82
83 CopyMem (
84 &snp->mode.BroadcastAddress,
85 &db->BroadcastAddr,
86 snp->mode.HwAddressSize
87 );
88
89 CopyMem (
90 &snp->mode.PermanentAddress,
91 &db->PermanentAddr,
92 snp->mode.HwAddressSize
93 );
94
95 return EFI_SUCCESS;
96 }
97
98 STATIC
99 EFI_STATUS
100 pxe_set_stn_addr (
101 SNP_DRIVER *snp,
102 EFI_MAC_ADDRESS *NewMacAddr
103 )
104 /*++
105
106 Routine Description:
107 this routine calls undi to set a new MAC address for the NIC,
108
109 Arguments:
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
113 address.
114
115 Returns:
116
117 --*/
118 {
119 PXE_CPB_STATION_ADDRESS *cpb;
120 PXE_DB_STATION_ADDRESS *db;
121
122 cpb = snp->cpb;
123 db = snp->db;
124 snp->cdb.OpCode = PXE_OPCODE_STATION_ADDRESS;
125
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;
130 } else {
131 snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ;
132 //
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.
135 //
136 CopyMem (&cpb->StationAddr, NewMacAddr, snp->mode.HwAddressSize);
137
138 snp->cdb.CPBsize = sizeof (PXE_CPB_STATION_ADDRESS);
139 snp->cdb.CPBaddr = (UINT64) (UINTN) cpb;
140 }
141
142 snp->cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS);
143 snp->cdb.DBaddr = (UINT64) (UINTN) db;
144
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;
149
150 //
151 // Issue UNDI command and check result.
152 //
153 DEBUG ((EFI_D_NET, "\nsnp->undi.station_addr() "));
154
155 (*snp->issue_undi32_command) ((UINT64) (UINTN) &snp->cdb);
156
157 if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {
158 DEBUG (
159 (EFI_D_ERROR,
160 "\nsnp->undi.station_addr() %xh:%xh\n",
161 snp->cdb.StatFlags,
162 snp->cdb.StatCode)
163 );
164
165 //
166 // UNDI command failed. Return UNDI status to caller.
167 //
168 return EFI_DEVICE_ERROR;
169 }
170 //
171 // read the changed address and save it in SNP->Mode structure
172 //
173 pxe_get_stn_addr (snp);
174
175 return EFI_SUCCESS;
176 }
177
178 EFI_STATUS
179 EFIAPI
180 snp_undi32_station_address (
181 IN EFI_SIMPLE_NETWORK_PROTOCOL * this,
182 IN BOOLEAN ResetFlag,
183 IN EFI_MAC_ADDRESS * NewMacAddr OPTIONAL
184 )
185 /*++
186
187 Routine Description:
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
191
192 Arguments:
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
196 address.
197 ResetFlag - If true, the mac address will change to NIC's original address
198
199 Returns:
200
201 --*/
202 {
203 SNP_DRIVER *snp;
204 EFI_STATUS Status;
205
206 //
207 // Get pointer to SNP driver instance for *this.
208 //
209 if (this == NULL) {
210 return EFI_INVALID_PARAMETER;
211 }
212
213 snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
214
215 if (snp == NULL) {
216 return EFI_DEVICE_ERROR;
217 }
218 //
219 // Return error if the SNP is not initialized.
220 //
221 switch (snp->mode.State) {
222 case EfiSimpleNetworkInitialized:
223 break;
224
225 case EfiSimpleNetworkStopped:
226 return EFI_NOT_STARTED;
227
228 case EfiSimpleNetworkStarted:
229 return EFI_DEVICE_ERROR;
230
231 default:
232 return EFI_DEVICE_ERROR;
233 }
234 //
235 // Check for invalid parameter combinations.
236 //
237 if (!ResetFlag && NewMacAddr == NULL) {
238 return EFI_INVALID_PARAMETER;
239 }
240
241 if (ResetFlag) {
242 Status = pxe_set_stn_addr (snp, NULL);
243 } else {
244 Status = pxe_set_stn_addr (snp, NewMacAddr);
245
246 }
247
248 return Status;
249 }