mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-28 11:35:48 +01:00
Only use 0x00 as auth flags on Mi Band 3 - to not disturb other devices
This commit is contained in:
parent
aa143577f8
commit
eef38d4680
@ -101,7 +101,7 @@ public class MiBand2Service {
|
|||||||
/**
|
/**
|
||||||
* In some logs it's 0x0...
|
* 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?
|
// maybe not really activity data, but steps?
|
||||||
public static final byte COMMAND_FETCH_DATA = 0x02;
|
public static final byte COMMAND_FETCH_DATA = 0x02;
|
||||||
|
@ -57,6 +57,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.ActivateDisplayOnLift;
|
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.HuamiCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipService;
|
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.MiBandCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService;
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile;
|
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.DaoSession;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample;
|
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.CallSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
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.common.SimpleNotification;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiBatteryInfo;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiBatteryInfo;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiDeviceEvent;
|
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.actions.StopNotificationAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.operations.FetchActivityOperation;
|
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.FetchSportsSummaryOperation;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.operations.InitOperation;
|
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.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.GB;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
@ -209,7 +210,11 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
try {
|
try {
|
||||||
boolean authenticate = needsAuth;
|
boolean authenticate = needsAuth;
|
||||||
needsAuth = false;
|
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);
|
characteristicHRControlPoint = getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
GB.toast(getContext(), "Initializing Mi Band 2 failed", Toast.LENGTH_SHORT, GB.ERROR, e);
|
GB.toast(getContext(), "Initializing Mi Band 2 failed", Toast.LENGTH_SHORT, GB.ERROR, e);
|
||||||
|
@ -49,10 +49,12 @@ public class InitOperation extends AbstractBTLEOperation<MiBand2Support> {
|
|||||||
|
|
||||||
private final TransactionBuilder builder;
|
private final TransactionBuilder builder;
|
||||||
private final boolean needsAuth;
|
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);
|
super(support);
|
||||||
this.needsAuth = needsAuth;
|
this.needsAuth = needsAuth;
|
||||||
|
this.authFlags = authFlags;
|
||||||
this.builder = builder;
|
this.builder = builder;
|
||||||
builder.setGattCallback(this);
|
builder.setGattCallback(this);
|
||||||
}
|
}
|
||||||
@ -63,7 +65,7 @@ public class InitOperation extends AbstractBTLEOperation<MiBand2Support> {
|
|||||||
if (needsAuth) {
|
if (needsAuth) {
|
||||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.AUTHENTICATING, getContext()));
|
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.AUTHENTICATING, getContext()));
|
||||||
// write key to miband2
|
// 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);
|
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_AUTH), sendKey);
|
||||||
} else {
|
} else {
|
||||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
|
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
|
||||||
@ -73,7 +75,7 @@ public class InitOperation extends AbstractBTLEOperation<MiBand2Support> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private byte[] requestAuthNumber() {
|
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() {
|
private byte[] getSecretKey() {
|
||||||
@ -105,7 +107,7 @@ public class InitOperation extends AbstractBTLEOperation<MiBand2Support> {
|
|||||||
// md5??
|
// md5??
|
||||||
byte[] eValue = handleAESAuth(value, getSecretKey());
|
byte[] eValue = handleAESAuth(value, getSecretKey());
|
||||||
byte[] responseValue = org.apache.commons.lang3.ArrayUtils.addAll(
|
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");
|
TransactionBuilder builder = createTransactionBuilder("Sending the encrypted random key to the band");
|
||||||
builder.write(characteristic, responseValue);
|
builder.write(characteristic, responseValue);
|
||||||
|
Loading…
Reference in New Issue
Block a user