IScsiInitiatorName.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /** @file
  2. Implementation for EFI iSCSI Initiator Name Protocol.
  3. Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "IScsiImpl.h"
  7. EFI_ISCSI_INITIATOR_NAME_PROTOCOL gIScsiInitiatorName = {
  8. IScsiGetInitiatorName,
  9. IScsiSetInitiatorName
  10. };
  11. /**
  12. Retrieves the current set value of iSCSI Initiator Name.
  13. @param[in] This Pointer to the EFI_ISCSI_INITIATOR_NAME_PROTOCOL
  14. instance.
  15. @param[in, out] BufferSize Size of the buffer in bytes pointed to by Buffer /
  16. Actual size of the variable data buffer.
  17. @param[out] Buffer Pointer to the buffer for data to be read.
  18. The data is a null-terminated UTF-8 encoded string.
  19. The maximum length is 223 characters, including the null-terminator.
  20. @retval EFI_SUCCESS Data was successfully retrieved into the provided
  21. buffer and the BufferSize was sufficient to handle
  22. the iSCSI initiator name.
  23. @retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the result. BufferSize
  24. will be updated with the size required to complete
  25. the request. Buffer will not be affected.
  26. @retval EFI_INVALID_PARAMETER BufferSize is NULL. BufferSize and Buffer will not
  27. be affected.
  28. @retval EFI_INVALID_PARAMETER Buffer is NULL. BufferSize and Buffer will not be
  29. affected.
  30. @retval EFI_DEVICE_ERROR The iSCSI initiator name could not be retrieved
  31. due to a hardware error.
  32. **/
  33. EFI_STATUS
  34. EFIAPI
  35. IScsiGetInitiatorName (
  36. IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL *This,
  37. IN OUT UINTN *BufferSize,
  38. OUT VOID *Buffer
  39. )
  40. {
  41. EFI_STATUS Status;
  42. if ((BufferSize == NULL) || (Buffer == NULL)) {
  43. return EFI_INVALID_PARAMETER;
  44. }
  45. Status = gRT->GetVariable (
  46. ISCSI_INITIATOR_NAME_VAR_NAME,
  47. &gEfiIScsiInitiatorNameProtocolGuid,
  48. NULL,
  49. BufferSize,
  50. Buffer
  51. );
  52. return Status;
  53. }
  54. /**
  55. Sets the iSSI Initiator Name.
  56. @param[in] This Pointer to the EFI_ISCSI_INITIATOR_NAME_PROTOCOL
  57. instance.
  58. @param[in, out] BufferSize Size of the buffer in bytes pointed to by Buffer.
  59. @param[in] Buffer Pointer to the buffer for data to be written.
  60. The data is a null-terminated UTF-8 encoded string.
  61. The maximum length is 223 characters, including the null-terminator.
  62. @retval EFI_SUCCESS Data was successfully stored by the protocol.
  63. @retval EFI_UNSUPPORTED Platform policies do not allow for data to be
  64. written.
  65. @retval EFI_INVALID_PARAMETER BufferSize exceeds the maximum allowed limit.
  66. BufferSize will be updated with the maximum size
  67. required to complete the request.
  68. @retval EFI_INVALID_PARAMETER Buffersize is NULL. BufferSize and Buffer will not
  69. be affected.
  70. @retval EFI_INVALID_PARAMETER Buffer is NULL. BufferSize and Buffer will not be
  71. affected.
  72. @retval EFI_DEVICE_ERROR The data could not be stored due to a hardware
  73. error.
  74. @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the data
  75. @retval EFI_PROTOCOL_ERROR Input iSCSI initiator name does not adhere to RFC
  76. 3720
  77. **/
  78. EFI_STATUS
  79. EFIAPI
  80. IScsiSetInitiatorName (
  81. IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL *This,
  82. IN OUT UINTN *BufferSize,
  83. IN VOID *Buffer
  84. )
  85. {
  86. EFI_STATUS Status;
  87. if ((BufferSize == NULL) || (Buffer == NULL)) {
  88. return EFI_INVALID_PARAMETER;
  89. }
  90. if (*BufferSize > ISCSI_NAME_MAX_SIZE) {
  91. *BufferSize = ISCSI_NAME_MAX_SIZE;
  92. return EFI_INVALID_PARAMETER;
  93. }
  94. //
  95. // Only support iqn iSCSI names.
  96. //
  97. Status = IScsiNormalizeName ((CHAR8 *)Buffer, *BufferSize - 1);
  98. if (EFI_ERROR (Status)) {
  99. return Status;
  100. }
  101. Status = gRT->SetVariable (
  102. ISCSI_INITIATOR_NAME_VAR_NAME,
  103. &gEfiIScsiInitiatorNameProtocolGuid,
  104. EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
  105. *BufferSize,
  106. Buffer
  107. );
  108. return Status;
  109. }