1 package org.metricshub.ipmi.core.coding.commands.sel;
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.commands.CommandCodes;
26 import org.metricshub.ipmi.core.coding.commands.IpmiCommandCoder;
27 import org.metricshub.ipmi.core.coding.commands.IpmiVersion;
28 import org.metricshub.ipmi.core.coding.commands.ResponseData;
29 import org.metricshub.ipmi.core.coding.payload.CompletionCode;
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.IpmiLanResponse;
34 import org.metricshub.ipmi.core.coding.payload.lan.NetworkFunction;
35 import org.metricshub.ipmi.core.coding.protocol.AuthenticationType;
36 import org.metricshub.ipmi.core.coding.protocol.IpmiMessage;
37 import org.metricshub.ipmi.core.coding.security.CipherSuite;
38 import org.metricshub.ipmi.core.common.TypeConverter;
39
40 import java.security.InvalidKeyException;
41 import java.security.NoSuchAlgorithmException;
42
43
44
45
46 public class ReserveSel extends IpmiCommandCoder {
47
48
49
50
51
52
53
54
55
56
57
58
59 public ReserveSel(IpmiVersion version, CipherSuite cipherSuite,
60 AuthenticationType authenticationType) {
61 super(version, cipherSuite, authenticationType);
62 }
63
64 @Override
65 public byte getCommandCode() {
66 return CommandCodes.RESERVE_SEL;
67 }
68
69 @Override
70 public NetworkFunction getNetworkFunction() {
71 return NetworkFunction.StorageRequest;
72 }
73
74 @Override
75 protected IpmiPayload preparePayload(int sequenceNumber)
76 throws NoSuchAlgorithmException, InvalidKeyException {
77 return new IpmiLanRequest(getNetworkFunction(), getCommandCode(), null,
78 TypeConverter.intToByte(sequenceNumber));
79 }
80
81 @Override
82 public ResponseData getResponseData(IpmiMessage message)
83 throws IPMIException,
84 NoSuchAlgorithmException, InvalidKeyException {
85
86 if (!isCommandResponse(message)) {
87 throw new IllegalArgumentException(
88 "This is not a response for Reserve SEL command");
89 }
90 if (!(message.getPayload() instanceof IpmiLanResponse)) {
91 throw new IllegalArgumentException("Invalid response payload");
92 }
93 if (((IpmiLanResponse) message.getPayload()).getCompletionCode() != CompletionCode.Ok) {
94 throw new IPMIException(
95 ((IpmiLanResponse) message.getPayload())
96 .getCompletionCode());
97 }
98
99 byte[] raw = message.getPayload().getIpmiCommandData();
100
101 if (raw == null || raw.length != 2) {
102 throw new IllegalArgumentException(
103 "Invalid response payload length: " + (raw != null ? raw.length : "null"));
104 }
105
106 ReserveSelResponseData responseData = new ReserveSelResponseData();
107
108 byte[] buffer = new byte[4];
109
110 buffer[0] = raw[0];
111 buffer[1] = raw[1];
112 buffer[2] = 0;
113 buffer[3] = 0;
114
115 responseData.setReservationId(TypeConverter
116 .littleEndianByteArrayToInt(buffer));
117
118 return responseData;
119 }
120
121 }