Changeset 4994 for trunk/module-cccam.c
- Timestamp:
- 04/13/11 23:19:59 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/module-cccam.c
r4991 r4994 15 15 const char *cmd0c_mode_name[] = { "NONE", "RC6", "RC4", "CC_CRYPT", "AES", "IDEA" }; 16 16 17 static uint8 cc_node_id[8];17 static uint8_t cc_node_id[8]; 18 18 19 19 #define getprefix() ((struct cc_data *)(cl->cc))->prefix 20 20 21 void cc_init_crypt(struct cc_crypt_block *block, uint8 *key, int len) {22 int i = 0;23 uint8 j = 0;21 void cc_init_crypt(struct cc_crypt_block *block, uint8_t *key, int32_t len) { 22 int32_t i = 0; 23 uint8_t j = 0; 24 24 25 25 for (i = 0; i < 256; i++) { … … 37 37 } 38 38 39 void cc_crypt(struct cc_crypt_block *block, uint8 *data, int len,39 void cc_crypt(struct cc_crypt_block *block, uint8_t *data, int32_t len, 40 40 cc_crypt_mode_t mode) { 41 int i;42 uint8 z;41 int32_t i; 42 uint8_t z; 43 43 44 44 for (i = 0; i < len; i++) { … … 56 56 } 57 57 58 void cc_rc4_crypt(struct cc_crypt_block *block, uint8 *data, int len,58 void cc_rc4_crypt(struct cc_crypt_block *block, uint8_t *data, int32_t len, 59 59 cc_crypt_mode_t mode) { 60 int i;61 uint8 z;60 int32_t i; 61 uint8_t z; 62 62 63 63 for (i = 0; i < len; i++) { … … 74 74 } 75 75 76 void cc_xor(uint8 *buf) {76 void cc_xor(uint8_t *buf) { 77 77 const char cccam[] = "CCcam"; 78 uint8 i;78 uint8_t i; 79 79 80 80 for (i = 0; i < 8; i++) { … … 86 86 } 87 87 88 void cc_cw_crypt(struct s_client *cl, uint8 *cws, uint32cardid) {88 void cc_cw_crypt(struct s_client *cl, uint8_t *cws, uint32_t cardid) { 89 89 struct cc_data *cc = cl->cc; 90 int64 node_id;91 uint8 tmp;92 int i;90 int64_t node_id; 91 uint8_t tmp; 92 int32_t i; 93 93 94 94 if (cl->typ != 'c') { … … 107 107 108 108 /** swap endianness (int) */ 109 static void SwapLBi(unsigned char *buff, int len)109 static void SwapLBi(unsigned char *buff, int32_t len) 110 110 { 111 111 #if __BYTE_ORDER != __BIG_ENDIAN … … 113 113 #endif 114 114 115 int i;115 int32_t i; 116 116 unsigned char swap[4]; 117 117 for (i = 0; i < len / 4; i++) { … … 125 125 } 126 126 127 void cc_crypt_cmd0c(struct s_client *cl, uint8 *buf, int len) {127 void cc_crypt_cmd0c(struct s_client *cl, uint8_t *buf, int32_t len) { 128 128 struct cc_data *cc = cl->cc; 129 uint8 *out = cs_malloc(&out, len, QUITERROR);129 uint8_t *out = cs_malloc(&out, len, QUITERROR); 130 130 131 131 switch (cc->cmd0c_mode) { … … 135 135 } 136 136 case MODE_CMD_0x0C_RC6 : { //RC6 137 int i;137 int32_t i; 138 138 SwapLBi(buf, len); 139 139 for (i = 0; i < len / 16; i++) 140 rc6_block_decrypt((u nsigned int*)(buf+i*16), (unsigned int*)(out+i*16), 1, cc->cmd0c_RC6_cryptkey);140 rc6_block_decrypt((uint32_t*)(buf+i*16), (uint32_t*)(out+i*16), 1, cc->cmd0c_RC6_cryptkey); 141 141 SwapLBi(out, len); 142 142 break; … … 153 153 } 154 154 case MODE_CMD_0x0C_AES: { // AES 155 int i;155 int32_t i; 156 156 for (i = 0; i<len / 16; i++) 157 157 AES_decrypt((unsigned char *) buf + i * 16, … … 160 160 } 161 161 case MODE_CMD_0x0C_IDEA : { //IDEA 162 int i=0;163 int j;162 int32_t i=0; 163 int32_t j; 164 164 165 165 while (i < len) { … … 184 184 185 185 186 void set_cmd0c_cryptkey(struct s_client *cl, uint8 *key, uint8len) {186 void set_cmd0c_cryptkey(struct s_client *cl, uint8_t *key, uint8_t len) { 187 187 struct cc_data *cc = cl->cc; 188 uint8 key_buf[32];188 uint8_t key_buf[32]; 189 189 190 190 memset(&key_buf, 0, sizeof(key_buf)); … … 219 219 220 220 case MODE_CMD_0x0C_IDEA : { //IDEA 221 uint8 key_buf_idea[16];221 uint8_t key_buf_idea[16]; 222 222 memcpy(key_buf_idea, key_buf, 16); 223 223 IDEA_KEY_SCHEDULE ekey; … … 230 230 } 231 231 232 int sid_eq(struct cc_srvid *srvid1, struct cc_srvid *srvid2) {232 int32_t sid_eq(struct cc_srvid *srvid1, struct cc_srvid *srvid2) { 233 233 return (srvid1->sid == srvid2->sid && (srvid1->ecmlen == srvid2->ecmlen || !srvid1->ecmlen || !srvid2->ecmlen)); 234 234 } 235 235 236 int is_sid_blocked(struct cc_card *card, struct cc_srvid *srvid_blocked) {236 int32_t is_sid_blocked(struct cc_card *card, struct cc_srvid *srvid_blocked) { 237 237 LL_ITER *it = ll_iter_create(card->badsids); 238 238 struct cc_srvid *srvid; … … 246 246 } 247 247 248 int is_good_sid(struct cc_card *card, struct cc_srvid *srvid_good) {248 int32_t is_good_sid(struct cc_card *card, struct cc_srvid *srvid_good) { 249 249 LL_ITER *it = ll_iter_create(card->goodsids); 250 250 struct cc_srvid *srvid; … … 306 306 * clears and frees values for reinit 307 307 */ 308 void cc_cli_close(struct s_client *cl, int call_conclose) {308 void cc_cli_close(struct s_client *cl, int32_t call_conclose) { 309 309 struct s_reader *rdr = cl->reader; 310 310 struct cc_data *cc = cl->cc; … … 331 331 332 332 struct cc_extended_ecm_idx *add_extended_ecm_idx(struct s_client *cl, 333 uint8 send_idx, ushort ecm_idx, struct cc_card *card,333 uint8_t send_idx, uint16_t ecm_idx, struct cc_card *card, 334 334 struct cc_srvid srvid) { 335 335 struct cc_data *cc = cl->cc; … … 346 346 347 347 struct cc_extended_ecm_idx *get_extended_ecm_idx(struct s_client *cl, 348 uint8 send_idx, int remove) {348 uint8_t send_idx, int32_t remove) { 349 349 struct cc_data *cc = cl->cc; 350 350 struct cc_extended_ecm_idx *eei; … … 367 367 368 368 struct cc_extended_ecm_idx *get_extended_ecm_idx_by_idx(struct s_client *cl, 369 u short ecm_idx, int remove) {369 uint16_t ecm_idx, int32_t remove) { 370 370 struct cc_data *cc = cl->cc; 371 371 struct cc_extended_ecm_idx *eei; … … 387 387 } 388 388 389 void cc_reset_pending(struct s_client *cl, int ecm_idx) {390 int i = 0;389 void cc_reset_pending(struct s_client *cl, int32_t ecm_idx) { 390 int32_t i = 0; 391 391 for (i = 0; i < CS_MAXPENDING; i++) { 392 392 if (cl->ecmtask[i].idx == ecm_idx && cl->ecmtask[i].rc == 101) … … 416 416 } 417 417 418 int cc_recv_to(struct s_client *cl, uint8 *buf, int len) {418 int32_t cc_recv_to(struct s_client *cl, uint8_t *buf, int32_t len) { 419 419 fd_set fds; 420 420 struct timeval timeout; 421 int rc;421 int32_t rc; 422 422 423 423 timeout.tv_sec = 2; … … 455 455 * receive a message 456 456 */ 457 int cc_msg_recv(struct s_client *cl, uint8 *buf, int maxlen) {457 int32_t cc_msg_recv(struct s_client *cl, uint8_t *buf, int32_t maxlen) { 458 458 struct s_reader *rdr = (cl->typ == 'c') ? NULL : cl->reader; 459 459 460 int len;460 int32_t len; 461 461 struct cc_data *cc = cl->cc; 462 462 463 int handle = cl->udp_fd;463 int32_t handle = cl->udp_fd; 464 464 465 465 if (handle <= 0 || maxlen < 4) … … 485 485 cc->g_flag = buf[0]; 486 486 487 int size = (buf[2] << 8) | buf[3];487 int32_t size = (buf[2] << 8) | buf[3]; 488 488 if (size) { // check if any data is expected in msg 489 489 if (size > maxlen) { … … 522 522 * send a message 523 523 */ 524 int cc_cmd_send(struct s_client *cl, uint8 *buf, int len, cc_msg_type_t cmd) {524 int32_t cc_cmd_send(struct s_client *cl, uint8_t *buf, int32_t len, cc_msg_type_t cmd) { 525 525 if (!cl->udp_fd) //disconnected 526 526 return -1; … … 528 528 struct s_reader *rdr = (cl->typ == 'c') ? NULL : cl->reader; 529 529 530 int n;531 uint8 netbuf[len + 4];530 int32_t n; 531 uint8_t netbuf[len + 4]; 532 532 struct cc_data *cc = cl->cc; 533 533 … … 576 576 */ 577 577 void cc_check_version(char *cc_version, char *cc_build) { 578 int i;578 int32_t i; 579 579 for (i = 0; strlen(version[i]); i++) { 580 580 if (!memcmp(cc_version, version[i], strlen(version[i]))) { … … 597 597 * sends own version information to the CCCam server 598 598 */ 599 int cc_send_cli_data(struct s_client *cl) {599 int32_t cc_send_cli_data(struct s_client *cl) { 600 600 struct s_reader *rdr = cl->reader; 601 601 602 int i;602 int32_t i; 603 603 struct cc_data *cc = cl->cc; 604 const int size = 20 + 8 + 6 + 26 + 4 + 28 + 1;604 const int32_t size = 20 + 8 + 6 + 26 + 4 + 28 + 1; 605 605 606 606 cs_debug_mask(D_READER, "cccam: send client data"); … … 608 608 memcpy(cc->node_id, cc_node_id, sizeof(cc_node_id)); 609 609 610 uint8 buf[size];610 uint8_t buf[size]; 611 611 memset(buf, 0, size); 612 612 … … 629 629 * sends version information to the client 630 630 */ 631 int cc_send_srv_data(struct s_client *cl) {631 int32_t cc_send_srv_data(struct s_client *cl) { 632 632 struct cc_data *cc = cl->cc; 633 633 … … 636 636 memcpy(cc->node_id, cc_node_id, sizeof(cc_node_id)); 637 637 638 uint8 buf[0x48];638 uint8_t buf[0x48]; 639 639 memset(buf, 0, 0x48); 640 640 641 int stealth = cl->account->cccstealth;641 int32_t stealth = cl->account->cccstealth; 642 642 if (stealth == -1) 643 643 stealth = cfg.cc_stealth; 644 644 if (stealth) 645 645 { 646 int i;646 int32_t i; 647 647 for (i=0;i<8;i++) 648 648 buf[i] = fast_rnd(); … … 661 661 } 662 662 663 int loop_check(uint8*myid, struct s_client *cl) {663 int32_t loop_check(uint8_t *myid, struct s_client *cl) { 664 664 if (!cl) 665 665 return 0; … … 676 676 * retrieves the next waiting ecm request 677 677 */ 678 int cc_get_nxt_ecm(struct s_client *cl) {678 int32_t cc_get_nxt_ecm(struct s_client *cl) { 679 679 struct cc_data *cc = cl->cc; 680 680 ECM_REQUEST *er, *ern = NULL; 681 int n, i;681 int32_t n, i; 682 682 time_t t; 683 683 … … 686 686 for (i = 0; i < CS_MAXPENDING; i++) { 687 687 er = &cl->ecmtask[i]; 688 if ((t - (u long) er->tps.time > ((cfg.ctimeout + 500)688 if ((t - (uint32_t) er->tps.time > ((cfg.ctimeout + 500) 689 689 / 1000) + 1) && (er->rc >= 10)) // drop timeouts 690 690 { … … 706 706 //check for already pending: 707 707 if (cc->extended_mode) { 708 int j,found;708 int32_t j,found; 709 709 ECM_REQUEST *erx; 710 710 for (found=j=0;j<CS_MAXPENDING;j++) { … … 735 735 * sends the secret cmd05 answer to the server 736 736 */ 737 int send_cmd05_answer(struct s_client *cl) {737 int32_t send_cmd05_answer(struct s_client *cl) { 738 738 struct s_reader *rdr = cl->reader; 739 739 struct cc_data *cc = cl->cc; … … 745 745 return 0; 746 746 747 uint8 *data = cc->cmd05_data;747 uint8_t *data = cc->cmd05_data; 748 748 cc_cmd05_mode cmd05_mode = MODE_UNKNOWN; 749 749 … … 764 764 case MODE_AES: { //encrypt with received aes128 key: 765 765 AES_KEY key; 766 uint8 aeskey[16];767 uint8 out[256];766 uint8_t aeskey[16]; 767 uint8_t out[256]; 768 768 769 769 memcpy(aeskey, cc->cmd05_aeskey, 16); … … 771 771 772 772 AES_set_encrypt_key((unsigned char *) &aeskey, 128, &key); 773 int i;773 int32_t i; 774 774 for (i = 0; i < 256; i += 16) 775 775 AES_encrypt((unsigned char *) data + i, (unsigned char *) &out … … 813 813 } 814 814 815 int get_UA_ofs(uint16caid) {816 int ofs = 0;815 int32_t get_UA_ofs(uint16_t caid) { 816 int32_t ofs = 0; 817 817 switch (caid >> 8) { 818 818 case 0x05: //VIACCESS: … … 832 832 } 833 833 834 int UA_len(uint8*ua) {835 int i, len=0;834 int32_t UA_len(uint8_t *ua) { 835 int32_t i, len=0; 836 836 for (i=0;i<8;i++) 837 837 if (ua[i]) len++; … … 839 839 } 840 840 841 void UA_left(uint8 *in, uint8 *out, int len) {842 int ofs = 0;843 int maxlen = 8;844 int orglen = len;841 void UA_left(uint8_t *in, uint8_t *out, int32_t len) { 842 int32_t ofs = 0; 843 int32_t maxlen = 8; 844 int32_t orglen = len; 845 845 while (len) { 846 846 memset(out, 0, orglen); … … 854 854 } 855 855 856 void UA_right(uint8 *in, uint8 *out, int len) {857 int ofs = 0;856 void UA_right(uint8_t *in, uint8_t *out, int32_t len) { 857 int32_t ofs = 0; 858 858 while (len) { 859 859 memcpy(out+ofs, in, len); … … 868 868 * cccam uses UA right justified 869 869 **/ 870 void cc_UA_oscam2cccam(uint8 *in, uint8 *out, uint16caid) {871 uint8 tmp[8];870 void cc_UA_oscam2cccam(uint8_t *in, uint8_t *out, uint16_t caid) { 871 uint8_t tmp[8]; 872 872 memset(out, 0, 8); 873 873 memset(tmp, 0, 8); … … 891 891 * oscam has a special format, depends on offset or type: 892 892 **/ 893 void cc_UA_cccam2oscam(uint8 *in, uint8 *out, uint16caid) {894 uint8 tmp[8];893 void cc_UA_cccam2oscam(uint8_t *in, uint8_t *out, uint16_t caid) { 894 uint8_t tmp[8]; 895 895 memset(out, 0, 8); 896 896 memset(tmp, 0, 8); … … 907 907 // //Place here your own adjustments! 908 908 //} 909 int ofs = get_UA_ofs(caid);910 int len = 8-ofs;909 int32_t ofs = get_UA_ofs(caid); 910 int32_t len = 8-ofs; 911 911 UA_left(in, tmp+ofs, len); 912 912 newcamd_to_hexserial(tmp, out, caid); 913 913 } 914 914 915 void cc_SA_oscam2cccam(uint8 *in, uint8*out) {915 void cc_SA_oscam2cccam(uint8_t *in, uint8_t *out) { 916 916 memcpy(out, in, 4); 917 917 } 918 918 919 void cc_SA_cccam2oscam(uint8 *in, uint8*out) {919 void cc_SA_cccam2oscam(uint8_t *in, uint8_t *out) { 920 920 memcpy(out, in, 4); 921 921 } 922 922 923 int cc_UA_valid(uint8*ua) {924 int i;923 int32_t cc_UA_valid(uint8_t *ua) { 924 int32_t i; 925 925 for (i = 0; i < 8; i++) 926 926 if (ua[i]) … … 949 949 LL_ITER *it2 = ll_iter_create(card->providers); 950 950 struct cc_provider *provider; 951 int p = 0;951 int32_t p = 0; 952 952 while ((provider = ll_iter_next(it2))) { 953 953 if (!cur_er || provider->prov == cur_er->prid || !provider->prov || !cur_er->prid) { … … 979 979 } 980 980 981 int same_first_node(struct cc_card *card1, struct cc_card *card2) {982 uint8 * node1 = ll_has_elements(card1->remote_nodes);983 uint8 * node2 = ll_has_elements(card2->remote_nodes);981 int32_t same_first_node(struct cc_card *card1, struct cc_card *card2) { 982 uint8_t * node1 = ll_has_elements(card1->remote_nodes); 983 uint8_t * node2 = ll_has_elements(card2->remote_nodes); 984 984 985 985 if (!node1 && !node2) return 1; //both NULL, same! … … 990 990 } 991 991 992 int same_card2(struct cc_card *card1, struct cc_card *card2) {992 int32_t same_card2(struct cc_card *card1, struct cc_card *card2) { 993 993 return (card1->caid == card2->caid && 994 994 card1->card_type == card2->card_type && … … 997 997 } 998 998 999 int same_card(struct cc_card *card1, struct cc_card *card2) {999 int32_t same_card(struct cc_card *card1, struct cc_card *card2) { 1000 1000 return (card1->remote_id == card2->remote_id && 1001 1001 same_card2(card1, card2) && … … 1007 1007 * sends a ecm request to the connected CCCam Server 1008 1008 */ 1009 int cc_send_ecm(struct s_client *cl, ECM_REQUEST *er, uchar *buf) {1009 int32_t cc_send_ecm(struct s_client *cl, ECM_REQUEST *er, uchar *buf) { 1010 1010 struct s_reader *rdr = cl->reader; 1011 1011 … … 1014 1014 cc_cli_connect(cl); 1015 1015 1016 int n, h = -1;1016 int32_t n, h = -1; 1017 1017 struct cc_data *cc = cl->cc; 1018 1018 struct cc_card *card = NULL; … … 1058 1058 struct timeb timeout; 1059 1059 timeout = cc->ecm_time; 1060 u nsigned int tt = cfg.ctimeout * 4;1060 uint32_t tt = cfg.ctimeout * 4; 1061 1061 timeout.time += tt / 1000; 1062 1062 timeout.millitm += tt % 1000; … … 1159 1159 if (card) { 1160 1160 card->time = time((time_t) 0); 1161 uint8 ecmbuf[255+13];1161 uint8_t ecmbuf[255+13]; 1162 1162 memset(ecmbuf, 0, 255+13); 1163 1163 … … 1178 1178 memcpy(ecmbuf + 13, cur_er->ecm, cur_er->l); 1179 1179 1180 uint8 send_idx = 1;1180 uint8_t send_idx = 1; 1181 1181 if (cc->extended_mode) { 1182 1182 cc->server_ecm_idx++; … … 1249 1249 1250 1250 /* 1251 int cc_abort_user_ecms(){1252 int n, i;1251 int32_t cc_abort_user_ecms(){ 1252 int32_t n, i; 1253 1253 time_t t;//, tls; 1254 1254 struct cc_data *cc = rdr->cc; … … 1262 1262 cl->ecmtask[i].rc=0; 1263 1263 } 1264 int td=abs(1000*(ecmtask[i].tps.time-cc->found->tps.time)+ecmtask[i].tps.millitm-cc->found->tps.millitm);1264 int32_t td=abs(1000*(ecmtask[i].tps.time-cc->found->tps.time)+ecmtask[i].tps.millitm-cc->found->tps.millitm); 1265 1265 if (ecmtask[i].rc>=10 && ecmtask[i].cidx==cc->found->cidx && &ecmtask[i]!=cc->found){ 1266 1266 cs_log("aborting idx:%d caid:%04x client:%d timedelta:%d",ecmtask[i].idx,ecmtask[i].caid,ecmtask[i].cidx,td); … … 1275 1275 */ 1276 1276 1277 int cc_send_pending_emms(struct s_client *cl) {1277 int32_t cc_send_pending_emms(struct s_client *cl) { 1278 1278 struct s_reader *rdr = cl->reader; 1279 1279 struct cc_data *cc = cl->cc; 1280 1280 1281 1281 LL_ITER *it = ll_iter_create(cc->pending_emms); 1282 uint8 *emmbuf;1283 int size = 0;1282 uint8_t *emmbuf; 1283 int32_t size = 0; 1284 1284 if ((emmbuf = ll_iter_next(it))) { 1285 1285 if (!cc->extended_mode) { … … 1311 1311 * find card by hexserial 1312 1312 * */ 1313 struct cc_card *get_card_by_hexserial(struct s_client *cl, uint8 *hexserial,1314 uint16 caid) {1313 struct cc_card *get_card_by_hexserial(struct s_client *cl, uint8_t *hexserial, 1314 uint16_t caid) { 1315 1315 struct cc_data *cc = cl->cc; 1316 1316 LL_ITER *it = ll_iter_create(cc->cards); … … 1329 1329 * ProcessEmm 1330 1330 * */ 1331 int cc_send_emm(EMM_PACKET *ep) {1331 int32_t cc_send_emm(EMM_PACKET *ep) { 1332 1332 struct s_client *cl = cur_client(); 1333 1333 struct s_reader *rdr = cl->reader; … … 1348 1348 } 1349 1349 1350 u short caid = b2i(2, ep->caid);1350 uint16_t caid = b2i(2, ep->caid); 1351 1351 1352 1352 //Last used card is first card of current_cards: … … 1356 1356 1357 1357 if (!emm_card) { 1358 uint8 hs[8];1358 uint8_t hs[8]; 1359 1359 cc_UA_oscam2cccam(ep->hexserial, hs, caid); 1360 1360 cs_debug_mask(D_EMM, … … 1379 1379 getprefix(), ep->client->thread, caid, emm_card->id); 1380 1380 1381 int size = ep->l + 12;1382 uint8 *emmbuf = cs_malloc(&emmbuf, size, QUITERROR);1381 int32_t size = ep->l + 12; 1382 uint8_t *emmbuf = cs_malloc(&emmbuf, size, QUITERROR); 1383 1383 memset(emmbuf, 0, size); 1384 1384 … … 1421 1421 } 1422 1422 1423 struct cc_card *cc_get_card_by_id(uint32 card_id, LLIST *cards) {1423 struct cc_card *cc_get_card_by_id(uint32_t card_id, LLIST *cards) { 1424 1424 if (!cards) 1425 1425 return NULL; … … 1435 1435 } 1436 1436 1437 void cc_free_cardlist(LLIST *card_list, int destroy_list) {1437 void cc_free_cardlist(LLIST *card_list, int32_t destroy_list) { 1438 1438 if (card_list) { 1439 1439 LL_ITER *it = ll_iter_create(card_list); … … 1477 1477 } 1478 1478 1479 int is_null_dcw(uint8*dcw) {1480 int i;1479 int32_t is_null_dcw(uint8_t *dcw) { 1480 int32_t i; 1481 1481 for (i = 0; i < 15; i++) 1482 1482 if (dcw[i]) … … 1485 1485 } 1486 1486 1487 /*int is_dcw_corrupted(uchar *dcw)1487 /*int32_t is_dcw_corrupted(uchar *dcw) 1488 1488 { 1489 int i;1490 int c, cs;1489 int32_t i; 1490 int32_t c, cs; 1491 1491 1492 1492 for (i=0; i<16; i+=4) … … 1500 1500 */ 1501 1501 1502 int check_extended_mode(struct s_client *cl, char *msg) {1502 int32_t check_extended_mode(struct s_client *cl, char *msg) { 1503 1503 //Extended mode: if PARTNER String is ending with [PARAM], extended mode is activated 1504 1504 //For future compatibilty the syntax should be compatible with … … 1513 1513 1514 1514 struct cc_data *cc = cl->cc; 1515 int has_param = 0;1515 int32_t has_param = 0; 1516 1516 char *p = strtok(msg, "["); 1517 1517 while (p) { … … 1547 1547 else 1548 1548 { 1549 int rto = abs(rdr->last_s - rdr->last_g);1549 int32_t rto = abs(rdr->last_s - rdr->last_g); 1550 1550 if (rto >= (rdr->tcp_rto*60)) 1551 1551 network_tcp_connection_close(cl, cl->udp_fd); … … 1553 1553 } 1554 1554 1555 struct cc_card *read_card(uint8 *buf, int ext) {1555 struct cc_card *read_card(uint8_t *buf, int32_t ext) { 1556 1556 struct cc_card *card = cs_malloc(&card, sizeof(struct cc_card), QUITERROR); 1557 1557 memset(card, 0, sizeof(struct cc_card)); 1558 1558 1559 int nprov, nassign = 0, nreject = 0, offset = 21;1559 int32_t nprov, nassign = 0, nreject = 0, offset = 21; 1560 1560 1561 1561 card->providers = ll_create(); … … 1583 1583 } 1584 1584 1585 int i;1585 int32_t i; 1586 1586 for (i = 0; i < nprov; i++) { // providers 1587 1587 struct cc_provider *prov = cs_malloc(&prov, sizeof(struct cc_provider), QUITERROR); … … 1597 1597 } 1598 1598 1599 uint8 *ptr = buf + offset;1599 uint8_t *ptr = buf + offset; 1600 1600 1601 1601 if (ext) { … … 1623 1623 } 1624 1624 1625 int remote_count = ptr[0];1625 int32_t remote_count = ptr[0]; 1626 1626 ptr++; 1627 1627 for (i = 0; i < remote_count; i++) { 1628 uint8 *remote_node = cs_malloc(&remote_node, 8, QUITERROR);1628 uint8_t *remote_node = cs_malloc(&remote_node, 8, QUITERROR); 1629 1629 memcpy(remote_node, ptr, 8); 1630 1630 ll_append(card->remote_nodes, remote_node); … … 1634 1634 } 1635 1635 1636 void cc_card_removed(struct s_client *cl, uint32 shareid) {1636 void cc_card_removed(struct s_client *cl, uint32_t shareid) { 1637 1637 struct cc_data *cc = cl->cc; 1638 1638 struct cc_card *card; … … 1682 1682 /*void fix_dcw(uchar *dcw) 1683 1683 { 1684 int i;1684 int32_t i; 1685 1685 for (i=0; i<16; i+=4) 1686 1686 { … … 1699 1699 } 1700 1700 1701 int cc_parse_msg(struct s_client *cl, uint8 *buf, int l) {1701 int32_t cc_parse_msg(struct s_client *cl, uint8_t *buf, int32_t l) { 1702 1702 struct s_reader *rdr = (cl->typ == 'c') ? NULL : cl->reader; 1703 uint8 token[256];1704 int ret = buf[1];1703 uint8_t token[256]; 1704 int32_t ret = buf[1]; 1705 1705 struct cc_data *cc = cl->cc; 1706 1706 1707 1707 cs_debug_mask(cl->typ=='c'?D_CLIENT:D_READER, "%s parse_msg=%d", getprefix(), buf[1]); 1708 1708 1709 uint8 *data = buf + 4;1709 uint8_t *data = buf + 4; 1710 1710 memcpy(&cc->receive_buffer, data, l - 4); 1711 1711 cc->last_msg = buf[1]; … … 1738 1738 1739 1739 if (!cc->is_oscam_cccam) {//Allready discovered oscam-cccam: 1740 uint16 sum = 0x1234;1741 uint16 recv_sum = (cc->peer_node_id[6] << 8)1740 uint16_t sum = 0x1234; 1741 uint16_t recv_sum = (cc->peer_node_id[6] << 8) 1742 1742 | cc->peer_node_id[7]; 1743 int i;1743 int32_t i; 1744 1744 for (i = 0; i < 6; i++) { 1745 1745 sum += cc->peer_node_id[i]; … … 1819 1819 case MSG_NEW_CARD_SIDINFO: 1820 1820 case MSG_NEW_CARD: { 1821 uint16 caid = b2i(2, buf + 12);1821 uint16_t caid = b2i(2, buf + 12); 1822 1822 //filter caid==0 and maxhop: 1823 1823 if (!caid || buf[14] >= rdr->cc_maxhop+1) … … 1843 1843 //Check if this card is from us: 1844 1844 LL_ITER *it = ll_iter_create(card->remote_nodes); 1845 uint8 *node_id;1845 uint8_t *node_id; 1846 1846 while ((node_id = ll_iter_next(it))) { 1847 1847 if (memcmp(node_id, cc_node_id, sizeof(cc_node_id)) == 0) { //this card is from us! … … 1909 1909 1910 1910 strncpy(cc->remote_oscam, msg+9, sizeof(cc->remote_oscam)-1); 1911 int has_param = check_extended_mode(cl, msg);1911 int32_t has_param = check_extended_mode(cl, msg); 1912 1912 if (!cc->is_oscam_cccam) { 1913 1913 cc->is_oscam_cccam = 1; … … 1952 1952 else 1953 1953 { 1954 u short ecm_idx = eei->ecm_idx;1954 uint16_t ecm_idx = eei->ecm_idx; 1955 1955 cc->recv_ecmtask = ecm_idx; 1956 1956 struct cc_card *card = eei->card; … … 1974 1974 //also origin card is only set on cccam clients 1975 1975 //so wie send back the nok to the client 1976 int i = 0;1976 int32_t i = 0; 1977 1977 for (i=0;i<CS_MAXPENDING;i++) { 1978 1978 if (cl->ecmtask[i].idx == ecm_idx) { … … 2095 2095 else 2096 2096 { 2097 u short ecm_idx = eei->ecm_idx;2097 uint16_t ecm_idx = eei->ecm_idx; 2098 2098 cc->recv_ecmtask = ecm_idx; 2099 2099 struct cc_card *card = eei->card; … … 2128 2128 struct timeb tpe; 2129 2129 cs_ftime(&tpe); 2130 u longcwlastresptime = 1000*(tpe.time-cc->ecm_time.time)+tpe.millitm-cc->ecm_time.millitm;2130 uint32_t cwlastresptime = 1000*(tpe.time-cc->ecm_time.time)+tpe.millitm-cc->ecm_time.millitm; 2131 2131 if (cwlastresptime > cfg.ftimeout && !cc->extended_mode) { 2132 2132 cs_debug_mask(D_READER, "%s card %04X is too slow, moving to the end...", getprefix(), card->id); … … 2191 2191 2192 2192 AES_KEY key; 2193 uint8 aeskey[16];2194 uint8 out[16];2193 uint8_t aeskey[16]; 2194 uint8_t out[16]; 2195 2195 2196 2196 memcpy(aeskey, cc->cmd0b_aeskey, 16); … … 2211 2211 2212 2212 case MSG_CMD_0C: { //New CCCAM 2.2.0 Server/Client fake check! 2213 int len = l-4;2213 int32_t len = l-4; 2214 2214 2215 2215 if (cl->typ == 'c') { //Only im comming from "client" 2216 2216 cs_debug_mask(D_CLIENT, "%s MSG_CMD_0C received (payload=%d)!", getprefix(), len); 2217 2217 2218 uint8 bytes[0x20];2218 uint8_t bytes[0x20]; 2219 2219 if (len < 0x20) //if less then 0x20 bytes, clear others: 2220 2220 memset(data+len, 0, 0x20-len); … … 2225 2225 2226 2226 //xor data: 2227 int i;2227 int32_t i; 2228 2228 for (i=0;i<0x20;i++) 2229 2229 bytes[i] ^= (data[i] & 0x7F); 2230 2230 2231 2231 //key is now the 16bit hash of md5: 2232 uint8 md5hash[0x10];2232 uint8_t md5hash[0x10]; 2233 2233 MD5(data, 0x20, md5hash); 2234 2234 memcpy(bytes, md5hash, 0x10); … … 2243 2243 cc_crypt_cmd0c(cl, data, len); 2244 2244 2245 uint8 CMD_0x0C_Command = data[0];2245 uint8_t CMD_0x0C_Command = data[0]; 2246 2246 2247 2247 switch (CMD_0x0C_Command) { … … 2286 2286 2287 2287 case MSG_CMD_0D: { //key update for the active cmd0x0c algo 2288 int len = l-4;2288 int32_t len = l-4; 2289 2289 if (cc->cmd0c_mode == MODE_CMD_0x0C_NONE) 2290 2290 break; … … 2378 2378 * Reader: write dcw to receive 2379 2379 */ 2380 int cc_recv_chk(struct s_client *cl, uchar *dcw, int *rc, uchar *buf, int UNUSED(n)) {2380 int32_t cc_recv_chk(struct s_client *cl, uchar *dcw, int32_t *rc, uchar *buf, int32_t UNUSED(n)) { 2381 2381 struct cc_data *cc = cl->cc; 2382 2382 … … 2399 2399 } 2400 2400 2401 //int is_softfail(int rc)2401 //int32_t is_softfail(int32_t rc) 2402 2402 //{ 2403 2403 // //see oscam.c send_dcw() for a full list … … 2451 2451 cc->g_flag = eei->send_idx; 2452 2452 2453 int nok;2453 int32_t nok; 2454 2454 if (!eei || !eei->card) 2455 2455 nok = MSG_CW_NOK1; //share no more available … … 2466 2466 } 2467 2467 2468 int cc_recv(struct s_client *cl, uchar *buf, int l) {2469 int n;2468 int32_t cc_recv(struct s_client *cl, uchar *buf, int32_t l) { 2469 int32_t n; 2470 2470 uchar *cbuf; 2471 2471 … … 2511 2511 * Starting readers to get cards: 2512 2512 **/ 2513 int cc_srv_wakeup_readers(struct s_client *cl) {2514 int wakeup = 0;2513 int32_t cc_srv_wakeup_readers(struct s_client *cl) { 2514 int32_t wakeup = 0; 2515 2515 struct s_reader *rdr; 2516 2516 for (rdr = first_active_reader; rdr; rdr = rdr->next) { … … 2533 2533 2534 2534 2535 int check_cccam_compat(struct cc_data *cc) {2536 int res = 0;2535 int32_t check_cccam_compat(struct cc_data *cc) { 2536 int32_t res = 0; 2537 2537 if (strcmp(cfg.cc_version, "2.2.0") == 0 || strcmp(cfg.cc_version, "2.2.1") == 0) { 2538 2538 … … 2544 2544 } 2545 2545 2546 int cc_srv_connect(struct s_client *cl) {2547 int i, wait_for_keepalive;2548 u longcmi;2549 uint8 buf[CC_MAXMSGSIZE];2550 uint8 data[16];2546 int32_t cc_srv_connect(struct s_client *cl) { 2547 int32_t i, wait_for_keepalive; 2548 uint32_t cmi; 2549 uint8_t buf[CC_MAXMSGSIZE]; 2550 uint8_t data[16]; 2551 2551 char usr[21], pwd[65]; 2552 2552 struct s_auth *account; … … 2571 2571 cc->extended_mode = 0; 2572 2572 2573 int keep_alive = 1;2573 int32_t keep_alive = 1; 2574 2574 setsockopt(cl->udp_fd, SOL_SOCKET, SO_KEEPALIVE, 2575 2575 (void *)&keep_alive, sizeof(keep_alive)); … … 2633 2633 struct cc_crypt_block *save_block = cs_malloc(&save_block, sizeof(struct cc_crypt_block), QUITERROR); 2634 2634 memcpy(save_block, cc->block, sizeof(struct cc_crypt_block)); 2635 int found = 0;2635 int32_t found = 0; 2636 2636 while (1) { 2637 2637 while (account) { … … 2650 2650 // receive passwd / 'CCcam' 2651 2651 memcpy(cc->block, save_block, sizeof(struct cc_crypt_block)); 2652 cc_crypt(&cc->block[DECRYPT], (uint8 *) pwd, strlen(pwd), ENCRYPT);2652 cc_crypt(&cc->block[DECRYPT], (uint8_t *) pwd, strlen(pwd), ENCRYPT); 2653 2653 cc_crypt(&cc->block[DECRYPT], buf, 6, DECRYPT); 2654 2654 //cs_ddump_mask(D_CLIENT, buf, 6, "cccam: pwd check '%s':", buf); //illegal buf-bytes could kill the logger! … … 2783 2783 2784 2784 cl->pfd = cl->udp_fd; 2785 int ret;2785 int32_t ret; 2786 2786 if ((ret=cc_srv_connect(cl)) < 0) { 2787 2787 if (errno != 0) … … 2796 2796 } 2797 2797 2798 int cc_cli_connect(struct s_client *cl) {2798 int32_t cc_cli_connect(struct s_client *cl) { 2799 2799 struct s_reader *rdr = cl->reader; 2800 2800 struct cc_data *cc = cl->cc; … … 2806 2806 if (!cl->udp_fd) { 2807 2807 cc_cli_init_int(cl); 2808 return -1; // cc_cli_init_int calls cc_cli_connect, so exit here!2808 return -1; // cc_cli_init_int32_t calls cc_cli_connect, so exit here! 2809 2809 } 2810 2810 … … 2812 2812 struct timeb cur_time; 2813 2813 cs_ftime(&cur_time); 2814 int time = 1000*(rdr->tcp_block_connect_till.time-cur_time.time)2814 int32_t time = 1000*(rdr->tcp_block_connect_till.time-cur_time.time) 2815 2815 +rdr->tcp_block_connect_till.millitm-cur_time.millitm; 2816 2816 cs_log("%s connection blocked, retrying in %ds", rdr->label, time/1000); … … 2818 2818 } 2819 2819 2820 int handle, n;2821 uint8 data[20];2822 uint8 hash[SHA_DIGEST_LENGTH];2823 uint8 buf[CC_MAXMSGSIZE];2820 int32_t handle, n; 2821 uint8_t data[20]; 2822 uint8_t hash[SHA_DIGEST_LENGTH]; 2823 uint8_t buf[CC_MAXMSGSIZE]; 2824 2824 char pwd[64]; 2825 2825 … … 2846 2846 // get init seed 2847 2847 if ((n = cc_recv_to(cl, data, 16)) != 16) { 2848 int err = errno;2848 int32_t err = errno; 2849 2849 if (n <= 0) 2850 2850 cs_log("%s server blocked connection!", rdr->label); … … 2903 2903 cs_ddump_mask(D_CLIENT, data, 16, "cccam: server init seed:"); 2904 2904 2905 uint16 sum = 0x1234;2906 uint16 recv_sum = (data[14] << 8) | data[15];2907 int i;2905 uint16_t sum = 0x1234; 2906 uint16_t recv_sum = (data[14] << 8) | data[15]; 2907 int32_t i; 2908 2908 for (i = 0; i < 14; i++) { 2909 2909 sum += data[i]; … … 2940 2940 memcpy(buf, "CCcam", 5); 2941 2941 strncpy(pwd, rdr->r_pwd, sizeof(pwd) - 1); 2942 cc_crypt(&cc->block[ENCRYPT], (uint8 *) pwd, strlen(pwd), ENCRYPT);2942 cc_crypt(&cc->block[ENCRYPT], (uint8_t *) pwd, strlen(pwd), ENCRYPT); 2943 2943 cc_cmd_send(cl, buf, 6, MSG_NO_HEADER); // send 'CCcam' xor w/ pwd 2944 2944 … … 2989 2989 } 2990 2990 2991 int cc_cli_init_int(struct s_client *cl) {2991 int32_t cc_cli_init_int(struct s_client *cl) { 2992 2992 struct s_reader *rdr = cl->reader; 2993 2993 if (rdr->tcp_connected) … … 2995 2995 2996 2996 struct protoent *ptrp; 2997 int p_proto;2997 int32_t p_proto; 2998 2998 2999 2999 if (cl->pfd) { … … 3041 3041 if (cfg.netprio) 3042 3042 setsockopt(cl->udp_fd, SOL_SOCKET, SO_PRIORITY, 3043 (void *)&cfg.netprio, sizeof(u long));3043 (void *)&cfg.netprio, sizeof(uintptr_t)); 3044 3044 #endif 3045 int keep_alive = 1;3045 int32_t keep_alive = 1; 3046 3046 setsockopt(cl->udp_fd, SOL_SOCKET, SO_KEEPALIVE, 3047 3047 (void *)&keep_alive, sizeof(keep_alive)); … … 3053 3053 memset((char *) &cl->udp_sa, 0, sizeof(cl->udp_sa)); 3054 3054 cl->udp_sa.sin_family = AF_INET; 3055 cl->udp_sa.sin_port = htons((u _short) rdr->r_port);3055 cl->udp_sa.sin_port = htons((uint16_t) rdr->r_port); 3056 3056 3057 3057 if (rdr->tcp_rto <= 2) … … 3066 3066 } 3067 3067 3068 int cc_cli_init(struct s_client *cl) {3068 int32_t cc_cli_init(struct s_client *cl) { 3069 3069 struct cc_data *cc = cl->cc; 3070 3070 struct s_reader *reader = cl->reader; … … 3073 3073 return -1; 3074 3074 3075 int res = cc_cli_init_int(cl); //Create socket3075 int32_t res = cc_cli_init_int(cl); //Create socket 3076 3076 3077 3077 if (res == 0 && reader && (reader->cc_keepalive || !cl->cc) && !reader->tcp_connected) { … … 3103 3103 * 3104 3104 */ 3105 int cc_available(struct s_reader *rdr, int checktype) {3105 int32_t cc_available(struct s_reader *rdr, int32_t checktype) { 3106 3106 if (!rdr || !rdr->client) return 0; 3107 3107 … … 3177 3177 //Partner Detection: 3178 3178 init_rnd(); 3179 uint16 sum = 0x1234; //This is our checksum3180 int i;3179 uint16_t sum = 0x1234; //This is our checksum 3180 int32_t i; 3181 3181 for (i = 0; i < 6; i++) { 3182 3182 cc_node_id[i] = fast_rnd();
Note:
See TracChangeset
for help on using the changeset viewer.