Hello Chris,

On 16.04.2012 11:07, Chris wrote:

> Hello, I’m a new user of SocketCAN and I’m working on an embedded system with
> built-in CAN-controller. I have to realize a system which has to act as a
> communication interface between two busses, analyze/filter values coded into
> these messages and respond with calculated values.
> 
> My first Test-C-Programs for RAW and BCM Sockets work fine, so my hardware is
> supported by SocketCAN.


Fine.

> My problem:
> I always power up the bus manually using ifconfig.
> Now I’m wondering how I could detect in my program if the bus is already 
> powered
> up or if not.  


Usually setting the bitrate and setting the interface 'up' is not the job of
the application programmer.

The sysadmin (root) knows the real hardware configuration and bitrates of the
attached CAN busses and should set the interfaces accordingly at system
startup. E.g. with a simple '/etc/init.d/can_if' script:

http://svn.berlios.de/wsvn/socketcan/trunk/etc/can_if

> When I use socket() bind()/connect() everything seems to work well also if the
> bus is shut down. Normally I would expect to get an error (-1) calling these
> functions. The error comes later when I try to use sendto(), recvfrom()…
> 
> Is this the normal behavior of SocketCAN and is there a possibility to easily
> (and securely!) detect a shut down bus?


You can get the IFF_UP information e.g. with an ioctl() call, e.g. see:
http://www.linuxquestions.org/questions/linux-networking-3/ioctl-and-changing-network-interface-flags-751709/

> 
> If possible I would also like to power up/down the bus and set its bitrate
> directly in my C-program. Surely I could do it with a system call. But maybe
> this functionality is already built in the SocketCAN library and accessible 
> in C?


Yes. There's a library available for that purpose:

http://git.pengutronix.de/?p=tools/libsocketcan.git;a=summary

> 
> Thank you for your ideas/proposals! 
> 


Hope that helped so far :-)

Regards,
Oliver

ps. I checked some other networking implementations like the packet socket,
which checks the IFF_UP state when doing bind() see here:
http://lxr.linux.no/#linux+v3.3.2/net/packet/af_packet.c#L2448

Checking the interface status when binding/connecting to a specific interface
is probably a thing to add ... today it's indeed missing.
_______________________________________________
Socketcan-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-users

Reply via email to