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