From 328a0f0a261a7349b3731dbfdfc6591188003c48 Mon Sep 17 00:00:00 2001 From: ppisa Date: Thu, 4 Mar 2004 18:02:41 +0000 Subject: [PATCH] Added QUERY ioctl command for checking of driver version and message formats. --- lincan/include/can.h | 5 +++++ lincan/include/constants.h | 10 ++++++++-- lincan/include/ioctl.h | 1 + lincan/src/Makefile.omk | 2 +- lincan/src/Makefile.std | 2 +- lincan/src/ioctl.c | 3 +++ lincan/src/ioctl_rtl.c | 4 ++++ lincan/utils/readburst.c | 20 +++++++++++++++++++- 8 files changed, 42 insertions(+), 5 deletions(-) diff --git a/lincan/include/can.h b/lincan/include/can.h index 3cf633b..0473dcc 100644 --- a/lincan/include/can.h +++ b/lincan/include/can.h @@ -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 diff --git a/lincan/include/constants.h b/lincan/include/constants.h index 8a918ba..81d39e1 100644 --- a/lincan/include/constants.h +++ b/lincan/include/constants.h @@ -13,8 +13,14 @@ /* 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 diff --git a/lincan/include/ioctl.h b/lincan/include/ioctl.h index c45e104..a8477ed 100644 --- a/lincan/include/ioctl.h +++ b/lincan/include/ioctl.h @@ -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); diff --git a/lincan/src/Makefile.omk b/lincan/src/Makefile.omk index 00e9914..e8e81eb 100644 --- a/lincan/src/Makefile.omk +++ b/lincan/src/Makefile.omk @@ -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 diff --git a/lincan/src/Makefile.std b/lincan/src/Makefile.std index dc60238..76d8633 100644 --- a/lincan/src/Makefile.std +++ b/lincan/src/Makefile.std @@ -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 diff --git a/lincan/src/ioctl.c b/lincan/src/ioctl.c index 51feb5b..4cf3ca5 100644 --- a/lincan/src/ioctl.c +++ b/lincan/src/ioctl.c @@ -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)); diff --git a/lincan/src/ioctl_rtl.c b/lincan/src/ioctl_rtl.c index 6c116a3..fe1809c 100644 --- a/lincan/src/ioctl_rtl.c +++ b/lincan/src/ioctl_rtl.c @@ -14,6 +14,7 @@ #include "../include/main.h" #include +#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)); diff --git a/lincan/utils/readburst.c b/lincan/utils/readburst.c index ca67257..c0e3ba1 100644 --- a/lincan/utils/readburst.c +++ b/lincan/utils/readburst.c @@ -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 CAN filter flags\n"); printf(" -w, --wait number of seconds to wait in select call\n"); printf(" -p, --prefix 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) { -- 2.39.2