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