]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/Receive.c
remove information output in SNP poll function.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Receive.c
1 /** @file
2 Implementation of receiving a packet from a network interface.
3
4 Copyright (c) 2004 - 2007, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials are licensed
6 and made available under the terms and conditions of the BSD License which
7 accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15
16 #include "Snp.h"
17
18 /**
19 Call UNDI to receive a packet and fills in the data in the input pointers.
20
21 @param Snp Pointer to snp driver structure
22 @param Buffer Pointer to the memory for the received data
23 @param BufferSize Pointer to the length of the buffer on entry and contains
24 the length of the received data on return
25 @param HeaderSize Pointer to the header portion of the data received.
26 @param SrcAddr Pointer to contain the source ethernet address on return
27 @param DestAddr Pointer to contain the destination ethernet address on
28 return
29 @param Protocol Pointer to contain the protocol type from the ethernet
30 header on return
31
32
33 @retval EFI_SUCCESS The received data was stored in Buffer, and
34 BufferSize has been updated to the number of
35 bytes received.
36 @retval EFI_DEVICE_ERROR Fail to execute UNDI command.
37 @retval EFI_NOT_READY No packets have been received on the network
38 interface.
39 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the received
40 packets. BufferSize has been updated to the
41 required size.
42
43 **/
44 EFI_STATUS
45 PxeReceive (
46 SNP_DRIVER *Snp,
47 VOID *Buffer,
48 UINTN *BufferSize,
49 UINTN *HeaderSize,
50 EFI_MAC_ADDRESS *SrcAddr,
51 EFI_MAC_ADDRESS *DestAddr,
52 UINT16 *Protocol
53 )
54 {
55 PXE_CPB_RECEIVE *Cpb;
56 PXE_DB_RECEIVE *Db;
57 UINTN BuffSize;
58
59 Cpb = Snp->Cpb;
60 Db = Snp->Db;
61 BuffSize = *BufferSize;
62
63 Cpb->BufferAddr = (UINT64)(UINTN) Buffer;
64 Cpb->BufferLen = (UINT32) *BufferSize;
65
66 Cpb->reserved = 0;
67
68 Snp->Cdb.OpCode = PXE_OPCODE_RECEIVE;
69 Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED;
70
71 Snp->Cdb.CPBsize = sizeof (PXE_CPB_RECEIVE);
72 Snp->Cdb.CPBaddr = (UINT64)(UINTN) Cpb;
73
74 Snp->Cdb.DBsize = sizeof (PXE_DB_RECEIVE);
75 Snp->Cdb.DBaddr = (UINT64)(UINTN) Db;
76
77 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
78 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
79 Snp->Cdb.IFnum = Snp->IfNum;
80 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
81
82 //
83 // Issue UNDI command and check result.
84 //
85 DEBUG ((EFI_D_NET, "\nsnp->undi.receive () "));
86
87 (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);
88
89 switch (Snp->Cdb.StatCode) {
90 case PXE_STATCODE_SUCCESS:
91 break;
92
93 case PXE_STATCODE_NO_DATA:
94 DEBUG (
95 (EFI_D_NET,
96 "\nsnp->undi.receive () %xh:%xh\n",
97 Snp->Cdb.StatFlags,
98 Snp->Cdb.StatCode)
99 );
100
101 return EFI_NOT_READY;
102
103 default:
104 DEBUG (
105 (EFI_D_NET,
106 "\nsnp->undi.receive() %xh:%xh\n",
107 Snp->Cdb.StatFlags,
108 Snp->Cdb.StatCode)
109 );
110
111 return EFI_DEVICE_ERROR;
112 }
113
114 *BufferSize = Db->FrameLen;
115
116 if (HeaderSize != NULL) {
117 *HeaderSize = Db->MediaHeaderLen;
118 }
119
120 if (SrcAddr != NULL) {
121 CopyMem (SrcAddr, &Db->SrcAddr, Snp->Mode.HwAddressSize);
122 }
123
124 if (DestAddr != NULL) {
125 CopyMem (DestAddr, &Db->DestAddr, Snp->Mode.HwAddressSize);
126 }
127
128 if (Protocol != NULL) {
129 //
130 // We need to do the byte swapping
131 //
132 *Protocol = (UINT16) PXE_SWAP_UINT16 (Db->Protocol);
133 }
134
135 return (*BufferSize <= BuffSize) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL;
136 }
137
138 /**
139 Receives a packet from a network interface.
140
141 This function retrieves one packet from the receive queue of a network interface.
142 If there are no packets on the receive queue, then EFI_NOT_READY will be
143 returned. If there is a packet on the receive queue, and the size of the packet
144 is smaller than BufferSize, then the contents of the packet will be placed in
145 Buffer, and BufferSize will be updated with the actual size of the packet.
146 In addition, if SrcAddr, DestAddr, and Protocol are not NULL, then these values
147 will be extracted from the media header and returned. EFI_SUCCESS will be
148 returned if a packet was successfully received.
149 If BufferSize is smaller than the received packet, then the size of the receive
150 packet will be placed in BufferSize and EFI_BUFFER_TOO_SMALL will be returned.
151 If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.
152
153 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
154 @param HeaderSize The size, in bytes, of the media header received on the network
155 interface. If this parameter is NULL, then the media header size
156 will not be returned.
157 @param BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in
158 bytes, of the packet that was received on the network interface.
159 @param Buffer A pointer to the data buffer to receive both the media
160 header and the data.
161 @param SrcAddr The source HW MAC address. If this parameter is NULL, the HW
162 MAC source address will not be extracted from the media header.
163 @param DestAddr The destination HW MAC address. If this parameter is NULL,
164 the HW MAC destination address will not be extracted from
165 the media header.
166 @param Protocol The media header type. If this parameter is NULL, then the
167 protocol will not be extracted from the media header. See
168 RFC 1700 section "Ether Types" for examples.
169
170 @retval EFI_SUCCESS The received data was stored in Buffer, and
171 BufferSize has been updated to the number of
172 bytes received.
173 @retval EFI_NOT_STARTED The network interface has not been started.
174 @retval EFI_NOT_READY No packets have been received on the network interface.
175 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the received packets.
176 BufferSize has been updated to the required size.
177 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
178 * The This parameter is NULL
179 * The This parameter does not point to a valid
180 EFI_SIMPLE_NETWORK_PROTOCOL structure.
181 * The BufferSize parameter is NULL
182 * The Buffer parameter is NULL
183 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
184
185 **/
186 EFI_STATUS
187 EFIAPI
188 SnpUndi32Receive (
189 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
190 OUT UINTN *HeaderSize OPTIONAL,
191 IN OUT UINTN *BufferSize,
192 OUT VOID *Buffer,
193 OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
194 OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,
195 OUT UINT16 *Protocol OPTIONAL
196 )
197 {
198 SNP_DRIVER *Snp;
199 EFI_TPL OldTpl;
200 EFI_STATUS Status;
201
202 if (This == NULL) {
203 return EFI_INVALID_PARAMETER;
204 }
205
206 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
207
208 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
209
210 switch (Snp->Mode.State) {
211 case EfiSimpleNetworkInitialized:
212 break;
213
214 case EfiSimpleNetworkStopped:
215 Status = EFI_NOT_STARTED;
216 goto ON_EXIT;
217
218 default:
219 Status = EFI_DEVICE_ERROR;
220 goto ON_EXIT;
221 }
222
223 if ((BufferSize == NULL) || (Buffer == NULL)) {
224 Status = EFI_INVALID_PARAMETER;
225 goto ON_EXIT;
226 }
227
228 if (!Snp->Mode.ReceiveFilterSetting) {
229 Status = EFI_DEVICE_ERROR;
230 goto ON_EXIT;
231 }
232
233 Status = PxeReceive (
234 Snp,
235 Buffer,
236 BufferSize,
237 HeaderSize,
238 SrcAddr,
239 DestAddr,
240 Protocol
241 );
242
243 ON_EXIT:
244 gBS->RestoreTPL (OldTpl);
245
246 return Status;
247 }