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 3cf633b..0473dcc 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 8a918ba..81d39e1 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 c45e104..a8477ed 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 00e9914..e8e81eb 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 dc60238..76d8633 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 51feb5b..4cf3ca5 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 6c116a3..fe1809c 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 ca67257..c0e3ba1 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) {