Browse Source

Make camd->do_ecm() and camd->do_emm() ops to take struct camd_msg.

Georgi Chorbadzhiyski 12 years ago
parent
commit
111846981a
5 changed files with 30 additions and 41 deletions
  1. 14
    16
      camd-cs378x.c
  2. 9
    18
      camd.c
  3. 3
    3
      camd.h
  4. 2
    2
      data.h
  5. 2
    2
      tables.c

+ 14
- 16
camd-cs378x.c View File

@@ -98,34 +98,32 @@ static void cs378x_buf_init(struct camd *c, uint8_t *data, int data_len) {
98 98
 	memcpy(c->cs378x.buf + CAMD35_HDR_LEN, data, data_len); // Copy data to buf
99 99
 }
100 100
 
101
-static int cs378x_do_ecm(struct camd *c, uint16_t ca_id, uint16_t service_id, uint8_t *data, uint8_t data_len) {
102
-	uint32_t provider_id = 0;
103
-	uint16_t idx = c->cs378x.msg_id++;
104
-	int to_send = boundary(4, CAMD35_HDR_LEN + data_len);
101
+static int cs378x_do_ecm(struct camd *c, struct camd_msg *msg) {
102
+	int to_send = boundary(4, CAMD35_HDR_LEN + msg->data_len);
105 103
 
106
-	cs378x_buf_init(c, data, (int)data_len);
104
+	cs378x_buf_init(c, msg->data, (int)msg->data_len);
105
+
106
+	c->cs378x.msg_id++;
107 107
 
108 108
 	c->cs378x.buf[0] = 0x00; // CMD ECM request
109
-	init_2b(service_id , c->cs378x.buf + 8);
110
-	init_2b(ca_id      , c->cs378x.buf + 10);
111
-	init_4b(provider_id, c->cs378x.buf + 12);
112
-	init_2b(idx        , c->cs378x.buf + 16);
109
+	init_2b(msg->service_id , c->cs378x.buf + 8);
110
+	init_2b(msg->ca_id      , c->cs378x.buf + 10);
111
+	init_4b(0               , c->cs378x.buf + 12); // Provider ID
112
+	init_2b(c->cs378x.msg_id, c->cs378x.buf + 16);
113 113
 	c->cs378x.buf[18] = 0xff;
114 114
 	c->cs378x.buf[19] = 0xff;
115 115
 
116 116
 	return cs378x_send_buf(c, to_send);
117 117
 }
118 118
 
119
-static int cs378x_do_emm(struct camd *c, uint16_t ca_id, uint16_t service_id, uint8_t *data, uint8_t data_len) {
120
-	(void)service_id;
121
-	uint32_t prov_id = 0;
122
-	int to_send = boundary(4, CAMD35_HDR_LEN + data_len);
119
+static int cs378x_do_emm(struct camd *c, struct camd_msg *msg) {
120
+	int to_send = boundary(4, CAMD35_HDR_LEN + msg->data_len);
123 121
 
124
-	cs378x_buf_init(c, data, (int)data_len);
122
+	cs378x_buf_init(c, msg->data, (int)msg->data_len);
125 123
 
126 124
 	c->cs378x.buf[0] = 0x06; // CMD incomming EMM
127
-	init_2b(ca_id  , c->cs378x.buf + 10);
128
-	init_4b(prov_id, c->cs378x.buf + 12);
125
+	init_2b(msg->ca_id  , c->cs378x.buf + 10);
126
+	init_4b(0           , c->cs378x.buf + 12); // Provider ID
129 127
 
130 128
 	return cs378x_send_buf(c, to_send);
131 129
 }

+ 9
- 18
camd.c View File

@@ -115,9 +115,9 @@ static int camd_recv_cw(struct ts *ts) {
115 115
 
116 116
 #undef ERR
117 117
 
118
-static int camd_send_ecm(struct ts *ts, uint16_t ca_id, uint16_t service_id, uint8_t *data, uint8_t data_len) {
118
+static int camd_send_ecm(struct ts *ts, struct camd_msg *msg) {
119 119
 	struct camd *c = &ts->camd;
120
-	int ret = c->ops.do_ecm(c, ca_id, service_id, data, data_len);
120
+	int ret = c->ops.do_ecm(c, msg);
121 121
 	if (ret <= 0) {
122 122
 		ts_LOGf("ERR | Error sending ecm packet, reconnecting to camd.\n");
123 123
 		ts->is_cw_error = 1;
@@ -140,9 +140,9 @@ static int camd_send_ecm(struct ts *ts, uint16_t ca_id, uint16_t service_id, uin
140 140
 	return ret;
141 141
 }
142 142
 
143
-static int camd_send_emm(struct ts *ts, uint16_t ca_id, uint16_t service_id, uint8_t *data, uint8_t data_len) {
143
+static int camd_send_emm(struct ts *ts, struct camd_msg *msg) {
144 144
 	struct camd *c = &ts->camd;
145
-	int ret = c->ops.do_emm(c, ca_id, service_id, data, data_len);
145
+	int ret = c->ops.do_emm(c, msg);
146 146
 	if (ret < 0) {
147 147
 		c->emm_recv_errors++;
148 148
 		if (c->emm_recv_errors >= EMM_RECV_ERRORS_LIMIT) {
@@ -159,30 +159,21 @@ static int camd_send_emm(struct ts *ts, uint16_t ca_id, uint16_t service_id, uin
159 159
 static void camd_do_msg(struct camd_msg *msg) {
160 160
 	if (msg->type == EMM_MSG) {
161 161
 		msg->ts->emm_seen_count++;
162
-		if (camd_send_emm(msg->ts, msg->ca_id, msg->service_id, msg->data, msg->data_len) > 0)
162
+		if (camd_send_emm(msg->ts, msg) > 0)
163 163
 			msg->ts->emm_processed_count++;
164 164
 	}
165 165
 	if (msg->type == ECM_MSG) {
166 166
 		msg->ts->ecm_seen_count++;
167
-		if (camd_send_ecm(msg->ts, msg->ca_id, msg->service_id, msg->data, msg->data_len) > 0)
167
+		if (camd_send_ecm(msg->ts, msg) > 0)
168 168
 			msg->ts->ecm_processed_count++;
169 169
 	}
170 170
 
171 171
 	camd_msg_free(&msg);
172 172
 }
173 173
 
174
-struct camd_msg *camd_msg_alloc_emm(uint16_t ca_id, uint8_t *data, uint8_t data_len) {
174
+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) {
175 175
 	struct camd_msg *c = calloc(1, sizeof(struct camd_msg));
176
-	c->type       = EMM_MSG;
177
-	c->ca_id      = ca_id;
178
-	c->data_len   = data_len;
179
-	memcpy(c->data, data, data_len);
180
-	return c;
181
-}
182
-
183
-struct camd_msg *camd_msg_alloc_ecm(uint16_t ca_id, uint16_t service_id, uint8_t *data, uint8_t data_len) {
184
-	struct camd_msg *c = calloc(1, sizeof(struct camd_msg));
185
-	c->type       = ECM_MSG;
176
+	c->type       = msg_type;
186 177
 	c->ca_id      = ca_id;
187 178
 	c->service_id = service_id;
188 179
 	c->data_len   = data_len;
@@ -217,7 +208,7 @@ static void *camd_thread(void *in_ts) {
217 208
 	pthread_exit(EXIT_SUCCESS);
218 209
 }
219 210
 
220
-void camd_msg_process(struct ts *ts, struct camd_msg *msg) {
211
+void camd_process_packet(struct ts *ts, struct camd_msg *msg) {
221 212
 	msg->ts = ts;
222 213
 	if (ts->camd.thread) {
223 214
 		if (msg->type == EMM_MSG)

+ 3
- 3
camd.h View File

@@ -22,13 +22,13 @@
22 22
 
23 23
 int						camd_tcp_connect	(struct in_addr ip, int port);
24 24
 
25
-struct camd_msg *		camd_msg_alloc_emm	(uint16_t ca_id, uint8_t *emm_data, uint8_t emm_data_len);
26
-struct camd_msg *		camd_msg_alloc_ecm	(uint16_t ca_id, uint16_t service_id, uint8_t *ecm_data, uint8_t ecm_data_len);
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);
27 26
 void					camd_msg_free   	(struct camd_msg **pmsg);
28 27
 
29 28
 void					camd_start			(struct ts *ts);
30 29
 void					camd_stop			(struct ts *ts);
31
-void					camd_msg_process	(struct ts *ts, struct camd_msg *msg);
30
+
31
+void					camd_process_packet	(struct ts *ts, struct camd_msg *msg);
32 32
 
33 33
 void					camd_proto_cs378x	(struct camd_ops *ops);
34 34
 

+ 2
- 2
data.h View File

@@ -85,8 +85,8 @@ struct camd_ops {
85 85
 	int (*connect)(struct camd *c);
86 86
 	void (*disconnect)(struct camd *c);
87 87
 	int (*reconnect)(struct camd *c);
88
-	int (*do_emm)(struct camd *c, uint16_t ca_id, uint16_t service_id, uint8_t *data, uint8_t data_len);
89
-	int (*do_ecm)(struct camd *c, uint16_t ca_id, uint16_t service_id, uint8_t *data, uint8_t data_len);
88
+	int (*do_emm)(struct camd *c, struct camd_msg *msg);
89
+	int (*do_ecm)(struct camd *c, struct camd_msg *msg);
90 90
 	int (*get_cw)(struct camd *c, uint16_t *ca_id, uint16_t *idx, uint8_t *cw);
91 91
 };
92 92
 

+ 2
- 2
tables.c View File

@@ -266,7 +266,7 @@ static void __process_emm(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
266 266
 			sec->section_data_len,
267 267
 			dump);
268 268
 	}
269
-	camd_msg_process(ts, camd_msg_alloc_emm(ts->emm_caid, sec->section_data, sec->section_data_len));
269
+	camd_process_packet(ts, camd_msg_alloc(EMM_MSG, ts->emm_caid, ts->service_id, sec->section_data, sec->section_data_len));
270 270
 	ts_privsec_copy(ts->emm, ts->last_emm);
271 271
 	ts_privsec_clear(ts->emm);
272 272
 }
@@ -310,7 +310,7 @@ static void __process_ecm(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
310 310
 				dump);
311 311
 		}
312 312
 		ts->is_cw_error = 0;
313
-		camd_msg_process(ts, camd_msg_alloc_ecm(ts->ecm_caid, ts->service_id, sec->section_data, sec->section_data_len));
313
+		camd_process_packet(ts, camd_msg_alloc(ECM_MSG, ts->ecm_caid, ts->service_id, sec->section_data, sec->section_data_len));
314 314
 	} else if (ts->debug_level >= 3) {
315 315
 		ts_LOGf("ECM | CAID: 0x%04x PID 0x%04x Table: 0x%02x Length: %3d Data: -dup-\n",
316 316
 			ts->ecm_caid,

Loading…
Cancel
Save