I have been learning about Android WiFi for a week. Today, I will post my daily learning achievements for future reference, from the framework to the adaptation layer of wpa_supplicant (WiFi. c) There are many posts on the Internet, and they are not complicated. The framework part should be noted in the wifiservice and wifimoniter sections, one is the CMD of the forwarding AP, and the other is the CMD from wpa_supplicant. They connect to the local database through the JNI method. The specific implementation method is in android_net_wifi_wifi.cpp. In this file, we can roughly see which commands the AP will give to wpa_supplicant. These commands are run through WiFi. c's wifi_command is sent to wpa_supplicant. During the command sending process, wpa_ctrl_request is called to complete the command sending. wpa_ctrl_request communicates with wpa_supplicant through socket, then, wpa_ctrl_recv is used to receive the command from wpa_supplicant and return the command ID to wifi_wait_for_event.
However, since wpa_supplicant is a standard open-source project, it has been transplanted to many platforms, I haven't looked at the intermediate process yet. The concern is how wpa_supplicant sends the command to the driver after receiving the upper-layer command, the parsing action of the driver after receiving the command, the process of calling the driver function, and the details of the driver's register control. Because the code should be kept confidential, I will not mention which WiFi chip is used or the platform or product on which the Wi-Fi driver is.
First paste a standard wpa_supplicant structure diagram:
Focus on the lower part of the block diagram, that is, how wpa_supplicant is connected with the driver. The whole process is currently dominated by the scan Command issued by the AP. Since most WiFi drivers currently support wext, we assume that our devices use the wext line. In fact, the process is similar to that of NDIS.
First, there is a struct wpa_driver_ops in the driver. h file:
/**
* Struct wpa_driver_ops-Driver Interface API Definition
*
* This structure defines the API that each driver interface needs to implement
* For core wpa_supplicant code. All driver specific functionality is captured
* In this wrapper.
*/
Struct wpa_driver_ops
This struct is declared in driver. C:
# Ifdef config_driver_wext
Extern struct wpa_driver_ops wpa_driver_wext_ops;/* driver_wext.c */
Then, fill in the struct member in driver_wext.c,
Const struct wpa_driver_ops wpa_driver_wext_ops = {
. Name = "wext ",
. DESC = "Linux wireless extensions (generic )",
. Get_bssid = wpa_driver_wext_get_bssid,
. Get_ssid = wpa_driver_wext_get_ssid,
. Set_wpa = wpa_driver_wext_set_wpa,
. Set_key = wpa_driver_wext_set_key,
. Set_countermeasures = wpa_driver_wext_set_countermeasures,
. Set_drop_unencrypted = wpa_driver_wext_set_drop_unencrypted,
. Scan = wpa_driver_wext_scan,
. Combo_scan = wpa_driver_wext_combo_scan,
. Get_scan_results2 = wpa_driver_wext_get_scan_results,
. Deauthenticate = wpa_driver_wext_deauthenticate,
. Disassociate = wpa_driver_wext_disassociate,
. Set_mode = wpa_driver_wext_set_mode,
. Associate = wpa_driver_wext_associate,
. Set_auth_alg = wpa_driver_wext_set_auth_alg,
. Init = wpa_driver_wext_init,
. Deinit = wpa_driver_wext_deinit,
. Add_pmkid = wpa_driver_wext_add_pmkid,
. Remove_pmkid = wpa_driver_wext_remove_pmkid,
. Flush_pmkid = wpa_driver_wext_flush_pmkid,
. Get_capa = wpa_driver_wext_get_capa,
. Set_operstate = wpa_driver_wext_set_operstate,
# Ifdef android
. Driver_cmd = wpa_driver_priv_driver_cmd,
# Endif
};
These members are actually the interfaces of the driver and wpa_supplicant. Take scan as an example:
Int wpa_driver_wext_scan (void * priv, const u8 * SSID, size_t ssid_len)
Line1174: If (IOCTL (DRV-> ioctl_sock, siocsiwscan, & IWR) <0) from here we can see that wpa_cupplicant uses IOCTL to call socket to communicate with driver, and issue the siocsiwscan command to the driver.
In this way, the route for a command from the AP to the framework to the local C ++ library and then to the wpa_supplicant adaptation layer, and then the CMD command under wpa_supplicant to the driver is connected, although not much written, it is also a small achievement.
It's been a very short time. It's been three weeks since I graduated. I regret that I didn't learn about WiFi in the lab. Now I have to start from scratch. Fortunately, the company environment is relatively easy, so you can have time to grasp the details. Later, we will begin to clarify the structure and process of the driver.