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