diff --git a/CHANGELOG.md b/CHANGELOG.md index 20bc482c..341549d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Hardware +## [26.1.31] + +### Added + +### Changed + +### Hardware + + ## [26.1.22] ### Added diff --git a/Hardware/V3 - Integrated PCB/PCB/SS2K_KiCad_Files/SmartSpin2k-backups/SmartSpin2k-2022-10-31_214835.zip b/Hardware/V3 - Integrated PCB/PCB/SS2K_KiCad_Files/SmartSpin2k-backups/SmartSpin2k-2022-10-31_214835.zip deleted file mode 100644 index a164b379..00000000 Binary files a/Hardware/V3 - Integrated PCB/PCB/SS2K_KiCad_Files/SmartSpin2k-backups/SmartSpin2k-2022-10-31_214835.zip and /dev/null differ diff --git a/Hardware/V3 - Integrated PCB/PCB/SS2K_KiCad_Files/SmartSpin2k-backups/SmartSpin2k-2023-01-21_082918.zip b/Hardware/V3 - Integrated PCB/PCB/SS2K_KiCad_Files/SmartSpin2k-backups/SmartSpin2k-2023-01-21_082918.zip deleted file mode 100644 index fffea6cb..00000000 Binary files a/Hardware/V3 - Integrated PCB/PCB/SS2K_KiCad_Files/SmartSpin2k-backups/SmartSpin2k-2023-01-21_082918.zip and /dev/null differ diff --git a/include/BLE_Zwift_Service.h b/include/BLE_Zwift_Service.h new file mode 100644 index 00000000..ae371fc2 --- /dev/null +++ b/include/BLE_Zwift_Service.h @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2020 Anthony Doud & Joel Baranick + * All rights reserved + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#pragma once + +#include +#include "Zwift_Protocol_Messages.h" + +// Zwift manufacturer ID +inline constexpr uint16_t kZwiftManufacturerId = 0x094A; + +// Zwift device type identifiers (from manufacturer data) +enum class ZwiftDeviceType : uint8_t { + BC1 = 0x09, + ClickV2Right = 0x0A, + ClickV2Left = 0x0B, +}; + +// Keepalive / riding data interval in milliseconds +inline constexpr unsigned long kZwiftKeepaliveIntervalMs = 5000; +inline constexpr unsigned long kZwiftSessionTimeoutMs = kZwiftKeepaliveIntervalMs * 2; +inline constexpr unsigned long kZwiftRidingDataIntervalMs = 250; +inline constexpr char kZwiftBleLogTag[] = "BLE_Zwift"; +inline constexpr char kZwiftDirConLogTag[] = "DRC_Zwift"; + +class BLE_Zwift_Service { + public: + BLE_Zwift_Service(); + void setupService(NimBLEServer *pServer); + void update(); + + // Returns true if a Zwift client has been used recently. + bool isConnected(); + + // Returns the current virtual gear ratio x10000 (0 = no virtual shifting active) + uint32_t getGearRatioX10000(); + + // Send a shift up notification to Zwift (key down + key up) + void sendShiftUp(); + + // Send a shift down notification to Zwift (key down + key up) + void sendShiftDown(); + + // Handle incoming write to sync_rx (handshake and protocol commands) + // isDirCon=true uses trainer protocol, isDirCon=false uses Click v2 controller protocol + void handleSyncRxWrite(const std::string &value, bool isDirCon = false); + + private: + NimBLEService *pZwiftService; + NimBLECharacteristic *asyncCharacteristic; + NimBLECharacteristic *syncRxCharacteristic; + NimBLECharacteristic *syncTxCharacteristic; + NimBLECharacteristic *unknownCharacteristic5; + NimBLECharacteristic *unknownCharacteristic6; + + bool isDirCon; + unsigned long _lastActivityTime; + unsigned long _lastKeepaliveTime; + unsigned long _lastRidingDataTime; + uint32_t _gearRatioX10000; + + const char *getLogTag() const; + bool keepAlive(unsigned long now); + void resetSession(); + + // Encode a button mask into a protobuf varint message and send as notification + void sendButtonNotification(ZwiftProtocol::RideButtonMask buttonMask); + + // Encode uint32 as protobuf varint, returns number of bytes written + static size_t encodeVarint32(uint32_t value, uint8_t *buffer); + + // Encode uint64 as ULEB128 varint, returns number of bytes written + static size_t encodeUleb128(uint64_t value, uint8_t *buffer); + // Returns the number of bytes a ULEB128-encoded value would occupy + static size_t encodeUleb128Len(uint64_t value); + + // Decode ULEB128 varint from buffer, returns number of bytes consumed + static size_t decodeUleb128(const uint8_t *buf, size_t bufLen, uint64_t *result); + + // Send the "all buttons released" state + void sendAllButtonsReleased(); + + // Send a fully-built payload on sync_tx and mirror it through DirCon. + void sendSyncTxPayload(const uint8_t *payload, size_t length); + + // Send a fully-built payload on async and mirror it through DirCon. + void sendAsyncPayload(const uint8_t *payload, size_t length); + + // Send current GearRatio device information on sync_tx. + void sendGearRatioSyncTx(); + + // Send current GeneralInfo device information on sync_tx. + void sendGeneralInfoSyncTx(); + + // Send TRAINER_CONFIG_STATUS category 2 with reported real/virtual gear ratios. + void sendTrainerConfigSimulationStatus(uint32_t realGearRatioX10000, uint32_t virtualGearRatioX10000); + + // Send TRAINER_CONFIG_STATUS category 3 with virtual_shifting_mode=1 on async. + void sendTrainerConfigVirtualShiftStatus(uint8_t virtualShiftingMode = 1); + + // Handle Zwift trainer protocol command (non-RideOn messages) + void handleZwiftCommand(const uint8_t *data, size_t length); + + // Apply received gear ratio to shifter position + void applyGearRatio(); + + friend class ZwiftSyncRxCallbacks; +}; + +// Callback class for the Zwift sync_rx characteristic writes +class ZwiftSyncRxCallbacks : public NimBLECharacteristicCallbacks { + public: + void onWrite(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo &connInfo) override; + void onSubscribe(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo &connInfo, uint16_t subValue) override; +}; + +extern BLE_Zwift_Service zwiftService; diff --git a/include/DirConManager.h b/include/DirConManager.h index a701a2c3..b19b36f7 100644 --- a/include/DirConManager.h +++ b/include/DirConManager.h @@ -21,7 +21,26 @@ #define DIRCON_MAX_CLIENTS 1 #define DIRCON_RECEIVE_BUFFER_SIZE 256 #define DIRCON_SEND_BUFFER_SIZE 256 -#define DIRCON_MAX_CHARACTERISTICS 10 // maximum number of characteristics to track for subscriptions +#define DIRCON_MAX_CHARACTERISTICS 20 // maximum number of characteristics to track for subscriptions +#define DIRCON_MAX_SERVICES 10 // maximum number of services that can register with DirCon + +// Result struct populated by service write handler callbacks +struct DirConWriteResult { + bool updateResponseData; // If true, response includes characteristic's current value + NimBLEUUID autoSubscribeUuids[4]; // UUIDs to auto-subscribe the client to + size_t autoSubscribeCount; // Number of valid entries in autoSubscribeUuids + + DirConWriteResult() : updateResponseData(false), autoSubscribeUuids(), autoSubscribeCount(0) {} +}; + +// Subscription entry: stores UUID alongside active flag to avoid hash collisions +struct Subscription { + NimBLEUUID uuid; + bool active = false; +}; + +// Write handler callback: returns true if the characteristic was handled by this service +typedef bool (*DirConWriteHandler)(NimBLECharacteristic* characteristic, const uint8_t* data, size_t length, DirConWriteResult* result); class DirConManager { public: @@ -29,13 +48,22 @@ class DirConManager { static void stop(); static void update(); - // Add a BLE service UUID to DirCon MDNS service - static void addBleServiceUuid(const NimBLEUUID& serviceUuid); + // Register a BLE service with DirCon for discovery and optional write handling. + // Services call this during setup. Write handler may be nullptr for read-only/notify-only services. + static void registerService(const NimBLEUUID& serviceUuid, DirConWriteHandler writeHandler = nullptr); // Notify DirCon clients about BLE characteristic changes - static void notifyCharacteristic(const NimBLEUUID& serviceUuid, const NimBLEUUID& characteristicUuid, uint8_t* data, size_t length); + static void notifyCharacteristic(const NimBLEUUID& serviceUuid, const NimBLEUUID& characteristicUuid, uint8_t* data, size_t length, bool onlySubscribers = true); private: + // Service registration + struct ServiceRegistration { + NimBLEUUID serviceUuid; + DirConWriteHandler writeHandler; + }; + static ServiceRegistration registeredServices[DIRCON_MAX_SERVICES]; + static size_t registeredServiceCount; + // Core functionality static bool started; static String statusMessage; @@ -56,17 +84,16 @@ class DirConManager { static bool processDirConMessage(DirConMessage* message, size_t clientIndex); static void sendErrorResponse(uint8_t messageId, uint8_t sequenceNumber, uint8_t errorCode, size_t clientIndex); static void sendResponse(DirConMessage* message, size_t clientIndex); - static void broadcastNotification(const NimBLEUUID& characteristicUuid, uint8_t* data, size_t length); + static void broadcastNotification(const NimBLEUUID& characteristicUuid, uint8_t* data, size_t length, bool onlySubscribers = true); // Service and characteristic handling - static std::vector getAvailableServices(); + static void addBleServiceUuid(const NimBLEUUID& serviceUuid); static std::vector getCharacteristics(const NimBLEUUID& serviceUuid); static uint8_t getDirConProperties(uint32_t characteristicProperties); static NimBLECharacteristic* findCharacteristic(const NimBLEUUID& characteristicUuid); // Subscription tracking - static bool clientSubscriptions[DIRCON_MAX_CLIENTS][DIRCON_MAX_CHARACTERISTICS]; // Simple subscription tracking - static size_t charSubscriptionIndex(const NimBLEUUID& characteristicUuid); + static Subscription clientSubscriptions[DIRCON_MAX_CLIENTS][DIRCON_MAX_CHARACTERISTICS]; static void addSubscription(size_t clientIndex, const NimBLEUUID& characteristicUuid); static void removeSubscription(size_t clientIndex, const NimBLEUUID& characteristicUuid); static void removeAllSubscriptions(size_t clientIndex); diff --git a/include/Main.h b/include/Main.h index bf1bfeb9..5a4ad692 100644 --- a/include/Main.h +++ b/include/Main.h @@ -65,6 +65,9 @@ class SS2K { int32_t getCurrentPosition() { return currentPosition; } void setCurrentPosition(int32_t cp) { currentPosition = cp; } + int getLastShifterPosition() { return lastShifterPosition; } + void setLastShifterPosition(int sp) { lastShifterPosition = sp; } + void resetIfShiftersHeld(); void startTasks(); void stopTasks(); diff --git a/include/SS2KLog.h b/include/SS2KLog.h index 6e6cf499..becbf40d 100644 --- a/include/SS2KLog.h +++ b/include/SS2KLog.h @@ -17,6 +17,7 @@ #include #include #include "LogAppender.h" +#include #include #define SS2K_LOG_TAG "SS2K" @@ -79,8 +80,11 @@ extern LogHandler logHandler; void ss2k_remove_newlines(std::string *str); -int ss2k_log_hex_to_buffer(const byte *data, const size_t data_length, char *buffer, const int buffer_offset, const size_t buffer_length); -int ss2k_log_hex_to_buffer(const char *data, const size_t data_length, char *buffer, const int buffer_offset, const size_t buffer_length); +template +std::string toHexString(const T *data, size_t dataLength); + +template +int ss2k_log_hex_to_buffer(const T *data, const size_t data_length, char *buffer, const int buffer_offset, const size_t buffer_length); void ss2k_log_write(esp_log_level_t level, const char *module, const char *format, ...); diff --git a/include/Zwift_Protocol_Messages.h b/include/Zwift_Protocol_Messages.h new file mode 100644 index 00000000..38f6c9bb --- /dev/null +++ b/include/Zwift_Protocol_Messages.h @@ -0,0 +1,277 @@ +/* + * Copyright (C) 2020 Anthony Doud & Joel Baranick + * All rights reserved + * + * SPDX-License-Identifier: GPL-2.0-only +*/ + +#pragma once + +#include +#include + +namespace ZwiftProtocol { + +template +constexpr auto toUnderlying(Enum value) noexcept -> std::underlying_type_t { + return static_cast>(value); +} + +enum class CommandCode : uint8_t { + HubRequest = 0x00, + HubRidingData = 0x03, + HubCommand = 0x04, + TrainerConfigStatus = 0x05, // Device → Zwift: report trainer config (virtual shifting) + PlayKeyPadStatus = 0x07, + PlayCommand = 0x12, + Idle = 0x19, + RideKeyPadStatus = 0x23, + ClickKeyPadStatus = 0x37, + DeviceInformation = 0x3C, +}; + +enum class WireType : uint8_t { + Varint = 0, + Fixed64 = 1, + LengthDelimited = 2, + StartGroup = 3, + EndGroup = 4, + Fixed32 = 5, +}; + +template +constexpr uint8_t makeTag(FieldEnum field, WireType wireType) noexcept { + return static_cast((toUnderlying(field) << 3U) | toUnderlying(wireType)); +} + +namespace HubRequest { +enum class Field : uint8_t { + DataId = 1, +}; + +enum class DataId : uint16_t { + GeneralInfo = 0, + GearRatio = 520, +}; + +constexpr uint16_t kReplyDataStart = 512; +constexpr uint16_t kReplyDataEnd = 534; +} // namespace HubRequest + +namespace HubRidingData { +enum class Field : uint8_t { + Power = 1, + Cadence = 2, + SpeedX100 = 3, + HeartRate = 4, + Unknown1 = 5, + Unknown2 = 6, +}; +} // namespace HubRidingData + +namespace SimulationParam { +enum class Field : uint8_t { + Wind = 1, + InclineX100 = 2, + CWa = 3, + Crr = 4, +}; +} // namespace SimulationParam + +namespace PhysicalParam { +enum class Field : uint8_t { + GearRatioX10000 = 2, + BikeWeightX100 = 4, + RiderWeightX100 = 5, +}; +} // namespace PhysicalParam + +namespace HubCommand { +enum class Field : uint8_t { + PowerTarget = 3, + Simulation = 4, + Physical = 5, +}; +} // namespace HubCommand + +namespace TrainerConfigStatus { +enum class Field : uint8_t { + GearIndex = 1, + Simulation = 2, + VirtualShift = 3, + Tilt = 4, + Unknown5 = 5, +}; +} // namespace TrainerConfigStatus + +namespace TrainerConfigSimulation { +enum class Field : uint8_t { + Resistance = 1, + ErgPower = 2, + AveragingWindow = 3, + Wind = 4, + Grade = 5, + RealGearRatio = 6, + VirtualGearRatio = 7, + Cw = 8, + WheelDiameter = 9, + BikeMass = 10, + RiderMass = 11, + Crr = 12, + FrontalArea = 13, + EBrake = 14, +}; +} // namespace TrainerConfigSimulation + +namespace TrainerConfigVirtualShift { +enum class Field : uint8_t { + VirtualShiftingMode = 1, + Field2 = 2, + Field3 = 3, +}; +} // namespace TrainerConfigVirtualShift + +enum class PlayButtonStatus : uint8_t { + On = 0, + Off = 1, +}; + +namespace PlayKeyPadStatus { +enum class Field : uint8_t { + RightPad = 1, + ButtonYUp = 2, + ButtonZLeft = 3, + ButtonARight = 4, + ButtonBDown = 5, + ButtonOn = 6, + ButtonShift = 7, + AnalogLR = 8, + AnalogUD = 9, +}; +} // namespace PlayKeyPadStatus + +namespace PlayCommandParameters { +enum class Field : uint8_t { + Param1 = 1, + Param2 = 2, + HapticPattern = 3, +}; +} // namespace PlayCommandParameters + +namespace PlayCommandContents { +enum class Field : uint8_t { + CommandParameters = 1, +}; +} // namespace PlayCommandContents + +namespace PlayCommand { +enum class Field : uint8_t { + CommandContents = 2, +}; +} // namespace PlayCommand + +namespace Idle { +enum class Field : uint8_t { + Unknown2 = 2, +}; +} // namespace Idle + +enum class RideButtonMask : uint32_t { + Left = 0x00001, + Up = 0x00002, + Right = 0x00004, + Down = 0x00008, + A = 0x00010, + B = 0x00020, + Y = 0x00040, + Z = 0x00100, + ShiftUpLeft = 0x00200, + ShiftDownLeft = 0x00400, + PowerupLeft = 0x00800, + OnOffLeft = 0x01000, + ShiftUpRight = 0x02000, + ShiftDownRight = 0x04000, + PowerupRight = 0x10000, + OnOffRight = 0x20000, +}; + +constexpr RideButtonMask operator|(RideButtonMask lhs, RideButtonMask rhs) noexcept { + return static_cast(toUnderlying(lhs) | toUnderlying(rhs)); +} + +constexpr RideButtonMask operator&(RideButtonMask lhs, RideButtonMask rhs) noexcept { + return static_cast(toUnderlying(lhs) & toUnderlying(rhs)); +} + +constexpr RideButtonMask operator~(RideButtonMask value) noexcept { + return static_cast(~toUnderlying(value)); +} + +enum class RideAnalogLocation : uint8_t { + Left = 0, + Right = 1, + Up = 2, + Down = 3, +}; + +namespace RideAnalogKeyPress { +enum class Field : uint8_t { + Location = 1, + AnalogValue = 2, +}; +} // namespace RideAnalogKeyPress + +namespace RideAnalogKeyGroup { +enum class Field : uint8_t { + GroupStatus = 1, +}; +} // namespace RideAnalogKeyGroup + +namespace RideKeyPadStatus { +enum class Field : uint8_t { + ButtonMap = 1, + AnalogButtons = 2, +}; +} // namespace RideKeyPadStatus + +namespace ClickKeyPadStatus { +enum class Field : uint8_t { + ButtonPlus = 1, + ButtonMinus = 2, +}; +} // namespace ClickKeyPadStatus + +namespace DeviceInformationContent { +enum class Field : uint8_t { +Unknown1 = 1, +SoftwareVersion = 2, +DeviceName = 3, +Unknown4 = 4, +Unknown5 = 5, +SerialNumber = 6, +HardwareVersion = 7, +ReplyData = 8, +Unknown9 = 9, +ProtocolVersion = 10, +Unknown13 = 13, +}; +} // namespace DeviceInformationContent + +namespace SubContent { +enum class Field : uint8_t { + Content = 1, + Unknown2 = 2, + Unknown4 = 4, + Unknown5 = 5, + Unknown6 = 6, +}; +} // namespace SubContent + +namespace DeviceInformation { +enum class Field : uint8_t { + InformationId = 1, + SubContent = 2, +}; +} // namespace DeviceInformation + +} // namespace ZwiftProtocol diff --git a/include/cert.h b/include/cert.h index dbe3280f..ef7252a0 100644 --- a/include/cert.h +++ b/include/cert.h @@ -7,41 +7,38 @@ /* * Automatically updated CA certificate for raw.githubusercontent.com - * Last updated: 2025-05-25 08:35:17 -*/ - - #pragma once + * Last updated: 2026-03-03 22:05:48 + */ +#pragma once // certificate for https://raw.githubusercontent.com -// Sectigo Limited Sectigo RSA Domain Validation Secure Server CA, valid until Sat Mar 07 2026, size: 2088 bytes +// Let's Encrypt R12, valid until Thu May 07 2026, size: 1934 bytes const char* rootCACertificate = "-----BEGIN CERTIFICATE-----\n" - "MIIF3jCCA8agAwIBAgIQAf1tMPyjylGoG7xkDjUDLTANBgkqhkiG9w0BAQwFADCBiDELMAkGA1UE\n" - "BhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0plcnNleSBDaXR5MR4wHAYDVQQK\n" - "ExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNVBAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNh\n" - "dGlvbiBBdXRob3JpdHkwHhcNMTAwMjAxMDAwMDAwWhcNMzgwMTE4MjM1OTU5WjCBiDELMAkGA1UE\n" - "BhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0plcnNleSBDaXR5MR4wHAYDVQQK\n" - "ExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNVBAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNh\n" - "dGlvbiBBdXRob3JpdHkwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCAEmUXNg7D2wiz\n" - "0KxXDXbtzSfTTK1Qg2HiqiBNCS1kCdzOiZ/MPans9s/B3PHTsdZ7NygRK0faOca8Ohm0X6a9fZ2j\n" - "Y0K2dvKpOyuR+OJv0OwWIJAJPuLodMkYtJHUYmTbf6MG8YgYapAiPLz+E/CHFHv25B+O1ORRxhFn\n" - "RghRy4YUVD+8M/5+bJz/Fp0YvVGONaanZshyZ9shZrHUm3gDwFA66Mzw3LyeTP6vBZY1H1dat//O\n" - "+T23LLb2VN3I5xI6Ta5MirdcmrS3ID3KfyI0rn47aGYBROcBTkZTmzNg95S+UzeQc0PzMsNT79uq\n" - "/nROacdrjGCT3sTHDN/hMq7MkztReJVni+49Vv4M0GkPGw/zJSZrM233bkf6c0Plfg6lZrEpfDKE\n" - "Y1WJxA3Bk1QwGROs0303p+tdOmw1XNtB1xLaqUkL39iAigmTYo61Zs8liM2EuLE/pDkP2QKe6xJM\n" - "lXzzawWpXhaDzLhn4ugTncxbgtNMs+1b/97lc6wjOy0AvzVVdAlJ2ElYGn+SNuZRkg7zJn0cTRe8\n" - "yexDJtC/QV9AqURE9JnnV4eeUB9XVKg+/XRjL7FQZQnmWEIuQxpMtPAlR1n6BB6T1CZGSlCBst6+\n" - "eLf8ZxXhyVeEHg9j1uliutZfVS7qXMYoCAQlObgOK6nyTJccBz8NUvXt7y+CDwIDAQABo0IwQDAd\n" - "BgNVHQ4EFgQUU3m/WqorSs9UgOHYm8Cd8rIDZsswDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQF\n" - "MAMBAf8wDQYJKoZIhvcNAQEMBQADggIBAFzUfA3P9wF9QZllDHPFUp/L+M+ZBn8b2kMVn54CVVeW\n" - "FPFSPCeHlCjtHzoBN6J2/FNQwISbxmtOuowhT6KOVWKR82kV2LyI48SqC/3vqOlLVSoGIG1VeCkZ\n" - "7l8wXEskEVX/JJpuXior7gtNn3/3ATiUFJVDBwn7YKnuHKsSjKCaXqeYalltiz8I+8jRRa8YFWSQ\n" - "Eg9zKC7F4iRO/Fjs8PRF/iKz6y+O0tlFYQXBl2+odnKPi4w2r78NBc5xjeambx9spnFixdjQg3IM\n" - "8WcRiQycE0xyNN+81XHfqnHd4blsjDwSXWXavVcStkNr/+XeTWYRUc+ZruwXtuhxkYzeSf7dNXGi\n" - "FSeUHM9h4ya7b6NnJSFd5t0dCy5oGzuCr+yDZ4XUmFF0sbmZgIn/f3gZXHlKYC6SQK5MNyosycdi\n" - "yA5d9zZbyuAlJQG03RoHnHcAP9Dc1ew91Pq7P8yF1m9/qS3fuQL39ZeatTXaw2ewh0qpKJ4jjv9c\n" - "J2vhsE/zB+4ALtRZh8tSQZXq9EfX7mRBVXyNWQKV3WKdwrnuWih0hKWbt5DHDAff9Yk2dDLWKMGw\n" - "sAvgnEzDHNb842m1R0aBL6KCq9NjRHDEjf8tM7qtj3u1cIiuPhnPQCjY/MiQu12ZIvVS5ljFH4gx\n" - "Q+6IHdfGjjxDah2nGN59PRbxYvnKkKj9\n" - "-----END CERTIFICATE-----\n"; + "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAwTzELMAkGA1UE\n" + "BhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2VhcmNoIEdyb3VwMRUwEwYDVQQD\n" + "EwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQG\n" + "EwJVUzEpMCcGA1UEChMgSW50ZXJuZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMT\n" + "DElTUkcgUm9vdCBYMTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54r\n" + "Vygch77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+0TM8ukj1\n" + "3Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6UA5/TR5d8mUgjU+g4rk8K\n" + "b4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sWT8KOEUt+zwvo/7V3LvSye0rgTBIlDHCN\n" + "Aymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyHB5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ\n" + "4Q7e2RCOFvu396j3x+UCB5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf\n" + "1b0SHzUvKBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWnOlFu\n" + "hjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTnjh8BCNAw1FtxNrQH\n" + "usEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbwqHyGO0aoSCqI3Haadr8faqU9GY/r\n" + "OPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CIrU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4G\n" + "A1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY\n" + "9umbbjANBgkqhkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL\n" + "ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ3BebYhtF8GaV\n" + "0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KKNFtY2PwByVS5uCbMiogziUwt\n" + "hDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJw\n" + "TdwJx4nLCgdNbOhdjsnvzqvHu7UrTkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nx\n" + "e5AW0wdeRlN8NwdCjNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZA\n" + "JzVcoyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq4RgqsahD\n" + "YVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPAmRGunUHBcnWEvgJBQl9n\n" + "JEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57demyPxgcYxn/eR44/KJ4EBs+lVDR3veyJ\n" + "m+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n" + "-----END CERTIFICATE-----\n"; \ No newline at end of file diff --git a/lib/SS2K/include/Constants.h b/lib/SS2K/include/Constants.h index f5a66edb..385f88da 100644 --- a/lib/SS2K/include/Constants.h +++ b/lib/SS2K/include/Constants.h @@ -109,3 +109,13 @@ #define HID_REPORT_MAP_UUID NimBLEUUID((uint16_t)0x2A4B) #define HID_CONTROL_POINT_UUID NimBLEUUID((uint16_t)0x2A4C) #define HID_REPORT_DATA_UUID NimBLEUUID((uint16_t)0x2A4D) + +// Zwift Custom Service (Virtual Shifting / Controller) +#define ZWIFT_CUSTOM_SERVICE_UUID NimBLEUUID("00000001-19CA-4651-86E5-FA29DCDD09D1") +#define ZWIFT_ASYNC_CHARACTERISTIC_UUID NimBLEUUID("00000002-19CA-4651-86E5-FA29DCDD09D1") +#define ZWIFT_SYNC_RX_CHARACTERISTIC_UUID NimBLEUUID("00000003-19CA-4651-86E5-FA29DCDD09D1") +#define ZWIFT_SYNC_TX_CHARACTERISTIC_UUID NimBLEUUID("00000004-19CA-4651-86E5-FA29DCDD09D1") +#define ZWIFT_UNKNOWN_CHARACTERISTIC5_UUID NimBLEUUID("00000005-19CA-4651-86E5-FA29DCDD09D1") +#define ZWIFT_UNKNOWN_CHARACTERISTIC6_UUID NimBLEUUID("00000006-19CA-4651-86E5-FA29DCDD09D1") +// Zwift Ride Custom Service (advertised for Zwift to discover) +#define ZWIFT_RIDE_CUSTOM_SERVICE_UUID NimBLEUUID((uint16_t)0xFC82) diff --git a/platformio.ini b/platformio.ini index d3bd22f9..f5710c41 100644 --- a/platformio.ini +++ b/platformio.ini @@ -74,7 +74,7 @@ lib_deps = ;https://github.com/gilmaimon/ArduinoWebsockets/archive/refs/tags/0.5.4.zip https://github.com/doudar/ArduinoWebsockets/ ;https://github.com/Links2004/arduinoWebSockets - ;https://github.com/doudar/NimBLE-Arduino/ + ;https://github.com/h2zero/NimBLE-Arduino/ [env:release] extends = esp32doit diff --git a/sdkconfig.release b/sdkconfig.release index 19490d81..3c6ff29e 100644 --- a/sdkconfig.release +++ b/sdkconfig.release @@ -484,7 +484,7 @@ CONFIG_ARDUINO_SELECTIVE_WebServer=y CONFIG_ARDUINO_SELECTIVE_WiFi=y CONFIG_ARDUINO_SELECTIVE_NetworkClientSecure=y # CONFIG_ARDUINO_SELECTIVE_WiFiProv is not set -CONFIG_ARDUINO_SELECTIVE_BLE=y +# CONFIG_ARDUINO_SELECTIVE_BLE is not set # CONFIG_ARDUINO_SELECTIVE_BluetoothSerial is not set # CONFIG_ARDUINO_SELECTIVE_SimpleBLE is not set # CONFIG_ARDUINO_SELECTIVE_RainMaker is not set @@ -615,7 +615,8 @@ CONFIG_BT_NIMBLE_RPA_TIMEOUT=900 CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS=y CONFIG_BT_NIMBLE_HS_STOP_TIMEOUT_MS=2000 # CONFIG_BT_NIMBLE_HOST_BASED_PRIVACY is not set -# CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT is not set +CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=y +CONFIG_BT_NIMBLE_MAX_CONN_REATTEMPT=3 # CONFIG_BT_NIMBLE_HANDLE_REPEAT_PAIRING_DELETION is not set # CONFIG_BT_NIMBLE_GATT_CACHING is not set # CONFIG_BT_NIMBLE_INCL_SVC_DISCOVERY is not set @@ -629,28 +630,19 @@ CONFIG_BT_NIMBLE_LEGACY_VHCI_ENABLE=y # # BLE Services # -CONFIG_BT_NIMBLE_PROX_SERVICE=y -CONFIG_BT_NIMBLE_ANS_SERVICE=y -CONFIG_BT_NIMBLE_CTS_SERVICE=y -CONFIG_BT_NIMBLE_HTP_SERVICE=y -CONFIG_BT_NIMBLE_IPSS_SERVICE=y -CONFIG_BT_NIMBLE_TPS_SERVICE=y -CONFIG_BT_NIMBLE_IAS_SERVICE=y -CONFIG_BT_NIMBLE_LLS_SERVICE=y -CONFIG_BT_NIMBLE_SPS_SERVICE=y -CONFIG_BT_NIMBLE_HR_SERVICE=y +# CONFIG_BT_NIMBLE_PROX_SERVICE is not set +# CONFIG_BT_NIMBLE_ANS_SERVICE is not set +# CONFIG_BT_NIMBLE_CTS_SERVICE is not set +# CONFIG_BT_NIMBLE_HTP_SERVICE is not set +# CONFIG_BT_NIMBLE_IPSS_SERVICE is not set +# CONFIG_BT_NIMBLE_TPS_SERVICE is not set +# CONFIG_BT_NIMBLE_IAS_SERVICE is not set +# CONFIG_BT_NIMBLE_LLS_SERVICE is not set +# CONFIG_BT_NIMBLE_SPS_SERVICE is not set +# CONFIG_BT_NIMBLE_HR_SERVICE is not set # CONFIG_BT_NIMBLE_HID_SERVICE is not set -CONFIG_BT_NIMBLE_BAS_SERVICE=y -# CONFIG_BT_NIMBLE_SVC_BAS_BATTERY_LEVEL_NOTIFY is not set -CONFIG_BT_NIMBLE_DIS_SERVICE=y -# CONFIG_BT_NIMBLE_SVC_DIS_MANUFACTURER_NAME is not set -# CONFIG_BT_NIMBLE_SVC_DIS_SERIAL_NUMBER is not set -# CONFIG_BT_NIMBLE_SVC_DIS_HARDWARE_REVISION is not set -# CONFIG_BT_NIMBLE_SVC_DIS_FIRMWARE_REVISION is not set -# CONFIG_BT_NIMBLE_SVC_DIS_SOFTWARE_REVISION is not set -# CONFIG_BT_NIMBLE_SVC_DIS_SYSTEM_ID is not set -# CONFIG_BT_NIMBLE_SVC_DIS_PNP_ID is not set -# CONFIG_BT_NIMBLE_SVC_DIS_INCLUDED is not set +# CONFIG_BT_NIMBLE_BAS_SERVICE is not set +# CONFIG_BT_NIMBLE_DIS_SERVICE is not set CONFIG_BT_NIMBLE_GAP_SERVICE=y # diff --git a/sdkconfig.release.old b/sdkconfig.release.old index e20af977..8e33c90d 100644 --- a/sdkconfig.release.old +++ b/sdkconfig.release.old @@ -1,6 +1,6 @@ # # Automatically generated file. DO NOT EDIT. -# Espressif IoT Development Framework (ESP-IDF) 5.4.1 Project Configuration +# Espressif IoT Development Framework (ESP-IDF) 5.4.2 Project Configuration # CONFIG_SOC_BROWNOUT_RESET_SUPPORTED="Not determined" CONFIG_SOC_TWAI_BRP_DIV_SUPPORTED="Not determined" @@ -259,13 +259,9 @@ CONFIG_APP_BUILD_TYPE_APP_2NDBOOT=y CONFIG_APP_BUILD_GENERATE_BINARIES=y CONFIG_APP_BUILD_BOOTLOADER=y CONFIG_APP_BUILD_USE_FLASH_SECTIONS=y -# default: # CONFIG_APP_REPRODUCIBLE_BUILD is not set -# default: # CONFIG_APP_NO_BLOBS is not set -# default: # CONFIG_APP_COMPATIBLE_PRE_V2_1_BOOTLOADERS is not set -# default: # CONFIG_APP_COMPATIBLE_PRE_V3_1_BOOTLOADERS is not set # end of Build type @@ -300,7 +296,6 @@ CONFIG_BOOTLOADER_LOG_LEVEL=3 # # Format # -# default: # CONFIG_BOOTLOADER_LOG_COLORS is not set CONFIG_BOOTLOADER_LOG_TIMESTAMP_SOURCE_CPU_TICKS=y # end of Format @@ -309,32 +304,23 @@ CONFIG_BOOTLOADER_LOG_TIMESTAMP_SOURCE_CPU_TICKS=y # # Serial Flash Configurations # -# default: # CONFIG_BOOTLOADER_FLASH_DC_AWARE is not set CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT=y # end of Serial Flash Configurations # CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V is not set CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y -# default: # CONFIG_BOOTLOADER_FACTORY_RESET is not set -# default: # CONFIG_BOOTLOADER_APP_TEST is not set CONFIG_BOOTLOADER_REGION_PROTECTION_ENABLE=y CONFIG_BOOTLOADER_WDT_ENABLE=y -# default: # CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE is not set CONFIG_BOOTLOADER_WDT_TIME_MS=9000 -# default: # CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE is not set -# default: # CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP is not set -# default: # CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON is not set -# default: # CONFIG_BOOTLOADER_SKIP_VALIDATE_ALWAYS is not set CONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0 -# default: # CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC is not set # end of Bootloader config @@ -342,11 +328,8 @@ CONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0 # Security features # CONFIG_SECURE_BOOT_V1_SUPPORTED=y -# default: # CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT is not set -# default: # CONFIG_SECURE_BOOT is not set -# default: # CONFIG_SECURE_FLASH_ENC_ENABLED is not set # end of Security features @@ -354,11 +337,8 @@ CONFIG_SECURE_BOOT_V1_SUPPORTED=y # Application manager # CONFIG_APP_COMPILE_TIME_DATE=y -# default: # CONFIG_APP_EXCLUDE_PROJECT_VER_VAR is not set -# default: # CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR is not set -# default: # CONFIG_APP_PROJECT_VER_FROM_CONFIG is not set CONFIG_APP_RETRIEVE_LEN_ELF_SHA=9 # end of Application manager @@ -381,7 +361,6 @@ CONFIG_ESP_ROM_HAS_OUTPUT_PUTC_FUNC=y # # Serial flasher config # -# default: # CONFIG_ESPTOOLPY_NO_STUB is not set # CONFIG_ESPTOOLPY_FLASHMODE_QIO is not set # CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set @@ -403,7 +382,6 @@ CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y # CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set # CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set CONFIG_ESPTOOLPY_FLASHSIZE="2MB" -# default: # CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE is not set CONFIG_ESPTOOLPY_BEFORE_RESET=y # CONFIG_ESPTOOLPY_BEFORE_NORESET is not set @@ -433,7 +411,6 @@ CONFIG_PARTITION_TABLE_MD5=y # CONFIG_ARDUINO_VARIANT="esp32" CONFIG_ENABLE_ARDUINO_DEPENDS=y -# default: # CONFIG_AUTOSTART_ARDUINO is not set # CONFIG_ARDUINO_RUN_CORE0 is not set CONFIG_ARDUINO_RUN_CORE1=y @@ -455,9 +432,7 @@ CONFIG_ARDUINO_UDP_RUN_CORE0=y # CONFIG_ARDUINO_UDP_RUN_NO_AFFINITY is not set CONFIG_ARDUINO_UDP_RUNNING_CORE=0 CONFIG_ARDUINO_UDP_TASK_PRIORITY=3 -# default: # CONFIG_ARDUINO_ISR_IRAM is not set -# default: # CONFIG_DISABLE_HAL_LOCKS is not set # @@ -470,9 +445,7 @@ CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_NONE=y # CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_DEBUG is not set # CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_VERBOSE is not set CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL=0 -# default: # CONFIG_ARDUHAL_LOG_COLORS is not set -# default: # CONFIG_ARDUHAL_ESP_LOG is not set # end of Debug Log Configuration @@ -485,28 +458,19 @@ CONFIG_ARDUHAL_PARTITION_SCHEME="min_spiffs" CONFIG_ARDUINO_SELECTIVE_COMPILATION=y CONFIG_ARDUINO_SELECTIVE_SPI=y CONFIG_ARDUINO_SELECTIVE_Wire=y -# default: # CONFIG_ARDUINO_SELECTIVE_ESP_SR is not set CONFIG_ARDUINO_SELECTIVE_EEPROM=y -# default: # CONFIG_ARDUINO_SELECTIVE_Preferences is not set -# default: # CONFIG_ARDUINO_SELECTIVE_Ticker is not set CONFIG_ARDUINO_SELECTIVE_Update=y -# default: # CONFIG_ARDUINO_SELECTIVE_Zigbee is not set CONFIG_ARDUINO_SELECTIVE_FS=y -# default: # CONFIG_ARDUINO_SELECTIVE_SD is not set -# default: # CONFIG_ARDUINO_SELECTIVE_SD_MMC is not set -# default: # CONFIG_ARDUINO_SELECTIVE_SPIFFS is not set -# default: # CONFIG_ARDUINO_SELECTIVE_FFat is not set CONFIG_ARDUINO_SELECTIVE_LittleFS=y CONFIG_ARDUINO_SELECTIVE_Network=y -# default: # CONFIG_ARDUINO_SELECTIVE_Ethernet is not set CONFIG_ARDUINO_SELECTIVE_PPP=y CONFIG_ARDUINO_SELECTIVE_ArduinoOTA=y @@ -514,25 +478,17 @@ CONFIG_ARDUINO_SELECTIVE_AsyncUDP=y CONFIG_ARDUINO_SELECTIVE_DNSServer=y CONFIG_ARDUINO_SELECTIVE_ESPmDNS=y CONFIG_ARDUINO_SELECTIVE_HTTPClient=y -# default: # CONFIG_ARDUINO_SELECTIVE_Matter is not set -# default: # CONFIG_ARDUINO_SELECTIVE_NetBIOS is not set CONFIG_ARDUINO_SELECTIVE_WebServer=y CONFIG_ARDUINO_SELECTIVE_WiFi=y CONFIG_ARDUINO_SELECTIVE_NetworkClientSecure=y -# default: # CONFIG_ARDUINO_SELECTIVE_WiFiProv is not set CONFIG_ARDUINO_SELECTIVE_BLE=y -# default: # CONFIG_ARDUINO_SELECTIVE_BluetoothSerial is not set -# default: # CONFIG_ARDUINO_SELECTIVE_SimpleBLE is not set -# default: # CONFIG_ARDUINO_SELECTIVE_RainMaker is not set -# default: # CONFIG_ARDUINO_SELECTIVE_OpenThread is not set -# default: # CONFIG_ARDUINO_SELECTIVE_Insights is not set # end of Arduino Configuration @@ -540,8 +496,8 @@ CONFIG_ARDUINO_SELECTIVE_BLE=y # Compiler options # # CONFIG_COMPILER_OPTIMIZATION_DEBUG is not set -# CONFIG_COMPILER_OPTIMIZATION_SIZE is not set -CONFIG_COMPILER_OPTIMIZATION_PERF=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +# CONFIG_COMPILER_OPTIMIZATION_PERF is not set # CONFIG_COMPILER_OPTIMIZATION_NONE is not set CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y # CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT is not set @@ -549,35 +505,25 @@ CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y CONFIG_COMPILER_ASSERT_NDEBUG_EVALUATE=y CONFIG_COMPILER_FLOAT_LIB_FROM_GCCLIB=y CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL=2 -# default: # CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT is not set CONFIG_COMPILER_HIDE_PATHS_MACROS=y -# default: # CONFIG_COMPILER_CXX_EXCEPTIONS is not set -# default: # CONFIG_COMPILER_CXX_RTTI is not set CONFIG_COMPILER_STACK_CHECK_MODE_NONE=y # CONFIG_COMPILER_STACK_CHECK_MODE_NORM is not set # CONFIG_COMPILER_STACK_CHECK_MODE_STRONG is not set # CONFIG_COMPILER_STACK_CHECK_MODE_ALL is not set -# default: # CONFIG_COMPILER_NO_MERGE_CONSTANTS is not set -# default: # CONFIG_COMPILER_WARN_WRITE_STRINGS is not set CONFIG_COMPILER_DISABLE_DEFAULT_ERRORS=y -# default: # CONFIG_COMPILER_DISABLE_GCC12_WARNINGS is not set -# default: # CONFIG_COMPILER_DISABLE_GCC13_WARNINGS is not set -# default: # CONFIG_COMPILER_DISABLE_GCC14_WARNINGS is not set -# default: # CONFIG_COMPILER_DUMP_RTL_FILES is not set CONFIG_COMPILER_RT_LIB_GCCLIB=y CONFIG_COMPILER_RT_LIB_NAME="gcc" CONFIG_COMPILER_ORPHAN_SECTIONS_WARNING=y # CONFIG_COMPILER_ORPHAN_SECTIONS_PLACE is not set -# default: # CONFIG_COMPILER_STATIC_ANALYZER is not set # end of Compiler options @@ -630,19 +576,18 @@ CONFIG_BT_NIMBLE_ROLE_CENTRAL=y CONFIG_BT_NIMBLE_ROLE_PERIPHERAL=y CONFIG_BT_NIMBLE_ROLE_BROADCASTER=y CONFIG_BT_NIMBLE_ROLE_OBSERVER=y -# default: +CONFIG_BT_NIMBLE_GATT_CLIENT=y +CONFIG_BT_NIMBLE_GATT_SERVER=y # CONFIG_BT_NIMBLE_NVS_PERSIST is not set -# default: # CONFIG_BT_NIMBLE_SMP_ID_RESET is not set -# default: # CONFIG_BT_NIMBLE_SECURITY_ENABLE is not set -# default: +CONFIG_BT_NIMBLE_PRINT_ERR_NAME=y # CONFIG_BT_NIMBLE_DEBUG is not set -# default: # CONFIG_BT_NIMBLE_DYNAMIC_SERVICE is not set CONFIG_BT_NIMBLE_SVC_GAP_DEVICE_NAME="nimble" CONFIG_BT_NIMBLE_GAP_DEVICE_NAME_MAX_LEN=31 CONFIG_BT_NIMBLE_ATT_PREFERRED_MTU=256 +CONFIG_BT_NIMBLE_ATT_MAX_PREP_ENTRIES=64 CONFIG_BT_NIMBLE_SVC_GAP_APPEARANCE=0 # @@ -666,39 +611,58 @@ CONFIG_BT_NIMBLE_HS_FLOW_CTRL_ITVL=1000 CONFIG_BT_NIMBLE_HS_FLOW_CTRL_THRESH=2 CONFIG_BT_NIMBLE_HS_FLOW_CTRL_TX_ON_DISCONNECT=y CONFIG_BT_NIMBLE_RPA_TIMEOUT=900 -# default: # CONFIG_BT_NIMBLE_MESH is not set CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS=y CONFIG_BT_NIMBLE_HS_STOP_TIMEOUT_MS=2000 -# default: # CONFIG_BT_NIMBLE_HOST_BASED_PRIVACY is not set -# default: # CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT is not set +# CONFIG_BT_NIMBLE_HANDLE_REPEAT_PAIRING_DELETION is not set +# CONFIG_BT_NIMBLE_GATT_CACHING is not set +# CONFIG_BT_NIMBLE_INCL_SVC_DISCOVERY is not set CONFIG_BT_NIMBLE_WHITELIST_SIZE=1 -# default: # CONFIG_BT_NIMBLE_TEST_THROUGHPUT_TEST is not set -# default: # CONFIG_BT_NIMBLE_BLUFI_ENABLE is not set CONFIG_BT_NIMBLE_USE_ESP_TIMER=y CONFIG_BT_NIMBLE_LEGACY_VHCI_ENABLE=y -# default: # CONFIG_BT_NIMBLE_BLE_GATT_BLOB_TRANSFER is not set # -# GAP Service +# BLE Services # +CONFIG_BT_NIMBLE_PROX_SERVICE=y +CONFIG_BT_NIMBLE_ANS_SERVICE=y +CONFIG_BT_NIMBLE_CTS_SERVICE=y +CONFIG_BT_NIMBLE_HTP_SERVICE=y +CONFIG_BT_NIMBLE_IPSS_SERVICE=y +CONFIG_BT_NIMBLE_TPS_SERVICE=y +CONFIG_BT_NIMBLE_IAS_SERVICE=y +CONFIG_BT_NIMBLE_LLS_SERVICE=y +CONFIG_BT_NIMBLE_SPS_SERVICE=y +CONFIG_BT_NIMBLE_HR_SERVICE=y +# CONFIG_BT_NIMBLE_HID_SERVICE is not set +CONFIG_BT_NIMBLE_BAS_SERVICE=y +# CONFIG_BT_NIMBLE_SVC_BAS_BATTERY_LEVEL_NOTIFY is not set +CONFIG_BT_NIMBLE_DIS_SERVICE=y +# CONFIG_BT_NIMBLE_SVC_DIS_MANUFACTURER_NAME is not set +# CONFIG_BT_NIMBLE_SVC_DIS_SERIAL_NUMBER is not set +# CONFIG_BT_NIMBLE_SVC_DIS_HARDWARE_REVISION is not set +# CONFIG_BT_NIMBLE_SVC_DIS_FIRMWARE_REVISION is not set +# CONFIG_BT_NIMBLE_SVC_DIS_SOFTWARE_REVISION is not set +# CONFIG_BT_NIMBLE_SVC_DIS_SYSTEM_ID is not set +# CONFIG_BT_NIMBLE_SVC_DIS_PNP_ID is not set +# CONFIG_BT_NIMBLE_SVC_DIS_INCLUDED is not set +CONFIG_BT_NIMBLE_GAP_SERVICE=y # # GAP Appearance write permissions # -# default: # CONFIG_BT_NIMBLE_SVC_GAP_APPEAR_WRITE is not set -# end of GAP Appearance write permissions - CONFIG_BT_NIMBLE_SVC_GAP_APPEAR_WRITE_PERM=0 CONFIG_BT_NIMBLE_SVC_GAP_APPEAR_WRITE_PERM_ENC=0 CONFIG_BT_NIMBLE_SVC_GAP_APPEAR_WRITE_PERM_ATHN=0 CONFIG_BT_NIMBLE_SVC_GAP_APPEAR_WRITE_PERM_ATHR=0 +# end of GAP Appearance write permissions + CONFIG_BT_NIMBLE_SVC_GAP_CAR_CHAR_NOT_SUPP=y # CONFIG_BT_NIMBLE_SVC_GAP_CAR_NOT_SUPP is not set # CONFIG_BT_NIMBLE_SVC_GAP_CAR_SUPP is not set @@ -707,61 +671,31 @@ CONFIG_BT_NIMBLE_SVC_GAP_CENT_ADDR_RESOLUTION=-1 # # GAP device name write permissions # -# default: # CONFIG_BT_NIMBLE_SVC_GAP_NAME_WRITE is not set # end of GAP device name write permissions -CONFIG_BT_NIMBLE_SVC_GAP_NAME_WRITE_PERM=0 -CONFIG_BT_NIMBLE_SVC_GAP_NAME_WRITE_PERM_ENC=0 -CONFIG_BT_NIMBLE_SVC_GAP_NAME_WRITE_PERM_AUTHEN=0 -CONFIG_BT_NIMBLE_SVC_GAP_NAME_WRITE_PERM_AUTHOR=0 +# +# PPCP settings +# CONFIG_BT_NIMBLE_SVC_GAP_PPCP_MAX_CONN_INTERVAL=0 CONFIG_BT_NIMBLE_SVC_GAP_PPCP_MIN_CONN_INTERVAL=0 CONFIG_BT_NIMBLE_SVC_GAP_PPCP_SLAVE_LATENCY=0 CONFIG_BT_NIMBLE_SVC_GAP_PPCP_SUPERVISION_TMO=0 -# default: -# CONFIG_BT_NIMBLE_SVC_GAP_GATT_SECURITY_LEVEL is not set -# end of GAP Service +# end of PPCP settings -# -# BLE Services -# -# default: -# CONFIG_BT_NIMBLE_HID_SERVICE is not set -# default: -# CONFIG_BT_NIMBLE_SVC_BAS_BATTERY_LEVEL_NOTIFY is not set - -# -# Device Information Service -# -# default: -# CONFIG_BT_NIMBLE_SVC_DIS_MANUFACTURER_NAME is not set -# default: -# CONFIG_BT_NIMBLE_SVC_DIS_SERIAL_NUMBER is not set -# default: -# CONFIG_BT_NIMBLE_SVC_DIS_HARDWARE_REVISION is not set -# default: -# CONFIG_BT_NIMBLE_SVC_DIS_FIRMWARE_REVISION is not set -# default: -# CONFIG_BT_NIMBLE_SVC_DIS_SOFTWARE_REVISION is not set -# default: -# CONFIG_BT_NIMBLE_SVC_DIS_SYSTEM_ID is not set -# default: -# CONFIG_BT_NIMBLE_SVC_DIS_PNP_ID is not set -# default: -# CONFIG_BT_NIMBLE_SVC_DIS_INCLUDED is not set -# end of Device Information Service +CONFIG_BT_NIMBLE_SVC_GAP_NAME_WRITE_PERM=0 +CONFIG_BT_NIMBLE_SVC_GAP_NAME_WRITE_PERM_ENC=0 +CONFIG_BT_NIMBLE_SVC_GAP_NAME_WRITE_PERM_AUTHEN=0 +CONFIG_BT_NIMBLE_SVC_GAP_NAME_WRITE_PERM_AUTHOR=0 +# CONFIG_BT_NIMBLE_SVC_GAP_GATT_SECURITY_LEVEL is not set +# CONFIG_BT_NIMBLE_SVC_GAP_RPA_ONLY is not set # end of BLE Services -# default: # CONFIG_BT_NIMBLE_VS_SUPPORT is not set -# default: # CONFIG_BT_NIMBLE_ENC_ADV_DATA is not set -# default: # CONFIG_BT_NIMBLE_HIGH_DUTY_ADV_ITVL is not set -# default: +# CONFIG_BT_NIMBLE_HOST_ALLOW_CONNECT_WITH_SCAN is not set # CONFIG_BT_NIMBLE_HOST_QUEUE_CONG_CHECK is not set -# default: # CONFIG_BT_NIMBLE_GATTC_PROC_PREEMPTION_PROTECT is not set # @@ -775,7 +709,6 @@ CONFIG_BT_NIMBLE_HCI_UART_CTS_PIN=23 # end of Host-controller Transport CONFIG_BT_NIMBLE_EATT_CHAN_NUM=0 -# default: # CONFIG_BT_NIMBLE_SUBRATE is not set # end of NimBLE Options @@ -818,12 +751,9 @@ CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE=y CONFIG_BTDM_SCAN_DUPL_TYPE=0 CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE=100 CONFIG_BTDM_SCAN_DUPL_CACHE_REFRESH_PERIOD=0 -# default: # CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN is not set CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED=y -# default: # CONFIG_BTDM_CTRL_SCAN_BACKOFF_UPPERLIMITMAX is not set -# default: # CONFIG_BTDM_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS is not set CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP=y CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM=100 @@ -832,15 +762,12 @@ CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD=20 # # BLE disconnects when Instant Passed (0x28) occurs # -# default: # CONFIG_BTDM_BLE_LLCP_CONN_UPDATE is not set -# default: # CONFIG_BTDM_BLE_LLCP_CHAN_MAP_UPDATE is not set # end of BLE disconnects when Instant Passed (0x28) occurs CONFIG_BTDM_BLE_CHAN_ASS_EN=y CONFIG_BTDM_BLE_PING_EN=y -# default: # CONFIG_BTDM_CTRL_CONTROLLER_DEBUG_MODE_1 is not set CONFIG_BTDM_RESERVE_DRAM=0xdb5c CONFIG_BTDM_CTRL_HLI=y @@ -850,21 +777,17 @@ CONFIG_BTDM_CTRL_HLI=y # Common Options # CONFIG_BT_ALARM_MAX_NUM=50 -# default: # CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED is not set # end of Common Options -# default: # CONFIG_BT_HCI_LOG_DEBUG_EN is not set # end of Bluetooth -# default: # CONFIG_BLE_MESH is not set # # Console Library # -# default: # CONFIG_CONSOLE_SORTED_HELP is not set # end of Console Library @@ -875,7 +798,6 @@ CONFIG_BT_ALARM_MAX_NUM=50 # # TWAI Configuration # -# default: # CONFIG_TWAI_ISR_IN_IRAM is not set CONFIG_TWAI_ERRATA_FIX_BUS_OFF_REC=y CONFIG_TWAI_ERRATA_FIX_TX_INTR_LOST=y @@ -888,9 +810,7 @@ CONFIG_TWAI_ERRATA_FIX_LISTEN_ONLY_DOM=y # Legacy ADC Driver Configuration # CONFIG_ADC_DISABLE_DAC=y -# default: # CONFIG_ADC_SUPPRESS_DEPRECATE_WARN is not set -# default: # CONFIG_ADC_SKIP_LEGACY_CONFLICT_CHECK is not set # @@ -899,7 +819,6 @@ CONFIG_ADC_DISABLE_DAC=y CONFIG_ADC_CAL_EFUSE_TP_ENABLE=y CONFIG_ADC_CAL_EFUSE_VREF_ENABLE=y CONFIG_ADC_CAL_LUT_ENABLE=y -# default: # CONFIG_ADC_CALI_SUPPRESS_DEPRECATE_WARN is not set # end of Legacy ADC Calibration Configuration # end of Legacy ADC Driver Configuration @@ -907,63 +826,55 @@ CONFIG_ADC_CAL_LUT_ENABLE=y # # Legacy DAC Driver Configurations # -# default: # CONFIG_DAC_SUPPRESS_DEPRECATE_WARN is not set -# default: # CONFIG_DAC_SKIP_LEGACY_CONFLICT_CHECK is not set # end of Legacy DAC Driver Configurations # # Legacy MCPWM Driver Configurations # -# default: # CONFIG_MCPWM_SUPPRESS_DEPRECATE_WARN is not set -# default: # CONFIG_MCPWM_SKIP_LEGACY_CONFLICT_CHECK is not set # end of Legacy MCPWM Driver Configurations # # Legacy Timer Group Driver Configurations # -# default: # CONFIG_GPTIMER_SUPPRESS_DEPRECATE_WARN is not set -# default: # CONFIG_GPTIMER_SKIP_LEGACY_CONFLICT_CHECK is not set # end of Legacy Timer Group Driver Configurations # # Legacy RMT Driver Configurations # -# default: # CONFIG_RMT_SUPPRESS_DEPRECATE_WARN is not set -# default: # CONFIG_RMT_SKIP_LEGACY_CONFLICT_CHECK is not set # end of Legacy RMT Driver Configurations # # Legacy I2S Driver Configurations # -# default: # CONFIG_I2S_SUPPRESS_DEPRECATE_WARN is not set -# default: # CONFIG_I2S_SKIP_LEGACY_CONFLICT_CHECK is not set # end of Legacy I2S Driver Configurations +# +# Legacy I2C Driver Configurations +# +# CONFIG_I2C_SKIP_LEGACY_CONFLICT_CHECK is not set +# end of Legacy I2C Driver Configurations + # # Legacy PCNT Driver Configurations # -# default: # CONFIG_PCNT_SUPPRESS_DEPRECATE_WARN is not set -# default: # CONFIG_PCNT_SKIP_LEGACY_CONFLICT_CHECK is not set # end of Legacy PCNT Driver Configurations # # Legacy SDM Driver Configurations # -# default: # CONFIG_SDM_SUPPRESS_DEPRECATE_WARN is not set -# default: # CONFIG_SDM_SKIP_LEGACY_CONFLICT_CHECK is not set # end of Legacy SDM Driver Configurations # end of Driver Configurations @@ -971,9 +882,7 @@ CONFIG_ADC_CAL_LUT_ENABLE=y # # eFuse Bit Manager # -# default: # CONFIG_EFUSE_CUSTOM_TABLE is not set -# default: # CONFIG_EFUSE_VIRTUAL is not set # CONFIG_EFUSE_CODE_SCHEME_COMPAT_NONE is not set CONFIG_EFUSE_CODE_SCHEME_COMPAT_3_4=y @@ -985,28 +894,19 @@ CONFIG_EFUSE_MAX_BLK_LEN=192 # ESP-TLS # CONFIG_ESP_TLS_USING_MBEDTLS=y -# default: # CONFIG_ESP_TLS_USE_SECURE_ELEMENT is not set -# default: # CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS is not set -# default: # CONFIG_ESP_TLS_SERVER_SESSION_TICKETS is not set -# default: # CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK is not set -# default: # CONFIG_ESP_TLS_SERVER_MIN_AUTH_MODE_OPTIONAL is not set -# default: # CONFIG_ESP_TLS_PSK_VERIFICATION is not set -# default: # CONFIG_ESP_TLS_INSECURE is not set # end of ESP-TLS # # ADC and ADC Calibration # -# default: # CONFIG_ADC_ONESHOT_CTRL_FUNC_IN_IRAM is not set -# default: # CONFIG_ADC_CONTINUOUS_ISR_IRAM_SAFE is not set # @@ -1018,7 +918,6 @@ CONFIG_ADC_CALI_LUT_ENABLE=y # end of ADC Calibration Configurations CONFIG_ADC_DISABLE_DAC_OUTPUT=y -# default: # CONFIG_ADC_ENABLE_DEBUG_LOG is not set # end of ADC and ADC Calibration @@ -1027,9 +926,7 @@ CONFIG_ADC_DISABLE_DAC_OUTPUT=y # CONFIG_ESP_COEX_ENABLED=y CONFIG_ESP_COEX_SW_COEXIST_ENABLE=y -# default: # CONFIG_ESP_COEX_POWER_MANAGEMENT is not set -# default: # CONFIG_ESP_COEX_GPIO_DEBUG is not set # end of Wireless Coexistence @@ -1042,11 +939,8 @@ CONFIG_ESP_ERR_TO_NAME_LOOKUP=y # # ESP-Driver:DAC Configurations # -# default: # CONFIG_DAC_CTRL_FUNC_IN_IRAM is not set -# default: # CONFIG_DAC_ISR_IRAM_SAFE is not set -# default: # CONFIG_DAC_ENABLE_DEBUG_LOG is not set CONFIG_DAC_DMA_AUTO_16BIT_ALIGN=y # end of ESP-Driver:DAC Configurations @@ -1054,9 +948,7 @@ CONFIG_DAC_DMA_AUTO_16BIT_ALIGN=y # # ESP-Driver:GPIO Configurations # -# default: # CONFIG_GPIO_ESP32_SUPPORT_SWITCH_SLP_PULL is not set -# default: # CONFIG_GPIO_CTRL_FUNC_IN_IRAM is not set # end of ESP-Driver:GPIO Configurations @@ -1064,90 +956,69 @@ CONFIG_DAC_DMA_AUTO_16BIT_ALIGN=y # ESP-Driver:GPTimer Configurations # CONFIG_GPTIMER_ISR_HANDLER_IN_IRAM=y -# default: # CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM is not set -# default: # CONFIG_GPTIMER_ISR_IRAM_SAFE is not set -# default: +CONFIG_GPTIMER_OBJ_CACHE_SAFE=y # CONFIG_GPTIMER_ENABLE_DEBUG_LOG is not set # end of ESP-Driver:GPTimer Configurations # # ESP-Driver:I2C Configurations # -# default: # CONFIG_I2C_ISR_IRAM_SAFE is not set -# default: # CONFIG_I2C_ENABLE_DEBUG_LOG is not set -# default: # CONFIG_I2C_ENABLE_SLAVE_DRIVER_VERSION_2 is not set # end of ESP-Driver:I2C Configurations # # ESP-Driver:I2S Configurations # -# default: # CONFIG_I2S_ISR_IRAM_SAFE is not set -# default: # CONFIG_I2S_ENABLE_DEBUG_LOG is not set # end of ESP-Driver:I2S Configurations # # ESP-Driver:LEDC Configurations # -# default: # CONFIG_LEDC_CTRL_FUNC_IN_IRAM is not set # end of ESP-Driver:LEDC Configurations # # ESP-Driver:MCPWM Configurations # -# default: # CONFIG_MCPWM_ISR_IRAM_SAFE is not set -# default: # CONFIG_MCPWM_CTRL_FUNC_IN_IRAM is not set -# default: # CONFIG_MCPWM_ENABLE_DEBUG_LOG is not set # end of ESP-Driver:MCPWM Configurations # # ESP-Driver:PCNT Configurations # -# default: # CONFIG_PCNT_CTRL_FUNC_IN_IRAM is not set -# default: # CONFIG_PCNT_ISR_IRAM_SAFE is not set -# default: # CONFIG_PCNT_ENABLE_DEBUG_LOG is not set # end of ESP-Driver:PCNT Configurations # # ESP-Driver:RMT Configurations # -# default: # CONFIG_RMT_ISR_IRAM_SAFE is not set -# default: # CONFIG_RMT_RECV_FUNC_IN_IRAM is not set -# default: # CONFIG_RMT_ENABLE_DEBUG_LOG is not set # end of ESP-Driver:RMT Configurations # # ESP-Driver:Sigma Delta Modulator Configurations # -# default: # CONFIG_SDM_CTRL_FUNC_IN_IRAM is not set -# default: # CONFIG_SDM_ENABLE_DEBUG_LOG is not set # end of ESP-Driver:Sigma Delta Modulator Configurations # # ESP-Driver:SPI Configurations # -# default: # CONFIG_SPI_MASTER_IN_IRAM is not set CONFIG_SPI_MASTER_ISR_IN_IRAM=y -# default: # CONFIG_SPI_SLAVE_IN_IRAM is not set CONFIG_SPI_SLAVE_ISR_IN_IRAM=y # end of ESP-Driver:SPI Configurations @@ -1155,36 +1026,28 @@ CONFIG_SPI_SLAVE_ISR_IN_IRAM=y # # ESP-Driver:Touch Sensor Configurations # -# default: # CONFIG_TOUCH_CTRL_FUNC_IN_IRAM is not set -# default: # CONFIG_TOUCH_ISR_IRAM_SAFE is not set -# default: # CONFIG_TOUCH_ENABLE_DEBUG_LOG is not set # end of ESP-Driver:Touch Sensor Configurations # # ESP-Driver:UART Configurations # -# default: # CONFIG_UART_ISR_IN_IRAM is not set # end of ESP-Driver:UART Configurations # # Ethernet # -# default: # CONFIG_ETH_USE_ESP32_EMAC is not set -# default: # CONFIG_ETH_USE_SPI_ETHERNET is not set -# default: # CONFIG_ETH_USE_OPENETH is not set # end of Ethernet # # Event Loop Library # -# default: # CONFIG_ESP_EVENT_LOOP_PROFILING is not set CONFIG_ESP_EVENT_POST_FROM_ISR=y CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=y @@ -1194,7 +1057,6 @@ CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=y # GDB Stub # CONFIG_ESP_GDBSTUB_ENABLED=y -# default: # CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME is not set CONFIG_ESP_GDBSTUB_SUPPORT_TASKS=y CONFIG_ESP_GDBSTUB_MAX_TASKS=32 @@ -1211,11 +1073,8 @@ CONFIG_ESPHID_TASK_SIZE_BLE=4096 # ESP HTTP client # CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS=y -# default: # CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH is not set -# default: # CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH is not set -# default: # CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT is not set CONFIG_ESP_HTTP_CLIENT_EVENT_POST_TIMEOUT=2000 # end of ESP HTTP client @@ -1227,11 +1086,8 @@ CONFIG_HTTPD_MAX_REQ_HDR_LEN=512 CONFIG_HTTPD_MAX_URI_LEN=512 CONFIG_HTTPD_ERR_RESP_NO_DELAY=y CONFIG_HTTPD_PURGE_BUF_LEN=32 -# default: # CONFIG_HTTPD_LOG_PURGE_DATA is not set -# default: # CONFIG_HTTPD_WS_SUPPORT is not set -# default: # CONFIG_HTTPD_QUEUE_WORK_BLOCKING is not set CONFIG_HTTPD_SERVER_EVENT_POST_TIMEOUT=2000 # end of HTTP Server @@ -1239,9 +1095,7 @@ CONFIG_HTTPD_SERVER_EVENT_POST_TIMEOUT=2000 # # ESP HTTPS OTA # -# default: # CONFIG_ESP_HTTPS_OTA_DECRYPT_CB is not set -# default: # CONFIG_ESP_HTTPS_OTA_ALLOW_HTTP is not set CONFIG_ESP_HTTPS_OTA_EVENT_POST_TIMEOUT=2000 # end of ESP HTTPS OTA @@ -1249,7 +1103,6 @@ CONFIG_ESP_HTTPS_OTA_EVENT_POST_TIMEOUT=2000 # # ESP HTTPS server # -# default: # CONFIG_ESP_HTTPS_SERVER_ENABLE is not set CONFIG_ESP_HTTPS_SERVER_EVENT_POST_TIMEOUT=2000 # end of ESP HTTPS server @@ -1296,27 +1149,20 @@ CONFIG_ESP_MAC_UNIVERSAL_MAC_ADDRESSES=4 # CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_TWO is not set CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR=y CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES=4 -# default: # CONFIG_ESP_MAC_IGNORE_MAC_CRC_ERROR is not set -# default: # CONFIG_ESP_MAC_USE_CUSTOM_MAC_AS_BASE_MAC is not set # end of MAC Config # # Sleep Config # -# default: # CONFIG_ESP_SLEEP_POWER_DOWN_FLASH is not set CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND=y -# default: # CONFIG_ESP_SLEEP_MSPI_NEED_ALL_IO_PU is not set CONFIG_ESP_SLEEP_RTC_BUS_ISO_WORKAROUND=y -# default: # CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND is not set CONFIG_ESP_SLEEP_WAIT_FLASH_READY_EXTRA_DELAY=2000 -# default: # CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION is not set -# default: # CONFIG_ESP_SLEEP_DEBUG is not set CONFIG_ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS=y # end of Sleep Config @@ -1353,7 +1199,6 @@ CONFIG_ESP_SPI_BUS_LOCK_ISR_FUNCS_IN_IRAM=y # # ESP-Driver:LCD Controller Configurations # -# default: # CONFIG_LCD_ENABLE_DEBUG_LOG is not set # end of ESP-Driver:LCD Controller Configurations @@ -1366,19 +1211,14 @@ CONFIG_ESP_SPI_BUS_LOCK_ISR_FUNCS_IN_IRAM=y # ESP NETIF Adapter # CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL=120 -# default: # CONFIG_ESP_NETIF_PROVIDE_CUSTOM_IMPLEMENTATION is not set CONFIG_ESP_NETIF_TCPIP_LWIP=y # CONFIG_ESP_NETIF_LOOPBACK is not set CONFIG_ESP_NETIF_USES_TCPIP_WITH_BSD_API=y CONFIG_ESP_NETIF_REPORT_DATA_TRAFFIC=y -# default: # CONFIG_ESP_NETIF_RECEIVE_REPORT_ERRORS is not set -# default: # CONFIG_ESP_NETIF_L2_TAP is not set -# default: # CONFIG_ESP_NETIF_BRIDGE_EN is not set -# default: # CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF is not set # end of ESP NETIF Adapter @@ -1392,44 +1232,35 @@ CONFIG_ESP_NETIF_REPORT_DATA_TRAFFIC=y # CONFIG_ESP_PHY_ENABLED=y CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE=y -# default: # CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION is not set CONFIG_ESP_PHY_MAX_WIFI_TX_POWER=20 CONFIG_ESP_PHY_MAX_TX_POWER=20 -# default: # CONFIG_ESP_PHY_REDUCE_TX_POWER is not set -# default: # CONFIG_ESP_PHY_ENABLE_CERT_TEST is not set CONFIG_ESP_PHY_RF_CAL_PARTIAL=y # CONFIG_ESP_PHY_RF_CAL_NONE is not set # CONFIG_ESP_PHY_RF_CAL_FULL is not set CONFIG_ESP_PHY_CALIBRATION_MODE=0 -# default: # CONFIG_ESP_PHY_PLL_TRACK_DEBUG is not set -# default: # CONFIG_ESP_PHY_RECORD_USED_TIME is not set # end of PHY # # Power Management # -# default: # CONFIG_PM_ENABLE is not set -# default: # CONFIG_PM_SLP_IRAM_OPT is not set # end of Power Management # # ESP PSRAM # -# default: # CONFIG_SPIRAM is not set # end of ESP PSRAM # # ESP Ringbuf # -# default: # CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH is not set # end of ESP Ringbuf @@ -1449,13 +1280,11 @@ CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ=160 # # Memory # -# default: # CONFIG_ESP32_USE_FIXED_STATIC_RAM_SIZE is not set # # Non-backward compatible options # -# default: # CONFIG_ESP_SYSTEM_ESP32_SRAM1_REGION_AS_IRAM is not set # end of Non-backward compatible options # end of Memory @@ -1463,7 +1292,6 @@ CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ=160 # # Trace memory # -# default: # CONFIG_ESP32_TRAX is not set CONFIG_ESP32_TRACEMEM_RESERVE_DRAM=0x0 # end of Trace memory @@ -1499,14 +1327,11 @@ CONFIG_ESP_INT_WDT_TIMEOUT_MS=300 CONFIG_ESP_INT_WDT_CHECK_CPU1=y CONFIG_ESP_TASK_WDT_EN=y CONFIG_ESP_TASK_WDT_INIT=y -# default: # CONFIG_ESP_TASK_WDT_PANIC is not set CONFIG_ESP_TASK_WDT_TIMEOUT_S=5 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=y CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=y -# default: # CONFIG_ESP_PANIC_HANDLER_IRAM is not set -# default: # CONFIG_ESP_DEBUG_STUBS_ENABLE is not set CONFIG_ESP_DEBUG_OCDAWARE=y CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_5=y @@ -1526,7 +1351,6 @@ CONFIG_ESP_BROWNOUT_DET_LVL_SEL_0=y CONFIG_ESP_BROWNOUT_DET_LVL=0 # end of Brownout Detector -# default: # CONFIG_ESP32_DISABLE_BASIC_ROM_CONSOLE is not set CONFIG_ESP_SYSTEM_BROWNOUT_INTR=y # end of ESP System Settings @@ -1542,18 +1366,15 @@ CONFIG_ESP_IPC_ISR_ENABLE=y # # ESP Timer (High Resolution Timer) # -# default: # CONFIG_ESP_TIMER_PROFILING is not set CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER=y CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER=y CONFIG_ESP_TIMER_TASK_STACK_SIZE=3584 CONFIG_ESP_TIMER_INTERRUPT_LEVEL=1 -# default: # CONFIG_ESP_TIMER_SHOW_EXPERIMENTAL is not set CONFIG_ESP_TIMER_TASK_AFFINITY=0x0 CONFIG_ESP_TIMER_TASK_AFFINITY_CPU0=y CONFIG_ESP_TIMER_ISR_AFFINITY_CPU0=y -# default: # CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD is not set CONFIG_ESP_TIMER_IMPL_TG0_LAC=y # end of ESP Timer (High Resolution Timer) @@ -1572,7 +1393,6 @@ CONFIG_ESP_WIFI_STATIC_RX_MGMT_BUFFER=y # CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUFFER is not set CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUF=0 CONFIG_ESP_WIFI_RX_MGMT_BUF_NUM_DEF=5 -# default: # CONFIG_ESP_WIFI_CSI_ENABLED is not set CONFIG_ESP_WIFI_AMPDU_TX_ENABLED=y CONFIG_ESP_WIFI_TX_BA_WIN=6 @@ -1583,17 +1403,13 @@ CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_0=y # CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_1 is not set CONFIG_ESP_WIFI_SOFTAP_BEACON_MAX_LEN=752 CONFIG_ESP_WIFI_MGMT_SBUF_NUM=32 -# default: # CONFIG_ESP_WIFI_IRAM_OPT is not set -# default: # CONFIG_ESP_WIFI_EXTRA_IRAM_OPT is not set -# default: # CONFIG_ESP_WIFI_RX_IRAM_OPT is not set CONFIG_ESP_WIFI_ENABLE_WPA3_SAE=y CONFIG_ESP_WIFI_ENABLE_SAE_PK=y CONFIG_ESP_WIFI_SOFTAP_SAE_SUPPORT=y CONFIG_ESP_WIFI_ENABLE_WPA3_OWE_STA=y -# default: # CONFIG_ESP_WIFI_SLP_IRAM_OPT is not set CONFIG_ESP_WIFI_SLP_DEFAULT_MIN_ACTIVE_TIME=50 CONFIG_ESP_WIFI_SLP_DEFAULT_MAX_ACTIVE_TIME=10 @@ -1601,41 +1417,28 @@ CONFIG_ESP_WIFI_SLP_DEFAULT_WAIT_BROADCAST_DATA_TIME=15 CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE=y CONFIG_ESP_WIFI_GMAC_SUPPORT=y CONFIG_ESP_WIFI_SOFTAP_SUPPORT=y -# default: # CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT is not set CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM=7 -# default: # CONFIG_ESP_WIFI_NAN_ENABLE is not set CONFIG_ESP_WIFI_MBEDTLS_CRYPTO=y CONFIG_ESP_WIFI_MBEDTLS_TLS_CLIENT=y -# default: # CONFIG_ESP_WIFI_WAPI_PSK is not set -# default: # CONFIG_ESP_WIFI_11KV_SUPPORT is not set -# default: # CONFIG_ESP_WIFI_MBO_SUPPORT is not set -# default: # CONFIG_ESP_WIFI_DPP_SUPPORT is not set -# default: # CONFIG_ESP_WIFI_11R_SUPPORT is not set -# default: # CONFIG_ESP_WIFI_WPS_SOFTAP_REGISTRAR is not set # # WPS Configuration Options # -# default: # CONFIG_ESP_WIFI_WPS_STRICT is not set -# default: # CONFIG_ESP_WIFI_WPS_PASSPHRASE is not set # end of WPS Configuration Options -# default: # CONFIG_ESP_WIFI_DEBUG_PRINT is not set -# default: # CONFIG_ESP_WIFI_TESTING_OPTIONS is not set CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT=y -# default: # CONFIG_ESP_WIFI_ENT_FREE_DYNAMIC_BUFFER is not set # end of Wi-Fi @@ -1682,17 +1485,22 @@ CONFIG_FATFS_CODEPAGE=437 CONFIG_FATFS_FS_LOCK=0 CONFIG_FATFS_TIMEOUT_MS=10000 CONFIG_FATFS_PER_FILE_CACHE=y -# default: # CONFIG_FATFS_USE_FASTSEEK is not set CONFIG_FATFS_USE_STRFUNC_NONE=y # CONFIG_FATFS_USE_STRFUNC_WITHOUT_CRLF_CONV is not set # CONFIG_FATFS_USE_STRFUNC_WITH_CRLF_CONV is not set CONFIG_FATFS_VFS_FSTAT_BLKSIZE=0 -# default: # CONFIG_FATFS_IMMEDIATE_FSYNC is not set -# default: # CONFIG_FATFS_USE_LABEL is not set CONFIG_FATFS_LINK_LOCK=y +# CONFIG_FATFS_USE_DYN_BUFFERS is not set + +# +# File system free space calculation behavior +# +CONFIG_FATFS_DONT_TRUST_FREE_CLUSTER_CNT=0 +CONFIG_FATFS_DONT_TRUST_LAST_ALLOC=0 +# end of File system free space calculation behavior # end of FAT Filesystem support # @@ -1702,9 +1510,7 @@ CONFIG_FATFS_LINK_LOCK=y # # Kernel # -# default: # CONFIG_FREERTOS_SMP is not set -# default: # CONFIG_FREERTOS_UNICORE is not set CONFIG_FREERTOS_HZ=1000 # CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set @@ -1712,12 +1518,9 @@ CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1536 -# default: # CONFIG_FREERTOS_USE_IDLE_HOOK is not set -# default: # CONFIG_FREERTOS_USE_TICK_HOOK is not set CONFIG_FREERTOS_MAX_TASK_NAME_LEN=16 -# default: # CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY is not set CONFIG_FREERTOS_USE_TIMERS=y CONFIG_FREERTOS_TIMER_SERVICE_TASK_NAME="Tmr Svc" @@ -1730,38 +1533,28 @@ CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=2048 CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10 CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0 CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=1 -# default: # CONFIG_FREERTOS_USE_TRACE_FACILITY is not set -# default: # CONFIG_FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES is not set -# default: # CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set -# default: # CONFIG_FREERTOS_USE_APPLICATION_TASK_TAG is not set # end of Kernel # # Port # -# default: # CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS=y -# default: # CONFIG_FREERTOS_TASK_PRE_DELETION_HOOK is not set -# default: # CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP is not set CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y CONFIG_FREERTOS_ISR_STACKSIZE=1536 CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y -# default: # CONFIG_FREERTOS_FPU_IN_ISR is not set CONFIG_FREERTOS_TICK_SUPPORT_CORETIMER=y CONFIG_FREERTOS_CORETIMER_0=y # CONFIG_FREERTOS_CORETIMER_1 is not set CONFIG_FREERTOS_SYSTICK_USES_CCOUNT=y -# default: # CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH is not set -# default: # CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set # end of Port @@ -1800,13 +1593,9 @@ CONFIG_HEAP_POISONING_DISABLED=y CONFIG_HEAP_TRACING_OFF=y # CONFIG_HEAP_TRACING_STANDALONE is not set # CONFIG_HEAP_TRACING_TOHOST is not set -# default: # CONFIG_HEAP_USE_HOOKS is not set -# default: # CONFIG_HEAP_TASK_TRACKING is not set -# default: # CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS is not set -# default: # CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH is not set # end of Heap memory debugging @@ -1835,7 +1624,6 @@ CONFIG_LOG_MAXIMUM_LEVEL=0 # # Level Settings # -# default: # CONFIG_LOG_MASTER_LEVEL is not set CONFIG_LOG_DYNAMIC_LEVEL_CONTROL=y # CONFIG_LOG_TAG_LEVEL_IMPL_NONE is not set @@ -1850,7 +1638,6 @@ CONFIG_LOG_TAG_LEVEL_IMPL_CACHE_SIZE=31 # # Format # -# default: # CONFIG_LOG_COLORS is not set CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y # CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM is not set @@ -1862,45 +1649,31 @@ CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y # CONFIG_LWIP_ENABLE=y CONFIG_LWIP_LOCAL_HOSTNAME="espressif" -# default: # CONFIG_LWIP_NETIF_API is not set CONFIG_LWIP_TCPIP_TASK_PRIO=18 -# default: # CONFIG_LWIP_TCPIP_CORE_LOCKING is not set -# default: # CONFIG_LWIP_CHECK_THREAD_SAFETY is not set CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y -# default: # CONFIG_LWIP_L2_TO_L3_COPY is not set -# default: # CONFIG_LWIP_IRAM_OPTIMIZATION is not set -# default: # CONFIG_LWIP_EXTRA_IRAM_OPTIMIZATION is not set CONFIG_LWIP_TIMERS_ONDEMAND=y CONFIG_LWIP_ND6=y -# default: # CONFIG_LWIP_FORCE_ROUTER_FORWARDING is not set CONFIG_LWIP_MAX_SOCKETS=10 -# default: # CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set -# default: # CONFIG_LWIP_SO_LINGER is not set CONFIG_LWIP_SO_REUSE=y CONFIG_LWIP_SO_REUSE_RXTOALL=y CONFIG_LWIP_SO_RCVBUF=y -# default: # CONFIG_LWIP_NETBUF_RECVINFO is not set CONFIG_LWIP_IP_DEFAULT_TTL=64 CONFIG_LWIP_IP4_FRAG=y CONFIG_LWIP_IP6_FRAG=y -# default: # CONFIG_LWIP_IP4_REASSEMBLY is not set -# default: # CONFIG_LWIP_IP6_REASSEMBLY is not set CONFIG_LWIP_IP_REASS_MAX_PBUFS=10 -# default: # CONFIG_LWIP_IP_FORWARD is not set -# default: # CONFIG_LWIP_STATS is not set CONFIG_LWIP_ESP_GRATUITOUS_ARP=y CONFIG_LWIP_GARP_TMR_INTERVAL=60 @@ -1910,10 +1683,8 @@ CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=32 CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y # CONFIG_LWIP_DHCP_DOES_ACD_CHECK is not set # CONFIG_LWIP_DHCP_DOES_NOT_CHECK_OFFERED_IP is not set -# default: # CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y -# default: # CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set CONFIG_LWIP_DHCP_OPTIONS_LEN=68 CONFIG_LWIP_NUM_NETIF_CLIENT_DATA=0 @@ -1929,16 +1700,12 @@ CONFIG_LWIP_DHCPS_STATIC_ENTRIES=y CONFIG_LWIP_DHCPS_ADD_DNS=y # end of DHCP server -# default: # CONFIG_LWIP_AUTOIP is not set CONFIG_LWIP_IPV4=y CONFIG_LWIP_IPV6=y -# default: # CONFIG_LWIP_IPV6_AUTOCONFIG is not set CONFIG_LWIP_IPV6_NUM_ADDRESSES=3 -# default: # CONFIG_LWIP_IPV6_FORWARD is not set -# default: # CONFIG_LWIP_NETIF_STATUS_CALLBACK is not set CONFIG_LWIP_NETIF_LOOPBACK=y CONFIG_LWIP_LOOPBACK_MAX_PBUFS=8 @@ -1962,7 +1729,6 @@ CONFIG_LWIP_TCP_ACCEPTMBOX_SIZE=6 CONFIG_LWIP_TCP_QUEUE_OOSEQ=y CONFIG_LWIP_TCP_OOSEQ_TIMEOUT=6 CONFIG_LWIP_TCP_OOSEQ_MAX_PBUFS=4 -# default: # CONFIG_LWIP_TCP_SACK_OUT is not set CONFIG_LWIP_TCP_OVERSIZE_MSS=y # CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS is not set @@ -1980,9 +1746,7 @@ CONFIG_LWIP_UDP_RECVMBOX_SIZE=6 # # Checksums # -# default: # CONFIG_LWIP_CHECKSUM_CHECK_IP is not set -# default: # CONFIG_LWIP_CHECKSUM_CHECK_UDP is not set CONFIG_LWIP_CHECKSUM_CHECK_ICMP=y # end of Checksums @@ -1997,18 +1761,14 @@ CONFIG_LWIP_IPV6_ND6_NUM_NEIGHBORS=5 CONFIG_LWIP_IPV6_ND6_NUM_PREFIXES=5 CONFIG_LWIP_IPV6_ND6_NUM_ROUTERS=3 CONFIG_LWIP_IPV6_ND6_NUM_DESTINATIONS=10 -# default: # CONFIG_LWIP_PPP_SUPPORT is not set -# default: # CONFIG_LWIP_SLIP_SUPPORT is not set # # ICMP # CONFIG_LWIP_ICMP=y -# default: # CONFIG_LWIP_MULTICAST_PING is not set -# default: # CONFIG_LWIP_BROADCAST_PING is not set # end of ICMP @@ -2022,7 +1782,6 @@ CONFIG_LWIP_MAX_RAW_PCBS=16 # SNTP # CONFIG_LWIP_SNTP_MAX_SERVERS=1 -# default: # CONFIG_LWIP_DHCP_GET_NTP_SRV is not set CONFIG_LWIP_SNTP_UPDATE_DELAY=3600000 CONFIG_LWIP_SNTP_STARTUP_DELAY=y @@ -2034,9 +1793,7 @@ CONFIG_LWIP_SNTP_MAXIMUM_STARTUP_DELAY=5000 # CONFIG_LWIP_DNS_MAX_HOST_IP=1 CONFIG_LWIP_DNS_MAX_SERVERS=3 -# default: # CONFIG_LWIP_FALLBACK_DNS_SERVER_SUPPORT is not set -# default: # CONFIG_LWIP_DNS_SETSERVER_WITH_NETIF is not set # end of DNS @@ -2068,7 +1825,6 @@ CONFIG_LWIP_HOOK_IP6_INPUT_DEFAULT=y # CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM is not set # end of Hooks -# default: # CONFIG_LWIP_DEBUG is not set # end of LWIP @@ -2081,21 +1837,15 @@ CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384 CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=4096 -# default: # CONFIG_MBEDTLS_DYNAMIC_BUFFER is not set -# default: # CONFIG_MBEDTLS_DEBUG is not set # # mbedTLS v3.x related # -# default: # CONFIG_MBEDTLS_SSL_PROTO_TLS1_3 is not set -# default: # CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH is not set -# default: # CONFIG_MBEDTLS_X509_TRUSTED_CERT_CALLBACK is not set -# default: # CONFIG_MBEDTLS_SSL_CONTEXT_SERIALIZATION is not set CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE=y CONFIG_MBEDTLS_PKCS7_C=y @@ -2108,35 +1858,27 @@ CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=y # CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN is not set # CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_NONE is not set -# default: # CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE is not set -# default: # CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEPRECATED_LIST is not set CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_MAX_CERTS=200 # end of Certificate Bundle -# default: # CONFIG_MBEDTLS_ECP_RESTARTABLE is not set CONFIG_MBEDTLS_CMAC_C=y CONFIG_MBEDTLS_HARDWARE_AES=y CONFIG_MBEDTLS_GCM_SUPPORT_NON_AES_CIPHER=y CONFIG_MBEDTLS_HARDWARE_MPI=y -# default: # CONFIG_MBEDTLS_LARGE_KEY_SOFTWARE_MPI is not set CONFIG_MBEDTLS_HARDWARE_SHA=y CONFIG_MBEDTLS_ROM_MD5=y -# default: # CONFIG_MBEDTLS_ATCA_HW_ECDSA_SIGN is not set -# default: # CONFIG_MBEDTLS_ATCA_HW_ECDSA_VERIFY is not set CONFIG_MBEDTLS_HAVE_TIME=y -# default: # CONFIG_MBEDTLS_PLATFORM_TIME_ALT is not set -# default: # CONFIG_MBEDTLS_HAVE_TIME_DATE is not set CONFIG_MBEDTLS_ECDSA_DETERMINISTIC=y +CONFIG_MBEDTLS_SHA1_C=y CONFIG_MBEDTLS_SHA512_C=y -# default: # CONFIG_MBEDTLS_SHA3_C is not set CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT=y # CONFIG_MBEDTLS_TLS_SERVER_ONLY is not set @@ -2163,9 +1905,7 @@ CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA=y CONFIG_MBEDTLS_SSL_RENEGOTIATION=y CONFIG_MBEDTLS_SSL_PROTO_TLS1_2=y -# default: # CONFIG_MBEDTLS_SSL_PROTO_GMTSSL1_1 is not set -# default: # CONFIG_MBEDTLS_SSL_PROTO_DTLS is not set CONFIG_MBEDTLS_SSL_ALPN=y CONFIG_MBEDTLS_CLIENT_SSL_SESSION_TICKETS=y @@ -2175,21 +1915,15 @@ CONFIG_MBEDTLS_SERVER_SSL_SESSION_TICKETS=y # Symmetric Ciphers # CONFIG_MBEDTLS_AES_C=y -# default: # CONFIG_MBEDTLS_CAMELLIA_C is not set -# default: # CONFIG_MBEDTLS_DES_C is not set -# default: # CONFIG_MBEDTLS_BLOWFISH_C is not set -# default: # CONFIG_MBEDTLS_XTEA_C is not set CONFIG_MBEDTLS_CCM_C=y CONFIG_MBEDTLS_GCM_C=y -# default: # CONFIG_MBEDTLS_NIST_KW_C is not set # end of Symmetric Ciphers -# default: # CONFIG_MBEDTLS_RIPEMD160_C is not set # @@ -2204,11 +1938,9 @@ CONFIG_MBEDTLS_X509_CSR_PARSE_C=y CONFIG_MBEDTLS_ECP_C=y CONFIG_MBEDTLS_PK_PARSE_EC_EXTENDED=y CONFIG_MBEDTLS_PK_PARSE_EC_COMPRESSED=y -# default: # CONFIG_MBEDTLS_DHM_C is not set CONFIG_MBEDTLS_ECDH_C=y CONFIG_MBEDTLS_ECDSA_C=y -# default: # CONFIG_MBEDTLS_ECJPAKE_C is not set CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED=y CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED=y @@ -2223,42 +1955,28 @@ CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED=y CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=y CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED=y CONFIG_MBEDTLS_ECP_NIST_OPTIM=y -# default: # CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM is not set -# default: # CONFIG_MBEDTLS_POLY1305_C is not set -# default: # CONFIG_MBEDTLS_CHACHA20_C is not set -# default: # CONFIG_MBEDTLS_HKDF_C is not set -# default: # CONFIG_MBEDTLS_THREADING_C is not set CONFIG_MBEDTLS_ERROR_STRINGS=y CONFIG_MBEDTLS_FS_IO=y +# CONFIG_MBEDTLS_ALLOW_WEAK_CERTIFICATE_VERIFICATION is not set # end of mbedTLS # # ESP-MQTT Configurations # -# default: # CONFIG_MQTT_PROTOCOL_311 is not set -# default: # CONFIG_MQTT_PROTOCOL_5 is not set -# default: # CONFIG_MQTT_TRANSPORT_SSL is not set -# default: # CONFIG_MQTT_TRANSPORT_WEBSOCKET is not set -# default: # CONFIG_MQTT_MSG_ID_INCREMENTAL is not set -# default: # CONFIG_MQTT_SKIP_PUBLISH_IF_DISCONNECTED is not set -# default: # CONFIG_MQTT_REPORT_DELETED_MESSAGES is not set -# default: # CONFIG_MQTT_USE_CUSTOM_CONFIG is not set -# default: # CONFIG_MQTT_TASK_CORE_SELECTION_ENABLED is not set -# default: # CONFIG_MQTT_CUSTOM_OUTBOX is not set # end of ESP-MQTT Configurations @@ -2271,7 +1989,6 @@ CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF=y # CONFIG_NEWLIB_STDIN_LINE_ENDING_CRLF is not set # CONFIG_NEWLIB_STDIN_LINE_ENDING_LF is not set CONFIG_NEWLIB_STDIN_LINE_ENDING_CR=y -# default: # CONFIG_NEWLIB_NANO_FORMAT is not set CONFIG_NEWLIB_TIME_SYSCALL_USE_RTC_HRT=y # CONFIG_NEWLIB_TIME_SYSCALL_USE_RTC is not set @@ -2282,22 +1999,18 @@ CONFIG_NEWLIB_TIME_SYSCALL_USE_RTC_HRT=y # # NVS # -# default: # CONFIG_NVS_ASSERT_ERROR_CHECK is not set -# default: # CONFIG_NVS_LEGACY_DUP_KEYS_COMPATIBILITY is not set # end of NVS # # OpenThread # -# default: # CONFIG_OPENTHREAD_ENABLED is not set # # OpenThread Spinel # -# default: # CONFIG_OPENTHREAD_SPINEL_ONLY is not set # end of OpenThread Spinel # end of OpenThread @@ -2351,35 +2064,28 @@ CONFIG_SPI_FLASH_BROWNOUT_RESET=y # Features here require specific hardware (READ DOCS FIRST!) # CONFIG_SPI_FLASH_SUSPEND_TSUS_VAL_US=50 -# default: # CONFIG_SPI_FLASH_FORCE_ENABLE_XMC_C_SUSPEND is not set +# CONFIG_SPI_FLASH_FORCE_ENABLE_C6_H2_SUSPEND is not set # end of Optional and Experimental Features (READ DOCS FIRST) # end of Main Flash configuration # # SPI Flash driver # -# default: # CONFIG_SPI_FLASH_VERIFY_WRITE is not set -# default: # CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS=y # CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS is not set # CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is not set -# default: # CONFIG_SPI_FLASH_SHARE_SPI1_BUS is not set -# default: # CONFIG_SPI_FLASH_BYPASS_BLOCK_ERASE is not set CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS=20 CONFIG_SPI_FLASH_ERASE_YIELD_TICKS=1 CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE=8192 -# default: # CONFIG_SPI_FLASH_SIZE_OVERRIDE is not set -# default: # CONFIG_SPI_FLASH_CHECK_ERASE_TIMEOUT_DISABLED is not set -# default: # CONFIG_SPI_FLASH_OVERRIDE_CHIP_DRIVER_LIST is not set # @@ -2394,9 +2100,7 @@ CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=y CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=y CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=y CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=y -# default: # CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP is not set -# default: # CONFIG_SPI_FLASH_SUPPORT_TH_CHIP is not set # end of Auto-detect flash chips @@ -2413,17 +2117,14 @@ CONFIG_SPIFFS_MAX_PARTITIONS=3 # CONFIG_SPIFFS_CACHE=y CONFIG_SPIFFS_CACHE_WR=y -# default: # CONFIG_SPIFFS_CACHE_STATS is not set # end of SPIFFS Cache Configuration CONFIG_SPIFFS_PAGE_CHECK=y CONFIG_SPIFFS_GC_MAX_RUNS=10 -# default: # CONFIG_SPIFFS_GC_STATS is not set CONFIG_SPIFFS_PAGE_SIZE=256 CONFIG_SPIFFS_OBJ_NAME_LEN=32 -# default: # CONFIG_SPIFFS_FOLLOW_SYMLINKS is not set CONFIG_SPIFFS_USE_MAGIC=y CONFIG_SPIFFS_USE_MAGIC_LENGTH=y @@ -2433,17 +2134,11 @@ CONFIG_SPIFFS_USE_MTIME=y # # Debug Configuration # -# default: # CONFIG_SPIFFS_DBG is not set -# default: # CONFIG_SPIFFS_API_DBG is not set -# default: # CONFIG_SPIFFS_GC_DBG is not set -# default: # CONFIG_SPIFFS_CACHE_DBG is not set -# default: # CONFIG_SPIFFS_CHECK_DBG is not set -# default: # CONFIG_SPIFFS_TEST_VISUALISATION is not set # end of Debug Configuration # end of SPIFFS Configuration @@ -2457,7 +2152,6 @@ CONFIG_SPIFFS_USE_MTIME=y # CONFIG_WS_TRANSPORT=y CONFIG_WS_BUFFER_SIZE=1024 -# default: # CONFIG_WS_DYNAMIC_BUFFER is not set # end of Websocket # end of TCP Transport @@ -2465,7 +2159,6 @@ CONFIG_WS_BUFFER_SIZE=1024 # # Ultra Low Power (ULP) Co-processor # -# default: # CONFIG_ULP_COPROC_ENABLED is not set # @@ -2479,14 +2172,10 @@ CONFIG_WS_BUFFER_SIZE=1024 # CONFIG_UNITY_ENABLE_FLOAT=y CONFIG_UNITY_ENABLE_DOUBLE=y -# default: # CONFIG_UNITY_ENABLE_64BIT is not set -# default: # CONFIG_UNITY_ENABLE_COLOR is not set CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=y -# default: # CONFIG_UNITY_ENABLE_FIXTURE is not set -# default: # CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL is not set # end of Unity unit testing library @@ -2497,7 +2186,6 @@ CONFIG_VFS_SUPPORT_IO=y CONFIG_VFS_SUPPORT_DIR=y CONFIG_VFS_SUPPORT_SELECT=y CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT=y -# default: # CONFIG_VFS_SELECT_IN_RAM is not set CONFIG_VFS_SUPPORT_TERMIOS=y CONFIG_VFS_MAX_COUNT=8 @@ -2524,14 +2212,10 @@ CONFIG_WL_SECTOR_SIZE=4096 # CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES=16 CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT=30 -# default: # CONFIG_WIFI_PROV_BLE_BONDING is not set CONFIG_WIFI_PROV_BLE_SEC_CONN=y -# default: # CONFIG_WIFI_PROV_BLE_FORCE_ENCRYPTION is not set -# default: # CONFIG_WIFI_PROV_BLE_NOTIFY is not set -# default: # CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV is not set CONFIG_WIFI_PROV_STA_ALL_CHANNEL_SCAN=y # CONFIG_WIFI_PROV_STA_FAST_SCAN is not set @@ -2540,30 +2224,20 @@ CONFIG_WIFI_PROV_STA_ALL_CHANNEL_SCAN=y # # Zigbee # -# default: # CONFIG_ZB_ENABLED is not set # end of Zigbee # # esp-modem # -# default: CONFIG_ESP_MODEM_CMUX_DEFRAGMENT_PAYLOAD=y -# default: # CONFIG_ESP_MODEM_USE_INFLATABLE_BUFFER_IF_NEEDED is not set -# default: CONFIG_ESP_MODEM_CMUX_DELAY_AFTER_DLCI_SETUP=0 -# default: # CONFIG_ESP_MODEM_CMUX_USE_SHORT_PAYLOADS_ONLY is not set -# default: # CONFIG_ESP_MODEM_ADD_CUSTOM_MODULE is not set -# default: CONFIG_ESP_MODEM_C_API_STR_MAX=128 -# default: # CONFIG_ESP_MODEM_URC_HANDLER is not set -# default: # CONFIG_ESP_MODEM_PPP_ESCAPE_BEFORE_EXIT is not set -# default: # CONFIG_ESP_MODEM_ADD_DEBUG_LOGS is not set # end of esp-modem @@ -2585,20 +2259,15 @@ CONFIG_MDNS_TASK_AFFINITY=0x0 # CONFIG_MDNS_TASK_CREATE_FROM_INTERNAL=y CONFIG_MDNS_MEMORY_ALLOC_INTERNAL=y -# default: # CONFIG_MDNS_MEMORY_CUSTOM_IMPL is not set # end of MDNS Memory Configuration CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS=2000 CONFIG_MDNS_TIMER_PERIOD_MS=100 -# default: # CONFIG_MDNS_NETWORKING_SOCKET is not set -# default: # CONFIG_MDNS_SKIP_SUPPRESSING_OWN_QUERIES is not set -# default: # CONFIG_MDNS_ENABLE_DEBUG_PRINTS is not set CONFIG_MDNS_ENABLE_CONSOLE_CLI=y -# default: # CONFIG_MDNS_RESPOND_REVERSE_QUERIES is not set CONFIG_MDNS_MULTIPLE_INSTANCE=y @@ -2616,12 +2285,9 @@ CONFIG_MDNS_PREDEF_NETIF_AP=y CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI=y CONFIG_NETWORK_PROV_SCAN_MAX_ENTRIES=16 CONFIG_NETWORK_PROV_AUTOSTOP_TIMEOUT=30 -# default: # CONFIG_NETWORK_PROV_BLE_BONDING is not set CONFIG_NETWORK_PROV_BLE_SEC_CONN=y -# default: # CONFIG_NETWORK_PROV_BLE_FORCE_ENCRYPTION is not set -# default: # CONFIG_NETWORK_PROV_KEEP_BLE_ON_AFTER_PROV is not set CONFIG_NETWORK_PROV_WIFI_STA_ALL_CHANNEL_SCAN=y # CONFIG_NETWORK_PROV_WIFI_STA_FAST_SCAN is not set @@ -2630,7 +2296,6 @@ CONFIG_NETWORK_PROV_WIFI_STA_ALL_CHANNEL_SCAN=y # # LittleFS # -# default: # CONFIG_LITTLEFS_SDMMC_SUPPORT is not set CONFIG_LITTLEFS_MAX_PARTITIONS=3 CONFIG_LITTLEFS_PAGE_SIZE=256 @@ -2641,28 +2306,20 @@ CONFIG_LITTLEFS_LOOKAHEAD_SIZE=128 CONFIG_LITTLEFS_CACHE_SIZE=512 CONFIG_LITTLEFS_BLOCK_CYCLES=512 CONFIG_LITTLEFS_USE_MTIME=y -# default: # CONFIG_LITTLEFS_USE_ONLY_HASH is not set -# default: # CONFIG_LITTLEFS_HUMAN_READABLE is not set CONFIG_LITTLEFS_MTIME_USE_SECONDS=y # CONFIG_LITTLEFS_MTIME_USE_NONCE is not set -# default: # CONFIG_LITTLEFS_SPIFFS_COMPAT is not set -# default: # CONFIG_LITTLEFS_FLUSH_FILE_EVERY_WRITE is not set -# default: # CONFIG_LITTLEFS_FCNTL_GET_PATH is not set -# default: # CONFIG_LITTLEFS_MULTIVERSION is not set # CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE is not set CONFIG_LITTLEFS_MALLOC_STRATEGY_DEFAULT=y # CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL is not set CONFIG_LITTLEFS_ASSERTS=y -# default: # CONFIG_LITTLEFS_MMAP_PARTITION is not set # end of LittleFS # end of Component config -# default: # CONFIG_IDF_EXPERIMENTAL_FEATURES is not set diff --git a/src/BLE_Custom_Characteristic.cpp b/src/BLE_Custom_Characteristic.cpp index 3b924a4c..1d9c5f9c 100644 --- a/src/BLE_Custom_Characteristic.cpp +++ b/src/BLE_Custom_Characteristic.cpp @@ -83,6 +83,7 @@ This characteristic allows for reading and writing various user configuration pa */ + #include #include #include diff --git a/src/BLE_Cycling_Power_Service.cpp b/src/BLE_Cycling_Power_Service.cpp index fa6b3914..19a7a605 100644 --- a/src/BLE_Cycling_Power_Service.cpp +++ b/src/BLE_Cycling_Power_Service.cpp @@ -29,8 +29,8 @@ void BLE_Cycling_Power_Service::setupService(NimBLEServer *pServer, MyCharacteri cyclingPowerMeasurementCharacteristic->setCallbacks(chrCallbacks); pPowerMonitor->start(); - // Add service UUID to DirCon MDNS - DirConManager::addBleServiceUuid(pPowerMonitor->getUUID()); + // Register with DirCon for service discovery + DirConManager::registerService(pPowerMonitor->getUUID()); } void BLE_Cycling_Power_Service::update() { diff --git a/src/BLE_Cycling_Speed_Cadence.cpp b/src/BLE_Cycling_Speed_Cadence.cpp index 92e9e2cc..8a2b22f4 100644 --- a/src/BLE_Cycling_Speed_Cadence.cpp +++ b/src/BLE_Cycling_Speed_Cadence.cpp @@ -25,8 +25,8 @@ void BLE_Cycling_Speed_Cadence::setupService(NimBLEServer *pServer, MyCharacteri cscMeasurement->setCallbacks(chrCallbacks); pCyclingSpeedCadenceService->start(); - // Add service UUID to DirCon MDNS - DirConManager::addBleServiceUuid(pCyclingSpeedCadenceService->getUUID()); + // Register with DirCon for service discovery + DirConManager::registerService(pCyclingSpeedCadenceService->getUUID()); } void BLE_Cycling_Speed_Cadence::update() { diff --git a/src/BLE_Device_Information_Service.cpp b/src/BLE_Device_Information_Service.cpp index 7babe62a..afa783f3 100644 --- a/src/BLE_Device_Information_Service.cpp +++ b/src/BLE_Device_Information_Service.cpp @@ -8,6 +8,32 @@ #include "BLE_Device_Information_Service.h" #include "Constants.h" +#include +#include + +namespace { +constexpr char kDisManufacturerName[] = "SmartSpin2k"; +constexpr char kDisModelNumber[] = "SmartSpin2k"; +constexpr char kDisHardwareRevision[] = "SmartSpin2k"; + +String buildSerialNumber(uint64_t efuseMac) { + char serialNumber[13]; + snprintf(serialNumber, sizeof(serialNumber), "%012llX", efuseMac & 0xFFFFFFFFFFFFULL); + return String(serialNumber); +} + +std::array buildSystemId(uint64_t efuseMac) { + const uint8_t mac0 = static_cast((efuseMac >> 40) & 0xFF); + const uint8_t mac1 = static_cast((efuseMac >> 32) & 0xFF); + const uint8_t mac2 = static_cast((efuseMac >> 24) & 0xFF); + const uint8_t mac3 = static_cast((efuseMac >> 16) & 0xFF); + const uint8_t mac4 = static_cast((efuseMac >> 8) & 0xFF); + const uint8_t mac5 = static_cast(efuseMac & 0xFF); + + return {mac0, mac1, mac2, 0xFF, 0xFE, mac3, mac4, mac5}; +} +} + BLE_Device_Information_Service::BLE_Device_Information_Service() : pDeviceInformationService(nullptr), pManufacturerNameCharacteristic(nullptr), @@ -16,31 +42,36 @@ BLE_Device_Information_Service::BLE_Device_Information_Service() pHardwareRevisionCharacteristic(nullptr), pFirmwareRevisionCharacteristic(nullptr), pSoftwareRevisionCharacteristic(nullptr), - pSystemIDCharacteristic(nullptr) {} + pSystemIDCharacteristic(nullptr), + pPnPIDCharacteristic(nullptr) {} void BLE_Device_Information_Service::setupService(NimBLEServer* pServer) { + const uint64_t efuseMac = ESP.getEfuseMac(); + const String serialNumber = buildSerialNumber(efuseMac); + const std::array systemId = buildSystemId(efuseMac); + pDeviceInformationService = pServer->createService(DEVICE_INFORMATION_SERVICE_UUID); pManufacturerNameCharacteristic = pDeviceInformationService->createCharacteristic(MANUFACTURER_NAME_UUID, NIMBLE_PROPERTY::READ); - pManufacturerNameCharacteristic->setValue((String)userConfig->getDeviceName()); + pManufacturerNameCharacteristic->setValue(kDisManufacturerName); pModelNumberCharacteristic = pDeviceInformationService->createCharacteristic(MODEL_NUMBER_UUID, NIMBLE_PROPERTY::READ); - pModelNumberCharacteristic->setValue((String)userConfig->getDeviceName()); + pModelNumberCharacteristic->setValue(kDisModelNumber); pSerialNumberCharacteristic = pDeviceInformationService->createCharacteristic(SERIAL_NUMBER_UUID, NIMBLE_PROPERTY::READ); - pSerialNumberCharacteristic->setValue((String)ESP.getEfuseMac()); + pSerialNumberCharacteristic->setValue(serialNumber); pHardwareRevisionCharacteristic = pDeviceInformationService->createCharacteristic(HARDWARE_REVISION_UUID, NIMBLE_PROPERTY::READ); - pHardwareRevisionCharacteristic->setValue((String)userConfig->getDeviceName()); + pHardwareRevisionCharacteristic->setValue(kDisHardwareRevision); pFirmwareRevisionCharacteristic = pDeviceInformationService->createCharacteristic(FIRMWARE_REVISION_UUID, NIMBLE_PROPERTY::READ); - pFirmwareRevisionCharacteristic->setValue((String)ESP.getChipRevision()); + pFirmwareRevisionCharacteristic->setValue(FIRMWARE_VERSION); pSoftwareRevisionCharacteristic = pDeviceInformationService->createCharacteristic(SOFTWARE_REVISION_UUID, NIMBLE_PROPERTY::READ); pSoftwareRevisionCharacteristic->setValue(FIRMWARE_VERSION); pSystemIDCharacteristic = pDeviceInformationService->createCharacteristic(SYSTEM_ID_UUID, NIMBLE_PROPERTY::READ); - pSystemIDCharacteristic->setValue((String)userConfig->getDeviceName()); + pSystemIDCharacteristic->setValue(systemId.data(), systemId.size()); pDeviceInformationService->start(); } diff --git a/src/BLE_Fitness_Machine_Service.cpp b/src/BLE_Fitness_Machine_Service.cpp index 58a68742..1ac61a5b 100644 --- a/src/BLE_Fitness_Machine_Service.cpp +++ b/src/BLE_Fitness_Machine_Service.cpp @@ -56,8 +56,16 @@ void BLE_Fitness_Machine_Service::setupService(NimBLEServer *pServer, MyCharacte fitnessMachineControlPoint->setCallbacks(chrCallbacks); pFitnessMachineService->start(); - // Add service UUID to DirCon MDNS - DirConManager::addBleServiceUuid(pFitnessMachineService->getUUID()); + // Register with DirCon for service discovery and write handling + DirConManager::registerService(pFitnessMachineService->getUUID(), [](NimBLECharacteristic *characteristic, const uint8_t *data, size_t length, DirConWriteResult *result) -> bool { + if (characteristic->getUUID().equals(FITNESSMACHINECONTROLPOINT_UUID)) { + spinBLEServer.writeCache.push(characteristic->getValue()); + fitnessMachineService.processFTMSWrite(); + result->updateResponseData = true; + return true; + } + return false; + }); } void BLE_Fitness_Machine_Service::update() { diff --git a/src/BLE_Heart_Service.cpp b/src/BLE_Heart_Service.cpp index d8c5732b..5346f7b3 100644 --- a/src/BLE_Heart_Service.cpp +++ b/src/BLE_Heart_Service.cpp @@ -18,8 +18,8 @@ void BLE_Heart_Service::setupService(NimBLEServer *pServer, MyCharacteristicCall heartRateMeasurementCharacteristic->setValue(heartRateMeasurement, 2); heartRateMeasurementCharacteristic->setCallbacks(chrCallbacks); pHeartService->start(); - // Add service UUID to DirCon MDNS - DirConManager::addBleServiceUuid(pHeartService->getUUID()); + // Register with DirCon for service discovery + DirConManager::registerService(pHeartService->getUUID()); } void BLE_Heart_Service::deinit() { diff --git a/src/BLE_Server.cpp b/src/BLE_Server.cpp index 7dba08c7..8cc3fa92 100644 --- a/src/BLE_Server.cpp +++ b/src/BLE_Server.cpp @@ -19,6 +19,7 @@ #include "BLE_Fitness_Machine_Service.h" #include "BLE_Custom_Characteristic.h" #include "BLE_Device_Information_Service.h" +#include "BLE_Zwift_Service.h" // BLE Server Settings SpinBLEServer spinBLEServer; @@ -31,6 +32,7 @@ BLE_Heart_Service heartService; BLE_Fitness_Machine_Service fitnessMachineService; BLE_ss2kCustomCharacteristic ss2kCustomCharacteristic; BLE_Device_Information_Service deviceInformationService; +BLE_Zwift_Service zwiftService; // BLE_Wattbike_Service wattbikeService; // BLE_SB20_Service sb20Service; @@ -44,32 +46,30 @@ void startBLEServer() { BLEAdvertising* pAdvertising = BLEDevice::getAdvertising(); pAdvertising->enableScanResponse(true); NimBLEAdvertisementData oScanResponseData; - NimBLEAdvertisementData oAdvertisementData; std::vector oServiceUUIDs; - oScanResponseData.setFlags(0x06); // General Discoverable, BR/EDR Not Supported - oScanResponseData.setCompleteServices(SMARTSPIN2K_SERVICE_UUID); cyclingSpeedCadenceService.setupService(spinBLEServer.pServer, &chrCallbacks); cyclingPowerService.setupService(spinBLEServer.pServer, &chrCallbacks); heartService.setupService(spinBLEServer.pServer, &chrCallbacks); fitnessMachineService.setupService(spinBLEServer.pServer, &chrCallbacks); ss2kCustomCharacteristic.setupService(spinBLEServer.pServer); deviceInformationService.setupService(spinBLEServer.pServer); - //add all service UUIDs to advertisement vector - oServiceUUIDs.push_back(CSCSERVICE_UUID); - oServiceUUIDs.push_back(CYCLINGPOWERSERVICE_UUID); - oServiceUUIDs.push_back(HEARTSERVICE_UUID); - oServiceUUIDs.push_back(FITNESSMACHINESERVICE_UUID); - oAdvertisementData.setFlags(0x06); // General Discoverable, BR/EDR Not Supported - oAdvertisementData.setCompleteServices16(oServiceUUIDs); - pAdvertising->setAdvertisementData(oAdvertisementData); + zwiftService.setupService(spinBLEServer.pServer); + pAdvertising->addServiceUUID(HEARTSERVICE_UUID); + // pAdvertising->addServiceUUID(ZWIFT_RIDE_CUSTOM_SERVICE_UUID); + pAdvertising->addServiceUUID(FITNESSMACHINESERVICE_UUID); + + // Put the device name and SmartSpin2k service UUID in the scan response to avoid + // overflowing the primary ad packet (which already carries manufacturer data + service UUIDs). + oScanResponseData.setName(userConfig->getDeviceName()); + oScanResponseData.setCompleteServices(SMARTSPIN2K_SERVICE_UUID); pAdvertising->setScanResponseData(oScanResponseData); + // wattbikeService.setupService(spinBLEServer.pServer); // No callback needed // sb20Service.begin(); BLEFirmwareSetup(spinBLEServer.pServer); // const std::string fitnessData = {0b00000001, 0b00100000, 0b00000000}; // pAdvertising->setServiceData(FITNESSMACHINESERVICE_UUID, fitnessData); - pAdvertising->setName(userConfig->getDeviceName()); pAdvertising->setMaxInterval(250); pAdvertising->setMinInterval(160); pAdvertising->start(); @@ -85,6 +85,7 @@ void SpinBLEServer::update() { cyclingPowerService.update(); cyclingSpeedCadenceService.update(); fitnessMachineService.update(); + zwiftService.update(); // wattbikeService.parseNemit(); // Changed from update() to parseNemit() // sb20Service.notify(); } @@ -157,7 +158,7 @@ void MyServerCallbacks::onDisconnect(NimBLEServer* pServer) { } void MyServerCallbacks::onMTUChange(uint16_t MTU, NimBLEConnInfo& connInfo) { - //SS2K_LOG(BLE_SERVER_LOG_TAG, "MTU updated: %u for connection ID: %u", MTU, connInfo.getConnHandle()); + // SS2K_LOG(BLE_SERVER_LOG_TAG, "MTU updated: %u for connection ID: %u", MTU, connInfo.getConnHandle()); } bool MyServerCallbacks::onConnParamsUpdateRequest(uint16_t handle, const ble_gap_upd_params* params) { diff --git a/src/BLE_Zwift_Service.cpp b/src/BLE_Zwift_Service.cpp new file mode 100644 index 00000000..80da8f5c --- /dev/null +++ b/src/BLE_Zwift_Service.cpp @@ -0,0 +1,720 @@ +/* + * Copyright (C) 2020 Anthony Doud & Joel Baranick + * All rights reserved + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#include "BLE_Zwift_Service.h" +#include "Main.h" +#include "SS2KLog.h" +#include "DirConManager.h" +#include + +using ZwiftProtocol::CommandCode; +using ZwiftProtocol::makeTag; +using ZwiftProtocol::RideButtonMask; +using ZwiftProtocol::toUnderlying; +using ZwiftProtocol::WireType; + +namespace { +constexpr uint8_t kRideAnalogButtonsPayloadSize = 0x18; + +constexpr uint8_t kRideKeypadButtonMapTag = makeTag(ZwiftProtocol::RideKeyPadStatus::Field::ButtonMap, WireType::Varint); +constexpr uint8_t kRideKeypadAnalogButtonsTag = makeTag(ZwiftProtocol::RideKeyPadStatus::Field::AnalogButtons, WireType::LengthDelimited); +constexpr uint8_t kRideAnalogGroupStatusTag = makeTag(ZwiftProtocol::RideAnalogKeyGroup::Field::GroupStatus, WireType::LengthDelimited); +constexpr uint8_t kRideAnalogLocationTag = makeTag(ZwiftProtocol::RideAnalogKeyPress::Field::Location, WireType::Varint); +constexpr uint8_t kRideAnalogValueTag = makeTag(ZwiftProtocol::RideAnalogKeyPress::Field::AnalogValue, WireType::Varint); + +uint32_t getNextZwiftField5Counter(uint16_t power) { + const int knownOutputs[] = {2864, 4060, 4636, 6803}; + static int counter = 0; + if (power > 0) { + counter++; + } else { + counter = 0; + } + return knownOutputs[counter % (sizeof(knownOutputs) / sizeof(knownOutputs[0]))]; +} +} // namespace + +// "RideOn" handshake bytes +static const char RideOn[7] = "RideOn"; +// static const uint8_t RIDE_ON[] = {0x52, 0x69, 0x64, 0x65, 0x4F, 0x6E}; +// static const size_t RIDE_ON_LEN = sizeof(RIDE_ON); + +// Response type bytes appended after RideOn for trainer emulation +static const uint8_t RESPONSE_START[] = {0x02, 0x00}; +static const size_t RESPONSE_START_LEN = sizeof(RESPONSE_START); + +// Async RideOn answer (protobuf-encoded "RIDE_ON(0)") - sent on async after handshake +static const uint8_t ASYNC_RIDEON_ANSWER[] = {0x2a, 0x08, 0x03, 0x12, 0x0d, 0x22, 0x0b, 0x52, 0x49, 0x44, 0x45, 0x5f, 0x4f, 0x4e, 0x28, 0x30, 0x29, 0x00}; +static const size_t ASYNC_RIDEON_ANSWER_LEN = sizeof(ASYNC_RIDEON_ANSWER); + +// Pre-computed "no buttons pressed" Ride notification (opcode 0x23 + bitmap + analog data) +static const uint8_t ALL_RELEASED[] = { + toUnderlying(CommandCode::RideKeyPadStatus), + kRideKeypadButtonMapTag, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0x0F, // field 1: bitmap = 0xFFFFFFFF (all released) + kRideKeypadAnalogButtonsTag, + kRideAnalogButtonsPayloadSize, + kRideAnalogGroupStatusTag, + 0x04, + kRideAnalogLocationTag, + toUnderlying(ZwiftProtocol::RideAnalogLocation::Left), + kRideAnalogValueTag, + 0x00, // analog 0 (LEFT): value 0 + kRideAnalogGroupStatusTag, + 0x04, + kRideAnalogLocationTag, + toUnderlying(ZwiftProtocol::RideAnalogLocation::Right), + kRideAnalogValueTag, + 0x00, // analog 1 (RIGHT): value 0 + kRideAnalogGroupStatusTag, + 0x04, + kRideAnalogLocationTag, + toUnderlying(ZwiftProtocol::RideAnalogLocation::Up), + kRideAnalogValueTag, + 0x00, // analog 2: value 0 + kRideAnalogGroupStatusTag, + 0x04, + kRideAnalogLocationTag, + toUnderlying(ZwiftProtocol::RideAnalogLocation::Down), + kRideAnalogValueTag, + 0x00 // analog 3: value 0 +}; +static const size_t ALL_RELEASED_LEN = sizeof(ALL_RELEASED); + +static const uint8_t ASK6_PREFIX[] = { + toUnderlying(CommandCode::HubCommand), + makeTag(ZwiftProtocol::HubCommand::Field::Physical, WireType::LengthDelimited), + 0x04, + makeTag(ZwiftProtocol::PhysicalParam::Field::GearRatioX10000, WireType::Varint), +}; + +static const uint8_t ASK7_PREFIX[] = { + toUnderlying(CommandCode::HubCommand), + makeTag(ZwiftProtocol::HubCommand::Field::Physical, WireType::LengthDelimited), + 0x03, + makeTag(ZwiftProtocol::PhysicalParam::Field::GearRatioX10000, WireType::Varint), +}; + +static ZwiftSyncRxCallbacks zwiftSyncRxCallbacks; + +BLE_Zwift_Service::BLE_Zwift_Service() + : pZwiftService(nullptr), + asyncCharacteristic(nullptr), + syncRxCharacteristic(nullptr), + syncTxCharacteristic(nullptr), + unknownCharacteristic5(nullptr), + unknownCharacteristic6(nullptr), + _lastActivityTime(0), + _lastKeepaliveTime(0), + _lastRidingDataTime(0), + _gearRatioX10000(0) {} + +const char* BLE_Zwift_Service::getLogTag() const { return isDirCon ? kZwiftDirConLogTag : kZwiftBleLogTag; } + +void BLE_Zwift_Service::resetSession() { + _lastActivityTime = 0; + _lastKeepaliveTime = 0; + _lastRidingDataTime = 0; + _gearRatioX10000 = 0; +} + +bool BLE_Zwift_Service::keepAlive(unsigned long now) { + if ((now - _lastActivityTime >= kZwiftSessionTimeoutMs) && isConnected()) { + SS2K_LOG(getLogTag(), "Zwift session timed out waiting for keepalive/activity"); + resetSession(); + return false; + } + + if (now - _lastKeepaliveTime >= kZwiftKeepaliveIntervalMs && isConnected()) { + // Keepalive sent on sync_tx as "no buttons pressed" notification + syncTxCharacteristic->setValue(ALL_RELEASED, ALL_RELEASED_LEN); + syncTxCharacteristic->indicate(); + DirConManager::notifyCharacteristic(NimBLEUUID(ZWIFT_RIDE_CUSTOM_SERVICE_UUID), syncTxCharacteristic->getUUID(), const_cast(ALL_RELEASED), ALL_RELEASED_LEN); + _lastKeepaliveTime = now; + } + + return true; +} + +void BLE_Zwift_Service::setupService(NimBLEServer* pServer) { + // Battery Level Service (0x180F) - Zwift expects this on Click controllers + NimBLEService* pBatteryService = pServer->createService(NimBLEUUID((uint16_t)0x180F)); + NimBLECharacteristic* batteryLevelChar = pBatteryService->createCharacteristic(NimBLEUUID((uint16_t)0x2A19), NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY); + uint8_t batteryLevel = 100; + batteryLevelChar->setValue(&batteryLevel, 1); + pBatteryService->start(); + + // Zwift Custom Service (use 0xFC82 to match advertisement) + pZwiftService = pServer->createService(ZWIFT_RIDE_CUSTOM_SERVICE_UUID); + + // Async characteristic: NOTIFY - sends button presses to Zwift + asyncCharacteristic = pZwiftService->createCharacteristic(ZWIFT_ASYNC_CHARACTERISTIC_UUID, NIMBLE_PROPERTY::NOTIFY); + + // Sync RX: WRITE_WITHOUT_RESPONSE - receives handshake from Zwift + syncRxCharacteristic = pZwiftService->createCharacteristic(ZWIFT_SYNC_RX_CHARACTERISTIC_UUID, NIMBLE_PROPERTY::WRITE_NR); + syncRxCharacteristic->setCallbacks(&zwiftSyncRxCallbacks); + + // Sync TX: READ | INDICATE - sends handshake response and keepalive + syncTxCharacteristic = pZwiftService->createCharacteristic(ZWIFT_SYNC_TX_CHARACTERISTIC_UUID, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::INDICATE); + + // Unknown characteristic 5: NOTIFY + unknownCharacteristic5 = pZwiftService->createCharacteristic(ZWIFT_UNKNOWN_CHARACTERISTIC5_UUID, NIMBLE_PROPERTY::NOTIFY); + + // Unknown characteristic 6: READ | WRITE | WRITE_NR | INDICATE + unknownCharacteristic6 = pZwiftService->createCharacteristic(ZWIFT_UNKNOWN_CHARACTERISTIC6_UUID, + NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::WRITE_NR | NIMBLE_PROPERTY::INDICATE); + + pZwiftService->start(); + + // Register with DirCon for service discovery and write handling + DirConManager::registerService(pZwiftService->getUUID(), [](NimBLECharacteristic* characteristic, const uint8_t* data, size_t length, DirConWriteResult* result) -> bool { + if (characteristic->getUUID().equals(NimBLEUUID(ZWIFT_SYNC_RX_CHARACTERISTIC_UUID))) { + result->autoSubscribeUuids[0] = NimBLEUUID(ZWIFT_SYNC_TX_CHARACTERISTIC_UUID); + result->autoSubscribeUuids[1] = NimBLEUUID(ZWIFT_ASYNC_CHARACTERISTIC_UUID); + result->autoSubscribeCount = 2; + std::string value(reinterpret_cast(data), length); + zwiftService.handleSyncRxWrite(value, true); + return true; + } + return false; + }); + + SS2K_LOG(getLogTag(), "Zwift Custom Service started"); +} + +void BLE_Zwift_Service::update() { + unsigned long now = millis(); + static unsigned long lastadvTime = 0; + static bool advertiseManufacturerData = true; + static bool swapAdv = false; + const unsigned long advSwapIntervalMs = 10000; // Toggle Manufacturer data advertisement every 10 seconds with current BLE address + NimBLEAdvertising* pAdvertising = NimBLEDevice::getAdvertising(); + + if (!keepAlive(now)) { + return; + } + + // // Zwift identifies controllers via manufacturer data with company ID 0x094A. + // // Set the last two bytes to the last two bytes of our BLE address in little endian. + // // We can't advertise this continuously however because Zwift doesn't configure virtual shifting correctly if it's on. + // if (now - lastadvTime >= advSwapIntervalMs) { + // lastadvTime = now; + // advertiseManufacturerData = !advertiseManufacturerData; + // swapAdv = !swapAdv; + // } + + // if (advertiseManufacturerData && swapAdv) { + // SS2K_LOG(getLogTag(), "Advertising Zwift Manufacturer Data"); + // uint8_t zwiftMfrData[] = {0x4A, 0x09, 0x0B, 0x58, 0x9A}; + // const std::string bleAddress = BLEDevice::getAddress().toString(); // "aa:bb:cc:dd:ee:ff" + // unsigned int mac[6] = {0}; + // if (sscanf(bleAddress.c_str(), "%02x:%02x:%02x:%02x:%02x:%02x", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) == 6) { + // // BLE address tail bytes are ee:ff in string form -> little endian in mfr data is ff, ee + // zwiftMfrData[3] = static_cast(mac[5]); + // zwiftMfrData[4] = static_cast(mac[4]); + // } + // pAdvertising->removeServices(); + // pAdvertising->setManufacturerData(zwiftMfrData, sizeof(zwiftMfrData)); + // swapAdv = !swapAdv; + // } else if (swapAdv) { + // SS2K_LOG(getLogTag(), "Stopping Zwift Service Advertisement"); + // pAdvertising->setManufacturerData(nullptr, 0); + // pAdvertising->addServiceUUID(FITNESSMACHINESERVICE_UUID); + // pAdvertising->addServiceUUID(HEARTSERVICE_UUID); + // swapAdv = !swapAdv; + // } + + uint8_t zData[48]; + size_t pos = 0; + const uint16_t powerWatts = static_cast(rtConfig->watts.getValue()); + const uint16_t cadence = static_cast(rtConfig->cad.getValue()); + const uint16_t heartRate = static_cast(rtConfig->hr.getValue()); + const uint32_t field5Counter = getNextZwiftField5Counter(powerWatts); + + zData[pos++] = toUnderlying(CommandCode::HubRidingData); + + // Field 1: Power (tag 0x08) + zData[pos++] = makeTag(ZwiftProtocol::HubRidingData::Field::Power, WireType::Varint); + pos += encodeUleb128(powerWatts, &zData[pos]); + + // Field 2: Cadence (tag 0x10) + zData[pos++] = makeTag(ZwiftProtocol::HubRidingData::Field::Cadence, WireType::Varint); + pos += encodeUleb128(cadence, &zData[pos]); + + // Field 3: SpeedX100 (tag 0x18) + int speedX100 = rtConfig->getSimulatedSpeed(); + zData[pos++] = makeTag(ZwiftProtocol::HubRidingData::Field::SpeedX100, WireType::Varint); + pos += encodeUleb128(static_cast(speedX100), &zData[pos]); + + // Field 4: HR (tag 0x20) + zData[pos++] = makeTag(ZwiftProtocol::HubRidingData::Field::HeartRate, WireType::Varint); + pos += encodeUleb128(heartRate, &zData[pos]); + + // Field 5: Rolling counter derived from the observed trainer payloads. + zData[pos++] = makeTag(ZwiftProtocol::HubRidingData::Field::Unknown1, WireType::Varint); + pos += encodeUleb128(field5Counter, &zData[pos]); + + // Field 6: Unknown2 (tag 0x30) - constant 25714 from SHIFTR reference + zData[pos++] = makeTag(ZwiftProtocol::HubRidingData::Field::Unknown2, WireType::Varint); + pos += encodeUleb128(30091, &zData[pos]); + + // every 5 seconds, print the zData for debugging. + // static unsigned long lastDebugTime = 0; + // if (now - lastDebugTime >= 5000) { + // lastDebugTime = now; + // SS2K_LOG(getLogTag(), "Zwift riding data: %s", toHexString(zData, pos).c_str()); + // } + + asyncCharacteristic->setValue(zData, pos); + asyncCharacteristic->notify(); + DirConManager::notifyCharacteristic(NimBLEUUID(ZWIFT_RIDE_CUSTOM_SERVICE_UUID), asyncCharacteristic->getUUID(), zData, pos); +} + +bool BLE_Zwift_Service::isConnected() { + unsigned long now = millis(); + return now - _lastActivityTime < kZwiftSessionTimeoutMs; +} + +uint32_t BLE_Zwift_Service::getGearRatioX10000() { return _gearRatioX10000; } + +void BLE_Zwift_Service::sendSyncTxPayload(const uint8_t* payload, size_t length) { + if (syncTxCharacteristic == nullptr || payload == nullptr || length == 0) { + return; + } + + syncTxCharacteristic->setValue(payload, length); + syncTxCharacteristic->indicate(); + DirConManager::notifyCharacteristic(NimBLEUUID(ZWIFT_RIDE_CUSTOM_SERVICE_UUID), syncTxCharacteristic->getUUID(), const_cast(payload), length); +} + +void BLE_Zwift_Service::sendAsyncPayload(const uint8_t* payload, size_t length) { + if (asyncCharacteristic == nullptr || payload == nullptr || length == 0) { + return; + } + + asyncCharacteristic->setValue(payload, length); + asyncCharacteristic->notify(); + DirConManager::notifyCharacteristic(NimBLEUUID(ZWIFT_RIDE_CUSTOM_SERVICE_UUID), asyncCharacteristic->getUUID(), const_cast(payload), length); +} + +void BLE_Zwift_Service::sendGearRatioSyncTx() { + uint32_t ratio = (_gearRatioX10000 > 0) ? _gearRatioX10000 : 15300; + uint8_t ratioEnc[5]; + size_t ratioLen = encodeUleb128(static_cast(ratio), ratioEnc); + size_t contentLen = 1 + ratioLen; + size_t subContentLen = 2 + contentLen; + + uint8_t resp[20]; + size_t pos = 0; + resp[pos++] = toUnderlying(CommandCode::DeviceInformation); + resp[pos++] = makeTag(ZwiftProtocol::DeviceInformation::Field::InformationId, WireType::Varint); + pos += encodeUleb128(toUnderlying(ZwiftProtocol::HubRequest::DataId::GearRatio), &resp[pos]); + resp[pos++] = makeTag(ZwiftProtocol::DeviceInformation::Field::SubContent, WireType::LengthDelimited); + pos += encodeUleb128(static_cast(subContentLen), &resp[pos]); + resp[pos++] = makeTag(ZwiftProtocol::SubContent::Field::Content, WireType::LengthDelimited); + pos += encodeUleb128(static_cast(contentLen), &resp[pos]); + resp[pos++] = makeTag(ZwiftProtocol::DeviceInformationContent::Field::ReplyData, WireType::Varint); + memcpy(&resp[pos], ratioEnc, ratioLen); + pos += ratioLen; + + sendSyncTxPayload(resp, pos); +} + +void BLE_Zwift_Service::sendGeneralInfoSyncTx() { + const char* deviceName = userConfig->getDeviceName(); + size_t nameLen = strlen(deviceName); + if (nameLen > 20) nameLen = 20; + + // Keep GeneralInfo minimal to match the currently recovered ZPDeviceInformation shape. + uint8_t content[40]; + size_t cpos = 0; + content[cpos++] = makeTag(ZwiftProtocol::DeviceInformationContent::Field::Unknown1, WireType::Varint); + cpos += encodeUleb128(1ULL, &content[cpos]); + content[cpos++] = makeTag(ZwiftProtocol::DeviceInformationContent::Field::SoftwareVersion, WireType::Varint); + cpos += encodeUleb128(100ULL, &content[cpos]); + content[cpos++] = makeTag(ZwiftProtocol::DeviceInformationContent::Field::DeviceName, WireType::LengthDelimited); + cpos += encodeUleb128(static_cast(nameLen), &content[cpos]); + memcpy(&content[cpos], deviceName, nameLen); + cpos += nameLen; + + size_t contentLen = cpos; + size_t subContentLen = 1 + encodeUleb128Len(contentLen) + contentLen; + + uint8_t resp[60]; + size_t pos = 0; + resp[pos++] = toUnderlying(CommandCode::DeviceInformation); + resp[pos++] = makeTag(ZwiftProtocol::DeviceInformation::Field::InformationId, WireType::Varint); + pos += encodeUleb128(toUnderlying(ZwiftProtocol::HubRequest::DataId::GeneralInfo), &resp[pos]); + resp[pos++] = makeTag(ZwiftProtocol::DeviceInformation::Field::SubContent, WireType::LengthDelimited); + pos += encodeUleb128(static_cast(subContentLen), &resp[pos]); + resp[pos++] = makeTag(ZwiftProtocol::SubContent::Field::Content, WireType::LengthDelimited); + pos += encodeUleb128(static_cast(contentLen), &resp[pos]); + memcpy(&resp[pos], content, cpos); + pos += cpos; + + sendSyncTxPayload(resp, pos); +} + +void BLE_Zwift_Service::sendTrainerConfigSimulationStatus(uint32_t realGearRatioX10000, uint32_t virtualGearRatioX10000) { + uint8_t content[16]; + size_t cpos = 0; + + content[cpos++] = makeTag(ZwiftProtocol::TrainerConfigSimulation::Field::RealGearRatio, WireType::Varint); + cpos += encodeUleb128(realGearRatioX10000, &content[cpos]); + content[cpos++] = makeTag(ZwiftProtocol::TrainerConfigSimulation::Field::VirtualGearRatio, WireType::Varint); + cpos += encodeUleb128(virtualGearRatioX10000, &content[cpos]); + + uint8_t payload[20]; + size_t pos = 0; + payload[pos++] = toUnderlying(CommandCode::TrainerConfigStatus); + payload[pos++] = makeTag(ZwiftProtocol::TrainerConfigStatus::Field::Simulation, WireType::LengthDelimited); + pos += encodeUleb128(static_cast(cpos), &payload[pos]); + memcpy(&payload[pos], content, cpos); + pos += cpos; + + SS2K_LOG(getLogTag(), "Sending TrainerConfigStatus simulation: real=%u virtual=%u", realGearRatioX10000, virtualGearRatioX10000); + sendAsyncPayload(payload, pos); +} + +void BLE_Zwift_Service::sendTrainerConfigVirtualShiftStatus(uint8_t virtualShiftingMode) { + uint8_t payload[8]; + size_t pos = 0; + payload[pos++] = toUnderlying(CommandCode::TrainerConfigStatus); + payload[pos++] = makeTag(ZwiftProtocol::TrainerConfigStatus::Field::VirtualShift, WireType::LengthDelimited); + payload[pos++] = 0x02; + payload[pos++] = makeTag(ZwiftProtocol::TrainerConfigVirtualShift::Field::VirtualShiftingMode, WireType::Varint); + payload[pos++] = virtualShiftingMode; + + SS2K_LOG(getLogTag(), "Sending TrainerConfigStatus virtual shift mode=%u", virtualShiftingMode); + sendAsyncPayload(payload, pos); +} + +void BLE_Zwift_Service::sendShiftUp() { + SS2K_LOG(getLogTag(), "Sending shift up to Zwift"); + sendButtonNotification(RideButtonMask::ShiftUpRight); + // Small delay then release - Zwift needs to see the transition + vTaskDelay(50 / portTICK_PERIOD_MS); + sendAllButtonsReleased(); +} + +void BLE_Zwift_Service::sendShiftDown() { + SS2K_LOG(getLogTag(), "Sending shift down to Zwift"); + sendButtonNotification(RideButtonMask::ShiftUpLeft); + // Small delay then release + vTaskDelay(50 / portTICK_PERIOD_MS); + sendAllButtonsReleased(); +} + +void BLE_Zwift_Service::sendButtonNotification(RideButtonMask buttonMask) { + // Build Ride format: opcode(1) + tag(1) + varint(max5) + analog(26) = max 33 bytes + uint32_t buttonMap = toUnderlying(~buttonMask); + + static const uint8_t analogData[] = {kRideKeypadAnalogButtonsTag, kRideKeypadAnalogButtonsTag + 0x06, + kRideAnalogGroupStatusTag, 0x04, + kRideAnalogLocationTag, toUnderlying(ZwiftProtocol::RideAnalogLocation::Left), + kRideAnalogValueTag, 0x00, + kRideAnalogGroupStatusTag, 0x04, + kRideAnalogLocationTag, toUnderlying(ZwiftProtocol::RideAnalogLocation::Right), + kRideAnalogValueTag, 0x00, + kRideAnalogGroupStatusTag, 0x04, + kRideAnalogLocationTag, toUnderlying(ZwiftProtocol::RideAnalogLocation::Up), + kRideAnalogValueTag, 0x00, + kRideAnalogGroupStatusTag, 0x04, + kRideAnalogLocationTag, toUnderlying(ZwiftProtocol::RideAnalogLocation::Down), + kRideAnalogValueTag, 0x00}; + + uint8_t buf[33]; + buf[0] = toUnderlying(CommandCode::RideKeyPadStatus); + buf[1] = kRideKeypadButtonMapTag; + size_t varintLen = encodeVarint32(buttonMap, &buf[2]); + size_t pos = 2 + varintLen; + memcpy(&buf[pos], analogData, sizeof(analogData)); + pos += sizeof(analogData); + + asyncCharacteristic->setValue(buf, pos); + asyncCharacteristic->notify(); + DirConManager::notifyCharacteristic(NimBLEUUID(ZWIFT_RIDE_CUSTOM_SERVICE_UUID), asyncCharacteristic->getUUID(), buf, pos); +} + +size_t BLE_Zwift_Service::encodeVarint32(uint32_t value, uint8_t* buffer) { + size_t i = 0; + while (value > 0x7F) { + buffer[i++] = static_cast((value & 0x7F) | 0x80); + value >>= 7; + } + buffer[i++] = static_cast(value); + return i; +} + +void BLE_Zwift_Service::sendAllButtonsReleased() { + asyncCharacteristic->setValue(ALL_RELEASED, ALL_RELEASED_LEN); + asyncCharacteristic->notify(); + DirConManager::notifyCharacteristic(NimBLEUUID(ZWIFT_RIDE_CUSTOM_SERVICE_UUID), asyncCharacteristic->getUUID(), const_cast(ALL_RELEASED), ALL_RELEASED_LEN); +} + +void BLE_Zwift_Service::handleSyncRxWrite(const std::string& value, bool _isDirCon) { + isDirCon = _isDirCon; + if (value.length() < 2) { + SS2K_LOG(getLogTag(), "Received short write on sync_rx, ignoring"); + return; + } + + _lastActivityTime = millis(); + + const uint8_t* data = reinterpret_cast(value.data()); + + // Check if it starts with "RideOn" (handshake) + if (value.length() >= 6 && memcmp(data, RideOn, 6) == 0) { + SS2K_LOG(getLogTag(), "Received RideOn handshake from Zwift (%s)", _isDirCon ? "DirCon" : "BLE"); + + // Send sync_tx response: "RideOn" + trainer response start bytes {0x02, 0x00} + uint8_t syncResponse[6 + RESPONSE_START_LEN]; + memcpy(syncResponse, RideOn, 6); + memcpy(syncResponse + 6, RESPONSE_START, RESPONSE_START_LEN); + syncTxCharacteristic->setValue(syncResponse, sizeof(syncResponse)); + syncTxCharacteristic->indicate(); + + // Send async RideOn answer (protobuf "RIDE_ON(0)") to signal trainer capability + asyncCharacteristic->setValue(ASYNC_RIDEON_ANSWER, ASYNC_RIDEON_ANSWER_LEN); + asyncCharacteristic->notify(); + + if (_isDirCon) { + DirConManager::notifyCharacteristic(NimBLEUUID(ZWIFT_RIDE_CUSTOM_SERVICE_UUID), syncTxCharacteristic->getUUID(), syncResponse, sizeof(syncResponse), false); + DirConManager::notifyCharacteristic(NimBLEUUID(ZWIFT_RIDE_CUSTOM_SERVICE_UUID), asyncCharacteristic->getUUID(), const_cast(ASYNC_RIDEON_ANSWER), + ASYNC_RIDEON_ANSWER_LEN, false); + } + + resetSession(); + _lastActivityTime = millis(); + _lastKeepaliveTime = _lastActivityTime; + _lastRidingDataTime = _lastActivityTime; + + SS2K_LOG(getLogTag(), "Handshake complete - %s mode active", _isDirCon ? "DirCon" : "BLE"); + + sendTrainerConfigVirtualShiftStatus(); + return; + } + // Handshake is already complete, handle commands + handleZwiftCommand(data, value.length()); +} + +void BLE_Zwift_Service::handleZwiftCommand(const uint8_t* data, size_t length) { + if (length < 1) return; + + uint8_t opcode = data[0]; + + switch (opcode) { + case toUnderlying(CommandCode::HubRequest): { + // Parse DataId from HubRequest: field 1 (tag 0x08) = DataId varint + uint64_t param = 0; + if (length >= 3 && data[1] == makeTag(ZwiftProtocol::HubRequest::Field::DataId, WireType::Varint)) { + // Standard protobuf: 0x00 0x08 + decodeUleb128(&data[2], length - 2, ¶m); + } else if (length >= 2) { + // Fallback: raw ULEB128 without protobuf tag + decodeUleb128(&data[1], length - 1, ¶m); + } + SS2K_LOG(getLogTag(), "Info request (0x%02X) param=%llu", opcode, param); + + if (param == toUnderlying(ZwiftProtocol::HubRequest::DataId::GearRatio)) { + sendGearRatioSyncTx(); + + } else if (param == toUnderlying(ZwiftProtocol::HubRequest::DataId::GeneralInfo)) { + sendGeneralInfoSyncTx(); + SS2K_LOG(getLogTag(), "Responded with device info"); + } + break; + } + + case toUnderlying(CommandCode::HubCommand): { + if (length < 2) { + break; + } + + uint8_t subtype = data[1]; + + switch (subtype) { + case makeTag(ZwiftProtocol::HubCommand::Field::PowerTarget, WireType::Varint): { + if (length >= 3) { + uint64_t power = 0; + decodeUleb128(&data[2], length - 2, &power); + SS2K_LOG(getLogTag(), "ERG power: %dW", static_cast(power)); + rtConfig->setFTMSMode(FitnessMachineControlPointProcedure::SetTargetPower); + rtConfig->watts.setTarget(static_cast(power)); + } + break; + } + + case makeTag(ZwiftProtocol::HubCommand::Field::Simulation, WireType::LengthDelimited): { + if (length >= 4) { + uint8_t subLen = data[2]; + size_t pos = 3; + while (pos < static_cast(3 + subLen) && pos < length) { + uint8_t fieldTag = data[pos++]; + uint64_t fieldValue = 0; + size_t decoded = decodeUleb128(&data[pos], length - pos, &fieldValue); + if (decoded == 0) break; + pos += decoded; + + if (fieldTag == makeTag(ZwiftProtocol::SimulationParam::Field::InclineX100, WireType::Varint)) { + int64_t grade = static_cast((fieldValue >> 1) ^ -(fieldValue & 1)); + SS2K_LOG(getLogTag(), "SIM grade: %.2f%%", grade / 100.0); + rtConfig->setFTMSMode(FitnessMachineControlPointProcedure::SetIndoorBikeSimulationParameters); + rtConfig->setTargetIncline(static_cast(grade)); + } + } + } + break; + } + + case makeTag(ZwiftProtocol::HubCommand::Field::Physical, WireType::LengthDelimited): { + if (length >= 4) { + bool isAsk6 = (length >= 7 && memcmp(data, ASK6_PREFIX, sizeof(ASK6_PREFIX)) == 0); + bool isAsk7 = (length >= 6 && memcmp(data, ASK7_PREFIX, sizeof(ASK7_PREFIX)) == 0); + + uint8_t subLen = data[2]; + size_t pos = 3; + while (pos < static_cast(3 + subLen) && pos < length) { + uint8_t fieldTag = data[pos++]; + uint64_t fieldValue = 0; + size_t decoded = decodeUleb128(&data[pos], length - pos, &fieldValue); + if (decoded == 0) break; + pos += decoded; + + if (fieldTag == makeTag(ZwiftProtocol::PhysicalParam::Field::GearRatioX10000, WireType::Varint)) { + _gearRatioX10000 = static_cast(fieldValue); + SS2K_LOG(getLogTag(), "Ask %d Gear ratio: %.4f", isAsk6 ? 6 : (isAsk7 ? 7 : 0), _gearRatioX10000 / 10000.0); + applyGearRatio(); + + const uint32_t reportedRatio = (_gearRatioX10000 > 0) ? _gearRatioX10000 : 15300; + + if (isAsk6) { + // Ask 6: send sync_tx ratio echo first, then async trainer-config confirmation. + sendGearRatioSyncTx(); + sendTrainerConfigVirtualShiftStatus(); + } else if (isAsk7) { + // Ask 7: preserve the observed async-then-sync ordering. + sendTrainerConfigVirtualShiftStatus(); + sendGearRatioSyncTx(); + } else { + sendGearRatioSyncTx(); + sendTrainerConfigVirtualShiftStatus(); + } + } + // Fields 0x20 (bike weight) and 0x28 (rider weight) - logged for debugging + else if (fieldTag == makeTag(ZwiftProtocol::PhysicalParam::Field::BikeWeightX100, WireType::Varint)) { + SS2K_LOG(getLogTag(), "Bike weight: %.2fkg", fieldValue / 100.0); + } else if (fieldTag == makeTag(ZwiftProtocol::PhysicalParam::Field::RiderWeightX100, WireType::Varint)) { + SS2K_LOG(getLogTag(), "Rider weight: %.2fkg", fieldValue / 100.0); + } + } + } + break; + } + + default: + SS2K_LOG(getLogTag(), "Unknown control subtype: 0x%02X", subtype); + break; + } + break; + } + + case 0x41: // Unknown request type (similar to info request) + SS2K_LOG(getLogTag(), "Request 0x41"); + break; + + default: + SS2K_LOG(getLogTag(), "Unknown command opcode: 0x%02X", opcode); + break; + } +} + +void BLE_Zwift_Service::applyGearRatio() { + if (_gearRatioX10000 == 0) return; + + // Zwift virtual gear ratios (24 gears, from 0.75 to 5.49) + static const uint32_t gearRatios[] = {7500, 8700, 9900, 11100, 12300, 13800, 15300, 16800, 18600, 20400, 22200, 24000, + 26100, 28200, 30300, 32400, 34900, 37400, 39900, 42400, 45400, 48400, 51400, 54900}; + // static const int kDefaultGearIndex = 11; // ratio 2.40 (≈ 34T/14T) + static const int kNumGears = sizeof(gearRatios) / sizeof(gearRatios[0]); + + // Find closest gear index + int closestIndex = 0; + uint32_t closestDist = 0xFFFFFFFFU; + for (int i = 0; i < kNumGears; i++) { + uint32_t dist = static_cast(abs(static_cast(_gearRatioX10000) - static_cast(gearRatios[i]))); + if (dist < closestDist) { + closestDist = dist; + closestIndex = i + 1; + } + } + + int newShifterPos = closestIndex; + rtConfig->setShifterPosition(newShifterPos); + // Also update lastShifterPosition so FTMSModeShiftModifier doesn't + // see this Zwift-driven change as a user shift and echo it back. + ss2k->setLastShifterPosition(newShifterPos); + SS2K_LOG(getLogTag(), "Gear %d -> shifter position %d", closestIndex + 1, newShifterPos); +} + +size_t BLE_Zwift_Service::decodeUleb128(const uint8_t* buf, size_t bufLen, uint64_t* result) { + *result = 0; + size_t i = 0; + unsigned shift = 0; + while (i < bufLen) { + uint8_t byte = buf[i]; + *result |= static_cast(byte & 0x7F) << shift; + i++; + if ((byte & 0x80) == 0) break; + shift += 7; + if (shift >= 64) break; // overflow protection + } + return i; +} + +size_t BLE_Zwift_Service::encodeUleb128(uint64_t value, uint8_t* buffer) { + size_t i = 0; + do { + uint8_t byte = static_cast(value & 0x7F); + value >>= 7; + if (value) byte |= 0x80; + buffer[i++] = byte; + } while (value); + return i; +} + +size_t BLE_Zwift_Service::encodeUleb128Len(uint64_t value) { + size_t len = 0; + do { + value >>= 7; + len++; + } while (value); + return len; +} + +// ---- Callbacks ---- + +void ZwiftSyncRxCallbacks::onWrite(NimBLECharacteristic* pCharacteristic, NimBLEConnInfo& connInfo) { + NimBLEAttValue value = pCharacteristic->getValue(); + // log the entire data recieved in 0x + std::string hexValue; + for (size_t i = 0; i < value.length(); i++) { + char buf[3]; + snprintf(buf, sizeof(buf), "%02X", value[i]); + hexValue.append(buf); + } + SS2K_LOG(zwiftService.getLogTag(), "Sync RX write from %s (len=%d) %s", connInfo.getAddress().toString().c_str(), value.length(), hexValue.c_str()); + zwiftService.handleSyncRxWrite(value); +} + +void ZwiftSyncRxCallbacks::onSubscribe(NimBLECharacteristic* pCharacteristic, NimBLEConnInfo& connInfo, uint16_t subValue) { + SS2K_LOG(zwiftService.getLogTag(), "Subscription change on %s: %d", pCharacteristic->getUUID().toString().c_str(), subValue); +} diff --git a/src/DirConManager.cpp b/src/DirConManager.cpp index 71d002b0..5d1c288a 100644 --- a/src/DirConManager.cpp +++ b/src/DirConManager.cpp @@ -8,7 +8,7 @@ #include "DirConManager.h" #include "SS2KLog.h" #include -#include +#include #define DIRCON_LOG_TAG "DirConManager" @@ -20,8 +20,10 @@ WiFiServer* DirConManager::tcpServer = nullptr; uint8_t DirConManager::receiveBuffer[DIRCON_MAX_CLIENTS][DIRCON_RECEIVE_BUFFER_SIZE]; size_t DirConManager::receiveBufferLength[DIRCON_MAX_CLIENTS] = {0}; uint8_t DirConManager::sendBuffer[DIRCON_SEND_BUFFER_SIZE]; -uint8_t DirConManager::lastSequenceNumber[DIRCON_MAX_CLIENTS] = {0}; -bool DirConManager::clientSubscriptions[DIRCON_MAX_CLIENTS][DIRCON_MAX_CHARACTERISTICS] = {false}; +uint8_t DirConManager::lastSequenceNumber[DIRCON_MAX_CLIENTS] = {0}; +Subscription DirConManager::clientSubscriptions[DIRCON_MAX_CLIENTS][DIRCON_MAX_CHARACTERISTICS]; +DirConManager::ServiceRegistration DirConManager::registeredServices[DIRCON_MAX_SERVICES] = {}; +size_t DirConManager::registeredServiceCount = 0; // Static buffer to store the list of UUIDs to avoid dynamic string allocations static char uuidListBuffer[128] = ""; @@ -34,7 +36,7 @@ bool DirConManager::start() { receiveBufferLength[i] = 0; lastSequenceNumber[i] = 0; for (int j = 0; j < DIRCON_MAX_CHARACTERISTICS; j++) { - clientSubscriptions[i][j] = false; + clientSubscriptions[i][j].active = false; } } @@ -51,6 +53,13 @@ bool DirConManager::start() { tcpServer->begin(); started = true; + + // Registered services have been stored before DirCon starts. + // Now that we're started, publish them to MDNS. + for (size_t i = 0; i < registeredServiceCount; i++) { + addBleServiceUuid(registeredServices[i].serviceUuid); + } + updateStatusMessage(); SS2K_LOG(DIRCON_LOG_TAG, "%s", statusMessage.c_str()); return true; @@ -98,7 +107,7 @@ void DirConManager::update() { handleClientData(); } -// returns true if we have clients connected +// returns the number of connected clients int DirConManager::connectedClients() { int connectedClients = 0; for (int i = 0; i < DIRCON_MAX_CLIENTS; i++) { @@ -108,6 +117,7 @@ int DirConManager::connectedClients() { } return connectedClients; } + void DirConManager::updateStatusMessage() { if (!started) { statusMessage = "DirCon service stopped"; @@ -152,6 +162,23 @@ void DirConManager::setupMDNS() { SS2K_LOG(DIRCON_LOG_TAG, "DirCon MDNS service setup complete"); } + +void DirConManager::registerService(const NimBLEUUID& serviceUuid, DirConWriteHandler writeHandler) { + if (registeredServiceCount >= DIRCON_MAX_SERVICES) { + SS2K_LOG(DIRCON_LOG_TAG, "Warning: Cannot register service, max services (%d) reached", DIRCON_MAX_SERVICES); + return; + } + + registeredServices[registeredServiceCount].serviceUuid = serviceUuid; + registeredServices[registeredServiceCount].writeHandler = writeHandler; + registeredServiceCount++; + + SS2K_LOG(DIRCON_LOG_TAG, "Registered service %s (write handler: %s)", serviceUuid.toString().c_str(), writeHandler ? "yes" : "no"); + + // If DirCon is already started, publish to MDNS immediately + addBleServiceUuid(serviceUuid); +} + void DirConManager::addBleServiceUuid(const NimBLEUUID& serviceUuid) { if (!started) { return; @@ -166,7 +193,6 @@ void DirConManager::addBleServiceUuid(const NimBLEUUID& serviceUuid) { // Check if UUID is already in the list if (strstr(uuidListBuffer, shortUuid) != nullptr) { - // UUID already added return; } @@ -219,7 +245,7 @@ void DirConManager::checkForNewClients() { receiveBufferLength[i] = 0; lastSequenceNumber[i] = 0; for (int j = 0; j < DIRCON_MAX_CHARACTERISTICS; j++) { - clientSubscriptions[i][j] = false; + clientSubscriptions[i][j].active = false; } break; @@ -307,40 +333,32 @@ bool DirConManager::processDirConMessage(DirConMessage* message, size_t clientIn switch (message->Identifier) { case DIRCON_MSGID_DISCOVER_SERVICES: { - // Handle service discovery response.Identifier = DIRCON_MSGID_DISCOVER_SERVICES; response.ResponseCode = DIRCON_RESPCODE_SUCCESS_REQUEST; - // Get all service UUIDs - std::vector services = getAvailableServices(); - for (NimBLEUUID& service : services) { - // Add each service UUID to the response - response.AdditionalUUIDs.push_back(service); + // Get all registered service UUIDs + for (size_t i = 0; i < registeredServiceCount; i++) { + response.AdditionalUUIDs.push_back(registeredServices[i].serviceUuid); } - // Log discovery request details SS2K_LOG(DIRCON_LOG_TAG, "Received service discovery request from client %d", clientIndex); - SS2K_LOG(DIRCON_LOG_TAG, "Responding with %d service UUIDs", services.size()); + SS2K_LOG(DIRCON_LOG_TAG, "Responding with %d service UUIDs", registeredServiceCount); - // Send the response sendResponse(&response, clientIndex); break; } case DIRCON_MSGID_DISCOVER_CHARACTERISTICS: { - // Handle characteristic discovery for a service response.Identifier = DIRCON_MSGID_DISCOVER_CHARACTERISTICS; response.ResponseCode = DIRCON_RESPCODE_SUCCESS_REQUEST; response.UUID = message->UUID; - // Get BLE service NimBLEService* service = NimBLEDevice::getServer()->getServiceByUUID(message->UUID); if (service == nullptr) { sendErrorResponse(DIRCON_MSGID_DISCOVER_CHARACTERISTICS, message->SequenceNumber, DIRCON_RESPCODE_SERVICE_NOT_FOUND, clientIndex); return false; } - // Get all characteristics for the service std::vector characteristics = service->getCharacteristics(); for (NimBLECharacteristic* characteristic : characteristics) { if (characteristic != nullptr) { @@ -357,29 +375,23 @@ bool DirConManager::processDirConMessage(DirConMessage* message, size_t clientIn } case DIRCON_MSGID_READ_CHARACTERISTIC: { - // Handle characteristic read response.Identifier = DIRCON_MSGID_READ_CHARACTERISTIC; response.ResponseCode = DIRCON_RESPCODE_SUCCESS_REQUEST; response.UUID = message->UUID; - // Use the helper function to find the characteristic NimBLECharacteristic* characteristic = findCharacteristic(message->UUID); - if (characteristic == nullptr) { sendErrorResponse(DIRCON_MSGID_READ_CHARACTERISTIC, message->SequenceNumber, DIRCON_RESPCODE_CHARACTERISTIC_NOT_FOUND, clientIndex); return false; } - // Check if read is allowed based on properties if (!(characteristic->getProperties() & NIMBLE_PROPERTY::READ)) { sendErrorResponse(DIRCON_MSGID_READ_CHARACTERISTIC, message->SequenceNumber, DIRCON_RESPCODE_CHARACTERISTIC_OPERATION_NOT_SUPPORTED, clientIndex); return false; } - // Read the value NimBLEAttValue value = characteristic->getValue(); size_t length = value.size(); - for (size_t i = 0; i < length; i++) { response.AdditionalData.push_back(value[i]); } @@ -389,24 +401,19 @@ bool DirConManager::processDirConMessage(DirConMessage* message, size_t clientIn } case DIRCON_MSGID_WRITE_CHARACTERISTIC: { - // Handle characteristic write response.Identifier = DIRCON_MSGID_WRITE_CHARACTERISTIC; response.ResponseCode = DIRCON_RESPCODE_SUCCESS_REQUEST; response.UUID = message->UUID; - // Use the helper function to find the characteristic NimBLECharacteristic* characteristic = findCharacteristic(message->UUID); - if (characteristic == nullptr) { sendErrorResponse(DIRCON_MSGID_WRITE_CHARACTERISTIC, message->SequenceNumber, DIRCON_RESPCODE_CHARACTERISTIC_NOT_FOUND, clientIndex); SS2K_LOG(DIRCON_LOG_TAG, "Write characteristic failed: characteristic %s not found", message->UUID.toString().c_str()); return false; } - // Check if write is allowed based on properties - if (!(characteristic->getProperties() & NIMBLE_PROPERTY::WRITE)) { + if (!(characteristic->getProperties() & (NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::WRITE_NR))) { sendErrorResponse(DIRCON_MSGID_WRITE_CHARACTERISTIC, message->SequenceNumber, DIRCON_RESPCODE_CHARACTERISTIC_OPERATION_NOT_SUPPORTED, clientIndex); - // log which characteristic failed SS2K_LOG(DIRCON_LOG_TAG, "Write operation not supported for characteristic %s", characteristic->getUUID().toString().c_str()); return false; } @@ -414,11 +421,22 @@ bool DirConManager::processDirConMessage(DirConMessage* message, size_t clientIn // Write the value (setValue doesn't return a status in NimBLE) characteristic->setValue(message->AdditionalData.data(), message->AdditionalData.size()); - // handle FTMS control Point Writes - if (characteristic->getUUID().equals(FITNESSMACHINECONTROLPOINT_UUID)) { - spinBLEServer.writeCache.push(characteristic->getValue()); - fitnessMachineService.processFTMSWrite(); - response.AdditionalData = characteristic->getValue(); + // Let registered services handle the write via callbacks + for (size_t i = 0; i < registeredServiceCount; i++) { + if (registeredServices[i].writeHandler != nullptr) { + DirConWriteResult writeResult; + if (registeredServices[i].writeHandler(characteristic, message->AdditionalData.data(), message->AdditionalData.size(), &writeResult)) { + if (writeResult.updateResponseData) { + response.AdditionalData = characteristic->getValue(); + } + for (size_t s = 0; s < writeResult.autoSubscribeCount; s++) { + if (!hasSubscription(clientIndex, writeResult.autoSubscribeUuids[s])) { + addSubscription(clientIndex, writeResult.autoSubscribeUuids[s]); + } + } + break; + } + } } sendResponse(&response, clientIndex); @@ -426,34 +444,28 @@ bool DirConManager::processDirConMessage(DirConMessage* message, size_t clientIn } case DIRCON_MSGID_ENABLE_CHARACTERISTIC_NOTIFICATIONS: { - // Handle notification subscription response.Identifier = DIRCON_MSGID_ENABLE_CHARACTERISTIC_NOTIFICATIONS; response.ResponseCode = DIRCON_RESPCODE_SUCCESS_REQUEST; response.UUID = message->UUID; - // Use the helper function to find the characteristic NimBLECharacteristic* characteristic = findCharacteristic(message->UUID); - if (characteristic == nullptr) { sendErrorResponse(DIRCON_MSGID_ENABLE_CHARACTERISTIC_NOTIFICATIONS, message->SequenceNumber, DIRCON_RESPCODE_CHARACTERISTIC_NOT_FOUND, clientIndex); SS2K_LOG(DIRCON_LOG_TAG, "Enable notifications failed: characteristic %s not found", message->UUID.toString().c_str()); return false; } - // Check if notifications are allowed based on properties - if (!(characteristic->getProperties() & NIMBLE_PROPERTY::NOTIFY)) { + if (!(characteristic->getProperties() & (NIMBLE_PROPERTY::NOTIFY | NIMBLE_PROPERTY::INDICATE))) { sendErrorResponse(DIRCON_MSGID_ENABLE_CHARACTERISTIC_NOTIFICATIONS, message->SequenceNumber, DIRCON_RESPCODE_CHARACTERISTIC_OPERATION_NOT_SUPPORTED, clientIndex); SS2K_LOG(DIRCON_LOG_TAG, "Notifications not supported for characteristic %s", characteristic->getUUID().toString().c_str()); return false; } - // Get enable/disable flag bool enableNotifications = false; if (message->AdditionalData.size() > 0) { enableNotifications = message->AdditionalData[0] != 0; } - // Update subscription if (enableNotifications) { addSubscription(clientIndex, message->UUID); } else { @@ -465,7 +477,6 @@ bool DirConManager::processDirConMessage(DirConMessage* message, size_t clientIn } default: - // Unknown message type sendErrorResponse(message->Identifier, message->SequenceNumber, DIRCON_RESPCODE_UNKNOWN_MESSAGE_TYPE, clientIndex); success = false; break; @@ -489,10 +500,8 @@ void DirConManager::sendResponse(DirConMessage* message, size_t clientIndex) { return; } - // Log the message type being sent SS2K_LOG(DIRCON_LOG_TAG, "Sending response message type 0x%02X to client %d", message->Identifier, clientIndex); - // For discover services, log additional details if (message->Identifier == DIRCON_MSGID_DISCOVER_SERVICES) { SS2K_LOG(DIRCON_LOG_TAG, "Discover services response contains %d UUIDs", message->AdditionalUUIDs.size()); for (size_t i = 0; i < message->AdditionalUUIDs.size(); i++) { @@ -502,99 +511,66 @@ void DirConManager::sendResponse(DirConMessage* message, size_t clientIndex) { std::vector* encodedMessage = message->encode(lastSequenceNumber[clientIndex]); if (encodedMessage != nullptr && encodedMessage->size() > 0) { - // SS2K_LOG(DIRCON_LOG_TAG, "Sending %d bytes to client %d", encodedMessage->size(), clientIndex); dirConClients[clientIndex].write(encodedMessage->data(), encodedMessage->size()); } else { SS2K_LOG(DIRCON_LOG_TAG, "Error: No encoded message to send"); } } -void DirConManager::notifyCharacteristic(const NimBLEUUID& serviceUuid, const NimBLEUUID& characteristicUuid, uint8_t* data, size_t length) { +void DirConManager::notifyCharacteristic(const NimBLEUUID& serviceUuid, const NimBLEUUID& characteristicUuid, uint8_t* data, size_t length, bool onlySubscribers) { if (!started || !connectedClients()) { return; } - // We can skip the service lookup since we're only validating that the characteristic exists - // and we'll directly broadcast to all clients anyway if (findCharacteristic(characteristicUuid) == nullptr) { return; } - // Send notifications to subscribed clients - broadcastNotification(characteristicUuid, data, length); + broadcastNotification(characteristicUuid, data, length, onlySubscribers); } -void DirConManager::broadcastNotification(const NimBLEUUID& characteristicUuid, uint8_t* data, size_t length) { - // Create a single notification message that will be reused for all clients - static DirConMessage notification; // Static to avoid repeated heap allocations +static SemaphoreHandle_t s_notifyMutex = xSemaphoreCreateMutex(); + +void DirConManager::broadcastNotification(const NimBLEUUID& characteristicUuid, uint8_t* data, size_t length, bool onlySubscribers) { + DirConMessage notification; // stack-allocated, safe per-call - // Initialize the notification once notification.Request = false; notification.Identifier = DIRCON_MSGID_UNSOLICITED_CHARACTERISTIC_NOTIFICATION; notification.UUID = characteristicUuid; - // Copy notification data (only done once) notification.AdditionalData.clear(); - notification.AdditionalData.reserve(length); // Pre-allocate space to avoid reallocations + notification.AdditionalData.reserve(length); for (size_t j = 0; j < length; j++) { notification.AdditionalData.push_back(data[j]); } - // Encode the message once std::vector* encodedMessage = notification.encode(0); if (encodedMessage == nullptr || encodedMessage->size() == 0) { - return; // Nothing to send + return; + } + + // Grab mutex before touching the TCP client + if (xSemaphoreTake(s_notifyMutex, pdMS_TO_TICKS(10)) != pdTRUE) { + SS2K_LOG(DIRCON_LOG_TAG, "broadcastNotification: failed to acquire mutex, dropping notification"); + return; } - // Send to all connected clients for (int i = 0; i < DIRCON_MAX_CLIENTS; i++) { - if (!dirConClients[i].connected() || !hasSubscription(i, characteristicUuid)) { + if (!dirConClients[i].connected() || (onlySubscribers && !hasSubscription(i, characteristicUuid))) { continue; } #ifdef DEBUG_DIRCON_MESSAGES - bool sentDebug = false; - // Print the outgoing raw message bytes to serial - if (!sentDebug) DirConMessage::printVectorBytesToSerial(*encodedMessage, false); - sentDebug = true; + DirConMessage::printVectorBytesToSerial(*encodedMessage, false); #endif dirConClients[i].write(encodedMessage->data(), encodedMessage->size()); } -} - -// Static variable to hold the available services (initialized once) -static std::vector cachedServices; -static bool servicesInitialized = false; - -std::vector DirConManager::getAvailableServices() { - // Initialize the services list only once - if (!servicesInitialized) { - cachedServices.clear(); - - // Add each service with descriptive name for better debugging - NimBLEUUID cyclingPowerUuid = NimBLEUUID(CYCLINGPOWERSERVICE_UUID); - cachedServices.push_back(cyclingPowerUuid); - - NimBLEUUID cscUuid = NimBLEUUID(CSCSERVICE_UUID); - cachedServices.push_back(cscUuid); - - NimBLEUUID heartUuid = NimBLEUUID(HEARTSERVICE_UUID); - cachedServices.push_back(heartUuid); - - NimBLEUUID ftmsUuid = NimBLEUUID(FITNESSMACHINESERVICE_UUID); - cachedServices.push_back(ftmsUuid); - - // Log summary - SS2K_LOG(DIRCON_LOG_TAG, "Initialized service discovery with %d services", cachedServices.size()); - servicesInitialized = true; - } - return cachedServices; + xSemaphoreGive(s_notifyMutex); } std::vector DirConManager::getCharacteristics(const NimBLEUUID& serviceUuid) { std::vector characteristics; - // Get the service NimBLEService* service = NimBLEDevice::getServer()->getServiceByUUID(serviceUuid); if (service == nullptr) { return characteristics; @@ -604,27 +580,7 @@ std::vector DirConManager::getCharacteristics(const NimBL characteristics.push_back(const_cast(characteristic)); } } - // Find service-specific characteristics based on known UUIDs - /*if (serviceUuid.equals(CYCLINGPOWERSERVICE_UUID)) { - characteristics.push_back(service->getCharacteristic(CYCLINGPOWERMEASUREMENT_UUID)); - characteristics.push_back(service->getCharacteristic(CYCLINGPOWERFEATURE_UUID)); - characteristics.push_back(service->getCharacteristic(SENSORLOCATION_UUID)); - } else if (serviceUuid.equals(CSCSERVICE_UUID)) { - characteristics.push_back(service->getCharacteristic(CSCMEASUREMENT_UUID)); - } else if (serviceUuid.equals(HEARTSERVICE_UUID)) { - characteristics.push_back(service->getCharacteristic(HEARTCHARACTERISTIC_UUID)); - } else if (serviceUuid.equals(FITNESSMACHINESERVICE_UUID)) { - characteristics.push_back(service->getCharacteristic(FITNESSMACHINEINDOORBIKEDATA_UUID)); - characteristics.push_back(service->getCharacteristic(FITNESSMACHINEFEATURE_UUID)); - characteristics.push_back(service->getCharacteristic(FITNESSMACHINECONTROLPOINT_UUID)); - characteristics.push_back(service->getCharacteristic(FITNESSMACHINESTATUS_UUID)); - } else if (serviceUuid.equals(DEVICE_INFORMATION_SERVICE_UUID)) { - // Add device info characteristics if needed - } else if (serviceUuid.equals(WATTBIKE_SERVICE_UUID)) { - // Add wattbike service characteristics - } -*/ - // Filter out null characteristics + auto it = std::remove_if(characteristics.begin(), characteristics.end(), [](NimBLECharacteristic* c) { return c == nullptr; }); characteristics.erase(it, characteristics.end()); @@ -632,12 +588,8 @@ std::vector DirConManager::getCharacteristics(const NimBL } NimBLECharacteristic* DirConManager::findCharacteristic(const NimBLEUUID& characteristicUuid) { - // Get cached services (doesn't allocate new memory) - const std::vector& services = getAvailableServices(); - - // Search through each service for the characteristic - for (const NimBLEUUID& serviceUuid : services) { - NimBLEService* service = NimBLEDevice::getServer()->getServiceByUUID(serviceUuid); + for (size_t i = 0; i < registeredServiceCount; i++) { + NimBLEService* service = NimBLEDevice::getServer()->getServiceByUUID(registeredServices[i].serviceUuid); if (service != nullptr) { NimBLECharacteristic* characteristic = service->getCharacteristic(characteristicUuid); if (characteristic != nullptr) { @@ -645,7 +597,6 @@ NimBLECharacteristic* DirConManager::findCharacteristic(const NimBLEUUID& charac } } } - return nullptr; } @@ -655,51 +606,61 @@ uint8_t DirConManager::getDirConProperties(uint32_t characteristicProperties) { if (characteristicProperties & NIMBLE_PROPERTY::READ) { properties |= DIRCON_CHAR_PROP_FLAG_READ; } - - if (characteristicProperties & NIMBLE_PROPERTY::WRITE) { + if (characteristicProperties & (NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::WRITE_NR)) { properties |= DIRCON_CHAR_PROP_FLAG_WRITE; } - if (characteristicProperties & NIMBLE_PROPERTY::NOTIFY) { properties |= DIRCON_CHAR_PROP_FLAG_NOTIFY; } - - return properties; -} - -size_t DirConManager::charSubscriptionIndex(const NimBLEUUID& characteristicUuid) { - // Simple hash function to get an index for the characteristic - // In a real implementation, this would be a proper data structure - std::string uuidStr = characteristicUuid.toString(); - uint32_t hash = 0; - - for (char c : uuidStr) { - hash = ((hash << 5) + hash) + c; + // DirCon protocol doesn't define a separate INDICATE flag; + // map INDICATE to NOTIFY so clients can subscribe to indicated characteristics + if (characteristicProperties & NIMBLE_PROPERTY::INDICATE) { + properties |= DIRCON_CHAR_PROP_FLAG_NOTIFY; } - return hash % DIRCON_MAX_CHARACTERISTICS; + return properties; } void DirConManager::addSubscription(size_t clientIndex, const NimBLEUUID& characteristicUuid) { - size_t index = charSubscriptionIndex(characteristicUuid); - clientSubscriptions[clientIndex][index] = true; - SS2K_LOG(DIRCON_LOG_TAG, "Client %d subscribed to characteristic %s", clientIndex, characteristicUuid.toString().c_str()); + for (int j = 0; j < DIRCON_MAX_CHARACTERISTICS; j++) { + if (clientSubscriptions[clientIndex][j].active && + clientSubscriptions[clientIndex][j].uuid == characteristicUuid) { + return; // already subscribed + } + if (!clientSubscriptions[clientIndex][j].active) { + clientSubscriptions[clientIndex][j].uuid = characteristicUuid; + clientSubscriptions[clientIndex][j].active = true; + SS2K_LOG(DIRCON_LOG_TAG, "Client %d subscribed to characteristic %s", clientIndex, characteristicUuid.toString().c_str()); + return; + } + } + SS2K_LOG(DIRCON_LOG_TAG, "Warning: no free subscription slot for client %d", clientIndex); } void DirConManager::removeSubscription(size_t clientIndex, const NimBLEUUID& characteristicUuid) { - size_t index = charSubscriptionIndex(characteristicUuid); - clientSubscriptions[clientIndex][index] = false; - SS2K_LOG(DIRCON_LOG_TAG, "Client %d unsubscribed from characteristic %s", clientIndex, characteristicUuid.toString().c_str()); + for (int j = 0; j < DIRCON_MAX_CHARACTERISTICS; j++) { + if (clientSubscriptions[clientIndex][j].active && + clientSubscriptions[clientIndex][j].uuid == characteristicUuid) { + clientSubscriptions[clientIndex][j].active = false; + SS2K_LOG(DIRCON_LOG_TAG, "Client %d unsubscribed from characteristic %s", clientIndex, characteristicUuid.toString().c_str()); + return; + } + } } void DirConManager::removeAllSubscriptions(size_t clientIndex) { - for (int i = 0; i < DIRCON_MAX_CHARACTERISTICS; i++) { - clientSubscriptions[clientIndex][i] = false; + for (int j = 0; j < DIRCON_MAX_CHARACTERISTICS; j++) { + clientSubscriptions[clientIndex][j].active = false; } SS2K_LOG(DIRCON_LOG_TAG, "Removed all subscriptions for client %d", clientIndex); } bool DirConManager::hasSubscription(size_t clientIndex, const NimBLEUUID& characteristicUuid) { - size_t index = charSubscriptionIndex(characteristicUuid); - return clientSubscriptions[clientIndex][index]; -} + for (int j = 0; j < DIRCON_MAX_CHARACTERISTICS; j++) { + if (clientSubscriptions[clientIndex][j].active && + clientSubscriptions[clientIndex][j].uuid == characteristicUuid) { + return true; + } + } + return false; +} \ No newline at end of file diff --git a/src/DirConMessage.cpp b/src/DirConMessage.cpp index d01e6fdc..0ab10075 100644 --- a/src/DirConMessage.cpp +++ b/src/DirConMessage.cpp @@ -320,7 +320,12 @@ size_t DirConMessage::parse(uint8_t* data, size_t len, uint8_t sequenceNumber) { break; default: - SS2K_LOG(DIRCON_LOG_TAG, "Error parsing DirCon message: Unknown identifier %d", this->Identifier); + char hexBuf[len * 3 + 1]; + for (size_t i = 0; i < len; i++) { + snprintf(hexBuf + i * 3, 4, "%02X ", data[i]); + } + hexBuf[len * 3] = '\0'; + SS2K_LOG(DIRCON_LOG_TAG, "Error parsing DirCon message: Unknown identifier %d. Full message (%d bytes): %s", this->Identifier, len, hexBuf); this->Identifier = DIRCON_MSGID_ERROR; return 0; break; diff --git a/src/Main.cpp b/src/Main.cpp index e55d4cac..54027fa7 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -24,6 +24,7 @@ #include "settings.h" // #include "BLE_Wattbike_Service.h" #include "BLE_Fitness_Machine_Service.h" +#include "BLE_Zwift_Service.h" #include "DirConManager.h" // Stepper Motor Serial @@ -339,6 +340,22 @@ void SS2K::maintenanceLoop(void* pvParameters) { void SS2K::FTMSModeShiftModifier() { int shiftDelta = rtConfig->getShifterPosition() - ss2k->lastShifterPosition; if (shiftDelta) { // Shift detected + // When Zwift virtual shifting is active, forward shifts to Zwift + // instead of handling them internally. Zwift sends gear changes + // back via the custom trainer protocol which we already handle. + // This needs to be moved so shift blocking/knob crashing prevention is enforced. + // Keeping here for now for development/testing purposes + + if (zwiftService.isConnected()) { + int absDelta = abs(shiftDelta); + for (int i = 0; i < absDelta; i++) { + if (shiftDelta > 0) { + zwiftService.sendShiftUp(); + } else { + zwiftService.sendShiftDown(); + } + } + } switch (rtConfig->getFTMSMode()) { case FitnessMachineControlPointProcedure::SetTargetPower: // ERG Mode { diff --git a/src/SS2KLog.cpp b/src/SS2KLog.cpp index bc83c437..4150c6f5 100644 --- a/src/SS2KLog.cpp +++ b/src/SS2KLog.cpp @@ -7,6 +7,7 @@ #include "SS2KLog.h" #include "Main.h" +#include LogHandler logHandler = LogHandler(); @@ -56,18 +57,27 @@ void LogHandler::writev(esp_log_level_t level, const char *module, const char *f } char formatString[256]; - sprintf(formatString, "[%6lu][%c](%s): %s", millis(), _logLevelToLetter(level), module, format); + snprintf(formatString, sizeof(formatString), "[%6lu][%c](%s): %s", millis(), _logLevelToLetter(level), module, format); const size_t buffer_size = 512; char buffer[buffer_size]; int written = vsnprintf(buffer, buffer_size, formatString, args); + if (written < 0) { + buffer[0] = '\0'; + written = 0; + } + + size_t bytesToSend = static_cast(written); + if (bytesToSend >= buffer_size) { + bytesToSend = buffer_size - 1; + } // Default logger -> write all to serial if connected if (Serial) { Serial.println(buffer); } - xMessageBufferSend(_messageBufferHandle, buffer, written, 0); + xMessageBufferSend(_messageBufferHandle, buffer, bytesToSend, 0); xSemaphoreGive(_logBufferMutex); } @@ -94,22 +104,45 @@ void ss2k_remove_newlines(std::string *str) { } } -int ss2k_log_hex_to_buffer(const byte *data, const size_t data_length, char *buffer, const int buffer_offset, const size_t buffer_length) { - int written = 0; - for (int data_offset = 0; data_offset < data_length; data_offset++) { - written += snprintf(buffer + buffer_offset + written, buffer_length - written + buffer_offset, "%02x ", *(data + data_offset)); +template +std::string toHexString(const T *data, size_t dataLength) { + static_assert(std::is_same::value || std::is_same::value, "toHexString only supports uint8_t and char data"); + + std::string result; + if (data == nullptr || dataLength == 0) { + return result; } - return written; + + result.reserve((dataLength * 3) - 1); + char byteBuffer[4]; + for (size_t index = 0; index < dataLength; ++index) { + snprintf(byteBuffer, sizeof(byteBuffer), "%02x", static_cast(data[index])); + result += byteBuffer; + if (index + 1 < dataLength) { + result += ' '; + } + } + + return result; } -int ss2k_log_hex_to_buffer(const char *data, const size_t data_length, char *buffer, const int buffer_offset, const size_t buffer_length) { +template std::string toHexString(const uint8_t *data, size_t dataLength); +template std::string toHexString(const char *data, size_t dataLength); + +template +int ss2k_log_hex_to_buffer(const T *data, const size_t data_length, char *buffer, const int buffer_offset, const size_t buffer_length) { + static_assert(std::is_same::value || std::is_same::value, "ss2k_log_hex_to_buffer only supports byte and char data"); + int written = 0; for (int data_offset = 0; data_offset < data_length; data_offset++) { - written += snprintf(buffer + buffer_offset + written, buffer_length - written + buffer_offset, "%02x ", *(data + data_offset)); + written += snprintf(buffer + buffer_offset + written, buffer_length - written + buffer_offset, "%02x ", static_cast(*(data + data_offset))); } return written; } +template int ss2k_log_hex_to_buffer(const byte *data, const size_t data_length, char *buffer, const int buffer_offset, const size_t buffer_length); +template int ss2k_log_hex_to_buffer(const char *data, const size_t data_length, char *buffer, const int buffer_offset, const size_t buffer_length); + void ss2k_log_write(esp_log_level_t level, const char *module, const char *format, ...) { va_list args; va_start(args, format);