Structured comments updated.
[lincan.git] / lincan / src / ioctl_rtl.c
1 /* ioctl.c
2  * Linux CAN-bus device driver.
3  * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
4  * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
5  * email:pisa@cmp.felk.cvut.cz
6  * This software is released under the GPL-License.
7  * Version lincan-0.2  9 Jul 2003
8  */
9
10 #ifdef CAN_WITH_RTL
11
12 #include "../include/can.h"
13 #include "../include/can_sysdep.h"
14 #include "../include/main.h"
15
16 #include <rtl_posixio.h>
17 #include "../include/ioctl.h"
18 #include "../include/can_iortl.h"
19
20
21 int can_ioctl_rtl_posix(struct rtl_file *fptr, unsigned int cmd, unsigned long arg)
22 {
23         struct canuser_t *canuser =
24                 (struct canuser_t *)can_get_rtl_file_private_data(fptr);
25         int i=0;
26         unsigned short channel=0;
27         unsigned btr0=0, btr1=0;
28         struct msgobj_t *obj;
29         struct chip_t *chip;
30         struct canque_ends_t *qends;
31         
32         if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
33                 CANMSG("can_ioctl_: bad canuser magic\n");
34                 return -ENODEV;
35         }
36         
37         obj = canuser->msgobj;
38         if (obj == NULL) {
39                 CANMSG("Could not assign buffer structure\n");
40                 return -1;
41         }
42
43         qends = canuser->qends;
44         chip = obj->hostchip;
45         if (chip == NULL) {
46                 CANMSG("Device is not correctly configured.\n");
47                 CANMSG("Please reload the driver.\n");
48                 return -1;
49         }
50
51         switch (cmd) {
52                 case CAN_DRV_QUERY: {
53                         return can_ioctl_query(canuser, arg);
54                 }
55                 case STAT: {
56                         for (i=0x0; i<0x100; i++)
57                                 CANMSG("0x%x is 0x%x\n",i,can_read_reg(chip,i));
58                         break;
59                 }
60                 case CMD_START: {
61                         if (chip->chipspecops->start_chip(chip))
62                                 return -1;
63                         break;
64                 }
65                 case CMD_STOP: {
66                         if (chip->chipspecops->stop_chip(chip))
67                                 return -1;
68                         break;
69                 }
70                 case CANQUE_FLUSH: {
71                         canque_flush(canuser->rx_edge0);
72                         break;
73                 }
74                 case CONF_FILTER: {
75                         if(canuser->rx_edge0){
76                                 canque_set_filt(canuser->rx_edge0, arg, ~0, 0);
77                         }
78
79                         break;
80                 }
81                 
82                 case CANQUE_FILTER: {
83                         struct canfilt_t canfilt=*(struct canfilt_t *)arg;
84                         if(canuser->rx_edge0){
85                                 canque_set_filt(canuser->rx_edge0, canfilt.id, canfilt.mask, canfilt.flags);
86                         }
87                         break;
88                 }
89
90                 case CONF_BAUD: {
91                         channel = arg & 0xff;
92                         btr0 = (arg >> 8) & 0xff;
93                         btr1 = (arg >> 16) & 0xff;
94
95                         if (chip->chipspecops->set_btregs(chip, btr0, btr1)) {
96                                 CANMSG("Error setting bit timing registers\n");
97                                 return -1;
98                         }
99                         break;
100                 }
101                 default: {
102                         CANMSG("Not a valid ioctl command\n");
103                         return -EINVAL;
104                 }
105                 
106         }
107
108         return 0;
109 }
110
111 #endif /*CAN_WITH_RTL*/