Skip to content

Commit

Permalink
Merge pull request #32 from muehlke/29-missing-can-isotp-wait-tx-done…
Browse files Browse the repository at this point in the history
…-flag-to-trigger-a-timeout

PR to close #29 missing can isotp wait tx done flag to trigger a timeout
  • Loading branch information
driftregion authored Jul 10, 2024
2 parents 8eaa0de + ec5e2a6 commit 24c60fd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Nick James Kirkby <iso14229dev@gmail.com>
Mark Corbin <mcorbin@lunarenergy.com>
Jens Fernández Mühlke <fernandezjens@gmail.com>
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);

// 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);
}

0 comments on commit 24c60fd

Please sign in to comment.