Changeset 11281


Ignore:
Timestamp:
Nov 20, 2016, 6:30:58 PM (3 years ago)
Author:
felixka
Message:

gbx:

  • Fix for local card with caprovid 00000000. Happens when oscam is patched with emu
  • Add log/msg for peer on-offline, authentication and connection lost
  • Add OSD notification for incoming GSMS
  • OSD feature enabled by suitable 'msg.osd' in tmp_dir
  • Add and update some debug log outputs
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/module-gbox-cards.c

    r11221 r11281  
    252252                if (card->caprovid == caprovid && card->id.peer == id_peer && card->id.slot == slot)
    253253                {
    254                         cs_log_dbg(D_READER, "getting backup card: %04X\n", card->id.peer);
     254                        cs_log_dbg(D_READER, "backup card from peer: %04X %08X", card->id.peer, card->caprovid );
    255255                        ll_remove(gbox_backup_cards, card);
    256256                        card->origin_peer = origin_peer;
     
    270270        uint32_t provid = gbox_get_provid(caprovid);
    271271
     272                if(!caprovid)   //skip caprov 00000000
     273                    { return; }
    272274        //don't insert 0100:000000
    273275        if(caid_is_seca(caid) && (!provid))
     
    285287                        return;
    286288                }
    287                 cs_log_dbg(D_READER, "new card: %04X\n", id_peer);
     289                cs_log_dbg(D_READER, "new card from peer: %04X %08X", id_peer, caprovid);
    288290                card->caprovid = caprovid;
    289291                card->id.peer = id_peer;
     
    363365                if (found)
    364366                {
    365                         cs_log_dbg(D_READER, "remove card: %04X\n", card->id.peer);
     367                        cs_log_dbg(D_READER, "remove card from peer: %04X %08X", card->id.peer, card->caprovid);
    366368                        ll_remove(gbox_cards, card);
    367369                        ll_append(gbox_backup_cards, card);
     
    436438                        srvid->srvid.provid_id = gbox_get_provid(card->caprovid);
    437439                        srvid->last_cw_received = time(NULL);
    438                         cs_log_dbg(D_READER, "Adding good SID: %04X for CAID: %04X Provider: %04X on CardID: %04X\n", sid_ok, caid, gbox_get_provid(card->caprovid), id_card);
     440                        cs_log_dbg(D_READER, "Adding good SID: %04X for CAID: %04X Provider: %04X on CardID: %04X", sid_ok, caid, gbox_get_provid(card->caprovid), id_card);
    439441                        ll_append(card->goodsids, srvid);
    440442                        break;
  • trunk/module-gbox-helper.c

    r10639 r11281  
    259259        *unpacked_len = 0x40000;
    260260        lzo_init();
    261         cs_log_dbg(D_READER, "decompressing %d bytes", len);
     261        cs_log_dbg(D_READER, "-> data decompressing %d bytes", len);
    262262        if((err = lzo1x_decompress_safe(buf + 12, len, tmp, (lzo_uint *)unpacked_len, NULL)) != LZO_E_OK)
    263263                { cs_log_dbg(D_READER, "gbox: decompression failed! errno=%d", err); }
  • trunk/module-gbox-sms.c

    r11232 r11281  
    5858static void write_gsms_to_osd_file(struct s_client *cli, unsigned char *gsms)
    5959{
    60 #ifdef GBOX_ENABLE_UNSAFE_OSD
     60#ifdef GBOX_ENABLE_UNSAFE_EXTENDED_OSD
    6161    char *fext= FILE_OSD_MSG;
    6262    char *fname = get_gbox_tmp_fname(fext);
     
    7777    }
    7878#else
    79     cs_log("OSD: username=%s dev=%s msg=%s", username(cli), cli->reader->device, gsms);
    80     cs_log_dbg(D_READER, "OSD is disabled because it is a security risk, to enable it recompile OSCAM.");
     79    cs_log_dbg(D_READER, "Extended OSD disabled. OSD: username=%s dev=%s msg=%s", username(cli), cli->reader->device, gsms);
    8180#endif
    8281    return;
     
    188187                outbuf[11] = peer->gbox.id & 0xff;
    189188                outbuf[12] = (local_gbox_id >> 8) & 0xff;
    190                 outbuf[13] = local_gbox_id & 0xff;                             
     189                outbuf[13] = local_gbox_id & 0xff;
    191190                outbuf[14] = msg_type; //msg type
    192191                outbuf[15] = gsms_len; // gsms length
  • trunk/module-gbox.c

    r11279 r11281  
    109109}
    110110
    111 static void write_msg_to_osd (struct s_client *cli, uint8_t msg_id)
    112 {
     111static void write_msg_to_osd (struct s_client *cli, uint8_t msg_id, uint16_t misc)
     112{
     113    #ifdef GBOX_ENABLE_UNSAFE_EXTENDED_OSD
     114    if (msg_id == MSGID_GSMS && misc == 0x31) {return;}
     115    #endif
    113116    char *fext= FILE_MSG_OSD;
    114117    char *fname = get_gbox_tmp_fname(fext);
    115118    if (file_exists(fname))
    116119    {
    117         char buf[50];
     120        char buf[120];
    118121        memset(buf, 0, sizeof(buf));
    119         snprintf(buf, sizeof(buf), "%s %d %s %s", fname, msg_id, username(cli), cli->reader->device);
    120         cs_log_dbg(D_READER, "found driver %s - write msg (id= %d) from %s %s to OSD", fname, msg_id, username(cli),cli->reader->device);
     122        snprintf(buf, sizeof(buf), "%s %d %s %s %s %d", fname, msg_id, username(cli), cli->reader->device, cs_inet_ntoa(cli->ip), misc);
     123        cs_log_dbg(D_READER, "found driver %s - write msg (id = %d) ref %s %s", fname, msg_id, username(cli),cli->reader->device);
    121124        char *cmd = buf;
    122125        FILE *p;
     
    148151        {
    149152            struct gbox_peer *peer = cl->gbox;
     153
    150154            if (peer->online)
    151                 { fprintf(fhandle, "1 %s %s %04X 2.%02X\n",cl->reader->device, cs_inet_ntoa(cl->ip),peer->gbox.id, peer->gbox.minor_version); }
     155                {
     156                    fprintf(fhandle, "1 %s %s %04X 2.%02X\n",cl->reader->device, cs_inet_ntoa(cl->ip),peer->gbox.id, peer->gbox.minor_version);
     157                        if (!peer->onlinestat)
     158                        {
     159                        peer->onlinestat = 1;
     160                        cs_log("comeONLINE: %s  %s  boxid: %04X  v2.%02X  cards:%d",cl->reader->device, cs_inet_ntoa(cl->ip),peer->gbox.id, peer->gbox.minor_version, peer->filtered_cards);
     161                        write_msg_to_osd(cl, MSGID_COMEONLINE, peer->filtered_cards);
     162                        }
     163                }
    152164            else
    153                 { fprintf(fhandle, "0 %s %s %04X 0.00\n",cl->reader->device, cs_inet_ntoa(cl->ip),peer->gbox.id); }
     165                {
     166                    fprintf(fhandle, "0 %s %s %04X 0.00\n",cl->reader->device, cs_inet_ntoa(cl->ip),peer->gbox.id);
     167                        if (peer->onlinestat)
     168                        {
     169                        peer->onlinestat = 0;
     170                        cs_log("goneOFFLINE: %s  %s  boxid: %04X",cl->reader->device, cs_inet_ntoa(cl->ip),peer->gbox.id);
     171                        write_msg_to_osd(cl, MSGID_GONEOFFLINE, 0);
     172                        }
     173                }
    154174        }
    155175    }
     
    243263    peer->ecm_idx       = 0;
    244264    peer->next_hello    = 0;
     265    peer->authstat      = 0;
    245266    gbox_delete_cards(GBOX_DELETE_FROM_PEER, peer->gbox.id);
    246267    gbox_peer_online(peer, GBOX_PEER_OFFLINE);
     
    267288    struct gbox_peer *peer = cli->gbox;
    268289
    269     cs_log_dump_dbg(D_READER, buf, l, "<- data (%d bytes):", l);
     290    cs_log_dump_dbg(D_READER, buf, l, "<- data to %s (%d bytes):", cli->reader->label, l);
    270291
    271292    hostname2ip(cli->reader->device, &SIN_GET_ADDR(cli->udp_sa));
     
    275296    gbox_encrypt(buf, l, peer->gbox.password);
    276297    sendto(cli->udp_fd, buf, l, 0, (struct sockaddr *)&cli->udp_sa, cli->udp_sa_len);
    277     cs_log_dump_dbg(D_READER, buf, l, "<- encrypted data (%d bytes):", l);
     298    cs_log_dump_dbg(D_READER, buf, l, "<- encrypted data to %s (%d bytes):", cli->reader->label, l);
    278299}
    279300
     
    332353        break;
    333354    }
    334     cs_log_dump_dbg(D_READER, outbuf, len, "<- hello, (len=%d):", len);
     355    cs_log_dump_dbg(D_READER, outbuf, len, "<- hello to %s, (len=%d):", cli->reader->label, len);
    335356
    336357    gbox_compress(outbuf, len, &len);
     
    431452    {
    432453        cs_log("gbox_server %s/%d", cli->reader->label, cli->port);
    433 //      gbox_check_header(cli, NULL, b, l);
     454//      gbox_check_header_recvd(cli, NULL, b, l);
    434455    }
    435456    return 0;
     
    562583{
    563584    struct gbox_peer *peer = cli->gbox;
    564     char tmp[14];
    565585
    566586    if(memcmp(peer->checkcode, checkcode, 7))
    567587    {
    568588        memcpy(peer->checkcode, checkcode, 7);
    569         cs_log_dbg(D_READER, "-> new checkcode=%s",  cs_hexdump(0, peer->checkcode, 14, tmp, sizeof(tmp)));
     589        cs_log_dump_dbg(D_READER, checkcode, 7, "-> new checkcode from %s:", cli->reader->label);
    570590        return 1;
    571591    }
     
    580600    gbox_message_header(outbuf, MSG_CHECKCODE, peer->gbox.password, local_gbox.password);
    581601    memcpy(outbuf + 10, gbox_get_checkcode(), 7);
    582 
     602    cs_log_dbg(D_READER,"<- Send my checkcode to %s", cli->reader->label);
    583603    gbox_send(cli, outbuf, 17);
    584604}
     
    598618    {
    599619        gbox_decompress(data, &payload_len);
    600         cs_log_dump_dbg(D_READER, data, payload_len, "decompressed data (%d bytes):", payload_len);     
     620        cs_log_dump_dbg(D_READER, data, payload_len, "-> data decompressed (%d bytes):", payload_len);     
    601621        ptr = data + 12;
    602622    }
     
    652672            //This is a good night / reset packet (good night data[0xA] / reset !data[0xA]
    653673            cs_log("-> Good Night from %s %s",username(cli), cli->reader->device);
    654             write_msg_to_osd(cli, MSGID_GOODNIGHT_OSD);
     674            write_msg_to_osd(cli, MSGID_GOODNIGHT, 0);
    655675            gbox_reinit_proxy(cli);
    656676        }
     
    904924}
    905925
    906 int32_t gbox_cmd_switch(struct s_client *proxy, uchar *data, int32_t n)
     926int32_t gbox_recv_cmd_switch(struct s_client *proxy, uchar *data, int32_t n)
    907927{
    908928    if (!data || !proxy) { return -1; }
     
    911931    {
    912932    case MSG_BOXINFO:
    913         cs_log("-> HERE? to %s",username(proxy));   
     933        cs_log("-> HERE? from %s %s",username(proxy), proxy->reader->device);   
    914934        gbox_send_hello(proxy, GBOX_STAT_HELLOR);
    915935        break;
    916936    case MSG_GOODBYE:
    917         cs_log("-> goodbye message to %s",username(proxy));
     937        cs_log("-> goodbye message from %s %s",username(proxy), proxy->reader->device);
    918938        //msg goodbye is an indication from peer that requested ECM failed (not found/rejected...)
    919         //TODO: implement on suitable place - rebroadcast ECM to other peers
     939        //TODO: implement on suitable place - rebroadcast ECM to other peers
     940        write_msg_to_osd(proxy, MSGID_GOODBYE, 0);
    920941        break;
    921942    case MSG_UNKNWN:
    922         cs_log("-> MSG_UNKNWN 48F9 to %s", username(proxy));     
     943        cs_log("-> MSG_UNKNWN 48F9 from %s %s", username(proxy), proxy->reader->device);     
    923944        break;
    924945    case MSG_GSMS_1:
    925946        if (!cfg.gsms_dis)
    926947        {
    927             cs_log("-> MSG_GSMS_1 to %s", username(proxy));
     948            cs_log("-> MSG_GSMS_1 from %s %s", username(proxy), proxy->reader->device);
    928949            gbox_send_gsms_ack(proxy,1);
    929950            write_gsms_msg(proxy, data +4, data[3], data[2]);
    930         }
    931         else
    932         {
    933             gsms_unavail();
    934         }
     951            write_msg_to_osd(proxy, MSGID_GSMS, data[3]); // Notification only, no message content
     952        }
     953        else    {gsms_unavail();}
    935954        break;
    936955    case MSG_GSMS_2:
    937956        if (!cfg.gsms_dis)
    938957        {
    939             cs_log("-> MSG_GSMS_2 to %s", username(proxy));
     958            cs_log("-> MSG_GSMS_2 from %s %s", username(proxy), proxy->reader->device);
    940959            gbox_send_gsms_ack(proxy,2);
    941960            write_gsms_msg(proxy, data +16, data[14], data[15]);
    942         }
    943         else
    944         {
    945             gsms_unavail();
    946         }
     961            write_msg_to_osd(proxy, MSGID_GSMS, data[14]); // Notification only, no message content
     962        }
     963        else    {gsms_unavail();}
    947964        break;
    948965    case MSG_GSMS_ACK_1:
    949966        if (!cfg.gsms_dis)
    950967        {
    951             cs_log("-> MSG_GSMS_ACK_1 to %s", username(proxy));
     968            cs_log("-> MSG_GSMS_ACK_1 from %s %s", username(proxy), proxy->reader->device);
    952969            write_gsms_ack(proxy,1);
    953970        }
    954         else
    955         {
    956             gsms_unavail();
    957         }
     971        else    {gsms_unavail();}
    958972        break;
    959973    case MSG_GSMS_ACK_2:
    960974        if (!cfg.gsms_dis)
    961975        {
    962             cs_log("-> MSG_GSMS_ACK_2 to %s", username(proxy));
     976            cs_log("-> MSG_GSMS_ACK_2 from %s %s", username(proxy), proxy->reader->device);
    963977            write_gsms_ack(proxy,2);
    964978        }
    965         else
    966         {
    967             gsms_unavail();
    968         }
     979        else    {gsms_unavail();}
    969980        break;
    970981    case MSG_HELLO1:
     
    983994        break;
    984995    default:
    985         cs_log("-> unknown command %04X received for %s", cmd, username(proxy));
    986         cs_log_dump_dbg(D_READER, data, n, "unknown data received (%d bytes):", n);
     996        cs_log("-> unknown command %04X received from %s %s", cmd, username(proxy), proxy->reader->device);
     997        cs_log_dump_dbg(D_READER, data, n, "unknown data (%d bytes) receivrd from %s %s", n, username(proxy), proxy->reader->device);
    987998    } // end switch
    988999    if ((time(NULL) - last_stats_written) > STATS_WRITE_TIME)
     
    10911102
    10921103//returns -1 in case of error, 1 if authentication was performed, 0 else
    1093 static int8_t gbox_check_header(struct s_client *cli, struct s_client *proxy, uchar *data, int32_t l)
     1104static int8_t gbox_check_header_recvd(struct s_client *cli, struct s_client *proxy, uchar *data, int32_t l)
    10941105{
    10951106    struct gbox_peer *peer = NULL; 
     
    11081119    if (my_received_pw == local_gbox.password)
    11091120    {
    1110         cs_log_dbg(D_READER, "-> data, peer : %04X   data: %s", cli->gbox_peer_id, cs_hexdump(0, data, l, tmp, sizeof(tmp)));
     1121        cs_log_dbg(D_READER, "-> data from peer: %04X   data: %s", cli->gbox_peer_id, cs_hexdump(0, data, l, tmp, sizeof(tmp)));
    11111122
    11121123        if (gbox_decode_cmd(data) != MSG_CW)
     
    11631174    }
    11641175    if(!peer) { return -1; }
    1165 
     1176       
     1177    if(!peer->authstat)
     1178    {
     1179    peer->authstat = 1;
     1180    cs_log("peer %04X authenticated successfully", cli->gbox_peer_id);
     1181    }
    11661182    return authentication_done;
    11671183}
     
    11841200    memcpy(&data[0], buf, n);
    11851201
    1186     ret = gbox_check_header(cli, proxy, &data[0], n);
     1202    ret = gbox_check_header_recvd(cli, proxy, &data[0], n);
    11871203    if (ret < 0) { return -1; }
    11881204   
     
    11991215               
    12001216    cs_writelock(__func__, &peer->lock);
    1201     tmp = gbox_cmd_switch(proxy, data, n);
     1217    tmp = gbox_recv_cmd_switch(proxy, data, n);
    12021218    cs_writeunlock(__func__, &peer->lock);
    12031219   
     
    12741290    gbox_send(cli, buf, ere->gbox_hops + 44);
    12751291
    1276     cs_log_dbg(D_READER, "<- CW (<- %d) to %04X from %s:%d", ere->gbox_hops, ere->gbox_peer, cli->reader->label, cli->port);
     1292    cs_log_dbg(D_READER, "<- CW (<- %d) to %04X  %s port:%d", ere->gbox_hops, ere->gbox_peer, cli->reader->label, cli->port);
    12771293}
    12781294/* // see r11270
     
    15111527
    15121528    local_gbox.password = a2i(cfg.gbox_my_password, 4);
    1513     cs_log_dbg(D_READER, "gbox my password: %s:", cfg.gbox_my_password);
     1529    //cs_log_dbg(D_READER, "gbox my password: %s:", cfg.gbox_my_password);
    15141530
    15151531    local_gbox.id = gbox_convert_password_to_id(local_gbox.password);
     
    15641580
    15651581    peer->gbox.password = a2i(rdr->r_pwd, 4);
    1566     cs_log_dbg(D_READER, "gbox peer password: %s:", rdr->r_pwd);
    1567 
     1582    cs_log_dbg(D_READER, "peer password (%s): %s", cli->reader->label, rdr->r_pwd);
    15681583    peer->gbox.id = gbox_convert_password_to_id(peer->gbox.password);   
    15691584    if (get_gbox_proxy(peer->gbox.id) || peer->gbox.id == NO_GBOX_ID || peer->gbox.id == local_gbox.id)
     
    16331648    return 0;
    16341649}
    1635 
     1650/*
     1651//static void gbox_send_HERE(struct s_client *cli)
     1652static void gbox_send_boxinfo(struct s_client *cli)
     1653{
     1654    struct gbox_peer *peer = cli->gbox;
     1655    uchar outbuf[30];
     1656    int32_t hostname_len = strlen(cfg.gbox_hostname);
     1657    gbox_message_header(outbuf, MSG_BOXINFO, peer->gbox.password, local_gbox.password);
     1658    outbuf[0xA] = gbox_get_my_vers();
     1659    outbuf[0xB] = gbox_get_my_cpu_api();
     1660    memcpy(&outbuf[0xC], cfg.gbox_hostname, hostname_len);
     1661    cs_log("gbox send 'HERE?' to boxid: %04X", peer->gbox.id);
     1662    //cs_log_dump_dbg(D_READER, outbuf, hostname_len + 0xC, "<- send HERE?, (len=%d):", hostname_len + 0xC);
     1663    cs_log_dump(outbuf, hostname_len + 0xC, "<- send HERE?, (len=%d):", hostname_len + 0xC);
     1664    gbox_send(cli, outbuf, hostname_len + 0xC);
     1665}
     1666*/
    16361667static void gbox_s_idle(struct s_client *cl)
    16371668{
     
    16451676            { time_since_last = llabs(cl->lastecm - time(NULL)); }
    16461677        else { time_since_last = llabs(proxy->last - time(NULL)); }
    1647         if (time_since_last > (HELLO_KEEPALIVE_TIME*3) && cl->gbox_peer_id != NO_GBOX_ID)   
     1678        if (time_since_last > (HELLO_KEEPALIVE_TIME*2) && cl->gbox_peer_id != NO_GBOX_ID)   
    16481679        {
    16491680            //gbox peer apparently died without saying goodnight
     
    16511682            cs_writelock(__func__, &peer->lock);
    16521683            cs_log_dbg(D_READER, "time since last proxy activity in sec: %d => taking gbox peer offline",time_since_last);
     1684                if (peer->online)
     1685                {
     1686                    cs_log("Lost connection to: %s  %s  boxid: %04X",proxy->reader->device, cs_inet_ntoa(proxy->ip), cl->gbox_peer_id);
     1687                    write_msg_to_osd(proxy, MSGID_LOSTCONNECT, 0);
     1688                }
    16531689            gbox_reinit_proxy(proxy);
    16541690            cs_writeunlock(__func__, &peer->lock);
     
    17251761}
    17261762
    1727 /*
    1728 void gbox_send_HERE_query (uint16_t boxid)  //gbox.net send this cmd
    1729 {
    1730     uchar outbuf[30];
    1731     int32_t hostname_len = strlen(cfg.gbox_hostname);
    1732     struct s_client *cli;
    1733     cs_readlock(__func__, &clientlist_lock);
    1734     for (cli = first_client; cli; cli = cli->next)
    1735     {
    1736         if(cli->gbox && cli->typ == 'p')
    1737         {
    1738             struct gbox_peer *peer = cli->gbox;
    1739             if (peer->online && boxid == peer->gbox.id)
    1740             {   
    1741                 gbox_message_header(outbuf, MSG_HERE, peer->gbox.password, local_gbox.password);
    1742                 outbuf[0xA] = gbox_get_my_vers();
    1743                 outbuf[0xB] = gbox_get_my_cpu_api();
    1744                 memcpy(&outbuf[0xC], cfg.gbox_hostname, hostname_len);
    1745                 cs_log("gbox send 'HERE?' to boxid: %04X", peer->gbox.id);
    1746                 gbox_send(cli, outbuf, hostname_len + 0xC);
    1747             }
    1748         }
    1749     }
    1750     cs_readunlock(__func__, &clientlist_lock);
    1751 }
    1752 //This is most likely the same as MSG_HERE. Don't know what would be the difference
    1753 static void gbox_send_boxinfo(struct s_client *cli)
    1754 {
    1755     struct gbox_peer *peer = cli->gbox;
    1756     uchar outbuf[256];
    1757     int32_t hostname_len = strlen(cfg.gbox_hostname);
    1758 
    1759     gbox_message_header(outbuf, MSG_BOXINFO, peer);
    1760     outbuf[0xA] = local_gbox.minor_version;
    1761     outbuf[0xB] = local_gbox.type;
    1762     memcpy(&outbuf[0xC], cfg.gbox_hostname, hostname_len);
    1763     gbox_send(cli, outbuf, hostname_len + 0xC);
    1764 }
    1765 */
    17661763void module_gbox(struct s_module *ph)
    17671764{
  • trunk/module-gbox.h

    r11279 r11281  
    88 * doing and accept the posssible *BAD* consequences
    99*/
    10 //#define GBOX_ENABLE_UNSAFE_OSD 1
     10//#define GBOX_ENABLE_UNSAFE_EXTENDED_OSD 1
    1111
    1212#ifdef MODULE_GBOX
     
    5858#define FILE_LOCAL_CARDS_INFO   "sc.info"
    5959
    60 #define MSGID_GOODNIGHT_OSD     0
    61 #define MSGID_GSMS1_OSD         1
    62 #define MSGID_GSMS2_OSD         2
    63 #define MSGID_GOODBYE_OSD       3
    64 #define MSGID_PEERONLINE_OSD    4
     60#define MSGID_GOODNIGHT         0
     61#define MSGID_GSMS              1
     62#define MSGID_GONEOFFLINE       2
     63#define MSGID_COMEONLINE        3
     64#define MSGID_GOODBYE           4
     65#define MSGID_LOSTCONNECT       5
    6566
    6667#define GBOX_STAT_HELLOL        0
     
    142143    uchar checkcode[7];
    143144    int8_t online;
     145    uint8_t onlinestat;
     146    uint8_t authstat;
    144147    uint8_t next_hello;
    145148    uchar ecm_idx;
Note: See TracChangeset for help on using the changeset viewer.