owlps/owlps-ardrone/script-drone/1.3.3/bin/wifi_setup.sh

111 lines
2.7 KiB
Bash
Executable File

#!/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 WORKAREA=/
#export ATH_PLATFORM=ardrone
#/usr/sbin/recEvent /data/athdbg.log&
if [ -s /factory/mac_address.txt ]
then
MAC_ADDR=`cat /factory/mac_address.txt`
else
MAC_ADDR=`cat /data/random_mac.txt`
fi
loadAR6k.sh --setmac $MAC_ADDR
#loadtestcmd.sh
# Waiting 2s for the wifi chip to be ready
sleep 2
# Increasing scan time to help detecting wifi networks
wmiconfig -i ath0 --scan --maxact=80
# Setting retry limits to 6
wmiconfig -i ath0 --setretrylimits 2 0 6 off
# Limiting available rates to 11, 24 or 54 Mb/s
wmiconfig -i ath0 --setfixrates 3 8 11
# Disabling powersaving
wmiconfig -i ath0 --power maxperf
SSID=`grep ssid_single_player /data/config.ini | awk -F "=" '{print $2}'`
if [ $SSID ]
then
echo "SSID=$SSID"
else
#default SSID.
SSID=ardrone_wifi
echo "SSID=$SSID"
fi
export NETIF=ath0
RANDOM_CHAN=`/bin/channelselector`
echo "Creating/Joining Network $SSID"
#iwconfig ath0 mode ad-hoc
#iwconfig ath0 channel $RANDOM_CHAN
#iwconfig ath0 essid $SSID
#iwconfig ath0 channel 1
iwconfig ath0 mode ad-hoc essid owl channel auto
OK=0
BASE_ADRESS=192.168.1.
PROBE=1
while [ $OK -eq 0 ]
do
#configuring interface.
ifconfig ath0 $BASE_ADRESS$PROBE
ifconfig ath0:0 192.168.11.1
arping -I ath0 -q -f -D -w 2 $BASE_ADRESS$PROBE
if [ $? -eq 1 ]
then
#generating random odd IP address
PROBE=`/bin/random_ip`
else
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 ath0" >> /tmp/udhcpd.conf
echo "decline_time 1" >> /tmp/udhcpd.conf
echo "conflict_time 1" >> /tmp/udhcpd.conf
echo "opt subnet 255.255.255.0" >> /tmp/udhcpd.conf
echo "opt router $BASE_ADRESS$PROBE" >> /tmp/udhcpd.conf
echo "opt lease 1200" >> /tmp/udhcpd.conf
/bin/pairing_setup.sh
# Saving random info for initialization at next reboot
date > /dev/urandom
/bin/random_mac > /data/random_mac.txt
iwconfig ath0 rate 54M
iwconfig ath0 rate auto
telnetd -l /bin/sh
udhcpd /tmp/udhcpd.conf
iptables -t nat -A POSTROUTING -p UDP --sport 8884 -j SNAT --to 192.168.1.254:5554
iptables -t nat -A PREROUTING -p UDP -d 192.168.1.254 --dport 5554 -j DNAT --to 192.168.1.1:8884
iptables -t nat -A POSTROUTING -p UDP --sport 8886 -j SNAT --to 192.168.1.254:5556
iptables -t nat -A PREROUTING -p UDP -d 192.168.1.254 --dport 5556 -j DNAT --to 192.168.1.1:8886