├── Makefile ├── README ├── mesh_run_old.sh ├── non-wrt └── piece_start_stop └── src ├── control ├── control └── prerm ├── data ├── etc │ ├── init.d │ │ └── mesh │ └── mesh.config └── usr │ └── share │ └── mesh │ └── mesh.common └── debian-binary /Makefile: -------------------------------------------------------------------------------- 1 | NAME = piratebox-mesh 2 | VERSION = 1.1.4 3 | ARCH = all 4 | IPK = $(NAME)_$(VERSION)_$(ARCH).ipk 5 | IPKDIR = src 6 | NON_WRT = $(NAME)_$(VERSION)_$(ARCH)_NON_WRT.sh 7 | 8 | .DEFAULT_GOAL = all 9 | 10 | $(IPKDIR)/control.tar.gz: $(IPKDIR)/control 11 | tar czf $@ -C $(IPKDIR)/control . 12 | 13 | control: $(IPKDIR)/control.tar.gz 14 | 15 | $(IPKDIR)/data.tar.gz: $(IPKDIR)/data 16 | tar czf $@ -C $(IPKDIR)/data . 17 | 18 | 19 | data: $(IPKDIR)/data.tar.gz $(IPKPSDIR)/data.tar.gz 20 | 21 | 22 | $(IPK): $(IPKDIR)/control.tar.gz $(IPKDIR)/data.tar.gz $(IPKDIR)/control $(IPKDIR)/data 23 | tar czf $@ -C $(IPKDIR) ./control.tar.gz ./data.tar.gz debian-binary 24 | 25 | all: $(IPK) $(NON_WRT) 26 | 27 | cleanbuild: 28 | -rm -f $(IPKDIR)/control.tar.gz 29 | -rm -f $(IPKDIR)/data.tar.gz 30 | 31 | clean: cleanbuild cleanlaptop 32 | -rm -f $(IPK) 33 | 34 | laptop: $(NON_WRT) 35 | 36 | $(NON_WRT): 37 | cat src/data/etc/mesh.config > $(NON_WRT) 38 | grep -v \#! src/data/usr/share/mesh/mesh.common >> $(NON_WRT) 39 | sed 's/OPENWRT=yes/OPENWRT=no/' -i $(NON_WRT) 40 | sed 's/IPV4_LOAD="yes"/IPV4_LOAD="no"/' -i $(NON_WRT) 41 | cat non-wrt/piece_start_stop >> $(NON_WRT) 42 | 43 | 44 | cleanlaptop: 45 | -rm -f $(NON_WRT) 46 | 47 | 48 | .PHONY: all clean laptop 49 | 50 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | # Enables the OpenWRT - PirateBox to mesh up with each other. 2 | # (c)2012 Matthias Strubel matthias.strubel@aod-rpg.de 3 | # Licenced under GPL-3 4 | 5 | 6 | KNOW SUPPORTED DEVICES: 7 | - TP-LINK MR3020 (wifi0: Atheros 9380) 8 | - TP-LINK MR3040 9 | - MikroTek RB411Uha 10 | - TP-LINK WR842ND 11 | 12 | - Linksys WRT54GL; tested trunk image. Works as relay only; no IPv6 support in Trunk 13 | 14 | OPENWRT-PACKAGE DEPENDENCIES: 15 | kmod-batman-adv (this depends on kmod-lib-crc16) 16 | wireless-tools 17 | 18 | DEBIAN DEPENDENCIES: 19 | batman-adv seems to be installed on default. You need to install batctl, if that script is not available 20 | this script tries to setup everything using the sys/class interface 21 | 22 | WHAT DO THIS PACKAGE?: 23 | - It installs on script with all needed defaults running in Mesh mode 24 | - Script set up everything needed to get the Box in Mesh mode 25 | - Box in Mesh don't have to be a AP at same time 26 | 27 | WHY AN EXTRA PACKAGE?: 28 | - I don't want to add the Mesh-software dependency to the normal PB-Package 29 | - Easier Update if something changes 30 | 31 | 32 | NOTEBOOK?: 33 | - Not every notebook can hold two network-interfaces online 34 | - You can join the network download this and do 35 | - currently there is no iptables included. You won't be able to route 36 | - Software needed: iw, ifconfig, bridge-utils like br-ctl & iptables Including support for "Bridge-nf" in some cases 37 | 38 | FAQ: 39 | 40 | I'm getting a "SIOCSIFFLAGS: No buffer space available" - what is this? 41 | - It seems you card cannot run with an exchanged MACAdress, switch it 42 | off. 43 | - Remember runnin stop to clean up the partly created stuff 44 | -------------------------------------------------------------------------------- /mesh_run_old.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RADIODEVICE=radio0 4 | OPENWRT=no 5 | # Interface for normal AP Mode 6 | AP_IF=wlan0 7 | # Interface for MESH 8 | MESH_IF=mesh0 9 | # Channel 10 | MESH_CHANNEL=0 11 | # Mesh-SSID 12 | MESH_SSID="PB-Mesh" 13 | # Needed MTU for B.A.T.M.A.N. 14 | MTU_NEEDED=1528 15 | # Change this to 2nd card, if needed 16 | IW_DEVICE=phy0 17 | # Modified MAC 18 | MODMAC="" 19 | EXCHANGE_MAC="yes" 20 | 21 | #### 22 | # BATMAN stuff 23 | BAT_IF=bat0 24 | # Increase lookup Frequency to 5s 25 | BAT_INT=5000 26 | 27 | check_rc() { 28 | MSG="" 29 | if [ -n "$2" ] ; then 30 | MSG="Error in $2" 31 | else 32 | MSG="Failed with RC $1" 33 | fi 34 | [ "$1" != "0" ] && echo $MSG && exit 255 35 | } 36 | 37 | 38 | uci_get_details() { 39 | #get mac Adress from uci 40 | SOURCEMAC=$(uci get wireless.$RADIODEVICE.macaddr) 41 | check_rc $? "getting SourceMac" 42 | [[ $MESH_CHANNEL = "0" ]] && MESH_CHANNEL=$( uci get wireless.$RADIODEVICE.channel) 43 | check_rc $? "getting Channel" 44 | } 45 | 46 | conservative_details() { 47 | SOURCEMAC="F8:D1:11:BD:57:5C" 48 | MESH_CHANNEL=11 49 | } 50 | 51 | modify_MAC() { 52 | # Modify MAC for 2nd interface if not set 53 | #Change two letters 54 | if [ "$MODMAC" = "" ] ; then 55 | MODMAC=$( echo $SOURCEMAC | sed 's/c/a/' | sed 's/1/2/' ) 56 | check_rc $? "sed :( " 57 | echo "Found MAC for $RADIODEVICE : $SOURCEMAC" 58 | echo " modified for 2nd Wifi-if : $MODMAC" 59 | fi 60 | } 61 | 62 | do_wlan_if_up() { 63 | echo "Setting up AdHoc Interface for B.A.T.M.A.N. " 64 | iw $IW_DEVICE interface add $MESH_IF type adhoc 65 | check_rc $? 66 | 67 | echo "Increasing MTU for $MESH_IF to $MTU_NEEDED" 68 | ifconfig $MESH_IF mtu $MTU_NEEDED 69 | check_rc $? 70 | 71 | if [ "$EXCHANGE_MAC" = "yes" ] ; then 72 | echo "Changing $MESH_IF MAC to $MODMAC" 73 | ifconfig $MESH_IF hw ether $MODMAC 74 | check_rc $? 75 | fi 76 | 77 | echo "Setting up Channel $MESH_CHANNEL" 78 | iwconfig $MESH_IF channel $MESH_CHANNEL 79 | check_rc $? 80 | 81 | echo "Setting SSID for Mesh $MESH_SSID" 82 | iwconfig $MESH_IF essid $MESH_SSID 83 | check_rc $? 84 | } 85 | 86 | 87 | do_batman_up() { 88 | 89 | echo "Adding $MESH_IF to B.A.T.M.A.N." 90 | batctl if add $MESH_IF 91 | check_rc $? 92 | 93 | echo "Starting $BAT_IF" 94 | ifconfig $BAT_IF 0.0.0.0 up 95 | check_rc $? 96 | 97 | echo "Setting B.A.T.M.A.N. Intervall to $BAT_INT " 98 | batctl it $BAT_INT 99 | check_rc $? 100 | 101 | } 102 | 103 | mesh_start() { 104 | echo "Starting Mesh-IF!" 105 | ifconfig $MESH_IF 0.0.0.0 up 106 | check_rc $? 107 | 108 | # Extract auto IPV6 adress and remove it from mesh if 109 | # AUTO_IPV6=$( ifconfig $MESH_IF | grep "inet6.* " | sed -e "s/^.*inet6 addr: //" -e "s/ Scope.*\$//" ) 110 | # echo "Removing .. $AUTO_IPV6 from $MESH_IF" 111 | # ifconfig $MESH_IF inet6 del $AUTO_IPV6 112 | # check_rc $? "resetting IPv6 on $MESH_IF" 113 | 114 | 115 | } 116 | 117 | mesh_stop() { 118 | echo "Stopping Mesh if!" 119 | ifconfig $MESH_IF down 120 | # check_rc $? 121 | } 122 | 123 | do_wlan_if_down() { 124 | echo "Cleaning up interfaces" 125 | iw dev $MESH_IF del 126 | # check_rc $? 127 | } 128 | 129 | do_batman_down() { 130 | echo "Remove $MESH_IF from $BAT_IF " 131 | batctl if del $MESH_IF 132 | # check_rc $? 133 | } 134 | 135 | check_requirements() { 136 | lsmod | grep batman >> /dev/null 137 | if [ "$?" != "0" ] ; then 138 | modprobe batman-adv 139 | check_rc $? "Loading kernel module batman-adv failed.. maybe not installed?" 140 | fi 141 | batctl if > /dev/null 142 | check_rc $? "Failed running batctl- maybe not installed? " 143 | } 144 | 145 | 146 | check_requirements 147 | 148 | if [ "$1" = "start" ] ; then 149 | echo "Starting Mesh Network with uci-collect..." 150 | uci_get_details 151 | modify_MAC 152 | do_wlan_if_up 153 | mesh_start 154 | do_batman_up 155 | echo "finished" 156 | elif [ "$1" = "stop" ] ; then 157 | echo "Stopping Mesh Network..." 158 | mesh_stop 159 | do_batman_down 160 | do_wlan_if_down 161 | echo "finished" 162 | elif [ "$1" = "start_conservative" ] ; then 163 | echo "Starting Mesh Network without Data-collecting..." 164 | conservative_details 165 | modify_MAC 166 | do_wlan_if_up 167 | mesh_start 168 | do_batman_up 169 | echo "finished" 170 | else 171 | echo "Valid options are: start start_conservative stop" 172 | fi 173 | -------------------------------------------------------------------------------- /non-wrt/piece_start_stop: -------------------------------------------------------------------------------- 1 | 2 | 3 | # ----piece_start_stop Start 4 | # -- Stuff will be added on Make 5 | 6 | check_config() { 7 | if [ "$MESH_CHANNEL" = "0" ] ; then 8 | echo "Please set option MESH_CHANNEL" 9 | exit 255 10 | elif [ "$EXCHANGE_MAC" = "yes" ] && [ "$SOURCEMAC" = "$MODMAC" ] ; then 11 | echo "Please set option SOURCEMAC to the MAC Address of you wifi device" 12 | ifconfig $AP_IF || ifconfig 13 | echo "Please set option SOURCEMAC to the MAC Address of you wifi device" 14 | echo " or enter a modified one in MODMAC and set EXCHANGE_MAC=no " 15 | exit 255 16 | fi 17 | } 18 | 19 | 20 | # Start Stop stuff for running in script directly 21 | if [ "$1" = "start" ] ; then 22 | check_config 23 | build_mesh 24 | elif [ "$1" = "stop" ] ; then 25 | destroy_mesh 26 | elif [ "$1" = "restart" ] ; then 27 | destroy_mesh 28 | check_config 29 | build_mesh 30 | elif [ "$1" = "test_gen" ] ; then 31 | generate_ipv4 32 | echo "Generated IPv4: $IPV4_FIXED" 33 | else 34 | echo "valid options are start|stop|restart" 35 | exit 255 36 | fi 37 | # ----piece_start_stop End 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/control/control: -------------------------------------------------------------------------------- 1 | Package: piratebox-mesh 2 | Version: 1.1.2 3 | Depends: kmod-batman-adv wireless-tools iptables-mod-extra 4 | Provides: 5 | Source: package/piratebox-mesh 6 | Section: net 7 | Status: unknown ok not-installed 8 | Essential: no 9 | Priority: optional 10 | Maintainer: Matthias Strubel 11 | Architecture: all 12 | Installed-Size: 101 13 | Description: Installs script for implementing B.A.T.M.A.N. adv on openwrt. It does not use the in build configurations, because the same script runs on other hardware too. 14 | -------------------------------------------------------------------------------- /src/control/prerm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . /etc/mesh.config 3 | . /usr/share/mesh/mesh.common 4 | rm $IPV4_IP_SAVE 5 | 6 | /etc/init.d/mesh disable 7 | /etc/init.d/mesh stop 8 | 9 | openwrt_preremove 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/data/etc/init.d/mesh: -------------------------------------------------------------------------------- 1 | #!/bin/sh /etc/rc.common 2 | 3 | NAME=mesh 4 | START=89 5 | STOP=11 6 | EXTRA_COMMANDS="init" 7 | EXTRA_HELP=" init Initializes all the OpenWRT stuff" 8 | 9 | # Include Mesh work-file 10 | . /usr/share/mesh/mesh.common 11 | 12 | #Load config 13 | . /etc/mesh.config 14 | 15 | start() { 16 | build_mesh 17 | } 18 | 19 | stop() { 20 | destroy_mesh 21 | } 22 | 23 | init() { 24 | openwrt_postinst 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/data/etc/mesh.config: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #------------------------------------ 4 | # Configuration for piratebox-mesh 5 | #------------------------------------ 6 | 7 | RADIODEVICE=radio0 8 | OPENWRT=yes 9 | OPENWRT_NETWORK="meshwork" 10 | # Interface for normal AP Mode 11 | AP_IF=wlan0 12 | # Interface for MESH 13 | MESH_IF=mesh0 14 | # Channel 15 | # If 0 it will use the same channel as configured 16 | # in /etc/config/wireless -> RADIODEVICE 17 | MESH_CHANNEL=0 18 | # Mesh-SSID 19 | MESH_SSID="PB-Mesh" 20 | # Needed MTU on Wifi-Interface for B.A.T.M.A.N. 21 | MTU_NEEDED=1560 22 | # Change this to 2nd card, if needed 23 | IW_DEVICE=phy0 24 | # Source MAC Adress.. If non WRT should be filled 25 | SOURCEMAC="" 26 | # Modified MAC 27 | # if empty, it will exchange a few letters for itself 28 | MODMAC="" 29 | # Needed for 2nd device comming up 30 | EXCHANGE_MAC="yes" 31 | 32 | #Fixed BSSID to avoid cell splitting 33 | CUSTOM_BSSID="12:CA:FF:EE:BA:BA" 34 | 35 | #Disable RTS/CTS 36 | DISABLE_RTS="yes" 37 | 38 | #### 39 | # BATMAN stuff 40 | BAT_IF=bat0 41 | # Increase lookup Frequency to 5s 42 | BAT_INT=5000 43 | # Gateway mode ( off ; client ; server ) 44 | # for NODE only (not be a PirateBox-AP at the same time), choose client 45 | # that will stick the client to the next PBx (hopefully) 46 | BAT_GW=server 47 | 48 | #------------------------------------------- 49 | # SET Ipv6 Stuff 50 | SET_IPV6="no" 51 | # Do you want a fixed address? 52 | IPV6_FIXED="" 53 | 54 | ####-------- 55 | # Extracts the fe80 address and adds an choosen prefix 56 | #### 57 | SET_GENERATED_IPV6="no" 58 | #used for mesh if 59 | IPV6_GEN_PREFIX="fdc0:ffea" 60 | #Enter without / 61 | IPV6_GEN_NETMASK="48" 62 | #--------------------------------------------- 63 | 64 | #--------------------------------------------- 65 | # IPV4 Stuff 66 | SET_IPV4="no" 67 | # Do you want to choose your IP? 68 | IPV4_FIXED="" 69 | IPV4_SUBNET_MASK="255.0.0.0" 70 | 71 | # Generates a 10.x.y.z IP Adress 72 | IPV4_GENERATE="no" 73 | 74 | #Load from file or openWRT config (if openwrt) 75 | IPV4_LOAD="no" 76 | 77 | IPV4_IP_SAVE=/etc/mesh_ipv4.cfg 78 | 79 | #--------------------------------------------- 80 | # Bridging options 81 | ### Should the BATMAN interface included to some available(!) bridge-devices 82 | ADD_BRIDGE="yes" 83 | BRIDGE_NAME="br-lan" 84 | 85 | FILTER_IPV4_BRIDGE="yes" 86 | 87 | #----- Configuration END 88 | -------------------------------------------------------------------------------- /src/data/usr/share/mesh/mesh.common: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #-------- Common Functiond 4 | BATCTL_FOUND="yes" 5 | V6_GEN_RESULT="" 6 | 7 | check_rc() { 8 | ### First parameter is the RC 9 | ### 2n parameter is a error-message 10 | MSG="" 11 | if [ -n "$2" ] ; then 12 | MSG="Error in $2" 13 | else 14 | MSG="Failed with RC $1" 15 | fi 16 | [ "$1" != "0" ] && echo $MSG && exit 255 17 | } 18 | 19 | 20 | uci_get_details() { 21 | #get mac Adress from uci 22 | SOURCEMAC=$(uci get wireless.$RADIODEVICE.macaddr) 23 | check_rc $? "getting SourceMac" 24 | 25 | if [ $MESH_CHANNEL = "0" ] ; then 26 | MESH_CHANNEL=$( uci get wireless.$RADIODEVICE.channel) 27 | check_rc $? "getting Channel" 28 | else 29 | echo "Taking channel for mesh interface out of the configuration" 30 | fi 31 | 32 | if [ "$IPV4_LOAD" = "yes" ] ; then 33 | IPV4_FIXED=$(uci get network.$OPENWRT_NETWORK.ipaddr) 34 | check_rc $? "getting IPv4 from openwrt config" 35 | fi 36 | } 37 | 38 | generate_v6() { 39 | IF=$1 40 | PREFIX="fd00" 41 | 42 | test -n "$2" && PREFIX=$2 43 | 44 | CURRENT_GEN=`ifconfig $IF | 45 | grep "inet6" | 46 | grep -o -E fe80:\[a-f,0-9:]* | 47 | sed -n "s|fe80::\([^/]*\)|\1|p" ` 48 | 49 | FIXED=$CURRENT_GEN 50 | 51 | echo "Extracted for $IF : $PREFIX::$FIXED " 52 | V6_GEN_RESULT="$PREFIX::$FIXED" 53 | } 54 | 55 | 56 | RANDOM_NUM=0 57 | random_num() { 58 | NUM=$((` "254" ]] && NUM=$(($NUM / 7)) 60 | RANDOM_NUM=$NUM 61 | } 62 | 63 | RANDOM_IP_NUM=0 64 | random_ip_num() { 65 | #Repeat until IP is in range 66 | RANDOM_IP_NUM=0 67 | RANDOM_NUM=0 68 | until [[ "$RANDOM_NUM" -gt "000" ]] && [[ $RANDOM_NUM -lt "255" ]] 69 | do 70 | random_num 71 | [[ 1 == 2 ]] && echo "Result random_num $RANDOM_NUM" 72 | done 73 | RANDOM_IP_NUM=$RANDOM_NUM 74 | 75 | [[ 1 == 2 ]] && echo "result random_ip_num $RANDOM_IP_NUM" 76 | } 77 | 78 | 79 | generate_ipv4() { 80 | # 10.x.y.z 81 | x=0 82 | y=0 83 | z=0 84 | 85 | random_ip_num 86 | x=$RANDOM_IP_NUM 87 | random_ip_num 88 | y=$RANDOM_IP_NUM 89 | random_ip_num 90 | z=$RANDOM_IP_NUM 91 | 92 | IPV4_FIXED="10.$x.$y.$z" 93 | } 94 | 95 | modify_MAC() { 96 | # Modify MAC for 2nd interface if not set 97 | #Change two letters 98 | if [ "$MODMAC" = "" ] ; then 99 | MODMAC=$( echo $SOURCEMAC | sed 's/c/a/' | sed 's/1/2/' ) 100 | check_rc $? "sed :( " 101 | if [ "$MODMAC" = "$SOURCEMAC" ] ; then 102 | MODMAC=$( echo $SOURCEMAC | sed 's/f/e/' | sed 's/2/3/' | sed 's/6/7/') 103 | check_rc $? "2nd sed :( " 104 | fi 105 | echo "Found MAC for $RADIODEVICE : $SOURCEMAC" 106 | echo " modified for 2nd Wifi-if : $MODMAC" 107 | fi 108 | } 109 | 110 | 111 | do_bridge_add(){ 112 | echo "Adding $BAT_IF to bridge $BRIDGE_NAME " 113 | brctl addif "$BRIDGE_NAME" "$BAT_IF" 114 | check_rc $? 115 | 116 | ## If we are working in a bridge, disable ipv6 on that device, too 117 | # Only disable, if IPV6 exists on device 118 | if [ -e "/proc/sys/net/ipv6/conf/$BAT_IF/disable_ipv6" ] ; then 119 | echo "Disabling IPV6 for $BAT_IF - IF without any configuration!" 120 | echo "1" > /proc/sys/net/ipv6/conf/$BAT_IF/disable_ipv6 121 | check_rc $? 122 | fi 123 | 124 | 125 | [ "$FILTER_IPV4_BRIDGE" = "yes" ] && do_bridge_filter 126 | } 127 | 128 | do_bridge_remove() { 129 | echo "Removing $BAT_IF from bridge $BRIDGE_NAME " 130 | brctl delif "$BRIDGE_NAME" "$BAT_IF" 131 | 132 | 133 | [ "$FILTER_IPV4_BRIDGE" = "yes" ] && do_bridge_filter_remove 134 | } 135 | 136 | 137 | do_bridge_filter() { 138 | # Since 3.18 we need to load the module 139 | [ "$OPENWRT" = "no" ] && modprobe br_netfilter 140 | 141 | echo "Add IPv4 filtering on the bridge interface." 142 | echo "1" > /proc/sys/net/bridge/bridge-nf-call-iptables 143 | check_rc $? 144 | iptables -I INPUT -m physdev -i "$BRIDGE_NAME" --physdev-in "$BAT_IF" -j DROP 145 | check_rc $? 146 | iptables -I FORWARD -m physdev -i "$BRIDGE_NAME" --physdev-in "$BAT_IF" -j DROP 147 | check_rc $? 148 | } 149 | 150 | do_bridge_filter_remove() { 151 | echo "Removing IPv4 filter on the bridge interface." 152 | iptables -D INPUT -m physdev -i "$BRIDGE_NAME" --physdev-in "$BAT_IF" -j DROP 153 | iptables -D FORWARD -m physdev -i "$BRIDGE_NAME" --physdev-in "$BAT_IF" -j DROP 154 | } 155 | 156 | do_wlan_if_up() { 157 | echo "Setting up AdHoc Interface for B.A.T.M.A.N. " 158 | iw $IW_DEVICE interface add $MESH_IF type adhoc 159 | check_rc $? 160 | 161 | echo "Setting fixed BSSID up" 162 | iwconfig $MESH_IF ap $CUSTOM_BSSID 163 | check_rc $? 164 | 165 | if [ "$DISABLE_RTS" = "yes" ] ; then 166 | echo "Disabling RTS/CTS " 167 | iwconfig $MESH_IF rts off 168 | check_rc $? 169 | fi 170 | 171 | echo "Increasing MTU for $MESH_IF to $MTU_NEEDED" 172 | ifconfig $MESH_IF mtu $MTU_NEEDED 173 | check_rc $? 174 | 175 | # Only disable, if IPV6 exists on device 176 | if [ -e "/proc/sys/net/ipv6/conf/$MESH_IF/disable_ipv6" ] ; then 177 | echo "Disabling IPV6 for $MESH_IF - IF without any configuration!" 178 | echo "1" > /proc/sys/net/ipv6/conf/$MESH_IF/disable_ipv6 179 | check_rc $? 180 | fi 181 | 182 | if [ "$EXCHANGE_MAC" = "yes" ] ; then 183 | echo "Changing $MESH_IF MAC to $MODMAC" 184 | ifconfig $MESH_IF hw ether $MODMAC 185 | check_rc $? 186 | fi 187 | 188 | echo "Setting up Channel $MESH_CHANNEL" 189 | iwconfig $MESH_IF channel $MESH_CHANNEL 190 | check_rc $? 191 | 192 | echo "Setting SSID for Mesh $MESH_SSID" 193 | iwconfig $MESH_IF essid $MESH_SSID 194 | check_rc $? 195 | } 196 | 197 | 198 | save_gen_ipv4() { 199 | #Save IPv4 Address to tmp-space for later use 200 | echo "$IPV4_FIXED" > $IPV4_IP_SAVE 201 | } 202 | 203 | load_gen_ipv4() { 204 | IPV4_FIXED=$(cat $IPV4_IP_SAVE) 205 | } 206 | 207 | do_batman_up() { 208 | if [ "$BATCTL_FOUND" = "yes" ] ; then 209 | echo "Adding $MESH_IF to B.A.T.M.A.N." 210 | batctl if add $MESH_IF 211 | check_rc $? 212 | else 213 | echo "Adding $MESH_IF to B.A.T.M.A.N. via /sys/class/ " 214 | echo "$BAT_IF" > /sys/class/net/$MESH_IF/batman_adv/mesh_iface 215 | check_rc $? 216 | fi 217 | 218 | dmesg | grep -e B.A.T.M.A.N 219 | 220 | echo "Starting $BAT_IF" 221 | ifconfig $BAT_IF 0.0.0.0 up 222 | check_rc $? 223 | 224 | if [ "$BATCTL_FOUND" = "yes" ] ; then 225 | echo "Setting B.A.T.M.A.N. Intervall to $BAT_INT " 226 | batctl it $BAT_INT 227 | check_rc $? 228 | else 229 | echo "Setting B.A.T.M.A.N. Intervall via /sys/class/ to $BAT_INT " 230 | echo "$BAT_INT" > /sys/class/net/$BAT_IF/mesh/orig_interval 231 | check_rc $? 232 | fi 233 | 234 | if [ "$SET_GENERATED_IPV6" = "yes" ] ; then 235 | echo "Generating IPv6 address for $BAT_IF" 236 | generate_v6 $BAT_IF $IPV6_GEN_PREFIX 237 | check_rc $? 238 | IPV6_FIXED="$V6_GEN_RESULT"/"$IPV6_GEN_NETMASK" 239 | fi 240 | 241 | if [ "$SET_IPV6" = "yes" ] ; then 242 | echo "Setting up ipv6 address ->$IPV6_FIXED<- on $BAT_IF" 243 | ifconfig "$BAT_IF" add $IPV6_FIXED 244 | check_rc $? 245 | fi 246 | 247 | if [ "$IPV4_GENERATE" = "yes" ] ; then 248 | echo "Generating IPv4 10.x.y.z address for $BAT_IF " 249 | generate_ipv4 250 | fi 251 | 252 | #Load if not OpenWRt from dataset 253 | [ "$IPV4_LOAD" = "yes" ] && load_gen_ipv4 254 | 255 | if [ "$SET_IPV4" = "yes" ] ; then 256 | echo "Setting up ipv4 address ->$IPV4_FIXED<- on $BAT_IF" 257 | ifconfig "$BAT_IF" $IPV4_FIXED netmask $IPV4_SUBNET_MASK 258 | check_rc $? 259 | fi 260 | 261 | echo "Setting up GatewayMode to $BAT_GW" 262 | if [ "$BATCTL_FOUND" = "yes" ] ; then 263 | batctl gw $BAT_GW 264 | check_rc $? 265 | else 266 | echo "... using /sys/class to switch to GW mode" 267 | echo "server" > /sys/class/net/"$BAT_IF"/mesh/gw_mode 268 | check_rc $? 269 | fi 270 | 271 | 272 | } 273 | 274 | mesh_start() { 275 | echo "Starting Mesh-IF!" 276 | ifconfig $MESH_IF 0.0.0.0 up 277 | check_rc $? 278 | 279 | # Extract auto IPV6 adress and remove it from mesh if 280 | # AUTO_IPV6=$( ifconfig $MESH_IF | grep "inet6.* " | sed -e "s/^.*inet6 addr: //" -e "s/ Scope.*\$//" ) 281 | # echo "Removing .. $AUTO_IPV6 from $MESH_IF" 282 | # ifconfig $MESH_IF inet6 del $AUTO_IPV6 283 | # check_rc $? "resetting IPv6 on $MESH_IF" 284 | 285 | } 286 | 287 | mesh_stop() { 288 | echo "Stopping Mesh if!" 289 | ifconfig $MESH_IF down 290 | } 291 | 292 | do_wlan_if_down() { 293 | echo "Cleaning up interfaces" 294 | iw dev $MESH_IF del 295 | } 296 | 297 | do_batman_down() { 298 | if [ "$BATCTL_FOUND" = "yes" ] ; then 299 | echo "Remove $MESH_IF from $BAT_IF " 300 | batctl if del $MESH_IF 301 | else 302 | echo "Remove $MESH_IF from $BAT_IF via /sys/class/" 303 | echo none > /sys/class/net/$MESH_IF/batman_adv/mesh_iface 304 | fi 305 | 306 | } 307 | 308 | check_requirements() { 309 | lsmod | grep batman >> /dev/null 310 | if [ "$?" != "0" ] ; then 311 | modprobe batman-adv 312 | check_rc $? "Loading kernel module batman-adv failed.. maybe not installed?" 313 | fi 314 | batctl if > /dev/null 315 | if [ $? != "0" ] ; then 316 | echo "Failed running batctl- maybe not installed? " 317 | echo "Try to use /sys/class/" 318 | BATCTL_FOUND='no' 319 | fi 320 | } 321 | 322 | build_mesh() { 323 | check_requirements 324 | [ "$OPENWRT" = "yes" ] && echo "Starting Mesh Network with uci-collect..." \ 325 | && uci_get_details 326 | # Run Modify_MAC always because severall Variables are shifted internally 327 | modify_MAC 328 | do_wlan_if_up 329 | mesh_start 330 | do_batman_up 331 | [ "$ADD_BRIDGE" = "yes" ] && do_bridge_add 332 | echo "finished" 333 | } 334 | 335 | destroy_mesh() { 336 | check_requirements 337 | echo "Stopping Mesh Network..." 338 | [ "$ADD_BRIDGE" = "yes" ] && do_bridge_remove 339 | mesh_stop 340 | do_batman_down 341 | do_wlan_if_down 342 | echo "finished" 343 | } 344 | 345 | 346 | openwrt_postinst() { 347 | 348 | if [ "$SET_IPV4" = "yes" ] ; then 349 | echo "Generating IPv4 ..." 350 | generate_ipv4 351 | save_gen_ipv4 352 | echo "Generated $IPV4_FIXED for this box!" 353 | 354 | echo "Backuping /etc/config/network" 355 | cp -v /etc/config/network /etc/config/network_pre_mesh.backup 356 | echo "Backuping /etc/config/firewall" 357 | cp -v /etc/config/firewall /etc/config/firewall_pre_mesh.backup 358 | 359 | echo "Do interface $OPENWRT_NETWORK setup on /etc/config/network" 360 | uci set network.$OPENWRT_NETWORK=interface 361 | uci set network.$OPENWRT_NETWORK.ipaddr=$IPV4_FIXED 362 | uci set network.$OPENWRT_NETWORK.netmask=$IPV4_SUBNET_MASK 363 | uci set network.$OPENWRT_NETWORK.proto=static 364 | uci set network.$OPENWRT_NETWORK.ifname=$BAT_IF 365 | uci commit 366 | 367 | echo "Do firewall configuration /etc/config/firewall" 368 | 369 | #Enable Forward on lan zone. Lan zone is always the first 370 | # in MR3020 371 | echo " ... enabling forward on lan" 372 | uci set firewall.@zone[0].forward=ACCEPT 373 | 374 | echo " ... inserting new zone $OPENWRT_NETWORK" 375 | uci add firewall zone 376 | uci set firewall.@zone[-1].name=$OPENWRT_NETWORK 377 | uci set firewall.@zone[-1].masq=1 378 | uci set firewall.@zone[-1].mtu_fix=1 379 | uci set firewall.@zone[-1].input=ACCEPT 380 | uci set firewall.@zone[-1].output=ACCEPT 381 | uci set firewall.@zone[-1].forward=REJECT 382 | 383 | echo " ... adding new forward-rule" 384 | uci add firewall forwarding 385 | uci set firewall.@forwarding[-1].src=lan 386 | uci set firewall.@forwarding[-1].dest=$OPENWRT_NETWORK 387 | 388 | uci commit 389 | 390 | echo "Reloading Firewall" 391 | /etc/init.d/firewall reload 392 | 393 | fi 394 | 395 | } 396 | 397 | openwrt_preremove() { 398 | if [ -f /etc/config/network_pre_mesh.backup ] ; then 399 | echo "Saving current state of config/network" 400 | mv /etc/config/network /etc/config/network_after_mesh.backup 401 | echo "Restoring config/network" 402 | mv /etc/config/network_pre_mesh.backup /etc/config/network 403 | fi 404 | 405 | if [ -f /etc/config/firewall_pre_mesh.backup ] ; then 406 | echo "Saving current state of config/firewall" 407 | mv /etc/config/firewall /etc/config/firewall_after_mesh.backup 408 | echo "Restoring config/firewall" 409 | mv /etc/config/firewall_pre_mesh.backup /etc/config/firewall 410 | fi 411 | } 412 | 413 | ## mesh.common END 414 | -------------------------------------------------------------------------------- /src/debian-binary: -------------------------------------------------------------------------------- 1 | 2.0 2 | --------------------------------------------------------------------------------