Browse Source

Add debug printing of all packets

Georgi Chorbadzhiyski 13 years ago
parent
commit
45beb933d8
1 changed files with 45 additions and 0 deletions
  1. 45
    0
      tsdecrypt.c

+ 45
- 0
tsdecrypt.c View File

@@ -76,6 +76,41 @@ void LOG_func(const char *msg) {
76 76
 	fprintf(stderr, "%s | %s", date, msg);
77 77
 }
78 78
 
79
+unsigned long ts_pack = 0;
80
+int ts_pack_shown = 0;
81
+
82
+static void show_ts_pack(uint16_t pid, char *wtf, char *extra, uint8_t *ts_packet) {
83
+	char cw1_dump[8 * 6];
84
+	char cw2_dump[8 * 6];
85
+	if (ts_pack_shown)
86
+		return;
87
+	int stype = ts_packet_get_scrambled(ts_packet);
88
+	ts_hex_dump_buf(cw1_dump, 8 * 6, cur_cw    , 8, 0);
89
+	ts_hex_dump_buf(cw2_dump, 8 * 6, cur_cw + 8, 8, 0);
90
+	fprintf(stdout, "%s %s %03x %5ld %7ld | %s   %s | %s\n",
91
+		stype == 0 ? "------" :
92
+		stype == 2 ? "even 0" :
93
+		stype == 3 ? "odd  1" : "??????",
94
+		wtf,
95
+		pid,
96
+		ts_pack, ts_pack * 188,
97
+		cw1_dump, cw2_dump, extra ? extra : wtf);
98
+}
99
+
100
+static void dump_ts_pack(uint16_t pid, uint8_t *ts_packet) {
101
+	if (pid == 0x012)		show_ts_pack(pid, "epg", NULL, ts_packet);
102
+	else if (pid == 0x10)	show_ts_pack(pid, "nit", NULL, ts_packet);
103
+	else if (pid == 0x11)	show_ts_pack(pid, "sdt", NULL, ts_packet);
104
+	else if (pid == 0x64)	show_ts_pack(pid, "PCR",  NULL, ts_packet);
105
+	else if (pid == 0x26)	show_ts_pack(pid, "EMM", "Cryptoworks", ts_packet);
106
+	else if (pid == 0x28)	show_ts_pack(pid, "emm", "No PAT/CAT/PMT yet.", ts_packet);
107
+	else if (pid == 0xd0)	show_ts_pack(pid, "  v", "Video", ts_packet);
108
+	else if (pid == 0x134)	show_ts_pack(pid, "  a", "Audio", ts_packet);
109
+	else if (pid == 0x513)	show_ts_pack(pid, "ECM", "Cryptoworks", ts_packet);
110
+	else if (pid == 0x522)	show_ts_pack(pid, "ecm", "No PAT/CAT/PMT yet.", ts_packet);
111
+	else					show_ts_pack(pid, "---", NULL, ts_packet);
112
+}
113
+
79 114
 enum CA_system req_CA_sys = CA_CONNAX;
80 115
 int server_fd = -1;
81 116
 char *camd35_server = "10.0.1.78";
@@ -248,6 +283,7 @@ static int camd35_send_emm(uint16_t ca_id, uint8_t *data, uint8_t data_len) {
248 283
 
249 284
 #define handle_table_changes(TABLE) \
250 285
 	do { \
286
+		show_ts_pack(pid, #TABLE, NULL, ts_packet); \
251 287
 		if (!ts->cur##TABLE) \
252 288
 			ts->cur##TABLE = ts_##TABLE##_alloc(); \
253 289
 		ts->cur##TABLE = ts_##TABLE##_push_packet(ts->cur##TABLE, ts_packet); \
@@ -314,6 +350,7 @@ void process_emm(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
314 350
 	if (!ts->emm_pid || ts->emm_pid != pid)
315 351
 		return;
316 352
 
353
+	show_ts_pack(pid, "emm", NULL, ts_packet);
317 354
 	if (!ts->emm)
318 355
 		ts->emm = ts_privsec_alloc();
319 356
 
@@ -372,6 +409,8 @@ void process_ecm(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
372 409
 	ts_privsec_free(&ts->last_ecm);
373 410
 	ts->last_ecm = ts->ecm;
374 411
 	ts->ecm = ts_privsec_alloc();
412
+
413
+	show_ts_pack(pid, !duplicate ? "ecm" : "ec+", NULL, ts_packet);
375 414
 }
376 415
 
377 416
 void ts_process_packets(struct ts *ts, uint8_t *data, uint8_t data_len) {
@@ -380,11 +419,17 @@ void ts_process_packets(struct ts *ts, uint8_t *data, uint8_t data_len) {
380 419
 		uint8_t *ts_packet = data + i;
381 420
 		uint16_t pid = ts_packet_get_pid(ts_packet);
382 421
 
422
+		ts_pack_shown = 0;
423
+
383 424
 		process_pat(ts, pid, ts_packet);
384 425
 		process_cat(ts, pid, ts_packet);
385 426
 		process_pmt(ts, pid, ts_packet);
386 427
 		process_emm(ts, pid, ts_packet);
387 428
 		process_ecm(ts, pid, ts_packet);
429
+
430
+		if (!ts_pack_shown)
431
+			dump_ts_pack(pid, ts_packet);
432
+		ts_pack++;
388 433
 	}
389 434
 }
390 435
 

Loading…
Cancel
Save