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