]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/SnpDxe/WaitForPacket.c
NetworkPkg: Apply uncrustify changes
[mirror_edk2.git] / NetworkPkg / SnpDxe / WaitForPacket.c
1 /** @file
2 Event handler to check for available packet.
3
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "Snp.h"
10
11 /**
12 Notification call back function for WaitForPacket event.
13
14 @param Event EFI Event.
15 @param SnpPtr Pointer to SNP_DRIVER structure.
16
17 **/
18 VOID
19 EFIAPI
20 SnpWaitForPacketNotify (
21 EFI_EVENT Event,
22 VOID *SnpPtr
23 )
24 {
25 PXE_DB_GET_STATUS PxeDbGetStatus;
26
27 //
28 // Do nothing if either parameter is a NULL pointer.
29 //
30 if ((Event == NULL) || (SnpPtr == NULL)) {
31 return;
32 }
33
34 //
35 // Do nothing if the SNP interface is not initialized.
36 //
37 switch (((SNP_DRIVER *)SnpPtr)->Mode.State) {
38 case EfiSimpleNetworkInitialized:
39 break;
40
41 case EfiSimpleNetworkStopped:
42 case EfiSimpleNetworkStarted:
43 default:
44 return;
45 }
46
47 //
48 // Fill in CDB for UNDI GetStatus().
49 //
50 ((SNP_DRIVER *)SnpPtr)->Cdb.OpCode = PXE_OPCODE_GET_STATUS;
51 ((SNP_DRIVER *)SnpPtr)->Cdb.OpFlags = 0;
52 ((SNP_DRIVER *)SnpPtr)->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
53 ((SNP_DRIVER *)SnpPtr)->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
54 ((SNP_DRIVER *)SnpPtr)->Cdb.DBsize = (UINT16)(sizeof (UINT32) * 2);
55 ((SNP_DRIVER *)SnpPtr)->Cdb.DBaddr = (UINT64)(UINTN)(((SNP_DRIVER *)SnpPtr)->Db);
56 ((SNP_DRIVER *)SnpPtr)->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
57 ((SNP_DRIVER *)SnpPtr)->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
58 ((SNP_DRIVER *)SnpPtr)->Cdb.IFnum = ((SNP_DRIVER *)SnpPtr)->IfNum;
59 ((SNP_DRIVER *)SnpPtr)->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
60
61 //
62 // Clear contents of DB buffer.
63 //
64 ZeroMem (((SNP_DRIVER *)SnpPtr)->Db, sizeof (UINT32) * 2);
65
66 //
67 // Issue UNDI command and check result.
68 //
69 (*((SNP_DRIVER *)SnpPtr)->IssueUndi32Command)((UINT64)(UINTN)&((SNP_DRIVER *)SnpPtr)->Cdb);
70
71 if (((SNP_DRIVER *)SnpPtr)->Cdb.StatCode != EFI_SUCCESS) {
72 return;
73 }
74
75 //
76 // We might have a packet. Check the receive length and signal
77 // the event if the length is not zero.
78 //
79 CopyMem (
80 &PxeDbGetStatus,
81 ((SNP_DRIVER *)SnpPtr)->Db,
82 sizeof (UINT32) * 2
83 );
84
85 if (PxeDbGetStatus.RxFrameLen != 0) {
86 gBS->SignalEvent (Event);
87 }
88 }