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