]> rtime.felk.cvut.cz Git - lincan.git/commitdiff
Added QUERY ioctl command for checking of driver version and message formats.
authorppisa <ppisa>
Thu, 4 Mar 2004 18:02:41 +0000 (18:02 +0000)
committerppisa <ppisa>
Thu, 4 Mar 2004 18:02:41 +0000 (18:02 +0000)
lincan/include/can.h
lincan/include/constants.h
lincan/include/ioctl.h
lincan/src/Makefile.omk
lincan/src/Makefile.std
lincan/src/ioctl.c
lincan/src/ioctl_rtl.c
lincan/utils/readburst.c

index 3cf633b75761318b4a28df9c61d522bd5c1bda4d..0473dcc393ceb3a854f7a6994f4e56c03038a9ba 100644 (file)
@@ -28,6 +28,11 @@ typedef unsigned long bittiming_t;
 typedef unsigned short channel_t;
 
 /* CAN ioctl functions */
+#define CAN_DRV_QUERY _IO(CAN_IOC_MAGIC, 0)
+#define CAN_DRV_QRY_BRANCH    0        /* returns driver branch value - "LINC" for LinCAN driver */
+#define CAN_DRV_QRY_VERSION   1        /* returns driver version as (major<<16) | (minor<<8) | patch */
+#define CAN_DRV_QRY_MSGFORMAT 2        /* format of canmsg_t structure */
+
 #define CMD_START _IOW(CAN_IOC_MAGIC, 1, channel_t)
 #define CMD_STOP _IOW(CAN_IOC_MAGIC, 2, channel_t)
 //#define CMD_RESET 3
index 8a918baca03cd5dae1d7cd825ea1c475ef4b9d80..81d39e1658e881af65003d8c890c7abd149cfef6 100644 (file)
 /* Device name as it will appear in /proc/devices */
 #define DEVICE_NAME "can"
 
-/* Version of the driver reported by */
-
+/* Branch of the driver */
+#define CAN_DRV_BRANCH (('L'<<24)|('I'<<16)|('N'<<8)|'C')
+
+/* Version of the driver */
+#define CAN_DRV_VER_MAJOR 0
+#define CAN_DRV_VER_MINOR 2
+#define CAN_DRV_VER_PATCH 1
+#define CAN_DRV_VER ((CAN_DRV_VER_MAJOR<<16) | (CAN_DRV_VER_MINOR<<8) | CAN_DRV_VER_PATCH)
 
 /* Default driver major number, see /usr/src/linux/Documentation/devices.txt */
 #define CAN_MAJOR 91
index c45e104203690335d0a104376e2a8004127ebba8..a8477ed190e1ed25d30c1a601d5cad098e39b49e 100644 (file)
@@ -8,3 +8,4 @@
  */
 
 int can_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
+int can_ioctl_query(struct canuser_t *canuser, unsigned long what);
index 00e99143a1f27f910226915805210fa5660afa1e..e8e81ebc75b083ebec083e76a98fea34b480eed8 100644 (file)
@@ -24,6 +24,6 @@ lincan_SOURCES = can_queue.c can_quekern.c can_quertl.c main.c modparms.c \
                devcommon.c can_devrtl.c setup.c finish.c irq.c boardlist.c \
                sja1000p.c sja1000.c i82527.c  \
                open.c close.c read.c write.c ioctl.c select.c fasync.c \
-               proc.c $(lincan_cards_SOURCES) $(lincan_rtl_SOURCES)
+               proc.c ioctl_query.c $(lincan_cards_SOURCES) $(lincan_rtl_SOURCES)
                
 endif #CONFIG_OC_LINCAN
index dc602386f79c2a680b115c9166727a76492aa51b..76d8633a826a4ebc3b2271a0895f634546458e1a 100644 (file)
@@ -133,7 +133,7 @@ O_OBJS       += can_queue.o can_quekern.o devcommon.o main.o modparms.o \
                setup.o finish.o irq.o boardlist.o \
                sja1000p.o sja1000.o i82527.o  \
                open.o proc.o close.o write.o read.o \
-               ioctl.o select.o fasync.o
+               ioctl.o ioctl_query.o select.o fasync.o
 # Objects with exported symbols (-DEXPORT_SYMTAB)
 OX_OBJS      = 
 # Module objects 
index 51feb5b0fc5cd42e2652dea00c737b66e47b37c4..4cf3ca5249535d90552fbc27fbc8d68cf8508137 100644 (file)
@@ -43,6 +43,9 @@ int can_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned
        }
 
        switch (cmd) {
+               case CAN_DRV_QUERY: {
+                       return can_ioctl_query(canuser, arg);
+               }
                case STAT: {
                        for (i=0x0; i<0x100; i++)
                                CANMSG("0x%x is 0x%x\n",i,can_read_reg(chip,i));
index 6c116a300bb8c01aa3a1178ad0bb385372c823fa..fe1809cc3d4500bf42695f626d1e8ed3164c7687 100644 (file)
@@ -14,6 +14,7 @@
 #include "../include/main.h"
 
 #include <rtl_posixio.h>
+#include "../include/ioctl.h"
 #include "../include/can_iortl.h"
 
 
@@ -48,6 +49,9 @@ int can_ioctl_rtl_posix(struct rtl_file *fptr, unsigned int cmd, unsigned long a
        }
 
        switch (cmd) {
+               case CAN_DRV_QUERY: {
+                       return can_ioctl_query(canuser, arg);
+               }
                case STAT: {
                        for (i=0x0; i<0x100; i++)
                                CANMSG("0x%x is 0x%x\n",i,can_read_reg(chip,i));
index ca6725702e91fee1c4ddd3c6de6a9c04aabf5759..c0e3ba1293ed2b026e0852ef323bf6e70571b6b1 100644 (file)
@@ -24,6 +24,8 @@ struct canfilt_t canfilt = {
 
 int canfilt_fl;
 
+int query_fl;
+
 int can_wait_sec = 5;
 
 char *can_dev_name = "/dev/can0";
@@ -67,6 +69,7 @@ usage(void)
   printf("  -f, --flags <num>        CAN filter flags\n");
   printf("  -w, --wait <num>         number of seconds to wait in select call\n");
   printf("  -p, --prefix <str>       string prefix for output\n");
+  printf("  -q, --query              query driver features\n");
   printf("  -V, --version            show version\n");
   printf("  -h, --help               this usage screen\n");
 }
@@ -81,6 +84,7 @@ int main(int argc, char *argv[])
                { "flags", 1, 0, 'f' },
                { "wait",  1, 0, 'w' },
                { "prefix",1, 0, 'p' },
+               { "query" ,0 ,0, 'q' },
                { "version",0,0, 'V' },
                { "help",  0, 0, 'h' },
                { 0, 0, 0, 0}
@@ -97,7 +101,7 @@ int main(int argc, char *argv[])
        struct sigaction act;
 
 
-       while ((opt = getopt_long(argc, argv, "d:m:i:f:w:p:Vh",
+       while ((opt = getopt_long(argc, argv, "d:m:i:f:w:p:qVh",
                            &long_opts[0], NULL)) != EOF) switch (opt) {
                case 'd':
                        can_dev_name=optarg;
@@ -120,6 +124,9 @@ int main(int argc, char *argv[])
                case 'p':
                        prt_prefix_in = optarg;
                        break;
+               case 'q':
+                       query_fl=1;
+                       break;
                case 'V':
                        fputs("LinCAN utilities v0.2\n", stdout);
                        exit(0);
@@ -143,6 +150,17 @@ int main(int argc, char *argv[])
                exit(1);        
        }
        
+       if (query_fl) {
+               n=ioctl(fd, CAN_DRV_QUERY, CAN_DRV_QRY_BRANCH);
+               printf("CAN driver branch:  %c%c%c%c\n",(n>>24)&0xff,(n>>16)&0xff,(n>>8)&0xff,n&0xff);
+               n=ioctl(fd, CAN_DRV_QUERY, CAN_DRV_QRY_VERSION);
+               printf("CAN driver version: %d.%d.%d\n",(n>>16)&0xff,(n>>8)&0xff,n&0xff);
+               n=ioctl(fd, CAN_DRV_QUERY, CAN_DRV_QRY_MSGFORMAT);
+               printf("CAN message format: %08x\n",n);
+               close(fd);
+               return 0;
+       }
+
        if (canfilt_fl) {
                ret = ioctl(fd, CANQUE_FILTER, &canfilt);
                if(ret<0) {