Browse Source

camd: Add camd_set_cw() function.

Georgi Chorbadzhiyski 12 years ago
parent
commit
6d2556067e
2 changed files with 26 additions and 17 deletions
  1. 24
    17
      camd.c
  2. 2
    0
      camd.h

+ 24
- 17
camd.c View File

@@ -33,6 +33,8 @@
33 33
 #include "camd.h"
34 34
 #include "notify.h"
35 35
 
36
+static uint8_t invalid_cw[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
37
+
36 38
 int camd_tcp_connect(struct in_addr ip, int port) {
37 39
 	ts_LOGf("CAM | Connecting to server %s:%d\n", inet_ntoa(ip), port);
38 40
 
@@ -60,10 +62,29 @@ int camd_tcp_connect(struct in_addr ip, int port) {
60 62
 	return fd;
61 63
 }
62 64
 
65
+void camd_set_cw(struct ts *ts, unsigned char *new_cw) {
66
+	struct camd *c = &ts->camd;
67
+
68
+	c->ecm_recv_errors = 0;
69
+
70
+	gettimeofday(&c->key->ts_keyset, NULL);
71
+	c->key->ts = c->key->ts_keyset.tv_sec;
72
+	ts->cw_last_warn = c->key->ts;
73
+
74
+	if (memcmp(c->key->cw, invalid_cw, 8) != 0) {
75
+		dvbcsa_key_set   (new_cw, c->key->csakey[0]);
76
+		dvbcsa_bs_key_set(new_cw, c->key->bs_csakey[0]);
77
+	}
78
+
79
+	if (memcmp(c->key->cw + 8, invalid_cw, 8) != 0) {
80
+		dvbcsa_key_set(new_cw + 8, c->key->csakey[1]);
81
+		dvbcsa_bs_key_set(new_cw + 8, c->key->bs_csakey[1]);
82
+	}
83
+}
84
+
63 85
 static int camd_recv_cw(struct ts *ts) {
64 86
 	struct camd *c = &ts->camd;
65 87
 	struct timeval tv1, tv2, last_ts_keyset;
66
-	static uint8_t invalid_cw[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
67 88
 	uint16_t ca_id = 0;
68 89
 	uint16_t idx = 0;
69 90
 	int ret;
@@ -98,22 +119,8 @@ static int camd_recv_cw(struct ts *ts) {
98 119
 
99 120
 	// At first ts_keyset is not initialized
100 121
 	last_ts_keyset = c->key->ts_keyset;
101
-	if (c->key->is_valid_cw) {
102
-		c->ecm_recv_errors = 0;
103
-
104
-		gettimeofday(&c->key->ts_keyset, NULL);
105
-		c->key->ts = c->key->ts_keyset.tv_sec;
106
-		ts->cw_last_warn = c->key->ts;
107
-
108
-		if (memcmp(c->key->cw, invalid_cw, 8) != 0) {
109
-			dvbcsa_key_set   (c->key->cw, c->key->csakey[0]);
110
-			dvbcsa_bs_key_set(c->key->cw, c->key->bs_csakey[0]);
111
-		}
112
-		if (memcmp(c->key->cw + 8, invalid_cw, 8) != 0) {
113
-			dvbcsa_key_set(c->key->cw + 8, c->key->csakey[1]);
114
-			dvbcsa_bs_key_set(c->key->cw + 8, c->key->bs_csakey[1]);
115
-		}
116
-	}
122
+	if (c->key->is_valid_cw)
123
+		camd_set_cw(ts, c->key->cw);
117 124
 
118 125
 	if (ts->ecm_cw_log) {
119 126
 		ts_LOGf("CW  | SID 0x%04x CAID: 0x%04x CW_recv: %5llu ms LastKey: %5llu ms Data: %s\n",

+ 2
- 0
camd.h View File

@@ -25,6 +25,8 @@ int						camd_tcp_connect	(struct in_addr ip, int port);
25 25
 struct camd_msg *		camd_msg_alloc		(enum msg_type msg_type, uint16_t ca_id, uint16_t service_id, uint8_t *data, uint8_t data_len);
26 26
 void					camd_msg_free   	(struct camd_msg **pmsg);
27 27
 
28
+void					camd_set_cw			(struct ts *ts, unsigned char *new_cw);
29
+
28 30
 void					camd_start			(struct ts *ts);
29 31
 void					camd_stop			(struct ts *ts);
30 32
 

Loading…
Cancel
Save