(just a repost on SocketCAN users mailing list)

Hi all,

as some of you already might have seen on the increasing SVN versions the last 
week, i have implemented a (quite old) idea for a kernel internal CAN message
routing.

The can-gw is configurable with the netlink (precisely rtnetlink) interface
via PF_NETLINK sockets like 'iproute2' and 'iptable' do. It's named as 'gateway'
and not as 'bridge' as it is not only capable to route CAN frames but can modify
application level data.

The can-gw features:

- based on the PF_CAN core infrastructure for msg filtering / msg sending

- route CAN frames to a specific CAN interface
  - without filter
  - with a specified can_filter that's also known from the can-raw sockets

- modify (routed) CAN frames on the fly
  - with other given CAN frame content or it's elements can_id, can_dlc, data
    - AND (bit operation)
    - OR  (bit operation)
    - XOR (bit operation)
    - SET (replace CAN frame elements)

- extra flags for
  - echo of sent CAN frames (mandatory on vcan's :-)
  - option to preserve the original rx interface timestamp

In general the can-gw module src can be enhanced to route on non-CAN interfaces.

The routing of CAN frames inside the kernel makes sense because of the missing 
copy to/from userspace and the scheduling that happens to userspace apps.
First tests proved a low latency (about 22 usecs on my Core2Duo 2GHz) and
especially a low jitter for the routed CAN frames.

The can-gw is tested on the latest net-next-2.6 and a 2.6.28 kernel.

The new files in the SVN are

trunk/kernel/2.6/include/socketcan/can/gw.h 
trunk/kernel/2.6/include/linux/can/gw.h (just includes socketcan/can/gw.h)
trunk/kernel/2.6/net/can/gw.c

and a simple can-gw netlink config tool can be found here

trunk/can-utils/cangw.c

Feel free to check it out and give some feedback on the can-gw.

Have fun,
Oliver

---

user$ cangw -?

Usage: cangw [options]

Commands:  -A (add a new rule)
           -D (delete a rule)
           -F (flush - delete all rules)  [not yet implemented]
           -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)

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

<filter> is a <value>:<mask> CAN identifier filter

<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 instructions are performed in the order 'AND' -> 'OR' -> 'XOR' -> 'SET'

Example:
cangw -A -s can0 -d vcan3 -f 123:C00007FF -m SET:IL:80000333.4.1122334455667788


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

Reply via email to