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