On 03.08.2011 13:56, uprinz wrote:
> 
> Hi Wolfgang,
> 
> I know that the behavior is normal and under normal conditions everything is
> working well.
> 
> But I need to have the virtual slave accepted by the bus even the bus is
> passive. Or even the physical bus is passive the master should see it active
> if the slave is online.
> 
> The thing is, that the master has some internal sensors that should be
> treated like an external slave.
> But reading all this, I believe that it would be fare more easy to rewrite
> master to be master+slave and give the sensors to him....
> 
> Nevertheless I thought about setting master and slave to vcan0 and establish
> sort of routing vcan0<->can0

Hi Ulrich,

indeed we used a similar setup some time ago.

The idea is to run the CAN applications on the virtual CAN interface (e.g. 
vcan0)
and then cross-route the CAN frames between vcan0 <-> can0.

Even if the can0 interface goes down/up the cross-route remains.
Only when you remove can0, all routings from/to can0 are purged.

To use the kernel-based CAN routing, you need to build the can-gw protocol which
is based on the PF_CAN network layer stuff and currently only sits in the 
Berlios SVN:

http://svn.berlios.de/wsvn/socketcan/trunk/kernel/2.6/net/can/gw.c?op=log&;

You also need the configuration tool cangw which is in trunk/can-utils/cangw.c

---8<---
user@linux:~$ cangw -?

Usage: cangw [options]

Commands:  -A (add a new rule)
           -D (delete a rule)
           -F (flush / delete all rules)
           -L (list all rules)
Mandatory: -s <src_dev>  (source netdevice)
           -d <dst_dev>  (destination netdevice)
Options:   -t (preserve src_dev rx timestamp)
           -e (echo sent frames - recommended on vcanx)
           -f <filter> (set CAN filter)
           -m <mod> (set frame modifications)
           -x <from_idx>:<to_idx>:<result_idx>:<init_xor_val> (XOR checksum)
           -c <from>:<to>:<result>:<init_val>:<xor_val>:<crctab[256]> (CRC8 cs)
           -p <profile>:[<profile_data>] (CRC8 checksum profile & parameters)

Values are given and expected in hexadecimal values. Leading 0s can be omitted.

<filter> is a <value><mask> CAN identifier filter
   <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)

<mod> is a CAN frame modification instruction consisting of
<instruction>:<can_frame-elements>:<can_id>.<can_dlc>.<can_data>
 - <instruction> is one of 'AND' 'OR' 'XOR' 'SET'
 - <can_frame-elements> is _one_ or _more_ of 'I'dentifier 'L'ength 'D'ata
 - <can_id> is an u32 value containing the CAN Identifier
 - <can_dlc> is an u8 value containing the data length code (0 .. 8)
 - <can_data> 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)

---8<---

The can-gw is pretty fast and efficient, so that you won't see any relevant 
timing
differences.

If you get any problems using can-gw or the cangw userspacetool please ask me.

I'm always interested in feedback ;-)

> 
> Is that an option, and if, how to do that? I googled for something like ip
> route add vcan...

Even if can-gw is using netlink i created a separate tool as all the CAN-stuff
and filtering is so different to IP and other networking.

Best regards,
Oliver


> No usable hits though.
> 
> -----
> Best regards
> Ulrich

_______________________________________________
Socketcan-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-users

Reply via email to