Skip to content

Commit f64f882

Browse files
committed
Add setting to disable DFU and FS access
1 parent b2e2690 commit f64f882

14 files changed

Lines changed: 152 additions & 2 deletions

File tree

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ list(APPEND SOURCE_FILES
418418
displayapp/screens/settings/SettingChimes.cpp
419419
displayapp/screens/settings/SettingShakeThreshold.cpp
420420
displayapp/screens/settings/SettingBluetooth.cpp
421+
displayapp/screens/settings/SettingOTA.cpp
421422

422423
## Watch faces
423424
displayapp/screens/WatchFaceAnalog.cpp

src/components/ble/DfuService.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "components/ble/DfuService.h"
22
#include <cstring>
33
#include "components/ble/BleController.h"
4+
#include "components/ble/NotificationManager.h"
5+
#include "components/settings/Settings.h"
46
#include "drivers/SpiNorFlash.h"
57
#include "systemtask/SystemTask.h"
68
#include <nrf_log.h>
@@ -78,6 +80,18 @@ void DfuService::Init() {
7880
}
7981

8082
int DfuService::OnServiceData(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context) {
83+
#ifndef PINETIME_IS_RECOVERY
84+
if (__builtin_expect(systemTask.GetSettings().GetDfuAndFsMode() == Pinetime::Controllers::Settings::DfuAndFsMode::Disabled, 0)) {
85+
Pinetime::Controllers::NotificationManager::Notification notif;
86+
memcpy(notif.message.data(), denyAlert, denyAlertLength);
87+
notif.size = denyAlertLength;
88+
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
89+
systemTask.GetNotificationManager().Push(std::move(notif));
90+
systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
91+
return BLE_ATT_ERR_INSUFFICIENT_RES;
92+
}
93+
#endif
94+
8195
if (bleController.IsFirmwareUpdating()) {
8296
xTimerStart(timeoutTimer, 0);
8397
}

src/components/ble/DfuService.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace Pinetime {
2020

2121
namespace Controllers {
2222
class Ble;
23+
class Settings;
24+
class NotificationManager;
2325

2426
class DfuService {
2527
public:
@@ -83,6 +85,9 @@ namespace Pinetime {
8385
DfuImage dfuImage;
8486
NotificationManager notificationManager;
8587

88+
static constexpr const char* denyAlert = "InfiniTime\0Firmware update attempted, but disabled.";
89+
static constexpr const uint8_t denyAlertLength = 52;
90+
8691
static constexpr uint16_t dfuServiceId {0x1530};
8792
static constexpr uint16_t packetCharacteristicId {0x1532};
8893
static constexpr uint16_t controlPointCharacteristicId {0x1531};

src/components/ble/FSService.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <nrf_log.h>
22
#include "FSService.h"
33
#include "components/ble/BleController.h"
4+
#include "components/ble/NotificationManager.h"
5+
#include "components/settings/Settings.h"
46
#include "systemtask/SystemTask.h"
57

68
using namespace Pinetime::Controllers;
@@ -49,6 +51,18 @@ void FSService::Init() {
4951
}
5052

5153
int FSService::OnFSServiceRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context) {
54+
#ifndef PINETIME_IS_RECOVERY
55+
if (__builtin_expect(systemTask.GetSettings().GetDfuAndFsMode() == Pinetime::Controllers::Settings::DfuAndFsMode::Disabled, 0)) {
56+
Pinetime::Controllers::NotificationManager::Notification notif;
57+
memcpy(notif.message.data(), denyAlert, denyAlertLength);
58+
notif.size = denyAlertLength;
59+
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
60+
systemTask.GetNotificationManager().Push(std::move(notif));
61+
systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
62+
return BLE_ATT_ERR_INSUFFICIENT_RES;
63+
}
64+
#endif
65+
5266
if (attributeHandle == versionCharacteristicHandle) {
5367
NRF_LOG_INFO("FS_S : handle = %d", versionCharacteristicHandle);
5468
int res = os_mbuf_append(context->om, &fsVersion, sizeof(fsVersion));

src/components/ble/FSService.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace Pinetime {
1414

1515
namespace Controllers {
1616
class Ble;
17+
class Settings;
18+
class NotificationManager;
1719

1820
class FSService {
1921
public:
@@ -26,6 +28,10 @@ namespace Pinetime {
2628
private:
2729
Pinetime::System::SystemTask& systemTask;
2830
Pinetime::Controllers::FS& fs;
31+
32+
static constexpr const char* denyAlert = "InfiniTime\0File access attempted, but disabled.";
33+
static constexpr const uint8_t denyAlertLength = 48;
34+
2935
static constexpr uint16_t FSServiceId {0xFEBB};
3036
static constexpr uint16_t fsVersionId {0x0100};
3137
static constexpr uint16_t fsTransferId {0x0200};

src/components/settings/Settings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ void Settings::LoadSettingsFromFile() {
3434
if (bufferSettings.version == settingsVersion) {
3535
settings = bufferSettings;
3636
}
37+
if (settings.dfuAndFsMode == DfuAndFsMode::EnabledTillReboot) {
38+
settings.dfuAndFsMode = DfuAndFsMode::Disabled;
39+
}
3740
}
3841

3942
void Settings::SaveSettingsToFile() {

src/components/settings/Settings.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace Pinetime {
3636
};
3737
enum class PTSGaugeStyle : uint8_t { Full, Half, Numeric };
3838
enum class PTSWeather : uint8_t { On, Off };
39+
enum class DfuAndFsMode : uint8_t { Disabled = 0, Enabled = 1, EnabledTillReboot = 2 };
3940

4041
struct PineTimeStyle {
4142
Colors ColorTime = Colors::Teal;
@@ -283,10 +284,21 @@ namespace Pinetime {
283284
return bleRadioEnabled;
284285
};
285286

287+
void SetDfuAndFsMode(DfuAndFsMode mode) {
288+
if (mode != settings.dfuAndFsMode) {
289+
settingsChanged = true;
290+
}
291+
settings.dfuAndFsMode = mode;
292+
};
293+
294+
DfuAndFsMode GetDfuAndFsMode() const {
295+
return settings.dfuAndFsMode;
296+
};
297+
286298
private:
287299
Pinetime::Controllers::FS& fs;
288300

289-
static constexpr uint32_t settingsVersion = 0x0007;
301+
static constexpr uint32_t settingsVersion = 0x0008;
290302

291303
struct SettingsData {
292304
uint32_t version = settingsVersion;
@@ -308,6 +320,8 @@ namespace Pinetime {
308320
uint16_t shakeWakeThreshold = 150;
309321

310322
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
323+
324+
DfuAndFsMode dfuAndFsMode = DfuAndFsMode::Disabled;
311325
};
312326

313327
SettingsData settings;

src/displayapp/DisplayApp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "displayapp/screens/settings/SettingChimes.h"
5050
#include "displayapp/screens/settings/SettingShakeThreshold.h"
5151
#include "displayapp/screens/settings/SettingBluetooth.h"
52+
#include "displayapp/screens/settings/SettingOTA.h"
5253

5354
#include "libs/lv_conf.h"
5455
#include "UserApps.h"
@@ -524,6 +525,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
524525
case Apps::SettingBluetooth:
525526
currentScreen = std::make_unique<Screens::SettingBluetooth>(this, settingsController);
526527
break;
528+
case Apps::SettingOTA:
529+
currentScreen = std::make_unique<Screens::SettingOTA>(this, settingsController);
530+
break;
527531
case Apps::BatteryInfo:
528532
currentScreen = std::make_unique<Screens::BatteryInfo>(batteryController);
529533
break;

src/displayapp/apps/Apps.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace Pinetime {
4242
SettingChimes,
4343
SettingShakeThreshold,
4444
SettingBluetooth,
45+
SettingOTA,
4546
Error
4647
};
4748

src/displayapp/fonts/fonts.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
{
99
"file": "FontAwesome5-Solid+Brands+Regular.woff",
10-
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf0f3, 0xf522, 0xf743"
10+
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf0f3, 0xf522, 0xf743, 0xf3ed"
1111
}
1212
],
1313
"bpp": 1,

0 commit comments

Comments
 (0)