]>
Commit | Line | Data |
---|---|---|
8a67d61d | 1 | /** @file\r |
2 | Copyright (c) 2004 - 2007, 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 | \r | |
24 | /**\r | |
25 | this routine calls undi to read the MAC address of the NIC and updates the\r | |
26 | mode structure with the address.\r | |
27 | \r | |
28 | @param snp pointer to snp driver structure\r | |
29 | \r | |
30 | \r | |
31 | **/\r | |
32 | EFI_STATUS\r | |
33 | pxe_get_stn_addr (\r | |
34 | SNP_DRIVER *snp\r | |
35 | )\r | |
36 | {\r | |
37 | PXE_DB_STATION_ADDRESS *db;\r | |
38 | \r | |
39 | db = snp->db;\r | |
40 | snp->cdb.OpCode = PXE_OPCODE_STATION_ADDRESS;\r | |
41 | snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ;\r | |
42 | \r | |
43 | snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r | |
44 | snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r | |
45 | \r | |
46 | snp->cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS);\r | |
47 | snp->cdb.DBaddr = (UINT64)(UINTN) db;\r | |
48 | \r | |
49 | snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r | |
50 | snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r | |
51 | snp->cdb.IFnum = snp->if_num;\r | |
52 | snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r | |
53 | \r | |
54 | //\r | |
55 | // Issue UNDI command and check result.\r | |
56 | //\r | |
57 | DEBUG ((EFI_D_NET, "\nsnp->undi.station_addr() "));\r | |
58 | \r | |
59 | (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);\r | |
60 | \r | |
61 | if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {\r | |
62 | DEBUG (\r | |
63 | (EFI_D_ERROR,\r | |
64 | "\nsnp->undi.station_addr() %xh:%xh\n",\r | |
65 | snp->cdb.StatFlags,\r | |
66 | snp->cdb.StatCode)\r | |
67 | );\r | |
68 | \r | |
69 | return EFI_DEVICE_ERROR;\r | |
70 | }\r | |
71 | //\r | |
72 | // Set new station address in SNP->Mode structure and return success.\r | |
73 | //\r | |
74 | CopyMem (\r | |
75 | &(snp->mode.CurrentAddress),\r | |
76 | &db->StationAddr,\r | |
77 | snp->mode.HwAddressSize\r | |
78 | );\r | |
79 | \r | |
80 | CopyMem (\r | |
81 | &snp->mode.BroadcastAddress,\r | |
82 | &db->BroadcastAddr,\r | |
83 | snp->mode.HwAddressSize\r | |
84 | );\r | |
85 | \r | |
86 | CopyMem (\r | |
87 | &snp->mode.PermanentAddress,\r | |
88 | &db->PermanentAddr,\r | |
89 | snp->mode.HwAddressSize\r | |
90 | );\r | |
91 | \r | |
92 | return EFI_SUCCESS;\r | |
93 | }\r | |
94 | \r | |
95 | \r | |
96 | /**\r | |
97 | this routine calls undi to set a new MAC address for the NIC,\r | |
98 | \r | |
99 | @param snp pointer to snp driver structure\r | |
100 | @param NewMacAddr pointer to a mac address to be set for the nic, if this is\r | |
101 | NULL then this routine resets the mac address to the NIC's\r | |
102 | original address.\r | |
103 | \r | |
104 | \r | |
105 | **/\r | |
106 | STATIC\r | |
107 | EFI_STATUS\r | |
108 | pxe_set_stn_addr (\r | |
109 | SNP_DRIVER *snp,\r | |
110 | EFI_MAC_ADDRESS *NewMacAddr\r | |
111 | )\r | |
112 | {\r | |
113 | PXE_CPB_STATION_ADDRESS *cpb;\r | |
114 | PXE_DB_STATION_ADDRESS *db;\r | |
115 | \r | |
116 | cpb = snp->cpb;\r | |
117 | db = snp->db;\r | |
118 | snp->cdb.OpCode = PXE_OPCODE_STATION_ADDRESS;\r | |
119 | \r | |
120 | if (NewMacAddr == NULL) {\r | |
121 | snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_RESET;\r | |
122 | snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r | |
123 | snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r | |
124 | } else {\r | |
125 | snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ;\r | |
126 | //\r | |
127 | // even though the OPFLAGS are set to READ, supplying a new address\r | |
128 | // in the CPB will make undi change the mac address to the new one.\r | |
129 | //\r | |
130 | CopyMem (&cpb->StationAddr, NewMacAddr, snp->mode.HwAddressSize);\r | |
131 | \r | |
132 | snp->cdb.CPBsize = sizeof (PXE_CPB_STATION_ADDRESS);\r | |
133 | snp->cdb.CPBaddr = (UINT64)(UINTN) cpb;\r | |
134 | }\r | |
135 | \r | |
136 | snp->cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS);\r | |
137 | snp->cdb.DBaddr = (UINT64)(UINTN) db;\r | |
138 | \r | |
139 | snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r | |
140 | snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r | |
141 | snp->cdb.IFnum = snp->if_num;\r | |
142 | snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r | |
143 | \r | |
144 | //\r | |
145 | // Issue UNDI command and check result.\r | |
146 | //\r | |
147 | DEBUG ((EFI_D_NET, "\nsnp->undi.station_addr() "));\r | |
148 | \r | |
149 | (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);\r | |
150 | \r | |
151 | if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {\r | |
152 | DEBUG (\r | |
153 | (EFI_D_ERROR,\r | |
154 | "\nsnp->undi.station_addr() %xh:%xh\n",\r | |
155 | snp->cdb.StatFlags,\r | |
156 | snp->cdb.StatCode)\r | |
157 | );\r | |
158 | \r | |
159 | //\r | |
160 | // UNDI command failed. Return UNDI status to caller.\r | |
161 | //\r | |
162 | return EFI_DEVICE_ERROR;\r | |
163 | }\r | |
164 | //\r | |
165 | // read the changed address and save it in SNP->Mode structure\r | |
166 | //\r | |
167 | pxe_get_stn_addr (snp);\r | |
168 | \r | |
169 | return EFI_SUCCESS;\r | |
170 | }\r | |
171 | \r | |
172 | \r | |
173 | /**\r | |
174 | This is the SNP interface routine for changing the NIC's mac address.\r | |
175 | This routine basically retrieves snp structure, checks the SNP state and\r | |
176 | calls the above routines to actually do the work\r | |
177 | \r | |
178 | @param this context pointer\r | |
179 | @param NewMacAddr pointer to a mac address to be set for the nic, if this is\r | |
180 | NULL then this routine resets the mac address to the NIC's\r | |
181 | original address.\r | |
182 | @param ResetFlag If true, the mac address will change to NIC's original\r | |
183 | address\r | |
184 | \r | |
185 | \r | |
186 | **/\r | |
187 | EFI_STATUS\r | |
188 | EFIAPI\r | |
189 | snp_undi32_station_address (\r | |
190 | IN EFI_SIMPLE_NETWORK_PROTOCOL * this,\r | |
191 | IN BOOLEAN ResetFlag,\r | |
192 | IN EFI_MAC_ADDRESS * NewMacAddr OPTIONAL\r | |
193 | )\r | |
194 | {\r | |
195 | SNP_DRIVER *snp;\r | |
196 | EFI_STATUS Status;\r | |
197 | EFI_TPL OldTpl;\r | |
198 | \r | |
199 | //\r | |
200 | // Check for invalid parameter combinations.\r | |
201 | //\r | |
202 | if ((this == NULL) ||\r | |
203 | (!ResetFlag && (NewMacAddr == NULL))) {\r | |
204 | return EFI_INVALID_PARAMETER;\r | |
205 | }\r | |
206 | \r | |
207 | snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);\r | |
208 | \r | |
209 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
210 | \r | |
211 | //\r | |
212 | // Return error if the SNP is not initialized.\r | |
213 | //\r | |
214 | switch (snp->mode.State) {\r | |
215 | case EfiSimpleNetworkInitialized:\r | |
216 | break;\r | |
217 | \r | |
218 | case EfiSimpleNetworkStopped:\r | |
219 | Status = EFI_NOT_STARTED;\r | |
220 | goto ON_EXIT;\r | |
221 | \r | |
222 | default:\r | |
223 | Status = EFI_DEVICE_ERROR;\r | |
224 | goto ON_EXIT;\r | |
225 | }\r | |
226 | \r | |
227 | if (ResetFlag) {\r | |
228 | Status = pxe_set_stn_addr (snp, NULL);\r | |
229 | } else {\r | |
230 | Status = pxe_set_stn_addr (snp, NewMacAddr);\r | |
231 | }\r | |
232 | \r | |
233 | ON_EXIT:\r | |
234 | gBS->RestoreTPL (OldTpl);\r | |
235 | \r | |
236 | return Status;\r | |
237 | }\r |