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.commands.IpmiVersion;
28 import org.metricshub.ipmi.core.coding.commands.ResponseData;
29 import org.metricshub.ipmi.core.coding.payload.CompletionCode;
30 import org.metricshub.ipmi.core.coding.payload.IpmiPayload;
31 import org.metricshub.ipmi.core.coding.payload.lan.IPMIException;
32 import org.metricshub.ipmi.core.coding.payload.lan.IpmiLanRequest;
33 import org.metricshub.ipmi.core.coding.payload.lan.IpmiLanResponse;
34 import org.metricshub.ipmi.core.coding.payload.lan.NetworkFunction;
35 import org.metricshub.ipmi.core.coding.protocol.AuthenticationType;
36 import org.metricshub.ipmi.core.coding.protocol.IpmiMessage;
37 import org.metricshub.ipmi.core.coding.security.CipherSuite;
38 import org.metricshub.ipmi.core.common.TypeConverter;
39
40 import java.security.InvalidKeyException;
41 import java.security.NoSuchAlgorithmException;
42
43
44
45
46 public class GetSelEntry extends IpmiCommandCoder {
47
48 private int reservationId;
49
50 private int recordId;
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 public GetSelEntry(IpmiVersion version, CipherSuite cipherSuite,
69 AuthenticationType authenticationType, int reservationId,
70 int recordId) {
71 super(version, cipherSuite, authenticationType);
72 this.recordId = recordId;
73 this.reservationId = reservationId;
74 }
75
76 @Override
77 public byte getCommandCode() {
78 return CommandCodes.GET_SEL_ENTRY;
79 }
80
81 @Override
82 public NetworkFunction getNetworkFunction() {
83 return NetworkFunction.StorageRequest;
84 }
85
86 @Override
87 protected IpmiPayload preparePayload(int sequenceNumber)
88 throws NoSuchAlgorithmException, InvalidKeyException {
89 byte[] payload = new byte[6];
90
91 byte[] buffer = TypeConverter.intToByteArray(reservationId);
92
93 payload[0] = buffer[3];
94 payload[1] = buffer[2];
95
96 buffer = TypeConverter.intToByteArray(recordId);
97
98 payload[2] = buffer[3];
99 payload[3] = buffer[2];
100
101 payload[4] = 0;
102 payload[5] = TypeConverter.intToByte(0xff);
103
104 return new IpmiLanRequest(getNetworkFunction(), getCommandCode(),
105 payload, TypeConverter.intToByte(sequenceNumber));
106 }
107
108 @Override
109 public ResponseData getResponseData(IpmiMessage message) throws IPMIException,
110 NoSuchAlgorithmException, InvalidKeyException {
111 if (!isCommandResponse(message)) {
112 throw new IllegalArgumentException(
113 "This is not a response for Get SEL Entry command");
114 }
115 if (!(message.getPayload() instanceof IpmiLanResponse)) {
116 throw new IllegalArgumentException("Invalid response payload");
117 }
118 if (((IpmiLanResponse) message.getPayload()).getCompletionCode() != CompletionCode.Ok) {
119 throw new IPMIException(
120 ((IpmiLanResponse) message.getPayload())
121 .getCompletionCode());
122 }
123
124 byte[] raw = message.getPayload().getIpmiCommandData();
125
126 if (raw == null || raw.length < 3) {
127 throw new IllegalArgumentException(
128 "Invalid response payload length");
129 }
130
131 GetSelEntryResponseData responseData = new GetSelEntryResponseData();
132
133 byte[] buffer = new byte[4];
134
135 buffer[0] = raw[0];
136 buffer[1] = raw[1];
137 buffer[2] = 0;
138 buffer[3] = 0;
139
140 responseData.setNextRecordId(TypeConverter
141 .littleEndianByteArrayToInt(buffer));
142
143 byte[] recordData = new byte[raw.length - 2];
144
145 System.arraycopy(raw, 2, recordData, 0, recordData.length);
146
147 responseData.setSelRecord(SelRecord.populateSelRecord(recordData));
148
149 return responseData;
150 }
151
152 }