lin-bus / linux-lin

Linux kernel LIN bus support implemented as TTY line discipline for generic UART conrollers, documentation https://github.com/lin-bus/linux-lin/wiki, based on https://github.com/lin-bus/linux-lin/wiki/sllin-rtlws14-paper.pdf, more CAN related projects http://canbus.pages.fel.cvut.cz/
https://github.com/lin-bus/linux-lin/wiki
38 stars 26 forks source link

Ubuntu 20.04 - ioctl SIOCGIFNAME: Inappropriate ioctl for device #11

Open engnfrc opened 2 years ago

engnfrc commented 2 years ago

I'm trying to get the Linux LIN stuff working and am running into troubles. I've built on the sllin ko on my target platform running Ubuntu 20.04 with a low-latency kernel (5.4.0-42-lowlatency) and then I've checked out can-utils and updated the files to do what I think your old files are trying to show (see below). Now when I run sudo ./slcan_attach -w /dev/ttyS0 I get this error: "ioctl SIOCGIFNAME: Inappropriate ioctl for device". Looking at /usr/include/linux/tty.h N_SLLIN 25 does not exist, is this the issue? Are we expected to do Kernel mods to make this stuff work? I would certainly prefer not to have to go that route...

Git Diff:


index cc13c37..acea823 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,6 +20,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSO_RXQ_OVFL=40")
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPF_CAN=29")
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DAF_CAN=PF_CAN")
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DN_SLCAN=17")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DN_SLLIN=25")
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSCM_TIMESTAMPING_OPT_STATS=54")

 include_directories (.)
diff --git a/configure.ac b/configure.ac
index f44a5e2..d31b528 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,6 +88,9 @@ AC_CHECK_DECL(AF_CAN,,
 AC_CHECK_DECL(N_SLCAN,,
     [AC_DEFINE([N_SLCAN], [17], [N_SLCAN])]
 )
+AC_CHECK_DECL(N_SLLIN,,
+    [AC_DEFINE([N_SLLIN], [25], [N_SLLIN])]
+)
 AC_CHECK_DECL(SCM_TIMESTAMPING_OPT_STATS,,
     [AC_DEFINE([SCM_TIMESTAMPING_OPT_STATS], [54], [SCM_TIMESTAMPING_OPT_STATS])]
 )
diff --git a/slcan_attach.c b/slcan_attach.c
index dc8e9f2..ab2e5f6 100644
--- a/slcan_attach.c
+++ b/slcan_attach.c
@@ -92,7 +92,8 @@ void print_usage(char *prg)
 int main(int argc, char **argv)
 {
        int fd;
-       int ldisc = N_SLCAN;
+       //int ldisc = N_SLCAN;
+       int ldisc = N_SLLIN;
        int detach = 0;
        int waitkey = 0;
        int send_open = 0;
diff --git a/slcand.c b/slcand.c
index 4a15697..858b0f5 100644
--- a/slcand.c
+++ b/slcand.c
@@ -199,7 +199,8 @@ int main(int argc, char *argv[])
        char *btr = NULL;
        int run_as_daemon = 1;
        char *pch;
-       int ldisc = N_SLCAN;
+       //int ldisc = N_SLCAN;
+       int ldisc = N_SLLIN;
        int fd;

        ttypath[0] = '\0';```
EliasKotlyar commented 2 years ago

Hey

I had the exact same issue yesterday. Let me tell you how to fix it for now, and then i will provide a proper description of the bug

  1. First of all you need a new Patch for slcan-attach, because the current can-utils version cannot be patched with it at all. You can use the patch which i used yesterday or do it yourself. Its really easy to patch:
    Index: slcan_attach.c
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- slcan_attach.c  (revision 0d84033fa47efaeec0df7a296d0c895d37256a72)
    +++ slcan_attach.c  (date 1635866057015)
    @@ -54,7 +54,7 @@
    #include <sys/socket.h>
    #include <termios.h>
    #include <unistd.h>
    -
    +#define LDISC_N_SLLIN 25
    void print_usage(char *prg)
    {
    fprintf(stderr, "%s - userspace tool for serial line CAN interface driver SLCAN.\n", prg);
    @@ -92,7 +92,7 @@
    int main(int argc, char **argv)
    {
    int fd;
    -   int ldisc = N_SLCAN;
    +   int ldisc = LDISC_N_SLLIN;
    int detach = 0;
    int waitkey = 0;
    int send_open = 0;
  2. Checkout this repository at following commit: https://github.com/lin-bus/linux-lin/commit/b56f1ea7a09bf50fc5f115a0c2e148e17d9e4799 This is the last commit which is working before it got broken. I was using 4.14.108 kernel when i was testing it
  3. Do not patch cangen, as its not required anymore. Someone already merged a RTR-Frame Patch inside it. You will have just to use "-R" instead of "-r"

Proper Bug description:

Steps to reproduce:

  1. Compile actual kernel module, modprobe it etc on kernel 4.14.108 (debian). It should also be reproducable on more recent kernels
  2. use either "sudo ldattach 25 /dev/ttyS0" or "sudo slcan_attach -w /dev/ttyS0"

Expected Result: You can do that without having an error.

Actual Result: You will get an error called: "ioctl SIOCGIFNAME: Inappropriate ioctl for device"