View Javadoc
1   package org.metricshub.ipmi.core.coding.commands.sel;
2   
3   /*-
4    * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5    * IPMI Java Client
6    * ჻჻჻჻჻჻
7    * Copyright 2023 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 java.security.InvalidKeyException;
26  import java.security.NoSuchAlgorithmException;
27  
28  import org.metricshub.ipmi.core.coding.commands.CommandCodes;
29  import org.metricshub.ipmi.core.coding.commands.IpmiCommandCoder;
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.NetworkFunction;
34  import org.metricshub.ipmi.core.coding.protocol.IpmiMessage;
35  import org.metricshub.ipmi.core.common.TypeConverter;
36  
37  /**
38   * Wrapper for the Get SEL Time UTC Offset command (IPMI 2.0 revision 1.1, section 31.11a): the offset from UTC of the
39   * SEL time, for a BMC that keeps its SEL time as local time. A BMC without the command (C1h) keeps it in UTC.
40   */
41  public class GetSelTimeUtcOffset extends IpmiCommandCoder<GetSelTimeUtcOffsetResponseData> {
42  
43  	private static final int RESPONSE_LENGTH = 2;
44  
45  	/**
46  	 * Initiates GetSelTimeUtcOffset for both encoding and decoding.
47  	 */
48  	public GetSelTimeUtcOffset() {}
49  
50  	@Override
51  	public byte getCommandCode() {
52  		return CommandCodes.GET_SEL_TIME_UTC_OFFSET;
53  	}
54  
55  	@Override
56  	public NetworkFunction getNetworkFunction() {
57  		return NetworkFunction.StorageRequest;
58  	}
59  
60  	@Override
61  	protected IpmiPayload preparePayload(int sequenceNumber) throws NoSuchAlgorithmException, InvalidKeyException {
62  		return new IpmiLanRequest(getNetworkFunction(), getCommandCode(), null, TypeConverter.intToByte(sequenceNumber));
63  	}
64  
65  	@Override
66  	public GetSelTimeUtcOffsetResponseData getResponseData(IpmiMessage message)
67  			throws IPMIException,
68  			NoSuchAlgorithmException,
69  			InvalidKeyException {
70  		byte[] raw = validateResponse(message);
71  
72  		if (raw == null || raw.length != RESPONSE_LENGTH) {
73  			throw new IllegalArgumentException("Invalid response payload length: " + (raw != null ? raw.length : "null"));
74  		}
75  
76  		GetSelTimeUtcOffsetResponseData responseData = new GetSelTimeUtcOffsetResponseData();
77  		// A signed 16-bit number of minutes, LS byte first; 07FFh when unspecified (as after Set SEL Time)
78  		responseData.setOffsetMinutes((short) ((raw[0] & 0xff) | (raw[1] & 0xff) << 8));
79  		return responseData;
80  	}
81  }