OpenWrt Forum Archive

Topic: Porting Freifunk features to OpenWrt

The content of this topic has been archived on 21 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I started from RC4, add OLSR routing, use Freifunk 1.0.7 web interface (and some of their glue scripts/confs), add QoS (wrt is acting both as edge and core router of the diffserv domain, ie: the wireless side), add Asterisk (on wired+wireless) and siproxd (on wireless+wan); then I built two rude web pages for QoS monitoring and VOIP setting/monitoring that use nvram vars to store configs (and startup scripts use this vars to build configs in /var/etc when the service is started).
The result is an 11 nodes (growing) mesh network, with voip capabilities and at least 2.4Mbit/s of real troughput on every link (300-800 meters) and every environment (we had snow on the trees in the last week, and there were no problems even on express forwarding traffic).
Now I need to put some order in my boxes but I'd prefer to do it mantaining minimal differences from OpenWrt development; this means, as an example, to port Freifunk web interface's features on the OpenWrt's one.

If someone of OpenWrt developers could point me to the right direction, I could port Freifunk features on OpenWrt.
Some of them need also some mods to the firewall (to allow olsr traffic, multiple DMZs, DHCP on the wireless side, etc) and other services (like dnsmasq).

ciao

Wallace

This is a small add-on for webif; it fetches OLSR infos and display them in Status-->OLSR.
Just create /www/cgi-bin/webif/olsr-status.sh with the following content:

#!/usr/bin/haserl
<?
. /usr/lib/webif/webif.sh
header "Status" "OLSR" "OLSR status"
?>

<div class="half noBorderOnLeft" align=center>
<table style="width: 50%">
<tr><td><?
wget -O - http://127.0.0.1:8080/all|awk '
/<h2>/, /<\/div>/ {
gsub("border=0", "border=1 cellspacing=0 cellpadding=0")
gsub("BORDER=0", "BORDER=1")
gsub("<select", "<select name=none")
print
}'
?>
</td></tr>
</table>
</div>

<? footer ?>
<!--
##WEBIF:name:Status:3:OLSR

ciao

Wallace

Active routes in kernel, file /www/cgi-bin/webif/route-status.sh

#!/usr/bin/haserl
<?
. /usr/lib/webif/webif.sh
header "Status" "Routes" "Active Routes"
?>

<div class="half noBorderOnLeft" align=center>
<table style="width: 50%">
<tr><td>
<?
route -n|awk '
function td(s) {
printf("<TD STYLE=\"padding:0 2 0 2;font-size:9px;\">%s</TD>", s);
}
function ip(s, m) {
if(m=="255.255.255.255"&&s!="0.0.0.0") {
td(sprintf("<A HREF=\"http://%s/\">%s</A>", s, s));
}
else {
td(s);
}
}
BEGIN {
print "<""TABLE BORDER=\"0\" CELLPADDING=\"5\" CELLSPACING=\"5\">";
}
/^[0-9]/ {
printf "<TR>";
ip($1, $3);
ip($2, $3);
for(i=3;i<=NF;i++) td($i);
printf "</TR>\n";
}
/^Destination/ {
printf "<TR>";
for(i=1;i<=NF;i++) printf("<TH STYLE=\"padding:0 2 0 2;\">%s</TH>", $i);
printf "</TR>\n";
}
END {
print "<""/TABLE>";
}'
?>
</td></tr>
</table>           
</div>             
                   
<? footer ?>       
<!--        
##WEBIF:name:Status:4:Routes
-->

ciao

Wallace

The same for "Wireless Scan",  file /www/cgi-bin/webif/wireless-scan.sh

#!/usr/bin/haserl
<?
. /usr/lib/webif/webif.sh
header "Status" "Scan" "Wireless Scan Results"
WLDEV=$(nvram get wifi_ifname)
?>

<div class="half noBorderOnLeft" align=center>
<table border="1" style="width: 50%">
<TR>
<TH>SSID</TH>
<TH>Channel</TH>
<TH>AdHoc</TH>
<TH>Open</TH>
<TH>Signal</TH>
<TH>Max.</TH>
<TH>BSSID</TH>
</TR>
<TR>
<TD COLSPAN="7">
<?
wl -i $WLDEV scan
sleep 2
wl -i $WLDEV scanresults|awk '
BEGIN {
print "</td></tr>";
}
/^SSID:/ {
ssid=substr($2, 2, length($2) - 2);
chan=" ";
adhoc="no";
open="yes";
rssi="0";
titl=" ";
rate=" ";
bssid=" ";
do {
if(!(getline))break;
if (/Channel:/) {
chan=$NF;
}
if (/Mode:/) {
adhoc=($2~/Managed/?"no":"yes");
}                               
if (/RSSI:/) {           
rssi=int(($(4+($3~/Hoc/))-$(7+($3~/Hoc/)))/4);
for(i=3; i<=8; i++) {                         
titl=titl$(i+($3~/Hoc/))" ";
}                           
if (0 > rssi) rssi = 0;                       
if (5 < rssi) rssi = 5;              
}                      
if (/Capability:/) {
for(i = 4; i <= NF; i++) {
if ($i~/^WEP/) open="no"; 
}                        
}              
if (/Supported Rates:/) {
rate=$(NF - 1);          
}              
if (/BSSID:/) {
bssid=$2;       
}        
} while(/\S/);   
print "<tr>"  
print "<td>"ssid"</td>"       
print "<td>"chan"</td>"
print "<td align=\"absmiddle\">"adhoc"</td>"
print "<td align=\"absmiddle\">"open"</td>" 
print "<td align=\"absmiddle\" nowrap>"titl"</td>"
print "<td>"rate"</td>"                           
print "<td>"bssid"</td>"
print "</tr>";          
}             
END {    
}'       
?>            
</td></tr>     
</table>  
</div>              
                 
<? footer ?>
<!--        
##WEBIF:name:Status:3:Scan

ciao

Wallace

N.b.: I'm just pasting Freifunk pages into OpenWrt webif... these should then be edited to result a bit more comfortable to view; check also the index number of the subcategory...

The same for "Overview", file /www/cgi-bin/webif/overview-status.sh

#!/usr/bin/haserl
<?
. /usr/lib/webif/webif.sh
header "Status" "Overview" "Device Infos"
WLDEV=$(nvram get wifi_ifname)
?>

<SCRIPT LANGUAGE="JavaScript"><!--
function fold(id) {
obj = document.getElementById(id);
obj.style.display = ('none'==obj.style.display?'block':'none');
return false;
}
//--></SCRIPT>

<div class="half noBorderOnLeft" align=center>
<table border="1" style="width: 50%">

<TR>
<TD>IP Address:</TD>
<TD>IP: <? ifconfig $WLDEV|awk 'sub("inet addr:","") {print $1}' ?>,
Mask: <? ifconfig $WLDEV|awk 'sub("Mask:","") {print $4}' ?>,
MAC: <? ifconfig $WLDEV|awk 'sub("HWaddr","") {print $4}' ?></TD>
</TR>

<TR>
<TD>WLAN Status:</TD>
<TD><? wl -i $WLDEV status 2>&1 ?></TD>
</TR>

<TR>
<TD>Uptime:</TD>
<TD><? uptime ?></TD>
</TR>

<TR>
<TD>Device Info:</TD>
<TD>Boardtype: <? nvram get boardtype ?>, Boardnum: <? nvram get boardnum ?></TD>
</TR>

<TR>
<TD>Kernel Log: </TD>
<TD><A HREF="#" ONCLICK="return fold('dmesg')">Show / Hide</A></TD>              
</TR>                                                                            
                                                                                 
<TR>                                                                             
<TD COLSPAN="2">                                                                 
<?                                                                               
echo -n '<PRE STYLE="display:none" ID="dmesg">'                                  
dmesg 2>&1                                                                       
echo '</PRE>'                                                                    
?>                                                                               
</TD>                                                                            
</TR>                                                                            
                                                                                 
<TR>                                                                             
<TD>System Log:                                                                  
</TD>                                                                            
<TD><A HREF="#" ONCLICK="return fold('logread')">Show / Hide</A></TD>            
</TR>                                                                            
                                                                                 
<TR>                                                                             
<TD COLSPAN="2">                                                                 
<?                                                                               
echo -n '<PRE STYLE="display:none" ID="logread">'                                
logread 2>&1                                                         
echo '</PRE>'                                                                    
?>                                                                               
</TD>                                                                            
</TR>                                                                            
                                                                                 
<TR>                                                                             
<TD>IP NAT: </TD>                                                                
<TD><A HREF="#" ONCLICK="return fold('nat')">Show / Hide</A></TD>                
</TR>                                                                            
<TR>                                                                             
<TD COLSPAN="2">                                                                 
<?                                                                               
echo -n '<PRE STYLE="display:none" ID="nat">'                                    
iptables -t nat -L -n -v 2>&1                                                    
echo '</PRE>'                                                        
?>                                                                   
</TD>                                                                
</TR>

<TR>                                                                             
<TD>Interface                                                                    
Config: </TD>                                                                    
<TD><A HREF="#" ONCLICK="return fold('ifconfig')">Show / Hide</A></TD>           
</TR>                                                                            
                                                                                 
<TR>                                                                             
<TD COLSPAN="2">                                                                 
<?                                                                               
echo -n '<PRE STYLE="display:none" ID="ifconfig">'                               
echo "lan_ifnames=$(nvram get lan_ifnames)"                                      
echo "lan_ifname=$(nvram get lan_ifname)"                             
echo "wl0_ifname=$(nvram get wl0_ifname)"                                        
echo "wifi_ifname=$(nvram get wifi_ifname)"                                      
echo "wan_ifname=$(nvram get wan_ifname)"                                        
echo                                                                             
brctl show 2>&1                                                                  
echo                                                                             
ifconfig 2>&1                                                                    
echo '</PRE>'                                                                    
?>                                                                               
</TD>                                                                            
</TR>                                                                            
</table>                                                                         
</div>                                                                           
                                                                                 
<? footer ?>                                                          
<!--                                                                  
##WEBIF:name:Status:1:Overview                                        
-->

bye

The same for contact page, file /www/cgi-bin/webif/contact.sh

#!/usr/bin/haserl
<?
. /usr/lib/webif/webif.sh
load_settings contact
load_settings nvram

if empty "$FORM_submit"; then
        FORM_nickname=${ff_adm_nick:-$(nvram get ff_adm_nick)}
        FORM_name=${ff_adm_name:-$(nvram get ff_adm_name)}
        FORM_email=${ff_adm_mail:-$(nvram get ff_adm_mail)}
        FORM_telephone=${ff_adm_tel:-$(nvram get ff_adm_tel)}
        FORM_location=${ff_adm_loc:-$(nvram get ff_adm_loc)}
        FORM_note=${ff_adm_note:-$(nvram get ff_adm_note)}
else
        SAVED=1
        validate <<EOF
nickname|FORM_nickname|Nickname|required|$FORM_nickname
location|FORM_location|Location|required|$FORM_location
EOF
        equal "$?" 0 && {
                save_setting contact ff_adm_nick $FORM_nickname
                save_setting contact ff_adm_name $FORM_name
                save_setting contact ff_adm_mail $FORM_email
                save_setting contact ff_adm_tel $FORM_telephone
                save_setting contact ff_adm_loc $FORM_location
                save_setting contact ff_adm_note $FORM_note
        }
fi

header "System" "Contact" "Router Contact" '' "$SCRIPT_NAME"

display_form <<EOF
start_form|Contact
field|Nickname
text|nickname|$FORM_nickname
field|Name
text|name|$FORM_name
field|eMail
text|email|$FORM_email
field|Telephone
text|telephone|$FORM_telephone
field|Location
text|location|$FORM_location
field|Note          
text|note|$FORM_note         
end_form                                                      
EOF                                                       
                                                           
footer ?>                                                    
<!--                                                        
##WEBIF:name:System:4:Contact                             
-->

Hi Wallace,

I notice that the code you're porting retains a lot of the Freifunk NVRAM variables.  This is fine in Freifunk, or even as a separate package.  But I believe OpenWRT's policy is to avoid introducing new NVRAM variables wherever possible.  So to get features like this accepted into the base configuration you'd need to work out a way of storing the FF variables in a file instead of NVRAM - see the new /etc/config method in Kamikaze.

Hey,

well - and in case you missed it: Theres already a new Freifunk available with enough openwrt/whiterussian compatibility for your needs. Since 24.dec theres FFF-1.1 based on the newer 2.4.30 / uClibc with a small addon ipk called "freifunk-openwrt-compat" (which re-adds the stuff I discarded for 2Mb-Flash-compatibility aka WAP54g). And of course you're free to do it yourself...

As pointed out elsewhere: FFF will make it's way into the OW build tree one day staying alive as IPK version. For now, the current version will do smile

LG
Sven-Ola

danversj wrote:

Hi Wallace,

I notice that the code you're porting retains a lot of the Freifunk NVRAM variables.

I just ported FF features to OpenWrt webif. The code pasted here is just an example... I posted the first pages to see if someone was interested in this kind of port.
As I am writing I just finished to build all the pages for olsrd config/status, voip config/status, QoS status (VOIP and QoS are my addons).

Now I'm debugging them moving some quirks (boot_wait, bridge breaking at boot, etc) from FF webif to startup scripts. As soon as I finished to debug the new pages, I'll rewrite all FF scripts (S45firewall, S50dnsmasq, etc) to be simple addons of OW ones instead of replacing them and I'll surely use the /etc/config setup of Kamikaze!

I'm alone and no-profit here, gimme time tongue

ciao

Wallace

sven-ola wrote:

Hey,

well - and in case you missed it: Theres already a new Freifunk available with enough openwrt/whiterussian compatibility for your needs. Since 24.dec theres FFF-1.1 based on the newer 2.4.30 / uClibc with a small addon ipk called "freifunk-openwrt-compat" (which re-adds the stuff I discarded for 2Mb-Flash-compatibility aka WAP54g). And of course you're free to do it yourself...

As pointed out elsewhere: FFF will make it's way into the OW build tree one day staying alive as IPK version. For now, the current version will do smile

LG
Sven-Ola

Hi Sven!!! I tried to write you by mail (I'm in contact with Nino of ninux.org Rome's wireless community) twice on november, but I didn't get any answer. When I digged in the forum I only found your message where you said that you didn't have time to fiddle with MBM.  That's why I proceeded by myself!

I started with OLSR last april/may with a "dynamic WDS" configuration, but I didn't have a comfortable interface to fine tuning everything. Moreover my "peer-mates" where unhappy by performances (about 4mbit on every link) as they were used to plain bridged-WDS (16-20mbit). So I left my work behind untill we moved our shared P2P server and reliability problems started... And we had to quickly move to mesh, but Freifunk 1.0.7 didn't work properly (11 WRT54G v2.2 to v4.0 here) so I put everything on OW RC4, then added a DiffServ domain on the olsr side and Asterisk+siproxd for voip purposes.
Now I'm re-writing everything to be OW-friendly instead of replacing parts of it!

ciao

Wallace

N.b.: as soon as I reach my version 1.0 I'll try to publish my ipkgs somewhere; now there is only a messy bunch of scripts.

danversj wrote:

see the new /etc/config method in Kamikaze.

Where can I get some more infos on /etc/config method?
Are there Kamikaze infos somewhere?
I tried to browse the source code from dev.openwrt.org but I couldn't find much.

Can someone point me to a link or something helpfull?

Regards

Wallace

The OpenWRT root filesystem development occurs in the "base-files" package.  You can follow it's progress on Trac.

The "base-files" package is split into two areas.  There's the generic code here:

https://dev.openwrt.org/browser/trunk/o … /?rev=2884

And the architecture-and-kernel-specific code here:
https://dev.openwrt.org/browser/trunk/o … /?rev=2884

For example, /etc/config/network for 2.4 kernels on Broadcom hardware is found here:
https://dev.openwrt.org/file/trunk/open … k?rev=2884

Note that these links reference a specific version of the code - I haven't found a way to bookmark the latest revision.

danversj wrote:

The OpenWRT root filesystem development occurs in the "base-files" package.  You can follow it's progress on Trac.

Thanks danversj!
I'm proceeding.

ciao

Wallace

n.b.: nice blog, I found a lot of helpfull informations on WiFi.

The discussion might have continued from here.