billigertelefonieren Documentation

0.1

Introduction

This is a least cost routing (LCR) application for the Fritz!Box fon by AVM. It uses the internet site billiger-telefonieren.de for determining the cheapest prefixes for phone rates in Germany. It has been tested for fixed rated calls as well as for mobile phone rates. Usually you are only able to use these prefixes if you have a line by T-Com. For example, if you want to call the number (0201) 123456 and you have the prefix 01013, you would call 01013 0201 123456. In the Fritz!Box fon you can do this automatically. This is what this application does:

It has been tested on a Fritz!Box fon 5050, firmware version 12.04.15 as well as 12.04.31

To use this programme, either run it from your computer or install it on the Fritz!Box. The easiest way to do this is to put it into the /var/tmp directory. The more elegant way is to put it permanently on the flash file system and to create a /etc/init.d script to run it as a daemon.

Since billiger-telefonieren.de changes its design from time to time, some adjustments to providers.c have to be made!

(c) 2005-2007 Markus Drescher last change: 27.12.07

ideas to implement:

Installation

Basic Installation
==================

Before compilation:

Adjust include/billigertelefonieren.h to your needs:
FR_PASSWORD: your Fritz!Box fon password
FR_PREFIX_LOCAL: your local prefix (for example 030 for Berlin)
FR_PREFIX_DISTANT: distant call prefixes (in Germany all numbers beginning with
02,03,04,05,06,07,08,09 are distant calls, i.e. calls outside your town)
0800 numbers are an exception and should be created manually in the
webinterface!
FR_PREFIX_MOBILE_XX: mobile phone prefixes
BT_HOSTNAME: hostname of the billiger-telefonieren.de site
BT_DAYOVERVIEW: part of the url of the daily rate overview

FB_HOSTNAME: Fritz!Box hostname

PR_PRESELECTION: preselection rate (your default rate if you aren't calling
with a prefix)
PR_IGNORE_THESE: ignore these prefixes (update only the others)

PR_SETTINGS_FIXED,PR_SETTINGS_MOBILE: files where the rates are being saved to

Compilation, installation
=========================

./configure --prefix=/tmp/bt
make
make install

Cross-compilation
=================

./configure --host=mipsel-linux --prefix=/tmp/bt
make
make install

(assumes that you have a working mipsel cross compiler for the Fritz!Box)

Howto cross-compile and install fritzbox-lcr on the Fritz!Box fon
=================================================================

Building cross-compiler
=======================

I use the toolchain by AVM. To get it, download the source files from
ftp://ftp.avm.de/develper/opensrc
I'm describing the procedure for fritzbox-source-files-04.29.tar.bz2:

# wget "ftp://ftp.avm.de/develper/opensrc/fritzbox-source-files-04.29.tar.bz2"
# mkdir fb-source
# cd fb-source
# tar jxvf ../fritzbox-source-files-04.29.tar.bz2
# cd GPL

In the Makefile it says that you'll need gcc 3.4 and a package called realpath.
So if you have the above, type:

# make

After some time you'll be asked for a kernel configuration:
*
* Target Architecture Features and Options
*
Target Processor Architecture
> 1. Generic (MIPS I) (CONFIG_MIPS_ISA_1) (NEW)
  2. MIPS II (CONFIG_MIPS_ISA_2) (NEW)
  3. MIPS III (CONFIG_MIPS_ISA_3) (NEW)
  4. MIPS IV (CONFIG_MIPS_ISA_4) (NEW)
  5. MIPS32 (CONFIG_MIPS_ISA_MIPS32) (NEW)
  6. MIPS64 (CONFIG_MIPS_ISA_MIPS64) (NEW)
choice[1-6?]:
choose 5

Target CPU has a memory management unit (MMU) (ARCH_HAS_MMU) [Y/n/?] (NEW)
Just press enter

And don't forget to drink some coffee, this might take a while.
While trying to compile the kernel, I got the message:
arch/mips/mips-boards/ohio/ohio_clk.c:44:29: linux/avm_power.h: No such file or
directory
And make stopped. But that doesn't matter, since the toolchain has been made.
To use the toolchain, you have to include the path to the binaries in your
PATH enviroment, i.e.
<PATH_TO_fb-source>/fb-source/GPL/base_8mb_26_build/toolchain/build_mipsel_nofpu/staging_dir/bin
to do so, type
# export PATH=<PATH_TO_fb-source>/fb-source/GPL/base_8mb_26_build/toolchain/build_mipsel_nofpu/staging_dir/bin:$PATH

You could - for instance - include this line in your ~/.bashrc.

Cross-compiling
===============

(If you're reading this from a file rather than on the web, skip the following:)
Obtain the source code via subversion, i.e. type:
# svn co https://fritzbox-lcr.svn.sourceforge.net/svnroot/fritzbox-lcr
# cd fritzbox-lcr/trunk

If you compiled anything before, type
# make clean

Then continue:
# ./configure --prefix=/tmp/bt --host=mipsel-linux-uclibc
# make
# make install

You can use the binary /tmp/bt/bin/billigertelefonieren, if everything worked
well!

Optionally, you may change to the /tmp/bt/bin directory and:
# cd /tmp/bt/bin
# mipsel-linux-uclibc-strip billigertelefonieren

The size of the executable shrinks a bit!

Installing
==========

This is the description for the installation of the Fritz!Box LCR on the box
itself.

1. Install the original firmware image as usual via the Webinterface. I don't
know whether this is necessary but I highly recommend it, because major changes
in the firmware might be adjusted with the install-script by AVM as well. So
just do it! It won't take too much of your time!
2. If you're using a newer firmware than 12.04.15, e.g. 12.04.31 follow step 4.
If not, these are the instructions for a firmware version 12.04.15 and below:
unpack the original Firmware image file:
# mkdir /tmp/fritz
# cd /tmp/fritz
# tar xvf ~/Desktop/fritz.box_fon_5050.12.04.15.image
./var/
./var/tmp/
./var/tmp/kernel.image
./var/tmp/filesystem.image
./var/flash_update.o
./var/info.txt
./var/install
./var/chksum
./var/regelex
./var/signature
3. Continue with step 5.
4. This is the first step for firmware version equal or greater than 12.04.31:
Assuming you have a TFTP server running on 192.168.0.2 login to the Fritz!Box
via telnet and type:
# tftp -p -l /dev/mtd1 -r filesystem.image 192.168.0.2
This saves the mtd block 1 (filesystem) of the Fritz!Box into a LZMA-compressed
squashfs dump file. Copy the file into a directory where you want to unpack it.
Alternativelty you can use the tool extractfilesystemimage which is also
included in the trunk. Type
# <PATH_TO_extractfilesystemimage>/extractfilesystemimage kernel.image filesystem.image
in order to create a new filesystem.image which is a LZMA-compressed squashfs
dump file.
5. To uncompress the file we need unsquashfs-lzma, included in
the danysahne-mod in source/squashfs2.2/squashfs-tools/
Assuming that you already compiled it, type on your computer as root (needed for
creating the devices correctly!):
# <PATH_TO_unsquashfs-lzma>/unsquashfs-lzma filesystem.image
If it works the output is for example:

created 846 files
created 66 directories
created 167 symlinks
created 128 devices
created 0 fifos

If you're getting warnings like these, you were not running it as root:
create_inode: could not create character device squashfs-root/dev/avm_event,
because you're not superuser!

6. So you unpacked the filesystem, right? Then there is a directory called
"squashfs-root"
# cd squashfs-root/lib
check whether there is a file called libgcc_s.so.1:
# ls -la libgcc_s.so.1
If there is none, copy libgcc_s.so.1 into this directory and create a symbolic
link:
# cp <PATH_TO_libgcc_s.so.1>/libgcc_s.so.1 .
# chmod 755 libgcc_s.so.1
# ln -s libgcc_s.so.1 libgcc_s.so
7. Copy the binary of billigertelefonieren to the usr/bin directory
(You're in squashfs-root/lib right now, aren't you?)
# cd ../usr/bin
# cp <PATH_TO_billigertelefonieren>/billigertelefonieren .
Assure that it is executable:
# chmod 755 billigertelefonieren
8. Edit a boot script so that the LCR will be run on startup, e.g. rc.voip and
add billigertelefonieren -d to the file. These are the changes for rc.voip:
# cd ../../etc/init.d
Use your favourite editor for editing the contents of rc.voip
# editor rc.voip
I changed
         if [ "$AB_TEST" = "1" ] ; then
            telefon > /dev/null
         else
            telefon a127.0.0.1> /dev/null
         fi
to
         if [ "$AB_TEST" = "1" ] ; then
            telefon > /dev/null
            billigertelefonieren -d
         else
            telefon a127.0.0.1> /dev/null
            billigertelefonieren -d
         fi
9. Create the new filesystem:
# cd ../../..
# <PATH_TO_mksquashfs-lzma>/mksquashfs-lzma squashfs-root/ newfilesystem.image
-b 16384 -le -root-owned
If it worked, the output might be:
Creating little endian 2.76 filesystem on newfilesystem.image, block size 16384.
Little endian filesystem, data block size 16384, compressed data, compressed metadata, compressed fragments
Filesystem size 3086.75 Kbytes (3.01 Mbytes)
        31.89% of uncompressed filesystem size (9678.91 Kbytes)
Inode table size 7687 bytes (7.51 Kbytes)
        27.77% of uncompressed inode table size (27684 bytes)
Directory table size 8035 bytes (7.85 Kbytes)
        44.47% of uncompressed directory table size (18070 bytes)
Number of duplicate files found 67
Number of inodes 1208
Number of files 847
Number of fragments 132
Number of symbolic links  167
Number of device nodes 128
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 66
Number of uids 1
        root (0)
Number of gids 0

If you're using newer firmware versions than 12.04.15, AVM has merged the
files kernel.image and filesystem.image. I.e. after some padding bytes, the
filesystem.image was appended to kernel.image. To create new kernel.image,
search the old one for the sequence "hsqs", then replace
everything starting with this sequence with the new file newfilesystem.image.
I've created a small application for this purpose, it's called buildkernelimage
and is included in the svn trunk. So goto its directory
# cd <PATH_TO_fritzbox-lcr-src>/fritzbox-lcr/trunk/buildkernelimage
# make
Be sure to compile this with your native compiler since you want to run it now!
If it has been compiled, go back to the directory where you created
newfilesystem.image and type:
# <PATH_TO_fritzbox-lcr-src>/fritzbox-lcr/trunk/buildkernelimage/buildkernelimage
kernel.image newfilesystem.image newkernel.image
The newkernel.image is the file you want to upload in the next step.

10. Update the filesystem of your box. For this you need an IP address in the
subnet 192.168.178.0/24, except 192.168.178.1! This is the box's ip when it's
booting with the ADAM2 bootloader. For example Debian users may use
/etc/network/interfaces and add:
iface eth0:0 inet static
        address 192.168.178.3
        netmask 255.255.255.0
        network 192.168.178.0
        broadcast 192.168.178.255

then enter as root:
# ifup eth0:0
So assuming that you have an IP address in the subnet, you have to reboot your
Fritz!Box. You can do that via telnet, but before that goto the directory where
your newfilesystem.image lies and enter:
# ftp
ftp> open 192.168.178.1
and retry this command as often as you can, because the ADAM2 bootloader doesn't
offer its FTP service that long. So type reboot in telnet and then retry this
command (press arrow up and ENTER). If successful, you'll see:
Connected to 192.168.178.1.
220 ADAM2 FTP Server ready
Name (192.168.178.1:user):

Type adam2, password adam2. If you see:
331 Password required for
530 not logged in
Login failed.

type:
ftp> user adam2
331 Password required for adam2
Password: adam2

so you'll see:
230 User adam2 successfully logged in
Remote system type is AVM.
Further response:
230 User adam2 successfully logged in
Remote system type is AVM.

Type now (only the lines with ftp>):
ftp> bin
200 Type set to BINARY
ftp> passive
Passive mode on.
ftp> quote MEDIA FLSH
200 Media set to MEDIA_FLASH

It seems that AVM has changed the bootloader a bit, so if you're using
Firmwares with version less or equal than 12.04.15 type:

ftp> put newfilesystem.image "1mtd0"

For newer ones, ther kernel.image and filesystem.image were merged (see above).
So, assuming that you created newkernel.image, type:

ftp> put newkernel.image "mtd1"

When using passive mode, there could occur an error "connection refused", so
just try again.

Possible response:
local: newkernel.image remote: mtd1
227 Entering Passive Mode (192,168,178,1,5,166)
150 Opening BINARY data connection
226 Transfer complete
3828736 bytes sent in 34.43 secs (108.6 kB/s)

If the upload has finished type:
ftp> quote REBOOT
221 Thank you for using the FTP service on ADAM2
ftp> quit
221 Goodbye.

The box should reboot now and it should be up in a minute. If not, plug the
power supply out and replug it.
11. Find out if the programme is runnning.
To do so, login via telnet and type:
# ps
If you're finding something like billigertelefonieren -d in the process list,
you're lucky, if not try running it in the shell:
# billigertelefonieren

Here's a list for error messages:
- ./billigertelefonieren: can't resolve symbol '__uClibc_start_main'

You cross-compiled the application wrong. You have to link it against the
correct uClibc version! (For example the firmware version 12.04.31 uses uClibc
0.28)
- to be continued...

Troubleshooting
===============

- The application runs for a while, but after every full hour it shuts down.
Check out what happens if you run the application from the shell.
Login via telnet, then type:
# billigertelefonieren
If you're getting errors like "unable to collect providers.",
"unable to update provider data. cause: ..." there were parsing errors for the
the billiger-telefonieren.de site. So their webmaster changed the design or
something. This is not your fault. So wait for an adjusted version of the
application or let me know in case I didn't notice. Or try for yourself...
There could be other errors because of parsing errors because of the Fritz!Box
webinterface (AVM updated it!) or password errors... you'll find out...

License

---------------------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ----------------------------------------------------------------------------

SourceForge.net Logo