Changeset 1345
- Timestamp:
- 01/22/10 17:43:59 (14 years ago)
- Location:
- branches/smartreader
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/smartreader/reader-nagra.c
r1336 r1345 35 35 #define SYSTEM_MASK 0xFF00 36 36 37 unsigned char XorSum(const unsigned char *mem, int len) 37 //unsigned char XorSum(const unsigned char *mem, int len) 38 unsigned char XorSum(unsigned char *mem, int len) 38 39 { 39 40 unsigned char cs; … … 47 48 } 48 49 49 static time_t tier_date(ulong date, char *buf, int l) 50 //static time_t tier_date(ulong date, char *buf, int l) 51 time_t tier_date(ulong date, char *buf, int l) 50 52 { 51 53 time_t ut=870393600L+date*(24*3600); … … 70 72 int msglen=ilen+6; 71 73 unsigned char msg[msglen]; 72 staticchar nagra_head[] = {0xA0, 0xCA, 0x00, 0x00};74 unsigned char nagra_head[] = {0xA0, 0xCA, 0x00, 0x00}; 73 75 74 76 memset(msg, 0, msglen); … … 141 143 } 142 144 143 void Signature(unsigned char *sig, const unsigned char *vkey,const unsigned char *msg, int len) 145 void Signature(unsigned char *sig, unsigned char *vkey,unsigned char *msg, int len) 146 //void Signature(unsigned char *sig, const unsigned char *vkey,const unsigned char *msg, int len) 144 147 { 145 148 IDEA_KEY_SCHEDULE ks; -
branches/smartreader/reader-videoguard2.c
r1337 r1345 16 16 AES_KEY dkey, ekey; 17 17 int BASEYEAR = 1997; 18 staticvoid cAES_SetKey(const unsigned char *key)18 void cAES_SetKey(const unsigned char *key) 19 19 { 20 20 AES_set_decrypt_key(key,128,&dkey); … … 23 23 } 24 24 25 staticint cAES_Encrypt(const unsigned char *data, int len, unsigned char *crypt)25 int cAES_Encrypt(const unsigned char *data, int len, unsigned char *crypt) 26 26 { 27 27 if(aes_active) { … … 34 34 } 35 35 36 staticint cw_is_valid(unsigned char *cw) //returns 1 if cw_is_valid, returns 0 if cw is all zeros36 int cw_is_valid(unsigned char *cw) //returns 1 if cw_is_valid, returns 0 if cw is all zeros 37 37 { 38 38 int i; … … 54 54 return; 55 55 #if __BYTE_ORDER == __BIG_ENDIAN 56 staticunsigned char Tb1[0xC]={0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,0xF8,0x61,0xCB,0x52};57 staticunsigned char Tb2[0x40]= {56 unsigned char Tb1[0xC]={0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,0xF8,0x61,0xCB,0x52}; 57 unsigned char Tb2[0x40]= { 58 58 0xC5,0x39,0xF5,0xB9,0x90,0x99,0x01,0x3A,0xD4,0xB9,0x6A,0xB5,0xEA,0x67,0x7E,0xB4, 59 59 0x6C,0x30,0x4B,0xF0,0xB8,0x10,0xB0,0xB5,0xB7,0x6D,0xA7,0x51,0x1A,0xE7,0x14,0xCA, … … 62 62 }; 63 63 #else 64 staticunsigned char Tb1[0xC]={0x23,0x01,0x67,0x45,0xAB,0x89,0xEF,0xCD,0x61,0xF8,0x52,0xCB};65 staticunsigned char Tb2[0x40]= {64 unsigned char Tb1[0xC]={0x23,0x01,0x67,0x45,0xAB,0x89,0xEF,0xCD,0x61,0xF8,0x52,0xCB}; 65 unsigned char Tb2[0x40]= { 66 66 0x39,0xC5,0xB9,0xF5,0x99,0x90,0x3A,0x01,0xB9,0xD4,0xB5,0x6A,0x67,0xEA,0xB4,0x7E, 67 67 0x30,0x6C,0xF0,0x4B,0x10,0xB8,0xB5,0xB0,0x6D,0xB7,0x51,0xA7,0xE7,0x1A,0xCA,0x14, … … 139 139 ////// ==================================================================================== 140 140 141 staticvoid swap_lb (unsigned char *buff, int len)141 void swap_lb (unsigned char *buff, int len) 142 142 { 143 143 … … 154 154 } 155 155 156 staticinline void __xxor(unsigned char *data, int len, const unsigned char *v1, const unsigned char *v2)156 inline void __xxor(unsigned char *data, int len, const unsigned char *v1, const unsigned char *v2) 157 157 { 158 158 switch(len) { // looks ugly, but the compiler can optimize it very well ;) … … 176 176 unsigned char stateD3A[16]; 177 177 178 staticvoid cCamCryptVG2_LongMult(unsigned short *pData, unsigned short *pLen, unsigned int mult, unsigned int carry);179 staticvoid cCamCryptVG2_PartialMod(unsigned short val, unsigned int count, unsigned short *outkey, const unsigned short *inkey);180 staticvoid cCamCryptVG2_RotateRightAndHash(unsigned char *p);181 staticvoid cCamCryptVG2_Reorder16A(unsigned char *dest, const unsigned char *src);182 staticvoid cCamCryptVG2_ReorderAndEncrypt(unsigned char *p);183 staticvoid cCamCryptVG2_Process_D0(const unsigned char *ins, unsigned char *data);184 staticvoid cCamCryptVG2_Process_D1(const unsigned char *ins, unsigned char *data, const unsigned char *status);185 staticvoid cCamCryptVG2_Decrypt_D3(unsigned char *ins, unsigned char *data, const unsigned char *status);186 staticvoid cCamCryptVG2_PostProcess_Decrypt(unsigned char *buff, int len, unsigned char *cw1, unsigned char *cw2);187 staticvoid cCamCryptVG2_SetSeed(unsigned char *Key1, unsigned char *Key2);188 staticvoid cCamCryptVG2_GetCamKey(unsigned char *buff);189 190 staticvoid cCamCryptVG2_SetSeed(unsigned char *Key1, unsigned char *Key2)178 void cCamCryptVG2_LongMult(unsigned short *pData, unsigned short *pLen, unsigned int mult, unsigned int carry); 179 void cCamCryptVG2_PartialMod(unsigned short val, unsigned int count, unsigned short *outkey, const unsigned short *inkey); 180 void cCamCryptVG2_RotateRightAndHash(unsigned char *p); 181 void cCamCryptVG2_Reorder16A(unsigned char *dest, const unsigned char *src); 182 void cCamCryptVG2_ReorderAndEncrypt(unsigned char *p); 183 void cCamCryptVG2_Process_D0(const unsigned char *ins, unsigned char *data); 184 void cCamCryptVG2_Process_D1(const unsigned char *ins, unsigned char *data, const unsigned char *status); 185 void cCamCryptVG2_Decrypt_D3(unsigned char *ins, unsigned char *data, const unsigned char *status); 186 void cCamCryptVG2_PostProcess_Decrypt(unsigned char *buff, int len, unsigned char *cw1, unsigned char *cw2); 187 void cCamCryptVG2_SetSeed(unsigned char *Key1, unsigned char *Key2); 188 void cCamCryptVG2_GetCamKey(unsigned char *buff); 189 190 void cCamCryptVG2_SetSeed(unsigned char *Key1, unsigned char *Key2) 191 191 { 192 192 swap_lb (Key1, 64); … … 198 198 } 199 199 200 staticvoid cCamCryptVG2_GetCamKey(unsigned char *buff)200 void cCamCryptVG2_GetCamKey(unsigned char *buff) 201 201 { 202 202 unsigned short *tb2=(unsigned short *)buff, c=1; … … 208 208 } 209 209 210 staticvoid cCamCryptVG2_PostProcess_Decrypt(unsigned char *buff, int len, unsigned char *cw1, unsigned char *cw2)210 void cCamCryptVG2_PostProcess_Decrypt(unsigned char *buff, int len, unsigned char *cw1, unsigned char *cw2) 211 211 { 212 212 switch(buff[0]) { … … 237 237 } 238 238 239 staticvoid cCamCryptVG2_Process_D0(const unsigned char *ins, unsigned char *data)239 void cCamCryptVG2_Process_D0(const unsigned char *ins, unsigned char *data) 240 240 { 241 241 switch(ins[1]) { … … 279 279 } 280 280 281 staticvoid cCamCryptVG2_Process_D1(const unsigned char *ins, unsigned char *data, const unsigned char *status)281 void cCamCryptVG2_Process_D1(const unsigned char *ins, unsigned char *data, const unsigned char *status) 282 282 { 283 283 unsigned char iter[16], tmp[16]; … … 316 316 } 317 317 318 staticvoid cCamCryptVG2_Decrypt_D3(unsigned char *ins, unsigned char *data, const unsigned char *status)318 void cCamCryptVG2_Decrypt_D3(unsigned char *ins, unsigned char *data, const unsigned char *status) 319 319 { 320 320 if(ins[4]>16) ins[4]-=16; … … 360 360 } 361 361 362 staticvoid cCamCryptVG2_ReorderAndEncrypt(unsigned char *p)362 void cCamCryptVG2_ReorderAndEncrypt(unsigned char *p) 363 363 { 364 364 unsigned char tmp[16]; … … 370 370 // reorder AAAABBBBCCCCDDDD to ABCDABCDABCDABCD 371 371 372 staticvoid cCamCryptVG2_Reorder16A(unsigned char *dest, const unsigned char *src)372 void cCamCryptVG2_Reorder16A(unsigned char *dest, const unsigned char *src) 373 373 { 374 374 int i; … … 380 380 } 381 381 382 staticvoid cCamCryptVG2_LongMult(unsigned short *pData, unsigned short *pLen, unsigned int mult, unsigned int carry)382 void cCamCryptVG2_LongMult(unsigned short *pData, unsigned short *pLen, unsigned int mult, unsigned int carry) 383 383 { 384 384 int i; … … 391 391 } 392 392 393 staticvoid cCamCryptVG2_PartialMod(unsigned short val, unsigned int count, unsigned short *outkey, const unsigned short *inkey)393 void cCamCryptVG2_PartialMod(unsigned short val, unsigned int count, unsigned short *outkey, const unsigned short *inkey) 394 394 { 395 395 if(count) { … … 411 411 } 412 412 413 staticconst unsigned char table1[256] = {413 const unsigned char table1[256] = { 414 414 0x63,0x7c,0x77,0x7b,0xf2,0x6b,0x6f,0xc5, 0x30,0x01,0x67,0x2b,0xfe,0xd7,0xab,0x76, 415 415 0xca,0x82,0xc9,0x7d,0xfa,0x59,0x47,0xf0, 0xad,0xd4,0xa2,0xaf,0x9c,0xa4,0x72,0xc0, … … 430 430 }; 431 431 432 staticvoid cCamCryptVG2_RotateRightAndHash(unsigned char *p)432 void cCamCryptVG2_RotateRightAndHash(unsigned char *p) 433 433 { 434 434 unsigned char t1=p[15]; … … 442 442 ////// ==================================================================================== 443 443 444 staticunsigned char CW1[8], CW2[8];444 unsigned char CW1[8], CW2[8]; 445 445 446 446 extern uchar cta_cmd[], cta_res[]; … … 483 483 } 484 484 485 staticint status_ok(const unsigned char *status){485 int status_ok(const unsigned char *status){ 486 486 //cs_log("check status %02x%02x", status[0],status[1]); 487 487 return (status[0] == 0x90 || status[0] == 0x91) … … 495 495 #define read_cmd(cmd, data) (card_write(cmd, NULL) == 0) 496 496 497 staticint read_cmd_len(const unsigned char *cmd)497 int read_cmd_len(const unsigned char *cmd) 498 498 { 499 499 unsigned char cmd2[5]; … … 508 508 } 509 509 510 static intdo_cmd(const unsigned char *ins, const unsigned char *txbuff, unsigned char *rxbuff)510 int videoguard2_do_cmd(const unsigned char *ins, const unsigned char *txbuff, unsigned char *rxbuff) 511 511 { 512 512 unsigned char ins2[5]; … … 548 548 } 549 549 550 staticvoid rev_date_calc(const unsigned char *Date, int *year, int *mon, int *day, int *hh, int *mm, int *ss)550 void rev_date_calc(const unsigned char *Date, int *year, int *mon, int *day, int *hh, int *mm, int *ss) 551 551 { 552 552 *year=(Date[0]/12)+BASEYEAR; … … 558 558 } 559 559 560 staticvoid read_tiers(void)561 { 562 staticconst unsigned char ins2a[5] = { 0xd0,0x2a,0x00,0x00,0x00 };560 void read_tiers(void) 561 { 562 const unsigned char ins2a[5] = { 0xd0,0x2a,0x00,0x00,0x00 }; 563 563 int l; 564 l= do_cmd(ins2a,NULL,NULL);564 l=videoguard2_do_cmd(ins2a,NULL,NULL); 565 565 if(l<0 || !status_ok(cta_res+l)) return; 566 staticunsigned char ins76[5] = { 0xd0,0x76,0x00,0x00,0x00 };566 unsigned char ins76[5] = { 0xd0,0x76,0x00,0x00,0x00 }; 567 567 ins76[3]=0x7f; ins76[4]=2; 568 568 if(!read_cmd(ins76,NULL) || !status_ok(cta_res+2)) return; … … 572 572 for(i=0; i<num; i++) { 573 573 ins76[2]=i; 574 l= do_cmd(ins76,NULL,NULL);574 l=videoguard2_do_cmd(ins76,NULL,NULL); 575 575 if(l<0 || !status_ok(cta_res+l)) return; 576 576 if(cta_res[2]==0 && cta_res[3]==0) break; … … 667 667 668 668 unsigned char ins7416[5] = { 0xD0,0x74,0x16,0x00,0x00 }; 669 if( do_cmd(ins7416, NULL, NULL)<0) {669 if(videoguard2_do_cmd(ins7416, NULL, NULL)<0) { 670 670 cs_log ("cmd 7416 failed"); 671 671 return 0; … … 684 684 /* we can try to get the boxid from the card */ 685 685 int boxidOK=0; 686 l= do_cmd(ins36, NULL, buff);686 l=videoguard2_do_cmd(ins36, NULL, buff); 687 687 if(l>=0) { 688 688 int i; … … 712 712 //short int SWIRDstatus = cta_res[1]; 713 713 unsigned char ins58[5] = { 0xD0,0x58,0x00,0x00,0x00 }; 714 l= do_cmd(ins58, NULL, buff);714 l=videoguard2_do_cmd(ins58, NULL, buff); 715 715 if(l<0) { 716 716 cs_log("cmd ins58 failed"); … … 749 749 unsigned char tbuff[64]; 750 750 cCamCryptVG2_GetCamKey(tbuff); 751 l= do_cmd(insB4, tbuff, NULL);751 l=videoguard2_do_cmd(insB4, tbuff, NULL); 752 752 if(l<0 || !status_ok(cta_res)) { 753 753 cs_log ("cmd D0B4 failed (%02X%02X)", cta_res[0], cta_res[1]); … … 756 756 757 757 unsigned char insBC[5] = { 0xD0,0xBC,0x00,0x00,0x00 }; 758 l= do_cmd(insBC, NULL, NULL);758 l=videoguard2_do_cmd(insBC, NULL, NULL); 759 759 if(l<0) { 760 760 cs_log("cmd D0BC failed"); … … 763 763 764 764 unsigned char insBE[5] = { 0xD3,0xBE,0x00,0x00,0x00 }; 765 l= do_cmd(insBE, NULL, NULL);765 l=videoguard2_do_cmd(insBE, NULL, NULL); 766 766 if(l<0) { 767 767 cs_log("cmd D3BE failed"); … … 770 770 771 771 unsigned char ins58a[5] = { 0xD1,0x58,0x00,0x00,0x00 }; 772 l= do_cmd(ins58a, NULL, NULL);772 l=videoguard2_do_cmd(ins58a, NULL, NULL); 773 773 if(l<0) { 774 774 cs_log("cmd D158 failed"); … … 777 777 778 778 unsigned char ins4Ca[5] = { 0xD1,0x4C,0x00,0x00,0x00 }; 779 l= do_cmd(ins4Ca,payload4C, NULL);779 l=videoguard2_do_cmd(ins4Ca,payload4C, NULL); 780 780 if(l<0 || !status_ok(cta_res)) { 781 781 cs_log("cmd D14Ca failed"); … … 797 797 int videoguard_do_ecm(ECM_REQUEST *er) 798 798 { 799 staticunsigned char ins40[5] = { 0xD1,0x40,0x00,0x80,0xFF };800 staticconst unsigned char ins54[5] = { 0xD3,0x54,0x00,0x00,0x00};799 unsigned char ins40[5] = { 0xD1,0x40,0x00,0x80,0xFF }; 800 const unsigned char ins54[5] = { 0xD3,0x54,0x00,0x00,0x00}; 801 801 int posECMpart2=er->ecm[6]+7; 802 802 int lenECMpart2=er->ecm[posECMpart2]+1; … … 806 806 ins40[4]=lenECMpart2; 807 807 int l; 808 l = do_cmd(ins40,tbuff,NULL);808 l = videoguard2_do_cmd(ins40,tbuff,NULL); 809 809 if(l>0 && status_ok(cta_res)) { 810 l = do_cmd(ins54,NULL,NULL);810 l = videoguard2_do_cmd(ins54,NULL,NULL); 811 811 if(l>0 && status_ok(cta_res+l)) { 812 812 if (!cw_is_valid(CW1)) //sky cards report 90 00 = ok but send cw = 00 when channel not subscribed … … 842 842 } 843 843 844 staticint num_addr(const unsigned char *data)844 int num_addr(const unsigned char *data) 845 845 { 846 846 return ((data[3]&0x30)>>4)+1; 847 847 } 848 848 849 staticint addr_mode(const unsigned char *data)849 int addr_mode(const unsigned char *data) 850 850 { 851 851 switch(data[3]&0xC0) { … … 856 856 } 857 857 858 staticconst unsigned char * payload_addr(const unsigned char *data, const unsigned char *a)858 const unsigned char * payload_addr(const unsigned char *data, const unsigned char *a) 859 859 { 860 860 int s; … … 920 920 if (payload) { 921 921 ins42[4]=*payload; 922 int l = do_cmd(ins42,payload+1,NULL);922 int l = videoguard2_do_cmd(ins42,payload+1,NULL); 923 923 if(l>0 && status_ok(cta_res)) { 924 924 rc=1;
Note:
See TracChangeset
for help on using the changeset viewer.