Skip to content

Commit 670badf

Browse files
committed
canutils/slcan: explicitly manage the interface.
A recent change (apache/nuttx#16199) has made the bitrate setting no longer bring the interface up. Moreover, it is now no longer possible to change bitrate of a CAN interface if it is up. Therefore, slcan needs to bring the interface down to change it. Fortunately, it already had commands to open and close the interface which map nicely to this. Signed-off-by: Carlos Sanchez <[email protected]>
1 parent 374dc21 commit 670badf

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

Diff for: canutils/slcan/slcan.c

+32-6
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,22 @@ int main(int argc, char *argv[])
316316
{
317317
/* open CAN interface */
318318

319-
mode = 1;
320-
debug_print("Open interface\n");
321-
ok_return(fd);
319+
struct ifreq ifr;
320+
321+
strlcpy(ifr.ifr_name, argv[1], IFNAMSIZ);
322+
323+
ifr.ifr_flags = IFF_UP;
324+
if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0)
325+
{
326+
syslog(LOG_ERR, "Open interface failed\n");
327+
fail_return(fd);
328+
}
329+
else
330+
{
331+
mode = 1;
332+
debug_print("Open interface\n");
333+
ok_return(fd);
334+
}
322335
}
323336
else if (buf[0] == 'S')
324337
{
@@ -394,9 +407,22 @@ int main(int argc, char *argv[])
394407
{
395408
/* close interface */
396409

397-
mode = 0;
398-
debug_print("Close interface\n");
399-
ok_return(fd);
410+
struct ifreq ifr;
411+
412+
strlcpy(ifr.ifr_name, argv[1], IFNAMSIZ);
413+
414+
ifr.ifr_flags = IFF_DOWN;
415+
if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0)
416+
{
417+
syslog(LOG_ERR, "Close interface failed\n");
418+
fail_return(fd);
419+
}
420+
else
421+
{
422+
mode = 0;
423+
debug_print("Close interface\n");
424+
ok_return(fd);
425+
}
400426
}
401427
else if (buf[0] == 'T')
402428
{

0 commit comments

Comments
 (0)