Commit 508048a3 authored by Elemer Lelik's avatar Elemer Lelik
Browse files

bugfixes and new test cases

parent 403f5b67
......@@ -7,3 +7,111 @@ https://projects.eclipse.org/projects/tools.titan
The source code of the TTCN-3 compiler and executor:
https://github.com/eclipse/titan.core
References:
https://www.kernel.org/doc/Documentation/networking/can.txt
Other useful documentation:
https://docs.python.org/3/library/socket.html (search for: "AF_CAN")
https://media.readthedocs.org/pdf/python-can/latest/python-can.pdf
http%3A%2F%2Fwww.can-cia.de%2Ffileadmin%2Fresources%2Fdocuments%2Fproceedings%2F2012_hartkopp.pdf
http://www.can-cia.de/fileadmin/resources/documents/proceedings/2012_hartkopp.pdf
http://v2.can-newsletter.org/uploads/media/raw/46c15d02e1fdd3b04e671693ec548ff7.pdf
# See file: src/initscript.sh:
#--------------------------------------
#!/bin/bash
# Add vcan module to kernel
sudo modprobe vcan
# Setup of virtual can vcan0
sudo ip link add dev vcan0 type vcan
# set it up at as a canfd can interface
sudo ip link set vcan0 mtu 72
sudo ip link set vcan0 up
# Setup of virtual can vcan1
sudo ip link add dev vcan1 type vcan
sudo ip link set vcan1 up
# example configuration of a physical can bus interface
#sudo ip link set can0 up type can bitrate 1000000
ifconfig
#--------------------------------------
cd src
./demo/initscript.sh
or alternatively
source demo/initscript.sh
make clean; make
ttcn3_start SocketCAN SocketCAN.cfg
or to run a certain testcase:
ttcn3_start SocketCAN SocketCAN.cfg SocketCANtest.tc_can_raw1 SocketCANtest.tc_can_bcm1
Review the newly created log files in the src directory
and use e.g. Wireshark to trace the CAN interfacce.
#--------------------------------------
Notes:
-Using multiple Test interfacces:
Currently the init script sets up multiple virtual can interfaces ("vcan0",
"vcan1" in oder to allow using multiple CAN interfaces.
The CAN interfaces have to be defined in the TTCN configuration files or may
alternatively be defined in the optional parameters of port messages commands
ioctl and send_data.
Handling of multiple CAN interfaces is work in progress and no test cases are
provided. In order to configure usage with multiple test interfaces,
test interfaces for each interface have to be defined in the MTC.
-CAN RAW:
CAN and CANFD has been implemented and tested.
Depending on the availability of the C-code #define "CAN_FD_FRAME"
in /usr/include/linux/can/bcm.h, CAN-FD support is enabled at compile time.
If you kernel does not have CANFD support comment out the #define "CAN_FD_FRAME
the file "src/SocketCAN_PT.cc"
The RAW setsockopt has path coverage. However no test coverage that insures
the setsockopt functionality provided by the kernel is working correctly.
For this purpose in the future might be added additional test cases.
-CAN BCM:
TX_SETUP, TX_DELETE have been tested, TX_READ is known to fail test cases.
Some tests have indicated, that that SocketCAN BCM does not support concurrently
active BCM channels.
The BCM has test coverage for TX_SETUP and TX_DELETE.
Return values other than the error code by the BCM are not yet supported.
-ISOTP:
Iso TP functionality has been added, however currently no options like padding
are supported. Feel free to request needed options.
First install the isotp kernel module as descibed here:
https://github.com/hartkopp/can-isotp-modules
./make_isotp.sh
sudo insmod ./can-isotp.ko
There is an endlessly running test case:
ttcn3_start SocketCAN SocketCAN.cfg Isotptest.tc_Isotp_Example001
-Merging of logfiles:
To merge the logfies from multiple Parallel Test Componets (PTCs) from a
single run in timely order into sigle file, run in demo directory:
$ ./merge.sh
the merged and pretty printed log file is found in "demo/log_merged_pretty.txt"
-Dunping CAN Frames using SocketCAN:
To dump all received can frames of e.g. "vcan0" run a seperate terminal:
$ candump "vcan0"
......@@ -171,7 +171,6 @@ function f_close_socket(in SocketCAN_socketid p_socket_id)
runs on PTC_isotp_CT {
pt_socketCAN.send(SocketCAN_close:{id:= p_socket_id});
}
function f_send_isotp_message(in SocketCAN_socketid p_socket_id,
in octetstring p_pdu)
runs on PTC_isotp_CT{
......
......@@ -28,7 +28,8 @@ LogEventTypes:= Yes
[EXECUTE]
//CAN RAW tests
SocketCAN_RAW_test.tc_can_raw_send_and_receive_frame
SocketCAN_RAW_test.tc_can_raw_send_and_receive_can_frame
SocketCAN_RAW_test.tc_can_raw_send_and_receive_canfd_frame
SocketCAN_RAW_test.tc_can_raw_setsockopt_CAN_RAW_FILTER
SocketCAN_RAW_test.tc_can_raw_setsockopt_CAN_RAW_ERR_FILTER
SocketCAN_RAW_test.tc_can_raw_setsockopt_CAN_RAW_LOOPBACK
......@@ -36,6 +37,7 @@ SocketCAN_RAW_test.tc_can_raw_setsockopt_CAN_RAW_RECV_OWN_MSGS
SocketCAN_RAW_test.tc_can_raw_setsockopt_CAN_RAW_FD_FRAMES
SocketCAN_RAW_test.tc_can_raw_setsockopt_CAN_RAW_JOIN_FILTERS
//CAN BCM tests
SocketCAN_BCM_test.tc_can_bcm_TX_SETUP_TX_DELETE
SocketCAN_BCM_test.tc_can_bcm_TX_SETUP_TX_DELETE_can_frame
// broken CAN BCM tests:
//SocketCAN_BCM_test.tc_can_bcm_TX_SETUP_TX_DELETE_TX_READ__broken
SocketCAN_BCM_test.tc_can_bcm_TX_SETUP_TX_DELETE_canfd_frame
//SocketCAN_BCM_test.tc_can_bcm_TX_SETUP_TX_READ
......@@ -21,7 +21,7 @@ import from Can all
template SocketCAN_CAN_or_CAN_FD_frame a_CAN_frame (template CAN_frame p_can_frame) := {can_frame := p_can_frame}
testcase tc_can_bcm_TX_SETUP_TX_DELETE() runs on MTC {
testcase tc_can_bcm_TX_SETUP_TX_DELETE_can_frame() runs on MTC {
// here are 5 CAN frames cyclicly started with TX_SETUP (can_id = 66), but after receiving
// a sequnce of 10 frames the cyclic sending of the frames is stopped with TX_DELETE (can id = 66).
......@@ -37,6 +37,7 @@ testcase tc_can_bcm_TX_SETUP_TX_DELETE() runs on MTC {
connect(mtc:pt_sync, v_ptc_rawFrameReceiver2:pt_sync)
var CAN_frame v_can_frame1, v_can_frame2, v_can_frame3, v_can_frame4, v_can_frame5;
var CANFD_frame v_canfd_frame1
var SocketCAN_bcm_frame v_bcm_activation_frame, v_bcm_deactivation_frame
......@@ -121,8 +122,7 @@ testcase tc_can_bcm_TX_SETUP_TX_DELETE() runs on MTC {
all component.kill;
}
testcase tc_can_bcm_TX_SETUP_TX_DELETE_TX_READ__broken() runs on MTC {
testcase tc_can_bcm_TX_SETUP_TX_DELETE_canfd_frame() runs on MTC {
// here are 5 CAN frames cyclicly started with TX_SETUP (can_id = 66), but after receiving
// a sequnce of 10 frames the cyclic sending of the frames is stopped with TX_DELETE (can id = 66).
......@@ -137,8 +137,131 @@ testcase tc_can_bcm_TX_SETUP_TX_DELETE_TX_READ__broken() runs on MTC {
connect(mtc:pt_sync, v_ptc_rawFrameReceiver1:pt_sync)
connect(mtc:pt_sync, v_ptc_rawFrameReceiver2:pt_sync)
var CAN_frame v_can_frame1, v_can_frame2, v_can_frame3, v_can_frame4, v_can_frame5;
var CANFD_frame v_canfd_frame1, v_canfd_frame2, v_canfd_frame3, v_canfd_frame4, v_canfd_frame5
var SocketCAN_bcm_frame v_bcm_activation_frame, v_bcm_deactivation_frame
v_canfd_frame1 :=
{can_id := '00000011'O,
can_flags := '10101010'B,
can_pdu := '1111111111111111'O
};
v_canfd_frame2 :=
{can_id := '00000012'O,
can_flags := '10101010'B,
can_pdu := '22222222222222222222222222222222'O
};
v_canfd_frame3 :=
{can_id := '00000013'O,
can_flags := '10101010'B,
can_pdu := '4444444444444444444444444444444444444444444444444444444444444444'O
};
v_canfd_frame4 :=
{can_id := '00000014'O,
can_flags := '10101010'B,
can_pdu := '55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555'O
};
v_canfd_frame5 :=
{can_id := '00000015'O,
can_flags := '01010101'B,
can_pdu := '0123'O
};
template SocketCAN_CAN_or_CAN_FD_frames a_expected_can_frames := {
{canfd_frame := v_canfd_frame1},
{canfd_frame := v_canfd_frame2},
{canfd_frame := v_canfd_frame3},
{canfd_frame := v_canfd_frame4},
{canfd_frame := v_canfd_frame5}
}
v_bcm_activation_frame := {
opcode := '00000001'O, // TX_SETUP
flags := '00000000000000000000000000000011'B, // refers to SETTIMER | STARTTIMER
// CAN_FD_FRAME flag is automatically set the
// test port for CANFD frames
count := 0,
ival1 := {0, 0},
ival2 := {0, 100000},
can_id := '00000042'O, // should become octetstring in the future
frames := {canfd_frame := {
v_canfd_frame1,
v_canfd_frame2,
v_canfd_frame3,
v_canfd_frame4,
v_canfd_frame5}}
}
v_bcm_deactivation_frame := {
opcode := '00000002'O, // TX_DELETE
flags := '00001000000000000000000000000000'B,
// CAN_FD_FRAME flag is automatically set the
// test port for CANFD frames
count := 0,
ival1 := {0, 0},
ival2 := {0, 0},
can_id := '00000042'O,
frames := {canfd_frame := {}} // needs to be canfd-frame here, to stop canfd frames
}
var BCM_cmds v_cmds :=
{
{phase := e_testbody2, bcm_frame := v_bcm_activation_frame},
{phase := e_testbody5, bcm_frame := v_bcm_deactivation_frame}
}
v_ptc_bcmConfigurator.start(f_ptc_bcmComandSendInitiator(v_cmds))
var SocketCAN_CAN_or_CAN_FD_frame v_frame_to_receive1
v_frame_to_receive1 := {canfd_frame := v_canfd_frame1}
// stop when receiving v_frame_to_receive
v_ptc_rawFrameReceiver1.start(f_ptc_RawFrameReceiver(e_testbody3, v_frame_to_receive1))
// stop when receiving v_frame_to_receive
v_ptc_rawFrameReceiver2.start(f_ptc_RawFrameSequenceReceiver(e_testbody4, a_expected_can_frames, e_testbody5, 2.0))
var e_Phase v_phase
for(v_phase := c_firstPhase; v_phase < e_testcase_complete; v_phase := f_incMTCPhase(v_phase)) {
f_startPhase(v_phase)
log("MTC: ", v_phase)
f_awaitEndPhase(v_phase)
}
all component.done;
log("MTC done")
disconnect(mtc:pt_sync, v_ptc_bcmConfigurator:pt_sync)
disconnect(mtc:pt_sync, v_ptc_rawFrameReceiver1:pt_sync)
disconnect(mtc:pt_sync, v_ptc_rawFrameReceiver2:pt_sync)
all component.kill;
}
testcase tc_can_bcm_TX_SETUP_TX_READ() runs on MTC {
// here are 5 CAN frames cyclicly started with TX_SETUP (can_id = 66), then with TX_READ the status is read
var PTC v_ptc_bcmConfigurator := PTC.create("PTC1_ptc_bcmConfigurator") alive
var PTC v_ptc_rawFrameReceiver1 := PTC.create("PTC2_ptc_rawFrameReceiver1") alive
f_addSyncSlaveSet(v_ptc_bcmConfigurator, v_PTCSet)
f_addSyncSlaveSet(v_ptc_rawFrameReceiver1, v_PTCSet)
connect(mtc:pt_sync, v_ptc_bcmConfigurator:pt_sync)
connect(mtc:pt_sync, v_ptc_rawFrameReceiver1:pt_sync)
var CAN_frame v_can_frame1, v_can_frame2, v_can_frame3, v_can_frame4, v_can_frame5;
var CANFD_frame v_canfd_frame1
var SocketCAN_bcm_frame v_bcm_activation_frame, v_bcm_deactivation_frame, v_bcm_read_status_frame
v_can_frame1 := {can_id := '00000001'O, can_pdu := '1111111111111111'O};
......@@ -147,20 +270,7 @@ testcase tc_can_bcm_TX_SETUP_TX_DELETE_TX_READ__broken() runs on MTC {
v_can_frame4 := {can_id := '00000004'O, can_pdu := '4444444444444444'O};
v_can_frame5 := {can_id := '00000005'O, can_pdu := '5555555555555555'O};
template SocketCAN_CAN_or_CAN_FD_frames a_expected_can_frames := {
{can_frame := v_can_frame1},
{can_frame := v_can_frame2},
{can_frame := v_can_frame3},
{can_frame := v_can_frame4},
{can_frame := v_can_frame5},
{can_frame := v_can_frame1},
{can_frame := v_can_frame2},
{can_frame := v_can_frame3},
{can_frame := v_can_frame4},
{can_frame := v_can_frame5}
}
v_bcm_activation_frame := {
v_bcm_activation_frame := {
opcode := '00000001'O, // TX_SETUP
flags := '00000000000000000000000000000011'B, // refers to SETTIMER | STARTTIMER
count := 0,
......@@ -175,16 +285,6 @@ v_bcm_activation_frame := {
v_can_frame5}}
}
v_bcm_deactivation_frame := {
opcode := '00000002'O, // TX_DELETE
flags := '00000000000000000000000000000000'B,
count := 0,
ival1 := {0, 0},
ival2 := {0, 0},
can_id := '00000042'O,
frames := {can_frame := {}}
}
v_bcm_read_status_frame := {
opcode := '00000003'O, // TX_READ
flags :=
......@@ -202,23 +302,17 @@ v_bcm_activation_frame := {
var BCM_cmds v_cmds :=
{
//{phase := e_testbody2, bcm_frame := v_bcm_activation_frame},
{phase := e_testbody3, bcm_frame := v_bcm_read_status_frame},
{phase := e_testbody4, bcm_frame := v_bcm_deactivation_frame},
{phase := e_testbody6, bcm_frame := v_bcm_read_status_frame}
{phase := e_testbody1, bcm_frame := v_bcm_activation_frame},
{phase := e_testbody3, bcm_frame := v_bcm_read_status_frame}
}
v_ptc_bcmConfigurator.start(f_ptc_bcmComandSendReceiveInitiator(v_cmds))
var SocketCAN_CAN_or_CAN_FD_frame v_frame_to_receive1, v_frame_to_receive5
var SocketCAN_CAN_or_CAN_FD_frame v_frame_to_receive1
v_frame_to_receive1 := {can_frame := v_can_frame1}
v_frame_to_receive5 := {can_frame := v_can_frame5}
// stop when receiving v_frame_to_receive
v_ptc_rawFrameReceiver1.start(f_ptc_RawFrameReceiver(e_testbody3, v_frame_to_receive1))
// stop when receiving v_frame_to_receive
v_ptc_rawFrameReceiver2.start(f_ptc_RawFrameSequenceReceiver(e_testbody5, a_expected_can_frames, e_testbody6, 2.0))
v_ptc_rawFrameReceiver1.start(f_ptc_RawFrameReceiver(e_testbody1, v_frame_to_receive1))
var e_Phase v_phase
......@@ -234,7 +328,6 @@ v_bcm_activation_frame := {
disconnect(mtc:pt_sync, v_ptc_bcmConfigurator:pt_sync)
disconnect(mtc:pt_sync, v_ptc_rawFrameReceiver1:pt_sync)
disconnect(mtc:pt_sync, v_ptc_rawFrameReceiver2:pt_sync)
all component.kill;
}
......
......@@ -22,7 +22,7 @@ import from Can all
import from Raw all
import from CanError all
testcase tc_can_raw_send_and_receive_frame() runs on MTC {
testcase tc_can_raw_send_and_receive_can_frame() runs on MTC {
var PTC v_ptc_rawSendInitiator := PTC.create("PTC1_ptc_rawSendInitiator") alive
var PTC v_ptc_rawFrameReceiver := PTC.create("PTC2_ptc_rawFrameReceiver") alive
......@@ -57,6 +57,45 @@ testcase tc_can_raw_send_and_receive_frame() runs on MTC {
all component.kill;
}
testcase tc_can_raw_send_and_receive_canfd_frame() runs on MTC {
var PTC v_ptc_rawSendInitiator := PTC.create("PTC1_ptc_rawSendInitiator") alive
var PTC v_ptc_rawFrameReceiver := PTC.create("PTC2_ptc_rawFrameReceiver") alive
f_addSyncSlaveSet(v_ptc_rawSendInitiator, v_PTCSet)
f_addSyncSlaveSet(v_ptc_rawFrameReceiver, v_PTCSet)
connect(mtc:pt_sync, v_ptc_rawSendInitiator:pt_sync)
connect(mtc:pt_sync, v_ptc_rawFrameReceiver:pt_sync)
var SocketCAN_CAN_or_CAN_FD_frame v_canfd_frame_to_send
v_canfd_frame_to_send := {canfd_frame :=
{can_id := '00000015'O,
can_flags := '10101010'B,
can_pdu := '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'O}
}
v_ptc_rawSendInitiator.start(f_ptc_RawSendInitiator(e_testbody2, v_canfd_frame_to_send))
v_ptc_rawFrameReceiver.start(f_ptc_RawFrameReceiver(e_testbody3, v_canfd_frame_to_send))
var e_Phase v_phase
for(v_phase := c_firstPhase; v_phase < e_testcase_complete;v_phase := f_incMTCPhase(v_phase)) {
f_startPhase(v_phase)
log("MTC: ", v_phase)
f_awaitEndPhase(v_phase)
}
all component.done;
log("MTC done")
disconnect(mtc:pt_sync, v_ptc_rawSendInitiator:pt_sync)
disconnect(mtc:pt_sync, v_ptc_rawFrameReceiver:pt_sync)
all component.kill;
}
testcase tc_can_raw_setsockopt_CAN_RAW_FILTER() runs on MTC {
var PTC v_ptc_rawSetFilters := PTC.create("PTC1_ptc_rawSetFilters") alive
......
......@@ -46,13 +46,11 @@ struct bcm_msg_head;
struct can_frame;
struct canfd_frame;
#define DEFAULT_NUM_SOCK 10
#define BCM_FRAME_BUFFER_SIZE 256
#define BCM_FRAME_FLAGS_SIZE 32 // size of SocketCAN_bcm_frame in Bit
#define ISOTP_RECIEVE_BUFSIZE 5000
// workaround, as some of those below may not yet be defined in "linux/can/raw.h":
#define CAN_RAW_FILTER 1 /* set 0 .. n can_filter(s) */
#define CAN_RAW_ERR_FILTER 2 /* set filter for error frames */
......@@ -69,6 +67,10 @@ struct canfd_frame;
// workaround, as not defined in some older kernel versions
#ifndef CAN_MTU
#define CAN_MTU (sizeof(struct can_frame))
#endif //CAN_MTU
#ifndef CANFD_MTU
#define CANFD_MTU (sizeof(struct canfd_frame))
#endif //CANFD_MTU
// workaround, as canfd not defined in some older kernel versions
......@@ -165,7 +167,7 @@ void SocketCAN__PT_PROVIDER::Handle_Fd_Event_Readable(int sock) {
(struct sockaddr*) &addr, &addr_len);
//nbytes = read(sock, msg, ISOTP_RECIEVE_BUFSIZE);
if(nbytes > 0 && nbytes < ISOTP_RECIEVE_BUFSIZE) {
if (nbytes > 0 && nbytes < ISOTP_RECIEVE_BUFSIZE) {
struct ifreq ifr;
ifr.ifr_ifindex = addr.can_ifindex;
parameters.ifr().if__index() = ifr.ifr_ifindex;
......@@ -184,7 +186,7 @@ void SocketCAN__PT_PROVIDER::Handle_Fd_Event_Readable(int sock) {
//ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
// struct sockaddr *src_addr, socklen_t *addrlen);
#ifdef CANFD_FRAME_STRUCT_DEFINED // struct canfd_frame is supported
struct canfd_frame frame; // always asume a CANFD_Frame shall be received
struct canfd_frame frame; // always assume a CANFD_Frame shall be received
ssize_t nbytes = recvfrom(sock, &frame, CANFD_MTU, 0,
(struct sockaddr*) &addr, &addr_len);
#else //CANFD_FRAME_STRUCT_DEFINED
......@@ -224,20 +226,26 @@ void SocketCAN__PT_PROVIDER::Handle_Fd_Event_Readable(int sock) {
TTCN_error(
"SocketCAN frame reception: Ioctl failed while retrieving the interface name from the socket: %d with interface index %d\n",
sock, ifr.ifr_ifindex);
parameters.ifr().if__index() = ifr.ifr_ifindex;
parameters.ifr().if__name() =
"SocketCAN : device name unknown, ioctl failed";
} else {
#ifdef CANFD_FRAME_STRUCT_DEFINED
log("SocketCAN: Received a CAN frame from interface %s",
if (nbytes == CANFD_MTU) {
log(
"SocketCAN: Received a CANFD frame from interface %s",
ifr.ifr_name, nbytes, frame.len);
} else {
log(
"SocketCAN: Received a CAN frame from interface %s",
ifr.ifr_name, nbytes, frame.len);
}
#else //CANFD_FRAME_STRUCT_DEFINED
log("SocketCAN: Received a CAN frame from interface %s",
ifr.ifr_name, nbytes, frame.can_dlc);
#endif //CANFD_FRAME_STRUCT_DEFINED
parameters.ifr().if__index() = ifr.ifr_ifindex;
parameters.ifr().if__name() =
"SocketCAN : device name unknown, ioctl failed";
} else {
parameters.ifr().if__index() = ifr.ifr_ifindex;
parameters.ifr().if__name() =
"SocketCAN : device name unknown, ioctl failed";
parameters.ifr().if__name() = ifr.ifr_name;
}
......@@ -285,9 +293,10 @@ void SocketCAN__PT_PROVIDER::Handle_Fd_Event_Readable(int sock) {
ifr.ifr_name, nbytes, (int) len);
frameref.can__id() = int2oct(can_id, 4);
#ifdef CANFD_FRAME_STRUCT_DEFINED
if (nbytes == CANFD_MTU) {
frameref.can__flags() = BITSTRING(
int2bit(frame.flags,
frameref.can__flags().lengthof()));
int2bit(frame.flags, 8));
}
#endif //CANFD_FRAME_STRUCT_DEFINED
frameref.can__pdu() = OCTETSTRING(len, frame.data);
}
......@@ -451,6 +460,7 @@ void SocketCAN__PT_PROVIDER::user_map(const char */*system_port */) {
num_of_sock = 0;
sock_list_length = DEFAULT_NUM_SOCK;
for (int a = 0; a < sock_list_length; a++) {
sock_list[a].fd = 0;
sock_list[a].status = SOCKET_NOT_ALLOCATED;
sock_list[a].protocol_family =
SocketCAN__PortType::SocketCAN__PT_PROVIDER::SOCKET_NO_PROTOCOL;
......@@ -648,7 +658,7 @@ void SocketCAN__PT_PROVIDER::outgoing_send(
log("entering SocketCAN__PT_PROVIDER::outgoing_send(SocketCAN__connect)");
int sock;
struct sockaddr_can addr;
struct sockaddr_can addr = { };
int cn = send_par.id();
int res;
SocketCAN__Types::SocketCAN__connect__result result;
......@@ -660,12 +670,13 @@ void SocketCAN__PT_PROVIDER::outgoing_send(
addr.can_family = AF_CAN;
SocketCAN__Types::SocketCAN__connectu connectu = send_par.connectu();
SocketCAN__Types::SocketCAN__connectu connectu =
send_par.connectu();
switch (connectu.get_selection()) {
case SocketCAN__Types::SocketCAN__connectu::ALT_bcm:
addr.can_ifindex = connectu.bcm().if__index();
sock_list[cn].protocol_family
= SocketCAN__PortType::SocketCAN__PT_PROVIDER::SOCKET_PROTOCOL_CAN_BCM;
sock_list[cn].protocol_family =
SocketCAN__PortType::SocketCAN__PT_PROVIDER::SOCKET_PROTOCOL_CAN_BCM;
break;
default:
TTCN_error(
......@@ -720,7 +731,7 @@ void SocketCAN__PT_PROVIDER::outgoing_send(
log("entering SocketCAN__PT_PROVIDER::outgoing_send(SocketCAN__bind)");
int sock;
struct sockaddr_can addr;
struct sockaddr_can addr = { };
int cn = send_par.id();
int res;
SocketCAN__Types::SocketCAN__bind__result result;
......@@ -737,17 +748,21 @@ void SocketCAN__PT_PROVIDER::outgoing_send(
SocketCAN__Types::SocketCAN__bindu bindu = send_par.bindu();
switch (bindu.get_selection()) {
case SocketCAN__Types::SocketCAN__bindu::ALT_raw:
case SocketCAN__Types::SocketCAN__bindu::ALT_raw: {
const int canfd_on = 1;
setsockopt(sock, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on,
sizeof(canfd_on));
if_index = bindu.raw().if__index();
protocol_family
= SocketCAN__PortType::SocketCAN__PT_PROVIDER::SOCKET_PROTOCOL_CAN_RAW;
protocol_family =
SocketCAN__PortType::SocketCAN__PT_PROVIDER::SOCKET_PROTOCOL_CAN_RAW;
}
break;
case SocketCAN__Types::SocketCAN__bindu::ALT_isotp:
if_index = bindu.isotp().if__index();
addr.can_addr.tp.rx_id = oct2int(bindu.isotp().rx__can__id());
addr.can_addr.tp.tx_id = oct2int(bindu.isotp().tx__can__id());
protocol_family
= SocketCAN__PortType::SocketCAN__PT_PROVIDER::SOCKET_PROTOCOL_CAN_ISOTP;
protocol_family =
SocketCAN__PortType::SocketCAN__PT_PROVIDER::SOCKET_PROTOCOL_CAN_ISOTP;
break;
default:
TTCN_error(
......@@ -766,7 +781,7 @@ void SocketCAN__PT_PROVIDER::outgoing_send(
result.result().err() = errno;
} else {
log("Binding socket %d was successful", sock);
sock_list[cn].protocol_family = protocol_family ;
sock_list[cn].protocol_family = protocol_family;
result.result().result__code() =
SocketCAN__Types::SocketCAN__Result__code::SocketCAN__SUCCESS;
result.result().err() = OMIT_VALUE;
......@@ -925,6 +940,12 @@ void SocketCAN__PT_PROVIDER::outgoing_send(
break;
#ifdef RAW_CANFD_SUPPORT
case SocketCAN__Types::SocketCAN__CAN__or__CAN__FD__frame::ALT_canfd__frame: {
{
// Enabling FD support had been successful!
log(
"SocketCAN: Enabling FD support had been successful on socket %d",
sock);
struct canfd_frame fd_frame;
log("SocketCAN: Sending CAN FD frame)");
......@@ -939,19 +960,23 @@ void SocketCAN__PT_PROVIDER::outgoing_send(
send_par.frame().canfd__frame().can__pdu().lengthof();
fd_frame.can_id = oct2int(
send_par.frame().canfd__frame().can__id());
fd_frame.flags = bit2int(
send_par.frame().canfd__frame().can__flags());
memcpy(fd_frame.data,
send_par.frame().canfd__frame().can__pdu(), len);
fd_frame.len = len;
fd_frame.__res0 = 0x00;
fd_frame.__res1 = 0x00;
nrOfBytestoSend = sizeof(fd_frame);
if (send_par.ifu().is_present()) {
nrOfBytesSent = sendto(sock, &fd_frame, nrOfBytestoSend, 0,
(struct sockaddr*) &addr, sizeof(addr));
nrOfBytesSent = sendto(sock, &fd_frame, nrOfBytestoSend,
0, (struct sockaddr*) &addr, sizeof(addr));
if (nrOfBytesSent < 0) {
TTCN_error(
"SocketCAN FD send with sendto() error while trying to send %d bytes",
nrOfBytestoSend);