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.IpmiPayload;
26 import org.metricshub.ipmi.core.common.TypeConverter;
27
28
29
30
31 public abstract class IpmiLanMessage extends IpmiPayload {
32 public static final int MIN_SEQUENCE_NUMBER = 1;
33 public static final int MAX_SEQUENCE_NUMBER = 63;
34
35 private byte responderAddress;
36
37 private byte networkFunction;
38
39 private byte responderLogicalUnitNumber;
40
41 private byte requesterAddress;
42
43 private byte requesterLogicalUnitNumber;
44
45 private byte sequenceNumber;
46
47 private byte command;
48
49 public void setResponderAddress(byte responderAddress) {
50 this.responderAddress = responderAddress;
51 }
52
53 public byte getResponderAddress() {
54 return responderAddress;
55 }
56
57 public void setNetworkFunction(NetworkFunction networkFunction) {
58 this.networkFunction = TypeConverter.intToByte(networkFunction.getCode());
59 }
60
61
62
63
64
65
66
67
68 public NetworkFunction getNetworkFunction() {
69 return NetworkFunction.parseInt(TypeConverter.byteToInt(networkFunction));
70 }
71
72
73
74
75
76
77 protected void setNetworkFunctionCode(byte networkFunctionCode) {
78 this.networkFunction = networkFunctionCode;
79 }
80
81
82
83
84
85
86
87 public byte getNetworkFunctionCode() {
88 return networkFunction;
89 }
90
91 public void setResponderLogicalUnitNumber(byte responderLogicalUnitNumber) {
92 this.responderLogicalUnitNumber = responderLogicalUnitNumber;
93 }
94
95 public byte getResponderLogicalUnitNumber() {
96 return responderLogicalUnitNumber;
97 }
98
99 public void setSequenceNumber(byte sequenceAddress) {
100 this.sequenceNumber = sequenceAddress;
101 }
102
103 public byte getSequenceNumber() {
104 return sequenceNumber;
105 }
106
107 public void setRequesterAddress(byte requesterAddress) {
108 this.requesterAddress = requesterAddress;
109 }
110
111 public byte getRequesterAddress() {
112 return requesterAddress;
113 }
114
115 public void setRequesterLogicalUnitNumber(byte requesterLogicalUnitNumber) {
116 this.requesterLogicalUnitNumber = requesterLogicalUnitNumber;
117 }
118
119 public byte getRequesterLogicalUnitNumber() {
120 return requesterLogicalUnitNumber;
121 }
122
123 public void setCommand(byte command) {
124 this.command = command;
125 }
126
127 public byte getCommand() {
128 return command;
129 }
130
131
132
133
134 @Override
135 public abstract int getPayloadLength();
136
137
138
139
140 @Override
141 public abstract byte[] getPayloadData();
142
143 protected byte getChecksum1(byte[] message) {
144 int checksum = 0;
145 for (int i = 0; i < 2; ++i) {
146 checksum = (checksum + TypeConverter.byteToInt(message[i])) % 256;
147 }
148 return (byte) -TypeConverter.intToByte(checksum);
149 }
150
151 protected byte getChecksum2(byte[] message) {
152 int checksum = 0;
153 for (int i = 3; i < message.length - 1; ++i) {
154 checksum = ((checksum + TypeConverter.byteToInt(message[i])) % 256);
155 }
156 return (byte) -TypeConverter.intToByte(checksum);
157 }
158
159 @Override
160 public byte[] getIpmiCommandData() {
161 return getData();
162 }
163 }