How to add wireless interface on Android

I’m configuring Android to add support to wireless adapter. Unfortunately it is not easy as it is on Linux. Let walk through the process:

I started compiling Linux kernel with support to my wireless adapter RT73, basically my kernel has:

CONFIG_WLAN_80211=y
CONFIG_RT2X00=y
CONFIG_RT73USB=y
CONFIG_RT2X00_LIB_USB=y
CONFIG_RT2X00_LIB=y
CONFIG_RT2X00_LIB_FIRMWARE=y
CONFIG_RT2X00_LIB_CRYPTO=y
CONFIG_RT2X00_LIB_RFKILL=y
CONFIG_RT2X00_LIB_LEDS=y

Other big mistake was the firmware path, in Linux kernel it is placed at /lib/firmware. I lost some time to figure out the right place it /etc/firmware:

$ adb push rt73.bin /etc/firmware/

After than I try to start-up wifi on Android shell this way:

# netcfg wlan0 up

Arggg, “no donuts for you” 😩

Finally I found more some nice tips here:
http://vinayharugop.blogspot.com/2009/02/android-wifi-driver-integration.html

Again, more issues, wpa_supplicant binary doesn’t exist. After a little more researches I found the problem: I need to inform to it be build: Edit external/wpa_supplicant/Android.mk and modify:

WPA_BUILD_SUPPLICANT := true

Compile Android again.

Create a wpa_supplicant.conf (in fact just modify the ti_wlan0 one) adding your wireless interface (wlan0 in my case):

ctrl_interface=wlan0

Connect in your AP:

# wpa_cli ... set_network 0 ssid "your_ap_name"
#wpa_cli ... set_network 0 key_mgmt WPA-PSK
#wpa_cli ... set_network 0 pairwise CCMP TKIP
#wpa_cli ... set_network 0 psk "makemeveryverysecret"

Configure route and DNS:

# route add default gw 192.168.0.254 dev wlan0
# setprop net.dns1 8.8.8.8

An useful thread about this topic is here:
http://www.mail-archive.com/android-porting@googlegroups.com/msg09574.html

Tips:

When trying to turn Wi-Fi ON using Android setting, I was getting this error message:

"unable to start Wi-Fi"

Then using “adb logcat” I can see the error:

"E/WifiService( 1935): Failed to load Wi-Fi driver"

Then I figured out the issue, Android wants loads the driver by itself, because I place the driver built-in into kernel, it will work at console, but will not work on graphic mode.

I saw some people suggesting adding it on init.rc:

setprop wlan.driver.status "ok"
setprop init.svc.wpa_supplicant "running"

Unfortunately it didn’t worked to me.

Then I changed the wifi driver to module on Linux kernel and modified “hardware/libhardware_legacy/wifi/wifi.c” to load that driver for me:

#ifndef WIFI_DRIVER_MODULE_PATH
#define WIFI_DRIVER_MODULE_PATH         "/system/lib/modules/rt73usb.ko"
#endif
#ifndef WIFI_DRIVER_MODULE_NAME
#define WIFI_DRIVER_MODULE_NAME         "rt73usb"
#endif

Also I copied the modules files (rt2x00lib.ko, rt2x00usb.ko, rt73usb.ko) to “/system/lib/modules” and called insmod to them in init.rc

UPDATE: Nicu Pavel created a great tutorial explaining more about Wireless on Android:
http://blog.linuxconsulting.ro/2010/04/porting-wifi-drivers-to-android.html

Advertisements

7 thoughts on “How to add wireless interface on Android

  1. Hi,
    I am trying to do something similar to you, in that I am trying to port the p54 drivers over to Android. I am using a USB dongle, so in the kernel I enabled the appropriate driver. I have 2 questions.

    1.) why did you include the rt200xx driver in the kernel configuration? is this required for all usb dongles, or just specifically for the driver you are using?

    2.) you mentioned that you pushed the “rt73usb.ko” file to the android filesystem using adb. where did the rt73usb.ko file reside on your computer? i did a search for all files with a .ko extension but I couldn’t find p54usb.ko

    Thanks

  2. Hi Kiran,

    You need to include RT2X00 driver because it is prerequisite to RT73. I did a mistake, I need to select RT73 as module (CONFIG_RT73USB=m) instead of built-in.

    In you case you need put P54 as module in order to generate .ko.

    BR,

    Alan

    1. Hi Alan,
      Thanks for responding so quickly. I compiled the kernel w/ p54 as a module (it shows M instead of *), and in the help option in the kernel, it says that the module will be called p54usb. I can’t find the p54usb.ko file though… Is it bundled inside the uImage?

      Thanks again!

      1. Hi Kiran,

        I reproduced it here and I found the module file at:

        linux-kernel/drivers/net/wireless/p54/p54usb.ko

        Make sure you select these items are selected in your .config:
        CONFIG_CFG80211=y
        CONFIG_CFG80211_WEXT=y
        CONFIG_MAC80211=y
        CONFIG_P54_COMMON=y
        CONFIG_P54_USB=m

        Best Regards,

        Alan

  3. Hey Alan,
    Thanks again for helping out. I had a mistake in my kernel configuration, as I was trying to build P54_COMMON as a module as well the P54_USB. I changed P54_COMMON from ‘m’ to ‘y’. I tried recompiling, and didn’t notice the kernel modules.

    I then decided to compile the kernel without the uImage option at the end. By default, the makefile is creating a zImage, and when I checked the drivers/net/wireless/p54 folder, i saw the p54usb.ko file. I tried investigating in the makefile, but am relatively new to makefiles and linux in general so I didn’t understand too much.

    Finally, I decided to make the kernel with the uImage option as:
    make ARCH=arm CROSS_COMPILE=arm-eabi- -j8 uImage
    After this, I found the make modules command on the internet and did that:
    make ARCH=arm CROSS_COMPILE=arm-eabi- j8 modules

    This created all the kernel modules.

    Anyways, thanks a lot for helping me out. Hopefully I can get this wifi off the ground soon!

  4. I want to connect to my smartphone und an wifi sensor node.(using an App).
    i want to read data from sensor node.
    do you have any idea how to find/connect other devices on a WiFi network ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s