source: trunk/reader-irdeto.c@ 3168

Last change on this file since 3168 was 3168, checked in by _network, 10 years ago

merge modular branch with trunk

File size: 18.0 KB
Line 
1#include "globals.h"
2#include "reader-common.h"
3
4static const uchar CryptTable[256] =
5{
6 0xDA, 0x26, 0xE8, 0x72, 0x11, 0x52, 0x3E, 0x46,
7 0x32, 0xFF, 0x8C, 0x1E, 0xA7, 0xBE, 0x2C, 0x29,
8 0x5F, 0x86, 0x7E, 0x75, 0x0A, 0x08, 0xA5, 0x21,
9 0x61, 0xFB, 0x7A, 0x58, 0x60, 0xF7, 0x81, 0x4F,
10 0xE4, 0xFC, 0xDF, 0xB1, 0xBB, 0x6A, 0x02, 0xB3,
11 0x0B, 0x6E, 0x5D, 0x5C, 0xD5, 0xCF, 0xCA, 0x2A,
12 0x14, 0xB7, 0x90, 0xF3, 0xD9, 0x37, 0x3A, 0x59,
13 0x44, 0x69, 0xC9, 0x78, 0x30, 0x16, 0x39, 0x9A,
14 0x0D, 0x05, 0x1F, 0x8B, 0x5E, 0xEE, 0x1B, 0xC4,
15 0x76, 0x43, 0xBD, 0xEB, 0x42, 0xEF, 0xF9, 0xD0,
16 0x4D, 0xE3, 0xF4, 0x57, 0x56, 0xA3, 0x0F, 0xA6,
17 0x50, 0xFD, 0xDE, 0xD2, 0x80, 0x4C, 0xD3, 0xCB,
18 0xF8, 0x49, 0x8F, 0x22, 0x71, 0x84, 0x33, 0xE0,
19 0x47, 0xC2, 0x93, 0xBC, 0x7C, 0x3B, 0x9C, 0x7D,
20 0xEC, 0xC3, 0xF1, 0x89, 0xCE, 0x98, 0xA2, 0xE1,
21 0xC1, 0xF2, 0x27, 0x12, 0x01, 0xEA, 0xE5, 0x9B,
22 0x25, 0x87, 0x96, 0x7B, 0x34, 0x45, 0xAD, 0xD1,
23 0xB5, 0xDB, 0x83, 0x55, 0xB0, 0x9E, 0x19, 0xD7,
24 0x17, 0xC6, 0x35, 0xD8, 0xF0, 0xAE, 0xD4, 0x2B,
25 0x1D, 0xA0, 0x99, 0x8A, 0x15, 0x00, 0xAF, 0x2D,
26 0x09, 0xA8, 0xF5, 0x6C, 0xA1, 0x63, 0x67, 0x51,
27 0x3C, 0xB2, 0xC0, 0xED, 0x94, 0x03, 0x6F, 0xBA,
28 0x3F, 0x4E, 0x62, 0x92, 0x85, 0xDD, 0xAB, 0xFE,
29 0x10, 0x2E, 0x68, 0x65, 0xE7, 0x04, 0xF6, 0x0C,
30 0x20, 0x1C, 0xA9, 0x53, 0x40, 0x77, 0x2F, 0xA4,
31 0xFA, 0x6D, 0x73, 0x28, 0xE2, 0xCD, 0x79, 0xC8,
32 0x97, 0x66, 0x8E, 0x82, 0x74, 0x06, 0xC7, 0x88,
33 0x1A, 0x4A, 0x6B, 0xCC, 0x41, 0xE9, 0x9D, 0xB8,
34 0x23, 0x9F, 0x3D, 0xBF, 0x8D, 0x95, 0xC5, 0x13,
35 0xB9, 0x24, 0x5A, 0xDC, 0x64, 0x18, 0x38, 0x91,
36 0x7F, 0x5B, 0x70, 0x54, 0x07, 0xB6, 0x4B, 0x0E,
37 0x36, 0xAC, 0x31, 0xE6, 0xD6, 0x48, 0xAA, 0xB4
38};
39
40uchar
41 sc_GetCountryCode[] = { 0x02, 0x02, 0x03, 0x00, 0x00 },
42 sc_GetASCIISerial[] = { 0x02, 0x00, 0x03, 0x00, 0x00 },
43 sc_GetHEXSerial[] = { 0x02, 0x01, 0x00, 0x00, 0x00 },
44 sc_GetCardFile[] = { 0x02, 0x0E, 0x02, 0x00, 0x00 },
45 sc_GetChanelIds[] = { 0x02, 0x04, 0x00, 0x00, 0x01, 0x00 },
46 sc_CamKey[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 },
47 sc_GetProvider[] = { 0x02, 0x03, 0x03, 0x00, 0x00 },
48 sc_GetCamKey383C[] = { 0x02, 0x09, 0x03, 0x00, 0x40,
49 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
50 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
51 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
52 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF,
53 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
54 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
55 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
56 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
57
58static const uchar
59 sc_GetCountryCode2[]= { 0x02, 0x0B, 0x00, 0x00, 0x00 },
60 sc_GetCamKey384CZ[] = { 0x02, 0x09, 0x03, 0x00, 0x40,
61 0x18, 0xD7, 0x55, 0x14, 0xC0, 0x83, 0xF1, 0x38,
62 0x39, 0x6F, 0xF2, 0xEC, 0x4F, 0xE3, 0xF1, 0x85,
63 0x01, 0x46, 0x06, 0xCE, 0x7D, 0x08, 0x2C, 0x74,
64 0x46, 0x8F, 0x72, 0xC4, 0xEA, 0xD7, 0x9C, 0xE0,
65 0xE1, 0xFF, 0x58, 0xE7, 0x70, 0x0C, 0x92, 0x45,
66 0x26, 0x18, 0x4F, 0xA0, 0xE2, 0xF5, 0x9E, 0x46,
67 0x6F, 0xAE, 0x95, 0x35, 0xB0, 0x49, 0xB2, 0x0E,
68 0xA4, 0x1F, 0x8E, 0x47, 0xD0, 0x24, 0x11, 0xD0 },
69 sc_GetCamKey384DZ[] = { 0x02, 0x09, 0x03, 0x00, 0x40,
70 0x27, 0xF2, 0xD6, 0xCD, 0xE6, 0x88, 0x62, 0x46,
71 0x81, 0xB0, 0xF5, 0x3E, 0x6F, 0x13, 0x4D, 0xCC,
72 0xFE, 0xD0, 0x67, 0xB1, 0x93, 0xDD, 0xF4, 0xDE,
73 0xEF, 0xF5, 0x3B, 0x04, 0x1D, 0xE5, 0xC3, 0xB2,
74 0x54, 0x38, 0x57, 0x7E, 0xC8, 0x39, 0x07, 0x2E,
75 0xD2, 0xF4, 0x05, 0xAA, 0x15, 0xB5, 0x55, 0x24,
76 0x90, 0xBB, 0x9B, 0x00, 0x96, 0xF0, 0xCB, 0xF1,
77 0x8A, 0x08, 0x7F, 0x0B, 0xB8, 0x79, 0xC3, 0x5D },
78 sc_GetCamKey384FZ[] = { 0x02, 0x09, 0x03, 0x00, 0x40,
79 0x62, 0xFE, 0xD8, 0x4F, 0x44, 0x86, 0x2C, 0x21,
80 0x50, 0x9A, 0xBE, 0x27, 0x15, 0x9E, 0xC4, 0x48,
81 0xF3, 0x73, 0x5C, 0xBD, 0x08, 0x64, 0x6D, 0x13,
82 0x64, 0x90, 0x14, 0xDB, 0xFF, 0xC3, 0xFE, 0x03,
83 0x97, 0xFA, 0x75, 0x08, 0x12, 0xF9, 0x8F, 0x84,
84 0x83, 0x17, 0xAA, 0x6F, 0xEF, 0x2C, 0x10, 0x1B,
85 0xBF, 0x31, 0x41, 0xC3, 0x54, 0x2F, 0x65, 0x50,
86 0x95, 0xA9, 0x64, 0x22, 0x5E, 0xA4, 0xAF, 0xA9 };
87
88typedef struct chid_base_date {
89 ushort caid;
90 ushort acs;
91 char c_code[4];
92 long base;
93} CHID_BASE_DATE;
94
95static void XRotateLeft8Byte(uchar *buf)
96{
97 int k;
98 uchar t1=buf[7];
99 uchar t2=0;
100 for(k=0; k<=7; k++)
101 {
102 t2=t1;
103 t1=buf[k];
104 buf[k]=(buf[k]<<1)|(t2>>7);
105 }
106}
107
108static void ReverseSessionKeyCrypt(const uchar *camkey, uchar *key)
109{
110 uchar localkey[8], tmp1, tmp2;
111 int idx1,idx2;
112
113 memcpy(localkey, camkey, 8) ;
114 for(idx1=0; idx1<8; idx1++)
115 {
116 for(idx2=0; idx2<8; idx2++)
117 {
118 tmp1 = CryptTable[key[7] ^ localkey[idx2] ^ idx1] ;
119 tmp2 = key[0] ;
120 key[0] = key[1] ;
121 key[1] = key[2] ;
122 key[2] = key[3] ;
123 key[3] = key[4] ;
124 key[4] = key[5] ;
125 key[5] = key[6] ^ tmp1 ;
126 key[6] = key[7] ;
127 key[7] = tmp1 ^ tmp2 ;
128 }
129 XRotateLeft8Byte(localkey);
130 }
131}
132
133static time_t chid_date(struct s_reader * reader, ulong date, char *buf, int l)
134{
135
136 // Irdeto date starts 01.08.1997 which is
137 // 870393600 seconds in unix calendar time
138 //
139 // The above might not be true for all Irdeto card
140 // we need to find a way to identify cards to set the base date
141 // like we did for NDS
142 //
143 // this is the known default value.
144 long date_base=870393600L; // this is actually 31.07.1997, 17:00
145 // CAID, ACS, Country, base date D . M. Y, h : m
146 CHID_BASE_DATE table[] = { {0x0604, 0x1541, "GRC", 977817600L}, // 26.12.2000, 00:00
147 {0x0604, 0x1542, "GRC", 977817600L}, // 26.12.2000, 00:00
148 {0x0604, 0x1543, "GRC", 977817600L}, // 26.12.2000, 00:00
149 {0x0604, 0x1544, "GRC", 977817600L}, // 26.12.2000, 17:00
150 {0x0628, 0x0606, "MCR", 1159574400L}, // 29.09.2006, 00:00
151 {0x0604, 0x0608, "EGY", 999993600L}, // 08.09.2001, 17:00
152 {0x0604, 0x0606, "EGY", 1003276800L}, // 16.10.2001, 17:00
153 {0x0627, 0x0608, "EGY", 946598400L}, // 30.12.1999, 16:00
154 {0x0664, 0x0608, "TUR", 946598400L}, // 31.12.1999, 00:00
155 // {0x1702, 0x0384, "GER", 888883200L}, // 02.03.1998, 16:00 -> this fixes some card but break others (S02).
156 {0x0, 0x0, "", 0L}
157 };
158
159 // now check for specific providers base date
160 int i=0;
161 while(table[i].caid) {
162 if(reader->caid[0]==table[i].caid && reader->acs==table[i].acs && !memcmp(reader->country_code,table[i].c_code,3) ) {
163 date_base = table[i].base;
164 break;
165 }
166 i++;
167 }
168
169 time_t ut=date_base+date*(24*3600);
170 if (buf) {
171 struct tm *t;
172 t=gmtime(&ut);
173 snprintf(buf, l, "%04d/%02d/%02d", t->tm_year+1900, t->tm_mon+1, t->tm_mday);
174 }
175 return(ut);
176}
177
178static int irdeto_do_cmd(struct s_reader * reader, uchar *buf, ushort good, uchar * cta_res, ushort * p_cta_lr)
179{
180 int rc;
181 if( (rc = reader_cmd2icc(reader, buf, buf[4] + 5, cta_res, p_cta_lr)) )
182 return(rc); // result may be 0 (success) or negative
183 if (*p_cta_lr < 2)
184 return(0x7F7F); // this should never happen
185 return(good != b2i(2, cta_res+*p_cta_lr-2));
186}
187
188#define reader_chk_cmd(cmd, l) \
189{ \
190 if (reader_cmd2icc(reader, cmd, sizeof(cmd), cta_res, &cta_lr)) return ERROR; \
191 if (l && (cta_lr!=l)) return ERROR; }
192
193static int irdeto_card_init_provider(struct s_reader * reader)
194{
195 def_resp;
196 int i, p;
197 uchar buf[256] = {0};
198
199 /*
200 * Provider
201 */
202 memset(reader->prid, 0xff, sizeof(reader->prid));
203 for (buf[0] = i = p = 0; i<reader->nprov; i++)
204 {
205 sc_GetProvider[3] = i;
206 reader_chk_cmd(sc_GetProvider, 0);
207 //if ((cta_lr==26) && (cta_res[0]!=0xf))
208 if ((cta_lr == 26) && ((!(i&1)) || (cta_res[0] != 0xf)))
209 {
210 reader->prid[i][4] = p++;
211
212 // maps the provider id for Betacrypt from FFFFFF to 000000,
213 // fixes problems with cascading CCcam and OSCam
214 if ((reader->caid[0] >= 0x1700) && (reader->caid[0] <= 0x1799))
215 memset(&reader->prid[i][0], 0, 4);
216 else
217 memcpy(&reader->prid[i][0], cta_res, 4);
218
219 sprintf((char *) buf+strlen((char *)buf), ",%06lx", b2i(3, &reader->prid[i][1]));
220 }
221 else
222 reader->prid[i][0] = 0xf;
223 }
224 if (p)
225 cs_ri_log(reader, "active providers: %d (%s)", p, buf + 1);
226
227 return OK;
228}
229
230int irdeto_card_init(struct s_reader * reader, ATR newatr)
231{
232 def_resp;
233 get_atr;
234 int camkey = 0;
235 uchar buf[256] = {0};
236
237 if (memcmp(atr+4, "IRDETO", 6))
238 return ERROR;
239 cs_ri_log(reader, "detect irdeto card");
240
241 if(reader->has_rsa && !reader->force_irdeto) // we use rsa from config as camkey
242 {
243 cs_debug("[irdeto-reader] using camkey data from config");
244 memcpy(&sc_GetCamKey383C[5], reader->rsa_mod, 0x40);
245 memcpy(sc_CamKey, reader->nagra_boxkey, 8);
246 cs_debug("[irdeto-reader] camkey: %s", cs_hexdump (0, sc_CamKey, 8));
247 cs_debug("[irdeto-reader] camkey-data: %s", cs_hexdump (0, &sc_GetCamKey383C[5], 32));
248 cs_debug("[irdeto-reader] camkey-data: %s", cs_hexdump (0, &sc_GetCamKey383C[37], 32));
249 }
250
251 /*
252 * ContryCode
253 */
254 reader_chk_cmd(sc_GetCountryCode, 18);
255 reader->acs = (cta_res[0] << 8) | cta_res[1];
256 reader->caid[0] = (cta_res[5] << 8) | cta_res[6];
257 memcpy(reader->country_code,cta_res + 13, 3);
258 cs_ri_log(reader, "caid: %04X, acs: %x.%02x, country code: %c%c%c",
259 reader->caid[0], cta_res[0], cta_res[1], cta_res[13], cta_res[14], cta_res[15]);
260
261 /*
262 * Ascii/Hex-Serial
263 */
264 reader_chk_cmd(sc_GetASCIISerial, 22);
265 memcpy(buf, cta_res, 10);
266 buf[10] = 0;
267 reader_chk_cmd(sc_GetHEXSerial, 18);
268 memcpy(reader->hexserial, cta_res+12, 8);
269 reader->nprov = cta_res[10];
270 cs_ri_log(reader, "providers: %d, ascii serial: %s, hex serial: %02X%02X%02X, hex base: %02X",
271 reader->nprov, buf, cta_res[12], cta_res[13], cta_res[14], cta_res[15]);
272
273 /*
274 * CardFile
275 */
276 for (sc_GetCardFile[2] = 2; sc_GetCardFile[2] < 4; sc_GetCardFile[2]++)
277 reader_chk_cmd(sc_GetCardFile, 0);
278
279 /*
280 * CamKey
281 */
282 if ((atr[14] == 0x03) && (atr[15] == 0x84) && (atr[16] == 0x55))
283 {
284 switch (reader->caid[0])
285 {
286 case 0x1702: camkey = 1; break;
287 case 0x1722: camkey = 2; break;
288 case 0x1762: camkey = 3; break;
289 default : camkey = 4; break;
290 }
291 }
292
293 cs_debug("[irdeto-reader] set camkey for type=%d", camkey);
294
295 switch (camkey)
296 {
297 case 1:
298 reader_chk_cmd(sc_GetCamKey384CZ, 10);
299 break;
300 case 2:
301 reader_chk_cmd(sc_GetCamKey384DZ, 10);
302 break;
303 case 3:
304 reader_chk_cmd(sc_GetCamKey384FZ, 10);
305 break;
306 default:
307 reader_chk_cmd(sc_GetCamKey383C, 0);
308 break;
309 }
310 if (reader->cardmhz != 600)
311 cs_log("WARNING: For Irdeto cards you will have to set 'cardmhz = 600' in oscam.server");
312
313 return irdeto_card_init_provider(reader);
314}
315
316int irdeto_do_ecm(struct s_reader * reader, ECM_REQUEST *er)
317{
318 def_resp; cta_lr = 0; //suppress compiler error
319 static const uchar sc_EcmCmd[] = { 0x05, 0x00, 0x00, 0x02, 0x00 };
320 uchar cta_cmd[272];
321
322 memcpy(cta_cmd, sc_EcmCmd, sizeof(sc_EcmCmd));
323 cta_cmd[4] = (er->ecm[2]) - 3;
324 memcpy(cta_cmd + sizeof(sc_EcmCmd), &er->ecm[6], cta_cmd[4]);
325
326 if (irdeto_do_cmd(reader, cta_cmd, 0x9D00, cta_res, &cta_lr)) {
327 if(cta_lr >= 2)
328 snprintf( er->msglog, MSGLOGSIZE, "irdeto_do_cmd [%d] %02x %02x", cta_lr, cta_res[cta_lr - 2], cta_res[cta_lr - 1] );
329 else
330 snprintf( er->msglog, MSGLOGSIZE, "irdeto_do_cmd [%d]<2", cta_lr);
331
332 return ERROR;
333 }
334
335 if (cta_lr < 24) {
336 snprintf( er->msglog, MSGLOGSIZE, "cta_lr (%d) < 24",cta_lr );
337 return ERROR;
338 }
339
340 ReverseSessionKeyCrypt(sc_CamKey, cta_res+6);
341 ReverseSessionKeyCrypt(sc_CamKey, cta_res+14);
342 memcpy(er->cw, cta_res + 6, 16);
343 return OK;
344}
345
346int irdeto_get_emm_type(EMM_PACKET *ep, struct s_reader * rdr) {
347
348 int i, l = (ep->emm[3]&0x07);
349 int base = (ep->emm[3]>>3);
350 char dumprdrserial[l*3];
351
352 cs_debug_mask(D_EMM, "Entered irdeto_get_emm_type ep->emm[3]=%02x",ep->emm[3]);
353
354 switch (l) {
355
356 case 0:
357 // global emm, 0 bytes addressed
358 ep->type = GLOBAL;
359 cs_debug_mask(D_EMM, "IRDETO EMM: GLOBAL");
360 return TRUE;
361
362 case 2:
363 // shared emm, 2 bytes addressed
364 ep->type = SHARED;
365 memset(ep->hexserial, 0, 8);
366 memcpy(ep->hexserial, ep->emm + 4, l);
367 strcpy(dumprdrserial, cs_hexdump(1, rdr->hexserial, l));
368 cs_debug_mask(D_EMM, "IRDETO EMM: SHARED l = %d ep = %s rdr = %s base = %02x", l,
369 cs_hexdump(1, ep->hexserial, l), dumprdrserial, base);
370
371 if (base & 0x10) {
372 // hex addressed
373 return (base == rdr->hexserial[3] && !memcmp(ep->emm + 4, rdr->hexserial, l));
374 }
375 else {
376 // provider addressed
377 for(i = 0; i < rdr->nprov; i++)
378 if (base == rdr->prid[i][0] && !memcmp(ep->emm + 4, &rdr->prid[i][1], l))
379 return TRUE;
380 }
381 cs_debug_mask(D_EMM, "IRDETO EMM: neither hex nor provider addressed or unknown provider id");
382 return FALSE;
383
384 case 3:
385 // unique emm, 3 bytes addressed
386 ep->type = UNIQUE;
387 memset(ep->hexserial, 0, 8);
388 memcpy(ep->hexserial, ep->emm + 4, l);
389 strcpy(dumprdrserial, cs_hexdump(1, rdr->hexserial, l));
390 cs_debug_mask(D_EMM, "IRDETO EMM: UNIQUE l = %d ep = %s rdr = %s", l,
391 cs_hexdump(1, ep->hexserial, l), dumprdrserial);
392
393 return (base == rdr->hexserial[3] && !memcmp(ep->emm + 4, rdr->hexserial, l));
394
395 default:
396 ep->type = UNKNOWN;
397 cs_debug_mask(D_EMM, "IRDETO EMM: UNKNOWN");
398 return TRUE;
399 }
400
401}
402
403void irdeto_get_emm_filter(struct s_reader * rdr, uchar *filter)
404{
405 filter[0]=0xFF;
406 filter[1]=3;
407
408 int base = rdr->hexserial[3];
409 int emm_g = base * 8;
410 int emm_s = emm_g + 2;
411 int emm_u = emm_g + 3;
412
413 filter[2]=GLOBAL;
414 filter[3]=0;
415
416 filter[4+0] = 0x82;
417 filter[4+0+16] = 0xFF;
418 filter[4+1] = emm_g;
419 filter[4+1+16] = 0x0F;
420
421 filter[36]=SHARED;
422 filter[37]=0;
423 filter[38+0] = 0x82;
424 filter[38+0+16] = 0xFF;
425 filter[38+1] = emm_s;
426 filter[38+1+16] = 0xFF;
427 memcpy(filter+38+2, rdr->hexserial, 2);
428 memset(filter+38+2+16, 0xFF, 2);
429
430 filter[70]=UNIQUE;
431 filter[71]=0;
432 filter[72+0] = 0x82;
433 filter[72+0+16] = 0xFF;
434 filter[72+1] = emm_u;
435 filter[72+1+16] = 0xFF;
436 memcpy(filter+72+2, rdr->hexserial, 3);
437 memset(filter+72+2+16, 0xFF, 3);
438
439 return;
440}
441
442int irdeto_do_emm(struct s_reader * reader, EMM_PACKET *ep)
443{
444 def_resp;
445 static const uchar sc_EmmCmd[] = { 0x01,0x00,0x00,0x00,0x00 };
446 uchar cta_cmd[272];
447
448 int i, l = (ep->emm[3] & 0x07), ok = 0;
449 int mode = (ep->emm[3] >> 3);
450
451 uchar *emm = ep->emm;
452 if (mode & 0x10) // Hex addressed
453 {
454 ok=(mode == reader->hexserial[3] &&
455 (!l || !memcmp(&emm[4], reader->hexserial, l)));
456 }
457 else // Provider addressed
458 {
459 for(i = 0; i < reader->nprov; i++)
460 {
461 ok=(mode == reader->prid[i][0] &&
462 (!l || !memcmp(&emm[4], &reader->prid[i][1], l)));
463 if (ok) break;
464 }
465 }
466
467 if (ok)
468 {
469 l++;
470 if (l <= ADDRLEN)
471 {
472 const int dataLen = SCT_LEN(emm) - 5 - l; // sizeof of emm bytes (nanos)
473 uchar *ptr = cta_cmd;
474 memcpy(ptr, sc_EmmCmd, sizeof(sc_EmmCmd)); // copy card command
475 ptr[4] = dataLen + ADDRLEN; // set card command emm size
476 ptr += sizeof(sc_EmmCmd); emm += 3;
477 memset(ptr, 0, ADDRLEN); // clear addr range
478 memcpy(ptr, emm, l); // copy addr bytes
479 ptr += ADDRLEN; emm += l;
480 memcpy(ptr, &emm[2], dataLen); // copy emm bytes
481 return(irdeto_do_cmd(reader, cta_cmd, 0, cta_res, &cta_lr) ? 0 : 1);
482 }
483 else
484 cs_debug("[irdeto-reader] addrlen %d > %d", l, ADDRLEN);
485 }
486 return ERROR;
487}
488
489int irdeto_card_info(struct s_reader * reader)
490{
491 def_resp;
492 int i, p;
493
494 /*
495 * ContryCode2
496 */
497 reader_chk_cmd(sc_GetCountryCode2, 0);
498
499 if ((cta_lr>9) && !(cta_res[cta_lr-2]|cta_res[cta_lr-1]))
500 {
501 cs_debug("[irdeto-reader] max chids: %d, %d, %d, %d", cta_res[6], cta_res[7], cta_res[8], cta_res[9]);
502
503 /*
504 * Provider 2
505 */
506 for (i=p=0; i<reader->nprov; i++)
507 {
508 int j, k, chid, first=1;
509 char t[32];
510 if (reader->prid[i][4]!=0xff)
511 {
512 p++;
513 sc_GetChanelIds[3]=i; // provider at index i
514 j=0;
515 // for (j=0; j<10; j++) => why 10 .. do we know for sure the there are only 10 chids !!!
516 // shouldn't it me the max chid value we read above ?!
517 while(1) // will exit if cta_lr < 61 .. which is the correct break condition.
518 {
519 sc_GetChanelIds[5]=j; // chid at index j for provider at index i
520 reader_chk_cmd(sc_GetChanelIds, 0);
521 // if (cta_lr<61) break; // why 61 (0 to 60 in steps of 6 .. is it 10*6 from the 10 in the for loop ?
522 // what happen if the card only send back.. 9 chids (or less)... we don't see them
523 // so we should check whether or not we have at least 6 bytes (1 chid).
524 if (cta_lr<6) break;
525
526 for(k=0; k<cta_lr; k+=6)
527 {
528 chid=b2i(2, cta_res+k);
529 if (chid && chid!=0xFFFF)
530 {
531 time_t date;
532 chid_date(reader,date=b2i(2, cta_res+k+2), t, 16);
533 chid_date(reader,date+cta_res[k+4], t+16, 16);
534 if (first)
535 {
536 cs_ri_log(reader, "entitlements for provider: %d, id: %06X", p, b2i(3, &reader->prid[i][1]));
537 first=0;
538 }
539 cs_ri_log(reader, "chid: %04X, date: %s - %s", chid, t, t+16);
540 }
541 }
542 j++;
543 }
544 }
545 }
546 }
547 cs_log("[irdeto-reader] ready for requests");
548 return OK;
549}
550
551void reader_irdeto(struct s_cardsystem *ph)
552{
553 ph->do_emm=irdeto_do_emm;
554 ph->do_ecm=irdeto_do_ecm;
555 ph->card_info=irdeto_card_info;
556 ph->card_init=irdeto_card_init;
557 ph->get_emm_type=irdeto_get_emm_type;
558 ph->get_emm_filter=irdeto_get_emm_filter;
559 ph->caids[0]=0x06;
560 ph->caids[1]=0x17;
561}
Note: See TracBrowser for help on using the repository browser.