1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-01 06:22:55 +01:00

Xiaomi Spp: Log plaintext payload

It's very hard to troubleshoot issues with Xiaomi Spp devices from logs
without having access to the plain-text payload, so we now log it.
This commit is contained in:
José Rebelo 2024-05-25 09:35:23 +01:00
parent b704276e49
commit db33bc3ee9
2 changed files with 11 additions and 8 deletions

View File

@ -16,6 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */ along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi; package nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi;
import androidx.annotation.NonNull;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -142,6 +144,8 @@ public class XiaomiSppPacket {
return new Builder(); return new Builder();
} }
@NonNull
@Override
public String toString() { public String toString() {
return String.format(Locale.ROOT, return String.format(Locale.ROOT,
"SppPacket{ channel=0x%x, flag=%b, needsResponse=%b, opCode=0x%x, frameSerial=0x%x, dataType=0x%x, payloadSize=%d }", "SppPacket{ channel=0x%x, flag=%b, needsResponse=%b, opCode=0x%x, frameSerial=0x%x, dataType=0x%x, payloadSize=%d }",

View File

@ -48,6 +48,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btbr.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.PlainAction; import nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.PlainAction;
import nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.SetDeviceStateAction; import nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.SetDeviceStateAction;
import nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.SetProgressAction; import nodomain.freeyourgadget.gadgetbridge.service.btbr.actions.SetProgressAction;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class XiaomiSppSupport extends XiaomiConnectionSupport { public class XiaomiSppSupport extends XiaomiConnectionSupport {
private static final Logger LOG = LoggerFactory.getLogger(XiaomiSppSupport.class); private static final Logger LOG = LoggerFactory.getLogger(XiaomiSppSupport.class);
@ -283,21 +284,19 @@ public class XiaomiSppSupport extends XiaomiConnectionSupport {
} }
@Override @Override
public void sendCommand(String taskName, XiaomiProto.Command command) { public void sendCommand(final String taskName, final XiaomiProto.Command command) {
try { try {
XiaomiSppPacket packet = XiaomiSppPacket.fromXiaomiCommand(command, frameCounter.getAndIncrement(), false); final TransactionBuilder builder = this.commsSupport.createTransactionBuilder("send " + taskName);
LOG.debug("sending packet: {}", packet); sendCommand(builder, command);
TransactionBuilder builder = this.commsSupport.createTransactionBuilder("send " + taskName);
builder.write(packet.encode(mXiaomiSupport.getAuthService(), encryptionCounter));
builder.queue(this.commsSupport.getQueue()); builder.queue(this.commsSupport.getQueue());
} catch (final Exception ex) { } catch (final Exception ex) {
LOG.error("Caught unexpected exception while sending command, device may not have been informed!: {}", ex, ex); LOG.error("Caught unexpected exception while sending command, device may not have been informed!", ex);
} }
} }
public void sendCommand(final TransactionBuilder builder, final XiaomiProto.Command command) { public void sendCommand(final TransactionBuilder builder, final XiaomiProto.Command command) {
XiaomiSppPacket packet = XiaomiSppPacket.fromXiaomiCommand(command, frameCounter.getAndIncrement(), false); final XiaomiSppPacket packet = XiaomiSppPacket.fromXiaomiCommand(command, frameCounter.getAndIncrement(), false);
LOG.debug("sending packet: {}", packet); LOG.debug("sending packet: {}, payload={}", packet, GB.hexdump(packet.getPayload()));
builder.write(packet.encode(mXiaomiSupport.getAuthService(), encryptionCounter)); builder.write(packet.encode(mXiaomiSupport.getAuthService(), encryptionCounter));
// do not queue here, that's the job of the caller // do not queue here, that's the job of the caller