Android phones use both Wi-Fi and data traffic

Source: Internet
Author: User

Android phones use both Wi-Fi and data traffic

As everyone knows, when the phone is successfully connected to a Wi-Fi hotspot, the Internet traffic generated by the phone is transmitted over Wi-Fi, and mobile traffic is disabled. However, we now have a special business need to let the phone successfully connected to Wi-Fi can also walk data traffic (such as 3G, 4G).

    • Android phones use both Wi-Fi and data traffic
        • Background introduction
        • Related research
        • Find method
        • Implementation method
        • Drive Wi-Fi using Wireless-tools mode
          • Preparatory work
          • To start the Wi-Fi module by command
          • Issues to be solved
        • Drive Wi-Fi using wpa_supplicant mode
          • Preparatory work
          • To start the Wi-Fi module by command
          • Issues to be solved
        • Summarize

Background introduction

The company's theme business is the development of the communication base station, I need to develop a software to match the base station test work. After connecting to the server via the Wi-Fi hotspot via the Android phone, a server is required to send commands over the Wi-Fi Channel to allow the phone to do the corresponding data traffic test. To meet this demand, we need to make the phone's Wi-Fi and data traffic work at the same time.

Related research

In normal use, we found that when the phone is connected to a Wi-Fi hotspot, the network card associated with the mobile phone will be dropped.
Turn off Wi-Fi for your phone, and when you open data traffic, use the NETCFG command to see the status of the NIC:
You can see that the Rmnet0 NIC status is: Up and has been successfully assigned to the IP address

Turn on the Wi-Fi status for your phone, this time the data traffic will automatically shut down, but the Wlan0 network card will be assigned an IP address:

The ideal state is that the Wlan0 and Rmnet0 are both up and can be DHCP to the address at the same time, so that network access can be guaranteed at the same date, as shown in the ideal state:

Find method

To implement the two NICs at the same time, I think of two ways:
-1, the mobile phone first successfully connected Wi-Fi hotspot, this time then manually set the Rmnet0 NIC to up status, and assign an IP address.
-2, the mobile phone uses data traffic, then we manually load the Wlan0 driver, finally let the network card can be successfully assigned to the IP address.

This is the two way I think about it, and in the follow-up study, I used the second method. is to manually load the Wlan0 kernel.

Implementation method

In Android, there are two ways to do this: Wpa_supplicant and the way you use Wireless-tools.
-Wpa_supplicant:wpa_supplicant is an open source project source code, was modified by Google to join the Android mobile platform, it is mainly used to support WEP,WPA/WPA2 and WAPI wireless protocol and encryption authentication, And the actual work is through the socket (whether the wpa_supplicant and the upper or the wpa_supplicant and drivers are using socket communication) and the driver to report data to the user, and the user can send commands through the socket to Wpa_ supplicant transfer drive to operate on WiFi chip. The advantage is: can support a variety of encryption mode WiFi base station, the disadvantage is: All drivers are not supported.

    • Wireless-tools:wireless Tools for Linux is a Linux command-line toolkit for setting up wireless devices that support the Linux wireless extension. The advantages are: support for almost all wireless network cards and drivers, the disadvantage is: can not connect to those who only support WPA, the router is set to WEP encryption method to connect.
Drive Wi-Fi readiness using the Wireless-tools method

1, need to pre-compile wireless-tools (please refer to "android4.2 WiFi driver Add and Debug").
2, after the completion of the compilation to get Libiw.a,iwlist,iwconfig files.
3. Using the ADB tool provided by Android, through the push command:
Put the libiw.a file into the/system/lib directory;
Put the iwlist,iwconfig file into the/system/bin directory;
EX:ADB Push E:\libiw.a/system/bin

To start the Wi-Fi module by command

Emphasize that the following commands must be executed sequentially.
1. Load Wlan0 Drive:
Command: Insmod/system/lib/modules/wlan.ko

2. Set the Wlan0 NIC to the UP state:
Command: Netcfg wlan0 up

3. Scan AP Hotspot:
Command: iwlist wlan0 scan

4, connect AP hotspot:
Command: Iwconfig wlan0 essid Hello
The "Hello" here is the name of the hotspot.

5. Assign IP address dynamically to Wlan0:
Command: Netcfg wlan0 DHCP

6, another: through Netcfg and Ifconfig wlan0, can see the status of the network card. The NIC is now up and can be assigned to an IP address normally.

Issues to be solved

1, through the test found: when WiFi through WPA\WPA2 encryption, it is not possible to connect to the WiFi hotspot in this way, as mentioned in the above: wiretool-tools This command can only be used to encrypt routers using WEP.

Drive Wi-Fi readiness using the Wpa_supplicant method

Because Google added the Wpa_supplicant module to the Android system, we no longer need to add additional packages

To start the Wi-Fi module by command

1. Load Wlan0 Drive:
Command: Insmod/system/lib/modules/wlan.ko

2. Set the Wlan0 NIC to the UP state:
Command: Netcfg wlan0 up

3. Connect Wlan0 network card to WiFi hotspot:
Command: Wpa_supplicant-iwlan0-c/data/misc/wifi/wpa_supplicant.conf–b

4. Assigning IP addresses to Wlan0
Command: Netcfg wlan0 DHCP

Issues to be solved

1. This method was successfully tested on Huawei G716, but failed to use on other mobile devices. The problem that is currently being fixed is: "Wpa_supplicant-iwlan0-c/data/misc/wifi/wpa_supplicant.conf–b" This sentence is not executed correctly.

Summarize

This article is mainly about how to get the Android phone to start the Wi-Fi module manually

Android phones use both Wi-Fi and data traffic

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.