From 1d4c85b7327e467b69a023596276ae7a09c85569 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Wed, 7 Aug 2024 14:58:26 +0200 Subject: [PATCH] Garmin: implement (some kind of) auth negotiation message Blindly implemented based on the legacy vivomoveHR code, not tested against real devices. --- .../messages/AuthNegotiationMessage.java | 59 +++++++++++++++++++ .../devices/garmin/messages/GFDIMessage.java | 1 + 2 files changed, 60 insertions(+) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/AuthNegotiationMessage.java diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/AuthNegotiationMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/AuthNegotiationMessage.java new file mode 100644 index 000000000..8b307b94d --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/AuthNegotiationMessage.java @@ -0,0 +1,59 @@ +package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages; + +import org.apache.commons.lang3.EnumUtils; + +import java.util.EnumSet; + +public class AuthNegotiationMessage extends GFDIMessage { + + private final int unknown; + private final EnumSet requestedAuthFlags; + + public AuthNegotiationMessage(GarminMessage garminMessage, int unknown, EnumSet requestedAuthFlags) { + this.garminMessage = garminMessage; + this.unknown = unknown; + this.requestedAuthFlags = requestedAuthFlags; + + LOG.info("Message {}, unkByte: {}, flags: {}", garminMessage, unknown, requestedAuthFlags); + + this.statusMessage = getStatusMessage(); + } + + public static AuthNegotiationMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) { + + final int unk = reader.readByte(); + final EnumSet authFlags = AuthFlags.fromBitMask(reader.readInt()); + + return new AuthNegotiationMessage(garminMessage, unk, authFlags); + } + + @Override + protected boolean generateOutgoing() { + + final MessageWriter writer = new MessageWriter(response); + writer.writeShort(0); // placeholder for packet size + writer.writeShort(this.garminMessage.getId()); + + //set all to 0 as we don't know what else to do + writer.writeByte(0); + writer.writeInt((int) EnumUtils.generateBitVector(AuthFlags.class, EnumSet.noneOf(AuthFlags.class))); + + return true; + } + + private enum AuthFlags { + UNK_00000001, //saw in logs + UNK_00000010, + UNK_00000100, + UNK_00001000, + UNK_00010000, + UNK_00100000, + UNK_01000000, + UNK_10000000, + ; + + public static EnumSet fromBitMask(final int code) { + return EnumUtils.processBitVector(AuthFlags.class, code); + } + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/GFDIMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/GFDIMessage.java index 7cb5a4240..b1acb444c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/GFDIMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/GFDIMessage.java @@ -116,6 +116,7 @@ public abstract class GFDIMessage { MUSIC_CONTROL_ENTITY_UPDATE(5049, MusicControlEntityUpdateMessage.class), CONFIGURATION(5050, ConfigurationMessage.class), CURRENT_TIME_REQUEST(5052, CurrentTimeRequestMessage.class), + AUTH_NEGOTIATION(5101, AuthNegotiationMessage.class) ; private final Class objectClass; private final int id;