source: titan/titan/cadev.h @ 14611

Last change on this file since 14611 was 10473, checked in by nit, 13 years ago

[titan] update structs

File size: 3.3 KB
Line 
1#ifndef CADEV_H
2#define CADEV_H
3
4struct dvbdev* caopen(int adapter)
5{
6        debug(1000, "in");
7        int fd = -1;
8        struct dvbdev* node = dvbdev;
9
10        while(node != NULL)
11        {
12                if(node->fd == -1 && node->type == CADEV && node->adapter == adapter)
13                        break;
14                node = node->next;
15        }
16
17        if(node != NULL)
18        {
19                if((fd = open(node->dev, O_RDWR | O_NONBLOCK)) < 0)
20                {
21                        debug(200, "open ca failed %s", node->dev);
22                        node = NULL;
23                }
24                else
25                {
26                        node->fd = fd;
27                        closeonexec(fd);
28                }
29        }
30
31        debug(1000, "out");
32        return node;
33}
34
35int caopendirect(char *cadev)
36{
37        debug(1000, "in");
38        int fd = -1;
39
40        if((fd = open(cadev, O_RDWR | O_NONBLOCK)) < 0)
41        {
42                debug(200, "open ca failed %s", cadev);
43        }
44
45        closeonexec(fd);
46        debug(1000, "out");
47        return fd;
48}
49
50void caclose(struct dvbdev* node, int fd)
51{
52        if(node != NULL)
53        {
54                close(node->fd);
55                node->fd = -1;
56        }
57        else
58                close(fd);
59}
60
61int cagetcaps(struct dvbdev* node, struct ca_caps* caps)
62{
63        if(node == NULL)
64        {
65                debug(1000, "out-> NULL detect");
66                return 1;
67        }
68
69        //caps.slot_num
70        //caps.slot_type
71        //caps.descr_num
72        //caps.descr_type
73
74        debug(200, "CA_GET_CAP");
75        if(ioctl(node->fd, CA_GET_CAP, caps) < 0)
76        {
77                perr("CA_GET_CAP");
78                return 1;
79        }
80
81        return 0;
82}
83
84int cagetmsg(struct dvbdev* node, struct ca_msg *msg)
85{
86        if(node == NULL)
87        {
88                debug(1000, "out-> NULL detect");
89                return 1;
90        }
91
92        debug(200, "CA_GET_MSG");
93        if(ioctl(node->fd, CA_GET_MSG, msg) < 0)
94        {
95                perr("CA_GET_MSG");
96                return 1;
97        }
98
99        return 0;
100}
101
102int casendmsg(struct dvbdev* node, struct ca_msg *msg)
103{
104        if(node == NULL)
105        {
106                debug(1000, "out-> NULL detect");
107                return 1;
108        }
109
110        debug(200, "CA_SEND_MSG");
111        if(ioctl(node->fd, CA_SEND_MSG, msg) < 0)
112        {
113                perr("CA_SEND_MSG");
114                return 1;
115        }
116
117        return 0;
118}
119
120int cagetdesc(struct dvbdev* node)
121{
122        if(node == NULL)
123        {
124                debug(1000, "out-> NULL detect");
125                return 1;
126        }
127
128        debug(200, "CA_GET_DESCR_INFO");
129        if(ioctl(node->fd, CA_GET_DESCR_INFO) < 0)
130        {
131                perr("CA_GET_DESCR_INFO");
132                return 1;
133        }
134
135        return 0;
136}
137
138int casetpid(struct dvbdev* node)
139{
140        if(node == NULL)
141        {
142                debug(1000, "out-> NULL detect");
143                return 1;
144        }
145
146        debug(200, "CA_SET_PID");
147        if(ioctl(node->fd, CA_SET_PID) < 0)
148        {
149                perr("CA_SET_PID");
150                return 1;
151        }
152
153        return 0;
154}
155
156int careset(struct dvbdev* node, int slot)
157{
158        if(node == NULL)
159        {
160                debug(1000, "out-> NULL detect");
161                return 1;
162        }
163
164        debug(200, "CA_RESET");
165        if(ioctl(node->fd, CA_RESET, slot) < 0)
166        {
167                perr("CA_RESET");
168                return 1;
169        }
170
171        return 0;
172}
173
174int cagetslotinfo(struct dvbdev* node, ca_slot_info_t* info)
175{
176        if(node == NULL)
177        {
178                debug(1000, "out-> NULL detect");
179                return 1;
180        }
181
182        //info.num
183        //info.type
184        //info.flags (1:no, 2:present, 3:ready)
185
186        debug(200, "CA_GET_SLOT_INFO");
187        if(ioctl(node->fd, CA_GET_SLOT_INFO, info) < 0)
188        {
189                perr("CA_GET_SLOT_INFO");
190                return 1;
191        }
192
193        return 0;
194}
195
196int cagetdev()
197{
198        debug(1000, "in");
199        int i, y, fd = -1, count = 0;
200        char *buf = NULL, *cadev = NULL;
201
202        cadev = getconfig("cadev", NULL);
203        if(cadev == NULL)
204        {
205                debug(1000, "out -> NULL detect");
206                return count;
207        }
208
209        buf = malloc(MINMALLOC);
210        if(buf == NULL)
211        {
212                err("no memory");
213                return count;
214        }
215
216        for(i = 0; i < MAXDVBADAPTER; i++)
217        {
218                for(y = 0; y < MAXCADEV; y++)
219                {
220                        sprintf(buf, cadev, i, y);
221                        fd = caopendirect(buf);
222                        if(fd >= 0)
223                        {
224                                caclose(NULL, fd);
225                                count++;
226                                adddvbdev(buf, i, y, -1, CADEV, NULL, NULL);
227                        }
228                }
229        }
230
231        free(buf);
232        debug(1000, "out");
233        return count;
234}
235
236#endif
Note: See TracBrowser for help on using the repository browser.