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