Changeset 5114 for trunk/module-cccam.c
- Timestamp:
- 04/29/11 17:15:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/module-cccam.c
r5100 r5114 532 532 533 533 int32_t n; 534 uint8_t netbuf[len + 4];534 uint8_t *netbuf = cs_malloc(&netbuf, len + 4, 0); 535 535 struct cc_data *cc = cl->cc; 536 536 … … 540 540 } 541 541 542 memset(netbuf, 0, len + 4);543 544 542 if (cmd == MSG_NO_HEADER) { 545 543 memcpy(netbuf, buf, len); … … 563 561 564 562 pthread_mutex_unlock(&cc->lockcmd); 565 563 564 free(netbuf); 565 566 566 if (n != len) { 567 567 if (rdr) … … 614 614 memcpy(cc->node_id, cc_node_id, sizeof(cc_node_id)); 615 615 616 uint8_t buf[size]; 617 memset(buf, 0, size); 616 uint8_t *buf = cs_malloc(&buf, size, 0); 618 617 619 618 memcpy(buf, rdr->r_usr, sizeof(rdr->r_usr)); … … 628 627 i = cc_cmd_send(cl, buf, size, MSG_CLI_DATA); 629 628 629 free(buf); 630 630 631 return i; 631 632 } … … 1170 1171 1171 1172 if (card) { 1172 uint8_t ecmbuf[255+13]; 1173 memset(ecmbuf, 0, 255+13); 1173 uint8_t *ecmbuf = cs_malloc(&ecmbuf, cur_er->l+13, 0); 1174 1174 1175 1175 // build ecm message … … 1208 1208 cc_cmd_send(cl, ecmbuf, cur_er->l + 13, MSG_CW_ECM); // send ecm 1209 1209 1210 free(ecmbuf); 1211 1210 1212 //For EMM 1211 1213 set_au_data(cl, rdr, card, cur_er); … … 1750 1752 int32_t cc_parse_msg(struct s_client *cl, uint8_t *buf, int32_t l) { 1751 1753 struct s_reader *rdr = (cl->typ == 'c') ? NULL : cl->reader; 1752 uint8_t token[256];1753 1754 int32_t ret = buf[1]; 1754 1755 struct cc_data *cc = cl->cc; … … 1799 1800 //Trick: when discovered partner is an Oscam Client, then we send him our version string: 1800 1801 if (cc->is_oscam_cccam) { 1802 uint8_t token[256]; 1801 1803 snprintf((char *)token, sizeof(token), 1802 1804 "PARTNER: OSCam v%s, build #%s (%s) [EXT,SID]", CS_VERSION, … … 1992 1994 } 1993 1995 1996 uchar token[256]; 1994 1997 snprintf((char *)token, sizeof(token), 1995 1998 "PARTNER: OSCam v%s, build #%s (%s)%s", … … 2630 2633 int32_t cc_srv_connect(struct s_client *cl) { 2631 2634 int32_t i, wait_for_keepalive; 2632 uint8_t buf[CC_MAXMSGSIZE];2633 2635 uint8_t data[16]; 2634 2636 char usr[21], pwd[65]; 2635 2637 struct s_auth *account; 2636 2638 struct cc_data *cc = cl->cc; 2637 uchar mbuf[1024];2638 2639 2639 2640 memset(usr, 0, sizeof(usr)); … … 2650 2651 cc_init_cc(cc); 2651 2652 } 2653 uint8_t *buf = cc->send_buffer; 2654 2652 2655 cc->mode = CCCAM_MODE_NOTINIT; 2653 2656 cc->server_ecm_pending = 0; … … 2691 2694 2692 2695 // receive username 2693 memset(buf, 0, sizeof(buf));2696 memset(buf, 0, CC_MAXMSGSIZE); 2694 2697 if ((i = cc_recv_to(cl, buf, 20)) == 20) { 2695 2698 cc_crypt(&cc->block[DECRYPT], buf, 20, DECRYPT); … … 2788 2791 2789 2792 // recv cli data 2790 memset(buf, 0, sizeof(buf));2791 i = cc_msg_recv(cl, buf, sizeof(buf));2793 memset(buf, 0, CC_MAXMSGSIZE); 2794 i = cc_msg_recv(cl, buf, CC_MAXMSGSIZE); 2792 2795 if (i < 0) 2793 2796 return -1; … … 2815 2818 //Wait for Partner detection (NOK1 with data) before reporting cards 2816 2819 //When Partner is detected, cccam220=1 is set. then we can report extended card data 2817 i = process_input( mbuf, sizeof(mbuf), 1);2820 i = process_input(buf, CC_MAXMSGSIZE, 1); 2818 2821 if (i<=0 && i != -9) 2819 2822 return 0; //disconnected … … 2838 2841 while (cl->pfd && cl->udp_fd && cc->mode == CCCAM_MODE_NORMAL && !cl->dup) 2839 2842 { 2840 i = process_input( mbuf, sizeof(mbuf), 10);2843 i = process_input(buf, CC_MAXMSGSIZE, 10); 2841 2844 if (i <= 0 && i != -9) 2842 2845 break; //Disconnected by client … … 2900 2903 struct cc_data *cc = cl->cc; 2901 2904 rdr->card_status = CARD_FAILURE; 2902 2905 2903 2906 if (cc && cc->mode == CCCAM_MODE_SHUTDOWN) 2904 2907 return -99; 2905 2906 if (!cl->udp_fd) {2907 cc_cli_init_int(cl);2908 return -1; // cc_cli_init_int32_t calls cc_cli_connect, so exit here!2909 }2910 2911 if (is_connect_blocked(rdr)) {2912 struct timeb cur_time;2913 cs_ftime(&cur_time);2914 int32_t time = 1000*(rdr->tcp_block_connect_till.time-cur_time.time)2915 +rdr->tcp_block_connect_till.millitm-cur_time.millitm;2916 cs_log("%s connection blocked, retrying in %ds", rdr->label, time/1000);2917 return -1;2918 }2919 2920 int32_t handle, n;2921 uint8_t data[20];2922 uint8_t hash[SHA_DIGEST_LENGTH];2923 uint8_t buf[CC_MAXMSGSIZE];2924 char pwd[64];2925 2926 // check cred config2927 if (rdr->device[0] == 0 || rdr->r_pwd[0] == 0 || rdr->r_usr[0] == 02928 || rdr->r_port == 0) {2929 cs_log("%s configuration error!", rdr->label);2930 return -5;2931 }2932 2933 // connect2934 handle = network_tcp_connection_open();2935 if (handle <= 0) {2936 cs_log("%s network connect error!", rdr->label);2937 return -1;2938 }2939 if (errno == EISCONN) {2940 cc_cli_close(cl, FALSE);2941 2942 block_connect(rdr);2943 return -1;2944 }2945 2946 // get init seed2947 if ((n = cc_recv_to(cl, data, 16)) != 16) {2948 int32_t err = errno;2949 if (n <= 0)2950 cs_log("%s server blocked connection!", rdr->label);2951 else2952 cs_log("%s server does not return 16 bytes (n=%d, errno=%d %s)",2953 rdr->label, n, err, strerror(errno));2954 block_connect(rdr);2955 return -2;2956 }2957 2908 2958 2909 if (!cc) { … … 2960 2911 cc = cs_malloc(&cc, sizeof(struct cc_data), QUITERROR); 2961 2912 memset(cc, 0, sizeof(struct cc_data)); 2913 cc_init_cc(cc); 2962 2914 cc->cards = ll_create(); 2963 2915 cl->cc = cc; 2964 2916 cc->pending_emms = ll_create(); 2965 2917 cc->extended_ecm_idx = ll_create(); 2966 cc_init_cc(cc);2967 2918 } else { 2968 2919 if (cc->cards) { … … 2990 2941 cc->prefix = cs_malloc(&cc->prefix, strlen(cl->reader->label)+20, QUITERROR); 2991 2942 snprintf(cc->prefix, strlen(cl->reader->label)+20, "cccam(r) %s: ", cl->reader->label); 2943 2944 if (!cl->udp_fd) { 2945 cc_cli_init_int(cl); 2946 return -1; // cc_cli_init_int32_t calls cc_cli_connect, so exit here! 2947 } 2948 2949 if (is_connect_blocked(rdr)) { 2950 struct timeb cur_time; 2951 cs_ftime(&cur_time); 2952 int32_t time = 1000*(rdr->tcp_block_connect_till.time-cur_time.time) 2953 +rdr->tcp_block_connect_till.millitm-cur_time.millitm; 2954 cs_log("%s connection blocked, retrying in %ds", rdr->label, time/1000); 2955 return -1; 2956 } 2957 2958 int32_t handle, n; 2959 uint8_t data[20]; 2960 uint8_t hash[SHA_DIGEST_LENGTH]; 2961 uint8_t *buf = cc->send_buffer; 2962 char pwd[64]; 2963 2964 // check cred config 2965 if (rdr->device[0] == 0 || rdr->r_pwd[0] == 0 || rdr->r_usr[0] == 0 2966 || rdr->r_port == 0) { 2967 cs_log("%s configuration error!", rdr->label); 2968 return -5; 2969 } 2970 2971 // connect 2972 handle = network_tcp_connection_open(); 2973 if (handle <= 0) { 2974 cs_log("%s network connect error!", rdr->label); 2975 return -1; 2976 } 2977 if (errno == EISCONN) { 2978 cc_cli_close(cl, FALSE); 2979 2980 block_connect(rdr); 2981 return -1; 2982 } 2983 2984 // get init seed 2985 if ((n = cc_recv_to(cl, data, 16)) != 16) { 2986 int32_t err = errno; 2987 if (n <= 0) 2988 cs_log("%s server blocked connection!", rdr->label); 2989 else 2990 cs_log("%s server does not return 16 bytes (n=%d, errno=%d %s)", 2991 rdr->label, n, err, strerror(errno)); 2992 block_connect(rdr); 2993 return -2; 2994 } 2995 2992 2996 2993 2997 cc->ecm_counter = 0; … … 3039 3043 cc_cmd_send(cl, hash, 20, MSG_NO_HEADER); // send crypted hash to server 3040 3044 3041 memset(buf, 0, sizeof(buf));3045 memset(buf, 0, CC_MAXMSGSIZE); 3042 3046 memcpy(buf, rdr->r_usr, strlen(rdr->r_usr)); 3043 3047 cs_ddump_mask(D_CLIENT, buf, 20, "cccam: username '%s':", buf); 3044 3048 cc_cmd_send(cl, buf, 20, MSG_NO_HEADER); // send usr '0' padded -> 20 bytes 3045 3049 3046 memset(buf, 0, sizeof(buf));3050 memset(buf, 0, CC_MAXMSGSIZE); 3047 3051 memset(pwd, 0, sizeof(pwd)); 3048 3052
Note:
See TracChangeset
for help on using the changeset viewer.