[COMMENT]
** Please note that this was written for sasc-ng. Some things may be different
** for vdr-sc. Corrections to this doc are welcome.
** Suggestion: start reading at 4)
[/COMMENT]

CCcam and sasc0-ng HOWTO..

Draft manual...

Dont try and do this unless you feel are very compentant at compiling, sasc-ng and chroot...
Please read the forums, dont PM me unless its constuctive or your contributing.

Instructions...

1) Download from svn sasc-ng, I used svn version 182, but it will probably work on later and earlier versions.

2) Apply the patch

	patch -p0 < CCcam-sasc-ng0.3.diff

Note the patch makes a small change to vdr-sc so I can get the card number.

3) Follow the sasc-ng instructions to complete the installation.

4) Your cardclient.cfg file needs an entry like this...

cccam:127.0.0.1:9000:0/0000/0000:/var/emu/chroot%d/tmp/camd.socket

Note: with that CCcam will offer to serve any ECMs.
Note: socketpath might need to be adjusted to your system.

5) Now it gets tricky, read some docs on the internet about chroot.

I did this on Ubuntu 7.10 so it might not work on other distros...

install dchroot,

	apt-get install dchroot
	
now create this directory structure 

/var/emu/
/var/emu/chroot0
/var/emu/chroot1
/var/emu/chroot2
/var/emu/chroot3

copy the cpchroot.sh script into /var/emu

cd /var/emu/chroot0

then run the script to setup the chroot. 

sh ../cpchroot.sh

This copies all the files you need from you main disk into the ringfenced chroot0.

Next we need to bind some directories...

mount --bind /dev /var/emu/chroot0/dev
mount --bind /lib /var/emu/chroot0/lib
mount --bind /bin /var/emu/chroot0/bin
mount --bind /usr /var/emu/chroot0/usr


You can check this is working by running 

chroot .

This should put you in a sub world with all facilities you expect in a linux box, be aware that /dev /lib /bin and /usr are all linked to your main dir so any changes will occur in your main world. Importantly /var isnt so thats where all your CCcam files go.

^D to exit the chroot.

If it doesnt then it should moan about some library thats missing which you need to copy from /lib or /usr/lib into the same
place inside the chroot.

6) Install CCcam into /var/emu/chroot0/var/emu, with the run.sh script and the ca.c file.
7) compile ca.c
	cd /var/emu/chroot0/var/emu
	gcc -O -fbuiltin -fomit-frame-pointer -fPIC -shared -o ca.so ca.c -ldl
[COMMENT]
** With vdr-sc the file has been renamed to cccam_ca.c and cccam_ca.so.
** You can find the source code in the contrib directory. To compile issue a
** "make cccam_ca.so" in that directory
** Probably you need to adjust you startup script to the new name.
[/COMMENT]

(ignore the warnings)
8) In yout boot up which method you use to do this you should have a line for insmod dvbloopback (assuming you have followed a guide for installing sasc-ng)

With these line add this line.

mount --bind /dev /var/emu/chroot0/dev
cd /var/emu
rm tmp/.CCcam.nodeid
chroot chroot0 /var/emu/run.sh
This gives access to the dvb devices in the sub chroot world.



Example from my system

mount --bind /dev /var/emu/chroot0/dev
mount --bind /dev /var/emu/chroot1/dev
mount --bind /dev /var/emu/chroot2/dev
mount --bind /dev /var/emu/chroot3/dev
rm /var/emu/chroot0/var/log/*
rm /var/emu/chroot1/var/log/*
rm /var/emu/chroot2/var/log/*
rm /var/emu/chroot3/var/log/*
rm /var/log/mythbackend.log
chroot /var/emu/chroot0 /var/emu/run.sh &
chroot /var/emu/chroot1 /var/emu/run.sh &
chroot /var/emu/chroot2 /var/emu/run.sh &
chroot /var/emu/chroot3 /var/emu/run.sh &
cd /var/emu/sasc-ng/dvbloopback/module
insmod dvbloopback.ko num_adapters=4
cd /var/emu/sasc-ng
sleep 5
./sasc-ng  -j 0:4 -j 1:5 -j 2:6 -j 3:7 > /var/log/sasclog.log&

(if your using the myth patch to kill errant CCcams you will need these lines also)
cd /var/emu
sh ./cckill.sh &

8) For multiple cards repeat steps 5 6 and 7 for /var/emu/chroot1,2,3. More than 4 cards wont work.

9) Configuring your CCcam.cfgs which will live in /var/emu/chroot0,1,2,3/var/etc
	The first card you set up to connect to your shares and your local cards.
	The other cards you need to change the server port number from 12000 and configure it to share with the first...
NOTE (PAY ATTENTION) its real important that if you connect all these instances to a central server that you make sure of these two things.
		a) make sure that each instance doesnt use the same /tmp/.CCcam.nodeid
		b) make sure that each instance has a different SERVER LISTEN PORT and logs in using DIFFERENT creditentials. (Your friends will get upset with you if you use the same C: line), So just to be CLEAR DO NOT HAVE MULTIPLE INSTANCES ON THE SAME C: LINE. (sorry about shouting)
	e.g. just an example of daisy chaining the CCcams.
	
	chroot0/var/etc/CCcam.cfg
		F: card1 mythtomyth 3 1 1
		F: card2 mythtomyth 3 1 1
		F: card3 mythtomyth 3 1 1
		C: myfriend.no-ip.info  12000   mates    matespass
		SERIAL READER : /dev/ttyUSB1 smartreader+
	chroot1/var/etc/CCcam.cfg
		C: 192.168.1.42 12000   card1   mythtomyth
		SERVER LISTEN PORT : 12001
		WEBINFO LISTEN PORT : 16001
	chroot2/var/etc/CCcam.cfg
		C: 192.168.1.42 12000   card2   mythtomyth
		SERVER LISTEN PORT : 12002
		WEBINFO LISTEN PORT : 16002
	chroot3/var/etc/CCcam.cfg
		C: 192.168.1.42 12000   card3   mythtomyth
		SERVER LISTEN PORT : 12003
		WEBINFO LISTEN PORT : 16003


10) As the intructions for sasc-ng say load the dvbloopback driver and run up sasc-ng.

Watching the logs on sasc-ng you should see something like this.
Mar 15 14:22:30.140 CAM(cardclient.cccam): Processing ECM....
Mar 15 14:22:30.149 CAM(cardclient.cccam):  Got: CC0f  XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
Mar 15 14:22:30.149 CAM(cardclient.cccam): SAVING KEYS USING PID FROM CCCAM  2 !!!!!!!!!!!
Mar 15 14:22:30.150 CAM(cardclient.cccam):       KEYS FOR CARD 2 !!!!!!!!!!!!!!!!!!
Called cSascDvbDevice::SetCaDescr
Mar 15 14:22:30.150 CSA: Got command(6): O idx: 1 pid: 0 key: XXXX...XX

CC = the card number 00,01,02,03 etc.

11) Notes....

		This hack is a little more complex than the ordinary, and you need to know your stuff to make it work. 
		Rules, dont PM me for help, try the forum.
		Bugs with fixes PM me, bugs without post on the forum.
		
12) TODO.
		Work out how to get EMMs working, you will need to share with a source of EMMs if you want to keep your 
		card upto date. 
		All work on the mythtv CCcam/sasc/gbox code has ceased and will not be supported.
		All work with gbox has ceased.
		Make this howto better, all contributions are greatfully received.

I have this working with a 4 card setup, running stock unpatched trunk myth.
