1 package org.metricshub.ipmi.core.coding.commands.sdr;
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 java.security.InvalidKeyException;
26 import java.security.NoSuchAlgorithmException;
27
28 import org.metricshub.ipmi.core.coding.commands.CommandCodes;
29 import org.metricshub.ipmi.core.coding.commands.IpmiCommandCoder;
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.NetworkFunction;
34 import org.metricshub.ipmi.core.coding.protocol.IpmiMessage;
35 import org.metricshub.ipmi.core.common.TypeConverter;
36
37
38
39
40 public class GetSdr extends IpmiCommandCoder<GetSdrResponseData> {
41
42 private int reservationId;
43
44 private int recordId;
45
46 private int offset;
47
48 private int bytesToRead;
49
50
51
52
53
54
55
56
57
58
59
60 public GetSdr(int reservationId, int recordId) {
61 this(reservationId, recordId, 0, 0xFF);
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 public GetSdr(int reservationId, int recordId, int offset, int bytesToRead) {
78 this.recordId = recordId;
79 this.reservationId = reservationId;
80 this.offset = offset;
81 this.bytesToRead = bytesToRead;
82 }
83
84 @Override
85 public byte getCommandCode() {
86 return CommandCodes.GET_SDR;
87 }
88
89 @Override
90 public NetworkFunction getNetworkFunction() {
91 return NetworkFunction.StorageRequest;
92 }
93
94 @Override
95 protected IpmiPayload preparePayload(int sequenceNumber) throws NoSuchAlgorithmException, InvalidKeyException {
96 byte[] payload = new byte[6];
97
98 byte[] buffer = TypeConverter.intToByteArray(reservationId);
99
100 payload[0] = buffer[3];
101 payload[1] = buffer[2];
102
103 buffer = TypeConverter.intToByteArray(recordId);
104
105 payload[2] = buffer[3];
106 payload[3] = buffer[2];
107
108 payload[4] = TypeConverter.intToByte(offset);
109 payload[5] = TypeConverter.intToByte(bytesToRead);
110
111 return new IpmiLanRequest(getNetworkFunction(), getCommandCode(), payload, TypeConverter.intToByte(sequenceNumber));
112 }
113
114 @Override
115 public GetSdrResponseData getResponseData(IpmiMessage message)
116 throws IPMIException,
117 NoSuchAlgorithmException,
118 InvalidKeyException {
119 byte[] raw = validateResponse(message);
120
121
122 if (raw == null || raw.length < 2) {
123 throw new IllegalArgumentException("Invalid response payload length");
124 }
125
126 GetSdrResponseData responseData = new GetSdrResponseData();
127
128 byte[] buffer = new byte[4];
129
130 buffer[0] = raw[0];
131 buffer[1] = raw[1];
132 buffer[2] = 0;
133 buffer[3] = 0;
134
135 responseData.setNextRecordId(TypeConverter.littleEndianByteArrayToInt(buffer));
136
137 byte[] recordData = new byte[raw.length - 2];
138
139 System.arraycopy(raw, 2, recordData, 0, recordData.length);
140
141 responseData.setSensorRecordData(recordData);
142
143 return responseData;
144 }
145
146 }