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 class for Get SEL Info request.
39   */
40  public class GetSelInfo extends IpmiCommandCoder<GetSelInfoResponseData> {
41  
42  	/**
43  	 * Initiates GetSelInfo for both encoding and decoding.
44  	 */
45  	public GetSelInfo() {}
46  
47  	@Override
48  	public byte getCommandCode() {
49  		return CommandCodes.GET_SEL_INFO;
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 GetSelInfoResponseData getResponseData(IpmiMessage message)
64  			throws IPMIException,
65  			NoSuchAlgorithmException,
66  			InvalidKeyException {
67  		byte[] raw = validateResponse(message);
68  
69  		if (raw == null || raw.length != 14) {
70  			throw new IllegalArgumentException("Invalid response payload length: " + (raw != null ? raw.length : "null"));
71  		}
72  
73  		GetSelInfoResponseData responseData = new GetSelInfoResponseData();
74  
75  		responseData.setSelVersion(TypeConverter.littleEndianBcdByteToInt(raw[0]));
76  
77  		byte[] buffer = new byte[4];
78  
79  		buffer[0] = raw[1];
80  		buffer[1] = raw[2];
81  		buffer[2] = 0;
82  		buffer[3] = 0;
83  
84  		responseData.setEntriesCount(TypeConverter.littleEndianByteArrayToInt(buffer));
85  
86  		System.arraycopy(raw, 5, buffer, 0, 4);
87  
88  		responseData.setAdditionTimestamp(TypeConverter.decodeDate(TypeConverter.littleEndianByteArrayToInt(buffer)));
89  
90  		System.arraycopy(raw, 9, buffer, 0, 4);
91  
92  		responseData.setEraseTimestamp(TypeConverter.decodeDate(TypeConverter.littleEndianByteArrayToInt(buffer)));
93  
94  		return responseData;
95  	}
96  
97  }