Re: ip link valid options checking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am Freitag, den 09.07.2021, 14:00 +0200 schrieb Vincent MAILHOL:
> On Wed. 7 Jul 2021 at 19:45, Joshua Quesenberry <engnfrc@xxxxxxxxx> wrote:
> > Good Afternoon,
> > 
> > Do any of you know a way to check what options are valid when setting up a
> > CAN device with the ip link commands, either from bash or through C++? I'm
> > working on a piece of code that will get used on systems with varying CAN
> > drivers and for instance one of them doesn't support CAN-FD, so how would I
> > be able to know that setting the fd flag or dbitrate value would fail before
> > calling the setup command and seeing it fail?
> 
> I would suggest to use:
> > ip --details link show can0
> 
> You can then parse the results to check if the data bitrate
> information is present. If so, it means that FD is supported.
> Also, the output might be easier to parse if formatted in json:
> > ip --details --json --pretty link show can0
> 
> Alternatively, instead of using the command line, you might
> prefer to directly use the kernel netlink interface to directly
> retrieve the different modes supported by the controller.
> You can refer to iproute2 source code for the how-to:
> 
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/ip/iplink_can.c#n282
> 

Unfortunately the netlink kernel interface gives access only to the
IFLA_CAN_CTRLMODE data which boils down to an access of the netdev_priv(dev)-
>priv->ctrlmode flags set in the driver (see also in a Linux tree under
drivers/net/can/dev/netlink.c). But the "ctrlmode" flags represent only the
current setup. So you can see if CAN-FD mode is currently enabled.

But I think the thread opener wants to know in advance if the kernel gives us
the information what modes a certain driver supports. That is encoded in
netdev_priv(dev)->priv->ctrlmode_supported and netdev_priv(dev)->priv-
>ctrlmode_static. But for these flags there is no netlink interface to
interrogate that settings at the moment.

So you can't see in advance if a CAN driver would support for instance triple-
sampling or the CAN_CTRLMODE_CC_LEN8_DLC mode. To know it you must try to set
such option atm. I think.

Best regards,
    Stefan





[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux