1 | #include "globals.h"
|
---|
2 | #ifdef READER_CONAX
|
---|
3 | #include "cscrypt/bn.h"
|
---|
4 | #include "reader-common.h"
|
---|
5 |
|
---|
6 | static int32_t RSA_CNX(struct s_reader *reader, unsigned char *msg, unsigned char *mod, unsigned char *exp, uint32_t cta_lr, uint32_t modbytes, uint32_t expbytes)
|
---|
7 | {
|
---|
8 | int32_t ret=0;
|
---|
9 | uint32_t n = 0, pre_size=0, size=0;
|
---|
10 | BN_CTX *ctx;
|
---|
11 | BIGNUM *bn_mod, *bn_exp, *bn_data, *bn_res;
|
---|
12 | unsigned char data[64];
|
---|
13 |
|
---|
14 | /*prefix size*/
|
---|
15 | pre_size = 2 + 4 + msg[5];
|
---|
16 | /*size of data to decryption*/
|
---|
17 | if(msg[1] > (pre_size-2))
|
---|
18 | size = msg[1] - pre_size + 2;
|
---|
19 |
|
---|
20 | if(cta_lr > (pre_size + size) &&
|
---|
21 | size >= modbytes && size < 128)
|
---|
22 | {
|
---|
23 | bn_mod = BN_new ();
|
---|
24 | bn_exp = BN_new ();
|
---|
25 | bn_data = BN_new ();
|
---|
26 | bn_res = BN_new ();
|
---|
27 | ctx= BN_CTX_new();
|
---|
28 | if (ctx == NULL) {
|
---|
29 | rdr_debug_mask(reader, D_READER, "RSA Error in RSA_CNX");
|
---|
30 | }
|
---|
31 |
|
---|
32 | /*RSA first round*/
|
---|
33 | BN_bin2bn (mod, modbytes, bn_mod); // rsa modulus
|
---|
34 | BN_bin2bn (exp, expbytes, bn_exp); // exponent
|
---|
35 | BN_bin2bn (msg+pre_size, modbytes, bn_data);
|
---|
36 | BN_mod_exp (bn_res, bn_data, bn_exp, bn_mod, ctx);
|
---|
37 |
|
---|
38 | n = BN_bn2bin (bn_res, data);
|
---|
39 |
|
---|
40 | size -= modbytes; //3
|
---|
41 | pre_size += modbytes;
|
---|
42 | /*Check if second round is needed*/
|
---|
43 | if(0 < size)
|
---|
44 | {
|
---|
45 | /*check if length of data from first RSA round will be enough to padding rest of data*/
|
---|
46 | if((n+size) >= modbytes)
|
---|
47 | {
|
---|
48 | /*RSA second round*/
|
---|
49 | /*move the remaining data at the beginning of the buffer*/
|
---|
50 | memcpy(msg, msg+pre_size, size);
|
---|
51 | /*padding buffer with data from first round*/
|
---|
52 | memcpy(msg+size, data+(n - (modbytes-size)), modbytes-size);
|
---|
53 |
|
---|
54 | BN_bin2bn (msg, modbytes, bn_data);
|
---|
55 | BN_mod_exp (bn_res, bn_data, bn_exp, bn_mod, ctx);
|
---|
56 | n = BN_bn2bin (bn_res, data);
|
---|
57 | if(0x25 !=data[0])
|
---|
58 | ret = -1; /*RSA key is probably wrong*/
|
---|
59 | }
|
---|
60 | else
|
---|
61 | ret = -3; /*wrong size of data for second round*/
|
---|
62 | }
|
---|
63 |
|
---|
64 | if(0 == ret)
|
---|
65 | memcpy(msg, data, n);
|
---|
66 | BN_CTX_free (ctx);
|
---|
67 | }
|
---|
68 | else
|
---|
69 | ret = -2; /*wrong size of data*/
|
---|
70 |
|
---|
71 | return ret;
|
---|
72 | }
|
---|
73 |
|
---|
74 | static time_t chid_date(const uchar *ptr, char *buf, int32_t l)
|
---|
75 | {
|
---|
76 | time_t rc = 0;
|
---|
77 | struct tm timeinfo;
|
---|
78 | memset(&timeinfo, 0, sizeof(struct tm));
|
---|
79 | if (buf){
|
---|
80 | timeinfo.tm_year = 90 + (ptr[1]>>4)+(((ptr[0]>>5)&7)*10);
|
---|
81 | timeinfo.tm_mon = (ptr[1]&0xf) - 1;
|
---|
82 | timeinfo.tm_mday = ptr[0]&0x1f;
|
---|
83 | rc = mktime(&timeinfo);
|
---|
84 | strftime(buf, l, "%Y/%m/%d", &timeinfo);
|
---|
85 | }
|
---|
86 | return(rc);
|
---|
87 | }
|
---|
88 |
|
---|
89 | static int32_t read_record(struct s_reader * reader, const uchar *cmd, const uchar *data, uchar * cta_res)
|
---|
90 | {
|
---|
91 | uint16_t cta_lr;
|
---|
92 | uchar insCA[] = {0xDD, 0xCA, 0x00, 0x00, 0x00};
|
---|
93 |
|
---|
94 | write_cmd(cmd, data); // select record
|
---|
95 | if (cta_res[0]!=0x98)
|
---|
96 | return(-1);
|
---|
97 |
|
---|
98 | insCA[4]=cta_res[1]; // get len
|
---|
99 | write_cmd(insCA, NULL); // read record
|
---|
100 | if ((cta_res[cta_lr-2]!=0x90) || (cta_res[cta_lr-1]))
|
---|
101 | return(-1);
|
---|
102 | return(cta_lr-2);
|
---|
103 | }
|
---|
104 |
|
---|
105 | static uint8_t PairingECMRotation(struct s_reader * reader, const ECM_REQUEST *er, int32_t n)
|
---|
106 | {
|
---|
107 | unsigned char cta_res[CTA_RES_LEN] = {0x00};
|
---|
108 | uchar ins26[] = {0xDD, 0x26, 0x00, 0x00, 0x03, 0x10, 0x01, 0x00};
|
---|
109 | uint8_t cnxcurrecm = 0;
|
---|
110 |
|
---|
111 | if(0x0 != reader->rsa_mod[0] && n > 3 &&
|
---|
112 | 0x54 == er->ecm[n-3] &&
|
---|
113 | 0x02 == er->ecm[n-2] &&
|
---|
114 | 0x00 == er->ecm[n-1])
|
---|
115 | {
|
---|
116 | cnxcurrecm = 1;
|
---|
117 | }
|
---|
118 |
|
---|
119 | if((0 == reader->cnxlastecm) != (0 == cnxcurrecm))
|
---|
120 | {
|
---|
121 | if(0 == cnxcurrecm) // not paired
|
---|
122 | ins26[7] = 0x30;
|
---|
123 | else
|
---|
124 | ins26[7] = 0x40;
|
---|
125 |
|
---|
126 | if(read_record(reader, ins26, ins26+5, cta_res)<=0)
|
---|
127 | rdr_log(reader, "PairingECMRotation - ERROR");
|
---|
128 | }
|
---|
129 | reader->cnxlastecm = cnxcurrecm;
|
---|
130 | return cnxcurrecm;
|
---|
131 | }
|
---|
132 |
|
---|
133 | static int32_t conax_card_init(struct s_reader * reader, ATR *newatr)
|
---|
134 | {
|
---|
135 | unsigned char cta_res[CTA_RES_LEN];
|
---|
136 | int32_t i, j, n;
|
---|
137 | static const uchar ins26[] = {0xDD, 0x26, 0x00, 0x00, 0x03, 0x10, 0x01, 0x40};
|
---|
138 | uchar ins82[] = {0xDD, 0x82, 0x00, 0x00, 0x11, 0x11, 0x0f, 0x01, 0xb0, 0x0f, 0xff, \
|
---|
139 | 0xff, 0xfb, 0x00, 0x00, 0x09, 0x04, 0x0b, 0x00, 0xe0, 0x30, 0x2b };
|
---|
140 |
|
---|
141 | uchar cardver=0;
|
---|
142 |
|
---|
143 | get_hist;
|
---|
144 | if ((hist_size < 4) || (memcmp(hist,"0B00",4)))
|
---|
145 | return ERROR;
|
---|
146 |
|
---|
147 | reader->caid=0xB00;
|
---|
148 |
|
---|
149 | if ((n=read_record(reader, ins26, ins26+5, cta_res))<=0) return ERROR; // read caid, card-version
|
---|
150 |
|
---|
151 | for (i=0; i<n; i+=cta_res[i+1]+2)
|
---|
152 | switch(cta_res[i])
|
---|
153 | {
|
---|
154 | case 0x20: cardver=cta_res[i+2]; break;
|
---|
155 | case 0x28: reader->caid=(cta_res[i+2]<<8)|cta_res[i+3];
|
---|
156 | }
|
---|
157 |
|
---|
158 | // Ins82 command needs to use the correct CAID reported in nano 0x28
|
---|
159 | ins82[17]=(reader->caid>>8)&0xFF;
|
---|
160 | ins82[18]=(reader->caid)&0xFF;
|
---|
161 |
|
---|
162 | if ((n=read_record(reader, ins82, ins82+5, cta_res))<=0) return ERROR; // read serial
|
---|
163 |
|
---|
164 | for (j=0, i=2; i<n; i+=cta_res[i+1]+2)
|
---|
165 | switch(cta_res[i])
|
---|
166 | {
|
---|
167 | case 0x23:
|
---|
168 | if (cta_res[i+5] != 0x00) {
|
---|
169 | memcpy(reader->hexserial, &cta_res[i+3], 6);
|
---|
170 | }
|
---|
171 | else {
|
---|
172 | memcpy(reader->sa[j], &cta_res[i+5], 4);
|
---|
173 | j++;
|
---|
174 | }
|
---|
175 | break;
|
---|
176 | }
|
---|
177 |
|
---|
178 | // we have one provider, 0x0000
|
---|
179 | reader->nprov = 1;
|
---|
180 | memset(reader->prid, 0x00, sizeof(reader->prid));
|
---|
181 |
|
---|
182 | rdr_log_sensitive(reader, "type: Conax, caid: %04X, serial: {%llu}, hex serial: {%02x%02x%02x%02x}, card: v%d",
|
---|
183 | reader->caid, (unsigned long long) b2ll(6, reader->hexserial), reader->hexserial[2],
|
---|
184 | reader->hexserial[3], reader->hexserial[4], reader->hexserial[5], cardver);
|
---|
185 |
|
---|
186 | rdr_log(reader, "Providers: %d", reader->nprov);
|
---|
187 |
|
---|
188 | for (j=0; j<reader->nprov; j++)
|
---|
189 | {
|
---|
190 | rdr_log(reader, "Provider: %d Provider-Id: %06X", j+1, b2i(4, reader->prid[j]));
|
---|
191 | rdr_log(reader, "Provider: %d SharedAddress: %08X", j+1, b2i(4, reader->sa[j]));
|
---|
192 | }
|
---|
193 |
|
---|
194 | return OK;
|
---|
195 | }
|
---|
196 |
|
---|
197 | static int32_t conax_send_pin(struct s_reader * reader)
|
---|
198 | {
|
---|
199 | def_resp;
|
---|
200 | unsigned char insPIN[] = { 0xDD,0xC8,0x00,0x00,0x07,0x1D,0x05,0x01,0x00,0x00,0x00,0x00 }; //Last four are the Pin-Code
|
---|
201 | memcpy(insPIN+8,reader->pincode,4);
|
---|
202 |
|
---|
203 | write_cmd(insPIN, insPIN+5);
|
---|
204 | rdr_debug_mask(reader, D_READER, "Sent pincode to card.");
|
---|
205 |
|
---|
206 | return OK;
|
---|
207 | }
|
---|
208 |
|
---|
209 | static int32_t conax_do_ecm(struct s_reader * reader, const ECM_REQUEST *er, struct s_ecm_answer *ea)
|
---|
210 | {
|
---|
211 | def_resp;
|
---|
212 | int32_t i,j,n,num_dw=0, rc=0;
|
---|
213 | unsigned char insA2[] = { 0xDD,0xA2,0x00,0x00,0x00 };
|
---|
214 | unsigned char insCA[] = { 0xDD,0xCA,0x00,0x00,0x00 };
|
---|
215 |
|
---|
216 | unsigned char exp[] = {0x01, 0x00, 0x01};
|
---|
217 | unsigned char buf[256];
|
---|
218 |
|
---|
219 | if ((n=check_sct_len(er->ecm, 3))<0)
|
---|
220 | return ERROR;
|
---|
221 |
|
---|
222 | buf[0]=0x14;
|
---|
223 | buf[1]=n+1;
|
---|
224 | if(0x0 != PairingECMRotation(reader, er, n))
|
---|
225 | buf[2]=2; // card will answer with encrypted dw
|
---|
226 | else
|
---|
227 | buf[2]=0;
|
---|
228 |
|
---|
229 | memcpy(buf+3, er->ecm, n);
|
---|
230 | insA2[4]=n+3;
|
---|
231 |
|
---|
232 | write_cmd(insA2, buf); // write Header + ECM
|
---|
233 |
|
---|
234 | while ((cta_res[cta_lr-2]==0x98) && // Antwort
|
---|
235 | ((insCA[4]=cta_res[cta_lr-1])>0) && (insCA[4]!=0xFF))
|
---|
236 | {
|
---|
237 | write_cmd(insCA, NULL); //Codeword auslesen
|
---|
238 |
|
---|
239 | if ((cta_res[cta_lr-2]==0x98) ||
|
---|
240 | ((cta_res[cta_lr-2]==0x90) ))
|
---|
241 | {
|
---|
242 | /*checks if answer is encrypted with RSA algo and decrypts it if needed*/
|
---|
243 | if(0x81 == cta_res[0] && 2 == cta_res[2] >> 5) /*81 XX 5X*/
|
---|
244 | {
|
---|
245 | if(0x00 == cta_res[cta_lr-1])
|
---|
246 | rc = RSA_CNX(reader, cta_res, reader->rsa_mod, exp, cta_lr, 64u, 3u);
|
---|
247 | else
|
---|
248 | rc = -4; /*card has no right to decode this channel*/
|
---|
249 | }
|
---|
250 |
|
---|
251 | if(0 == rc)
|
---|
252 | for(i = 0; i < cta_lr-2 && num_dw < 2; i+=cta_res[i+1]+2)
|
---|
253 | {
|
---|
254 | switch (cta_res[i])
|
---|
255 | {
|
---|
256 | case 0x25:
|
---|
257 | if ( (cta_res[i+1]>=0xD) && !((n=cta_res[i+4])&0xFE) )
|
---|
258 | {
|
---|
259 | rc|=(1<<n);
|
---|
260 | memcpy(ea->cw+(n<<3), cta_res+i+7, 8);
|
---|
261 | ++num_dw;
|
---|
262 | }
|
---|
263 | break;
|
---|
264 | case 0x31:
|
---|
265 | if ( (cta_res[i+1]==0x02 && cta_res[i+2]==0x00 && cta_res[i+3]==0x00) || \
|
---|
266 | (cta_res[i+1]==0x02 && cta_res[i+2]==0x40 && cta_res[i+3]==0x00) )
|
---|
267 | break;
|
---|
268 | else if (strcmp(reader->pincode, "none"))
|
---|
269 | {
|
---|
270 | conax_send_pin(reader);
|
---|
271 | write_cmd(insA2, buf); // write Header + ECM
|
---|
272 |
|
---|
273 | while ((cta_res[cta_lr-2]==0x98) && // Antwort
|
---|
274 | ((insCA[4]=cta_res[cta_lr-1])>0) && (insCA[4]!=0xFF))
|
---|
275 | {
|
---|
276 | write_cmd(insCA, NULL); //Codeword auslesen
|
---|
277 |
|
---|
278 | if ((cta_res[cta_lr-2]==0x98) ||
|
---|
279 | ((cta_res[cta_lr-2]==0x90) && (!cta_res[cta_lr-1])))
|
---|
280 | {
|
---|
281 | for(j=0;j<cta_lr-2; j+=cta_res[j+1]+2)
|
---|
282 | if ((cta_res[j]==0x25) && // access: is cw
|
---|
283 | (cta_res[j+1]>=0xD) && // 0xD: 5 header + 8 cw
|
---|
284 | !((n=cta_res[j+4])&0xFE)) // cw idx must be 0 or 1
|
---|
285 | {
|
---|
286 | rc|=(1<<n);
|
---|
287 | memcpy(ea->cw+(n<<3), cta_res+j+7, 8);
|
---|
288 | ++num_dw;
|
---|
289 | }
|
---|
290 | }
|
---|
291 | }
|
---|
292 | }
|
---|
293 | break;
|
---|
294 | }
|
---|
295 | }
|
---|
296 | }
|
---|
297 | }
|
---|
298 |
|
---|
299 | switch(rc)
|
---|
300 | {
|
---|
301 | case -1:
|
---|
302 | rdr_log(reader, "conax decode ECM problem - RSA key is probably faulty");
|
---|
303 | break;
|
---|
304 | case -2:
|
---|
305 | rdr_log(reader, "conax RSA pairing - wrong size of data");
|
---|
306 | break;
|
---|
307 | case -3:
|
---|
308 | rdr_log(reader, "conax RSA pairing- wrong size of data for second round");
|
---|
309 | case -4:
|
---|
310 | rdr_log(reader, "card has no right to decode this channel");
|
---|
311 | break;
|
---|
312 | }
|
---|
313 |
|
---|
314 | /* answer 9011 - conax smart card need reset */
|
---|
315 | if(2<=cta_lr && 0x90==cta_res[cta_lr-2] &&
|
---|
316 | 0x11==cta_res[cta_lr-1])
|
---|
317 | {
|
---|
318 | rdr_log(reader, "conax card hangs - reset is required");
|
---|
319 | reader->card_status = UNKNOWN;
|
---|
320 | }
|
---|
321 |
|
---|
322 | if (rc==3)
|
---|
323 | return OK;
|
---|
324 | else
|
---|
325 | return ERROR;
|
---|
326 | }
|
---|
327 |
|
---|
328 | static int32_t conax_get_emm_type(EMM_PACKET *ep, struct s_reader * rdr)
|
---|
329 | {
|
---|
330 | int32_t i, ok = 0;
|
---|
331 | char tmp_dbg[17];
|
---|
332 |
|
---|
333 | rdr_debug_mask(rdr, D_EMM, "Entered conax_get_emm_type ep->emm[2]=%02x", ep->emm[2]);
|
---|
334 |
|
---|
335 | for (i = 0; i < rdr->nprov; i++) {
|
---|
336 | ok = (!memcmp(&ep->emm[6], rdr->sa[i], 4));
|
---|
337 | if (ok) break;
|
---|
338 | }
|
---|
339 |
|
---|
340 | if (ok) {
|
---|
341 | ep->type = SHARED;
|
---|
342 | memset(ep->hexserial, 0, 8);
|
---|
343 | memcpy(ep->hexserial, &ep->emm[6], 4);
|
---|
344 | rdr_debug_mask_sensitive(rdr, D_EMM, "SHARED, ep->hexserial = {%s}", cs_hexdump(1, ep->hexserial, 8, tmp_dbg, sizeof(tmp_dbg)));
|
---|
345 | return 1;
|
---|
346 | }
|
---|
347 | else {
|
---|
348 | if (!memcmp(&ep->emm[6], rdr->hexserial+2, 4)) {
|
---|
349 | ep->type = UNIQUE;
|
---|
350 | memset(ep->hexserial, 0, 8);
|
---|
351 | memcpy(ep->hexserial+2, &ep->emm[6], 4);
|
---|
352 | rdr_debug_mask_sensitive(rdr, D_EMM, "UNIQUE, ep->hexserial = {%s}", cs_hexdump(1, ep->hexserial, 8, tmp_dbg, sizeof(tmp_dbg)));
|
---|
353 | return 1;
|
---|
354 | }
|
---|
355 | else {
|
---|
356 | ep->type = GLOBAL;
|
---|
357 | rdr_debug_mask(rdr, D_EMM, "GLOBAL");
|
---|
358 | memset(ep->hexserial, 0, 8);
|
---|
359 | return 1;
|
---|
360 | }
|
---|
361 | }
|
---|
362 | }
|
---|
363 |
|
---|
364 | static void conax_get_emm_filter(struct s_reader * rdr, uchar *filter)
|
---|
365 | {
|
---|
366 | int32_t idx = 2;
|
---|
367 |
|
---|
368 | filter[0]=0xFF; //header
|
---|
369 | filter[1]=0; //filter count
|
---|
370 |
|
---|
371 | filter[idx++]=EMM_GLOBAL;
|
---|
372 | filter[idx++]=1; // FIXME: dont see any conax global EMM yet
|
---|
373 | filter[idx+0] = 0x82;
|
---|
374 | filter[idx+0+16] = 0xFF;
|
---|
375 | filter[idx+8] = 0x70;
|
---|
376 | filter[idx+8+16] = 0xFF;
|
---|
377 | filter[1]++;
|
---|
378 | idx += 32;
|
---|
379 |
|
---|
380 | filter[idx++]=EMM_SHARED;
|
---|
381 | filter[idx++]=0;
|
---|
382 | filter[idx+0] = 0x82;
|
---|
383 | filter[idx+0+16] = 0xFF;
|
---|
384 | filter[idx+8] = 0x70;
|
---|
385 | filter[idx+8+16] = 0xFF;
|
---|
386 | memcpy(filter+idx+4, rdr->sa[0], 4);
|
---|
387 | memset(filter+idx+4+16, 0xFF, 4);
|
---|
388 | filter[1]++;
|
---|
389 | idx += 32;
|
---|
390 |
|
---|
391 | filter[idx++]=EMM_UNIQUE;
|
---|
392 | filter[idx++]=0;
|
---|
393 | filter[idx+0] = 0x82;
|
---|
394 | filter[idx+0+16] = 0xFF;
|
---|
395 | filter[idx+8] = 0x70;
|
---|
396 | filter[idx+8+16] = 0xFF;
|
---|
397 | memcpy(filter+idx+4, rdr->hexserial + 2, 4);
|
---|
398 | memset(filter+idx+4+16, 0xFF, 4);
|
---|
399 | filter[1]++;
|
---|
400 |
|
---|
401 | return;
|
---|
402 | }
|
---|
403 |
|
---|
404 | static int32_t conax_do_emm(struct s_reader * reader, EMM_PACKET *ep)
|
---|
405 | {
|
---|
406 | def_resp;
|
---|
407 | unsigned char insCA[] = { 0xDD,0xCA,0x00,0x00,0x00 };
|
---|
408 | unsigned char insEMM[] = { 0xDD,0x84,0x00,0x00,0x00 };
|
---|
409 | unsigned char buf[255];
|
---|
410 | int32_t rc=0;
|
---|
411 |
|
---|
412 | const int32_t l = ep->emm[2];
|
---|
413 |
|
---|
414 | insEMM[4]=l+5;
|
---|
415 | buf[0]=0x12;
|
---|
416 | buf[1]=l+3;
|
---|
417 | memcpy(buf+2, ep->emm, buf[1]);
|
---|
418 | write_cmd(insEMM, buf);
|
---|
419 |
|
---|
420 | if (cta_res[0] == 0x98) {
|
---|
421 | insCA[4] = cta_res[1];
|
---|
422 | write_cmd(insCA, NULL);
|
---|
423 | }
|
---|
424 |
|
---|
425 | rc=((cta_res[0]==0x90)&&(cta_res[1]==0x00));
|
---|
426 |
|
---|
427 | if (rc)
|
---|
428 | return OK;
|
---|
429 | else
|
---|
430 | return ERROR;
|
---|
431 | }
|
---|
432 |
|
---|
433 | static int32_t conax_card_info(struct s_reader * reader)
|
---|
434 | {
|
---|
435 | def_resp;
|
---|
436 | int32_t type, i, j, k=0, n=0, l;
|
---|
437 | uint16_t provid = 0;
|
---|
438 | char provname[32], pdate[32], chid[32];
|
---|
439 | static const uchar insC6[] = {0xDD, 0xC6, 0x00, 0x00, 0x03, 0x1C, 0x01, 0x00};
|
---|
440 | static const uchar ins26[] = {0xDD, 0x26, 0x00, 0x00, 0x03, 0x1C, 0x01, 0x01};
|
---|
441 | uchar insCA[] = {0xDD, 0xCA, 0x00, 0x00, 0x00};
|
---|
442 | char *txt[] = { "Package", "PPV-Event" };
|
---|
443 | static const uchar *cmd[] = { insC6, ins26 };
|
---|
444 | time_t start_t = 0, end_t = 0;
|
---|
445 | uint32_t cxclass = 0;
|
---|
446 |
|
---|
447 | cs_clear_entitlement(reader); // reset the entitlements
|
---|
448 |
|
---|
449 | for (type=0; type<2; type++) {
|
---|
450 | n=0;
|
---|
451 | write_cmd(cmd[type], cmd[type]+5);
|
---|
452 | while (cta_res[cta_lr-2]==0x98) {
|
---|
453 | insCA[4]=cta_res[cta_lr-1]; // get len
|
---|
454 | write_cmd(insCA, NULL); // read
|
---|
455 | if ((cta_res[cta_lr-2]==0x90) || (cta_res[cta_lr-2]==0x98)) {
|
---|
456 | for (j=0; j<cta_lr-2; j+=cta_res[j+1]+2) {
|
---|
457 | provid=(cta_res[j+2+type]<<8) | cta_res[j+3+type];
|
---|
458 | chid[0] = '\0';
|
---|
459 | for (k=0, i=j+4+type; (i<j+cta_res[j+1]); i+=cta_res[i+1]+2) {
|
---|
460 | switch(cta_res[i]) {
|
---|
461 | case 0x01:
|
---|
462 | l=(cta_res[i+1]<(sizeof(provname)-1)) ? cta_res[i+1] : sizeof(provname)-1;
|
---|
463 | memcpy(provname, cta_res+i+2, l);
|
---|
464 | provname[l]='\0';
|
---|
465 | break;
|
---|
466 | case 0x30:
|
---|
467 | if (k > 1) {
|
---|
468 | rdr_log(reader, "%s: %d, id: %04X%s, date: %s - %s, name: %s", txt[type], ++n, provid, chid, pdate, pdate+16, trim(provname));
|
---|
469 |
|
---|
470 | // add entitlements to list
|
---|
471 | cs_add_entitlement(reader, reader->caid, b2ll(4, reader->prid[0]), provid, cxclass, start_t, end_t, type + 1);
|
---|
472 |
|
---|
473 | k = 0;
|
---|
474 | chid[0] = '\0';
|
---|
475 | }
|
---|
476 | if(k == 0) start_t = chid_date(cta_res+i+2, pdate, 15);
|
---|
477 | else end_t = chid_date(cta_res+i+2, pdate+16, 15);
|
---|
478 | ++k;
|
---|
479 | break;
|
---|
480 | case 0x20: // Provider classes
|
---|
481 | case 0x90: // (?) not sure what this is, saw it once in log
|
---|
482 | snprintf(chid, sizeof(chid), ", classes: %02X%02X%02X%02X", cta_res[i+2], cta_res[i+3], cta_res[i+4] ,cta_res[i+5]);
|
---|
483 | cxclass = b2ll(4, &cta_res[i+2]);
|
---|
484 | break;
|
---|
485 | }
|
---|
486 | }
|
---|
487 | rdr_log(reader, "%s: %d, id: %04X%s, date: %s - %s, name: %s", txt[type], ++n, provid, chid, pdate, pdate+16, trim(provname));
|
---|
488 |
|
---|
489 | // add entitlements to list
|
---|
490 | cs_add_entitlement(reader, reader->caid, b2ll(4, reader->prid[0]), provid, cxclass, start_t, end_t, type + 1);
|
---|
491 | }
|
---|
492 | }
|
---|
493 | }
|
---|
494 | }
|
---|
495 | rdr_log(reader, "ready for requests");
|
---|
496 | return OK;
|
---|
497 | }
|
---|
498 |
|
---|
499 | void reader_conax(struct s_cardsystem *ph)
|
---|
500 | {
|
---|
501 | ph->do_emm=conax_do_emm;
|
---|
502 | ph->do_ecm=conax_do_ecm;
|
---|
503 | ph->card_info=conax_card_info;
|
---|
504 | ph->card_init=conax_card_init;
|
---|
505 | ph->get_emm_type=conax_get_emm_type;
|
---|
506 | ph->get_emm_filter=conax_get_emm_filter;
|
---|
507 | ph->caids[0]=0x0B;
|
---|
508 | ph->desc="conax";
|
---|
509 | }
|
---|
510 | #endif
|
---|