1 package org.sentrysoftware.ipmi.core.sm.states;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import org.sentrysoftware.ipmi.core.coding.commands.session.Rakp1;
26 import org.sentrysoftware.ipmi.core.coding.payload.PlainMessage;
27 import org.sentrysoftware.ipmi.core.coding.protocol.AuthenticationType;
28 import org.sentrysoftware.ipmi.core.coding.protocol.IpmiMessage;
29 import org.sentrysoftware.ipmi.core.coding.protocol.PayloadType;
30 import org.sentrysoftware.ipmi.core.coding.protocol.decoder.PlainCommandv20Decoder;
31 import org.sentrysoftware.ipmi.core.coding.protocol.decoder.ProtocolDecoder;
32 import org.sentrysoftware.ipmi.core.coding.protocol.decoder.Protocolv20Decoder;
33 import org.sentrysoftware.ipmi.core.coding.rmcp.RmcpMessage;
34 import org.sentrysoftware.ipmi.core.coding.security.CipherSuite;
35 import org.sentrysoftware.ipmi.core.common.TypeConverter;
36 import org.sentrysoftware.ipmi.core.sm.StateMachine;
37 import org.sentrysoftware.ipmi.core.sm.actions.ErrorAction;
38 import org.sentrysoftware.ipmi.core.sm.actions.ResponseAction;
39 import org.sentrysoftware.ipmi.core.sm.events.DefaultAck;
40 import org.sentrysoftware.ipmi.core.sm.events.StateMachineEvent;
41 import org.sentrysoftware.ipmi.core.sm.events.Timeout;
42
43
44
45
46
47
48
49
50 public class Rakp1Waiting extends State {
51
52 private Rakp1 rakp1;
53
54 private int tag;
55
56
57
58
59
60
61
62
63 public Rakp1Waiting(int tag, Rakp1 rakp1) {
64 this.tag = tag;
65 this.rakp1 = rakp1;
66 }
67
68 @Override
69 public void doTransition(StateMachine stateMachine,
70 StateMachineEvent machineEvent) {
71 if (machineEvent instanceof DefaultAck) {
72 stateMachine.setCurrent(new Rakp1Complete(rakp1));
73 } else if (machineEvent instanceof Timeout) {
74 stateMachine.setCurrent(new Authcap());
75 } else {
76 stateMachine.doExternalAction(new ErrorAction(
77 new IllegalArgumentException("Invalid transition")));
78 }
79
80 }
81
82 @Override
83 public void doAction(StateMachine stateMachine, RmcpMessage message) {
84 if (ProtocolDecoder.decodeAuthenticationType(message) != AuthenticationType.RMCPPlus) {
85 return;
86 }
87 PlainCommandv20Decoder decoder = new PlainCommandv20Decoder(
88 CipherSuite.getEmpty());
89 if (Protocolv20Decoder.decodePayloadType(message.getData()[1]) != PayloadType.Rakp2) {
90 return;
91 }
92 IpmiMessage ipmiMessage = null;
93 try {
94 ipmiMessage = decoder.decode(message);
95 if (rakp1.isCommandResponse(ipmiMessage)
96 && TypeConverter.byteToInt(((PlainMessage) ipmiMessage
97 .getPayload()).getPayloadData()[0]) == tag) {
98 stateMachine.doExternalAction(new ResponseAction(rakp1
99 .getResponseData(ipmiMessage)));
100 }
101 } catch (Exception e) {
102 stateMachine.doExternalAction(new ErrorAction(e));
103 }
104 }
105 }