Setting up freecwmp development environment for the first time can be somewhat complicated. If you don’t have Arch Linux this is the tutorial you should use.

general

freecwmp and libfreecwmp will be placed in /opt/dev/ directory. All other dependencies will be installed in /opt/git/ directory.

Configure USER and GROUP variables that we are going to use:

USER=your_user
GROUP=your_group

Create directories:

sudo mkdir -p /opt/{dev,git}
sudo chown -R $USER:$GROUP /opt/{dev,git}

dependencies

In order to build and run freecwmp you will need the following libraries (install order):

  1. curl

  2. uci

  3. json-c

  4. libubox

  5. ubus

  6. microxml

  7. zstream

  8. libfreecwmp

curl

Your distribution should already have curl development package. Use that for now.

uci

Get the sources:

git clone git://nbd.name/uci.git /opt/git/uci
cd /opt/git/uci/

Configure:

cmake CMakeLists.txt -DBUILD_LUA=OFF

Build:

make

Install:

sudo make install
sudo ln -sf /usr/bin/uci /sbin/uci

json-c

Your distribution might have a json-c development package. Debian calls it libjson0-dev.

Or install from sources:

git clone git://github.com/json-c/json-c.git /opt/git/json-c
cd /opt/git/json-c/

Generate configuration files:

autoreconf -i

Configure:

./configure --prefix=/usr

Build:

make

Install:

sudo make install
sudo ln -sf /usr/include/json-c /usr/include/json

libubox

Get the sources:

git clone git://nbd.name/luci2/libubox.git /opt/git/libubox
cd /opt/git/libubox/

Configure:

cmake CMakeLists.txt -DBUILD_LUA=OFF

Build:

make

Install:

sudo make install

ubus

Get the sources:

git clone git://nbd.name/luci2/ubus.git /opt/git/ubus
cd /opt/git/ubus/

Configure:

cmake CMakeLists.txt -DBUILD_LUA=OFF

Build:

make

Install:

sudo make install

microxml

Get the sources:

git clone git://dev.freecwmp.org/microxml /opt/git/microxml
cd /opt/git/microxml/

Generate configuration files:

autoconf -i

Configure:

./configure --prefix=/usr --enable-threads --enable-shared --enable-static

Build:

make

Install:

sudo make install

zstream

Get the sources:

git clone git://midlink.org/zstream.git /opt/git/zstream
cd /opt/git/zstream/

Build:

make -j1

Install:

sudo make install

libfreecwmp

Get the sources:

git clone git://dev.libfreecwmp.org/libfreecwmp /opt/dev/libfreecwmp
cd /opt/dev/libfreecwmp/

Generate configuration files:

autoreconf -i

Configure:

./configure --prefix=/usr

Build:

make

Install:

sudo make install

shflags

Get the sources:

git svn clone http://shflags.googlecode.com/svn/trunk/source/1.0/lib /opt/dev/shflags
cd /opt/dev/shflags/

Install:

sudo mkdir -p /usr/share/shflags/
sudo cp shflags /usr/share/shflags/shflags.sh

freecwmp

compiling

Once the dependencies have been installed we can start compiling freecwmp.

Get the sources:

git clone git://dev.freecwmp.org/freecwmp /opt/dev/freecwmp
cd /opt/dev/freecwmp/

Generate configuration files:

autoreconf -i

Configure:

./configure --enable-dummy-mode --enable-debug --enable-devel --enable-acs=multi --enable-http=curl

Build:

make

configuration

We won’t install freecwmp, we’ll use it from /opt/dev/freecwmp/ directory. Make sure we are located there:

cd /opt/dev/freecwmp/

Because we are using this setup for development we want that all our changes are visible in our git clone. Best way to do this is to use symlinks. First create the directory where scripts are located on actual device:

sudo mkdir -p /usr/share/freecwmp/functions

Then create symlinks for freecwmp scripts:

sudo ln -sf /opt/dev/freecwmp/ext/openwrt/scripts/freecwmp.sh /usr/sbin/freecwmp
sudo ln -sf /opt/dev/freecwmp/ext/openwrt/scripts/defaults /usr/share/freecwmp/defaults
sudo ln -sf /opt/dev/freecwmp/ext/openwrt/scripts/functions/misc /usr/share/freecwmp/functions/misc
sudo ln -sf /opt/dev/freecwmp/ext/openwrt/scripts/functions/common /usr/share/freecwmp/functions/common
sudo ln -sf /opt/dev/freecwmp/ext/openwrt/scripts/functions/device_info /usr/share/freecwmp/functions/device_info
sudo ln -sf /opt/dev/freecwmp/ext/openwrt/scripts/functions/lan_device /usr/share/freecwmp/functions/lan_device
sudo ln -sf /opt/dev/freecwmp/ext/openwrt/scripts/functions/management_server /usr/share/freecwmp/functions/management_server
sudo ln -sf /opt/dev/freecwmp/ext/openwrt/scripts/functions/voice_service /usr/share/freecwmp/functions/voice_service
sudo ln -sf /opt/dev/freecwmp/ext/openwrt/scripts/functions/wan_device /usr/share/freecwmp/functions/wan_device
sudo ln -sf /opt/dev/freecwmp/ext/openwrt/scripts/functions/x_freecwmp_org /usr/share/freecwmp/functions/x_freecwmp_org
sudo ln -sf /opt/dev/freecwmp/ext/openwrt/scripts/functions/device_users /usr/share/freecwmp/functions/device_users
sudo ln -sf /opt/dev/freecwmp/ext/openwrt/scripts/functions/device_hosts /usr/share/freecwmp/functions/device_hosts
sudo ln -sf /opt/dev/freecwmp/ext/openwrt/scripts/functions/device_routing /usr/share/freecwmp/functions/device_routing
sudo ln -sf /opt/dev/freecwmp/ext/openwrt/scripts/functions/device_ip /usr/share/freecwmp/functions/device_ip

Also, you can create symlink for freecwmp configuration file:

sudo mkdir /etc/config
sudo ln -sf /opt/dev/freecwmp/ext/openwrt/config/freecwmp /etc/config/freecwmp

And finally create symlink for freecwmpd binary:

sudo ln -sf /opt/dev/freecwmp/bin/freecwmpd /usr/sbin/freecwmpd

We need to export few variables that are used in freecwmp scripts:

export UCI_CONFIG_DIR="/opt/dev/freecwmp/ext/openwrt/config/"
export UBUS_SOCKET="/tmp/ubus.sock"

Install few shell scripts from OpenWrt:

sudo mkdir -p /lib/{config,functions}
sudo wget http://pastebin.lukaperkov.net/openwrt/20121219_lib_functions.sh -O /lib/functions.sh
sudo wget http://pastebin.lukaperkov.net/openwrt/20121219_lib_config_uci.sh -O /lib/config/uci.sh
sudo wget http://pastebin.lukaperkov.net/openwrt/20121219_lib_functions_network.sh -O /lib/functions/network.sh

If everything is configured properly when you run:

bash /usr/sbin/freecwmp get InternetGatewayDevice.

You should see some output like this:

InternetGatewayDevice.DeviceInfo.Manufacturer : freecwmp
InternetGatewayDevice.DeviceInfo.ManufacturerOUI : FFFFFF
InternetGatewayDevice.DeviceInfo.ProductClass : freecwmp
InternetGatewayDevice.DeviceInfo.SerialNumber : FFFFFF123456
InternetGatewayDevice.DeviceInfo.HardwareVersion : example_hw_version
InternetGatewayDevice.DeviceInfo.SoftwareVersion : example_sw_version
InternetGatewayDevice.DeviceInfo.UpTime : 1158811
...

Depending on your system you might need to:

export PATH=$PATH:/usr/sbin:/sbin
sudo ln -sf bash /bin/sh

Make changes in /etc/config/freecwmp and in /usr/share/freecwmp/defaults so freecwmpd can connect to your ACS server. But before you run freecwmpd make sure that you have in another terminal running ubusd:

/usr/sbin/ubusd -s /tmp/ubus.sock

Finally you can run freecwmpd:

/usr/sbin/freecwmpd -f