浏览代码

Bridging the mesh to a wifi hotspot

Bob Mottram 8 年前
父节点
当前提交
e635453d98
共有 3 个文件被更改,包括 88 次插入38 次删除
  1. 87
    25
      src/freedombone-mesh-batman
  2. 0
    12
      src/freedombone-utils-wifi
  3. 1
    1
      src/freedombone-wifi

+ 87
- 25
src/freedombone-mesh-batman 查看文件

30
 
30
 
31
 PROJECT_NAME='freedombone'
31
 PROJECT_NAME='freedombone'
32
 COMPLETION_FILE=/root/${PROJECT_NAME}-completed.txt
32
 COMPLETION_FILE=/root/${PROJECT_NAME}-completed.txt
33
+HOTSPOT_PASSPHRASE='mesh'
34
+
35
+function count_wlan {
36
+    # counts the number of wlan devices
37
+    ctr=0
38
+
39
+    for i in $(seq 0 -1 10); do
40
+        if grep -q "wlan${i}" /proc/net/dev; then
41
+            ctr=$((ctr + 1))
42
+        fi
43
+    done
44
+    echo $ctr
45
+}
46
+
47
+function update_wifi_adaptors {
48
+    IFACE=
49
+    IFACE_SECONDARY=
50
+
51
+    for i in $(seq 10 -1 0); do
52
+        if grep -q "wlan${i}" /proc/net/dev; then
53
+            if [ ! $IFACE ]; then
54
+                IFACE="wlan${i}"
55
+            else
56
+                IFACE_SECONDARY="wlan${i}"
57
+                return
58
+            fi
59
+        fi
60
+    done
61
+}
33
 
62
 
34
 if [[ $1 == "start" ]]; then
63
 if [[ $1 == "start" ]]; then
35
     # install avahi
64
     # install avahi
68
 
97
 
69
 # Ethernet bridge definition (bridged to bat0)
98
 # Ethernet bridge definition (bridged to bat0)
70
 BRIDGE=br-mesh
99
 BRIDGE=br-mesh
71
-IFACE='wlan0'
100
+BRIDGE_HOTSPOT=br-hotspot
101
+IFACE=
102
+IFACE_SECONDARY=
72
 EIFACE=eth0
103
 EIFACE=eth0
104
+WLAN_ADAPTORS=$(count_wlan)
73
 
105
 
74
-if [[ $IFACE == "wlan0" ]]; then
75
-    if grep -q "wlan5" /proc/net/dev; then
76
-        IFACE=wlan5
77
-    fi
78
-fi
79
-if [[ $IFACE == "wlan0" ]]; then
80
-    if grep -q "wlan4" /proc/net/dev; then
81
-        IFACE=wlan4
82
-    fi
106
+if [ $WLAN_ADAPTORS -eq 0 ]; then
107
+    echo $'No wlan adaptors found'
108
+    exit 0
83
 fi
109
 fi
84
-if [[ $IFACE == "wlan0" ]]; then
85
-    if grep -q "wlan3" /proc/net/dev; then
86
-        IFACE=wlan3
87
-    fi
88
-fi
89
-if [[ $IFACE == "wlan0" ]]; then
90
-    if grep -q "wlan2" /proc/net/dev; then
91
-        IFACE=wlan2
92
-    fi
93
-fi
94
-if [[ $IFACE == "wlan0" ]]; then
95
-    if grep -q "wlan1" /proc/net/dev; then
96
-        IFACE=wlan1
97
-    fi
110
+
111
+update_wifi_adaptors
112
+
113
+if [ ! $IFACE ]; then
114
+    echo $'No wlan adaptor'
115
+    exit 0
98
 fi
116
 fi
99
 
117
 
100
 if [ -e /etc/default/batctl ]; then
118
 if [ -e /etc/default/batctl ]; then
126
         brctl delbr $BRIDGE
144
         brctl delbr $BRIDGE
127
         ifconfig $EIFACE down -promisc
145
         ifconfig $EIFACE down -promisc
128
     fi
146
     fi
147
+    if [ $IFACE_SECONDARY ]; then
148
+        brctl delif $BRIDGE_HOTSPOT bat0
149
+        ifconfig $BRIDGE_HOTSPOT down || true
150
+        brctl delbr $BRIDGE_HOTSPOT
151
+    fi
129
 
152
 
130
     avahi-autoipd -k $BRIDGE
153
     avahi-autoipd -k $BRIDGE
131
     avahi-autoipd -k $IFACE
154
     avahi-autoipd -k $IFACE
220
     modprobe batman-adv
243
     modprobe batman-adv
221
     batctl if add $IFACE
244
     batctl if add $IFACE
222
     ifconfig $IFACE up
245
     ifconfig $IFACE up
223
-    avahi-autoipd --force-bind --daemonize --wait $BRIDGE
224
     avahi-autoipd --force-bind --daemonize --wait $IFACE
246
     avahi-autoipd --force-bind --daemonize --wait $IFACE
225
     ifconfig bat0 up promisc
247
     ifconfig bat0 up promisc
226
 
248
 
242
         ifconfig $EIFACE 0.0.0.0
264
         ifconfig $EIFACE 0.0.0.0
243
         ifconfig $EIFACE up promisc
265
         ifconfig $EIFACE up promisc
244
         ifconfig $BRIDGE up
266
         ifconfig $BRIDGE up
267
+        avahi-autoipd --force-bind --daemonize --wait $BRIDGE
268
+    fi
269
+
270
+    if [ $IFACE_SECONDARY ]; then
271
+        if [[ $IFACE != $IFACE_SECONDARY ]]; then
272
+            if [ -d /etc/hostapd ]; then
273
+                # bridge between mesh and wifi hotspot for mobile
274
+                HOTSPOT_NAME=$"${WIFI_SSID}-hotspot"
275
+                ifconfig $IFACE_SECONDARY down
276
+                iwconfig $IFACE_SECONDARY mode managed essid $HOTSPOT_NAME channel ${CHANNEL}
277
+                iwconfig $IFACE_SECONDARY ap $CELLID
278
+
279
+                brctl addbr $BRIDGE_HOTSPOT
280
+                brctl addif $BRIDGE_HOTSPOT bat0
281
+                brctl addif $BRIDGE_HOTSPOT $IFACE_SECONDARY
282
+                ifconfig bat0 0.0.0.0
283
+                ifconfig $IFACE_SECONDARY 0.0.0.0
284
+
285
+                sed -i 's|#DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
286
+
287
+                echo "interface=$IFACE_SECONDARY" > /etc/hostapd/hostapd.conf
288
+                echo "bridge=${BRIDGE_HOTSPOT}" >> /etc/hostapd/hostapd.conf
289
+                echo 'driver=nl80211' >> /etc/hostapd/hostapd.conf
290
+                echo "country_code=UK" >> /etc/hostapd/hostapd.conf
291
+                echo "ssid=$HOTSPOT_NAME" >> /etc/hostapd/hostapd.conf
292
+                echo 'hw_mode=g' >> /etc/hostapd/hostapd.conf
293
+                echo "channel=${CHANNEL}" >> /etc/hostapd/hostapd.conf
294
+                echo 'wpa=2' >> /etc/hostapd/hostapd.conf
295
+                echo "wpa_passphrase=$HOTSPOT_PASSPHRASE" >> /etc/hostapd/hostapd.conf
296
+                echo 'wpa_key_mgmt=WPA-PSK' >> /etc/hostapd/hostapd.conf
297
+                echo 'wpa_pairwise=TKIP' >> /etc/hostapd/hostapd.conf
298
+                echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
299
+                echo 'auth_algs=1' >> /etc/hostapd/hostapd.conf
300
+                echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf
301
+
302
+                ifconfig $IFACE_SECONDARY up promisc
303
+                ifconfig $BRIDGE_HOTSPOT up
304
+                avahi-autoipd --force-bind --daemonize --wait $BRIDGE_HOTSPOT
305
+            fi
306
+        fi
245
     fi
307
     fi
246
 
308
 
247
     iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
309
     iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT

+ 0
- 12
src/freedombone-utils-wifi 查看文件

39
 # repo for atheros AR9271 wifi driver
39
 # repo for atheros AR9271 wifi driver
40
 ATHEROS_WIFI_REPO="https://github.com/qca/open-ath9k-htc-firmware.git"
40
 ATHEROS_WIFI_REPO="https://github.com/qca/open-ath9k-htc-firmware.git"
41
 
41
 
42
-function count_wlan {
43
-    # counts the number of wlan devices
44
-    ctr=0
45
-
46
-    for i in $(seq 0 10); do
47
-        if grep -q "wlan${i}" /proc/net/dev; then
48
-            ctr=$((ctr + 1))
49
-        fi
50
-    done
51
-    echo $ctr
52
-}
53
-
54
 function setup_wifi {
42
 function setup_wifi {
55
     if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
43
     if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
56
         return
44
         return

+ 1
- 1
src/freedombone-wifi 查看文件

110
     echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
110
     echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
111
     echo '' >> /etc/hostapd/hostapd.conf
111
     echo '' >> /etc/hostapd/hostapd.conf
112
     echo '## Shared Key Authentication ##'
112
     echo '## Shared Key Authentication ##'
113
-    echo 'auth_algs=1'
113
+    echo 'auth_algs=1' >> /etc/hostapd/hostapd.conf
114
     echo '' >> /etc/hostapd/hostapd.conf
114
     echo '' >> /etc/hostapd/hostapd.conf
115
     echo '## Accept all MAC address ###' >> /etc/hostapd/hostapd.conf
115
     echo '## Accept all MAC address ###' >> /etc/hostapd/hostapd.conf
116
     echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf
116
     echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf