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