1 | #ifndef CIDEV_H |
---|
2 | #define CIDEV_H |
---|
3 | |
---|
4 | struct dvbdev* ciopen(struct dvbdev* node) |
---|
5 | { |
---|
6 | int fd = -1; |
---|
7 | |
---|
8 | if(node != NULL) |
---|
9 | { |
---|
10 | if((fd = open(node->dev, O_RDWR | O_NONBLOCK)) < 0) |
---|
11 | { |
---|
12 | debug(200, "open ci failed %s", node->dev); |
---|
13 | node = NULL; |
---|
14 | } |
---|
15 | else |
---|
16 | { |
---|
17 | node->fd = fd; |
---|
18 | closeonexec(fd); |
---|
19 | } |
---|
20 | } |
---|
21 | |
---|
22 | return node; |
---|
23 | } |
---|
24 | |
---|
25 | int ciopendirect(char *cidev) |
---|
26 | { |
---|
27 | int fd = -1; |
---|
28 | |
---|
29 | if((fd = open(cidev, O_RDWR | O_NONBLOCK)) < 0) |
---|
30 | { |
---|
31 | debug(200, "open ci failed %s", cidev); |
---|
32 | } |
---|
33 | |
---|
34 | closeonexec(fd); |
---|
35 | return fd; |
---|
36 | } |
---|
37 | |
---|
38 | void ciclose(struct dvbdev* node, int fd) |
---|
39 | { |
---|
40 | if(node != NULL) |
---|
41 | { |
---|
42 | close(node->fd); |
---|
43 | node->fd = -1; |
---|
44 | } |
---|
45 | else |
---|
46 | close(fd); |
---|
47 | } |
---|
48 | |
---|
49 | int cigetdev() |
---|
50 | { |
---|
51 | int i = 0, y = 0, fd = -1, count = 0; |
---|
52 | char *buf = NULL, *cidev = NULL; |
---|
53 | |
---|
54 | cidev = getconfig("cidev", NULL); |
---|
55 | if(cidev == NULL) |
---|
56 | { |
---|
57 | err("NULL detect"); |
---|
58 | return count; |
---|
59 | } |
---|
60 | |
---|
61 | buf = malloc(MINMALLOC); |
---|
62 | if(buf == NULL) |
---|
63 | { |
---|
64 | err("no memory"); |
---|
65 | return count; |
---|
66 | } |
---|
67 | |
---|
68 | #ifdef MIPSEL |
---|
69 | for(y = 0; y < MAXCIDEV; y++) |
---|
70 | { |
---|
71 | sprintf(buf, cidev, y); |
---|
72 | fd = ciopendirect(buf); |
---|
73 | if(fd >= 0) |
---|
74 | { |
---|
75 | count++; |
---|
76 | adddvbdev(buf, i, y, fd, CIDEV, NULL, NULL, NULL, 0); |
---|
77 | } |
---|
78 | } |
---|
79 | #else |
---|
80 | for(i = 0; i < MAXDVBADAPTER; i++) |
---|
81 | { |
---|
82 | for(y = 0; y < MAXCIDEV; y++) |
---|
83 | { |
---|
84 | sprintf(buf, cidev, i, y); |
---|
85 | fd = ciopendirect(buf); |
---|
86 | if(fd >= 0) |
---|
87 | { |
---|
88 | count++; |
---|
89 | //if(y == 3) |
---|
90 | adddvbdev(buf, i, y, fd, CIDEV, NULL, NULL, NULL, 0); |
---|
91 | } |
---|
92 | } |
---|
93 | } |
---|
94 | #endif |
---|
95 | |
---|
96 | free(buf); |
---|
97 | return count; |
---|
98 | } |
---|
99 | |
---|
100 | #endif |
---|