Skip to content

Commit

Permalink
Merge branch 'oscam-svn' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
oscam-emu committed Oct 25, 2020
2 parents be8465d + 584302f commit d08b705
Show file tree
Hide file tree
Showing 36 changed files with 489 additions and 240 deletions.
73 changes: 44 additions & 29 deletions csctapi/ifd_smartreader.c
Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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;
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions csctapi/protocol_t1.c
Expand Up @@ -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);
Expand All @@ -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!
Expand Down
10 changes: 5 additions & 5 deletions globals.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions module-cacheex.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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++; }
Expand Down
4 changes: 2 additions & 2 deletions module-cacheex.h
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit d08b705

Please sign in to comment.