WiFi Details (v)

Source: Internet
Author: User

1 Android platform WiFi module porting Essentials 1.1 WiFi structure

User interface

Android Wifiservice

Wpa_supplicant

DHD Driver

Dongle Binary

Bcm43xxhardware

Blue: Need to be modified

Black: No Modification required

The blue part is for the Android environment, support BCM43XX chip needs to modify the section, the functions of the various parts are as follows:

1. User interface (interface layer): controls and sets the user interface layer of WiFi

2. Android WiFi service: It is part of the WiFi services in Android system, mainly used to start and stop wpa_supplicant, and as a bridge between the user interface layer and wpa_supplicant interaction exists

3. Wpa_supplicant: external libraries that support WPA and WAPI

4. DHD driver:driver for WiFi module

5. Dongle binary:bcm43xx firmware

6. bcm43xx:WiFi hardware Chip (is a combined integrated chip)

1.2 WiFi Module Environment

The WiFi module environment includes the following sections:

1. bcm43xx Drive Source Code

2. Wpa_supplicant and Support WAPI's Wapilib library

3. Nvram.txt (bcm43xx chip configuration file)

4. wpa_supplicant.conf and WiFi firmware

Generally, the documents of the third and IV conditions are included in the bcm43xx source code.

1.3 Wi-Fi module compilation 1.3.1 WiFi driver source

This is not a particular type of BCM43XX chip and Android version as a special case to explain the Wi-Fi module compilation process, only the general part of the compilation to do a brief description.

In general, the WiFi module can be compiled in two red ways: First, the internal compilation, and the second is the module compilation. The module compilation is usually used, and the module compiles the WiFi module as an example to illustrate the process of compiling the WiFi module.

In the WiFi module driver source code, mainly contains the following directories:

Firmware: It will provide the firmware corresponding to the BCM43XX chip.

Config: Provide wpa_supplicant.conf and nvram.txt as well as dhcpcd.conf, and android.mk files. If you do not have the above configuration file, you need to locate the directory.

ANDROID.MK: This is a file that is also the gateway to compile the Android platform to compile the WiFi module

Src:wifi Drive Source Directory

In fact, you see the Broadcom to provide the driving source may be organized in a way that is different from the above, but the approximate content of the above is only for the module source code in the directory and file for different purposes to illustrate.

1.3.2 Add bcm43xx driver on Android platform

To compile the WiFi module on the Android platform, first add the source code of the WiFi module to the directory under the Android platform. As to where to add is not fixed, generally will be added to the vendor directory under a directory, the following we put bcm43xx module source under Vendor/xxxx/wlan/bcm43xx (xxxxx represents the product name). You know, before adding the source code, this bcm43xx directory does not exist, it needs to be created manually, and in this directory to create Android and SRC two directories:

pc$ cd<android_root>

pc$ mkdir‐p vendor/xxxx/wlan/bcm4325/

pc$ cdvendor/xxxx/wlan/bcm4325/

pc$ mkdirandroid src

pc$ ls

Android SRC

After creating the above directory, you can add bcm43xx in the directory of the relevant source code, SRC Store is the driver source code, the main storage of the Android directory firmware (that is, two-level mirror), compiled files (android.mk), configuration files (Nvram.txt and Wpa_ supplicant.conf) and so on.

Add good related source code, still need to do some modification work (mainly to the compilation file modification), otherwise the module can not be normal compilation, ANDROID.MK content modification operation as follows.

pc$ cp<work>/bcm4325_source/open‐src/src/dhd/android/config/android.mk

<android_root>/vendor/xxxx/wlan/bcm4325/android

pc$ cd<android_root>/vendor/xxxx/wlan/bcm4325/android

pc$ viandroid.mk//Get here, find the Android.mk file, the file contents are as follows

......

#

# Install WLAN Driver, firmware, and configurationfiles.

#

Local_target_dir: =$ (TARGET_OUT_ETC)/firmware//Here defines the path of Local_target_dir, which will be used later

########################

Local_path: = $ (call My-dir)

Include $ (clear_vars)

Local_module: =sdio-g-cdc-reclaim-idsup-wme-ccx-wapi.bin

Local_module_tags: = User Development

Local_module_class: = ETC

Local_module_path: = $ (Local_target_dir)

Local_src_files: = $ (Local_module)

Include $ (build_prebuilt)

########################

Include $ (clear_vars)

Local_module: = Nvram_4325b0.txt

Local_module_tags: = User Development

Local_module_class: = ETC

Local_module_path: = $ (Local_target_dir)

Local_src_files: = $ (Local_module)

Include $ (build_prebuilt)

########################

Include $ (clear_vars)

Local_module: = Dhd.ko

Local_module_tags: = User Development

Local_module_class: = ETC

Local_module_path: =$ (target_out)/lib/modules

Local_src_files: = $ (Local_module)

Include $ (build_prebuilt)

########################

Include $ (clear_vars)

Local_module: = wpa_supplicant.conf

Local_module_tags: = User Development

Local_module_class: = ETC

Local_module_path: = $ (TARGET_OUT_ETC)/wifi

Local_src_files: = $ (Local_module)

Include $ (build_prebuilt)

########################

Include $ (clear_vars)

Local_module: = dhcpcd.conf

Local_module_tags: = User Development

Local_module_class: = ETC

Local_module_path: =$ (TARGET_OUT_ETC)/dhcpcd

Local_src_files: = android_dhcpcd.conf

Include $ (build_prebuilt)

########################

It is necessary to explain the above: the definition of Local_module and Local_module_path is the place to be modified here. Certain of the changes to Local_module_path, but it relies primarily on variables already defined with the Android platform, such as Target_out _etc and Target_out. Local_module defines the object to be manipulated, as well as the previously mentioned configuration file, the compiled driver module binaries and firmware, and so on.

The purpose of this file is to copy individual files to a defined place for use by driver modules and wpa_supplicant. 、

For the driver source code, the user can use the customized WiFi chip management function to turn off and turn on the WiFi module, in the DHD/SYS/DHD_CUSTOM_GPIO.C file has the following function definition:

#define CUSTOMER_HW

#ifdef CUSTOMER_HW

extern void Bcm_wlan_power_off (int);

bcm43xx bcm43xx Porting Guide for Android System

Broadcom Corporation Proprietary and confidential

9

extern void bcm_wlan_power_on (int);

#endif/* CUSTOMER_HW */

So the user can use their own custom switch function, or use BCM43XX's own switch function to control the WiFi module switch. If you use a custom switch function, you need to define these two functions in the platform-related code:

Path:kernel/arch/arm/mach‐xxx/board‐xxxx.c

......

void Bcm_wlan_power_off (int onoff);

void bcm_wlan_power_on (int onoff);

......

In the previous android.mk modification, there is a copy operation to the Dhd.ko, which means that the module binaries generated by the source code should be temporarily copied to the place indicated in Android.mk. This temporary copy operation is executed in the dhd/linux/makefile of the driver source code compiled file.

pc$ CD<ANDROID_ROOT>/VENDOR/XXXX/WLAN/BCM4325/SRC

pc$ VI dhd/linux/makefile +315

Modules: $ (ofiles)

Test-r./makefile | | Ln–s $ (srcbase)/dhd/linux/makefile.26./makefile

$ (make)-C $ (linuxdir) m=$ (shell pwd) $ (if $ (VERBOSE), v=1) modules

CP $ (kmodules) $ (srcbase)/. /android/.

The next step is to put the WiFi module source in the top-level directory of the Android.mk file into the bcm43xx directory, it is the Android compilation portal file, indicating that when compiling Android, this WiFi driver module is included in the entire Android compilation system. Its content is as follows:

pc$ CD <android_root>/vendor/xxxx/wlan/bcm4325/

pc$ Vim Android.mk

Ifeq ($ (board_wlan_device), bcm43xx)

Include $ (callall-subdir-makefiles)

endif

Very simply, if the board_wlan_device is defined as bcm43xx, call all-subdir-makefiles function to include all subdirectories under the Android.mk file, which is the rule of Android compiler system.

The final step, then, is to define Board_wlan_device as bcm43xx in the relevant platform configuration file, file path:vendor/xxxx/xxxx/boardconfig.mk.

1.3.3 Build WiFi Drive source code

Before compiling the WiFi drive source code, the first to establish the kernel environment, that is, to compile the WiFi module before compiling kernel, because the module's compile-time dependencies and the kernel.

The kernel compiles as follows:

pc$ CD <android_root>/kernel

pc$ make Arch=arm cross_compile=<android_root>/prebuilt/

Linuxx86/toolchain/arm‐eabi‐4.4.0/bin/arm‐eabi‐xxxx_defconfig

pc$ make arch=armcross_compile=<android_root>/prebuilt/

Linuxx86/toolchain/arm‐eabi‐4.4.0/bin/arm‐eabi‐zimage

If you set up the environment variables for arch and cross_compile, you can omit the definitions of these two options and use the Make command to generate the zimage directly.

After compiling the good kernel, you can enter the bcm43xx source directory Dhd/linux, There are two files in this makefile and makefile.26, if there is no makefile file will makfeile.26 copied into the Makfile file (actually created a symbolic link file), of course, also do the previous Dhd.ko temporary copy of the command added. In this directory, enter the following command to compile the module source code:

pc$ CD<ANDROID_ROOT>/VENDOR/XXXX/WLAN/BCM4325/SRC

pc$ CD dhd/linux/

pc$ make Arch=armlinuxdir=<android_root>/kernel

Cross_compile=<android_root>/prebuilt/linux‐x86/toolchain/arm‐eabi‐

4.4.0/bin/arm‐eabi‐dhd‐cdc‐sdmmc‐gpl

The last command adds a command option Linuxdir, which tells the location of the compiled file kernel, enters the kernel makefile file to do the setup work, and then returns the makefile file under that directory for compilation.

Here bcm43xx driver Source code has been compiled, you can go to the Android directory to see if there is no Dhd.ko file generation, if any, that is, the compilation is successful, otherwise review the compilation process error message, resolve the error problem and then compile until the compilation is successful.

1.3.4 using bcm43xx in Android

The previous procedure just adds the bcm43xx driver source to the Android system, but it takes a while to use it in Android. The places that need to be modified are already marked with a blue background at the beginning, where we want to see exactly which files to modify.

1.3.4.1 HARDWARE/LIBHARDWARE_LEGACY/WIFI/WIFI.C

Make appropriate modifications to the BCM43XX driver module. WIFI.C exists as an important role in loading the WiFi driver module and starting off Wpa_supplicant, and in order for WiFi to work better, some variable parameters in the file must be set appropriately (according to Wpa_supplicant.conf).

pc$ VI hardware/libhardware_legacy/wifi/wifi.c

......

#define Wifi_driver_module_path

"/system/lib/modules/dhd.ko"

......

#define WIFI_DRIVER_MODULE_NAME "DHD"

......

#define Wifi_driver_module_arg

"Firmware_path=/etc/firmware/sdio-g-cdc-reclaim-idsup-wme-ccxwapi.

Bin Nvram_path=/etc/firmware/nvram_4325b0.txt "

......

#define WIFI_TEST_INTERFACE "Eth0"

......

static const char iface_dir[] = "";

......

static const char supp_config_template[]=

"/data/misc/wifi/wpa_supplicant.conf";

......

static const char supp_config_file[] =

"/etc/wifi/wpa_supplicant.conf";

......

The red part above is a specialized definition of the WiFi driver, and different WiFi drivers will have different definitions. The modifications also include the path to the firmware and the configuration file, as well as the associated definition of the interface name.

wifi_test_interface defines the interface name of the Wpa_supplicant and UI, which is used when a WIFI interface name error is obtained through the Property_get () function. The interface name obtained by the Property_get () function is the wifi.interface of the interface definition in the Init.xx.rc file:

SetProp wifi.interface "Eth0"

supp_config_template defines a temporary file for the wpa_supplicant configuration file. supp_config_file Defines the configuration file that is used by the Wpa_supplicant runtime, and changes to the WiFi configuration are maintained in this file.

Iface_dir is the directory of the Wpa_supplicant control interface, the interface is used by the UI to connect to Wpa_supplicant, this directory is determined by the wpa_supplicant, in fact, This interface is actually a socket, created at wpa_supplicant startup, Wpa_supplicant_ctrl_iface_init ()

There are two ways to create this socket interface:

(1) socket for Android system

It uses the wpa_%ctrl_interface% combination to define its own name, through Socketwpa_eth0 dgram ... command to generate (in init.rc), if this socket is used, the interface name in the following code must be always:

Ctrl_interface=eth0 (in wpa_supplicant.conf)

"Socket Wpa_eth0 ..." (In init.*.rc)

SetProp wifi.interface "Eth0" (in init.*.rc)

Wpa_supplicant‐ieth0 ... (In init.*.rc)

At this point, the definition of iface_dir is null.

(2) Special socket

The wpa_supplicant will create a control interface socket through the Ctrl_interface directory in the wpa_supplicant.conf, which is generally defined as: "ctrl_interface=dir=/data/misc/ .... ", the name of this socket is passed by the"-i "parameter of wpa_supplicant, and if the socket is used this way, the following variable definitions must be consistent:

ctrl_interface=dir=/data/misc/(in wpa_supplicant.conf)

iface_dir=/data/misc/(in Wifi.c)

1.3.4.2 kernel/arch/arm/mach‐xxx/board‐xxxx.c

Add a Power Management section to the bcm43xx driver, which is not described in detail here.

1.3.4.3 system/core/rootdir/etc/init.xxx.rc

To support the BCM43XX driver module, modify the Wpa_supplicant service. The contents of the Init.xxx.rc file are generally as follows:

pc$ VI system/core/rootdir/etc/init.xxx.rc

...//Add Android System interface

# to enable WiFi

SetProp wifi.interface "Eth0"

# End of WiFi

...//Modify permissions for wpa_supplicant.conf

chmod 0660/etc/wifi/wpa_supplicant.conf

Chown WiFi wifi/etc/wifi/wpa_supplicant.conf

... start command for//wpa_supplicant service

Service Wpa_supplicant/system/bin/logwrapper

/system/bin/wpa_supplicant-dwext-ieth0-

C/etc/wifi/wpa_supplicant.conf

...//Modify the socket interface for Wpa_supplicant

Socket wpa_eth0 Dgram 660 WiFi wifi

...//Modify DHCP interface

Service DHCPCD/SYSTEM/BIN/DHCPCD-BKL eth0

......

1.3.4.4 vendor/xxxx/xxxx/boardconfig.mk

Add configuration variables for the bcm43xx driver.

pc$ VI vendor/xxxx/xxxx/boardconfig.mk

......

Ifneq ($ (build_tiny_android), true)

......

Board_wpa_supplicant_driver: = Wext

Board_wlan_device: = bcm43xx

ENDIF #! Build_tiny_android

......

Support for BCM43XX's WAPI also requires a series of modifications, which are not described in detail here.

2 Summary

The recent period of time on the WiFi module learning, let me have more knowledge of WiFi, but these are not enough. For the WiFi module, need to know a lot of things, here only the principle of its work and workflow and the porting process is simply elaborated, there are many aspects not summarized, such as: the implementation of the protocol layer and process, as well as the details of data transmission and SDIO related content, etc. These in the actual WiFi module work may need us to further analysis and grasp, although the understanding of WiFi may not be in place, but for this period of time to learn to do a summary, but also helpful, I hope to have the opportunity to learn more in-depth WiFi module.

In the WiFi module debugging process will also appear a series of problems, these problems can be summed up into different types, these types of problems to do analysis and summary, can help us in the future debugging work to quickly locate the problem.

The understanding of WiFi is far from enough, hope and WiFi interest and has become a master of the colleagues can have more communication.

WiFi Details (v)

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.