Jelly Bean WiFi Research (1)

Source: Internet
Author: User

I have nothing to do recently. I have studied the workflow of jelly bean wifi.

1. The first step is to enable the WiFi process.

Packages/apps/settings/src/COM/Android/settings. java will hold a wifienabler. java object. When you click the switch control of WiFi, mwifienabler is called. setswitch (holder. switch _), and then go to wifienabler to check it.

The 102 and 104 lines are the switch control UI that controls wifi.

To enable WiFi, you need to see here: oncheckedchanged (...)

First, judge the status of the statte machine event. If you have clicked the mstatemachineevent, it seems that it has always been false. It doesn't matter.

Then check that WiFi (line 1) is not supported in airplane mode, and Jelly Bean (114) source code is supported.

If the Wi-Fi AP is enabled, it is disabled (121 ~ 125 rows)

All preparations are completed. Last thing to do: Turn on WiFi (126 rows)

The wifimanager calls the setwifienabled method in the wifiservice. It calls the setwifienabled method in the wifistatemachine. {You need to continue to follow up here, corresponding to wifi. int wifi_wait_for_event (char * Buf, size_t buflen )}

The setwifienabled method in the wifistatemachine sends messages. sendmessage puts messages containing the pai_load_driver and wifi_state_enabling parameters into the message queue. It will be received in handlemessage (knowing the statemachine mechanism is not hard to read)

The actual execution is in the internal class of driverunloadingstate mwifinative. loaddriver ().

Check out the local method:

Public native static Boolean loaddriver ();

Just a simple line. Haha. Now let's look at JNI. Frameworks/base/CORE/JNI/android_net_wifi_wifi.cpp

Please refer to this line: {"loaddriver", "() Z", (void *) android_net_wifi_loaddriver}

The corresponding Java method is loaddriver (), and the method in JNI is android_net_wifi_loaddriver (). Check whether the method in C is wifi_load_driver () and the return value is bool.

Static jboolean android_net_wifi_loaddriver (jnienv * ENV, jobject)
{
Return (jboolean) (: wifi_load_driver () = 0 );
}

At this point, the Java layer has been completed, and the next step is to look at the underlying processing.

1. to load the module wifi_load_driver, read the WiFi Hal interface section of appending first. ======================================== Appending ====================== ============ 1. the wifi Hal interface is defined in Android/hardware/libhardware_legacy/include/hardware_legacy/wifi. in the H file, there is a detailed explanation of the Hal layer interface. The specific functions of the function are implemented in Android/hardware/libhardware_legacy/WiFi/wifi. C. The interface is mainly used to communicate with wpa_supplicant. The Wi-Fi control flow information must pass through wpa_supplicant. For data streams, the classic TCP/IP model is generally used. 2. The role of wpa_supplicant in wireless network security is divided into two objects: Supplicant (requester) and authenticator (authenticator ). We use supplicant that includes the WPA encryption protocol. Here, Supplicant is a daemon. Supplicant is mainly responsible for managing encryption and network connections. More specifically, it is the link layer. Therefore, this type of problem is usually encountered during debugging. You can also pay attention to the four-way handshake protocol between supplicant and authenticator. In the <link layer details> that I sent you, I will provide a detailed introduction. 3. ipv80211 and nl80211 protocols are a set of protocols used in combination. It is used for the communication between the supplicant of the WLAN device and the kernel layer. The Supplicant layer uses the nl80211 protocol to encapsulate functions and data. The underlying driver uses the 201780211 protocol to encapsulate the upper layer of data. The protocol communication uses the Netlink mechanism (socket is mainly used for communication between Linux kernel and userspace ).

Return to the Java layer. If the driver load succeeds, statemachine is notified to change the status.

Change the status to loaded.

After loaded is successful, the state machine does not need to do anything. Here, only a log is played.

Continue!

Review the setwifienabled method in wifistatemachine

Check Row 3. when processing the cmd_start_supplicant message, it is processed in the driverloadedstate class.

It will perform a series of operations, including

Wifinative. startsupplicant ()
Mwifimonitor. startmonitoring ();

Row 2383,2385.

Let's take a look at the second line of mwifimonitor. startmonitoring ()

It will enable a thread to listen to the WiFi event, without saying anything, directly paste the Code (Part), the event source wifinative. waitforevent (). {Continue here, corresponding to int wifi_wait_for_event (char * Buf, size_t buflen) in wifi. c )}

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.