1 system diagram
The above figure is got from the web thank to the author J
wpa_supplicant is in external directory, wifi is in hardware/libhardware_legacy/wifi
OK, let us focus on interfaces between different module.
There exists four type interfaces in android wifi system:
1) AIDL interface between WifiManager and WifiService
2) JNI interface between WifiNative and Wifi
3) Domain Socket interface between wpa_client used by Wifi and wpa_supplilcant
4) ioctrl interface between wpa_supplicant and wifi driver
this is aidl interface between different process. the interface is defined in IWifiManager:
interface IWifiManager
{
boolean enableNetwork(int netId, boolean disableOthers);
boolean startScan(boolean forceActive);
boolean setWifiEnabled(boolean enable);
boolean setWifiApEnabled(in WifiConfiguration wifiConfig, boolean enable);
…
…
…
}
setWifiEnabled function will enable the wifi network, its invocation sequence is as the following:
the invocation flow is WifiManager-(AIDL)->WifiService-(JNI)->WifiNative-(socket)->WPA_CTRL
setWifiApEnabled the invoke flow is as the following:
Netd::SoftapControoller will invoke ioctrl function on mSock, and transfer the necessary property : like passwd, channel ).
mSock is created in the following way:
mSock = socket(AF_INET, SOCK_DGRAM,0)
3 JNI interface between WifiNative and Wifi
public class WifiNative {
public native static boolean loadDriver();
public native static boolean unloadDriver();
public native static boolean startSupplicant();
public native static boolean connectToSupplicant();
…
…
}
4 domain socket interface between wpa_client and wpa_supplicant
this interface is mainly defined in wpa_ctrl.h
struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path);
void wpa_ctrl_close(struct wpa_ctrl *ctrl);
int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
char *reply, size_t *reply_len,
void (*msg_cb)(char *msg, size_t len));
int wpa_ctrl_attach(struct wpa_ctrl *ctrl);
int wpa_ctrl_detach(struct wpa_ctrl *ctrl);
int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len);
int wpa_ctrl_pending(struct wpa_ctrl *ctrl);
int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl);
void wpa_ctrl_cleanup(void);
these interface use domain socket to communicate.
5 some tips when integrate wifi on android
start parameter of wpa_supplicant
wpa_supplicant -Dwext -imlan0 -c/data/misc/wifi/wpa_supplicant.conf
1)driver with wifi module is wext
2)ifname is mlan0
3)confname is /data/misc/wifi/wpa_supplicant.conf,
wpa_supplicant config file:
##### wpa_supplicant configuration file #####
update_config=1
ctrl_interface=/data/system/wpa_supplicant
eapol_version=1
ap_scan=1
fast_reauth=1
here, control unix domain socket of wpa_supplicant is at /data/system/wpa_supplicant/mlan0