Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[trunk] Sync with 11725 #68

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .trunk-svn
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11720
11726
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,15 @@ ifeq ($(uname_S),FreeBSD)
DEFAULT_LIBUSB_LIB = -lusb
endif
ifeq ($(uname_S),Darwin)
DEFAULT_LIBUSB_FLAGS = -I/opt/local/include
DEFAULT_LIBUSB_LIB = -L/opt/local/lib -lusb-1.0
DEFAULT_PCSC_FLAGS = -isysroot $(OSX_SDK)
DEFAULT_PCSC_LIB = -isysroot $(OSX_SDK) -framework IOKit -framework CoreFoundation -framework PCSC
FIX_OPENSSL_FLAGS_DIR := $(shell ln -sf /usr/local/opt/[email protected]/include/openssl /usr/local/include)
FIX_OPENSSL_LIB_DIR := $(shell ln -sf /usr/local/opt/[email protected]/lib/libssl.1.1.dylib /usr/local/lib)
FIX_OPENSSL_LIBCRYPTO_DIR := $(shell ln -sf /usr/local/opt/[email protected]/lib/libcrypto.1.1.dylib /usr/local/lib)
DEFAULT_LIBCRYPTO_LIB = -L/usr/local/opt/[email protected]/lib -lcrypto
DEFAULT_SSL_LIB = -L/usr/local/opt/[email protected]/lib -lssl
DEFAULT_LIBUSB_FLAGS = -I/usr/local/opt/libusb/include
DEFAULT_LIBUSB_LIB = -L/usr/local/opt/libusb/lib -lusb-1.0 -framework IOKit -framework CoreFoundation -framework Security
DEFAULT_PCSC_FLAGS = -I/usr/local/opt/pcsc-lite/include/PCSC
DEFAULT_PCSC_LIB = -L/usr/local/opt/pcsc-lite/lib -framework IOKit -framework CoreFoundation -framework PCSC
else
# Get the compiler's last include PATHs. Basicaly it is /usr/include
# but in case of cross compilation it might be something else.
Expand Down
13 changes: 11 additions & 2 deletions csctapi/ifd_pcsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,24 @@
#define __nullnullterminated
#include <specstrings.h>
#include <WinSCard.h>
#else
#endif

#if !defined(__CYGWIN__)
#if !defined(__APPLE__)
#include <PCSC/pcsclite.h>
#include <PCSC/winscard.h>
#include <PCSC/wintypes.h>
#if !defined(__APPLE__)
#include <PCSC/reader.h>
#endif
#endif

#if defined(__APPLE__)
#include "pcsclite.h"
#include "winscard.h"
#include "wintypes.h"
#include "reader.h"
#endif

#ifndef ERR_INVALID
#define ERR_INVALID -1
#endif
Expand Down
51 changes: 45 additions & 6 deletions csctapi/io_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
#include "icc_async.h"
#include "io_serial.h"

#if defined(__APPLE__)
#include <IOKIT/serial/ioss.h>
#endif

#define OK 0
#define ERROR 1

Expand Down Expand Up @@ -134,25 +138,35 @@ bool IO_Serial_DTR_RTS(struct s_reader *reader, int32_t *dtr, int32_t *rts)
bool IO_Serial_SetBitrate(struct s_reader *reader, uint32_t bitrate, struct termios *tio)
{
/* Set the bitrate */
#if defined(__linux__)
//FIXME workaround for Smargo until native mode works
if((reader->mhz == reader->cardmhz) && (reader->smargopatch != 1) && IO_Serial_Bitrate(bitrate) != B0)
#else
#if !defined(__linux__)
#if !defined(__APPLE__)
if(IO_Serial_Bitrate(bitrate) == B0)
{
rdr_log(reader, "Baudrate %u not supported", bitrate);
return ERROR;
}
else
#endif
{
//no overclocking
cfsetospeed(tio, IO_Serial_Bitrate(bitrate));
cfsetispeed(tio, IO_Serial_Bitrate(bitrate));
rdr_log_dbg(reader, D_DEVICE, "standard baudrate: cardmhz=%d mhz=%d -> effective baudrate %u",
reader->cardmhz, reader->mhz, bitrate);
}
#endif
#endif

/* Set the bitrate */
#if defined(__linux__)
//FIXME workaround for Smargo until native mode works
if((reader->mhz == reader->cardmhz) && (reader->smargopatch != 1) && IO_Serial_Bitrate(bitrate) != B0)
{
//no overclocking
cfsetospeed(tio, IO_Serial_Bitrate(bitrate));
cfsetispeed(tio, IO_Serial_Bitrate(bitrate));
rdr_log_dbg(reader, D_DEVICE, "standard baudrate: cardmhz=%d mhz=%d -> effective baudrate %u",
reader->cardmhz, reader->mhz, bitrate);
}
else
{
//over or underclocking
Expand Down Expand Up @@ -186,6 +200,31 @@ bool IO_Serial_SetBitrate(struct s_reader *reader, uint32_t bitrate, struct term
cfsetispeed(tio, IO_Serial_Bitrate(38400));
}
#endif

/* Set the bitrate */
#if defined(__APPLE__)
if(IO_Serial_Bitrate(bitrate) == B0)
{
if(ioctl(reader->handle, IOSSIOSPEED, &bitrate) < 0)
{
rdr_log(reader, "Baudrate %u not supported", bitrate);
return ERROR;
}
else
{
rdr_log_dbg(reader, D_DEVICE, "custom baudrate: cardmhz=%d mhz=%d -> effective baudrate %u",
reader->cardmhz, reader->mhz, bitrate);
}
}
else
{
//no overclocking
cfsetospeed(tio, IO_Serial_Bitrate(bitrate));
cfsetispeed(tio, IO_Serial_Bitrate(bitrate));
rdr_log_dbg(reader, D_DEVICE, "standard baudrate: cardmhz=%d mhz=%d -> effective baudrate %u",
reader->cardmhz, reader->mhz, bitrate);
}
#endif
return OK;
}

Expand Down Expand Up @@ -620,7 +659,7 @@ static int32_t IO_Serial_Bitrate(int32_t bitrate)
{ 115200, B115200 },
#endif
#ifdef B76800
{ 76800, B76800 },
{ 76800, B76800 },
#endif
#ifdef B57600
{ 57600, B57600 },
Expand Down
20 changes: 20 additions & 0 deletions globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
#include <termios.h>
#include <inttypes.h>
#include <sys/utsname.h>

#if !defined(__APPLE__)
#include <sys/sysmacros.h>
#endif

/*
* The following hack is taken from Linux: include/linux/kconfig.h
Expand All @@ -60,6 +63,11 @@
# define WITH_LIBCRYPTO 1
#endif

/* For deprecated but still needed cryptography functions:
* 10002 corresponds to OpenSSL version 1.0.2*/

#define OPENSSL_API_COMPAT 10002

#if defined(__CYGWIN__) || defined(__arm__) || defined(__SH4__) || defined(__MIPS__) || defined(__MIPSEL__) || defined(__powerpc__)
# define CS_LOGFILE "/dev/tty"
#endif
Expand Down Expand Up @@ -409,6 +417,8 @@
#define MAX_EMM_SIZE 512
#endif

#define MAX_CMD_SIZE 0xff + 5 // maximum value from length byte + command header

#ifdef WITH_EMU
#define CS_EMMCACHESIZE 1024 // nr of EMMs that EMU reader will cache
#else
Expand Down Expand Up @@ -901,6 +911,7 @@ typedef struct s_entitlement // contains entitlement Info
struct s_client;
struct ecm_request_t;
struct emm_packet_t;
struct cmd_packet_t;
struct s_ecm_answer;
struct demux_s;

Expand Down Expand Up @@ -1007,6 +1018,7 @@ struct s_cardsystem
int32_t (*do_ecm)(struct s_reader *, const struct ecm_request_t *, struct s_ecm_answer *);
int32_t (*do_emm_reassembly)(struct s_reader *, struct s_client *, struct emm_packet_t *); // Returns 1/true if the EMM is ready to be written in the card
int32_t (*do_emm)(struct s_reader *, struct emm_packet_t *);
int32_t (*do_rawcmd)(struct s_reader *, struct cmd_packet_t *);
void (*post_process)(struct s_reader *);
int32_t (*get_emm_type)(struct emm_packet_t *, struct s_reader *);
int32_t (*get_emm_filter)(struct s_reader *, struct s_csystem_emm_filter **, uint32_t *);
Expand Down Expand Up @@ -1535,6 +1547,13 @@ typedef struct emm_packet_t
struct s_client *client;
} EMM_PACKET;

typedef struct cmd_packet_t
{
uint8_t cmd[MAX_CMD_SIZE];
int16_t cmdlen;
struct s_client *client;
} CMD_PACKET;

struct s_reader // contains device info, reader info and card info
{
uint8_t keepalive;
Expand Down Expand Up @@ -1895,6 +1914,7 @@ struct s_reader // contains device info, reader info and card info
int8_t readtiers; // method to get videoguard tiers
uint8_t ins7E[0x1A + 1];
uint8_t ins7E11[0x01 + 1];
uint8_t ins42[0x25 + 1];
uint8_t ins2e06[0x04 + 1];
int8_t ins7e11_fast_reset;
uint8_t k1_generic[0x10 + 1]; // k1 for generic pairing mode
Expand Down
76 changes: 76 additions & 0 deletions module-webif.c
Original file line number Diff line number Diff line change
Expand Up @@ -2900,6 +2900,11 @@ static char *send_oscam_reader_config(struct templatevars *vars, struct uriparam
{
for(i = 0; i < 26 ; i++) { tpl_printf(vars, TPLAPPEND, "INS7E", "%02X", rdr->ins7E[i]); }
}
// ins42
if(rdr->ins42[0x25])
{
for(i = 0; i < 37 ; i++) { tpl_printf(vars, TPLAPPEND, "INS42", "%02X", rdr->ins42[i]); }
}

// ins7E11
if(rdr->ins7E11[0x01])
Expand Down Expand Up @@ -8586,6 +8591,77 @@ static char *send_oscam_api(struct templatevars * vars, FILE * f, struct uripara
return tpl_getTpl(vars, "APIERROR");
}
}
else if(strcmp(getParam(params, "part"), "sendcmd") == 0)
{
if(strcmp(getParam(params, "label"), ""))
{
struct s_reader *rdr = get_reader_by_label(getParam(params, "label"));
if(rdr)
{
char api_msg[150];
CMD_PACKET *cmd_pack = NULL;
if(!cs_malloc(&cmd_pack, sizeof(CMD_PACKET)))
{
tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", "cs_malloc failed!");
return tpl_getTpl(vars, "APIERROR");
}
struct s_client *webif_client = cur_client();
webif_client->grp = 0xFF; // access all readers

memset(cmd_pack, '0', sizeof(CMD_PACKET));
cmd_pack->client = webif_client;
cmd_pack->cmdlen = strlen(getParam(params, "cmd")) / 2;

if(cmd_pack->cmdlen > 0 && abs(cmd_pack->cmdlen) <= sizeof(cmd_pack->cmd))
{
if(key_atob_l(getParam(params, "cmd"), cmd_pack->cmd, cmd_pack->cmdlen*2))
{
tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", "'cmd' has not been sent due to wrong value!");
return tpl_getTpl(vars, "APIERROR");
}
}
else
{
if(cmd_pack->cmdlen)
{
snprintf(api_msg, sizeof(api_msg), "Command would exceed %lu bytes!", (long unsigned int)sizeof(cmd_pack->cmd));
tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", api_msg);
}
else
{
tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", "Missing parameter 'cmd'!");
}
return tpl_getTpl(vars, "APIERROR");
}

struct s_client *cl = rdr->client;
if(rdr->enable == 1 && cl && cl->typ == 'r')
{
add_job(cl, ACTION_READER_SENDCMD, cmd_pack, sizeof(CMD_PACKET));
tpl_addVar(vars, TPLADD, "APICONFIRMMESSAGE", "command sent");
return tpl_getTpl(vars, "APICONFIRMATION");
}
else
{
snprintf(api_msg, sizeof(api_msg), "Reader '%s' is not suitable!", xml_encode(vars, rdr->label));
tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", api_msg);
return tpl_getTpl(vars, "APIERROR");
}
}
else
{
//Send Errormessage
tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", "no such reader");
return tpl_getTpl(vars, "APIERROR");
}
}
else
{
//Send Errormessage
tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", "no reader selected");
return tpl_getTpl(vars, "APIERROR");
}
}
else if(strcmp(getParam(params, "part"), "shutdown") == 0)
{
if((strcmp(strtolower(getParam(params, "action")), "restart") == 0) ||
Expand Down
31 changes: 30 additions & 1 deletion oscam-config-reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,34 @@ static void ins7E_fn(const char *token, char *value, void *setting, long var_siz
{ fprintf_conf(f, token, "\n"); }
}

static void ins42_fn(const char *token, char *value, void *setting, long var_size, FILE *f)
{
uint8_t *var = setting;
var_size -= 1; // var_size contains sizeof(var) which is [X + 1]
if(value)
{
int32_t len = cs_strlen(value);
if(len != var_size * 2 || key_atob_l(value, var, len))
{
if(len > 0)
{ fprintf(stderr, "reader %s parse error, %s=%s\n", token, token, value); }
memset(var, 0, var_size + 1);
}
else
{
var[var_size] = 1; // found and correct
}
return;
}
if(var[var_size])
{
char tmp[var_size * 2 + 1];
fprintf_conf(f, token, "%s\n", cs_hexdump(0, var, var_size, tmp, sizeof(tmp)));
}
else if(cfg.http_full_cfg)
{ fprintf_conf(f, token, "\n"); }
}

static void des_and_3des_key_fn(const char *token, char *value, void *setting, FILE *f)
{
uint8_t *var = setting;
Expand Down Expand Up @@ -1844,6 +1872,7 @@ static const struct config_list reader_opts[] =

DEF_OPT_INT8("cak7_mode" , OFS(cak7_mode), 0),
DEF_OPT_FUNC_X("ins7e" , OFS(ins7E), ins7E_fn, SIZEOF(ins7E)),
DEF_OPT_FUNC_X("ins42" , OFS(ins42), ins42_fn, SIZEOF(ins42)),
DEF_OPT_FUNC_X("ins7e11" , OFS(ins7E11), ins7E_fn, SIZEOF(ins7E11)),
DEF_OPT_FUNC_X("ins2e06" , OFS(ins2e06), ins7E_fn, SIZEOF(ins2e06)),
DEF_OPT_FUNC("k1_generic" , OFS(k1_generic), des_and_3des_key_fn),
Expand Down Expand Up @@ -1953,7 +1982,7 @@ static bool reader_check_setting(const struct config_list *UNUSED(clist), void *
static const char *hw_only_settings[] =
{
"readnano", "resetcycle", "smargopatch", "autospeed", "sc8in1_dtrrts_patch", "boxid","fix07",
"fix9993", "rsakey", "deskey", "ins7e", "ins7e11", "ins2e06", "k1_generic", "k1_unique", "force_irdeto", "needsemmfirst", "boxkey",
"fix9993", "rsakey", "deskey", "ins7e", "ins42", "ins7e11", "ins2e06", "k1_generic", "k1_unique", "force_irdeto", "needsemmfirst", "boxkey",
"atr", "detect", "nagra_read", "mhz", "cardmhz", "readtiers", "read_old_classes", "use_gpio", "needsglobalfirst",
#ifdef READER_NAGRA_MERLIN
"mod1", "idird", "cmd0eprov", "mod2", "key3588", "key3460", "key3310", "data50", "mod50", "nuid", "forcepair", "otpcsc", "otacsc", "cwpkcaid", "cwekey0", "cwekey1", "cwekey2", "cwekey3", "cwekey4", "cwekey5", "cwekey6", "cwekey7",
Expand Down
23 changes: 22 additions & 1 deletion oscam-work.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void *work_thread(void *ptr)
{ return NULL; }

cl->work_mbuf = mbuf; // Track locally allocated data, because some callback may call cs_exit/cs_disconect_client/pthread_exit and then mbuf would be leaked
int32_t n = 0, rc = 0, i, idx, s;
int32_t n = 0, rc = 0, i, idx, s, dblvl;
uint8_t dcw[16];
int8_t restart_reader = 0;

Expand Down Expand Up @@ -301,6 +301,27 @@ void *work_thread(void *ptr)
reader_do_emm(reader, data->ptr);
break;

case ACTION_READER_SENDCMD:
dblvl = cs_dblevel;
cs_dblevel = dblvl | D_READER;
rc = cardreader_do_rawcmd(reader, data->ptr);
cs_log_dbg(D_TRACE, "sendcmd rc: %i, csystem: %s", rc, reader->csystem->desc);
if(rc == -9)
{
CMD_PACKET *cp = data->ptr;
uint8_t response[MAX_CMD_SIZE];
memset(response, 0, sizeof(response));
uint16_t response_length[1] = { 0 };
rc = reader_cmd2icc(reader, cp->cmd, cp->cmdlen, response, response_length);
cs_log_dbg(D_TRACE, "sendcmd rc: %i, len: %i", rc, *response_length);
if (*response_length)
{
cs_log_dump_dbg(D_TRACE, response, *response_length, "sendcmd response:");
}
}
cs_dblevel = dblvl;
break;

case ACTION_READER_CARDINFO:
reader_do_card_info(reader);
break;
Expand Down
1 change: 1 addition & 0 deletions oscam-work.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum actions
// Client actions
ACTION_CLIENT_UDP = 22, // wc22
ACTION_CLIENT_TCP = 23, // wc23
ACTION_READER_SENDCMD = 15, // wr15
ACTION_CLIENT_KILL = 24, // wc24
ACTION_CLIENT_INIT = 25, // wc25
ACTION_CLIENT_IDLE = 26, // wc26
Expand Down
Loading
Loading