2018-02-26 14:27:32 +01:00
|
|
|
/* Copyright (C) 2017-2018 Andreas Shimokawa, Carsten Pfeiffer
|
2017-08-25 00:21:47 +02:00
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip;
|
|
|
|
|
2017-10-24 22:01:25 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2017-08-25 00:21:47 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
2017-10-24 22:01:25 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo;
|
2017-10-21 22:50:28 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType;
|
2017-08-25 00:21:47 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
|
2018-05-12 00:05:30 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Version;
|
2017-08-25 00:21:47 +02:00
|
|
|
|
2017-10-24 22:01:25 +02:00
|
|
|
public class AmazfitBipFirmwareInfo extends HuamiFirmwareInfo {
|
2017-12-22 23:29:38 +01:00
|
|
|
// gps detection is totally bogus, just the first 16 bytes
|
2017-08-25 00:21:47 +02:00
|
|
|
private static final byte[] GPS_HEADER = new byte[]{
|
|
|
|
(byte) 0xcb, 0x51, (byte) 0xc1, 0x30, 0x41, (byte) 0x9e, 0x5e, (byte) 0xd3,
|
|
|
|
0x51, 0x35, (byte) 0xdf, 0x66, (byte) 0xed, (byte) 0xd9, 0x5f, (byte) 0xa7
|
|
|
|
};
|
2017-10-25 08:29:33 +02:00
|
|
|
private static final byte[] GPS_HEADER2 = new byte[]{
|
|
|
|
0x10, 0x50, 0x26, 0x76, (byte) 0x8f, 0x4a, (byte) 0xa1, 0x49,
|
|
|
|
(byte) 0xa7, 0x26, (byte) 0xd0, (byte) 0xe6, 0x4a, 0x21, (byte) 0x88, (byte) 0xd4
|
|
|
|
};
|
2017-12-22 23:29:38 +01:00
|
|
|
private static final byte[] GPS_HEADER3 = new byte[]{
|
|
|
|
(byte) 0xeb, (byte) 0xfa, (byte) 0xc5, (byte) 0x89, (byte) 0xf0, 0x5c, 0x2e, (byte) 0xcc,
|
|
|
|
(byte) 0xfa, (byte) 0xf3, 0x62, (byte) 0xeb, (byte) 0x92, (byte) 0xc6, (byte) 0xa1, (byte) 0xbb
|
|
|
|
};
|
2017-08-25 00:21:47 +02:00
|
|
|
|
2018-01-13 11:12:58 +01:00
|
|
|
private static final byte[] GPS_HEADER4 = new byte[]{
|
|
|
|
0x0b, 0x61, 0x53, (byte) 0xed, (byte) 0x83, (byte) 0xac, 0x07, 0x21,
|
|
|
|
(byte) 0x8c, 0x36, 0x2e, (byte) 0x8c, (byte) 0x9c, 0x08, 0x54, (byte) 0xa6
|
|
|
|
};
|
|
|
|
|
2018-05-12 00:05:30 +02:00
|
|
|
// this is the same as Cor
|
2017-08-25 00:21:47 +02:00
|
|
|
private static final byte[] FW_HEADER = new byte[]{
|
2018-05-12 00:05:30 +02:00
|
|
|
0x00, (byte) 0x98, 0x00, 0x20, (byte) 0xA5, 0x04, 0x00, 0x20, (byte) 0xAD, 0x04, 0x00, 0x20, (byte) 0xC5, 0x04, 0x00, 0x20
|
2017-08-25 00:21:47 +02:00
|
|
|
};
|
|
|
|
|
2017-09-24 22:44:18 +02:00
|
|
|
private static final byte[] GPS_ALMANAC_HEADER = new byte[]{ // probably wrong
|
|
|
|
(byte) 0xa0, (byte) 0x80, 0x08, 0x00, (byte) 0x8b, 0x07
|
2017-09-15 11:44:24 +02:00
|
|
|
};
|
|
|
|
|
2017-09-24 22:44:18 +02:00
|
|
|
private static final byte[] GPS_CEP_HEADER = new byte[]{ // probably wrong
|
|
|
|
0x2a, 0x12, (byte) 0xa0, 0x02
|
2017-09-15 11:44:24 +02:00
|
|
|
};
|
2017-08-25 00:21:47 +02:00
|
|
|
|
2017-10-24 22:01:25 +02:00
|
|
|
private static Map<Integer, String> crcToVersion = new HashMap<>();
|
2017-08-25 00:21:47 +02:00
|
|
|
static {
|
|
|
|
// firmware
|
|
|
|
crcToVersion.put(25257, "0.0.8.74");
|
2017-09-11 23:05:49 +02:00
|
|
|
crcToVersion.put(57724, "0.0.8.88");
|
2017-09-15 11:44:24 +02:00
|
|
|
crcToVersion.put(27668, "0.0.8.96");
|
2017-09-24 22:44:18 +02:00
|
|
|
crcToVersion.put(60173, "0.0.8.97");
|
2017-12-11 23:36:39 +01:00
|
|
|
crcToVersion.put(3462, "0.0.8.98");
|
2017-09-28 16:20:22 +02:00
|
|
|
crcToVersion.put(55420, "0.0.9.14");
|
2017-10-25 08:29:33 +02:00
|
|
|
crcToVersion.put(39465, "0.0.9.26");
|
2017-11-09 21:59:41 +01:00
|
|
|
crcToVersion.put(27394, "0.0.9.40");
|
2017-12-02 01:28:59 +01:00
|
|
|
crcToVersion.put(24736, "0.0.9.49");
|
|
|
|
crcToVersion.put(49555, "0.0.9.59");
|
2017-12-16 23:25:56 +01:00
|
|
|
crcToVersion.put(28586, "0.1.0.08");
|
2017-12-02 01:28:59 +01:00
|
|
|
crcToVersion.put(26714, "0.1.0.11");
|
2017-12-16 23:25:56 +01:00
|
|
|
crcToVersion.put(64160, "0.1.0.17");
|
2018-01-13 11:12:58 +01:00
|
|
|
crcToVersion.put(21992, "0.1.0.26");
|
2017-12-16 23:25:56 +01:00
|
|
|
crcToVersion.put(43028, "0.1.0.27");
|
2017-12-22 23:29:38 +01:00
|
|
|
crcToVersion.put(59462, "0.1.0.33");
|
2017-12-31 00:07:40 +01:00
|
|
|
crcToVersion.put(55277, "0.1.0.39");
|
2018-01-13 11:12:58 +01:00
|
|
|
crcToVersion.put(47685, "0.1.0.43");
|
2018-01-27 23:03:47 +01:00
|
|
|
crcToVersion.put(2839, "0.1.0.44");
|
2018-01-13 11:12:58 +01:00
|
|
|
crcToVersion.put(30229, "0.1.0.45");
|
2018-02-08 22:41:16 +01:00
|
|
|
crcToVersion.put(24302, "0.1.0.70");
|
|
|
|
crcToVersion.put(1333, "0.1.0.80");
|
2018-02-24 00:03:19 +01:00
|
|
|
crcToVersion.put(12017, "0.1.0.86");
|
2018-03-30 14:40:40 +02:00
|
|
|
crcToVersion.put(8276, "0.1.1.14");
|
2018-05-06 09:54:31 +02:00
|
|
|
crcToVersion.put(5914, "0.1.1.17");
|
|
|
|
crcToVersion.put(6228, "0.1.1.29");
|
|
|
|
crcToVersion.put(44223, "0.1.1.31");
|
|
|
|
crcToVersion.put(39726, "0.1.1.36");
|
|
|
|
crcToVersion.put(11062, "0.1.1.39");
|
2017-08-25 00:21:47 +02:00
|
|
|
|
|
|
|
// resources
|
2017-12-11 23:36:39 +01:00
|
|
|
crcToVersion.put(12586, "0.0.8.74");
|
|
|
|
crcToVersion.put(34068, "0.0.8.88");
|
|
|
|
crcToVersion.put(59839, "0.0.8.96-98");
|
|
|
|
crcToVersion.put(50401, "0.0.9.14-26");
|
|
|
|
crcToVersion.put(22051, "0.0.9.40");
|
|
|
|
crcToVersion.put(46233, "0.0.9.49-0.1.0.11");
|
2017-12-16 23:25:56 +01:00
|
|
|
crcToVersion.put(12098, "0.1.0.17");
|
2018-05-06 09:54:31 +02:00
|
|
|
crcToVersion.put(28696, "0.1.0.26-27");
|
2017-12-22 23:29:38 +01:00
|
|
|
crcToVersion.put(5650, "0.1.0.33");
|
2018-05-06 09:54:31 +02:00
|
|
|
crcToVersion.put(16117, "0.1.0.39-45");
|
|
|
|
crcToVersion.put(22506, "0.1.0.66-70");
|
|
|
|
crcToVersion.put(42264, "0.1.0.77-80");
|
|
|
|
crcToVersion.put(55934, "0.1.0.86-89");
|
|
|
|
crcToVersion.put(26587, "0.1.1.14-25");
|
|
|
|
crcToVersion.put(7446, "0.1.1.29");
|
|
|
|
crcToVersion.put(47887, "0.1.1.31-36");
|
|
|
|
crcToVersion.put(14334, "0.1.1.39");
|
2017-08-25 00:21:47 +02:00
|
|
|
|
|
|
|
// gps
|
2017-12-11 23:36:39 +01:00
|
|
|
crcToVersion.put(61520, "9367,8f79a91,0,0,");
|
|
|
|
crcToVersion.put(8784, "9565,dfbd8fa,0,0,");
|
2017-12-22 23:29:38 +01:00
|
|
|
crcToVersion.put(16716, "9565,dfbd8faf42,0");
|
2018-01-13 11:12:58 +01:00
|
|
|
crcToVersion.put(54154, "9567,8b05506,0,0,");
|
2018-02-08 22:41:16 +01:00
|
|
|
|
|
|
|
// font
|
|
|
|
crcToVersion.put(61054, "8");
|
|
|
|
crcToVersion.put(62291, "9 (Latin)");
|
2017-08-25 00:21:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public AmazfitBipFirmwareInfo(byte[] bytes) {
|
|
|
|
super(bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-10-21 22:50:28 +02:00
|
|
|
protected HuamiFirmwareType determineFirmwareType(byte[] bytes) {
|
2018-01-27 21:41:35 +01:00
|
|
|
if (ArrayUtils.startsWith(bytes, RES_HEADER) || ArrayUtils.startsWith(bytes, NEWRES_HEADER)) {
|
2018-05-06 16:34:14 +02:00
|
|
|
if (bytes.length > 700000) { // dont know how to distinguish from Cor .res
|
2017-10-24 22:01:25 +02:00
|
|
|
return HuamiFirmwareType.INVALID;
|
|
|
|
}
|
2017-10-21 22:50:28 +02:00
|
|
|
return HuamiFirmwareType.RES;
|
2017-08-25 00:21:47 +02:00
|
|
|
}
|
2018-01-13 11:12:58 +01:00
|
|
|
if (ArrayUtils.startsWith(bytes, GPS_HEADER) || ArrayUtils.startsWith(bytes, GPS_HEADER2) || ArrayUtils.startsWith(bytes, GPS_HEADER3) || ArrayUtils.startsWith(bytes, GPS_HEADER4)) {
|
2017-10-21 22:50:28 +02:00
|
|
|
return HuamiFirmwareType.GPS;
|
2017-08-25 00:21:47 +02:00
|
|
|
}
|
2017-09-15 11:44:24 +02:00
|
|
|
if (ArrayUtils.startsWith(bytes, GPS_ALMANAC_HEADER)) {
|
2017-10-21 22:50:28 +02:00
|
|
|
return HuamiFirmwareType.GPS_ALMANAC;
|
2017-09-15 11:44:24 +02:00
|
|
|
}
|
|
|
|
if (ArrayUtils.startsWith(bytes, GPS_CEP_HEADER)) {
|
2017-10-21 22:50:28 +02:00
|
|
|
return HuamiFirmwareType.GPS_CEP;
|
2017-09-15 11:44:24 +02:00
|
|
|
}
|
2018-05-12 00:05:30 +02:00
|
|
|
if (ArrayUtils.startsWith(bytes, FW_HEADER)) {
|
|
|
|
String foundVersion = searchFirmwareVersion(bytes);
|
|
|
|
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;
|
2017-08-25 00:21:47 +02:00
|
|
|
}
|
2017-11-09 21:59:41 +01:00
|
|
|
if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER)) {
|
|
|
|
return HuamiFirmwareType.WATCHFACE;
|
|
|
|
}
|
2018-01-27 21:41:35 +01:00
|
|
|
if (ArrayUtils.startsWith(bytes, NEWFT_HEADER)) {
|
2018-01-30 23:28:49 +01:00
|
|
|
if (bytes[10] == 0x01) {
|
2018-01-27 21:41:35 +01:00
|
|
|
return HuamiFirmwareType.FONT;
|
2018-01-30 23:28:49 +01:00
|
|
|
} else if (bytes[10] == 0x02) {
|
|
|
|
return HuamiFirmwareType.FONT_LATIN;
|
2018-01-27 21:41:35 +01:00
|
|
|
}
|
|
|
|
}
|
2017-10-21 22:50:28 +02:00
|
|
|
return HuamiFirmwareType.INVALID;
|
2017-08-25 00:21:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isGenerallyCompatibleWith(GBDevice device) {
|
|
|
|
return isHeaderValid() && device.getType() == DeviceType.AMAZFITBIP;
|
|
|
|
}
|
|
|
|
|
2017-10-24 22:01:25 +02:00
|
|
|
@Override
|
|
|
|
protected Map<Integer, String> getCrcMap() {
|
|
|
|
return crcToVersion;
|
|
|
|
}
|
2017-08-25 00:21:47 +02:00
|
|
|
}
|