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