xref: /onnv-gate/usr/src/cmd/lms/heci/PTHICommand.cpp (revision 9203:3ebffd0a1b10)
1*9203SMark.Logan@Sun.COM /*******************************************************************************
2*9203SMark.Logan@Sun.COM  * Copyright (C) 2004-2008 Intel Corp. All rights reserved.
3*9203SMark.Logan@Sun.COM  *
4*9203SMark.Logan@Sun.COM  * Redistribution and use in source and binary forms, with or without
5*9203SMark.Logan@Sun.COM  * modification, are permitted provided that the following conditions are met:
6*9203SMark.Logan@Sun.COM  *
7*9203SMark.Logan@Sun.COM  *  - Redistributions of source code must retain the above copyright notice,
8*9203SMark.Logan@Sun.COM  *    this list of conditions and the following disclaimer.
9*9203SMark.Logan@Sun.COM  *
10*9203SMark.Logan@Sun.COM  *  - Redistributions in binary form must reproduce the above copyright notice,
11*9203SMark.Logan@Sun.COM  *    this list of conditions and the following disclaimer in the documentation
12*9203SMark.Logan@Sun.COM  *    and/or other materials provided with the distribution.
13*9203SMark.Logan@Sun.COM  *
14*9203SMark.Logan@Sun.COM  *  - Neither the name of Intel Corp. nor the names of its
15*9203SMark.Logan@Sun.COM  *    contributors may be used to endorse or promote products derived from this
16*9203SMark.Logan@Sun.COM  *    software without specific prior written permission.
17*9203SMark.Logan@Sun.COM  *
18*9203SMark.Logan@Sun.COM  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
19*9203SMark.Logan@Sun.COM  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*9203SMark.Logan@Sun.COM  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*9203SMark.Logan@Sun.COM  * ARE DISCLAIMED. IN NO EVENT SHALL Intel Corp. OR THE CONTRIBUTORS
22*9203SMark.Logan@Sun.COM  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*9203SMark.Logan@Sun.COM  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*9203SMark.Logan@Sun.COM  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*9203SMark.Logan@Sun.COM  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*9203SMark.Logan@Sun.COM  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*9203SMark.Logan@Sun.COM  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*9203SMark.Logan@Sun.COM  * POSSIBILITY OF SUCH DAMAGE.
29*9203SMark.Logan@Sun.COM  *******************************************************************************/
30*9203SMark.Logan@Sun.COM 
31*9203SMark.Logan@Sun.COM //----------------------------------------------------------------------------
32*9203SMark.Logan@Sun.COM //
33*9203SMark.Logan@Sun.COM //  File:       PTHICommand.cpp
34*9203SMark.Logan@Sun.COM //
35*9203SMark.Logan@Sun.COM //----------------------------------------------------------------------------
36*9203SMark.Logan@Sun.COM 
37*9203SMark.Logan@Sun.COM #ifdef HAVE_CONFIG_H
38*9203SMark.Logan@Sun.COM #include "config.h"
39*9203SMark.Logan@Sun.COM #endif
40*9203SMark.Logan@Sun.COM #include <cstdio>
41*9203SMark.Logan@Sun.COM #include <cstdlib>
42*9203SMark.Logan@Sun.COM #include "PTHICommand.h"
43*9203SMark.Logan@Sun.COM 
44*9203SMark.Logan@Sun.COM 
PTHICommand(bool verbose,unsigned long sendTimeout)45*9203SMark.Logan@Sun.COM PTHICommand::PTHICommand(bool verbose, unsigned long sendTimeout) :
46*9203SMark.Logan@Sun.COM PTHIClient(HECI_PTHI, verbose),
47*9203SMark.Logan@Sun.COM m_sendTimeout(sendTimeout)
48*9203SMark.Logan@Sun.COM {
49*9203SMark.Logan@Sun.COM }
50*9203SMark.Logan@Sun.COM 
~PTHICommand(void)51*9203SMark.Logan@Sun.COM PTHICommand::~PTHICommand(void)
52*9203SMark.Logan@Sun.COM {
53*9203SMark.Logan@Sun.COM }
54*9203SMark.Logan@Sun.COM 
_call(const unsigned char * command,UINT32 command_size,UINT8 ** readBuffer,UINT32 rcmd,unsigned int expSize)55*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::_call(const unsigned char *command, UINT32 command_size, UINT8 **readBuffer, UINT32 rcmd, unsigned int expSize)
56*9203SMark.Logan@Sun.COM {
57*9203SMark.Logan@Sun.COM 	UINT32 inBuffSize;
58*9203SMark.Logan@Sun.COM 	UINT32 outBuffSize = 0;
59*9203SMark.Logan@Sun.COM 
60*9203SMark.Logan@Sun.COM 	inBuffSize = PTHIClient.GetBufferSize();
61*9203SMark.Logan@Sun.COM 	*readBuffer = (UINT8 *)malloc(sizeof(UINT8) * inBuffSize);
62*9203SMark.Logan@Sun.COM 	if (NULL == *readBuffer)
63*9203SMark.Logan@Sun.COM 	{
64*9203SMark.Logan@Sun.COM 		return PTSDK_STATUS_RESOURCES;
65*9203SMark.Logan@Sun.COM 	}
66*9203SMark.Logan@Sun.COM 	memset(*readBuffer, 0, inBuffSize);
67*9203SMark.Logan@Sun.COM 
68*9203SMark.Logan@Sun.COM 	int bytesWritten = PTHIClient.SendMessage(command, command_size, m_sendTimeout);
69*9203SMark.Logan@Sun.COM 	if ((UINT32)bytesWritten != command_size)
70*9203SMark.Logan@Sun.COM 	{
71*9203SMark.Logan@Sun.COM 		return AMT_STATUS_INTERNAL_ERROR;
72*9203SMark.Logan@Sun.COM 	}
73*9203SMark.Logan@Sun.COM 	outBuffSize = PTHIClient.ReceiveMessage(*readBuffer, inBuffSize);
74*9203SMark.Logan@Sun.COM 	if (0 == outBuffSize)
75*9203SMark.Logan@Sun.COM 	{
76*9203SMark.Logan@Sun.COM 		return PTHI_STATUS_EMPTY_RESPONSE;
77*9203SMark.Logan@Sun.COM 	}
78*9203SMark.Logan@Sun.COM 	AMT_STATUS status = ((PTHI_RESPONSE_MESSAGE_HEADER *)*readBuffer)->Status;
79*9203SMark.Logan@Sun.COM 	if (status != AMT_STATUS_SUCCESS)
80*9203SMark.Logan@Sun.COM 	{
81*9203SMark.Logan@Sun.COM 		return status;
82*9203SMark.Logan@Sun.COM 	}
83*9203SMark.Logan@Sun.COM 	status = _verifyResponseHeader(rcmd, ((PTHI_RESPONSE_MESSAGE_HEADER *)*readBuffer)->Header, outBuffSize);
84*9203SMark.Logan@Sun.COM 	if (status != AMT_STATUS_SUCCESS)
85*9203SMark.Logan@Sun.COM 	{
86*9203SMark.Logan@Sun.COM 		return status;
87*9203SMark.Logan@Sun.COM 	}
88*9203SMark.Logan@Sun.COM 	if ((expSize != 0) && (expSize != outBuffSize))
89*9203SMark.Logan@Sun.COM 	{
90*9203SMark.Logan@Sun.COM 		return PTSDK_STATUS_INTERNAL_ERROR;
91*9203SMark.Logan@Sun.COM 	}
92*9203SMark.Logan@Sun.COM 	return AMT_STATUS_SUCCESS;
93*9203SMark.Logan@Sun.COM }
94*9203SMark.Logan@Sun.COM 
95*9203SMark.Logan@Sun.COM /*
96*9203SMark.Logan@Sun.COM * Confirms the correctness of the response message header
97*9203SMark.Logan@Sun.COM * and the response message size
98*9203SMark.Logan@Sun.COM * Arguments:
99*9203SMark.Logan@Sun.COM *	command	- appropriate Host interface command
100*9203SMark.Logan@Sun.COM *	response_header	- reference to the response message header
101*9203SMark.Logan@Sun.COM *	response_size	- value that holds the actual size of the
102*9203SMark.Logan@Sun.COM *                         response message
103*9203SMark.Logan@Sun.COM *	expected_size	- value that holds the expected size of the
104*9203SMark.Logan@Sun.COM *                         response message
105*9203SMark.Logan@Sun.COM * Return values:
106*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
107*9203SMark.Logan@Sun.COM *	PTSDK_STATUS_INTERNAL_ERROR - on failure
108*9203SMark.Logan@Sun.COM */
_verifyResponseHeader(const UINT32 command,const PTHI_MESSAGE_HEADER & response_header,UINT32 response_size)109*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::_verifyResponseHeader(
110*9203SMark.Logan@Sun.COM 	const UINT32 command, const PTHI_MESSAGE_HEADER &response_header,
111*9203SMark.Logan@Sun.COM 	UINT32 response_size)
112*9203SMark.Logan@Sun.COM {
113*9203SMark.Logan@Sun.COM 	AMT_STATUS status = AMT_STATUS_SUCCESS;
114*9203SMark.Logan@Sun.COM 
115*9203SMark.Logan@Sun.COM 	if (response_size < sizeof(PTHI_RESPONSE_MESSAGE_HEADER)) {
116*9203SMark.Logan@Sun.COM 		status = AMT_STATUS_INTERNAL_ERROR;
117*9203SMark.Logan@Sun.COM 	} else if (response_size != (response_header.Length + sizeof(PTHI_MESSAGE_HEADER))) {
118*9203SMark.Logan@Sun.COM 		status = AMT_STATUS_INTERNAL_ERROR;
119*9203SMark.Logan@Sun.COM 	} else if (response_header.Command.cmd.val != command) {
120*9203SMark.Logan@Sun.COM 		status = AMT_STATUS_INTERNAL_ERROR;
121*9203SMark.Logan@Sun.COM 	} else if (response_header.Reserved != 0) {
122*9203SMark.Logan@Sun.COM 		status = AMT_STATUS_INTERNAL_ERROR;
123*9203SMark.Logan@Sun.COM 	} else if (response_header.Version.MajorNumber != AMT_MAJOR_VERSION
124*9203SMark.Logan@Sun.COM 		|| response_header.Version.MinorNumber < AMT_MINOR_VERSION) {
125*9203SMark.Logan@Sun.COM 			status = AMT_STATUS_INTERNAL_ERROR;
126*9203SMark.Logan@Sun.COM 	}
127*9203SMark.Logan@Sun.COM 
128*9203SMark.Logan@Sun.COM 	return status;
129*9203SMark.Logan@Sun.COM }
130*9203SMark.Logan@Sun.COM 
131*9203SMark.Logan@Sun.COM /*
132*9203SMark.Logan@Sun.COM * Confirms the correctness of the GetCodeVersions response message
133*9203SMark.Logan@Sun.COM * Arguments:
134*9203SMark.Logan@Sun.COM *	response - reference to the response message
135*9203SMark.Logan@Sun.COM * Return values:
136*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
137*9203SMark.Logan@Sun.COM *	PTSDK_STATUS_INTERNAL_ERROR - on failure
138*9203SMark.Logan@Sun.COM */
_verifyCodeVersions(const CFG_GET_CODE_VERSIONS_RESPONSE & response)139*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::_verifyCodeVersions(
140*9203SMark.Logan@Sun.COM 	const CFG_GET_CODE_VERSIONS_RESPONSE &response)
141*9203SMark.Logan@Sun.COM {
142*9203SMark.Logan@Sun.COM 	AMT_STATUS status = AMT_STATUS_SUCCESS;
143*9203SMark.Logan@Sun.COM 	UINT32 codeVerLen;
144*9203SMark.Logan@Sun.COM 	UINT32 ptVerTypeCount;
145*9203SMark.Logan@Sun.COM 	UINT32 len = 0;
146*9203SMark.Logan@Sun.COM 	UINT32 i;
147*9203SMark.Logan@Sun.COM 
148*9203SMark.Logan@Sun.COM 	do {
149*9203SMark.Logan@Sun.COM 		codeVerLen = response.Header.Header.Length - sizeof(AMT_STATUS);
150*9203SMark.Logan@Sun.COM 		ptVerTypeCount = codeVerLen - sizeof(response.CodeVersions.BiosVersion)- sizeof(response.CodeVersions.VersionsCount);
151*9203SMark.Logan@Sun.COM 		if (response.CodeVersions.VersionsCount != (ptVerTypeCount/sizeof(AMT_VERSION_TYPE)))
152*9203SMark.Logan@Sun.COM 		{
153*9203SMark.Logan@Sun.COM 			status = AMT_STATUS_INTERNAL_ERROR;
154*9203SMark.Logan@Sun.COM 			break;
155*9203SMark.Logan@Sun.COM 		}
156*9203SMark.Logan@Sun.COM 
157*9203SMark.Logan@Sun.COM 		for (i = 0; i < (response.CodeVersions.VersionsCount); i ++)
158*9203SMark.Logan@Sun.COM 		{
159*9203SMark.Logan@Sun.COM 			len = response.CodeVersions.Versions[i].Description.Length;
160*9203SMark.Logan@Sun.COM 
161*9203SMark.Logan@Sun.COM 			if (len > UNICODE_STRING_LEN)
162*9203SMark.Logan@Sun.COM 			{
163*9203SMark.Logan@Sun.COM 				status = AMT_STATUS_INTERNAL_ERROR;
164*9203SMark.Logan@Sun.COM 				break;
165*9203SMark.Logan@Sun.COM 			}
166*9203SMark.Logan@Sun.COM 
167*9203SMark.Logan@Sun.COM 			len = response.CodeVersions.Versions[i].Version.Length;
168*9203SMark.Logan@Sun.COM 			if (response.CodeVersions.Versions[i].Version.String[len] != '\0' ||
169*9203SMark.Logan@Sun.COM 				(len != strlen((CHAR *)(response.CodeVersions.Versions[i].Version.String))))
170*9203SMark.Logan@Sun.COM 			{
171*9203SMark.Logan@Sun.COM 				status = AMT_STATUS_INTERNAL_ERROR;
172*9203SMark.Logan@Sun.COM 				break;
173*9203SMark.Logan@Sun.COM 			}
174*9203SMark.Logan@Sun.COM 		}
175*9203SMark.Logan@Sun.COM 	} while (0);
176*9203SMark.Logan@Sun.COM 
177*9203SMark.Logan@Sun.COM 	return status;
178*9203SMark.Logan@Sun.COM }
179*9203SMark.Logan@Sun.COM 
180*9203SMark.Logan@Sun.COM /*
181*9203SMark.Logan@Sun.COM * GetVersions response message PTHI command
182*9203SMark.Logan@Sun.COM * Arguments:
183*9203SMark.Logan@Sun.COM *	response - reference to the CODE_VERSIONS struct
184*9203SMark.Logan@Sun.COM * Return values:
185*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
186*9203SMark.Logan@Sun.COM *	AMT_STATUS_INTERNAL_ERROR - on failure
187*9203SMark.Logan@Sun.COM */
GetCodeVersions(CODE_VERSIONS & codeVersions)188*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetCodeVersions(CODE_VERSIONS &codeVersions)
189*9203SMark.Logan@Sun.COM {
190*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
191*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(GET_CODE_VERSION_HEADER);
192*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
193*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_CODE_VERSION_HEADER), sizeof(GET_CODE_VERSION_HEADER));
194*9203SMark.Logan@Sun.COM 
195*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, CODE_VERSIONS_RESPONSE, 0);
196*9203SMark.Logan@Sun.COM 	do {
197*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
198*9203SMark.Logan@Sun.COM 		{
199*9203SMark.Logan@Sun.COM 			break;
200*9203SMark.Logan@Sun.COM 		}
201*9203SMark.Logan@Sun.COM 		CFG_GET_CODE_VERSIONS_RESPONSE *tmp_response = (CFG_GET_CODE_VERSIONS_RESPONSE *)readBuffer;
202*9203SMark.Logan@Sun.COM 		status = _verifyCodeVersions(*tmp_response);
203*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
204*9203SMark.Logan@Sun.COM 		{
205*9203SMark.Logan@Sun.COM 			break;
206*9203SMark.Logan@Sun.COM 		}
207*9203SMark.Logan@Sun.COM 
208*9203SMark.Logan@Sun.COM 		memcpy(&codeVersions, &(tmp_response->CodeVersions), sizeof(CODE_VERSIONS));
209*9203SMark.Logan@Sun.COM 
210*9203SMark.Logan@Sun.COM 	} while (0);
211*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
212*9203SMark.Logan@Sun.COM 	{
213*9203SMark.Logan@Sun.COM 		free(readBuffer);
214*9203SMark.Logan@Sun.COM 	}
215*9203SMark.Logan@Sun.COM 	return status;
216*9203SMark.Logan@Sun.COM }
217*9203SMark.Logan@Sun.COM 
218*9203SMark.Logan@Sun.COM /*
219*9203SMark.Logan@Sun.COM * Calls to GetProvisioningMode Host interface command
220*9203SMark.Logan@Sun.COM * Arguments:
221*9203SMark.Logan@Sun.COM *	mode - reference to the pre-allocated structure
222*9203SMark.Logan@Sun.COM *       which will hold the result
223*9203SMark.Logan@Sun.COM * Return values:
224*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
225*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
226*9203SMark.Logan@Sun.COM */
GetProvisioningMode(CFG_PROVISIONING_MODE & mode)227*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetProvisioningMode(CFG_PROVISIONING_MODE &mode)
228*9203SMark.Logan@Sun.COM {
229*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
230*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(GET_PROVISIONING_MODE_HEADER);
231*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
232*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_PROVISIONING_MODE_HEADER), sizeof(GET_PROVISIONING_MODE_HEADER));
233*9203SMark.Logan@Sun.COM 
234*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, PROVISIONING_MODE_RESPONSE, sizeof(CFG_GET_PROVISIONING_MODE_RESPONSE));
235*9203SMark.Logan@Sun.COM 	do {
236*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
237*9203SMark.Logan@Sun.COM 		{
238*9203SMark.Logan@Sun.COM 			break;
239*9203SMark.Logan@Sun.COM 		}
240*9203SMark.Logan@Sun.COM 		CFG_GET_PROVISIONING_MODE_RESPONSE *tmp_response = (CFG_GET_PROVISIONING_MODE_RESPONSE *)readBuffer;
241*9203SMark.Logan@Sun.COM 
242*9203SMark.Logan@Sun.COM 		mode = tmp_response->ProvisioningMode;
243*9203SMark.Logan@Sun.COM 
244*9203SMark.Logan@Sun.COM 	} while (0);
245*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
246*9203SMark.Logan@Sun.COM 	{
247*9203SMark.Logan@Sun.COM 		free(readBuffer);
248*9203SMark.Logan@Sun.COM 	}
249*9203SMark.Logan@Sun.COM 	return status;
250*9203SMark.Logan@Sun.COM }
GetProvisioningMode(CFG_PROVISIONING_MODE & mode,AMT_BOOLEAN & legacy)251*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetProvisioningMode(CFG_PROVISIONING_MODE &mode, AMT_BOOLEAN &legacy)
252*9203SMark.Logan@Sun.COM {
253*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
254*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(GET_PROVISIONING_MODE_HEADER);
255*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
256*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_PROVISIONING_MODE_HEADER), sizeof(GET_PROVISIONING_MODE_HEADER));
257*9203SMark.Logan@Sun.COM 
258*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, PROVISIONING_MODE_RESPONSE, sizeof(CFG_GET_PROVISIONING_MODE_RESPONSE));
259*9203SMark.Logan@Sun.COM 	do {
260*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
261*9203SMark.Logan@Sun.COM 		{
262*9203SMark.Logan@Sun.COM 			break;
263*9203SMark.Logan@Sun.COM 		}
264*9203SMark.Logan@Sun.COM 		CFG_GET_PROVISIONING_MODE_RESPONSE *tmp_response = (CFG_GET_PROVISIONING_MODE_RESPONSE *)readBuffer;
265*9203SMark.Logan@Sun.COM 
266*9203SMark.Logan@Sun.COM 		mode = tmp_response->ProvisioningMode;
267*9203SMark.Logan@Sun.COM 		legacy = tmp_response->LegacyMode;
268*9203SMark.Logan@Sun.COM 
269*9203SMark.Logan@Sun.COM 	} while (0);
270*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
271*9203SMark.Logan@Sun.COM 	{
272*9203SMark.Logan@Sun.COM 		free(readBuffer);
273*9203SMark.Logan@Sun.COM 	}
274*9203SMark.Logan@Sun.COM 	return status;
275*9203SMark.Logan@Sun.COM }
276*9203SMark.Logan@Sun.COM 
277*9203SMark.Logan@Sun.COM /*
278*9203SMark.Logan@Sun.COM * Calls to GetProvisioningState Host interface command
279*9203SMark.Logan@Sun.COM * Arguments:
280*9203SMark.Logan@Sun.COM *	state - reference to the pre-allocated structure
281*9203SMark.Logan@Sun.COM *       which will hold the result
282*9203SMark.Logan@Sun.COM * Return values:
283*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
284*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
285*9203SMark.Logan@Sun.COM */
GetProvisioningState(AMT_PROVISIONING_STATE & state)286*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetProvisioningState(AMT_PROVISIONING_STATE &state)
287*9203SMark.Logan@Sun.COM {
288*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
289*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(GET_PROVISIONING_STATE_HEADER);
290*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
291*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_PROVISIONING_STATE_HEADER), sizeof(GET_PROVISIONING_STATE_HEADER));
292*9203SMark.Logan@Sun.COM 
293*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, PROVISIONING_STATE_RESPONSE, sizeof(CFG_GET_PROVISIONING_STATE_RESPONSE));
294*9203SMark.Logan@Sun.COM 	do {
295*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
296*9203SMark.Logan@Sun.COM 		{
297*9203SMark.Logan@Sun.COM 			break;
298*9203SMark.Logan@Sun.COM 		}
299*9203SMark.Logan@Sun.COM 		CFG_GET_PROVISIONING_STATE_RESPONSE *tmp_response = (CFG_GET_PROVISIONING_STATE_RESPONSE *)readBuffer;
300*9203SMark.Logan@Sun.COM 
301*9203SMark.Logan@Sun.COM 		state = tmp_response->ProvisioningState;
302*9203SMark.Logan@Sun.COM 
303*9203SMark.Logan@Sun.COM 	} while (0);
304*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
305*9203SMark.Logan@Sun.COM 	{
306*9203SMark.Logan@Sun.COM 		free(readBuffer);
307*9203SMark.Logan@Sun.COM 	}
308*9203SMark.Logan@Sun.COM 	return status;
309*9203SMark.Logan@Sun.COM }
310*9203SMark.Logan@Sun.COM 
311*9203SMark.Logan@Sun.COM /*
312*9203SMark.Logan@Sun.COM * Calls to GetFeatureState Host interface command
313*9203SMark.Logan@Sun.COM * Arguments:
314*9203SMark.Logan@Sun.COM *	requestID Indicates what feature status to query:
315*9203SMark.Logan@Sun.COM *		0	Redirection Sessions Status
316*9203SMark.Logan@Sun.COM *		1	System Defense Status
317*9203SMark.Logan@Sun.COM *		2	WebUI Status
318*9203SMark.Logan@Sun.COM *  requestStatus The requested feature state(the size depand on the requestID).(OUT)
319*9203SMark.Logan@Sun.COM *
320*9203SMark.Logan@Sun.COM * Return values:
321*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
322*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
323*9203SMark.Logan@Sun.COM */
GetFeaturesState(UINT32 requestID,AMT_BOOLEAN (& requestStatus)[2])324*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetFeaturesState(UINT32 requestID, AMT_BOOLEAN (&requestStatus)[2])
325*9203SMark.Logan@Sun.COM {
326*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
327*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(CFG_GET_FEATURES_STATE_REQUEST);
328*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
329*9203SMark.Logan@Sun.COM 
330*9203SMark.Logan@Sun.COM 	memcpy(command, &GET_FEATURES_STATE_HEADER, sizeof(GET_FEATURES_STATE_HEADER));
331*9203SMark.Logan@Sun.COM 	memcpy(command + sizeof(GET_FEATURES_STATE_HEADER), &(requestID), sizeof(UINT32));
332*9203SMark.Logan@Sun.COM 
333*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, GET_FEATURES_STATE_RESPONSE, sizeof(CFG_GET_FEATURES_STATE_RESPONSE));
334*9203SMark.Logan@Sun.COM 	do {
335*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
336*9203SMark.Logan@Sun.COM 		{
337*9203SMark.Logan@Sun.COM 			break;
338*9203SMark.Logan@Sun.COM 		}
339*9203SMark.Logan@Sun.COM 		CFG_GET_FEATURES_STATE_RESPONSE *tmp_response = (CFG_GET_FEATURES_STATE_RESPONSE *)readBuffer;
340*9203SMark.Logan@Sun.COM 
341*9203SMark.Logan@Sun.COM 		GET_FEATURES_REDIRECTION_SESSION_STATUS redirectionState;
342*9203SMark.Logan@Sun.COM 		GET_FEATURES_SYSTEM_DEFENSE_STATUS_RESPONSE systemDefenseState;
343*9203SMark.Logan@Sun.COM 		GET_FEATURES_WEB_UI_STATUS_RESPONSE webUIState;
344*9203SMark.Logan@Sun.COM 		switch (requestID)
345*9203SMark.Logan@Sun.COM 		{
346*9203SMark.Logan@Sun.COM 		case REDIRECTION_SESSION:
347*9203SMark.Logan@Sun.COM 			redirectionState = tmp_response->Data.rs;
348*9203SMark.Logan@Sun.COM 			requestStatus[0] = redirectionState.SolOpen;
349*9203SMark.Logan@Sun.COM 			requestStatus[1] = redirectionState.IderOpen;
350*9203SMark.Logan@Sun.COM 			break;
351*9203SMark.Logan@Sun.COM 
352*9203SMark.Logan@Sun.COM 		case SYSTEM_DEFENSE:
353*9203SMark.Logan@Sun.COM 			systemDefenseState = tmp_response->Data.sd;
354*9203SMark.Logan@Sun.COM 			requestStatus[0] = systemDefenseState.SystemDefenseActivated;
355*9203SMark.Logan@Sun.COM 			break;
356*9203SMark.Logan@Sun.COM 
357*9203SMark.Logan@Sun.COM 		case WEB_UI:
358*9203SMark.Logan@Sun.COM 			webUIState = tmp_response->Data.webUI;
359*9203SMark.Logan@Sun.COM 			requestStatus[0] = webUIState.WebUiEnabled;
360*9203SMark.Logan@Sun.COM 			break;
361*9203SMark.Logan@Sun.COM 		}
362*9203SMark.Logan@Sun.COM 	} while (0);
363*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
364*9203SMark.Logan@Sun.COM 	{
365*9203SMark.Logan@Sun.COM 		free(readBuffer);
366*9203SMark.Logan@Sun.COM 	}
367*9203SMark.Logan@Sun.COM 	return status;
368*9203SMark.Logan@Sun.COM }
369*9203SMark.Logan@Sun.COM 
370*9203SMark.Logan@Sun.COM /*
371*9203SMark.Logan@Sun.COM * Calls to GetLastHostResetReason Host interface command
372*9203SMark.Logan@Sun.COM * Arguments:
373*9203SMark.Logan@Sun.COM *	reason Indicates whether the last host reason was because of remote control operation(0)
374*9203SMark.Logan@Sun.COM *		or other reason(1). (OUT)
375*9203SMark.Logan@Sun.COM *  remoteControlTimeStamp In case the reason was due to remote control then this field
376*9203SMark.Logan@Sun.COM *		indicates the timestamp of when the remote control command has been executed.
377*9203SMark.Logan@Sun.COM *		(The timestamp is the number of seconds since 1/1/1970)
378*9203SMark.Logan@Sun.COM *
379*9203SMark.Logan@Sun.COM * Return values:
380*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
381*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
382*9203SMark.Logan@Sun.COM */
GetLastHostResetReason(UINT32 & reason,UINT32 & remoteControlTimeStamp)383*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetLastHostResetReason(UINT32 &reason, UINT32 &remoteControlTimeStamp)
384*9203SMark.Logan@Sun.COM {
385*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
386*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(GET_LAST_HOST_RESET_REASON_HEADER);
387*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
388*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_LAST_HOST_RESET_REASON_HEADER), sizeof(GET_LAST_HOST_RESET_REASON_HEADER));
389*9203SMark.Logan@Sun.COM 
390*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, GET_LAST_HOST_RESET_REASON_RESPONSE, sizeof(CFG_GET_LAST_HOST_RESET_REASON_RESPONSE));
391*9203SMark.Logan@Sun.COM 	do {
392*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
393*9203SMark.Logan@Sun.COM 		{
394*9203SMark.Logan@Sun.COM 			break;
395*9203SMark.Logan@Sun.COM 		}
396*9203SMark.Logan@Sun.COM 		CFG_GET_LAST_HOST_RESET_REASON_RESPONSE *tmp_response = (CFG_GET_LAST_HOST_RESET_REASON_RESPONSE *)readBuffer;
397*9203SMark.Logan@Sun.COM 
398*9203SMark.Logan@Sun.COM 		reason = tmp_response->Reason;
399*9203SMark.Logan@Sun.COM 		remoteControlTimeStamp = tmp_response->RemoteControlTimeStamp;
400*9203SMark.Logan@Sun.COM 
401*9203SMark.Logan@Sun.COM 	} while (0);
402*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
403*9203SMark.Logan@Sun.COM 	{
404*9203SMark.Logan@Sun.COM 		free(readBuffer);
405*9203SMark.Logan@Sun.COM 	}
406*9203SMark.Logan@Sun.COM 	return status;
407*9203SMark.Logan@Sun.COM }
408*9203SMark.Logan@Sun.COM 
409*9203SMark.Logan@Sun.COM /*
410*9203SMark.Logan@Sun.COM * Calls to GetCurrentPowerPolicy Host interface command
411*9203SMark.Logan@Sun.COM * Arguments:
412*9203SMark.Logan@Sun.COM *	 policyName The power policy name. (OUT)
413*9203SMark.Logan@Sun.COM * Return values:
414*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
415*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
416*9203SMark.Logan@Sun.COM */
GetCurrentPowerPolicy(AMT_ANSI_STRING & policyName)417*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetCurrentPowerPolicy(AMT_ANSI_STRING &policyName)
418*9203SMark.Logan@Sun.COM {
419*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
420*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(GET_CURRENT_POWER_POLICY_HEADER);
421*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
422*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_CURRENT_POWER_POLICY_HEADER), sizeof(GET_CURRENT_POWER_POLICY_HEADER));
423*9203SMark.Logan@Sun.COM 
424*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, GET_CURRENT_POWER_POLICY_RESPONSE, 0);
425*9203SMark.Logan@Sun.COM 	do {
426*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
427*9203SMark.Logan@Sun.COM 		{
428*9203SMark.Logan@Sun.COM 			break;
429*9203SMark.Logan@Sun.COM 		}
430*9203SMark.Logan@Sun.COM 		CFG_GET_CURRENT_POWER_POLICY_RESPONSE *tmp_response = (CFG_GET_CURRENT_POWER_POLICY_RESPONSE *)readBuffer;
431*9203SMark.Logan@Sun.COM 		status = _verifyCurrentPowerPolicy(*tmp_response);
432*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
433*9203SMark.Logan@Sun.COM 		{
434*9203SMark.Logan@Sun.COM 			break;
435*9203SMark.Logan@Sun.COM 		}
436*9203SMark.Logan@Sun.COM 
437*9203SMark.Logan@Sun.COM 		policyName.Length = tmp_response->PolicyName.Length;
438*9203SMark.Logan@Sun.COM 		policyName.Buffer = (CHAR *)malloc(policyName.Length * sizeof(CHAR));
439*9203SMark.Logan@Sun.COM 		if (NULL == policyName.Buffer) {
440*9203SMark.Logan@Sun.COM 			status = AMT_STATUS_INTERNAL_ERROR;
441*9203SMark.Logan@Sun.COM 		} else {
442*9203SMark.Logan@Sun.COM 			memcpy(policyName.Buffer, &(tmp_response->PolicyName.Buffer),
443*9203SMark.Logan@Sun.COM 			       policyName.Length * sizeof(CHAR));
444*9203SMark.Logan@Sun.COM 		}
445*9203SMark.Logan@Sun.COM 	} while (0);
446*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
447*9203SMark.Logan@Sun.COM 	{
448*9203SMark.Logan@Sun.COM 		free(readBuffer);
449*9203SMark.Logan@Sun.COM 	}
450*9203SMark.Logan@Sun.COM 	return status;
451*9203SMark.Logan@Sun.COM }
452*9203SMark.Logan@Sun.COM 
453*9203SMark.Logan@Sun.COM /*
454*9203SMark.Logan@Sun.COM * Confirms the correctness of the GetCurrentPowerPolicy response message
455*9203SMark.Logan@Sun.COM * Arguments:
456*9203SMark.Logan@Sun.COM *	response - reference to the response message
457*9203SMark.Logan@Sun.COM * Return values:
458*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
459*9203SMark.Logan@Sun.COM *	PTSDK_STATUS_INTERNAL_ERROR - on failure
460*9203SMark.Logan@Sun.COM */
_verifyCurrentPowerPolicy(const CFG_GET_CURRENT_POWER_POLICY_RESPONSE & response)461*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::_verifyCurrentPowerPolicy(const CFG_GET_CURRENT_POWER_POLICY_RESPONSE &response)
462*9203SMark.Logan@Sun.COM {
463*9203SMark.Logan@Sun.COM 	ULONG ByteCount = response.Header.Header.Length;
464*9203SMark.Logan@Sun.COM 	if (ByteCount != (sizeof(CFG_GET_CURRENT_POWER_POLICY_RESPONSE)
465*9203SMark.Logan@Sun.COM 	                  - sizeof(PTHI_MESSAGE_HEADER) - sizeof(CHAR *)
466*9203SMark.Logan@Sun.COM 	                  + response.PolicyName.Length))
467*9203SMark.Logan@Sun.COM 	{
468*9203SMark.Logan@Sun.COM 		return PTSDK_STATUS_INTERNAL_ERROR;
469*9203SMark.Logan@Sun.COM 	}
470*9203SMark.Logan@Sun.COM 	return AMT_STATUS_SUCCESS;
471*9203SMark.Logan@Sun.COM }
472*9203SMark.Logan@Sun.COM 
473*9203SMark.Logan@Sun.COM /*
474*9203SMark.Logan@Sun.COM * Calls to GetLanInterfaceSttings Host interface command
475*9203SMark.Logan@Sun.COM * Arguments:
476*9203SMark.Logan@Sun.COM *	 interfaceSettings The interface to get the settings for.
477*9203SMark.Logan@Sun.COM *	 lanSettings reference to a pre allocated struct which will hold the lan settings. (OUT)
478*9203SMark.Logan@Sun.COM * Return values:
479*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
480*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
481*9203SMark.Logan@Sun.COM */
GetLanInterfaceSettings(UINT32 interfaceSettings,LAN_SETTINGS & lanSettings)482*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetLanInterfaceSettings(UINT32 interfaceSettings, LAN_SETTINGS &lanSettings)
483*9203SMark.Logan@Sun.COM {
484*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
485*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(CFG_GET_LAN_INTERFACE_SETTINGS_REQUEST);
486*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
487*9203SMark.Logan@Sun.COM 
488*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_LAN_INTERFACE_SETTINGS_HEADER), sizeof(GET_LAN_INTERFACE_SETTINGS_HEADER));
489*9203SMark.Logan@Sun.COM 	memcpy(command + sizeof(GET_LAN_INTERFACE_SETTINGS_HEADER),
490*9203SMark.Logan@Sun.COM 	       &(interfaceSettings), sizeof(UINT32));
491*9203SMark.Logan@Sun.COM 
492*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, GET_LAN_INTERFACE_SETTINGS_RESPONSE, sizeof(CFG_GET_LAN_INTERFACE_SETTINGS_RESPONSE));
493*9203SMark.Logan@Sun.COM 	do {
494*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
495*9203SMark.Logan@Sun.COM 		{
496*9203SMark.Logan@Sun.COM 			break;
497*9203SMark.Logan@Sun.COM 		}
498*9203SMark.Logan@Sun.COM 		CFG_GET_LAN_INTERFACE_SETTINGS_RESPONSE *tmp_response = (CFG_GET_LAN_INTERFACE_SETTINGS_RESPONSE *)readBuffer;
499*9203SMark.Logan@Sun.COM 
500*9203SMark.Logan@Sun.COM 		lanSettings.Enabled = tmp_response->Enabled;
501*9203SMark.Logan@Sun.COM 		lanSettings.Ipv4Address = tmp_response->Ipv4Address;
502*9203SMark.Logan@Sun.COM 		lanSettings.DhcpEnabled = tmp_response->DhcpEnabled;
503*9203SMark.Logan@Sun.COM 		lanSettings.DhcpIpMode = tmp_response->DhcpIpMode;
504*9203SMark.Logan@Sun.COM 		lanSettings.LinkStatus = tmp_response->LinkStatus;
505*9203SMark.Logan@Sun.COM 		memcpy(lanSettings.MacAddress, tmp_response->MacAddress, sizeof(tmp_response->MacAddress));
506*9203SMark.Logan@Sun.COM 
507*9203SMark.Logan@Sun.COM 	} while (0);
508*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
509*9203SMark.Logan@Sun.COM 	{
510*9203SMark.Logan@Sun.COM 		free(readBuffer);
511*9203SMark.Logan@Sun.COM 	}
512*9203SMark.Logan@Sun.COM 	return status;
513*9203SMark.Logan@Sun.COM }
514*9203SMark.Logan@Sun.COM 
515*9203SMark.Logan@Sun.COM /**
516*9203SMark.Logan@Sun.COM * Gets the HECI driver version
517*9203SMark.Logan@Sun.COM * Arguments:
518*9203SMark.Logan@Sun.COM *	heciVersion - pointewr to HECI_VERSION struct (out)
519*9203SMark.Logan@Sun.COM * Return values:
520*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
521*9203SMark.Logan@Sun.COM *	PTSDK_STATUS_INVALID_PARAM - on failure
522*9203SMark.Logan@Sun.COM */
GetHeciVersion(HECI_VERSION & heciVersion)523*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetHeciVersion(HECI_VERSION &heciVersion)
524*9203SMark.Logan@Sun.COM {
525*9203SMark.Logan@Sun.COM 	if (PTHIClient.GetHeciVersion(heciVersion)) {
526*9203SMark.Logan@Sun.COM 		return AMT_STATUS_SUCCESS;
527*9203SMark.Logan@Sun.COM 	}
528*9203SMark.Logan@Sun.COM 	return AMT_STATUS_INTERNAL_ERROR;
529*9203SMark.Logan@Sun.COM }
530*9203SMark.Logan@Sun.COM 
531*9203SMark.Logan@Sun.COM /*
532*9203SMark.Logan@Sun.COM * Calls to GetSecurityParameters Host interface command
533*9203SMark.Logan@Sun.COM * Arguments:
534*9203SMark.Logan@Sun.COM *	tlsEnabled true if AMT on TLS mode. (OUT)
535*9203SMark.Logan@Sun.COM * Return values:
536*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
537*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
538*9203SMark.Logan@Sun.COM */
GetTLSEnabled(AMT_BOOLEAN & tlsEnabled)539*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetTLSEnabled(AMT_BOOLEAN &tlsEnabled)
540*9203SMark.Logan@Sun.COM {
541*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
542*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(GET_SECURITY_PARAMETERS_HEADER);
543*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
544*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_SECURITY_PARAMETERS_HEADER), sizeof(GET_SECURITY_PARAMETERS_HEADER));
545*9203SMark.Logan@Sun.COM 
546*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, GET_SECURITY_PARAMETERS_RESPONSE, sizeof(CFG_GET_SECURITY_PARAMETERS_RESPONSE));
547*9203SMark.Logan@Sun.COM 	do {
548*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
549*9203SMark.Logan@Sun.COM 		{
550*9203SMark.Logan@Sun.COM 			break;
551*9203SMark.Logan@Sun.COM 		}
552*9203SMark.Logan@Sun.COM 		CFG_GET_SECURITY_PARAMETERS_RESPONSE *tmp_response = (CFG_GET_SECURITY_PARAMETERS_RESPONSE *)readBuffer;
553*9203SMark.Logan@Sun.COM 
554*9203SMark.Logan@Sun.COM 		tlsEnabled = tmp_response->TLSEnabled;
555*9203SMark.Logan@Sun.COM 
556*9203SMark.Logan@Sun.COM 	} while (0);
557*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
558*9203SMark.Logan@Sun.COM 	{
559*9203SMark.Logan@Sun.COM 		free(readBuffer);
560*9203SMark.Logan@Sun.COM 	}
561*9203SMark.Logan@Sun.COM 	return status;
562*9203SMark.Logan@Sun.COM }
563*9203SMark.Logan@Sun.COM 
564*9203SMark.Logan@Sun.COM /*
565*9203SMark.Logan@Sun.COM * Calls to GetDNSSuffixList Host interface command
566*9203SMark.Logan@Sun.COM * Arguments:
567*9203SMark.Logan@Sun.COM *	 dnsSuffixList reference to list of DNS suffix strings. (OUT)
568*9203SMark.Logan@Sun.COM * Return values:
569*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
570*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
571*9203SMark.Logan@Sun.COM */
GetDNSSuffixList(std::list<std::string> & dnsSuffixList)572*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetDNSSuffixList(std::list<std::string> &dnsSuffixList)
573*9203SMark.Logan@Sun.COM {
574*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
575*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(GET_DNS_SUFFIX_LIST_HEADER);
576*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
577*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_DNS_SUFFIX_LIST_HEADER), sizeof(GET_DNS_SUFFIX_LIST_HEADER));
578*9203SMark.Logan@Sun.COM 
579*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, GET_DNS_SUFFIX_LIST_RESPONSE, 0);
580*9203SMark.Logan@Sun.COM 	do {
581*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
582*9203SMark.Logan@Sun.COM 		{
583*9203SMark.Logan@Sun.COM 			break;
584*9203SMark.Logan@Sun.COM 		}
585*9203SMark.Logan@Sun.COM 		CFG_GET_DNS_SUFFIX_LIST_RESPONSE *tmp_response = (CFG_GET_DNS_SUFFIX_LIST_RESPONSE *)readBuffer;
586*9203SMark.Logan@Sun.COM 		status = _verifyGetDNSSuffixList(*tmp_response);
587*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
588*9203SMark.Logan@Sun.COM 		{
589*9203SMark.Logan@Sun.COM 			break;
590*9203SMark.Logan@Sun.COM 		}
591*9203SMark.Logan@Sun.COM 
592*9203SMark.Logan@Sun.COM 		char *current = (char *)tmp_response->Data;
593*9203SMark.Logan@Sun.COM 		while (current < (char *)tmp_response->Data + tmp_response->DataLength)
594*9203SMark.Logan@Sun.COM 		{
595*9203SMark.Logan@Sun.COM 			std::string dnsSuffix = current;
596*9203SMark.Logan@Sun.COM 			if (dnsSuffix.length() > tmp_response->DataLength)
597*9203SMark.Logan@Sun.COM 			{
598*9203SMark.Logan@Sun.COM 				status = PTSDK_STATUS_INTERNAL_ERROR;
599*9203SMark.Logan@Sun.COM 				break;
600*9203SMark.Logan@Sun.COM 			}
601*9203SMark.Logan@Sun.COM 			if (!dnsSuffix.empty())
602*9203SMark.Logan@Sun.COM 			{
603*9203SMark.Logan@Sun.COM 				dnsSuffixList.push_back(dnsSuffix);
604*9203SMark.Logan@Sun.COM 			}
605*9203SMark.Logan@Sun.COM 			current += dnsSuffix.length() + 1;
606*9203SMark.Logan@Sun.COM 		}
607*9203SMark.Logan@Sun.COM 	} while (0);
608*9203SMark.Logan@Sun.COM 
609*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
610*9203SMark.Logan@Sun.COM 	{
611*9203SMark.Logan@Sun.COM 		free(readBuffer);
612*9203SMark.Logan@Sun.COM 	}
613*9203SMark.Logan@Sun.COM 	return status;
614*9203SMark.Logan@Sun.COM }
615*9203SMark.Logan@Sun.COM 
616*9203SMark.Logan@Sun.COM /*
617*9203SMark.Logan@Sun.COM * Confirms the correctness of the GetDNSSuffixList response message
618*9203SMark.Logan@Sun.COM * Arguments:
619*9203SMark.Logan@Sun.COM *	response - reference to the response message
620*9203SMark.Logan@Sun.COM * Return values:
621*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
622*9203SMark.Logan@Sun.COM *	PTSDK_STATUS_INTERNAL_ERROR - on failure
623*9203SMark.Logan@Sun.COM */
_verifyGetDNSSuffixList(const CFG_GET_DNS_SUFFIX_LIST_RESPONSE & response)624*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::_verifyGetDNSSuffixList(const CFG_GET_DNS_SUFFIX_LIST_RESPONSE &response)
625*9203SMark.Logan@Sun.COM {
626*9203SMark.Logan@Sun.COM 	ULONG ByteCount = response.Header.Header.Length;
627*9203SMark.Logan@Sun.COM 	if (ByteCount != (sizeof(CFG_GET_DNS_SUFFIX_LIST_RESPONSE)
628*9203SMark.Logan@Sun.COM 	                  - sizeof(PTHI_MESSAGE_HEADER)
629*9203SMark.Logan@Sun.COM 	                  + response.DataLength))
630*9203SMark.Logan@Sun.COM 	{
631*9203SMark.Logan@Sun.COM 		return PTSDK_STATUS_INTERNAL_ERROR;
632*9203SMark.Logan@Sun.COM 	}
633*9203SMark.Logan@Sun.COM 	return AMT_STATUS_SUCCESS;
634*9203SMark.Logan@Sun.COM }
635*9203SMark.Logan@Sun.COM 
636*9203SMark.Logan@Sun.COM /*
637*9203SMark.Logan@Sun.COM * Calls to SetEnterpriseAccess Host interface command
638*9203SMark.Logan@Sun.COM * Arguments:
639*9203SMark.Logan@Sun.COM *	Flags flags
640*9203SMark.Logan@Sun.COM *	HostIPAddress host IP address for enterprise access
641*9203SMark.Logan@Sun.COM *	EnterpriseAccess enterprise access mode
642*9203SMark.Logan@Sun.COM * Return values:
643*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
644*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
645*9203SMark.Logan@Sun.COM */
SetEnterpriseAccess(UINT8 Flags,UINT8 HostIPAddress[16],UINT8 EnterpriseAccess)646*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::SetEnterpriseAccess(UINT8 Flags, UINT8 HostIPAddress[16], UINT8 EnterpriseAccess)
647*9203SMark.Logan@Sun.COM {
648*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
649*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(CFG_SET_ENTERPRISE_ACCESS_REQUEST);
650*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
651*9203SMark.Logan@Sun.COM 
652*9203SMark.Logan@Sun.COM 	memcpy(command, &(SET_ENTERPRISE_ACCESS_HEADER), sizeof(SET_ENTERPRISE_ACCESS_HEADER));
653*9203SMark.Logan@Sun.COM 	memcpy(command + sizeof(SET_ENTERPRISE_ACCESS_HEADER), &(Flags), sizeof(UINT8));
654*9203SMark.Logan@Sun.COM 	memcpy(command + sizeof(SET_ENTERPRISE_ACCESS_HEADER) + sizeof(UINT8), HostIPAddress, sizeof(HostIPAddress));
655*9203SMark.Logan@Sun.COM 	memcpy(command + sizeof(SET_ENTERPRISE_ACCESS_HEADER) + sizeof(UINT8) + sizeof(HostIPAddress), &(EnterpriseAccess), sizeof(UINT8));
656*9203SMark.Logan@Sun.COM 
657*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, SET_ENTERPRISE_ACCESS_RESPONSE, sizeof(CFG_SET_ENTERPRISE_ACCESS_RESPONSE));
658*9203SMark.Logan@Sun.COM 
659*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
660*9203SMark.Logan@Sun.COM 	{
661*9203SMark.Logan@Sun.COM 		free(readBuffer);
662*9203SMark.Logan@Sun.COM 	}
663*9203SMark.Logan@Sun.COM 	return status;
664*9203SMark.Logan@Sun.COM }
665*9203SMark.Logan@Sun.COM 
666*9203SMark.Logan@Sun.COM /*
667*9203SMark.Logan@Sun.COM * Get FW last reset reason
668*9203SMark.Logan@Sun.COM * Arguments:
669*9203SMark.Logan@Sun.COM *	reason - last FW reason
670*9203SMark.Logan@Sun.COM * Return values:
671*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
672*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
673*9203SMark.Logan@Sun.COM */
GetFWResetReason(UINT8 & MEResetReason)674*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetFWResetReason(UINT8 &MEResetReason)
675*9203SMark.Logan@Sun.COM {
676*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
677*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(STATE_GET_AMT_STATE_REQUEST);
678*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
679*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_AMT_STATE_HEADER), sizeof(GET_AMT_STATE_HEADER));
680*9203SMark.Logan@Sun.COM 	memcpy(command + sizeof(GET_AMT_STATE_HEADER), &(AMT_UUID_LINK_STATE), sizeof(AMT_UUID));
681*9203SMark.Logan@Sun.COM 
682*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, GET_AMT_STATE_RESPONSE, sizeof(STATE_GET_AMT_STATE_RESPONSE));
683*9203SMark.Logan@Sun.COM 	do {
684*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
685*9203SMark.Logan@Sun.COM 		{
686*9203SMark.Logan@Sun.COM 			break;
687*9203SMark.Logan@Sun.COM 		}
688*9203SMark.Logan@Sun.COM 		STATE_GET_AMT_STATE_RESPONSE *tmp_response = (STATE_GET_AMT_STATE_RESPONSE *)readBuffer;
689*9203SMark.Logan@Sun.COM 
690*9203SMark.Logan@Sun.COM 		MEResetReason = tmp_response->StateData.LastMEResetReason;
691*9203SMark.Logan@Sun.COM 
692*9203SMark.Logan@Sun.COM 	} while (0);
693*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
694*9203SMark.Logan@Sun.COM 	{
695*9203SMark.Logan@Sun.COM 		free(readBuffer);
696*9203SMark.Logan@Sun.COM 	}
697*9203SMark.Logan@Sun.COM 	return status;
698*9203SMark.Logan@Sun.COM }
699*9203SMark.Logan@Sun.COM 
700*9203SMark.Logan@Sun.COM /* Calls to OpenUserInitiatedConnection Host interface command
701*9203SMark.Logan@Sun.COM * Return values:
702*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
703*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
704*9203SMark.Logan@Sun.COM */
OpenUserInitiatedConnection()705*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::OpenUserInitiatedConnection()
706*9203SMark.Logan@Sun.COM {
707*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
708*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(OPEN_USER_INITIATED_CONNECTION_HEADER);
709*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
710*9203SMark.Logan@Sun.COM 	memcpy(command, &(OPEN_USER_INITIATED_CONNECTION_HEADER), sizeof(OPEN_USER_INITIATED_CONNECTION_HEADER));
711*9203SMark.Logan@Sun.COM 
712*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, OPEN_USER_INITIATED_CONNECTION_RESPONSE, sizeof(CFG_OPEN_USER_INITIATED_CONNECTION_RESPONSE));
713*9203SMark.Logan@Sun.COM 
714*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
715*9203SMark.Logan@Sun.COM 	{
716*9203SMark.Logan@Sun.COM 		free(readBuffer);
717*9203SMark.Logan@Sun.COM 	}
718*9203SMark.Logan@Sun.COM 	return status;
719*9203SMark.Logan@Sun.COM }
720*9203SMark.Logan@Sun.COM 
721*9203SMark.Logan@Sun.COM /* Calls to CloseUserInitiatedConnection Host interface command
722*9203SMark.Logan@Sun.COM * Return values:
723*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
724*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
725*9203SMark.Logan@Sun.COM */
CloseUserInitiatedConnection()726*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::CloseUserInitiatedConnection()
727*9203SMark.Logan@Sun.COM {
728*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
729*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(CLOSE_USER_INITIATED_CONNECTION_HEADER);
730*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
731*9203SMark.Logan@Sun.COM 	memcpy(command, &(CLOSE_USER_INITIATED_CONNECTION_HEADER), sizeof(CLOSE_USER_INITIATED_CONNECTION_HEADER));
732*9203SMark.Logan@Sun.COM 
733*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, CLOSE_USER_INITIATED_CONNECTION_RESPONSE, sizeof(CFG_CLOSE_USER_INITIATED_CONNECTION_RESPONSE));
734*9203SMark.Logan@Sun.COM 
735*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
736*9203SMark.Logan@Sun.COM 	{
737*9203SMark.Logan@Sun.COM 		free(readBuffer);
738*9203SMark.Logan@Sun.COM 	}
739*9203SMark.Logan@Sun.COM 	return status;
740*9203SMark.Logan@Sun.COM }
741*9203SMark.Logan@Sun.COM 
742*9203SMark.Logan@Sun.COM /* Calls to GetRemoteAccessConnectionStatus Host interface command
743*9203SMark.Logan@Sun.COM * Return values:
744*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
745*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
746*9203SMark.Logan@Sun.COM */
GetRemoteAccessConnectionStatus(REMOTE_ACCESS_STATUS & remoteAccessStatus)747*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetRemoteAccessConnectionStatus(REMOTE_ACCESS_STATUS &remoteAccessStatus)
748*9203SMark.Logan@Sun.COM {
749*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
750*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(GET_REMOTE_ACCESS_CONNECTION_STATUS_HEADER);
751*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
752*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_REMOTE_ACCESS_CONNECTION_STATUS_HEADER), sizeof(GET_REMOTE_ACCESS_CONNECTION_STATUS_HEADER));
753*9203SMark.Logan@Sun.COM 
754*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, GET_REMOTE_ACCESS_CONNECTION_STATUS_RESPONSE, 0);
755*9203SMark.Logan@Sun.COM 	do {
756*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
757*9203SMark.Logan@Sun.COM 		{
758*9203SMark.Logan@Sun.COM 			break;
759*9203SMark.Logan@Sun.COM 		}
760*9203SMark.Logan@Sun.COM 		CFG_GET_REMOTE_ACCESS_CONNECTION_STATUS_RESPONSE *tmp_response = (CFG_GET_REMOTE_ACCESS_CONNECTION_STATUS_RESPONSE *)readBuffer;
761*9203SMark.Logan@Sun.COM 		status = _verifyRemoteAccessConnectionStatus(*tmp_response);
762*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
763*9203SMark.Logan@Sun.COM 		{
764*9203SMark.Logan@Sun.COM 			break;
765*9203SMark.Logan@Sun.COM 		}
766*9203SMark.Logan@Sun.COM 
767*9203SMark.Logan@Sun.COM 		remoteAccessStatus.AmtNetworkConnectionStatus    = tmp_response->AmtNetworkConnectionStatus;
768*9203SMark.Logan@Sun.COM 		remoteAccessStatus.RemoteAccessConnectionStatus  = tmp_response->RemoteAccessConnectionStatus;
769*9203SMark.Logan@Sun.COM 		remoteAccessStatus.RemoteAccessConnectionTrigger = tmp_response->RemoteAccessConnectionTrigger;
770*9203SMark.Logan@Sun.COM 
771*9203SMark.Logan@Sun.COM 		remoteAccessStatus.MpsHostname.Length = tmp_response->MpsHostname.Length;
772*9203SMark.Logan@Sun.COM 		remoteAccessStatus.MpsHostname.Buffer = (CHAR *)malloc(remoteAccessStatus.MpsHostname.Length * sizeof(CHAR));
773*9203SMark.Logan@Sun.COM 		if (NULL == remoteAccessStatus.MpsHostname.Buffer) {
774*9203SMark.Logan@Sun.COM 			status = AMT_STATUS_INTERNAL_ERROR;
775*9203SMark.Logan@Sun.COM 		} else {
776*9203SMark.Logan@Sun.COM 			memcpy(remoteAccessStatus.MpsHostname.Buffer,
777*9203SMark.Logan@Sun.COM 			       &(tmp_response->MpsHostname.Buffer),
778*9203SMark.Logan@Sun.COM 			       tmp_response->MpsHostname.Length * sizeof(CHAR));
779*9203SMark.Logan@Sun.COM 		}
780*9203SMark.Logan@Sun.COM 	} while (0);
781*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
782*9203SMark.Logan@Sun.COM 	{
783*9203SMark.Logan@Sun.COM 		free(readBuffer);
784*9203SMark.Logan@Sun.COM 	}
785*9203SMark.Logan@Sun.COM 	return status;
786*9203SMark.Logan@Sun.COM }
787*9203SMark.Logan@Sun.COM 
788*9203SMark.Logan@Sun.COM /*
789*9203SMark.Logan@Sun.COM * Confirms the correctness of the GetRemoteAccessConnectionStatus response message
790*9203SMark.Logan@Sun.COM * Arguments:
791*9203SMark.Logan@Sun.COM *	response - reference to the response message
792*9203SMark.Logan@Sun.COM * Return values:
793*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
794*9203SMark.Logan@Sun.COM *	PTSDK_STATUS_INTERNAL_ERROR - on failure
795*9203SMark.Logan@Sun.COM */
_verifyRemoteAccessConnectionStatus(const CFG_GET_REMOTE_ACCESS_CONNECTION_STATUS_RESPONSE & response)796*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::_verifyRemoteAccessConnectionStatus(const CFG_GET_REMOTE_ACCESS_CONNECTION_STATUS_RESPONSE &response)
797*9203SMark.Logan@Sun.COM {
798*9203SMark.Logan@Sun.COM 	ULONG ByteCount = response.Header.Header.Length;
799*9203SMark.Logan@Sun.COM 	if (ByteCount != (sizeof(CFG_GET_REMOTE_ACCESS_CONNECTION_STATUS_RESPONSE)
800*9203SMark.Logan@Sun.COM 			  - sizeof(PTHI_MESSAGE_HEADER) - sizeof(CHAR *)
801*9203SMark.Logan@Sun.COM 			  + response.MpsHostname.Length))
802*9203SMark.Logan@Sun.COM 	{
803*9203SMark.Logan@Sun.COM 		return PTSDK_STATUS_INTERNAL_ERROR;
804*9203SMark.Logan@Sun.COM 	}
805*9203SMark.Logan@Sun.COM 	return AMT_STATUS_SUCCESS;
806*9203SMark.Logan@Sun.COM }
807*9203SMark.Logan@Sun.COM 
808*9203SMark.Logan@Sun.COM /*
809*9203SMark.Logan@Sun.COM * Calls to GenerateRngKey Host interface command
810*9203SMark.Logan@Sun.COM * Arguments:
811*9203SMark.Logan@Sun.COM *	None
812*9203SMark.Logan@Sun.COM * Return values:
813*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - or AMT_STATUS_IN_PROGRESS on success
814*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
815*9203SMark.Logan@Sun.COM */
GenerateRngKey()816*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GenerateRngKey()
817*9203SMark.Logan@Sun.COM {
818*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
819*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(GENERATE_RNG_SEED_HEADER);
820*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
821*9203SMark.Logan@Sun.COM 	memcpy(command, &(GENERATE_RNG_SEED_HEADER), sizeof(GENERATE_RNG_SEED_HEADER));
822*9203SMark.Logan@Sun.COM 
823*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, GENERATE_RNG_SEED_RESPONSE, sizeof(CFG_GENERATE_RNG_SEED_RESPONSE));
824*9203SMark.Logan@Sun.COM 
825*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
826*9203SMark.Logan@Sun.COM 	{
827*9203SMark.Logan@Sun.COM 		free(readBuffer);
828*9203SMark.Logan@Sun.COM 	}
829*9203SMark.Logan@Sun.COM 	return status;
830*9203SMark.Logan@Sun.COM }
831*9203SMark.Logan@Sun.COM 
832*9203SMark.Logan@Sun.COM /*
833*9203SMark.Logan@Sun.COM * Calls to GetRngSeedStatus Host interface command
834*9203SMark.Logan@Sun.COM * Arguments:
835*9203SMark.Logan@Sun.COM *	rngStatus - reference to the pre-allocated structure
836*9203SMark.Logan@Sun.COM *	   which will hold the result
837*9203SMark.Logan@Sun.COM * Return values:
838*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
839*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
840*9203SMark.Logan@Sun.COM */
GetRngSeedStatus(AMT_RNG_STATUS & rngStatus)841*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetRngSeedStatus(AMT_RNG_STATUS &rngStatus)
842*9203SMark.Logan@Sun.COM {
843*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
844*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(GET_RNG_SEED_STATUS_HEADER);
845*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
846*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_RNG_SEED_STATUS_HEADER), sizeof(GET_RNG_SEED_STATUS_HEADER));
847*9203SMark.Logan@Sun.COM 
848*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, GET_RNG_SEED_STATUS_RESPONSE, sizeof(CFG_GET_RNG_SEED_STATUS_RESPONSE));
849*9203SMark.Logan@Sun.COM 
850*9203SMark.Logan@Sun.COM 	CFG_GET_RNG_SEED_STATUS_RESPONSE *tmp_response = (CFG_GET_RNG_SEED_STATUS_RESPONSE *)readBuffer;
851*9203SMark.Logan@Sun.COM 
852*9203SMark.Logan@Sun.COM 	rngStatus = tmp_response->RngStatus;
853*9203SMark.Logan@Sun.COM 
854*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
855*9203SMark.Logan@Sun.COM 	{
856*9203SMark.Logan@Sun.COM 		free(readBuffer);
857*9203SMark.Logan@Sun.COM 	}
858*9203SMark.Logan@Sun.COM 	return status;
859*9203SMark.Logan@Sun.COM }
860*9203SMark.Logan@Sun.COM 
861*9203SMark.Logan@Sun.COM /*
862*9203SMark.Logan@Sun.COM * Calls to ZeroTouchEnabled Host interface command
863*9203SMark.Logan@Sun.COM * Arguments:
864*9203SMark.Logan@Sun.COM *	zeroTouchEnabled - reference to the pre-allocated structure
865*9203SMark.Logan@Sun.COM *	   which will hold the result
866*9203SMark.Logan@Sun.COM * Return values:
867*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
868*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
869*9203SMark.Logan@Sun.COM */
GetZeroTouchEnabled(AMT_BOOLEAN & zeroTouchEnabled)870*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetZeroTouchEnabled(AMT_BOOLEAN &zeroTouchEnabled)
871*9203SMark.Logan@Sun.COM {
872*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
873*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(GET_ZERO_TOUCH_ENABLED_HEADER);
874*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
875*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_ZERO_TOUCH_ENABLED_HEADER), sizeof(GET_ZERO_TOUCH_ENABLED_HEADER));
876*9203SMark.Logan@Sun.COM 
877*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, GET_ZERO_TOUCH_ENABLED_RESPONSE, sizeof(CFG_GET_ZERO_TOUCH_ENABLED_RESPONSE));
878*9203SMark.Logan@Sun.COM 
879*9203SMark.Logan@Sun.COM 	CFG_GET_ZERO_TOUCH_ENABLED_RESPONSE *tmp_response = (CFG_GET_ZERO_TOUCH_ENABLED_RESPONSE *)readBuffer;
880*9203SMark.Logan@Sun.COM 
881*9203SMark.Logan@Sun.COM 	zeroTouchEnabled = tmp_response->ZeroTouchEnabled;
882*9203SMark.Logan@Sun.COM 
883*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
884*9203SMark.Logan@Sun.COM 	{
885*9203SMark.Logan@Sun.COM 		free(readBuffer);
886*9203SMark.Logan@Sun.COM 	}
887*9203SMark.Logan@Sun.COM 	return status;
888*9203SMark.Logan@Sun.COM }
889*9203SMark.Logan@Sun.COM 
890*9203SMark.Logan@Sun.COM /*
891*9203SMark.Logan@Sun.COM * Calls to GetProvisioningTlsMode Host interface command
892*9203SMark.Logan@Sun.COM * Arguments:
893*9203SMark.Logan@Sun.COM *	provisioningTlsMode - reference to the pre-allocated structure
894*9203SMark.Logan@Sun.COM *	   which will hold the result
895*9203SMark.Logan@Sun.COM * Return values:
896*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
897*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
898*9203SMark.Logan@Sun.COM */
GetProvisioningTlsMode(AMT_PROVISIONING_TLS_MODE & provisioningTlsMode)899*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetProvisioningTlsMode(AMT_PROVISIONING_TLS_MODE &provisioningTlsMode)
900*9203SMark.Logan@Sun.COM {
901*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
902*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(GET_PROVISIONING_TLS_MODE_HEADER);
903*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
904*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_PROVISIONING_TLS_MODE_HEADER), sizeof(GET_PROVISIONING_TLS_MODE_HEADER));
905*9203SMark.Logan@Sun.COM 
906*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, GET_PROVISIONING_TLS_MODE_RESPONSE, sizeof(CFG_GET_PROVISIONING_TLS_MODE_RESPONSE));
907*9203SMark.Logan@Sun.COM 
908*9203SMark.Logan@Sun.COM 	CFG_GET_PROVISIONING_TLS_MODE_RESPONSE *tmp_response = (CFG_GET_PROVISIONING_TLS_MODE_RESPONSE *)readBuffer;
909*9203SMark.Logan@Sun.COM 
910*9203SMark.Logan@Sun.COM 	provisioningTlsMode = tmp_response->ProvisioningTlsMode;
911*9203SMark.Logan@Sun.COM 
912*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
913*9203SMark.Logan@Sun.COM 	{
914*9203SMark.Logan@Sun.COM 		free(readBuffer);
915*9203SMark.Logan@Sun.COM 	}
916*9203SMark.Logan@Sun.COM 	return status;
917*9203SMark.Logan@Sun.COM }
918*9203SMark.Logan@Sun.COM 
919*9203SMark.Logan@Sun.COM /*
920*9203SMark.Logan@Sun.COM * Calls to StartConfiguration Host interface command
921*9203SMark.Logan@Sun.COM * Arguments:
922*9203SMark.Logan@Sun.COM *	None
923*9203SMark.Logan@Sun.COM * Return values:
924*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - or AMT_STATUS_CERTIFICATE_NOT_READY on success
925*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
926*9203SMark.Logan@Sun.COM */
StartConfiguration()927*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::StartConfiguration()
928*9203SMark.Logan@Sun.COM {
929*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
930*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(START_CONFIGURATION_HEADER);
931*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
932*9203SMark.Logan@Sun.COM 	memcpy(command, &(START_CONFIGURATION_HEADER), sizeof(START_CONFIGURATION_HEADER));
933*9203SMark.Logan@Sun.COM 
934*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, START_CONFIGURATION_RESPONSE, sizeof(CFG_START_CONFIGURATION_RESPONSE));
935*9203SMark.Logan@Sun.COM 
936*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
937*9203SMark.Logan@Sun.COM 	{
938*9203SMark.Logan@Sun.COM 		free(readBuffer);
939*9203SMark.Logan@Sun.COM 	}
940*9203SMark.Logan@Sun.COM 	return status;
941*9203SMark.Logan@Sun.COM }
942*9203SMark.Logan@Sun.COM 
943*9203SMark.Logan@Sun.COM /*
944*9203SMark.Logan@Sun.COM * Calls to SetProvisioningServerOTP Host interface command
945*9203SMark.Logan@Sun.COM * Arguments:
946*9203SMark.Logan@Sun.COM *	passwordOTP AMT_ANSI_STRING structure of OTP password
947*9203SMark.Logan@Sun.COM * Return values:
948*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
949*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
950*9203SMark.Logan@Sun.COM */
SetProvisioningServerOTP(AMT_ANSI_STRING passwordOTP)951*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::SetProvisioningServerOTP(AMT_ANSI_STRING passwordOTP)
952*9203SMark.Logan@Sun.COM {
953*9203SMark.Logan@Sun.COM 	if (NULL == passwordOTP.Buffer)
954*9203SMark.Logan@Sun.COM 	{
955*9203SMark.Logan@Sun.COM 		return PTSDK_STATUS_INVALID_PARAM;
956*9203SMark.Logan@Sun.COM 	}
957*9203SMark.Logan@Sun.COM 
958*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
959*9203SMark.Logan@Sun.COM 	UINT32 msgLength = sizeof(passwordOTP.Length) + (passwordOTP.Length * sizeof(CHAR));
960*9203SMark.Logan@Sun.COM 	PTHI_MESSAGE_HEADER SET_PROVISIONING_SERVER_OTP_HEADER = {
961*9203SMark.Logan@Sun.COM 		{AMT_MAJOR_VERSION, AMT_MINOR_VERSION}, 0, {{SET_PROVISIONING_SERVER_OTP_REQUEST}}, msgLength
962*9203SMark.Logan@Sun.COM 	};
963*9203SMark.Logan@Sun.COM 
964*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(SET_PROVISIONING_SERVER_OTP_HEADER) + msgLength;
965*9203SMark.Logan@Sun.COM 	unsigned char *command;
966*9203SMark.Logan@Sun.COM 	command = (unsigned char *)malloc(command_size);
967*9203SMark.Logan@Sun.COM 	if (NULL == command)
968*9203SMark.Logan@Sun.COM 	{
969*9203SMark.Logan@Sun.COM 		return PTSDK_STATUS_INTERNAL_ERROR;
970*9203SMark.Logan@Sun.COM 	}
971*9203SMark.Logan@Sun.COM 	memcpy(command, &SET_PROVISIONING_SERVER_OTP_HEADER, sizeof(SET_PROVISIONING_SERVER_OTP_HEADER));
972*9203SMark.Logan@Sun.COM 	memcpy(command + sizeof(SET_PROVISIONING_SERVER_OTP_HEADER), &(passwordOTP.Length), sizeof(passwordOTP.Length));
973*9203SMark.Logan@Sun.COM 	memcpy(command + sizeof(SET_PROVISIONING_SERVER_OTP_HEADER) + sizeof(passwordOTP.Length),
974*9203SMark.Logan@Sun.COM 		passwordOTP.Buffer, passwordOTP.Length);
975*9203SMark.Logan@Sun.COM 
976*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, SET_PROVISIONING_SERVER_OTP_RESPONSE, sizeof(CFG_SET_PROVISIONING_SERVER_OTP_RESPONSE));
977*9203SMark.Logan@Sun.COM 
978*9203SMark.Logan@Sun.COM 	if (NULL != command)
979*9203SMark.Logan@Sun.COM 	{
980*9203SMark.Logan@Sun.COM 		free(command);
981*9203SMark.Logan@Sun.COM 	}
982*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
983*9203SMark.Logan@Sun.COM 	{
984*9203SMark.Logan@Sun.COM 		free(readBuffer);
985*9203SMark.Logan@Sun.COM 	}
986*9203SMark.Logan@Sun.COM 	return status;
987*9203SMark.Logan@Sun.COM }
988*9203SMark.Logan@Sun.COM 
989*9203SMark.Logan@Sun.COM /*
990*9203SMark.Logan@Sun.COM * Calls to SetDnsSuffix Host interface command
991*9203SMark.Logan@Sun.COM * Arguments:
992*9203SMark.Logan@Sun.COM *	dnsSuffix AMT_ANSI_STRING structure of DNS suffix
993*9203SMark.Logan@Sun.COM * Return values:
994*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
995*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
996*9203SMark.Logan@Sun.COM */
SetDnsSuffix(AMT_ANSI_STRING dnsSuffix)997*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::SetDnsSuffix(AMT_ANSI_STRING dnsSuffix)
998*9203SMark.Logan@Sun.COM {
999*9203SMark.Logan@Sun.COM 	if (NULL == dnsSuffix.Buffer)
1000*9203SMark.Logan@Sun.COM 	{
1001*9203SMark.Logan@Sun.COM 		return PTSDK_STATUS_INVALID_PARAM;
1002*9203SMark.Logan@Sun.COM 	}
1003*9203SMark.Logan@Sun.COM 
1004*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
1005*9203SMark.Logan@Sun.COM 	UINT32 msgLength = sizeof(dnsSuffix.Length) + (dnsSuffix.Length * sizeof(CHAR));
1006*9203SMark.Logan@Sun.COM 	PTHI_MESSAGE_HEADER SET_DNS_SUFFIX_HEADER = {
1007*9203SMark.Logan@Sun.COM 		{AMT_MAJOR_VERSION, AMT_MINOR_VERSION}, 0, {{SET_DNS_SUFFIX_REQUEST}}, msgLength
1008*9203SMark.Logan@Sun.COM 	};
1009*9203SMark.Logan@Sun.COM 
1010*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(SET_DNS_SUFFIX_HEADER) + msgLength;
1011*9203SMark.Logan@Sun.COM 	unsigned char *command;
1012*9203SMark.Logan@Sun.COM 	command = (unsigned char *)malloc(command_size);
1013*9203SMark.Logan@Sun.COM 	if (NULL == command)
1014*9203SMark.Logan@Sun.COM 	{
1015*9203SMark.Logan@Sun.COM 		return PTSDK_STATUS_INTERNAL_ERROR;
1016*9203SMark.Logan@Sun.COM 	}
1017*9203SMark.Logan@Sun.COM 	memcpy(command, &SET_DNS_SUFFIX_HEADER, sizeof(SET_DNS_SUFFIX_HEADER));
1018*9203SMark.Logan@Sun.COM 	memcpy(command + sizeof(SET_DNS_SUFFIX_HEADER), &(dnsSuffix.Length), sizeof(dnsSuffix.Length));
1019*9203SMark.Logan@Sun.COM 	memcpy(command + sizeof(SET_DNS_SUFFIX_HEADER) + sizeof(dnsSuffix.Length), dnsSuffix.Buffer, dnsSuffix.Length);
1020*9203SMark.Logan@Sun.COM 
1021*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, SET_DNS_SUFFIX_RESPONSE, sizeof(CFG_SET_DNS_SUFFIX_RESPONSE));
1022*9203SMark.Logan@Sun.COM 
1023*9203SMark.Logan@Sun.COM 	if (NULL != command)
1024*9203SMark.Logan@Sun.COM 	{
1025*9203SMark.Logan@Sun.COM 		free(command);
1026*9203SMark.Logan@Sun.COM 	}
1027*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
1028*9203SMark.Logan@Sun.COM 	{
1029*9203SMark.Logan@Sun.COM 		free(readBuffer);
1030*9203SMark.Logan@Sun.COM 	}
1031*9203SMark.Logan@Sun.COM 	return status;
1032*9203SMark.Logan@Sun.COM }
1033*9203SMark.Logan@Sun.COM 
1034*9203SMark.Logan@Sun.COM /*
1035*9203SMark.Logan@Sun.COM * Calls to EnumerateHashHandles Host interface command
1036*9203SMark.Logan@Sun.COM * Arguments:
1037*9203SMark.Logan@Sun.COM *	hashHandles - reference to the pre-allocated structure
1038*9203SMark.Logan@Sun.COM *	   which will hold the result
1039*9203SMark.Logan@Sun.COM * Return values:
1040*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
1041*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
1042*9203SMark.Logan@Sun.COM */
EnumerateHashHandles(AMT_HASH_HANDLES & hashHandles)1043*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::EnumerateHashHandles(AMT_HASH_HANDLES &hashHandles)
1044*9203SMark.Logan@Sun.COM {
1045*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
1046*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(ENUMERATE_HASH_HANDLES_HEADER);
1047*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
1048*9203SMark.Logan@Sun.COM 	memcpy(command, &(ENUMERATE_HASH_HANDLES_HEADER), sizeof(ENUMERATE_HASH_HANDLES_HEADER));
1049*9203SMark.Logan@Sun.COM 
1050*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, ENUMERATE_HASH_HANDLES_RESPONSE, 0);
1051*9203SMark.Logan@Sun.COM 	do {
1052*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
1053*9203SMark.Logan@Sun.COM 		{
1054*9203SMark.Logan@Sun.COM 			break;
1055*9203SMark.Logan@Sun.COM 		}
1056*9203SMark.Logan@Sun.COM 		CFG_GET_HASH_HANDLES_RESPONSE *tmp_response = (CFG_GET_HASH_HANDLES_RESPONSE *)readBuffer;
1057*9203SMark.Logan@Sun.COM 		status = _verifyHashHandles(*tmp_response);
1058*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
1059*9203SMark.Logan@Sun.COM 		{
1060*9203SMark.Logan@Sun.COM 			break;
1061*9203SMark.Logan@Sun.COM 		}
1062*9203SMark.Logan@Sun.COM 
1063*9203SMark.Logan@Sun.COM 		memset(hashHandles.Handles, 0, sizeof(UINT32) * CERT_HASH_MAX_NUMBER);
1064*9203SMark.Logan@Sun.COM 		hashHandles.Length = tmp_response->HashHandles.Length;
1065*9203SMark.Logan@Sun.COM 		if (CERT_HASH_MAX_NUMBER < hashHandles.Length)
1066*9203SMark.Logan@Sun.COM 		{
1067*9203SMark.Logan@Sun.COM 			status = PTSDK_STATUS_INTERNAL_ERROR;
1068*9203SMark.Logan@Sun.COM 			break;
1069*9203SMark.Logan@Sun.COM 		}
1070*9203SMark.Logan@Sun.COM 
1071*9203SMark.Logan@Sun.COM 		memcpy(hashHandles.Handles, tmp_response->HashHandles.Handles, sizeof(UINT32) * hashHandles.Length);
1072*9203SMark.Logan@Sun.COM 
1073*9203SMark.Logan@Sun.COM 	} while (0);
1074*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
1075*9203SMark.Logan@Sun.COM 	{
1076*9203SMark.Logan@Sun.COM 		free(readBuffer);
1077*9203SMark.Logan@Sun.COM 	}
1078*9203SMark.Logan@Sun.COM 	return status;
1079*9203SMark.Logan@Sun.COM }
1080*9203SMark.Logan@Sun.COM 
1081*9203SMark.Logan@Sun.COM /*
1082*9203SMark.Logan@Sun.COM * Confirms the correctness of the EnumerateHashHandles response message
1083*9203SMark.Logan@Sun.COM * Arguments:
1084*9203SMark.Logan@Sun.COM *	response - reference to the response message
1085*9203SMark.Logan@Sun.COM * Return values:
1086*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
1087*9203SMark.Logan@Sun.COM *	PTSDK_STATUS_INTERNAL_ERROR - on failure
1088*9203SMark.Logan@Sun.COM */
_verifyHashHandles(const CFG_GET_HASH_HANDLES_RESPONSE & response)1089*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::_verifyHashHandles(const CFG_GET_HASH_HANDLES_RESPONSE &response)
1090*9203SMark.Logan@Sun.COM {
1091*9203SMark.Logan@Sun.COM 	ULONG ByteCount = response.Header.Header.Length;
1092*9203SMark.Logan@Sun.COM 
1093*9203SMark.Logan@Sun.COM 	if (ByteCount !=
1094*9203SMark.Logan@Sun.COM 		sizeof(AMT_STATUS) + sizeof(response.HashHandles.Length) + (sizeof(UINT32) * response.HashHandles.Length))
1095*9203SMark.Logan@Sun.COM 	{
1096*9203SMark.Logan@Sun.COM 		return PTSDK_STATUS_INTERNAL_ERROR;
1097*9203SMark.Logan@Sun.COM 	}
1098*9203SMark.Logan@Sun.COM 	return AMT_STATUS_SUCCESS;
1099*9203SMark.Logan@Sun.COM }
1100*9203SMark.Logan@Sun.COM 
1101*9203SMark.Logan@Sun.COM 
1102*9203SMark.Logan@Sun.COM /*
1103*9203SMark.Logan@Sun.COM * Calls to GetCertificateHashEntry Host interface command
1104*9203SMark.Logan@Sun.COM * Arguments:
1105*9203SMark.Logan@Sun.COM *	passwordOTP AMT_ANSI_STRING structure of DNS suffix
1106*9203SMark.Logan@Sun.COM * Return values:
1107*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
1108*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
1109*9203SMark.Logan@Sun.COM */
GetCertificateHashEntry(UINT32 hashHandle,CERTHASH_ENTRY & hashEntry)1110*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetCertificateHashEntry(UINT32 hashHandle, CERTHASH_ENTRY &hashEntry)
1111*9203SMark.Logan@Sun.COM {
1112*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
1113*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(CFG_GET_CERTHASH_ENTRY_REQUEST);
1114*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
1115*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_CERTHASH_ENTRY_HEADER), sizeof(GET_CERTHASH_ENTRY_HEADER));
1116*9203SMark.Logan@Sun.COM 	memcpy(command + sizeof(GET_CERTHASH_ENTRY_HEADER), &(hashHandle), sizeof(hashHandle));
1117*9203SMark.Logan@Sun.COM 
1118*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, GET_CERTHASH_ENTRY_RESPONSE, 0);
1119*9203SMark.Logan@Sun.COM 	do {
1120*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
1121*9203SMark.Logan@Sun.COM 		{
1122*9203SMark.Logan@Sun.COM 			break;
1123*9203SMark.Logan@Sun.COM 		}
1124*9203SMark.Logan@Sun.COM 		CFG_GET_CERTHASH_ENTRY_RESPONSE *tmp_response = (CFG_GET_CERTHASH_ENTRY_RESPONSE *)readBuffer;
1125*9203SMark.Logan@Sun.COM 		status = _verifyGetCertificateHashEntry(*tmp_response);
1126*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
1127*9203SMark.Logan@Sun.COM 		{
1128*9203SMark.Logan@Sun.COM 			break;
1129*9203SMark.Logan@Sun.COM 		}
1130*9203SMark.Logan@Sun.COM 
1131*9203SMark.Logan@Sun.COM 		hashEntry.IsActive = tmp_response->Hash.IsActive;
1132*9203SMark.Logan@Sun.COM 		hashEntry.IsDefault = tmp_response->Hash.IsDefault;
1133*9203SMark.Logan@Sun.COM 		hashEntry.Name.Length = tmp_response->Hash.Name.Length;
1134*9203SMark.Logan@Sun.COM 		hashEntry.HashAlgorithm = tmp_response->Hash.HashAlgorithm;
1135*9203SMark.Logan@Sun.COM 		memcpy(hashEntry.CertificateHash, tmp_response->Hash.CertificateHash, sizeof(tmp_response->Hash.CertificateHash));
1136*9203SMark.Logan@Sun.COM 		hashEntry.Name.Buffer = (CHAR *)malloc(hashEntry.Name.Length * sizeof(CHAR));
1137*9203SMark.Logan@Sun.COM 		if (NULL == hashEntry.Name.Buffer)
1138*9203SMark.Logan@Sun.COM 		{
1139*9203SMark.Logan@Sun.COM 			status = PTSDK_STATUS_INTERNAL_ERROR;
1140*9203SMark.Logan@Sun.COM 			break;
1141*9203SMark.Logan@Sun.COM 		}
1142*9203SMark.Logan@Sun.COM 		memcpy(hashEntry.Name.Buffer, &(tmp_response->Hash.Name.Buffer), hashEntry.Name.Length * sizeof(CHAR));
1143*9203SMark.Logan@Sun.COM 
1144*9203SMark.Logan@Sun.COM 	} while (0);
1145*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
1146*9203SMark.Logan@Sun.COM 	{
1147*9203SMark.Logan@Sun.COM 		free(readBuffer);
1148*9203SMark.Logan@Sun.COM 	}
1149*9203SMark.Logan@Sun.COM 	return status;
1150*9203SMark.Logan@Sun.COM }
1151*9203SMark.Logan@Sun.COM /*
1152*9203SMark.Logan@Sun.COM * Confirms the correctness of the GetCertificateHashEntry response message
1153*9203SMark.Logan@Sun.COM * Arguments:
1154*9203SMark.Logan@Sun.COM *	response - reference to the response message
1155*9203SMark.Logan@Sun.COM * Return values:
1156*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
1157*9203SMark.Logan@Sun.COM *	PTSDK_STATUS_INTERNAL_ERROR - on failure
1158*9203SMark.Logan@Sun.COM */
_verifyGetCertificateHashEntry(const CFG_GET_CERTHASH_ENTRY_RESPONSE & response)1159*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::_verifyGetCertificateHashEntry(const CFG_GET_CERTHASH_ENTRY_RESPONSE &response)
1160*9203SMark.Logan@Sun.COM {
1161*9203SMark.Logan@Sun.COM 	ULONG ByteCount = response.Header.Header.Length;
1162*9203SMark.Logan@Sun.COM 
1163*9203SMark.Logan@Sun.COM 	if (ByteCount !=
1164*9203SMark.Logan@Sun.COM 		(sizeof(CFG_GET_CERTHASH_ENTRY_RESPONSE) - sizeof(PTHI_MESSAGE_HEADER)
1165*9203SMark.Logan@Sun.COM 		- sizeof(CHAR *) + response.Hash.Name.Length))
1166*9203SMark.Logan@Sun.COM 	{
1167*9203SMark.Logan@Sun.COM 		return PTSDK_STATUS_INTERNAL_ERROR;
1168*9203SMark.Logan@Sun.COM 	}
1169*9203SMark.Logan@Sun.COM 	return AMT_STATUS_SUCCESS;
1170*9203SMark.Logan@Sun.COM }
1171*9203SMark.Logan@Sun.COM 
1172*9203SMark.Logan@Sun.COM /*
1173*9203SMark.Logan@Sun.COM * Calls to GetDnsSuffix Host interface command
1174*9203SMark.Logan@Sun.COM * Arguments:
1175*9203SMark.Logan@Sun.COM *	dnsSuffix - reference to the pre-allocated structure
1176*9203SMark.Logan@Sun.COM *	   which will hold the result
1177*9203SMark.Logan@Sun.COM * Return values:
1178*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
1179*9203SMark.Logan@Sun.COM *	appropriate error value defined in StatusCodeDefinitions.h - on failure
1180*9203SMark.Logan@Sun.COM */
GetDnsSuffix(AMT_ANSI_STRING & dnsSuffix)1181*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::GetDnsSuffix(AMT_ANSI_STRING &dnsSuffix)
1182*9203SMark.Logan@Sun.COM {
1183*9203SMark.Logan@Sun.COM 	UINT8 *readBuffer = NULL;
1184*9203SMark.Logan@Sun.COM 	const UINT32 command_size = sizeof(GET_PKI_FQDN_SUFFIX_HEADER);
1185*9203SMark.Logan@Sun.COM 	unsigned char command[command_size];
1186*9203SMark.Logan@Sun.COM 	memcpy(command, &(GET_PKI_FQDN_SUFFIX_HEADER), sizeof(GET_PKI_FQDN_SUFFIX_HEADER));
1187*9203SMark.Logan@Sun.COM 
1188*9203SMark.Logan@Sun.COM 	AMT_STATUS status = _call(command, command_size, &readBuffer, GET_PKI_FQDN_SUFFIX_RESPONSE, 0);
1189*9203SMark.Logan@Sun.COM 	do {
1190*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
1191*9203SMark.Logan@Sun.COM 		{
1192*9203SMark.Logan@Sun.COM 			break;
1193*9203SMark.Logan@Sun.COM 		}
1194*9203SMark.Logan@Sun.COM 		CFG_GET_PKI_FQDN_SUFFIX_RESPONSE *tmp_response = (CFG_GET_PKI_FQDN_SUFFIX_RESPONSE *)readBuffer;
1195*9203SMark.Logan@Sun.COM 		status = _verifyGetDnsSuffix(*tmp_response);
1196*9203SMark.Logan@Sun.COM 		if (status != AMT_STATUS_SUCCESS)
1197*9203SMark.Logan@Sun.COM 		{
1198*9203SMark.Logan@Sun.COM 			break;
1199*9203SMark.Logan@Sun.COM 		}
1200*9203SMark.Logan@Sun.COM 
1201*9203SMark.Logan@Sun.COM 		dnsSuffix.Length = tmp_response->Suffix.Length;
1202*9203SMark.Logan@Sun.COM 		dnsSuffix.Buffer = (CHAR *)malloc(dnsSuffix.Length * sizeof(CHAR));
1203*9203SMark.Logan@Sun.COM 		if (NULL == dnsSuffix.Buffer)
1204*9203SMark.Logan@Sun.COM 		{
1205*9203SMark.Logan@Sun.COM 			status = PTSDK_STATUS_INTERNAL_ERROR;
1206*9203SMark.Logan@Sun.COM 			break;
1207*9203SMark.Logan@Sun.COM 		}
1208*9203SMark.Logan@Sun.COM 		memcpy(dnsSuffix.Buffer, &(tmp_response->Suffix.Buffer), dnsSuffix.Length * sizeof(CHAR));
1209*9203SMark.Logan@Sun.COM 
1210*9203SMark.Logan@Sun.COM 	} while (0);
1211*9203SMark.Logan@Sun.COM 	if (readBuffer != NULL)
1212*9203SMark.Logan@Sun.COM 	{
1213*9203SMark.Logan@Sun.COM 		free(readBuffer);
1214*9203SMark.Logan@Sun.COM 	}
1215*9203SMark.Logan@Sun.COM 	return status;
1216*9203SMark.Logan@Sun.COM }
1217*9203SMark.Logan@Sun.COM /*
1218*9203SMark.Logan@Sun.COM * Confirms the correctness of the GetDnsSuffix response message
1219*9203SMark.Logan@Sun.COM * Arguments:
1220*9203SMark.Logan@Sun.COM *	response - reference to the response message
1221*9203SMark.Logan@Sun.COM * Return values:
1222*9203SMark.Logan@Sun.COM *	AMT_STATUS_SUCCESS - on success
1223*9203SMark.Logan@Sun.COM *	PTSDK_STATUS_INTERNAL_ERROR - on failure
1224*9203SMark.Logan@Sun.COM */
_verifyGetDnsSuffix(const CFG_GET_PKI_FQDN_SUFFIX_RESPONSE & response)1225*9203SMark.Logan@Sun.COM AMT_STATUS PTHICommand::_verifyGetDnsSuffix(const CFG_GET_PKI_FQDN_SUFFIX_RESPONSE &response)
1226*9203SMark.Logan@Sun.COM {
1227*9203SMark.Logan@Sun.COM 	ULONG ByteCount = response.Header.Header.Length;
1228*9203SMark.Logan@Sun.COM 
1229*9203SMark.Logan@Sun.COM 	if (ByteCount  !=
1230*9203SMark.Logan@Sun.COM 		sizeof(AMT_STATUS) + sizeof(response.Suffix.Length) + response.Suffix.Length * sizeof(CHAR))
1231*9203SMark.Logan@Sun.COM 	{
1232*9203SMark.Logan@Sun.COM 		return PTSDK_STATUS_INTERNAL_ERROR;
1233*9203SMark.Logan@Sun.COM 	}
1234*9203SMark.Logan@Sun.COM 	return AMT_STATUS_SUCCESS;
1235*9203SMark.Logan@Sun.COM }
1236*9203SMark.Logan@Sun.COM 
1237