|
@@ -139,7 +139,7 @@ static uint8_t newcamd_send_msg(struct camd *c, const uint8_t *data, int data_le
|
139
|
139
|
uint8_t netbuf[NEWCAMD_MSG_SIZE];
|
140
|
140
|
|
141
|
141
|
if (newcamd_connect(c) < 0)
|
142
|
|
- return 0;
|
|
142
|
+ return -1;
|
143
|
143
|
|
144
|
144
|
if (data_len < 3 || (data_len + NEWCAMD_HDR_LEN + 4) > NEWCAMD_MSG_SIZE) {
|
145
|
145
|
ts_LOGf("ERR | [%s] Bad message size.\n", c->ops.ident);
|
|
@@ -349,8 +349,10 @@ static int newcamd_login(struct camd *c) {
|
349
|
349
|
static int newcamd_connect(struct camd *c) {
|
350
|
350
|
if (c->server_fd < 0) {
|
351
|
351
|
c->server_fd = camd_tcp_connect(c->server_addr, c->server_port);
|
352
|
|
- if (!newcamd_login(c))
|
|
352
|
+ if (!newcamd_login(c)) {
|
353
|
353
|
shutdown_fd(&c->server_fd);
|
|
354
|
+ return -1;
|
|
355
|
+ }
|
354
|
356
|
}
|
355
|
357
|
return c->server_fd;
|
356
|
358
|
}
|
|
@@ -365,7 +367,8 @@ static int newcamd_reconnect(struct camd *c) {
|
365
|
367
|
}
|
366
|
368
|
|
367
|
369
|
static int newcamd_do_ecm(struct camd *c, struct camd_msg *msg) {
|
368
|
|
- return newcamd_send_msg(c, msg->data, msg->data_len, msg->service_id, 1);
|
|
370
|
+ int ret = newcamd_send_msg(c, msg->data, msg->data_len, msg->service_id, 1);
|
|
371
|
+ return ret <= 0 ? -1 : ret;
|
369
|
372
|
}
|
370
|
373
|
|
371
|
374
|
static int newcamd_do_emm(struct camd *c, struct camd_msg *msg) {
|
|
@@ -373,8 +376,8 @@ static int newcamd_do_emm(struct camd *c, struct camd_msg *msg) {
|
373
|
376
|
int ret;
|
374
|
377
|
|
375
|
378
|
ret = newcamd_send_msg(c, msg->data, msg->data_len, msg->service_id, 1);
|
376
|
|
- if (!ret)
|
377
|
|
- return ret;
|
|
379
|
+ if (ret <= 0)
|
|
380
|
+ return -1;
|
378
|
381
|
|
379
|
382
|
int data_len = newcamd_recv_msg(c, buf, 1);
|
380
|
383
|
if (data_len >= 3) {
|
|
@@ -391,17 +394,25 @@ static int newcamd_do_emm(struct camd *c, struct camd_msg *msg) {
|
391
|
394
|
|
392
|
395
|
static int newcamd_get_cw(struct camd *c, uint16_t *ca_id, uint16_t *idx, uint8_t *cw) {
|
393
|
396
|
int ret;
|
|
397
|
+ int sync_try = 0;
|
394
|
398
|
uint8_t *buf = c->newcamd.buf;
|
395
|
399
|
|
396
|
|
- while((ret = newcamd_recv_msg(c, buf, 1)) == -2)
|
|
400
|
+ while((ret = newcamd_recv_msg(c, buf, 1)) == -2) {
|
397
|
401
|
ts_LOGf("ERR | [%s] msg_id sync error. retrying...\n", c->ops.ident);
|
|
402
|
+ if (++sync_try > ECM_QUEUE_HARD_LIMIT) {
|
|
403
|
+ ts_LOGf("ERR | [%s] Can't sync msg_id after %d tries.\n", c->ops.ident, sync_try);
|
|
404
|
+ return -1;
|
|
405
|
+ }
|
|
406
|
+ }
|
398
|
407
|
|
399
|
408
|
if (ret != 19) {
|
400
|
|
- if (ret == 3)
|
|
409
|
+ if (ret == 3) {
|
401
|
410
|
ts_LOGf("ERR | [%s] Card was not able to decode the channel.\n", c->ops.ident);
|
402
|
|
- else
|
|
411
|
+ return 0;
|
|
412
|
+ } else {
|
403
|
413
|
ts_LOGf("ERR | [%s] Unexpected CAMD server response (code %d).\n", c->ops.ident, ret);
|
404
|
|
- return 0;
|
|
414
|
+ return -1;
|
|
415
|
+ }
|
405
|
416
|
}
|
406
|
417
|
|
407
|
418
|
*ca_id = c->newcamd.caid;
|