From f56a4b9f0ca005612872b576c7836c100c68b18a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sun, 8 Oct 2023 17:28:13 +0100 Subject: [PATCH] Mi Band 8: Add MTU warn on sendCommand --- .../gadgetbridge/service/devices/xiaomi/XiaomiSupport.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/XiaomiSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/XiaomiSupport.java index 849d15df1..570b76ee8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/XiaomiSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/XiaomiSupport.java @@ -513,7 +513,12 @@ public class XiaomiSupport extends AbstractBTLEDeviceSupport { public void sendCommand(final TransactionBuilder builder, final XiaomiProto.Command command) { final byte[] commandBytes = command.toByteArray(); final byte[] encryptedCommandBytes = authService.encrypt(commandBytes, encryptedIndex); - final ByteBuffer buf = ByteBuffer.allocate(6 + encryptedCommandBytes.length).order(ByteOrder.LITTLE_ENDIAN); + final int commandLength = 6 + encryptedCommandBytes.length; + if (commandLength > getMTU()) { + LOG.warn("Command with {} bytes is too large for MTU of {}", commandLength, getMTU()); + } + + final ByteBuffer buf = ByteBuffer.allocate(commandLength).order(ByteOrder.LITTLE_ENDIAN); buf.putShort((short) 0); buf.put((byte) 2); // 2 for command buf.put((byte) 1); // 1 for encrypted