Android platform-WiFi function porting

Source: Internet
Author: User

I. Basic architecture of WiFi

1. WiFi user space programs and libraries:
External/wpa_supplicant/
Generate libwpaclient. So and wpa_supplicant. 2. Hardware/libhardware_legary/WiFi/is the WiFi management library. 3. JNI:
Frameworks/base/CORE/JNI/android_net_wifi_wifi.cpp 4. Java part:
Frameworks/base/services/Java/COM/Android/Server/
The frameworks/base/WiFi/Java/Android/NET/WiFi/5 and WiFi settings applications are located:
Packages/apps/settings/src/COM/Android/settings/WiFi/2. How does WiFi work in Android use a modified version of wpa_supplicant as daemon to control WiFi, the code is located in external/wpa_supplicant. Wpa_supplicant uses
Hardware/libhardware_legacy/WiFi/wifi. c Communication. The UI uses android.net. WiFi package
(Frameworks/base/WiFi/Java/Android/NET/WiFi/) send a command to wifi. C.
The corresponding JNI implementation is located in frameworks/base/CORE/JNI/android_net_wifi_wifi.cpp.
The higher level of network management is in frameworks/base/CORE/Java/Android/net.

3. Configure android to support WiFi and add it to boardconfig. mk:
Board_have_wifi: = true
Board_wpa_supplicant_driver: = wext

This will set wpa_build_supplicant to true in external/wpa_supplicant/Android. mk,
Driver_wext.c is used by default.
If you use a custom wpa_supplicant Driver (such as madwifi), you can set:
Board_wpa_supplicant_driver: = madwifi

4. Enable wpa_supplicant. The default value of wpa_supplicant is msg_info. to output more information, you can modify the following parameters:
1. Set wpa_debug_level = msg_debug in common. C;
2. in common. C, set the # define wpa_printf macro
If (level)> = msg_info)
Change
If (level)> = msg_debug) 5. Configure wpa_supplicant.conf

Wpa_supplicant uses ctrl_interface = in wpa_supplicant.conf to control the socket. You should configure copy to $ (target_out_etc)/WiFi (that is,/system/etc/WiFi/wpa_supplicant.conf) in androidboard)
This location will be detected again in init. RC.
The general wpa_supplicant.conf configuration is as follows:
Ctrl_interface = dir =/data/system/wpa_supplicant group = WiFi
Update_config = 1
Fast_reauth = 1
Sometimes, the driver needs to be added:
Ap_scan = 1 if an AP connection problem occurs, you need to modify ap_scan = 0 to connect the driver, instead of wpa_supplicant.

To connect to non-WPA or open wireless networks, add:
Network = {
Key_mgmt = none
} 6. wpa_supplicant with the configuration path and permission modified by Google should run under WiFi users and groups. The code shows the OS _program_init () function in wpa_supplicant/OS _unix.c.

If the configuration is incorrect, the following error occurs:
E/wifihw (): Unable to open connection to supplicant on "/data/system/wpa_supplicant/wlan0": no such file or directory will appear.
 
Check that init. RC has the following Configuration:
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 socket
Mkdir/data/system/wpa_supplicant 0771 WiFi
Chmod 0771/data/system/wpa_supplicant
# Wpa_supplicant control socket for Android wifi. c
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 if the/system directory of the system is read-only, use the path/data/MISC/WiFi/wpa_supplicant.conf.

7. Run wpa_supplicant and dhcpcd

Make sure the following statements are available in init. RC:
Service wpa_supplicant/system/bin/logwrapper/system/bin/wpa_supplicant-dd-dwext-iwlan0-C/data/MISC/WiFi/wpa_supplicant.conf
User Root
Group WiFi inet
Socket wpa_wlan0 dgram 660 WiFi
Oneshot service dhcpcd/system/bin/logwrapper/system/bin/dhcpcd-D-B wlan0
Disabled
Oneshot: Based on the name of the WiFi driver used, change wlan0 to the name of the driver.

7. Compile WiFi driver as module or kernel built in 1. Compile as module
Add the following in boardconfig. mk:
Wifi_driver_module_path: = "/system/lib/modules/ar6000.ko"
Wifi_driver_module_arg: = "" # For example nohwcrypt
Wifi_driver_module_name: = "ar6000" # For example wlan0
Wifi_firmware_loader: = ""

2. Compile as kernel built in
1) In hardware/libhardware_legacy/WiFi/wifi. C, modify the interface name,
2) Add the following in init. RC:
Setprop wifi. Interface "wlan0"
3) When insmod/rmmod is in hardware/libhardware_legacy/WiFi/wifi. C,
Return 0 directly.
 
8. Firmware Android required by WiFi does not use the standard hotplug binary. Firmware required by WiFi must be copied to/etc/firmware.

Or copy to the location specified by the WiFi driver, and then the WiFi driver is automatically loaded. 9. Modify the WiFi driver. The wpa_supplicant modified by Android requires siocsiwpriv IOCTL to send commands to the driver and receive information, such as signal strength, MAC address of the AP, and link speed. Therefore, to correctly implement the WiFi driver, you need to return the information of the signal strength and macaddr from the siocsiwpriv IOCTL. If IOCTL is not implemented, the following error occurs:
E/wpa_supplicant (): wpa_driver_priv_driver_cmd failed

Wpa_driver_priv_driver_cmd EAP 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

10. Set dhcpcd. conf

Generally, the configuration of/system/etc/dhcpcd. conf is as follows:
Interface wlan0
Option subnet_mask, routers, domain_name_servers

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.