]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/IScsiDxe/IScsiInitiatorName.c
1. Update iSCSI UI to be more user-friendly.
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiInitiatorName.c
CommitLineData
4c5a5e0c 1/** @file\r
2 Implementation for EFI iSCSI Initiator Name Protocol.\r
3\r
4Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
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
12\r
13**/\r
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
22\r
23/**\r
24 Retrieves the current set value of iSCSI Initiator Name.\r
25\r
26 @param[in] This Pointer to the EFI_ISCSI_INITIATOR_NAME_PROTOCOL\r
27 instance.\r
28 @param[in, out] BufferSize Size of the buffer in bytes pointed to by Buffer /\r
29 Actual size of the variable data buffer.\r
30 @param[out] Buffer Pointer to the buffer for data to be read.\r
31 The data is a null-terminated UTF-8 encoded string.\r
32 The maximum length is 223 characters, including the null-terminator.\r
33\r
34 @retval EFI_SUCCESS Data was successfully retrieved into the provided\r
35 buffer and the BufferSize was sufficient to handle\r
36 the iSCSI initiator name.\r
37 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the result. BufferSize\r
38 will be updated with the size required to complete\r
39 the request. Buffer will not be affected.\r
40 @retval EFI_INVALID_PARAMETER BufferSize is NULL. BufferSize and Buffer will not\r
41 be affected.\r
42 @retval EFI_INVALID_PARAMETER Buffer is NULL. BufferSize and Buffer will not be\r
43 affected.\r
44 @retval EFI_DEVICE_ERROR The iSCSI initiator name could not be retrieved\r
45 due to a hardware error.\r
46\r
47**/\r
48EFI_STATUS\r
49EFIAPI\r
50IScsiGetInitiatorName (\r
51 IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL *This,\r
52 IN OUT UINTN *BufferSize,\r
53 OUT VOID *Buffer\r
54 )\r
55{\r
56 EFI_STATUS Status;\r
57\r
58 if ((BufferSize == NULL) || (Buffer == NULL)) {\r
59 return EFI_INVALID_PARAMETER;\r
60 }\r
61\r
62 Status = gRT->GetVariable (\r
63 ISCSI_INITIATOR_NAME_VAR_NAME,\r
64 &gEfiIScsiInitiatorNameProtocolGuid,\r
65 NULL,\r
66 BufferSize,\r
67 Buffer\r
68 );\r
69\r
70 return Status;\r
71}\r
72\r
73\r
74/**\r
75 Sets the iSSI Initiator Name.\r
76\r
77 @param[in] This Pointer to the EFI_ISCSI_INITIATOR_NAME_PROTOCOL\r
78 instance.\r
79 @param[in, out] BufferSize Size of the buffer in bytes pointed to by Buffer.\r
80 @param[in] Buffer Pointer to the buffer for data to be written.\r
81 The data is a null-terminated UTF-8 encoded string.\r
82 The maximum length is 223 characters, including the null-terminator.\r
83\r
84 @retval EFI_SUCCESS Data was successfully stored by the protocol.\r
85 @retval EFI_UNSUPPORTED Platform policies do not allow for data to be\r
86 written.\r
87 @retval EFI_INVALID_PARAMETER BufferSize exceeds the maximum allowed limit.\r
88 BufferSize will be updated with the maximum size\r
89 required to complete the request.\r
90 @retval EFI_INVALID_PARAMETER Buffersize is NULL. BufferSize and Buffer will not\r
91 be affected.\r
92 @retval EFI_INVALID_PARAMETER Buffer is NULL. BufferSize and Buffer will not be\r
93 affected.\r
94 @retval EFI_DEVICE_ERROR The data could not be stored due to a hardware\r
95 error.\r
96 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the data\r
97 @retval EFI_PROTOCOL_ERROR Input iSCSI initiator name does not adhere to RFC\r
98 3720\r
99\r
100**/\r
101EFI_STATUS\r
102EFIAPI\r
103IScsiSetInitiatorName (\r
104 IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL *This,\r
105 IN OUT UINTN *BufferSize,\r
106 IN VOID *Buffer\r
107 )\r
108{\r
109 EFI_STATUS Status;\r
110\r
111 if ((BufferSize == NULL) || (Buffer == NULL)) {\r
112 return EFI_INVALID_PARAMETER;\r
113 }\r
114\r
115 if (*BufferSize > ISCSI_NAME_MAX_SIZE) {\r
116 *BufferSize = ISCSI_NAME_MAX_SIZE;\r
117 return EFI_INVALID_PARAMETER;\r
118 }\r
119 //\r
120 // Only support iqn iSCSI names.\r
121 //\r
122 Status = IScsiNormalizeName ((CHAR8 *) Buffer, *BufferSize - 1);\r
123 if (EFI_ERROR (Status)) {\r
124 return Status;\r
125 }\r
126\r
127 Status = gRT->SetVariable (\r
128 ISCSI_INITIATOR_NAME_VAR_NAME,\r
129 &gEfiIScsiInitiatorNameProtocolGuid,\r
130 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
131 *BufferSize,\r
132 Buffer\r
133 );\r
134\r
135 return Status;\r
136}\r