查看ip版本和用法:
$ ./ip -V
ip utility, iproute2-ss110629
$ ./ip link help
Usage: ip link add link DEV [ name ] NAME
[ txqueuelen PACKETS ]
[ address LLADDR ]
[ broadcast LLADDR ]
[ mtu MTU ]
type TYPE [ ARGS ]
ip link delete DEV type TYPE [ ARGS ]
ip link set { dev DEVICE | group DEVGROUP } [ { up | down } ]
[ arp { on | off } ]
[ dynamic { on | off } ]
[ multicast { on | off } ]
[ allmulticast { on | off } ]
[ promisc { on | off } ]
[ trailers { on | off } ]
[ txqueuelen PACKETS ]
[ name NEWNAME ]
[ address LLADDR ]
[ broadcast LLADDR ]
[ mtu MTU ]
[ netns PID ]
[ alias NAME ]
[ vf NUM [ mac LLADDR ]
[ vlan VLANID [ qos VLAN-QOS ] ]
[ rate TXRATE ] ]
[ master DEVICE ]
[ nomaster ]
ip link show [ DEVICE | group GROUP ]
TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | can }
1>. 查看can接口状态
down下的状态
# ip link set can0 down
# ip -details link show can0
2: can0: <NOARP,ECHO> mtu 16 qdisc pfifo_fast state DOWN qlen 10
link/can
can state STOPPED (berr-counter tx 0 rx 0) restart-ms 0
bitrate 49999 sample-point 0.875
tq 2500 prop-seg 3 phase-seg1 3 phase-seg2 1 sjw 1
xilinx_can: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..256 brp-inc 1
clock 99999999
loopback状态
# ip link set can0 type can bitrate 50000 loopback on
xilinx_can e0008000.can can0: bitrate error 0.0%
# ip -details link show can0
2: can0: <NOARP,ECHO> mtu 16 qdisc pfifo_fast state DOWN qlen 10
link/can
can <LOOPBACK> state STOPPED (berr-counter tx 0 rx 0) restart-ms 0
bitrate 49999 sample-point 0.875
tq 2500 prop-seg 3 phase-seg1 3 phase-seg2 1 sjw 1
xilinx_can: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..256 brp-inc 1
clock 99999999
up下的状态
# ip link set can0 down
# ip link set can0 type can bitrate 50000 loopback off
xilinx_can e0008000.can can0: bitrate error 0.0%
# ip link set can0 up
# ip -details link show can0
2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
link/can
can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
bitrate 49999 sample-point 0.875
tq 2500 prop-seg 3 phase-seg1 3 phase-seg2 1 sjw 1
xilinx_can: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..256 brp-inc 1
clock 99999999
2>. 使用loopback模式测试:
使用loopback模式可测试本机的can驱动是否正常工作.
# ip link set can0 down
# ip link set can0 type can bitrate 50000 loopback on
xilinx_can e0008000.can can0: bitrate error 0.0%
# ip link set can0 up
# candump can0 &
# cansend can0 123#11223344556677
# can0 123 [7] 11 22 33 44 55 66 77
can0 123 [7] 11 22 33 44 55 66 77