Skip to content

Commit b742cfb

Browse files
committed
Add setting to disable DFU and FS access
1 parent a08eb06 commit b742cfb

File tree

13 files changed

+164
-3
lines changed

13 files changed

+164
-3
lines changed

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 (systemTask.GetSettings().GetDfuAndFsMode() == Pinetime::Controllers::Settings::DfuAndFsMode::Disabled) {
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_AUTHOR;
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:
@@ -87,6 +89,9 @@ namespace Pinetime {
8789
DfuImage dfuImage;
8890
NotificationManager notificationManager;
8991

92+
static constexpr const char denyAlert[] = "InfiniTime\0Firmware update attempted, but disabled in settings.";
93+
static constexpr const uint8_t denyAlertLength = sizeof(denyAlert); // for this to work denyAlert MUST be array
94+
9095
static constexpr uint16_t dfuServiceId {0x1530};
9196
static constexpr uint16_t packetCharacteristicId {0x1532};
9297
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 (systemTask.GetSettings().GetDfuAndFsMode() == Pinetime::Controllers::Settings::DfuAndFsMode::Disabled) {
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_AUTHOR;
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 in settings.";
33+
static constexpr const uint8_t denyAlertLength = sizeof(denyAlert); // for this to work denyAlert MUST be array
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.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "components/brightness/BrightnessController.h"
55
#include "components/fs/FS.h"
66
#include "displayapp/apps/Apps.h"
7+
#include <nrf_log.h>
78

89
namespace Pinetime {
910
namespace Controllers {
@@ -36,6 +37,7 @@ namespace Pinetime {
3637
};
3738
enum class PTSGaugeStyle : uint8_t { Full, Half, Numeric };
3839
enum class PTSWeather : uint8_t { On, Off };
40+
enum class DfuAndFsMode : uint8_t { Disabled, Enabled, EnabledTillReboot };
3941

4042
struct PineTimeStyle {
4143
Colors ColorTime = Colors::Teal;
@@ -298,10 +300,33 @@ namespace Pinetime {
298300
return bleRadioEnabled;
299301
};
300302

303+
void SetDfuAndFsMode(DfuAndFsMode mode) {
304+
if (mode == GetDfuAndFsMode()) {
305+
return;
306+
}
307+
if (mode == DfuAndFsMode::Enabled || GetDfuAndFsMode() == DfuAndFsMode::Enabled) {
308+
settingsChanged = true;
309+
}
310+
settings.dfuAndFsEnabledOnBoot = (mode == DfuAndFsMode::Enabled);
311+
dfuAndFsEnabledTillReboot = (mode == DfuAndFsMode::EnabledTillReboot);
312+
};
313+
314+
DfuAndFsMode GetDfuAndFsMode() {
315+
if (dfuAndFsEnabledTillReboot) {
316+
if (settings.dfuAndFsEnabledOnBoot) { // ensure both variables are in consistent state
317+
settingsChanged = true;
318+
settings.dfuAndFsEnabledOnBoot = false;
319+
NRF_LOG_ERROR("Settings: DfuAndFsMode data corrupted");
320+
}
321+
return DfuAndFsMode::EnabledTillReboot;
322+
}
323+
return (settings.dfuAndFsEnabledOnBoot ? DfuAndFsMode::Enabled : DfuAndFsMode::Disabled);
324+
};
325+
301326
private:
302327
Pinetime::Controllers::FS& fs;
303328

304-
static constexpr uint32_t settingsVersion = 0x0008;
329+
static constexpr uint32_t settingsVersion = 0x0009;
305330

306331
struct SettingsData {
307332
uint32_t version = settingsVersion;
@@ -325,6 +350,8 @@ namespace Pinetime {
325350
uint16_t shakeWakeThreshold = 150;
326351

327352
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
353+
354+
bool dfuAndFsEnabledOnBoot = false;
328355
};
329356

330357
SettingsData settings;
@@ -337,6 +364,7 @@ namespace Pinetime {
337364
* to off (false) on every boot because we always want ble to be enabled on startup
338365
*/
339366
bool bleRadioEnabled = true;
367+
bool dfuAndFsEnabledTillReboot = false;
340368

341369
void LoadSettingsFromFile();
342370
void SaveSettingsToFile();

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"
@@ -612,6 +613,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
612613
case Apps::SettingBluetooth:
613614
currentScreen = std::make_unique<Screens::SettingBluetooth>(this, settingsController);
614615
break;
616+
case Apps::SettingOTA:
617+
currentScreen = std::make_unique<Screens::SettingOTA>(this, settingsController);
618+
break;
615619
case Apps::BatteryInfo:
616620
currentScreen = std::make_unique<Screens::BatteryInfo>(batteryController);
617621
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,

src/displayapp/screens/Symbols.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Pinetime {
88
static constexpr const char* batteryHalf = "\xEF\x89\x82";
99
static constexpr const char* heartBeat = "\xEF\x88\x9E";
1010
static constexpr const char* bluetooth = "\xEF\x8A\x94";
11+
static constexpr const char* shieldAlt = "\xEF\x8F\xAD";
1112
static constexpr const char* plug = "\xEF\x87\xA6";
1213
static constexpr const char* shoe = "\xEF\x95\x8B";
1314
static constexpr const char* clock = "\xEF\x80\x97";

0 commit comments

Comments
 (0)