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,3 +1,7 @@
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 5
 2013-09-12 : Version 10.0
2 6
  * Add --ecm-only (-v) option. This allows processing of ECMs but without
3 7
    decoding the input stream.

+ 4
- 0
camd.c View File

@@ -170,6 +170,10 @@ static int camd_recv_cw(struct ts *ts) {
170 170
 #undef ERR
171 171
 
172 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 177
 	struct camd *c = &ts->camd;
174 178
 	int ret = c->ops.do_ecm(c, msg);
175 179
 	if (ret <= 0) {

+ 3
- 0
data.h View File

@@ -276,6 +276,9 @@ struct ts {
276 276
 	time_t				cw_next_warn;
277 277
 	struct timeval		ecm_change_time;
278 278
 
279
+	unsigned int		stream_is_encrypted;
280
+	time_t				last_scrambled_packet_ts;
281
+
279 282
 	unsigned int		pid_report;
280 283
 	unsigned int		pid_stats[MAX_PIDS];
281 284
 

+ 14
- 0
process.c View File

@@ -20,6 +20,7 @@
20 20
 #include "csa.h"
21 21
 #include "tables.h"
22 22
 #include "util.h"
23
+#include "notify.h"
23 24
 
24 25
 static unsigned long ts_pack;
25 26
 static int ts_pack_shown;
@@ -122,12 +123,18 @@ static void decode_buffer(struct ts *ts, uint8_t *data, int data_len) {
122 123
 
123 124
 	int scramble_idx_old = 0;
124 125
 
126
+	time_t now = time(NULL);
127
+
125 128
 	// Prepare batch structure
126 129
 	for (i = 0; i < batch_sz; i++) {
127 130
 		uint8_t *ts_packet = data + (i * 188);
128 131
 
129 132
 		uint16_t pid = ts_packet_get_pid(ts_packet);
130 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 138
 			if (ts->key.is_valid_cw) {
132 139
 				int scramble_idx = ts_packet_get_scrambled(ts_packet);
133 140
 				if (!scramble_idx_old)
@@ -174,6 +181,13 @@ static void decode_buffer(struct ts *ts, uint8_t *data, int data_len) {
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 191
 	// Decode packets
178 192
 	if (even_packets) {
179 193
 		if (use_dvbcsa) {

+ 6
- 1
tsdecrypt.1 View File

@@ -340,7 +340,12 @@ currently defined events are:
340 340
 
341 341
   \fBNO_CODE_WORD\fR    No valid code word was received for X seconds. The
342 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 350
   \fBNO_EMM_RECEIVED\fR    No EMM packet have been received for X seconds.
346 351
 

Loading…
Cancel
Save