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
8 changes: 6 additions & 2 deletions include/platform/lwip/net_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ static inline int someip_shutdown_socket(someip_socket_t fd) {
static inline int someip_set_nonblocking(someip_socket_t fd) {
int flags = lwip_fcntl(fd, F_GETFL, 0);
if (flags < 0) return -1;
return lwip_fcntl(fd, F_SETFL, flags | O_NONBLOCK);
return lwip_fcntl(fd, F_SETFL,
static_cast<int>(static_cast<unsigned int>(flags) |
static_cast<unsigned int>(O_NONBLOCK)));
}

/** @implements REQ_PLATFORM_LWIP_001 */
static inline int someip_set_blocking(someip_socket_t fd) {
int flags = lwip_fcntl(fd, F_GETFL, 0);
if (flags < 0) return -1;
return lwip_fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
return lwip_fcntl(fd, F_SETFL,
static_cast<int>(static_cast<unsigned int>(flags) &
~static_cast<unsigned int>(O_NONBLOCK)));
}

/* ---------- Socket creation & connection ----------------------------------- */
Expand Down
8 changes: 6 additions & 2 deletions include/platform/posix/net_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ static inline int someip_set_nonblocking(someip_socket_t fd) {
if (flags < 0) {
return -1;
}
return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
return fcntl(fd, F_SETFL,
static_cast<int>(static_cast<unsigned int>(flags) |
static_cast<unsigned int>(O_NONBLOCK)));
}

/** @implements REQ_PAL_NET_BLOCK, REQ_PAL_NET_MODE_E01 */
Expand All @@ -55,7 +57,9 @@ static inline int someip_set_blocking(someip_socket_t fd) {
if (flags < 0) {
return -1;
}
return fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
return fcntl(fd, F_SETFL,
static_cast<int>(static_cast<unsigned int>(flags) &
~static_cast<unsigned int>(O_NONBLOCK)));
}

/* ---------- Socket creation & connection ----------------------------------- */
Expand Down
8 changes: 6 additions & 2 deletions include/platform/zephyr/net_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ static inline int someip_shutdown_socket(someip_socket_t fd) {
static inline int someip_set_nonblocking(someip_socket_t fd) {
int flags = zsock_fcntl(fd, ZVFS_F_GETFL, 0);
if (flags < 0) return -1;
return zsock_fcntl(fd, ZVFS_F_SETFL, flags | ZVFS_O_NONBLOCK);
return zsock_fcntl(fd, ZVFS_F_SETFL,
static_cast<int>(static_cast<unsigned int>(flags) |
static_cast<unsigned int>(ZVFS_O_NONBLOCK)));
}

static inline int someip_set_blocking(someip_socket_t fd) {
int flags = zsock_fcntl(fd, ZVFS_F_GETFL, 0);
if (flags < 0) return -1;
return zsock_fcntl(fd, ZVFS_F_SETFL, flags & ~ZVFS_O_NONBLOCK);
return zsock_fcntl(fd, ZVFS_F_SETFL,
static_cast<int>(static_cast<unsigned int>(flags) &
~static_cast<unsigned int>(ZVFS_O_NONBLOCK)));
}

/* ---------- Socket creation & connection ----------------------------------- */
Expand Down
12 changes: 6 additions & 6 deletions include/sd/sd_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,22 @@ class SdMessage {
bool deserialize(const std::vector<uint8_t>& data);

// Helper methods
bool is_reboot() const { return (flags_ & 0x80) != 0; }
bool is_unicast() const { return (flags_ & 0x40) != 0; }
bool is_reboot() const { return (static_cast<uint32_t>(flags_) & 0x80U) != 0; }
bool is_unicast() const { return (static_cast<uint32_t>(flags_) & 0x40U) != 0; }

void set_reboot(bool reboot) {
if (reboot) {
flags_ |= 0x80;
flags_ = static_cast<uint8_t>(static_cast<uint32_t>(flags_) | 0x80U);
} else {
flags_ &= ~0x80;
flags_ = static_cast<uint8_t>(static_cast<uint32_t>(flags_) & ~0x80U);
}
}

void set_unicast(bool unicast) {
if (unicast) {
flags_ |= 0x40;
flags_ = static_cast<uint8_t>(static_cast<uint32_t>(flags_) | 0x40U);
} else {
flags_ &= ~0x40;
flags_ = static_cast<uint8_t>(static_cast<uint32_t>(flags_) & ~0x40U);
}
}

Expand Down
8 changes: 4 additions & 4 deletions include/someip/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ struct MessageId {
MessageId(uint16_t service, uint16_t method) : service_id(service), method_id(method) {}

uint32_t to_uint32() const {
return (static_cast<uint32_t>(service_id) << 16) | method_id;
return (static_cast<uint32_t>(service_id) << 16) | static_cast<uint32_t>(method_id);
}

static MessageId from_uint32(uint32_t value) {
return MessageId(static_cast<uint16_t>(value >> 16), static_cast<uint16_t>(value & 0xFFFF));
return MessageId(static_cast<uint16_t>(value >> 16), static_cast<uint16_t>(value & 0xFFFFU));
}

bool operator==(const MessageId& other) const {
Expand All @@ -103,11 +103,11 @@ struct RequestId {
RequestId(uint16_t client, uint16_t session) : client_id(client), session_id(session) {}

uint32_t to_uint32() const {
return (static_cast<uint32_t>(client_id) << 16) | session_id;
return (static_cast<uint32_t>(client_id) << 16) | static_cast<uint32_t>(session_id);
}

static RequestId from_uint32(uint32_t value) {
return RequestId(static_cast<uint16_t>(value >> 16), static_cast<uint16_t>(value & 0xFFFF));
return RequestId(static_cast<uint16_t>(value >> 16), static_cast<uint16_t>(value & 0xFFFFU));
}

bool operator==(const RequestId& other) const {
Expand Down
2 changes: 1 addition & 1 deletion include/tp/tp_segmenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class TpSegmenter {
const std::vector<uint8_t>& payload,
std::vector<TpSegment>& segments);

void serialize_tp_header(std::vector<uint8_t>& payload, uint16_t offset, bool more_segments);
void serialize_tp_header(std::vector<uint8_t>& payload, uint32_t offset, bool more_segments);
MessageType add_tp_flag(MessageType type) const;
};

Expand Down
36 changes: 18 additions & 18 deletions src/e2e/e2e_crc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,41 @@ static constexpr uint8_t SAE_J1850_INIT = 0xFF;

/** @implements REQ_E2E_PLUGIN_004 */
uint8_t calculate_crc8_sae_j1850(const std::vector<uint8_t>& data) {
uint8_t crc = SAE_J1850_INIT;
uint32_t crc_reg = SAE_J1850_INIT;

for (uint8_t byte : data) {
crc ^= byte;
crc_reg ^= static_cast<uint32_t>(byte);
for (int i = 0; i < 8; ++i) {
if ((crc & 0x80) != 0) {
crc = (crc << 1) ^ SAE_J1850_POLY;
if ((crc_reg & 0x80U) != 0) {
crc_reg = ((crc_reg << 1U) ^ static_cast<uint32_t>(SAE_J1850_POLY)) & 0xFFU;
} else {
crc <<= 1;
crc_reg = (crc_reg << 1U) & 0xFFU;
}
}
}

return crc;
return static_cast<uint8_t>(crc_reg);
}

// ITU-T X.25 / CCITT CRC-16 polynomial: 0x1021 (x^16 + x^12 + x^5 + 1)
static constexpr uint16_t ITU_X25_POLY = 0x1021;
static constexpr uint16_t ITU_X25_INIT = 0xFFFF;

uint16_t calculate_crc16_itu_x25(const std::vector<uint8_t>& data) {
uint16_t crc = ITU_X25_INIT;
uint32_t crc_reg = ITU_X25_INIT;

for (uint8_t byte : data) {
crc ^= (static_cast<uint16_t>(byte) << 8);
crc_reg ^= static_cast<uint32_t>(byte) << 8U;
for (int i = 0; i < 8; ++i) {
if ((crc & 0x8000) != 0) {
crc = (crc << 1) ^ ITU_X25_POLY;
if ((crc_reg & 0x8000U) != 0) {
crc_reg = ((crc_reg << 1U) ^ static_cast<uint32_t>(ITU_X25_POLY)) & 0xFFFFU;
} else {
crc <<= 1;
crc_reg = (crc_reg << 1U) & 0xFFFFU;
}
}
}

return crc;
return static_cast<uint16_t>(crc_reg);
}

// CRC-32 polynomial: 0x04C11DB7 (IEEE 802.3)
Expand All @@ -81,12 +81,12 @@ 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;
uint32_t crc = i << 24U;
for (int j = 0; j < 8; ++j) {
if (crc & 0x80000000) {
crc = (crc << 1) ^ CRC32_POLY;
if (crc & 0x80000000U) {
crc = (crc << 1U) ^ CRC32_POLY;
} else {
crc <<= 1;
crc <<= 1U;
}
}
t[i] = crc;
Expand All @@ -104,8 +104,8 @@ uint32_t calculate_crc32(const std::vector<uint8_t>& data) {
uint32_t crc = CRC32_INIT;

for (uint8_t byte : data) {
uint32_t index = ((crc >> 24) ^ byte) & 0xFF;
crc = (crc << 8) ^ crc32_table[index];
uint32_t index = ((crc >> 24U) ^ static_cast<uint32_t>(byte)) & 0xFFU;
crc = (crc << 8U) ^ crc32_table[index];
}

return crc;
Expand Down
20 changes: 11 additions & 9 deletions src/e2e/e2e_profiles/standard_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class BasicE2EProfile : public E2EProfile {
auto now = std::chrono::steady_clock::now();
auto ms =
std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
freshness = static_cast<uint16_t>(ms & 0xFFFF);
freshness = static_cast<uint16_t>(static_cast<uint64_t>(ms) & 0xFFFFULL);
freshness_values_[config.data_id] = freshness;
}

Expand Down Expand Up @@ -185,11 +185,11 @@ class BasicE2EProfile : public E2EProfile {

uint32_t received_crc = header.crc;
if (config.crc_type == 0) { // 8-bit
received_crc &= 0xFF;
expected_crc &= 0xFF;
received_crc &= 0xFFU;
expected_crc &= 0xFFU;
} else if (config.crc_type == 1) { // 16-bit
received_crc &= 0xFFFF;
expected_crc &= 0xFFFF;
received_crc &= 0xFFFFU;
expected_crc &= 0xFFFFU;
}

if (received_crc != expected_crc) {
Expand Down Expand Up @@ -246,7 +246,7 @@ class BasicE2EProfile : public E2EProfile {
auto now = std::chrono::steady_clock::now();
auto ms_now = std::chrono::duration_cast<std::chrono::milliseconds>(
now.time_since_epoch()).count();
auto current_freshness = static_cast<uint16_t>(ms_now & 0xFFFF);
auto current_freshness = static_cast<uint16_t>(static_cast<uint64_t>(ms_now) & 0xFFFFULL);

// Calculate freshness difference (handle wrap-around)
// Since we're using 16-bit values, we need to handle wrap-around
Expand All @@ -258,14 +258,16 @@ class BasicE2EProfile : public E2EProfile {
freshness_diff = current_freshness - header.freshness_value;
} else {
// Wrap-around case - calculate how much time passed
freshness_diff = (0xFFFF - header.freshness_value) + current_freshness + 1;
freshness_diff = static_cast<uint16_t>((0xFFFFU - static_cast<uint32_t>(header.freshness_value)) +
static_cast<uint32_t>(current_freshness) + 1U);
}

// Convert timeout to 16-bit units (approximately)
// Since we're storing lower 16 bits of milliseconds,
// we compare against timeout_ms directly (assuming timeout < 65535 ms)
auto const timeout_units = static_cast<uint16_t>(config.freshness_timeout_ms);
if (freshness_diff > timeout_units && freshness_diff < (0xFFFF - timeout_units)) {
auto const timeout_units = static_cast<uint16_t>(
config.freshness_timeout_ms > 0xFFFFU ? 0xFFFFU : config.freshness_timeout_ms);
if (freshness_diff > timeout_units && freshness_diff < (0xFFFFU - timeout_units)) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
// If difference is large and not due to wrap-around, it's stale
return Result::TIMEOUT; // Stale data
}
Expand Down
14 changes: 7 additions & 7 deletions src/events/event_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace someip::events {
*/
class EventSubscriberImpl : public transport::ITransportListener {
public:
EventSubscriberImpl(uint16_t client_id)
explicit EventSubscriberImpl(uint16_t client_id)
: client_id_(client_id),
transport_(std::make_shared<transport::UdpTransport>(
transport::Endpoint("127.0.0.1", 0))),
Expand Down Expand Up @@ -112,8 +112,8 @@ class EventSubscriberImpl : public transport::ITransportListener {

// Add subscription data to payload
std::vector<uint8_t> payload;
payload.push_back((eventgroup_id >> 8) & 0xFF);
payload.push_back(eventgroup_id & 0xFF);
payload.push_back(static_cast<uint8_t>((static_cast<uint32_t>(eventgroup_id) >> 8U) & 0xFFU));
payload.push_back(static_cast<uint8_t>(static_cast<uint32_t>(eventgroup_id) & 0xFFU));
subscription_msg.set_payload(payload);

Result send_result = transport_->send_message(subscription_msg, service_endpoint);
Expand Down Expand Up @@ -146,8 +146,8 @@ class EventSubscriberImpl : public transport::ITransportListener {

// Add unsubscription data to payload
std::vector<uint8_t> payload;
payload.push_back((eventgroup_id >> 8) & 0xFF);
payload.push_back(eventgroup_id & 0xFF);
payload.push_back(static_cast<uint8_t>((static_cast<uint32_t>(eventgroup_id) >> 8U) & 0xFFU));
payload.push_back(static_cast<uint8_t>(static_cast<uint32_t>(eventgroup_id) & 0xFFU));
unsubscription_msg.set_payload(payload);

Result result = transport_->send_message(unsubscription_msg, service_endpoint);
Expand Down Expand Up @@ -181,8 +181,8 @@ class EventSubscriberImpl : public transport::ITransportListener {

// Add field ID to payload
std::vector<uint8_t> payload;
payload.push_back((event_id >> 8) & 0xFF);
payload.push_back(event_id & 0xFF);
payload.push_back(static_cast<uint8_t>((static_cast<uint32_t>(event_id) >> 8U) & 0xFFU));
payload.push_back(static_cast<uint8_t>(static_cast<uint32_t>(event_id) & 0xFFU));
field_msg.set_payload(payload);

return transport_->send_message(field_msg, service_endpoint) == Result::SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/rpc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace someip::rpc {
*/
class RpcClientImpl : public transport::ITransportListener {
public:
RpcClientImpl(uint16_t client_id)
explicit RpcClientImpl(uint16_t client_id)
: client_id_(client_id),
session_manager_(std::make_unique<SessionManager>()),
transport_(std::make_shared<transport::UdpTransport>(transport::Endpoint("127.0.0.1", 0))),
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace someip::rpc {
*/
class RpcServerImpl : public transport::ITransportListener {
public:
RpcServerImpl(uint16_t service_id)
explicit RpcServerImpl(uint16_t service_id)
: service_id_(service_id),
transport_(std::make_shared<transport::UdpTransport>(transport::Endpoint("127.0.0.1", 30490))),
running_(false) {
Expand Down
2 changes: 1 addition & 1 deletion src/sd/sd_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::shared_ptr<transport::UdpTransport> create_sd_transport(const SdConfig& con
*/
class SdClientImpl : public transport::ITransportListener {
public:
SdClientImpl(const SdConfig& config)
explicit SdClientImpl(const SdConfig& config)
: config_(config),
transport_(create_sd_transport(config)),
next_request_id_(1),
Expand Down
Loading
Loading