Skip to content

Commit 1dfa051

Browse files
feat: enforce mitm=0 and iocaps=none in GapSt (#604)
* Updated GapSt and friends * Cleanup * ST can only have MITM=0 now. * remove unnecessary import * removed another unnecessary import
1 parent d6b490b commit 1dfa051

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

hal_st/middlewares/ble_middleware/GapSt.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "ble_types.h"
55
#include "infra/event/EventDispatcherWithWeakPtr.hpp"
66
#include "services/ble/Gap.hpp"
7-
#include <cstdint>
87

98
namespace hal
109
{
@@ -111,17 +110,25 @@ namespace hal
111110
return (level == services::GapPairing::SecurityLevel::level4) ? SecureConnection::mandatory : SecureConnection::optional;
112111
}
113112

113+
uint8_t GapSt::SecurityLevelToMITM(services::GapPairing::SecurityLevel level) const
114+
{
115+
return 0;
116+
}
117+
114118
void GapSt::SetSecurityMode(services::GapPairing::SecurityMode mode, services::GapPairing::SecurityLevel level)
115119
{
116120
assert(mode == services::GapPairing::SecurityMode::mode1);
117121

118-
auto support = SecurityLevelToSecureConnection(level);
119-
auto mitmMode = (level == services::GapPairing::SecurityLevel::level3 || level == services::GapPairing::SecurityLevel::level4) ? MITM_PROTECTION_REQUIRED : MITM_PROTECTION_NOT_REQUIRED;
120-
aci_gap_set_authentication_requirement(bondingMode, mitmMode, static_cast<uint8_t>(support), keypressNotificationSupport, 16, 16, 0, 111111, GAP_PUBLIC_ADDR);
122+
SecureConnection secureConnectionSupport = SecurityLevelToSecureConnection(level);
123+
uint8_t mitmMode = SecurityLevelToMITM(level);
124+
125+
aci_gap_set_authentication_requirement(bondingMode, mitmMode, static_cast<uint8_t>(secureConnectionSupport), keypressNotificationSupport, 16, 16, 0, 111111, GAP_PUBLIC_ADDR);
121126
}
122127

123128
void GapSt::SetIoCapabilities(services::GapPairing::IoCapabilities caps)
124129
{
130+
really_assert(caps == IoCapabilities::none);
131+
125132
tBleStatus status = BLE_STATUS_FAILED;
126133

127134
switch (caps)

hal_st/middlewares/ble_middleware/GapSt.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ namespace hal
9797
virtual void HandleMtuExchangeResponseEvent(const aci_att_exchange_mtu_resp_event_rp0& event);
9898

9999
[[nodiscard]] virtual SecureConnection SecurityLevelToSecureConnection(services::GapPairing::SecurityLevel level) const;
100+
[[nodiscard]] virtual uint8_t SecurityLevelToMITM(services::GapPairing::SecurityLevel level) const;
100101

101102
void SetAddress(const MacAddress& address, services::GapDeviceAddressType addressType) const;
102103

0 commit comments

Comments
 (0)