aboutsummaryrefslogtreecommitdiffstats
path: root/src/components
diff options
context:
space:
mode:
authorDāvis Mošenkovs <davikovs@gmail.com>2025-09-03 21:50:13 +0300
committerGitHub <noreply@github.com>2025-09-03 20:50:13 +0200
commite03414ce6d96c3acdc6bb56be59c50fb6a1721fc (patch)
treefb36f10fc657c821d1bdb4fd4476a1f41f71d179 /src/components
parent9afc23cba9bcf938d8c49d6e15e7662ee8e6385d (diff)
Setting to disable DFU and FS access (#1891)
* Expose SystemTask dependency controllers Expose NotificationManager and Settings for use by the feature in next commit. This is a memory efficient way for accessing SystemTask dependencies from controllers that have SystemTask injected as a dependency. Looks like each direct dependency injection uses 4 bytes RAM. As InfiniTime is close to running out of RAM (using 16 more bytes causes build to fail with "ld: region RAM overflowed with stack") it might be helpful to use this approach more. * Add setting to disable DFU and FS access
Diffstat (limited to 'src/components')
-rw-r--r--src/components/ble/DfuService.cpp14
-rw-r--r--src/components/ble/DfuService.h5
-rw-r--r--src/components/ble/FSService.cpp14
-rw-r--r--src/components/ble/FSService.h6
-rw-r--r--src/components/settings/Settings.h28
5 files changed, 67 insertions, 0 deletions
diff --git a/src/components/ble/DfuService.cpp b/src/components/ble/DfuService.cpp
index 2427513d..ad9c99e9 100644
--- a/src/components/ble/DfuService.cpp
+++ b/src/components/ble/DfuService.cpp
@@ -1,6 +1,8 @@
#include "components/ble/DfuService.h"
#include <cstring>
#include "components/ble/BleController.h"
+#include "components/ble/NotificationManager.h"
+#include "components/settings/Settings.h"
#include "drivers/SpiNorFlash.h"
#include "systemtask/SystemTask.h"
#include <nrf_log.h>
@@ -78,6 +80,18 @@ void DfuService::Init() {
}
int DfuService::OnServiceData(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context) {
+#ifndef PINETIME_IS_RECOVERY
+ if (systemTask.GetSettings().GetDfuAndFsMode() == Pinetime::Controllers::Settings::DfuAndFsMode::Disabled) {
+ Pinetime::Controllers::NotificationManager::Notification notif;
+ memcpy(notif.message.data(), denyAlert, denyAlertLength);
+ notif.size = denyAlertLength;
+ notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
+ systemTask.GetNotificationManager().Push(std::move(notif));
+ systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
+ return BLE_ATT_ERR_INSUFFICIENT_AUTHOR;
+ }
+#endif
+
if (bleController.IsFirmwareUpdating()) {
xTimerStart(timeoutTimer, 0);
}
diff --git a/src/components/ble/DfuService.h b/src/components/ble/DfuService.h
index 6652cdc1..99be27b9 100644
--- a/src/components/ble/DfuService.h
+++ b/src/components/ble/DfuService.h
@@ -20,6 +20,8 @@ namespace Pinetime {
namespace Controllers {
class Ble;
+ class Settings;
+ class NotificationManager;
class DfuService {
public:
@@ -87,6 +89,9 @@ namespace Pinetime {
DfuImage dfuImage;
NotificationManager notificationManager;
+ static constexpr const char denyAlert[] = "InfiniTime\0Firmware update attempted, but disabled in settings.";
+ static constexpr const uint8_t denyAlertLength = sizeof(denyAlert); // for this to work denyAlert MUST be array
+
static constexpr uint16_t dfuServiceId {0x1530};
static constexpr uint16_t packetCharacteristicId {0x1532};
static constexpr uint16_t controlPointCharacteristicId {0x1531};
diff --git a/src/components/ble/FSService.cpp b/src/components/ble/FSService.cpp
index fda6b392..721ed297 100644
--- a/src/components/ble/FSService.cpp
+++ b/src/components/ble/FSService.cpp
@@ -1,6 +1,8 @@
#include <nrf_log.h>
#include "FSService.h"
#include "components/ble/BleController.h"
+#include "components/ble/NotificationManager.h"
+#include "components/settings/Settings.h"
#include "systemtask/SystemTask.h"
using namespace Pinetime::Controllers;
@@ -49,6 +51,18 @@ void FSService::Init() {
}
int FSService::OnFSServiceRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context) {
+#ifndef PINETIME_IS_RECOVERY
+ if (systemTask.GetSettings().GetDfuAndFsMode() == Pinetime::Controllers::Settings::DfuAndFsMode::Disabled) {
+ Pinetime::Controllers::NotificationManager::Notification notif;
+ memcpy(notif.message.data(), denyAlert, denyAlertLength);
+ notif.size = denyAlertLength;
+ notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
+ systemTask.GetNotificationManager().Push(std::move(notif));
+ systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
+ return BLE_ATT_ERR_INSUFFICIENT_AUTHOR;
+ }
+#endif
+
if (attributeHandle == versionCharacteristicHandle) {
NRF_LOG_INFO("FS_S : handle = %d", versionCharacteristicHandle);
int res = os_mbuf_append(context->om, &fsVersion, sizeof(fsVersion));
diff --git a/src/components/ble/FSService.h b/src/components/ble/FSService.h
index b2299623..b43bc9e4 100644
--- a/src/components/ble/FSService.h
+++ b/src/components/ble/FSService.h
@@ -14,6 +14,8 @@ namespace Pinetime {
namespace Controllers {
class Ble;
+ class Settings;
+ class NotificationManager;
class FSService {
public:
@@ -26,6 +28,10 @@ namespace Pinetime {
private:
Pinetime::System::SystemTask& systemTask;
Pinetime::Controllers::FS& fs;
+
+ static constexpr const char denyAlert[] = "InfiniTime\0File access attempted, but disabled in settings.";
+ static constexpr const uint8_t denyAlertLength = sizeof(denyAlert); // for this to work denyAlert MUST be array
+
static constexpr uint16_t FSServiceId {0xFEBB};
static constexpr uint16_t fsVersionId {0x0100};
static constexpr uint16_t fsTransferId {0x0200};
diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h
index c9615126..093a3ac6 100644
--- a/src/components/settings/Settings.h
+++ b/src/components/settings/Settings.h
@@ -4,6 +4,7 @@
#include "components/brightness/BrightnessController.h"
#include "components/fs/FS.h"
#include "displayapp/apps/Apps.h"
+#include <nrf_log.h>
namespace Pinetime {
namespace Controllers {
@@ -37,6 +38,7 @@ namespace Pinetime {
enum class PTSGaugeStyle : uint8_t { Full, Half, Numeric };
enum class PTSWeather : uint8_t { On, Off };
enum class PrideFlag : uint8_t { Gay, Trans, Bi, Lesbian };
+ enum class DfuAndFsMode : uint8_t { Disabled, Enabled, EnabledTillReboot };
struct PineTimeStyle {
Colors ColorTime = Colors::Teal;
@@ -309,6 +311,29 @@ namespace Pinetime {
return bleRadioEnabled;
};
+ void SetDfuAndFsMode(DfuAndFsMode mode) {
+ if (mode == GetDfuAndFsMode()) {
+ return;
+ }
+ if (mode == DfuAndFsMode::Enabled || GetDfuAndFsMode() == DfuAndFsMode::Enabled) {
+ settingsChanged = true;
+ }
+ settings.dfuAndFsEnabledOnBoot = (mode == DfuAndFsMode::Enabled);
+ dfuAndFsEnabledTillReboot = (mode == DfuAndFsMode::EnabledTillReboot);
+ };
+
+ DfuAndFsMode GetDfuAndFsMode() {
+ if (dfuAndFsEnabledTillReboot) {
+ if (settings.dfuAndFsEnabledOnBoot) { // ensure both variables are in consistent state
+ settingsChanged = true;
+ settings.dfuAndFsEnabledOnBoot = false;
+ NRF_LOG_ERROR("Settings: DfuAndFsMode data corrupted");
+ }
+ return DfuAndFsMode::EnabledTillReboot;
+ }
+ return (settings.dfuAndFsEnabledOnBoot ? DfuAndFsMode::Enabled : DfuAndFsMode::Disabled);
+ };
+
private:
Pinetime::Controllers::FS& fs;
@@ -338,6 +363,8 @@ namespace Pinetime {
uint16_t shakeWakeThreshold = 150;
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
+
+ bool dfuAndFsEnabledOnBoot = false;
};
SettingsData settings;
@@ -350,6 +377,7 @@ namespace Pinetime {
* to off (false) on every boot because we always want ble to be enabled on startup
*/
bool bleRadioEnabled = true;
+ bool dfuAndFsEnabledTillReboot = false;
void LoadSettingsFromFile();
void SaveSettingsToFile();