summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Universal/Network/SnpDxe/WaitForPacket.c
blob: 57d82ea160203fc5f3b2da8a387f5812ac3fe0d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/** @file
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution.  The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

Module name:
  WaitForPacket.c

Abstract:
  Event handler to check for available packet.


**/

#include "Snp.h"


/**



**/
VOID
EFIAPI
SnpWaitForPacketNotify (
  EFI_EVENT Event,
  VOID      *SnpPtr
  )
{
  PXE_DB_GET_STATUS PxeDbGetStatus;

  //
  // Do nothing if either parameter is a NULL pointer.
  //
  if (Event == NULL || SnpPtr == NULL) {
    return ;
  }
  //
  // Do nothing if the SNP interface is not initialized.
  //
  switch (((SNP_DRIVER *) SnpPtr)->mode.State) {
  case EfiSimpleNetworkInitialized:
    break;

  case EfiSimpleNetworkStopped:
  case EfiSimpleNetworkStarted:
  default:
    return ;
  }
  //
  // Fill in CDB for UNDI GetStatus().
  //
  ((SNP_DRIVER *) SnpPtr)->cdb.OpCode     = PXE_OPCODE_GET_STATUS;
  ((SNP_DRIVER *) SnpPtr)->cdb.OpFlags    = 0;
  ((SNP_DRIVER *) SnpPtr)->cdb.CPBsize    = PXE_CPBSIZE_NOT_USED;
  ((SNP_DRIVER *) SnpPtr)->cdb.CPBaddr    = PXE_CPBADDR_NOT_USED;
  ((SNP_DRIVER *) SnpPtr)->cdb.DBsize     = sizeof (UINT32) * 2;
  ((SNP_DRIVER *) SnpPtr)->cdb.DBaddr     = (UINT64)(UINTN) (((SNP_DRIVER *) SnpPtr)->db);
  ((SNP_DRIVER *) SnpPtr)->cdb.StatCode   = PXE_STATCODE_INITIALIZE;
  ((SNP_DRIVER *) SnpPtr)->cdb.StatFlags  = PXE_STATFLAGS_INITIALIZE;
  ((SNP_DRIVER *) SnpPtr)->cdb.IFnum      = ((SNP_DRIVER *) SnpPtr)->if_num;
  ((SNP_DRIVER *) SnpPtr)->cdb.Control    = PXE_CONTROL_LAST_CDB_IN_LIST;

  //
  // Clear contents of DB buffer.
  //
  ZeroMem (((SNP_DRIVER *) SnpPtr)->db, sizeof (UINT32) * 2);

  //
  // Issue UNDI command and check result.
  //
  (*((SNP_DRIVER *) SnpPtr)->issue_undi32_command) ((UINT64)(UINTN) &((SNP_DRIVER *) SnpPtr)->cdb);

  if (((SNP_DRIVER *) SnpPtr)->cdb.StatCode != EFI_SUCCESS) {
    return ;
  }
  //
  // We might have a packet.  Check the receive length and signal
  // the event if the length is not zero.
  //
  CopyMem (
    &PxeDbGetStatus,
    ((SNP_DRIVER *) SnpPtr)->db,
    sizeof (UINT32) * 2
    );

  if (PxeDbGetStatus.RxFrameLen != 0) {
    gBS->SignalEvent (Event);
  }
}

/* eof - WaitForPacket.c */