• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   Implementation for EFI iSCSI Initiator Name Protocol.
3 
4 Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
5 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 **/
14 
15 #include "IScsiImpl.h"
16 
17 EFI_ISCSI_INITIATOR_NAME_PROTOCOL gIScsiInitiatorName = {
18   IScsiGetInitiatorName,
19   IScsiSetInitiatorName
20 };
21 
22 /**
23   Retrieves the current set value of iSCSI Initiator Name.
24 
25   @param[in]       This       Pointer to the EFI_ISCSI_INITIATOR_NAME_PROTOCOL instance.
26   @param[in, out]  BufferSize Size of the buffer in bytes pointed to by Buffer / Actual size of the
27                               variable data buffer.
28   @param[out]      Buffer     Pointer to the buffer for data to be read. The data is a null-terminated UTF-8 encoded string.
29                               The maximum length is 223 characters, including the null-terminator.
30 
31   @retval EFI_SUCCESS           Data was successfully retrieved into the provided buffer and the
32                                 BufferSize was sufficient to handle the iSCSI initiator name.
33   @retval EFI_BUFFER_TOO_SMALL  BufferSize is too small for the result.
34   @retval EFI_INVALID_PARAMETER BufferSize or Buffer is NULL.
35   @retval EFI_DEVICE_ERROR      The iSCSI initiator name could not be retrieved due to a hardware error.
36   @retval Others                Other errors as indicated.
37 **/
38 EFI_STATUS
39 EFIAPI
IScsiGetInitiatorName(IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL * This,IN OUT UINTN * BufferSize,OUT VOID * Buffer)40 IScsiGetInitiatorName (
41   IN     EFI_ISCSI_INITIATOR_NAME_PROTOCOL  *This,
42   IN OUT UINTN                              *BufferSize,
43   OUT    VOID                               *Buffer
44   )
45 {
46   EFI_STATUS  Status;
47 
48   if ((BufferSize == NULL) || (Buffer == NULL)) {
49     return EFI_INVALID_PARAMETER;
50   }
51 
52   Status = gRT->GetVariable (
53                   ISCSI_INITIATOR_NAME_VAR_NAME,
54                   &gEfiIScsiInitiatorNameProtocolGuid,
55                   NULL,
56                   BufferSize,
57                   Buffer
58                   );
59 
60   return Status;
61 }
62 
63 /**
64   Sets the iSCSI Initiator Name.
65 
66   @param[in]       This       Pointer to the EFI_ISCSI_INITIATOR_NAME_PROTOCOL instance.
67   @param[in, out]  BufferSize Size of the buffer in bytes pointed to by Buffer.
68   @param[in]       Buffer     Pointer to the buffer for data to be written. The data is a null-terminated UTF-8 encoded string.
69                               The maximum length is 223 characters, including the null-terminator.
70 
71   @retval EFI_SUCCESS           Data was successfully stored by the protocol.
72   @retval EFI_UNSUPPORTED       Platform policies do not allow for data to be written.
73                                 Currently not implemented.
74   @retval EFI_INVALID_PARAMETER BufferSize or Buffer is NULL, or BufferSize exceeds the maximum allowed limit.
75   @retval EFI_DEVICE_ERROR      The data could not be stored due to a hardware error.
76   @retval EFI_OUT_OF_RESOURCES  Not enough storage is available to hold the data.
77   @retval EFI_PROTOCOL_ERROR    Input iSCSI initiator name does not adhere to RFC 3720
78                                 (and other related protocols).
79   @retval Others                Other errors as indicated.
80 **/
81 EFI_STATUS
82 EFIAPI
IScsiSetInitiatorName(IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL * This,IN OUT UINTN * BufferSize,IN VOID * Buffer)83 IScsiSetInitiatorName (
84   IN     EFI_ISCSI_INITIATOR_NAME_PROTOCOL  *This,
85   IN OUT UINTN                              *BufferSize,
86   IN     VOID                               *Buffer
87   )
88 {
89   EFI_STATUS  Status;
90 
91   if ((BufferSize == NULL) || (Buffer == NULL)) {
92     return EFI_INVALID_PARAMETER;
93   }
94 
95   if (*BufferSize > ISCSI_NAME_MAX_SIZE) {
96     *BufferSize = ISCSI_NAME_MAX_SIZE;
97     return EFI_INVALID_PARAMETER;
98   }
99   //
100   // only support iqn iSCSI names.
101   //
102   Status = IScsiNormalizeName ((CHAR8 *) Buffer, *BufferSize - 1);
103   if (EFI_ERROR (Status)) {
104     return Status;
105   }
106 
107   Status = gRT->SetVariable (
108                   ISCSI_INITIATOR_NAME_VAR_NAME,
109                   &gEfiIScsiInitiatorNameProtocolGuid,
110                   EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
111                   *BufferSize,
112                   Buffer
113                   );
114 
115   return Status;
116 }
117