-
Notifications
You must be signed in to change notification settings - Fork 4
/
wifi_setup.sh
166 lines (126 loc) · 3.35 KB
/
wifi_setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/sh
#
# Script to see if an IP adress is already used or not
#
# Getting SSID from config.ini file.
#initializing random generator
cat /data/random_mac.txt > /dev/urandom
/bin/random_mac > /data/random_mac.txt
#echo 2 > /proc/cpu/alignment
export NETIF=ath0
export WORKAREA="/lib/firmware"
export ATH_PLATFORM="parrot-omap-sdio"
export ATH_MODULE_ARGS="ifname=$NETIF"
# Switch Wifi mode depending on value into /data/config.ini
#
WIFI_MODE=`grep wifi_mode /data/config.ini | awk -F "=" '{ gsub(/ */,"",$2); pr
int $2}'`
case $WIFI_MODE in
0)
WIFI_MODE=master
;;
1)
WIFI_MODE=ad-hoc
;;
2)
WIFI_MODE=managed
;;
*)
WIFI_MODE=master
;;
esac
if [ -s /factory/mac_address.txt ]
then
MAC_ADDR=`cat /factory/mac_address.txt`
else
MAC_ADDR=`cat /data/random_mac.txt`
fi
loadAR6000.sh -i $NETIF --setmac $MAC_ADDR
# Waiting 2s for the wifi chip to be ready
sleep 2
AR6K_PID=`ps_procps -A -T -c | grep AR6K | awk '{print $1}'`
SDIO_PID=`ps_procps -A -T -c | grep ksdioirqd | awk '{print $1}'`
#Changing wifi priority
chrt -p -r 25 $SDIO_PID
chrt -p -r 24 $AR6K_PID
# Disabling powersaving
wmiconfig -i $NETIF --power maxperf
# Disabling 802.11n aggregation
wmiconfig -i $NETIF --allow_aggr 0 0
# enabling WMM
wmiconfig -i $NETIF --setwmm 1
i=0
while [ ! -n "$SSID" ] && [ $i -lt 10 ]
do
i=`expr $i + 1`
SSID=`grep ssid_single_player /data/config.ini | awk -F "=" '{print $2}'`
# Removing leading and trailing spaces
SSID=`echo $SSID`
sleep 1
done
if [ -n "$SSID" ]
then
echo "SSID=$SSID"
else
#default SSID.
SSID=ardrone2_wifi
echo "SSID=\"$SSID\""
fi
RANDOM_CHAN=auto
echo "Creating $WIFI_MODE Network $SSID"
iwconfig $NETIF mode $WIFI_MODE
iwconfig $NETIF essid "$SSID"
if [ "$WIFI_MODE" != "managed" ]
then
# Allowing ACS to select only channels 1 & 6
wmiconfig -i $NETIF --acsdisablehichannels 1
iwconfig $NETIF channel $RANDOM_CHAN
iwconfig $NETIF rate auto
iwconfig $NETIF commit
fi
wmiconfig -i $NETIF --dtim 1
wmiconfig -i $NETIF --commit
OK=0
BASE_ADRESS=192.168.1.
PROBE=1
while [ $OK -eq 0 ]
do
#configuring interface.
ifconfig $NETIF $BASE_ADRESS$PROBE
arping -I $NETIF -q -f -D -w 2 $BASE_ADRESS$PROBE
if [ $? -eq 1 ]
then
if [ -s /data/old_adress.txt ]
then
# Testing previously given adress.
PROBE=`cat /data/old_adress.txt`
else
#generating random odd IP address
PROBE=`/bin/random_ip`
fi
/bin/random_ip > /data/old_adress.txt
else
echo $PROBE > /data/old_adress.txt
OK=1
fi
done
#Configuring DHCP server.
echo "Using address $BASE_ADRESS$PROBE"
echo "start $BASE_ADRESS`expr $PROBE + 1`" > /tmp/udhcpd.conf
echo "end $BASE_ADRESS`expr $PROBE + 4`" >> /tmp/udhcpd.conf
echo "interface $NETIF" >> /tmp/udhcpd.conf
echo "decline_time 1" >> /tmp/udhcpd.conf
echo "conflict_time 1" >> /tmp/udhcpd.conf
echo "opt router $BASE_ADRESS$PROBE" >> /tmp/udhcpd.conf
echo "opt subnet 255.255.255.0" >> /tmp/udhcpd.conf
echo "opt lease 1200" >> /tmp/udhcpd.conf
/bin/pairing_setup.sh
# Saving random info for initialization at next reboot
echo $MAC_ADDR `date` `/bin/random_mac` > /dev/urandom
/bin/random_mac > /data/random_mac.txt
telnetd -l /bin/sh
udhcpd /tmp/udhcpd.conf
# Adding route for multicast-packet
route add -net 224.0.0.0 netmask 240.0.0.0 dev $NETIF
# Starting the daemon which responds to the AUTH messages from FreeFlight
/bin/parrotauthdaemon