1 | /** @file
|
---|
2 | Implementation of reading the MAC address of a network adapter.
|
---|
3 |
|
---|
4 | Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #include "Snp.h"
|
---|
10 |
|
---|
11 | /**
|
---|
12 | Call UNDI to read the MAC address of the NIC and update the mode structure
|
---|
13 | with the address.
|
---|
14 |
|
---|
15 | @param Snp Pointer to snp driver structure.
|
---|
16 |
|
---|
17 | @retval EFI_SUCCESS The MAC address of the NIC is read successfully.
|
---|
18 | @retval EFI_DEVICE_ERROR Failed to read the MAC address of the NIC.
|
---|
19 |
|
---|
20 | **/
|
---|
21 | EFI_STATUS
|
---|
22 | PxeGetStnAddr (
|
---|
23 | SNP_DRIVER *Snp
|
---|
24 | )
|
---|
25 | {
|
---|
26 | PXE_DB_STATION_ADDRESS *Db;
|
---|
27 |
|
---|
28 | Db = Snp->Db;
|
---|
29 | Snp->Cdb.OpCode = PXE_OPCODE_STATION_ADDRESS;
|
---|
30 | Snp->Cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ;
|
---|
31 |
|
---|
32 | Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
|
---|
33 | Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
|
---|
34 |
|
---|
35 | Snp->Cdb.DBsize = (UINT16)sizeof (PXE_DB_STATION_ADDRESS);
|
---|
36 | Snp->Cdb.DBaddr = (UINT64)(UINTN)Db;
|
---|
37 |
|
---|
38 | Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
|
---|
39 | Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
|
---|
40 | Snp->Cdb.IFnum = Snp->IfNum;
|
---|
41 | Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
|
---|
42 |
|
---|
43 | //
|
---|
44 | // Issue UNDI command and check result.
|
---|
45 | //
|
---|
46 | DEBUG ((DEBUG_NET, "\nsnp->undi.station_addr() "));
|
---|
47 |
|
---|
48 | (*Snp->IssueUndi32Command)((UINT64)(UINTN)&Snp->Cdb);
|
---|
49 |
|
---|
50 | if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) {
|
---|
51 | DEBUG (
|
---|
52 | (DEBUG_ERROR,
|
---|
53 | "\nsnp->undi.station_addr() %xh:%xh\n",
|
---|
54 | Snp->Cdb.StatFlags,
|
---|
55 | Snp->Cdb.StatCode)
|
---|
56 | );
|
---|
57 |
|
---|
58 | return EFI_DEVICE_ERROR;
|
---|
59 | }
|
---|
60 |
|
---|
61 | //
|
---|
62 | // Set new station address in SNP->Mode structure and return success.
|
---|
63 | //
|
---|
64 | CopyMem (
|
---|
65 | &(Snp->Mode.CurrentAddress),
|
---|
66 | &Db->StationAddr,
|
---|
67 | Snp->Mode.HwAddressSize
|
---|
68 | );
|
---|
69 |
|
---|
70 | CopyMem (
|
---|
71 | &Snp->Mode.BroadcastAddress,
|
---|
72 | &Db->BroadcastAddr,
|
---|
73 | Snp->Mode.HwAddressSize
|
---|
74 | );
|
---|
75 |
|
---|
76 | CopyMem (
|
---|
77 | &Snp->Mode.PermanentAddress,
|
---|
78 | &Db->PermanentAddr,
|
---|
79 | Snp->Mode.HwAddressSize
|
---|
80 | );
|
---|
81 |
|
---|
82 | return EFI_SUCCESS;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | Call UNDI to set a new MAC address for the NIC.
|
---|
87 |
|
---|
88 | @param Snp Pointer to Snp driver structure.
|
---|
89 | @param NewMacAddr Pointer to a MAC address to be set for the NIC, if this is
|
---|
90 | NULL then this routine resets the mac address to the NIC's
|
---|
91 | original address.
|
---|
92 |
|
---|
93 |
|
---|
94 | **/
|
---|
95 | EFI_STATUS
|
---|
96 | PxeSetStnAddr (
|
---|
97 | SNP_DRIVER *Snp,
|
---|
98 | EFI_MAC_ADDRESS *NewMacAddr
|
---|
99 | )
|
---|
100 | {
|
---|
101 | PXE_CPB_STATION_ADDRESS *Cpb;
|
---|
102 | PXE_DB_STATION_ADDRESS *Db;
|
---|
103 |
|
---|
104 | Cpb = Snp->Cpb;
|
---|
105 | Db = Snp->Db;
|
---|
106 | Snp->Cdb.OpCode = PXE_OPCODE_STATION_ADDRESS;
|
---|
107 |
|
---|
108 | if (NewMacAddr == NULL) {
|
---|
109 | Snp->Cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_RESET;
|
---|
110 | Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
|
---|
111 | Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
|
---|
112 | } else {
|
---|
113 | Snp->Cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_WRITE;
|
---|
114 | //
|
---|
115 | // Supplying a new address in the CPB will make undi change the mac address to the new one.
|
---|
116 | //
|
---|
117 | CopyMem (&Cpb->StationAddr, NewMacAddr, Snp->Mode.HwAddressSize);
|
---|
118 |
|
---|
119 | Snp->Cdb.CPBsize = (UINT16)sizeof (PXE_CPB_STATION_ADDRESS);
|
---|
120 | Snp->Cdb.CPBaddr = (UINT64)(UINTN)Cpb;
|
---|
121 | }
|
---|
122 |
|
---|
123 | Snp->Cdb.DBsize = (UINT16)sizeof (PXE_DB_STATION_ADDRESS);
|
---|
124 | Snp->Cdb.DBaddr = (UINT64)(UINTN)Db;
|
---|
125 |
|
---|
126 | Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
|
---|
127 | Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
|
---|
128 | Snp->Cdb.IFnum = Snp->IfNum;
|
---|
129 | Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
|
---|
130 |
|
---|
131 | //
|
---|
132 | // Issue UNDI command and check result.
|
---|
133 | //
|
---|
134 | DEBUG ((DEBUG_NET, "\nsnp->undi.station_addr() "));
|
---|
135 |
|
---|
136 | (*Snp->IssueUndi32Command)((UINT64)(UINTN)&Snp->Cdb);
|
---|
137 |
|
---|
138 | if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) {
|
---|
139 | DEBUG (
|
---|
140 | (DEBUG_ERROR,
|
---|
141 | "\nsnp->undi.station_addr() %xh:%xh\n",
|
---|
142 | Snp->Cdb.StatFlags,
|
---|
143 | Snp->Cdb.StatCode)
|
---|
144 | );
|
---|
145 |
|
---|
146 | //
|
---|
147 | // UNDI command failed. Return UNDI status to caller.
|
---|
148 | //
|
---|
149 | return EFI_DEVICE_ERROR;
|
---|
150 | }
|
---|
151 |
|
---|
152 | //
|
---|
153 | // read the changed address and save it in SNP->Mode structure
|
---|
154 | //
|
---|
155 | PxeGetStnAddr (Snp);
|
---|
156 |
|
---|
157 | return EFI_SUCCESS;
|
---|
158 | }
|
---|
159 |
|
---|
160 | /**
|
---|
161 | Modifies or resets the current station address, if supported.
|
---|
162 |
|
---|
163 | This function modifies or resets the current station address of a network
|
---|
164 | interface, if supported. If Reset is TRUE, then the current station address is
|
---|
165 | set to the network interface's permanent address. If Reset is FALSE, and the
|
---|
166 | network interface allows its station address to be modified, then the current
|
---|
167 | station address is changed to the address specified by New. If the network
|
---|
168 | interface does not allow its station address to be modified, then
|
---|
169 | EFI_INVALID_PARAMETER will be returned. If the station address is successfully
|
---|
170 | updated on the network interface, EFI_SUCCESS will be returned. If the driver
|
---|
171 | has not been initialized, EFI_DEVICE_ERROR will be returned.
|
---|
172 |
|
---|
173 | @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
|
---|
174 | @param Reset Flag used to reset the station address to the network interface's
|
---|
175 | permanent address.
|
---|
176 | @param New New station address to be used for the network interface.
|
---|
177 |
|
---|
178 |
|
---|
179 | @retval EFI_SUCCESS The network interface's station address was updated.
|
---|
180 | @retval EFI_NOT_STARTED The Simple Network Protocol interface has not been
|
---|
181 | started by calling Start().
|
---|
182 | @retval EFI_INVALID_PARAMETER The New station address was not accepted by the NIC.
|
---|
183 | @retval EFI_INVALID_PARAMETER Reset is FALSE and New is NULL.
|
---|
184 | @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not
|
---|
185 | been initialized by calling Initialize().
|
---|
186 | @retval EFI_DEVICE_ERROR An error occurred attempting to set the new
|
---|
187 | station address.
|
---|
188 | @retval EFI_UNSUPPORTED The NIC does not support changing the network
|
---|
189 | interface's station address.
|
---|
190 |
|
---|
191 | **/
|
---|
192 | EFI_STATUS
|
---|
193 | EFIAPI
|
---|
194 | SnpUndi32StationAddress (
|
---|
195 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
---|
196 | IN BOOLEAN Reset,
|
---|
197 | IN EFI_MAC_ADDRESS *New OPTIONAL
|
---|
198 | )
|
---|
199 | {
|
---|
200 | SNP_DRIVER *Snp;
|
---|
201 | EFI_STATUS Status;
|
---|
202 | EFI_TPL OldTpl;
|
---|
203 |
|
---|
204 | //
|
---|
205 | // Check for invalid parameter combinations.
|
---|
206 | //
|
---|
207 | if ((This == NULL) ||
|
---|
208 | (!Reset && (New == NULL)))
|
---|
209 | {
|
---|
210 | return EFI_INVALID_PARAMETER;
|
---|
211 | }
|
---|
212 |
|
---|
213 | Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
|
---|
214 |
|
---|
215 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
---|
216 |
|
---|
217 | //
|
---|
218 | // Return error if the SNP is not initialized.
|
---|
219 | //
|
---|
220 | switch (Snp->Mode.State) {
|
---|
221 | case EfiSimpleNetworkInitialized:
|
---|
222 | break;
|
---|
223 |
|
---|
224 | case EfiSimpleNetworkStopped:
|
---|
225 | Status = EFI_NOT_STARTED;
|
---|
226 | goto ON_EXIT;
|
---|
227 |
|
---|
228 | default:
|
---|
229 | Status = EFI_DEVICE_ERROR;
|
---|
230 | goto ON_EXIT;
|
---|
231 | }
|
---|
232 |
|
---|
233 | if (Reset) {
|
---|
234 | Status = PxeSetStnAddr (Snp, NULL);
|
---|
235 | } else {
|
---|
236 | Status = PxeSetStnAddr (Snp, New);
|
---|
237 | }
|
---|
238 |
|
---|
239 | ON_EXIT:
|
---|
240 | gBS->RestoreTPL (OldTpl);
|
---|
241 |
|
---|
242 | return Status;
|
---|
243 | }
|
---|