This is a "plugin" for the Video Disk Recorder (VDR).

See the file COPYING for license information.

Description: SoftCAM for Irdeto, Seca, Viaccess, Nagra, Conax & Cryptoworks

-----------------------------------------------------------------------



WARNING! This is the SC plugin development branch !!

This is a beta release. We encourage everybody to try this release, nevertheless
it should be used under controlled conditions.

Feel free to put your bugreports, suggestions and/or wishes to the 4free or DVBN
board. A bugreports should at least include the console log.



What is it ?
------------

First: Most certainly it's not legal to use this software in most countries of
the world. But probably you already know this...

SC means softcam, which means a software CAM emulation.

The main development goal for this branch is a full-featured implementation
without the needs to patch VDR. Recent changes in the new VDR development branch
opened a possibility for that.

The plugin captures the DVB devices in an early startup stage of VDR startup
(before VDR itself has got access to them) and makes VDR believe that there is
another CAM connected to the device. This CAM is emulated from the plugin by
providing a cut-down EN50221 interface for communication with the VDR core. From
VDR views there is no difference between a real hardware CAM and the emulated
CAM. 

The plugin decrypts the scrambling codewords from the incomming ECM stream. The
actual descrambling of the video stream is either done by the ECD chip on
full-featured DVB cards or with the included FFdecsa implementation on budget
cards.

This piece of software is originaly based on (and still contains code from)
mgcam (a standalone CAM emulation). Many thanks to the (anonymous) author for
his really fine piece of software :-)



Requirements
------------

* DVB driver from dvb-kernel 2.6 or 2.4 branch with applied patches
* a patched firmware version 2620 or newer
* VDR 1.5.0 or newer (VDR 1.4.6+ in compatibility mode, see 1.4.x setup section)
* Openssl package version 0.9.7 or newer



How to setup ?
--------------

First you should start with a recent dvb-kernel driver (cvs recomended). Copy
the patched firmware in place and apply at least the dvb-cwidx patch. Make sure
that you use a patched firmware if you intend to use the plugin together with a
full-featured DVB card. You definitely need a patched firmware in this case, but
only recent versions support concurrent recording! Recompile the driver, unload
the modules, install the new ones and reload the DVB driver. If you suffer from
ARM crashes, add "hw_sections=0" while loading the dvb-ttpci module.

Contrary to older plugin versions you MUST NOT apply any patches to the VDR core
(neither vdr-sc nor ffdecsa/softcsa).

You must have installed the openssl development files. For most distributions
this means to install openssl-devel package. You should use a openssl package
with AES and IDEA enabled, as support for openssl without these will be removed
in the near future.

Now follow the VDR instruction to compile plugins (make plugins). Beside the
core plugin (libvdr-sc.so), the make process (if successfull) creates an
additional shared library object for every supported system (libsc-*.so). You
can enable/disable individual systems by adding or removing the shared library
from your VDR plugin lib directory.

Starting with version 0.5.8 all make compile time options (e.g. IRDETO=1) except
DEFAULT_PORT have been removed!

Note that some budget card drivers provide a CA device too. This might make VDR
and the plugin detect the card as a full-featured card, thus disabling FFdecsa.
You should use commandline option -B to force detection as a budget card in such
a case.

For testing purpose you should start VDR in foreground always. The plugin gives
a lot of additional information to the console. This may be helpful in case it
doesn't work at once.



How to setup for VDR 1.4.x ?
----------------------------

Additional to the points mentioned above, you have to patch the VDR core with
the supplied patch (vdr-1.4.x-sc7.diff). Recompile VDR and use the new binary.
Patches from older SC releases are not going to work.

Even with VDR 1.4.x you don't have to use a softcsa/ffdecsa patch.

Activating/deactivating DVB cards in the plugin setup menu needs a VDR restart
to take effect.



Pre-compiled libraries
----------------------


There is the possibility that encryption systems are provided in binary, pre-
compiled only form. During make process, all pre-compiled libraries are copied
to your VDR plugin lib directory.

Please be aware, that pre-compiled libraries are more or less bound to the hard-
& software configuration they have been build on. Currently the build system is
Intel 32bit, gcc 3.2.2, glibc 2.2.5. If your system differs too much, it may be
impossible to use the pre-compiled libraries.

Obviously, pre-compiled libraries cannot be exchanged between different SC
and/or VDR API versions. Be aware that if you patch your VDR core and this patch
involves changes to header files (*.h) this might change the VDR API even if the
API version number hasn't changed. This may lead to silent malfunction/failure
of pre-compiled libraries. In particular you should stay away from thread.h and
tools.h as classes from there are used at many, many places.

The naming scheme for the libraries is libsc-<MODULE>-<SCAPI>.so.<APIVERSION>,
e.g. libsc-cardclient-2.so.1.3.47



CAID and VDR CICAM setup
------------------------

The activation of the SC is controlled by your CICAM setup. As general setup
(which is not SC specific) you should leave the CA values (in channels.conf)
set to zero and let VDR's channel scanner (autopid) fill in the correct values.
Don't touch the CA values afterwards.
In the plugin setup menu, you now have to specify for which DVB cards the SC
should be activated. The first two cards can be setup from the menu. If you
need more, you can edit the setup.conf file manualy and add up to 10 cards.

A real hardware CAM normaly knows which CAIDs it supports. With SC the situation
is a bit different. There is support for a wide range of encryption system and
cardclients. This results in a huge number of supported CAIDs, but for most of
them it's uncertain if SC will actualy be able to decrypt a channel for them.
On the other hand VDR limits the number of supported CAIDs to 16 for a CAM slot,
so SC is able to announce a small number of CAIDs only. This is not as bad as it
sounds, as VDR will try a CAM if ANY of the channel CAIDs matches the CAIDs
announced by the CAM.
On startup and at regular intervals the plugin scans the channels list and
builds a chain of CAIDs. The CAIDs are assigned to the simulated CAM. 

To reduce the number of CAIDs SC has to deal with, you should obey some rules:
-Remove all libsc-* files for encryption system which you don't intend to use
 (e.g. SHL seems pretty useless nowadays).
-When using a cardclient, be as precise as possible with the CAID/MASK values in
 the cardclient.conf file. Using wide open 0000/0000 is deprecated.
-Add CAIDs which you cannot use due to lack of keys to the SC.CaIgnore setting.




Concurrent Recordings
---------------------

There is an entries in the plugin setup menu to control concurrent usage of a
full-featured DVB card. You should enable concurrent usage only if you are using
the special patched firmware AND a patched DVB driver. Note that toggling the
flag will take effect the next time the plugin is idle on that specific DVB card
only (i.e. no channel is being decrypted).

There is no possibility to limit the number of concurrent streams. VDR itself
has no limit in concurrent streams (neither FTA nor encrypted) and as the VDR
core control all aspects of operation, there is no way to enforce a limit
(beside disabling concurrent encrypted streams at all).



Additional files
----------------

All config files must be located in a subdirectory (of your VDR config
directory) called "plugins". The private plugin cache file is saved to this
directory too. The keyfile must be named "SoftCam.Key".

For Seca2 support you need binary files which contain the hash & mask tables.
The file format is the same as for Yankse. The files must be located in the
"plugins/seca" subdirectory. The name sheme is s2_TTTT_XXXX.bin where TTTT is
one of "hash","mt" and XXXX is the provider ID (e.g. s2_hash_0064.bin,
s2_mt_0070.bin). The hash file must be 1536 bytes long. The mt file is normaly
16384 bytes long, but this may differ for your provider. For advanced Seca2
providers you may need additional table files. At the moment these are
s2_sse.bin, s2_sse_XXXX.bin and s2_cw_XXXX.bin.

Although there is support for Viaccess TPS AU, you still can provide a "tps.bin"
file in the "plugins/viaccess" subdirectory in case AU doesn't work for your
provider. Be aware that in most cases this file has to be updated on a daily
basis.

Note, that for this @SHL implementation the key must be in Z 00 00 <key> format
(the V 000000 00 <key> format doesn't work).

For Irdeto, Seca and Viaccess AU you need valid subscription card data, which
have to be located in the files "Ird-Beta.KID", "Seca.KID" or "Viaccess.KID".
See the files in the "examples" subdirectory for file formats.

For Nagra1 AU you need appropriate binary Rom and Eeprom files. The files have
to be named "ROMX.bin", "ROMXext.bin" or "eepX_Z.bin", where X is the ROM number
(decimal) and Z is the upper part of the provider ID (hexadecimal). The Eeprom
files may be updated from the EMM data, take care that the permissions are set
right. The plugin searches for these files in the "plugins/nagra" subdirectory.

For Nagra2 AU some providers need binary Rom and Eeprom files. The files have to
be named "ROMxxx.bin" and "EEPyy_xxx.bin", where xxx is the ROM version (e.g.
102) and yy is the upper part of the provider ID (e.g. 08 for BEV). The files
must contain the joined contents of all Rom/Eeprom pages. The plugin searches
for these files in the "plugins/nagra" subdirectory.



External key updates
--------------------

If key updates are available from external sources (e.g. website) only, they may
be feed from a shell script. To enable this, you have to specify the script name
with commandline option "-E". The script will be called at a regular interval
(currently 15 minutes) or whenever a needed key is not available (but not more
often than every 2 minutes). The script has to output the keys to it's stdout in
the same format as for the key file. The script may output several keys in one
call (each key on a seperate line). You can find an example script in the
"examples" subdirectory.



Smartcard support
-----------------

For most encrpytion systems this plugin supports original subscription
smartcards on a Phoenix/Smartmouse ISO interface connected to a serial port.

To enable smartcard support you have to copy one or more of the smartcard
systems to the VDR plugin lib directory. To actually activate the smartcard
interface, you should use the commandline option "-s" to specify one or more
serial devices to which the Phoenix interface are connected e.g. use "-s
/dev/ttyS0 -s /dev/ttyS1" to use two intefaces at COM1/COM2. If you want to add
a default smartcard interface at compile time use the make option DEFAULT_PORT,
e.g. DEFAULT_PORT='"/dev/ttyS0",0,0,0'. Note the quotes and double quotes. The
three numeric values are identical to the -I and -R options (set to 1 to enable)
and -C option (set to 0 for default clock) below.

Appearently there are "broken" card readers which swap the meaning of the CD
line (used for card detection). For these readers use the option "-I". This
enables inverse CD detection for the next interface e.g. "-I -s /dev/ttyS0 -s
/dev/ttyS1" will use inverse CD on COM1 and normal CD on COM2 while "-I -s
/dev/ttyS0 -I -s /dev/ttyS1" will use inverse CD on both.
Some other card readers have a reversed logic with the reset line (card won't
reset with default settings). You can use the option "-R" for these readers.
In some cases it's mandatory to know the exact clock frequency at which your
cardreader runs (e.g. for baudrate calculations). With the option "-C" you can
give a clock frequency (in Hz) which will be used instead of the default
(3571200 Hz) for the next interface e.g. "-C 3579545 -s /dev/ttyS1".

Some smartcards need additional information to establish communication with the
card (e.g. certificate or box key for camcrypt). These information must be
available in the "smartcard.conf" file (see example file for format) or you card
won't work correctly.

If you insert a card into a interface the card is autodetected (your interface
should use the CD line to signal card presence or it won't work) and
initialised (this may take some seconds to complete). You can use the setup
menu to see which cards are currently inserted and detected. You can remove a
smartcard at any time without prior action, but of course this will disrupt
decryption if you are tuned to a channel which requires the card.



Cardserver client
-----------------

The cardclient is a client for several cardservers. Supported cardservers are :
radegast, newcamd, camd33 (tcp), camd35 (udp), cardd, buffy and aroureos.

You can configure as many clients for different servers as you want. The client
configuration is read from the file "cardclient.conf". Every line in the file
defines a client-server connection. The line starts with the client name and is
followed by additional arguments which depend on the client type. See the file
"examples/cardclient.conf.example" for format and arguments.

The connections are tried in the order they are defined in the conf file until
a valid decryption is obtained. After that, the decryption sticks to that
particular connection until next channel switch.

The network code supports dialup on demand. To use this you have to provide an
external script to connect/disconnect your dialup link. Use commandline option
-d to set the script name and enable the feature, e.g. "-d dialup.sh". See the
example script "examples/dialup.sh.example". The network is brought up as soon
as an server connection is requested. All server connections are disconnected if
they are idle too long (normaly after 120 seconds). The network is brought down
after the last connection has terminated and an additional network timeout has
expired. The network timeout is configurable with the commandline option -t and
defaults to 60 seconds, e.g. "-t 120".

The current cardclient implementation is loosely based on the Streamboard
client (contributed by S.Laurel from the Streamboard), which was included in
earlier releases.



SVDR interface
--------------

The plugin implements a SVDR interface. Supported commands are:
   RELOAD
     reload all configuration files (only if the softcam isn't active at the
     moment).
     Return codes: 550 - Softcam active, can't reload files.
                   901 - Reloading files not entirely successfull. Most of the
                         time this will leave you with an unusable softcam.
                   900 - Reload successfull.

   LOG [on|off] module.option[,module.option][,...]
     Enables or disables all given message classes.
     Return codes: 501 - Syntax error or unknown message class.
                   900 - Options set and saved.

   LOGCFG
     Display all available message classes and report their status. This can be
     usefull if you want to provide an external GUI or whatever to handle the
     message classes.
     Return codes: 901 - No message classes available.
                   900 - Message class status (multi line reply).
