但是命令发到wpa_supplicant后的流程网上提到的资料就非常少了,不过由于wpa_supplicant是一个标准的开源项目,已经被移植到很多平台上,它中间的过程我暂时还没有去细看。比较关心的是wpa_supplicant在接收到上层的命令后是怎么将命令发给DRIVER的,DRIVER在接收到命令后的解析的动作以及之后调用驱动功能函数的流程以及驱动对寄存器控制的细节。由于需要注意代码保密,之后不会提及具体使用了哪块WIFI芯片也不会提及此WIFI DRIVER是在什么平台什么产品。
先贴一张wpa_supplicant的标准结构框图:
重点关注框图的下半部分,即wpa_supplicant是如何与DRIVER进行联系的。整个过程暂以AP发出SCAN命令为主线。由于现在大部分WIFI DRIVER都支持wext,所以就假设我们的设备走的是wext这条线,其实用ndis也一样,流程感觉差不多。
首先要说的是,在/src/drivers/driver.h文件中有个结构体wpa_driver_ops:
/**
* 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
这个结构体在/src/drivers/driver.c中被声明为:
#ifdef CONFIG_DRIVER_WEXT
extern struct wpa_driver_ops wpa_driver_wext_ops; /* driver_wext.c */
然后在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
};
这些成员其实都是驱动和wpa_supplicant的接口,以SCAN为例:
int wpa_driver_wext_scan(void *priv, const u8 *ssid, size_t ssid_len)
中的LINE1174:if (ioctl(drv->ioctl_sock, SIOCSIWSCAN, &iwr) < 0)从这里可以看出wpa_cupplicant是通过IOCTL来调用SOCKET与DRIVER进行通信的,并给DRIVER下达SIOCSIWSCAN这个命令。
这样,一个命令从AP到FRAMEWORK到C++本地库再到wpa_supplicant适配层,再由wpa_supplicant下CMD给DRIVER的路线就打通了,写起来虽然不多但也是一点小成果。