2018-06-25 18:35:46 +02:00
|
|
|
/* Copyright (C) 2016-2018 Andreas Shimokawa, Carsten Pfeiffer, Davis
|
|
|
|
Mosenkovs
|
2017-03-10 14:53:19 +01: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/>. */
|
2018-06-14 18:16:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband3;
|
2016-12-11 02:10:07 +01:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
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;
|
2016-12-11 02:10:07 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
|
|
|
|
|
2018-06-14 18:16:49 +02:00
|
|
|
public class MiBand3FirmwareInfo extends HuamiFirmwareInfo {
|
|
|
|
// this is the same as Mi Band 2
|
2016-12-11 02:10:07 +01:00
|
|
|
private static final byte[] FW_HEADER = new byte[]{
|
2018-06-14 18:16:49 +02:00
|
|
|
(byte) 0xa3, (byte) 0x68, (byte) 0x04, (byte) 0x3b, (byte) 0x02, (byte) 0xdb,
|
|
|
|
(byte) 0xc8, (byte) 0x58, (byte) 0xd0, (byte) 0x50, (byte) 0xfa, (byte) 0xe7,
|
|
|
|
(byte) 0x0c, (byte) 0x34, (byte) 0xf3, (byte) 0xe7,
|
2016-12-11 02:10:07 +01:00
|
|
|
};
|
2017-03-07 23:20:59 +01:00
|
|
|
|
2016-12-11 02:10:07 +01:00
|
|
|
private static final int FW_HEADER_OFFSET = 0x150;
|
|
|
|
|
2018-06-14 18:16:49 +02:00
|
|
|
private static final byte FW_MAGIC = (byte) 0xf9;
|
|
|
|
private static final int FW_MAGIC_OFFSET = 0x17d;
|
|
|
|
|
2018-01-13 16:56:30 +01:00
|
|
|
private static Map<Integer, String> crcToVersion = new HashMap<>();
|
2017-12-10 11:30:31 +01:00
|
|
|
|
2016-12-11 02:10:07 +01:00
|
|
|
static {
|
2017-03-14 22:40:17 +01:00
|
|
|
// firmware
|
2018-07-19 12:00:17 +02:00
|
|
|
crcToVersion.put(55852, "1.2.0.8");
|
2018-08-12 00:28:27 +02:00
|
|
|
crcToVersion.put(14899, "1.3.0.4");
|
|
|
|
crcToVersion.put(20651, "1.3.0.8");
|
2018-08-28 22:10:58 +02:00
|
|
|
crcToVersion.put(60781, "1.4.0.12");
|
|
|
|
crcToVersion.put(30045, "1.5.0.2");
|
|
|
|
crcToVersion.put(38254, "1.5.0.7");
|
|
|
|
crcToVersion.put(46985, "1.5.0.11");
|
2018-09-11 21:35:30 +02:00
|
|
|
crcToVersion.put(31330, "1.6.0.16");
|
2018-06-14 18:16:49 +02:00
|
|
|
|
|
|
|
// resources
|
2018-07-19 12:00:17 +02:00
|
|
|
crcToVersion.put(54724, "1.2.0.8");
|
2018-08-12 00:28:27 +02:00
|
|
|
crcToVersion.put(52589, "1.3.0.4");
|
|
|
|
crcToVersion.put(34642, "1.3.0.8");
|
2018-09-11 21:35:30 +02:00
|
|
|
crcToVersion.put(25278, "1.4.0.12-1.6.0.16");
|
2018-07-19 12:00:17 +02:00
|
|
|
|
|
|
|
// font
|
|
|
|
crcToVersion.put(19775, "1");
|
2016-12-11 02:10:07 +01:00
|
|
|
}
|
|
|
|
|
2018-06-14 18:16:49 +02:00
|
|
|
public MiBand3FirmwareInfo(byte[] bytes) {
|
2017-10-24 22:01:25 +02:00
|
|
|
super(bytes);
|
2017-03-07 23:20:59 +01:00
|
|
|
}
|
|
|
|
|
2018-06-14 18:16:49 +02:00
|
|
|
@Override
|
2017-10-21 22:50:28 +02:00
|
|
|
protected HuamiFirmwareType determineFirmwareType(byte[] bytes) {
|
2018-07-01 22:41:37 +02:00
|
|
|
if (ArrayUtils.startsWith(bytes, FT_HEADER)) {
|
|
|
|
if (bytes[FONT_TYPE_OFFSET] == 0x03 || bytes[FONT_TYPE_OFFSET] == 0x04) {
|
|
|
|
return HuamiFirmwareType.FONT;
|
|
|
|
}
|
|
|
|
return HuamiFirmwareType.INVALID;
|
|
|
|
}
|
2018-06-14 18:16:49 +02:00
|
|
|
if (ArrayUtils.startsWith(bytes, RES_HEADER)) {
|
2018-08-18 23:02:36 +02:00
|
|
|
if (bytes.length > 150000) { // don't know how to distinguish from Bip/Cor .res
|
2018-06-14 18:16:49 +02:00
|
|
|
return HuamiFirmwareType.INVALID;
|
|
|
|
}
|
|
|
|
return HuamiFirmwareType.RES;
|
2017-03-07 23:20:59 +01:00
|
|
|
}
|
2018-06-14 18:16:49 +02:00
|
|
|
if (ArrayUtils.equals(bytes, FW_HEADER, FW_HEADER_OFFSET)
|
|
|
|
&& (bytes[FW_MAGIC_OFFSET] == FW_MAGIC)) {
|
2017-03-07 23:20:59 +01:00
|
|
|
// TODO: this is certainly not a correct validation, but it works for now
|
2017-10-21 22:50:28 +02:00
|
|
|
return HuamiFirmwareType.FIRMWARE;
|
2017-03-07 23:20:59 +01:00
|
|
|
}
|
2017-10-21 22:50:28 +02:00
|
|
|
return HuamiFirmwareType.INVALID;
|
2016-12-11 02:10:07 +01:00
|
|
|
}
|
|
|
|
|
2018-06-14 18:16:49 +02:00
|
|
|
|
|
|
|
@Override
|
2016-12-11 02:10:07 +01:00
|
|
|
public boolean isGenerallyCompatibleWith(GBDevice device) {
|
2018-06-14 18:16:49 +02:00
|
|
|
return isHeaderValid() && device.getType() == DeviceType.MIBAND3;
|
2016-12-11 02:10:07 +01:00
|
|
|
}
|
|
|
|
|
2018-06-14 18:16:49 +02:00
|
|
|
@Override
|
2017-10-24 22:01:25 +02:00
|
|
|
protected Map<Integer, String> getCrcMap() {
|
|
|
|
return crcToVersion;
|
2017-03-07 23:20:59 +01:00
|
|
|
}
|
2017-12-10 11:30:31 +01:00
|
|
|
|
|
|
|
@Override
|
2017-12-10 20:30:27 +01:00
|
|
|
protected String searchFirmwareVersion(byte[] fwbytes) {
|
2018-06-14 18:16:49 +02:00
|
|
|
// does not work for Mi Band 3
|
2017-12-10 11:30:31 +01:00
|
|
|
return null;
|
|
|
|
}
|
2016-12-11 02:10:07 +01:00
|
|
|
}
|