Skip to content

Commit

Permalink
Fix SECA/Nagra card unable to start in CAK7 mode on PCSC and Tongfang…
Browse files Browse the repository at this point in the history
… code clean up.

* Fix bug where SECA/Nagra card unable to start in CAK7 mode on PCSC reader (Thanks to @kind regards)
* Tongfang code clean up
* Tongfang webif code clean up

cherry-pick > https://git.streamboard.tv/common/oscam/-/commit/763df442882a4e9bd1d8e6c46ee20da88bc1bd6e
  • Loading branch information
fairbird committed Oct 6, 2024
1 parent c7cb235 commit 0ee6845
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion csctapi/icc_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ int32_t ICC_Async_Activate(struct s_reader *reader, ATR *atr, uint16_t deprecate
{
reader->crdr_flush = crdr_ops->flush; // Flush flag may be changed for each reader
call(crdr_ops->activate(reader, atr));
if(reader->typ == R_EMU)
if((crdr_ops->skip_extra_atr_parsing) && (reader->cak7_mode == 0))
{
return OK;
}
Expand Down
1 change: 1 addition & 0 deletions csctapi/ifd_pcsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ const struct s_cardreader cardreader_pcsc =
{
.desc = "pcsc",
.typ = R_PCSC,
.skip_extra_atr_parsing = 1,
.skip_t1_command_retries = 1,
.skip_setting_ifsc = 1,
.reader_init = pcsc_init,
Expand Down
14 changes: 8 additions & 6 deletions globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ struct s_cardreader
//io_serial config
int8_t flush;
int8_t read_written; // 1 = written bytes has to read from device
bool skip_extra_atr_parsing;
bool skip_t1_command_retries;
bool skip_setting_ifsc;
};
Expand Down Expand Up @@ -1714,6 +1715,7 @@ struct s_reader
#if defined(READER_STREAMGUARD) || defined(READER_TONGFANG) || defined(READER_JET)
uint32_t cas_version; // cas version, used by tongfang,jet and streamguard. manual set for streamguard.
#endif
int8_t cak7_mode;
int8_t nagra_read; // read nagra ncmed records: 0 Disabled (default), 1 read all records, 2 read valid records only
int8_t detect_seca_nagra_tunneled_card;
int8_t force_irdeto;
Expand All @@ -1723,18 +1725,18 @@ struct s_reader
uint8_t rsa_mod_length;
uint8_t des_key[128]; // 3des key for Viaccess 16 bytes, des key for Dre 128 bytes
uint8_t des_key_length;
uint8_t atr[64];
uint8_t card_atr[64]; // ATR readed from card
uint8_t atr[64];
uint8_t card_atr[64]; // ATR readed from card
int8_t card_atr_length; // length of ATR
int8_t seca_nagra_card; // seca nagra card
int32_t atrlen;
SIDTABS sidtabs;
SIDTABS lb_sidtabs;
SIDTABS lb_prio_sidtabs;
uint8_t hexserial[8];
uint8_t hexserial[8];
int32_t nprov;
uint8_t prid[CS_MAXPROV][8];
uint8_t sa[CS_MAXPROV][4]; // viaccess & seca
uint8_t prid[CS_MAXPROV][8];
uint8_t sa[CS_MAXPROV][4]; // viaccess & seca
uint8_t read_old_classes; // viaccess
int8_t ecmending; // viaccess
uint8_t maturity; // viaccess & seca maturity level
Expand All @@ -1743,7 +1745,7 @@ struct s_reader
uint16_t b_nano;
uint16_t s_nano;
int8_t ecmcommand; // used for filtering nagra bad ecm commands
uint8_t ecmcommandcache[5]; // cachebuff for ecm commands
uint8_t ecmcommandcache[5]; // cachebuff for ecm commands
int32_t blockemm;
int32_t saveemm;
LLIST *blockemmbylen;
Expand Down
4 changes: 4 additions & 0 deletions module-webif.c
Original file line number Diff line number Diff line change
Expand Up @@ -2781,6 +2781,10 @@ static char *send_ncam_reader_config(struct templatevars *vars, struct uriparams
}
#endif

// cak7_mode
if(rdr->cak7_mode)
{ tpl_addVar(vars, TPLADD, "NAGRACAK7MODECHECKED", "checked"); }

// ins7E
if(rdr->ins7E[0x1A])
{
Expand Down
3 changes: 2 additions & 1 deletion ncam-config-reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ static const struct config_list reader_opts[] =
DEF_OPT_FUNC("nuid" , 0, nuid_fn),
DEF_OPT_FUNC("cwekey" , 0, cwekey_fn),
#endif
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)),
Expand Down Expand Up @@ -1538,7 +1539,7 @@ static bool reader_check_setting(const struct config_list *UNUSED(clist), void *
"exec_cmd_file",
#endif
#if defined(READER_TONGFANG)
"tongfang3_calibsn", "tongfang_boxid", "stbid", "tongfang3_deskey",
"tongfang3_deskey", "tongfang3_calibsn", "stbid", "tongfang_boxid",
#endif
#ifdef WITH_AZBOX
"mode",
Expand Down
2 changes: 1 addition & 1 deletion reader-nagra.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ static int32_t nagra2_card_init(struct s_reader *reader, ATR *newatr)
}
memcpy(reader->rom, cta_res + 2, 15);
}
else if(reader->detect_seca_nagra_tunneled_card && memcmp(atr + 7, "pp", 2) == 0 && ((atr[9]&0x0F) >= 10))
else if(!reader->cak7_mode && reader->detect_seca_nagra_tunneled_card && memcmp(atr + 7, "pp", 2) == 0 && ((atr[9]&0x0F) >= 10))
{
rdr_log(reader, "detect seca/nagra tunneled card");

Expand Down
14 changes: 13 additions & 1 deletion reader-nagracak7.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,19 @@ static int32_t nagra3_card_init(struct s_reader *reader, ATR *newatr)
reader->cak7_seq = 0;
cs_clear_entitlement(reader);

if(memcmp(atr + 11, "DNASP4", 6) == 0)
if(memcmp(atr + 8, "DNASP4", 6) == 0)
{
if((memcmp(atr + 8, "DNASP400", 8) == 0) && !reader->cak7_mode)
{
return ERROR;
}
else
{
memcpy(reader->rom, atr + 8, 15);
rdr_log(reader,"Rom revision: %.15s", reader->rom);
}
}
else if(memcmp(atr + 11, "DNASP4", 6) == 0)
{
memcpy(reader->rom, atr + 11, 15);
rdr_log(reader,"Rom revision: %.15s", reader->rom);
Expand Down
1 change: 1 addition & 0 deletions webif/readerconfig/readerconfig_hwreader_nagracak7.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<TR><TH COLSPAN="2">Reader specific settings for Nagra Merlin</TH></TR>
<TR><TD><A>Init card in CAK7 mode:</A></TD><TD><input name="cak7_mode" type="hidden" value="0"><input name="cak7_mode" type="checkbox" value="1" ##NAGRACAK7MODECHECKED##><label></label></TD></TR>
<TR><TD><A>mod1:</A></TD><TD><textarea name="mod1" rows="4" class="bt" maxlength="224">##MOD1##</textarea></TD></TR>
<TR><TD><A>data50:</A></TD><TD><textarea name="data50" rows="2" class="bt" maxlength="160">##DATA50##</textarea></TD></TR>
<TR><TD><A>mod50:</A></TD><TD><textarea name="mod50" rows="2" class="bt" maxlength="160">##MOD50##</textarea></TD></TR>
Expand Down
11 changes: 4 additions & 7 deletions webif/readerconfig/readerconfig_hwreader_tongfang.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<TR><TH COLSPAN="2">Reader specific settings for TongFang</TH></TR>
<TR>
<TR><TD><A>DES Key for TONGFANG v3:</A></TD><TD><input name="tongfang3_deskey" class="longer" type="text" maxlength="16" value="##TONGFANGDESKEY##"></TD></TR>
<TD><A>CalibSN for TONGFANG v3:</A></TD>
<TD><input name="tongfang3_calibsn" class="medium" type="text" maxlength="8" value="##TONGFANGCALIBSN##"></TD>
<TR><TD><A>STB ID for TONGFANG v3:</A></TD><TD><input name="stbid" class="longer" type="text" maxlength="16" value="##STBID##"></TD></TR>
<TR><TD><A>Box ID for TONGFANG:</A></TD><TD><input name="tongfang_boxid" class="medium" type="text" maxlength="8" value="##TONGFANGBOXID##"></TD></TR>
</TR>
<TR><TD><A>DES Key for TONGFANG v3:</A></TD><TD><input name="tongfang3_deskey" class="longer" type="text" maxlength="16" value="##TONGFANGDESKEY##"></TD></TR>
<TR><TD><A>CalibSN for TONGFANG v3:</A></TD><TD><input name="tongfang3_calibsn" class="medium" type="text" maxlength="8" value="##TONGFANGCALIBSN##"></TD></TR>
<TR><TD><A>STB ID for TONGFANG v3:</A></TD><TD><input name="stbid" class="longer" type="text" maxlength="16" value="##STBID##"></TD></TR>
<TR><TD><A>Boxid for TONGFANG:</A></TD><TD><input name="tongfang_boxid" class="medium" type="text" maxlength="8" value="##TONGFANGBOXID##"></TD></TR>

0 comments on commit 0ee6845

Please sign in to comment.