Android WiFi porting

Source: Internet
Author: User

 

Very detailed Android WiFi porting article

 

The 8686 WiFi wpa_driver_priv_driver_cmd failed problem on the Development Board is serious, and the scanning problem cannot be reached.

 

Http://blog.linuxconsulting.ro/2010/04/porting-wifi-drivers-to-android.html

 

For mini-box.com picopc we want to support several USB and minipci WiFi dongles, this Guide provides a step by step explanation of what's involved in adding a new WiFi driver and making WiFi work in a custom Android build (This guide was written for Android 2.1 but shoshould be applicable to previous Android releases and hopefully future releases ).

Contents

0. Understand how Android wifi works.
1. enable building of wpa_supplicant in your boardconfig. mk
2. (optional) Enable debug for wpa_supplicant.
3. Provide a proper wpa_supplicant.conf for your device
4. Have the correct paths and permissions created from init. RC
5. Make sure your wpa_supplicant and dhcpcd (optional) are starting from init. RC
6. Provide your driver either as a module or built in kernel and proper Kernel support for it and modify Android Source Code accordingly.
7. Provide a firmware if your module needs it.
8. Make your driver work with Android custom wpa_supplicant commands and siocsiwpriv IOCTL

Now onto details.


0. Understand how Android wifi works.

Android uses a modifiedWpa_supplicant(External/wpa_supplicant) daemon for WiFi support which is controlled through a socket byhardware/libhardware_legacy/WiFi/wifi. C (wifihw) that gets controlled from Android UI throughAndroid.net. WiFiPackage fromframeworks/base/WiFi/Java/Android/NET/WiFi/and it's corresponding JNI implementation in frameworks/base/CORE/JNI/android_net_wifi_wifi.cpp higher level network management is done in frameworks /base/CORE/Java/Android/Net


1. enable building of wpa_supplicant in your boardconfig. mk

This is by simply adding: board_wpa_supplicant_driver: = wext
To your boardconfig. mk. This will set wpa_build_supplicant to true in
External/wpa_supplicant/Android. mk enabling building of driver_wext.c
If you have a custom wpa_supplicant Driver (like madwifi or my custom Android private commands emulation-see last paragraph) You can replace wext with awext or your driver name (madwifi, Prism etc ).

2. (optional) Enable debug for wpa_supplicant.

By default wpa_supplicant is set to msg_info that doesn't tell much. To enable more messages:
2.1 modify common. C and set wpa_debug_level = msg_debug
2.2 modify common. h and change # define wpa_printf from if (level)> = msg_info) to If (level)> = msg_debug)

3. Provide a proper wpa_supplicant.conf for your device

Providing a wpa_supplicant.conf it's important because the control socket for Android is specified in this file (ctrl_interface = ). this file shoshould be copied by your androidboard. MK to $ (target_out_etc)/WiFi (usually/system/etc/WiFi/wpa_supplicant.conf ). this location will be used on wpa_supplicant service from init. RC.

There are two different ways in which wpa_supplicant can be configured, one is to use a "private" socket in Android namespace, created bysocket_local_client_connect () function in wpa_ctrl.c and another is by using a standard UNIX socket.

Minimum Required config options in wpa_supplicant.conf:

-Android private socket

Ctrl_interface = wlan0
Update_config = 1

-UNIX standard socket

Ctrl_interface = dir =/data/system/wpa_supplicant group = WiFi
Update_config = 1

Depending on your driver you might also want to add:

Ap_scan = 1

If you have AP Association problems with shocould change to ap_scan = 0 to let the driver do the association instead of wpa_supplicant.

If you want to let wpa_supplicant connect to non-WPA or open wireless networks (by default it skips these kind) Add:

Network = {
Key_mgmt = none
}

4. Have the correct permissions and paths created from init. RC

Incorrect permisions will result in wpa_supplicant not being able to create/open the control socket and libhardware_legacy/WiFi/wifi. c won't connect.
Since Google modified wpa_supplicant to runWiFiUser/group the directory structure and File Ownership shoshould belong to wifi user/group (seeos_program_init () function in wpa_supplicant/OS _unix.c ).

Otherwise errors like:

E/wifihw (): Unable to open connection to supplicant on "/data/system/wpa_supplicant/wlan0": no such file or directory will appear.

Also wpa_supplicant.conf showould belong to wifi user/group because wpa_supplicant will want to modify this file. if your system has/system as read-only use a location like/data/MISC/WiFi/wpa_supplicant.conf and modify wpa_supplicant service in init. RC with new location.

Make sure the paths are correctly created in init. RC:

Mkdir/system/etc/WiFi 0770 WiFi
Chmod 0770/system/etc/WiFi
Chmod 0660/system/etc/WiFi/wpa_supplicant.conf
Chown WiFi/system/etc/WiFi/wpa_supplicant.conf
# Wpa_supplicant control socket for Android wifi. C (Android private socket)
Mkdir/data/MISC/WiFi 0770 WiFi
Mkdir/data/MISC/WiFi/sockets 0770 WiFi
Chmod 0770/data/MISC/WiFi
Chmod 0660/data/MISC/WiFi/wpa_supplicant.conf
Chown WiFi/data/MISC/WiFi
Chown WiFi/data/MISC/WiFi/wpa_supplicant.conf

If you useUNIX standard socketIn wpa_supplicant.conf (see abve) Add:

# Wpa_supplicant socket (UNIX socket mode)
Mkdir/data/system/wpa_supplicant 0771 WiFi
Chmod 0771/data/system/wpa_supplicant
Chown WiFi/data/system/wpa_supplicant

Do not add these if you use Android private socket because it will make wpa_supplicant non-functional, becausehardware/libhardware_legacy/wifi. c check for existence of the/data/system/wpa_supplicant folder and will pass a wrong Interface Name towpa_ctrl_open () function.

5. Make sure your wpa_supplicant and dhcpcd are starting from init. RC

For wpa_supplicant the init. RC startup like shocould be depending on which path you chosen:

-Android private socket:

Service wpa_supplicant/system/bin/wpa_supplicant-dd-dwext-iwlan0-C/system/etc/WiFi/wpa_supplicant.conf
Socket wpa_wlan0 dgram 660 WiFi
Group system WiFi inet
Disabled
Oneshot

-UNIX standard socket:

Service wpa_supplicant/system/bin/wpa_supplicant-dd-dwext-iwlan0-C/system/etc/WiFi/wpa_supplicant.conf
Group system WiFi inet
Disabled
Oneshot

If your wifi driver creates a WiFi interface with other name than wlan0 you will have to modify the above line accordingly.

You also shocould have dhcpcd starting from init. RC
Service dhcpcd/system/bin/dhcpcd wlan0
Group system DHCP
Disabled
Oneshot

6. Provide your driver either as a module or built in kernel and proper Kernel support for it.

First make sure that config_packet and config_net_radio (wireless extensions) are enabled in your kernel. the driver can be built as module (default android way) or built in kernel (if you want to rely in kernel auto probing to support multiple driver eg. USB WiFi) but will require source code modifications (see below ).

-As kernel module:

Define in your boardconfig. mk:

1. wifi_driver_module_path: = path to the module to be loaded

You need to specify Module name in that path too, usually shoshould look something like/system/lib/modules/WLAN. Ko

2. wifi_driver_module_name: = the name of the network interface that the driver creates, for example wlan0

3. wifi_driver_module_arg: = any arguments that you want to pass to the driver on insmod, for example nohwcrypt


Make sure you copy your kernel module when building android to the correct location.

-As built in kernel:

-First init. RC needs to be modified to inform Hardware/libhardware_legacy/WiFi/wifi. c about the name of the interface, that the driver is already loaded and set the status of wpa_supplicant to running:

Setprop wifi. Interface "wlan0"
Setprop WLAN. Driver. Status "OK"

DoNotAdd setprop init. SVC. wpa_supplicant "running" as I previusly mentioned as it will prevent wpa_supplicant from starting from init.

-Secondly Hardware/libhardware_legacy/WiFi/wifi. c need to be modified so the functions insmod () and rmmod () return 0 (simply add return 0; as the first line in functions since they are not needed when driver is built in kernel) and return before checking for/proc/modules in check_driver_loaded () function.

You might encounter problems with wifihw module not being able to connect to wpa_supplicant socket even with the correct permisions. Try to turn off/turn on WiFi from the GUI.

7. Provide a firmware if your driver needs it

If your driver needs a firmware you will have to copy this firmware file to/etc/firmware on your android build. android doesn't use a standard hotplug binary (although there is an implementation available on android-x86 system/code/toolbox/hotplug. c) instead the INIT process takes care of firmware events and loads the firmware file from/etc/firmware (see: System/CORE/init/devices. c handle_firmware_event () function ).
Firmware file name is defined by the driver and might also contain a folder like: rtl8192su/rtl8192sfw. Bin, entire file path shocould be available in/etc/firmware


8. Make your driver work with Android custom wpa_supplicant commands and siocsiwpriv IOCTL.

Android uses siocsiwpriv IOCTL to send commands to modify driver behaviour and receive information like signal strength, MAC address of the AP, link speed etc. this IOCTL is usually not implemented in any known wireless drivers limit t bcm4329 which is in Google MSM kernel branch.

The errors from not having this IOCTL implemented will look like:

E/wpa_supplicant (): wpa_driver_priv_driver_cmd failed wpa_driver_priv_driver_cmd Arg Len = 4096
E/wpa_supplicant (): wpa_driver_priv_driver_cmd failed
D/wpa_supplicant (): wpa_driver_priv_driver_cmd linkspeed Len = 4096
E/wpa_supplicant (): wpa_driver_priv_driver_cmd failed
I/wpa_supplicant (): CTRL-EVENT-DRIVER-STATE hanged

After 4, wext_number_sequential_errors errors, Android will abort using the device.

To quickly test your wifi from interface you can disable error checking in external/wpa_supplicant/driver_wext.c by simply making ret = 0; wait () function after the siocsiwpriv IOCTL call. this will make all access points in Android UI appear without signal or MAC address.

To proper implement the ioctl you will need to modify your kernel driver to reply to siocsiwpriv IOCTL with signal strength and macaddr commands being the most important.

A better way is to add a custom driver_xxx.c to Google external/wpa_supplicant/implementing evaluate, with the rest of the functions being called from driver_wext.c.

Below is a link to a patch for wpa_supplicant that I did for mini-box.com picopc Android build. It creates a new driver awext which "emulates" android driver commands using wireless extensions IOCTLs.

How to use the new driver:

1. In your boardconfig. mk define: board_wpa_supplicant_driver: = awext
2. Change init. RC wpa_supplicant service command line by replacind-dwext with-dawext

Awext driver patch download: 0001-added-a-separate-driver-awext-to-emulate-android-dri.patch

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.