I sell on Tindie

Saturday, December 6, 2014

Beaglebone black as 3G router or wireless access point with 3G connection

Here are things that I found at my storage.
- Beaglebone black
- HUAWEI E220 3G modem
- D-Link DWA-140 wireless N USB stick
- USB hub

Lets make a 3G Wireless AP from this.
All drivers should be enabled in kernel as modules and all devices should be recognized. I tested it with kernel 3.15

1. Get device id with lsusb

Bus 002 Device 003: ID 2001:3c15 D-Link Corp. DWA-140 RangeBooster N Adapter(rev.B3) [Ralink RT5372]
Bus 002 Device 005: ID 12d1:1003 Huawei Technologies Co., Ltd. E220 HSDPA Modem / E230/E270/E870 HSDPA/HSUPA Modem
Bus 002 Device 002: ID 05e3:0605 Genesys Logic, Inc. USB 2.0 Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

2. Install ppp

sudo apt-get install ppp

3. Install umtskeeper

wget http://zool33.uni-graz.at/petz/umtskeeper/src/umtskeeper.tar.gz 
sudo tar -xzvf umtskeeper.tar.gz
sudo chmod +x umtskeeper

4. Get sakis3g

sudo wget "http://downloads.sourceforge.net/project/vim-n4n0/sakis3g.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fvim-n4n0%2Ffiles%2F&ts=1363537696&use_mirror=tene~t" -O sakis3g.tar.gz
sudo tar -xzvf sakis3g.tar.gz
sudo chmod +x sakis3g

5. Try to connect with sakis3g

./sakis3g --interactive

After some scripts running you should be connected. You should know user and password for your operator.
You can test the connection with

ping -c 4 www.google.com

Now try to run the script from command line

./umtskeeper --sakisoperators "USBINTERFACE='0' OTHER='USBMODEM' USBMODEM='12d1:1003' APN='CUSTOM_APN' CUSTOM_APN='safaricom' SIM_PIN='1234' APN_USER='saf' APN_PASS='data'" --sakisswitches "--sudo --console" --devicename 'Huawei' --log --silent --monthstart 8 --nat 'no'

A few remarks about this command:
in USBMODEM put device Id from lsusb
CUSTOM_APN - access point name reported by sakis3g
SIM_PIN - pin code if it exists
APN_USER/PASSWORD - user name and password for your 3g provider

If it works - put it at the end of /etc/rc.local

PATH_GOES_HERE/umtskeeper --sakisoperators "USBINTERFACE='0' OTHER='USBMODEM' USBMODEM='12d1:1003' APN='CUSTOM_APN' CUSTOM_APN='safaricom' SIM_PIN='1234' APN_USER='saf' APN_PASS='data'" --sakisswitches "--sudo --console" --devicename 'Huawei' --log --silent --monthstart 8 --nat 'no' &

At this point you can restart the beaglebone and make sure that you have the 3G internet.

6. Install hostapd and configure it

sudo apt-get install hostapd
zcat /usr/share/doc/hostapd/examples/hostapd.conf.gz | sudo tee -a   /etc/hostapd/hostapd.conf

Change in /etc/hostapd/hostapd.conf

ssid=NAME OF YOUR WIRELESS NETWORK GOES HERE
channel=10
wpa=2 # This sets the security settings to WPA2
wpa_passphrase=PASSWORD FOR NETWORK GOES HERE
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP

7. Ad to the end of /etc/network/interfaces

auto wlan0
iface wlan0 inet static
hostapd /etc/hostapd/hostapd.conf
address 192.168.8.1
netmask 255.255.255.0

At this point you can restart your beaglebone and make sure that you can connect to wireless access point.

8. Set the routing tables.
Enable routing in kernel. At the /etc/sysctl.conf change the following

net.ipv4.ip_forward=1

Beaglebone should be restarted after this step.

Now set the routing tables

sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
sudo iptables -A FORWARD -i ppp0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o ppp0 -j ACCEPT

You should be able now to connect to the acces point and surf the internet.

For make the routing tables permanent:

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Now edit the file /etc/network/interfaces and add the following line to the bottom of the file:

up iptables-restore < /etc/iptables.ipv4.nat

That's all. Enjoy your beaglebone.

Links used:
http://www.instructables.com/id/Raspberry-Pi-as-a-3g-Huawei-E303-wireless-Edima/
http://seravo.fi/2014/create-wireless-access-point-hostapd
http://elinux.org/RPI-Wireless-Hotspot

No comments: