Browse Source

Track if stream is encrypted or not

Georgi Chorbadzhiyski 7 years ago
parent
commit
0652f234f5
5 changed files with 31 additions and 1 deletions
  1. 4
    0
      ChangeLog
  2. 4
    0
      camd.c
  3. 3
    0
      data.h
  4. 14
    0
      process.c
  5. 6
    1
      tsdecrypt.1

+ 4
- 0
ChangeLog View File

1
+xxxx-xx-xx : Version -next
2
+ * Add new notification message STREAM_NOT_ENCRYPTED. When stream is not
3
+   encrypted no NO_CODE_WORD notifications are sent.
4
+
1
 2013-09-12 : Version 10.0
5
 2013-09-12 : Version 10.0
2
  * Add --ecm-only (-v) option. This allows processing of ECMs but without
6
  * Add --ecm-only (-v) option. This allows processing of ECMs but without
3
    decoding the input stream.
7
    decoding the input stream.

+ 4
- 0
camd.c View File

170
 #undef ERR
170
 #undef ERR
171
 
171
 
172
 static int camd_send_ecm(struct ts *ts, struct camd_msg *msg) {
172
 static int camd_send_ecm(struct ts *ts, struct camd_msg *msg) {
173
+	if (!ts->stream_is_encrypted) {
174
+		return 0;
175
+	}
176
+
173
 	struct camd *c = &ts->camd;
177
 	struct camd *c = &ts->camd;
174
 	int ret = c->ops.do_ecm(c, msg);
178
 	int ret = c->ops.do_ecm(c, msg);
175
 	if (ret <= 0) {
179
 	if (ret <= 0) {

+ 3
- 0
data.h View File

276
 	time_t				cw_next_warn;
276
 	time_t				cw_next_warn;
277
 	struct timeval		ecm_change_time;
277
 	struct timeval		ecm_change_time;
278
 
278
 
279
+	unsigned int		stream_is_encrypted;
280
+	time_t				last_scrambled_packet_ts;
281
+
279
 	unsigned int		pid_report;
282
 	unsigned int		pid_report;
280
 	unsigned int		pid_stats[MAX_PIDS];
283
 	unsigned int		pid_stats[MAX_PIDS];
281
 
284
 

+ 14
- 0
process.c View File

20
 #include "csa.h"
20
 #include "csa.h"
21
 #include "tables.h"
21
 #include "tables.h"
22
 #include "util.h"
22
 #include "util.h"
23
+#include "notify.h"
23
 
24
 
24
 static unsigned long ts_pack;
25
 static unsigned long ts_pack;
25
 static int ts_pack_shown;
26
 static int ts_pack_shown;
122
 
123
 
123
 	int scramble_idx_old = 0;
124
 	int scramble_idx_old = 0;
124
 
125
 
126
+	time_t now = time(NULL);
127
+
125
 	// Prepare batch structure
128
 	// Prepare batch structure
126
 	for (i = 0; i < batch_sz; i++) {
129
 	for (i = 0; i < batch_sz; i++) {
127
 		uint8_t *ts_packet = data + (i * 188);
130
 		uint8_t *ts_packet = data + (i * 188);
128
 
131
 
129
 		uint16_t pid = ts_packet_get_pid(ts_packet);
132
 		uint16_t pid = ts_packet_get_pid(ts_packet);
130
 		if (pidmap_get(&ts->pidmap, pid) && ts_packet_is_scrambled(ts_packet)) {
133
 		if (pidmap_get(&ts->pidmap, pid) && ts_packet_is_scrambled(ts_packet)) {
134
+			if (ts_packet_is_scrambled(ts_packet) && ts->last_scrambled_packet_ts != now) {
135
+				ts->stream_is_encrypted = 1;
136
+				ts->last_scrambled_packet_ts = now;
137
+			}
131
 			if (ts->key.is_valid_cw) {
138
 			if (ts->key.is_valid_cw) {
132
 				int scramble_idx = ts_packet_get_scrambled(ts_packet);
139
 				int scramble_idx = ts_packet_get_scrambled(ts_packet);
133
 				if (!scramble_idx_old)
140
 				if (!scramble_idx_old)
174
 		}
181
 		}
175
 	}
182
 	}
176
 
183
 
184
+	if (ts->last_scrambled_packet_ts && ts->last_scrambled_packet_ts < now - 5) {
185
+		ts_LOGf("N/E | No encrypted packet came during the last 5 seconds, disabling NO_CODE_WORD notifcation\n");
186
+		notify(ts, "STREAM_NOT_ENCRYPTED", "No encrypted packets were seen in the last 5 seconds.");
187
+		ts->stream_is_encrypted = 0;
188
+		ts->last_scrambled_packet_ts = 0;
189
+	}
190
+
177
 	// Decode packets
191
 	// Decode packets
178
 	if (even_packets) {
192
 	if (even_packets) {
179
 		if (use_dvbcsa) {
193
 		if (use_dvbcsa) {

+ 6
- 1
tsdecrypt.1 View File

340
 
340
 
341
   \fBNO_CODE_WORD\fR    No valid code word was received for X seconds. The
341
   \fBNO_CODE_WORD\fR    No valid code word was received for X seconds. The
342
                   decryption process have been suspended until valid
342
                   decryption process have been suspended until valid
343
-                  code word is received.
343
+                  code word is received. This event is sent only if
344
+                  the stream is encrypted and there are no new code words
345
+                  from the CAMD server.
346
+
347
+  \fBSTREAM_NOT_ENCRYPTED\fR    No encrypted packets arrived in the input stream
348
+                  for the last 5 seconds. The stream is probably not encrypted.
344
 
349
 
345
   \fBNO_EMM_RECEIVED\fR    No EMM packet have been received for X seconds.
350
   \fBNO_EMM_RECEIVED\fR    No EMM packet have been received for X seconds.
346
 
351
 

Loading…
Cancel
Save