diff --git a/csctapi/ifd_smartreader.c b/csctapi/ifd_smartreader.c index 092eff580..5805eb5cb 100644 --- a/csctapi/ifd_smartreader.c +++ b/csctapi/ifd_smartreader.c @@ -1007,13 +1007,17 @@ static int32_t smartreader_usb_open_dev(struct s_reader *reader) // Likely scenario is a static smartreader_sio kernel module. if(libusb_detach_kernel_driver(crdr_data->usb_dev_handle, crdr_data->interface) != 0 && errno != ENODATA) { - detach_errno = errno; smartreader_usb_close_internal(reader); rdr_log(reader, "Couldn't detach interface from kernel. Please unload the FTDI drivers"); return (LIBUSB_ERROR_NOT_SUPPORTED); } #endif ret = libusb_get_device_descriptor(crdr_data->usb_dev, &usbdesc); + if(ret != 0) { + rdr_log_dbg(reader, D_IFD, "libusb_get_device_descriptor failed"); + } else { + rdr_log_dbg(reader, D_IFD, "libusb_get_device_descriptor ok"); + } #ifdef __WIN32__ // set configuration (needed especially for windows) @@ -1025,51 +1029,44 @@ static int32_t smartreader_usb_open_dev(struct s_reader *reader) ret = libusb_get_configuration(crdr_data->usb_dev_handle, &config); // libusb-win32 on Windows 64 can return a null pointer for a valid device - if(libusb_set_configuration(crdr_data->usb_dev_handle, config) && - errno != EBUSY) + if(libusb_set_configuration(crdr_data->usb_dev_handle, config) && errno != EBUSY) { -#if defined(__linux__) -// if(detach_errno == 0) { libusb_attach_kernel_driver(crdr_data->usb_dev_handle, crdr_data->interface); } -#endif smartreader_usb_close_internal(reader); if(detach_errno == EPERM) { rdr_log(reader, "inappropriate permissions on device!"); return (-8); - } - else - { + } else { rdr_log(reader, "unable to set usb configuration. Make sure smartreader_sio is unloaded!"); return (-3); } + } else { + rdr_log_dbg(rdr, D_IFD, "libusb_set_configuration failed"); } } #endif ret = libusb_claim_interface(crdr_data->usb_dev_handle, crdr_data->interface) ; + if(ret != 0) { -#if defined(__linux__) -// if(detach_errno == 0) { libusb_attach_kernel_driver(crdr_data->usb_dev_handle, crdr_data->interface); } -#endif smartreader_usb_close_internal(reader); if(detach_errno == EPERM) { rdr_log(reader, "inappropriate permissions on device!"); return (-8); - } - else - { + } else { rdr_log(reader, "unable to claim usb device. Make sure smartreader_sio is unloaded!"); return (-5); } } + else { + rdr_log_dbg(reader, D_IFD, "smartreader_usb_close_internal OK"); + } + if(smartreader_usb_reset(reader) != 0) { libusb_release_interface(crdr_data->usb_dev_handle, crdr_data->interface); -#if defined(__linux__) -// if(detach_errno == 0) { libusb_attach_kernel_driver(crdr_data->usb_dev_handle, crdr_data->interface); } -#endif smartreader_usb_close_internal(reader); rdr_log(reader, "smartreader_usb_reset failed"); return (-6); @@ -1086,9 +1083,7 @@ static int32_t smartreader_usb_open_dev(struct s_reader *reader) if(usbdesc.idProduct == 0x6011) { crdr_data->type = TYPE_4232H; - } - else - { + } else { crdr_data->type = TYPE_2232C; } } @@ -1107,9 +1102,6 @@ static int32_t smartreader_usb_open_dev(struct s_reader *reader) if(smartreader_set_baudrate(reader, 9600) != 0) { libusb_release_interface(crdr_data->usb_dev_handle, crdr_data->interface); -#if defined(__linux__) -// if(detach_errno == 0) { libusb_attach_kernel_driver(crdr_data->usb_dev_handle, crdr_data->interface); } -#endif smartreader_usb_close_internal(reader); rdr_log(reader, "set baudrate failed"); return (-7); @@ -1232,6 +1224,12 @@ static void *ReaderThread(void *p) 0); ret = libusb_submit_transfer(crdr_data->usbt[idx]); + if(ret != 0) + { + rdr_log_dbg(reader, D_IFD, "libusb_submit_transfer ok"); + } else { + rdr_log_dbg(reader, D_IFD, "libusb_submit_transfer failed"); + } } while(crdr_data->running) @@ -1369,26 +1367,43 @@ static int32_t SR_Init(struct s_reader *reader) rdr_log(reader, "Unable to open smartreader device %s in bus %s endpoint in 0x%02X out 0x%02X (ret=%d)\n", dev, busname, crdr_data->in_ep, crdr_data->out_ep, ret); return ERROR; } - if (crdr_data->rdrtype >= 2) { - - rdr_log_dbg(reader, D_DEVICE, "SR: Setting smartreader latency timer to 16 ms"); + if (crdr_data->rdrtype >= 2) { //Set the FTDI latency timer to 16 ms is ftdi default latency. ret = smartreader_set_latency_timer(reader, 16); + rdr_log_dbg(reader, D_DEVICE, "SR: Setting smartreader latency timer to %d ms", ret); } else { - rdr_log_dbg(reader, D_DEVICE, "SR: Setting smartreader latency timer to 1 ms"); //Set the FTDI latency timer to 1 ms . ret = smartreader_set_latency_timer(reader, 1); + rdr_log_dbg(reader, D_DEVICE, "SR: Setting smartreader latency timer to %d ms", ret); } + //Set databits to 8o2 ret = smartreader_set_line_property(reader, BITS_8, STOP_BIT_2, ODD); + if(ret != 0) + { + rdr_log_dbg(reader, D_IFD, "smartreader_set_line_property ok"); + } else { + rdr_log_dbg(reader, D_IFD, "smartreader_set_line_property failed"); + } //Set the DTR LOW and RTS LOW ret = smartreader_setdtr_rts(reader, 0, 0); - + if(ret != 0) + { + rdr_log_dbg(reader, D_IFD, "smartreader_setdtr_rts ok"); + } else { + rdr_log_dbg(reader, D_IFD, "smartreader_setdtr_rts failed"); + } //Disable flow control ret = smartreader_setflowctrl(reader, 0); + if(ret != 0) + { + rdr_log_dbg(reader, D_IFD, "smartreader_setflowctrl ok"); + } else { + rdr_log_dbg(reader, D_IFD, "smartreader_setflowctrl failed"); + } // start the reading thread crdr_data->g_read_buffer_size = 0; diff --git a/csctapi/protocol_t1.c b/csctapi/protocol_t1.c index fd1a321a7..9adf9615a 100644 --- a/csctapi/protocol_t1.c +++ b/csctapi/protocol_t1.c @@ -145,10 +145,12 @@ int32_t Protocol_T1_Command(struct s_reader *reader, unsigned char *command, uin timeout = ICC_Async_GetTimings(reader, reader->CWT); // we are going to send: CWT timeout //cs_sleepus(reader->block_delay); // we were receiving, now sending so wait BGT time ret = T1_Block_SendSBlock(reader, block_data, T1_BLOCK_S_IFS_REQ, 1, &inf, timeout); - rdr_log_dbg(reader, D_IFD, "Protocol: Sending block S(IFS request, %d)", inf); + if(ret == ERROR) + { + rdr_log_dbg(reader, D_IFD, "Protocol: Sending block S(IFS request, %d)", inf); + } /* Receive a block */ - timeout = ICC_Async_GetTimings(reader, reader->BWT); // we are going to receive so set Block Waiting Timeout! //cs_sleepus(reader->block_delay); // we were sending, now receiving so wait BGT time ret = Protocol_T1_ReceiveBlock(reader, block_data, &block_length, &rsp_type, timeout); @@ -170,7 +172,10 @@ int32_t Protocol_T1_Command(struct s_reader *reader, unsigned char *command, uin timeout = ICC_Async_GetTimings(reader, reader->CWT); // we are going to send: CWT timeout //cs_sleepus(reader->block_delay); // we were receiving, now sending so wait BGT time ret = T1_Block_SendSBlock(reader, block_data, T1_BLOCK_S_RESYNCH_REQ, 0, NULL, timeout); - rdr_log_dbg(reader, D_IFD, "Protocol: Sending block S(RESYNCH request)"); + if(ret == ERROR) + { + rdr_log_dbg(reader, D_IFD, "Protocol: Sending block S(RESYNCH request)"); + } /* Receive a block */ timeout = ICC_Async_GetTimings(reader, reader->BWT); // we are going to receive so set Block Waiting Timeout! diff --git a/globals.h b/globals.h index 88db41728..8313eda59 100644 --- a/globals.h +++ b/globals.h @@ -361,13 +361,13 @@ * constants * =========================== */ #define CS_VERSION "1.20_svn" +#ifndef CS_SVN_VERSION +# define CS_SVN_VERSION "test" +#endif #ifdef CS_CACHEEX #ifdef CS_CACHEEX_AIO -#define CS_AIO_VERSION "9.2.6" -#endif +#define CS_AIO_VERSION CS_SVN_VERSION #endif -#ifndef CS_SVN_VERSION -# define CS_SVN_VERSION "test" #endif #ifndef CS_TARGET # define CS_TARGET "unknown" @@ -742,8 +742,8 @@ typedef struct s_tuntab typedef struct s_sidtab { char label[64]; - uint8_t disablecrccws_only_for_exception; #ifdef CS_CACHEEX_AIO + uint8_t disablecrccws_only_for_exception; uint8_t no_wait_time; uint8_t lg_only_exception; #endif diff --git a/module-cacheex.c b/module-cacheex.c index 8b93ed60d..5a7a8d6fe 100644 --- a/module-cacheex.c +++ b/module-cacheex.c @@ -513,9 +513,10 @@ int8_t cacheex_maxhop_lg(struct s_client *cl) { if(cl->reader->cacheex.maxhop_lg > max) { - maxhop_lg = max; + cl->reader->cacheex.maxhop_lg = max; } - else if(cl->reader->cacheex.maxhop_lg < maxhop) + + if(cl->reader->cacheex.maxhop_lg < maxhop) { maxhop_lg = maxhop; } @@ -692,8 +693,8 @@ void cacheex_cache_push(ECM_REQUEST *er) && chk_ctab(er->caid, &rdr->ctab) // Caid-check && (!checkECMD5(er) || chk_ident_filter(er->caid, er->prid, &rdr->ftab)) // Ident-check (not for csp: prid=0 always!) && chk_srvid(cl, er) // Service-check -#ifdef CS_CACHEEX_AIO && chk_csp_ctab(er, &rdr->cacheex.filter_caidtab) // cacheex_ecm_filter +#ifdef CS_CACHEEX_AIO && (er->localgenerated // lg-only-check || chk_srvid_localgenerated_only_exception(er) // service-exception || !(rdr->cacheex.localgenerated_only // rdr-lg-only @@ -782,6 +783,7 @@ bool cacheex_is_match_alias(struct s_client *cl, ECM_REQUEST *er) return check_client(cl) && cl->account && cl->account->cacheex.mode == 1 && is_cacheex_matcher_matching(NULL, er); } +#ifdef WITH_DEBUG static void log_cacheex_cw(ECM_REQUEST *er, char *reason) { uint8_t *data; @@ -797,6 +799,7 @@ static void log_cacheex_cw(ECM_REQUEST *er, char *reason) cs_log_dbg(D_CACHEEX,"got pushed ecm [%s]: %s - odd/even 0x%x - CSP cw: %s - pushed from %s, at hop %d, origin node-id %" PRIu64 "X", reason, buf_ecm, er->ecm[0], (checkECMD5(er)?"NO":"YES"), er->from_csp ? "csp" : username((er->cacheex_src?er->cacheex_src:er->client)), ll_count(er->csp_lastnodes), er->csp_lastnodes ? cacheex_node_id(remotenodeid): 0); } +#endif // check if sky_ger 64 bit CW has valid checksum bytes and therefore is probably invalid uint8_t check_nds_cwex(ECM_REQUEST *er) @@ -841,7 +844,7 @@ static int32_t cacheex_add_to_cache_int(struct s_client *cl, ECM_REQUEST *er, in return 0; } - if(!cfg.disablecrccws && ((cl->typ == 'c' && !cl->account->disablecrccacheex) || ( cl->typ == 'p' && !cl->reader->disablecrccws))) + if(!cfg.disablecrccws && ((cl->typ == 'c' && cl->account && !cl->account->disablecrccacheex) || ( cl->typ == 'p' && cl->reader && !cl->reader->disablecrccws))) { uint8_t selectedForIgnChecksum = chk_if_ignore_checksum(er, &cfg.disablecrccws_only_for); if(cl->typ == 'c') @@ -878,7 +881,7 @@ static int32_t cacheex_add_to_cache_int(struct s_client *cl, ECM_REQUEST *er, in { if(check_nds_cwex(er)) { - if(cl->reader->dropbadcws) + if(check_client(cl) && cl->reader && cl->reader->dropbadcws) { if (((D_CACHEEX) & cs_dblevel)) // avoid useless operations if debug is not enabled { @@ -942,7 +945,12 @@ static int32_t cacheex_add_to_cache_int(struct s_client *cl, ECM_REQUEST *er, in if(!chk_halfCW(er, er->cw)) { - log_cacheex_cw(er, "bad half cw"); +#ifdef WITH_DEBUG + if(cs_dblevel & D_CACHEEX) + { + log_cacheex_cw(er, "bad half cw"); + } +#endif cl->cwcacheexerr++; if(cl->account) { cl->account->cwcacheexerr++; } diff --git a/module-cacheex.h b/module-cacheex.h index c8df2e847..1d6b80c62 100644 --- a/module-cacheex.h +++ b/module-cacheex.h @@ -30,7 +30,7 @@ extern void cacheex_init(void); extern void cacheex_clear_account_stats(struct s_auth *account); extern void cacheex_clear_client_stats(struct s_client *client); extern void cacheex_load_config_file(void); -static inline bool cacheex_reader(struct s_reader *rdr) { return rdr->cacheex.mode == 1; } +static inline bool cacheex_reader(struct s_reader *rdr) { return rdr ? (rdr->cacheex.mode == 1 ? 1 : 0) : 0; } extern bool cacheex_is_match_alias(struct s_client *cl, ECM_REQUEST *er); void cacheex_set_csp_lastnode(ECM_REQUEST *er); void cacheex_set_cacheex_src(ECM_REQUEST *ecm, struct s_client *cl); @@ -39,7 +39,7 @@ void cacheex_free_csp_lastnodes(ECM_REQUEST *er); void checkcache_process_thread_start(void); void cacheex_push_out(struct s_client *cl, ECM_REQUEST *er); bool cacheex_check_queue_length(struct s_client *cl); -static inline int8_t cacheex_get_rdr_mode(struct s_reader *reader) { return reader->cacheex.mode; } +static inline int8_t cacheex_get_rdr_mode(struct s_reader *reader) { return reader ? reader->cacheex.mode : 0; } void cacheex_init_hitcache(void); void cacheex_free_hitcache(void); void cacheex_cleanup_hitcache(bool force); diff --git a/module-camd35-cacheex.c b/module-camd35-cacheex.c index 460840df3..c9309391d 100644 --- a/module-camd35-cacheex.c +++ b/module-camd35-cacheex.c @@ -35,6 +35,18 @@ void camd35_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) feature = buf[21] | (buf[20] << 8); FTAB *lgonly_tab; + // check client & cacheex-mode + if( + !check_client(cl) || + !( + (cl->typ == 'c' && cl->account->cacheex.mode > 0) || + (cl->typ == 'p' && cl->reader->cacheex.mode > 0) + ) + ) + { + return; + } + switch(feature) { // set localgenerated only @@ -61,7 +73,7 @@ void camd35_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) memset(&lgonly_tab, 0, sizeof(lgonly_tab)); - if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 ||cl->account->cacheex.mode == 1)) + if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1)) { lgonly_tab = &cl->account->cacheex.lg_only_tab; } @@ -69,11 +81,15 @@ void camd35_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) { lgonly_tab = &cl->reader->cacheex.lg_only_tab; } + else + { + return; + } // remotesettings enabled - replace local settings if(cfg.cacheex_lg_only_remote_settings || ( - (cl->typ == 'c' && (cl->account->cacheex.mode == 2 ||cl->account->cacheex.mode == 1) && cl->account->cacheex.lg_only_remote_settings) + (cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1) && cl->account->cacheex.lg_only_remote_settings) || (cl->typ == 'p' && cl->reader->cacheex.mode == 3 && cl->reader->cacheex.lg_only_remote_settings) ) ) @@ -145,7 +161,7 @@ void camd35_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) CECSPVALUETAB *filter; memset(&filter, 0, sizeof(filter)); - if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 ||cl->account->cacheex.mode == 1) && cl->account->cacheex.allow_filter) + if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1) && cl->account->cacheex.allow_filter) { filter = &cl->account->cacheex.filter_caidtab; } @@ -153,6 +169,10 @@ void camd35_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) { filter = &cl->reader->cacheex.filter_caidtab; } + else + { + return; + } cecspvaluetab_clear(filter); @@ -193,14 +213,18 @@ void camd35_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) CAIDVALUETAB *ctab; memset(&ctab, 0, sizeof(ctab)); - if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 ||cl->account->cacheex.mode == 1)) - { - ctab = &cl->account->cacheex.cacheex_nopushafter_tab; - } - else if(cl->typ == 'p' && cl->reader->cacheex.mode == 3) - { - ctab = &cl->reader->cacheex.cacheex_nopushafter_tab; - } + if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1)) + { + ctab = &cl->account->cacheex.cacheex_nopushafter_tab; + } + else if(cl->typ == 'p' && cl->reader->cacheex.mode == 3) + { + ctab = &cl->reader->cacheex.cacheex_nopushafter_tab; + } + else + { + return; + } filter_count = buf[i+4]; i += 5; @@ -231,7 +255,7 @@ void camd35_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) break; // max hop case 16: - if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 ||cl->account->cacheex.mode == 1) && cl->account->cacheex.allow_maxhop) + if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1) && cl->account->cacheex.allow_maxhop) { cl->account->cacheex.maxhop = buf[24]; cl->account->cacheex.maxhop_lg = buf[25]; @@ -259,7 +283,7 @@ void camd35_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) case 64: ; memset(&lgonly_tab, 0, sizeof(lgonly_tab)); - if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 ||cl->account->cacheex.mode == 1)) + if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1)) { lgonly_tab = &cl->account->cacheex.lg_only_tab; } @@ -267,6 +291,10 @@ void camd35_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) { lgonly_tab = &cl->reader->cacheex.lg_only_tab; } + else + { + return; + } filter_count = buf[i+4]; i += 5; @@ -274,7 +302,7 @@ void camd35_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) // remotesettings enabled - replace local settings if(cfg.cacheex_lg_only_remote_settings || ( - (cl->typ == 'c' && (cl->account->cacheex.mode == 2 ||cl->account->cacheex.mode == 1) && cl->account->cacheex.lg_only_remote_settings) + (cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1) && cl->account->cacheex.lg_only_remote_settings) || (cl->typ == 'p' && cl->reader->cacheex.mode == 3 && cl->reader->cacheex.lg_only_remote_settings) || !lgonly_tab->nfilts ) @@ -365,6 +393,12 @@ void camd35_cacheex_feature_trigger(struct s_client *cl, int32_t feature, uint8_ uint8_t payload[MAX_ECM_SIZE-size]; memset(payload, 0, sizeof(payload)); + // check client & cacheex-mode + if(!check_client(cl)) + { + return; + } + switch(feature) { FTAB *lgonly_tab; @@ -387,7 +421,6 @@ void camd35_cacheex_feature_trigger(struct s_client *cl, int32_t feature, uint8_ payload[i] = cl->reader->cacheex.localgenerated_only_in; else payload[i] = cfg.cacheex_localgenerated_only_in; - i += 1; } else if(mode == 3) { @@ -395,7 +428,6 @@ void camd35_cacheex_feature_trigger(struct s_client *cl, int32_t feature, uint8_ payload[i] = cl->account->cacheex.localgenerated_only_in; else payload[i] = cfg.cacheex_localgenerated_only_in; - i += 1; } break; @@ -856,7 +888,6 @@ void camd35_cacheex_feature_request(struct s_client *cl) buf[2] = 0; i2b_buf(2, CACHEEX_FEATURES, buf + i); // set feature-list here - i += 2; camd35_send_without_timeout(cl, buf, 12); //send adds +20 } @@ -873,7 +904,6 @@ void camd35_cacheex_feature_request_reply(struct s_client *cl, uint8_t *buf) rbuf[2] = 0; i2b_buf(2, CACHEEX_FEATURES, rbuf + i); - i += 2; camd35_send_without_timeout(cl, rbuf, 12); //send adds +20 } @@ -1196,7 +1226,6 @@ static int32_t camd35_cacheex_push_out(struct s_client *cl, struct ecm_request_t { *ofs = 0xFF; } - ofs += 1; #endif int32_t res = camd35_send(cl, buf, size); NULLFREE(buf); @@ -1213,7 +1242,7 @@ static void camd35_cacheex_push_in(struct s_client *cl, uint8_t *buf) uint16_t size = buf[1] | (buf[2] << 8); if(size < sizeof(er->ecmd5) + sizeof(er->csp_hash) + sizeof(er->cw)) { - cs_log_dbg(D_CACHEEX, "cacheex: %s received old cash-push format! data ignored!", username(cl)); + cs_log_dbg(D_CACHEEX, "cacheex: %s received old cache-push format! data ignored!", username(cl)); return; } @@ -1591,7 +1620,7 @@ bool camd35_cacheex_server(struct s_client *client, uint8_t *mbuf) camd35_cacheex_feature_request_reply(client, mbuf); break; case 0x41: // cacheex-features answer - camd35_cacheex_feature_request_save(client, mbuf); + // camd35_cacheex_feature_request_save(client, mbuf); break; case 0x42: // cacheex-feature trigger in camd35_cacheex_feature_trigger_in(client, mbuf); @@ -1635,7 +1664,7 @@ bool camd35_cacheex_recv_chk(struct s_client *client, uint8_t *buf) camd35_cacheex_feature_request_reply(client, buf); break; case 0x41: // cacheex-features answer - camd35_cacheex_feature_request_save(client, buf); + // camd35_cacheex_feature_request_save(client, buf); break; case 0x42: // cacheex-feature trigger in camd35_cacheex_feature_trigger_in(client, buf); diff --git a/module-cccam-cacheex.c b/module-cccam-cacheex.c index a668289c6..ff1ec5d2c 100644 --- a/module-cccam-cacheex.c +++ b/module-cccam-cacheex.c @@ -37,6 +37,18 @@ void cc_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) feature = buf[1] | (buf[0] << 8); FTAB *lgonly_tab; + // check client & cacheex-mode + if( + !check_client(cl) || + !( + (cl->typ == 'c' && cl->account->cacheex.mode > 0) || + (cl->typ == 'p' && cl->reader->cacheex.mode > 0) + ) + ) + { + return; + } + switch(feature) { // set localgenerated only @@ -71,6 +83,10 @@ void cc_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) { lgonly_tab = &cl->reader->cacheex.lg_only_tab; } + else + { + return; + } // remotesettings enabled - replace local settings if(cfg.cacheex_lg_only_remote_settings || @@ -155,6 +171,10 @@ void cc_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) { filter = &cl->reader->cacheex.filter_caidtab; } + else + { + return; + } cecspvaluetab_clear(filter); @@ -196,13 +216,17 @@ void cc_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) memset(&ctab, 0, sizeof(ctab)); if(cl->typ == 'c' && (cl->account->cacheex.mode == 2 || cl->account->cacheex.mode == 1)) - { - ctab = &cl->account->cacheex.cacheex_nopushafter_tab; - } - else if(cl->typ == 'p' && cl->reader->cacheex.mode == 3) - { - ctab = &cl->reader->cacheex.cacheex_nopushafter_tab; - } + { + ctab = &cl->account->cacheex.cacheex_nopushafter_tab; + } + else if(cl->typ == 'p' && cl->reader->cacheex.mode == 3) + { + ctab = &cl->reader->cacheex.cacheex_nopushafter_tab; + } + else + { + return; + } filter_count = buf[i+4]; i += 5; @@ -269,6 +293,10 @@ void cc_cacheex_feature_trigger_in(struct s_client *cl, uint8_t *buf) { lgonly_tab = &cl->reader->cacheex.lg_only_tab; } + else + { + return; + } filter_count = buf[i+4]; i += 5; @@ -367,6 +395,12 @@ void cc_cacheex_feature_trigger(struct s_client *cl, int32_t feature, uint8_t mo uint8_t payload[MAX_ECM_SIZE-size]; memset(payload, 0, sizeof(payload)); + // check client & cacheex-mode + if(!check_client(cl)) + { + return; + } + switch(feature) { FTAB *lgonly_tab; @@ -388,7 +422,6 @@ void cc_cacheex_feature_trigger(struct s_client *cl, int32_t feature, uint8_t mo payload[i] = cl->reader->cacheex.localgenerated_only_in; else payload[i] = cfg.cacheex_localgenerated_only_in; - i += 1; } else if(mode == 3) { @@ -396,7 +429,6 @@ void cc_cacheex_feature_trigger(struct s_client *cl, int32_t feature, uint8_t mo payload[i] = cl->account->cacheex.localgenerated_only_in; else payload[i] = cfg.cacheex_localgenerated_only_in; - i += 1; } break; @@ -1203,7 +1235,6 @@ static int32_t cc_cacheex_push_out(struct s_client *cl, struct ecm_request_t *er { *ofs = 0xFF; } - ofs += 1; #endif int32_t res = cc_cmd_send(cl, buf, size + 20, MSG_CACHE_PUSH); diff --git a/module-cccam.c b/module-cccam.c index 366172e97..30859b9cd 100644 --- a/module-cccam.c +++ b/module-cccam.c @@ -883,6 +883,7 @@ int32_t cc_cmd_send(struct s_client *cl, uint8_t *buf, int32_t len, cc_msg_type_ uint8_t *netbuf; if(!cs_malloc(&netbuf, len + 4)) { + cs_writeunlock(__func__, &cc->lockcmd); return -1; } @@ -922,7 +923,6 @@ int32_t cc_cmd_send(struct s_client *cl, uint8_t *buf, int32_t len, cc_msg_type_ } else { - cs_writeunlock(__func__, &cc->cards_busy); cs_disconnect_client(cl); } n = -1; @@ -1068,7 +1068,7 @@ int32_t cc_send_srv_data(struct s_client *cl) int32_t loop_check(uint8_t *myid, struct s_client *cl) { - if(!cl) + if(!cl || !myid) { return 0; } @@ -1860,6 +1860,7 @@ int32_t cc_send_ecm(struct s_client *cl, ECM_REQUEST *er) uint8_t *ecmbuf; if(!cs_malloc(&ecmbuf, cur_er->ecmlen + 13)) { + cs_readunlock(__func__, &cc->cards_busy); break; } @@ -1963,6 +1964,7 @@ int32_t cc_send_ecm(struct s_client *cl, ECM_REQUEST *er) cur_er->rc = E_WAITING; // mark as waiting } } + cs_readunlock(__func__, &cc->cards_busy); // process next pending ecm! @@ -2147,6 +2149,7 @@ int32_t cc_send_emm(EMM_PACKET *ep) if(!cs_malloc(&emmbuf, size)) { + cs_readunlock(__func__, &cc->cards_busy); return 0; } @@ -2775,6 +2778,7 @@ int32_t cc_parse_msg(struct s_client *cl, uint8_t *buf, int32_t l) if(l == 0x48) // 72 bytes: normal server data { cs_writelock(__func__, &cc->cards_busy); + cc_free_cardlist(cc->cards, 0); free_extended_ecm_idx(cc); cc->last_emm_card = NULL; @@ -2785,7 +2789,6 @@ int32_t cc_parse_msg(struct s_client *cl, uint8_t *buf, int32_t l) cc->num_reshare1 = 0; cc->num_reshare2 = 0; cc->num_resharex = 0; - cs_writeunlock(__func__, &cc->cards_busy); memcpy(cc->peer_node_id, data, 8); memcpy(cc->peer_version, data + 8, 8); @@ -2806,6 +2809,8 @@ int32_t cc_parse_msg(struct s_client *cl, uint8_t *buf, int32_t l) cs_log_dbg(D_READER, "multics detected: %s!", getprefix()); } + cs_writeunlock(__func__, &cc->cards_busy); + cs_log_dbg(D_READER, "%s remote server %s running v%s (%s)", getprefix(), cs_hexdump(0, cc->peer_node_id, 8, tmp_dbg, sizeof(tmp_dbg)), cc->remote_version, cc->remote_build); @@ -2831,45 +2836,57 @@ int32_t cc_parse_msg(struct s_client *cl, uint8_t *buf, int32_t l) } else if(l >= 0x00 && l <= 0x0F) { + cs_writelock(__func__, &cc->cards_busy); cc->cmd05_offset = l; + cs_writeunlock(__func__, &cc->cards_busy); // // 16..43 bytes: RC4 encryption // } else if((l >= 0x10 && l <= 0x1f) || (l >= 0x24 && l <= 0x2b)) { + cs_writelock(__func__, &cc->cards_busy); cc_init_crypt(&cc->cmd05_cryptkey, data, l); cc->cmd05_mode = MODE_RC4_CRYPT; + cs_writeunlock(__func__, &cc->cards_busy); // // 32 bytes: set AES128 key for CMD_05, Key=16 bytes offset keyoffset // } else if(l == 0x20) { + cs_writelock(__func__, &cc->cards_busy); memcpy(cc->cmd05_aeskey, data + cc->cmd05_offset, 16); cc->cmd05_mode = MODE_AES; + cs_writeunlock(__func__, &cc->cards_busy); // // 33 bytes: xor-algo mit payload-bytes, offset keyoffset // } else if(l == 0x21) { + cs_writelock(__func__, &cc->cards_busy); cc_init_crypt(&cc->cmd05_cryptkey, data + cc->cmd05_offset, l); cc->cmd05_mode = MODE_CC_CRYPT; + cs_writeunlock(__func__, &cc->cards_busy); // // 34 bytes: cmd_05 plain back // } else if(l == 0x22) { + cs_writelock(__func__, &cc->cards_busy); cc->cmd05_mode = MODE_PLAIN; + cs_writeunlock(__func__, &cc->cards_busy); // // 35 bytes: Unknown!! 2 256 byte keys exchange // } else if(l == 0x23) { + cs_writelock(__func__, &cc->cards_busy); cc->cmd05_mode = MODE_UNKNOWN; + cs_writeunlock(__func__, &cc->cards_busy); cc_cycle_connection(cl); // // 44 bytes: set aes128 key, Key=16 bytes [Offset=len(password)] @@ -2877,16 +2894,20 @@ int32_t cc_parse_msg(struct s_client *cl, uint8_t *buf, int32_t l) } else if(l == 0x2c) { + cs_writelock(__func__, &cc->cards_busy); memcpy(cc->cmd05_aeskey, data + cs_strlen(rdr->r_pwd), 16); cc->cmd05_mode = MODE_AES; + cs_writeunlock(__func__, &cc->cards_busy); // // 45 bytes: set aes128 key, Key=16 bytes [Offset=len(username)] // } else if(l == 0x2d) { + cs_writelock(__func__, &cc->cards_busy); memcpy(cc->cmd05_aeskey, data + cs_strlen(rdr->r_usr), 16); cc->cmd05_mode = MODE_AES; + cs_writeunlock(__func__, &cc->cards_busy); // //Unknown!! // @@ -2905,7 +2926,7 @@ int32_t cc_parse_msg(struct s_client *cl, uint8_t *buf, int32_t l) case MSG_NEW_CARD_SIDINFO: case MSG_NEW_CARD: { - if(l < 16) + if(l < 16 || !rdr) { break; } @@ -3074,7 +3095,8 @@ int32_t cc_parse_msg(struct s_client *cl, uint8_t *buf, int32_t l) if(config_enabled(WITH_LB) && !cfg.lb_mode) { cl->stopped = 1; // server says invalid - rdr->card_status = CARD_FAILURE; + if(rdr) + rdr->card_status = CARD_FAILURE; } } } @@ -4183,7 +4205,6 @@ int32_t cc_srv_wakeup_readers(struct s_client *cl) int32_t wakeup = 0; struct s_reader *rdr; struct s_client *client; - struct cc_data *cc; for(rdr = first_active_reader; rdr; rdr = rdr->next) { @@ -4210,7 +4231,7 @@ int32_t cc_srv_wakeup_readers(struct s_client *cl) } // reader is in shutdown - if((client = rdr->client) == NULL || (cc = client->cc) == NULL || client->kill) + if((client = rdr->client) == NULL || (client->cc) == NULL || client->kill) { continue; } @@ -4285,7 +4306,7 @@ int32_t cc_srv_connect(struct s_client *cl) cs_log_dbg(D_TRACE, "receive ccc checksum"); - if((i = cc_recv_to(cl, buf, 20)) == 20) + if(cc_recv_to(cl, buf, 20) == 20) { //cs_log_dump_dbg(D_CLIENT, buf, 20, "cccam: recv:"); cc_crypt(&cc->block[DECRYPT], buf, 20, DECRYPT); @@ -4749,7 +4770,7 @@ int32_t cc_cli_connect(struct s_client *cl) cc_crypt(&cc->block[ENCRYPT], (uint8_t *)pwd, cs_strlen(pwd), ENCRYPT); cc_cmd_send(cl, buf, 6, MSG_NO_HEADER); // send 'CCcam' xor w/ pwd - if((n = cc_recv_to(cl, data, 20)) != 20) + if((cc_recv_to(cl, data, 20)) != 20) { cs_log("%s login failed, usr/pwd invalid", getprefix()); cc_cli_close(cl, 0); diff --git a/module-cccshare.c b/module-cccshare.c index 44939bfc9..e5fa37a42 100644 --- a/module-cccshare.c +++ b/module-cccshare.c @@ -1247,14 +1247,20 @@ void update_card_list(void) { card = create_card2(rdr, (j << 8) | k, ptr->caid[k], reshare); if(!card) - { return; } + { + cs_readunlock(__func__, &readerlist_lock); + return; + } card->card_type = CT_CARD_BY_SERVICE_READER; card->sidtab = ptr; for(l = 0; l < ptr->num_provid; l++) { struct cc_provider *prov; if(!cs_malloc(&prov, sizeof(struct cc_provider))) - { return; } + { + cs_readunlock(__func__, &readerlist_lock); + return; + } prov->prov = ptr->provid[l]; ll_append(card->providers, prov); } @@ -1284,7 +1290,10 @@ void update_card_list(void) { card = create_card2(rdr, j, caid, reshare); if(!card) - { return; } + { + cs_readunlock(__func__, &readerlist_lock); + return; + } card->card_type = CT_LOCALCARD; //Setting UA: (Unique Address): @@ -1295,7 +1304,10 @@ void update_card_list(void) { struct cc_provider *prov; if(!cs_malloc(&prov, sizeof(struct cc_provider))) - { return; } + { + cs_readunlock(__func__, &readerlist_lock); + return; + } prov->prov = rdr->ftab.filts[j].prids[k]; //cs_log("Ident CCcam card report provider: %02X%02X%02X", buf[21 + (k*7)]<<16, buf[22 + (k*7)], buf[23 + (k*7)]); @@ -1334,7 +1346,10 @@ void update_card_list(void) { card = create_card2(rdr, j, lcaid, reshare); if(!card) - { return; } + { + cs_readunlock(__func__, &readerlist_lock); + return; + } card->card_type = CT_CARD_BY_CAID1; if(!rdr->audisabled) { cc_UA_oscam2cccam(rdr->hexserial, card->hexserial, lcaid); } @@ -1370,7 +1385,10 @@ void update_card_list(void) uint32_t prid = get_reader_prid(rdr, j); struct cc_provider *prov; if(!cs_malloc(&prov, sizeof(struct cc_provider))) - { return; } + { + cs_readunlock(__func__, &readerlist_lock); + return; + } prov->prov = prid; //cs_log("Ident CCcam card report provider: %02X%02X%02X", buf[21 + (k*7)]<<16, buf[22 + (k*7)], buf[23 + (k*7)]); if(!rdr->audisabled) @@ -1397,7 +1415,10 @@ void update_card_list(void) uint16_t caid = rdr->caid; card = create_card2(rdr, 1, caid, reshare); if(!card) - { return; } + { + cs_readunlock(__func__, &readerlist_lock); + return; + } card->card_type = CT_CARD_BY_CAID3; if(!rdr->audisabled) @@ -1407,7 +1428,10 @@ void update_card_list(void) uint32_t prid = get_reader_prid(rdr, j); struct cc_provider *prov; if(!cs_malloc(&prov, sizeof(struct cc_provider))) - { return; } + { + cs_readunlock(__func__, &readerlist_lock); + return; + } prov->prov = prid; //cs_log("Ident CCcam card report provider: %02X%02X%02X", buf[21 + (k*7)]<<16, buf[22 + (k*7)], buf[23 + (k*7)]); if(!rdr->audisabled) diff --git a/module-cw-cycle-check.c b/module-cw-cycle-check.c index 13188bbac..c53c5651b 100644 --- a/module-cw-cycle-check.c +++ b/module-cw-cycle-check.c @@ -90,8 +90,18 @@ static uint8_t countCWpart(ECM_REQUEST *er, struct s_cw_cycle_check *cwc) { uint8_t eo = cwc->nextcyclecw ? 0 : 8; int8_t i, ret = 0; - char cwc_cw[9 * 3]; - char er_cw[9 * 3]; + +#ifdef WITH_DEBUG + if(cs_dblevel & D_CWC) + { + char cwc_cw[9 * 3]; + char er_cw[9 * 3]; + cs_hexdump(0, cwc->cw + eo, 8, cwc_cw, sizeof(cwc_cw)); + cs_hexdump(0, er->cw + eo, 8, er_cw, sizeof(er_cw)); + cs_log_dbg(D_CWC, "cyclecheck [countCWpart] er-cw %s", er_cw); + cs_log_dbg(D_CWC, "cyclecheck [countCWpart] cw-cw %s", cwc_cw); + } +#endif for(i = 0; i < 8; i++) { @@ -101,10 +111,7 @@ static uint8_t countCWpart(ECM_REQUEST *er, struct s_cw_cycle_check *cwc) } } - cs_hexdump(0, cwc->cw + eo, 8, cwc_cw, sizeof(cwc_cw)); - cs_hexdump(0, er->cw + eo, 8, er_cw, sizeof(er_cw)); - cs_log_dbg(D_CWC, "cyclecheck [countCWpart] er-cw %s", er_cw); - cs_log_dbg(D_CWC, "cyclecheck [countCWpart] cw-cw %s", cwc_cw); + if(ret > cfg.cwcycle_sensitive) { cs_log("cyclecheck [countCWpart] new cw is to like old one (unused part), sensitive %d, same bytes %d", cfg.cwcycle_sensitive, ret); @@ -191,9 +198,11 @@ static int32_t checkcwcycle_int(ECM_REQUEST *er, char *er_ecmf , char *user, uin char cwstr[17 * 3]; // cw to check char cwc_ecmf[ECM_FMT_LEN]; - char cwc_md5[17 * 3]; char cwc_cw[17 * 3]; +#ifdef WITH_DEBUG + char cwc_md5[17 * 3]; char cwc_csp[5 * 3]; +#endif int8_t n = 1, m = 1, k; int32_t mcl = cfg.maxcyclelist; struct s_cw_cycle_check *currentnode = NULL, *cwc = NULL; @@ -208,6 +217,7 @@ static int32_t checkcwcycle_int(ECM_REQUEST *er, char *er_ecmf , char *user, uin //read lock cs_readlock(__func__, &cwcycle_lock); + bool readlocked = true; for(currentnode = cw_cc_list; currentnode; currentnode = currentnode->next) { if(currentnode->caid != er->caid || currentnode->provid != er->prid || currentnode->sid != er->srvid || currentnode->chid != er->chid) @@ -225,15 +235,16 @@ static int32_t checkcwcycle_int(ECM_REQUEST *er, char *er_ecmf , char *user, uin } need_new_entry = 0; // we got a entry for caid/prov/sid so we dont need new one - cs_hexdump(0, cw, 16, cwstr, sizeof(cwstr)); //checked cw for log - +#ifdef WITH_DEBUG + if(cs_dblevel & D_CWC) + { + cs_hexdump(0, cw, 16, cwstr, sizeof(cwstr)); //checked cw for log + } +#endif if(cs_malloc(&cwc, sizeof(struct s_cw_cycle_check))) { - memcpy(cwc, currentnode, sizeof(struct s_cw_cycle_check)); //copy current to new - - if(!currentnode->old) { currentnode->old = 1; //need later to counting @@ -241,11 +252,16 @@ static int32_t checkcwcycle_int(ECM_REQUEST *er, char *er_ecmf , char *user, uin } //now we have all data and can leave read lock cs_readunlock(__func__, &cwcycle_lock); - - cs_hexdump(0, cwc->ecm_md5[cwc->cwc_hist_entry].md5, 16, cwc_md5, sizeof(cwc_md5)); - cs_hexdump(0, (void *)&cwc->ecm_md5[cwc->cwc_hist_entry].csp_hash, 4, cwc_csp, sizeof(cwc_csp)); - cs_hexdump(0, cwc->cw, 16, cwc_cw, sizeof(cwc_cw)); - ecmfmt(cwc_ecmf, ECM_FMT_LEN, cwc->caid, 0, cwc->provid, cwc->chid, 0, cwc->sid, cwc->ecmlen, cwc_md5, cwc_csp, cwc_cw, 0, 0, NULL, NULL); + readlocked = false; +#ifdef WITH_DEBUG + if(cs_dblevel & D_CWC) + { + cs_hexdump(0, cwc->ecm_md5[cwc->cwc_hist_entry].md5, 16, cwc_md5, sizeof(cwc_md5)); + cs_hexdump(0, (void *)&cwc->ecm_md5[cwc->cwc_hist_entry].csp_hash, 4, cwc_csp, sizeof(cwc_csp)); + cs_hexdump(0, cwc->cw, 16, cwc_cw, sizeof(cwc_cw)); + ecmfmt(cwc_ecmf, ECM_FMT_LEN, cwc->caid, 0, cwc->provid, cwc->chid, 0, cwc->sid, cwc->ecmlen, cwc_md5, cwc_csp, cwc_cw, 0, 0, NULL, NULL); + } +#endif // Cycletime over Cacheex if (cfg.cwcycle_usecwcfromce) @@ -370,9 +386,14 @@ static int32_t checkcwcycle_int(ECM_REQUEST *er, char *er_ecmf , char *user, uin #endif { cs_log_dbg(D_CWC, "cyclecheck [OLD] [CheckedECM] Client: %s EA: %s", user, er_ecmf); - cs_hexdump(0, cwc->ecm_md5[k].md5, 16, cwc_md5, sizeof(cwc_md5)); - cs_hexdump(0, (void *)&cwc->ecm_md5[k].csp_hash, 4, cwc_csp, sizeof(cwc_csp)); - cs_log_dbg(D_CWC, "cyclecheck [OLD] [Stored ECM] Client: %s EA: %s.%s", user, cwc_md5, cwc_csp); +#ifdef WITH_DEBUG + if(cs_dblevel & D_CWC) + { + cs_hexdump(0, cwc->ecm_md5[k].md5, 16, cwc_md5, sizeof(cwc_md5)); + cs_hexdump(0, (void *)&cwc->ecm_md5[k].csp_hash, 4, cwc_csp, sizeof(cwc_csp)); + cs_log_dbg(D_CWC, "cyclecheck [OLD] [Stored ECM] Client: %s EA: %s.%s", user, cwc_md5, cwc_csp); + } +#endif if(!cfg.cwcycle_dropold && !memcmp(cwc->ecm_md5[k].cw, cw, 16)) { ret = 4; } else @@ -564,6 +585,11 @@ static int32_t checkcwcycle_int(ECM_REQUEST *er, char *er_ecmf , char *user, uin break; } + if (readlocked) + { + cs_readunlock(__func__, &cwcycle_lock); + } + if(need_new_entry) { cs_readunlock(__func__, &cwcycle_lock); diff --git a/module-dvbapi.c b/module-dvbapi.c index 08fda8d11..08646debc 100644 --- a/module-dvbapi.c +++ b/module-dvbapi.c @@ -7332,8 +7332,13 @@ void dvbapi_write_cw(int32_t demux_id, int32_t pid, int32_t stream_id, uint8_t * char lastcw[2 * cw_length + 1]; char newcw[2 * cw_length + 1]; - cs_hexdump(0, demux[demux_id].last_cw[stream_id][n], cw_length, lastcw, sizeof(lastcw)); - cs_hexdump(0, cw + (n * cw_length), cw_length, newcw, sizeof(newcw)); +#ifdef WITH_DEBUG + if(cs_dblevel & D_DVBAPI) + { + cs_hexdump(0, demux[demux_id].last_cw[stream_id][n], cw_length, lastcw, sizeof(lastcw)); + cs_hexdump(0, cw + (n * cw_length), cw_length, newcw, sizeof(newcw)); + } +#endif for(i = 0; i < CA_MAX; i++) { @@ -7552,8 +7557,12 @@ void dvbapi_send_dcw(struct s_client *client, ECM_REQUEST *er) uint32_t status = dvbapi_check_ecm_delayed_delivery(i, er); uint32_t comparecw0 = 0, comparecw1 = 0; char ecmd5[17 * 3]; - cs_hexdump(0, er->ecmd5, 16, ecmd5, sizeof(ecmd5)); - +#ifdef WITH_DEBUG + if(cs_dblevel & D_DVBAPI) + { + cs_hexdump(0, er->ecmd5, 16, ecmd5, sizeof(ecmd5)); + } +#endif if(status == 1 && er->rc) // wrong ecmhash { cs_log_dbg(D_DVBAPI, "Demuxer %d not interested in response ecmhash %s (requested different one)", i, ecmd5); @@ -8529,8 +8538,12 @@ int32_t dvbapi_check_ecm_delayed_delivery(int32_t demux_id, ECM_REQUEST *er) { demux[demux_id].demux_fd[filternum].lastresult = er->rc; // save last result char ecmd5[17 * 3]; - cs_hexdump(0, er->ecmd5, 16, ecmd5, sizeof(ecmd5)); - +#ifdef WITH_DEBUG + if(cs_dblevel & D_DVBAPI) + { + cs_hexdump(0, er->ecmd5, 16, ecmd5, sizeof(ecmd5)); + } +#endif cs_log_dbg(D_DVBAPI, "Demuxer %d requested controlword for ecm %s on fd %d", demux_id, ecmd5, demux[demux_id].demux_fd[filternum].fd); diff --git a/module-ghttp.c b/module-ghttp.c index 5ef695f6c..fea2db0bd 100644 --- a/module-ghttp.c +++ b/module-ghttp.c @@ -614,7 +614,7 @@ static char *_ghttp_basic_auth(struct s_client *client) { cs_log_dbg(D_CLIENT, "%s: username specified and no existing session, adding basic auth", client->reader->label); ret = snprintf((char *)auth, sizeof(auth), "%s:%s", client->reader->r_usr, client->reader->r_pwd); - ret = b64encode((char *)auth, ret, &encauth); + b64encode((char *)auth, ret, &encauth); } return encauth; } @@ -859,7 +859,7 @@ static int32_t ghttp_capmt_notify(struct s_client *client, struct demux_s *demux client->reader->label, (pids_len > 0) ? "POST" : "GET", demux->onid, demux->tsid, demux->program_number, demux->ECMpidcount, demux->ens); - ret = ghttp_send(client, req, ret + pids_len); + ghttp_send(client, req, ret + pids_len); if(pids_len > 0) { diff --git a/module-stat.c b/module-stat.c index 128ff58e8..ee179b794 100644 --- a/module-stat.c +++ b/module-stat.c @@ -1737,11 +1737,14 @@ void stat_get_best_reader(ECM_REQUEST *er) if(nr > 5) { snprintf(rptr, l, "...(%d more)", nr - 5); } - char ecmbuf[ECM_FMT_LEN]; - format_ecm(er, ecmbuf, ECM_FMT_LEN); + if(cs_dblevel & D_LB) + { + char ecmbuf[ECM_FMT_LEN]; + format_ecm(er, ecmbuf, ECM_FMT_LEN); - cs_log_dbg(D_LB, "loadbalancer: client %s for %s: n=%d selected readers: %s", - username(er->client), ecmbuf, nr, buf); + cs_log_dbg(D_LB, "loadbalancer: client %s for %s: n=%d selected readers: %s", + username(er->client), ecmbuf, nr, buf); + } } #endif return; diff --git a/module-webif.c b/module-webif.c index d942a220f..5b06f9583 100644 --- a/module-webif.c +++ b/module-webif.c @@ -6682,14 +6682,14 @@ static char *send_oscam_services_edit(struct templatevars * vars, struct uripara tpl_addVar(vars, TPLADD, "LABEL", xml_encode(vars, sidtab->label)); tpl_addVar(vars, TPLADD, "LABELENC", urlencode(vars, sidtab->label)); -#ifdef CS_CACHEEX_AIO - tpl_addVar(vars, TPLADD, "DCRCCHECKED", (sidtab->disablecrccws_only_for_exception == 1) ? "checked" : "" ); - tpl_addVar(vars, TPLADD, "NWCHECKED", (sidtab->no_wait_time == 1) ? "checked" : "" ); - tpl_addVar(vars, TPLADD, "LGOECHECKED", (sidtab->lg_only_exception == 1) ? "checked" : "" ); -#endif if(sidtab) { +#ifdef CS_CACHEEX_AIO + tpl_addVar(vars, TPLADD, "DCRCCHECKED", (sidtab->disablecrccws_only_for_exception == 1) ? "checked" : "" ); + tpl_addVar(vars, TPLADD, "NWCHECKED", (sidtab->no_wait_time == 1) ? "checked" : "" ); + tpl_addVar(vars, TPLADD, "LGOECHECKED", (sidtab->lg_only_exception == 1) ? "checked" : "" ); +#endif for(i = 0; i < sidtab->num_caid; i++) { if(i == 0) { tpl_printf(vars, TPLADD, "CAIDS", "%04X", sidtab->caid[i]); } @@ -7402,7 +7402,7 @@ static char *send_oscam_failban(struct templatevars * vars, struct uriparams * p if(strcmp(getParam(params, "intip"), "all") == 0) { // clear whole list - while((v_ban_entry = ll_iter_next(&itr))) + while(ll_iter_next(&itr)) { ll_iter_remove_data(&itr); } @@ -8097,7 +8097,7 @@ static char *send_oscam_cacheex(struct templatevars * vars, struct uriparams * p else { #ifdef CS_CACHEEX_AIO - tpl_addVar(vars, TPLAPPEND, rowvariable, tpl_getTpl(vars, "CACHEEXAIOTABLEROW")); + tpl_addVar(vars, TPLAPPEND, rowvariable, tpl_getTpl(vars, "CACHEEXAIOTABLEROWSTATS")); #else tpl_addVar(vars, TPLAPPEND, rowvariable, tpl_getTpl(vars, "CACHEEXTABLEROW")); #endif diff --git a/oscam-cache.c b/oscam-cache.c index a200d1b64..19ca3fddc 100644 --- a/oscam-cache.c +++ b/oscam-cache.c @@ -486,15 +486,19 @@ static void cacheex_cache_add(ECM_REQUEST *er, ECMHASH *result, CW *cw, bool add #else cw1, cw2); #endif - - LL_LOCKITER *li = ll_li_create(er->csp_lastnodes, 0); - uint8_t *nodeid; - uint8_t hops = 0; - while((nodeid = ll_li_next(li))) +#ifdef WITH_DEBUG + if(cs_dblevel & D_CACHEEX) { - cs_log_dbg(D_CACHEEX, "Different CW-nodelist hop%02u: %" PRIu64 "X", ++hops, cacheex_node_id(nodeid)); + LL_LOCKITER *li = ll_li_create(er->csp_lastnodes, 0); + uint8_t *nodeid; + uint8_t hops = 0; + while((nodeid = ll_li_next(li))) + { + cs_log_dbg(D_CACHEEX, "Different CW-nodelist hop%02u: %" PRIu64 "X", ++hops, cacheex_node_id(nodeid)); + } + ll_li_destroy(li); } - ll_li_destroy(li); +#endif } } #endif @@ -611,7 +615,7 @@ static bool cw_cache_check(ECM_REQUEST *er) if(cw_cache_setting.timediff_old_cw > 0 && gone_diff > cw_cache_setting.timediff_old_cw) // late (>cw_cache_setting.timediff_old_cw) cw incoming { // log every dupe cw - if(D_CW_CACHE & cs_dblevel) + if(cs_dblevel & D_CW_CACHE) { uint8_t remotenodeid[8]; cacheex_get_srcnodeid(er, remotenodeid); @@ -633,9 +637,14 @@ static bool cw_cache_check(ECM_REQUEST *er) } else if(gone_diff > 15000) // same cw later as 15 secs { - uint8_t remotenodeid[8]; - cacheex_get_srcnodeid(er, remotenodeid); - cs_log_dbg(D_CW_CACHE,"[late-15sec+ CW] cache: %04X:%06X:%04X:%s | in: %04X:%06X:%04X:%s | diff(now): %"PRIi64" ms > %"PRIu16" - %s - hop %i%s, src-nodeid %" PRIu64 "X", cw_cache->caid, cw_cache->prid, cw_cache->srvid, cw1, er->caid, er->prid, er->srvid, cw2, gone_diff, cw_cache_setting.timediff_old_cw, (er->selected_reader && cs_strlen(er->selected_reader->label)) ? er->selected_reader->label : username(er->cacheex_src), ll_count(er->csp_lastnodes), (er->localgenerated) ? " (lg)" : "", er->csp_lastnodes ? cacheex_node_id(remotenodeid): 0); +#ifdef WITH_DEBUG + if(cs_dblevel & D_CW_CACHE) + { + uint8_t remotenodeid[8]; + cacheex_get_srcnodeid(er, remotenodeid); + cs_log_dbg(D_CW_CACHE,"[late-15sec+ CW] cache: %04X:%06X:%04X:%s | in: %04X:%06X:%04X:%s | diff(now): %"PRIi64" ms > %"PRIu16" - %s - hop %i%s, src-nodeid %" PRIu64 "X", cw_cache->caid, cw_cache->prid, cw_cache->srvid, cw1, er->caid, er->prid, er->srvid, cw2, gone_diff, cw_cache_setting.timediff_old_cw, (er->selected_reader && cs_strlen(er->selected_reader->label)) ? er->selected_reader->label : username(er->cacheex_src), ll_count(er->csp_lastnodes), (er->localgenerated) ? " (lg)" : "", er->csp_lastnodes ? cacheex_node_id(remotenodeid): 0); + } +#endif drop_cw = 1; } diff --git a/oscam-chk.c b/oscam-chk.c index afb798108..5caf94faa 100644 --- a/oscam-chk.c +++ b/oscam-chk.c @@ -53,7 +53,7 @@ static int32_t chk_class(ECM_REQUEST *er, CLASSTAB *clstab, const char *type, co if(er->caid != 0x0500 && er->caid != 0x4AE1) { return 1; } if(!clstab->bn && !clstab->an) { return 1; } - j = an = cl_n = l = 0; + j = an = cl_n = 0; if(er->caid == 0x0500) { @@ -154,6 +154,7 @@ int32_t chk_srvid_match(ECM_REQUEST *er, SIDTAB *sidtab) return (rc == 7); } +#ifdef CS_CACHEEX_AIO int32_t chk_srvid_disablecrccws_only_for_exception(ECM_REQUEST *er) { int32_t nr; @@ -169,7 +170,6 @@ int32_t chk_srvid_disablecrccws_only_for_exception(ECM_REQUEST *er) return(0); } -#ifdef CS_CACHEEX_AIO int32_t chk_srvid_no_wait_time(ECM_REQUEST *er) { int32_t nr; @@ -572,7 +572,7 @@ int32_t chk_rsfilter(struct s_reader *reader, ECM_REQUEST *er) return 1; } - rc = prid = 0; + rc = 0; caid = reader->caid; if(caid == er->caid) { diff --git a/oscam-chk.h b/oscam-chk.h index 4c66bb307..557188a61 100644 --- a/oscam-chk.h +++ b/oscam-chk.h @@ -39,8 +39,8 @@ int32_t chk_is_null_nodeid(uint8_t node_id[], uint8_t len); bool check_client(struct s_client *cl); uint16_t caidvaluetab_get_value(CAIDVALUETAB *cv, uint16_t caid, uint16_t default_value); int32_t chk_is_fakecw(uint8_t *cw); -int32_t chk_srvid_disablecrccws_only_for_exception(ECM_REQUEST *er); #ifdef CS_CACHEEX_AIO +int32_t chk_srvid_disablecrccws_only_for_exception(ECM_REQUEST *er); int32_t chk_srvid_no_wait_time(ECM_REQUEST *er); int32_t chk_srvid_localgenerated_only_exception(ECM_REQUEST *er); bool chk_nopushafter(uint16_t caid, CAIDVALUETAB *cv, int32_t ecm_time); diff --git a/oscam-conf-chk.c b/oscam-conf-chk.c index 9157438db..6d601bfd4 100644 --- a/oscam-conf-chk.c +++ b/oscam-conf-chk.c @@ -382,9 +382,9 @@ void chk_cltab(char *classasc, CLASSTAB *clstab) for(ptr1 = strtok_r(classasc, ",", &saveptr1); ptr1; ptr1 = strtok_r(NULL, ",", &saveptr1)) { ptr1 = trim(ptr1); - if(ptr1[0] == '!') + if(ptr1[0] == '!' && newclstab.bclass != NULL) { newclstab.bclass[newclstab.bn++] = (uint8_t)a2i(ptr1 + 1, 2); } - else + else if(newclstab.aclass != NULL) { newclstab.aclass[newclstab.an++] = (uint8_t)a2i(ptr1, 2); } } diff --git a/oscam-conf-mk.c b/oscam-conf-mk.c index 30232d7b5..9439f0933 100644 --- a/oscam-conf-mk.c +++ b/oscam-conf-mk.c @@ -619,7 +619,7 @@ char *mk_t_logfile(void) if(cfg.logfile) { - pos += snprintf(value + pos, needed - pos, "%s%s", dot, cfg.logfile); + snprintf(value + pos, needed - pos, "%s%s", dot, cfg.logfile); } return value; } @@ -1037,12 +1037,12 @@ char *mk_t_allowedtimeframe(struct s_auth *account) if(account->allowedtimeframe_set) { - char mytime[6]; + char mytime[8]; uint8_t day; uint8_t value_in_day = 0; uint8_t intime = 0; - uint16_t minutes =0; - uint16_t hours; + uint8_t minutes =0; + uint8_t hours; char septime[2] = {'\0'}; char sepday[2] = {'\0'}; @@ -1068,7 +1068,7 @@ char *mk_t_allowedtimeframe(struct s_auth *account) if(!intime) { cs_strncat(result, &septime[0], MAXALLOWEDTF); - snprintf(mytime, 6, "%02d:%02d", hours, minutes); + snprintf(mytime, sizeof(mytime), "%02d:%02d", hours, minutes); cs_strncat(result, mytime, MAXALLOWEDTF); cs_strncat(result, "-", MAXALLOWEDTF); septime[0] = ','; @@ -1086,7 +1086,7 @@ char *mk_t_allowedtimeframe(struct s_auth *account) } else if(intime) { - snprintf(mytime, 6, "%02d:%02d", hours, minutes); + snprintf(mytime, sizeof(mytime), "%02d:%02d", hours, minutes); cs_strncat(result, mytime, MAXALLOWEDTF); septime[0] = ','; intime = 0; diff --git a/oscam-config-account.c b/oscam-config-account.c index 935818d81..351a91041 100644 --- a/oscam-config-account.c +++ b/oscam-config-account.c @@ -634,15 +634,13 @@ int32_t init_free_userdb(struct s_auth *ptr) config_list_gc_values(account_opts, ptr); ftab_clear(&ptr->ftab); ftab_clear(&ptr->fchid); -#ifdef CS_CACHEEX_AIO - ftab_clear(&ptr->disablecrccacheex_only_for); -#endif tuntab_clear(&ptr->ttab); caidtab_clear(&ptr->ctab); NULLFREE(ptr->cltab.aclass); NULLFREE(ptr->cltab.bclass); #ifdef CS_CACHEEX cecspvaluetab_clear(&ptr->cacheex.filter_caidtab); + ftab_clear(&ptr->disablecrccacheex_only_for); #ifdef CS_CACHEEX_AIO caidtab_clear(&ptr->cacheex.localgenerated_only_caidtab); caidtab_clear(&ptr->cacheex.localgenerated_only_in_caidtab); diff --git a/oscam-config-reader.c b/oscam-config-reader.c index cd7b6cb21..dcd0ad6ac 100644 --- a/oscam-config-reader.c +++ b/oscam-config-reader.c @@ -1465,9 +1465,7 @@ void free_reader(struct s_reader *rdr) ftab_clear(&rdr->localcards); ftab_clear(&rdr->fchid); ftab_clear(&rdr->ftab); -#ifdef CS_CACHEEX_AIO ftab_clear(&rdr->disablecrccws_only_for); -#endif NULLFREE(rdr->cltab.aclass); NULLFREE(rdr->cltab.bclass); diff --git a/oscam-config.c b/oscam-config.c index e0b51b85a..67ea64cd2 100644 --- a/oscam-config.c +++ b/oscam-config.c @@ -350,14 +350,14 @@ int32_t init_provid(void) nr = 0; while(fgets(token, MAXLINESIZE, fp)) { - int32_t i, l; + int32_t i; struct s_provid *new_provid = NULL; char *tmp, *ptr1; tmp = trim(token); if(tmp[0] == '#') { continue; } - if((l = cs_strlen(tmp)) < 11) { continue; } + if(cs_strlen(tmp) < 11) { continue; } if(!(payload = strchr(token, '|'))) { continue; } *payload++ = '\0'; @@ -519,14 +519,14 @@ int32_t init_srvid(void) while(fgets(token, MAXLINESIZE, fp)) { - int32_t l, len = 0, len2, srvidtmp; + int32_t len = 0, len2, srvidtmp; uint32_t k; uint32_t pos; char *srvidasc, *prov; tmp = trim(token); if(tmp[0] == '#') { continue; } - if((l = cs_strlen(tmp)) < 6) { continue; } + if(cs_strlen(tmp) < 6) { continue; } if(!(srvidasc = strchr(token, ':'))) { continue; } if(!(payload = strchr(token, '|'))) { continue; } *payload++ = '\0'; @@ -1091,14 +1091,12 @@ int32_t init_tierid(void) nr = 0; while(fgets(token, MAXLINESIZE, fp)) { - - int32_t l; void *ptr; char *tmp, *tieridasc; tmp = trim(token); if(tmp[0] == '#') { continue; } - if((l = cs_strlen(tmp)) < 6) { continue; } + if(cs_strlen(tmp) < 6) { continue; } if(!(payload = strchr(token, '|'))) { continue; } if(!(tieridasc = strchr(token, ':'))) { continue; } *payload++ = '\0'; diff --git a/oscam-ecm.c b/oscam-ecm.c index e20abbace..c0262a9be 100644 --- a/oscam-ecm.c +++ b/oscam-ecm.c @@ -84,13 +84,11 @@ static uint8_t time_sort(ECM_CACHE *a, ECM_CACHE *b) return (((int64_t)(a->upd_time.time) * 1000ull + (int64_t) a->upd_time.millitm) > ((int64_t)(b->upd_time.time) * 1000ull + (int64_t) b->upd_time.millitm)) ? -1 : 1; } -#ifdef CS_CACHEEX static int compare_csp_hash_ecmcache(const void *arg, const void *obj) { uint32_t h = ((const ECM_CACHE*)obj)->csp_hash; return memcmp(arg, &h, 4); } -#endif void ecm_cache_cleanup(bool force) { @@ -950,8 +948,7 @@ int32_t send_dcw(struct s_client *client, ECM_REQUEST *er) #ifdef CS_CACHEEX_AIO if(er->cw_count > 0x0F000000 || er->localgenerated) { - uint32_t cw_count_cleaned; - cw_count_cleaned = er->cw_count ^= 0x0F000000; + uint32_t cw_count_cleaned = er->cw_count ^ 0x0F000000; if(cw_count_cleaned > 1) snprintf(sreason+cx, (sizeof sreason)-cx, " (cw count %d) (lg)", cw_count_cleaned); else @@ -1386,10 +1383,14 @@ void request_cw_from_readers(ECM_REQUEST *er, uint8_t stop_stage) } struct s_reader *rdr = ea->reader; - char ecmd5[17 * 3]; - cs_hexdump(0, er->ecmd5, 16, ecmd5, sizeof(ecmd5)); - cs_log_dbg(D_TRACE | D_CSP, "request_cw stage=%d to reader %s ecm hash=%s", er->stage, rdr ? rdr->label : "", ecmd5); - +#ifdef WITH_DEBUG + if (cs_dblevel & (D_TRACE | D_CSP)) + { + char ecmd5[17 * 3]; + cs_hexdump(0, er->ecmd5, 16, ecmd5, sizeof(ecmd5)); + cs_log_dbg(D_TRACE | D_CSP, "request_cw stage=%d to reader %s ecm hash=%s", er->stage, rdr ? rdr->label : "", ecmd5); + } +#endif ea->status |= REQUEST_SENT; cs_ftime(&ea->time_request_sent); @@ -1471,7 +1472,7 @@ void chk_dcw(struct s_ecm_answer *ea) ECM_REQUEST *ert = ea->er; struct s_ecm_answer *ea_list; struct s_reader *eardr = ea->reader; - if(!ert) + if(!ert || !eardr) { return; } // ecm request already answered! @@ -1481,9 +1482,13 @@ void chk_dcw(struct s_ecm_answer *ea) if(ea && ert->rc < E_NOTFOUND && ea->rc < E_NOTFOUND && memcmp(ea->cw, ert->cw, sizeof(ert->cw)) != 0) { char cw1[16 * 3 + 2], cw2[16 * 3 + 2]; - cs_hexdump(0, ea->cw, 16, cw1, sizeof(cw1)); - cs_hexdump(0, ert->cw, 16, cw2, sizeof(cw2)); - +#ifdef WITH_DEBUG + if(cs_dblevel & D_TRACE) + { + cs_hexdump(0, ea->cw, 16, cw1, sizeof(cw1)); + cs_hexdump(0, ert->cw, 16, cw2, sizeof(cw2)); + } +#endif char ip1[20] = "", ip2[20] = ""; if(ea->reader && check_client(ea->reader->client)) { cs_strncpy(ip1, cs_inet_ntoa(ea->reader->client->ip), sizeof(ip1)); } if(ert->cacheex_src) { cs_strncpy(ip2, cs_inet_ntoa(ert->cacheex_src->ip), sizeof(ip2)); } @@ -1752,6 +1757,11 @@ int32_t write_ecm_answer(struct s_reader *reader, ECM_REQUEST *er, int8_t rc, ui struct timeb now; cs_ftime(&now); +#ifdef CS_CACHEEX_AIO + uint8_t dontsetAnswered = 0; +#endif + uint8_t dontwriteStats = 0; + if(er && er->parent) { // parent is only set on reader->client->ecmtask[], but we want original er @@ -1768,6 +1778,16 @@ int32_t write_ecm_answer(struct s_reader *reader, ECM_REQUEST *er, int8_t rc, ui { return 0; } } +#ifdef CS_CACHEEX_AIO + if(rc < E_NOTFOUND && !er->localgenerated && (reader->cacheex.localgenerated_only_in || chk_lg_only(er, &reader->cacheex.lg_only_in_tab)) && !chk_srvid_localgenerated_only_exception(er)) + { + cs_log_dbg(D_CACHEEX, "reader: %s !er->localgenerated - rc: E_NOTFOUND set, no stats written for reader", reader ? reader->label : "-"); + rc = E_NOTFOUND; + dontsetAnswered = 1; + dontwriteStats = 1; + } +#endif + struct s_ecm_answer *ea = get_ecm_answer(reader, er); if(!ea) { return 0; } @@ -1784,26 +1804,24 @@ int32_t write_ecm_answer(struct s_reader *reader, ECM_REQUEST *er, int8_t rc, ui // Skip check for BISS1 - cw could be zero but still catch cw=0 by anticascading // Skip check for BISS2 - we use the extended cw, so the "simple" cw is always zero -#ifdef CS_CACHEEX_AIO - // vg2 bad/wrong chksum/ecm + // bad/wrong chksum/ecm if(rc == E_NOTFOUND && rcEx == E2_WRONG_CHKSUM) { - er->rc = E_INVALID; - er->rcEx = rcEx; - er->stage = 5; - er->reader_avail= 0; // count of available readers for ecm - er->readers= 0; // count of available used readers for ecm - er->reader_requested= 0; // count of real requested readers - er->localreader_count= 0; // count of selected local readers - er->cacheex_reader_count= 0; // count of selected cacheex mode-1 readers - er->fallback_reader_count= 0; // count of selected fb readers - er->reader_count= 0; // count of selected not fb readers - send_dcw(er->client, er); cs_log_dbg(D_READER, "ECM for reader %s was bad/has a wrong chksum!", reader ? reader->label : "-"); - cs_writeunlock(__func__, &ea->ecmanswer_lock); - return 0; + rc = E_INVALID; + rcEx = E2_WRONG_CHKSUM; + er->stage = 5; + + // dont write stats for bad/wrong chksum/ecm + dontwriteStats = 1; + + // set all other matching_readers => inactive to skip them and dont spread the bad ecm + struct s_ecm_answer *ea_list; + for(ea_list = er->matching_rdr; ea_list; ea_list = ea_list->next) + { + ea_list->status &= ~(READER_ACTIVE | READER_FALLBACK); + } } -#endif if(rc < E_NOTFOUND && cw && chk_is_null_CW(cw) && !caid_is_biss(er->caid)) { @@ -1876,7 +1894,11 @@ int32_t write_ecm_answer(struct s_reader *reader, ECM_REQUEST *er, int8_t rc, ui cs_log_dbg(D_TRACE, "notice: CW checksum check disabled"); } - if(chk_if_ignore_checksum(er, &reader->disablecrccws_only_for) && caid_is_videoguard(er->caid) && !chk_srvid_disablecrccws_only_for_exception(er)) + if(chk_if_ignore_checksum(er, &reader->disablecrccws_only_for) && caid_is_videoguard(er->caid) +#ifdef CS_CACHEEX_AIO + && !chk_srvid_disablecrccws_only_for_exception(er) +#endif + ) { uint8_t k, csum; uint8_t hit = 0; @@ -1943,7 +1965,14 @@ int32_t write_ecm_answer(struct s_reader *reader, ECM_REQUEST *er, int8_t rc, ui #endif //END -- SPECIAL CHECKs for rc - ea->status |= REQUEST_ANSWERED; +#ifdef CS_CACHEEX_AIO + if(!dontsetAnswered) + { +#endif + ea->status |= REQUEST_ANSWERED; +#ifdef CS_CACHEEX_AIO + } +#endif ea->rc = rc; ea->ecm_time = comp_timeb(&now, &ea->time_request_sent); if(ea->ecm_time < 1) { ea->ecm_time = 1; } // set ecm_time 1 if answer immediately @@ -1999,14 +2028,21 @@ int32_t write_ecm_answer(struct s_reader *reader, ECM_REQUEST *er, int8_t rc, ui #endif } - // readers stats for LB - send_reader_stat(reader, er, ea, ea->rc); - + if(!dontwriteStats) + { + // readers stats for LB + send_reader_stat(reader, er, ea, ea->rc); + } + // reader checks +#ifdef WITH_DEBUG + if(cs_dblevel & D_TRACE) + { char ecmd5[17 * 3]; cs_hexdump(0, er->ecmd5, 16, ecmd5, sizeof(ecmd5)); rdr_log_dbg(reader, D_TRACE, "ecm answer for ecm hash %s rc=%d", ecmd5, ea->rc); - + } +#endif // Update reader stats: if(ea->rc == E_FOUND) { diff --git a/oscam-garbage.c b/oscam-garbage.c index 15aae5b3b..1b0373b23 100644 --- a/oscam-garbage.c +++ b/oscam-garbage.c @@ -139,10 +139,7 @@ static void garbage_collector(void) } } - if(j < 3) - { - cs_writeunlock(__func__, &garbage_lock[i]); - } + cs_writeunlock(__func__, &garbage_lock[i]); // list has been taken out before so we don't need a lock here anymore! while(garbage) diff --git a/oscam-reader.c b/oscam-reader.c index 0c3fbc2ce..e0d4f5122 100644 --- a/oscam-reader.c +++ b/oscam-reader.c @@ -114,9 +114,14 @@ static int32_t ecm_ratelimit_findspace(struct s_reader *reader, ECM_REQUEST *er, if(reader->rlecmh[h].srvid == er->srvid && reader->rlecmh[h].caid == rl.caid && reader->rlecmh[h].provid == rl.provid && (!reader->rlecmh[h].chid || (reader->rlecmh[h].chid == rl.chid))) { - int64_t gone = comp_timeb(&actualtime, &reader->rlecmh[h].last); - cs_log_dbg(D_CLIENT, "ratelimiter found srvid %04X for %"PRId64" ms in slot %d/%d of reader %s", er->srvid, gone, h + 1, MAXECMRATELIMIT, reader->label); - + int64_t gone = 0; +#ifdef WITH_DEBUG + if(cs_dblevel & D_CLIENT) + { + gone = comp_timeb(&actualtime, &reader->rlecmh[h].last); + cs_log_dbg(D_CLIENT, "ratelimiter found srvid %04X for %"PRId64" ms in slot %d/%d of reader %s", er->srvid, gone, h + 1, MAXECMRATELIMIT, reader->label); + } +#endif // check ecmunique if enabled and ecmunique time is done if(reader_mode && reader->ecmunique) { @@ -130,11 +135,15 @@ static int32_t ecm_ratelimit_findspace(struct s_reader *reader, ECM_REQUEST *er, if(er->ecm[0] == reader->rlecmh[h].kindecm) { // same ecm type! - char ecmd5[17 * 3]; - cs_hexdump(0, reader->rlecmh[h].ecmd5, 16, ecmd5, sizeof(ecmd5)); - cs_log_dbg(D_CLIENT, "ratelimiter ecm %s in this slot for next %d ms!", ecmd5, - (int)(reader->rlecmh[h].ratelimittime - gone)); - +#ifdef WITH_DEBUG + if(cs_dblevel & D_CLIENT) + { + char ecmd5[17 * 3]; + cs_hexdump(0, reader->rlecmh[h].ecmd5, 16, ecmd5, sizeof(ecmd5)); + cs_log_dbg(D_CLIENT, "ratelimiter ecm %s in this slot for next %d ms!", ecmd5, + (int)(reader->rlecmh[h].ratelimittime - gone)); + } +#endif struct ecm_request_t *erold = NULL; if(!cs_malloc(&erold, sizeof(struct ecm_request_t))) { return -2; } @@ -259,9 +268,14 @@ static int32_t ecm_ratelimit_findspace(struct s_reader *reader, ECM_REQUEST *er, } else // occupied slots { - int64_t gone = comp_timeb(&actualtime, &reader->rlecmh[h].last); - cs_log_dbg(D_CLIENT, "ratelimiter srvid %04X for %"PRId64" ms present in slot %d/%d of reader %s", - reader->rlecmh[h].srvid, gone , h + 1, maxecms, reader->label); +#ifdef WITH_DEBUG + if(cs_dblevel & D_CLIENT) + { + int64_t gone = comp_timeb(&actualtime, &reader->rlecmh[h].last); + cs_log_dbg(D_CLIENT, "ratelimiter srvid %04X for %"PRId64" ms present in slot %d/%d of reader %s", + reader->rlecmh[h].srvid, gone , h + 1, maxecms, reader->label); + } +#endif } } diff --git a/oscam-string.c b/oscam-string.c index e2def2c04..97c0f416a 100644 --- a/oscam-string.c +++ b/oscam-string.c @@ -428,7 +428,7 @@ int32_t dyn_word_atob(char *asc) { for(i = 0, rc = 0; i < len; i++) { - if(!gethexval_within_range(asc[0]) || !gethexval_within_range(asc[1]) || !gethexval_within_range(asc[2]) || !gethexval_within_range(asc[3])) + if(!gethexval_within_range(asc[i])) { return -1; } diff --git a/reader-common.c b/reader-common.c index c6606298c..81fe2988f 100644 --- a/reader-common.c +++ b/reader-common.c @@ -549,11 +549,15 @@ void cardreader_process_ecm(struct s_reader *reader, struct s_client *cl, ECM_RE write_ecm_answer(reader, er, ea.rc, ea.rcEx, ea.cw, ea.msglog, ea.tier, &ea.cw_ex); cl->lastecm = time((time_t *)0); - char ecmd5[17 * 3]; - cs_hexdump(0, er->ecmd5, 16, ecmd5, sizeof(ecmd5)); - - rdr_log_dbg(reader, D_READER, "ecm hash: %s real time: %"PRId64" ms", ecmd5, comp_timeb(&tpe, &tps)); +#ifdef WITH_DEBUG + if(cs_dblevel & D_READER) + { + char ecmd5[17 * 3]; + cs_hexdump(0, er->ecmd5, 16, ecmd5, sizeof(ecmd5)); + rdr_log_dbg(reader, D_READER, "ecm hash: %s real time: %"PRId64" ms", ecmd5, comp_timeb(&tpe, &tps)); + } +#endif reader_post_process(reader); } diff --git a/reader-cryptoworks.c b/reader-cryptoworks.c index e532902d7..456e14c8e 100644 --- a/reader-cryptoworks.c +++ b/reader-cryptoworks.c @@ -496,8 +496,13 @@ static int32_t cryptoworks_get_emm_type(EMM_PACKET *ep, struct s_reader *rdr) ep->type = UNIQUE; memset(ep->hexserial, 0, 8); memcpy(ep->hexserial, ep->emm + 5, 5); - cs_hexdump(1, rdr->hexserial, 5, dumprdrserial, sizeof(dumprdrserial)); - cs_hexdump(1, ep->hexserial, 5, dumpemmserial, sizeof(dumpemmserial)); +#ifdef WITH_DEBUG + if(cs_dblevel & D_EMM) + { + cs_hexdump(1, rdr->hexserial, 5, dumprdrserial, sizeof(dumprdrserial)); + cs_hexdump(1, ep->hexserial, 5, dumpemmserial, sizeof(dumpemmserial)); + } +#endif i2b_buf(4, cryptoworks_get_emm_provid(ep->emm + 12, ep->emmlen - 12), ep->provid); rdr_log_dbg_sensitive(rdr, D_EMM, "UNIQUE, ep = {%s} rdr = {%s}", dumpemmserial, dumprdrserial); return (!memcmp(ep->emm + 5, rdr->hexserial, 5)); // check for serial @@ -510,8 +515,13 @@ static int32_t cryptoworks_get_emm_type(EMM_PACKET *ep, struct s_reader *rdr) ep->type = SHARED; memset(ep->hexserial, 0, 8); memcpy(ep->hexserial, ep->emm + 5, 4); - cs_hexdump(1, rdr->hexserial, 4, dumprdrserial, sizeof(dumprdrserial)); - cs_hexdump(1, ep->hexserial, 4, dumpemmserial, sizeof(dumpemmserial)); +#ifdef WITH_DEBUG + if(cs_dblevel & D_EMM) + { + cs_hexdump(1, rdr->hexserial, 4, dumprdrserial, sizeof(dumprdrserial)); + cs_hexdump(1, ep->hexserial, 4, dumpemmserial, sizeof(dumpemmserial)); + } +#endif i2b_buf(4, cryptoworks_get_emm_provid(ep->emm + 12, ep->emmlen - 12), ep->provid); rdr_log_dbg_sensitive(rdr, D_EMM, "SHARED, ep = {%s} rdr = {%s}", dumpemmserial, dumprdrserial); return (!memcmp(ep->emm + 5, rdr->hexserial, 4)); // check for SA diff --git a/reader-dre-cas.c b/reader-dre-cas.c index 0fb569205..d3bc3815d 100644 --- a/reader-dre-cas.c +++ b/reader-dre-cas.c @@ -535,7 +535,7 @@ static int32_t drecas_card_init(struct s_reader *reader, ATR *newatr) do { tempbuf[0] = '\0'; - if(usercmd != NULL) free(usercmd); + if(usercmd != NULL) NULLFREE(usercmd); if(fgets(tempbuf, 2048, pFile) == NULL) continue; @@ -571,7 +571,7 @@ static int32_t drecas_card_init(struct s_reader *reader, ATR *newatr) rdr_log(reader, "Can't open script file (%s)", reader->userscript); } - //if(usercmd != NULL) free(usercmd); + if(usercmd != NULL) free(usercmd); if(tempbuf != NULL) free(tempbuf); } diff --git a/reader-dre-common.c b/reader-dre-common.c index 3942ed47c..1f530f96e 100644 --- a/reader-dre-common.c +++ b/reader-dre-common.c @@ -367,7 +367,6 @@ static void rcu_load(uint8_t *rcu) { uint32_t destructors[rcuh.dessize / sizeof(int)]; rcu_load_offs(destructors, ptr, rcuh.dessize); - ptr += rcuh.dessize; } ptr = rcu_data + rcu_data_size - 16 + 4; diff --git a/reader-dre.c b/reader-dre.c index 9213133b2..f9d922234 100644 --- a/reader-dre.c +++ b/reader-dre.c @@ -594,7 +594,7 @@ static int32_t dre_card_init(struct s_reader *reader, ATR *newatr) do { tempbuf[0] = '\0'; - if(usercmd != NULL) free(usercmd); + if(usercmd != NULL) NULLFREE(usercmd); if(fgets(tempbuf, 2048, pFile) == NULL) continue; @@ -648,7 +648,7 @@ static int32_t dre_card_init(struct s_reader *reader, ATR *newatr) rdr_log(reader, "Can't open script file (%s)", reader->userscript); } - //if(usercmd != NULL) free(usercmd); + if(usercmd != NULL) free(usercmd); if(tempbuf != NULL) free(tempbuf); } diff --git a/reader-irdeto.c b/reader-irdeto.c index ea4881588..0c2972b55 100644 --- a/reader-irdeto.c +++ b/reader-irdeto.c @@ -856,8 +856,13 @@ static int32_t irdeto_get_emm_type(EMM_PACKET *ep, struct s_reader *rdr) ep->type = SHARED; memset(ep->hexserial, 0, 8); memcpy(ep->hexserial, ep->emm + 4, l); - cs_hexdump(1, rdr->hexserial, l, dumprdrserial, sizeof(dumprdrserial)); - cs_hexdump(1, ep->hexserial, l, dumpemmserial, sizeof(dumpemmserial)); +#ifdef WITH_DEBUG + if(cs_dblevel & D_EMM) + { + cs_hexdump(1, rdr->hexserial, l, dumprdrserial, sizeof(dumprdrserial)); + cs_hexdump(1, ep->hexserial, l, dumpemmserial, sizeof(dumpemmserial)); + } +#endif rdr_log_dbg_sensitive(rdr, D_EMM, "SHARED l = %d ep = {%s} rdr = {%s} base = %02x", l, dumpemmserial, dumprdrserial, base); @@ -890,11 +895,16 @@ static int32_t irdeto_get_emm_type(EMM_PACKET *ep, struct s_reader *rdr) ep->type = UNIQUE; memset(ep->hexserial, 0, 8); memcpy(ep->hexserial, ep->emm + 4, l); - cs_hexdump(1, rdr->hexserial, l, dumprdrserial, sizeof(dumprdrserial)); - cs_hexdump(1, ep->hexserial, l, dumpemmserial, sizeof(dumpemmserial)); - rdr_log_dbg_sensitive(rdr, D_EMM, "UNIQUE l = %d ep = {%s} rdr = {%s} base = %02x", - l, dumpemmserial, dumprdrserial, base); +#ifdef WITH_DEBUG + if(cs_dblevel & D_EMM) + { + cs_hexdump(1, rdr->hexserial, l, dumprdrserial, sizeof(dumprdrserial)); + cs_hexdump(1, ep->hexserial, l, dumpemmserial, sizeof(dumpemmserial)); + rdr_log_dbg_sensitive(rdr, D_EMM, "UNIQUE l = %d ep = {%s} rdr = {%s} base = %02x", + l, dumpemmserial, dumprdrserial, base); + } +#endif if(base & 0x10) // unique hex addressed { return ((base == rdr->hexserial[3]) && (!memcmp(ep->emm + 4, rdr->hexserial, l))); diff --git a/webif/cacheexaio/cacheex_tablerow.html b/webif/cacheexaio/cacheex_tablerow.html new file mode 100644 index 000000000..1aefc901b --- /dev/null +++ b/webif/cacheexaio/cacheex_tablerow.html @@ -0,0 +1 @@ +  ##DIRECTIONIMG##  ##TYPE####NAME####IP####NODE####LEVEL####PUSH####PUSHLG####GOT####GOTLG####HIT####REL_CACHEXHITGOT####CWCINFO####ERRCW####ERR## diff --git a/webif/cacheexaio/cacheex_tablerow_stats.html b/webif/cacheexaio/cacheex_tablerow_stats.html index 502939b96..8e6d52dcf 100644 --- a/webif/cacheexaio/cacheex_tablerow_stats.html +++ b/webif/cacheexaio/cacheex_tablerow_stats.html @@ -1 +1 @@ -   ##DIRECTIONIMG##  ##TYPE####NAME####IP####NODE####LEVEL####PUSH####PUSHLG####GOT####GOTLG####HIT####REL_CACHEXHITGOT####CWCINFO####ERRCW####ERR## +   ##DIRECTIONIMG##  ##TYPE####NAME####IP####NODE####LEVEL####PUSH####PUSHLG####GOT####GOTLG####HIT####REL_CACHEXHITGOT####CWCINFO####ERRCW####ERR## diff --git a/webif/pages_index.txt b/webif/pages_index.txt index 83c79e5a8..919c5c9e9 100644 --- a/webif/pages_index.txt +++ b/webif/pages_index.txt @@ -46,7 +46,8 @@ CACHEEXPAGE cacheex/cacheex.html CACHEEXTABLEROW cacheex/cacheex_tablerow.html CS_CACHEEX CACHEEXAIOPAGE cacheexaio/cacheex.html CS_CACHEEX_AIO -CACHEEXAIOTABLEROW cacheexaio/cacheex_tablerow_stats.html CS_CACHEEX_AIO +CACHEEXAIOTABLEROW cacheexaio/cacheex_tablerow.html CS_CACHEEX_AIO +CACHEEXAIOTABLEROWSTATS cacheexaio/cacheex_tablerow_stats.html CS_CACHEEX_AIO CONFIGANTICASC config/anticasc.html CS_ANTICASC CONFIGCACHE config/cache.html diff --git a/webif/services_edit/services_edit.html b/webif/services_edit/services_edit.html index c9b9d8b33..80b4af881 100644 --- a/webif/services_edit/services_edit.html +++ b/webif/services_edit/services_edit.html @@ -13,7 +13,6 @@ Caid: Provid: Srvid: - Disable CRC-check