Skip to content

Commit f94bccf

Browse files
csanchezdllxiaoxiang781216
authored andcommitted
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 4fb47a6 commit f94bccf

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

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
{
@@ -392,9 +405,22 @@ int main(int argc, char *argv[])
392405
{
393406
/* close interface */
394407

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

0 commit comments

Comments
 (0)