View Javadoc
1   package org.metricshub.ipmi.core.coding.commands.session;
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.IpmiCommandCoder;
26  import org.metricshub.ipmi.core.coding.commands.IpmiVersion;
27  import org.metricshub.ipmi.core.coding.commands.ResponseData;
28  import org.metricshub.ipmi.core.coding.payload.IpmiPayload;
29  import org.metricshub.ipmi.core.coding.payload.lan.IPMIException;
30  import org.metricshub.ipmi.core.coding.payload.lan.IpmiLanRequest;
31  import org.metricshub.ipmi.core.coding.payload.lan.NetworkFunction;
32  import org.metricshub.ipmi.core.coding.protocol.AuthenticationType;
33  import org.metricshub.ipmi.core.coding.protocol.IpmiMessage;
34  import org.metricshub.ipmi.core.coding.security.CipherSuite;
35  import org.metricshub.ipmi.core.common.TypeConverter;
36  
37  import java.security.InvalidKeyException;
38  import java.security.NoSuchAlgorithmException;
39  
40  /**
41   * Wrapper for Close Session request
42   */
43  public class CloseSession extends IpmiCommandCoder {
44  
45      private int sessionId;
46  
47      /**
48       * Initiates CloseSession for both encoding and decoding.
49       *
50       * @param version
51       *            - IPMI version of the command.
52       * @param cipherSuite
53       *            - {@link CipherSuite} containing authentication,
54       *            confidentiality and integrity algorithms for this session.
55       * @param authenticationType
56       *            - Type of authentication used. Must be RMCPPlus for IPMI v2.0.
57       * @param sessionId
58       *            - Generated by managed system ID of the session to close.
59       */
60      public CloseSession(IpmiVersion version, CipherSuite cipherSuite,
61              AuthenticationType authenticationType, int sessionId) {
62          super(version, cipherSuite, authenticationType);
63  
64          if (sessionId == 0) {
65              throw new IllegalArgumentException("Cannot close session '0'");
66          }
67  
68          this.sessionId = sessionId;
69      }
70  
71      @Override
72      public byte getCommandCode() {
73          return TypeConverter.intToByte(0x3c);
74      }
75  
76      @Override
77      public NetworkFunction getNetworkFunction() {
78          return NetworkFunction.ApplicationRequest;
79      }
80  
81      @Override
82      protected IpmiPayload preparePayload(int sequenceNumber)
83              throws NoSuchAlgorithmException, InvalidKeyException {
84  
85          byte[] payload = TypeConverter.intToLittleEndianByteArray(sessionId);
86  
87          return new IpmiLanRequest(getNetworkFunction(), getCommandCode(),
88                  payload, TypeConverter.intToByte(sequenceNumber));
89      }
90  
91      @Override
92      public ResponseData getResponseData(IpmiMessage message) throws IPMIException, NoSuchAlgorithmException, InvalidKeyException {
93          return new CloseSessionResponseData();
94      }
95  
96  }