]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/IScsiDxe/IScsiInitiatorName.c
Per UEFI spec, on CallBack action EFI_BROWSER_ACTION_CHANGING, the return value of...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiInitiatorName.c
CommitLineData
12618416 1/** @file\r
2 Implementation for EFI iSCSI Initiator Name Protocol.\r
6a690e23 3\r
4f077902 4Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
7a444476 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
6a690e23 12\r
12618416 13**/\r
6a690e23 14\r
15#include "IScsiImpl.h"\r
16\r
17EFI_ISCSI_INITIATOR_NAME_PROTOCOL gIScsiInitiatorName = {\r
18 IScsiGetInitiatorName,\r
19 IScsiSetInitiatorName\r
20};\r
21\r
12618416 22/**\r
9fd6fde8 23 Retrieves the current set value of iSCSI Initiator Name.\r
24\r
25 @param[in] This Pointer to the EFI_ISCSI_INITIATOR_NAME_PROTOCOL instance.\r
26 @param[in, out] BufferSize Size of the buffer in bytes pointed to by Buffer / Actual size of the\r
27 variable data buffer.\r
4f077902
SZ
28 @param[out] Buffer Pointer to the buffer for data to be read. The data is a null-terminated UTF-8 encoded string.\r
29 The maximum length is 223 characters, including the null-terminator.\r
9fd6fde8 30\r
31 @retval EFI_SUCCESS Data was successfully retrieved into the provided buffer and the\r
55a64ae0 32 BufferSize was sufficient to handle the iSCSI initiator name.\r
9fd6fde8 33 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the result.\r
34 @retval EFI_INVALID_PARAMETER BufferSize or Buffer is NULL.\r
35 @retval EFI_DEVICE_ERROR The iSCSI initiator name could not be retrieved due to a hardware error.\r
963dbb30 36 @retval Others Other errors as indicated.\r
12618416 37**/\r
6a690e23 38EFI_STATUS\r
39EFIAPI\r
40IScsiGetInitiatorName (\r
41 IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL *This,\r
42 IN OUT UINTN *BufferSize,\r
43 OUT VOID *Buffer\r
44 )\r
6a690e23 45{\r
46 EFI_STATUS Status;\r
47\r
48 if ((BufferSize == NULL) || (Buffer == NULL)) {\r
49 return EFI_INVALID_PARAMETER;\r
50 }\r
51\r
52 Status = gRT->GetVariable (\r
53 ISCSI_INITIATOR_NAME_VAR_NAME,\r
54 &gEfiIScsiInitiatorNameProtocolGuid,\r
55 NULL,\r
56 BufferSize,\r
57 Buffer\r
58 );\r
59\r
60 return Status;\r
61}\r
62\r
12618416 63/**\r
9fd6fde8 64 Sets the iSCSI Initiator Name.\r
12618416 65\r
9fd6fde8 66 @param[in] This Pointer to the EFI_ISCSI_INITIATOR_NAME_PROTOCOL instance.\r
67 @param[in, out] BufferSize Size of the buffer in bytes pointed to by Buffer.\r
4f077902
SZ
68 @param[in] Buffer Pointer to the buffer for data to be written. The data is a null-terminated UTF-8 encoded string.\r
69 The maximum length is 223 characters, including the null-terminator.\r
12618416 70\r
12618416 71 @retval EFI_SUCCESS Data was successfully stored by the protocol.\r
12618416 72 @retval EFI_UNSUPPORTED Platform policies do not allow for data to be written.\r
9fd6fde8 73 Currently not implemented.\r
74 @retval EFI_INVALID_PARAMETER BufferSize or Buffer is NULL, or BufferSize exceeds the maximum allowed limit.\r
12618416 75 @retval EFI_DEVICE_ERROR The data could not be stored due to a hardware error.\r
12618416 76 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the data.\r
9fd6fde8 77 @retval EFI_PROTOCOL_ERROR Input iSCSI initiator name does not adhere to RFC 3720\r
55a64ae0 78 (and other related protocols).\r
963dbb30 79 @retval Others Other errors as indicated.\r
12618416 80**/\r
81EFI_STATUS\r
82EFIAPI\r
83IScsiSetInitiatorName (\r
84 IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL *This,\r
85 IN OUT UINTN *BufferSize,\r
9fd6fde8 86 IN VOID *Buffer\r
12618416 87 )\r
6a690e23 88{\r
89 EFI_STATUS Status;\r
90\r
91 if ((BufferSize == NULL) || (Buffer == NULL)) {\r
92 return EFI_INVALID_PARAMETER;\r
93 }\r
94\r
95 if (*BufferSize > ISCSI_NAME_MAX_SIZE) {\r
96 *BufferSize = ISCSI_NAME_MAX_SIZE;\r
97 return EFI_INVALID_PARAMETER;\r
98 }\r
99 //\r
100 // only support iqn iSCSI names.\r
101 //\r
102 Status = IScsiNormalizeName ((CHAR8 *) Buffer, *BufferSize - 1);\r
103 if (EFI_ERROR (Status)) {\r
104 return Status;\r
105 }\r
106\r
107 Status = gRT->SetVariable (\r
108 ISCSI_INITIATOR_NAME_VAR_NAME,\r
109 &gEfiIScsiInitiatorNameProtocolGuid,\r
110 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
111 *BufferSize,\r
112 Buffer\r
113 );\r
114\r
115 return Status;\r
116}\r