Skip to content

Commit

Permalink
Add support Tongfang3 (NTIC2) CAS (Thanks to @nx111)
Browse files Browse the repository at this point in the history
  • Loading branch information
fairbird committed Oct 3, 2024
1 parent 748cbb9 commit a6d32b3
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 99 deletions.
10 changes: 8 additions & 2 deletions globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -1692,8 +1692,14 @@ struct s_reader
CAIDTAB ctab;
uint32_t boxid;
#ifdef READER_TONGFANG
uint32_t tongfang3_calibsn;
uint8_t tongfang3_commkey[8];
uint32_t tongfang_version;
uint8_t tongfang3_commkey[8];
uint32_t tongfang3_calibsn;
uint32_t tongfang_boxid;
uint8_t tongfang3_deskey[8];
uint8_t tongfang3_deskey_length;
uint8_t stbid[8];
uint8_t stbid_length;
#endif
#ifdef READER_JET
uint8_t jet_vendor_key[32];
Expand Down
3 changes: 1 addition & 2 deletions module-cccam.c
Original file line number Diff line number Diff line change
Expand Up @@ -1289,8 +1289,7 @@ int32_t get_UA_ofs(uint16_t caid)
case 0x0D: // CRYPTOWORKS
//ofs = 1;
//break;
case 0x4A: // STREAMGUARD:
case 0x4B: // TONGFANG
case 0x4A: // TONGFANG
case 0x09: // VIDEOGUARD
case 0x0B: // CONAX
case 0x18: // NAGRA
Expand Down
18 changes: 18 additions & 0 deletions module-webif.c
Original file line number Diff line number Diff line change
Expand Up @@ -3128,6 +3128,24 @@ static char *send_ncam_reader_config(struct templatevars *vars, struct uriparams
if(rdr->tongfang3_calibsn)
{ tpl_printf(vars, TPLADD, "TONGFANGCALIBSN", "%08X", rdr->tongfang3_calibsn); }

if(rdr->tongfang_boxid)
{ tpl_printf(vars, TPLADD, "TONGFANGBOXID", "%08X", rdr->tongfang_boxid); }

if(rdr->tongfang3_deskey_length > 0)
{
for(i = 0; i < rdr->tongfang3_deskey_length ; i++)
{
tpl_printf(vars, TPLAPPEND, "TONGFANGDESKEY", "%02X", rdr->tongfang3_deskey[i]);
}
}

if(rdr->stbid_length > 0)
{
for(i = 0; i < rdr->stbid_length ; i++)
{
tpl_printf(vars, TPLAPPEND, "STBID", "%02X", rdr->stbid[i]);
}
}
#endif
#ifdef READER_JET
for(i = 0; (size_t)i < sizeof(rdr->jet_authorize_id) && rdr->jet_authorize_id[i] == 0; i++);
Expand Down
98 changes: 97 additions & 1 deletion ncam-config-reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,104 @@ static void tongfang3_calibsn_fn(const char *token, char *value, void *setting,
struct s_reader *rdr = setting;
if(value)
{
rdr->tongfang3_calibsn = cs_strlen(value) ? a2i(value, 4) : 0;
rdr->tongfang3_calibsn = strlen(value) ? a2i(value, 4) : 0;
return;
}
if(rdr->tongfang3_calibsn)
fprintf_conf(f, token, "%08X\n", rdr->tongfang3_calibsn);
else if(cfg.http_full_cfg)
{ fprintf_conf(f, token, "\n"); }
}

static void tongfang_boxid_fn(const char *token, char *value, void *setting, FILE *f)
{
struct s_reader *rdr = setting;
if(value)
{
rdr->tongfang_boxid = cs_strlen(value) ? a2i(value, 4) : 0;
return;
}
if(rdr->tongfang_boxid)
{ fprintf_conf(f, token, "%08X\n", rdr->tongfang_boxid); }
else if(cfg.http_full_cfg)
{ fprintf_conf(f, token, "\n"); }
}

static void stbid_fn(const char *token, char *value, void *setting, FILE *f)
{
struct s_reader *rdr = setting;
if(value)
{
int32_t len = cs_strlen(value);
if(len != 16)
{
rdr->stbid_length = 0;
memset(rdr->stbid, 0, 8);
}
else
{
if(key_atob_l(value, rdr->stbid, len))
{
fprintf(stderr, "reader stbid parse error, %s=%s\n", token, value);
rdr->stbid_length = 0;
memset(rdr->stbid, 0, sizeof(rdr->stbid));
}
else
{
rdr->stbid_length = len/2;
}
}
return;
}
int32_t len = rdr->stbid_length;
if(len > 0)
{
char tmp[len * 2 + 1];
fprintf_conf(f, "stbid", "%s\n", cs_hexdump(0, rdr->stbid, len, tmp, sizeof(tmp)));
}
else if(cfg.http_full_cfg)
{
fprintf_conf(f, "stbid", "\n");
}
}

static void tongfang3_deskey_fn(const char *token, char *value, void *setting, FILE *f)
{
struct s_reader *rdr = setting;
if(value)
{
int32_t len = cs_strlen(value);
if(len != 16)
{
rdr->tongfang3_deskey_length = 0;
memset(rdr->tongfang3_deskey, 0, 8);
}
else
{
if(key_atob_l(value, rdr->tongfang3_deskey, len))
{
fprintf(stderr, "reader tongfang3_deskey parse error, %s=%s\n", token, value);
rdr->tongfang3_deskey_length = 0;
memset(rdr->tongfang3_deskey, 0, sizeof(rdr->tongfang3_deskey));
}
else
{
rdr->tongfang3_deskey_length = len/2;
}
}
return;
}
int32_t len = rdr->tongfang3_deskey_length;
if(len > 0)
{
char tmp[len * 2 + 1];
fprintf_conf(f, "tongfang3_deskey", "%s\n", cs_hexdump(0, rdr->tongfang3_deskey, len, tmp, sizeof(tmp)));
}
else if(cfg.http_full_cfg)
{
fprintf_conf(f, "tongfang3_deskey", "\n");
}
}
#endif

static void rsakey_fn(const char *token, char *value, void *setting, FILE *f)
Expand Down Expand Up @@ -1300,6 +1390,9 @@ static const struct config_list reader_opts[] =
#endif
#ifdef READER_TONGFANG
DEF_OPT_FUNC("tongfang3_calibsn" , 0, tongfang3_calibsn_fn),
DEF_OPT_FUNC("tongfang_boxid" , 0, tongfang_boxid_fn),
DEF_OPT_FUNC("stbid" , 0, stbid_fn),
DEF_OPT_FUNC("tongfang3_deskey" , 0, tongfang3_deskey_fn),
#endif
#ifdef READER_JET
DEF_OPT_FUNC("jet_authorize_id" , 0, jet_authorize_id_fn),
Expand Down Expand Up @@ -1444,6 +1537,9 @@ static bool reader_check_setting(const struct config_list *UNUSED(clist), void *
#if defined(READER_DRE) || defined(READER_DRECAS)
"exec_cmd_file",
#endif
#if defined(READER_TONGFANG)
"tongfang3_calibsn", "tongfang_boxid", "stbid", "tongfang3_deskey",
#endif
#ifdef WITH_AZBOX
"mode",
#endif
Expand Down
Loading

0 comments on commit a6d32b3

Please sign in to comment.