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