Google
 
Showing posts with label wireless. Show all posts
Showing posts with label wireless. Show all posts

Monday, March 19, 2012

Multiple SSID on OpenWRT with bandwidth limit

If you're a network junkie and not been living under the rocks, you must have heard of OpenWRT. It's a Linux distribution for embedded devices (routers) and gives you power to do things usually impossible or difficult with inbuilt router firmware. Wireless Freedom indeed.

This was my scenario: I had to create two wireless APs for my office, one for the guests (no password but bandwidth limited) and another for non-guest users (password protected but no limit on bandwidth). That way the visitors will have free wireless internet, but with limited bandwidth. The office staffs will have to connect to a password protected wifi for unrestricted bandwidth.

The requirements for the APs are,

Free Wifi for visitors
- SSID: FreeWifi
- Password: none
- Bandwidth limit: 256Kbps uplink, 128Kbps downlink

Office Wifi for staffs
- SSID: OfficeAP
- Password: 1234567890
- Encryption: WPA2
- Bandwidth limit: none

Here's how I did it on OpenWRT. Connect to OpenWRT shell.

1. First create two wireless APs with above configuration. Add the following lines to /etc/config/wireless (Remove any existing 'wifi-iface' configurations)

# Free Wifi
config 'wifi-iface'
        option 'device' 'wifi0'
        option 'ssid' 'FreeWifi'
        option 'mode' 'ap'
        option 'network' 'lan'


# Office Wifi
config 'wifi-iface'
        option 'device' 'wifi0'
        option 'ssid' 'OfficeAP'
        option 'mode' 'ap'
        option 'network' 'lan'
        option 'encryption' 'psk2'
        option 'key' '1234567890'


As simple as that! Now to enable the wifi, go to shell and

# wifi down; wifi up

2. Now to limit bandwidth, we'll be using wondershaper. To install:

# opkg update
# opkg install wshaper


3. Now find which interface is the FreeWifi assigned to

# iwconfig

On mine, it was on ath0

4. Modify /etc/config/wshaper and start wondershaper

config 'wshaper' 'settings'
    option 'network' 'ath0'
    option 'downlink' '256'
    option 'uplink' '128'


Now, start wondershaper.

# /etc/init.d/wshaper start

5. By default, wshaper isnt enabled at startup. so,

# ln -s /etc/init.d/wshaper /etc/rc.d/S99wshaper

Thursday, February 25, 2010

Internet Connection Sharing in Linux over Ad-hoc Wireless

Laptops are common these days and so is wireless networking that comes with it. Almost all of us use Wireless Router for wireless networking and internet sharing. But most of us might not be familiar with ad-hoc mode that works in every wireless card and can eliminate the use of router altogether. Here's how:

To setup ad-hoc wireless, you basically set two or more wireless cards to same ESSID in ad-hoc mode and different IP addresses.

Setting the wireless card in ad-hoc mode

Generally iwconfig is used to set the wireless mode, but if you have madwifi drivers (see this too), the commands are slightly different. Go to terminal and type,

iwconfig
If you see interfaces named wlan0, wlan1, etc iwconfig will work. If you see interface names similar to ath1 and wifi0, then madwifi specific commands are to be used.

For general wifi cards:
sudo iwconfig wlan0 mode ad-hoc
Replace wlan0 with the interface name as listed by iwconfig

For cards using madwifi driver:
sudo wlanconfig ath1 destroy
sudo wlanconfig ath1 create wlandev wifi0 wlanmode adhoc
Now set essid. Pick some name like 'adhocwifi'
sudo iwconfig wlan0 essid adhocwifi
If required, to set encryption key
sudo iwconfig wlan0 key 1234567890
Now set IP address:
sudo ifconfig wlan0 192.168.0.1
Follow the above steps for another wireless card and set IP address in same subnet, say 192.168.0.2, and ping each other.

The whole ad-hoc mode setting can also be done using GUI network-manager, but since i'm not so much fond of graphical interface i'm not covering it. It should be simple.. :)

Internet Connection Sharing

Now to share the internet over wireless,
sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
where ppp0 is the connection you want to share (PPPoE connection in this case)

You also need to enable IP forwarding:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Or, to enable permanently add the following line to /etc/sysctl.conf
net.ipv4.ip_forward=1
Some ISPs might limit the TTL so that you wont be able to share the internet. Fix:
sudo iptables -t mangle -A PREROUTING -j TTL --ttl-inc 1

Using the shared internet (in Linux)

Now to use the shared internet on another computer, set it to ad-hoc mode and assign IP address in the same subnet as described above and perform the following:

1. Set the IP of computer sharing internet as gateway
sudo route add default gw 192.168.0.1
2. Set DNS server. We're using Google's DNS.
sudo sh -c "echo 'nameserver 8.8.8.8' >> /etc/resolv.conf"
You can also use IP and DNS Masquerading to ease the task.


Using the shared internet (in M$ Windows)

If you want to use the shared internet on M$ Windows,

1. Connect to the Wireless Network (in this case 'adhocwifi')
2. Go to Network Connections
3. Right click the Wireless Connection
4. Select the Internet Protocol (TCP/IP) and click Properties
5. Set IP to 192.168.0.2 (or accordingly in the same subnet as set on Linux box), gateway to 192.168.0.1 (as set on Linux box) and DNS to 8.8.8.8

Wednesday, February 03, 2010

Making DLink DWL-650+ PCMCIA Wireless card work under linux

The DLink DWL-650+ PCMCIA Wireless card doesn't work on recent Linux distros (I tried Ubuntu Hardy to Jaunty). After plugging in, the system hangs with CapsLock flashing.

Turns out the card is handled by acx module and the support is broken for this card. So use ndiswrapper instead.

First blacklist acx module. Open /etc/modprobe.d/blacklist.conf file and add the following line

blacklist acx
Now install ndiswrapper
sudo apt-get install ndiswrapper-common
Now get the Windows driver for the card from here. Extract the file, go to the winxp folder and,
sudo ndiswrapper -i AIRPLUS.INF
The card should work now.

Monday, January 05, 2009

No Wifi to Master-mode

Linux recognizes my wifi card as AR242x and there's no out-of-the-box support till now.

$ lspci | grep 'Wireless'
02:00.0 Ethernet controller: Atheros Communications Inc. AR242x 802.11abg Wireless PCI Express Adapter (rev 01)
However compiling the latest snapshot from madwifi.org works. (Instructions here)
$ wget -c http://snapshots.madwifi-project.org/madwifi-hal-0.10.5.6-current.tar.gz
$ tar xvf madwifi*.tar.gz
$ cd madwifi*r*

$ sudo make install
$ sudo modprobe ath_pci
$ sudo modprobe wlan_scan_sta
Cool. But the problem is no other modes except managed-mode seem to work.
$ sudo iwconfig ath1 mode ad-hoc
Error for wireless request "Set Mode" (8B06) :
SET failed on device ath1 ; Operation not permitted.
I was little curious about this as every wireless card supports at least ad-hoc mode if not managed. So I did a lil' diggin into madwifi's source code and found out that it supports all modes including master (or ap) mode too. This was quite startling to me coz i've been told that Master (or AP) mode is only for dedicated Wireless APs or expensive wireless cards.

Madwifi comes with nice wlanconfig tool.
$ wlanconfig
usage: wlanconfig athX create [nounit] wlandev wifiY
wlanmode [sta|adhoc|ap|monitor|wds|ahdemo] [uniquebssid]
usage: wlanconfig athX destroy
usage: wlanconfig athX list [active|ap|caps|chan|freq|keys|scan|sta|wme]
Now to start AP mode,
$ sudo wlanconfig ath1 destroy
$ sudo wlanconfig ath1 create wlandev wifi0 wlanmode ap
Now set the ESSID for the wireless network and IP for the interface
$ sudo ifconfig ath1 192.168.0.1
$ sudo iwconfig ath1 essid 'TestAP'
Voila! It worked and I can connect to this AP from another computer, set the IP to 192.168.0.x range and ping too. Now I'm wondering if AP mode is available in every card but is restricted by software so that ppl are forced to buy expensive APs.

Monday, January 14, 2008

Yipee, laptop wireless finally working!

Finally, my laptop's wireless is working under Linux. Hi5!

Well, my laptop is Acer Aspire 5103WLMi. It came with Windows Vista, but the moment i got it, installed Linux (Ubuntu) and never have used Vista (actually it's in Japanese so no question of using it even if i liked it.. ;))

Every piece of hardware worked fine except the card reader and wireless. Card reader worked as Ubuntu Gutsy came along, but still my Atheros AR5007EG wireless was causing trouble.

But thanx to this post of Ubuntu Forum, i finally got the wireless working! Actually i'd gone through this post before, how come i missed it then?

Now the only thing remaining to work on my laptop is Microphone. It's ATI Technologies Inc SB450 HDA Audio. Do any of u have any idea how to make the mic work?