Browse Source

Increase code word error notification time.

Georgi Chorbadzhiyski 12 years ago
parent
commit
affd0d8dab
6 changed files with 27 additions and 11 deletions
  1. 1
    1
      README
  2. 12
    3
      camd.c
  3. 3
    1
      data.c
  4. 1
    0
      data.h
  5. 1
    1
      tsdecrypt.1
  6. 9
    5
      tsdecrypt.c

+ 1
- 1
README View File

@@ -87,7 +87,7 @@ ECM options:
87 87
  -G --ecm-irdeto-type <int> | Process IRDETO ECMs with type X /0-3/. Default: 0
88 88
  -K --ecm-no-log            | Disable ECM and code words logging.
89 89
  -J --cw-warn-time <sec>    | Warn if no valid code word has been received.
90
-                            .   Set <sec> to 0 to disable. Default: 20 sec
90
+                            .   Set <sec> to 0 to disable. Default: 60 sec
91 91
 
92 92
 Misc options:
93 93
  -D --debug <level>         | Message debug level.

+ 12
- 3
camd.c View File

@@ -139,11 +139,20 @@ static int camd_send_ecm(struct ts *ts, struct camd_msg *msg) {
139 139
 
140 140
 	ret = camd_recv_cw(ts);
141 141
 	if (ret < 1) {
142
+		time_t now = time(NULL);
142 143
 		ts->is_cw_error = 1;
143
-		if (ts->key.ts && time(NULL) - ts->key.ts > KEY_VALID_TIME) {
144
-			if (c->key->is_valid_cw)
144
+		if (ts->key.ts && now - ts->key.ts > KEY_VALID_TIME) {
145
+			if (c->key->is_valid_cw) {
145 146
 				notify(ts, "NO_CODE_WORD", "No code word was set in %ld sec. Decryption is disabled.",
146
-					time(NULL) - ts->key.ts);
147
+					now - ts->key.ts);
148
+				ts_LOGf("CW  | *ERR* No valid code word was received in %ld seconds. Decryption is disabled.\n",
149
+					now - ts->key.ts);
150
+				ts->cw_last_warn = time(NULL);
151
+				ts->cw_next_warn = ts->cw_last_warn + ts->cw_warn_sec;
152
+				ts->cw_next_warn -= now - ts->key.ts;
153
+				if (ts->cw_next_warn <= ts->cw_last_warn)
154
+					ts->cw_next_warn = ts->cw_last_warn + ts->cw_warn_sec;
155
+			}
147 156
 			c->key->is_valid_cw = 0;
148 157
 		}
149 158
 		return 0;

+ 3
- 1
data.c View File

@@ -88,8 +88,10 @@ void data_init(struct ts *ts) {
88 88
 	ts->ecm_report_interval = 60;
89 89
 	ts->ecm_last_report     = time(NULL);
90 90
 
91
-	ts->cw_warn_sec = 20;
91
+	ts->cw_warn_sec = 60;
92 92
 	ts->cw_last_warn= time(NULL);
93
+	ts->cw_last_warn= ts->cw_last_warn + ts->cw_warn_sec;
94
+	ts->key.ts      = time(NULL);
93 95
 
94 96
 	ts->input.fd    = 0; // STDIN
95 97
 	ts->input.type  = FILE_IO;

+ 1
- 0
data.h View File

@@ -213,6 +213,7 @@ struct ts {
213 213
 
214 214
 	unsigned int		cw_warn_sec;
215 215
 	time_t				cw_last_warn;
216
+	time_t				cw_next_warn;
216 217
 
217 218
 	unsigned int		pid_report;
218 219
 	unsigned int		pid_stats[MAX_PIDS];

+ 1
- 1
tsdecrypt.1 View File

@@ -211,7 +211,7 @@ reports are not affected by this option.
211 211
 .TP
212 212
 \fB\-J\fR, \fB\-\-cw\-warn\-time\fR <seconds>
213 213
 After how much seconds to warn if valid code word was not received.
214
-The default is \fB20\fR seconds. Set to \fB0\fR to disable the warning.
214
+The default is \fB60\fR seconds. Set to \fB0\fR to disable the warning.
215 215
 .SH EVENTS
216 216
 Notification events are sent when \fB\-\-notify\-program\fR and \fB\-\-ident\fR
217 217
 options are used. The event parameters are set as environmental variables

+ 9
- 5
tsdecrypt.c View File

@@ -454,6 +454,7 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
454 454
 				ts->cw_warn_sec = strtoul(optarg, NULL, 10);
455 455
 				if (ts->cw_warn_sec > 86400)
456 456
 					ts->cw_warn_sec = 86400;
457
+				ts->cw_last_warn= ts->cw_last_warn + ts->cw_warn_sec;
457 458
 				break;
458 459
 
459 460
 			case 'D':
@@ -647,11 +648,14 @@ static void report_ecms(struct ts *ts, time_t now) {
647 648
 }
648 649
 
649 650
 static void report_cw_warn(struct ts *ts, time_t now) {
650
-	notify(ts, "NO_CODE_WORD", "No valid code word was received for %ld sec.",
651
-		now - ts->cw_last_warn);
652
-	ts_LOGf("CW  | *ERR* No valid code word was received for %ld seconds!\n",
653
-		now - ts->cw_last_warn);
651
+	if (now - ts->key.ts > 1) {
652
+		notify(ts, "NO_CODE_WORD", "No valid code word was received in %ld sec.",
653
+			now - ts->key.ts);
654
+		ts_LOGf("CW  | *ERR* No valid code word was received for %ld seconds!\n",
655
+			now - ts->key.ts);
656
+	}
654 657
 	ts->cw_last_warn = now;
658
+	ts->cw_next_warn = now + ts->cw_warn_sec;
655 659
 }
656 660
 
657 661
 static void do_reports(struct ts *ts) {
@@ -678,7 +682,7 @@ static void do_reports(struct ts *ts) {
678 682
 	}
679 683
 
680 684
 	if (!ts->emm_only && !ts->key.is_valid_cw) {
681
-		if ((time_t)(ts->cw_last_warn + ts->cw_warn_sec) <= now) {
685
+		if (ts->cw_warn_sec && now >= ts->cw_next_warn) {
682 686
 			report_cw_warn(ts, now);
683 687
 		}
684 688
 	}

Loading…
Cancel
Save