Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
97b6319
Revert "fix: GPDMA channel abort sequence (#555)"
oguzcanoguz May 20, 2025
8bceda5
Initial commit; added descriptive comments to SecureConnection enum
XavierBernhardt-Philips May 28, 2025
11e4e76
Revert formatting in unrelated file
XavierBernhardt-Philips May 28, 2025
5ba8925
Merge remote-tracking branch 'origin/HEAD'
XavierBernhardt-Philips May 28, 2025
1fcda26
fix: in StBootloaderCommunicatorUart use different timeout for erasin…
richardapeters May 22, 2025
55deec3
Merge branch 'main' into feature/pairing-security-requirements
XavierBernhardt-Philips May 28, 2025
13ac267
fix: in StBootloaderCommunicatorUart use different timeout for erasin…
richardapeters May 22, 2025
627e934
Rewriting SetSecurityMode to SetSecurityRequirements; updated signature
XavierBernhardt-Philips May 28, 2025
3896f4b
Better enum naming for ConnectionMode and ManInTheMiddleMode
MiquelJayson-Philips Jun 6, 2025
8173e57
Renamed notRequired to Disabled
MiquelJayson-Philips Jun 6, 2025
c744c01
Rename values in SecureConnectionMode enum
MiquelJayson-Philips Jun 13, 2025
2f2cd52
Refactoring SecureConnectionMode and MITMMODE into 2 functions
XavierBernhardt-Philips Jun 16, 2025
f3780f5
fix compile errors
XavierBernhardt-Philips Jun 18, 2025
c4e625d
Removed todos
XavierBernhardt-Philips Jun 18, 2025
88b67ce
refactoring
XavierBernhardt-Philips Jun 18, 2025
e43b0be
Merge branch 'main' into feature/pairing-security-requirements
XavierBernhardt-Philips Jun 18, 2025
e05f5a5
Removed unnecessary headers and add SC ble defs
MiquelJayson-Philips Jun 19, 2025
7936cd2
Merge branch 'main' into feature/pairing-security-requirements
XavierBernhardt-Philips Jul 22, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,12 @@
#define AUTHORIZATION_NOT_REQUIRED 0x00U
#define AUTHORIZATION_REQUIRED 0x01U

/* Secure Connections Support
*/
#define SECURE_NOT_SUPPORTED 0x00
#define SECURE_OPTIONAL 0x01
#define SECURE_MANDATORY 0x02

/* Connection authorization
*/
#define CONNECTION_AUTHORIZED 0x01U
Expand Down
3 changes: 2 additions & 1 deletion hal_st/middlewares/ble_middleware/GapCentralSt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@
aci_gatt_update_char_value(gapServiceHandle, gapAppearanceCharHandle, 0, sizeof(gapService.appearance), reinterpret_cast<const uint8_t*>(&gapService.appearance));

SetIoCapabilities(services::GapPairing::IoCapabilities::none);
SetSecurityMode(services::GapPairing::SecurityMode::mode1, services::GapPairing::SecurityLevel::level1);
SetManInTheMiddleMode(services::GapPairing::ManInTheMiddleMode::disabled);

Check failure on line 294 in hal_st/middlewares/ble_middleware/GapCentralSt.cpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wba52)

'services::GapPairing::ManInTheMiddleMode' has not been declared
SetSecureConnectionMode(services::GapPairing::SecureConnectionMode::disabled);

Check failure on line 295 in hal_st/middlewares/ble_middleware/GapCentralSt.cpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wba52)

'services::GapPairing::SecureConnectionMode' has not been declared
hci_le_set_default_phy(allPhys, speed2Mbps, speed2Mbps);
}

Expand Down
3 changes: 2 additions & 1 deletion hal_st/middlewares/ble_middleware/GapPeripheralSt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ namespace hal
aci_gatt_update_char_value(gapServiceHandle, gapAppearanceCharHandle, 0, sizeof(gapService.appearance), reinterpret_cast<const uint8_t*>(&gapService.appearance));

SetIoCapabilities(services::GapPairing::IoCapabilities::none);
SetSecurityMode(services::GapPairing::SecurityMode::mode1, services::GapPairing::SecurityLevel::level1);
SetManInTheMiddleMode(services::GapPairing::ManInTheMiddleMode::disabled);
SetSecureConnectionMode(services::GapPairing::SecureConnectionMode::disabled);

hci_le_write_suggested_default_data_length(services::GapConnectionParameters::connectionInitialMaxTxOctets, services::GapConnectionParameters::connectionInitialMaxTxTime);
hci_le_set_default_phy(allPhys, speed2Mbps, speed2Mbps);
Expand Down
49 changes: 39 additions & 10 deletions hal_st/middlewares/ble_middleware/GapSt.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "hal_st/middlewares/ble_middleware/GapSt.hpp"
#include "ble_gap_aci.h"
#include "ble_types.h"
#include "services/ble/Gap.hpp"

namespace hal
Expand Down Expand Up @@ -96,21 +97,49 @@
aci_gap_send_pairing_req(connectionContext.connectionHandle, NO_BONDING);
}

void GapSt::SetSecurityMode(services::GapPairing::SecurityMode mode, services::GapPairing::SecurityLevel level)
void GapSt::SetManInTheMiddleMode(services::GapPairing::ManInTheMiddleMode mitmMode)

Check failure on line 100 in hal_st/middlewares/ble_middleware/GapSt.cpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wb55)

'ManInTheMiddleMode' is not a member of 'services::GapPairing'

Check failure on line 100 in hal_st/middlewares/ble_middleware/GapSt.cpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wb55)

variable or field 'SetManInTheMiddleMode' declared void
{
assert(mode == services::GapPairing::SecurityMode::mode1);
auto selectedMitmMode = this->mitmMode;
switch (mitmMode)
{
case services::GapPairing::ManInTheMiddleMode::disabled:
selectedMitmMode = MITM_PROTECTION_NOT_REQUIRED;
break;
case services::GapPairing::ManInTheMiddleMode::supported:
selectedMitmMode = MITM_PROTECTION_NOT_REQUIRED;
break;
case services::GapPairing::ManInTheMiddleMode::enforced:
selectedMitmMode = MITM_PROTECTION_REQUIRED;
break;
default:
std::abort();
}
this->mitmMode = selectedMitmMode;

aci_gap_set_authentication_requirement(bondingMode, this->mitmMode, this->secureConnectionSupport, keypressNotificationSupport, 16, 16, 0, 111111, GAP_PUBLIC_ADDR);
}

enum class SecureConnection : uint8_t
void GapSt::SetSecureConnectionMode(services::GapPairing::SecureConnectionMode connectionMode)

Check failure on line 122 in hal_st/middlewares/ble_middleware/GapSt.cpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wb55)

'SecureConnectionMode' is not a member of 'services::GapPairing'

Check failure on line 122 in hal_st/middlewares/ble_middleware/GapSt.cpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wb55)

variable or field 'SetSecureConnectionMode' declared void
{
auto selectedConnectionMode = this->secureConnectionSupport;
switch (connectionMode)
{
notSupported = 0,
optional = 1,
mandatory
};
case services::GapPairing::SecureConnectionMode::disabled:
selectedConnectionMode = SECURE_NOT_SUPPORTED;
break;
case services::GapPairing::SecureConnectionMode::supported:
selectedConnectionMode = SECURE_OPTIONAL;
break;
case services::GapPairing::SecureConnectionMode::enforced:
selectedConnectionMode = SECURE_MANDATORY;
break;
default:
std::abort();
}

SecureConnection secureConnectionSupport = (level == services::GapPairing::SecurityLevel::level4) ? SecureConnection::mandatory : SecureConnection::optional;
uint8_t mitmMode = (level == services::GapPairing::SecurityLevel::level3 || level == services::GapPairing::SecurityLevel::level4) ? 1 : 0;
this->secureConnectionSupport = selectedConnectionMode;

aci_gap_set_authentication_requirement(bondingMode, mitmMode, static_cast<uint8_t>(secureConnectionSupport), keypressNotificationSupport, 16, 16, 0, 111111, GAP_PUBLIC_ADDR);
aci_gap_set_authentication_requirement(bondingMode, this->mitmMode, this->secureConnectionSupport, keypressNotificationSupport, 16, 16, 0, 111111, GAP_PUBLIC_ADDR);
}

void GapSt::SetIoCapabilities(services::GapPairing::IoCapabilities caps)
Expand Down
27 changes: 16 additions & 11 deletions hal_st/middlewares/ble_middleware/GapSt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#define HAL_ST_GAP_ST_HPP

#include "ble/ble.h"
#include "ble_defs.h"
#include "hal_st/middlewares/ble_middleware/HciEventObserver.hpp"
#include "infra/util/BoundedString.hpp"
#include "services/ble/BondStorageSynchronizer.hpp"
#include "services/ble/Gap.hpp"
#include "services/ble/Gatt.hpp"
#include <cstdint>

namespace hal
{
Expand Down Expand Up @@ -49,8 +51,11 @@

// Implementation of GapPairing
void Pair() override;
void SetSecurityMode(services::GapPairing::SecurityMode mode, services::GapPairing::SecurityLevel level) override;
void SetIoCapabilities(services::GapPairing::IoCapabilities caps) override;

void SetManInTheMiddleMode(ManInTheMiddleMode mitmMode) override;

Check failure on line 55 in hal_st/middlewares/ble_middleware/GapSt.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wb55)

'ManInTheMiddleMode' has not been declared

Check failure on line 55 in hal_st/middlewares/ble_middleware/GapSt.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wb55)

'void hal::GapSt::SetManInTheMiddleMode(int)' marked 'override', but does not override

Check failure on line 55 in hal_st/middlewares/ble_middleware/GapSt.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wb55)

'ManInTheMiddleMode' has not been declared

Check failure on line 55 in hal_st/middlewares/ble_middleware/GapSt.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wba52)

'void hal::GapSt::SetManInTheMiddleMode(int)' marked 'override', but does not override

Check failure on line 55 in hal_st/middlewares/ble_middleware/GapSt.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wba52)

'ManInTheMiddleMode' has not been declared

Check failure on line 55 in hal_st/middlewares/ble_middleware/GapSt.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wba52)

'void hal::GapSt::SetManInTheMiddleMode(int)' marked 'override', but does not override

Check failure on line 55 in hal_st/middlewares/ble_middleware/GapSt.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wba52)

'ManInTheMiddleMode' has not been declared
void SetSecureConnectionMode(SecureConnectionMode connectionMode) override;

Check failure on line 56 in hal_st/middlewares/ble_middleware/GapSt.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wb55)

'SecureConnectionMode' has not been declared

Check failure on line 56 in hal_st/middlewares/ble_middleware/GapSt.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wb55)

'void hal::GapSt::SetSecureConnectionMode(int)' marked 'override', but does not override

Check failure on line 56 in hal_st/middlewares/ble_middleware/GapSt.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wb55)

'SecureConnectionMode' has not been declared

Check failure on line 56 in hal_st/middlewares/ble_middleware/GapSt.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wba52)

'SecureConnectionMode' has not been declared

Check failure on line 56 in hal_st/middlewares/ble_middleware/GapSt.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wba52)

'void hal::GapSt::SetSecureConnectionMode(int)' marked 'override', but does not override

Check failure on line 56 in hal_st/middlewares/ble_middleware/GapSt.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wba52)

'SecureConnectionMode' has not been declared

void SetIoCapabilities(IoCapabilities caps) override;
void AuthenticateWithPasskey(uint32_t passkey) override;
void NumericComparisonConfirm(bool accept) override;

Expand All @@ -60,17 +65,17 @@
virtual void HandleHciDisconnectEvent(hci_event_pckt& eventPacket);

virtual void HandleHciLeConnectionCompleteEvent(evt_le_meta_event* metaEvent);
virtual void HandleHciLeAdvertisingReportEvent(evt_le_meta_event* metaEvent){};
virtual void HandleHciLeConnectionUpdateCompleteEvent(evt_le_meta_event* metaEvent){};
virtual void HandleHciLeDataLengthChangeEvent(evt_le_meta_event* metaEvent){};
virtual void HandleHciLePhyUpdateCompleteEvent(evt_le_meta_event* metaEvent){};
virtual void HandleHciLeAdvertisingReportEvent(evt_le_meta_event* metaEvent) {};
virtual void HandleHciLeConnectionUpdateCompleteEvent(evt_le_meta_event* metaEvent) {};
virtual void HandleHciLeDataLengthChangeEvent(evt_le_meta_event* metaEvent) {};
virtual void HandleHciLePhyUpdateCompleteEvent(evt_le_meta_event* metaEvent) {};
virtual void HandleHciLeEnhancedConnectionCompleteEvent(evt_le_meta_event* metaEvent);

virtual void HandlePairingCompleteEvent(evt_blecore_aci* vendorEvent);
virtual void HandleBondLostEvent(evt_blecore_aci* vendorEvent);
virtual void HandleGapProcedureCompleteEvent(evt_blecore_aci* vendorEvent){};
virtual void HandleGattCompleteEvent(evt_blecore_aci* vendorEvent){};
virtual void HandleL2capConnectionUpdateRequestEvent(evt_blecore_aci* vendorEvent){};
virtual void HandleGapProcedureCompleteEvent(evt_blecore_aci* vendorEvent) {};
virtual void HandleGattCompleteEvent(evt_blecore_aci* vendorEvent) {};
virtual void HandleL2capConnectionUpdateRequestEvent(evt_blecore_aci* vendorEvent) {};
virtual void HandleMtuExchangeResponseEvent(evt_blecore_aci* vendorEvent);

void SetAddress(const MacAddress& address, services::GapDeviceAddressType addressType);
Expand Down Expand Up @@ -104,14 +109,14 @@

const uint8_t ioCapability = IO_CAP_NO_INPUT_NO_OUTPUT;
const uint8_t bondingMode = BONDING;
const uint8_t mitmMode = MITM_PROTECTION_NOT_REQUIRED;
const uint8_t secureConnectionSupport = 0x01; /* Secure Connections Pairing supported but optional */
const uint8_t keypressNotificationSupport = KEYPRESS_SUPPORTED;
static constexpr uint8_t maxNumberOfBonds = 10;

private:
services::BondStorageSynchronizer& bondStorageSynchronizer;
uint16_t maxAttMtu = defaultMaxAttMtuSize;
uint8_t mitmMode = MITM_PROTECTION_NOT_REQUIRED;
uint8_t secureConnectionSupport = SECURE_OPTIONAL;

Check failure on line 119 in hal_st/middlewares/ble_middleware/GapSt.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wba52)

'SECURE_OPTIONAL' was not declared in this scope
};
}

Expand Down
12 changes: 9 additions & 3 deletions hal_st/middlewares/ble_middleware/TracingGapCentralSt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@ namespace hal
GapCentralSt::Pair();
}

void TracingGapCentralSt::SetSecurityMode(services::GapPairing::SecurityMode mode, services::GapPairing::SecurityLevel level)
void TracingGapCentralSt::SetManInTheMiddleMode(services::GapPairing::ManInTheMiddleMode mitmMode)
{
tracer.Trace() << "TracingGapCentralSt::SetSecurityMode";
GapCentralSt::SetSecurityMode(mode, level);
tracer.Trace() << "TracingGapCentralSt::SetManInTheMiddleMode";
GapCentralSt::SetManInTheMiddleMode(mitmMode);
}

void TracingGapCentralSt::SetSecureConnectionMode(services::GapPairing::SecureConnectionMode connectionMode)
{
tracer.Trace() << "TracingGapCentralSt::SetSecureConnectionMode";
GapCentralSt::SetSecureConnectionMode(connectionMode);
}

void TracingGapCentralSt::SetIoCapabilities(services::GapPairing::IoCapabilities caps)
Expand Down
4 changes: 3 additions & 1 deletion hal_st/middlewares/ble_middleware/TracingGapCentralSt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ namespace hal

// Implementation of GapPairing
void Pair() override;
void SetSecurityMode(services::GapPairing::SecurityMode mode, services::GapPairing::SecurityLevel level) override;

void SetManInTheMiddleMode(services::GapPairing::ManInTheMiddleMode mitmMode) override;
void SetSecureConnectionMode(services::GapPairing::SecureConnectionMode connectionMode) override;
void SetIoCapabilities(services::GapPairing::IoCapabilities caps) override;
void AuthenticateWithPasskey(uint32_t passkey) override;
void NumericComparisonConfirm(bool accept) override;
Expand Down
Loading