Changeset 3197
- Timestamp:
- 09/23/10 14:46:28 (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/globals.h
r3196 r3197 423 423 //int ridx (reader to check) 424 424 //int checktype (0=return connected, 1=return loadbalance-avail) return int 425 void (*c_idle)(); //Schlocke: called when reader is idle 425 void (*c_idle)(); //Schlocke: called when reader is idle 426 void (*c_card_info)(); //Schlocke: request card infos 426 427 int c_port; 427 428 PTAB *ptab; -
trunk/module-cccam.c
r3193 r3197 26 26 27 27 cc->prefix = malloc(100); 28 if (cl ient[cs_idx].is_server)28 if (cl->is_server) 29 29 sprintf(cc->prefix, "cccam(s) %s: ", cl->usr); 30 30 else … … 132 132 int i; 133 133 134 if (!cl ient[cs_idx].is_server) {134 if (!cl->is_server) { 135 135 node_id = b2ll(8, cc->node_id); 136 136 } else { … … 348 348 349 349 //cs_sleepms(100); 350 if (cl ient[cs_idx].pfd) {351 close(cl ient[cs_idx].pfd);352 cl ient[cs_idx].pfd = 0;350 if (cl->pfd) { 351 close(cl->pfd); 352 cl->pfd = 0; 353 353 cl->udp_fd = 0; 354 354 } else if (cl->udp_fd) { 355 355 close(cl->udp_fd); 356 356 cl->udp_fd = 0; 357 cl ient[cs_idx].pfd = 0;357 cl->pfd = 0; 358 358 } 359 359 //cs_sleepms(100); … … 480 480 481 481 len = recv(handle, netbuf, 4, MSG_WAITALL); 482 if (!cl ient[cs_idx].is_server)482 if (!cl->is_server) 483 483 rdr->last_g = time(NULL); 484 484 … … 505 505 506 506 len = recv(handle, netbuf + 4, size, MSG_WAITALL); // read rest of msg 507 if (!cl ient[cs_idx].is_server)507 if (!cl->is_server) 508 508 rdr->last_g = time(NULL); 509 509 … … 555 555 556 556 n = send(cl->udp_fd, netbuf, len, 0); 557 if (!cl ient[cs_idx].is_server)557 if (!cl->is_server) 558 558 rdr->last_s = time(NULL); 559 559 560 560 if (n != len) { 561 if (cl ient[cs_idx].is_server)561 if (cl->is_server) 562 562 cs_disconnect_client(); 563 563 else … … 664 664 */ 665 665 int cc_get_nxt_ecm() { 666 struct s_client *cl = &client[cs_idx]; 666 667 int n, i; 667 668 time_t t; … … 670 671 n = -1; 671 672 for (i = 0; i < CS_MAXPENDING; i++) { 672 if ((t - (ulong) cl ient[cs_idx].ecmtask[i].tps.time > ((cfg->ctimeout + 500) / 1000)673 + 1) && (cl ient[cs_idx].ecmtask[i].rc >= 10)) // drop timeouts673 if ((t - (ulong) cl->ecmtask[i].tps.time > ((cfg->ctimeout + 500) / 1000) 674 + 1) && (cl->ecmtask[i].rc >= 10)) // drop timeouts 674 675 { 675 cl ient[cs_idx].ecmtask[i].rc = 0;676 } 677 678 if (cl ient[cs_idx].ecmtask[i].rc >= 10 && client[cs_idx].ecmtask[i].rc != 101) { // stil active and waiting676 cl->ecmtask[i].rc = 0; 677 } 678 679 if (cl->ecmtask[i].rc >= 10 && cl->ecmtask[i].rc != 101) { // stil active and waiting 679 680 // search for the ecm with the lowest time, this should be the next to go 680 if ((n < 0 || cl ient[cs_idx].ecmtask[n].tps.time - client[cs_idx].ecmtask[i].tps.time < 0)681 && &cl ient[cs_idx].ecmtask[n])681 if ((n < 0 || cl->ecmtask[n].tps.time - cl->ecmtask[i].tps.time < 0) 682 && &cl->ecmtask[n]) 682 683 n = i; 683 684 } … … 846 847 //cs_debug_mask(D_TRACE, "%s cc_send_ecm", getprefix()); 847 848 cc_cli_init_int(); 848 849 849 850 int n, h = -1; 850 851 struct cc_data *cc = cl->cc; … … 856 857 cs_ftime(&cur_time); 857 858 858 if (!cc || (cl ient[cs_idx].pfd < 1) || !rdr->tcp_connected) {859 if (!cc || (cl->pfd < 1) || !rdr->tcp_connected) { 859 860 if (er) { 860 861 er->rc = 0; 861 862 er->rcEx = 0x27; 862 863 cs_debug_mask(D_TRACE, "%s server not init! ccinit=%d pfd=%d", 863 getprefix(), cc ? 1 : 0, cl ient[cs_idx].pfd);864 getprefix(), cc ? 1 : 0, cl->pfd); 864 865 write_ecm_answer(rdr, fd_c2m, er); 865 866 } … … 924 925 return 0; // no queued ecms 925 926 } 926 cur_er = &cl ient[cs_idx].ecmtask[n];927 cur_er = &cl->ecmtask[n]; 927 928 cur_er->rc = 101; //mark ECM as already send 928 929 cs_debug("cccam: ecm-task %d", cur_er->idx); … … 1128 1129 for (i=1,n=1; i<CS_MAXPENDING; i++) 1129 1130 { 1130 if ((t-cl ient[cs_idx].ecmtask[i].tps.time > ((cfg->ctimeout + 500) / 1000) + 1) &&1131 (cl ient[cs_idx].ecmtask[i].rc>=10)) // drop timeouts1131 if ((t-cl->ecmtask[i].tps.time > ((cfg->ctimeout + 500) / 1000) + 1) && 1132 (cl->ecmtask[i].rc>=10)) // drop timeouts 1132 1133 { 1133 cl ient[cs_idx].ecmtask[i].rc=0;1134 cl->ecmtask[i].rc=0; 1134 1135 } 1135 1136 int td=abs(1000*(ecmtask[i].tps.time-cc->found->tps.time)+ecmtask[i].tps.millitm-cc->found->tps.millitm); … … 1207 1208 struct cc_data *cc = cl->cc; 1208 1209 1209 if (!cc || (cl ient[cs_idx].pfd < 1) || !rdr->tcp_connected) {1210 if (!cc || (cl->pfd < 1) || !rdr->tcp_connected) { 1210 1211 cs_log("%s server not init! ccinit=%d pfd=%d", getprefix(), cc ? 1 : 0, 1211 cl ient[cs_idx].pfd);1212 cl->pfd); 1212 1213 return 0; 1213 1214 } … … 1735 1736 } 1736 1737 1737 if (cl ient[cs_idx].is_server) //for reader only1738 if (cl->is_server) //for reader only 1738 1739 return ret; 1739 1740 … … 1768 1769 int i = 0; 1769 1770 for (i = 0; i < CS_MAXPENDING; i++) { 1770 if (cl ient[cs_idx].ecmtask[i].idx == ecm_idx)1771 cl ient[cs_idx].ecmtask[i].rc = 100; //Mark unused1771 if (cl->ecmtask[i].idx == ecm_idx) 1772 cl->ecmtask[i].rc = 100; //Mark unused 1772 1773 } 1773 1774 } … … 1785 1786 case MSG_CW_ECM: 1786 1787 cc->just_logged_in = 0; 1787 if (cl ient[cs_idx].is_server) { //SERVER:1788 if (cl->is_server) { //SERVER: 1788 1789 ECM_REQUEST *er; 1789 1790 … … 1851 1852 int i = 0; 1852 1853 for (i = 0; i < CS_MAXPENDING; i++) { 1853 if (cl ient[cs_idx].ecmtask[i].idx == ecm_idx)1854 cl ient[cs_idx].ecmtask[i].rc = 100; //Mark unused1854 if (cl->ecmtask[i].idx == ecm_idx) 1855 cl->ecmtask[i].rc = 100; //Mark unused 1855 1856 } 1856 1857 … … 1884 1885 case MSG_KEEPALIVE: 1885 1886 cc->just_logged_in = 0; 1886 if (!cl ient[cs_idx].is_server) {1887 if (!cl->is_server) { 1887 1888 cs_debug("cccam: keepalive ack"); 1888 1889 } else { … … 1897 1898 1898 1899 case MSG_CMD_05: 1899 if (!cl ient[cs_idx].is_server) {1900 if (!cl->is_server) { 1900 1901 cc->just_logged_in = 0; 1901 1902 l = l - 4;//Header Length=4 Byte … … 1938 1939 case MSG_EMM_ACK: { 1939 1940 cc->just_logged_in = 0; 1940 if (cl ient[cs_idx].is_server) { //EMM Request received1941 if (cl->is_server) { //EMM Request received 1941 1942 cc_cmd_send(NULL, 0, MSG_EMM_ACK); //Send back ACK 1942 1943 if (l > 4) { … … 2111 2112 NULLFREE(cbuf); 2112 2113 2113 if (!cl ient[cs_idx].is_server && (n == -1)) {2114 if (!cl->is_server && (n == -1)) { 2114 2115 cc_cli_close(); 2115 2116 } … … 2240 2241 rdr->last_g); 2241 2242 2242 cl ient[cs_idx].pfd = cl->udp_fd;2243 cs_debug("cccam: pfd=%d", cl ient[cs_idx].pfd);2243 cl->pfd = cl->udp_fd; 2244 cs_debug("cccam: pfd=%d", cl->pfd); 2244 2245 2245 2246 if (cc_send_cli_data() <= 0) { … … 2645 2646 struct cc_data *rcc = rc->cc; 2646 2647 2648 //reader connected? If not try to connect: 2649 if (!rcc || !rcc->cards || reader[r].tcp_connected != 2) { 2650 uchar dummy[1] = {0}; 2651 write_to_pipe(reader[r].fd, PIP_ID_CIN, dummy, 1); 2652 2653 //wait until all cards are received. No good solution here, maybe better later 2654 int j; 2655 for (j=0;j<10;j++) { 2656 cs_sleepms(100); 2657 if (reader[r].tcp_connected == 2) { 2658 cs_sleepms(50); 2659 break; 2660 } 2661 } 2662 rcc = rc->cc; 2663 } 2664 2665 int count = 0; 2647 2666 if (rcc && rcc->cards) { 2648 2667 pthread_mutex_lock(&rcc->cards_busy); … … 2650 2669 LLIST_ITR itr; 2651 2670 card = llist_itr_init(rcc->cards, &itr); 2652 int count = 0;2653 2671 while (card) { 2654 2672 if (card->hop <= maxhops && //card->maxdown > 0 && … … 2680 2698 } 2681 2699 pthread_mutex_unlock(&rcc->cards_busy); 2682 2683 cs_debug_mask(D_TRACE, "%s got %d cards from %s", getprefix(),2684 count, reader[r].label);2685 2700 } 2701 cs_debug_mask(D_TRACE, "%s got %d cards from %s", getprefix(), 2702 count, reader[r].label); 2686 2703 } 2687 2704 } … … 2775 2792 cl->cc_extended_ecm_mode = 0; 2776 2793 cc->cc_use_rc4 = 0; 2777 cl ient[cs_idx].is_server = 1;2794 cl->is_server = 1; 2778 2795 2779 2796 // calc + send random seed … … 2822 2839 cc_rc4_crypt(&block_rc4[DECRYPT], buf_rc4, 20, DECRYPT); 2823 2840 2824 if ((i = recv(cl ient[cs_idx].pfd, buf, 20, MSG_WAITALL)) == 20) {2841 if ((i = recv(cl->pfd, buf, 20, MSG_WAITALL)) == 20) { 2825 2842 cs_ddump(buf, 20, "cccam: recv:"); 2826 2843 memcpy(buf_rc4, buf, CC_MAXMSGSIZE); … … 2832 2849 2833 2850 // receive username 2834 if ((i = recv(cl ient[cs_idx].pfd, buf, 20, MSG_WAITALL)) == 20) {2851 if ((i = recv(cl->pfd, buf, 20, MSG_WAITALL)) == 20) { 2835 2852 memcpy(buf_rc4, buf, CC_MAXMSGSIZE); 2836 2853 cc_crypt(&cc->block[DECRYPT], buf, 20, DECRYPT); … … 2888 2905 // receive passwd / 'CCcam' 2889 2906 cc_crypt(&cc->block[DECRYPT], (uint8 *) pwd, strlen(pwd), DECRYPT); 2890 if ((i = recv(cl ient[cs_idx].pfd, buf, 6, MSG_WAITALL)) == 6) {2907 if ((i = recv(cl->pfd, buf, 6, MSG_WAITALL)) == 6) { 2891 2908 cc_crypt(&cc->block[DECRYPT], buf, 6, DECRYPT); 2892 2909 cs_ddump(buf, 6, "cccam: pwd check '%s':", buf); … … 2904 2921 cs_ddump(buf, 20, "cccam: send ack:"); 2905 2922 cc_crypt(&cc->block[ENCRYPT], buf, 20, ENCRYPT); 2906 send(cl ient[cs_idx].pfd, buf, 20, 0);2923 send(cl->pfd, buf, 20, 0); 2907 2924 2908 2925 // recv cli data … … 2970 2987 void cc_srv_init() { 2971 2988 struct s_client *cl = &client[cs_idx]; 2972 cl ient[cs_idx].pfd = cl->udp_fd;2989 cl->pfd = cl->udp_fd; 2973 2990 //cc_auth_client(cl->ip); 2974 2991 if (cc_srv_connect() < 0) … … 2989 3006 int p_proto; 2990 3007 2991 cl ient[cs_idx].pfd = 0;3008 cl->pfd = 0; 2992 3009 if (rdr->r_port <= 0) { 2993 3010 cs_log("%s invalid port %d for server %s", getprefix(), … … 3073 3090 } 3074 3091 3092 /** 3093 * 3094 * 3095 **/ 3096 void cc_card_info() { 3097 struct s_client *cl = &client[cs_idx]; 3098 struct s_reader *rdr = &reader[cl->ridx]; 3099 3100 if (!rdr->tcp_connected) 3101 cc_cli_init_int(); 3102 } 3103 3075 3104 void cc_cleanup(void) { 3076 3105 struct s_client *cl = &client[cs_idx]; 3077 if (!cl ient[cs_idx].is_server) {3106 if (!cl->is_server) { 3078 3107 cc_cli_close(); // we need to close open fd's 3079 3108 } … … 3099 3128 ph->send_dcw = cc_send_dcw; 3100 3129 ph->c_available = cc_available; 3130 ph->c_card_info = cc_card_info; 3101 3131 static PTAB ptab; //since there is always only 1 cccam server running, this is threadsafe 3102 3132 ptab.ports[0].s_port = cfg->cc_port; -
trunk/reader-common.c
r3182 r3197 230 230 } 231 231 } 232 if (reader->ph.c_card_info) 233 reader->ph.c_card_info(); 232 234 } 233 235
Note:
See TracChangeset
for help on using the changeset viewer.