Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"Bash(grep:*)",
"Bash(tshark:*)",
"Bash(find:*)",
"Bash(python3:*)",
"Bash(python3:*)",
"Bash(git log:*)",
"Bash(git ls-tree:*)"
"Bash(git ls-tree:*)",
"Bash(/c/Android/sdk/platform-tools/adb.exe pull *)"
]
}
}
385 changes: 385 additions & 0 deletions DIRCON-SERVER-REFACTOR.md

Large diffs are not rendered by default.

442 changes: 442 additions & 0 deletions WINDOWS-BLE-HARDENING.md

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion src/characteristics/characteristicnotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@
#define CN_INVALID -1
#define CN_OK 0

class bluetoothdevice;

class CharacteristicNotifier : public QObject {
Q_OBJECT
quint16 my_uuid;

protected:
// The device every subclass reads its values from. Held in the base so that
// DirconManager::setDevice() can rebind the whole notifier chain in one pass;
// subclasses that used to declare their own `Bike` now inherit this one.
bluetoothdevice *Bike = nullptr;

public:
explicit CharacteristicNotifier(quint16 uuid, QObject *parent = nullptr) : QObject(parent), my_uuid(uuid) {}
explicit CharacteristicNotifier(quint16 uuid, bluetoothdevice *device, QObject *parent = nullptr)
: QObject(parent), my_uuid(uuid), Bike(device) {}
virtual int notify(QByteArray &out) = 0;
quint16 uuid() const { return my_uuid; }

// May be called with nullptr: notify() implementations must tolerate a null
// device once the DIRCON endpoint outlives the bike.
virtual void setDevice(bluetoothdevice *device) { Bike = device; }
bluetoothdevice *device() const { return Bike; }
signals:
};

Expand Down
3 changes: 1 addition & 2 deletions src/characteristics/characteristicnotifier0002.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#include <QList>

CharacteristicNotifier0002::CharacteristicNotifier0002(bluetoothdevice *bike, QObject *parent)
: CharacteristicNotifier(0x0002, parent) {
Bike = bike;
: CharacteristicNotifier(0x0002, bike, parent) {
answerList = QList<QByteArray>(); // Initialize empty list
}

Expand Down
1 change: 0 additions & 1 deletion src/characteristics/characteristicnotifier0002.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class CharacteristicNotifier0002 : public CharacteristicNotifier {
Q_OBJECT
bluetoothdevice* Bike = nullptr;
QList<QByteArray> answerList;

public:
Expand Down
3 changes: 1 addition & 2 deletions src/characteristics/characteristicnotifier0004.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#include <QList>

CharacteristicNotifier0004::CharacteristicNotifier0004(bluetoothdevice *bike, QObject *parent)
: CharacteristicNotifier(0x0004, parent) {
Bike = bike;
: CharacteristicNotifier(0x0004, bike, parent) {
answerList = QList<QByteArray>();
}

Expand Down
1 change: 0 additions & 1 deletion src/characteristics/characteristicnotifier0004.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class CharacteristicNotifier0004 : public CharacteristicNotifier {
Q_OBJECT
bluetoothdevice* Bike = nullptr;
QList<QByteArray> answerList;

public:
Expand Down
2 changes: 1 addition & 1 deletion src/characteristics/characteristicnotifier2a37.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "characteristicnotifier2a37.h"

CharacteristicNotifier2A37::CharacteristicNotifier2A37(bluetoothdevice *Bike, QObject *parent)
: CharacteristicNotifier(0x2a37, parent), Bike(Bike) {}
: CharacteristicNotifier(0x2a37, Bike, parent) {}

int CharacteristicNotifier2A37::notify(QByteArray &valueHR) {
valueHR.append(char(0)); // Flags that specify the format of the value.
Expand Down
1 change: 0 additions & 1 deletion src/characteristics/characteristicnotifier2a37.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "characteristicnotifier.h"

class CharacteristicNotifier2A37 : public CharacteristicNotifier {
bluetoothdevice *Bike;

public:
explicit CharacteristicNotifier2A37(bluetoothdevice *Bike, QObject *parent = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/characteristics/characteristicnotifier2a53.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "devices/treadmill.h"

CharacteristicNotifier2A53::CharacteristicNotifier2A53(bluetoothdevice *Bike, QObject *parent)
: CharacteristicNotifier(0x2a53, parent), Bike(Bike) {}
: CharacteristicNotifier(0x2a53, Bike, parent) {}

int CharacteristicNotifier2A53::notify(QByteArray &value) {
BLUETOOTH_TYPE dt = Bike->deviceType();
Expand Down
1 change: 0 additions & 1 deletion src/characteristics/characteristicnotifier2a53.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "characteristicnotifier.h"

class CharacteristicNotifier2A53 : public CharacteristicNotifier {
bluetoothdevice *Bike;

public:
explicit CharacteristicNotifier2A53(bluetoothdevice *Bike, QObject *parent = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/characteristics/characteristicnotifier2a5b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <QSettings>

CharacteristicNotifier2A5B::CharacteristicNotifier2A5B(bluetoothdevice *Bike, QObject *parent)
: CharacteristicNotifier(0x2a5b, parent), Bike(Bike) {
: CharacteristicNotifier(0x2a5b, Bike, parent) {
QSettings settings;
bike_wheel_revs = settings.value(QZSettings::bike_wheel_revs, QZSettings::default_bike_wheel_revs).toBool();
}
Expand Down
1 change: 0 additions & 1 deletion src/characteristics/characteristicnotifier2a5b.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "characteristicnotifier.h"

class CharacteristicNotifier2A5B : public CharacteristicNotifier {
bluetoothdevice *Bike;
uint16_t lastWheelTime = 0;
uint32_t wheelRevs = 0;
bool bike_wheel_revs;
Expand Down
2 changes: 1 addition & 1 deletion src/characteristics/characteristicnotifier2a63.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "characteristicnotifier2a63.h"

CharacteristicNotifier2A63::CharacteristicNotifier2A63(bluetoothdevice *Bike, QObject *parent)
: CharacteristicNotifier(0x2a63, parent), Bike(Bike) {}
: CharacteristicNotifier(0x2a63, Bike, parent) {}

int CharacteristicNotifier2A63::notify(QByteArray &value) {
double normalizeWattage = Bike->wattsMetricforUI();
Expand Down
1 change: 0 additions & 1 deletion src/characteristics/characteristicnotifier2a63.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "characteristicnotifier.h"

class CharacteristicNotifier2A63 : public CharacteristicNotifier {
bluetoothdevice *Bike;

public:
explicit CharacteristicNotifier2A63(bluetoothdevice *Bike, QObject *parent = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/characteristics/characteristicnotifier2acc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <qmath.h>

CharacteristicNotifier2ACC::CharacteristicNotifier2ACC(bluetoothdevice *Bike, QObject *parent)
: CharacteristicNotifier(0x2ACC, parent), Bike(Bike) {}
: CharacteristicNotifier(0x2ACC, Bike, parent) {}

int CharacteristicNotifier2ACC::notify(QByteArray &value) {
value.append((char)0x83); // average speed, cadence and resistance level supported
Expand Down
1 change: 0 additions & 1 deletion src/characteristics/characteristicnotifier2acc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "characteristicnotifier.h"

class CharacteristicNotifier2ACC : public CharacteristicNotifier {
bluetoothdevice *Bike;

public:
explicit CharacteristicNotifier2ACC(bluetoothdevice *Bike, QObject *parent = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/characteristics/characteristicnotifier2acd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <QTime> // Include QTime for Bike->elapsedTime()

CharacteristicNotifier2ACD::CharacteristicNotifier2ACD(bluetoothdevice *Bike, QObject *parent)
: CharacteristicNotifier(0x2acd, parent), Bike(Bike) {}
: CharacteristicNotifier(0x2acd, Bike, parent) {}

int CharacteristicNotifier2ACD::notify(QByteArray &value) {
BLUETOOTH_TYPE dt = Bike->deviceType();
Expand Down
1 change: 0 additions & 1 deletion src/characteristics/characteristicnotifier2acd.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "characteristicnotifier.h"

class CharacteristicNotifier2ACD : public CharacteristicNotifier {
bluetoothdevice *Bike;

public:
explicit CharacteristicNotifier2ACD(bluetoothdevice *Bike, QObject *parent = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/characteristics/characteristicnotifier2ad2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <QSettings>

CharacteristicNotifier2AD2::CharacteristicNotifier2AD2(bluetoothdevice *Bike, QObject *parent)
: CharacteristicNotifier(0x2ad2, parent), Bike(Bike) {}
: CharacteristicNotifier(0x2ad2, Bike, parent) {}

int CharacteristicNotifier2AD2::notify(QByteArray &value) {
BLUETOOTH_TYPE dt = Bike->deviceType();
Expand Down
1 change: 0 additions & 1 deletion src/characteristics/characteristicnotifier2ad2.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "characteristicnotifier.h"

class CharacteristicNotifier2AD2 : public CharacteristicNotifier {
bluetoothdevice *Bike;

public:
explicit CharacteristicNotifier2AD2(bluetoothdevice *Bike, QObject *parent = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/characteristics/characteristicnotifier2ad9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "devices/ftmsbike/ftmsbike.h"

CharacteristicNotifier2AD9::CharacteristicNotifier2AD9(bluetoothdevice *Bike, QObject *parent)
: CharacteristicNotifier(0x2ad9, parent), Bike(Bike) {}
: CharacteristicNotifier(0x2ad9, Bike, parent) {}

int CharacteristicNotifier2AD9::notify(QByteArray &value) {
if(answer.length()) {
Expand Down
1 change: 0 additions & 1 deletion src/characteristics/characteristicnotifier2ad9.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "characteristicnotifier.h"

class CharacteristicNotifier2AD9 : public CharacteristicNotifier {
bluetoothdevice *Bike;

public:
explicit CharacteristicNotifier2AD9(bluetoothdevice *Bike, QObject *parent = nullptr);
Expand Down
7 changes: 7 additions & 0 deletions src/characteristics/characteristicwriteprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class CharacteristicWriteProcessor : public QObject {

explicit CharacteristicWriteProcessor(double bikeResistanceGain, int8_t bikeResistanceOffset,
bluetoothdevice *bike, QObject *parent = nullptr);

// Rebind the control path when the DIRCON endpoint outlives the bike it was
// built for. May be called with nullptr; writeProcess(), changePower() and
// changeSlope() all dereference Bike, so callers must not drive a processor
// whose device is null.
virtual void setDevice(bluetoothdevice *bike) { Bike = bike; }

virtual int writeProcess(quint16 uuid, const QByteArray &data, QByteArray &out) = 0;
virtual void changePower(uint16_t power);
virtual void changeSlope(int16_t iresistance, uint8_t crr, uint8_t cw);
Expand Down
4 changes: 4 additions & 0 deletions src/characteristics/characteristicwriteprocessor0003.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ QByteArray CharacteristicWriteProcessor0003::buildCurrentHubRidingData() {
}

int CharacteristicWriteProcessor0003::writeProcess(quint16 uuid, const QByteArray &data, QByteArray &reply) {
if (!Bike) {
qDebug() << "CharacteristicWriteProcessor0003: write with no device attached, ignoring";
return CP_INVALID;
}
static const QByteArray expectedHexArray = QByteArray::fromHex("52696465 4F6E02");
static const QByteArray expectedHexArray2 = QByteArray::fromHex("410805");
static const QByteArray expectedHexArray3 = QByteArray::fromHex("00088804");
Expand Down
6 changes: 6 additions & 0 deletions src/characteristics/characteristicwriteprocessor2ad9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ CharacteristicWriteProcessor2AD9::CharacteristicWriteProcessor2AD9(double bikeRe
: CharacteristicWriteProcessor(bikeResistanceGain, bikeResistanceOffset, bike, parent), notifier(notifier) {}

int CharacteristicWriteProcessor2AD9::writeProcess(quint16 uuid, const QByteArray &data, QByteArray &reply) {
if (!Bike) {
// The DIRCON endpoint outlives the bike, so a client can write while nothing
// is attached. Refuse rather than dereference a device that is not there.
qDebug() << "CharacteristicWriteProcessor2AD9: write with no device attached, ignoring";
return CP_INVALID;
}
if (data.size()) {
BLUETOOTH_TYPE dt = Bike->deviceType();
if (dt == BIKE || dt == ROWING) {
Expand Down
4 changes: 4 additions & 0 deletions src/characteristics/characteristicwriteprocessore005.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ CharacteristicWriteProcessorE005::CharacteristicWriteProcessorE005(double bikeRe
: CharacteristicWriteProcessor(bikeResistanceGain, bikeResistanceOffset, bike, parent) {}

int CharacteristicWriteProcessorE005::writeProcess(quint16 uuid, const QByteArray &data, QByteArray &reply) {
if (!Bike) {
qDebug() << "CharacteristicWriteProcessorE005: write with no device attached, ignoring";
return CP_INVALID;
}
if (data.size()) {
BLUETOOTH_TYPE dt = Bike->deviceType();
if (dt == BIKE) {
Expand Down
Loading
Loading