Google
 

Sunday, May 31, 2009

NTC's GPRS in Linux via Bluetooth using Nokia phone

The following guide explains how to connect to Nepal Telecom's GPRS service from Linux via Bluetooth using Nokia phone. This guide is based on Linux GPRS Guide. The steps have been tested on Nokia 6600, 6630 and 5300 but should work on all Nokia phones.

NTC's GPRS is *really* slow so I won't recommend it for everyday use. However simple mail checking and tweeting ;) should do just fine.

Requirements
1. Nokia Phone
2. Nepal Telecom GPRS Account
3. Bluetooth Dongle (if not inbuilt in your PC/laptop)
4. Linux (the following steps were tested on Ubuntu)

Steps

1. Download ntgprs.tar.gz and extract (ntgprs, ntgprs-wvdial.conf and ntgprs-disconnect)
2. Copy the files to /etc/ppp/peers/ (you need root or sudo access)
3. Turn on Bluetooth on your Nokia phone
4. Plug in Bluetooth Dongle to PC or enable it (if inbuilt)
5. Fire up terminal (the commands to be entered are in bold-face):

Make sure the bluetooth is running on PC:

$ hciconfig
hci0: Type: USB
BD Address: 11:11:11:11:11:11 ACL MTU: 672:3 SCO MTU: 48:1
UP RUNNING PSCAN ISCAN
RX bytes:149397 acl:1046 sco:0 events:764 errors:0
TX bytes:40320 acl:628 sco:0 commands:74 errors:0

The following command will find bluetooth address of your phone
$ hcitool scan
Scanning ...
00:0E:6D:C2:99:42 Nokia

Create a RFCOMM port and bind it to phone's Bluetooth address.
$ sudo rfcomm bind /dev/rfcomm0 00:0E:6D:C2:99:42 1

Please note that the bluetooth address in the above command should match the address found by 'hcitool scan' command.

Check if the port has been created
$ rfcomm -a
rfcomm0: 00:0E:6D:C2:99:42 channel 1 closed

Now dial.
$ sudo pon ntgprs

--> WvDial: Internet dialer version 1.60
--> Initializing modem.
--> Sending: ATH
ATH
OK
--> Sending: ATE1
ATE1
OK
--> Sending: AT+CGDCONT=1,"IP","internet","",0,0
AT+CGDCONT=1,"IP","internet","",0,0
OK
--> Sending: AT+CBST=0,0,1;+CHSN=6,0,0,0;+CGDCONT=,,"ntnet"
AT+CBST=0,0,1;+CHSN=6,0,0,0;+CGDCONT=,,"ntnet"
OK
--> Modem initialized.
--> Sending: ATD*99#
--> Waiting for carrier.
ATD*99#
CONNECT
~[7f]}#@!}!} } }2}#}$@#}!}$}%\}"}&} }*} } g}%~
--> Carrier detected. Waiting for prompt.
~[7f]}#@!}!} } }2}#}$@#}!}$}%\}"}&} }*} } g}%~
--> PPP negotiation detected.
Serial connection established.
using channel 9
Using interface ppp0
Connect: ppp0 <--> /dev/rfcomm0
sent [LCP ConfReq id=0x1 ]
rcvd [LCP ConfAck id=0x1 ]
rcvd [LCP ConfReq id=0x0 ]
sent [LCP ConfAck id=0x0 ]
sent [PAP AuthReq id=0x1 user="user" password="pass"]
rcvd [PAP AuthAck id=0x1 ""]
PAP authentication succeeded
sent [IPCP ConfReq id=0x1 ]
rcvd [IPCP ConfReq id=0x0 ]
sent [IPCP ConfNak id=0x0 ]
rcvd [IPCP ConfNak id=0x1 ]
sent [IPCP ConfReq id=0x2 ]
rcvd [IPCP ConfReq id=0x1 ]
sent [IPCP ConfAck id=0x1 ]
rcvd [IPCP ConfAck id=0x2 ]
Cannot determine ethernet address for proxy ARP
local IP address 10.1.4.101
remote IP address 10.0.0.1
primary DNS address 202.70.64.5
secondary DNS address 202.70.64.15
Script /etc/ppp/ip-up started (pid 9902)
Script /etc/ppp/ip-up finished (pid 9902), status = 0x0

To disconnect
$ sudo poff ntgprs

Tuesday, April 07, 2009

Easy bandwidth shaping in Linux

There is an extensive and nicely written HOWTO on this topic but here I'm talking about some really easy to use bandwidth shaping tools -- wondershaper and trickle.

Wondershaper
This is the easiest tool I have found to limit bandwidth of a particular interface. All it takes is,


$ sudo wondershaper {interface} {down} {up}
the {down} and {up} are bandwidth in kilobits. So for example if you want to limit the bandwidth of interface eth1 to 256kbps uplink and 128kbps downlink,

$ sudo wondershaper eth1 256 128
To clear the limit,

$ sudo wondershaper clear eth1
Easy, eh?

Trickle
Unlike wondershaper, which limits the bandwidth to an entire interface, trickle is user-space bandwidth limiting tool. The syntax is,

$ trickle -u {up} -d {down} {program}
Both {up} and {down} and bandwidth in KB/s. Now if you invoke it as,

$ trickle -u 8 -d 8 firefox
It will fire up Firefox, limiting the bandwidth to 8KB/s. This is very useful specially if you are a web developer and want to test your application under various bandwidth conditions.

Furthermore, you can also run trickle as daemon (trickled) which can limit the bandwidth to several programs.

Friday, April 03, 2009

Fixing Nepali Unicode in Ubuntu

Setting up to type Unicode Nepali in Ubuntu is easy (just add Keyboard Indicator applet and add Nepali Layout). For more, follow this article in Ubuntu Nepali wiki. However there are few glitches.

Incomplete keyboard layout
The Nepali Romanized Keyboard layout shipped with Ubuntu (located at /usr/share/X11/xkb/symbols/np) is incomplete. The definition for the whole upper row (1-0 keys) are missing. Also, more importantly, zero-width joiner (ZWJ) and zero-width non-joiner (ZWNJ) characters are wrongly defined (ref: standard layout map).

You can find the working version here: http://www.nepalinux.org/input/ne. So lets, fix it. Fire up your terminal


$ cd /usr/share/X11/xkb/symbols/
$ sudo mv np np.bak
$ sudo wget http://www.nepalinux.org/input/ne -O np
Glyph missing
The devanagari fonts included in the standard Ubuntu installation has few Nepali specific glyphs missing. Most notably, 'pareli ra' or 'samyukta ra' (whatever it is called, the one you use in the word 'paryo').

Well, the fix is to install a font file which has this glyph. My recommendation is Lohit Nepali, available at http://nepalinux.org/fonts/. At terminal,

$ cd /usr/share/fonts/truetype
$ sudo wget http://nepalinux.org/fonts/Lohit-Nepali.ttf
$ sudo fc-cache -fv
Now if you want a specific font file (say, Kalimati) to be used as default devanagari font file, follow the following procedure.

Create a file in /etc/fonts/conf.avail/

$ sudo gedit /etc/fonts/conf.avail/64-ttf-nepali.conf
and paste the following content

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<alias>
<family>serif</family>
<prefer>
<family>Kalimati</family>
</prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer>
<family>Kalimati</family>
</prefer>
</alias>
</fontconfig>
Now, create a symbolic link to it in /etc/fonts/conf.d/

$ sudo ln -s /etc/fonts/conf.avail/64-ttf-nepali.conf /etc/fonts/conf.d/64-ttf-nepali.conf
You might have to restart X to see the changes.

Tuesday, January 27, 2009

Firefox Nepali Dictionary now public

Firefox Nepali Dictionary Plugin has been approved for public status. The plugin is now also listed at Dictionary and Languages page at Firefox Addon site.

For more on the plugin, see this blog post.

Tuesday, January 13, 2009

Using wget and dd to download file segment

Prasanna's this tweet caught my attention:

what would be sweet is if I could download segments from a file using wget ... any ideas?

Well, dd can help.

Suppose we need to extract 889th byte to 1298th byte of GPLv2 document, located at http://www.gnu.org/licenses/gpl-2.0.txt

1. Create a file (gpl_partial.txt) containing 888 bytes (i.e., the portion to skip)

dd if=/dev/zero of=gpl_partial.txt bs=1 count=888
2. Download the rest of the file and save it to gpl_partial.txt. (Assuming the server supports Range header)

wget -c http://www.gnu.org/licenses/gpl-2.0.txt -O gpl_partial.txt
wget interactively shows the download byte count. You can stop the download (Ctrl+c) after required bytes have been downloaded.

3. Now extract the required segment from gpl_partial.txt and save it to gpl_segment.txt (889th byte to 1298th byte = 410 bytes)

dd if=gpl_partial.txt of=gpl_segment.txt bs=1 skip=888 count=410

Update:
If wget is not a requirement, you can use cURL to get rid of all the hassles. To achieve the above mentioned segment,
curl -o gpl_segment.txt -r 888-1297 http://www.gnu.org/licenses/gpl-2.0.txt
Or, if you wanna do it in Python way, use httpheader Python module.

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.

Thursday, January 01, 2009

Battery charged notification

Load-shedding is driving us nuts! My solution is to move all my works to laptop and buy a spare battery. I think this is more cost effective and energy saving than buying expensive inverters. I've got an extra 8-cell battery for my laptop and altogether I have 6+ hours of backup.

But the problem is I keep forgetting to charge the batteries. The one in laptop starts charging when light is back but when it's done charging I forget to switch battery.

The solution lies at /proc/acpi/battery/BAT1/state

$ cat /proc/acpi/battery/BAT1/state
present: yes
capacity state: ok
charging state: discharging
present rate: 1342 mA
remaining capacity: 2201 mAh
present voltage: 11432 mV
Our line of concern is 'charging state:' which can have one of three values - charging, discharging or charged. So here's a simple bash script to monitor this file for charged state and pop a message to switch the battery.

#!/bin/sh

charged=0
while : ; do
if grep -iq 'charged' /proc/acpi/battery/BAT1/state
then
# nofify if previous state is uncharged
if [ $charged = 0 ] ; then
zenity --info --text "Battery charged. You might wanna charge another."
fi
charged=1
else
charged=0
fi
sleep 5m # wait for 5 minutes
done
Now put this program to System > Preferences > Sessions > Startup Programs.