1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-14 00:50:34 +02:00

Only use 0x00 as auth flags on Mi Band 3 - to not disturb other devices

This commit is contained in:
Andreas Shimokawa 2018-07-17 00:29:36 +02:00
parent aa143577f8
commit eef38d4680
3 changed files with 17 additions and 10 deletions

View File

@ -101,7 +101,7 @@ public class MiBand2Service {
/**
* In some logs it's 0x0...
*/
public static final byte AUTH_BYTE = 0x00;
public static final byte AUTH_BYTE = 0x08;
// maybe not really activity data, but steps?
public static final byte COMMAND_FETCH_DATA = 0x02;

View File

@ -57,6 +57,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.ActivateDisplayOnLift;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipService;
@ -69,7 +70,6 @@ import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample;
@ -84,6 +84,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
@ -103,13 +104,13 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.heartrate.Hear
import nodomain.freeyourgadget.gadgetbridge.service.devices.common.SimpleNotification;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiBatteryInfo;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.RealtimeSamplesSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.actions.StopNotificationAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.operations.FetchActivityOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.operations.FetchSportsSummaryOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.operations.InitOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.operations.UpdateFirmwareOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.RealtimeSamplesSupport;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
@ -209,7 +210,11 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
try {
boolean authenticate = needsAuth;
needsAuth = false;
new InitOperation(authenticate, this, builder).perform();
byte authFlags = MiBand2Service.AUTH_BYTE;
if (gbDevice.getType() == DeviceType.MIBAND3) {
authFlags = 0x00;
}
new InitOperation(authenticate, authFlags, this, builder).perform();
characteristicHRControlPoint = getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT);
} catch (IOException e) {
GB.toast(getContext(), "Initializing Mi Band 2 failed", Toast.LENGTH_SHORT, GB.ERROR, e);
@ -219,7 +224,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
/**
* Returns the given date/time (calendar) as a byte sequence, suitable for sending to the
* Mi Band 2 (or derivative). The band appears to not handle DST offsets, so we simply add this
* Mi Band 2 (or derivative). The band appears to not handle DST offsets, so we simply add this
* to the timezone.
* @param calendar
* @param precision

View File

@ -49,10 +49,12 @@ public class InitOperation extends AbstractBTLEOperation<MiBand2Support> {
private final TransactionBuilder builder;
private final boolean needsAuth;
private final byte authFlags;
public InitOperation(boolean needsAuth, MiBand2Support support, TransactionBuilder builder) {
public InitOperation(boolean needsAuth, byte authFlags, MiBand2Support support, TransactionBuilder builder) {
super(support);
this.needsAuth = needsAuth;
this.authFlags = authFlags;
this.builder = builder;
builder.setGattCallback(this);
}
@ -63,7 +65,7 @@ public class InitOperation extends AbstractBTLEOperation<MiBand2Support> {
if (needsAuth) {
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.AUTHENTICATING, getContext()));
// write key to miband2
byte[] sendKey = org.apache.commons.lang3.ArrayUtils.addAll(new byte[]{MiBand2Service.AUTH_SEND_KEY, MiBand2Service.AUTH_BYTE}, getSecretKey());
byte[] sendKey = org.apache.commons.lang3.ArrayUtils.addAll(new byte[]{MiBand2Service.AUTH_SEND_KEY, authFlags}, getSecretKey());
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_AUTH), sendKey);
} else {
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
@ -73,7 +75,7 @@ public class InitOperation extends AbstractBTLEOperation<MiBand2Support> {
}
private byte[] requestAuthNumber() {
return new byte[]{MiBand2Service.AUTH_REQUEST_RANDOM_AUTH_NUMBER, MiBand2Service.AUTH_BYTE};
return new byte[]{MiBand2Service.AUTH_REQUEST_RANDOM_AUTH_NUMBER, authFlags};
}
private byte[] getSecretKey() {
@ -105,7 +107,7 @@ public class InitOperation extends AbstractBTLEOperation<MiBand2Support> {
// md5??
byte[] eValue = handleAESAuth(value, getSecretKey());
byte[] responseValue = org.apache.commons.lang3.ArrayUtils.addAll(
new byte[]{MiBand2Service.AUTH_SEND_ENCRYPTED_AUTH_NUMBER, MiBand2Service.AUTH_BYTE}, eValue);
new byte[]{MiBand2Service.AUTH_SEND_ENCRYPTED_AUTH_NUMBER, authFlags}, eValue);
TransactionBuilder builder = createTransactionBuilder("Sending the encrypted random key to the band");
builder.write(characteristic, responseValue);