TianoCore EDK2 master
Loading...
Searching...
No Matches
Station_address.c
Go to the documentation of this file.
1
9#include "Snp.h"
10
23 SNP_DRIVER *Snp
24 )
25{
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
97 SNP_DRIVER *Snp,
98 EFI_MAC_ADDRESS *NewMacAddr
99 )
100{
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
193EFIAPI
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
239ON_EXIT:
240 gBS->RestoreTPL (OldTpl);
241
242 return Status;
243}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS PxeGetStnAddr(SNP_DRIVER *Snp)
EFI_STATUS PxeSetStnAddr(SNP_DRIVER *Snp, EFI_MAC_ADDRESS *NewMacAddr)
EFI_STATUS EFIAPI SnpUndi32StationAddress(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN Reset, IN EFI_MAC_ADDRESS *New OPTIONAL)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINTN EFI_TPL
Definition: UefiBaseType.h:41
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
#define PXE_CPBSIZE_NOT_USED
zero
Definition: UefiPxe.h:57
#define PXE_OPCODE_STATION_ADDRESS
Definition: UefiPxe.h:135
#define PXE_CPBADDR_NOT_USED
zero
Definition: UefiPxe.h:59
#define PXE_OPFLAGS_STATION_ADDRESS_READ
Definition: UefiPxe.h:313
#define PXE_STATCODE_SUCCESS
Definition: UefiPxe.h:602
EFI_MAC_ADDRESS CurrentAddress
EFI_MAC_ADDRESS PermanentAddress
EFI_MAC_ADDRESS BroadcastAddress
Definition: Snp.h:55
PXE_MAC_ADDR StationAddr
Definition: UefiPxe.h:1336
PXE_MAC_ADDR PermanentAddr
Definition: UefiPxe.h:1353
PXE_MAC_ADDR StationAddr
Definition: UefiPxe.h:1343
PXE_MAC_ADDR BroadcastAddr
Definition: UefiPxe.h:1348