View Single Post
Posts: 1,425 | Thanked: 983 times | Joined on May 2010 @ Hong Kong
#1
1 Background

The advantage of using this script to build WiFi Hotspot over the packages mobilehotspot and joikuspot is that it's simple and consume less power. The original script is written by jebba, modified slightly by me for easy customization, DNS and process initialization; therefore credit still goes to him.

The reason I post this script is for those who are having technical problems with mobilehotspot or joikuspot, and for those who'd want to run a WiFi hotspot with minimum power usage.

2 Installation

The script is pretty self explanatory therefore I'll let you explore it yourself.

It can be run as root or triggered by Queen Beecon Widget. Tell me if you need help on this.

The SSID is honeypot and the password is 0000000000000. You can customize them for your own use. Note that the length of the password must be 13.

It needs packages wireless-tools and iptables, and iptables depends on kernel power. Therefore, you must be well-aware of the risk running kernel power so use it at your own risk.

Code:
#!/bin/sh
# Original script by Jebba, modified by 9000 @ talk.maemo.org
# Run this script to share your Internet connection.
# Activate your gprs0 (fone data) connection with the GUI

#run-standalone.sh dbus-send --system --type=method_call --dest=com.nokia.icd_ui /com/nokia/icd_ui com.nokia.icd_ui.show_conn_dlg boolean:false

IP_ADDR="192.168.1.1"
NETMASK="255.255.255.0"
DHCP_RANGE="192.168.1.100,192.168.1.127"
RUNFILE="/var/run/wifi_tethering.pid"
DNSMASQ="/usr/sbin/dnsmasq"
ESSID="honeypot"
PASSWORD="0000000000000"
CHANNEL="10"
HOSTIDEV="gprs0"

set -x

start wlancond

# Load modules
modprobe crc7
modprobe mac80211
modprobe wl12xx
modprobe ipt_MASQUERADE

# flush old rules
iptables -F
iptables -t nat -F

iptables -t nat -A POSTROUTING -o $HOSTIDEV -j MASQUERADE

# forward IPs
echo 1 > /proc/sys/net/ipv4/ip_forward

ifconfig wlan0 down
iwconfig wlan0 mode ad-hoc
ifconfig wlan0 up
iwconfig wlan0 essid $ESSID
iwconfig wlan0 key s:$PASSWORD
iwconfig wlan0 channel $CHANNEL
ifconfig wlan0 $IP_ADDR netmask $NETMASK up

# Setup DNS and DHCP
start-stop-daemon -S -p $RUNFILE -m -b -x $DNSMASQ -- -k -I lo -z -a $IP_ADDR -F $DHCP_RANGE -b

run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'WiFi HotSpot Activated'
3 How to turn it off

You can turn it off by using any WiFi switching applet/widget, or you could use this script (again, run as root):
Code:
#!/bin/sh
# Description: Turn WiFi on/off
# Original script from http://wiki.maemo.org/Desktop_Command_Execution_Widget_scripts
# Modified by 9000 @ talk.maemo.org on 27/6/2010
#
out=`ifconfig wlan0`
if [ $? -eq "0" ] ; then
if [ `echo "$out" | grep -c RUNNING` -gt "0" ] ; then
run-standalone.sh dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
fi
ifconfig wlan0 down
rmmod wl12xx
rmmod mac80211
rmmod crc7
stop wlancond
run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'Wi-Fi Disabled'
exit 2
else
modprobe crc7
modprobe mac80211
modprobe wl12xx
wl1251-cal
stop wlancond
start wlancond
iwconfig wlan0 mode managed
ifconfig wlan0 up
run-standalone.sh dbus-send --system --type=method_call --dest=com.nokia.icd_ui /com/nokia/icd_ui com.nokia.icd_ui.show_conn_dlg boolean:false
run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'Wi-Fi Enabled'
exit 0
fi
To further save the power, this script will unload unnecessary modules when WiFi is switched off. Those unloaded modules will be reloaded again when the script is run again (switching on and off).

4. Troubleshooting

4.1 Q: Password rejected.
A: The length of the password must be 13.

4.2 Q:Tell me how to setup Queen Beecon Widget
A:
1) Add new Widget
2) Choose Queen BeeCon Widget
3) Edit the Widget you've created on your desktop
4) Add Cmd
5) Enter Title: WiFi HotSpot
6) Enter Command: echo <path_to_script>/<name of the script> | root
e.g. if the path to the script is /home/user/script/ and the name of the script is open_wifi_hotspot.sh, then the line would be:
echo /home/user/script/open_wifi_hotspot.sh | root
(you need rootsh installed, but I'm sure you do)
7) Save
8) If you don't need to change the outlook of your QBW icon, you can just accept all the default and save.
9) Done

Similarly for wifi.sh:
echo /home/user/script/wifi.sh | root
wifi.sh uses exit code (2 and 0) to tell you the status of the wifi. Therefore, you'd like to config different color for different exit code. I use the following:
0 - Green, WiFi is enabled
2 - Red, WiFi is disabled

Or you could just use the default. The script would give you popup message anyway.

4.3 The module ipt_MASQUERADE isn't loaded after upgrading to kernel-power v47

The module works fine in v46. Downgrade your kernel-power. (at your own risk)

(Please reply here if you've any question. Then I'll update this section.)

EDIT: wireless-tools provides iwconfig. Revised.
EDIT: Report has it that ipt_MASQUERADE isn't loaded in kernel-power v47. Troubleshooting updated.
Attached Files
File Type: tar wifi_hotspot.tar (5.0 KB, 853 views)

Last edited by 9000; 2011-06-27 at 14:51.
 

The Following 39 Users Say Thank You to 9000 For This Useful Post: