Skip to content

Commit

Permalink
- Introduced more output for debugging (w/ log level debug) (openhab#…
Browse files Browse the repository at this point in the history
…15070)

- Fixed support for MB-LAN (=KM200, version 1.0) by avoiding query of an unsupported attribute.
- BEFORE this fix: The MBLAN does not support the /gateway/registrations attribute and returns an invalid answer:
*   [b.binding.km200.internal.KM200Device] - /gateway/registrations: trying to query information.
*   [b.binding.km200.internal.KM200Device] - /gateway/registrations: trying to decode: [B@4de25f6.
*   [binding.km200.internal.KM200Cryption] - Length of message is 11.
*   [binding.km200.internal.KM200Cryption] - Did NOT decrypt message
*   [binding.km200.internal.KM200Cryption] - Exception on encoding

Logging of detailed error message.

Signed-off-by: [email protected]
Signed-off-by: Thomas Burri <[email protected]>
  • Loading branch information
gs4711 authored and tburri-alstom committed Jun 19, 2023
1 parent a671fe4 commit 833dad3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ private byte[] addZeroPadding(byte[] bdata, int bSize, String cSet) throws Unsup
try {
/* Check whether the length of the decryptData is NOT multiplies of 16 */
if ((decodedB64.length & 0xF) != 0) {
logger.debug("Length of message is {}.", decodedB64.length);
/* Return the data */
retString = new String(decodedB64, remoteDevice.getCharSet());
logger.debug("Did NOT decrypt message");
logger.debug("Did NOT decrypt message, returning {}.", retString);
return retString;
}
// --- create cipher
Expand All @@ -95,7 +96,7 @@ private byte[] addZeroPadding(byte[] bdata, int bSize, String cSet) throws Unsup
byte[] decryptedDataWOZP = removeZeroPadding(decryptedData);
return (new String(decryptedDataWOZP, remoteDevice.getCharSet()));
} catch (UnsupportedEncodingException | GeneralSecurityException e) {
logger.warn("Exception on encoding", e);
logger.warn("Exception on encoding ({})", e.getMessage());
return null;
}
}
Expand All @@ -119,7 +120,7 @@ private byte[] addZeroPadding(byte[] bdata, int bSize, String cSet) throws Unsup
logger.debug("Base64encoding not possible: {}", e.getMessage());
}
} catch (UnsupportedEncodingException | GeneralSecurityException e) {
logger.warn("Exception on encoding", e);
logger.warn("Exception on encoding ({})", e.getMessage());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class KM200Device {
public KM200Device(HttpClient httpClient) {
serviceTreeMap = new HashMap<>();
getBlacklistMap().add("/gateway/firmware");
getBlacklistMap().add("/gateway/registrations");
virtualList = new ArrayList<>();
comCryption = new KM200Cryption(this);
deviceCommunicator = new KM200Comm<>(this, httpClient);
Expand Down Expand Up @@ -330,6 +331,7 @@ public Boolean containsService(String service) {
public @Nullable JsonObject getServiceNode(String service) {
String decodedData = null;
JsonObject nodeRoot = null;
logger.debug("{}: trying to query information.", service);
byte[] recData = deviceCommunicator.getDataFromService(service.toString());
try {
if (recData == null) {
Expand All @@ -347,6 +349,7 @@ public Boolean containsService(String service) {
decodedData = "";
return nodeRoot;
} else {
logger.debug("{}: trying to decode: {}.", service, recData.toString());
decodedData = comCryption.decodeMessage(recData);
if (decodedData == null) {
logger.warn("Decoding of the KM200 message is not possible!");
Expand All @@ -355,9 +358,10 @@ public Boolean containsService(String service) {
}
if (decodedData.length() > 0) {
if ("SERVICE NOT AVAILABLE".equals(decodedData)) {
logger.debug("{}: SERVICE NOT AVAILABLE", service);
logger.warn("{}: SERVICE NOT AVAILABLE", service);
return null;
} else {
logger.debug("{}: trying to parse {}", service, decodedData.toString());
nodeRoot = (JsonObject) JsonParser.parseString(decodedData);
}
} else {
Expand Down

0 comments on commit 833dad3

Please sign in to comment.