1 | #define MODULE_LOG_PREFIX "serial"
|
---|
2 |
|
---|
3 | #include "globals.h"
|
---|
4 | #ifdef MODULE_SERIAL
|
---|
5 | #include "oscam-config.h"
|
---|
6 | #include "oscam-client.h"
|
---|
7 | #include "oscam-ecm.h"
|
---|
8 | #include "oscam-net.h"
|
---|
9 | #include "oscam-string.h"
|
---|
10 | #include "oscam-time.h"
|
---|
11 | #include "oscam-reader.h"
|
---|
12 |
|
---|
13 | extern int32_t exit_oscam;
|
---|
14 |
|
---|
15 | #define HSIC_CRC 0xA5
|
---|
16 | #define SSSP_MAX_PID 8
|
---|
17 |
|
---|
18 | #define P_HSIC 1 // Humax Sharing Interface Client
|
---|
19 | #define P_SSSP 2 // Simple Serial Sharing Protocol
|
---|
20 | #define P_BOMBA 3 // This is not really a Protocol
|
---|
21 | #define P_DSR95 4 // DSR9500 with SID
|
---|
22 | #define P_GS 5 // GS7001
|
---|
23 | #define P_ALPHA 6 // AlphaStar Receivers
|
---|
24 | #define P_DSR95_OLD 7 // DSR9500 without SID
|
---|
25 | #define P_GBOX 8 // Arion with gbox
|
---|
26 | #define P_TWIN 9 // Twin Protocol
|
---|
27 | #define P_MAX P_TWIN
|
---|
28 | #define P_AUTO 0xFF
|
---|
29 |
|
---|
30 | #define P_DSR_AUTO 0
|
---|
31 | #define P_DSR_GNUSMAS 1
|
---|
32 | #define P_DSR_OPEN 2
|
---|
33 | #define P_DSR_PIONEER 3
|
---|
34 | #define P_DSR_WITHSID 4
|
---|
35 | #define P_DSR_UNKNOWN 5
|
---|
36 |
|
---|
37 | #define IS_ECM 0 // incoming data is ECM
|
---|
38 | #define IS_DCW 1 // incoming data is DCW
|
---|
39 | #define IS_PMT 2 // incoming data is PMT
|
---|
40 | #define IS_LGO 3 // incoming data is client logon
|
---|
41 | #define IS_ECHO 4 // incoming data is DCW echo from Samsung
|
---|
42 | #define IS_CAT 5 // incoming data is CAT
|
---|
43 | #define IS_BAD 0xFF // incoming data is unknown
|
---|
44 |
|
---|
45 | static const char *const proto_txt[] = { "unknown", "hsic", "sssp", "bomba", "dsr9500", "gs",
|
---|
46 | "alpha", "dsr9500old", "gbox", "twin" };
|
---|
47 |
|
---|
48 | static const char *const dsrproto_txt[] = {"unknown", "samsung", "openbox", "pioneer", "extended", "unknown" };
|
---|
49 |
|
---|
50 | typedef struct s_gbox
|
---|
51 | {
|
---|
52 | int32_t cat_len;
|
---|
53 | int32_t pmt_len;
|
---|
54 | int32_t ecm_len;
|
---|
55 | } GBOX_LENS;
|
---|
56 |
|
---|
57 | typedef struct s_sssp
|
---|
58 | {
|
---|
59 | uint16_t caid;
|
---|
60 | uint16_t pid;
|
---|
61 | uint32_t prid;
|
---|
62 | } SSSP_TAB;
|
---|
63 |
|
---|
64 | // added to support multiple instances with thread
|
---|
65 | struct s_serial_client
|
---|
66 | {
|
---|
67 | int32_t connected;
|
---|
68 | struct timeb tps;
|
---|
69 | struct timeb tpe;
|
---|
70 | char oscam_ser_usr[32];
|
---|
71 | char oscam_ser_device[64];
|
---|
72 | int32_t oscam_ser_port;
|
---|
73 | speed_t oscam_ser_baud;
|
---|
74 | int32_t oscam_ser_delay;
|
---|
75 | int32_t oscam_ser_timeout;
|
---|
76 | int32_t oscam_ser_proto;
|
---|
77 | int32_t serial_errors;
|
---|
78 | int32_t dsr9500type;
|
---|
79 | int32_t samsung_0a; // number of 0A in ALL dcw sent into samsung
|
---|
80 | int32_t samsung_dcw; // number of dcw sent into samsung before echo or ecm is received
|
---|
81 |
|
---|
82 | GBOX_LENS gbox_lens;
|
---|
83 | SSSP_TAB sssp_tab[SSSP_MAX_PID];
|
---|
84 | uint16_t sssp_srvid;
|
---|
85 | int32_t sssp_num;
|
---|
86 | int32_t sssp_fix;
|
---|
87 | };
|
---|
88 |
|
---|
89 | static pthread_mutex_t mutex;
|
---|
90 | static pthread_cond_t cond;
|
---|
91 | static int32_t bcopy_end = -1;
|
---|
92 | static struct s_module *serial_ph = NULL;
|
---|
93 |
|
---|
94 | struct s_thread_param
|
---|
95 | {
|
---|
96 | uint8_t module_idx;
|
---|
97 | struct s_serial_client serialdata;
|
---|
98 | };
|
---|
99 |
|
---|
100 | static int32_t chk_ser_srvid_match(uint16_t caid, uint16_t sid, uint32_t provid, SIDTAB *sidtab)
|
---|
101 | {
|
---|
102 | int32_t i, rc = 0;
|
---|
103 |
|
---|
104 | if(!sidtab->num_caid)
|
---|
105 | { rc |= 1; }
|
---|
106 | else
|
---|
107 | for(i = 0; (i < sidtab->num_caid) && (!(rc & 1)); i++)
|
---|
108 | if(caid == sidtab->caid[i]) { rc |= 1; }
|
---|
109 |
|
---|
110 | if(!sidtab->num_provid)
|
---|
111 | { rc |= 2; }
|
---|
112 | else
|
---|
113 | for(i = 0; (i < sidtab->num_provid) && (!(rc & 2)); i++)
|
---|
114 | if(provid == sidtab->provid[i]) { rc |= 2; }
|
---|
115 |
|
---|
116 | if(!sidtab->num_srvid)
|
---|
117 | { rc |= 4; }
|
---|
118 | else
|
---|
119 | for(i = 0; (i < sidtab->num_srvid) && (!(rc & 4)); i++)
|
---|
120 | if(sid == sidtab->srvid[i]) { rc |= 4; }
|
---|
121 |
|
---|
122 | return (rc == 7);
|
---|
123 | }
|
---|
124 |
|
---|
125 | static int32_t chk_ser_srvid(struct s_client *cl, uint16_t caid, uint16_t sid, uint32_t provid)
|
---|
126 | {
|
---|
127 | int32_t nr, rc = 0;
|
---|
128 | SIDTAB *sidtab;
|
---|
129 |
|
---|
130 | if(!cl->sidtabs.ok)
|
---|
131 | {
|
---|
132 | if(!cl->sidtabs.no) { return (1); }
|
---|
133 | rc = 1;
|
---|
134 | }
|
---|
135 | for(nr = 0, sidtab = cfg.sidtab; sidtab; sidtab = sidtab->next, nr++)
|
---|
136 | if(sidtab->num_caid | sidtab->num_provid | sidtab->num_srvid)
|
---|
137 | {
|
---|
138 | if((cl->sidtabs.no & ((SIDTABBITS)1 << nr)) &&
|
---|
139 | (chk_ser_srvid_match(caid, sid, provid, sidtab)))
|
---|
140 | { return (0); }
|
---|
141 | if((cl->sidtabs.ok & ((SIDTABBITS)1 << nr)) &&
|
---|
142 | (chk_ser_srvid_match(caid, sid, provid, sidtab)))
|
---|
143 | { rc = 1; }
|
---|
144 | }
|
---|
145 | return (rc);
|
---|
146 | }
|
---|
147 |
|
---|
148 | static void oscam_wait_ser_fork(void)
|
---|
149 | {
|
---|
150 | SAFE_MUTEX_LOCK(&mutex);
|
---|
151 | do
|
---|
152 | {
|
---|
153 | if(bcopy_end)
|
---|
154 | {
|
---|
155 | bcopy_end = 0;
|
---|
156 | break;
|
---|
157 | }
|
---|
158 | else
|
---|
159 | { SAFE_COND_WAIT(&cond, &mutex); }
|
---|
160 | }
|
---|
161 | while(1);
|
---|
162 | SAFE_MUTEX_UNLOCK(&mutex);
|
---|
163 | }
|
---|
164 |
|
---|
165 | static int32_t oscam_ser_alpha_convert(uint8_t *buf, int32_t l)
|
---|
166 | {
|
---|
167 | int32_t i;
|
---|
168 | if(buf[0] == 0x7E) // normalize
|
---|
169 | {
|
---|
170 | l -= 2;
|
---|
171 | memmove(buf, buf + 1, l); // remove BOT/EOT
|
---|
172 | for(i = 0; i < l; i++)
|
---|
173 | if(buf[i] == 0x20)
|
---|
174 | {
|
---|
175 | memmove(buf + i, buf + i + 1, --l);
|
---|
176 | buf[i] ^= 0x20;
|
---|
177 | }
|
---|
178 | }
|
---|
179 | else // to alphastar
|
---|
180 | {
|
---|
181 | memmove(buf + 1, buf, l++); // insert BOT
|
---|
182 | buf[0] = 0x7E;
|
---|
183 | for(i = 1; i < l; i++)
|
---|
184 | if((buf[i] == 0x20) || (buf[i] == 0x7E) || (buf[i] == 0x7F))
|
---|
185 | {
|
---|
186 | buf[i] ^= 0x20;
|
---|
187 | memmove(buf + i + 1, buf + i, l++);
|
---|
188 | buf[i++] = 0x20;
|
---|
189 | }
|
---|
190 | buf[l++] = 0x7F; // insert EOT
|
---|
191 | }
|
---|
192 | return (l);
|
---|
193 | }
|
---|
194 |
|
---|
195 | static void oscam_ser_disconnect(void);
|
---|
196 |
|
---|
197 | static int32_t oscam_ser_parse_url(char *url, struct s_serial_client *serialdata, char *pcltype)
|
---|
198 | {
|
---|
199 | char *service, *usr, *dev, *baud = NULL, *dummy, *para;
|
---|
200 | char cltype;
|
---|
201 |
|
---|
202 | cltype = pcltype ? (*pcltype) : cur_client()->typ;
|
---|
203 |
|
---|
204 | serialdata->oscam_ser_proto = P_AUTO;
|
---|
205 | if((dummy = strstr(url, "://")))
|
---|
206 | {
|
---|
207 | int32_t i;
|
---|
208 | service = url;
|
---|
209 | url = dummy + 3;
|
---|
210 | *dummy = 0;
|
---|
211 | for(i = 1; i <= P_MAX; i++)
|
---|
212 | if(!strcmp(service, proto_txt[i]))
|
---|
213 | { serialdata->oscam_ser_proto = i; }
|
---|
214 | }
|
---|
215 | if(!(cltype == 'c') && (serialdata->oscam_ser_proto == P_AUTO)) { return (0); }
|
---|
216 |
|
---|
217 | switch(serialdata->oscam_ser_proto) // set the defaults
|
---|
218 | {
|
---|
219 | case P_GS:
|
---|
220 | serialdata->oscam_ser_timeout = 500;
|
---|
221 | serialdata->oscam_ser_baud = B19200;
|
---|
222 | break;
|
---|
223 |
|
---|
224 | default:
|
---|
225 | serialdata->oscam_ser_timeout = 50;
|
---|
226 | #ifdef B115200
|
---|
227 | serialdata->oscam_ser_baud = B115200;
|
---|
228 | #else
|
---|
229 | serialdata->oscam_ser_baud = B9600;
|
---|
230 | #endif
|
---|
231 | }
|
---|
232 |
|
---|
233 | switch(serialdata->oscam_ser_proto)
|
---|
234 | {
|
---|
235 | case P_DSR95:
|
---|
236 | serialdata->dsr9500type = (cltype == 'c') ? P_DSR_AUTO : P_DSR_WITHSID;
|
---|
237 | break;
|
---|
238 |
|
---|
239 | case P_DSR95_OLD:
|
---|
240 | serialdata->dsr9500type = P_DSR_AUTO;
|
---|
241 | serialdata->oscam_ser_proto = P_DSR95;
|
---|
242 | }
|
---|
243 |
|
---|
244 | usr = url;
|
---|
245 | if((dev = strchr(usr, '@')))
|
---|
246 | {
|
---|
247 | *dev++ = '\0';
|
---|
248 | if((dummy = strchr(usr, ':'))) // fake pwd
|
---|
249 | { *dummy++ = '\0'; }
|
---|
250 | if((cltype == 'c') && (!usr[0])) { return (0); }
|
---|
251 | }
|
---|
252 | else
|
---|
253 | {
|
---|
254 | if(cltype == 'c') { return (0); } // user needed in server-mode
|
---|
255 | dev = usr;
|
---|
256 | }
|
---|
257 |
|
---|
258 | if((baud = strchr(dev, ':'))) // port = baud
|
---|
259 | { *baud++ = '\0'; }
|
---|
260 |
|
---|
261 | dummy = baud ? baud : dev;
|
---|
262 | if((para = strchr(dummy, '?')))
|
---|
263 | {
|
---|
264 | char *ptr1, *ptr2, *saveptr1 = NULL;
|
---|
265 | *para++ = '\0';
|
---|
266 | for(ptr1 = strtok_r(para, "&", &saveptr1); ptr1; ptr1 = strtok_r(NULL, "&", &saveptr1))
|
---|
267 | {
|
---|
268 | if(!(ptr2 = strchr(ptr1, '='))) { continue; }
|
---|
269 | *ptr2++ = '\0';
|
---|
270 | strtolower(ptr1);
|
---|
271 | if(!strcmp("delay" , ptr1)) { serialdata->oscam_ser_delay = atoi(ptr2); }
|
---|
272 | if(!strcmp("timeout", ptr1)) { serialdata->oscam_ser_timeout = atoi(ptr2); }
|
---|
273 | }
|
---|
274 | }
|
---|
275 |
|
---|
276 | if(baud)
|
---|
277 | {
|
---|
278 | trim(baud);
|
---|
279 | #ifdef B115200
|
---|
280 | if(!strcmp(baud, "115200"))
|
---|
281 | { serialdata->oscam_ser_baud = B115200; }
|
---|
282 | else
|
---|
283 | #endif
|
---|
284 | #ifdef B57600
|
---|
285 | if(!strcmp(baud, "57600"))
|
---|
286 | { serialdata->oscam_ser_baud = B57600; }
|
---|
287 | else
|
---|
288 | #endif
|
---|
289 | if(!strcmp(baud, "38400"))
|
---|
290 | { serialdata->oscam_ser_baud = B38400; }
|
---|
291 | else if(!strcmp(baud, "19200"))
|
---|
292 | { serialdata->oscam_ser_baud = B19200; }
|
---|
293 | else if(!strcmp(baud, "9600"))
|
---|
294 | { serialdata->oscam_ser_baud = B9600; }
|
---|
295 | }
|
---|
296 |
|
---|
297 | if((para = strchr(dev, ','))) // device = ip/hostname and port
|
---|
298 | {
|
---|
299 | *para++ = '\0';
|
---|
300 | serialdata->oscam_ser_port = atoi(para);
|
---|
301 | }
|
---|
302 | else
|
---|
303 | { serialdata->oscam_ser_port = 0; }
|
---|
304 | cs_strncpy(serialdata->oscam_ser_usr, usr, sizeof(serialdata->oscam_ser_usr));
|
---|
305 | cs_strncpy(serialdata->oscam_ser_device, dev, sizeof(serialdata->oscam_ser_device));
|
---|
306 | return (serialdata->oscam_ser_baud);
|
---|
307 | }
|
---|
308 |
|
---|
309 | static void oscam_ser_set_baud(struct termios *tio, speed_t baud)
|
---|
310 | {
|
---|
311 | cfsetospeed(tio, baud);
|
---|
312 | cfsetispeed(tio, baud);
|
---|
313 | }
|
---|
314 |
|
---|
315 | static int32_t oscam_ser_set_serial_device(int32_t fd, speed_t baud)
|
---|
316 | {
|
---|
317 | struct termios tio;
|
---|
318 |
|
---|
319 | memset(&tio, 0, sizeof(tio));
|
---|
320 | //tio.c_cflag = (CS8 | CREAD | HUPCL | CLOCAL);
|
---|
321 | tio.c_cflag = (CS8 | CREAD | CLOCAL);
|
---|
322 | tio.c_iflag = IGNPAR;
|
---|
323 | tio.c_cc[VMIN] = 1;
|
---|
324 | tio.c_cc[VTIME] = 0;
|
---|
325 | //#if !defined(__CYGWIN__)
|
---|
326 | oscam_ser_set_baud(&tio, B1200);
|
---|
327 | tcsetattr(fd, TCSANOW, &tio);
|
---|
328 | cs_sleepms(500);
|
---|
329 | //#endif
|
---|
330 | oscam_ser_set_baud(&tio, baud);
|
---|
331 | return (tcsetattr(fd, TCSANOW, &tio));
|
---|
332 | }
|
---|
333 |
|
---|
334 | static int32_t oscam_ser_poll(int32_t event, struct s_client *client)
|
---|
335 | {
|
---|
336 | int64_t msec;
|
---|
337 | struct pollfd pfds;
|
---|
338 | struct timeb tpc;
|
---|
339 | cs_ftime(&tpc);
|
---|
340 | msec = comp_timeb(&client->serialdata->tpe, &tpc);
|
---|
341 | if(msec < 0)
|
---|
342 | { return (0); }
|
---|
343 | pfds.fd = cur_client()->pfd;
|
---|
344 | pfds.events = event;
|
---|
345 | pfds.revents = 0;
|
---|
346 | if(poll(&pfds, 1, msec) != 1)
|
---|
347 | { return (0); }
|
---|
348 | else
|
---|
349 | { return (((pfds.revents)&event) == event); }
|
---|
350 | }
|
---|
351 |
|
---|
352 | static int32_t oscam_ser_write(struct s_client *client, const uint8_t *const buf, int32_t n)
|
---|
353 | {
|
---|
354 | int32_t i;
|
---|
355 | for(i = 0; (i < n) && (oscam_ser_poll(POLLOUT, client)); i++)
|
---|
356 | {
|
---|
357 | if(client->serialdata->oscam_ser_delay)
|
---|
358 | { cs_sleepms(client->serialdata->oscam_ser_delay); }
|
---|
359 | if(write(client->pfd, buf + i, 1) < 1)
|
---|
360 | { break; }
|
---|
361 | }
|
---|
362 | return (i);
|
---|
363 | }
|
---|
364 |
|
---|
365 | static int32_t oscam_ser_send(struct s_client *client, const uint8_t *const buf, int32_t l)
|
---|
366 | {
|
---|
367 | int32_t n;
|
---|
368 | struct s_serial_client *serialdata = client->serialdata ;
|
---|
369 | if(!client->pfd) { return (0); }
|
---|
370 | cs_ftime(&serialdata->tps);
|
---|
371 | serialdata->tpe = client->serialdata->tps;
|
---|
372 | add_ms_to_timeb(&serialdata->tpe, serialdata->oscam_ser_timeout);
|
---|
373 | add_ms_to_timeb(&serialdata->tpe, (l * (serialdata->oscam_ser_delay + 1)));
|
---|
374 | n = oscam_ser_write(client, buf, l);
|
---|
375 | cs_ftime(&serialdata->tpe);
|
---|
376 | cs_log_dump_dbg(D_CLIENT, buf, l, "send %d of %d bytes to %s in %"PRId64" ms", n, l, remote_txt(),
|
---|
377 | comp_timeb(&serialdata->tpe, &serialdata->tps));
|
---|
378 | if(n != l)
|
---|
379 | { cs_log("transmit error. send %d of %d bytes only !", n, l); }
|
---|
380 | return (n);
|
---|
381 | }
|
---|
382 |
|
---|
383 | static int32_t oscam_ser_selrec(uint8_t *buf, int32_t n, int32_t l, int32_t *c)
|
---|
384 | {
|
---|
385 | int32_t i;
|
---|
386 | if(*c + n > l)
|
---|
387 | { n = l - *c; }
|
---|
388 | if(n <= 0) { return (0); }
|
---|
389 | for(i = 0; (i < n) && (oscam_ser_poll(POLLIN, cur_client())); i++)
|
---|
390 | if(read(cur_client()->pfd, buf + *c, 1) < 1)
|
---|
391 | { return (0); }
|
---|
392 | else
|
---|
393 | { (*c)++; }
|
---|
394 | return (i == n);
|
---|
395 | }
|
---|
396 |
|
---|
397 | static int32_t oscam_ser_recv(struct s_client *client, uint8_t *xbuf, int32_t l)
|
---|
398 | {
|
---|
399 | int32_t s, p, n, r;
|
---|
400 | uint8_t job = IS_BAD;
|
---|
401 | static uint8_t lb;
|
---|
402 | static int32_t have_lb = 0;
|
---|
403 | uint8_t *buf = xbuf + 1;
|
---|
404 | struct s_serial_client *serialdata = client->serialdata;
|
---|
405 |
|
---|
406 | if(!client->pfd) { return (-1); }
|
---|
407 | cs_ftime(&serialdata->tps);
|
---|
408 | serialdata->tpe = serialdata->tps;
|
---|
409 | add_ms_to_timeb(&serialdata->tpe, serialdata->oscam_ser_timeout);
|
---|
410 | buf[0] = lb;
|
---|
411 | for(s = p = r = 0, n = have_lb; (s < 4) && (p >= 0); s++)
|
---|
412 | {
|
---|
413 | switch(s)
|
---|
414 | {
|
---|
415 | case 0: // STAGE 0: skip known garbage from DSR9500
|
---|
416 | if(oscam_ser_selrec(buf, 2 - n, l, &n))
|
---|
417 | {
|
---|
418 | if((buf[0] == 0x0A) && (buf[1] == 0x0D))
|
---|
419 | { p = (-4); }
|
---|
420 | if((buf[0] == 0x0D) && (buf[1] == 0x0A))
|
---|
421 | { p = (-4); }
|
---|
422 | }
|
---|
423 | else
|
---|
424 | { p = (-3); }
|
---|
425 | have_lb = 0;
|
---|
426 | break;
|
---|
427 |
|
---|
428 | case 1: // STAGE 1: identify protocol
|
---|
429 | p = (-3);
|
---|
430 | if(oscam_ser_selrec(buf, 1, l, &n)) // now we have 3 bytes in buf
|
---|
431 | {
|
---|
432 | // skip unsupported Advanced Serial Sharing Protocol HF 8900
|
---|
433 | if((buf[0] == 0x04) && (buf[1] == 0x00) && (buf[2] == 0x02))
|
---|
434 | {
|
---|
435 | oscam_ser_selrec(buf, 2, l, &n); // get rest 2 bytes to buffor
|
---|
436 | p = (-4);
|
---|
437 | have_lb = 0;
|
---|
438 | break;
|
---|
439 | }
|
---|
440 | else
|
---|
441 | {
|
---|
442 | p = (-2);
|
---|
443 | if(client->typ == 'c') // HERE IS SERVER
|
---|
444 | {
|
---|
445 | job = IS_ECM; // assume ECM
|
---|
446 | switch(buf[0])
|
---|
447 | {
|
---|
448 | case 0x00:
|
---|
449 | if((buf[1] == 0x01) && (buf[2] == 0x00))
|
---|
450 | {
|
---|
451 | p = P_GS;
|
---|
452 | job = IS_LGO;
|
---|
453 | serialdata->tpe.time++;
|
---|
454 | }
|
---|
455 | break;
|
---|
456 |
|
---|
457 | case 0x01:
|
---|
458 | if((buf[1] & 0xf0) == 0xb0) { p = P_GBOX; }
|
---|
459 | else
|
---|
460 | {
|
---|
461 | p = P_SSSP;
|
---|
462 | job = IS_PMT;
|
---|
463 | }
|
---|
464 | break; // pmt-request
|
---|
465 |
|
---|
466 | case 0x02:
|
---|
467 | p = P_HSIC;
|
---|
468 | break;
|
---|
469 |
|
---|
470 | case 0x03:
|
---|
471 | switch(serialdata->oscam_ser_proto)
|
---|
472 | {
|
---|
473 | case P_SSSP:
|
---|
474 | case P_GS:
|
---|
475 | case P_DSR95:
|
---|
476 | p = serialdata->oscam_ser_proto;
|
---|
477 | break;
|
---|
478 |
|
---|
479 | case P_AUTO:
|
---|
480 | p = (buf[1] < 0x30) ? P_SSSP : P_DSR95;
|
---|
481 | break; // auto for GS is useless!!
|
---|
482 | }
|
---|
483 | break;
|
---|
484 |
|
---|
485 | case 0x04:
|
---|
486 | p = P_DSR95;
|
---|
487 | job = IS_ECHO;
|
---|
488 | serialdata->dsr9500type = P_DSR_GNUSMAS;
|
---|
489 | break;
|
---|
490 |
|
---|
491 | case 0x7E:
|
---|
492 | p = P_ALPHA;
|
---|
493 | if(buf[1] != 0x80) { job = IS_BAD; }
|
---|
494 | break;
|
---|
495 |
|
---|
496 | case 0x80:
|
---|
497 | case 0x81:
|
---|
498 | p = P_BOMBA;
|
---|
499 | break;
|
---|
500 | }
|
---|
501 | }
|
---|
502 | else // HERE IS CLIENT
|
---|
503 | {
|
---|
504 | job = IS_DCW; // assume DCW
|
---|
505 | switch(serialdata->oscam_ser_proto)
|
---|
506 | {
|
---|
507 | case P_HSIC :
|
---|
508 | if((buf[0] == 4) && (buf[1] == 4)) { p = P_HSIC; }
|
---|
509 | break;
|
---|
510 |
|
---|
511 | case P_BOMBA:
|
---|
512 | p = P_BOMBA;
|
---|
513 | break;
|
---|
514 |
|
---|
515 | case P_DSR95:
|
---|
516 | if(buf[0] == 4) { p = P_DSR95; }
|
---|
517 | break;
|
---|
518 |
|
---|
519 | case P_ALPHA:
|
---|
520 | if(buf[0] == 0x88) { p = P_ALPHA; }
|
---|
521 | break;
|
---|
522 |
|
---|
523 | case P_TWIN:
|
---|
524 | if((buf[0] == 0xF7) && (buf[1] == 0x00) && (buf[2] == 0x16)) { p = P_TWIN; }
|
---|
525 | break;
|
---|
526 | }
|
---|
527 | }
|
---|
528 |
|
---|
529 | if((serialdata->oscam_ser_proto != p) && (serialdata->oscam_ser_proto != P_AUTO))
|
---|
530 | { p = (-2); }
|
---|
531 | }
|
---|
532 | }
|
---|
533 | break;
|
---|
534 |
|
---|
535 | case 2: // STAGE 2: examine length
|
---|
536 | if(client->typ == 'c')
|
---|
537 | {
|
---|
538 | switch(p)
|
---|
539 | {
|
---|
540 | case P_SSSP:
|
---|
541 | r = (buf[1] << 8) | buf[2];
|
---|
542 | break;
|
---|
543 |
|
---|
544 | case P_BOMBA:
|
---|
545 | r = buf[2];
|
---|
546 | break;
|
---|
547 |
|
---|
548 | case P_HSIC:
|
---|
549 | if(oscam_ser_selrec(buf, 12, l, &n)) { r = buf[14]; }
|
---|
550 | else { p = (-1); }
|
---|
551 | break;
|
---|
552 |
|
---|
553 | case P_DSR95:
|
---|
554 | if(job == IS_ECHO)
|
---|
555 | {
|
---|
556 | r = 17 * serialdata->samsung_dcw - 3 + serialdata->samsung_0a;
|
---|
557 | serialdata->samsung_dcw = serialdata->samsung_0a = 0;
|
---|
558 | }
|
---|
559 | else
|
---|
560 | {
|
---|
561 | if(oscam_ser_selrec(buf, 16, l, &n))
|
---|
562 | {
|
---|
563 | uint8_t b;
|
---|
564 | if(cs_atob(&b, (char *)buf + 17, 1) < 0)
|
---|
565 | { p = (-2); }
|
---|
566 | else
|
---|
567 | {
|
---|
568 | r = (b << 1);
|
---|
569 | r += (serialdata->dsr9500type == P_DSR_WITHSID) ? 4 : 0;
|
---|
570 | }
|
---|
571 | }
|
---|
572 | else { p = (-1); }
|
---|
573 | }
|
---|
574 | break;
|
---|
575 |
|
---|
576 | case P_GS:
|
---|
577 | if(job == IS_LGO) { r = 5; }
|
---|
578 | else
|
---|
579 | {
|
---|
580 | if(oscam_ser_selrec(buf, 1, l, &n))
|
---|
581 | { r = (buf[3] << 8) | buf[2]; }
|
---|
582 | else { p = (-1); }
|
---|
583 | }
|
---|
584 | break;
|
---|
585 |
|
---|
586 | case P_ALPHA:
|
---|
587 | r = -0x7F; // char specifying EOT
|
---|
588 | break;
|
---|
589 |
|
---|
590 | case P_GBOX:
|
---|
591 | r = ((buf[1] & 0xf) << 8) | buf[2];
|
---|
592 | serialdata->gbox_lens.cat_len = r;
|
---|
593 | break;
|
---|
594 |
|
---|
595 | default:
|
---|
596 | serialdata->dsr9500type = P_DSR_AUTO;
|
---|
597 | }
|
---|
598 | }
|
---|
599 | else
|
---|
600 | {
|
---|
601 | switch(p)
|
---|
602 | {
|
---|
603 | case P_HSIC:
|
---|
604 | r = (buf[2] == 0x3A) ? 20 : 0;
|
---|
605 | break; // 3A=DCW / FC=ECM was wrong
|
---|
606 |
|
---|
607 | case P_BOMBA:
|
---|
608 | r = 13;
|
---|
609 | break;
|
---|
610 |
|
---|
611 | case P_DSR95:
|
---|
612 | r = 14;
|
---|
613 | break;
|
---|
614 |
|
---|
615 | case P_ALPHA:
|
---|
616 | r = (buf[1] << 8) | buf[2];
|
---|
617 | break; // should be 16 always
|
---|
618 |
|
---|
619 | case P_TWIN:
|
---|
620 | r = 16;
|
---|
621 | break;
|
---|
622 | }
|
---|
623 | }
|
---|
624 | break;
|
---|
625 |
|
---|
626 | case 3: // STAGE 3: get the rest...
|
---|
627 | if(r > 0) // read r additional bytes
|
---|
628 | {
|
---|
629 | int32_t all = n + r;
|
---|
630 | if(!oscam_ser_selrec(buf, r, l, &n))
|
---|
631 | {
|
---|
632 | cs_log_dbg(D_CLIENT, "not all data received, waiting another 50 ms");
|
---|
633 | add_ms_to_timeb(&serialdata->tpe, 50);
|
---|
634 | if(!oscam_ser_selrec(buf, all - n, l, &n))
|
---|
635 | { p = (-1); }
|
---|
636 | }
|
---|
637 | // auto detect DSR9500 protocol
|
---|
638 | if(client->typ == 'c' && p == P_DSR95 && serialdata->dsr9500type == P_DSR_AUTO)
|
---|
639 | {
|
---|
640 | add_ms_to_timeb(&serialdata->tpe, 20);
|
---|
641 | if(oscam_ser_selrec(buf, 2, l, &n))
|
---|
642 | {
|
---|
643 | if(cs_atoi((char *)buf + n - 2, 1, 1) == 0xFFFFFFFF)
|
---|
644 | {
|
---|
645 | switch((buf[n - 2] << 8) | buf[n - 1])
|
---|
646 | {
|
---|
647 | case 0x0A0D:
|
---|
648 | serialdata->dsr9500type = P_DSR_OPEN;
|
---|
649 | break;
|
---|
650 |
|
---|
651 | case 0x0D0A:
|
---|
652 | serialdata->dsr9500type = P_DSR_PIONEER;
|
---|
653 | break;
|
---|
654 |
|
---|
655 | default:
|
---|
656 | serialdata->dsr9500type = P_DSR_UNKNOWN;
|
---|
657 | break;
|
---|
658 | }
|
---|
659 | }
|
---|
660 | else
|
---|
661 | {
|
---|
662 | if(oscam_ser_selrec(buf, 2, l, &n))
|
---|
663 | if(cs_atoi((char *)buf + n - 2, 1, 1) == 0xFFFFFFFF)
|
---|
664 | { serialdata->dsr9500type = P_DSR_UNKNOWN; }
|
---|
665 | else
|
---|
666 | { serialdata->dsr9500type = P_DSR_WITHSID; }
|
---|
667 | else
|
---|
668 | {
|
---|
669 | serialdata->dsr9500type = P_DSR_UNKNOWN;
|
---|
670 | p = (-1);
|
---|
671 | }
|
---|
672 | }
|
---|
673 | }
|
---|
674 | else
|
---|
675 | { serialdata->dsr9500type = P_DSR_GNUSMAS; }
|
---|
676 | if(p)
|
---|
677 | cs_log("detected dsr9500-%s type receiver",
|
---|
678 | dsrproto_txt[serialdata->dsr9500type]);
|
---|
679 | }
|
---|
680 | // gbox
|
---|
681 | if(client->typ == 'c' && p == P_GBOX)
|
---|
682 | {
|
---|
683 | int32_t j;
|
---|
684 | for(j = 0; (j < 3) && (p > 0); j++)
|
---|
685 | {
|
---|
686 | switch(j)
|
---|
687 | {
|
---|
688 | case 0: // PMT head
|
---|
689 | if(!oscam_ser_selrec(buf, 3, l, &n))
|
---|
690 | { p = (-1); }
|
---|
691 | else if(!(buf[n - 3] == 0x02 && (buf[n - 2] & 0xf0) == 0xb0))
|
---|
692 | { p = (-2); }
|
---|
693 | break;
|
---|
694 |
|
---|
695 | case 1: // PMT + ECM header
|
---|
696 | serialdata->gbox_lens.pmt_len = ((buf[n - 2] & 0xf) << 8) | buf[n - 1];
|
---|
697 | if(!oscam_ser_selrec(buf, serialdata->gbox_lens.pmt_len + 3, l, &n))
|
---|
698 | { p = (-1); }
|
---|
699 | break;
|
---|
700 |
|
---|
701 | case 2: // ECM + ECM PID
|
---|
702 | serialdata->gbox_lens.ecm_len = ((buf[n - 2] & 0xf) << 8) | buf[n - 1];
|
---|
703 | if(!oscam_ser_selrec(buf, serialdata->gbox_lens.ecm_len + 4, l, &n))
|
---|
704 | { p = (-1); }
|
---|
705 | }
|
---|
706 | }
|
---|
707 | } // gbox
|
---|
708 | }
|
---|
709 | else if(r < 0) // read until specified char (-r)
|
---|
710 | {
|
---|
711 | while((buf[n - 1] != (-r)) && (p > 0))
|
---|
712 | if(!oscam_ser_selrec(buf, 1, l, &n))
|
---|
713 | { p = (-1); }
|
---|
714 | }
|
---|
715 | break;
|
---|
716 | }
|
---|
717 | }
|
---|
718 |
|
---|
719 | if(p == (-2) || p == (-1))
|
---|
720 | {
|
---|
721 | oscam_ser_selrec(buf, l - n, l, &n); // flush buffer
|
---|
722 | serialdata->serial_errors++;
|
---|
723 | }
|
---|
724 |
|
---|
725 | cs_ftime(&serialdata->tpe);
|
---|
726 | cs_log_dump_dbg(D_CLIENT, buf, n, "received %d bytes from %s in %"PRId64" ms", n, remote_txt(), comp_timeb(&serialdata->tpe, &serialdata->tps));
|
---|
727 | client->last = serialdata->tpe.time;
|
---|
728 |
|
---|
729 | switch(p)
|
---|
730 | {
|
---|
731 | case (-1):
|
---|
732 | if(client->typ == 'c' && (n > 2) && (buf[0] == 2) && (buf[1] == 2) && (buf[2] == 2))
|
---|
733 | {
|
---|
734 | oscam_ser_disconnect();
|
---|
735 | cs_log("humax powered on"); // this is nice ;)
|
---|
736 | }
|
---|
737 | else
|
---|
738 | {
|
---|
739 | if(client->typ == 'c' && buf[0] == 0x1 && buf[1] == 0x08 && buf[2] == 0x20 && buf[3] == 0x08)
|
---|
740 | {
|
---|
741 | oscam_ser_disconnect();
|
---|
742 | cs_log("ferguson powered on"); // this is nice to ;)
|
---|
743 | }
|
---|
744 | else
|
---|
745 | cs_log("incomplete request (%d bytes)", n);
|
---|
746 | }
|
---|
747 | break;
|
---|
748 |
|
---|
749 | case (-2):
|
---|
750 | cs_log_dbg(D_CLIENT, "unknown request or garbage");
|
---|
751 | break;
|
---|
752 | }
|
---|
753 |
|
---|
754 | xbuf[0] = (uint8_t)((job << 4) | p);
|
---|
755 | return ((p < 0) ? 0 : n + 1);
|
---|
756 | }
|
---|
757 |
|
---|
758 | /*
|
---|
759 | * server functions
|
---|
760 | */
|
---|
761 |
|
---|
762 | static void oscam_ser_disconnect_client(void)
|
---|
763 | {
|
---|
764 | uint8_t mbuf[1024];
|
---|
765 | struct s_serial_client *serialdata = cur_client()->serialdata;
|
---|
766 |
|
---|
767 | switch(serialdata->connected ? serialdata->connected : serialdata->oscam_ser_proto)
|
---|
768 | {
|
---|
769 | case P_GS:
|
---|
770 | mbuf[0] = 0x01;
|
---|
771 | mbuf[1] = 0x00;
|
---|
772 | mbuf[2] = 0x00;
|
---|
773 | mbuf[3] = 0x00;
|
---|
774 | oscam_ser_send(cur_client(), mbuf, 4);
|
---|
775 | break;
|
---|
776 | }
|
---|
777 | serialdata->dsr9500type = P_DSR_AUTO;
|
---|
778 | serialdata->serial_errors = 0;
|
---|
779 | }
|
---|
780 |
|
---|
781 | static void oscam_ser_init_client(void)
|
---|
782 | {
|
---|
783 | uint8_t mbuf[4];
|
---|
784 | switch(cur_client()->serialdata->oscam_ser_proto) // sure, does not work in auto-mode
|
---|
785 | {
|
---|
786 | case P_GS:
|
---|
787 | oscam_ser_disconnect_client(); // send disconnect first
|
---|
788 | cs_sleepms(300); // wait a little bit
|
---|
789 | mbuf[0] = 0x00;
|
---|
790 | mbuf[1] = 0x00;
|
---|
791 | mbuf[2] = 0x00;
|
---|
792 | mbuf[3] = 0x00;
|
---|
793 | oscam_ser_send(cur_client(), mbuf, 4); // send connect
|
---|
794 | break;
|
---|
795 | }
|
---|
796 | }
|
---|
797 |
|
---|
798 | static void oscam_ser_disconnect(void)
|
---|
799 | {
|
---|
800 | oscam_ser_disconnect_client();
|
---|
801 | if(cur_client()->serialdata->connected)
|
---|
802 | { cs_log("%s disconnected (%s)", username(cur_client()), proto_txt[cur_client()->serialdata->connected]); }
|
---|
803 | cur_client()->serialdata->connected = 0;
|
---|
804 | }
|
---|
805 |
|
---|
806 | static void oscam_ser_auth_client(int32_t proto)
|
---|
807 | {
|
---|
808 | int32_t ok = 0;
|
---|
809 | struct s_serial_client *serialdata = cur_client()->serialdata;
|
---|
810 | // After reload base account ptrs may be placed in other address,
|
---|
811 | // and we may can't find it in this process.
|
---|
812 | // Simply save valid account.
|
---|
813 | struct s_auth *account = 0;
|
---|
814 |
|
---|
815 | if(serialdata->connected == proto)
|
---|
816 | { return; }
|
---|
817 | if(serialdata->connected)
|
---|
818 | { oscam_ser_disconnect(); }
|
---|
819 | serialdata->connected = proto;
|
---|
820 |
|
---|
821 | for(ok = 0, account = cfg.account; (account) && (!ok); account = account->next)
|
---|
822 | if((ok = !strcmp(serialdata->oscam_ser_usr, account->usr)))
|
---|
823 | { break; }
|
---|
824 | cs_auth_client(cur_client(), ok ? account : (struct s_auth *)(-1), proto_txt[serialdata->connected]);
|
---|
825 | }
|
---|
826 |
|
---|
827 | static void oscam_ser_send_dcw(struct s_client *client, ECM_REQUEST *er)
|
---|
828 | {
|
---|
829 | uint8_t mbuf[23];
|
---|
830 | int32_t i;
|
---|
831 | uint8_t crc;
|
---|
832 | struct s_serial_client *serialdata = cur_client()->serialdata;
|
---|
833 |
|
---|
834 | if(er->rc < E_NOTFOUND) // found
|
---|
835 | {
|
---|
836 | switch(serialdata->connected)
|
---|
837 | {
|
---|
838 | case P_HSIC:
|
---|
839 | for(i = 0, crc = HSIC_CRC; i < 16; i++)
|
---|
840 | { crc ^= er->cw[i]; }
|
---|
841 | memset(mbuf, 0x04, 2);
|
---|
842 | memset(mbuf + 2, 0x3a, 2);
|
---|
843 | memcpy(mbuf + 4, er->cw, 16);
|
---|
844 | memcpy(mbuf + 20, &crc, 1);
|
---|
845 | memset(mbuf + 21, 0x1b, 2);
|
---|
846 | oscam_ser_send(client, mbuf, 23);
|
---|
847 | break;
|
---|
848 |
|
---|
849 | case P_SSSP:
|
---|
850 | mbuf[0] = 0xF2;
|
---|
851 | mbuf[1] = 0;
|
---|
852 | mbuf[2] = 16;
|
---|
853 | memcpy(mbuf + 3, er->cw, 16);
|
---|
854 | oscam_ser_send(client, mbuf, 19);
|
---|
855 | if(!serialdata->sssp_fix)
|
---|
856 | {
|
---|
857 | mbuf[0] = 0xF1;
|
---|
858 | mbuf[1] = 0;
|
---|
859 | mbuf[2] = 2;
|
---|
860 | i2b_buf(2, er->pid, mbuf + 3);
|
---|
861 | oscam_ser_send(client, mbuf, 5);
|
---|
862 | serialdata->sssp_fix = 1;
|
---|
863 | }
|
---|
864 | break;
|
---|
865 |
|
---|
866 | case P_GBOX:
|
---|
867 | case P_BOMBA:
|
---|
868 | oscam_ser_send(client, er->cw, 16);
|
---|
869 | break;
|
---|
870 |
|
---|
871 | case P_DSR95:
|
---|
872 | mbuf[0] = 4;
|
---|
873 | memcpy(mbuf + 1, er->cw, 16);
|
---|
874 | oscam_ser_send(client, mbuf, 17);
|
---|
875 | if(serialdata->dsr9500type == P_DSR_GNUSMAS)
|
---|
876 | {
|
---|
877 | serialdata->samsung_0a = 0;
|
---|
878 | for(i = 1; i < 17; i++)
|
---|
879 | if(mbuf[i] == 0x0A)
|
---|
880 | { serialdata->samsung_0a++; }
|
---|
881 | serialdata->samsung_dcw++;
|
---|
882 | }
|
---|
883 | break;
|
---|
884 |
|
---|
885 | case P_GS:
|
---|
886 | mbuf[0] = 0x03;
|
---|
887 | mbuf[1] = 0x08;
|
---|
888 | mbuf[2] = 0x10;
|
---|
889 | mbuf[3] = 0x00;
|
---|
890 | memcpy(mbuf + 4, er->cw, 16);
|
---|
891 | oscam_ser_send(client, mbuf, 20);
|
---|
892 | break;
|
---|
893 |
|
---|
894 | case P_ALPHA:
|
---|
895 | mbuf[0] = 0x88;
|
---|
896 | mbuf[1] = 0x00;
|
---|
897 | mbuf[2] = 0x10;
|
---|
898 | memcpy(mbuf + 3, er->cw, 16);
|
---|
899 | oscam_ser_send(client, mbuf, 19);
|
---|
900 | break;
|
---|
901 | }
|
---|
902 | }
|
---|
903 | else // not found
|
---|
904 | {
|
---|
905 | switch(serialdata->connected)
|
---|
906 | {
|
---|
907 | case P_GS:
|
---|
908 | mbuf[0] = 0x03;
|
---|
909 | mbuf[1] = 0x09;
|
---|
910 | mbuf[2] = 0x00;
|
---|
911 | mbuf[3] = 0x00;
|
---|
912 | oscam_ser_send(client, mbuf, 4);
|
---|
913 | break;
|
---|
914 | }
|
---|
915 | }
|
---|
916 | serialdata->serial_errors = 0; // clear error counter
|
---|
917 | }
|
---|
918 |
|
---|
919 | static void oscam_ser_process_pmt(uint8_t *buf, int32_t l)
|
---|
920 | {
|
---|
921 | int32_t i;
|
---|
922 | uint8_t sbuf[32];
|
---|
923 | struct s_serial_client *serialdata = cur_client()->serialdata;
|
---|
924 |
|
---|
925 | switch(serialdata->connected)
|
---|
926 | {
|
---|
927 | case P_SSSP:
|
---|
928 | serialdata->sssp_fix = 0;
|
---|
929 | memset(serialdata->sssp_tab, 0, sizeof(serialdata->sssp_tab));
|
---|
930 | serialdata->sssp_srvid = b2i(2, buf + 3);
|
---|
931 | serialdata->sssp_num = 0;
|
---|
932 |
|
---|
933 | for(i = 9; (i < l) && (serialdata->sssp_num < SSSP_MAX_PID); i += 7)
|
---|
934 | {
|
---|
935 | // check support for pid (caid, sid and provid in oscam.services)
|
---|
936 | if(chk_ser_srvid(cur_client(), b2i(2, buf + i), b2i(2, buf + 3), b2i(3, buf + i + 4)))
|
---|
937 | {
|
---|
938 | memcpy(sbuf + 3 + (serialdata->sssp_num << 1), buf + i + 2, 2);
|
---|
939 | serialdata->sssp_tab[serialdata->sssp_num].caid = b2i(2, buf + i);
|
---|
940 | serialdata->sssp_tab[serialdata->sssp_num].pid = b2i(2, buf + i + 2);
|
---|
941 | serialdata->sssp_tab[serialdata->sssp_num].prid = b2i(3, buf + i + 4);
|
---|
942 | serialdata->sssp_num++;
|
---|
943 | }
|
---|
944 | }
|
---|
945 |
|
---|
946 | sbuf[0] = 0xF1;
|
---|
947 | sbuf[1] = 0;
|
---|
948 | sbuf[2] = (serialdata->sssp_num << 1);
|
---|
949 | oscam_ser_send(cur_client(), sbuf, sbuf[2] + 3);
|
---|
950 | break;
|
---|
951 | }
|
---|
952 | }
|
---|
953 |
|
---|
954 | static void oscam_ser_client_logon(uint8_t *buf, int32_t l)
|
---|
955 | {
|
---|
956 | uint8_t gs_logon[] = {0, 1, 0, 0, 2, 1, 0, 0};
|
---|
957 |
|
---|
958 | switch(cur_client()->serialdata->connected)
|
---|
959 | {
|
---|
960 | case P_GS:
|
---|
961 | if((l >= 8) && (!memcmp(buf, gs_logon, 8)))
|
---|
962 | {
|
---|
963 | buf[0] = 0x02;
|
---|
964 | buf[1] = 0x04;
|
---|
965 | buf[2] = 0x00;
|
---|
966 | buf[3] = 0x00;
|
---|
967 | oscam_ser_send(cur_client(), buf, 4);
|
---|
968 | }
|
---|
969 | break;
|
---|
970 | }
|
---|
971 | }
|
---|
972 |
|
---|
973 | static int32_t oscam_ser_check_ecm(ECM_REQUEST *er, uint8_t *buf, int32_t l)
|
---|
974 | {
|
---|
975 | int32_t i;
|
---|
976 | struct s_serial_client *serialdata = cur_client()->serialdata;
|
---|
977 |
|
---|
978 | if(l < 16)
|
---|
979 | {
|
---|
980 | cs_log("incomplete request (%d bytes)", l);
|
---|
981 | return (1);
|
---|
982 | }
|
---|
983 |
|
---|
984 | switch(serialdata->connected)
|
---|
985 | {
|
---|
986 | case P_HSIC:
|
---|
987 | er->ecmlen = l - 12;
|
---|
988 | if(er->ecmlen < 0 || er->ecmlen > MAX_ECM_SIZE)
|
---|
989 | { return (3); }
|
---|
990 | er->caid = b2i(2, buf + 1);
|
---|
991 | er->prid = b2i(3, buf + 3);
|
---|
992 | er->pid = b2i(2, buf + 6);
|
---|
993 | er->srvid = b2i(2, buf + 10);
|
---|
994 | memcpy(er->ecm, buf + 12, er->ecmlen);
|
---|
995 | break;
|
---|
996 |
|
---|
997 | case P_SSSP:
|
---|
998 | er->pid = b2i(2, buf + 3);
|
---|
999 |
|
---|
1000 | for(i = 0; (i < 8) && (serialdata->sssp_tab[i].pid != er->pid); i++) { ; }
|
---|
1001 |
|
---|
1002 | if(i >= serialdata->sssp_num)
|
---|
1003 | {
|
---|
1004 | cs_log_dbg(D_CLIENT, "illegal request, unknown pid=%04X", er->pid);
|
---|
1005 | return (2);
|
---|
1006 | }
|
---|
1007 | er->ecmlen = l - 5;
|
---|
1008 | if(er->ecmlen < 0 || er->ecmlen > MAX_ECM_SIZE)
|
---|
1009 | { return (3); }
|
---|
1010 | er->srvid = serialdata->sssp_srvid;
|
---|
1011 | er->caid = serialdata->sssp_tab[i].caid;
|
---|
1012 | er->prid = serialdata->sssp_tab[i].prid;
|
---|
1013 | memcpy(er->ecm, buf + 5, er->ecmlen);
|
---|
1014 | break;
|
---|
1015 |
|
---|
1016 | case P_BOMBA:
|
---|
1017 | er->ecmlen = l;
|
---|
1018 | if(er->ecmlen < 0 || er->ecmlen > MAX_ECM_SIZE)
|
---|
1019 | { return (3); }
|
---|
1020 | memcpy(er->ecm, buf, er->ecmlen);
|
---|
1021 | break;
|
---|
1022 |
|
---|
1023 | case P_DSR95:
|
---|
1024 | buf[l] = '\0'; // prepare for trim
|
---|
1025 | trim((char *)buf + 13); // strip spc, nl, cr ...
|
---|
1026 | er->ecmlen = strlen((char *)buf + 13) >> 1;
|
---|
1027 | if(er->ecmlen < 0 || er->ecmlen > MAX_ECM_SIZE)
|
---|
1028 | { return (3); }
|
---|
1029 | er->prid = cs_atoi((char *)buf + 3, 3, 0); // ignore errors
|
---|
1030 | er->caid = cs_atoi((char *)buf + 9, 2, 0); // ignore errors
|
---|
1031 | if(cs_atob(er->ecm, (char *)buf + 13, er->ecmlen) < 0)
|
---|
1032 | {
|
---|
1033 | cs_log("illegal characters in ecm-request");
|
---|
1034 | return (1);
|
---|
1035 | }
|
---|
1036 | if(serialdata->dsr9500type == P_DSR_WITHSID)
|
---|
1037 | {
|
---|
1038 | er->ecmlen -= 2;
|
---|
1039 | if(er->ecmlen < 0)
|
---|
1040 | { return (3); }
|
---|
1041 | er->srvid = cs_atoi((char *)buf + 13 + (er->ecmlen << 1), 2, 0);
|
---|
1042 | }
|
---|
1043 | break;
|
---|
1044 |
|
---|
1045 | case P_GS:
|
---|
1046 | er->ecmlen = ((buf[3] << 8) | buf[2]) - 6;
|
---|
1047 | er->srvid = (buf[5] << 8) | buf[4]; // sid
|
---|
1048 | er->caid = (buf[7] << 8) | buf[6];
|
---|
1049 | er->prid = 0;
|
---|
1050 |
|
---|
1051 | if(er->ecmlen < 0 || er->ecmlen > MAX_ECM_SIZE || (10 + er->ecmlen > l))
|
---|
1052 | { return (3); }
|
---|
1053 | memcpy(er->ecm, buf + 10, er->ecmlen);
|
---|
1054 | break;
|
---|
1055 |
|
---|
1056 | case P_ALPHA:
|
---|
1057 | l = oscam_ser_alpha_convert(buf, l);
|
---|
1058 | er->ecmlen = b2i(2, buf + 1) - 2;
|
---|
1059 | er->caid = b2i(2, buf + 3);
|
---|
1060 | if((er->ecmlen != l - 5) || (er->ecmlen > MAX_ECM_SIZE) || (er->ecmlen < 0))
|
---|
1061 | {
|
---|
1062 | cs_log("incomplete request (%d bytes)", l);
|
---|
1063 | return (1);
|
---|
1064 | }
|
---|
1065 | memcpy(er->ecm, buf + 5, er->ecmlen);
|
---|
1066 | break;
|
---|
1067 |
|
---|
1068 | case P_GBOX:
|
---|
1069 | if(((serialdata->gbox_lens.cat_len + 3 + 3 + 1) > l)
|
---|
1070 | || ((serialdata->gbox_lens.ecm_len + 3) > l))
|
---|
1071 | {
|
---|
1072 | return (3);
|
---|
1073 | }
|
---|
1074 | er->srvid = b2i(2, buf + serialdata->gbox_lens.cat_len + 3 + 3);
|
---|
1075 | er->ecmlen = serialdata->gbox_lens.ecm_len + 3;
|
---|
1076 |
|
---|
1077 | if(er->ecmlen < 0 || er->ecmlen > MAX_ECM_SIZE)
|
---|
1078 | { return (3); }
|
---|
1079 | if(serialdata->gbox_lens.cat_len + 3 + serialdata->gbox_lens.pmt_len + 3 + er->ecmlen > l)
|
---|
1080 | { return (3); }
|
---|
1081 |
|
---|
1082 | memcpy(er->ecm, buf + serialdata->gbox_lens.cat_len + 3 + serialdata->gbox_lens.pmt_len + 3, er->ecmlen);
|
---|
1083 | break;
|
---|
1084 | }
|
---|
1085 | return (0);
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 | static void oscam_ser_process_ecm(uint8_t *buf, int32_t l)
|
---|
1089 | {
|
---|
1090 | ECM_REQUEST *er;
|
---|
1091 |
|
---|
1092 | if(!(er = get_ecmtask()))
|
---|
1093 | { return; }
|
---|
1094 |
|
---|
1095 | switch(oscam_ser_check_ecm(er, buf, l))
|
---|
1096 | {
|
---|
1097 | default:
|
---|
1098 | case 3:
|
---|
1099 | case 2:
|
---|
1100 | //er->rc = E_CORRUPT;
|
---|
1101 | NULLFREE(er);
|
---|
1102 | return; // error without log
|
---|
1103 | case 1:
|
---|
1104 | er->rc = E_CORRUPT; // error with log
|
---|
1105 | break;
|
---|
1106 | }
|
---|
1107 | get_cw(cur_client(), er);
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 |
|
---|
1111 | static void oscam_ser_server(void)
|
---|
1112 | {
|
---|
1113 | int32_t n;
|
---|
1114 | uint8_t mbuf[1024];
|
---|
1115 | int32_t *pserial_errors = &cur_client()->serialdata->serial_errors;
|
---|
1116 |
|
---|
1117 | cur_client()->serialdata->connected = 0;
|
---|
1118 | oscam_ser_init_client();
|
---|
1119 |
|
---|
1120 | while((n = process_input(mbuf, sizeof(mbuf), INT_MAX)) > 0)
|
---|
1121 | {
|
---|
1122 | if((*pserial_errors) > 3)
|
---|
1123 | {
|
---|
1124 | cs_log("too many errors, reiniting...");
|
---|
1125 | break;
|
---|
1126 | }
|
---|
1127 |
|
---|
1128 | oscam_ser_auth_client(mbuf[0] & 0xF);
|
---|
1129 | switch(mbuf[0] >> 4)
|
---|
1130 | {
|
---|
1131 | case IS_ECM:
|
---|
1132 | oscam_ser_process_ecm(mbuf + 1, n - 1);
|
---|
1133 | break;
|
---|
1134 | case IS_PMT:
|
---|
1135 | oscam_ser_process_pmt(mbuf + 1, n - 1);
|
---|
1136 | break;
|
---|
1137 | case IS_LGO:
|
---|
1138 | oscam_ser_client_logon(mbuf + 1, n - 1);
|
---|
1139 | break;
|
---|
1140 | }
|
---|
1141 | }
|
---|
1142 |
|
---|
1143 | if(cur_client()->serialdata->oscam_ser_port > 0)
|
---|
1144 | { network_tcp_connection_close(cur_client()->reader, "error reading from socket"); }
|
---|
1145 | oscam_ser_disconnect();
|
---|
1146 | }
|
---|
1147 |
|
---|
1148 | static int32_t init_oscam_ser_device(struct s_client *cl)
|
---|
1149 | {
|
---|
1150 | char *device = cl->serialdata->oscam_ser_device;
|
---|
1151 | speed_t baud = cl->serialdata->oscam_ser_baud;
|
---|
1152 | int32_t port = cl->serialdata->oscam_ser_port;
|
---|
1153 | int32_t fd;
|
---|
1154 |
|
---|
1155 | // network connection to a TCP-exposed serial port
|
---|
1156 | if(port > 0)
|
---|
1157 | {
|
---|
1158 | cs_strncpy(cl->reader->device, device, sizeof(cl->reader->device));
|
---|
1159 | cl->reader->r_port = cl->port = port;
|
---|
1160 | fd = network_tcp_connection_open(cl->reader);
|
---|
1161 | if(fd < 0)
|
---|
1162 | { return 0; }
|
---|
1163 | else
|
---|
1164 | { return fd; }
|
---|
1165 | }
|
---|
1166 | else // standard serial port connection
|
---|
1167 | {
|
---|
1168 | fd = open(device, O_RDWR | O_NOCTTY | O_SYNC | O_NONBLOCK);
|
---|
1169 | if(fd > 0)
|
---|
1170 | {
|
---|
1171 | fcntl(fd, F_SETFL, 0);
|
---|
1172 | if(oscam_ser_set_serial_device(fd, baud) < 0) { cs_log("ERROR ioctl"); }
|
---|
1173 | if(tcflush(fd, TCIOFLUSH) < 0) { cs_log("ERROR flush"); }
|
---|
1174 | }
|
---|
1175 | else
|
---|
1176 | {
|
---|
1177 | fd = 0;
|
---|
1178 | cs_log("ERROR opening %s (errno=%d %s)", device, errno, strerror(errno));
|
---|
1179 | }
|
---|
1180 | return (fd);
|
---|
1181 | }
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | static void oscam_copy_serialdata(struct s_serial_client *dest, struct s_serial_client *src)
|
---|
1185 | {
|
---|
1186 | if(dest && src)
|
---|
1187 | {
|
---|
1188 | dest->connected = src->connected;
|
---|
1189 | memcpy(&dest->tps, &src->tps, sizeof(dest->tps));
|
---|
1190 | memcpy(&dest->tpe, &src->tpe, sizeof(dest->tpe));
|
---|
1191 | memcpy(&dest->oscam_ser_usr, &src->oscam_ser_usr, sizeof(dest->oscam_ser_usr));
|
---|
1192 | memcpy(&dest->oscam_ser_device, &src->oscam_ser_device, sizeof(dest->oscam_ser_device));
|
---|
1193 | dest->oscam_ser_port = src->oscam_ser_port;
|
---|
1194 | dest->oscam_ser_baud = src->oscam_ser_baud;
|
---|
1195 | dest->oscam_ser_delay = src->oscam_ser_delay;
|
---|
1196 | dest->oscam_ser_timeout = src->oscam_ser_timeout;
|
---|
1197 | dest->oscam_ser_proto = src->oscam_ser_proto;
|
---|
1198 | dest->serial_errors = src->serial_errors;
|
---|
1199 | dest->dsr9500type = src->dsr9500type;
|
---|
1200 | dest->samsung_0a = src->samsung_0a; // number of 0A in ALL dcw sent into samsung
|
---|
1201 | dest->samsung_dcw = src->samsung_dcw; // number of dcw sent into samsung before echo or ecm is received
|
---|
1202 |
|
---|
1203 | dest->gbox_lens = src->gbox_lens;
|
---|
1204 | memcpy(&dest->sssp_tab, &src->sssp_tab, sizeof(dest->sssp_tab));
|
---|
1205 | dest->sssp_srvid = src->sssp_srvid;
|
---|
1206 | dest->sssp_num = src->sssp_num;
|
---|
1207 | dest->sssp_fix = src->sssp_fix;
|
---|
1208 | }
|
---|
1209 | }
|
---|
1210 |
|
---|
1211 | static void oscam_init_serialdata(struct s_serial_client *dest)
|
---|
1212 | {
|
---|
1213 | if(dest)
|
---|
1214 | {
|
---|
1215 | memset(dest, 0, sizeof(struct s_serial_client));
|
---|
1216 | dest->oscam_ser_timeout = 50;
|
---|
1217 | dest->dsr9500type = P_DSR_AUTO;
|
---|
1218 | }
|
---|
1219 | }
|
---|
1220 |
|
---|
1221 | static void *oscam_ser_fork(void *pthreadparam)
|
---|
1222 | {
|
---|
1223 | struct s_thread_param *pparam = (struct s_thread_param *) pthreadparam;
|
---|
1224 | struct s_client *cl = create_client(get_null_ip());
|
---|
1225 | SAFE_SETSPECIFIC(getclient, cl);
|
---|
1226 | cl->thread = pthread_self();
|
---|
1227 | cl->typ = 'c';
|
---|
1228 | cl->module_idx = pparam->module_idx;
|
---|
1229 | cl->account = first_client->account;
|
---|
1230 |
|
---|
1231 | if(!cl->serialdata && !cs_malloc(&cl->serialdata, sizeof(struct s_serial_client)))
|
---|
1232 | { return NULL; }
|
---|
1233 |
|
---|
1234 | set_thread_name(__func__);
|
---|
1235 | oscam_init_serialdata(cl->serialdata);
|
---|
1236 | oscam_copy_serialdata(cl->serialdata, &pparam->serialdata);
|
---|
1237 |
|
---|
1238 | if(cl->serialdata->oscam_ser_port > 0)
|
---|
1239 | {
|
---|
1240 | // reader struct for serial network connection
|
---|
1241 | struct s_reader *newrdr;
|
---|
1242 | if(!cs_malloc(&newrdr, sizeof(struct s_reader)))
|
---|
1243 | { return NULL; }
|
---|
1244 | memset(newrdr, 0, sizeof(struct s_reader));
|
---|
1245 | newrdr->client = cl;
|
---|
1246 | newrdr->ph = *serial_ph;
|
---|
1247 | cl->reader = newrdr;
|
---|
1248 | cs_strncpy(cl->reader->label, "network-socket", sizeof(cl->reader->label));
|
---|
1249 | }
|
---|
1250 |
|
---|
1251 | cs_log("serial: initialized (%s@%s)", cl->serialdata->oscam_ser_proto > P_MAX ?
|
---|
1252 | "auto" : proto_txt[cl->serialdata->oscam_ser_proto], cl->serialdata->oscam_ser_device);
|
---|
1253 |
|
---|
1254 | SAFE_MUTEX_LOCK(&mutex);
|
---|
1255 | bcopy_end = 1;
|
---|
1256 | SAFE_MUTEX_UNLOCK(&mutex);
|
---|
1257 | SAFE_COND_SIGNAL(&cond);
|
---|
1258 |
|
---|
1259 | while(!exit_oscam)
|
---|
1260 | {
|
---|
1261 | cl->login = time((time_t *)0);
|
---|
1262 | cl->pfd = init_oscam_ser_device(cl);
|
---|
1263 | if(cl->pfd)
|
---|
1264 | { oscam_ser_server(); }
|
---|
1265 | else
|
---|
1266 | { cs_sleepms(60000); } // retry in 1 min. (USB-Device ?)
|
---|
1267 | if(cl->pfd) { close(cl->pfd); }
|
---|
1268 | }
|
---|
1269 | NULLFREE(cl->serialdata);
|
---|
1270 | NULLFREE(cl->reader);
|
---|
1271 | return NULL;
|
---|
1272 | }
|
---|
1273 |
|
---|
1274 | void *init_oscam_ser(struct s_client *UNUSED(cl), uint8_t *UNUSED(mbuf), int32_t module_idx)
|
---|
1275 | {
|
---|
1276 | char sdevice[512];
|
---|
1277 | int32_t ret;
|
---|
1278 | struct s_thread_param param;
|
---|
1279 | oscam_init_serialdata(¶m.serialdata);
|
---|
1280 |
|
---|
1281 | if(cfg.ser_device)
|
---|
1282 | { cs_strncpy(sdevice, cfg.ser_device, sizeof(sdevice)); }
|
---|
1283 | else
|
---|
1284 | { memset(sdevice, 0, sizeof(sdevice)); }
|
---|
1285 |
|
---|
1286 | param.module_idx = module_idx;
|
---|
1287 | char *p;
|
---|
1288 | char cltype = 'c'; // now auto should work
|
---|
1289 |
|
---|
1290 | if(bcopy_end == -1) // mutex should be initialized only once
|
---|
1291 | {
|
---|
1292 | cs_pthread_cond_init(__func__, &mutex, &cond);
|
---|
1293 | bcopy_end = 0;
|
---|
1294 | }
|
---|
1295 |
|
---|
1296 | while((p = strrchr(sdevice, ';')))
|
---|
1297 | {
|
---|
1298 | *p = 0;
|
---|
1299 | if(!(p + 1) || (!(p + 1)[0])) { return NULL; }
|
---|
1300 | if(!oscam_ser_parse_url(p + 1, ¶m.serialdata, &cltype)) { return NULL; }
|
---|
1301 |
|
---|
1302 | ret = start_thread("oscam_ser_fork", oscam_ser_fork, (void *) ¶m, NULL, 1, 1);
|
---|
1303 | if(ret)
|
---|
1304 | {
|
---|
1305 | return NULL;
|
---|
1306 | }
|
---|
1307 | else
|
---|
1308 | {
|
---|
1309 | oscam_wait_ser_fork();
|
---|
1310 | }
|
---|
1311 | }
|
---|
1312 |
|
---|
1313 | if(!sdevice[0]) { return NULL; }
|
---|
1314 | if(!oscam_ser_parse_url(sdevice, ¶m.serialdata, &cltype)) { return NULL; }
|
---|
1315 |
|
---|
1316 | ret = start_thread("oscam_ser_fork", oscam_ser_fork, (void *) ¶m, NULL, 1, 1);
|
---|
1317 | if(ret)
|
---|
1318 | {
|
---|
1319 | return NULL;
|
---|
1320 | }
|
---|
1321 | else
|
---|
1322 | {
|
---|
1323 | oscam_wait_ser_fork();
|
---|
1324 | }
|
---|
1325 | return NULL;
|
---|
1326 | }
|
---|
1327 |
|
---|
1328 | /*
|
---|
1329 | * client functions
|
---|
1330 | */
|
---|
1331 |
|
---|
1332 | static int32_t oscam_ser_client_init(struct s_client *client)
|
---|
1333 | {
|
---|
1334 | if(!client->serialdata && !cs_malloc(&client->serialdata, sizeof(struct s_serial_client)))
|
---|
1335 | { return 1; }
|
---|
1336 |
|
---|
1337 | oscam_init_serialdata(client->serialdata);
|
---|
1338 |
|
---|
1339 | if((!client->reader->device[0])) { cs_disconnect_client(client); }
|
---|
1340 | if(!oscam_ser_parse_url(client->reader->device, client->serialdata, NULL)) { cs_disconnect_client(client); }
|
---|
1341 | client->pfd = init_oscam_ser_device(client);
|
---|
1342 |
|
---|
1343 | if(client->serialdata->oscam_ser_proto == P_TWIN)
|
---|
1344 | {
|
---|
1345 | if(client->pfd > 0)
|
---|
1346 | {
|
---|
1347 | client->reader->tcp_connected = 1;
|
---|
1348 | client->reader->card_status = CARD_INSERTED;
|
---|
1349 | }
|
---|
1350 | }
|
---|
1351 |
|
---|
1352 | return ((client->pfd > 0) ? 0 : 1);
|
---|
1353 | }
|
---|
1354 |
|
---|
1355 | static int32_t oscam_ser_twin_send(struct s_client *client, ECM_REQUEST *er)
|
---|
1356 | {
|
---|
1357 | struct ecmtw tw;
|
---|
1358 | tw = get_twin(er);
|
---|
1359 | cs_debug_mask(D_CLIENT, "found channel: %04X:%06X:%04X:%04X:%04X", tw.caid, tw.provid, tw.deg, tw.freq, tw.srvid);
|
---|
1360 | uint8_t wbuf[32];
|
---|
1361 | wbuf[0] = 7;
|
---|
1362 | wbuf[1] = 6;
|
---|
1363 | wbuf[2] = tw.deg >> 8;
|
---|
1364 | wbuf[3] = tw.deg & 0xff;
|
---|
1365 | wbuf[4] = tw.freq >> 8;
|
---|
1366 | wbuf[5] = tw.freq & 0xff;
|
---|
1367 | wbuf[6] = tw.srvid >> 8;
|
---|
1368 | wbuf[7] = tw.srvid & 0xff;
|
---|
1369 | wbuf[8] = wbuf[0] ^ wbuf[1] ^ wbuf[2] ^ wbuf[3] ^ wbuf[4] ^ wbuf[5] ^ wbuf[6] ^ wbuf[7];
|
---|
1370 | oscam_ser_send(client, wbuf, 9);
|
---|
1371 | return(0);
|
---|
1372 | }
|
---|
1373 |
|
---|
1374 | static int32_t oscam_ser_send_ecm(struct s_client *client, ECM_REQUEST *er)
|
---|
1375 | {
|
---|
1376 | char *tmp;
|
---|
1377 | uint8_t *buf;
|
---|
1378 | if(!cs_malloc(&buf, er->ecmlen + 12))
|
---|
1379 | {
|
---|
1380 | return(-1);
|
---|
1381 | }
|
---|
1382 |
|
---|
1383 | switch(client->serialdata->oscam_ser_proto)
|
---|
1384 | {
|
---|
1385 | case P_HSIC:
|
---|
1386 | memset(buf, 0, 12);
|
---|
1387 | buf[0] = 2;
|
---|
1388 | i2b_buf(2, er->caid, buf + 1);
|
---|
1389 | i2b_buf(3, er->prid, buf + 3);
|
---|
1390 | i2b_buf(2, er->pid, buf + 6);
|
---|
1391 | i2b_buf(2, er->srvid, buf + 10);
|
---|
1392 | memcpy(buf + 12, er->ecm, er->ecmlen);
|
---|
1393 | oscam_ser_send(client, buf, 12 + er->ecmlen);
|
---|
1394 | break;
|
---|
1395 |
|
---|
1396 | case P_BOMBA:
|
---|
1397 | oscam_ser_send(client, er->ecm, er->ecmlen);
|
---|
1398 | break;
|
---|
1399 |
|
---|
1400 | case P_DSR95:
|
---|
1401 | if(cs_malloc(&tmp, er->ecmlen * 2 + 1))
|
---|
1402 | {
|
---|
1403 | if(client->serialdata->dsr9500type == P_DSR_WITHSID)
|
---|
1404 | {
|
---|
1405 | snprintf((char *)buf, 512, "%c%08X%04X%s%04X\n\r",
|
---|
1406 | 3, er->prid, er->caid, cs_hexdump(0, er->ecm, er->ecmlen, tmp, er->ecmlen * 2 + 1), er->srvid);
|
---|
1407 | oscam_ser_send(client, buf, (er->ecmlen << 1) + 19); // 1 + 8 + 4 + l*2 + 4 + 2
|
---|
1408 | }
|
---|
1409 | else
|
---|
1410 | {
|
---|
1411 | snprintf((char *)buf, 512, "%c%08X%04X%s\n\r",
|
---|
1412 | 3, er->prid, er->caid, cs_hexdump(0, er->ecm, er->ecmlen, tmp, er->ecmlen * 2 + 1));
|
---|
1413 | oscam_ser_send(client, buf, (er->ecmlen << 1) + 15); // 1 + 8 + 4 + l*2 + 2
|
---|
1414 | }
|
---|
1415 | NULLFREE(tmp);
|
---|
1416 | }
|
---|
1417 | break;
|
---|
1418 |
|
---|
1419 | case P_ALPHA:
|
---|
1420 | buf[0] = 0x80;
|
---|
1421 | i2b_buf(2, 2 + er->ecmlen, buf + 1);
|
---|
1422 | i2b_buf(2, er->caid, buf + 3);
|
---|
1423 | memcpy(buf + 5, er->ecm, er->ecmlen);
|
---|
1424 | oscam_ser_send(client, buf, oscam_ser_alpha_convert(buf, 5 + er->ecmlen));
|
---|
1425 | break;
|
---|
1426 |
|
---|
1427 | case P_TWIN:
|
---|
1428 | oscam_ser_twin_send(client, er);
|
---|
1429 | break;
|
---|
1430 | }
|
---|
1431 | NULLFREE(buf);
|
---|
1432 | return (0);
|
---|
1433 | }
|
---|
1434 |
|
---|
1435 | static void oscam_ser_process_dcw(uint8_t *dcw, int32_t *rc, uint8_t *buf, int32_t l, struct s_client *client)
|
---|
1436 | {
|
---|
1437 | switch(client->serialdata->oscam_ser_proto)
|
---|
1438 | {
|
---|
1439 | case P_HSIC:
|
---|
1440 | if((l >= 23) && (buf[2] == 0x3A) && (buf[3] == 0x3A))
|
---|
1441 | {
|
---|
1442 | int32_t i;
|
---|
1443 | uint8_t crc;
|
---|
1444 | for(i = 4, crc = HSIC_CRC; i < 20; i++)
|
---|
1445 | { crc ^= buf[i]; }
|
---|
1446 | if(crc == buf[20])
|
---|
1447 | {
|
---|
1448 | memcpy(dcw, buf + 4, 16);
|
---|
1449 | *rc = 1;
|
---|
1450 | }
|
---|
1451 | }
|
---|
1452 | break;
|
---|
1453 |
|
---|
1454 | case P_BOMBA:
|
---|
1455 | if(l >= 16)
|
---|
1456 | {
|
---|
1457 | memcpy(dcw, buf, 16);
|
---|
1458 | *rc = 1;
|
---|
1459 | }
|
---|
1460 | break;
|
---|
1461 |
|
---|
1462 | case P_DSR95:
|
---|
1463 | if((l >= 17) && (buf[0] == 4))
|
---|
1464 | {
|
---|
1465 | memcpy(dcw, buf + 1, 16);
|
---|
1466 | *rc = 1;
|
---|
1467 | }
|
---|
1468 | break;
|
---|
1469 |
|
---|
1470 | case P_ALPHA:
|
---|
1471 | if((l >= 19) && (buf[0] == 0x88))
|
---|
1472 | {
|
---|
1473 | memcpy(dcw, buf + 3, 16);
|
---|
1474 | *rc = 1;
|
---|
1475 | }
|
---|
1476 | break;
|
---|
1477 |
|
---|
1478 | case P_TWIN:
|
---|
1479 | if ((l >= 19) && (buf[0] == 0xF7))
|
---|
1480 | {
|
---|
1481 | memcpy(dcw, buf + 3, 16);
|
---|
1482 | *rc = 1;
|
---|
1483 | }
|
---|
1484 | }
|
---|
1485 | }
|
---|
1486 |
|
---|
1487 | static int32_t oscam_ser_recv_chk(struct s_client *client, uint8_t *dcw, int32_t *rc, uint8_t *buf, int32_t n)
|
---|
1488 | {
|
---|
1489 | *rc = (-1);
|
---|
1490 |
|
---|
1491 | switch(buf[0] >> 4)
|
---|
1492 | {
|
---|
1493 | case IS_DCW:
|
---|
1494 | oscam_ser_process_dcw(dcw, rc, buf + 1, n - 1, client);
|
---|
1495 | break;
|
---|
1496 | }
|
---|
1497 | return ((*rc < 0) ? (-1) : 0); // idx not supported in serial module
|
---|
1498 | }
|
---|
1499 |
|
---|
1500 | /*
|
---|
1501 | * protocol structure
|
---|
1502 | */
|
---|
1503 |
|
---|
1504 | void module_serial(struct s_module *ph)
|
---|
1505 | {
|
---|
1506 | ph->desc = "serial";
|
---|
1507 | ph->type = MOD_CONN_SERIAL;
|
---|
1508 | ph->large_ecm_support = 1;
|
---|
1509 | ph->listenertype = LIS_SERIAL;
|
---|
1510 | ph->s_handler = init_oscam_ser;
|
---|
1511 | ph->recv = oscam_ser_recv;
|
---|
1512 | ph->send_dcw = oscam_ser_send_dcw;
|
---|
1513 | ph->c_init = oscam_ser_client_init;
|
---|
1514 | ph->c_recv_chk = oscam_ser_recv_chk;
|
---|
1515 | ph->c_send_ecm = oscam_ser_send_ecm;
|
---|
1516 | ph->num = R_SERIAL;
|
---|
1517 | serial_ph = ph;
|
---|
1518 | }
|
---|
1519 | #endif
|
---|