Changeset 4994 for trunk/reader-viaccess.c
- Timestamp:
- 04/13/11 23:19:59 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/reader-viaccess.c
r4904 r4994 3 3 4 4 struct via_date { 5 u short day_s : 5;6 u short month_s : 4;7 u short year_s : 7;8 9 u short day_e : 5;10 u short month_e : 4;11 u short year_e : 7;5 uint16_t day_s : 5; 6 uint16_t month_s : 4; 7 uint16_t year_s : 7; 8 9 uint16_t day_e : 5; 10 uint16_t month_e : 4; 11 uint16_t year_e : 7; 12 12 }; 13 13 14 static void parse_via_date(const uchar *buf, struct via_date *vd, int fend)15 { 16 u short date;14 static void parse_via_date(const uchar *buf, struct via_date *vd, int32_t fend) 15 { 16 uint16_t date; 17 17 18 18 date = (buf[0]<<8) | buf[1]; … … 30 30 } 31 31 32 static void show_class(struct s_reader * reader, const char *p, const uchar *b, int l)33 { 34 int i, j;32 static void show_class(struct s_reader * reader, const char *p, const uchar *b, int32_t l) 33 { 34 int32_t i, j; 35 35 36 36 // b -> via date (4 bytes) … … 69 69 /* 70 70 { 71 int i, j, byts;71 int32_t i, j, byts; 72 72 const uchar *oemm; 73 73 … … 117 117 } 118 118 119 static int chk_prov(struct s_reader * reader, uchar *id, uchar keynr)120 { 121 int i, j, rc;119 static int32_t chk_prov(struct s_reader * reader, uchar *id, uchar keynr) 120 { 121 int32_t i, j, rc; 122 122 for (rc=i=0; (!rc) && (i<reader->nprov); i++) 123 123 if(!memcmp(&reader->prid[i][1], id, 3)) … … 128 128 } 129 129 130 static int unlock_parental(struct s_reader * reader)130 static int32_t unlock_parental(struct s_reader * reader) 131 131 { 132 132 /* disabling parental lock. assuming pin "0000" if no pin code is provided in the config */ … … 160 160 } 161 161 162 static int viaccess_card_init(struct s_reader * reader, ATR newatr)162 static int32_t viaccess_card_init(struct s_reader * reader, ATR newatr) 163 163 { 164 164 get_atr; 165 165 def_resp; 166 int i;166 int32_t i; 167 167 uchar buf[256]; 168 168 uchar insac[] = { 0xca, 0xac, 0x00, 0x00, 0x00 }; // select data … … 225 225 memcpy(&reader->prid[i][1], cta_res, 3); 226 226 memcpy(&reader->availkeys[i][0], cta_res+10, 16); 227 snprintf((char *)buf+strlen((char *)buf), sizeof(buf)-strlen((char *)buf), ",%06 lX", b2i(3, &reader->prid[i][1]));227 snprintf((char *)buf+strlen((char *)buf), sizeof(buf)-strlen((char *)buf), ",%06X", b2i(3, &reader->prid[i][1])); 228 228 //cs_log("[viaccess-reader] buf: %s", buf); 229 229 … … 257 257 bool check_crc( uchar *data ) 258 258 { 259 int valid = 0;259 int32_t valid = 0; 260 260 261 261 uchar sum1=data[0] + data[1] + data[2] ; … … 270 270 } 271 271 272 static int viaccess_do_ecm(struct s_reader * reader, ECM_REQUEST *er)272 static int32_t viaccess_do_ecm(struct s_reader * reader, ECM_REQUEST *er) 273 273 { 274 274 def_resp; … … 279 279 280 280 uchar *ecm88Data=er->ecm+4; //XXX what is the 4th byte for ?? 281 int ecm88Len=SCT_LEN(er->ecm)-4;282 u longprovid=0;283 int rc=0;284 int hasD2 = 0;285 int curEcm88len=0;286 int nanoLen=0;281 int32_t ecm88Len=SCT_LEN(er->ecm)-4; 282 uint32_t provid=0; 283 int32_t rc=0; 284 int32_t hasD2 = 0; 285 int32_t curEcm88len=0; 286 int32_t nanoLen=0; 287 287 uchar *nextEcm; 288 288 uchar DE04[256]; 289 int D2KeyID=0;290 int curnumber_ecm=0;289 int32_t D2KeyID=0; 290 int32_t curnumber_ecm=0; 291 291 //nanoD2 d2 02 0d 02 -> D2 nano, len 2 292 292 // 0d -> post AES decrypt CW 293 293 // 0b -> pre AES decrypt CW 294 int nanoD2 = 0; // 0x0b = 1 0x0d = 2294 int32_t nanoD2 = 0; // 0x0b = 1 0x0d = 2 295 295 296 296 memset(DE04, 0, sizeof(DE04)); //fix dorcel de04 bug … … 332 332 } 333 333 // use the d2 arguments to get the key # to be used 334 int len = ecm88Data[1] + 2;334 int32_t len = ecm88Data[1] + 2; 335 335 D2KeyID=ecm88Data[3]; 336 336 ecm88Data += len; … … 350 350 uchar ident[3], keynr; 351 351 uchar *ecmf8Data=0; 352 int ecmf8Len=0;352 int32_t ecmf8Len=0; 353 353 354 354 nanoLen=ecm88Data[1] + 2; … … 387 387 // check that we have the AES key to decode the CW 388 388 // if not there is no need to send the ecm to the card 389 if(!aes_present(reader->aes_list, 0x500, (uint32 ) (provid & 0xFFFFF0) , D2KeyID))389 if(!aes_present(reader->aes_list, 0x500, (uint32_t) (provid & 0xFFFFF0) , D2KeyID)) 390 390 return ERROR; 391 391 } … … 423 423 { 424 424 uchar *ecm88DataCW = ecm88Data; 425 int cwStart = 0;426 //int cwStartRes = 0;427 int exit = 0;425 int32_t cwStart = 0; 426 //int32_t cwStartRes = 0; 427 int32_t exit = 0; 428 428 // find CW start 429 429 while(cwStart < curEcm88len -1 && !exit) … … 438 438 // use AES from list to decrypt CW 439 439 cs_debug_mask(D_READER, "Decoding CW : using AES key id %d for provider %06x",D2KeyID, (provid & 0xFFFFF0)); 440 if (aes_decrypt_from_list(reader->aes_list,0x500, (uint32 ) (provid & 0xFFFFF0), D2KeyID, &ecm88DataCW[0], 16) == 0)441 snprintf( er->msglog, MSGLOGSIZE, "AES Decrypt : key id %d not found for CAID %04X , provider %06 lx", D2KeyID, 0x500, (provid & 0xFFFFF0) );440 if (aes_decrypt_from_list(reader->aes_list,0x500, (uint32_t) (provid & 0xFFFFF0), D2KeyID, &ecm88DataCW[0], 16) == 0) 441 snprintf( er->msglog, MSGLOGSIZE, "AES Decrypt : key id %d not found for CAID %04X , provider %06x", D2KeyID, 0x500, (provid & 0xFFFFF0) ); 442 442 } 443 443 444 444 while(ecm88Len>0 && ecm88Data[0]<0xA0) 445 445 { 446 int nanoLen=ecm88Data[1]+2;446 int32_t nanoLen=ecm88Data[1]+2; 447 447 if (!ecmf8Data) 448 448 ecmf8Data=(uchar *)ecm88Data; … … 511 511 if ( hasD2 && !check_crc(er->cw) && nanoD2 == 2) { 512 512 cs_debug_mask(D_READER, "Decoding CW : using AES key id %d for provider %06x",D2KeyID, (provid & 0xFFFFF0)); 513 rc=aes_decrypt_from_list(reader->aes_list,0x500, (uint32 ) (provid & 0xFFFFF0), D2KeyID,er->cw, 16);513 rc=aes_decrypt_from_list(reader->aes_list,0x500, (uint32_t) (provid & 0xFFFFF0), D2KeyID,er->cw, 16); 514 514 if( rc == 0 ) 515 snprintf( er->msglog, MSGLOGSIZE, "AES Decrypt : key id %d not found for CAID %04X , provider %06 lx", D2KeyID, 0x500, (provid & 0xFFFFF0) );515 snprintf( er->msglog, MSGLOGSIZE, "AES Decrypt : key id %d not found for CAID %04X , provider %06x", D2KeyID, 0x500, (provid & 0xFFFFF0) ); 516 516 } 517 517 … … 519 519 } 520 520 521 static int viaccess_get_emm_type(EMM_PACKET *ep, struct s_reader * rdr)522 { 523 u longprovid=0;521 static int32_t viaccess_get_emm_type(EMM_PACKET *ep, struct s_reader * rdr) 522 { 523 uint32_t provid=0; 524 524 cs_debug_mask(D_EMM, "Entered viaccess_get_emm_type ep->emm[0]=%02x",ep->emm[0]); 525 525 … … 565 565 static void viaccess_get_emm_filter(struct s_reader * rdr, uchar *filter) 566 566 { 567 int idx = 2;567 int32_t idx = 2; 568 568 569 569 filter[0]=0xFF; … … 600 600 } 601 601 602 static int viaccess_do_emm(struct s_reader * reader, EMM_PACKET *ep)602 static int32_t viaccess_do_emm(struct s_reader * reader, EMM_PACKET *ep) 603 603 { 604 604 def_resp; … … 611 611 // static const unsigned char insc8Data[] = { 0x00,0x00 }; // data for read extended status 612 612 613 int emmdatastart=7;613 int32_t emmdatastart=7; 614 614 if (ep->type == UNIQUE) emmdatastart++; 615 int emmLen=SCT_LEN(ep->emm)-emmdatastart;616 int rc=0;615 int32_t emmLen=SCT_LEN(ep->emm)-emmdatastart; 616 int32_t rc=0; 617 617 618 618 ///cs_dump(ep->emm, emmLen+emmdatastart, "RECEIVED EMM VIACCESS"); 619 619 620 int emmUpToEnd;620 int32_t emmUpToEnd; 621 621 uchar *emmParsed = ep->emm+emmdatastart; 622 int provider_ok = 0;623 u nsigned int emm_provid;622 int32_t provider_ok = 0; 623 uint32_t emm_provid; 624 624 uchar keynr = 0; 625 int ins18Len = 0;625 int32_t ins18Len = 0; 626 626 uchar ins18Data[512]; 627 627 uchar insData[512]; … … 826 826 } 827 827 828 static int viaccess_card_info(struct s_reader * reader)828 static int32_t viaccess_card_info(struct s_reader * reader) 829 829 { 830 830 def_resp; 831 int i, l, scls, show_cls;831 int32_t i, l, scls, show_cls; 832 832 uchar insac[] = { 0xca, 0xac, 0x00, 0x00, 0x00 }; // select data 833 833 uchar insb8[] = { 0xca, 0xb8, 0x00, 0x00, 0x00 }; // read selected data … … 857 857 for (i=1; (cta_res[cta_lr-2]==0x90) && (cta_res[cta_lr-1]==0); i++) 858 858 { 859 u longl_provid, l_sa;859 uint32_t l_provid, l_sa; 860 860 uchar l_name[64]; 861 861 insc0[4]=0x1a; write_cmd(insc0, NULL); // show provider properties … … 895 895 if( (cta_res[cta_lr-2]==0x90) && (cta_res[cta_lr-1]==0) ) 896 896 { 897 int fshow;897 int32_t fshow; 898 898 l=cta_res[1]; 899 899 //fshow=(client[cs_idx].dbglvl==D_DUMP)?1:(scls < show_cls)?1:0; … … 918 918 919 919 #ifdef HAVE_DVBAPI 920 void dvbapi_sort_nanos(unsigned char *dest, const unsigned char *src, int len);921 922 int viaccess_reassemble_emm(uchar *buffer, uint *len) {920 void dvbapi_sort_nanos(unsigned char *dest, const unsigned char *src, int32_t len); 921 922 int32_t viaccess_reassemble_emm(uchar *buffer, uint32_t *len) { 923 923 static uchar emm_global[512]; 924 static int emm_global_len = 0;925 926 int pos=0, i;927 uint k;924 static int32_t emm_global_len = 0; 925 926 int32_t pos=0, i; 927 uint32_t k; 928 928 929 929 // Viaccess
Note:
See TracChangeset
for help on using the changeset viewer.