모종의 음모/CAN2025. 2. 19. 16:35

 

$ modprobe vcan
modprobe: ERROR: could not insert 'vcan': Operation not permitted

$ sudo modprobe vcan
sudo ip link add dev vcan0 type vcan

$ ifconfig
br-638c83b169eb: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.18.0.1  netmask 255.255.0.0  broadcast 172.18.255.255
        ether 02:42:d5:e6:f1:21  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:40:63:97:cb  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enxf8e43b9b776b: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.220.108  netmask 255.255.0.0  broadcast 192.168.255.255
        inet6 fe80::81f4:65ad:f7cc:2f2c  prefixlen 64  scopeid 0x20<link>
        ether f8:e4:3b:9b:77:6b  txqueuelen 1000  (Ethernet)
        RX packets 3619726  bytes 2156366501 (2.1 GB)
        RX errors 0  dropped 106170  overruns 0  frame 0
        TX packets 1452518  bytes 317915291 (317.9 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 160829  bytes 14028478 (14.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 160829  bytes 14028478 (14.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlo1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.220.107  netmask 255.255.0.0  broadcast 192.168.255.255
        inet6 fe80::104b:d69c:878f:cfaa  prefixlen 64  scopeid 0x20<link>
        ether 8c:55:4a:28:25:bc  txqueuelen 1000  (Ethernet)
        RX packets 809871  bytes 90255020 (90.2 MB)
        RX errors 0  dropped 99865  overruns 0  frame 0
        TX packets 53067  bytes 6125665 (6.1 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

$ ifconfig -a
br-638c83b169eb: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.18.0.1  netmask 255.255.0.0  broadcast 172.18.255.255
        ether 02:42:d5:e6:f1:21  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:40:63:97:cb  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enxf8e43b9b776b: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.220.108  netmask 255.255.0.0  broadcast 192.168.255.255
        inet6 fe80::81f4:65ad:f7cc:2f2c  prefixlen 64  scopeid 0x20<link>
        ether f8:e4:3b:9b:77:6b  txqueuelen 1000  (Ethernet)
        RX packets 3620125  bytes 2156544266 (2.1 GB)
        RX errors 0  dropped 106183  overruns 0  frame 0
        TX packets 1452676  bytes 317938700 (317.9 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 160841  bytes 14030154 (14.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 160841  bytes 14030154 (14.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vcan0: flags=128<NOARP>  mtu 72
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlo1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.220.107  netmask 255.255.0.0  broadcast 192.168.255.255
        inet6 fe80::104b:d69c:878f:cfaa  prefixlen 64  scopeid 0x20<link>
        ether 8c:55:4a:28:25:bc  txqueuelen 1000  (Ethernet)
        RX packets 809990  bytes 90270371 (90.2 MB)
        RX errors 0  dropped 99877  overruns 0  frame 0
        TX packets 53074  bytes 6126348 (6.1 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

$ sudo ifconfig vcan0 up
$ ifconfig
br-638c83b169eb: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.18.0.1  netmask 255.255.0.0  broadcast 172.18.255.255
        ether 02:42:d5:e6:f1:21  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:40:63:97:cb  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enxf8e43b9b776b: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.220.108  netmask 255.255.0.0  broadcast 192.168.255.255
        inet6 fe80::81f4:65ad:f7cc:2f2c  prefixlen 64  scopeid 0x20<link>
        ether f8:e4:3b:9b:77:6b  txqueuelen 1000  (Ethernet)
        RX packets 3620430  bytes 2156573250 (2.1 GB)
        RX errors 0  dropped 106197  overruns 0  frame 0
        TX packets 1452764  bytes 317953427 (317.9 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 160841  bytes 14030154 (14.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 160841  bytes 14030154 (14.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vcan0: flags=193<UP,RUNNING,NOARP>  mtu 72
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlo1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.220.107  netmask 255.255.0.0  broadcast 192.168.255.255
        inet6 fe80::104b:d69c:878f:cfaa  prefixlen 64  scopeid 0x20<link>
        ether 8c:55:4a:28:25:bc  txqueuelen 1000  (Ethernet)
        RX packets 810099  bytes 90278671 (90.2 MB)
        RX errors 0  dropped 99889  overruns 0  frame 0
        TX packets 53074  bytes 6126348 (6.1 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[링크 : https://ola-page.tistory.com/66]

 

 

 

$ candump 
candump - dump CAN bus traffic.

Usage: candump [options] <CAN interface>+
  (use CTRL-C to terminate candump)

Options:
         -t <type>   (timestamp: (a)bsolute/(d)elta/(z)ero/(A)bsolute w date)
         -H          (read hardware timestamps instead of system timestamps)
         -c          (increment color mode level)
         -i          (binary output - may exceed 80 chars/line)
         -a          (enable additional ASCII output)
         -S          (swap byte order in printed CAN data[] - marked with '`' )
         -s <level>  (silent mode - 0: off (default) 1: animation 2: silent)
         -l          (log CAN-frames into file. Sets '-s 2' by default)
         -L          (use log file format on stdout)
         -n <count>  (terminate after reception of <count> CAN frames)
         -r <size>   (set socket receive buffer to <size>)
         -D          (Don't exit if a "detected" can device goes down.
         -d          (monitor dropped CAN frames)
         -e          (dump CAN error frames in human-readable format)
         -x          (print extra message infos, rx/tx brs esi)
         -T <msecs>  (terminate after <msecs> without any reception)

Up to 16 CAN interfaces with optional filter sets can be specified
on the commandline in the form: <ifname>[,filter]*

Filters:
  Comma separated filters can be specified for each given CAN interface:
    <can_id>:<can_mask>
         (matches when <received_can_id> & mask == can_id & mask)
    <can_id>~<can_mask>
         (matches when <received_can_id> & mask != can_id & mask)
    #<error_mask>
         (set error frame filter, see include/linux/can/error.h)
    [j|J]
         (join the given CAN filters - logical AND semantic)

CAN IDs, masks and data content are given and expected in hexadecimal values.
When the can_id is 8 digits long the CAN_EFF_FLAG is set for 29 bit EFF format.
Without any given filter all data frames are received ('0:0' default filter).

Use interface name 'any' to receive from all CAN interfaces.

Examples:
candump -c -c -ta can0,123:7FF,400:700,#000000FF can2,400~7F0 can3 can8

candump -l any,0~0,#FFFFFFFF
         (log only error frames but no(!) data frames)
candump -l any,0:0,#FFFFFFFF
         (log error frames and also all data frames)
candump vcan2,12345678:DFFFFFFF
         (match only for extended CAN ID 12345678)
candump vcan2,123:7FF
         (matches CAN ID 123 - including EFF and RTR frames)
candump vcan2,123:C00007FF
         (matches CAN ID 123 - only SFF and non-RTR frames)

 

$ cansend vcan0
cansend - send CAN-frames via CAN_RAW sockets.

Usage: cansend <device> <can_frame>.

<can_frame>:
 <can_id>#{data}          for 'classic' CAN 2.0 data frames
 <can_id>#R{len}          for 'classic' CAN 2.0 data frames
 <can_id>##<flags>{data}  for CAN FD frames

<can_id>:
 3 (SFF) or 8 (EFF) hex chars
{data}:
 0..8 (0..64 CAN FD) ASCII hex-values (optionally separated by '.')
{len}:
 an optional 0..8 value as RTR frames can contain a valid dlc field
<flags>:
 a single ASCII Hex value (0 .. F) which defines canfd_frame.flags

Examples:
  5A1#11.2233.44556677.88 / 123#DEADBEEF / 5AA# / 123##1 / 213##311223344 /
  1F334455#1122334455667788 / 123#R / 00000123#R3

 

아래는 데이터 출력 포맷 확인용

인터페이스 / CAN id / 길이 / 데이터(페이로드 길이)

receive send
$ candump vcan0
  vcan0  111   [5]  01 02 03 04 05
$ cansend vcan0 111#010203.04.05
  vcan0  112   [5]  01 02 03 04 05 $ cansend vcan0 112#010203.04.05
  vcan0  112   [0]  $ cansend vcan0 112#
  vcan0  112  [00] $ cansend vcan0 112##1
  vcan0  112  [01]  23 $ cansend vcan0 112##123
  vcan0  112   [0]  remote request $ cansend vcan0 112#R
  vcan0  112   [3]  remote request $ cansend vcan0 112#R3

 

받는 쪽에서 CAN id 제한할 경우, 112를 받도록 설정했기에 113은 무시된다.

   
$ candump vcan0,112:FF $ cansend vcan0 111#R3
  vcan0  112   [3]  remote request $ cansend vcan0 112#R3
  $ cansend vcan0 113#R3
  vcan0  112   [5]  01 02 03 04 05 $ cansend vcan0 112#010203.04.05
  vcan0  112   [6]  01 02 03 04 05 06 $ cansend vcan0 112#010203.04.0506
  vcan0  112   [7]  01 02 03 04 05 06 07 $ cansend vcan0 112#010203.04.0506.07
  vcan0  112   [0]  remote request $ cansend vcan0 112#R
$ cansend vcan0 112#R10
$ cansend vcan0 112#R100
  vcan0  112   [1]  remote request $ cansend vcan0 112#R1
  vcan0  112   [2]  remote request $ cansend vcan0 112#R2
  vcan0  112   [8]  remote request $ cansend vcan0 112#R8

 

그나저나 mask 라는데 이해가 안되네..

123 = 0x7B & 0x7F0 하면 0x7B가 되어야 하니 16개에 대해서 받아들여야 할 거 같은데 왜 119에서 130 까지 12개 받아들여 질까?

$ candump vcan0,123:7F0
  vcan0  120   [0]  remote request
  vcan0  121   [0]  remote request
  vcan0  122   [0]  remote request
  vcan0  123   [0]  remote request
  vcan0  124   [0]  remote request
  vcan0  125   [0]  remote request
  vcan0  126   [0]  remote request
  vcan0  127   [0]  remote request
  vcan0  128   [0]  remote request
  vcan0  129   [0]  remote request
$ cansend vcan0 119#R
$ cansend vcan0 120#R
$ cansend vcan0 121#R
$ cansend vcan0 122#R
$ cansend vcan0 123#R
$ cansend vcan0 124#R
$ cansend vcan0 125#R
$ cansend vcan0 126#R
$ cansend vcan0 127#R
$ cansend vcan0 128#R
$ cansend vcan0 129#R
$ cansend vcan0 130#R

'모종의 음모 > CAN' 카테고리의 다른 글

can invader  (0) 2024.01.09
CAN(controller area network)  (0) 2023.10.31
mcp2515 can  (0) 2023.10.30
CAN 통신 우선순위  (0) 2015.01.23
Posted by 구차니