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 GetSelEntry extends IpmiCommandCoder<GetSelEntryResponseData> {
41
42 private int reservationId;
43
44 private int recordId;
45
46
47
48
49
50
51
52
53
54
55 public GetSelEntry(int reservationId, int recordId) {
56 this.recordId = recordId;
57 this.reservationId = reservationId;
58 }
59
60 @Override
61 public byte getCommandCode() {
62 return CommandCodes.GET_SEL_ENTRY;
63 }
64
65 @Override
66 public NetworkFunction getNetworkFunction() {
67 return NetworkFunction.StorageRequest;
68 }
69
70 @Override
71 protected IpmiPayload preparePayload(int sequenceNumber) throws NoSuchAlgorithmException, InvalidKeyException {
72 byte[] payload = new byte[6];
73
74 byte[] buffer = TypeConverter.intToByteArray(reservationId);
75
76 payload[0] = buffer[3];
77 payload[1] = buffer[2];
78
79 buffer = TypeConverter.intToByteArray(recordId);
80
81 payload[2] = buffer[3];
82 payload[3] = buffer[2];
83
84 payload[4] = 0;
85 payload[5] = TypeConverter.intToByte(0xff);
86
87 return new IpmiLanRequest(getNetworkFunction(), getCommandCode(), payload, TypeConverter.intToByte(sequenceNumber));
88 }
89
90 @Override
91 public GetSelEntryResponseData getResponseData(IpmiMessage message)
92 throws IPMIException,
93 NoSuchAlgorithmException,
94 InvalidKeyException {
95 byte[] raw = validateResponse(message);
96
97 if (raw == null || raw.length < 3) {
98 throw new IllegalArgumentException("Invalid response payload length");
99 }
100
101 GetSelEntryResponseData responseData = new GetSelEntryResponseData();
102
103 byte[] buffer = new byte[4];
104
105 buffer[0] = raw[0];
106 buffer[1] = raw[1];
107 buffer[2] = 0;
108 buffer[3] = 0;
109
110 responseData.setNextRecordId(TypeConverter.littleEndianByteArrayToInt(buffer));
111
112 byte[] recordData = new byte[raw.length - 2];
113
114 System.arraycopy(raw, 2, recordData, 0, recordData.length);
115
116 responseData.setSelRecord(SelRecord.populateSelRecord(recordData));
117
118 return responseData;
119 }
120
121 }