]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/IScsiDxe/IScsiInitiatorName.c
NetworkPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiInitiatorName.c
1 /** @file
2 Implementation for EFI iSCSI Initiator Name Protocol.
3
4 Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "IScsiImpl.h"
10
11 EFI_ISCSI_INITIATOR_NAME_PROTOCOL gIScsiInitiatorName = {
12 IScsiGetInitiatorName,
13 IScsiSetInitiatorName
14 };
15
16
17 /**
18 Retrieves the current set value of iSCSI Initiator Name.
19
20 @param[in] This Pointer to the EFI_ISCSI_INITIATOR_NAME_PROTOCOL
21 instance.
22 @param[in, out] BufferSize Size of the buffer in bytes pointed to by Buffer /
23 Actual size of the variable data buffer.
24 @param[out] Buffer Pointer to the buffer for data to be read.
25 The data is a null-terminated UTF-8 encoded string.
26 The maximum length is 223 characters, including the null-terminator.
27
28 @retval EFI_SUCCESS Data was successfully retrieved into the provided
29 buffer and the BufferSize was sufficient to handle
30 the iSCSI initiator name.
31 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the result. BufferSize
32 will be updated with the size required to complete
33 the request. Buffer will not be affected.
34 @retval EFI_INVALID_PARAMETER BufferSize is NULL. BufferSize and Buffer will not
35 be affected.
36 @retval EFI_INVALID_PARAMETER Buffer is NULL. BufferSize and Buffer will not be
37 affected.
38 @retval EFI_DEVICE_ERROR The iSCSI initiator name could not be retrieved
39 due to a hardware error.
40
41 **/
42 EFI_STATUS
43 EFIAPI
44 IScsiGetInitiatorName (
45 IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL *This,
46 IN OUT UINTN *BufferSize,
47 OUT VOID *Buffer
48 )
49 {
50 EFI_STATUS Status;
51
52 if ((BufferSize == NULL) || (Buffer == NULL)) {
53 return EFI_INVALID_PARAMETER;
54 }
55
56 Status = gRT->GetVariable (
57 ISCSI_INITIATOR_NAME_VAR_NAME,
58 &gEfiIScsiInitiatorNameProtocolGuid,
59 NULL,
60 BufferSize,
61 Buffer
62 );
63
64 return Status;
65 }
66
67
68 /**
69 Sets the iSSI Initiator Name.
70
71 @param[in] This Pointer to the EFI_ISCSI_INITIATOR_NAME_PROTOCOL
72 instance.
73 @param[in, out] BufferSize Size of the buffer in bytes pointed to by Buffer.
74 @param[in] Buffer Pointer to the buffer for data to be written.
75 The data is a null-terminated UTF-8 encoded string.
76 The maximum length is 223 characters, including the null-terminator.
77
78 @retval EFI_SUCCESS Data was successfully stored by the protocol.
79 @retval EFI_UNSUPPORTED Platform policies do not allow for data to be
80 written.
81 @retval EFI_INVALID_PARAMETER BufferSize exceeds the maximum allowed limit.
82 BufferSize will be updated with the maximum size
83 required to complete the request.
84 @retval EFI_INVALID_PARAMETER Buffersize is NULL. BufferSize and Buffer will not
85 be affected.
86 @retval EFI_INVALID_PARAMETER Buffer is NULL. BufferSize and Buffer will not be
87 affected.
88 @retval EFI_DEVICE_ERROR The data could not be stored due to a hardware
89 error.
90 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the data
91 @retval EFI_PROTOCOL_ERROR Input iSCSI initiator name does not adhere to RFC
92 3720
93
94 **/
95 EFI_STATUS
96 EFIAPI
97 IScsiSetInitiatorName (
98 IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL *This,
99 IN OUT UINTN *BufferSize,
100 IN VOID *Buffer
101 )
102 {
103 EFI_STATUS Status;
104
105 if ((BufferSize == NULL) || (Buffer == NULL)) {
106 return EFI_INVALID_PARAMETER;
107 }
108
109 if (*BufferSize > ISCSI_NAME_MAX_SIZE) {
110 *BufferSize = ISCSI_NAME_MAX_SIZE;
111 return EFI_INVALID_PARAMETER;
112 }
113 //
114 // Only support iqn iSCSI names.
115 //
116 Status = IScsiNormalizeName ((CHAR8 *) Buffer, *BufferSize - 1);
117 if (EFI_ERROR (Status)) {
118 return Status;
119 }
120
121 Status = gRT->SetVariable (
122 ISCSI_INITIATOR_NAME_VAR_NAME,
123 &gEfiIScsiInitiatorNameProtocolGuid,
124 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
125 *BufferSize,
126 Buffer
127 );
128
129 return Status;
130 }