WaitForPacket.c 2.3 KB

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