@@ -110,6 +110,20 @@ const struct isotp_msg_id tx_addr_ext = {
110110 .ext_addr = EXT_ADDR
111111};
112112
113+ const struct isotp_msg_id rx_addr_fixed = {
114+ .ext_id = 0x18DA0201 ,
115+ .id_type = CAN_EXTENDED_IDENTIFIER ,
116+ .use_ext_addr = 0 ,
117+ .use_fixed_addr = 1
118+ };
119+
120+ const struct isotp_msg_id tx_addr_fixed = {
121+ .ext_id = 0x18DA0102 ,
122+ .id_type = CAN_EXTENDED_IDENTIFIER ,
123+ .use_ext_addr = 0 ,
124+ .use_fixed_addr = 1
125+ };
126+
113127const struct device * can_dev ;
114128struct isotp_recv_ctx recv_ctx ;
115129struct isotp_send_ctx send_ctx ;
@@ -173,8 +187,6 @@ static void get_sf(struct isotp_recv_ctx *recv_ctx, size_t data_size)
173187 zassert_equal (ret , 0 , "Data differ" );
174188}
175189
176- #ifdef CONFIG_ISOTP_REQUIRE_RX_PADDING
177-
178190static void get_sf_ignore (struct isotp_recv_ctx * recv_ctx )
179191{
180192 int ret ;
@@ -183,8 +195,6 @@ static void get_sf_ignore(struct isotp_recv_ctx *recv_ctx)
183195 zassert_equal (ret , ISOTP_RECV_TIMEOUT , "recv returned %d" , ret );
184196}
185197
186- #endif
187-
188198static void send_test_data (const uint8_t * data , size_t len )
189199{
190200 int ret ;
@@ -229,7 +239,8 @@ static void send_frame_series(struct frame_desired *frames, size_t length,
229239{
230240 int i , ret ;
231241 struct zcan_frame frame = {
232- .id_type = CAN_STANDARD_IDENTIFIER ,
242+ .id_type = (id > 0x7FF ) ? CAN_EXTENDED_IDENTIFIER :
243+ CAN_STANDARD_IDENTIFIER ,
233244 .rtr = CAN_DATAFRAME ,
234245 .id = id
235246 };
@@ -274,15 +285,16 @@ static void check_frame_series(struct frame_desired *frames, size_t length,
274285 zassert_equal (ret , - EAGAIN , "Expected timeout, but received %d" , ret );
275286}
276287
277- static int attach_msgq (uint32_t id )
288+ static int attach_msgq (uint32_t id , uint32_t mask )
278289{
279290 int filter_id ;
280291 struct zcan_filter filter = {
281- .id_type = CAN_STANDARD_IDENTIFIER ,
292+ .id_type = (id > 0x7FF ) ? CAN_EXTENDED_IDENTIFIER :
293+ CAN_STANDARD_IDENTIFIER ,
282294 .rtr = CAN_DATAFRAME ,
283295 .id = id ,
284296 .rtr_mask = 1 ,
285- .id_mask = CAN_STD_ID_MASK
297+ .id_mask = mask
286298 };
287299
288300 filter_id = can_attach_msgq (can_dev , & frame_msgq , & filter );
@@ -326,7 +338,7 @@ static void test_send_sf(void)
326338 memcpy (& des_frame .data [1 ], random_data , DATA_SIZE_SF );
327339 des_frame .length = DATA_SIZE_SF + 1 ;
328340
329- filter_id = attach_msgq (rx_addr .std_id );
341+ filter_id = attach_msgq (rx_addr .std_id , CAN_STD_ID_MASK );
330342 zassert_true ((filter_id >= 0 ), "Negative filter number [%d]" ,
331343 filter_id );
332344
@@ -378,7 +390,7 @@ static void test_send_sf_ext(void)
378390 memcpy (& des_frame .data [2 ], random_data , DATA_SIZE_SF_EXT );
379391 des_frame .length = DATA_SIZE_SF_EXT + 2 ;
380392
381- filter_id = attach_msgq (rx_addr_ext .std_id );
393+ filter_id = attach_msgq (rx_addr_ext .std_id , CAN_STD_ID_MASK );
382394 zassert_true ((filter_id >= 0 ), "Negative filter number [%d]" ,
383395 filter_id );
384396
@@ -424,6 +436,62 @@ static void test_receive_sf_ext(void)
424436 isotp_unbind (& recv_ctx );
425437}
426438
439+ static void test_send_sf_fixed (void )
440+ {
441+ int filter_id , ret ;
442+ struct frame_desired des_frame ;
443+
444+ des_frame .data [0 ] = SF_PCI_BYTE_1 ;
445+ memcpy (& des_frame .data [1 ], random_data , DATA_SIZE_SF );
446+ des_frame .length = DATA_SIZE_SF + 1 ;
447+
448+ /* mask to allow any priority and source address (SA) */
449+ filter_id = attach_msgq (rx_addr_fixed .ext_id , 0x03FFFF00 );
450+ zassert_true ((filter_id >= 0 ), "Negative filter number [%d]" ,
451+ filter_id );
452+
453+ ret = isotp_send (& send_ctx , can_dev , random_data , DATA_SIZE_SF ,
454+ & rx_addr_fixed , & tx_addr_fixed , send_complette_cb ,
455+ ISOTP_N_OK );
456+ zassert_equal (ret , 0 , "Send returned %d" , ret );
457+
458+ check_frame_series (& des_frame , 1 , & frame_msgq );
459+
460+ can_detach (can_dev , filter_id );
461+ }
462+
463+ static void test_receive_sf_fixed (void )
464+ {
465+ int ret ;
466+ struct frame_desired single_frame ;
467+
468+ single_frame .data [0 ] = SF_PCI_BYTE_1 ;
469+ memcpy (& single_frame .data [1 ], random_data , DATA_SIZE_SF );
470+ single_frame .length = DATA_SIZE_SF + 1 ;
471+
472+ ret = isotp_bind (& recv_ctx , can_dev , & rx_addr_fixed , & tx_addr_fixed ,
473+ & fc_opts_single , K_NO_WAIT );
474+ zassert_equal (ret , ISOTP_N_OK , "Binding failed [%d]" , ret );
475+
476+ /* default source address */
477+ send_frame_series (& single_frame , 1 , rx_addr_fixed .ext_id );
478+ get_sf (& recv_ctx , DATA_SIZE_SF );
479+
480+ /* different source address */
481+ send_frame_series (& single_frame , 1 , rx_addr_fixed .ext_id | 0xFF );
482+ get_sf (& recv_ctx , DATA_SIZE_SF );
483+
484+ /* different priority */
485+ send_frame_series (& single_frame , 1 , rx_addr_fixed .ext_id | (7U << 26 ));
486+ get_sf (& recv_ctx , DATA_SIZE_SF );
487+
488+ /* different target address (should fail) */
489+ send_frame_series (& single_frame , 1 , rx_addr_fixed .ext_id | 0xFF00 );
490+ get_sf_ignore (& recv_ctx );
491+
492+ isotp_unbind (& recv_ctx );
493+ }
494+
427495static void test_send_data (void )
428496{
429497 struct frame_desired fc_frame , ff_frame ;
@@ -446,7 +514,7 @@ static void test_send_data(void)
446514 prepare_cf_frames (des_frames , ARRAY_SIZE (des_frames ), data_ptr ,
447515 remaining_length );
448516
449- filter_id = attach_msgq (rx_addr .std_id );
517+ filter_id = attach_msgq (rx_addr .std_id , CAN_STD_ID_MASK );
450518 zassert_true ((filter_id >= 0 ), "Negative filter number [%d]" ,
451519 filter_id );
452520
@@ -487,7 +555,7 @@ static void test_send_data_blocks(void)
487555
488556 remaining_length = DATA_SEND_LENGTH ;
489557
490- filter_id = attach_msgq (rx_addr .std_id );
558+ filter_id = attach_msgq (rx_addr .std_id , CAN_STD_ID_MASK );
491559 zassert_true ((filter_id >= 0 ), "Negative filter number [%d]" ,
492560 filter_id );
493561
@@ -548,7 +616,7 @@ static void test_receive_data(void)
548616 prepare_cf_frames (des_frames , ARRAY_SIZE (des_frames ), data_ptr ,
549617 remaining_length );
550618
551- filter_id = attach_msgq (tx_addr .std_id );
619+ filter_id = attach_msgq (tx_addr .std_id , CAN_STD_ID_MASK );
552620
553621 ret = isotp_bind (& recv_ctx , can_dev , & rx_addr , & tx_addr ,
554622 & fc_opts_single , K_NO_WAIT );
@@ -594,7 +662,7 @@ static void test_receive_data_blocks(void)
594662
595663 remaining_frames = CEIL (remaining_length , DATA_SIZE_CF );
596664
597- filter_id = attach_msgq (tx_addr .std_id );
665+ filter_id = attach_msgq (tx_addr .std_id , CAN_STD_ID_MASK );
598666 zassert_true ((filter_id >= 0 ), "Negative filter number [%d]" ,
599667 filter_id );
600668
@@ -741,7 +809,7 @@ static void test_stmin(void)
741809 fc_frame .data [2 ] = FC_PCI_BYTE_3 (STMIN_VAL_1 );
742810 fc_frame .length = DATA_SIZE_FC ;
743811
744- filter_id = attach_msgq (rx_addr .std_id );
812+ filter_id = attach_msgq (rx_addr .std_id , CAN_STD_ID_MASK );
745813 zassert_true ((filter_id >= 0 ), "Negative filter number [%d]" ,
746814 filter_id );
747815
@@ -796,7 +864,7 @@ void test_receiver_fc_errors(void)
796864 fc_frame .data [2 ] = FC_PCI_BYTE_3 (fc_opts .stmin );
797865 fc_frame .length = DATA_SIZE_FC ;
798866
799- filter_id = attach_msgq (tx_addr .std_id );
867+ filter_id = attach_msgq (tx_addr .std_id , CAN_STD_ID_MASK );
800868 zassert_true ((filter_id >= 0 ), "Negative filter number [%d]" ,
801869 filter_id );
802870
@@ -836,7 +904,7 @@ void test_sender_fc_errors(void)
836904 memcpy (& ff_frame .data [2 ], random_data , DATA_SIZE_FF );
837905 ff_frame .length = DATA_SIZE_FF + 2 ;
838906
839- filter_id = attach_msgq (tx_addr .std_id );
907+ filter_id = attach_msgq (tx_addr .std_id , CAN_STD_ID_MASK );
840908
841909 /* invalid flow status */
842910 fc_frame .data [0 ] = FC_PCI_BYTE_1 (3 );
@@ -866,7 +934,7 @@ void test_sender_fc_errors(void)
866934 zassert_equal (ret , ISOTP_N_BUFFER_OVERFLW ,
867935 "Expected overflow but got %d" , ret );
868936 isotp_unbind (& recv_ctx );
869- filter_id = attach_msgq (tx_addr .std_id );
937+ filter_id = attach_msgq (tx_addr .std_id , CAN_STD_ID_MASK );
870938
871939 k_sem_reset (& send_compl_sem );
872940 ret = isotp_send (& send_ctx , can_dev , random_data , DATA_SEND_LENGTH ,
@@ -918,6 +986,8 @@ void test_main(void)
918986 ztest_unit_test (test_receive_sf ),
919987 ztest_unit_test (test_send_sf_ext ),
920988 ztest_unit_test (test_receive_sf_ext ),
989+ ztest_unit_test (test_send_sf_fixed ),
990+ ztest_unit_test (test_receive_sf_fixed ),
921991 ztest_unit_test (test_send_data ),
922992 ztest_unit_test (test_send_data_blocks ),
923993 ztest_unit_test (test_receive_data ),
0 commit comments