1 | #ifndef SCDEV_H |
---|
2 | #define SCDEV_H |
---|
3 | |
---|
4 | #ifndef IOCTL_SET_RESET |
---|
5 | #define IOCTL_SET_RESET _IOW('s', 1, uint32_t) |
---|
6 | #endif |
---|
7 | |
---|
8 | #ifndef IOCTL_SET_MODES |
---|
9 | #define IOCTL_SET_MODES _IOW('s', 2, scimodes) |
---|
10 | #endif |
---|
11 | |
---|
12 | #ifndef IOCTL_GET_MODES |
---|
13 | #define IOCTL_GET_MODES _IOW('s', 3, scimodes) |
---|
14 | #endif |
---|
15 | |
---|
16 | #ifndef IOCTL_SET_PARAMETERS |
---|
17 | #define IOCTL_SET_PARAMETERS _IOW('s', 4, sciparameters) |
---|
18 | #endif |
---|
19 | |
---|
20 | #ifndef IOCTL_GET_PARAMETERS |
---|
21 | #define IOCTL_GET_PARAMETERS _IOW('s', 5, sciparameters) |
---|
22 | #endif |
---|
23 | |
---|
24 | #ifndef IOCTL_SET_CLOCK_START |
---|
25 | #define IOCTL_SET_CLOCK_START _IOW('s', 6, uint32_t) |
---|
26 | #endif |
---|
27 | |
---|
28 | #ifndef IOCTL_SET_CLOCK_STOP |
---|
29 | #define IOCTL_SET_CLOCK_STOP _IOW('s', 7, uint32_t) |
---|
30 | #endif |
---|
31 | |
---|
32 | #ifndef IOCTL_GET_IS_CARD_PRESENT |
---|
33 | #define IOCTL_GET_IS_CARD_PRESENT _IOW('s', 8, uint32_t) |
---|
34 | #endif |
---|
35 | |
---|
36 | #ifndef IOCTL_GET_IS_CARD_ACTIVATED |
---|
37 | #define IOCTL_GET_IS_CARD_ACTIVATED _IOW('s', 9, uint32_t) |
---|
38 | #endif |
---|
39 | |
---|
40 | #ifndef IOCTL_SET_DEACTIVATE |
---|
41 | #define IOCTL_SET_DEACTIVATE _IOW('s', 10, uint32_t) |
---|
42 | #endif |
---|
43 | |
---|
44 | #ifndef IOCTL_SET_ATR_READY |
---|
45 | #define IOCTL_SET_ATR_READY _IOW('s', 11, uint32_t) |
---|
46 | #endif |
---|
47 | |
---|
48 | #ifndef IOCTL_GET_ATR_STATUS |
---|
49 | #define IOCTL_GET_ATR_STATUS _IOW('s', 12, uint32_t) |
---|
50 | #endif |
---|
51 | |
---|
52 | #ifndef IOCTL_DUMP_REGS |
---|
53 | #define IOCTL_DUMP_REGS _IOW('s', 20, uint32_t) |
---|
54 | #endif |
---|
55 | |
---|
56 | #ifndef IOCTL_SET_CLOCK |
---|
57 | #define IOCTL_SET_CLOCK _IOW('s', 13, uint32_t) |
---|
58 | #endif |
---|
59 | |
---|
60 | #ifndef IOCTL_SET_ONLY_RESET |
---|
61 | #define IOCTL_SET_ONLY_RESET _IOW('s', 100, uint32_t) |
---|
62 | #endif |
---|
63 | |
---|
64 | struct dvbdev* scopen() |
---|
65 | { |
---|
66 | debug(1000, "in"); |
---|
67 | int fd = -1; |
---|
68 | struct dvbdev* node = dvbdev; |
---|
69 | |
---|
70 | while(node != NULL) |
---|
71 | { |
---|
72 | if(node->fd == -1 && node->type == SCDEV) |
---|
73 | break; |
---|
74 | node = node->next; |
---|
75 | } |
---|
76 | |
---|
77 | if(node != NULL) |
---|
78 | { |
---|
79 | if((fd = open(node->dev, O_RDWR)) < 0) |
---|
80 | { |
---|
81 | debug(200, "open sc failed %s", node->dev); |
---|
82 | node = NULL; |
---|
83 | } |
---|
84 | else |
---|
85 | { |
---|
86 | node->fd = fd; |
---|
87 | closeonexec(fd); |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | debug(1000, "out"); |
---|
92 | return node; |
---|
93 | } |
---|
94 | |
---|
95 | int scopendirect(char *scdev) |
---|
96 | { |
---|
97 | debug(1000, "in"); |
---|
98 | int fd = -1; |
---|
99 | |
---|
100 | if((fd = open(scdev, O_RDWR)) < 0) |
---|
101 | { |
---|
102 | debug(200, "open sc failed %s", scdev); |
---|
103 | } |
---|
104 | |
---|
105 | closeonexec(fd); |
---|
106 | debug(1000, "out"); |
---|
107 | return fd; |
---|
108 | } |
---|
109 | |
---|
110 | void scclose(struct dvbdev* node, int fd) |
---|
111 | { |
---|
112 | if(node != NULL) |
---|
113 | { |
---|
114 | close(node->fd); |
---|
115 | node->fd = -1; |
---|
116 | } |
---|
117 | else |
---|
118 | close(fd); |
---|
119 | } |
---|
120 | |
---|
121 | int scsetreset(struct dvbdev* node) |
---|
122 | { |
---|
123 | if(node == NULL) |
---|
124 | { |
---|
125 | debug(1000, "out-> NULL detect"); |
---|
126 | return 1; |
---|
127 | } |
---|
128 | |
---|
129 | debug(200, "IOCTL_SET_RESET"); |
---|
130 | if(ioctl(node->fd, IOCTL_SET_RESET) < 0) |
---|
131 | { |
---|
132 | perr("IOCTL_SET_RESET"); |
---|
133 | return 1; |
---|
134 | } |
---|
135 | |
---|
136 | return 0; |
---|
137 | } |
---|
138 | |
---|
139 | int scsetmodes(struct dvbdev* node, struct sci_modes* modes) |
---|
140 | { |
---|
141 | if(node == NULL || modes == NULL) |
---|
142 | { |
---|
143 | debug(1000, "out-> NULL detect"); |
---|
144 | return 1; |
---|
145 | } |
---|
146 | |
---|
147 | debug(200, "IOCTL_SET_MODES"); |
---|
148 | if(ioctl(node->fd, IOCTL_SET_MODES, modes) < 0) |
---|
149 | { |
---|
150 | perr("IOCTL_SET_MODES"); |
---|
151 | return 1; |
---|
152 | } |
---|
153 | |
---|
154 | return 0; |
---|
155 | } |
---|
156 | |
---|
157 | int scgetmodes(struct dvbdev* node, struct sci_modes* modes) |
---|
158 | { |
---|
159 | if(node == NULL || modes == NULL) |
---|
160 | { |
---|
161 | debug(1000, "out-> NULL detect"); |
---|
162 | return 1; |
---|
163 | } |
---|
164 | |
---|
165 | debug(200, "IOCTL_GET_MODES"); |
---|
166 | if(ioctl(node->fd, IOCTL_GET_MODES, modes) < 0) |
---|
167 | { |
---|
168 | perr("IOCTL_GET_MODES"); |
---|
169 | return 1; |
---|
170 | } |
---|
171 | |
---|
172 | return 0; |
---|
173 | } |
---|
174 | |
---|
175 | int scsetparameters(struct dvbdev* node, struct sci_parameters* parameters) |
---|
176 | { |
---|
177 | if(node == NULL || parameters == NULL) |
---|
178 | { |
---|
179 | debug(1000, "out-> NULL detect"); |
---|
180 | return 1; |
---|
181 | } |
---|
182 | |
---|
183 | debug(200, "IOCTL_SET_PARAMETERS"); |
---|
184 | if(ioctl(node->fd, IOCTL_SET_PARAMETERS, parameters) < 0) |
---|
185 | { |
---|
186 | perr("IOCTL_SET_PARAMETERS"); |
---|
187 | return 1; |
---|
188 | } |
---|
189 | |
---|
190 | return 0; |
---|
191 | } |
---|
192 | |
---|
193 | int scgetparameters(struct dvbdev* node, struct sci_parameters* parameters) |
---|
194 | { |
---|
195 | if(node == NULL || parameters == NULL) |
---|
196 | { |
---|
197 | debug(1000, "out-> NULL detect"); |
---|
198 | return 1; |
---|
199 | } |
---|
200 | |
---|
201 | debug(200, "IOCTL_GET_PARAMETERS"); |
---|
202 | if(ioctl(node->fd, IOCTL_GET_PARAMETERS, parameters) < 0) |
---|
203 | { |
---|
204 | perr("IOCTL_GET_PARAMETERS"); |
---|
205 | return 1; |
---|
206 | } |
---|
207 | |
---|
208 | return 0; |
---|
209 | } |
---|
210 | |
---|
211 | int scsetclockstart(struct dvbdev* node) |
---|
212 | { |
---|
213 | if(node == NULL) |
---|
214 | { |
---|
215 | debug(1000, "out-> NULL detect"); |
---|
216 | return 1; |
---|
217 | } |
---|
218 | |
---|
219 | debug(200, "IOCTL_SET_CLOCK_START"); |
---|
220 | if(ioctl(node->fd, IOCTL_SET_CLOCK_START) < 0) |
---|
221 | { |
---|
222 | perr("IOCTL_SET_CLOCK_START"); |
---|
223 | return 1; |
---|
224 | } |
---|
225 | |
---|
226 | return 0; |
---|
227 | } |
---|
228 | |
---|
229 | int scsetclockstop(struct dvbdev* node) |
---|
230 | { |
---|
231 | if(node == NULL) |
---|
232 | { |
---|
233 | debug(1000, "out-> NULL detect"); |
---|
234 | return 1; |
---|
235 | } |
---|
236 | |
---|
237 | debug(200, "IOCTL_SET_CLOCK_STOP"); |
---|
238 | if(ioctl(node->fd, IOCTL_SET_CLOCK_STOP) < 0) |
---|
239 | { |
---|
240 | perr("IOCTL_SET_CLOCK_STOP"); |
---|
241 | return 1; |
---|
242 | } |
---|
243 | |
---|
244 | return 0; |
---|
245 | } |
---|
246 | |
---|
247 | int scgetiscardpresent(struct dvbdev* node, uint32_t* status) |
---|
248 | { |
---|
249 | if(node == NULL) |
---|
250 | { |
---|
251 | debug(1000, "out-> NULL detect"); |
---|
252 | return 1; |
---|
253 | } |
---|
254 | |
---|
255 | debug(200, "IOCTL_GET_IS_CARD_PRESENT"); |
---|
256 | if(ioctl(node->fd, IOCTL_GET_IS_CARD_PRESENT, status) < 0) |
---|
257 | { |
---|
258 | perr("IOCTL_GET_IS_CARD_PRESENT"); |
---|
259 | return 1; |
---|
260 | } |
---|
261 | |
---|
262 | return 0; |
---|
263 | } |
---|
264 | |
---|
265 | int scgetiscardactivated(struct dvbdev* node, uint32_t* status) |
---|
266 | { |
---|
267 | if(node == NULL) |
---|
268 | { |
---|
269 | debug(1000, "out-> NULL detect"); |
---|
270 | return 1; |
---|
271 | } |
---|
272 | |
---|
273 | debug(200, "IOCTL_GET_IS_CARD_ACTIVATED"); |
---|
274 | if(ioctl(node->fd, IOCTL_GET_IS_CARD_ACTIVATED, status) < 0) |
---|
275 | { |
---|
276 | perr("IOCTL_GET_IS_CARD_ACTIVATED"); |
---|
277 | return 1; |
---|
278 | } |
---|
279 | |
---|
280 | return 0; |
---|
281 | } |
---|
282 | |
---|
283 | int scsetdeactivate(struct dvbdev* node) |
---|
284 | { |
---|
285 | if(node == NULL) |
---|
286 | { |
---|
287 | debug(1000, "out-> NULL detect"); |
---|
288 | return 1; |
---|
289 | } |
---|
290 | |
---|
291 | debug(200, "IOCTL_SET_DEACTIVATE"); |
---|
292 | if(ioctl(node->fd, IOCTL_SET_DEACTIVATE) < 0) |
---|
293 | { |
---|
294 | perr("IOCTL_SET_DEACTIVATE"); |
---|
295 | return 1; |
---|
296 | } |
---|
297 | |
---|
298 | return 0; |
---|
299 | } |
---|
300 | |
---|
301 | int scsetatrready(struct dvbdev* node) |
---|
302 | { |
---|
303 | if(node == NULL) |
---|
304 | { |
---|
305 | debug(1000, "out-> NULL detect"); |
---|
306 | return 1; |
---|
307 | } |
---|
308 | |
---|
309 | debug(200, "IOCTL_SET_ATR_READY"); |
---|
310 | if(ioctl(node->fd, IOCTL_SET_ATR_READY) < 0) |
---|
311 | { |
---|
312 | perr("IOCTL_SET_ATR_READY"); |
---|
313 | return 1; |
---|
314 | } |
---|
315 | |
---|
316 | return 0; |
---|
317 | } |
---|
318 | |
---|
319 | int scgetatrstatus(struct dvbdev* node, uint32_t* status) |
---|
320 | { |
---|
321 | if(node == NULL) |
---|
322 | { |
---|
323 | debug(1000, "out-> NULL detect"); |
---|
324 | return 1; |
---|
325 | } |
---|
326 | |
---|
327 | debug(200, "IOCTL_GET_ATR_STATUS"); |
---|
328 | if(ioctl(node->fd, IOCTL_GET_ATR_STATUS, status) < 0) |
---|
329 | { |
---|
330 | perr("IOCTL_GET_ATR_STATUS"); |
---|
331 | return 1; |
---|
332 | } |
---|
333 | |
---|
334 | return 0; |
---|
335 | } |
---|
336 | |
---|
337 | int scsetclock(struct dvbdev* node, uint32_t* clock) |
---|
338 | { |
---|
339 | if(node == NULL) |
---|
340 | { |
---|
341 | debug(1000, "out-> NULL detect"); |
---|
342 | return 1; |
---|
343 | } |
---|
344 | |
---|
345 | debug(200, "IOCTL_SET_CLOCK"); |
---|
346 | if(ioctl(node->fd, IOCTL_SET_CLOCK, clock) < 0) |
---|
347 | { |
---|
348 | perr("IOCTL_SET_CLOCK"); |
---|
349 | return 1; |
---|
350 | } |
---|
351 | |
---|
352 | return 0; |
---|
353 | } |
---|
354 | |
---|
355 | int scsetonlyreset(struct dvbdev* node) |
---|
356 | { |
---|
357 | if(node == NULL) |
---|
358 | { |
---|
359 | debug(1000, "out-> NULL detect"); |
---|
360 | return 1; |
---|
361 | } |
---|
362 | |
---|
363 | debug(200, "IOCTL_SET_ONLY_RESET"); |
---|
364 | if(ioctl(node->fd, IOCTL_SET_ONLY_RESET) < 0) |
---|
365 | { |
---|
366 | perr("IOCTL_SET_ONLY_RESET"); |
---|
367 | return 1; |
---|
368 | } |
---|
369 | |
---|
370 | return 0; |
---|
371 | } |
---|
372 | |
---|
373 | int scgetdev() |
---|
374 | { |
---|
375 | debug(1000, "in"); |
---|
376 | int i, y, fd = -1, count = 0; |
---|
377 | char *buf = NULL, *scdev = NULL; |
---|
378 | |
---|
379 | scdev = getconfig("scdev", NULL); |
---|
380 | if(scdev == NULL) |
---|
381 | { |
---|
382 | debug(1000, "out -> NULL detect"); |
---|
383 | return count; |
---|
384 | } |
---|
385 | |
---|
386 | buf = malloc(MINMALLOC); |
---|
387 | if(buf == NULL) |
---|
388 | { |
---|
389 | err("no memory"); |
---|
390 | return count; |
---|
391 | } |
---|
392 | |
---|
393 | for(i = 0; i < MAXDVBADAPTER; i++) |
---|
394 | { |
---|
395 | for(y = 0; y < MAXSCDEV; y++) |
---|
396 | { |
---|
397 | sprintf(buf, scdev, i, y); |
---|
398 | fd = scopendirect(buf); |
---|
399 | if(fd >= 0) |
---|
400 | { |
---|
401 | scclose(NULL, fd); |
---|
402 | count++; |
---|
403 | adddvbdev(buf, i, y, -1, SCDEV, NULL, NULL, 0); |
---|
404 | } |
---|
405 | } |
---|
406 | } |
---|
407 | |
---|
408 | free(buf); |
---|
409 | debug(1000, "out"); |
---|
410 | return count; |
---|
411 | } |
---|
412 | |
---|
413 | #endif |
---|