Add secure transport and OAM router runtime implementations
- Implement secure transport mechanisms in `gateway_knx_secure_transport.cpp` for handling secure sessions, including AES encryption, session key generation, and secure packet wrapping and unwrapping. - Introduce `OamRouterRuntime` in `oam_router_runtime.cpp` to manage OAM router identity, individual addresses, and tunnel frame handling. - Enhance secure session management with functions for session allocation, authentication, and secure packet processing. - Ensure compatibility with existing KNXnet/IP protocols while adding support for secure communications. Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
#include "gateway_controller.hpp"
|
||||
#include "gateway_runtime.hpp"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_timer.h"
|
||||
#include "host/ble_gap.h"
|
||||
@@ -29,6 +32,8 @@ constexpr uint16_t kChannel2Uuid = 0xFFF2;
|
||||
constexpr uint16_t kGatewayUuid = 0xFFF3;
|
||||
constexpr int64_t kGenericDedupeWindowUs = 120000;
|
||||
constexpr size_t kGatewayCharacteristicIndex = 2;
|
||||
constexpr int kGatewayNotifyAllocationAttempts = 6;
|
||||
constexpr TickType_t kGatewayNotifyRetryDelayTicks = pdMS_TO_TICKS(20);
|
||||
|
||||
gateway::GatewayBleBridge* s_active_bridge = nullptr;
|
||||
uint16_t s_value_handles[3] = {0, 0, 0};
|
||||
@@ -348,9 +353,25 @@ void GatewayBleBridge::notifyCharacteristic(size_t index, const std::vector<uint
|
||||
}
|
||||
|
||||
characteristic_values_[index] = payload;
|
||||
struct os_mbuf* buffer = ble_hs_mbuf_from_flat(payload.data(), payload.size());
|
||||
const int allocation_attempts =
|
||||
index == kGatewayCharacteristicIndex ? kGatewayNotifyAllocationAttempts : 1;
|
||||
struct os_mbuf* buffer = nullptr;
|
||||
for (int attempt = 0; attempt < allocation_attempts; ++attempt) {
|
||||
if (conn_handle_ == kInvalidConnectionHandle || !notify_enabled_[index]) {
|
||||
return;
|
||||
}
|
||||
buffer = ble_hs_mbuf_from_flat(payload.data(), payload.size());
|
||||
if (buffer != nullptr) {
|
||||
break;
|
||||
}
|
||||
if (attempt + 1 < allocation_attempts) {
|
||||
vTaskDelay(kGatewayNotifyRetryDelayTicks);
|
||||
}
|
||||
}
|
||||
if (buffer == nullptr) {
|
||||
ESP_LOGW(kTag, "failed to allocate notify mbuf idx=%u", static_cast<unsigned>(index));
|
||||
ESP_LOGW(kTag, "failed to allocate notify mbuf idx=%u attempts=%d len=%u",
|
||||
static_cast<unsigned>(index), allocation_attempts,
|
||||
static_cast<unsigned>(payload.size()));
|
||||
return;
|
||||
}
|
||||
const int rc = ble_gatts_notify_custom(conn_handle_, s_value_handles[index], buffer);
|
||||
|
||||
Reference in New Issue
Block a user