1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 03:16:51 +01:00

Amazfit Cor: Fix recogition of new firmwares

Newer Cor and Bip firmwares seem to be indistinguishable,
What we do for now is use the version we already search for say
Bip firmwares are valid from 0.0.8.00 to < 1.0.5.00 (lastest as of today is 0.1.0.39)
Cor firmwares are valid from 1.0.5.00

This should work for a while.
Fixes #1095
This commit is contained in:
Andreas Shimokawa 2018-05-12 00:05:30 +02:00
parent 3f421facab
commit 746cb00460
2 changed files with 30 additions and 28 deletions

View File

@ -24,6 +24,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType;
import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils; import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Version;
public class AmazfitBipFirmwareInfo extends HuamiFirmwareInfo { public class AmazfitBipFirmwareInfo extends HuamiFirmwareInfo {
// gps detection is totally bogus, just the first 16 bytes // gps detection is totally bogus, just the first 16 bytes
@ -45,21 +46,11 @@ public class AmazfitBipFirmwareInfo extends HuamiFirmwareInfo {
(byte) 0x8c, 0x36, 0x2e, (byte) 0x8c, (byte) 0x9c, 0x08, 0x54, (byte) 0xa6 (byte) 0x8c, 0x36, 0x2e, (byte) 0x8c, (byte) 0x9c, 0x08, 0x54, (byte) 0xa6
}; };
// guessed - at least it is the same across versions from 0.0.7.x to 0.0.9.x // this is the same as Cor
// and different from other devices
private static final byte[] FW_HEADER = new byte[]{ private static final byte[] FW_HEADER = new byte[]{
0x68, 0x46, 0x70, 0x47, 0x68, 0x46, 0x70, 0x47, 0x00, (byte) 0x98, 0x00, 0x20, (byte) 0xA5, 0x04, 0x00, 0x20, (byte) 0xAD, 0x04, 0x00, 0x20, (byte) 0xC5, 0x04, 0x00, 0x20
0x68, 0x46, 0x70, 0x47, 0x68, 0x46, 0x70, 0x47
}; };
// guessed - this is true for 0.1.0.11
private static final byte[] FW_HEADER_NEW = new byte[]{
0x60, (byte) 0xeb, 0x03, 0x0c, 0x70, 0x46, 0x31, 0x46,
0x3a, 0x46, 0x63, 0x46, (byte) 0xbd, (byte) 0xe8, (byte) 0xf0, (byte) 0x81
};
private static final int FW_HEADER_OFFSET = 0x9330;
private static final byte[] GPS_ALMANAC_HEADER = new byte[]{ // probably wrong private static final byte[] GPS_ALMANAC_HEADER = new byte[]{ // probably wrong
(byte) 0xa0, (byte) 0x80, 0x08, 0x00, (byte) 0x8b, 0x07 (byte) 0xa0, (byte) 0x80, 0x08, 0x00, (byte) 0x8b, 0x07
}; };
@ -152,9 +143,15 @@ public class AmazfitBipFirmwareInfo extends HuamiFirmwareInfo {
if (ArrayUtils.startsWith(bytes, GPS_CEP_HEADER)) { if (ArrayUtils.startsWith(bytes, GPS_CEP_HEADER)) {
return HuamiFirmwareType.GPS_CEP; return HuamiFirmwareType.GPS_CEP;
} }
if (ArrayUtils.equals(bytes, FW_HEADER, FW_HEADER_OFFSET) || ArrayUtils.equals(bytes, FW_HEADER_NEW, FW_HEADER_OFFSET)) { if (ArrayUtils.startsWith(bytes, FW_HEADER)) {
// TODO: this is certainly not a correct validation, but it works for now String foundVersion = searchFirmwareVersion(bytes);
return HuamiFirmwareType.FIRMWARE; if (foundVersion != null) {
Version version = new Version(foundVersion);
if ((version.compareTo(new Version("0.0.8.00")) >= 0) && (version.compareTo(new Version("1.0.5.00")) < 0)) {
return HuamiFirmwareType.FIRMWARE;
}
}
return HuamiFirmwareType.INVALID;
} }
if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER)) { if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER)) {
return HuamiFirmwareType.WATCHFACE; return HuamiFirmwareType.WATCHFACE;

View File

@ -24,19 +24,14 @@ import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType;
import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils; import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Version;
public class AmazfitCorFirmwareInfo extends HuamiFirmwareInfo { public class AmazfitCorFirmwareInfo extends HuamiFirmwareInfo {
// guessed - at least it is the same accross current versions and different from other devices // this is the same as Bip
private static final byte[] FW_HEADER = new byte[]{ private static final byte[] FW_HEADER = new byte[]{
(byte) 0x06, (byte) 0x48, (byte) 0x00, (byte) 0x47, (byte) 0xfe, (byte) 0xe7, (byte) 0xfe, (byte) 0xe7, 0x00, (byte) 0x98, 0x00, 0x20, (byte) 0xA5, 0x04, 0x00, 0x20, (byte) 0xAD, 0x04, 0x00, 0x20, (byte) 0xC5, 0x04, 0x00, 0x20
(byte) 0xfe, (byte) 0xe7, (byte) 0xfe, (byte) 0xe7, (byte) 0xfe, (byte) 0xe7, (byte) 0xfe, (byte) 0xe7
}; };
//FIXME: this is a moving target :/
private static final int FW_HEADER_OFFSET = 0x9330;
private static final int FW_HEADER_OFFSET_2 = 0x9340;
private static final int FW_HEADER_OFFSET_3 = 0x9288;
private static final int COMPRESSED_RES_HEADER_OFFSET = 0x9; private static final int COMPRESSED_RES_HEADER_OFFSET = 0x9;
private static Map<Integer, String> crcToVersion = new HashMap<>(); private static Map<Integer, String> crcToVersion = new HashMap<>();
@ -65,14 +60,24 @@ public class AmazfitCorFirmwareInfo extends HuamiFirmwareInfo {
return HuamiFirmwareType.INVALID; return HuamiFirmwareType.INVALID;
} }
return HuamiFirmwareType.RES; return HuamiFirmwareType.RES;
} else if (ArrayUtils.equals(bytes, RES_HEADER, COMPRESSED_RES_HEADER_OFFSET) || ArrayUtils.equals(bytes, NEWRES_HEADER, COMPRESSED_RES_HEADER_OFFSET)) { }
if (ArrayUtils.equals(bytes, RES_HEADER, COMPRESSED_RES_HEADER_OFFSET) || ArrayUtils.equals(bytes, NEWRES_HEADER, COMPRESSED_RES_HEADER_OFFSET)) {
return HuamiFirmwareType.RES_COMPRESSED; return HuamiFirmwareType.RES_COMPRESSED;
} else if (ArrayUtils.equals(bytes, FW_HEADER, FW_HEADER_OFFSET) || ArrayUtils.equals(bytes, FW_HEADER, FW_HEADER_OFFSET_2) || ArrayUtils.equals(bytes, FW_HEADER, FW_HEADER_OFFSET_3)) { }
// TODO: this is certainly not a correct validation, but it works for now if (ArrayUtils.startsWith(bytes, FW_HEADER)) {
return HuamiFirmwareType.FIRMWARE; String foundVersion = searchFirmwareVersion(bytes);
} else if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER)) { if (foundVersion != null) {
Version version = new Version(foundVersion);
if (version.compareTo(new Version("1.0.5.00")) >= 0) {
return HuamiFirmwareType.FIRMWARE;
}
}
return HuamiFirmwareType.INVALID;
}
if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER)) {
return HuamiFirmwareType.WATCHFACE; return HuamiFirmwareType.WATCHFACE;
} }
return HuamiFirmwareType.INVALID; return HuamiFirmwareType.INVALID;
} }