Stop.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /** @file
  2. Implementation of stopping a network interface.
  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. Call UNDI to stop the interface and changes the snp state.
  9. @param Snp Pointer to snp driver structure
  10. @retval EFI_SUCCESS The network interface was stopped.
  11. @retval EFI_DEVICE_ERROR SNP is not initialized.
  12. **/
  13. EFI_STATUS
  14. PxeStop (
  15. SNP_DRIVER *Snp
  16. )
  17. {
  18. Snp->Cdb.OpCode = PXE_OPCODE_STOP;
  19. Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED;
  20. Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
  21. Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED;
  22. Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
  23. Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED;
  24. Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
  25. Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
  26. Snp->Cdb.IFnum = Snp->IfNum;
  27. Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
  28. //
  29. // Issue UNDI command
  30. //
  31. DEBUG ((DEBUG_NET, "\nsnp->undi.stop() "));
  32. (*Snp->IssueUndi32Command)((UINT64)(UINTN)&Snp->Cdb);
  33. if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) {
  34. DEBUG (
  35. (DEBUG_WARN,
  36. "\nsnp->undi.stop() %xh:%xh\n",
  37. Snp->Cdb.StatFlags,
  38. Snp->Cdb.StatCode)
  39. );
  40. return EFI_DEVICE_ERROR;
  41. }
  42. //
  43. // Set simple network state to Started and return success.
  44. //
  45. Snp->Mode.State = EfiSimpleNetworkStopped;
  46. return EFI_SUCCESS;
  47. }
  48. /**
  49. Changes the state of a network interface from "started" to "stopped."
  50. This function stops a network interface. This call is only valid if the network
  51. interface is in the started state. If the network interface was successfully
  52. stopped, then EFI_SUCCESS will be returned.
  53. @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL
  54. instance.
  55. @retval EFI_SUCCESS The network interface was stopped.
  56. @retval EFI_NOT_STARTED The network interface has not been started.
  57. @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a
  58. valid EFI_SIMPLE_NETWORK_PROTOCOL structure.
  59. @retval EFI_DEVICE_ERROR The command could not be sent to the network
  60. interface.
  61. @retval EFI_UNSUPPORTED This function is not supported by the network
  62. interface.
  63. **/
  64. EFI_STATUS
  65. EFIAPI
  66. SnpUndi32Stop (
  67. IN EFI_SIMPLE_NETWORK_PROTOCOL *This
  68. )
  69. {
  70. SNP_DRIVER *Snp;
  71. EFI_TPL OldTpl;
  72. EFI_STATUS Status;
  73. if (This == NULL) {
  74. return EFI_INVALID_PARAMETER;
  75. }
  76. Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
  77. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  78. switch (Snp->Mode.State) {
  79. case EfiSimpleNetworkStarted:
  80. break;
  81. case EfiSimpleNetworkStopped:
  82. Status = EFI_NOT_STARTED;
  83. goto ON_EXIT;
  84. default:
  85. Status = EFI_DEVICE_ERROR;
  86. goto ON_EXIT;
  87. }
  88. Status = PxeStop (Snp);
  89. ON_EXIT:
  90. gBS->RestoreTPL (OldTpl);
  91. return Status;
  92. }