1 package org.sentrysoftware.ipmi.core.coding.rmcp;
2
3 /*-
4 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5 * IPMI Java Client
6 * ჻჻჻჻჻჻
7 * Copyright 2023 Verax Systems, Sentry Software
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.sentrysoftware.ipmi.core.common.TypeConverter;
26
27 /**
28 * A wrapper class for ASF ping message.
29 */
30 public class RmcpPingMessage extends RmcpMessage {
31 /**
32 * Prepares a ready to send ASF ping message.
33 *
34 * @param sequenceNumber
35 * Used for pairing request with response. Can't be 255.
36 * @throws IllegalArgumentException
37 * when sequence number is 255.
38 */
39 public RmcpPingMessage(int sequenceNumber) {
40 super();
41 if (sequenceNumber > 254 || sequenceNumber < 0) {
42 throw new IllegalArgumentException(
43 "Sequence number must be in range 0-254");
44 }
45 setVersion(RmcpVersion.RMCP1_0);
46 setClassOfMessage(RmcpClassOfMessage.Asf);
47 setData(preparePingMessage(sequenceNumber));
48 }
49
50 private byte[] preparePingMessage(int sequenceNumber) {
51 byte[] message = new byte[8];
52
53 // set IANA Enterprise Number
54 System.arraycopy(TypeConverter.intToByteArray(RmcpConstants.ASFIANA),
55 0, message, 0, 4);
56
57 // set message type as presence ping
58 message[4] = RmcpConstants.PRESENCE_PING;
59
60 // set message tag (ASF version of a sequence number)
61 message[5] = TypeConverter.intToByte(sequenceNumber);
62
63 // reserved
64 message[6] = 0;
65
66 // data length
67 message[7] = 0;
68
69 return message;
70 }
71 }