Skype for Asterisk using FreeSWITCH, for hackers

Some time ago I explored FreeSWITCH’s mod_skypopen. The module works great and cleanly connects FreeSWITCH to a normal Skype account. In that posting, I noted that there’s a simple script you can run to set it all up. But the script only works if you are using a mostly default FreeSWITCH install with all the configs in place. If, on the other hand, you have a minimal FreeSWITCH install as a Google Voice gateway to Asterisk, like I do, the script won’t work. 
Below is the step-by-step method to configuring mod_skypopen on FreeSWITCH if you’re using it only as a gateway/connector. I had thought that no one would want this and had forgotten about it, until PSU VoIP reader Ranga asked about it. Major thanks to Ranga for testing out the following procedure and providing helpful feedback! I admit, it’s still pretty laborious–not an easy how-to by any definition. But it works as a reliable method of connecting Skype to your Asterisk server.
The procedure: Start here

Log in to your system’s command line interface and perform all the steps as root unless otherwise instructed.

If any step results in an error where the command is not found, you may need to install the program using yum (yum install program name) or build the program from sources on the web. You can find Git at http://git-scm.com/.

cd /usr/local/src
git clone git://git.freeswitch.org/freeswitch.git

Refer to the FreeSWITCH installation wiki for installing FS from Git: http://wiki.freeswitch.org/wiki/Installation_Guide to install from Git
These are the basic instructions for doing so, but be sure to follow the wiki.

cd freeswitch
./bootstrap.sh
./configure

Edit modules.conf and uncomment endpoints/mod_skypopen because we want to build it.

Make sure kernel sources are installed (yum install kernel-devel on CentOS)

Also make sure there are no sound modules already loaded in the kernel. lsmod | grep snd

If there are any, they should be removed prior to performing the next steps.

cd src/mod/endpoints/mod_skypopen/oss
make clean; make; insmod ./skypopen.ko; mknod /dev/dsp c 14 3

If no errors appear, this verifies that the kernel module installs OK.

Add all the prerequisite components from yum (listed in the wiki for your distro) – for Amazon Linux I added:

yum -y install autoconf automake gcc-c++ git-core libjpeg-devel libtool
make ncurses-devel unixODBC-devel openssl-devel gnutls-devel libogg-devel
libvorbis-devel curl-devel libtiff-devel libjpeg-devel subversion autoconf
automake libtool gcc-c++ ncurses-devel make libX11-devel Xvfb alsa-utils
libXv libXScrnSaver xorg-x11-fonts* alsa-lib libXScrnSaver libtiff-devel
libjpeg-devel kernel-devel git
alsa-lib.i686  fontconfig.i686  freetype.i686  glibc.i686  libgcc.i686 
libICE.i686  libSM.i686 libstdc++.i686  libX11.i686  libXau.i686 libxcb.i686
libXcursor.i686  libXext.i686 libXfixes.i686  libXi.i686  libXinerama.i686
libXrandr.i686  libXrender.i686 libXScrnSaver.i686  libXv.i686

yum install xauth

but you should use the list provided in the wiki for your own distro. Refer to http://wiki.freeswitch.org/wiki/Mod_skypopen

Back to freeswitch source dir: cd /usr/local/src/freeswitch

make
make install

mv /usr/local/src/freeswitch/src/mod/endpoints/mod_skypopen/oss/skypopen.ko /usr/local/lib

New – March 2012: the archives at kernel.org/archlinux have been repackaged with “xz”. So first install the xz tool: yum install xz  Then perform the following steps.

Go to the root (/) directory to install Skype binaries:
cd /
wget "http://mirrors.kernel.org/archlinux/community/os/i686/skype-oss-2.0.0.72-3-i686.pkg.tar.xz"
xzcat skype-oss-2.0.0.72-3-i686.pkg.tar.xz | tar xv


Start and login to Skype as regular user through X. This may be tricky. I use SSH tunneling and on my workstation (Mac) I have X11 available to display X programs. If you want to do it at your server console you’ll need to install X11.org or maybe just use vncserver. There are a few options here. Setting up a way to run X programs = exercise left for the reader.

Log out of Skype after successfully logging in once. The Skype config is in /home/username/.Skype .

Copy it to /root (so that you have /root/.Skype). If you just ran Skype as root, the config is already in the right place.

Edit the /root/.Skype/SKYPEUSERNAME/config.xml file and add the bolded lines in before the Reminders tag at the bottom:

    <UI>
      <API>
        <Authorizations>skypopen</Authorizations>
        <BlockedPrograms></BlockedPrograms>
      </API>

      <Reminders>
        <BirthdaysSeen></BirthdaysSeen>
      </Reminders>
    </UI>

Now start the phony X server, Xvfb: (as root)

/usr/bin/Xvfb :101 -ac -nolisten tcp -screen 0 640x480x8 &

Start Skype as root:

su root -c "/bin/echo 'SKYPEUSERNAME SKYPEPASSWORD'| DISPLAY=:101  skype --pipelogin &"

Skype is now running in the background on the phony X server and should be logged in to your account.

Put the following extremely simplified freeswitch.xml file in place in /usr/local/freeswitch/conf (overwrite what is there):

Simplified Skype-to-Asterisk-via-FreeSWITCH config

Change all occurrences of SKYPEUSERNAME in the XML file with your Skype user name.

Now start Freeswitch:

ulimit -s 240
/usr/local/freeswitch/bin/freeswitch -c

See what scrolls by. The Skypopen module should find your logged in Skype user. Test with “sk list”

Once you see that it is working you can configure the kernel sound driver, the phony X server, skype, and Freeswitch to all start at boot time using rc.local:

Put at the bottom of /etc/rc.local:

# freeswitch
# Skype driver insmod /usr/local/lib/skypopen.ko mknod /dev/dsp c 14 3 # Skype /usr/bin/Xvfb :101 -ac -nolisten tcp -screen 0 640x480x8 & sleep 3 su root -c "/bin/echo 'SKYPEUSERNAME SKYPEPASSWORD'| DISPLAY=:101 /usr/bin/skype --pipelogin &" # Freeswitch main ulimit -s 240 /usr/local/freeswitch/bin/freeswitch -nc ###

Now you have FreeSWITCH connected to Skype and Skype is logged in. It is time to configure Asterisk.

Incoming Skype calls will ring sip:75973@127.0.0.1, so asterisk needs to be listening on 127.0.0.1 (it does by default) and have a route for number 75973. If you write your own Asterisk config files, add some dialplan in extensions.conf to route 75973 to wherever you want. For FreePBX, set up an Inbound Route for DID 75973 and route it where you’d like your incoming Skype calls to go.

Outgoing calls should be sent to num-or-skype-name@127.0.0.1:5050 from Asterisk. If you edit configs by hand, set up extension routing to SIP/${exten}@127.0.0.1:5050 as appropriate or if you use FreePBX, create a Trunk – SIP with host=127.0.0.1 and port 5050 or just create a custom trunk as SIP/$OUTNUM$@127.0.0.1:5050.

If you configured NAT on Asterisk, be sure to exclude 127.0.0.1 from the NAT. (localnet=127.0.0.0/255.0.0.0 in sip.conf or configured through the FreePBX GUI).

That’s it! If you’ve hacked through all this, congratulations. I have found the FreeSWITCH-Skype connector to be extremely reliable and you probably will, too.

4 thoughts on “Skype for Asterisk using FreeSWITCH, for hackers”

  1. hi,Bill – great creator.

    Bill and Jason and Ranga.

    could not get download of – wget “http://mirrors.kernel.org/archlinux/community/os/i686/skype-oss-2.0.0.72-2-i686.pkg.tar.gz”
    how do for install Skype for Asterisk using FreeSWITCH, need of skype-oss-2.0.0.72-2-i686 rpm or other.

    grateful for helping us.

  2. Million thanks to Bill for writing this up on my request. While I was testing the procedure, I got stuck a couple of times (mostly due to my inadvertent mistakes) and Bill promptly helped me out. My Asterisk server is now running seamlessly with Freeswitch. Though a bit laborious, Bill has made it simple enough! Congratulations!

Comments are closed.