Unlock an AT&T iPhone 3G (with iOS 4.2.1) For Use With T-Mobile (RedSn0w Edition)

Mobile Devices 2 Comments

iphone3g-redSn0wMy nephew got an iPhone 3G and wanted to unlock it for use with his T-Mobile plan. Unfortunately, the iPhone was stuck in a weird state with only the Apple logo showing, and the iTunes application did not recognize it. I found that I could put the iPhone into Recovery mode. I then attempted to jailbreak using the custom PwnageTool firmware image I created in my last blog on iPhone jailbreak/unlock (my nephew’s iPhone 3G is the same model as mine’s). Unfortunately, the custom image restore process failed midway. I decided to load the latest official Apple iOS 4.2.1 image onto the iPhone and then use RedSn0w to jailbreak it.

To load the iPhone with the official Apple image, I had to put it into Recovery mode. Here’s how I got the iPhone into Recovery mode to do an official Apple restore:

  1. Connect the iPhone to the computer with the USB cable and start the iTunes application.
  2. Turn off the iPhone by holding the Power button until the Shutdown option appears at the top of the screen. If the iPhone is in a state where the shutdown option does not show and the screen is lit up, then just hold both the Power and Home buttons down for several seconds until the screen goes black.
  3. To enable Recovery mode, press and hold both Power and Home buttons until the screen lights up and you see the apple logo. Release the Power button but keep holding the Home button. After several seconds, iTunes will detect the iPhone and show a dialog saying the device is in recovery mode. You can release the Home button at that point.
  4. On iTunes, select the iPhone, and click the Restore button. Follow the iTunes instructions.

After the restore, the iPhone booted up with the following two messages: “No SIM card installed” and “Insert a valid SIM with no PIN lock to activate iPhone”. And when I slide to unlock the iPhone, it displayed a dial-pad with the title “Emergency call” mode. There was no way to access the normal application home screen. This was okay and something RedSn0w will take care of as part of the jailbreak.

To perform the jailbreak, I followed the instructions from How to Prepare your iPhone 4.2.1 for Unlock using RedSn0w.

  • In step 4, the download link for RedSn0w 0.9.6 beta 5 is broken. Instead, I downloaded it from Download Redsn0w 0.9.6 Beta 5 For Windows, Mac OS X.
  • In step 7, I saw a new option called “Enabled battery percentage” which was checked by default. I left it checked and when enabled in Settings->General, a useful charge percentage appeared next to the top-right battery icon on the iPhone.

Thankfully, the iPhone rebooted successfully and I was able to successfully repeat the unlock using UltraSn0w. My nephew was very happy with his new T-mobile iPhone!


Configure Wireless Access for the Brother HL-2280DW Multi-Function Laser Printer

Mac OS X, Windows 60 Comments

I scored a great deal on two Brother HL-2280DW Wireless Laser Printers (with scanner functions) during Thanksgiving break. Once I got the printers and tried to configure them for wireless, I found that Brother’s wireless configuration options were lacking and in some cases, didn’t work at all.

Unfortunately, the Ethernet connectivity on one of the printers was broken; worse, that was the printer I picked first to configure. After wasting half the weekend, I thought I would document how I finally went about configuring the wireless access for the Brother HL-2280DW printer and adding it to my Windows and Mac OS X machines. Hopefully, the steps below will help you with your Brother printer woes.

Note: The instructions below will work for other Brother wireless printers. I’ve also tried them successfully with Brother HL-2170W, HL-2270DW, and MFC-7860DW printers.

Note: I recently setup the newest model Brother HL-L2380DW printer. Unfortunately, I had to configured the printer to use a static IP address in order for it to be used from Windows 7. If you don’t configure a static IP address, when you install the Windows HL-L2380DW printer drivers, the installer will say that the printer is not configured properly and offer to configure it (set a static IP address). Mac OS X did not require the printer to have a static IP address.

Configure Wireless Access With Ethernet Connection and Web Interface

Note: The WPS and “WPS with Pin” setup did not work with my Cisco Linksys E1000 router. And while the printer allowed me to manually input the SSID and passphrase using the up/down arrows, the printer’s LCD only displayed the first 10-12 digits of the passphrase making it impossible to input the rest! Because I dislike using the USB method (which required installing, uninstalling, and then re-installing software), I decided that using the printer’s Ethernet connection and web interface was the best solution.

  1. Before we start, you will need to know the following info concerning your wireless network (check your wireless router’s configuration):
    • Network ID (SSID)
    • Channel Number (usually 3, 7, or 11)
    • Authentication Method (WEP, WPA or WPA2)
    • Encryption Mode (TKIP or AES)
  2. Follow the included Brother “Start Here” manual to prepare the printer for operation.
  3. Before turning on the printer, connect it to your wireless router by Ethernet cable.
  4. After the printer is on, we will need to find its assigned IP address:
    • Look it up on the printer:
      1. Press the Menu button to the right of the printer’s LCD and you will see “1. General Setup” menu item show up. You might need to press the Menu button twice sometimes. (Do not select the “1. General Setup” item.)
      2. Select the following menu items by pressing the up/down arrows and clicking on the OK button:
        • 4. Network
        • 1. Wired LAN
        • 1. TCP/IP
        • 2. IP Address
    • Alternatively, you can browse to your wireless router’s web interface and look at the list of connected DHCP clients.
  5. Browse to the printer’s assigned IP address to access its web interface.
  6. Configure the printer to enable toner save mode and to allow printing even if the toner is low:
    1. Click on “General Setup” at the top.
    2. You will be prompted for the user/password. Input the default: admin/access.
    3. Set the following options:
      • Toner Save: On
      • Replace Toner: Continue
    4. Click on the Submit button
  7. Configure the wireless network access:
    1. Click on “Network Configuration” link at the top.
    2. Click on the “Configure Wireless” link near the bottom of the page.
    3. Configure the following options:
      • Communication Mode: “1) Infrastructure Mode”
      • SSID: [input your wireless ID]
      • Channel: [input the wireless channel]
      • Authentication Method: WPA/WPA2-PSK (usually)
      • Encryption Mode: AES (usually for WPA2)
      • Passphrase: [input your wireless password]
    4. Click the Submit button.
    5. Answer Yes to “Would you like to enable the wireless interface?”.
    6. You will get a message to unplug the Ethernet cable. The printer will reboot and then print a page indicating whether the wireless connection succeeded or not.
  8. If the wireless connection didn’t succeed, then connect the Ethernet cable and repeat from step #4. Usually, the wireless router will give the printer the same IP address.
  9. If you are totally lost, you can reset the printer configuration by doing the following:
    1. Click on the Menu button next to the printer’s LCD.
    2. Select the following with the up/down arrows and the OK button:
      • 1. General Setup
      • 5. Reset
      • 2. All Settings
    3. Hit the Up arrow to Reboot.

Mac OS X: Add Printer, Set Toner Save Mode, and Scan

To add the printer on Mac OS X, do the following:

  1. Open up System Preferences.
  2. Click on “Print & Fax” under Hardware.
  3. Click the Plus button underneath the list of printers on the left.
  4. Bonjour should detect the printer and you will see “Brother HL-2280DW” listed.
  5. Select it and the “Print Using:” field will populate with “Brother HL-2280DW CUPS” driver.
  6. Click the Add button.
  7. The Brother HL-2280DW should show up on the list of Printers. To make it the default printer, double-click on it and select “Set default printer”.

To configure Mac OS X to use Toner Save Mode by default:

  1. Browse to the local CUPS driver web interface running on your machine. (You may be asked to run “cupsctl WebInterface=yes” in the Terminal application to enable the CUPS web interface.)
  2. Click on the Printers tab to the top-right.
  3. Click on the “Brother_HL_2280DW” printer in the list.
  4. Click on the Administration drop-down list box and select “Set Default Options”.
  5. Change “Toner Save Mode” to be “On”.
  6. Click on “Set Default Options” button.
  7. If you are prompted for a user/password, input your Mac OS X login username and the administration password.

The built-in way to do a scan on Mac OS X:

  1. Open up System Preferences.
  2. Click on “Print & Fax” under Hardware.
  3. Select the printer.
  4. Click on the “Scan” tab.
  5. Click the “Open Scanner…” button.
  6. Click “Show Details” for more options like output format and location.
  7. Make your selections and click on the “Scan” button.
  8. The scan will be taken and saved to the “Pictures” folder by default.

Windows XP and 7: Add Printer, Set Toner Save Mode, and Scan

To add the printer on Windows, do the following:

  1. Download the latest Brothers HL-2280DW printer software (it is the same file for Windows XP, Windows 7 32-bit, and Windows 7 64-bit and is named “HL-2280DW-inst-B1-usa.EXE”).
  2. Run the downloaded installation executable.
  3. Select “usa” for language. Click OK.
  4. Select “Wireless Network Connection” and check “Custom Install”.
  5. Take the default for “Change the Firewall port settings…”. Click Next.
  6. Take the default selected features (all are selected) and click Next.
  7. I usually select “No, I don’t want to register this PC to ‘Scan To’ button”; however, feel free to select Yes. (I think this option is so when you press the Scan button on the printer, it will send the image to this computer.) Click Next.
  8. On Windows XP:
    1. Keep the “Search the network for devices…” selected and click Next.
    2. Select the found Brother printer (the node name looks like “BRxxxxxxxxxx”) and click Next.
  9. On Windows 7, the printer detection doesn’t work so you will select either “Specify your machine by address” (IP address) or “Specify your machine by name” (node name/hostname). I usually do it by using the node name:
    1. To lookup the node name, go to the printer, press the Menu button, select “4. Network”, “2. WLAN”, “1. TCP/IP”, and “5. Node Name”. (Alternatively, the wireless router’s DHCP client table should have the printer’s hostname which is the same as the node name.)
    2. Back in the Brother setup dialog, select “Specify your machine by name” and input the node name.
    3. Click Next.
  10. The installation program will take several minutes to install the various Brother driver and tools.
  11. Click Next and Next to skip the “User’s Guides” and “On-Line Registration”.
  12. I usually uncheck “Enable Status Monitor on startup” and leave the “Set as Default Printer” checked. Click Next.
  13. The setup will request a reboot.
  14. After the reboot, you will see a new, red “CC4” icon in the status tray. This is the Brother Control Center software which allows you to set device properties, print, and scan. Because I prefer using my own programs to scan, I usually remove this from the tray by doing the following:
    1. Right-click on the CC4 icon and select “Preferences”.
    2. Unselect “Start ControlCenter on computer startup”.
    3. Hit the OK button.
    4. Right-click the CC4 icon and select “Close”.
  15. (OPTIONAL) Even though I have configured the Brother software to not run Control Center and the Status Monitor (unchecked “Enable Status Monitor on startup” in last page of installation wizard), Brother still runs them stealthily on startup. To really get rid of them, I had to do the following:
    1. Run “msconfig”.
    2. Select Startup tab.
    3. Under Windows 7, uncheck “Brother ControlCenter” and “Brother Status Monitor Application”.
    4. Under Windows XP, uncheck “BrCcBoot” and “BrStMonW”.
    5. Click Apply and then click OK.
    6. You may be prompted to restart.

To configure Windows to use Toner Save Mode by default:

  1. Go to menu “Start->Control Panel”.
  2. On Windows XP:
    1. Click on “Printers and Other Hardware”.
    2. Click on “View installed printers or fax machines”.
    3. Right-click on printer and select “Printer Preferences” to open the “Brother HL-2280DW Printer Printing Preferences” dialog.
  3. On Windows 7:
    1. Click on “View devices and printers”.
    2. Double-click on the Brother printer to open it.
    3. Double-click “Adjust print options” to open the “Brother HL-2280DW Printer Printing Preferences” dialog.
  4. In the Printer Preferences dialog:
    1. Select the Advanced tab.
    2. Check the “Toner Save Mode” option.
    3. Hit the Apply button and then the OK button.

The built-in way to do a scan on Windows XP:

  1. Run “Start->All Programs->Accessories->Scanner and Camera Wizard”.
  2. The Brother printer will be listed at the top. Click Next.
  3. Click on Preview, select options, and click Next.
  4. Select output format and folder. Click Next.
  5. The scan will be taken and saved to the “My Pictures” folder by default.

The built-in way to do a scan on Windows 7:

  1. Run “Windows Fax and Scan”.
  2. Click the “New Scan” button in the top toolbar.
  3. Hit Preview to see a preview image.
  4. Select the options and hit Scan.
  5. The scan will be taken and saved to the “Documents\Scanned Documents” folder by default.

One Button Scanning With Control Center

If you plan to do a lot of scanning, the Brother Control Center software (you’ll need to download and install it separately on Mac OS X) allows you to pre-configure the scan to file properties (including directory to save to and DPI quality). Once configured, you will only need to press the Control Center software’s scan button once to take a scan.

Note: The Scan To PC function allows you to press the hardware Scan key on the printer to save the file to your computer. You can configure this function using the Control Center. When adding the Brother scanner to Control Center, make sure to configure the “Scan Key” with a name. Unfortunately, using the Scan key on the printer requires multiple selection key presses, so it is not as convenient as the Control Center’s software scan key.

Though I refer specifically to the Brother HL-2280DW, these instructions most likely apply to other Brother wireless printer models.


PHP Script to Convert Firefox’s “sessionstore.js” to HTML

Internet 5 Comments

Today, my Firefox browser decided to freeze on startup while loading the pre-existing tabs. After killing it and restarting several times, I realized that the only way to recover was to prevent Firefox from loading the tabs. I located Firefox’s “sessionstore.js” file and moved it (one could also rename it). I started Firefox and it came up fine.

To find the “sessionstore.js” file on Windows 7, open up a “Command Prompt” and type the following:

cd %APPDATA%\Mozilla\Firefox\Profiles
cd <random_alphanumeric>.default

The macro %APPDATA% will translate to “C:\Users\your_username\AppData\Roaming”.
Windows XP and Mac OS X will have the “sessionstore.js” file in a different location.

I had about 25 tabs opened in the previous session and I did not want to lose those tabs. The tab URLs were stored in the “sessionstore.js” file but the file was big (it contained the open tab URLs and historical URLs) and hard to parse (it was a single huge JSON text string).

I decided to write a PHP script to convert the JSON string into an HTML file with a list of all the URL as links. Below is the PHP script I wrote. Just run it using the command line PHP executable, provide the “sessionstore.js” file location as the input, and it will create a “sessionstore.js.html” file (in the current directory), which you can then open in a browser to see the list of links.

 // Make sure we have the correct number of args
 $args = $_SERVER['argv'];
 if (2 != $_SERVER['argc']) {
   echo "Format: $args[0] <filename>\n";
 $filename = $args[1];

 // Read the input file into a json string
 $jsonStore = file_get_contents($filename) or die("Failed to open input file");

 // Convert the json string into an object
 $store = json_decode($jsonStore);

 // Create an output .html file
 $file = fopen("$filename.html", "w") or die("Failed to create output file");

 // Add HTML header
 fwrite($file, "<html><body><ul>\n");

 // Parse the session store object and generate HTML links for each tab.
 // Session stores have windows->tabs->entries array-of-arrays structure.
 $windows = $store->windows;
 foreach ($windows as $window) {
   $tabs = $window->tabs;
   foreach ($tabs as $tab) {
     $entries = $tab->entries;
     foreach ($entries as $entry) {
       fwrite($file, "<li><a href="$entry->url">$entry->title</a>\n");

 // Add HTML footer
 fwrite($file, "</ul></body></html>\n");

 // Close the output file

If you find that the “sessionstore.js” does not contain your open tabs, use the “sessionstore.bak” backup file instead. I hope that the script above may prove useful for you. Good luck with your Firefox blues.


Unlock an AT&T iPhone 3G (with iOS 4.1 or 4.2.1) For Use With T-Mobile (PwnageTool Edition)

Mobile Devices 2 Comments

iphone3g-pwnagetoolMy friend gave me his old AT&T iPhone 3G. I decided to unlock it for use with T-Mobile. On the web, there was a lot of info on how to go about doing the unlock and a lot of caveats. I wanted to summarize my findings below and provide details on how I went about the process of unlocking the iPhone 3G. (Though I did the unlock on Mac OS X, the instructions for Windows are the same.)

Note: I decided to remove the AT&T SIM card to see if I could do the unlock without it. This would be useful for those who got their iPhone 3G without an AT&T SIM card. It turns out that the AT&T SIM card is not required. (To remove the SIM card, locate the card slot at the top of the iPhone 3G with a visible little hole. Insert the end of paperclip into the hole, push down gently, and the SIM card holder will pop up.)

Some important pointers:

  • There are software and hardware unlocking methods. The hardware unlock usually requires a custom SIM card overlay or a custom SIM card holder. I will be doing a software unlock.
  • An iPhone has two very important information, the iOS version and the baseband version, which determines whether the unlock is possible. Confusingly, some websites will refer to the iOS version as the “firmware” version and Apple refers to the baseband version as the “modem firmware”.
  • An official Apple iOS version update may also include a baseband version update. Unlock is very dependent on the baseband version so be very careful to avoid official Apple iOS upgrades unless you know what you are doing.
  • In order to unlock, you must jailbreak first. The popular jailbreak methods (like RedSn0w and PwnageTool) will include a way to preserve the baseband version. PwnageTool creates a custom upgrade file (ipsw) by modifying the official upgrade ipsw file to remove the baseband version update.
  • The software unlock method “UltraSn0w” that I plan to use supports only specific baseband versions.

First, we need to figure out what we are working with:

  1. Determine the iPhone model by looking at the back of the phone for the model number. Check the Apple site to find a match. My iPhone had a model number of “A1241” which matched with “iPhone 3G”. (I couldn’t tell visually whether I had an iPhone 2G, 3G, or 3GS.)
  2. Determine the iOS and baseband versions by going to “Settings->General->About” on the iPhone. My iPhone 3G had an iOS “Version” of 4.1 and a baseband “Modem Firmware” version of 05.14.02.

Unfortunately, my iPhone 3G had a baseband version 05.14.02 which was not supported by UltraSn0w according to this UltraSn0w unlocking tutorial. If I upgrade to iOS 4.2.1, the baseband version would be upgraded to 05.15.xx which is also not supported by UltraSn0w. The workaround is to upgrade the baseband to the 06.15.00 version, which is surprisingly provided in the iPad 1 iOS 3.2.2 image.

Updating to 06.15.00 baseband is not reversible (back to 05.14.xx or 05.15.xx) so it would void the Apple warranty (I didn’t care because the iPhone is out of warranty) and future upgrades would require custom ipsw images. To me, it looks like Apple doesn’t plan to upgrade iPhone 3G past iOS version 4.2.1 and even if that were to happen, I could figure out how to use PwnageTool to create the necessary custom ipsw image. So, I made the decision to upgrade the iOS version to 4.2.1 and the baseband version to 06.15.00 so I could unlock using UltraSn0w.

According to the UltraSn0w tutorial, I could jailbreak and update to 06.15.00 using either the RedSn0w jailbreak tutorial or the PwnageTool jailbreak tutorial. I decided to use the PwnageTool because it would allow me to avoid having to do an official Apple iOS upgrade to 4.2.1 (required by the RedSn0w method) and it would allow me to get familiar with PwnageTool (I have used RedSn0w before).

To perform the jailbreak, I followed the PwnageTool tutorial step by step:

  • Before starting, I connected my iPhone 3G using the USB cable and quit the iTunes application.
  • In step #1, make sure to download the specific version 4.1.3 of PwnageTool requested (I tried the latest version which wouldn’t accept any of the ipsw files), the iPhone 3G iOS 4.2.1 image file “iPhone1,2_4.2.1_8C148_Restore.ipsw”, and the iPad 1 iOS 3.2.2 image file “iPad1,1_3.2.2_7B500_Restore.ipsw” (which contained the 6.15.00 baseband).
  • In step #5, the first ipsw file to select is the iPhone 3G iOS 4.2.1 ipsw image file. The second one to select is the iPad 1 iOS 3.2.2 ipsw image file containing the baseband.
  • Step #6 was a little confusing. After reading it a couple of times, I got that if you plan to use the iPhone with the service provider it was originally locked to, then do not check the “Activate the phone” option. If like me, you wish to use an unofficial service provider (I’m using an AT&T iPhone with T-Mobile), then check the “Activate the phone” option. (For me, the “Activate the phone” option was selected by default.)
  • Also in step #6, my “Root partition size” was set to 731MB by default. I manually increased it to 834MB to match the picture in the tutorial. (I don’t know if this was necessary or not, but I figured it could only help.)
  • During step #12, when following PwnageTool’s steps to put the iPhone into DFU mode, the iTunes application was automatically started. I minimized iTunes and restarted the PwnageTool DFU instructions. When the iPhone entered DFU mode, iTunes threw an error dialog saying there was an unrecognized device. I had to disconnect and reconnect the USB cable in order for iTunes to recognize the phone properly and the DFU mode. (Now that the iPhone was in DFU mode, I quit the PwnageTool application.)
  • Once the iPhone was successfully restored (using the PwnageTool custom ipsw image) and restarted, I verified that the “Settings->General->About” listed the Version as 4.2.1 and the Modem Firmware as 6.15.00.
  • Whew, I was really glad the iPhone came back to life because I was waiting for a long time. The restore took about 10 minutes and the restart took several minutes.

To perform the unlock, I followed the original UltraSn0w tutorial step by step:

  • Before starting, I configured the iPhone (Settings->Wi-Fi) to connect to my wireless network.
  • In step #2, Cydia took a couple of minutes to update itself on initial startup. Then it asked me if I would like to update packages. I selected the “Complete Upgrade” option which took several minutes to complete and required a reboot. (Once Cydia was done with the update, it showed a large Reboot text at the bottom of the screen; I just tapped on the text to do a reboot.)
  • In step #3, I clicked on the Cydia Search tab to find and install UltraSn0w (that’s a number zero in the word “sn0w”). The UltraSn0w installation also required a reboot when it completed.

Finally everything was done. I shut down the iPhone, inserted my T-Mobile SIM card, and restarted. After startup, the iPhone took a couple of minutes to find the T-Mobile network. Because my T-Mobile plan did not have a data plan (and I didn’t want to be charged for one), I disabled the 3G connectivity function by going to “Settings->General->Network” and setting the “Enable 3G” and “Cellular Data” options to Off. I then tested the iPhone by taking a call, making a call, receiving a text, and sending a text. It works, yeah!

Unfortunately, when using PwnageTool to create the custom image earlier, I neglected to enable the very useful battery percentage indicator (which RedSn0w enables by default). To enable the battery percentage at this late stage, I found a useful guide, Enable Battery Percentage in iOS 4 on iPhone 3G without Redsn0w, which worked for me. (Hint: You may need to install “cmd-files” before you can install “iFile”.) After restarting the iphone, I went into Settings->General and turned on “Enable Battery Percentage”.

Hopefully the above is helpful. Good luck with your unlocking.


Migrating from Windows XP to Mac OS X, Part 2

Mac OS X No Comments

stevejobsIt has been over a year since I migrated to a Macbook Pro laptop and started using the Mac OS X operating system. Since then, I have learned some useful tips and tricks, which I have shared below.

Using Keyboard Shortcuts

If you can master keyboard shortcuts, you will be able to perform some actions (especially repetitive ones) much faster than using the trackpad.

Enable Tabbing Between All Controls

This will allow you to tab to any control, such as a button, in a window or dialog.

  1. Go to “System Preferences” and Keyboard.
  2. In the “Full Keyboard Access: …” section at the bottom, make sure that the “All controls” radio option is checked.

Strangely, after you tab to a button, some dialogs require you to press the Return key and other dialogs require you to press the Space key in order to “click” the button.

Perform a Screen Capture

Use the following key combinations to perform either a full screenshot or a cropped screenshot:

  • Simultaneously press Apple + Shift + 3 keys to perform a full screenshot.
  • Simultaneously press Apple + Shift + 4 keys to enter cropped screenshot mode, where the cursor becomes a target icon. Click down, without releasing, to pick a corner of the shot and drag to frame the shot (you will see a translucent rectangle). Release to take the cropped screenshot.

The screenshots will appear on your desktop as PNG image files.

Deleting Files

Select one or more files and simultaneously press Apple + Delete keys to delete them. This key combination will also work to delete folders. The deleted files and folders are placed in the waste basket.

Force Quit an Application

If your Mac OS X appears to be frozen due to an unresponsive program, one drastic measure is to kill that program’s process. Simultaneously press Command + Option + Esc keys to open up the “Force Quit Applications” dialog, select the offending application, and click on the “Force Quit” button.

Note: For more details on running applications (in addition to disk, memory, and network usage), you can launch the “Activity Monitor”.

Just for Fun

There are a ton of keyboard shortcuts. You just have to find the ones most useful to you. For example, here’s a fun shortcut: press Fn + Shift + F10 keys to make the current window bright and slowly move to the center, while everything else fades away.

Command Line With Terminal

The Terminal application is equivalent to the Linux shell or the DOS command prompt. For certain activities such as writing scripts or doing development, I prefer to use the command line. So I was very glad that Mac OS X came with the Terminal application. One can open several Terminals and even skin them so they will be partially transparent.

Launch an Application

One can launch a Mac OS X application from the Terminal by issuing the following commands:

  • Run “open [application | file | directory | URL]” to launch a particular application (ex: “/Applications/TextEdit.app”), open a file with its default associated application, open a directory using Finder, or browse to a URL using the default browser respectively.
  • Run “open -e [file]” to open a file with the TextEdit application.
  • Run “open -a [application] [file]” to open a file using the specified application.

Debug the Wireless Network

Mac OS X comes with a nifty command line wireless utility called airport. To enable easy access to it, run the following to put it in the command line’s search path:

sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport

Once you have run the above, you can now issue the following commands:

  • Run “airport -I” to see the current wireless status, what SSID you are connected to and the strength of the signal. Note that some of this info is also shown if you hold down Option key while clicking on the Airport status icon in the top menu bar (on the right-hand side).
  • Run “airport -s” to scan the wireless broadcast space.
  • Run “airport -z” to disassociate from any wireless network.

Some other useful commands are:

  • Run “ifconfig en1” to see your machine’s assigned IP address on the wireless network.
  • Run “dscacheutil -flushcache” to flush the DNS cache.

Where’s My CD?

To access another partition or a CD using Terminal, change to the “/Volumes” directory.

Reset Your Admin Password

If you ever forget your administrative password, there are two easy methods to reset the password. One requires the Mac OS X Install CD and the other does not.

Require the Mac OS X Install CD

First method is to boot from the Mac OS X Install CD and run the reset password application.

  1. Insert the Mac OS X Install CD and restart the Mac.
  2. Hold the “C” key on startup to boot from the CD.
  3. Once the specialized Mac OS X operating system on the CD is booted, go to menu “Utilities->Password Reset”.
  4. Select the Mac OS X hard drive.
  5. Select your username and input the new password.
  6. Restart the Mac.

Don’t Require Mac OS X Install CD

Second method uses single user mode and does not require the Mac OS X Install CD.

  1. Restart the Mac.
  2. On startup, hold the Command + S keys down to boot into single user mode.
  3. Once you have Terminal access, input the following commands to reset your password:
    mount -uw /
    ls /Users
    passwd [your_username]
    shutdown -r now

    The second command will show the list of users, one of which will be your username.

  4. Alternatively, if you wish to have Mac OS X prompt you to create a new administrative user, run the following command instead of the “passwd [your_username]”:
    rm /var/db/.AppleSetupDone

    Deleting the .AppleSetupDone file will cause Mac OS X to re-run the setup wizard on bootup, which will prompt you to create a new user account with administrative permission. You can then run “System Preferences->Accounts” to reset any user’s password.

Note: Did you know that Mac OS X, like Windows, has a Safe Mode? If you ever need it, just hold the Shift key on bootup to go into Safe Mode.

Boot Camp for the Schizophrenic

Boot Camp comes with Mac OS X and allows you to dual-boot into either Mac OS X or Windows. It is very easy to setup as long as you have an official Windows installation CD with product key. The only decision you have to make is how much space to allocate to Windows; I recommend 32GB or more for Windows 7 to allow space for applications.

Install Windows

Run “Boot Camp Assistant” and follow the directions.

  • The Windows Support Software can be considered Windows drivers for Mac hardware such as video cards, trackpad, etc. I consider it a requirement, otherwise Windows would not perform well on the Mac.
  • For the “Download Windows Support Software” page, I selected the second option since I had the Mac OS X Installation CD. I did try the first option “Download the Windows support software…” on another Macbook but it failed after several minutes; maybe you will have better luck if you use this option.
  • Per the instructions, insert the Windows installation CD and start the Boot Camp installation.
  • Note: I recommend using an official, unmodified Windows CD. I tried this with a customized, no interaction Windows Install CD and its custom installation script repartitioned the whole drive as a Windows partition (thereby destroying the Mac OS X partition). To recover, I had to reinstall the Mac OS X operating system from scratch.

Configure Windows

Once Boot Camp is installed, on startup, just hold the Option key down and you will be presented with a menu to select either Mac OS X or Windows to boot into. When you are in Windows, insert the Mac OS X Install CD to install the necessary Apple Windows drivers. Once installed, you will see a Boot Camp icon in the bottom-right dock which will allow you to configure the Trackpad, which OS to boot by default, etc.

Mac Keyboards Are Strange!

You will need to either get used to using Windows with the Mac keyboard or alternatively, to remap the Mac keys to match Windows.

Emacs The Way You Want It

Mac OS X comes with a command line version of Emacs. However, I’ve gotten used to GNU Emacs on Windows and wanted the same on the Mac OS X. Here’s how to install GNU Emacs on your Mac:

  1. Download the latest GNU Emacs for Mac OS X.
  2. Open the disk image and copy Emacs.app to the “/Applications” folder.
  3. You can launch GNU Emacs from the command line using “open -a /Applications/Emacs.app [file]”.

Customize Emacs

If you want to customize Emacs to disable the startup splash screen and enable mouse scrolling, create a “~/.emacs” file with the following content:

;;Prevent startup splash screen
(setq inhibit-splash-screen t)

;;Increase width to 120 chars
(add-to-list 'default-frame-alist (cons 'width 120))

;;Set tab to be displayed as 4 spaces, not the default 8
(setq-default tab-width 4)

;;Enable wheelmouse support
(require 'mwheel)

;;Define the mouse scroll wheel
(defun up-slightly () (interactive) (scroll-up 5))
(defun down-slightly () (interactive) (scroll-down 5))
(global-set-key [mouse-4] 'down-slightly)
(global-set-key [mouse-5] 'up-slightly)

;;Support for scrolling (two finger scrolling is double-wheel-up/down)
(global-set-key [wheel-down] 'up-slightly)
(global-set-key [wheel-up] 'down-slightly)
(global-set-key [double-wheel-down] 'up-slightly)
(global-set-key [double-wheel-up] 'down-slightly)
(global-set-key [triple-wheel-down] 'up-slightly)
(global-set-key [triple-wheel-up] 'down-slightly)

Restart Emacs for the changes to take effect.

Remove Windows Return Characters

Files from Windows may contain return characters which show up as visually distracting ^M characters in Emacs. Worse, the Windows return characters inside a bash script file will cause errors on execution. To remove the Windows return characters, open the file in Emacs and perform one of these two methods:

  1. Type “Esc-x set-buffer-file-coding-system”, Enter key, “unix”, Enter key to switch the format to Unix (from Windows).
  2. Type “Esc-x replace-string Ctrl-q Ctrl-m” and Enter key to replace the Windows return characters with nothing. The Ctrl-q will allow you to type control characters into the input buffer, such as Ctrl-m for the Windows return character.


This is the dumping ground for random, but possibly useful tips.

VMWare Fusion

When using VMWare Fusion running Windows, you will need to add Fn to the normal Windows keyboard shortcuts. For example:

  • Use Fn + Control + Option + Delete keys to issue a Windows Ctrl-Alt-Delete command.
  • Use Fn + Delete to issue a Windows Delete command.


To run Firefox in 32bit mode by default (so some legacy plugins can work):

  1. Go to /Application and select the Firefox icon.
  2. Left-click and select “Get Info” on the Firefox application.
  3. Check the “Open in 32-bit mode” box.

Did you know that you can issue commands in the Firefox address bar? Try the following:

  • Input “about:blank” to get a blank page. (You can also set this as the home page.)
  • Input “about:sessionrestore” to load the tabs that were opened in the previous session. Try using this if Firefox complains that it is unable to recover your saved tabs on startup.
  • Input “about:plugins” to see a description of all the installed plugins.

The above will work in Firefox running on all supported operating systems.

Hopefully all the tips here will help you to enjoy your own Mac migration.

No Comments

Import Movies and TV Shows to Your Apple iPad

Audio Visual, Mobile Devices No Comments

Have you ever imported movies and TV show episodes into your Apple iPad and have them show up as generic videos, not movies or TV shows? Worse, these videos show up without a preview image, just a totally black square? And are the episodes nicely grouped under the TV show’s name? Finally, when you play a movie, can you skip to later chapters?

ipad-indiajonesWell, I have had all of the above problems until I discovered Subler. Subler is available only for Mac OS X. It is used to add meta-info to the movie or TV episode files so they will show up in iTunes and iPad correctly as movies or TV shows. In addition, Subler supports adding chapters, subtitles, and secondary audio tracks (like for other languages). Below are my notes on how I used Subler.

Before anything else, you will need to convert your movie or TV episode into the iPad supported format (usually an MPEG4 file ending in .m4v or .mp4 extension). There are several resources on the Internet about how to do the conversion. Here is a nice tutorial using the free Handbrake tool to convert a movie DVD. If you use this tutorial, before importing the movie into iTunes, make sure to run Subler on it to add a preview image and chapters.

Apple iPad Supported Formats

A quick google search identifies that the iPad supports the following video formats:

  • H.264 video (up to 720p 1280×720, 30 frames per second) with AAC audio (main profile level 3.1 with AAC-LC audio up to 160 Kbps, 48kHz, stereo) in .m4v, .mp4, and .mov file formats.
  • MPEG-4 video (up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second) and AAC audio (simple profile with AAC-LC audio up to 160 Kbps, 48kHz, stereo) in .m4v, .mp4, and .mov file formats.
  • Motion JPEG (M-JPEG) video (up to 35 Mbps, 1280 by 720 pixels, 30 frames per second) and PCM audio (ulaw, stereo) in .avi file format.

For simplicity, I always encode movies and TV episodes using the first format: “H.264/MPEG-4 AVC” video and “MPEG-4 AAC” audio.

Using Subler for Movies

I use Subler to add a preview image and chapters to a movie file. Subler will also add meta-info to indicate that the file is a movie type so that iTunes and iPad will recognize it accordingly. Here are the steps:

  1. Launch Subler. Subler won’t open a default project window so the only change you will see is that the top menu title changes to Subler.
  2. (Do this once) Go to menu Subler->Preferences and check the “Create Preview Images” for Chapters. This will cause Subler to generate chapter preview images when you save. Without this option, chapters will show up as black squares on the iPad. (QuickTime player and iTunes will generate the chapter previews on the fly if they don’t exist, but the iPad won’t.)
  3. Go to File->Open to find your mp4 or m4v iPad supported movie file. The project window will appear.
  4. In the project window, you will see a line for the “Video Track” for video and “Sound Track” (or sometimes “Stereo” track) for audio. Optionally, you may see a second audio track, a “Subtitle Track”, or a “Chapter Track”. Tracks with a check are enabled by default.
  5. If you don’t select any of the track line items (just click on any blank area in the project window), you should see the following appear at the bottom: Metadata, Artwork, and Other Settings.
  6. Go to menu “File->Import->Search metadata online” to find the movie description and artwork (preview image).
    • The Movie search tab will be selected by default.
    • Input the Movie Title, click the Search button, select the movie, and click the Add button.
    • Select a picture and click the “Set as artwork” button. Note that I could not find a way in Subler to change the artwork once it has been selected!
    • The Metadata and Artwork content at the bottom will be populated.
  7. Go to menu “Edit->Insert a Chapter Every X minutes” to add the chapters. I recommend selecting the “5 minutes” interval. (See below for how to add your own custom chapters at specific times.)
    • A “Chapter Track” will appear.
    • Make sure to check the chapter track to enable it.
  8. Commit your changes by going to menu File->Save. Subler will generate the chapter preview images and store them in a new “Video Track” with format “Photo – JPEG”. Leave this new video track unchecked.

Using Subler for TV Episodes

Adding meta-info to TV episodes is very similar to the above. The difference to keep in mind is that episodes have seasons and are numbered. iTunes and iPad will use the seasons and episode numbers meta-info to group TV episodes together (usually episodes together under a season). If you end the TV episode file names with the season and episode number like “S02E15” (Season 2, Episode 15), Subler will automatically pre-populate the search form. Here are the steps:

  1. Open the TV episode file using menu “File->Open”.
  2. Go to menu “”File->Import->Search metadata online”.
  3. If you have named your file with the season and episode number, Subler will select the TV Episode search tab and fill in the TV Show, Season #, and Episode # fields. If this didn’t happen, manually make the selection and inputs.
  4. Select the TV episode and artwork like above. (The first option for artwork is usually a screenshot from the episode. I recommend you select this so that each episode will have a unique preview image.)
  5. Verify the info in the Metadata tab content at the bottom. Make sure that the TV Season, TV Episode #, and Track # (aka episode number) is correct. The “Track #” will consist of the episode number and the total number of episodes in the season; for example, “5/21” meaning episode number 5 out of 21 episodes. Usually the Metadata will not have the total number of episodes; when you save without specifying it, the Track # will default to zero for total number of episodes. (I don’t think missing the total number of episodes will affect iTunes or iPad, but I have not tried it.)
  6. I don’t believe that the “TV Episode ID” is used by iTunes or iPad; however, it doesn’t hurt to make sure it is correctly filled-in. Basically, it is the season followed by the episode number; for example, “203” meaning season 2 and episode 3.
  7. I believe you can add chapters to TV episodes if you wish to. I don’t think it hurts and I’m not sure if iTunes or iPad will make use of chapters for TV episodes.

Use Subler to Increase Sound Volume

Subler has other functions which allow you to scale the video resolution or increase/decrease the sound volume. To double the sound volume:

  1. Select the “Sound Track” in Subler.
  2. In the Sound Settings that appear below, drag the Volume marker to the maximum “+6 db” setting. (From a quick google seach, “+6 db” effectively equals to double the sound volume.)

If you need to increase the sound volume further, you may wish to use a tool like AACGain.

Finally, import your movies and TV episodes to iTunes and/or iPad. They will show up under the correct Movies or TV Shows section, instead of the generic Videos section. Good luck!

Adding Custom Chapters to Subler

Adding custom chapters to Subler involves creating a raw text file, inputting the chapter times and names into it, and then dragging it into Subler. Subler will automatically recognize it as a Chapter Track.

The Subler documentation indicates that there are two formats for the chapter text files; I chose the more compact mp4v2 format. Here’s an example:

00:00:00:000 Opening
00:00:53:000 Robot Monkey Hullabaloo
00:13:56:000 Curious George, Spy Monkey
00:27:00:000 Curious George Rides a Bike
00:40:03:000 Curious George vs. the Turbo Python 3000
00:53:06:000 Monkey Fever
01:06:10:000 The Lucky Cap
01:19:14:000 Candy Counter
01:32:17:000 Gutter Monkey

Some comments about the above:

  • The file should contain a space between the time and the name, not a tab character.
  • The file extension should be “.txt”.
  • The first chapter must be at zero time. (If you don’t have a zero time chapter, then the rest of the chapters won’t be placed at the specified times.)
  • If you use TextEdit on Mac OS X, be sure to set plain text format by going to menu “Format–>Make Plain Text”. When saving, select the default “Unicode (UTF-8)” plain text encoding.

Before dragging the chapter file to Subler, make sure that Subler does not have any existing Chapter Track entry (you can delete the Chapter Track if it already exists). After dragging the chapter file to Subler, enabling it by checking the Chapter Track, and saving, you should see the following:

To verify the generated chapter images, open the movie file in QuickTime Player and select the “Show Chapters”. You should then see the following:

If there are any mistakes, just open the movie with Subler, delete the Chapter Track and “Photo – Jpeg” Video Track (which contains the generated chapter images), and start over with a corrected chapter text file.

For more info and advanced tips, see the following web forums and websites:

No Comments

Holy Cow, Batman! My Linux Server Got Hacked!

Linux 3 Comments

It was quiet, peaceful Tuesday night when I attempted to log into my Ubuntu Linux server as the root user. Permission denied, I got back. I tried it again. And again. Access denied. What the heck? I’m sure it was the correct password. I then tried all the passwords that it could be, from past to present. No luck. I got a sinking feeling. My root password was easy to remember and thus, easy to guess. I think my Linux server has been hacked!

No problem, I thought, I just have to reboot and log into single user mode… uh, unfortunately, my Linux server was sitting somewhere in cyberspace and I couldn’t do any of that. So I called up the service provider and they said, we didn’t touch your server and we don’t know who did. However, for $25, they can reset the root password. Having no choice, I accepted. Hours passed and finally I got an email with the new password.

I logged in, viewed the “/etc/passwd” file, and noticed two new users. Bad news, my server definitely got hacked. Good news, the hackers weren’t too sophisticated and had left a huge clue. I immediately copy the users’ info down and deleted them. Then it was off to google for what to do after a server hack. After looking at several websites, the most relevant one I found was How to restore a hacked Linux server.

What I got from the research was that once your Linux server is compromised, the best solution is to re-install the operating system. I did not want to do that because it would cost (a) money to ask the service provider to reinstall Ubuntu and (b) time for me to reinstall the applications. So I decided to play detective, find any damages, and fix them. Below are the steps I took.

1. Are there any unidentified users?

Run the following to list the users and groups:

more /etc/passwd
more /etc/group

Make a copy of the unknown users’ info, especially their usernames and ids, and delete them using the “userdel <unknown_username>” command. You should also check for and delete their home directories, located at “/home/username”.

2. Are there any strange processes running?

Run the following to list all the active processes started by the root or by the unidentified users:

ps -aef | grep root
ps -aef | grep <unknown_username>

Look for processes with weird names like “AkjwetSAG”; these are usually suspect. You can then run “lsof -p <process_id>” to get more info.

On my Ubuntu server, I found two processes, “avahi-daemon: chroot helper” and “/usr/sbin/console-kit-daemon –no-daemon”, that looked weird; but it turned out they were valid processes. After some quick online searches, I found that Avahi was used to detect network devices (not necessary for a server so it can be disabled or deleted) and console-kit was used for GUI related functions.

3. Are there any tracks left by the perpetrators?

Run the following to find any commands to change a password in the system:

cd /var/log
grep -R -i passwd *

This command returned several entries in the “auth.log” which included password changes for the unidentified user accounts. Strangely, there was no reference to a password change for the root user. By luck, there were two “Invalid user passwd from <ip_address>” messages containing the IP addresses of the perpetrators.

I then did a search on each of those two IP addresses:

grep -R -i <ip_address> *

I got back a ton of entries in “auth.log” which show numerous failed attempts using different usernames from these two IP addresses. I guess they kept trying until they got lucky. And they got lucky about five days ago.

Just for curiosity’s sake, I installed traceroute (it isn’t installed on Ubuntu by default) to see where the perpetrators came from:

apt-get install traceroute
traceroute <ip_address>

One of the IP address came from “CHINA-NETCO.edge3.SanJose1.Level3.net” and the other from “DC-PT-01-te1-2.ip4.012.net.il”. China and Israel. But there was no guarantee that those were the origins because the perpetrators could have hacked some machines there and then used those machines to hack into my server.

4. Are there any surprises left behind?

To be on the safer side, I installed and ran two rootkit scanners recommended by the website I found:

apt-get install rkhunter
rkhunter --check

apt-get install chkrootkit

Both reported a clean bill of health. There were one or two false positives which I investigated and cleared. Finally, some good news! It looks like the hackers didn’t do anything damaging (cross my fingers).

5. Any strange new files?

One of the recommended actions was to look for new files that were created since the break-in. But I didn’t find this useful at all; it was like looking for a needle in a haystack. (Funny, in real life, robbers take stuff. In cyberspace, they leave stuff… malicious stuff.)

On Ubuntu, I couldn’t find a way to search for newly created files since 5 days ago. So I did the next best thing, which was to search for files last modified in the past 5 days.

find / -mtime -5

Unfortunately, the service provider had rebooted the machine as part of the password reset. So I got a ton of results back. Too much info to process.

6. What can I do to prepare for the next assault?

First, secure the root access. I changed the root password to an incomprehensible, random string of numbers, letters (lower and upper case), and special symbols. Try guessing that! And I will only share this root password with one other person as a backup.

Second, enable auditing of the server so we will have a record of every command issued by any user. This will make it easier to figure out what actions any user, legitimate or not, does on the server. I installed the Process Accounting (psacct or acct) service which this website recommended.

apt-get install acct
service acct start

By default, the service is configured to start on bootup. To double-check, I tried using the “update-rc.d acct defaults” command but got back a strange warning “update-rc.d: warning: acct stop runlevel arguments (0 1 6) do not match LSB Default-Stop values (1)”. I didn’t know what it meant so decided to use an alternative check:

apt-get install chkconfig
chkconfig acct

This command returned “acct on”, meaning that the Process Accounting service was configured to start on bootup.

Hopefully the above info will help you should you ever encounter the same misfortune. And maybe, the last section might help you to be better prepared.


Purchasing a Wireless Router for Real People

Internet No Comments

Recently, my trusty 2.4Ghz wireless G router (a Netgear WGR614) died after many years of service. I went looking for a new router and found that the information on which router to get was not clear or conclusively. The routers that people agreed were the best cost easily over $100. I wanted an inexpensive, reliable router with a strong signal, the same or better than my old router. In the end, I got a 2.4Ghz wireless N router for $25 (a new Cisco Linksys E1000 from craigslist) that matched my needs and actually provided a stronger wireless signal.

LinksysE1000RouterTo help others avoid having to repeat my research, I will summarize my findings below. I will simplify things and that will mean leaving out some info; otherwise, this post would turn into a small book.

2.4Ghz or 5.0Ghz

Un-intuitively, the first choice is whether you want 2.4Ghz or 5.0Ghz wireless signals, not Wireless G or Wireless N. Though Wireless G can operate only in 2.4Ghz, Wireless N can operate in both 2.4Ghz and 5.0Ghz, separately (dual-band router) or simultaneously (simultaneous dual-band router). While the 5.0Ghz wireless signal supports greater bandwidth, it turns out that the 2.4Ghz wireless signal has greater range. With a lower frequency, a 2.4Ghz wireless signal will actually penetrate better through walls. The 2.4Ghz wireless signal is like a sub-woofer in how its low frequency sounds penetrate the walls and floor. Comparatively, the 5.0Ghz wireless’s high-frequency signals might bounce off a wall, rather than penetrate.

Note: A non-simultaneous dual-band 2.4Ghz/5.0Ghz Wireless N router will switch to 2.4Ghz Wireless G mode if you have just one 2.4Ghz Wireless G client device connecting. You would then end up effectively with a more expensive 2.4Ghz Wireless G router.

To compensate, 5.0Ghz Wireless N has methods to overcome such obstacles as walls. The most visible method is to use multiple antennas. Two or three antennas are common, though the newer routers have six or more. The antennas receive the 5.0Ghz wireless N signal and its many reflections (from bouncing off walls), which the router analyzes and combines into a strong signal. A second method is waveform shaping to increase the signal strength. This is similar to using a cone-shaped horn to amplify your voice. Unfortunately, like with the router, you have to know where the person you are shouting to is located so you can point the horn at him. A third method is to increase the signal spread from the standard 20Mhz to 40Mhz, similar to magically doubling the width of a clogged water pipe in order to get more water through. This would result in the router taking up double the frequency range and would only be viable if there is little or no congestion; if the pipe you are doubling the size of is right next to a bunch of other pipes, those other pipes would interfere with the size change.

Your environment will determine whether 2.4Ghz Wireless G/N or 5.0Ghz Wireless N has the most range. Currently, 2.4Ghz Wireless G/N congestion will increase the chances of interference and reduce the 2.4Ghz Wireless G/N range. Many household devices like wireless digital phones, microwaves, garage opener remotes, etc., might use the same 2.4Ghz signal. And neighbors left, right, front, and behind are getting wireless routers (almost all 2.4Ghz Wireless G/N routers because they are cheap and provided free by the Internet broadband providers). So, it might be best to go with 5.0Ghz Wireless N for now, until it too gets congested.

Tip: If you have a Windows machine, I suggest getting the free inSSIDer Home tool; the latest inSSIDer is no longer free. It will scan the 2.4Ghz Wireless G/N and 5.0Ghz Wireless N (if your Windows machine has a 5.0Ghz wireless N capable adapter) ranges and show all the wireless routers nearby. This will give you an idea of the congestion.

Single Band or Dual Band

Your devices will determine whether you can use 5.0Ghz Wireless N. If all your devices support 5.0Ghz wireless N, I would say to go with a 5.0Ghz Wireless N router. If some of your devices are 2.4Ghz Wireless G, then you might choose a 2.4Ghz wireless G/N router or if you have spending cash, a simultaneous dual-band Wireless N router. Again, simultaneous dual-band means that the wireless router handles both 2.4Ghz Wireless G and 5.0Ghz Wireless N traffic in parallel and at the same time. It is like having two routers, a 2.4Ghz Wireless G and a 5.0Ghz Wireless N router, in one. A non-simultaneous dual-band Wireless N router can operate either as a 2.4Ghz Wireless G/N or as a 5.0Ghz Wireless N router.

Note: I tested inSSIDer with a simultaneous dual-band Wireless N router (at work) which outputted both 2.4Ghz Wireless G and 5.0Ghz Wireless N signals; inSSIDer showed that the 5.0Ghz Wireless N signal was about 20% weaker than the 2.4Ghz Wireless G signal.

I have found that the SmallNetBuilder website provides the best review of wireless routers. If you don’t mind spending the money, the best router to get is the Cisco Linksys E4200 Wireless N router for about $180 retail. After that is the Netgear WNDR4000 N750 Wireless N router for $170 retail. Both are simultaneous dual-band routers.

Update: If you have the cash, get the Linksys WRT1900ACS Dual-Band Wi-Fi Router. I purchased it for my brother’s large house and the signal strengths for both 2.4Ghz and 5.0Ghz were the best (strong and solid) that he had ever ever gotten. The 5.0Ghz signal was still 10-15% weaker though.

If you get a dual band wireless router, I recommend using different SSIDs (Service Set Identifiers, a.k.a. network names) for the 2.4Ghz and 5.0Ghz signals. Some recommend using the same SSID for both and leaving it to each wireless client to pick the strongest signal to use. The wireless client could also switch signals on-the-fly to ensure the fastest connection. However, in practice, I found that due to interference on the 2.4Ghz frequency, wireless clients switching to and from the 2.4Ghz signal caused the network connections to misbehave. And some old 2.4Ghz-only wireless clients, like Sonos hubs, got very confused. So, it is best to use separate SSIDs for now.

What I Ended Up With

I decided to get a 2.4Ghz Wireless N router because my old 2.4Ghz Wireless G router worked fine (without congestion issues), none of my devices were 5.0Ghz Wireless N capable, and I didn’t want to spend more than $50. In the end, buying a wireless router is like playing Russian roulette. I went on craigslist and searched for name brand wireless routers like Linksys, Netgear, and D-Link. I found a sweet deal, a brand new Cisco Linksys E1000 2.4Ghz Wireless N router for $25 (50% off retail price), and managed to purchase it. (The Linksys E1000 supports Wireless N on the 2.4Ghz frequency so I consider it essentially a Wireless G router.)

Setup was a breeze. I plugged the Linksys E1000 into the wall outlet, connected my laptop by Ethernet cable to it, browsed to the E1000’s default gateway address, logged in (had to google for the default user/password which was blank user and “admin” password), and manually configured it. (I did not run the software on the included CD.) I setup up the same WPA-Personal security as my old router’s configuration. I manually forced Wireless G only mode (since any one of my Wireless G device connecting would force this), selected 20Mhz range (since WPA-Personal and Wireless G mode would force this), and channel 11 (it worked well in the old router and inSSIDer showed it was the best option).

After I finished configuring the router, I was pleasantly surprised to find that the 2.4Ghz Wireless G signal was significantly stronger than my old router’s signal. Machines at the back of the house that showed low connectivity before were now reporting good connectivity. The inSSIDer tool on my desktop (about 15 feet and two walls from the router) showed an increase from -50db to -40db in signal strength.

Finally, a cautionary tale on wireless repeaters which are devices used to extend the wireless range. It is like shouting to a friend, who then repeats the message to a second friend further away. A few years ago, I tried to use a Linksys WRE54G wireless G extender with my Netgear WGR614 wireless G router. It worked and boosted the wireless signal, but after a few minutes, my Netgear router went dead and needed to be rebooted. This consistently happened and I could only conclude that the Netgear router and Linksys extender did not like each other. Probably, compatibility is a lot better now. However, if you decide to get an extender, I would recommend getting the same brand as the router’s or getting something you can easily return. This gives me a thought… The Linksys WRE54G extender could get rid of my neighborhood wireless congestion if I were to use it to “helpfully” extend (aka “kill”) the neighbors’ routers. But that would be too evil.

Good luck with your wireless router purchase.

No Comments

Post a Movie File On Your Website

Internet No Comments

If you have ever wanted to post a movie on your website (instead of using Youtube and other similar services), the steps below might help you get started. I will provide instructions for converting a movie AVI file from my digital camera into a Flash Video (FLV) file for posting on a web page.

019MickeyMagicMy camera, a Canon SD870 IS, produces video files in AVI (Audio Video Interleaved) format. The videos are 640×480 at 30 frames per second (at about 18mbps bitrate) and mono audio at 44kHz sample rate (at 705kbps bitrate). The bitrate and audio bitrates, in combination with the other attributes, determine the video and audio quality. For example, at a higher bitrate, a video frame will look much sharper with less artifacts. Also, the video and audio bitrates together determine how much bandwidth you would use to play the movie when streaming it. Knowing this info will come in useful when we do the movie conversion below.

The goal is to convert the AVI movie file into a FLV movie file which is much smaller and supports streaming playback (which allows the user to view the movie as it downloads). As an example, I have an AVI file which is 17 seconds long and 30MB in size. I will want to convert that down to a 2-4MB FLV file size (1/10 the original size) with a 1-1.5mbps video bitrate and at most 96kbps audio bitrate. These bitrates should be easily handled by users who are using DSL or cable Internet broadband services. To maintain video quality, I will also switch the video to be 15 frames per second while keeping the same 640×480 resolution.

There are two free utilities that you will need to download and install:

  • MediaInfo supplies technical information (resolution, frame rate, bitrate, sample rate, etc.) about a video and/or audio file.
  • Free FLV Converter to convert from AVI (and others) to FLV format.
    Note: When installing, select “Custom Installation” and unselect the two Searchqu install options!

First, run MediaInfo and open the original movie file. Take note of the video bitrate, video resolution, video frames per second (fps), audio bitrate, audio sample rate, and number of channels (mono 1 vs stereo 2). When you set the target FLV attributes, you will want to pick values which are equal to or less than the original values. You can keep MediaInfo opened to refer to.

Second, run “Free FLV Converter” and click on the “Conversion to FLV” button at the top middle. Browse to and select the original movie file; AVI file in my case. Unfortunately, the “Free FLV Converter” does not use the original file’s video/audio attributes. Instead, in the “Output configuration”, I had to make the following changes:

  • Change Video Size from 320×240 to 640×480.
  • Change Video Bitrate from 386 to 1500. (I tried keeping it at 386 and the resulting FLV movie was extremely pixelated. Even at 800, it was still too pixelated for my taste.)
  • Change Frame rate from 25 to 15.

I left the Audio settings of Frequency (aka sample rate) at 44100 and Bitrate at 96 Kbps. Hit the Convert button to convert to FLV format.

The “Free FLV Converter” utility will save the converted FLV movie file (with the same name as the original file but a .flv extension) to the desktop. The resulting file size is 3.5MB. If the file had been bigger, I would need to reduce the FLV target settings further. In addition, the utility will nicely generate an example HTML file (with same name as the video file), a FLVPlayer.swf (a Shockwave Flash movie player), and a Skin.swf (skin for the Flash movie player) file. Open the HTML file in a browser to play the FLV movie. Hopefully, the quality of the generated movie is good.

You can use the generated HTML file as-is or as a reference. To use as-is, just copy the generated FLV movie file, the HTML file, the FLVPlayer.swf, and the Skin.swf to your website. You will want to upload the four files into the same online directory. To use as a reference, copy-paste the <object> definition from the generated HTML to your own HTML page. You will still need to copy the FLVPlayer.swf and Skin.swf files to your website.

Note: If you use another FLV conversion software and notice that the download progress bar on the movie player (dark grey background) doesn’t advance, then it may be that the software did not add the appropriate meta data to the FLV file. In this case, you can use flvmdi.exe tool to add the missing metadata.

The settings used above worked for me. You may wish to adjust for your needs accordingly. Have fun!

No Comments

Compile VLC Player for Android on Mac OS X Snow Leopard

Mac OS X 4 Comments

vlcplayerIn this post, I will outline the steps necessary to compile the VLC Player for Android devices. As a pre-requisite, please see my post about installing Eclipse Indigo for Android Development on Mac OS X Snow Leopard.

Prepare Your System for VLC Compilation:

  1. Download the latest Apple Xcode development tool suite. Xcode is required by MacPorts below. (I downloaded Xcode 4.0.2 and iOS SDK 4.3)
    • Update: For the latest Xcode 4.5.1 (which I installed from the Mac App Store), after you install it, you will need to manually install the “Command Line Tools” which are required by Macports. To do so: go to Xcode->Preferences, Downloads, and click on “Install” for “Command Line Tools”.
    • (You will need to create a free Apple account, if you don’t already have one. This can be the same as your iTunes account.)
    • Double-click on the downloaded “xcode_4.0.2_and_ios_sdk_4.3.dmg” to mount the disk image.
    • It will show up on your desktop as a new drive “Xcode and iOS SDK”. Open the drive (if it doesn’t automatically open), launch the “Xcode and iOS SDK.mpkg” file, and follow the installation wizard instructions.
  2. Download the latest MacPorts which is an open-source utility to make it easy to download, install, and upgrade open-source software such as subversion, wget, etc. We will need it to set up the environment for VLC android compilation. (I downloaded “MacPorts-2.0.0-10.6-SnowLeopard.dmg”)
    • Look under “Mac OS X Package (.pkg) Installer” section for the dmg installable image for Snow Leopard.
    • Double-click on the downloaded “MacPorts-2.0.0-10.6-SnowLeopard.dmg” to mount the disk image.
    • It will show up on your desktop as a new drive “MacPorts-2.0.0”. Open the drive (if it doesn’t automatically open), launch the “MacPorts-2.0.0.pkg” file, and follow the installation wizard instructions.

    Periodically, you can run this command in a Terminal to update MacPorts and the programs which it has installed.

    sudo port -v selfupdate
    sudo port -v upgrade outdated

    To see the programs installed and managed by MacPorts, run this command in a Terminal:

    sudo port installed
  3. Open up a new Terminal and use MacPorts to install the following utilities:
    sudo port install wget
    sudo port install autoconf
    sudo port install libtool
    sudo port install pkgconfig
    sudo port install subversion

    The first installation, wget, will take a long time so just have patience.
    Note: After installing programs using MacPorts, you will want to re-start the Terminal before using these command line tools.

Install Subversion Eclipse Plugin (Subclipse)

Optionally, add support for subversion in Eclipse:

  1. Install the subversion JavaHL bindings which is required by the Eclipse subversion plugin.
    sudo port install subversion-javahlbindings
    • Updated Note: Macports’ latest subversion-javahlbindings 1.7.x works fine with Eclipse Juno.
    • Note: Macports’ recent upgrade of subversion-javahlbindings to version 1.7.1 (from 1.6.17) broke Subclipse compatibility with Eclipse Indigo. If you use Eclipse Indigo, you will want to install the JavaHL 1.6.x bindings from Collabnet Website instead.
  2. Run Eclipse.
  3. Go to Eclipse menu Help->Install New Software…
  4. Input “http://subclipse.tigris.org/update_1.8.x” into the “Work with” field and the table will be updated with installation packages available at that location. (You can check what is the latest subclipse here.)
  5. Check just the “Subclipse” package and click Next, Next, accept the license, Finish.
    • Note: If the first Next button freezes Eclipse with a message saying that it is “Calculating requirements…”, then it may be that one or more Eclipse update sites are unreachable. If you encounter this, you may need to force quit Eclipse (canceling doesn’t seem to unfreeze it). Restart Eclipse, repeat these steps, but uncheck the “Contact all update sites during install to find required software” before clicking on the first Next button.
  6. If the Security Warning dialog about the “unsigned content” appears, click Ok to accept.
  7. Click on “Restart Now” to restart Eclipse.

Download and Compile VLC

We will download and install VLC android according to the VideoLan website’s VLC Android Compile directions. I will repeat the relevant instructions below with my additional notes. Please double-check the instructions below against the VideoLan website because the VideoLan instructions are updated continually.

  1. Get the VLC source using Git. Run the following on a newly opened Terminal in the directory (ex: “~/projects”) where you want to download VLC android to:
    git clone git://git.videolan.org/vlc/vlc-android.git

    This operation will take a long time. By default, it will create a subdirectory called “vlc-android”. If you don’t like that, then add the custom subdirectory name as an additional argument to the end of the “git clone” command. Alternatively, you can always rename the “vlc-android” subdirectory afterwards.

  2. Configure 3rd party modules for android compilation:
    cd vlc-android/extras/contrib
    ./bootstrap -t arm-eabi -d android

    This step will create the following files: config.mak, distro.mak (softlink to src/Distributions/android.mak), Makefile (softlink to contrib.mak), toolchain.cmake. Also, the following directories are created: build (softlink to hosts/arm-eabi), build-src, hosts.

    • Hint: It looks like you can edit “distro.mak” to enable/disable 3rd party module compilation by editing the “all” target to include/exclude projects.
  3. Retrieve 3rd party modules from the internet (which uses the wget and subversion that we had installed with MacPorts) and compile them for Android. Under the same “vlc-android/extras/contrib” directory, run:

    Some things to watch for:

    • With the VLC version I got, the make command failed with an error:
      RTSPServerSupportingHTTPStreaming.cpp:69: error: invalid conversion from 'long unsigned int*' to 'const time_t*'

      I fixed it by modifying the “./build-src/live/liveMedia/RTSPServerSupportingHTTPStreaming.cpp” file (you will need to chmod it first to make it modifiable) and inserting an explicit cast “(const time_t*)” in the call to gmtime: “gmtime((const time_t*)&sb.st_mtime)”.

    • The make will retrieve the 3rd party module source code under the “./build-src” subdirectory and will generate the library files under the “./hosts/arm-eabi/lib” subdirectory. The corresponding library headers can be found under the “./hosts/arm-eabi/include” subdirectory.
  4. Configure the main VLC codebase for Android compilation:
    • First before you do anything else, go back to the original root “vlc-android” git clone directory. The VideoLan website neglects to include this step. Assuming that you created “vlc-android” under your home directory, run these commands:
      cd ~/vlc-android

      This step will create these files: ABOUT-NLS, aclocal.m4, config.h.in, configure, Makefile.in. And will create a directory, autom4te.cache, and add these files to the autotools directory: compile, config.guess, config.sub, depcomp, install-sh, ltmain.sh, missing. Additionally, the Makefile.in file is added to directories: bin, compat, doc, all subdirectories under libs, m4, modules (including most subdirectories of), share, src, test. Finally, directories m4 and po got other miscellaneous files.

    • Create our own build directory and prepare it to hold the compiled VLC classes:
      mkdir build
      cd build

      This step will create a bunch of files and directories under the “build” directory. The most important files are:

      • config.h – contains directives to customize the build; the variable CONFIGURE_LINE will reflect the enable/disable directives from configure.sh.
      • Makefile – builds the Android-compatible static .a library files for enabled modules

      Hint: Before running “../extras/package/android/configure.sh”, you can edit it to enable/disable modules. Search for “–enable” or “–disable” and adjust accordingly. When enabling/disabling 3rd party libraries, please make sure that your changes here matches the changes you made to “distro.mak” earlier.

  5. Compile VLC and configure Android JNI generation:
    • Run this command to compile the VLC source code (it will take a long time before completing).
      ./compile -k

      This program uses GNU libtool to compile the VLC source and prepare it to generate a shareable library (or dynamically-linked library). As a result, besides the standard object .o files and static library .a files, you will see .libs and .dep subdirectories and .la, .lo, and .Plo files required by libtool. Most of these files will be created under the build directory’s src and modules subdirectories.

    • Create the NDK makefile and build the VLC JNI library for Android by running these commands:
      cd ../extras/package/android
      VLC_BUILD_DIR=../../../build make

      Things to note:

      • Under the “vlc-android/extras/package/android/vlc-android” directory, you will see the following new subdirectories: bin, gen (contains auto-generated Android java sources like R.java), libs (contains libvlcjni.so which is the VLC shared library), and obj. In addition, you will see the following new files: local.properties, jni/Android.mk (NDK makefile) and jni/libvlcjni.h (declare VLC plugins). (Android.mk and libvlcjni.h should only contain the enabled modules matching your changes to “distro.mak” earlier.)
      • If you did not name your “build” directory as “vlc-android/build”, then you will need to adjust the value for VLC_BUILD_DIR in the command above accordingly. If you ran the above command with the wrong VLC_BUILD_DIR, run the following commands to cleanup before re-running the make again:
        make clean
        rm vlc-android/jni/Android.mk

        The “make clean” deletes the bin, libs, and obj subdirectories but neglects to delete jni/Android.mk which makes use of the VLC_BUILD_DIR variable.

Compile and Deploy the Android VLC Player

  1. Launch Eclipse.
  2. Create a new project by doing the following:
    • Select menu File->New->Project…
    • Select Android->Android Project. Click Next.
    • Click on “Create project from existing source”.
    • Press the Browse… button and locate the “vlc-android/extras/package/android/vlc-android” directory.
    • Update “Project name” field to “vlc-android” (or whatever you want). Press the Finish button.
  3. The new “vlc-android” project will be created and will appear under the Eclipse Package Explorer left-most pane. The Eclipse ADT plugin will automatically compile the newly-imported vlc-android project and prepare it for deployment. Hopefully you don’t see any errors.
  4. Deploy the VLC Player to an Android device:
    • Connect your Android device to your Mac. You can double-check that the Android device is recognized by opening up a Terminal and running the follow ADB command:
      adb devices

      You should see your Android device listed with a 12 alphanumeric characters long identifier.

    • Locate “vlc-android” project under the Eclipse Package Explorer pane.
    • Right-click on “vlc-android” project and select “Run As”->”1 Android Application”. Eclipse ADT will deploy the VLC Player to your Android device and launch it.
    • If you have more than one Android device connected or you have created an emulator (VLC Player cannot run under an emulator), you will need to configure Eclipse ADT to allow you to manually select the Android device to deploy to:
      • Right-click on “vlc-android” project and select “Run As”->”Run Configurations…”.
      • “Android Applications”->”vlc-android” should already be selected.
      • Click on Target tab and check the Manual radio button.
      • Hit Apply and Close buttons.

Using the Android VLC Player

  1. Before running the VLC Player, you will need to prepare some movies for it to play.
    • You can download some Android compatible movie trailers here. If you create your own sample movie files, I recommend making sure the video encoding, video resolution, audio encoding, audio sample rate are supported by your Android device.
    • Copy the video files to your SD card under a directory called “movies”. You can remove the SD card from the Android device and stick it into your computer to copy the movies over. Or you can use ADB to copy the video files to the Android device over USB like so:
      adb shell
      cd sdcard
      mkdir movies

      adb push movie1.mp4 /sdcard/movies
      adb push movie2.mp4 /sdcard/movies
    • Launch VLC Player on your Android device. You will get a notice that it is alpha software; just click ok.
    • You will get the main VLC page with the message “No Media Files”. Fix that by doing the following on the Android device:
      • Touch the menu button and select Preferences.
      • Tap on Directories, on “sdcard”, and on the checkbox to the left of “movies”.
      • Touch return three times to get back to the main VLC page.
      • A list containing the movies and their preview images should appear.
    • Select a movie to play it.

Modifying VLC Source and Re-compiling the Android VLC Player

If you wish to modify VLC source code without having to redo the long compilation from scratch, below are some hints. Suppose that you wish to rebuild after modifying the “vlc-android/modules/video_filter/rotate.c” file:

  1. Force the rebuild of the object files related to “rotate.c” by doing the following under the “vlc-android/build” directory:
    cd build
    find . -name "*rotate*.*" -print | xargs rm
    ./compile -k
    ./compile -k

    The “./compile -k” is run twice because the first time, the libtool will error out because the dependency file .Plo will be missing. However, libtool generates the missing .Plo file all the same. The second time will succeed. (For cases where the .Plo file is not required by libtool, the first run will succeed.)

  2. Rebuild the Android NDK JNI related files by doing the following:
    cd ../extras/package/android
    make clean
    VLC_BUILD_DIR=../../../build make
  3. In Eclipse, right-click on the “vlc-android” project and select Refresh.
    • Note:If the “vlc-android” project starts throwing a bunch of “Cannot resolve type” class errors, you will need to tell Eclipse that it is okay to rebuild class files which have been modified externally (by our script commands above). To do so, enable the ”Rebuild class files modified by others” option under menu “Eclipse->Preferences–>Java–>Compiler–>Building–>Output folder”.
  4. Use Eclipse to re-deploy VLC Player to your Android device.
    • Note: I have seen instances where the re-deploy does not update the VLC Player on the Android and there are no error messages from Eclipse. If I suspect that, then I will manually uninstall VLC Player (on Android, tap “Settings->Applications->Manage applications->VLC media player->Uninstall”) from the Android device and then do a fresh deployment from Eclipse. As a shortcut, you can do this by opening a Terminal and running the following commands:
      adb uninstall org.videolan.vlc.android
      cd vlc-android/extras/package/android/vlc-android/bin
      adb install vlc-android.apk

Tips for Developing and Debugging with Android

  • To run the ndk-build script directly, you can do the following:
    cd vlc-android/extras/package/android/vlc-android/jni
    $ANDROID_NDK/ndk-build -B V=1

    The “-B” flag indicates a rebuild and the “V=1” flag enables verbose output.

  • VLC Player and other applications (including your own) may output debug traces to the adb logger (called logcat). (Under native C code, use msg_Dbg and msg_Err statements. Under Java, use the android.util.Log class.) Under Elipse, you can display the logger debug traces in real-time by going to menu “Window->Show View->Other…->Android->LogCat”. (Note: Under Eclipse, the filter only works on the Message text field.) Alternatively, you can open up a Terminal and run “adb logcat”.
  • Check CPU usage on the Android by opening a Terminal and running “adb shell top -m 5”.
  • Show the library dependencies by opening a Terminal and running “otool -L libvlcjni.so”. (The otool utility is the Mac OS X equivalent of the Linux ldd or readelf utilities.)

That’s it. Hope that you have fun developing with Android.


« Previous Entries