1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-19 11:30:44 +02:00

Mi Band 8: Fix watchface upload

This commit is contained in:
José Rebelo 2023-10-23 23:30:59 +01:00
parent 27fba50283
commit cab63b2c98
2 changed files with 7 additions and 8 deletions

View File

@ -276,21 +276,18 @@ public class XiaomiCharacteristic {
final boolean encrypt = isEncrypted && authService.isEncryptionInitialized();
if (encrypt) {
currentPayload.setBytesToSend(authService.encrypt(currentPayload.getBytesToSend(), encryptedIndex));
currentPayload.setBytesToSend(authService.encrypt(currentPayload.getBytesToSend(), incrementNonce ? encryptedIndex : 0));
}
if (shouldWriteChunked(currentPayload.getBytesToSend())) {
if (encrypt) {
if (encrypt && incrementNonce) {
// Prepend encrypted index for the nonce
currentPayload.setBytesToSend(
ByteBuffer.allocate(2 + currentPayload.getBytesToSend().length).order(ByteOrder.LITTLE_ENDIAN)
.putShort(encryptedIndex)
.putShort(encryptedIndex++)
.put(currentPayload.getBytesToSend())
.array()
);
if (incrementNonce) {
encryptedIndex++;
}
}
LOG.debug("Sending {} - chunked", currentPayload.getTaskName());
@ -319,9 +316,10 @@ public class XiaomiCharacteristic {
buf.put((byte) 2); // 2 for command
buf.put((byte) (encrypt ? 1 : 2));
if (encrypt) {
buf.putShort(encryptedIndex);
if (incrementNonce) {
encryptedIndex++;
buf.putShort(encryptedIndex++);
} else {
buf.putShort((short) 0);
}
}
buf.put(currentPayload.getBytesToSend()); // it's already encrypted

View File

@ -244,6 +244,7 @@ public class XiaomiWatchfaceService extends AbstractXiaomiService implements Xia
if (success) {
setWatchface(fwHelper.getId());
requestWatchfaceList();
}
fwHelper = null;