Skip to content
Merged
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
2 changes: 1 addition & 1 deletion include/someip/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class Message {

// Utility methods
size_t get_total_size() const {
size_t e2e_size = e2e_header_.has_value() ? e2e_header_->get_header_size() : 0;
size_t e2e_size = e2e_header_.has_value() ? e2e::E2EHeader::get_header_size() : 0;
return HEADER_SIZE + e2e_size + payload_.size();
}
static size_t get_header_size() { return HEADER_SIZE; }
Expand Down
8 changes: 4 additions & 4 deletions include/tp/tp_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ struct TpTransfer {
TpTransfer() = default;

TpTransfer(uint32_t id, uint32_t msg_id)
: transfer_id(id), message_id(msg_id) {
start_time = std::chrono::steady_clock::now();
last_activity = start_time;
}
: transfer_id(id),
message_id(msg_id),
start_time(std::chrono::steady_clock::now()),
last_activity(start_time) {}
};

/**
Expand Down
2 changes: 1 addition & 1 deletion include/transport/udp_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct UdpTransportConfig {
bool reuse_address{true}; // Allow address reuse (SO_REUSEADDR)
bool reuse_port{false}; // Allow port reuse (SO_REUSEPORT) - for multicast
bool enable_broadcast{false}; // Enable broadcast sending
std::string multicast_interface{}; // Interface for multicast (empty = INADDR_ANY)
std::string multicast_interface; // Interface for multicast (empty = INADDR_ANY)
int multicast_ttl{1}; // Multicast TTL (1 = local network only)

// SOME/IP spec recommends max 1400 bytes to avoid IP fragmentation
Expand Down
44 changes: 21 additions & 23 deletions src/e2e/e2e_crc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "e2e/e2e_crc.h"
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>

Expand Down Expand Up @@ -74,34 +75,31 @@ uint16_t calculate_crc16_itu_x25(const std::vector<uint8_t>& data) {
static constexpr uint32_t CRC32_POLY = 0x04C11DB7;
static constexpr uint32_t CRC32_INIT = 0xFFFFFFFF;

// Precomputed CRC32 lookup table
static uint32_t crc32_table[256];

// Initialize CRC32 lookup table (called once)
static bool crc32_table_initialized = false;

static void init_crc32_table() {
if (crc32_table_initialized) {
return;
}

for (uint32_t i = 0; i < 256; ++i) {
uint32_t crc = i << 24;
for (int j = 0; j < 8; ++j) {
if (crc & 0x80000000) {
crc = (crc << 1) ^ CRC32_POLY;
} else {
crc <<= 1;
namespace {

const std::array<uint32_t, 256>& get_crc32_table() {
static const std::array<uint32_t, 256> table = [] {
std::array<uint32_t, 256> t{};
for (uint32_t i = 0; i < 256; ++i) {
uint32_t crc = i << 24;
for (int j = 0; j < 8; ++j) {
if (crc & 0x80000000) {
crc = (crc << 1) ^ CRC32_POLY;
} else {
crc <<= 1;
}
}
t[i] = crc;
}
crc32_table[i] = crc;
}

crc32_table_initialized = true;
return t;
}();
return table;
}

} // namespace

uint32_t calculate_crc32(const std::vector<uint8_t>& data) {
init_crc32_table();
const auto& crc32_table = get_crc32_table();

uint32_t crc = CRC32_INIT;

Expand Down
13 changes: 7 additions & 6 deletions src/events/event_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <unordered_map>
#include <atomic>
#include <algorithm>
#include <utility>

namespace someip::events {

Expand Down Expand Up @@ -90,14 +91,14 @@ class EventSubscriberImpl : public transport::ITransportListener {

SubscriptionInfo sub_info;
sub_info.subscription = subscription;
sub_info.notification_callback = notification_callback;
sub_info.status_callback = status_callback;
sub_info.notification_callback = std::move(notification_callback);
sub_info.status_callback = std::move(status_callback);
sub_info.filters = filters;

// Store subscription
platform::ScopedLock const subs_lock(subscriptions_mutex_);
std::string key = make_subscription_key(service_id, instance_id, eventgroup_id);
subscriptions_[key] = sub_info;
subscriptions_[key] = std::move(sub_info);

// Send subscription request via RPC (simplified - in real implementation,
// this would use SD to find the service endpoint and send subscription)
Expand Down Expand Up @@ -169,7 +170,7 @@ class EventSubscriberImpl : public transport::ITransportListener {
// Store callback for field response
platform::ScopedLock const field_lock(field_requests_mutex_);
std::string key = make_field_key(service_id, instance_id, event_id);
field_requests_[key] = callback;
field_requests_[key] = std::move(callback);

// Send field request
transport::Endpoint service_endpoint("127.0.0.1", 30500); // TODO: Get from SD
Expand Down Expand Up @@ -356,7 +357,7 @@ bool EventSubscriber::subscribe_eventgroup(uint16_t service_id, uint16_t instanc
SubscriptionStatusCallback status_callback,
const std::vector<EventFilter>& filters) {
return impl_->subscribe_eventgroup(service_id, instance_id, eventgroup_id,
notification_callback, status_callback, filters);
std::move(notification_callback), std::move(status_callback), filters);
}

bool EventSubscriber::unsubscribe_eventgroup(uint16_t service_id, uint16_t instance_id, uint16_t eventgroup_id) {
Expand All @@ -365,7 +366,7 @@ bool EventSubscriber::unsubscribe_eventgroup(uint16_t service_id, uint16_t insta

bool EventSubscriber::request_field(uint16_t service_id, uint16_t instance_id, uint16_t event_id,
EventNotificationCallback callback) {
return impl_->request_field(service_id, instance_id, event_id, callback);
return impl_->request_field(service_id, instance_id, event_id, std::move(callback));
}

bool EventSubscriber::set_event_filters(uint16_t service_id, uint16_t instance_id, uint16_t eventgroup_id,
Expand Down
53 changes: 33 additions & 20 deletions src/platform/freertos/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@

static constexpr size_t POOL_SIZE = SOMEIP_FREERTOS_MESSAGE_POOL_SIZE;

alignas(someip::Message) static char
namespace {

alignas(someip::Message) char
pool_buffer[POOL_SIZE * sizeof(someip::Message)];

static bool block_used[POOL_SIZE] = {};
static SemaphoreHandle_t pool_mutex = nullptr;
static std::atomic<bool> pool_initialized{false};
bool block_used[POOL_SIZE] = {};
SemaphoreHandle_t pool_mutex = nullptr;
std::atomic<bool> pool_initialized{false};

static void ensure_pool_init() {
void ensure_pool_init() {
if (pool_initialized.load(std::memory_order_acquire)) {
return;
}
Expand All @@ -57,6 +59,31 @@ static void ensure_pool_init() {
taskEXIT_CRITICAL();
}

void release_message_impl(someip::Message* msg) {
if (!msg) {
return;
}

auto* raw = reinterpret_cast<char*>(msg);
auto* pool_start = static_cast<char*>(pool_buffer);
if (raw < pool_start || raw >= pool_start + POOL_SIZE * sizeof(someip::Message)) {
return;
}
size_t const byte_offset = static_cast<size_t>(raw - pool_start);
if (byte_offset % sizeof(someip::Message) != 0) {
return;
}
size_t const index = byte_offset / sizeof(someip::Message);
Comment thread
vtz marked this conversation as resolved.

msg->~Message();

xSemaphoreTake(pool_mutex, portMAX_DELAY);
block_used[index] = false;
xSemaphoreGive(pool_mutex);
}

} // namespace

namespace someip::platform {

/** @implements REQ_PLATFORM_FREERTOS_002 */
Expand All @@ -83,21 +110,7 @@ MessagePtr allocate_message() {
}

void release_message(Message* msg) {
if (!msg) {
return;
}

msg->~Message();

auto* raw = reinterpret_cast<char*>(msg);
size_t const offset = static_cast<size_t>(raw - pool_buffer);
size_t const index = offset / sizeof(Message);

if (index < POOL_SIZE) {
xSemaphoreTake(pool_mutex, portMAX_DELAY);
block_used[index] = false;
xSemaphoreGive(pool_mutex);
}
release_message_impl(msg);
}

} // namespace someip::platform
31 changes: 20 additions & 11 deletions src/platform/threadx/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@

static constexpr size_t POOL_SIZE = SOMEIP_THREADX_MESSAGE_POOL_SIZE;

alignas(someip::Message) static UCHAR
pool_buffer[POOL_SIZE * sizeof(someip::Message)];

TX_BLOCK_POOL message_pool;
static TX_MUTEX pool_guard;
std::atomic<bool> pool_initialized{false};

static void ensure_pool_init() {
namespace {

alignas(someip::Message) UCHAR
pool_buffer[POOL_SIZE * sizeof(someip::Message)];

TX_MUTEX pool_guard;

void ensure_pool_init() {
if (pool_initialized.load(std::memory_order_acquire)) {
return;
}
Expand Down Expand Up @@ -67,6 +70,17 @@ static void ensure_pool_init() {
TX_RESTORE
}

void release_message_impl(someip::Message* msg) {
if (!msg) {
return;
}

msg->~Message();
tx_block_release(static_cast<void*>(msg));
}

} // namespace

namespace someip::platform {

/** @implements REQ_PLATFORM_THREADX_002 */
Expand All @@ -86,12 +100,7 @@ MessagePtr allocate_message() {
}

void release_message(Message* msg) {
if (!msg) {
return;
}

msg->~Message();
tx_block_release(static_cast<void*>(msg));
release_message_impl(msg);
}

} // namespace someip::platform
4 changes: 2 additions & 2 deletions src/rpc/rpc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class RpcClientImpl : public transport::ITransportListener {
PendingCall call_info{
service_id, method_id, session_id,
std::chrono::steady_clock::now(),
timeout, callback
timeout, std::move(callback)
};

RpcCallHandle handle = 0;
Expand Down Expand Up @@ -305,7 +305,7 @@ RpcCallHandle RpcClient::call_method_async(uint16_t service_id, MethodId method_
const std::vector<uint8_t>& parameters,
RpcCallback callback,
const RpcTimeout& timeout) {
return impl_->call_method_async(service_id, method_id, parameters, callback, timeout);
return impl_->call_method_async(service_id, method_id, parameters, std::move(callback), timeout);
}

bool RpcClient::cancel_call(RpcCallHandle handle) {
Expand Down
9 changes: 5 additions & 4 deletions src/rpc/rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "common/result.h"
#include <unordered_map>
#include <atomic>
#include <utility>

namespace someip::rpc {

Expand Down Expand Up @@ -79,7 +80,7 @@ class RpcServerImpl : public transport::ITransportListener {
// Check if already registered
bool already_exists = method_handlers_.count(method_id) > 0;
if (!already_exists) {
method_handlers_[method_id] = handler;
method_handlers_[method_id] = std::move(handler);
}
return !already_exists;
}
Expand Down Expand Up @@ -160,7 +161,7 @@ class RpcServerImpl : public transport::ITransportListener {
}

/** @implements REQ_MSG_115, REQ_MSG_117, REQ_MSG_117_E01 */
void send_success_response(MessagePtr request, const transport::Endpoint& sender,
void send_success_response(MessagePtr const& request, const transport::Endpoint& sender,
const std::vector<uint8_t>& return_values) {
MessageId response_msg_id(request->get_service_id(), request->get_method_id());
Message response(response_msg_id, request->get_request_id(),
Expand All @@ -174,7 +175,7 @@ class RpcServerImpl : public transport::ITransportListener {
}

/** @implements REQ_MSG_115, REQ_MSG_117, REQ_MSG_117_E01, REQ_MSG_129 */
void send_error_response(MessagePtr request, const transport::Endpoint& sender, ReturnCode error_code) {
void send_error_response(MessagePtr const& request, const transport::Endpoint& sender, ReturnCode error_code) {
MessageId response_msg_id(request->get_service_id(), request->get_method_id());
Message response(response_msg_id, request->get_request_id(),
MessageType::ERROR, error_code);
Expand Down Expand Up @@ -227,7 +228,7 @@ void RpcServer::shutdown() {
}

bool RpcServer::register_method(MethodId method_id, MethodHandler handler) {
return impl_->register_method(method_id, handler);
return impl_->register_method(method_id, std::move(handler));
}

bool RpcServer::unregister_method(MethodId method_id) {
Expand Down
8 changes: 6 additions & 2 deletions src/sd/sd_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@

namespace someip::sd {

static std::shared_ptr<transport::UdpTransport> create_sd_transport(const SdConfig& config) {
namespace {

std::shared_ptr<transport::UdpTransport> create_sd_transport(const SdConfig& config) {
transport::UdpTransportConfig cfg;
cfg.reuse_port = true;
cfg.multicast_interface = config.unicast_address;
return std::make_shared<transport::UdpTransport>(
transport::Endpoint("0.0.0.0", config.multicast_port), cfg);
}

} // namespace

/**
* @brief Service Discovery Client implementation
* @implements REQ_ARCH_001
Expand Down Expand Up @@ -349,7 +353,7 @@ class SdClientImpl : public transport::ITransportListener {
for (uint8_t i = 0; i < run1 && (index1 + i) < options.size(); ++i) {
const auto& option = options[index1 + i];
if (option->get_type() == OptionType::IPV4_ENDPOINT) {
auto* ep = static_cast<const IPv4EndpointOption*>(option.get());
const auto* ep = static_cast<const IPv4EndpointOption*>(option.get());
instance.ip_address = ep->get_ipv4_address_string();
instance.port = ep->get_port();
instance.protocol = ep->get_protocol();
Expand Down
4 changes: 2 additions & 2 deletions src/sd/sd_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ bool IPv4EndpointOption::deserialize(const std::vector<uint8_t>& data, size_t& o
<< ((ipv4_address_ >> 24) & 0xFF) << "."
<< ((ipv4_address_ >> 16) & 0xFF) << "."
<< ((ipv4_address_ >> 8) & 0xFF) << "."
<< (ipv4_address_ & 0xFF) << std::endl;
<< (ipv4_address_ & 0xFF) << '\n';
// Continue processing despite invalid address
}

Expand Down Expand Up @@ -343,7 +343,7 @@ bool IPv4MulticastOption::deserialize(const std::vector<uint8_t>& data, size_t&
<< ((ipv4_address_ >> 24) & 0xFF) << "."
<< ((ipv4_address_ >> 16) & 0xFF) << "."
<< ((ipv4_address_ >> 8) & 0xFF) << "."
<< (ipv4_address_ & 0xFF) << std::endl;
<< (ipv4_address_ & 0xFF) << '\n';
// Continue processing despite invalid address
}
port_ = (data[offset] << 8) | data[offset + 1];
Expand Down
Loading
Loading