Changeset 3166
- Timestamp:
- 09/22/10 19:11:11 (14 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/globals.h
r3162 r3166 192 192 193 193 #ifdef CS_CORE 194 char *PIP_ID_TXT[] = { "ECM", "EMM", "LOG", "CIN", "HUP", "RST", "KCL", "STA", "BES", "RES", "CCC",NULL };194 char *PIP_ID_TXT[] = { "ECM", "EMM", "LOG", "CIN", "HUP", "RST", "KCL", "STA", "BES", "RES", NULL }; 195 195 char *RDR_CD_TXT[] = { "cd", "dsr", "cts", "ring", "none", 196 196 #ifdef USE_GPIO … … 212 212 #define PIP_ID_BES 8 // Schlocke: Get best reader (param ECM_REQUEST, return to client with data int ridx) 213 213 #define PIP_ID_RES 9 // Schlocke: reset reader statistiks 214 #define PIP_ID_CCC 10 // Schlocke: Request card from reader 215 #define PIP_ID_DCW 11 216 #define PIP_ID_MAX PIP_ID_CCC 214 #define PIP_ID_DCW 10 215 #define PIP_ID_MAX PIP_ID_RES 217 216 218 217 … … 418 417 //int checktype (0=return connected, 1=return loadbalance-avail) return int 419 418 void (*c_idle)(); //Schlocke: called when reader is idle 420 void (*c_report_cards)(); //Schlocke: report cards (CCCam)421 419 int c_port; 422 420 PTAB *ptab; -
trunk/module-cccam.c
r3158 r3166 36 36 sprintf(cc->prefix, "cccam(s) %s: ", cl->usr); 37 37 else 38 sprintf(cc->prefix, "cccam(r) %s: ", reader[cl ient[cs_idx].ridx].label);38 sprintf(cc->prefix, "cccam(r) %s: ", reader[cl->ridx].label); 39 39 while (strlen(cc->prefix) < 22) 40 40 strcat(cc->prefix, " "); … … 346 346 void cc_cli_close() { 347 347 struct s_client *cl = &client[cs_idx]; 348 struct s_reader *rdr = &reader[cl ient[cs_idx].ridx];348 struct s_reader *rdr = &reader[cl->ridx]; 349 349 rdr->tcp_connected = 0; 350 350 rdr->card_status = NO_CARD; … … 369 369 pthread_mutex_unlock(&cc->lock); 370 370 pthread_mutex_unlock(&cc->ecm_busy); 371 pthread_mutex_unlock(&cc->cards_busy); 371 372 cc_clear_auto_blocked(cc->auto_blocked); 372 373 cc->just_logged_in = 0; … … 474 475 int cc_msg_recv(uint8 *buf) { 475 476 struct s_client *cl = &client[cs_idx]; 476 struct s_reader *rdr = cl ient[cs_idx].is_server?NULL:&reader[client[cs_idx].ridx];477 struct s_reader *rdr = cl->is_server?NULL:&reader[cl->ridx]; 477 478 478 479 int len; … … 536 537 int cc_cmd_send(uint8 *buf, int len, cc_msg_type_t cmd) { 537 538 struct s_client *cl = &client[cs_idx]; 538 struct s_reader *rdr = cl ient[cs_idx].is_server?NULL:&reader[client[cs_idx].ridx];539 struct s_reader *rdr = cl->is_server?NULL:&reader[cl->ridx]; 539 540 540 541 int n; … … 606 607 int cc_send_cli_data() { 607 608 struct s_client *cl = &client[cs_idx]; 608 struct s_reader *rdr = &reader[cl ient[cs_idx].ridx];609 struct s_reader *rdr = &reader[cl->ridx]; 609 610 610 611 int i; … … 640 641 int cc_send_srv_data() { 641 642 struct s_client *cl = &client[cs_idx]; 642 struct s_reader *rdr = &reader[cl ient[cs_idx].ridx];643 struct s_reader *rdr = &reader[cl->ridx]; 643 644 int i; 644 645 struct cc_data *cc = cl->cc; … … 697 698 int send_cmd05_answer() { 698 699 struct s_client *cl = &client[cs_idx]; 699 struct s_reader *rdr = &reader[cl ient[cs_idx].ridx];700 struct s_reader *rdr = &reader[cl->ridx]; 700 701 struct cc_data *cc = cl->cc; 701 702 if (!cc->cmd05_active || !rdr->available) //exit if not in cmd05 or waiting for ECM answer … … 848 849 int cc_send_ecm(ECM_REQUEST *er, uchar *buf) { 849 850 struct s_client *cl = &client[cs_idx]; 850 struct s_reader *rdr = &reader[cl ient[cs_idx].ridx];851 struct s_reader *rdr = &reader[cl->ridx]; 851 852 852 853 //cs_debug_mask(D_TRACE, "%s cc_send_ecm", getprefix()); … … 941 942 cur_srvid.ecmlen = cur_er->l; 942 943 944 pthread_mutex_lock(&cc->cards_busy); 943 945 //search cache: 944 946 current_card = cc_find_current_card_by_srvid(cc, cur_er->caid, … … 1069 1071 cs_hexdump(0, rdr->hexserial, 8), saprov); 1070 1072 } 1073 pthread_mutex_unlock(&cc->cards_busy); 1071 1074 1072 1075 return 0; … … 1113 1116 } 1114 1117 } 1118 pthread_mutex_unlock(&cc->cards_busy); 1115 1119 if (!cc->extended_mode) { 1116 1120 rdr->available = 1; … … 1151 1155 int cc_send_pending_emms() { 1152 1156 struct s_client *cl = &client[cs_idx]; 1153 struct s_reader *rdr = &reader[cl ient[cs_idx].ridx];1157 struct s_reader *rdr = &reader[cl->ridx]; 1154 1158 struct cc_data *cc = cl->cc; 1155 1159 … … 1204 1208 int cc_send_emm(EMM_PACKET *ep) { 1205 1209 struct s_client *cl = &client[cs_idx]; 1206 struct s_reader *rdr = &reader[cl ient[cs_idx].ridx];1210 struct s_reader *rdr = &reader[cl->ridx]; 1207 1211 1208 1212 cc_cli_init_int(); … … 1223 1227 1224 1228 //Last used card is first card of current_cards: 1229 pthread_mutex_lock(&cc->cards_busy); 1225 1230 LLIST_ITR itr; 1226 1231 struct cc_current_card *current_card = llist_itr_init(cc->current_cards, … … 1241 1246 cs_log("%s emm for client %d not possible, no card found!", 1242 1247 getprefix(), ep->cidx); 1248 pthread_mutex_unlock(&cc->cards_busy); 1243 1249 return 0; 1244 1250 } … … 1266 1272 emmbuf[11] = ep->l; 1267 1273 memcpy(emmbuf + 12, ep->emm, ep->l); 1274 1275 pthread_mutex_unlock(&cc->cards_busy); 1268 1276 1269 1277 llist_append(cc->pending_emms, emmbuf); … … 1386 1394 pthread_mutex_destroy(&cc->lock); 1387 1395 pthread_mutex_destroy(&cc->ecm_busy); 1396 pthread_mutex_destroy(&cc->cards_busy); 1388 1397 free(cc->prefix); 1389 1398 free(cc); … … 1447 1456 void cc_idle() { 1448 1457 struct s_client *cl = &client[cs_idx]; 1449 struct s_reader *rdr = &reader[cl ient[cs_idx].ridx];1458 struct s_reader *rdr = &reader[cl->ridx]; 1450 1459 struct cc_data *cc = cl->cc; 1451 1460 if (!rdr->tcp_connected) … … 1459 1468 cc->answer_on_keepalive = time(NULL); 1460 1469 } 1461 }1462 1463 /**1464 * write card-send-request request via pipe to the reader.1465 * reader then sends the cards by fifo-pipe1466 *1467 * THREADED: This function should be removed if using threaded1468 **/1469 int cc_request_server_cards(int ridx, int dest_cs_idx) {1470 char fname[40];1471 sprintf(fname, "%s/card%d-%d", get_tmp_dir(), ridx, dest_cs_idx);1472 unlink(fname);1473 mkfifo(fname, 0666);1474 //Request cards from server:1475 int data[2] = {ridx, dest_cs_idx};1476 write_to_pipe(fd_c2m, PIP_ID_CCC, (uchar*)data, sizeof(data));1477 1478 int pipe = open(fname, O_RDONLY);1479 if (pipe <= 0)1480 return 0;1481 else1482 return pipe;1483 }1484 1485 /**1486 * closes fifo-pipe1487 *1488 * THREADED: This function should be removed if using threaded1489 **/1490 void cc_close_request_server_cards(int pipe, int ridx, int dest_cs_idx) {1491 close(pipe);1492 char fname[40];1493 sprintf(fname, "%s/card%d-%d", get_tmp_dir(), ridx, dest_cs_idx);1494 unlink(fname);1495 1470 } 1496 1471 … … 1529 1504 1530 1505 #define READ_CARD_TIMEOUT 100 1531 1532 struct cc_card *read_card_from(int pipe) {1533 int size = 0;1534 uint8 buf[CC_MAXMSGSIZE];1535 1536 int n = read(pipe, &size, sizeof(size));1537 if (n < 0 || size <= 0 || size > CC_MAXMSGSIZE)1538 return NULL;1539 1540 n = read(pipe, buf, size);1541 if (n < 0 || n != size)1542 return NULL;1543 1544 return read_card(buf);1545 }1546 1506 1547 1507 int write_card(struct cc_data *cc, uint8 *buf, struct cc_card *card) { … … 1609 1569 int cc_parse_msg(uint8 *buf, int l) { 1610 1570 struct s_client *cl = &client[cs_idx]; 1611 struct s_reader *rdr = cl ient[cs_idx].is_server?NULL:&reader[client[cs_idx].ridx];1571 struct s_reader *rdr = cl->is_server?NULL:&reader[cl->ridx]; 1612 1572 1613 1573 int ret = buf[1]; … … 1707 1667 rdr->card_status = CARD_INSERTED; 1708 1668 1669 pthread_mutex_lock(&cc->cards_busy); 1670 1709 1671 struct cc_card *card = read_card(buf + 4); 1710 1672 … … 1734 1696 prov = llist_itr_next(&itr); 1735 1697 } 1698 1699 pthread_mutex_unlock(&cc->cards_busy); 1736 1700 //SS: Hack end 1737 1701 } … … 1739 1703 1740 1704 case MSG_CARD_REMOVED: { 1705 pthread_mutex_lock(&cc->cards_busy); 1741 1706 cc_card_removed(b2i(4, buf + 4)); 1707 pthread_mutex_unlock(&cc->cards_busy); 1742 1708 } 1743 1709 break; … … 2161 2127 int cc_cli_connect() { 2162 2128 struct s_client *cl = &client[cs_idx]; 2163 struct s_reader *rdr = &reader[cl ient[cs_idx].ridx];2129 struct s_reader *rdr = &reader[cl->ridx]; 2164 2130 2165 2131 int handle, n; … … 2209 2175 pthread_mutex_init(&cc->lock, NULL); 2210 2176 pthread_mutex_init(&cc->ecm_busy, NULL); 2177 pthread_mutex_init(&cc->cards_busy, NULL); 2211 2178 } 2212 2179 cc->ecm_counter = 0; … … 2678 2645 if (reader[r].typ == R_CCCAM && !flt && reader[r].fd) { 2679 2646 2680 cs_debug_mask(D_TRACE, "%s asking reader %s for cards...", getprefix(), reader[r].label); 2681 2647 cs_debug_mask(D_TRACE, "%s asking reader %s for cards...", 2648 getprefix(), reader[r].label); 2649 2682 2650 struct cc_card *card; 2683 int pipe = cc_request_server_cards(r, cs_idx); 2684 2685 //When reader has connection problems, client whould stuck! so we need to get sure he is connected AND has cards: 2686 int retry = 3; 2687 while (pipe && reader[r].tcp_connected != 2 && retry > 0) { 2688 cs_sleepms(200); 2689 retry--; 2690 } 2691 2692 int count = 0; 2693 while (reader[r].tcp_connected == 2 && pipe) 2694 { 2695 card = read_card_from(pipe); 2696 if (!card) break; 2697 2698 if (card->hop <= maxhops && //card->maxdown > 0 && 2699 chk_ctab(card->caid, &cl->ctab) && chk_ctab( 2700 card->caid, &reader[r].ctab)) { 2701 int ignore = 0; 2702 2703 LLIST_ITR itr_prov; 2704 struct cc_provider *prov = llist_itr_init(card->providers, 2705 &itr_prov); 2706 while (prov) { 2707 ulong prid = prov->prov; 2708 prov = llist_itr_next(&itr_prov); 2709 if (!chk_srvid_by_caid_prov(card->caid, prid, cs_idx) 2710 || !chk_srvid_by_caid_prov(card->caid, prid, 2711 reader[r].cidx)) { 2712 ignore = 1; 2713 break; 2651 struct s_client *rc = &client[reader[r].cidx]; 2652 struct cc_data *rcc = rc->cc; 2653 2654 if (rcc && rcc->cards) { 2655 pthread_mutex_lock(&rcc->cards_busy); 2656 2657 LLIST_ITR itr; 2658 card = llist_itr_init(rcc->cards, &itr); 2659 int count = 0; 2660 while (card) { 2661 if (card->hop <= maxhops && //card->maxdown > 0 && 2662 chk_ctab(card->caid, &cl->ctab) && chk_ctab( 2663 card->caid, &reader[r].ctab)) { 2664 int ignore = 0; 2665 2666 LLIST_ITR itr_prov; 2667 struct cc_provider *prov = llist_itr_init( 2668 card->providers, &itr_prov); 2669 while (prov) { 2670 ulong prid = prov->prov; 2671 prov = llist_itr_next(&itr_prov); 2672 if (!chk_srvid_by_caid_prov(card->caid, prid, 2673 cs_idx) || !chk_srvid_by_caid_prov( 2674 card->caid, prid, reader[r].cidx)) { 2675 ignore = 1; 2676 break; 2677 } 2678 } 2679 if (!ignore) { //Filtered by service 2680 card->maxdown = reshare; 2681 add_card_to_serverlist(server_cards, card); 2682 count++; 2714 2683 } 2715 2684 } 2716 if (!ignore) { //Filtered by service 2717 card->maxdown = reshare; 2718 add_card_to_serverlist(server_cards, card); 2719 count++; 2720 } 2685 2721 2686 } 2722 free(card); 2723 2687 pthread_mutex_unlock(&rcc->cards_busy); 2688 2689 cs_debug_mask(D_TRACE, "%s got %d cards from %s", getprefix(), 2690 count, reader[r].label); 2724 2691 } 2725 cc_close_request_server_cards(pipe, r, cs_idx);2726 cs_debug_mask(D_TRACE, "%s got %d cards from %s", getprefix(), count, reader[r].label);2727 2692 } 2728 2693 } … … 2782 2747 } 2783 2748 2784 void cc_cli_report_cards(int client_idx) {2785 struct s_client *cl = &client[cs_idx];2786 struct s_reader *rdr = &reader[client[cs_idx].ridx];2787 struct cc_data *cc = cl->cc;2788 int count = 0;2789 2790 uint8 buf[CC_MAXMSGSIZE];2791 sprintf((char*) buf, "%s/card%d-%d", get_tmp_dir(), client[client_idx].ridx, client_idx);2792 int pipe = open((char*) buf, O_WRONLY);2793 2794 cs_debug_mask(D_TRACE, "%s reporting cards...", rdr->label);2795 if (!cc || rdr->tcp_connected == 0) {2796 cc_cli_init_int();2797 cc = cl->cc;2798 }2799 2800 if (cc && rdr->tcp_connected == 2) {2801 2802 LLIST_ITR itr;2803 struct cc_card *card = llist_itr_init(cc->cards, &itr);2804 //cs_debug_mask(D_TRACE, "%s reporting server cards...", getprefix());2805 while (card) {2806 //cs_debug_mask(D_TRACE, "%s reporting server card %d", getprefix(), card->id);2807 int size = write_card(cc, buf, card);2808 write(pipe, &size, sizeof(size));2809 write(pipe, buf, size);2810 card = llist_itr_next(&itr);2811 count++;2812 }2813 }2814 //No (more) cards:2815 int n = 0;2816 write(pipe, &n, sizeof(n));2817 close(pipe);2818 cs_debug_mask(D_TRACE, "%s finished reporting %d server cards",2819 getprefix(), count);2820 }2821 2822 2749 int cc_srv_connect() { 2823 2750 struct s_client *cl = &client[cs_idx]; … … 2848 2775 pthread_mutex_init(&cc->lock, NULL); 2849 2776 pthread_mutex_init(&cc->ecm_busy, NULL); 2777 pthread_mutex_init(&cc->cards_busy, NULL); 2850 2778 } 2851 2779 cc->server_ecm_pending = 0; … … 3060 2988 int cc_cli_init_int() { 3061 2989 struct s_client *cl = &client[cs_idx]; 3062 struct s_reader *rdr = &reader[cl ient[cs_idx].ridx];2990 struct s_reader *rdr = &reader[cl->ridx]; 3063 2991 if (rdr->tcp_connected) 3064 2992 return -1; … … 3177 3105 ph->send_dcw = cc_send_dcw; 3178 3106 ph->c_available = cc_available; 3179 ph->c_report_cards = cc_cli_report_cards;3180 3107 static PTAB ptab; 3181 3108 ptab.ports[0].s_port = cfg->cc_port; -
trunk/module-cccam.h
r3156 r3166 152 152 pthread_mutex_t lock; 153 153 pthread_mutex_t ecm_busy; 154 pthread_mutex_t cards_busy; 154 155 struct timeb ecm_time; 155 156 time_t answer_on_keepalive; … … 172 173 173 174 struct cc_card *read_card_from(int pipe); 174 int cc_request_server_cards(int ridx, int dest_cs_idx);175 void cc_close_request_server_cards(int pipe, int ridx, int dest_cs_idx);176 175 177 176 #endif /* MODULECCCAM_H_ */ -
trunk/oscam-http.c
r3165 r3166 1641 1641 if (reader[ridx].typ == R_CCCAM) { 1642 1642 1643 int pipe = cc_request_server_cards(ridx, cs_idx); 1644 if (pipe) { 1645 int caidcount = 0; 1646 1647 char *provider = ""; 1648 1649 struct cc_card *card; 1650 while ((card = read_card_from(pipe))) { 1643 int caidcount = 0; 1644 1645 char *provider = ""; 1646 1647 struct cc_card *card; 1648 struct s_client *rc = &client[reader[ridx].cidx]; 1649 struct cc_data *rcc = rc->cc; 1650 1651 if (rcc && rcc->cards) { 1652 pthread_mutex_lock(&rcc->cards_busy); 1653 1654 LLIST_ITR itr; 1655 card = llist_itr_init(rcc->cards, &itr); 1656 while (card) { 1657 1651 1658 tpl_printf(vars, 1, "LOGHISTORY", 1652 1659 "caid: %04X hop: %d<BR>\n", card->caid, card->hop); … … 1654 1661 int provcount = 0; 1655 1662 LLIST_ITR itr; 1656 struct cc_provider *prov = llist_itr_init(card->providers, &itr); 1663 struct cc_provider *prov = llist_itr_init(card->providers, 1664 &itr); 1657 1665 while (prov) { 1658 1666 provider = get_provider(card->caid, prov->prov); … … 1667 1675 tpl_addVar(vars, 1, "LOGHISTORY", "<BR>\n"); 1668 1676 caidcount++; 1669 1670 cc_free_card(card); 1677 card = llist_itr_next(&itr); 1671 1678 } 1672 cc_close_request_server_cards(pipe, ridx, cs_idx); 1673 1674 if (caidcount) 1675 tpl_printf(vars, 1, "LOGSUMMARY", 1676 "<BR>%d caid found on this reader<BR><BR>\n", 1677 caidcount); 1678 1679 tpl_printf(vars, 1, "LOGHISTORY", "cardfile end<BR>\n"); 1680 1679 pthread_mutex_unlock(&rcc->cards_busy); 1680 1681 if (caidcount) 1682 tpl_printf(vars, 1, "LOGSUMMARY", 1683 "<BR>%d caid found on this reader<BR><BR>\n", caidcount); 1684 1685 tpl_printf(vars, 1, "LOGHISTORY", "cardfile end<BR>\n"); 1681 1686 } else { 1682 1687 tpl_printf(vars, 1, "LOGHISTORY", "no cardfile found<BR>\n"); -
trunk/oscam-reader.c
r3153 r3166 663 663 } 664 664 665 void reader_ext_card_info(struct s_reader * reader, int *data) {666 //data[0] = ridx, data[1] = dest_cs_idx667 if (reader->ph.c_report_cards)668 reader->ph.c_report_cards(data[1]);669 }670 671 665 static void reader_do_pipe(struct s_reader * reader) 672 666 { … … 688 682 reader_card_info(reader); 689 683 break; 690 case PIP_ID_CCC:691 reader_ext_card_info(reader, (int*)ptr);692 break;693 684 } 694 685 }
Note:
See TracChangeset
for help on using the changeset viewer.