Skip to content

Commit a9c7c58

Browse files
henrikbrixandersencarlescufi
authored andcommitted
canbus: isotp: avoid reusing CAN controller driver API definitions
Avoid reusing the CAN_EXTENDED_IDENTIFIER and CAN_STANDARD_IDENTIFIER definitions from the CAN controller driver API for ISO-TP structure members as this is a fragile design. The ISO-TP layer must be responsible for its own definitions where needed. Replace the "id_type" ISO-TP struct member with a well-known abbreviated "ide" bit (Identifier Extension Bit) struct member. Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent 1a161b9 commit a9c7c58

File tree

5 files changed

+20
-20
lines changed
  • include/zephyr/canbus
  • samples/subsys/canbus/isotp/src
  • subsys/canbus/isotp
  • tests/subsys/canbus/isotp

5 files changed

+20
-20
lines changed

include/zephyr/canbus/isotp.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ struct isotp_msg_id {
146146
};
147147
/** ISO-TP extended address (if used) */
148148
uint8_t ext_addr;
149-
/** Indicates the CAN identifier type (standard or extended) */
150-
uint8_t id_type : 1;
149+
/** Indicates the CAN identifier type (0 for standard or 1 for extended) */
150+
uint8_t ide : 1;
151151
/** Indicates if ISO-TP extended addressing is used */
152152
uint8_t use_ext_addr : 1;
153153
/** Indicates if ISO-TP fixed addressing (acc. to SAE J1939) is used */

samples/subsys/canbus/isotp/src/main.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ const struct isotp_fc_opts fc_opts_0_5 = {.bs = 0, .stmin = 5};
1616

1717
const struct isotp_msg_id rx_addr_8_0 = {
1818
.std_id = 0x80,
19-
.id_type = CAN_STANDARD_IDENTIFIER,
19+
.ide = 0,
2020
.use_ext_addr = 0
2121
};
2222
const struct isotp_msg_id tx_addr_8_0 = {
2323
.std_id = 0x180,
24-
.id_type = CAN_STANDARD_IDENTIFIER,
24+
.ide = 0,
2525
.use_ext_addr = 0
2626
};
2727
const struct isotp_msg_id rx_addr_0_5 = {
2828
.std_id = 0x01,
29-
.id_type = CAN_STANDARD_IDENTIFIER,
29+
.ide = 0,
3030
.use_ext_addr = 0
3131
};
3232
const struct isotp_msg_id tx_addr_0_5 = {
3333
.std_id = 0x101,
34-
.id_type = CAN_STANDARD_IDENTIFIER,
34+
.ide = 0,
3535
.use_ext_addr = 0
3636
};
3737

subsys/canbus/isotp/isotp.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static inline uint32_t receive_get_sf_length(struct net_buf *buf)
119119
static void receive_send_fc(struct isotp_recv_ctx *ctx, uint8_t fs)
120120
{
121121
struct can_frame frame = {
122-
.id_type = ctx->tx_addr.id_type,
122+
.id_type = ctx->tx_addr.ide == 0 ? CAN_STANDARD_IDENTIFIER : CAN_EXTENDED_IDENTIFIER,
123123
.rtr = CAN_DATAFRAME,
124124
.id = ctx->tx_addr.ext_id
125125
};
@@ -571,7 +571,7 @@ static inline int attach_ff_filter(struct isotp_recv_ctx *ctx)
571571
}
572572

573573
struct can_filter filter = {
574-
.id_type = ctx->rx_addr.id_type,
574+
.id_type = ctx->rx_addr.ide == 0 ? CAN_STANDARD_IDENTIFIER : CAN_EXTENDED_IDENTIFIER,
575575
.rtr = CAN_DATAFRAME,
576576
.id = ctx->rx_addr.ext_id,
577577
.rtr_mask = 1,
@@ -866,7 +866,7 @@ static void pull_data_ctx(struct isotp_send_ctx *ctx, size_t len)
866866
static inline int send_sf(struct isotp_send_ctx *ctx)
867867
{
868868
struct can_frame frame = {
869-
.id_type = ctx->tx_addr.id_type,
869+
.id_type = ctx->tx_addr.ide == 0 ? CAN_STANDARD_IDENTIFIER : CAN_EXTENDED_IDENTIFIER,
870870
.rtr = CAN_DATAFRAME,
871871
.id = ctx->tx_addr.ext_id
872872
};
@@ -904,7 +904,7 @@ static inline int send_sf(struct isotp_send_ctx *ctx)
904904
static inline int send_ff(struct isotp_send_ctx *ctx)
905905
{
906906
struct can_frame frame = {
907-
.id_type = ctx->tx_addr.id_type,
907+
.id_type = ctx->tx_addr.ide == 0 ? CAN_STANDARD_IDENTIFIER : CAN_EXTENDED_IDENTIFIER,
908908
.rtr = CAN_DATAFRAME,
909909
.id = ctx->tx_addr.ext_id,
910910
.dlc = ISOTP_CAN_DL
@@ -946,7 +946,7 @@ static inline int send_ff(struct isotp_send_ctx *ctx)
946946
static inline int send_cf(struct isotp_send_ctx *ctx)
947947
{
948948
struct can_frame frame = {
949-
.id_type = ctx->tx_addr.id_type,
949+
.id_type = ctx->tx_addr.ide == 0 ? CAN_STANDARD_IDENTIFIER : CAN_EXTENDED_IDENTIFIER,
950950
.rtr = CAN_DATAFRAME,
951951
.id = ctx->tx_addr.ext_id,
952952
};
@@ -1129,7 +1129,7 @@ static void send_work_handler(struct k_work *item)
11291129
static inline int attach_fc_filter(struct isotp_send_ctx *ctx)
11301130
{
11311131
struct can_filter filter = {
1132-
.id_type = ctx->rx_addr.id_type,
1132+
.id_type = ctx->rx_addr.ide == 0 ? CAN_STANDARD_IDENTIFIER : CAN_EXTENDED_IDENTIFIER,
11331133
.rtr = CAN_DATAFRAME,
11341134
.id = ctx->rx_addr.ext_id,
11351135
.rtr_mask = 1,

tests/subsys/canbus/isotp/conformance/src/main.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -81,39 +81,39 @@ const struct isotp_fc_opts fc_opts_single = {
8181
};
8282
const struct isotp_msg_id rx_addr = {
8383
.std_id = 0x10,
84-
.id_type = CAN_STANDARD_IDENTIFIER,
84+
.ide = 0,
8585
.use_ext_addr = 0
8686
};
8787
const struct isotp_msg_id tx_addr = {
8888
.std_id = 0x11,
89-
.id_type = CAN_STANDARD_IDENTIFIER,
89+
.ide = 0,
9090
.use_ext_addr = 0
9191
};
9292

9393
const struct isotp_msg_id rx_addr_ext = {
9494
.std_id = 0x10,
95-
.id_type = CAN_STANDARD_IDENTIFIER,
95+
.ide = 0,
9696
.use_ext_addr = 1,
9797
.ext_addr = EXT_ADDR
9898
};
9999

100100
const struct isotp_msg_id tx_addr_ext = {
101101
.std_id = 0x11,
102-
.id_type = CAN_STANDARD_IDENTIFIER,
102+
.ide = 0,
103103
.use_ext_addr = 1,
104104
.ext_addr = EXT_ADDR
105105
};
106106

107107
const struct isotp_msg_id rx_addr_fixed = {
108108
.ext_id = 0x18DA0201,
109-
.id_type = CAN_EXTENDED_IDENTIFIER,
109+
.ide = 1,
110110
.use_ext_addr = 0,
111111
.use_fixed_addr = 1
112112
};
113113

114114
const struct isotp_msg_id tx_addr_fixed = {
115115
.ext_id = 0x18DA0102,
116-
.id_type = CAN_EXTENDED_IDENTIFIER,
116+
.ide = 1,
117117
.use_ext_addr = 0,
118118
.use_fixed_addr = 1
119119
};

tests/subsys/canbus/isotp/implementation/src/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ const struct isotp_fc_opts fc_opts_single = {
3737
};
3838
const struct isotp_msg_id rx_addr = {
3939
.std_id = 0x10,
40-
.id_type = CAN_STANDARD_IDENTIFIER,
40+
.ide = 0,
4141
.use_ext_addr = 0
4242
};
4343
const struct isotp_msg_id tx_addr = {
4444
.std_id = 0x11,
45-
.id_type = CAN_STANDARD_IDENTIFIER,
45+
.ide = 0,
4646
.use_ext_addr = 0
4747
};
4848

0 commit comments

Comments
 (0)