3131#define FC_PCI_BYTE_1 (FS ) ((FC_PCI_TYPE << PCI_TYPE_POS) | (FS))
3232#define FC_PCI_BYTE_2 (BS ) (BS)
3333#define FC_PCI_BYTE_3 (ST_MIN ) (ST_MIN)
34- #define DATA_SIZE_FC 3
3534#define CF_PCI_TYPE 2
3635#define CF_PCI_BYTE_1 (CF_PCI_TYPE << PCI_TYPE_POS)
3736#define STMIN_VAL_1 5
3837#define STMIN_VAL_2 50
3938#define STMIN_UPPER_TOLERANCE 5
4039
40+ #if defined(CONFIG_ISOTP_ENABLE_TX_PADDING ) || \
41+ defined(CONFIG_ISOTP_ENABLE_TX_PADDING )
42+ #define DATA_SIZE_FC CAN_DL
43+ #else
44+ #define DATA_SIZE_FC 3
45+ #endif
46+
4147#define CEIL (A , B ) (((A) + (B) - 1) / (B))
4248
4349#define BS_TIMEOUT_UPPER_MS 1100
@@ -167,6 +173,8 @@ static void get_sf(struct isotp_recv_ctx *recv_ctx, size_t data_size)
167173 zassert_equal (ret , 0 , "Data differ" );
168174}
169175
176+ #ifdef CONFIG_ISOTP_REQUIRE_RX_PADDING
177+
170178static void get_sf_ignore (struct isotp_recv_ctx * recv_ctx )
171179{
172180 int ret ;
@@ -175,6 +183,8 @@ static void get_sf_ignore(struct isotp_recv_ctx *recv_ctx)
175183 zassert_equal (ret , ISOTP_RECV_TIMEOUT , "recv returned %d" , ret );
176184}
177185
186+ #endif
187+
178188static void send_test_data (const uint8_t * data , size_t len )
179189{
180190 int ret ;
@@ -246,11 +256,18 @@ static void check_frame_series(struct frame_desired *frames, size_t length,
246256 zassert_equal (ret , 0 , "Timeout waiting for msg nr %d. ret: %d" ,
247257 i , ret );
248258
259+ #if !defined(CONFIG_ISOTP_REQUIRE_RX_PADDING ) && \
260+ !defined(CONFIG_ISOTP_ENABLE_TX_PADDING )
249261 zassert_equal (frame .dlc , desired -> length ,
250262 "DLC of frame nr %d differ. Desired: %d, Got: %d" ,
251263 i , desired -> length , frame .dlc );
264+ #endif
265+
266+ #if !defined(CONFIG_ISOTP_ENABLE_TX_PADDING )
252267 ret = check_data (frame .data , desired -> data , desired -> length );
253268 zassert_equal (ret , 0 , "Data differ" );
269+ #endif
270+
254271 desired ++ ;
255272 }
256273 ret = k_msgq_get (msgq , & frame , K_MSEC (200 ));
@@ -289,7 +306,9 @@ static void prepare_cf_frames(struct frame_desired *frames, size_t frames_cnt,
289306 memcpy (& des_frames [i ].data [1 ], data_ptr , DATA_SIZE_CF );
290307
291308 if (remaining_length < DATA_SIZE_CF ) {
309+ #ifndef CONFIG_ISOTP_ENABLE_TX_PADDING
292310 frames [i ].length = remaining_length + 1 ;
311+ #endif
293312 remaining_length = 0 ;
294313 }
295314
@@ -338,11 +357,13 @@ static void test_receive_sf(void)
338357 single_frame .data [0 ] = SF_PCI_BYTE_LEN_8 ;
339358 send_frame_series (& single_frame , 1 , rx_addr .std_id );
340359
360+ #ifdef CONFIG_ISOTP_REQUIRE_RX_PADDING
341361 single_frame .data [0 ] = SF_PCI_BYTE_1 ;
342362 single_frame .length = 7 ;
343363 send_frame_series (& single_frame , 1 , rx_addr .std_id );
344364
345365 get_sf_ignore (& recv_ctx );
366+ #endif
346367
347368 isotp_unbind (& recv_ctx );
348369}
@@ -392,11 +413,13 @@ static void test_receive_sf_ext(void)
392413 single_frame .data [1 ] = SF_PCI_BYTE_1 ;
393414 send_frame_series (& single_frame , 1 , rx_addr .std_id );
394415
416+ #ifdef CONFIG_ISOTP_REQUIRE_RX_PADDING
395417 single_frame .data [1 ] = SF_PCI_BYTE_2_EXT ;
396418 single_frame .length = 7 ;
397419 send_frame_series (& single_frame , 1 , rx_addr .std_id );
398420
399421 get_sf_ignore (& recv_ctx );
422+ #endif
400423
401424 isotp_unbind (& recv_ctx );
402425}
@@ -418,7 +441,7 @@ static void test_send_data(void)
418441 fc_frame .data [0 ] = FC_PCI_BYTE_1 (FC_PCI_CTS );
419442 fc_frame .data [1 ] = FC_PCI_BYTE_2 (0 );
420443 fc_frame .data [2 ] = FC_PCI_BYTE_3 (0 );
421- fc_frame .length = 3 ;
444+ fc_frame .length = DATA_SIZE_FC ;
422445
423446 prepare_cf_frames (des_frames , ARRAY_SIZE (des_frames ), data_ptr ,
424447 remaining_length );
@@ -457,7 +480,7 @@ static void test_send_data_blocks(void)
457480 fc_frame .data [0 ] = FC_PCI_BYTE_1 (FC_PCI_CTS );
458481 fc_frame .data [1 ] = FC_PCI_BYTE_2 (fc_opts .bs );
459482 fc_frame .data [2 ] = FC_PCI_BYTE_3 (0 );
460- fc_frame .length = 3 ;
483+ fc_frame .length = DATA_SIZE_FC ;
461484
462485 prepare_cf_frames (des_frames , ARRAY_SIZE (des_frames ), data_ptr ,
463486 remaining_length );
@@ -520,7 +543,7 @@ static void test_receive_data(void)
520543 fc_frame .data [0 ] = FC_PCI_BYTE_1 (FC_PCI_CTS );
521544 fc_frame .data [1 ] = FC_PCI_BYTE_2 (fc_opts_single .bs );
522545 fc_frame .data [2 ] = FC_PCI_BYTE_3 (fc_opts_single .stmin );
523- fc_frame .length = 3 ;
546+ fc_frame .length = DATA_SIZE_FC ;
524547
525548 prepare_cf_frames (des_frames , ARRAY_SIZE (des_frames ), data_ptr ,
526549 remaining_length );
@@ -564,7 +587,7 @@ static void test_receive_data_blocks(void)
564587 fc_frame .data [0 ] = FC_PCI_BYTE_1 (FC_PCI_CTS );
565588 fc_frame .data [1 ] = FC_PCI_BYTE_2 (fc_opts .bs );
566589 fc_frame .data [2 ] = FC_PCI_BYTE_3 (fc_opts .stmin );
567- fc_frame .length = 3 ;
590+ fc_frame .length = DATA_SIZE_FC ;
568591
569592 prepare_cf_frames (des_frames , ARRAY_SIZE (des_frames ), data_ptr ,
570593 remaining_length );
@@ -615,7 +638,7 @@ static void test_send_timeouts(void)
615638 fc_cts_frame .data [0 ] = FC_PCI_BYTE_1 (FC_PCI_CTS );
616639 fc_cts_frame .data [1 ] = FC_PCI_BYTE_2 (fc_opts .bs );
617640 fc_cts_frame .data [2 ] = FC_PCI_BYTE_3 (0 );
618- fc_cts_frame .length = 3 ;
641+ fc_cts_frame .length = DATA_SIZE_FC ;
619642
620643 /* Test timeout for first FC*/
621644 start_time = k_uptime_get_32 ();
@@ -716,7 +739,7 @@ static void test_stmin(void)
716739 fc_frame .data [0 ] = FC_PCI_BYTE_1 (FC_PCI_CTS );
717740 fc_frame .data [1 ] = FC_PCI_BYTE_2 (2 );
718741 fc_frame .data [2 ] = FC_PCI_BYTE_3 (STMIN_VAL_1 );
719- fc_frame .length = 3 ;
742+ fc_frame .length = DATA_SIZE_FC ;
720743
721744 filter_id = attach_msgq (rx_addr .std_id );
722745 zassert_true ((filter_id >= 0 ), "Negative filter number [%d]" ,
@@ -771,7 +794,7 @@ void test_receiver_fc_errors(void)
771794 fc_frame .data [0 ] = FC_PCI_BYTE_1 (FC_PCI_CTS );
772795 fc_frame .data [1 ] = FC_PCI_BYTE_2 (fc_opts .bs );
773796 fc_frame .data [2 ] = FC_PCI_BYTE_3 (fc_opts .stmin );
774- fc_frame .length = 3 ;
797+ fc_frame .length = DATA_SIZE_FC ;
775798
776799 filter_id = attach_msgq (tx_addr .std_id );
777800 zassert_true ((filter_id >= 0 ), "Negative filter number [%d]" ,
@@ -819,7 +842,7 @@ void test_sender_fc_errors(void)
819842 fc_frame .data [0 ] = FC_PCI_BYTE_1 (3 );
820843 fc_frame .data [1 ] = FC_PCI_BYTE_2 (fc_opts .bs );
821844 fc_frame .data [2 ] = FC_PCI_BYTE_3 (fc_opts .stmin );
822- fc_frame .length = 3 ;
845+ fc_frame .length = DATA_SIZE_FC ;
823846
824847 k_sem_reset (& send_compl_sem );
825848 ret = isotp_send (& send_ctx , can_dev , random_data , DATA_SEND_LENGTH ,
@@ -841,7 +864,7 @@ void test_sender_fc_errors(void)
841864 ret = isotp_send (& send_ctx , can_dev , random_data , 5 * 1024 ,
842865 & tx_addr , & rx_addr , NULL , NULL );
843866 zassert_equal (ret , ISOTP_N_BUFFER_OVERFLW ,
844- "Expected overflow bot got %d" , ret );
867+ "Expected overflow but got %d" , ret );
845868 isotp_unbind (& recv_ctx );
846869 filter_id = attach_msgq (tx_addr .std_id );
847870
0 commit comments