-
Notifications
You must be signed in to change notification settings - Fork 0
/
PefCMD.cpp
281 lines (227 loc) · 7.26 KB
/
PefCMD.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//
// PefCMD.cpp
// J3NI
//
// Created by Neil on 2014-03-14.
// Copyright (c) 2014 J3NI. All rights reserved.
//
#include <fstream>
#include <stdlib.h>
#include <syslog.h>
#include <time.h>
#include <PefCMD.h>
#include <IpmiCommandDefines.h>
using namespace IpmiCommandDefines;
extern std::ofstream log_file;
GetPefCapabCMD::GetPefCapabCMD() : pefCapab_(0x0E)
{
}
void GetPefCapabCMD::setPefCapab(unsigned char pefCap)
{
pefCapab_ = pefCap;
}
unsigned char GetPefCapabCMD::getPefCapab() const
{
return pefCapab_;
}
int GetPefCapabCMD::process(const unsigned char* req, int reqLength,
unsigned char* resp)
{
syslog(LOG_NOTICE, "Processing Get PEF Capabilities Command");
log_file << "Processing Get PEF Capabilities Command\n";
resp[0] = COMP_CODE_OK;
resp[1] = 0x51;
resp[2] = pefCapab_;
resp[3] = 0x00;
return 4;
}
ArmPefPostponeTimerCMD::ArmPefPostponeTimerCMD() : countdownDuration(0)
{
setTime = time(0);
}
int ArmPefPostponeTimerCMD::process(const unsigned char* req, int reqLength,
unsigned char* resp)
{
syslog(LOG_NOTICE, "Processing Arm PEF Postpone Timer CMD");
log_file << "Arm PEF Postpone Timer Command" << std::endl;
time_t t = time(0);
if(req[0] == 0xFE || req[0] == 0x00)
{
countdownDuration = 0;
}
else if(req[0] != 0xFF)
{
countdownDuration = req[0];
setTime = t;
}
unsigned char countdownValue = countdownDuration;
if(req[0] == 0xFF)
{
countdownValue = (t - setTime) % countdownDuration;
}
resp[0] = COMP_CODE_OK;
resp[1] = countdownValue;
return 2;
}
GetPefConfigParamCMD::GetPefConfigParamCMD()
{
unsigned char defaultInProgress = 0x00;
pefConfigMap[0x00] = new ConfigParam(1, &defaultInProgress);
unsigned char defaultControl = 0x01;
pefConfigMap[0x01] = new ConfigParam(1, &defaultControl);
unsigned char defaultActionControl = 0x0E;
pefConfigMap[0x02] = new ConfigParam(1, &defaultActionControl);
unsigned char defaultStartupDelay = 0x00;
pefConfigMap[0x03] = new ConfigParam(1, &defaultStartupDelay);
unsigned char defaultAlertStartupDelay = 0x00;
pefConfigMap[0x04] = new ConfigParam(1, &defaultAlertStartupDelay);
unsigned char eventFilters = 0x00;
pefConfigMap[0x05] = new ConfigParam(1, &eventFilters, true);
unsigned char alertPolicyNum = 0x00;
pefConfigMap[0x08] = new ConfigParam(1, &alertPolicyNum, true);
unsigned char* guid = new unsigned char[16];
pefConfigMap[0x0A] = new ConfigParam(16, guid);
delete [] guid;
}
GetPefConfigParamCMD::~GetPefConfigParamCMD()
{
for(ConfigParamMap::iterator it = pefConfigMap.begin();
it != pefConfigMap.end(); it++)
{
delete it->second;
}
pefConfigMap.clear();
}
unsigned char GetPefConfigParamCMD::setMap(unsigned char param,
const unsigned char* paramValue,
int length)
{
unsigned char paramSelector = paramValue[0] & 0x7F;
ConfigParamMap::iterator it = pefConfigMap.find(paramSelector);
if(it == pefConfigMap.end())
{
return PARAM_UNSUPPORTED;
}
ConfigParam* configParam = it->second;
if(configParam->readOnly)
{
return WRITE_TO_READ_ONLY;
}
if((param == 0x00) && (configParam->data[0] != 0x00))
{
return SET_IN_PROGRESS_FAIL;
}
if(configParam->length != length)
{
delete[] configParam->data;
configParam->data = new unsigned char[length];
}
for(int i = 0; i < configParam->length; i++)
{
configParam->data[i] = paramValue[i];
}
return COMP_CODE_OK;
}
int GetPefConfigParamCMD::process(const unsigned char* req, int reqLength,
unsigned char* resp)
{
syslog(LOG_NOTICE, "Processing Get PEF Configuration Parameters CMD");
log_file << "Get PEF Configuration Parameters Command" << std::endl;
resp[0] = COMP_CODE_OK;
resp[1] = 0x11;
if((req[0] & 0x80) == 0x80)
return 2;
unsigned char paramSelector = req[0] & 0x7F;
ConfigParamMap::iterator it = pefConfigMap.find(paramSelector);
if(it == pefConfigMap.end())
{
resp[0] = PARAM_UNSUPPORTED;
return 2;
}
ConfigParam* param = it->second;
int i = 0;
for(; i < param->length; i++)
{
resp[2 + i] = param->data[i];
}
return 2 + i;
}
SetPefConfigParamCMD::SetPefConfigParamCMD(GetPefConfigParamCMD* getPefConfigParam)
{
getPefConfigParam_ = getPefConfigParam;
}
int SetPefConfigParamCMD::process(const unsigned char* req, int reqLength,
unsigned char* resp)
{
syslog(LOG_NOTICE, "Processing Set PEF Configuration Parameters CMD");
log_file << "Set PEF Configuration Parameters Command" << std::endl;
unsigned char paramSelector = req[0] & 0x7F;
resp[0] = getPefConfigParam_->setMap(paramSelector,
req + 1, reqLength - 1);
return 1;
}
GetLastProcEventIdCMD::GetLastProcEventIdCMD()
: mostRecentId_(NULL), bmcRecordId_(0x0000), swRecordId_(0x0000)
{
timestamp_ = time(0);
mostRecentId_ = &swRecordId_;
}
void GetLastProcEventIdCMD::setBmcRecordId(const unsigned char* recordId, int length)
{
if(length < 2) return;
bmcRecordId_ = recordId[0] | (recordId[1] << 8);
mostRecentId_ = &bmcRecordId_;
timestamp_ = time(0);
}
void GetLastProcEventIdCMD::setSwRecordId(const unsigned char* recordId, int length)
{
if(length < 2) return;
swRecordId_ = recordId[0] | (recordId[1] << 8);
mostRecentId_ = &swRecordId_;
timestamp_ = time(0);
}
uint16_t GetLastProcEventIdCMD::getBmcRecordId() const
{
return bmcRecordId_;
}
uint16_t GetLastProcEventIdCMD::getSwRecordId() const
{
return swRecordId_;
}
int GetLastProcEventIdCMD::process(const unsigned char* req, int reqLength,
unsigned char* resp)
{
syslog(LOG_NOTICE, "Processing Get Last Proccessed Event Id CMD");
log_file << "Get Last Proccessed Event Id Command" << std::endl;
resp[0] = COMP_CODE_OK;
resp[1] = timestamp_ & 0x000000FF;
resp[2] = (timestamp_ & 0x0000FF00) >> 8;
resp[3] = (timestamp_ & 0x00FF0000) >> 16;
resp[4] = (timestamp_ & 0xFF000000) >> 24;
resp[5] = *mostRecentId_ & 0x00FF ;
resp[6] = (*mostRecentId_ & 0xFF00) >> 8;
resp[7] = swRecordId_ & 0x00FF ;
resp[8] = (swRecordId_ & 0xFF00) >> 8;
resp[9] = swRecordId_ & 0x00FF ;
resp[10] = (swRecordId_ & 0xFF00) >> 8;
return 11;
}
SetLastProcEventIdCMD::SetLastProcEventIdCMD(GetLastProcEventIdCMD* lastProcEventCmd)
{
lastProcEventCmd_ = lastProcEventCmd;
}
int SetLastProcEventIdCMD::process(const unsigned char* req, int reqLength,
unsigned char* resp)
{
syslog(LOG_NOTICE, "Processing Set Last Proccessed Event Id CMD");
log_file << "Set Last Proccessed Event Id Command" << std::endl;
resp[0] = COMP_CODE_OK;
if (reqLength >= 3)
{
if((req[0] & 0x01) == 0x01)
lastProcEventCmd_->setBmcRecordId(req + 1, 2);
else
lastProcEventCmd_->setSwRecordId(req + 1, 2);
}
return 1;
}