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