catalinii / minisatip

minisatip is an SATIP server for linux using local DVB-S2, DVB-C, DVB-T or ATSC cards
https://minisatip.org
328 stars 81 forks source link

Descrambling ICAM with OSCAM dreambox mode #1126

Closed djseban closed 9 months ago

djseban commented 1 year ago

Hey there,

Recently I tried to descramble ICAM packets by minisatip - turns out in dreambox mode it's impossible (or using libdvbcsa in general) - I have to use hardware descrambler, at least on my sh4 box. Unfortunately that makes descrambling ICAM streams impossible.

What I tried is relaying entire stream to TVH for it do descramble - unfortunately the descrambler won't touch the stream it receives from minisatip (TS introduces itself as not scrambled maybe? - at least that's what I get in VLC codec info). How could I handle this issue? Thanks.

catalinii commented 1 year ago

You need either a compiled binary from here: https://github.com/catalinii/minisatip/releases or a patched libdvbcsa (https://github.com/catalinii/libdvbcsa)

djseban commented 1 year ago

@catalinii Thanks for fast reply :). I am compiling myself. I already patched libdvbcsa and compiled newest commit in your repo. I also recompiled patched and recompiled TVH, also with patched libdvbcsa.

djseban commented 1 year ago

@catalinii I attached gdb to tvheadend process, and in fact the stream appears as descrambled ((tsb[3] & 0xc0) false and scrambled false in tsdemux.c of TVH). Regards

djseban commented 1 year ago

I did some research and there were already some SAT>IP issues on SH4 boxes (i.e. not being able to descramble ts on TVH, but only by DVBAPI coupled with local CA). What I reckoned is that I'd try manipulating CW based on ECM directly in OSCAM:

        for(j = 0; j < demux[i].ECMpidcount; j++) // check for matching ecmpid
        {
            if((demux[i].ECMpids[j].CAID == er->caid || demux[i].ECMpids[j].CAID == er->ocaid)
                && demux[i].ECMpids[j].ECM_PID == er->pid && demux[i].ECMpids[j].PROVID == er->prid
                && demux[i].ECMpids[j].VPID == er->vpid)
            {
                if (er->icam_csa_ks == NULL) {
                    er->icam_csa_ks = get_key_struct();
                }

                if (er->ecm[0] == 0x80) {
                    set_even_control_word_ecm(er->icam_csa_ks, er->cw, er->ecm[0x15]);
                } else {
                    set_odd_control_word_ecm(er->icam_csa_ks, er->cw + 8, er->ecm[0x15]);
                }
                get_control_words(er->icam_csa_ks, er->cw, er->cw + 8);
                break;
            }
        }

As you can see it also involves adding icam_csa_ks to ECM_REQUEST struct. This way every ECM gets handled by ffdecsa, and if it detects ICAM it will handle the key as needed. Non-ICAM still works, the problem is ICAM hw descrambling still won't work in that configuration. Non-ICAMs working indicate that ffdecsa handles CWs correctly, but ICAM not working tells I am missing something. TVH only spits out some invalid start codes if I try to stream with HTSP:

2023-09-13 16:55:13.049 TS: Astra/11992.5H/Sky Cinema 007 HD: AC3 @ #259: Invalid start code c9:7c:12
2023-09-13 16:55:13.334 TS: Astra/11992.5H/Sky Cinema 007 HD: AC3 @ #260: Invalid start code fa:53:08
2023-09-13 16:55:20.190 TS: Astra/11992.5H/Sky Cinema 007 HD: H264 @ #255: Invalid start code 36:30:e6
2023-09-13 16:55:23.063 TS: Astra/11992.5H/Sky Cinema 007 HD: AC3 @ #259: Invalid start code f2:45:b4
2023-09-13 16:55:23.389 TS: Astra/11992.5H/Sky Cinema 007 HD: AC3 @ #260: Invalid start code a6:18:da

With pass I get nothing in log. Regards :)

catalinii commented 1 year ago

Which receiver with sh4 are u using?

djseban commented 1 year ago

ADB-5800SX (adb_box) with GraterliaOS core without E2 (https://graterlia.xunil.pl/index.php/Pobierz)

Jalle19 commented 10 months ago

Is there anything actionable here or can this ticket be closed?

lars18th commented 9 months ago

Is there anything actionable here or can this ticket be closed?

I feel this can be closed.