Wednesday, August 5, 2009

enable wifi ad hoc on Andrid

Android comes with wifi ad hoc disable by default.  I have always wanted to use my Android the cheap way.  I do not have data plan.  Typically I am either at home or work.  My android is configured to connect to my home router via wifi.  We can not have a wifi router at work.  So a peer to peer connection would let my pc tether for my Android phone's internet connection.  And today I found it amazingly easy to do.

1.  edit /system/etc/wifi/tiwlan.ini

adb pull /system/etc/wifi/tiwlan.ini .
vi tiwlan.ini
find line "WiFiAdhoc = 0" and make the 0 1.  This would probably already be ok.  But somewhere I copied and pasted 2 more lines below, so now that block looks like

WiFiAdhoc = 1
dot11DesiredSSID = YOUR_SSID
dot11DesiredBSSType = 0
....

2  edit /data/misc/wifi/wpa_supplicant.conf 
This is for security.  Of course if you want to use it every day.
adb pull /data/misc/wifi/wpa_supplicant.conf .
vi wpa_supplicant.conf
if it is and empty file, paste in below and modify your ssid and wep_key0
update_config=0
ctrl_interface=tiwlan0
eapol_version=2
ap_scan=2
fast_reauth=1
network={
    ssid="YOUR_SSID"
    scan_ssid=0
    mode=1
    key_mgmt=NONE
    group=WEP104
    auth_alg=SHARED
    wep_key0="13alphanumeri"
}

if it not an empty, you must already have a ap connection configuration.  Just paste in the network clause.  Then it seems one or both of the below 2 lines is a must have to have security turned on.  
eapol_version=2
ap_scan=2

Then your pc or linux will be able to find the ssid specifed in the network clause as soon as wifi is turned on on Android.  Connect and enter the preset wep_key.  Make sure the pc or linux is configured to share internet connection.

Pretty sweet.

Thursday, May 14, 2009

command line launching Android app

am start -a android.intent.action.MAIN -n com.android.settings/.Settings

Sunday, February 22, 2009

PAN and SSH Android phone

Again, internet is good stuff. Without it, none of this would be this easy.

To do anything below, the phone must be rootable. G1 dev phone, or hacked G1 commercial. There is hacking info all over the web. Maybe someday I will come back and sort it up and place it here.

Enabling PAN on Android.

Android does not come with PAN enabled. The default Bluetooth profiles are Handsfree and Headset. When tried with "pand" command, error return says "Failed to open control socket: Protocol not supported". This means it needs bnep.ko module.

To enable PAN, I needed to build bnep.ko kernel module and insmod it on the device. Here is a very good tutorial. I pretty much followed it.

But it did work for me initially. When loading the ko module, it told me "insmod: init_module 'bnep.ko' failed (Exec format error)". Dmesg gets "bnep: version magic '2.6.27-01843-gfea26b0 preempt mod_unload modversions ARMv6 ' should be '2.6.25-01843-gfea26b0 preempt mod_unload ARMv6 '". Ahh! So the version of my kernel source is newer than the one in my phone. Then I went off to www.kernel.org and downloaded version 2.6.25, and repeated the same work, config, make modules, adb push bnep.ko, insmod. Dallah!

Then set up a pand NAP
# pand -s -r NAP

Now if I see NAP in my service list
# sdptool browse local
...
Service Name: Network Access Point
Service Description: BlueZ PAN Service
Service Provider: BlueZ PAN
Service RecHandle: 0x10002
Service Class ID List:
"Network Access Point" (0x1116)
Protocol Descriptor List:
"L2CAP" (0x0100)
PSM: 15
"BNEP" (0x000f)
Version: 0x0100
SEQ16: 800 806
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"Network Access Point" (0x1116)
Version: 0x0100

A simple "pand -c
" from my computer, I had 2 devices connected via PAN. Of course I had to assign them IP address manually. A little tricky with Android is that, ifconfig does not print anything. But I figured out that before they could ping each other, I had to explicitly
# ifconfig bnep0 up

SSH from PAN'ed Android phone
Natually, I wanted to try ssh once the 2 devices can see each other on the same subnet. But here is what I get
# ssh ktang@192.168.11.4
ssh: Warning: Reading the random source seems to have blocked.
If you experience problems, you probably need to find a better entropy source.

Internet never fails me. Here is some good info. Smart people everywhere. Briefly, this is the cure.
# ls /dev/random
/dev/random
# ls /dev/urandom
/dev/urandom
# mv /dev/random /dev/random.bk
# ln -s /dev/urandom /dev/random
# ssh ktang@192.168.11.4
ssh: Warning: failed creating //.ssh: Read-only file system

Host '192.168.11.4' is not in the trusted hosts file.
(fingerprint md5 ..................................)
Do you want to continue connecting? (y/n)
y
Password:
Last login: Sun Feb 22 02:08:36 2009 from tanglin
TangMac:~ ktang$

Made me happy!

Sunday, February 15, 2009

enabling ip forward

ktang@TangLin:~$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0

ktang@TangLin:~$ sudo vi /etc/sysctl.conf

ktang@TangLin:~$ sudo sysctl -p /etc/sysctl.conf
kernel.printk = 4 4 1 7
kernel.maps_protect = 1
fs.inotify.max_user_watches = 524288
vm.mmap_min_addr = 65536
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.ip_forward = 1

ktang@TangLin:~$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

Here is a great site of cheap sheet

Wednesday, January 21, 2009

Installing Adobe Flash Player 10 on Ubuntu Hardy

Due to the previously mentioned 2 GB limit with flash player 9, I attempted to upgrade Hardy with Adobe provided player 10 deb.

sudo apt-get install remove --purge flashplugin-nonfree libflashsupport
dpkg -i install_flash_player_10_linux.deb

But it did not work. After all the googling fun, this link was helpful. Briefly this is the key:

sudo ln -s /usr/lib/libssl3.so.1d /usr/lib/libssl3.so
sudo ln -s /usr/lib/libnss3.so.1d /usr/lib/libnss3.so
sudo ln -s /usr/lib/libnspr4.so.0d /usr/lib/libnspr4.so

sudo ln -s /usr/lib/libsmime3.so.1d /usr/lib/libsmime3.so
sudo ln -s /usr/lib/libplds4.so.0d /usr/lib/libplds4.so
sudo ln -s /usr/lib/libplc4.so.0d /usr/lib/libplc4.so

Yeah, it worked, for me at least.

Another overflow, or it looks like

Had a few large mp4 files unable to play on adobe flash player. The threshold happens to be 2 GB (overflow of a signed integer, it must be). Here is a bullet from Adobe Flash Player 9 release notes

  • Flash Player cannot progressively load files that are greater than 2Gb (210223)
I hope my guess was wrong. It would have been a low bug then.

Thursday, January 8, 2009

MP4Box - Out Of Memory

It wasn't this easy to find out.  It all started from when I was trying to convert my son's favorite dinosaur DVD's to h264 files.  I have a script, that calls for ffmpeg, feeding in parameters, and have the h264 files generated to the directories I want, then run MP4Box to hint them.  There were a dozen of them.  Encoding h264 isn't anything for the impatient.  So I left it running.  Day after day, there were some new h264 file created.  Then all done, finally.  But I found 2 largest VOB files (4.4 GB and 4.3 GB) ended up to be converted to mp4 files of 68 bytes each.  Bummer!

Of course I first thought it was ffmpeg, that it might have overflow problem.  Long story short, it was not.  I suddenly remembered that there was MP4Box hinting invoked at the end of the script.  Then I broke it into 2 steps, or course, ffmpeg got me a good unhinted mp4 file.  While I tried to run MP4Box on it, it gave me 

[iso file] Read Box "..A." failed (Out Of Memory)

I was using MP4Box from gpac 0.4.4.  Upgrading to gpac 0.4.5 fixed it.  What was unbelievable was 0.4.5 wasn't out until Dec 2008.  And until then, no one had such problem?  MP4Box isn't anything new to world.  Neither is DVD.  How come the fix isn't out until a month ago?  Weird.

A little side story on this.  When I first upgraded it, I did not see the upgrade fixing the problem.  What happened was that I made a build with the new source code, and ran the new MP4Box locally.  It did not work because it was pulling the libgpac.so from system directory, which was still the older version, because I did not "make install" the new version yet.  Seeing it not working, I was so pumped up to fix it myself.  So I loaded up ddd debugger.  That was where I found out it was using the libgpac.so of the older version.  So that took me no time.  Just that I did not get to have the sense of accomplishment.  But I am happy it is working now.