5 # Required-Start: $local_fs $syslog mountkernfs
6 # Required-Stop: $local_fs $syslog mountkernfs
7 # Default-Start: 2 3 4 5
9 # Short-Description: Starts the configured CAN-Interfaces and creates virtual CAN Interfaces on the system.
15 # Simple script to start CAN and VCAN interfaces with netlink configuration
17 # Copyright (c) 2009 Volkswagen Group Electronic Research
20 # Exit if 'ip' from the iproute2 package is not installed
21 test -x /sbin/ip || exit 0
23 # On some systems the automatic module loading via
24 # /etc/modules.conf is quite slow. To ensure the immediately
25 # availability of specific modules you can define critical
26 # modules in the PROBE variable. E.g. PROBE="can-tp20"
28 # Exit if modprobe is not installed
29 test -x /sbin/modprobe || exit 0
31 # The syntax for the CAN devices is: devname[@bitrate][,restart-ms]
32 # example CAN_IF="can0 can1@500000 can2@500000,200 can3,500"
35 # To modify the sampling-point and SJW settings for the in-kernel bittiming
36 # calculation. "0" => set default values (CAN CIA sampling-point / sjw=1)
37 SAMPOINT="0" # example for 84% : SAMPOINT=".840"
38 SJW="0" # example for max. sjw : SJW="4"
40 VCAN_IF="vcan0 vcan1 vcan2 vcan3"
45 if [ -n "$PROBE" ] ; then
46 echo -n "Extra probing CAN modules:"
47 for MODULE in $PROBE; do
49 /sbin/modprobe -q $MODULE
53 if [ -n "$CAN_IF" ] ; then
54 echo -n "Enabling CAN interfaces:"
59 HASBTR=`echo $IF | grep "@"`
60 if [ -n "$HASBTR" ]; then
63 /sbin/ip link set $DEVICE type can bitrate $BITRATE sample-point $SAMPOINT sjw $SJW
65 HASMS=`echo $IF | grep ","`
66 if [ -n "$HASMS" ]; then
68 /sbin/ip link set $DEVICE type can restart-ms $RESTARTMS
70 /sbin/ip link set $DEVICE up
74 if [ -n "$VCAN_IF" ] ; then
75 echo -n "Creating and enabling virtual CAN interfaces:"
76 for IF in $VCAN_IF; do
78 /sbin/ip link add name $IF type vcan
79 /sbin/ip link set $IF up
85 if [ -n "$CAN_IF" ] ; then
86 echo -n "Restarting CAN interfaces:"
91 /sbin/ip link set $DEVICE down
92 /sbin/ip link set $DEVICE up
96 if [ -n "$VCAN_IF" ] ; then
97 echo -n "Restarting virtual CAN interfaces:"
98 for IF in $VCAN_IF; do
100 /sbin/ip link set $IF down
101 /sbin/ip link set $IF up
107 if [ -n "$CAN_IF" ] ; then
108 echo -n "Shutting down CAN interfaces:"
109 for IF in $CAN_IF; do
113 /sbin/ip link set $DEVICE down
117 if [ -n "$VCAN_IF" ] ; then
118 echo -n "Shutting down and removing virtual CAN interfaces:"
119 for IF in $VCAN_IF; do
121 /sbin/ip link set $IF down
122 /sbin/ip link del $IF
128 echo "Usage: /etc/init.d/can_if {start|stop|restart|reload|force-reload}"