1 package org.sentrysoftware.ipmi.core.coding.protocol.decoder;
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.sentrysoftware.ipmi.core.coding.protocol.AuthenticationType;
26 import org.sentrysoftware.ipmi.core.coding.protocol.IpmiMessage;
27 import org.sentrysoftware.ipmi.core.coding.protocol.Ipmiv15Message;
28 import org.sentrysoftware.ipmi.core.coding.protocol.PayloadType;
29 import org.sentrysoftware.ipmi.core.coding.rmcp.RmcpMessage;
30 import org.sentrysoftware.ipmi.core.common.TypeConverter;
31
32
33
34
35 public class Protocolv15Decoder extends ProtocolDecoder {
36
37 public Protocolv15Decoder() {
38 super();
39 }
40
41
42
43
44
45
46
47
48
49
50
51
52 @Override
53 public IpmiMessage decode(RmcpMessage rmcpMessage) {
54 Ipmiv15Message message = new Ipmiv15Message();
55
56 byte[] raw = rmcpMessage.getData();
57
58 message.setAuthenticationType(decodeAuthenticationType(raw[0]));
59
60 int offset = 1;
61
62 message.setSessionSequenceNumber(decodeSessionSequenceNumber(raw,
63 offset));
64
65 offset += 4;
66
67 message.setSessionID(decodeSessionID(raw, offset));
68
69 offset += 4;
70
71 if (message.getAuthenticationType() != AuthenticationType.None) {
72 message.setAuthCode(decodeAuthCode(raw, offset));
73 offset += 16;
74 }
75
76 int payloadLength = decodePayloadLength(raw, offset);
77
78 message.setPayloadLength(payloadLength);
79 ++offset;
80
81 message.setPayload(decodePayload(raw, offset, payloadLength,
82 message.getConfidentialityAlgorithm(), PayloadType.Ipmi));
83
84 return message;
85 }
86
87
88
89
90
91
92
93
94
95
96 private byte[] decodeAuthCode(byte[] rawMessage, int offset) {
97 byte[] authCode = new byte[16];
98
99 System.arraycopy(rawMessage, offset, authCode, 0, 16);
100
101 return authCode;
102 }
103
104 @Override
105 protected int decodePayloadLength(byte[] rawData, int offset) {
106 return TypeConverter.byteToInt(rawData[offset]);
107 }
108 }