Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR to close #29 missing can isotp wait tx done flag to trigger a timeout #32

Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 11 additions & 7 deletions src/tp/isotp_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,21 @@ static int LinuxSockBind(const char *if_name, uint32_t rxid, uint32_t txid, bool
perror("setsockopt");
return -1;
}


struct can_isotp_options opts;
memset(&opts, 0, sizeof(opts));
// configure socket to wait for tx completion to catch FC frame timeouts
opts.flags |= CAN_ISOTP_WAIT_TX_DONE;

if (functional) {
printf("configuring fd: %d as functional\n", fd);
// configure the socket as listen-only to avoid sending FC frames
struct can_isotp_options opts;
memset(&opts, 0, sizeof(opts));
opts.flags |= CAN_ISOTP_LISTEN_MODE;
if (setsockopt(fd, SOL_CAN_ISOTP, CAN_ISOTP_OPTS, &opts, sizeof(opts)) < 0) {
perror("setsockopt (isotp_options):");
return -1;
}
}

if (setsockopt(fd, SOL_CAN_ISOTP, CAN_ISOTP_OPTS, &opts, sizeof(opts)) < 0) {
perror("setsockopt (isotp_options):");
return -1;
}

struct ifreq ifr;
Expand Down
18 changes: 18 additions & 0 deletions test/test_tp_compliance.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,31 @@ void TestISOTPSendRecvMaxLen(void **state) {
assert_memory_equal(UDSTpGetRecvBuf(srv, NULL), MSG, sizeof(MSG));
}

void TestISOTPFlowControlFrameTimeout(void **state) {
if (!IsISOTP()) {
skip();
}

// killing server so that no response is sent to client
ENV_TpFree(srv);
Copy link
Author

@muehlke muehlke Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added ENV_TpFree(srv); because for the test it is necessary that no server responds to the request so that we can get the desired timeout on the ISOTP socket. Because of the timeout error, the value of ret is <0, which was not the case before the flag was set on the socket.


// sending multiframe to wait for Flow Control frame
// which will not arrive since no server is running
const uint8_t MSG[] = {1, 2, 3, 4, 5, 6, 7, 8};
ssize_t ret = UDSTpSend(client, MSG, sizeof(MSG), NULL);

// failure is expected as the elapsed 1s timeout raises an error on the ISOTP socket
assert_true(ret < 0);
}

int main() {
const struct CMUnitTest tests[] = {
// cmocka_unit_test_setup_teardown(TestSendRecv, setup, teardown),
cmocka_unit_test_setup_teardown(TestSendRecvFunctional, setup, teardown),
cmocka_unit_test_setup_teardown(TestISOTPSendLargestSingleFrame, setup, teardown),
cmocka_unit_test_setup_teardown(TestISOTPSendLargerThanSingleFrameFails, setup, teardown),
cmocka_unit_test_setup_teardown(TestISOTPSendRecvMaxLen, setup, teardown),
cmocka_unit_test_setup_teardown(TestISOTPFlowControlFrameTimeout, setup, teardown),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}