View Javadoc
1   package org.metricshub.ipmi.core.coding.commands.chassis;
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.ResponseData;
26  import org.metricshub.ipmi.core.common.TypeConverter;
27  
28  /**
29   * Wrapper for Get Chassis Status response.
30   */
31  public class GetChassisStatusResponseData implements ResponseData {
32  
33      public static final String FRONT_PANEL_BUTTON_CAPABILITIES_NOT_SET_MESSAGE = "Front Panel Button Capabilities not set";
34  
35      private byte currentPowerState;
36  
37      private byte lastPowerEvent;
38  
39      private byte miscChassisState;
40  
41      private boolean isFrontPanelButtonCapabilitiesSet;
42  
43      private byte frontPanelButtonCapabilities;
44  
45      public GetChassisStatusResponseData() {
46          setFrontPanelButtonCapabilitiesSet(false);
47      }
48  
49      public void setCurrentPowerState(byte currentPowerState) {
50          this.currentPowerState = currentPowerState;
51      }
52  
53      public byte getCurrentPowerState() {
54          return currentPowerState;
55      }
56  
57      public PowerRestorePolicy getPowerRestorePolicy() {
58          switch ((currentPowerState & TypeConverter.intToByte(0x60)) >> 5) {
59          case 0:
60              return PowerRestorePolicy.PoweredOff;
61          case 1:
62              return PowerRestorePolicy.PowerRestored;
63          case 2:
64              return PowerRestorePolicy.PoweredUp;
65          default:
66              throw new IllegalArgumentException("Invalid Power Restore Policy");
67          }
68      }
69  
70      /**
71       * @return True when controller attempted to turn system power on or off,
72       *         but system did not enter desired state
73       */
74      public boolean isPowerControlFault() {
75          return ((currentPowerState & TypeConverter.intToByte(0x10)) != 0);
76      }
77  
78      /**
79       * @return True when fault was detected in main power subsystem.
80       */
81      public boolean isPowerFault() {
82          return ((currentPowerState & TypeConverter.intToByte(0x8)) != 0);
83      }
84  
85      /**
86       * @return True when interlock was detected (chassis is presently shut down
87       *         because a chassis panel interlock switch is active)
88       */
89      public boolean isInterlock() {
90          return ((currentPowerState & TypeConverter.intToByte(0x4)) != 0);
91      }
92  
93      /**
94       * @return True when system was shut down because of power overload
95       *         condition.
96       */
97      public boolean isPowerOverload() {
98          return ((currentPowerState & TypeConverter.intToByte(0x2)) != 0);
99      }
100 
101     /**
102      * @return True when system power is on.
103      */
104     public boolean isPowerOn() {
105         return ((currentPowerState & TypeConverter.intToByte(0x1)) != 0);
106     }
107 
108     public void setLastPowerEvent(byte lastPowerEvent) {
109         this.lastPowerEvent = lastPowerEvent;
110     }
111 
112     public byte getLastPowerEvent() {
113         return lastPowerEvent;
114     }
115 
116     /**
117      * @return True when last 'Power is on' state was entered via IPMI command.
118      */
119     public boolean wasIpmiPowerOn() {
120         return ((lastPowerEvent & TypeConverter.intToByte(0x10)) != 0);
121     }
122 
123     /**
124      * @return True if last power down caused by power fault.
125      */
126     public boolean wasPowerFault() {
127         return ((lastPowerEvent & TypeConverter.intToByte(0x8)) != 0);
128     }
129 
130     /**
131      * @return True if last power down caused by a power interlock being
132      *         activated.
133      */
134     public boolean wasInterlock() {
135         return ((lastPowerEvent & TypeConverter.intToByte(0x4)) != 0);
136     }
137 
138     /**
139      * @return True if last power down caused by a Power overload.
140      */
141     public boolean wasPowerOverload() {
142         return ((lastPowerEvent & TypeConverter.intToByte(0x2)) != 0);
143     }
144 
145     /**
146      * @return True if AC failed.
147      */
148     public boolean acFailed() {
149         return ((lastPowerEvent & TypeConverter.intToByte(0x1)) != 0);
150 
151     }
152 
153     public void setMiscChassisState(byte miscChassisState) {
154         this.miscChassisState = miscChassisState;
155     }
156 
157     public byte getMiscChassisState() {
158         return miscChassisState;
159     }
160 
161     /**
162      * @return True if Chassis Identify command and state info supported.
163      */
164     public boolean isChassisIdentifyCommandSupported() {
165         return ((miscChassisState & TypeConverter.intToByte(0x40)) != 0);
166     }
167 
168     public ChassisIdentifyState getChassisIdentifyState() {
169         if (!isChassisIdentifyCommandSupported()) {
170             throw new IllegalAccessError(
171                     "Chassis Idetify command and state not supported");
172         }
173 
174         return ChassisIdentifyState.parseInt((miscChassisState & TypeConverter
175                 .intToByte(0x30)) >> 4);
176     }
177 
178     /**
179      * @return True if cooling or fan fault was detected.
180      */
181     public boolean coolingFaultDetected() {
182         return ((miscChassisState & TypeConverter.intToByte(0x8)) != 0);
183     }
184 
185     /**
186      * @return True if drive fault was detected.
187      */
188     public boolean driveFaultDetected() {
189         return ((miscChassisState & TypeConverter.intToByte(0x4)) != 0);
190     }
191 
192     /**
193      * @return True if Front Panel Lockout active (power off and reset via
194      *         chassis push-buttons disabled.).
195      */
196     public boolean isFrontPanelLockoutActive() {
197         return ((miscChassisState & TypeConverter.intToByte(0x2)) != 0);
198     }
199 
200     /**
201      * @return True if Chassis intrusion active is active.
202      */
203     public boolean isChassisIntrusionActive() {
204         return ((miscChassisState & TypeConverter.intToByte(0x1)) != 0);
205     }
206 
207     public void setFrontPanelButtonCapabilities(
208             byte frontPanelButtonCapabilities) {
209         this.frontPanelButtonCapabilities = frontPanelButtonCapabilities;
210         setFrontPanelButtonCapabilitiesSet(true);
211     }
212 
213     public byte getFrontPanelButtonCapabilities() {
214         return frontPanelButtonCapabilities;
215     }
216 
217     /**
218      * @return Standby (sleep) button disable is allowed.
219      * @throws IllegalAccessException
220      *             when Front Panel Button Capabilities wasn't set.
221      */
222     public boolean isStandbyButtonDisableAllowed()
223             throws IllegalAccessException {
224         if (!isFrontPanelButtonCapabilitiesSet()) {
225             throw new IllegalAccessException(FRONT_PANEL_BUTTON_CAPABILITIES_NOT_SET_MESSAGE);
226         }
227         return ((frontPanelButtonCapabilities & TypeConverter.intToByte(0x80)) != 0);
228     }
229 
230     /**
231      * @return Diagnostic Interrupt button disable is allowed.
232      * @throws IllegalAccessException
233      *             when Front Panel Button Capabilities wasn't set.
234      */
235     public boolean isDiagnosticInterruptButtonDisableAllowed()
236             throws IllegalAccessException {
237         if (!isFrontPanelButtonCapabilitiesSet()) {
238             throw new IllegalAccessException(FRONT_PANEL_BUTTON_CAPABILITIES_NOT_SET_MESSAGE);
239         }
240         return ((frontPanelButtonCapabilities & TypeConverter.intToByte(0x40)) != 0);
241     }
242 
243     /**
244      * @return Reset button disable is allowed.
245      * @throws IllegalAccessException
246      *             when Front Panel Button Capabilities wasn't set.
247      */
248     public boolean isResetButtonDisableAllowed() throws IllegalAccessException {
249         if (!isFrontPanelButtonCapabilitiesSet()) {
250             throw new IllegalAccessException(FRONT_PANEL_BUTTON_CAPABILITIES_NOT_SET_MESSAGE);
251         }
252         return ((frontPanelButtonCapabilities & TypeConverter.intToByte(0x20)) != 0);
253     }
254 
255     /**
256      * @return Power off button disable allowed (in the case there is a single
257      *         combined power/standby (sleep) button, disabling power off also
258      *         disables sleep requests via that button.)
259      * @throws IllegalAccessException
260      *             when Front Panel Button Capabilities wasn't set.
261      */
262     public boolean isPowerOffButtonDisableAllowed()
263             throws IllegalAccessException {
264         if (!isFrontPanelButtonCapabilitiesSet()) {
265             throw new IllegalAccessException(FRONT_PANEL_BUTTON_CAPABILITIES_NOT_SET_MESSAGE);
266         }
267         return ((frontPanelButtonCapabilities & TypeConverter.intToByte(0x10)) != 0);
268     }
269 
270     /**
271      * @return Standby (sleep) button disabled.
272      * @throws IllegalAccessException
273      *             when Front Panel Button Capabilities wasn't set.
274      */
275     public boolean isStandbyButtonDisabled() throws IllegalAccessException {
276         if (!isFrontPanelButtonCapabilitiesSet()) {
277             throw new IllegalAccessException(FRONT_PANEL_BUTTON_CAPABILITIES_NOT_SET_MESSAGE);
278         }
279         return ((frontPanelButtonCapabilities & TypeConverter.intToByte(0x8)) != 0);
280     }
281 
282     /**
283      * @return Diagnostic Interrupt button disabled.
284      * @throws IllegalAccessException
285      *             when Front Panel Button Capabilities wasn't set.
286      */
287     public boolean isDiagnosticInterruptButtonDisabled()
288             throws IllegalAccessException {
289         if (!isFrontPanelButtonCapabilitiesSet()) {
290             throw new IllegalAccessException(FRONT_PANEL_BUTTON_CAPABILITIES_NOT_SET_MESSAGE);
291         }
292         return ((frontPanelButtonCapabilities & TypeConverter.intToByte(0x4)) != 0);
293     }
294 
295     /**
296      * @return Reset button disabled.
297      * @throws IllegalAccessException
298      *             when Front Panel Button Capabilities wasn't set.
299      */
300     public boolean isResetButtonDisabled() throws IllegalAccessException {
301         if (!isFrontPanelButtonCapabilitiesSet()) {
302             throw new IllegalAccessException(FRONT_PANEL_BUTTON_CAPABILITIES_NOT_SET_MESSAGE);
303         }
304         return ((frontPanelButtonCapabilities & TypeConverter.intToByte(0x2)) != 0);
305     }
306 
307     /**
308      * @return Power off button disabled (in the case there is a single combined
309      *         power/standby (sleep) button, disabling power off also disables
310      *         sleep requests via that button are also disabled.)
311      * @throws IllegalAccessException
312      *             when Front Panel Button Capabilities wasn't set.
313      */
314     public boolean isPowerOffButtonDisabled() throws IllegalAccessException {
315         if (!isFrontPanelButtonCapabilitiesSet()) {
316             throw new IllegalAccessException(
317                     FRONT_PANEL_BUTTON_CAPABILITIES_NOT_SET_MESSAGE);
318         }
319         return ((frontPanelButtonCapabilities & TypeConverter.intToByte(0x1)) != 0);
320     }
321 
322     private void setFrontPanelButtonCapabilitiesSet(
323             boolean isFrontPanelButtonCapabilitiesSet) {
324         this.isFrontPanelButtonCapabilitiesSet = isFrontPanelButtonCapabilitiesSet;
325     }
326 
327     public boolean isFrontPanelButtonCapabilitiesSet() {
328         return isFrontPanelButtonCapabilitiesSet;
329     }
330 
331 }