From 1920968fba3912c1fbad12dac9b08094f4e35249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Tue, 17 Oct 2023 13:14:35 +0100 Subject: [PATCH] Mi Watch Lite: Attempt to fix plaintext support --- .../devices/xiaomi/XiaomiCharacteristic.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/XiaomiCharacteristic.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/XiaomiCharacteristic.java index 6c7f664db..70a06ad35 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/XiaomiCharacteristic.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/XiaomiCharacteristic.java @@ -242,11 +242,13 @@ public class XiaomiCharacteristic { } if (shouldWriteChunked(currentSending)) { - // Prepend encrypted index - currentSending = ByteBuffer.allocate(2 + currentSending.length).order(ByteOrder.LITTLE_ENDIAN) - .putShort(encryptedIndex++) - .put(currentSending) - .array(); + if (isEncrypted) { + // Prepend encrypted index for the nonce + currentSending = ByteBuffer.allocate(2 + currentSending.length).order(ByteOrder.LITTLE_ENDIAN) + .putShort(encryptedIndex++) + .put(currentSending) + .array(); + } LOG.debug("Sending next - chunked"); @@ -255,7 +257,7 @@ public class XiaomiCharacteristic { final ByteBuffer buf = ByteBuffer.allocate(6).order(ByteOrder.LITTLE_ENDIAN); buf.putShort((short) 0); buf.put((byte) 0); - buf.put((byte) 1); + buf.put((byte) (isEncrypted ? 1 : 0)); buf.putShort((short) Math.round(currentSending.length / 247.0)); final TransactionBuilder builder = mSupport.createTransactionBuilder("send chunked start");