- Timestamp:
- 12/17/17 22:09:03 (6 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/module-gbox-cards.c
r11354 r11395 509 509 } 510 510 511 uint8_t gbox_get_cards_for_ecm(uchar *send_buf _1, int32_t cont_1, uint8_t max_cards, ECM_REQUEST *er, uint32_t *current_avg_card_time, uint16_t peer_id)512 { 513 if (!send_buf_1|| !er)514 515 516 uint8_t cont_card_1= 0;517 518 519 uint8_t enough = 0; 520 521 522 523 524 cs_readlock(__func__, &gbox_cards_lock); 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 { cont_1 = cont_1- 3; }548 549 550 cont_card_1++;551 552 553 554 i2b_buf(2, card->id.peer, send_buf_1 + cont_1);555 send_buf_1[cont_1+ 2] = card->id.slot;556 cont_1 = cont_1+ 3;557 558 559 560 561 562 563 if(cont_card_1== max_cards)564 565 566 511 uint8_t gbox_get_cards_for_ecm(uchar *send_buf, int32_t len2, uint8_t max_cards, ECM_REQUEST *er, uint32_t *current_avg_card_time, uint16_t peer_id) 512 { 513 if (!send_buf || !er) 514 { return 0; } 515 516 uint8_t nb_matching_crds = 0; 517 struct gbox_good_srvid *srvid_good = NULL; 518 struct gbox_bad_srvid *srvid_bad = NULL; 519 uint8_t enough = 0; 520 uint8_t sid_verified = 0; 521 time_t time_since_lastcw; 522 523 //loop over good only 524 cs_readlock(__func__, &gbox_cards_lock); 525 LL_ITER it = ll_iter_create(gbox_cards); 526 LL_ITER it2; 527 struct gbox_card *card; 528 529 while((card = ll_iter_next(&it))) 530 { 531 if(card->origin_peer && card->origin_peer->gbox.id == peer_id && card->type == GBOX_CARD_TYPE_GBOX && 532 gbox_get_caid(card->caprovid) == er->caid && gbox_get_provid(card->caprovid) == er->prid && !is_already_pending(er->gbox_cards_pending, card->id.peer, card->id.slot)) 533 { 534 sid_verified = 0; 535 536 //check if sid is good 537 it2 = ll_iter_create(card->goodsids); 538 while((srvid_good = ll_iter_next(&it2))) 539 { 540 if(srvid_good->srvid.provid_id == er->prid && srvid_good->srvid.sid == er->srvid) 541 { 542 if (!enough || *current_avg_card_time > card->average_cw_time) 543 { 544 time_since_lastcw = llabs(srvid_good->last_cw_received - time(NULL)); 545 *current_avg_card_time = card->average_cw_time; 546 if (enough) 547 { len2 = len2 - 3; } 548 else 549 { 550 nb_matching_crds++; 551 if (time_since_lastcw < GBOX_SID_CONFIRM_TIME && er->gbox_ecm_status == GBOX_ECM_NOT_ASKED) 552 { enough = 1; } 553 } 554 i2b_buf(2, card->id.peer, send_buf + len2); 555 send_buf[len2 + 2] = card->id.slot; 556 len2 = len2 + 3; 557 sid_verified = 1; 558 break; 559 } 560 } 561 } 562 563 if(nb_matching_crds == max_cards) 564 { break; } 565 } 566 } 567 567 cs_readunlock(__func__, &gbox_cards_lock); 568 568 … … 610 610 if(sid_verified != 1) 611 611 { 612 i2b_buf(2, card->id.peer, send_buf _1 + cont_1);613 send_buf _1[cont_1+ 2] = card->id.slot;614 cont_1 = cont_1+ 3;615 cont_card_1++;612 i2b_buf(2, card->id.peer, send_buf + len2); 613 send_buf[len2 + 2] = card->id.slot; 614 len2 = len2 + 3; 615 nb_matching_crds++; 616 616 617 617 if (!sid_verified) … … 633 633 } 634 634 635 if( cont_card_1== max_cards)635 if(nb_matching_crds == max_cards) 636 636 { break; } 637 637 } 638 638 } 639 639 cs_writeunlock(__func__, &gbox_cards_lock); 640 return cont_card_1;640 return nb_matching_crds; 641 641 } 642 642 -
trunk/module-gbox-cards.h
r11354 r11395 25 25 void gbox_remove_bad_sid(uint16_t id_peer, uint8_t id_slot, uint16_t sid); 26 26 uint8_t gbox_next_free_slot(uint16_t id); 27 uint8_t gbox_get_cards_for_ecm(uchar *send_buf _1, int32_t cont_1, uint8_t max_cards, ECM_REQUEST *er, uint32_t *current_avg_card_time, uint16_t peer_id);27 uint8_t gbox_get_cards_for_ecm(uchar *send_buf, int32_t len2, uint8_t max_cards, ECM_REQUEST *er, uint32_t *current_avg_card_time, uint16_t peer_id); 28 28 #endif 29 29 -
trunk/module-gbox.c
r11381 r11395 1019 1019 switch(cmd) 1020 1020 { 1021 case MSG_ BOXINFO:1021 case MSG_HERE: 1022 1022 cs_log("-> HERE? from %s %s",username(proxy), proxy->reader->device); 1023 1023 gbox_send_hello(proxy, GBOX_STAT_HELLOR); … … 1028 1028 //TODO: implement on suitable place - rebroadcast ECM to other peers 1029 1029 write_msg_info(proxy, MSGID_GOODBYE, 0, 0); 1030 break;1031 case MSG_UNKNWN:1032 cs_log("-> MSG_UNKNWN 48F9 from %s %s", username(proxy), proxy->reader->device);1033 write_msg_info(proxy, MSGID_UNKNOWNMSG, 0, 0);1034 1030 break; 1035 1031 case MSG_GSMS: … … 1071 1067 default: 1072 1068 cs_log("-> unknown command %04X received from %s %s", cmd, username(proxy), proxy->reader->device); 1069 write_msg_info(proxy, MSGID_UNKNOWNMSG, 0, 0); 1073 1070 cs_log_dump_dbg(D_READER, data, n, "unknown data (%d bytes) receivrd from %s %s", n, username(proxy), proxy->reader->device); 1074 1071 } // end switch … … 1378 1375 i2b_buf(2, ere->gbox_peer, buf + 39); //Target peer 1379 1376 if (er->rc == E_CACHE1 || er->rc == E_CACHE2 || er->rc == E_CACHEEX) 1380 { buf[41] = 0x03; } // cache1377 { buf[41] = 0x03; } //source of cw -> cache 1381 1378 else 1382 { buf[41] = 0x01; } // card, emu, needs probably further investigation1379 { buf[41] = 0x01; } //source of cw -> card, emu 1383 1380 buf[42] = 0x30; //1st nibble unknown / 2nd nibble distance 1381 //buf[42] = 0x30 | (ere->gbox_hops & 0x0f); 1384 1382 buf[43] = ere->gbox_unknown; //meaning unknown, copied from ECM request 1385 1383 … … 1393 1391 */ 1394 1392 gbox_send(cli, buf, ere->gbox_hops + 44); 1395 1396 1393 cs_log_dbg(D_READER, "<- CW (<- %d) to %04X %s port:%d", ere->gbox_hops, ere->gbox_peer, cli->reader->label, cli->port); 1397 1394 } … … 1442 1439 } 1443 1440 */ 1441 1444 1442 static int32_t gbox_send_ecm(struct s_client *cli, ECM_REQUEST *er) 1445 1443 { … … 1455 1453 1456 1454 struct gbox_peer *peer = cli->gbox; 1457 int32_t cont_1; 1458 1455 1459 1456 if(!peer->filtered_cards) 1460 1457 { 1461 cs_log_dbg(D_READER, " %s NO CARDS!", cli->reader->label);1458 cs_log_dbg(D_READER, "Send ECM failed, %s NO CARDS!", cli->reader->label); 1462 1459 write_ecm_answer(cli->reader, er, E_NOTFOUND, E2_CCCAM_NOCARD, NULL, NULL, 0, NULL); 1463 1460 return -1; … … 1466 1463 if(!peer->online) 1467 1464 { 1468 cs_log_dbg(D_READER, " peer is OFFLINE!");1465 cs_log_dbg(D_READER, "Send ECM failed, peer is OFFLINE!"); 1469 1466 write_ecm_answer(cli->reader, er, E_NOTFOUND, 0x27, NULL, NULL, 0, NULL); 1470 1467 // gbox_send_hello(cli,0); … … 1485 1482 } 1486 1483 1487 uchar send_buf _1[1024];1488 int32_t len2;1484 uchar send_buf[1024]; 1485 int32_t buflen, len1; 1489 1486 1490 1487 if(!er->ecmlen) { return 0; } 1491 1488 1492 len 2 = er->ecmlen + 18;1489 len1 = er->ecmlen + 18; // length till end of ECM 1493 1490 er->gbox_crc = gbox_get_ecmchecksum(&er->ecm[0], er->ecmlen); 1494 1491 1495 memset(send_buf _1, 0, sizeof(send_buf_1));1496 1497 uint8_t cont_card_1= 0;1498 1499 uint32_t current_avg_card_time = 0; 1500 1501 gbox_message_header(send_buf _1, MSG_ECM , peer->gbox.password, local_gbox.password);1502 1503 i2b_buf(2, er->pid, send_buf _1+ 10);1504 i2b_buf(2, er->srvid, send_buf _1+ 12);1505 send_buf _1[14] = 0x00;1506 send_buf _1[15] = 0x00;1507 1508 send_buf _1[16] = cont_card_1;1509 send_buf _1[17] = 0x00;1510 1511 memcpy(send_buf _1+ 18, er->ecm, er->ecmlen);1512 1513 i2b_buf(2, local_gbox.id, send_buf _1 + len2);1514 1515 send_buf _1[len2+ 2] = cfg.gbox_my_vers;1516 send_buf _1[len2+ 3] = 0x00;1517 send_buf _1[len2+ 4] = gbox_get_my_cpu_api();1492 memset(send_buf, 0, sizeof(send_buf)); 1493 1494 uint8_t nb_matching_crds = 0; 1495 uint8_t max_ecm_reached = 0; 1496 uint32_t current_avg_card_time = 0; 1497 1498 gbox_message_header(send_buf, MSG_ECM , peer->gbox.password, local_gbox.password); 1499 1500 i2b_buf(2, er->pid, send_buf + 10); 1501 i2b_buf(2, er->srvid, send_buf + 12); 1502 send_buf[14] = 0x00; 1503 send_buf[15] = 0x00; 1504 1505 send_buf[16] = nb_matching_crds; //Number of cards the ECM should be forwarded to 1506 send_buf[17] = 0x00; 1507 1508 memcpy(send_buf + 18, er->ecm, er->ecmlen); 1509 1510 i2b_buf(2, local_gbox.id, send_buf + len1); 1511 1512 send_buf[len1 + 2] = cfg.gbox_my_vers; 1513 send_buf[len1 + 3] = 0x00; 1514 send_buf[len1 + 4] = gbox_get_my_cpu_api(); 1518 1515 1519 1516 uint32_t caprovid = gbox_get_caprovid(er->caid, er->prid); 1520 i2b_buf(4, caprovid, send_buf _1 + len2+ 5);1521 1522 send_buf _1[len2+ 9] = 0x00;1523 cont_1 = len2+ 10;1524 1525 cont_card_1 = gbox_get_cards_for_ecm(&send_buf_1[0], len2+ 10, cli->reader->gbox_maxecmsend, er, ¤t_avg_card_time, peer->gbox.id);1526 if ( cont_card_1== cli->reader->gbox_maxecmsend)1517 i2b_buf(4, caprovid, send_buf + len1 + 5); 1518 1519 send_buf[len1 + 9] = 0x00; 1520 buflen = len1 + 10; 1521 1522 nb_matching_crds = gbox_get_cards_for_ecm(&send_buf[0], len1 + 10, cli->reader->gbox_maxecmsend, er, ¤t_avg_card_time, peer->gbox.id); 1523 if (nb_matching_crds == cli->reader->gbox_maxecmsend) 1527 1524 { max_ecm_reached = 1; } 1528 cont_1 += cont_card_1* 3;1525 buflen += nb_matching_crds * 3; 1529 1526 1530 if(! cont_card_1&& er->gbox_ecm_status == GBOX_ECM_NOT_ASKED)1527 if(!nb_matching_crds && er->gbox_ecm_status == GBOX_ECM_NOT_ASKED) 1531 1528 { 1532 1529 cs_log_dbg(D_READER, "no valid card found for CAID: %04X PROVID: %04X", er->caid, er->prid); … … 1534 1531 return -1; 1535 1532 } 1536 if(cont_card_1) 1537 { 1538 send_buf_1[16] = cont_card_1; 1539 1540 //Hops 1541 send_buf_1[cont_1] = 0; 1542 cont_1++; 1543 1544 memcpy(&send_buf_1[cont_1], gbox_get_my_checkcode(), 7); 1545 cont_1 = cont_1 + 7; 1546 memcpy(&send_buf_1[cont_1], peer->checkcode, 7); 1547 cont_1 = cont_1 + 7; 1548 1549 cs_log_dbg(D_READER, "gbox sending ecm for %04X@%06X:%04X to %d cards -> %s", er->caid, er->prid , er->srvid, cont_card_1, cli->reader->label); 1533 if(nb_matching_crds) 1534 { 1535 send_buf[16] = nb_matching_crds; 1536 1537 //distance ECM 1538 send_buf[buflen] = 0; //fix me! if ecm to be forwarded -> must add +1 1539 buflen++; 1540 1541 memcpy(&send_buf[buflen], gbox_get_my_checkcode(), 7); 1542 buflen = buflen + 7; 1543 memcpy(&send_buf[buflen], peer->checkcode, 7); 1544 buflen = buflen + 7; 1545 1550 1546 uint32_t i = 0; 1551 1547 struct gbox_card_pending *pending = NULL; 1552 1548 struct timeb t_now; 1553 1549 cs_ftime(&t_now); 1554 for (i = 0; i < cont_card_1; i++)1550 for (i = 0; i < nb_matching_crds; i++) 1555 1551 { 1556 1552 if(!cs_malloc(&pending, sizeof(struct gbox_card_pending))) … … 1559 1555 return -1; 1560 1556 } 1561 pending->id.peer = (send_buf _1[len2+10+i*3] << 8) | send_buf_1[len2+11+i*3];1562 pending->id.slot = send_buf _1[len2+12+i*3];1557 pending->id.peer = (send_buf[len1+10+i*3] << 8) | send_buf[len1+11+i*3]; 1558 pending->id.slot = send_buf[len1+12+i*3]; 1563 1559 pending->pending_time = comp_timeb(&t_now, &er->tps); 1564 ll_append(er->gbox_cards_pending, pending); 1565 cs_log_dbg(D_READER, " gbox card %d: ID: %04X, Slot: %02X", i+1, (send_buf_1[len2+10+i*3] << 8) | send_buf_1[len2+11+i*3], send_buf_1[len2+12+i*3]);1560 ll_append(er->gbox_cards_pending, pending); 1561 cs_log_dbg(D_READER, "matching gbox card(s): %d, ID: %04X, Slot: %02X", i+1, (send_buf[len1+10+i*3] << 8) | send_buf[len1+11+i*3], send_buf[len1+12+i*3]); 1566 1562 } 1567 1563 … … 1579 1575 else 1580 1576 { er->gbox_ecm_status = GBOX_ECM_SENT_ALL; } 1581 cli->pending++; 1582 } 1583 gbox_send(cli, send_buf_1, cont_1); 1577 cli->pending++; 1578 } 1579 cs_log_dbg(D_READER, "sending ecm for %04X@%06X sid: %04X to %d card(s) of %s", er->caid, er->prid , er->srvid, nb_matching_crds, cli->reader->label); 1580 gbox_send(cli, send_buf, buflen); 1584 1581 cli->reader->last_s = time((time_t *) 0); 1582 1585 1583 /* // see r11270 1586 1584 if(er->gbox_ecm_status < GBOX_ECM_ANSWERED) … … 1778 1776 } 1779 1777 /* 1780 //static void gbox_send_HERE(struct s_client *cli) 1781 static void gbox_send_boxinfo(struct s_client *cli) 1778 static void gbox_send_HERE(struct s_client *cli) 1782 1779 { 1783 1780 struct gbox_peer *peer = cli->gbox; 1784 uchar outbuf[3 0];1781 uchar outbuf[32]; 1785 1782 int32_t hostname_len = strlen(cfg.gbox_hostname); 1786 gbox_message_header(outbuf, MSG_ BOXINFO, peer->gbox.password, local_gbox.password);1783 gbox_message_header(outbuf, MSG_HERE, peer->gbox.password, local_gbox.password); 1787 1784 outbuf[0xA] = cfg.gbox_my_vers; 1788 1785 outbuf[0xB] = gbox_get_my_cpu_api(); … … 1803 1800 if (proxy && proxy->gbox) 1804 1801 { 1805 if (llabs(proxy->last - time(NULL)) > llabs(cl->lastecm - time(NULL))) 1806 { ptime_elapsed = llabs(cl->lastecm - time(NULL)); } 1807 else { ptime_elapsed = llabs(proxy->last - time(NULL)); } 1802 etime_elapsed = llabs(cl->lastecm - time(NULL)); 1803 if (llabs(proxy->last - time(NULL)) > etime_elapsed ) 1804 { ptime_elapsed = etime_elapsed; } 1805 else 1806 { ptime_elapsed = llabs(proxy->last - time(NULL)); } 1807 1808 1808 if (ptime_elapsed > (cfg.gbox_reconnect *2) && cl->gbox_peer_id != NO_GBOX_ID) 1809 1809 { … … 1811 1811 peer = proxy->gbox; 1812 1812 cs_writelock(__func__, &peer->lock); 1813 cs_log_dbg(D_READER, "time since last proxy activity: %d sec => lost connection - taking peer %04X - %s offline", ptime_elapsed, cl->gbox_peer_id, username(cl));1814 1813 if (peer->online) 1815 1814 { 1816 1815 cs_log("Lost connection to: %s %s - taking peer %04X %s offline",proxy->reader->device, cs_inet_ntoa(proxy->ip), cl->gbox_peer_id, username(cl)); 1816 cs_log_dbg(D_READER, "time since last proxy activity: %d sec > %d => lost connection - taking peer %04X - %s offline", ptime_elapsed, cfg.gbox_reconnect *2, cl->gbox_peer_id, username(cl)); 1817 1817 write_msg_info(proxy, MSGID_LOSTCONNECT, 0, 0); 1818 1818 gbox_reinit_proxy(proxy); … … 1821 1821 } 1822 1822 1823 etime_elapsed = llabs(cl->lastecm - time(NULL));1824 1823 if (etime_elapsed > cfg.gbox_reconnect && cl->gbox_peer_id != NO_GBOX_ID) 1825 1824 { … … 1829 1828 if (!(check_peer_ignored(cl->gbox_peer_id))) 1830 1829 { 1831 if (!peer->online && !(ptime_elapsed > cfg.gbox_reconnect *5))1830 if (!peer->online && ptime_elapsed < cfg.gbox_reconnect *3) 1832 1831 { 1833 cs_log_dbg(D_READER, "%04X - %s : time since last ecm: %d sec => trigger keepalive HELLOL", cl->gbox_peer_id, username(cl), etime_elapsed);1832 cs_log_dbg(D_READER, "%04X - %s -> offline - time since last ecm / proxy_act: %d sec / %d sec => trigger HELLOL", cl->gbox_peer_id, username(cl), etime_elapsed, ptime_elapsed); 1834 1833 gbox_send_hello(proxy, GBOX_STAT_HELLOL); 1835 1834 //gbox_send_HERE(proxy); … … 1837 1836 if (peer->online) 1838 1837 { 1839 cs_log_dbg(D_READER, "%04X - %s : time since last ecm: %d sec => trigger keepalive HELLOS", cl->gbox_peer_id, username(cl), etime_elapsed);1838 cs_log_dbg(D_READER, "%04X - %s -> online - time since last ecm /proxy activity: %d sec / %d sec => trigger keepalive HELLOS", cl->gbox_peer_id, username(cl), etime_elapsed, ptime_elapsed); 1840 1839 gbox_send_hello(proxy, GBOX_STAT_HELLOS); 1841 1840 } -
trunk/module-gbox.h
r11378 r11395 26 26 #define MSG_GSMS_ACK 0x9099 27 27 #define MSG_GSMS 0x0FFF 28 #define MSG_BOXINFO 0xA0A1 29 #define MSG_UNKNWN 0x48F9 28 #define MSG_HERE 0xA0A1 30 29 31 30 #define GBOX_ECM_NOT_ASKED 0 -
trunk/oscam.c
r11386 r11395 1895 1895 // Cleanup 1896 1896 #ifdef MODULE_GBOX 1897 stop_sms_sender(); 1897 if(!cfg.gsms_dis) 1898 { stop_sms_sender(); } 1898 1899 #endif 1899 1900 webif_close();
Note:
See TracChangeset
for help on using the changeset viewer.