1 package org.metricshub.ipmi.core.coding.commands.sel;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import org.metricshub.ipmi.core.coding.commands.CommandCodes;
26 import org.metricshub.ipmi.core.coding.commands.IpmiCommandCoder;
27 import org.metricshub.ipmi.core.coding.payload.IpmiPayload;
28 import org.metricshub.ipmi.core.coding.payload.lan.IPMIException;
29 import org.metricshub.ipmi.core.coding.payload.lan.IpmiLanRequest;
30 import org.metricshub.ipmi.core.coding.payload.lan.NetworkFunction;
31 import org.metricshub.ipmi.core.coding.protocol.IpmiMessage;
32 import org.metricshub.ipmi.core.common.TypeConverter;
33
34 import java.security.InvalidKeyException;
35 import java.security.NoSuchAlgorithmException;
36
37
38
39
40 public class GetSelInfo extends IpmiCommandCoder<GetSelInfoResponseData> {
41
42
43
44
45 public GetSelInfo() {}
46
47 @Override
48 public byte getCommandCode() {
49 return CommandCodes.GET_SEL_INFO;
50 }
51
52 @Override
53 public NetworkFunction getNetworkFunction() {
54 return NetworkFunction.StorageRequest;
55 }
56
57 @Override
58 protected IpmiPayload preparePayload(int sequenceNumber) throws NoSuchAlgorithmException, InvalidKeyException {
59 return new IpmiLanRequest(getNetworkFunction(), getCommandCode(), null, TypeConverter.intToByte(sequenceNumber));
60 }
61
62 @Override
63 public GetSelInfoResponseData getResponseData(IpmiMessage message)
64 throws IPMIException,
65 NoSuchAlgorithmException,
66 InvalidKeyException {
67 byte[] raw = validateResponse(message);
68
69 if (raw == null || raw.length != 14) {
70 throw new IllegalArgumentException("Invalid response payload length: " + (raw != null ? raw.length : "null"));
71 }
72
73 GetSelInfoResponseData responseData = new GetSelInfoResponseData();
74
75 responseData.setSelVersion(TypeConverter.littleEndianBcdByteToInt(raw[0]));
76
77 byte[] buffer = new byte[4];
78
79 buffer[0] = raw[1];
80 buffer[1] = raw[2];
81 buffer[2] = 0;
82 buffer[3] = 0;
83
84 responseData.setEntriesCount(TypeConverter.littleEndianByteArrayToInt(buffer));
85
86 System.arraycopy(raw, 5, buffer, 0, 4);
87
88 responseData.setAdditionTimestamp(TypeConverter.decodeDate(TypeConverter.littleEndianByteArrayToInt(buffer)));
89
90 System.arraycopy(raw, 9, buffer, 0, 4);
91
92 responseData.setEraseTimestamp(TypeConverter.decodeDate(TypeConverter.littleEndianByteArrayToInt(buffer)));
93
94 return responseData;
95 }
96
97 }