2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.velux.internal.bridge.slip;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.velux.internal.bridge.common.Login;
17 import org.openhab.binding.velux.internal.bridge.slip.utils.KLF200Response;
18 import org.openhab.binding.velux.internal.bridge.slip.utils.Packet;
19 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.Command;
20 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.CommandNumber;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Protocol specific bridge communication supported by the Velux bridge:
26 * <B>Authenticate / login</B>
28 * Common Message semantic: Communication with the bridge and (optionally) storing returned information within the class
31 * As 3rd level class it defines informations how to send query and receive answer through the
32 * {@link org.openhab.binding.velux.internal.bridge.VeluxBridgeProvider VeluxBridgeProvider}
33 * as described by the interface {@link org.openhab.binding.velux.internal.bridge.slip.SlipBridgeCommunicationProtocol
34 * SlipBridgeCommunicationProtocol}.
36 * Methods in addition to the mentioned interface:
38 * <LI>{@link #setPassword(String)} to define the authentication reqPassword to be used.</LI>
39 * <LI>{@link #getAuthToken()} to retrieve the authentication reqPassword.</LI>
43 * @see SlipBridgeCommunicationProtocol
46 * @author Guenther Schreiner - Initial contribution.
49 class SClogin extends Login implements SlipBridgeCommunicationProtocol {
50 private final Logger logger = LoggerFactory.getLogger(SClogin.class);
52 private static final String DESCRIPTION = "Authenticate / login";
53 private static final Command COMMAND = Command.GW_PASSWORD_ENTER_REQ;
56 * ===========================================================
57 * Message Content Parameters
60 private String reqPassword = "";
63 * ===========================================================
67 private byte[] requestData = new byte[0];
70 * ===========================================================
74 private boolean success = false;
75 private boolean finished = false;
78 * ===========================================================
79 * Methods required for interface {@link SlipBridgeCommunicationProtocol}.
83 public String name() {
88 public CommandNumber getRequestCommand() {
89 return COMMAND.getCommand();
93 public byte[] getRequestDataAsArrayOfBytes() {
94 requestData = new byte[32];
95 byte[] password = reqPassword.getBytes();
96 System.arraycopy(password, 0, requestData, 0, password.length);
101 public void setResponse(short responseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
102 KLF200Response.introLogging(logger, responseCommand, thisResponseData);
105 Packet responseData = new Packet(thisResponseData);
106 switch (Command.get(responseCommand)) {
107 case GW_PASSWORD_ENTER_CFM:
108 if (!KLF200Response.isLengthValid(logger, responseCommand, thisResponseData, 1)) {
111 int cfmStatus = responseData.getOneByteValue(0);
114 logger.debug("setResponse(): bridge connection successfully established (login succeeded).");
118 logger.warn("setResponse(): bridge connection successfully established but login failed.");
121 logger.warn("setResponse(): returned status={} (not defined).", cfmStatus);
127 KLF200Response.errorLogging(logger, responseCommand);
130 KLF200Response.outroLogging(logger, success, finished);
134 public boolean isCommunicationFinished() {
139 public boolean isCommunicationSuccessful() {
144 * ===========================================================
145 * Methods in addition to interface {@link BridgeCommunicationProtocol}.
149 public void setPassword(String thisPassword) {
150 logger.trace("setPassword({}) called.", thisPassword.replaceAll(".", "*"));
151 reqPassword = thisPassword;
156 public String getAuthToken() {
157 logger.trace("getAuthToken() called, returning {}.", reqPassword.replaceAll(".", "*"));