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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ list(APPEND SOURCE_FILES
displayapp/screens/settings/SettingChimes.cpp
displayapp/screens/settings/SettingShakeThreshold.cpp
displayapp/screens/settings/SettingBluetooth.cpp
displayapp/screens/settings/SettingBluetoothMain.cpp
displayapp/screens/settings/SettingBluetoothSecurity.cpp
displayapp/screens/settings/SettingOTA.cpp

## Watch faces
Expand Down Expand Up @@ -795,6 +797,7 @@ add_definitions(-DFREERTOS)
add_definitions(-D__STACK_SIZE=1024)
add_definitions(-D__HEAP_SIZE=0)
add_definitions(-DMYNEWT_VAL_BLE_LL_RFMGMT_ENABLE_TIME=1500)
add_definitions(-DMYNEWT_VAL_BLE_RPA_TIMEOUT=900)
add_definitions(-DLFS_CONFIG=libs/lfs_config.h)

# _sbrk is purposefully not implemented so that builds fail when it is used
Expand Down
3 changes: 3 additions & 0 deletions src/components/ble/AlertNotificationService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <hal/nrf_rtc.h>
#include <cstring>
#include <algorithm>
#include "components/ble/NimbleController.h"
#include "components/ble/NotificationManager.h"
#include "systemtask/SystemTask.h"

Expand All @@ -17,6 +18,8 @@ int AlertNotificationCallback(uint16_t /*conn_handle*/, uint16_t /*attr_handle*/
}

void AlertNotificationService::Init() {
systemTask.nimble().AddCharacteristicSecurity(serviceDefinition);

int res;
res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);
Expand Down
6 changes: 5 additions & 1 deletion src/components/ble/BatteryInformationService.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "components/ble/BatteryInformationService.h"
#include <nrf_log.h>
#include "components/battery/BatteryController.h"
#include "components/ble/NimbleController.h"

using namespace Pinetime::Controllers;

Expand All @@ -12,8 +13,9 @@ int BatteryInformationServiceCallback(uint16_t /*conn_handle*/, uint16_t attr_ha
return batteryInformationService->OnBatteryServiceRequested(attr_handle, ctxt);
}

BatteryInformationService::BatteryInformationService(Controllers::Battery& batteryController)
BatteryInformationService::BatteryInformationService(Controllers::NimbleController& nimble, Controllers::Battery& batteryController)
: batteryController {batteryController},
nimble {nimble},
characteristicDefinition {{.uuid = &batteryLevelUuid.u,
.access_cb = BatteryInformationServiceCallback,
.arg = this,
Expand All @@ -30,6 +32,8 @@ BatteryInformationService::BatteryInformationService(Controllers::Battery& batte
}

void BatteryInformationService::Init() {
nimble.AddCharacteristicSecurity(serviceDefinition);

int res = 0;
res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);
Expand Down
4 changes: 3 additions & 1 deletion src/components/ble/BatteryInformationService.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ namespace Pinetime {

namespace Controllers {
class Battery;
class NimbleController;

class BatteryInformationService {
public:
BatteryInformationService(Controllers::Battery& batteryController);
BatteryInformationService(Controllers::NimbleController& nimble, Controllers::Battery& batteryController);
void Init();

int OnBatteryServiceRequested(uint16_t attributeHandle, ble_gatt_access_ctxt* context);
void NotifyBatteryLevel(uint16_t connectionHandle, uint8_t level);

private:
Controllers::Battery& batteryController;
Controllers::NimbleController& nimble;
static constexpr uint16_t batteryInformationServiceId {0x180F};
static constexpr uint16_t batteryLevelId {0x2A19};

Expand Down
8 changes: 6 additions & 2 deletions src/components/ble/CurrentTimeService.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "components/ble/CurrentTimeService.h"
#include "components/ble/NimbleController.h"
#include <nrf_log.h>

using namespace Pinetime::Controllers;
Expand All @@ -24,6 +25,8 @@ int CurrentTimeService::OnCurrentTimeServiceAccessed(struct ble_gatt_access_ctxt
}

void CurrentTimeService::Init() {
nimble.AddCharacteristicSecurity(serviceDefinition);

int res;
res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);
Expand Down Expand Up @@ -97,7 +100,7 @@ int CurrentTimeService::OnLocalTimeAccessed(struct ble_gatt_access_ctxt* ctxt) {
return 0;
}

CurrentTimeService::CurrentTimeService(DateTime& dateTimeController)
CurrentTimeService::CurrentTimeService(NimbleController& nimble, DateTime& dateTimeController)
: characteristicDefinition {

{.uuid = &ctsLtChrUuid.u,
Expand All @@ -118,5 +121,6 @@ CurrentTimeService::CurrentTimeService(DateTime& dateTimeController)
.characteristics = characteristicDefinition},
{0},
},
m_dateTimeController {dateTimeController} {
m_dateTimeController {dateTimeController},
nimble{nimble} {
}
5 changes: 4 additions & 1 deletion src/components/ble/CurrentTimeService.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

namespace Pinetime {
namespace Controllers {
class NimbleController;

class CurrentTimeService {
public:
CurrentTimeService(DateTime& dateTimeController);
CurrentTimeService(NimbleController& nimble, DateTime& dateTimeController);
void Init();

int OnCurrentTimeServiceAccessed(struct ble_gatt_access_ctxt* ctxt);
Expand Down Expand Up @@ -52,6 +54,7 @@ namespace Pinetime {
} CtsLocalTimeData;

DateTime& m_dateTimeController;
NimbleController& nimble;
};
}
}
4 changes: 4 additions & 0 deletions src/components/ble/DfuService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ DfuService::DfuService(Pinetime::System::SystemTask& systemTask,
}

void DfuService::Init() {
systemTask.nimble().AddCharacteristicSecurity(serviceDefinition);

int res;
res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);
Expand All @@ -90,6 +92,8 @@ int DfuService::OnServiceData(uint16_t connectionHandle, uint16_t attributeHandl
systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
return BLE_ATT_ERR_INSUFFICIENT_AUTHOR;
}
if (!systemTask.nimble().IsConnSecurityOK())
return BLE_ATT_ERR_INSUFFICIENT_AUTHEN;
#endif

if (bleController.IsFirmwareUpdating()) {
Expand Down
4 changes: 4 additions & 0 deletions src/components/ble/FSService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ FSService::FSService(Pinetime::System::SystemTask& systemTask, Pinetime::Control
}

void FSService::Init() {
systemTask.nimble().AddCharacteristicSecurity(serviceDefinition);

int res = 0;
res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);
Expand All @@ -61,6 +63,8 @@ int FSService::OnFSServiceRequested(uint16_t connectionHandle, uint16_t attribut
systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
return BLE_ATT_ERR_INSUFFICIENT_AUTHOR;
}
if (!systemTask.nimble().IsConnSecurityOK())
return BLE_ATT_ERR_INSUFFICIENT_AUTHEN;
#endif

if (attributeHandle == versionCharacteristicHandle) {
Expand Down
7 changes: 6 additions & 1 deletion src/components/ble/HeartRateService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ HeartRateService::HeartRateService(NimbleController& nimble, Controllers::HeartR
}

void HeartRateService::Init() {
nimble.AddCharacteristicSecurity(serviceDefinition);

int res = 0;
res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);
Expand All @@ -46,6 +48,9 @@ void HeartRateService::Init() {
}

int HeartRateService::OnHeartRateRequested(uint16_t attributeHandle, ble_gatt_access_ctxt* context) {
if (!nimble.IsConnSecurityOK())
return BLE_ATT_ERR_INSUFFICIENT_AUTHEN;

if (attributeHandle == heartRateMeasurementHandle) {
NRF_LOG_INFO("HEARTRATE : handle = %d", heartRateMeasurementHandle);
uint8_t buffer[2] = {0, heartRateController.HeartRate()}; // [0] = flags, [1] = hr value
Expand All @@ -65,7 +70,7 @@ void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) {

uint16_t connectionHandle = nimble.connHandle();

if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE || !nimble.IsConnSecurityOK()) {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/components/ble/ImmediateAlertService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ ImmediateAlertService::ImmediateAlertService(Pinetime::System::SystemTask& syste
}

void ImmediateAlertService::Init() {
systemTask.nimble().AddCharacteristicSecurity(serviceDefinition);

int res = 0;
res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);
Expand Down
9 changes: 7 additions & 2 deletions src/components/ble/MotionService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ MotionService::MotionService(NimbleController& nimble, Controllers::MotionContro
}

void MotionService::Init() {
nimble.AddCharacteristicSecurity(serviceDefinition);

int res = 0;
res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);
Expand All @@ -60,6 +62,9 @@ void MotionService::Init() {
}

int MotionService::OnStepCountRequested(uint16_t attributeHandle, ble_gatt_access_ctxt* context) {
if (!nimble.IsConnSecurityOK())
return BLE_ATT_ERR_INSUFFICIENT_AUTHEN;

if (attributeHandle == stepCountHandle) {
NRF_LOG_INFO("Motion-stepcount : handle = %d", stepCountHandle);
uint32_t buffer = motionController.NbSteps();
Expand All @@ -86,7 +91,7 @@ void MotionService::OnNewStepCountValue(uint32_t stepCount) {

uint16_t connectionHandle = nimble.connHandle();

if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE || !nimble.IsConnSecurityOK()) {
return;
}

Expand All @@ -103,7 +108,7 @@ void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) {

uint16_t connectionHandle = nimble.connHandle();

if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE || !nimble.IsConnSecurityOK()) {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/components/ble/MusicService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ Pinetime::Controllers::MusicService::MusicService(Pinetime::Controllers::NimbleC
}

void Pinetime::Controllers::MusicService::Init() {
nimble.AddCharacteristicSecurity(serviceDefinition);

uint8_t res = 0;
res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);
Expand Down
Loading
Loading