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 protected 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 public NetworkFunction getNetworkFunction() {
62 return NetworkFunction.parseInt(TypeConverter.byteToInt(networkFunction));
63 }
64
65 public void setResponderLogicalUnitNumber(byte responderLogicalUnitNumber) {
66 this.responderLogicalUnitNumber = responderLogicalUnitNumber;
67 }
68
69 public byte getResponderLogicalUnitNumber() {
70 return responderLogicalUnitNumber;
71 }
72
73 public void setSequenceNumber(byte sequenceAddress) {
74 this.sequenceNumber = sequenceAddress;
75 }
76
77 public byte getSequenceNumber() {
78 return sequenceNumber;
79 }
80
81 public void setRequesterAddress(byte requesterAddress) {
82 this.requesterAddress = requesterAddress;
83 }
84
85 public byte getRequesterAddress() {
86 return requesterAddress;
87 }
88
89 public void setRequesterLogicalUnitNumber(byte requesterLogicalUnitNumber) {
90 this.requesterLogicalUnitNumber = requesterLogicalUnitNumber;
91 }
92
93 public byte getRequesterLogicalUnitNumber() {
94 return requesterLogicalUnitNumber;
95 }
96
97 public void setCommand(byte command) {
98 this.command = command;
99 }
100
101 public byte getCommand() {
102 return command;
103 }
104
105
106
107
108 @Override
109 public abstract int getPayloadLength();
110
111
112
113
114 @Override
115 public abstract byte[] getPayloadData();
116
117 protected byte getChecksum1(byte[] message) {
118 int checksum = 0;
119 for(int i = 0; i < 2; ++i) {
120 checksum = (checksum + TypeConverter.byteToInt(message[i])) % 256;
121 }
122 return (byte) -TypeConverter.intToByte(checksum);
123 }
124
125 protected byte getChecksum2(byte[] message) {
126 int checksum = 0;
127 for(int i = 3; i < message.length-1; ++i) {
128 checksum = ((checksum + TypeConverter.byteToInt(message[i])) % 256);
129 }
130 return (byte)-TypeConverter.intToByte(checksum);
131 }
132
133 @Override
134 public byte[] getIpmiCommandData() {
135 return getData();
136 }
137 }