]> git.proxmox.com Git - mirror_edk2.git/blame - 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
CommitLineData
878ddf1f 1/*++\r
2Copyright (c) 2006, Intel Corporation \r
3All rights reserved. This program and the accompanying materials \r
4are licensed and made available under the terms and conditions of the BSD License \r
5which accompanies this distribution. The full text of the license may be found at \r
6http://opensource.org/licenses/bsd-license.php \r
7 \r
8THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
9WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
10\r
11Module name:\r
12 station_address.c\r
13\r
14Abstract:\r
15\r
16Revision history:\r
17 2000-Feb-17 M(f)J Genesis.\r
18--*/\r
19\r
20\r
4cbd855e 21#include "Snp.h"\r
878ddf1f 22\r
23EFI_STATUS\r
24pxe_get_stn_addr (\r
25 SNP_DRIVER *snp\r
26 )\r
27/*++\r
28\r
29Routine Description:\r
30 this routine calls undi to read the MAC address of the NIC and updates the\r
31 mode structure with the address.\r
32\r
33Arguments:\r
34 snp - pointer to snp driver structure\r
35\r
36Returns:\r
37 \r
38--*/\r
39{\r
40 PXE_DB_STATION_ADDRESS *db;\r
41\r
42 db = snp->db;\r
43 snp->cdb.OpCode = PXE_OPCODE_STATION_ADDRESS;\r
44 snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ;\r
45\r
46 snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r
47 snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
48\r
49 snp->cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS);\r
50 snp->cdb.DBaddr = (UINT64) (UINTN) db;\r
51\r
52 snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
53 snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
54 snp->cdb.IFnum = snp->if_num;\r
55 snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
56\r
57 //\r
58 // Issue UNDI command and check result.\r
59 //\r
60 DEBUG ((EFI_D_NET, "\nsnp->undi.station_addr() "));\r
61\r
62 (*snp->issue_undi32_command) ((UINT64) (UINTN) &snp->cdb);\r
63\r
64 if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {\r
65 DEBUG (\r
66 (EFI_D_ERROR,\r
67 "\nsnp->undi.station_addr() %xh:%xh\n",\r
68 snp->cdb.StatFlags,\r
69 snp->cdb.StatCode)\r
70 );\r
71\r
72 return EFI_DEVICE_ERROR;\r
73 }\r
74 //\r
75 // Set new station address in SNP->Mode structure and return success.\r
76 //\r
77 CopyMem (\r
78 &(snp->mode.CurrentAddress),\r
79 &db->StationAddr,\r
80 snp->mode.HwAddressSize\r
81 );\r
82\r
83 CopyMem (\r
84 &snp->mode.BroadcastAddress,\r
85 &db->BroadcastAddr,\r
86 snp->mode.HwAddressSize\r
87 );\r
88\r
89 CopyMem (\r
90 &snp->mode.PermanentAddress,\r
91 &db->PermanentAddr,\r
92 snp->mode.HwAddressSize\r
93 );\r
94\r
95 return EFI_SUCCESS;\r
96}\r
97\r
1cc8ee78 98STATIC\r
878ddf1f 99EFI_STATUS\r
100pxe_set_stn_addr (\r
101 SNP_DRIVER *snp,\r
102 EFI_MAC_ADDRESS *NewMacAddr\r
103 )\r
104/*++\r
105\r
106Routine Description:\r
107 this routine calls undi to set a new MAC address for the NIC,\r
108\r
109Arguments:\r
110 snp - pointer to snp driver structure\r
111 NewMacAddr - pointer to a mac address to be set for the nic, if this is NULL\r
112 then this routine resets the mac address to the NIC's original\r
113 address.\r
114\r
115Returns:\r
116\r
117--*/\r
118{\r
119 PXE_CPB_STATION_ADDRESS *cpb;\r
120 PXE_DB_STATION_ADDRESS *db;\r
121\r
122 cpb = snp->cpb;\r
123 db = snp->db;\r
124 snp->cdb.OpCode = PXE_OPCODE_STATION_ADDRESS;\r
125\r
126 if (NewMacAddr == NULL) {\r
127 snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_RESET;\r
128 snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
129 snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r
130 } else {\r
131 snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ;\r
132 //\r
133 // even though the OPFLAGS are set to READ, supplying a new address\r
134 // in the CPB will make undi change the mac address to the new one.\r
135 //\r
136 CopyMem (&cpb->StationAddr, NewMacAddr, snp->mode.HwAddressSize);\r
137\r
138 snp->cdb.CPBsize = sizeof (PXE_CPB_STATION_ADDRESS);\r
139 snp->cdb.CPBaddr = (UINT64) (UINTN) cpb;\r
140 }\r
141\r
142 snp->cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS);\r
143 snp->cdb.DBaddr = (UINT64) (UINTN) db;\r
144\r
145 snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
146 snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
147 snp->cdb.IFnum = snp->if_num;\r
148 snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
149\r
150 //\r
151 // Issue UNDI command and check result.\r
152 //\r
153 DEBUG ((EFI_D_NET, "\nsnp->undi.station_addr() "));\r
154\r
155 (*snp->issue_undi32_command) ((UINT64) (UINTN) &snp->cdb);\r
156\r
157 if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {\r
158 DEBUG (\r
159 (EFI_D_ERROR,\r
160 "\nsnp->undi.station_addr() %xh:%xh\n",\r
161 snp->cdb.StatFlags,\r
162 snp->cdb.StatCode)\r
163 );\r
164\r
165 //\r
166 // UNDI command failed. Return UNDI status to caller.\r
167 //\r
168 return EFI_DEVICE_ERROR;\r
169 }\r
170 //\r
171 // read the changed address and save it in SNP->Mode structure\r
172 //\r
173 pxe_get_stn_addr (snp);\r
174\r
175 return EFI_SUCCESS;\r
176}\r
177\r
178EFI_STATUS\r
179EFIAPI\r
180snp_undi32_station_address (\r
181 IN EFI_SIMPLE_NETWORK_PROTOCOL * this,\r
182 IN BOOLEAN ResetFlag,\r
183 IN EFI_MAC_ADDRESS * NewMacAddr OPTIONAL\r
184 )\r
185/*++\r
186\r
187Routine Description:\r
188 This is the SNP interface routine for changing the NIC's mac address.\r
189 This routine basically retrieves snp structure, checks the SNP state and\r
190 calls the above routines to actually do the work\r
191\r
192Arguments:\r
193 this - context pointer\r
194 NewMacAddr - pointer to a mac address to be set for the nic, if this is NULL\r
195 then this routine resets the mac address to the NIC's original\r
196 address.\r
197 ResetFlag - If true, the mac address will change to NIC's original address\r
198\r
199Returns:\r
200\r
201--*/\r
202{\r
203 SNP_DRIVER *snp;\r
204 EFI_STATUS Status;\r
205\r
206 //\r
207 // Get pointer to SNP driver instance for *this.\r
208 //\r
209 if (this == NULL) {\r
210 return EFI_INVALID_PARAMETER;\r
211 }\r
212\r
213 snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);\r
214\r
215 if (snp == NULL) {\r
216 return EFI_DEVICE_ERROR;\r
217 }\r
218 //\r
219 // Return error if the SNP is not initialized.\r
220 //\r
221 switch (snp->mode.State) {\r
222 case EfiSimpleNetworkInitialized:\r
223 break;\r
224\r
225 case EfiSimpleNetworkStopped:\r
226 return EFI_NOT_STARTED;\r
227\r
228 case EfiSimpleNetworkStarted:\r
229 return EFI_DEVICE_ERROR;\r
230\r
231 default:\r
232 return EFI_DEVICE_ERROR;\r
233 }\r
234 //\r
235 // Check for invalid parameter combinations.\r
236 //\r
237 if (!ResetFlag && NewMacAddr == NULL) {\r
238 return EFI_INVALID_PARAMETER;\r
239 }\r
240\r
241 if (ResetFlag) {\r
242 Status = pxe_set_stn_addr (snp, NULL);\r
243 } else {\r
244 Status = pxe_set_stn_addr (snp, NewMacAddr);\r
245\r
246 }\r
247\r
248 return Status;\r
249}\r