]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/WaitForPacket.c
Import SnpDxe, Tcp4Dxe, Udp4Dxe and MnpDxe.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / WaitForPacket.c
1 /** @file
2 Copyright (c) 2004, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
7
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
10
11 Module name:
12 WaitForPacket.c
13
14 Abstract:
15 Event handler to check for available packet.
16
17
18 **/
19
20 #include "Snp.h"
21
22
23 /**
24
25
26
27 **/
28 VOID
29 EFIAPI
30 SnpWaitForPacketNotify (
31 EFI_EVENT Event,
32 VOID *SnpPtr
33 )
34 {
35 PXE_DB_GET_STATUS PxeDbGetStatus;
36
37 //
38 // Do nothing if either parameter is a NULL pointer.
39 //
40 if (Event == NULL || SnpPtr == NULL) {
41 return ;
42 }
43 //
44 // Do nothing if the SNP interface is not initialized.
45 //
46 switch (((SNP_DRIVER *) SnpPtr)->mode.State) {
47 case EfiSimpleNetworkInitialized:
48 break;
49
50 case EfiSimpleNetworkStopped:
51 case EfiSimpleNetworkStarted:
52 default:
53 return ;
54 }
55 //
56 // Fill in CDB for UNDI GetStatus().
57 //
58 ((SNP_DRIVER *) SnpPtr)->cdb.OpCode = PXE_OPCODE_GET_STATUS;
59 ((SNP_DRIVER *) SnpPtr)->cdb.OpFlags = 0;
60 ((SNP_DRIVER *) SnpPtr)->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
61 ((SNP_DRIVER *) SnpPtr)->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
62 ((SNP_DRIVER *) SnpPtr)->cdb.DBsize = sizeof (UINT32) * 2;
63 ((SNP_DRIVER *) SnpPtr)->cdb.DBaddr = (UINT64)(UINTN) (((SNP_DRIVER *) SnpPtr)->db);
64 ((SNP_DRIVER *) SnpPtr)->cdb.StatCode = PXE_STATCODE_INITIALIZE;
65 ((SNP_DRIVER *) SnpPtr)->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
66 ((SNP_DRIVER *) SnpPtr)->cdb.IFnum = ((SNP_DRIVER *) SnpPtr)->if_num;
67 ((SNP_DRIVER *) SnpPtr)->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
68
69 //
70 // Clear contents of DB buffer.
71 //
72 ZeroMem (((SNP_DRIVER *) SnpPtr)->db, sizeof (UINT32) * 2);
73
74 //
75 // Issue UNDI command and check result.
76 //
77 (*((SNP_DRIVER *) SnpPtr)->issue_undi32_command) ((UINT64)(UINTN) &((SNP_DRIVER *) SnpPtr)->cdb);
78
79 if (((SNP_DRIVER *) SnpPtr)->cdb.StatCode != EFI_SUCCESS) {
80 return ;
81 }
82 //
83 // We might have a packet. Check the receive length and signal
84 // the event if the length is not zero.
85 //
86 CopyMem (
87 &PxeDbGetStatus,
88 ((SNP_DRIVER *) SnpPtr)->db,
89 sizeof (UINT32) * 2
90 );
91
92 if (PxeDbGetStatus.RxFrameLen != 0) {
93 gBS->SignalEvent (Event);
94 }
95 }
96
97 /* eof - WaitForPacket.c */