Skip to contentSkip to conversation

xeno 3-rc7 : rtcanconfig fails to set baudrate

Xenomai Frederik Bayart 2 participants 4 messages Aug 18, 2015 – Aug 19, 2015

lore
Share & tools
lore
#0 lore raw

I have build xeno-3.0.rc7 with kernel 3.18.12.
I have a PEAK-PCIe CAN card in my system.
Drivers are loaded and rtcan0 en rtcan1 are created in /proc/rtcan.

However, I'm not able to set the baudrate when I'm execute 'rtcanconfig rtcan0 -v -b 1000000 start'

By adding debug statements in rtcanconfig, I found that ioctl(can_fd, SIOCSCANBAUDRATE, &u.ifr); fails,

errno gives : SIOCSCANBAUDRATE(errno=19): No such device

Below the output of rtcan0/info and xeno-config --info

Any suggestions ?

Frederik

$cat ./rtcan0/info
Device     rtcan0
Controller SJA1000
Board      PEAK-PCI
Clock-Hz   8000000
Baudrate   undefined
Bit-time   brp=0 prop_seg=0 phase_seg1=0 phase_seg2=0 sjw=0 sam=0 Ctrl-Mode
State      stopped
TX-Counter 0
RX-Counter 0
Errors     0
Refcount   0

$ xeno-config --info
Xenomai version: Xenomai/cobalt v3.0-rc7 -- 
Linux dev1 3.18.12-x86-64-xeno-3.0.rc7 #1 SMP PREEMPT Tue Aug 18 16:33:55 CEST 2015 x86_64 GNU/Linux
Kernel parameters: BOOT_IMAGE=/vmlinuz-3.18.12-x86-64-xeno-3.0.rc7 root=UUID=20f2dd2f-f02f-4b82-8538-8fe52e55a8ff ro quiet
I-pipe release #1 detected
Cobalt core 3.0-rc7 detected
Compiler: gcc version 4.9.2 (Debian 4.9.2-10) 
Build args: --prefix=/usr --includedir=/usr/include/xenomai --mandir=/usr/share/man --with-testdir=/usr/lib/xenomai/testsuite --with-core=cobalt --enable-smp --enable-pshared --enable-registry --build x86_64-linux-gnu build_alias=x86_64-linux-gnu
#1 lore raw
Quoted 6 lines · Frederik Bayart

I have build xeno-3.0.rc7 with kernel 3.18.12.
I have a PEAK-PCIe CAN card in my system.
Drivers are loaded and rtcan0 en rtcan1 are created in /proc/rtcan.

However, I'm not able to set the baudrate when I'm execute 'rtcanconfig rtcan0 -v -b 1000000 start'

Quoted 7 lines

By adding debug statements in rtcanconfig, I found that ioctl(can_fd, SIOCSCANBAUDRATE, &u.ifr); fails,

errno gives : SIOCSCANBAUDRATE(errno=19): No such device

Below the output of rtcan0/info and xeno-config --info

Any suggestions ?

This error is documented, I would check ->ifr_name in the request block:

http://www.xenomai.org/documentation/xenomai-3/html/xeno3prm/group__rtdm__can.html#ga7c070037c218b40de849ebf4d299f977

Signature · 1 line
Philippe.
#2 lore raw
Quoted 13 lines · Philippe Gerum
Quoted 11 lines · Frederik Bayart

I have build xeno-3.0.rc7 with kernel 3.18.12.
I have a PEAK-PCIe CAN card in my system.
Drivers are loaded and rtcan0 en rtcan1 are created in /proc/rtcan.

However, I'm not able to set the baudrate when I'm execute 'rtcanconfig rtcan0 -v -b 1000000 start' By adding debug statements in rtcanconfig, I found that ioctl(can_fd, SIOCSCANBAUDRATE, &u.ifr); fails, errno gives : SIOCSCANBAUDRATE(errno=19): No such device
Below the output of rtcan0/info and xeno-config --info
Any suggestions ?

Quoted 6 lines

This error is documented, I would check ->ifr_name in the request block:

http://www.xenomai.org/documentation/xenomai-3/html/xeno3prm/group__rtdm__can.html#ga7c070037c218b40de849ebf4d299f977

Signature · 1 line
Philippe.

The problem was that the interface name was overwritten by the baudrate. The problem is caused by use of

union {
struct ifreq ifr;
struct can_bittime bittime;
can_baudrate_t baudrate;
can_ctrlmode_t ctrlmode;
can_mode_t mode;
} u;

I think the intention was to put struct ifreq.ifr_ifru in the union. But I think the union above doesn't work because struct ifreq has first member ifr_ifrn

struct ifreq {
#define IFHWADDRLEN 6
union
{
char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
} ifr_ifrn;

union {
...snip...
} ifr_ifru;
};

If I revert the union, the problem is solved. Diff below.

Frederik

rtcanconfig.c.new renamed from rtcanconfig.c.old +0 -0
@@ -88,16 +88,10 @@
int     new_ctrlmode = 0, set_ctrlmode = 0;
int     verbose = 0;
int     bittime_count = 0, bittime_data[6];

+ struct ifreq ifr;
can_baudrate_t *baudrate;
can_ctrlmode_t *ctrlmode;
can_mode_t *mode;
- union {

-      struct ifreq ifr;
-      struct can_bittime bittime;
-      can_baudrate_t baudrate;
-      can_ctrlmode_t ctrlmode;
-      can_mode_t mode;

- } u;
struct can_bittime *bittime;
int opt, ret;
char* ptr;
@@ -169,7 +163,7 @@
}

strncpy(ifname, argv[optind], IFNAMSIZ);
- strncpy(u.ifr.ifr_name, ifname, IFNAMSIZ);
+ strncpy(ifr.ifr_name, ifname, IFNAMSIZ);

if (optind == argc - 2) { /* Get mode setting */
new_mode = string_to_mode(argv[optind + 1]);
@@ -187,7 +181,7 @@
return can_fd;
}

- ret = ioctl(can_fd, SIOCGIFINDEX, &u.ifr);
+ ret = ioctl(can_fd, SIOCGIFINDEX, &ifr);
if (ret) {
fprintf(stderr,"Can't get interface index for %s, code = %d\n", ifname, ret); return ret;
@@ -197,16 +191,15 @@
if (new_baudrate != -1) {
if (verbose)
printf("baudrate: %d\n", new_baudrate);
- baudrate = &u.baudrate;
+ baudrate = (can_baudrate_t *)&ifr.ifr_ifru;
*baudrate = new_baudrate;
- ret = ioctl(can_fd, SIOCSCANBAUDRATE, &u.ifr);
+ ret = ioctl(can_fd, SIOCSCANBAUDRATE, &ifr);
if (ret) {
goto abort;
}
}
-
if (bittime_count) {
- bittime = &u.bittime;
+ bittime = (struct can_bittime *)&ifr.ifr_ifru;
if (bittime_count == 2) {
bittime->type = CAN_BITTIME_BTR;
bittime->btr.btr0 = bittime_data[0];
@@ -233,7 +226,7 @@
bittime->std.sam);
}

- ret = ioctl(can_fd, SIOCSCANCUSTOMBITTIME, &u.ifr);
+ ret = ioctl(can_fd, SIOCSCANCUSTOMBITTIME, &ifr);
if (ret) {
goto abort;
}
@@ -241,20 +234,20 @@
}

if (set_ctrlmode != 0) {
- ctrlmode = &u.ctrlmode;
+ ctrlmode = (can_ctrlmode_t *)&ifr.ifr_ifru;
*ctrlmode = new_ctrlmode;
if (verbose)
printf("ctrlmode: %#x\n", new_ctrlmode);
- ret = ioctl(can_fd, SIOCSCANCTRLMODE, &u.ifr);
+ ret = ioctl(can_fd, SIOCSCANCTRLMODE, &ifr);
if (ret) {
goto abort;
}
}

if (new_mode != -1) {
- mode = &u.mode;
+ mode = (can_mode_t *)&ifr.ifr_ifru;
*mode = new_mode;
- ret = ioctl(can_fd, SIOCSCANMODE, &u.ifr);
+ ret = ioctl(can_fd, SIOCSCANMODE, &ifr);
if (ret) {
goto abort;
}

#3 lore raw
Quoted 31 lines · Frederik Bayart
Quoted 13 lines · Philippe Gerum
Quoted 11 lines · Frederik Bayart

I have build xeno-3.0.rc7 with kernel 3.18.12.
I have a PEAK-PCIe CAN card in my system.
Drivers are loaded and rtcan0 en rtcan1 are created in /proc/rtcan.

However, I'm not able to set the baudrate when I'm execute 'rtcanconfig rtcan0 -v -b 1000000 start' By adding debug statements in rtcanconfig, I found that ioctl(can_fd, SIOCSCANBAUDRATE, &u.ifr); fails, errno gives : SIOCSCANBAUDRATE(errno=19): No such device
Below the output of rtcan0/info and xeno-config --info
Any suggestions ?

Quoted 6 lines

This error is documented, I would check ->ifr_name in the request block:

http://www.xenomai.org/documentation/xenomai-3/html/xeno3prm/group__rtdm__can.html#ga7c070037c218b40de849ebf4d299f977

Signature · 1 line
Philippe.

The problem was that the interface name was overwritten by the baudrate. The problem is caused by use of

union {
struct ifreq ifr;
struct can_bittime bittime;
can_baudrate_t baudrate;
can_ctrlmode_t ctrlmode;
can_mode_t mode;
} u;

Quoted 1 line

I think the intention was to put struct ifreq.ifr_ifru in the union. But I think the union above doesn't work because struct ifreq has first member ifr_ifrn

I broke this code:

commit 78e77431163e35a3dafb30c86cc71fa167c7faa2

Author: Philippe Gerum <[email protected]>
Date:   Thu Dec 1 19:02:42 2011 +0100

utils/rtcanconfig: fix aliasing

But we can't just revert it, the data aliasing is wrong. I'll have a look, thanks for the debug work.

Signature · 1 line
Philippe.