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