1 package org.metricshub.ipmi.core.coding.payload.lan;
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.payload.CompletionCode;
26 import org.metricshub.ipmi.core.common.TypeConverter;
27
28
29
30
31 public class IpmiLanResponse extends IpmiLanMessage {
32
33 private static final int GENERIC_CODES_START = 0xC0;
34
35 private CompletionCode completionCode;
36
37 private int rawCompletionCode;
38
39
40
41
42
43
44
45
46 public void setCompletionCode(byte completionCode) {
47 rawCompletionCode = TypeConverter.byteToInt(completionCode);
48 this.completionCode = rawCompletionCode == 0 || rawCompletionCode >= GENERIC_CODES_START ?
49 CompletionCode.parseInt(rawCompletionCode) :
50 CompletionCode.Unknown;
51 }
52
53 public CompletionCode getCompletionCode() {
54 return completionCode;
55 }
56
57
58
59
60 public int getRawCompletionCode() {
61 return rawCompletionCode;
62 }
63
64
65
66
67
68
69
70
71 public IpmiLanResponse(byte[] rawData) {
72
73 if (rawData.length < 8) {
74 throw new IllegalArgumentException("IPMI LAN response is too short: " + rawData.length + " bytes");
75 }
76 setRequesterAddress(rawData[0]);
77 setNetworkFunctionCode(TypeConverter.intToByte((TypeConverter.byteToInt(rawData[1]) & 0xfC) >> 2));
78 setRequesterLogicalUnitNumber(TypeConverter.intToByte(TypeConverter.byteToInt(rawData[1]) & 0x03));
79 if (rawData[2] != getChecksum1(rawData)) {
80 throw new IllegalArgumentException("Checksum 1 failed");
81 }
82 setResponderAddress(rawData[3]);
83 setSequenceNumber(TypeConverter.intToByte((TypeConverter.byteToInt(rawData[4]) & 0xfC) >> 2));
84 setResponderLogicalUnitNumber(TypeConverter.intToByte(TypeConverter.byteToInt(rawData[4]) & 0x03));
85 setCommand(rawData[5]);
86 setCompletionCode(rawData[6]);
87
88 if (rawData.length > 8) {
89 byte[] data = new byte[rawData.length - 8];
90
91 System.arraycopy(rawData, 7, data, 0, rawData.length - 8);
92
93 setData(data);
94 }
95
96 if (rawData[rawData.length - 1] != getChecksum2(rawData)) {
97 throw new IllegalArgumentException("Checksum 2 failed");
98 }
99 }
100
101 @Override
102 public int getPayloadLength() {
103 int length = 8;
104 if (getData() != null) {
105 length += getData().length;
106 }
107 return length;
108 }
109
110
111
112
113 @Override
114 @Deprecated
115 public byte[] getPayloadData() {
116 return null;
117 }
118
119 }