====== can-utils Tipps ====== Ist eigentlich nur eine Ansammlung von Stichwörten welche mir als Gedankenhilfe zu den can-utils dienen. Und hier noch der Hinweis zum aktullen Release (... cansniffer jetzt mit canfd..): * [[https://github.com/linux-can/can-utils/releases/tag/v2023.03|can-utils v2023.03]] - aktueller Debian Release (Kernel Version beachten) ===== Senden - cansend ===== einzelne Botschaft senden: cansend vcan0 244#00000011F6 Botschaft wiederholt senden (eventuell mit sleep verzögern): while true; do cansend vcan0 244#00000011F6; done while true; do cansend can0 123#4444; sleep 0.1; done bestimmte Botschaften aus Logfile senden (geht auch mit canplayer): candump vcan0 | grep " 244 " | while read line; do cansend vcan0 244#00000011F6; done ===== Senden - canplayer ===== alle Botschaften wie geloggt auf entsprechenden Interface senden: canplayer -I can.log.log canplayer -I can.log.log -l 1 # nur einmal abspielen oder canplayer vcan0=can0 < candump-2013-05-06_190603.log weitere Beispiele: canplayer -v -I candump-2019-01-16_193032.log can0=can0 can0=vcan1 # alle Botschaften von can0 und vcan1 auf can0 abspielen canplayer -v -I candump-2019-01-16_193032.log can0=can0 # alle can0 Botschaften aus dem Log auf can0 abspielen egrep -v "12d#" candump-2019-01-16_193032.log | canplayer can0=can0 # Alle IDs ausser 0x12D aus dem Log-File abspielen egrep "12d#" candump-2019-01-16_193032.log | canplayer can0=can0 # Nur die ID 0x12D aus dem Log-File abspielen egrep "(133#|401#)" acc_rev.log |canplayer # Nur die IDs 0x133 u. 0x401 aus dem Logfile abspielen **canplayer** - Hilfe Usage: canplayer [interface assignment]* Options: -I (default stdin) -l (process input file times) (Use 'i' for infinite loop - default: 1) -t (ignore timestamps: send frames immediately) -g (gap in milli seconds - default: 1 ms) -s (skip gaps in timestamps > 's' seconds) -x (disable local loopback of sent CAN frames) -v (verbose: print sent CAN frames) Interface assignment: 0..n assignments like = e.g. vcan2=can0 ( send frames received from can0 on vcan2 ) extra hook: stdout=can0 ( print logfile line marked with can0 on stdout ) No assignments => send frames to the interface(s) they had been received from. Lines in the logfile not beginning with '(' (start of timestamp) are ignored. ===== Senden - caribou ===== ==== Fuzzer Modus ==== ./cc.py -i vcan0 fuzzer mutate 0b4 ....1111 -delay 0.1 * -i vcan0 wählt ein alternatives Interface wenn man nicht das default Interface verwenden will aus .canrc * sendet die 0b4 und mutiert die Datenbytes D0 und D1 * -delay stellt die zykluszeit auf 100 ms ===== Gateway ===== gateway: (Regel löschen) sudo cangw -D -s vcan0 -d vcan1 -e -f 244:C00007FF -m SET:IL:333.4.1122334455667788 244=> nach vcan 1 als 333 weiterreichen ohne Daten zu ändern (nur ID und DLC) neue Regel hinzufügen: sudo cangw -A -s vcan0 -d vcan1 -e -f 244:C00007FF -m SET:ILD:333.4.1122334455667788 ^ =set Data ^ = set Len ^ = set ID ==> jetzt nach Daten Änderung sudo cangw -A -s vcan0 -d vcan1 -e -f 244:C00007FF -m AND:D:244.5.11223300FF667788 D3 filtern und löschen: sudo cangw -D -s vcan0 -d vcan1 -e -f 244:C00007FF -m AND:D:244.5.11223300FF667788 nochmal nur D3 filtern (war DLC=5): sudo cangw -A -s vcan0 -d vcan1 -e -f 244:C00007FF -m AND:D:244.5.FFFFFF00FF667788 Filter Test: sudo cangw -A -s vcan0 -d vcan1 -e -f 244~244 ??? alles aus 244 routen sudo cangw -A -s vcan0 -d vcan1 -e -f 244:C00007FF -m AND:D:244.8.FFFFFFFF00667788 // und jetzt D5 filter noch 2 Beispiele: 1) alles außer 0x466 routen: sudo cangw -A -s can0 -d can1 -f 466~7ff 2)alles außerr 1B8 routen: sudo cangw -A -s can0 -f 1B8~C00007FF -d can1 D0,D2,D3 lassen, D1=22 setzen sudo cangw -A -s can0 -d can1 -f 1B8:C00007FF -m AND:D:1B8.4.FF00FFFF4455667788 -m OR:D:1B8.4.0022000000000000 ===== cangw - hilfe ===== Usage: cangw [options] Commands: -A (add a new rule) -D (delete a rule) -F (flush / delete all rules) -L (list all rules) Mandatory: -s (source netdevice) -d (destination netdevice) Options: -t (preserve src_dev rx timestamp) -e (echo sent frames - recommended on vcanx) -i (allow to route to incoming interface) -u (user defined modification identifier) -l (limit the number of frame hops / routings) -f (set CAN filter) -m (set frame modifications) -x ::: (XOR checksum) -c ::::: (CRC8 cs) -p :[] (CRC8 checksum profile & parameters) Values are given and expected in hexadecimal values. Leading 0s can be omitted. is a CAN identifier filter : (matches when & mask == can_id & mask) ~ (matches when & mask != can_id & mask) is a CAN frame modification instruction consisting of ::.. - is one of 'AND' 'OR' 'XOR' 'SET' - is _one_ or _more_ of 'I'dentifier 'L'ength 'D'ata - is an u32 value containing the CAN Identifier - is an u8 value containing the data length code (0 .. 8) - is always eight(!) u8 values containing the CAN frames data The max. four modifications are performed in the order AND -> OR -> XOR -> SET Example: cangw -A -s can0 -d vcan3 -e -f 123:C00007FF -m SET:IL:333.4.1122334455667788 Supported CRC 8 profiles: Profile '1' (1U8) - add one additional u8 value Profile '2' (16U8) - add u8 value from table[16] indexed by (data[1] & 0xF) Profile '3' (SFFID_XOR) - add u8 value (can_id & 0xFF) ^ (can_id >> 8 & 0xFF) ===== candump ===== candump -ta vcan0 # mit Zeitstempel absolute -td=delta, usw... candump -ta -a vcan0 # mit Zeitstempel und ASCII-Anzeige candump -L vcan0 # Verwendet für die Anzeige wie es beim Logfile abgespeichert wird candump -l vcan0 # CAN-Frames in Dateispeichern (dieses File kann mit log2asc in das lesbare Format konvertiert werden.) candump -l any # alle CAN Interfaces loggen candump -L can0 |log2long can0 # inkl. Konvertierung zu Long und ASCII candump -L can0 |log2asc can0 Aus Dump-File nur bestimmte IDs anzeigen: cat can.log | log2long can0 | egrep ' 020 | 02F ' candump -cae can0,0:0,#FFFFFFFF # alle IDs und Error Frames , ASCII, farblich Interface markieren Auszug von candump -h: 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,92345678: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) Alle IDs bis auf 0x122 und 0x2FA aufzeichnen: candump can0,122~7FF,j,2fa~7FF,j Alle VW-Digagnose IDs >0x700 , ausser die 0x700 Broadcast ID: candump -ta -a can0,700~7FF,j,700:700 * candump -cae can0,0:0,#FFFFFFFFcandump (Farbe, alles, Filter alle IDs und ERRORFrames anzeigen) * candump -L can0 | split -C 500MB Falls die Logfiles zu groß werden, kann man sie hiermit aufsplitten. * candump -L any | log2long can0, can1 Alle CAN-Boschaften (CAN0,CAN1) etwas schöner formatiert anzeigen ===== cansniffer ===== to do todo... obiges dirket auf den Wiki-Seiten hinzufügen