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