Browse Source

Factor some code into camd35_buf_init()

Georgi Chorbadzhiyski 13 years ago
parent
commit
16d24140d4
1 changed files with 11 additions and 13 deletions
  1. 11
    13
      tsdecrypt.c

+ 11
- 13
tsdecrypt.c View File

@@ -210,25 +210,28 @@ static int camd35_send(uint8_t *data, uint8_t data_len, enum e_flag tp) {
210 210
 	return 0;
211 211
 }
212 212
 
213
+static void camd35_buf_init(uint8_t *buf, uint8_t *data, uint8_t data_len) {
214
+	memset(buf, 0, HDR_LEN); // Reset header
215
+	memset(buf + HDR_LEN, 0xff, BUF_SIZE - HDR_LEN); // Reset data
216
+	buf[1] = data_len; // Data length
217
+	init_4b(crc32(0L, data, data_len), buf + 4); // Data CRC is at buf[4]
218
+	memcpy(buf + HDR_LEN, data, data_len); // Copy data to buf
219
+}
213 220
 
214 221
 static int camd35_send_ecm(uint16_t service_id, uint16_t ca_id, uint16_t idx, uint8_t *data, uint8_t data_len) {
215 222
 	uint8_t buf[BUF_SIZE];
216 223
 	uint32_t provider_id = 0;
217
-	uint32_t crc = crc32(0L, data, data_len);
218 224
 	int to_send = boundary(4, HDR_LEN + data_len);
219 225
 
220
-	memset(buf, 0xff, BUF_SIZE);
226
+	camd35_buf_init(buf, data, data_len);
221 227
 
222
-	memset(buf, 0, HDR_LEN);
223
-	buf[1] = data_len;
224
-	init_4b(crc        , buf + 4);
228
+	buf[0] = 0x00; // CMD ECM request
225 229
 	init_2b(service_id , buf + 8);
226 230
 	init_2b(ca_id      , buf + 10);
227 231
 	init_4b(provider_id, buf + 12);
228 232
 	init_2b(idx        , buf + 16);
229 233
 	buf[18] = 0xff;
230 234
 	buf[19] = 0xff;
231
-	memcpy(buf + HDR_LEN, data, data_len);
232 235
 
233 236
 	return camd35_send(buf, to_send, TYPE_ECM);
234 237
 }
@@ -236,18 +239,13 @@ static int camd35_send_ecm(uint16_t service_id, uint16_t ca_id, uint16_t idx, ui
236 239
 static int camd35_send_emm(uint16_t ca_id, uint8_t *data, uint8_t data_len) {
237 240
 	uint8_t buf[BUF_SIZE];
238 241
 	uint32_t prov_id = 0;
239
-	uint32_t crc = crc32(0L, data, data_len);
240 242
 	int to_send = boundary(4, data_len + HDR_LEN);
241 243
 
242
-	memset(buf, 0xff, BUF_SIZE);
244
+	camd35_buf_init(buf, data, data_len);
243 245
 
244
-	memset(buf, 0, HDR_LEN);
245
-	buf[0] = 0x06;
246
-	buf[1] = data_len;
247
-	init_4b(crc    , buf + 4);
246
+	buf[0] = 0x06; // CMD incomming EMM
248 247
 	init_2b(ca_id  , buf + 10);
249 248
 	init_4b(prov_id, buf + 12);
250
-	memcpy(buf + HDR_LEN, data, data_len);
251 249
 
252 250
 	return camd35_send(buf, to_send, TYPE_EMM);
253 251
 }

Loading…
Cancel
Save