View Javadoc
1   package org.metricshub.ipmi.core.coding.payload.lan;
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.payload.CompletionCode;
26  import org.metricshub.ipmi.core.common.TypeConverter;
27  
28  /**
29   * A wrapper class for IPMB response message.
30   */
31  public class IpmiLanResponse extends IpmiLanMessage {
32  
33      private CompletionCode completionCode;
34  
35      public void setCompletionCode(byte completionCode) {
36          this.completionCode = CompletionCode.parseInt(TypeConverter
37                  .byteToInt(completionCode));
38      }
39  
40      public CompletionCode getCompletionCode() {
41          return completionCode;
42      }
43  
44      /**
45       * Builds IPMI LAN response message from byte array.
46       *
47       * @param rawData
48       * @throws IllegalArgumentException
49       *             when checksum is corrupted
50       */
51      public IpmiLanResponse(byte[] rawData) {
52          setRequesterAddress(rawData[0]);
53          networkFunction = TypeConverter.intToByte((TypeConverter
54                  .byteToInt(rawData[1]) & 0xfC) >> 2);
55          setRequesterLogicalUnitNumber(TypeConverter.intToByte(TypeConverter
56                  .byteToInt(rawData[1]) & 0x03));
57          if (rawData[2] != getChecksum1(rawData)) {
58              throw new IllegalArgumentException("Checksum 1 failed");
59          }
60          setResponderAddress(rawData[3]);
61          setSequenceNumber(TypeConverter.intToByte((TypeConverter
62                  .byteToInt(rawData[4]) & 0xfC) >> 2));
63          setResponderLogicalUnitNumber(TypeConverter.intToByte(TypeConverter
64                  .byteToInt(rawData[4]) & 0x03));
65          setCommand(rawData[5]);
66          setCompletionCode(rawData[6]);
67  
68          if (rawData.length > 8) {
69              byte[] data = new byte[rawData.length - 8];
70  
71              System.arraycopy(rawData, 7, data, 0, rawData.length - 8);
72  
73              setData(data);
74          }
75  
76          if (rawData[rawData.length - 1] != getChecksum2(rawData)) {
77              throw new IllegalArgumentException("Checksum 2 failed");
78          }
79      }
80  
81      @Override
82      public int getPayloadLength() {
83          int length = 8;
84          if (getData() != null) {
85              length += getData().length;
86          }
87          return length;
88      }
89  
90      /**
91       * @deprecated LAN response does not hve payload data
92       */
93      @Override
94      @Deprecated
95      public byte[] getPayloadData() {
96          return null;
97      }
98  
99  }