Tuesday 3 December 2013

Flat Network 1: USB Internet Dongle

The steps to set up your dongle is explained on the OpenWRT wiki. But I had some problems because of the Specific dongle I was using (The Nokia dongle you get from CellC). So here is how to get it working.

ssh into the router then install packages with the following command:
opkg install comgt usbutils kmod-usb2 kmod-usb-ohci kmod-usb-serial \
kmod-usb-serial-option kmod-usb-acm usb-modeswitch usb-modeswitch-data
optionally also
opkg install luci-proto-3g
for the gui. Run lsusb, plug the dongle into the USB port of the router and run lsusb again. You should see a new device. Take note of the ID. The first part is the Vendor and the second part is the Product ID. Run:
ls /dev/
You will see that no new tty devices appear when you insert the dongle, this is because the dongle is not in the correct mode. This product's mode needs to be changed and it is not known to modeswitch, so it does not know what to do with it. Run:
ls /etc/usb_modeswitch.d
You will see that your ID is not there. But there are other devices from the same vendor (Nokia). A few of these devices run as the same product, so just copy one of these files to a file with your ID as the name and edit the product ID field to match yours.

Remove the dongle and plug it in again and you will see that the ID lsusb gives you is now different and you have two new devices in /dev/, ttyACM0 and ttyACM1. If you run:
gcom -d /dev/ttyACM0
You should see something like:
SIM ready
Waiting for Registration..(120 sec max)
Registered on Home network: "Cell C",2
Signal Quality: 9,0
So you know the device is communicating correctly. Now edit your /etc/config/network file and edit the wan section:
config interface wan
        option ifname  ppp0
        option pincode 1234
        option device  /dev/ttyACM0
        option apn     internet
        option service umts
        option proto   3g
        option pppd_options "noipdefault refuse-chap refuse-mschap \
                refuse-mschap-v2 refuse-eap"

Most websites recommend that you set a pin code for the dongle's SIM if it does not have one already, as some OpenWrt builds do not connect correctly without it. Run:
ifup wan
If it runs successfully it should give the output:
SIM ready
PIN set successfully
You should now have a working internet connection.

Sunday 27 October 2013

Using Netgear N300 as a modem only

Telkom gives a Netgear N300 modem to their new customers. If you want to use it as a modem only and dial from another router (I use a TP-link router running OpenWRT), follow these easy steps.

Force a 10.0.0.0/8 range IP on your computer (I used 10.0.0.3) and connect to 10.0.0.2 in your browser, the default username and password is usually admin:admin or admin:<blank>.


Then go to 'Setup > Basic Settings', at 'Does Your Internet Connection Require A Login?', set it to 'No', make sure 'Enable' is ticked under 'NAT' and select 'Apply'.


Next go to 'Advanced > WAN Setup', make sure 'Enable PPPoE Relay' is ticked and 'Apply'.


Then go to 'Advanced > LAN Setup', untick 'Use Router as DHCP Server' and 'Apply'.


All that is left is to plug a cable from the modem into the WAN port of your chosen router and dial a PPPoE connection with your Telkom login details.

Setting up iTunes in Linux

I got iTunes working on Ubuntu 13.04 after some googling, but it should work on any Debian based distro. I tested buying and downloading an album and that works. I am not interested in using it as a music player, so you can test that if you want and let me know in a comment.

You will need:

  • iTunes 10 - 32 bit (iTunes 11 works, but cannot connect to the internet, so it is useless and 64 bit does not work)
  • The newest PlayOnLinux (At the time of writing it was version 4.2.1)
  • Wine 1.4.1
iTunes 10.3.1 is available from the Apple support site, so download it (direct dl link).
For the newest PlayOnLinux you will need to add the ppa, instructions are here. There is not an option for Raring Ringtail, Ubuntu 13.04, but I just used the Quantal ppa and that worked fine.
You will need to install wine:
sudo apt-get install wine

Now, run PlayOnLinux and choose 'Install'.


Tick the 'Testing' box and search for iTunes. Select iTunes 10 and press Install.


Follow the steps, they will ask you to select an iTunes installer, select the one you downloaded previously. When you finish, you should have a working iTunes in Linux.

Monday 23 September 2013

Reset Locked Chinese Tablet

Someone gave me this cheap Chinese tablet:


He forgot the unlock pattern for the tablet and trying to guess it, we got totally locked out. You could still reset it with your google account, but the wifi was off and there is no way to turn it on whilst locked out. So +Nicholas Thompson and I spent some hours figuring out how to reset this tablet.

I found out this tablet uses a rk2918 (Rockchip) SoC (you can open it up or if you know someone else with the same tablet, go to Settings > About Device and check the 'Model Number', mine was 'Full AOSP on Rk29sdk')

First I had to get the tablet into recovery mode. The tablet has no volume buttons, so it has a different key combination from most tablets. So to get into recovery mode make sure the data cable is disconnected, turn off the tablet, then hold the power and menu buttons until the android logo appears. It should now be in recovery mode. Connect the data cable to the computer and run:
lsusb
You will get something like:
Bus 001 Device 011: ID 18d1:d001 Google Inc.
For some reason this is a Google Inc device because of its Vendor ID (list of vendors for those interested). You will need to get adb somewhere, I got it from the android website but it is a big download. You can download just the platform-tools here or run:
wget http://dl.google.com/android/repository/platform-tools_r18.0.1-linux.zip
unzip platform-tools_r18.0.1-linux.zip
cd platform-tools/
You should see a device with the command:
./adb devices
listed as:
???????????? no permissions
Add the tablet's vendor to the udev file to get the correct permissions:
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="18d1" , MODE="0666", GROUP="plugdev"' >> /etc/udev/rules.d/51-android.rules
disconnect and reconnect the data cables and run ./adb devices again and you should get:
0123456789ABCDEF recovery
To get the tablet info flash mode run:
./adb reboot bootloader
The tablet screen will go black, but it is not off, you will see it if you run lsusb again. It should be listed as something like Bus 001 Device 013: ID 2207:281a. Add this device to the udev rules as well:
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="2207", MODE="0666", GROUP="plugdev"' >> /etc/udev/rules.d/51-android.rules
For the next step you will need Rockbatchtool. I found some instructions and a linux version here.

You need to install the needed package and build the executable:
wget -O rkflashtool-v2.zip http://forum.xda-developers.com/attachment.php?attachmentid=785592&d=1321547155
unzip rkflashtool-v2.zip
sudo apt-get install libusb-1.0-0-dev
gcc -o rkflashtool rkflashtool.c -lusb-1.0 -O2 -W -Wall -s
Find the tablet's partition table by running:
./rkflashtool r 0x0000 0x2000 >parm
then check the start of this file with a hex dump:
xxd parm | less
mine looked like this:
0000000: 5041 524d 5302 0000 4649 524d 5741 5245  PARMS...FIRMWARE
0000010: 5f56 4552 3a30 2e32 2e33 0d0a 4d41 4348  _VER:0.2.3..MACH
0000020: 494e 455f 4d4f 4445 4c3a 4675 6c6c 2041  INE_MODEL:Full A
0000030: 4f53 5020 6f6e 2052 6b32 3973 646b 200d  OSP on Rk29sdk .
0000040: 0a4d 4143 4849 4e45 5f49 443a 3030 370d  .MACHINE_ID:007.
0000050: 0a4d 414e 5546 4143 5455 5245 523a 524b  .MANUFACTURER:RK
0000060: 3239 5344 4b0d 0a4d 4147 4943 3a20 3078  29SDK..MAGIC: 0x
0000070: 3530 3431 3532 3442 0d0a 4154 4147 3a20  5041524B..ATAG: 
0000080: 3078 3630 3030 3038 3030 0d0a 4d41 4348  0x60000800..MACH
0000090: 494e 453a 2032 3932 390d 0a43 4845 434b  INE: 2929..CHECK
00000a0: 5f4d 4153 4b3a 2030 7838 300d 0a4b 4552  _MASK: 0x80..KER
00000b0: 4e45 4c5f 494d 473a 2030 7836 3034 3038  NEL_IMG: 0x60408
00000c0: 3030 300d 0a43 4d44 4c49 4e45 3a20 636f  000..CMDLINE: co
00000d0: 6e73 6f6c 653d 7474 7953 312c 3131 3532  nsole=ttyS1,1152
00000e0: 3030 6e38 6e20 616e 6472 6f69 6462 6f6f  00n8n androidboo
00000f0: 742e 636f 6e73 6f6c 653d 7474 7953 3120  t.console=ttyS1 
0000100: 696e 6974 3d2f 696e 6974 2069 6e69 7472  init=/init initr
0000110: 643d 3078 3632 3030 3030 3030 2c30 7838  d=0x62000000,0x8
0000120: 3030 3030 3020 6d74 6470 6172 7473 3d72  00000 mtdparts=r
0000130: 6b32 3978 786e 616e 643a 3078 3030 3030  k29xxnand:0x0000
0000140: 3230 3030 4030 7830 3030 3032 3030 3028  2000@0x00002000(
0000150: 6d69 7363 292c 3078 3030 3030 3430 3030  misc),0x00004000
0000160: 4030 7830 3030 3034 3030 3028 6b65 726e  @0x00004000(kern
0000170: 656c 292c 3078 3030 3030 3830 3030 4030  el),0x00008000@0
0000180: 7830 3030 3038 3030 3028 626f 6f74 292c  x00008000(boot),
0000190: 3078 3030 3030 3830 3030 4030 7830 3030  0x00008000@0x000
00001a0: 3130 3030 3028 7265 636f 7665 7279 292c  10000(recovery),
00001b0: 3078 3030 3046 3030 3030 4030 7830 3030  0x000F0000@0x000
00001c0: 3138 3030 3028 6261 636b 7570 292c 3078  18000(backup),0x
00001d0: 3030 3033 6130 3030 4030 7830 3031 3038  0003a000@0x00108
00001e0: 3030 3028 6361 6368 6529 2c30 7830 3031  000(cache),0x001
00001f0: 3030 3030 3040 3078 3030 3134 3230 3030  00000@0x00142000
0000200: 2875 7365 7264 6174 6129 2c30 7830 3030  (userdata),0x000
0000210: 3032 3030 3040 3078 3030 3234 3230 3030  02000@0x00242000
0000220: 286b 7061 6e69 6329 2c30 7830 3030 4536  (kpanic),0x000E6
0000230: 3030 3040 3078 3030 3234 3430 3030 2873  000@0x00244000(s
0000240: 7973 7465 6d29 2c2d 4030 7830 3033 3241  ystem),-@0x0032A
0000250: 3030 3028 7573 6572 290d 0a3b ff43 e300  000(user)..;.C..
The relevant parts are:
0x0003a000@0x00108000(cache) and 0x00100000@0x00142000(userdata).

This means the cache partition has a size of 0x0003a000 and starts at 0x00108000 and the userdata a size of 0x00100000 and starts at 0x00142000.

Firstly backup both these partitions (in case this does not work):
./rkflashtool r 0x108000 0x3a000 >cache_backup
./rkflashtool r 0x142000 0x100000 >userdata_backup
Then overwrite both partitions with 0's:
./rkflashtool w 0x108000 0x3a000 </dev/zero
./rkflashtool w 0x142000 0x100000 </dev/zero
Lastly reboot the tablet with:
./rkflashtool b
The tablet should now boot as though it was factory reset. I went to the settings menu anyway and did another factory reset from there, just in case.