xref: /titanic_41/usr/src/cmd/lms/heci/MNGCommand.cpp (revision 617e2443dfc17fe44fd44c0675d6aad2ffc9df42)
1*617e2443SMark Logan /*******************************************************************************
2*617e2443SMark Logan  * Copyright (C) 2004-2008 Intel Corp. All rights reserved.
3*617e2443SMark Logan  *
4*617e2443SMark Logan  * Redistribution and use in source and binary forms, with or without
5*617e2443SMark Logan  * modification, are permitted provided that the following conditions are met:
6*617e2443SMark Logan  *
7*617e2443SMark Logan  *  - Redistributions of source code must retain the above copyright notice,
8*617e2443SMark Logan  *    this list of conditions and the following disclaimer.
9*617e2443SMark Logan  *
10*617e2443SMark Logan  *  - Redistributions in binary form must reproduce the above copyright notice,
11*617e2443SMark Logan  *    this list of conditions and the following disclaimer in the documentation
12*617e2443SMark Logan  *    and/or other materials provided with the distribution.
13*617e2443SMark Logan  *
14*617e2443SMark Logan  *  - Neither the name of Intel Corp. nor the names of its
15*617e2443SMark Logan  *    contributors may be used to endorse or promote products derived from this
16*617e2443SMark Logan  *    software without specific prior written permission.
17*617e2443SMark Logan  *
18*617e2443SMark Logan  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
19*617e2443SMark Logan  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*617e2443SMark Logan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*617e2443SMark Logan  * ARE DISCLAIMED. IN NO EVENT SHALL Intel Corp. OR THE CONTRIBUTORS
22*617e2443SMark Logan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*617e2443SMark Logan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*617e2443SMark Logan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*617e2443SMark Logan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*617e2443SMark Logan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*617e2443SMark Logan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*617e2443SMark Logan  * POSSIBILITY OF SUCH DAMAGE.
29*617e2443SMark Logan  *******************************************************************************/
30*617e2443SMark Logan 
31*617e2443SMark Logan #ifdef HAVE_CONFIG_H
32*617e2443SMark Logan #include "config.h"
33*617e2443SMark Logan #endif
34*617e2443SMark Logan #include <cstdio>
35*617e2443SMark Logan #include <cstdlib>
36*617e2443SMark Logan 
37*617e2443SMark Logan #ifdef __sun
38*617e2443SMark Logan #include <stdio.h>
39*617e2443SMark Logan #include <stdlib.h>
40*617e2443SMark Logan #endif	// __sun
41*617e2443SMark Logan 
42*617e2443SMark Logan #include "MNGCommand.h"
43*617e2443SMark Logan 
MNGCommand(bool verbose)44*617e2443SMark Logan MNGCommand::MNGCommand(bool verbose) :
45*617e2443SMark Logan MNGClient(WD_GUID, verbose)
46*617e2443SMark Logan {
47*617e2443SMark Logan 	_verbose = verbose;
48*617e2443SMark Logan }
49*617e2443SMark Logan 
~MNGCommand(void)50*617e2443SMark Logan MNGCommand::~MNGCommand(void)
51*617e2443SMark Logan {
52*617e2443SMark Logan }
53*617e2443SMark Logan 
_call(const unsigned char * command,UINT32 command_size,UINT8 ** readBuffer,UINT32 * outBuffSize)54*617e2443SMark Logan HECI_STATUS MNGCommand::_call(const unsigned char *command, UINT32 command_size, UINT8 **readBuffer, UINT32 *outBuffSize)
55*617e2443SMark Logan {
56*617e2443SMark Logan 	UINT32 inBuffSize;
57*617e2443SMark Logan 	*outBuffSize = 0;
58*617e2443SMark Logan 
59*617e2443SMark Logan 	inBuffSize = MNGClient.GetBufferSize();
60*617e2443SMark Logan 	if (NULL == *readBuffer)
61*617e2443SMark Logan 	{
62*617e2443SMark Logan 		*readBuffer = (UINT8 *)malloc(sizeof(UINT8) * inBuffSize);
63*617e2443SMark Logan 		if (NULL == *readBuffer)
64*617e2443SMark Logan 		{
65*617e2443SMark Logan 			if (_verbose)
66*617e2443SMark Logan 			{
67*617e2443SMark Logan 				fprintf(stderr, "Error: Malloc failed\n");
68*617e2443SMark Logan 			}
69*617e2443SMark Logan 			return HECI_STATUS_MEMORY_ALLOCATION_ERROR;
70*617e2443SMark Logan 		}
71*617e2443SMark Logan 	}
72*617e2443SMark Logan 	memset(*readBuffer, 0, inBuffSize);
73*617e2443SMark Logan 
74*617e2443SMark Logan 	int bytesWritten = MNGClient.SendMessage(command, command_size);
75*617e2443SMark Logan 	if ((UINT32)bytesWritten != command_size)
76*617e2443SMark Logan 	{
77*617e2443SMark Logan 		if (_verbose)
78*617e2443SMark Logan 		{
79*617e2443SMark Logan 			fprintf(stderr, "Error: Could not send data to MNG client through MEI\n");
80*617e2443SMark Logan 		}
81*617e2443SMark Logan 		return HECI_STATUS_MSG_TRANSMISSION_ERROR;
82*617e2443SMark Logan 	}
83*617e2443SMark Logan 	*outBuffSize = MNGClient.ReceiveMessage(*readBuffer, inBuffSize, 15000);
84*617e2443SMark Logan 	if (0 == *outBuffSize)
85*617e2443SMark Logan 	{
86*617e2443SMark Logan 		if (_verbose)
87*617e2443SMark Logan 		{
88*617e2443SMark Logan 			fprintf(stderr, "Error: Could not read data from MNG client through MEI\n");
89*617e2443SMark Logan 		}
90*617e2443SMark Logan 		return HECI_STATUS_UNEXPECTED_RESPONSE;
91*617e2443SMark Logan 	}
92*617e2443SMark Logan 	if (_verbose)
93*617e2443SMark Logan 	{
94*617e2443SMark Logan 		fprintf(stdout, "Data received from MNG Client. %d bytes read\n", *outBuffSize);
95*617e2443SMark Logan 	}
96*617e2443SMark Logan 	return HECI_STATUS_OK;
97*617e2443SMark Logan }
98*617e2443SMark Logan 
99*617e2443SMark Logan 
100*617e2443SMark Logan /*
101*617e2443SMark Logan  * Get ME data information from MNG client
102*617e2443SMark Logan  */
103*617e2443SMark Logan HECI_STATUS
GetMEInfo(MNG_GET_ME_INFORMATION_RESPONSE & infoMsg)104*617e2443SMark Logan MNGCommand::GetMEInfo(MNG_GET_ME_INFORMATION_RESPONSE &infoMsg)
105*617e2443SMark Logan {
106*617e2443SMark Logan 	UINT8 *readBuffer = NULL;
107*617e2443SMark Logan 	UINT32 command_size = sizeof(MNG_GET_ME_INFO_HEADER);
108*617e2443SMark Logan 	UINT32 replySize = 0;
109*617e2443SMark Logan 	MNG_REQUEST msg = MNG_GET_ME_INFO_HEADER;
110*617e2443SMark Logan 	HECI_STATUS status;
111*617e2443SMark Logan 
112*617e2443SMark Logan 	status = _call((const unsigned char *)&msg, command_size,
113*617e2443SMark Logan 			&readBuffer, &replySize);
114*617e2443SMark Logan 
115*617e2443SMark Logan 	if (status != HECI_STATUS_OK)
116*617e2443SMark Logan 	{
117*617e2443SMark Logan 		goto mngend;
118*617e2443SMark Logan 	}
119*617e2443SMark Logan 	if (replySize != sizeof(MNG_GET_ME_INFORMATION_RESPONSE))
120*617e2443SMark Logan 	{
121*617e2443SMark Logan 		if (_verbose)
122*617e2443SMark Logan 		{
123*617e2443SMark Logan 			fprintf(stderr, "Error: Size of MEI response is not as expected\n");
124*617e2443SMark Logan 		}
125*617e2443SMark Logan 		status = HECI_STATUS_UNEXPECTED_RESPONSE;
126*617e2443SMark Logan 		goto mngend;
127*617e2443SMark Logan 	}
128*617e2443SMark Logan 	if (((MNG_GET_ME_INFORMATION_RESPONSE *)readBuffer)->Version != MNG_GET_ME_INFO_Version)
129*617e2443SMark Logan 	{
130*617e2443SMark Logan 		if (_verbose)
131*617e2443SMark Logan 		{
132*617e2443SMark Logan 			fprintf(stderr, "Error: MEI response size is not as expected\n");
133*617e2443SMark Logan 		}
134*617e2443SMark Logan 		status = HECI_STATUS_UNEXPECTED_RESPONSE;
135*617e2443SMark Logan 		goto mngend;
136*617e2443SMark Logan 	}
137*617e2443SMark Logan 	memcpy(&infoMsg, readBuffer, sizeof(MNG_GET_ME_INFORMATION_RESPONSE));
138*617e2443SMark Logan 
139*617e2443SMark Logan mngend:
140*617e2443SMark Logan 
141*617e2443SMark Logan 	if (readBuffer != NULL)
142*617e2443SMark Logan 	{
143*617e2443SMark Logan 		free(readBuffer);
144*617e2443SMark Logan 	}
145*617e2443SMark Logan 
146*617e2443SMark Logan 	return status;
147*617e2443SMark Logan }
148