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