Install Open-SASC-NG

From Dolot

Jump to:navigation, search

Contents

1 Introduction

SASC-NG is a so called "softcam". It's a piece of software which is able to decode satellite feeds.

This can be useful in multiple cases:

2 Preparation

2.1 Got root?

Installing everything is much easier when you're root.

sudo -s

2.2 Installing dependencies

The following packages are needed to compile sasc-ng.

apt-get install linux-headers-`uname -r` build-essential subversion openssl gettext libssl-dev screen


3 Installing sasc-ng

3.1 Getting sasc-ng source

cd /usr/local/src
svn co https://opensvn.csie.org/opensascng/open-sasc-ng/ opensasc

3.2 Patching the source

We need to copy these files

cp /usr/local/src/s2-liplianin/linux/drivers/media/dvb/dvb-core/dvbdev.h /usr/local/src/opensasc/dvbloopback/module/dvbdev.h
cp /usr/local/src/s2-liplianin/linux/drivers/media/dvb/dvb-core/dvbdev.h /usr/local/src/opensasc/dvbloopback/module/config-dvb/dvbdev.h

The latest revision (r77) needs a few adjustments when compiled on kernel 2.6.30 and above.

cd /usr/local/src/opensasc
wget http://dolot.kipdola.com/w/uploads/sasc-patch/sasc-g34.patch
wget http://dolot.kipdola.com/w/uploads/sasc-patch/sasc-gcc.patch
wget http://dolot.kipdola.com/w/uploads/sasc-patch/sasc-makefile.patch
wget http://dolot.kipdola.com/w/uploads/sasc-patch/sasc-newcamd-login.patch
wget http://dolot.kipdola.com/w/uploads/sasc-patch/sasc-soname.patch
wget wget http://dolot.kipdola.com/w/uploads/sasc-patch/opensascng-kernel-2.6.31-pawel5870.patch 


patch -p1 < sasc-g34.patch
patch -p0 < sasc-gcc.patch
patch -p0 < sasc-makefile.patch
patch -p0 < sasc-newcamd-login.patch
patch -p0 < sasc-soname.patch
patch -p0 < opensascng-kernel-2.6.31-pawel5870.patch 

I got these fixes from these sources: (I have to recreate a few because they wouldn't apply for some reason)

sasc-g34.patch - Format string vulnerability (gcc 3.4 thing) https://opensvn.csie.org/traccgi/opensascng/ticket/5

sasc-gcc.patch & sasc-makefile.patch - A missing "Return 0" https://opensvn.csie.org/traccgi/opensascng/ticket/43 https://opensvn.csie.org/traccgi/opensascng/ticket/31

sasc-newcamd-login.patch - Fixes a newcamd login error https://opensvn.csie.org/traccgi/opensascng/ticket/50

sasc-procpatch.patch - In 2.6.30 several proc paths have changed, this fixes a compile error. https://opensvn.csie.org/traccgi/opensascng/ticket/46

sasc-soname.patch - Some .so filenames are wrongly named, apparently. This should fix that. https://opensvn.csie.org/traccgi/opensascng/ticket/51

3.3 Configuring and compiling

cd /usr/local/src/opensasc/
./configure --shared --dvb-dir=/usr/local/src/s2-liplianin
make
make module 


Installing the dvbloopback module (so it can load at boot)

rm /lib/modules/`uname -r`/misc/dvbloopback.ko
cd /usr/local/src/opensasc/
cp sasc-ng /usr/bin
cp /usr/local/src/opensasc/sc/PLUGINS/lib/* /usr/lib/
mkdir /lib/modules/`uname -r`/misc
/usr/bin/install dvbloopback.ko /lib/modules/`uname -r`/misc/
depmod

3.4 Loading the modules

since we installed the module at the appropriate position we can modprobe it:

modprobe dvbloopback

If you have multiple adapters (like I do, the reason why I'm using sasc-ng) you need to specify the amount of adapters you have. I have 3 adapters, so I do:

modprobe dvbloopback num_adapters=3

For some reason I'm constantly getting segfaults on Ubuntu (it doesn't matter what kernel I'm using), but not on Debian.

3.5 Loading at boot

I used to advise you to add a line to your /etc/modules file to load the module at boot. This is no longer necessary with the new runsasc script (which you can find below.) In fact, removing it (therefore putting the script in charge of loading the module) resolved a few headaches for me.

3.6 Starting sasc-ng

To start sasc-ng:

LD_LIBRARY_PATH=/usr/local/src/opensasc/sc/PLUGINS/lib/ ./sasc-ng -j 0:1 --cam-budget

To use it with MythTV:

LD_LIBRARY_PATH=/usr/local/src/opensasc/sc/PLUGINS/lib/ ./sasc-ng -j 0:1 --cam-budget --sid-allpid --sid-nocache
LD_LIBRARY_PATH=/usr/local/src/opensasc/sc/PLUGINS/lib/ ./sasc-ng  -j 0:3 -j 1:4 -j 2:5 --cam-budget --sid-nocache -d 0xf0a --cam-dir /etc/camfiles

To use sasc-ng with newcs, add:

cardclient.conf:

newcamd:localhost:15000:1/0602/ffff:dummy:dummy:0102030405060708091011121314

4 Cleaning up

4.1 Moving files & folders

We will give our camfiles (cardclient.conf) a proper home & copy sasc-ng to the binary folder.

mkdir /etc/camfiles
cd /usr/local/src/opensasc
mv sc_files/* /etc/camfiles/
cp sasc-ng /usr/bin/

Now we'll move the needed library files to the correct place.

cp /usr/local/src/opensasc/sc/PLUGINS/lib/* /usr/lib/

Now we'll edit the startup files.

nano /usr/local/bin/runsasc

And paste this script (you can ignore the DRIVERDIR variable in this script. Since we copied the module to our kernel tree we can just "modprobe dvbloopback" without any path.) Pay attention to the number of adapters you're loading! I've set it to 3 and have added the necessary "-j" options.

#!/bin/bash 

# Script to automate running of SASC-NG and Drivers 

# Driver directory 
DRIVERDIR="/usr/local/src/mythtv.cvs/sasc-ng" 
# Path to SASC-NG binary 
SASCPRG="sasc-ng" 
# Path to CAM Directory 
CAMDIR="/etc/camfiles/" 
# Number of DVB Cards you have in your system dedicated to SASC-NG 
ADAPTERS="3" 
# Startup Options passed to SASC-NG.  Adjust according to your devices. 
#OPTIONS="-r 0 -v 2 -o" 
OPTIONS="-j 0:3 -j 1:4 -j 2:5 --cam-budget --sid-allpid --sid-nocache --cam-dir" 
# Number of times runsasc will attempt to restart SASC-NG after a crash has occured (set to 0 for no limit) 
MAXTRIES=10 
# Minimum runtime required (in seconds) for SASC-NG to continue restart attempts 
MINRUN=20 

## End Configuration Section ## 

SASCCMD="$SASCPRG $OPTIONS $CAMDIR" 
KILL="/usr/bin/killall -q -TERM" 

# Detect whether the DVBLooopback driver is already loaded 
# and return 0 if it *is* loaded, 1 if not: 
function DriverLoaded() 
{ 
  grep -qse dvbloopback /proc/modules 
} 

# Load all DVBLoopback driver modules needed for your hardware: 
function LoadDriver() 
{ 
  modprobe dvbloopback num_adapters=$ADAPTERS 
  sleep 5 
} 

# Unload all DVBLoopback driver modules loaded in LoadDriver(): 
function UnloadDriver() 
{ 
  rmmod dvbloopback
} 

# Load driver if it hasn't been loaded already: 
if ! DriverLoaded; then 
   LoadDriver 
   fi 

LASTRESTART=$(date +%s) 
LOOPCOUNT=0 
while (true) do 
      if [ $LOOPCOUNT -le $MAXTRIES ] || [ $MAXTRIES -eq 0 ] ; then 
        eval "screen -D -m -S sasc-ng $SASCCMD &" 
        # Wait for SASC-NG to initialize then do rest 
        sleep 10 
        touch /tmp/SASC_COMPLETE 
      else 
        $KILL runsasc 
      fi 
      # Remember PID of SASC-NG process 
      PID=$! 
      # Wait for SASC-NG to end or signal to arrive 
      wait $PID 
      # Remember return value of SASC-NG 
      RET=$? 
      if test $RET -eq 0 -o $RET -eq 2; then exit; fi 
      TIMEOFDEATH=$(date +%s) 
      RUNTIME=$((TIMEOFDEATH - LASTRESTART)) 
      if [ $TIMEOFDEATH -le $(($LASTRESTART + $MINRUN)) ] ; then 
        echo "`date` SASC-NG crashed in $RUNTIME seconds. Minimum required runtime for SASC-NG is $MINRUN seconds. Killing runsasc process..." 
        $KILL runsasc 
      fi 
      echo "`date` Reloading DVBLoopback drivers" 
      $KILL sasc-ng 
      sleep 10 
      UnloadDriver 
      LoadDriver 
      LASTRESTART=$(date +%s) 
      LOOPCOUNT=$((LOOPCOUNT+1)) 
      echo "`date` Restarting SASC-NG $LOOPCOUNT time(s). Maximum retries set to $MAXTRIES" 
      done

And give it the proper permissions:

chmod 755 /usr/local/bin/runsasc
chmod +x /usr/local/bin/runsasc

4.2 Init script

An init script will take care of sasc-ng starting up at boot.

nano /etc/init.d/sascd

Add these lines:

#! /bin/bash 
# 
# sasc start-stop script 
# 

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 
NAME="runsasc" 
DESC="SASC-NG" 
DAEMON="sasc-ng" 

ENABLED=0 
test -f /etc/default/sascc && . /etc/default/sascc 
test "$ENABLED" != "0" || exit 0 

rm -f /tmp/SASC_COMPLETE 

LOOP=0 
case "$1" in 
  start) 
         if ! ps -C sasc-ng > /dev/null 2>&1; then 
         echo -e "Starting $DESC: $NAME. \n" 
         runsasc & 
         until [ -e /tmp/SASC_COMPLETE ] || [ $LOOP -eq $TIMEOUT ] ; do 
           sleep 1 
           LOOP=$((LOOP+1)) 
         done 
         if [ $LOOP -eq $TIMEOUT ]; then 
           echo -e "SASC-NG startup sequence has timed out in $TIMEOUT seconds. SASC-NG will not start. \n" 
           exit 1 
         fi 
         echo -e "SASC-NG startup time was $LOOP second(s). \n" 
         echo -e "SASC-NG startup sequence completed. \n" 
         else 
         echo -e "SASC-NG is already running. \n" 
         fi 
         ;; 
  stop) 
         if ps -C sasc-ng > /dev/null 2>&1; then 
         echo -e "Stopping $DESC: $NAME. \n" 
         sleep 3 
         killall -q -TERM $NAME 
         killall -q -TERM $DAEMON 
         sleep 5 
         rmmod dvbloopback.ko 
         else 
         echo -e "SASC-NG is not running. \n" 
         fi 
         ;; 
  restart|force-reload) 
         if ps -C sasc-ng > /dev/null 2>&1; then 
         echo -e "Restarting $DESC: $NAME. \n" 
         sleep 3 
         killall -q -TERM $NAME 
         killall -q -TERM $DAEMON 
         sleep 5 
         rmmod dvbloopback.ko 
         sleep 2 
         runsasc & 
         until [ -e /tmp/SASC_COMPLETE ] || [ $LOOP -eq $TIMEOUT ] ; do 
           sleep 1 
           LOOP=$((LOOP+1)) 
         done 
         if [ $LOOP -eq $TIMEOUT ]; then 
           echo -e "SASC-NG startup sequence has timed out in $TIMEOUT seconds. SASC-NG will not start. \n" 
           exit 1 
         fi 
         echo -e "SASC-NG startup time was $LOOP second(s). \n" 
         echo -e "SASC-NG startup sequence completed. \n" 
         else 
         echo -e "SASC-NG is not running. \n" 
         fi 
         ;; 
  *) 
         N=/etc/init.d/$NAME 
         echo "Use: $N {start|stop|restart|force-reload}" >&2 
         exit 1 
        ;; 
esac 

rm -f /tmp/SASC_COMPLETE 

exit 0

And now we set the proper permissions and actually add it to the runlevels:

chmod +x /etc/init.d/sascd
update-rc.d sascd defaults 21

We just need one more config file:

nano /etc/default/sascc

Add this:

# /etc/default/sascc 
# Default SASC-NG startup config 

# Change to 1 to enable sasc-ng's init-script 
ENABLED=1 

# DVBLoopback Device creation timeout (in seconds) 
TIMEOUT=60

5 Additional files

We're planning on using this thing legally, with NewCS in our own system. We need a cardclient.conf file for that:

nano /etc/camfiles/cardclient.conf

And put this in it. (I added some more lines so you'll get an idea as to how this thing works.)

#
# Comment lines can start with # or ;
#
# every client line starts with the client name, followed by some arguments:
# 'hostname' is the name of the server
# 'port'     is the port on the server
# 'emm'      is a flag to allow EMM transfers to the server
#            (0=disabled 1=enabled)
# 'caid'     (optional) caid on which this client should work
# 'mask'     (optional) mask for caid e.g. caid=1700 mask=FF00 would allow
#            anything between 1700 & 17FF.
#            Default is 1700 & FF00. If only caid is given mask is FFFF.
#            You may give multiple caid/mask values comma separated
#            (e.g. 1702,1722,0d0c/ff00).
# 'username' is the login username
# 'password' is the login password
#
# radegast client
#radegast:hostname:port:emm/caid/mask
#
# aroureos client
# 'hexbase'
# 'hexserial' card data for which EMM updates should be send
#aroureos:hostname:port:emm/caid/mask:hexbase:hexserial
#
# camd33 client (tcp protocol)
# 'aeskey'   is the AES key (32bytes), disable encryption if missing
#camd33:hostname:port:emm/caid/mask:username:password:aeskey
#
# camd35 client (udp protocol)
#camd35:hostname:port:emm/caid/mask:username:password
#
# cardd client
#cardd:hostname:port:emm/caid/mask:username:password
#
# buffy client
# 'aeskey'   is the AES key (32bytes), disable encryption if missing
#buffy:hostname:port:emm:username:password:aeskey
#some examples
#newcamd:192.168.0.10:10000:1/1801/FF00:mythtv:xxxxxxxx:XXXXXXXXXXXXXXXXXXXXXXXXXXXX
#radegast:192.168.0.10:10001:1/1801/FF00 
#
# newcamd client
# 'cfgkey' is the config key (28bytes)
#newcamd:hostname:port:emm/caid/mask:username:password:cfgKey
newcamd:127.0.0.1:10000:1/1801/FF00:test:test:0102030405060708091011121314
#
# gbox client
#
# NOTE: hostname & port will be ignore. GBOX must be runnning on the local
# machine. For convinience you should choose localhost:8004
#gbox:hostname:port:emm/caid/mask
#newcamd:hostname:port:emm/caid/mask:username:password:cfgKey 
#newcamd:localhost:15000:1/0602/ffff:dummy:dummy:0102030405060708091011121314
radegast:192.168.1.2:10001:0/0100/ffff

6 Other Tutorials

Navigation
Toolbox