Friday, October 30, 2015

MT7601 on Raspberry Pi

Here's how to cross compile driver for Mediatek MT7601 based wifi dongle.

Before this, you need to compile your own raspibian kernel, see my old post: http://igunosystem.blogspot.co.id/2014/03/step-by-step-building-raspibian-on.html
After above process is OK, You'll have compiled kernel source and working root file system with working chroot (using qemu-arm-static) for raspberry pi board on your Desktop PC.

mt7601
download source:
https://github.com/porjo/mt7601/archive/master.zip
or
git clone https://github.com/porjo/mt7601.git

RTL8188eu on Raspberry pi

Here's how to cross compile driver for RTL8188eu based wifi dongle

Before this, you need to compile your own raspibian kernel, see my old post:
http://igunosystem.blogspot.co.id/2014/03/step-by-step-building-raspibian-on.html
After above process is OK, You'll have compiled kernel source and working root file system with working chroot (using qemu-arm-static) for raspberry pi board on your Desktop PC.

download source:
https://github.com/lwfinger/rtl8188eu/archive/master.zip
or
git clone https://github.com/lwfinger/rtl8188eu

Wednesday, October 21, 2015

WVDIAL Keep Alive

Here's a script to make the wvdial keep alive. Similar to umtskeeper that use sakis3g, this one can be use for some modem or internet provider that sakis3g won't connect. let's call this script as runwvd.
runwvd: (moved to github)

https://github.com/huntu2/wvdial-keepalive/blob/master/runwvd

make the script executable
chmod a+x runwvd

change the MODEM_NAME to your modem vendor that shown by lsusb


To start do following:
sudo ./runwvd start

To stop:
sudo ./runwvd stop

To view progres:
tail -f /tmp/runwvd.log

Prerequisites:
Before above script able to run properly, you'll need package:
sudo apt-get install wvdial usb-modeswitch fping ppp nohup usbutils

configure wvdial.conf by executing
sudo wvdialconf

copy the result at /etc/wvdial.conf and place it in the same folder as this script. Complete the Phone number username and password, something like this
wvdial.conf:
#-----------------------------------------------
[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2
Modem Type = Analog Modem
ISDN = 0
Modem = /dev/ttyUSB0
Baud = 9600
Phone = *99#
Username = '0'
Password = '0'
#------------------------------------------------


the '0' means no username and password supplied.

You also need resetusb, here's the source:
resetusb.c
#----------------------------------------------------
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>
void main(int argc, char **argv)
{
    const char *filename;
    int fd;
    filename = argv[1];
    fd = open(filename, O_WRONLY);
    ioctl(fd, USBDEVFS_RESET, 0);
    close(fd);
    return;
}
#----------------------------------------------------

compile it using:
gcc -o resetusb resetusb.c

Brief how it works:

The runwvd start with stamp file (/tmp/.runwvd) to control the loop, if this file gone, the loop will stop and the script terminated. The output process can be shown at /tmp/runwvd.log and the wvdial progress can be monitored from /tmp/wvdial.log.
 

First, it will call wvdial with wvdial.conf at the same folder. Then every SLEEPTIME period (above is 3 second) will regularly check for ppp0 existence and wvdial process. If both is missing, then the script will kill the wvdial and redial again.
 

Second, if first step is passed , the script will try to ping the dns server on peride CHECKTIME x SLEEPTIME, (above every 3x60=3minutes). The IP of the DNS were taken from /etc/resolv.conf resulted by wvdial upon successful connection. The ping loop will try to reach the DNS server for PINGLIMIT times (above is 5) with 1 second delay each. If all fail, then the script will terminate the wvdial and redial again.
 

Third, if the redial process happen more than REDIALIMIT (above is 5 times), then the script will try to reset the 3G modem after the wvdial terminated, and then redial again. This will help to re-register the 3G modem to the mobile network base station.
 

This note was written for my own record continuing previous blog on my homemade 3g router, but this might be useful for others who need it. 
Sorry for the bad blog format due to  my poor knowledge of the HTML and english language.

Sunday, October 18, 2015

Routing subnet below net


iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

iptables -I FORWARD -i br0 -o 10.1.1.60 -s 10.1.1.0/24 -d 10.1.2.0/24 -j ACCEPT
ip route add 10.1.2.0/24 via 10.1.1.60

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o wlan0 -s 10.1.1.0/24 -d 10.1.2.0/24 -j ACCEPT