Просмотр исходного кода

Bridging the mesh to a wifi hotspot

Bob Mottram 8 лет назад
Родитель
Сommit
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,6 +30,35 @@
30 30
 
31 31
 PROJECT_NAME='freedombone'
32 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 63
 if [[ $1 == "start" ]]; then
35 64
     # install avahi
@@ -68,33 +97,22 @@ TAHOELAFS_PORT=50213
68 97
 
69 98
 # Ethernet bridge definition (bridged to bat0)
70 99
 BRIDGE=br-mesh
71
-IFACE='wlan0'
100
+BRIDGE_HOTSPOT=br-hotspot
101
+IFACE=
102
+IFACE_SECONDARY=
72 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 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 116
 fi
99 117
 
100 118
 if [ -e /etc/default/batctl ]; then
@@ -126,6 +144,11 @@ function stop {
126 144
         brctl delbr $BRIDGE
127 145
         ifconfig $EIFACE down -promisc
128 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 153
     avahi-autoipd -k $BRIDGE
131 154
     avahi-autoipd -k $IFACE
@@ -220,7 +243,6 @@ function start {
220 243
     modprobe batman-adv
221 244
     batctl if add $IFACE
222 245
     ifconfig $IFACE up
223
-    avahi-autoipd --force-bind --daemonize --wait $BRIDGE
224 246
     avahi-autoipd --force-bind --daemonize --wait $IFACE
225 247
     ifconfig bat0 up promisc
226 248
 
@@ -242,6 +264,46 @@ function start {
242 264
         ifconfig $EIFACE 0.0.0.0
243 265
         ifconfig $EIFACE up promisc
244 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 307
     fi
246 308
 
247 309
     iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT

+ 0
- 12
src/freedombone-utils-wifi Просмотреть файл

@@ -39,18 +39,6 @@ WIFI_NETWORKS_FILE=~/${PROJECT_NAME}-wifi.cfg
39 39
 # repo for atheros AR9271 wifi driver
40 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 42
 function setup_wifi {
55 43
     if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
56 44
         return

+ 1
- 1
src/freedombone-wifi Просмотреть файл

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