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