Browse Source

newcamd: Return correct error codes so the reconnects work.

Georgi Chorbadzhiyski 12 years ago
parent
commit
7717b692c2
1 changed files with 20 additions and 9 deletions
  1. 20
    9
      camd-newcamd.c

+ 20
- 9
camd-newcamd.c View File

139
 	uint8_t netbuf[NEWCAMD_MSG_SIZE];
139
 	uint8_t netbuf[NEWCAMD_MSG_SIZE];
140
 
140
 
141
 	if (newcamd_connect(c) < 0)
141
 	if (newcamd_connect(c) < 0)
142
-		return 0;
142
+		return -1;
143
 
143
 
144
 	if (data_len < 3 || (data_len + NEWCAMD_HDR_LEN + 4) > NEWCAMD_MSG_SIZE) {
144
 	if (data_len < 3 || (data_len + NEWCAMD_HDR_LEN + 4) > NEWCAMD_MSG_SIZE) {
145
 		ts_LOGf("ERR | [%s] Bad message size.\n", c->ops.ident);
145
 		ts_LOGf("ERR | [%s] Bad message size.\n", c->ops.ident);
349
 static int newcamd_connect(struct camd *c) {
349
 static int newcamd_connect(struct camd *c) {
350
 	if (c->server_fd < 0) {
350
 	if (c->server_fd < 0) {
351
 		c->server_fd = camd_tcp_connect(c->server_addr, c->server_port);
351
 		c->server_fd = camd_tcp_connect(c->server_addr, c->server_port);
352
-		if (!newcamd_login(c))
352
+		if (!newcamd_login(c)) {
353
 			shutdown_fd(&c->server_fd);
353
 			shutdown_fd(&c->server_fd);
354
+			return -1;
355
+		}
354
 	}
356
 	}
355
 	return c->server_fd;
357
 	return c->server_fd;
356
 }
358
 }
365
 }
367
 }
366
 
368
 
367
 static int newcamd_do_ecm(struct camd *c, struct camd_msg *msg) {
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
 static int newcamd_do_emm(struct camd *c, struct camd_msg *msg) {
374
 static int newcamd_do_emm(struct camd *c, struct camd_msg *msg) {
373
 	int ret;
376
 	int ret;
374
 
377
 
375
 	ret = newcamd_send_msg(c, msg->data, msg->data_len, msg->service_id, 1);
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
 	int data_len = newcamd_recv_msg(c, buf, 1);
382
 	int data_len = newcamd_recv_msg(c, buf, 1);
380
 	if (data_len >= 3) {
383
 	if (data_len >= 3) {
391
 
394
 
392
 static int newcamd_get_cw(struct camd *c, uint16_t *ca_id, uint16_t *idx, uint8_t *cw) {
395
 static int newcamd_get_cw(struct camd *c, uint16_t *ca_id, uint16_t *idx, uint8_t *cw) {
393
 	int ret;
396
 	int ret;
397
+	int sync_try = 0;
394
 	uint8_t *buf = c->newcamd.buf;
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
 		ts_LOGf("ERR | [%s] msg_id sync error. retrying...\n", c->ops.ident);
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
 	if (ret != 19) {
408
 	if (ret != 19) {
400
-		if (ret == 3)
409
+		if (ret == 3) {
401
 			ts_LOGf("ERR | [%s] Card was not able to decode the channel.\n", c->ops.ident);
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
 			ts_LOGf("ERR | [%s] Unexpected CAMD server response (code %d).\n", c->ops.ident, ret);
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
 	*ca_id = c->newcamd.caid;
418
 	*ca_id = c->newcamd.caid;

Loading…
Cancel
Save