TianoCore EDK2 master
Loading...
Searching...
No Matches
Receive.c
Go to the documentation of this file.
1
9#include "Snp.h"
10
39 SNP_DRIVER *Snp,
40 VOID *Buffer,
41 UINTN *BufferSize,
42 UINTN *HeaderSize,
43 EFI_MAC_ADDRESS *SrcAddr,
44 EFI_MAC_ADDRESS *DestAddr,
45 UINT16 *Protocol
46 )
47{
48 PXE_CPB_RECEIVE *Cpb;
50 UINTN BuffSize;
51
52 Cpb = Snp->Cpb;
53 Db = Snp->Db;
54 BuffSize = *BufferSize;
55
56 Cpb->BufferAddr = (UINT64)(UINTN)Buffer;
57 Cpb->BufferLen = (UINT32)*BufferSize;
58
59 Cpb->reserved = 0;
60
61 Snp->Cdb.OpCode = PXE_OPCODE_RECEIVE;
62 Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED;
63
64 Snp->Cdb.CPBsize = (UINT16)sizeof (PXE_CPB_RECEIVE);
65 Snp->Cdb.CPBaddr = (UINT64)(UINTN)Cpb;
66
67 Snp->Cdb.DBsize = (UINT16)sizeof (PXE_DB_RECEIVE);
68 Snp->Cdb.DBaddr = (UINT64)(UINTN)Db;
69
70 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
71 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
72 Snp->Cdb.IFnum = Snp->IfNum;
73 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
74
75 //
76 // Issue UNDI command and check result.
77 //
78 DEBUG ((DEBUG_NET, "\nsnp->undi.receive () "));
79
80 (*Snp->IssueUndi32Command)((UINT64)(UINTN)&Snp->Cdb);
81
82 switch (Snp->Cdb.StatCode) {
84 break;
85
86 case PXE_STATCODE_NO_DATA:
87 DEBUG (
88 (DEBUG_NET,
89 "\nsnp->undi.receive () %xh:%xh\n",
90 Snp->Cdb.StatFlags,
91 Snp->Cdb.StatCode)
92 );
93
94 return EFI_NOT_READY;
95
96 default:
97 DEBUG (
98 (DEBUG_ERROR,
99 "\nsnp->undi.receive() %xh:%xh\n",
100 Snp->Cdb.StatFlags,
101 Snp->Cdb.StatCode)
102 );
103
104 return EFI_DEVICE_ERROR;
105 }
106
107 *BufferSize = Db->FrameLen;
108
109 if (HeaderSize != NULL) {
110 *HeaderSize = Db->MediaHeaderLen;
111 }
112
113 if (SrcAddr != NULL) {
114 CopyMem (SrcAddr, &Db->SrcAddr, Snp->Mode.HwAddressSize);
115 }
116
117 if (DestAddr != NULL) {
118 CopyMem (DestAddr, &Db->DestAddr, Snp->Mode.HwAddressSize);
119 }
120
121 if (Protocol != NULL) {
122 //
123 // We need to do the byte swapping
124 //
125 *Protocol = (UINT16)PXE_SWAP_UINT16 (Db->Protocol);
126 }
127
128 //
129 // We have received a packet from network interface, which implies that the
130 // network cable should be present. While, some UNDI driver may not report
131 // correct media status during Snp->Initialize(). So, we need ensure
132 // MediaPresent in SNP mode data is set to correct value.
133 //
134 if (Snp->Mode.MediaPresentSupported && !Snp->Mode.MediaPresent) {
135 Snp->Mode.MediaPresent = TRUE;
136 }
137
138 return (*BufferSize <= BuffSize) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL;
139}
140
190EFIAPI
193 OUT UINTN *HeaderSize OPTIONAL,
194 IN OUT UINTN *BufferSize,
195 OUT VOID *Buffer,
196 OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
197 OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,
198 OUT UINT16 *Protocol OPTIONAL
199 )
200{
201 SNP_DRIVER *Snp;
202 EFI_TPL OldTpl;
203 EFI_STATUS Status;
204
205 if (This == NULL) {
206 return EFI_INVALID_PARAMETER;
207 }
208
209 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
210
211 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
212
213 switch (Snp->Mode.State) {
214 case EfiSimpleNetworkInitialized:
215 break;
216
217 case EfiSimpleNetworkStopped:
218 Status = EFI_NOT_STARTED;
219 goto ON_EXIT;
220
221 default:
222 Status = EFI_DEVICE_ERROR;
223 goto ON_EXIT;
224 }
225
226 if ((BufferSize == NULL) || (Buffer == NULL)) {
227 Status = EFI_INVALID_PARAMETER;
228 goto ON_EXIT;
229 }
230
231 if (Snp->Mode.ReceiveFilterSetting == 0) {
232 Status = EFI_DEVICE_ERROR;
233 goto ON_EXIT;
234 }
235
236 Status = PxeReceive (
237 Snp,
238 Buffer,
239 BufferSize,
240 HeaderSize,
241 SrcAddr,
242 DestAddr,
243 Protocol
244 );
245
246ON_EXIT:
247 gBS->RestoreTPL (OldTpl);
248
249 return Status;
250}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS PxeReceive(SNP_DRIVER *Snp, VOID *Buffer, UINTN *BufferSize, UINTN *HeaderSize, EFI_MAC_ADDRESS *SrcAddr, EFI_MAC_ADDRESS *DestAddr, UINT16 *Protocol)
Definition: Receive.c:38
EFI_STATUS EFIAPI SnpUndi32Receive(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, OUT UINTN *HeaderSize OPTIONAL, IN OUT UINTN *BufferSize, OUT VOID *Buffer, OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL, OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL, OUT UINT16 *Protocol OPTIONAL)
Definition: Receive.c:191
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_OPCODE_RECEIVE
Definition: UefiPxe.h:170
#define PXE_STATCODE_SUCCESS
Definition: UefiPxe.h:602
Definition: Snp.h:55
PXE_UINT32 reserved
Definition: UefiPxe.h:1740
PXE_UINT32 BufferLen
Definition: UefiPxe.h:1735
PXE_UINT64 BufferAddr
Definition: UefiPxe.h:1728
PXE_MAC_ADDR SrcAddr
Definition: UefiPxe.h:1747
PXE_UINT32 FrameLen
Definition: UefiPxe.h:1755
PXE_UINT16 MediaHeaderLen
Definition: UefiPxe.h:1765
PXE_MEDIA_PROTOCOL Protocol
Definition: UefiPxe.h:1760