Browse Source

Add struct key

Georgi Chorbadzhiyski 13 years ago
parent
commit
979034cb53
4 changed files with 25 additions and 21 deletions
  1. 6
    8
      camd.c
  2. 3
    3
      data.c
  3. 8
    0
      data.h
  4. 8
    10
      tsdecrypt.c

+ 6
- 8
camd.c View File

@@ -13,13 +13,11 @@
13 13
 #include "libfuncs/libfuncs.h"
14 14
 #include "libts/tsfuncs.h"
15 15
 
16
+#include "data.h"
16 17
 #include "util.h"
17 18
 #include "camd.h"
18 19
 
19
-
20
-extern uint8_t cur_cw[16];
21
-extern int is_valid_cw;
22
-extern struct dvbcsa_key_s *csakey[2];
20
+extern struct key key;
23 21
 
24 22
 static int camd35_server_fd;
25 23
 extern struct in_addr camd35_server_addr;
@@ -128,15 +126,15 @@ NEXT:
128 126
 	uint16_t ca_id = (data[10] << 8) | data[11];
129 127
 	uint16_t idx   = (data[16] << 8) | data[17];
130 128
 	uint8_t *cw = data + 20;
131
-	memcpy(cur_cw, cw, 16);
129
+	memcpy(key.cw, cw, 16);
132 130
 
133 131
 	char cw_dump[16 * 6];
134 132
 	ts_hex_dump_buf(cw_dump, 16 * 6, cw, 16, 0);
135 133
 	ts_LOGf("CW  | CAID: 0x%04x ---------------------------------- IDX: 0x%04x Data: %s\n", ca_id, idx, cw_dump);
136 134
 
137
-	is_valid_cw = valid_cw(cur_cw);
138
-	dvbcsa_key_set(cur_cw    , csakey[0]);
139
-	dvbcsa_key_set(cur_cw + 8, csakey[1]);
135
+	key.is_valid_cw = valid_cw(key.cw);
136
+	dvbcsa_key_set(key.cw    , key.csakey[0]);
137
+	dvbcsa_key_set(key.cw + 8, key.csakey[1]);
140 138
 
141 139
 	return NULL;
142 140
 }

+ 3
- 3
data.c View File

@@ -57,7 +57,7 @@ void LOG_func(const char *msg) {
57 57
 extern int debug_level;
58 58
 extern unsigned long ts_pack;
59 59
 extern int ts_pack_shown;
60
-extern uint8_t cur_cw[16];
60
+extern struct key key;
61 61
 
62 62
 void show_ts_pack(uint16_t pid, char *wtf, char *extra, uint8_t *ts_packet) {
63 63
 	char cw1_dump[8 * 6];
@@ -66,8 +66,8 @@ void show_ts_pack(uint16_t pid, char *wtf, char *extra, uint8_t *ts_packet) {
66 66
 		if (ts_pack_shown)
67 67
 			return;
68 68
 		int stype = ts_packet_get_scrambled(ts_packet);
69
-		ts_hex_dump_buf(cw1_dump, 8 * 6, cur_cw    , 8, 0);
70
-		ts_hex_dump_buf(cw2_dump, 8 * 6, cur_cw + 8, 8, 0);
69
+		ts_hex_dump_buf(cw1_dump, 8 * 6, key.cw    , 8, 0);
70
+		ts_hex_dump_buf(cw2_dump, 8 * 6, key.cw + 8, 8, 0);
71 71
 		fprintf(stderr, "@ %s %s %03x %5ld %7ld | %s   %s | %s\n",
72 72
 			stype == 0 ? "------" :
73 73
 			stype == 2 ? "even 0" :

+ 8
- 0
data.h View File

@@ -1,6 +1,8 @@
1 1
 #ifndef DATA_H
2 2
 #define DATA_H
3 3
 
4
+#include <dvbcsa/dvbcsa.h>
5
+
4 6
 #include "libts/tsfuncs.h"
5 7
 
6 8
 struct ts {
@@ -17,6 +19,12 @@ struct ts {
17 19
 	pidmap_t			pidmap;
18 20
 };
19 21
 
22
+struct key {
23
+	uint8_t				cw[16];
24
+	int					is_valid_cw;
25
+	struct dvbcsa_key_s	*csakey[2];
26
+};
27
+
20 28
 struct ts *ts_alloc();
21 29
 void ts_free(struct ts **pts);
22 30
 

+ 8
- 10
tsdecrypt.c View File

@@ -13,9 +13,7 @@
13 13
 #include "camd.h"
14 14
 #include "tables.h"
15 15
 
16
-uint8_t cur_cw[16];
17
-int is_valid_cw = 0;
18
-struct dvbcsa_key_s *csakey[2];
16
+struct key key;
19 17
 
20 18
 int debug_level = 0;
21 19
 unsigned long ts_pack = 0;
@@ -184,11 +182,11 @@ void ts_process_packets(struct ts *ts, uint8_t *data, ssize_t data_len) {
184 182
 
185 183
 		int scramble_idx = ts_packet_get_scrambled(ts_packet);
186 184
 		if (scramble_idx > 1) {
187
-			if (is_valid_cw) {
185
+			if (key.is_valid_cw) {
188 186
 				// scramble_idx 2 == even key
189 187
 				// scramble_idx 3 == odd key
190 188
 				ts_packet_set_not_scrambled(ts_packet);
191
-				dvbcsa_decrypt(csakey[scramble_idx - 2], ts_packet + 4, 184);
189
+				dvbcsa_decrypt(key.csakey[scramble_idx - 2], ts_packet + 4, 184);
192 190
 			} else {
193 191
 				// Can't decrypt the packet just make it NULL packet
194 192
 				if (pid_filter)
@@ -220,10 +218,10 @@ int main(int argc, char **argv) {
220 218
 	ssize_t readen;
221 219
 	uint8_t ts_packet[FRAME_SIZE];
222 220
 
223
-	csakey[0] = dvbcsa_key_alloc();
224
-	csakey[1] = dvbcsa_key_alloc();
221
+	memset(&key, 0, sizeof(key));
222
+	key.csakey[0] = dvbcsa_key_alloc();
223
+	key.csakey[1] = dvbcsa_key_alloc();
225 224
 
226
-	memset(cur_cw, 0, sizeof(cur_cw));
227 225
 	ts_set_log_func(LOG_func);
228 226
 
229 227
 	parse_options(argc, argv);
@@ -240,8 +238,8 @@ int main(int argc, char **argv) {
240 238
 	} while (readen > 0);
241 239
 	ts_free(&ts);
242 240
 
243
-	dvbcsa_key_free(csakey[0]);
244
-	dvbcsa_key_free(csakey[1]);
241
+	dvbcsa_key_free(key.csakey[0]);
242
+	dvbcsa_key_free(key.csakey[1]);
245 243
 
246 244
 	camd35_disconnect();
247 245
 	exit(0);

Loading…
Cancel
Save