Reply
Thread Tools
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, 851 views)

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

The Following 39 Users Say Thank You to 9000 For This Useful Post:
Posts: 539 | Thanked: 518 times | Joined on May 2010 @ nanaurbusiness
#2
I could need some help here. My Laptop is only getting a private IP so DHCP doesn't seem to work properly.
Here's my output.
Code:
IroN900:/usr/bin# wlapon 
+ start wlancond
start: Job not changed: wlancond
+ modprobe crc7
+ modprobe mac80211
+ modprobe wl12xx
+ modprobe ipt_MASQUERADE
+ iptables -F
+ iptables -t nat -F
+ iptables -t nat -A POSTROUTING -o gprs0 -j MASQUERADE
+ echo 1
+ ifconfig wlan0 down
+ iwconfig wlan0 mode ad-hoc
+ ifconfig wlan0 up
+ iwconfig wlan0 essid TKX
+ iwconfig wlan0 key s:00000
+ iwconfig wlan0 channel 11
+ ifconfig wlan0 10.161.3.1 netmask 255.255.255.0 up
+ start-stop-daemon -S -p /var/run/wifi_tethering.pid -m -b -x /usr/sbin/dnsmasq -- -k -I lo -z -a 10.161.3.1 -F 10.161.3.2,10.161.3.10 -b
/usr/sbin/dnsmasq already running.
+ run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:WiFi HotSpot Activated
Edit: I tried also to give static addresses (IP, Gateway and DNS) but I can't even ping my N900 from the Laptop.

Greetz,

J4ZZ

Last edited by J4ZZ; 2011-05-26 at 11:45.
 
Posts: 43 | Thanked: 18 times | Joined on Jul 2010
#3
Thanks, I just have a question:

If I would only want to connect to my N900 with wifi but without using it as a hot-spot (so, without gprs0), I guess I would just need to take out these lines:

HOSTIDEV="gprs0"
modprobe ipt_MASQUERADE
iptables -t nat -A POSTROUTING -o $HOSTIDEV -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

would I need to keep:
iptables -t nat -F

I would say that I don't need iptables at all, is that right?

i.

Last edited by ivanrajkovic; 2011-05-26 at 11:43.
 
Posts: 1,048 | Thanked: 1,127 times | Joined on Jan 2010 @ Amsterdam
#4
Bows in gratitude _O_
 
blipnl's Avatar
Posts: 279 | Thanked: 231 times | Joined on Apr 2010 @ Holland
#5
So this script is executable via QBW? I sure hope this works, seems complicated though!

I hope I don't ask too much of you, but since i am no expert of QBW could you please import the script to a QBW-instance and upload it to post #1? (export buffer to file) That would be just great
__________________
Is that a N900 in your pants or are you just happy to see me?
 
Posts: 1,425 | Thanked: 983 times | Joined on May 2010 @ Hong Kong
#6
Originally Posted by J4ZZ View Post
I could need some help here. My Laptop is only getting a private IP so DHCP doesn't seem to work properly.
Here's my output.
Code:
IroN900:/usr/bin# wlapon 
+ start wlancond
start: Job not changed: wlancond
+ modprobe crc7
+ modprobe mac80211
+ modprobe wl12xx
+ modprobe ipt_MASQUERADE
+ iptables -F
+ iptables -t nat -F
+ iptables -t nat -A POSTROUTING -o gprs0 -j MASQUERADE
+ echo 1
+ ifconfig wlan0 down
+ iwconfig wlan0 mode ad-hoc
+ ifconfig wlan0 up
+ iwconfig wlan0 essid TKX
+ iwconfig wlan0 key s:00000
+ iwconfig wlan0 channel 11
+ ifconfig wlan0 10.161.3.1 netmask 255.255.255.0 up
+ start-stop-daemon -S -p /var/run/wifi_tethering.pid -m -b -x /usr/sbin/dnsmasq -- -k -I lo -z -a 10.161.3.1 -F 10.161.3.2,10.161.3.10 -b
/usr/sbin/dnsmasq already running.
+ run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:WiFi HotSpot Activated
Edit: I tried also to give static addresses (IP, Gateway and DNS) but I can't even ping my N900 from the Laptop.

Greetz,

J4ZZ
I spot you've made change to the followings:

1) The password. Note that that the length of password must be exactly 13 words.
2) You've made change to the network and the DHCP network, that would cause routing problem as the routing on your own private networking may not be able to route the wifi traffic when you get them all into the same network, unless you tells the routing table how to diffentiate different traffic. That's why you got connection problem.

Unless you're very familiar with TCP/IP routing, I'd suggest you stick to the original settings first. Make the change by trial and error later after you've successfully got the initial connection work.

Last edited by 9000; 2011-05-27 at 02:17.
 
Posts: 1,425 | Thanked: 983 times | Joined on May 2010 @ Hong Kong
#7
Originally Posted by ivanrajkovic View Post
Thanks, I just have a question:

If I would only want to connect to my N900 with wifi but without using it as a hot-spot (so, without gprs0), I guess I would just need to take out these lines:

HOSTIDEV="gprs0"
modprobe ipt_MASQUERADE
iptables -t nat -A POSTROUTING -o $HOSTIDEV -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

would I need to keep:
iptables -t nat -F

I would say that I don't need iptables at all, is that right?

i.
Yes, you could just leave the iptables alone if you just want to connect to N900 without a tethering need.

And you don't need that modprobe ipt_MASQUERADE as well.

However, one thing you must note that if you're using Windows PC to connect to any WiFi, it always tries to make it as the default route, i.e. all internet traffice request would go to WiFi. Unless you made change to this default behaviour, you might not be able to go to internet via your private network of your PC when you're connecting to WiFi.

Last edited by 9000; 2011-05-27 at 02:27.
 

The Following User Says Thank You to 9000 For This Useful Post:
Posts: 1,425 | Thanked: 983 times | Joined on May 2010 @ Hong Kong
#8
Originally Posted by blipnl View Post
So this script is executable via QBW? I sure hope this works, seems complicated though!

I hope I don't ask too much of you, but since i am no expert of QBW could you please import the script to a QBW-instance and upload it to post #1? (export buffer to file) That would be just great
Actually I've already deleted the QBW that run open_wifi_hotspot.sh as I'm using Bluetooth-PAN tethering now, for better security (small proximity) and much lower power consumption. (you may refer to my sig for details).

However, setting up QBW for this script is very simple:

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

Hope this helps.

Last edited by 9000; 2011-05-27 at 01:59.
 

The Following User Says Thank You to 9000 For This Useful Post:
Posts: 539 | Thanked: 518 times | Joined on May 2010 @ nanaurbusiness
#9
Thanks for replying, I got it working now.
Now I have another request, is there a way to just start and stop Hotspot with a script and keep WiFi running. What I want is to have a QBW Button to just toggle Hotspot on/off if needed, but keep my WiFi or GPRS connection running afterwards.

Thx in advance,

Greetz,

J4ZZ
 
Posts: 1,425 | Thanked: 983 times | Joined on May 2010 @ Hong Kong
#10
Originally Posted by J4ZZ View Post
Thanks for replying, I got it working now.
Now I have another request, is there a way to just start and stop Hotspot with a script and keep WiFi running. What I want is to have a QBW Button to just toggle Hotspot on/off if needed, but keep my WiFi or GPRS connection running afterwards.

Thx in advance,

Greetz,

J4ZZ
What you want to do is changing WiFi from ad hoc mode (hotspot) to managed mode. The second script wifi.sh does that, only you would need to trigger it twice to turn it off and than back on.

Or you may just run that particular line that changes the wifi back to managed.
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 14:47.