View Javadoc
1   package org.metricshub.ipmi.core.coding.commands.sel;
2   
3   /*-
4    * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5    * IPMI Java Client
6    * ჻჻჻჻჻჻
7    * Copyright 2023 Verax Systems, MetricsHub
8    * ჻჻჻჻჻჻
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   *
19   * You should have received a copy of the GNU General Lesser Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
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.payload.IpmiPayload;
28  import org.metricshub.ipmi.core.coding.payload.lan.IPMIException;
29  import org.metricshub.ipmi.core.coding.payload.lan.IpmiLanRequest;
30  import org.metricshub.ipmi.core.coding.payload.lan.NetworkFunction;
31  import org.metricshub.ipmi.core.coding.protocol.IpmiMessage;
32  import org.metricshub.ipmi.core.common.TypeConverter;
33  
34  import java.security.InvalidKeyException;
35  import java.security.NoSuchAlgorithmException;
36  
37  /**
38   * Wrapper for Reserve SEL command.
39   */
40  public class ReserveSel extends IpmiCommandCoder<ReserveSelResponseData> {
41  
42  	/**
43  	 * Initiates ReserveSel for both encoding and decoding.
44  	 */
45  	public ReserveSel() {}
46  
47  	@Override
48  	public byte getCommandCode() {
49  		return CommandCodes.RESERVE_SEL;
50  	}
51  
52  	@Override
53  	public NetworkFunction getNetworkFunction() {
54  		return NetworkFunction.StorageRequest;
55  	}
56  
57  	@Override
58  	protected IpmiPayload preparePayload(int sequenceNumber) throws NoSuchAlgorithmException, InvalidKeyException {
59  		return new IpmiLanRequest(getNetworkFunction(), getCommandCode(), null, TypeConverter.intToByte(sequenceNumber));
60  	}
61  
62  	@Override
63  	public ReserveSelResponseData getResponseData(IpmiMessage message)
64  			throws IPMIException,
65  			NoSuchAlgorithmException,
66  			InvalidKeyException {
67  
68  		byte[] raw = validateResponse(message);
69  
70  		if (raw == null || raw.length != 2) {
71  			throw new IllegalArgumentException("Invalid response payload length: " + (raw != null ? raw.length : "null"));
72  		}
73  
74  		ReserveSelResponseData responseData = new ReserveSelResponseData();
75  
76  		byte[] buffer = new byte[4];
77  
78  		buffer[0] = raw[0];
79  		buffer[1] = raw[1];
80  		buffer[2] = 0;
81  		buffer[3] = 0;
82  
83  		responseData.setReservationId(TypeConverter.littleEndianByteArrayToInt(buffer));
84  
85  		return responseData;
86  	}
87  
88  }