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