2735e5d0 |
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 |
2735e5d0 |
106 | EFI_STATUS\r |
107 | pxe_set_stn_addr (\r |
108 | SNP_DRIVER *snp,\r |
109 | EFI_MAC_ADDRESS *NewMacAddr\r |
110 | )\r |
111 | {\r |
112 | PXE_CPB_STATION_ADDRESS *cpb;\r |
113 | PXE_DB_STATION_ADDRESS *db;\r |
114 | \r |
115 | cpb = snp->cpb;\r |
116 | db = snp->db;\r |
117 | snp->cdb.OpCode = PXE_OPCODE_STATION_ADDRESS;\r |
118 | \r |
119 | if (NewMacAddr == NULL) {\r |
120 | snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_RESET;\r |
121 | snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r |
122 | snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r |
123 | } else {\r |
124 | snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ;\r |
125 | //\r |
126 | // even though the OPFLAGS are set to READ, supplying a new address\r |
127 | // in the CPB will make undi change the mac address to the new one.\r |
128 | //\r |
129 | CopyMem (&cpb->StationAddr, NewMacAddr, snp->mode.HwAddressSize);\r |
130 | \r |
131 | snp->cdb.CPBsize = sizeof (PXE_CPB_STATION_ADDRESS);\r |
132 | snp->cdb.CPBaddr = (UINT64)(UINTN) cpb;\r |
133 | }\r |
134 | \r |
135 | snp->cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS);\r |
136 | snp->cdb.DBaddr = (UINT64)(UINTN) db;\r |
137 | \r |
138 | snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r |
139 | snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r |
140 | snp->cdb.IFnum = snp->if_num;\r |
141 | snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r |
142 | \r |
143 | //\r |
144 | // Issue UNDI command and check result.\r |
145 | //\r |
146 | DEBUG ((EFI_D_NET, "\nsnp->undi.station_addr() "));\r |
147 | \r |
148 | (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);\r |
149 | \r |
150 | if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {\r |
151 | DEBUG (\r |
152 | (EFI_D_ERROR,\r |
153 | "\nsnp->undi.station_addr() %xh:%xh\n",\r |
154 | snp->cdb.StatFlags,\r |
155 | snp->cdb.StatCode)\r |
156 | );\r |
157 | \r |
158 | //\r |
159 | // UNDI command failed. Return UNDI status to caller.\r |
160 | //\r |
161 | return EFI_DEVICE_ERROR;\r |
162 | }\r |
163 | //\r |
164 | // read the changed address and save it in SNP->Mode structure\r |
165 | //\r |
166 | pxe_get_stn_addr (snp);\r |
167 | \r |
168 | return EFI_SUCCESS;\r |
169 | }\r |
170 | \r |
171 | \r |
172 | /**\r |
173 | This is the SNP interface routine for changing the NIC's mac address.\r |
174 | This routine basically retrieves snp structure, checks the SNP state and\r |
175 | calls the above routines to actually do the work\r |
176 | \r |
177 | @param this context pointer\r |
178 | @param NewMacAddr pointer to a mac address to be set for the nic, if this is\r |
179 | NULL then this routine resets the mac address to the NIC's\r |
180 | original address.\r |
181 | @param ResetFlag If true, the mac address will change to NIC's original\r |
182 | address\r |
183 | \r |
184 | \r |
185 | **/\r |
186 | EFI_STATUS\r |
187 | EFIAPI\r |
188 | snp_undi32_station_address (\r |
189 | IN EFI_SIMPLE_NETWORK_PROTOCOL * this,\r |
190 | IN BOOLEAN ResetFlag,\r |
191 | IN EFI_MAC_ADDRESS * NewMacAddr OPTIONAL\r |
192 | )\r |
193 | {\r |
194 | SNP_DRIVER *snp;\r |
195 | EFI_STATUS Status;\r |
196 | EFI_TPL OldTpl;\r |
197 | \r |
198 | //\r |
199 | // Check for invalid parameter combinations.\r |
200 | //\r |
201 | if ((this == NULL) ||\r |
202 | (!ResetFlag && (NewMacAddr == NULL))) {\r |
203 | return EFI_INVALID_PARAMETER;\r |
204 | }\r |
205 | \r |
206 | snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);\r |
207 | \r |
208 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
209 | \r |
210 | //\r |
211 | // Return error if the SNP is not initialized.\r |
212 | //\r |
213 | switch (snp->mode.State) {\r |
214 | case EfiSimpleNetworkInitialized:\r |
215 | break;\r |
216 | \r |
217 | case EfiSimpleNetworkStopped:\r |
218 | Status = EFI_NOT_STARTED;\r |
219 | goto ON_EXIT;\r |
220 | \r |
221 | default:\r |
222 | Status = EFI_DEVICE_ERROR;\r |
223 | goto ON_EXIT;\r |
224 | }\r |
225 | \r |
226 | if (ResetFlag) {\r |
227 | Status = pxe_set_stn_addr (snp, NULL);\r |
228 | } else {\r |
229 | Status = pxe_set_stn_addr (snp, NewMacAddr);\r |
230 | }\r |
231 | \r |
232 | ON_EXIT:\r |
233 | gBS->RestoreTPL (OldTpl);\r |
234 | \r |
235 | return Status;\r |
236 | }\r |