From 6f2876fa66b41781f4fa3ad4352b7e81e1524bd6 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Sun, 26 Nov 2023 00:22:37 +0100 Subject: [PATCH] Mi Watch 3 Lite: Fix firmware update (not enabled yet) --- .../xiaomi/services/XiaomiDataUploadService.java | 15 ++++++++++++--- app/src/main/proto/xiaomi.proto | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiDataUploadService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiDataUploadService.java index cffe771e7..9299fa81e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiDataUploadService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiDataUploadService.java @@ -50,6 +50,8 @@ public class XiaomiDataUploadService extends AbstractXiaomiService { private byte currentType; private byte[] currentBytes; + private int chunkSize; + public XiaomiDataUploadService(final XiaomiSupport support) { super(support); } @@ -59,14 +61,21 @@ public class XiaomiDataUploadService extends AbstractXiaomiService { switch (cmd.getSubtype()) { case CMD_UPLOAD_START: final XiaomiProto.DataUploadAck dataUploadAck = cmd.getDataUpload().getDataUploadAck(); - LOG.debug("Got upload start, unknown2={}, unknown4={}", dataUploadAck.getUnknown2(), dataUploadAck.getUnknown4()); + LOG.debug("Got upload start, unknown2={}, resumePosition={}", dataUploadAck.getUnknown2(), dataUploadAck.getResumePosition()); - if (dataUploadAck.getUnknown2() != 0 || dataUploadAck.getUnknown4() != 0) { + if (dataUploadAck.getUnknown2() != 0 || dataUploadAck.getResumePosition() != 0) { LOG.warn("Unexpected response"); this.currentType = 0; this.currentBytes = null; return; } + + if (dataUploadAck.hasChunkSize()) { + chunkSize = dataUploadAck.getChunkSize(); + } else { + chunkSize = 2048; + } + doUpload(currentType, currentBytes); return; } @@ -131,7 +140,7 @@ public class XiaomiDataUploadService extends AbstractXiaomiService { buf2.putInt(CheckSums.getCRC32(buf1.array())); final byte[] payload = buf2.array(); - final int partSize = 2044; // 2 + 2 at beginning of each for total and progress + final int partSize = chunkSize - 4; // 2 + 2 at beginning of each for total and progress final int totalParts = (int) Math.ceil(payload.length / (float) partSize); characteristic.setCallback(remainingParts -> { diff --git a/app/src/main/proto/xiaomi.proto b/app/src/main/proto/xiaomi.proto index 51a6934d0..fba30a3f4 100644 --- a/app/src/main/proto/xiaomi.proto +++ b/app/src/main/proto/xiaomi.proto @@ -869,5 +869,6 @@ message DataUploadRequest { message DataUploadAck { optional bytes md5sum = 1; optional uint32 unknown2 = 2; // 0 - optional uint32 unknown4 = 4; // 0 + optional uint32 resumePosition = 4; + optional uint32 chunkSize = 5; // 4096 on Redmi Watch 3 Active, Nonexistent on Mi Band 8 }