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"
34 VCAN_IF="vcan0 vcan1 vcan2 vcan3"
39 if [ -n "$PROBE" ] ; then
40 echo -n "Extra probing CAN modules:"
41 for MODULE in $PROBE; do
43 /sbin/modprobe -q $MODULE
47 if [ -n "$CAN_IF" ] ; then
48 echo -n "Enabling CAN interfaces:"
53 HASBTR=`echo $IF | grep "@"`
54 if [ -n "$HASBTR" ]; then
57 /sbin/ip link set $DEVICE type can bitrate $BITRATE
59 HASMS=`echo $IF | grep ","`
60 if [ -n "$HASMS" ]; then
62 /sbin/ip link set $DEVICE type can restart-ms $RESTARTMS
64 /sbin/ip link set $DEVICE up
68 if [ -n "$VCAN_IF" ] ; then
69 echo -n "Creating and enabling virtual CAN interfaces:"
70 for IF in $VCAN_IF; do
72 /sbin/ip link add name $IF type vcan
73 /sbin/ip link set $IF up
79 if [ -n "$CAN_IF" ] ; then
80 echo -n "Restarting CAN interfaces:"
85 /sbin/ip link set $DEVICE down
86 /sbin/ip link set $DEVICE up
90 if [ -n "$VCAN_IF" ] ; then
91 echo -n "Restarting virtual CAN interfaces:"
92 for IF in $VCAN_IF; do
94 /sbin/ip link set $IF down
95 /sbin/ip link set $IF up
101 if [ -n "$CAN_IF" ] ; then
102 echo -n "Shutting down CAN interfaces:"
103 for IF in $CAN_IF; do
107 /sbin/ip link set $DEVICE down
111 if [ -n "$VCAN_IF" ] ; then
112 echo -n "Shutting down and removing virtual CAN interfaces:"
113 for IF in $VCAN_IF; do
115 /sbin/ip link set $IF down
116 /sbin/ip link del $IF
122 echo "Usage: /etc/init.d/can_if {start|stop|restart|reload|force-reload}"