View Javadoc
1   package org.metricshub.ipmi.core.sm.states;
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.Encoder;
26  import org.metricshub.ipmi.core.coding.commands.session.Rakp1;
27  import org.metricshub.ipmi.core.coding.commands.session.Rakp3;
28  import org.metricshub.ipmi.core.coding.protocol.encoder.Protocolv20Encoder;
29  import org.metricshub.ipmi.core.coding.rmcp.RmcpMessage;
30  import org.metricshub.ipmi.core.sm.StateMachine;
31  import org.metricshub.ipmi.core.sm.actions.ErrorAction;
32  import org.metricshub.ipmi.core.sm.actions.GetSikAction;
33  import org.metricshub.ipmi.core.sm.events.Rakp2Ack;
34  import org.metricshub.ipmi.core.sm.events.StateMachineEvent;
35  
36  /**
37   * At this state RAKP Message 2 was received - waiting for the confirmation to
38   * send RAKP Message 3. Transition to {@link Rakp3Waiting} on {@link Rakp2Ack}.
39   */
40  public class Rakp1Complete extends State {
41  
42  	private Rakp1 rakp1;
43  
44  	/**
45  	 * Initiates state.
46  	 *
47  	 * @param rakp1
48  	 *        - the {@link Rakp1} message that was sent earlier in the
49  	 *        authentification process.
50  	 */
51  	public Rakp1Complete(Rakp1 rakp1) {
52  		this.rakp1 = rakp1;
53  	}
54  
55  	@Override
56  	public void doTransition(StateMachine stateMachine, StateMachineEvent machineEvent) {
57  		if (machineEvent instanceof Rakp2Ack) {
58  			Rakp2Ack event = (Rakp2Ack) machineEvent;
59  
60  			Rakp3 rakp3 = new Rakp3(
61  					event.getStatusCode(),
62  					event.getManagedSystemSessionId(),
63  					event.getCipherSuite(),
64  					rakp1,
65  					event.getRakp1ResponseData());
66  
67  			try {
68  				stateMachine.setCurrent(
69  						new Rakp3Waiting(event.getSequenceNumber(), rakp1, event.getRakp1ResponseData(), event.getCipherSuite()));
70  				stateMachine.sendMessage(Encoder.encode(new Protocolv20Encoder(), rakp3, event.getSequenceNumber(), 0, 0));
71  				stateMachine.doExternalAction(new GetSikAction(rakp1.calculateSik(event.getRakp1ResponseData())));
72  			} catch (Exception e) {
73  				stateMachine.setCurrent(this);
74  				stateMachine.doExternalAction(new ErrorAction(e));
75  			}
76  		} else {
77  			stateMachine.doExternalAction(new ErrorAction(new IllegalArgumentException("Invalid transition")));
78  		}
79  
80  	}
81  
82  	@Override
83  	public void doAction(StateMachine stateMachine, RmcpMessage message) {
84  		// No action is needed
85  	}
86  
87  }