struct wpa_global* wpa_supplicant_init(struct wap_params* params)
{
struct wpa_global* global;
init ret, i;
...
#ifdef CONFIG_DRIVER_NDIS
.... // windows driver支持
#endif
#ifdef CONFIG_NO_WPA_MSG
// 设置全局回调函数
.....
ret = eap_register_methods();
#endif
}
static wpa_msg_get_ifname_func wpa_msg_ifname_cb = NULL;
void wap_msg_register_ifname_cb(wpa_msg_get_ifname_func _func)
{
wpa_msg_ifname_cb = func;
}
static wap_msg_cb_fun wpa_msg_cb = NULL;
void wpa_msg_register_cb(wpa_msg_cb_func func) {
wpa_msg_cb = func;
}
int eap_register_methods(void)
{
int res = 0;
#ifdef EAP_MD5
if (ret == 0)
ret = eap_peer_md5_register();
#endif
...
#ifdef EAP_SERVER_MD5
if (ret == 0)
ret = eap)server_md5_register();
#endif
....
return ret;
}
## 3.eloop提供的时间注册API
```cpp
int eloop_register_read_sock(int sock, eloop_sock_handler handler, void *eloop_data, void *user_data); // 注册socket读事件处理函数
int eloop_register_sock(int sock, eloop_event_type type, eloop_sock_handler handler, void *eloop_data, void *user_data); // 注册socket事件处理函数
int ellop_register_timeout(unsigned int secs, unsigned int usecs, eloop_timeout_handler handler, void *eloop_data, void *user_data); // 注册超时事件处理函数
int eloop_register_signal(int sig, eloop_sign_handler handler, void *user_data); // 注册信号事件处理函数
struct wpa_driver_ops* wap_drivers[] = {
#ifdef CONFIG_DRIVER_WEXT &wpa_diver_wext_ops,
#endif
#ifdef CONFIG_DRIVER_NL80211 &wpa_driver_nl80211_ops,
#endif
}
const struct wpa_driver_ops wpa_driver_nl80211_ops = {
.name = "nl80211",
.desc = "Linux nl80211/cfg80211",
.get_bssid = wpa_driver_nl80211_get_bssid,
...
.scan2 = wpa_driver_nl80211_scan,
...
.get_scan_result2 = wpa_driver_nl80211_get_scan_results,
...
.disassociate = wpa_driver_nl80211_disassociate,
.autherticate = wpa_driver_nl80211_authenticate,
...
}
struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global, struct wpa_interface *iface)
{
struct wpa_supplicant *wpa_s;
struct wpa_interface t_iface;
struct wpa_ssid *ssid;
....
wpa_s = wpa_supplicant_alloc();
....
wpa_s->global = global;
t_iface = *iface;
....
if (wpa_supplicant_init_iface(wpa_s, &t_iface)) {
.....
}
// 通过dbus通知外界有新的iface加入
if (wpas_notify_iface_added(wpa_s)) {
....
}
// 通过dbus通知外界有新的无线网络加入
for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
wpas_notify_network_added(wpas_s, ssid);
}
wpa_s->next = global->ifaces;
global->ifaces = wpa_s;
return wpa_s;
}
802.1X的目的就是为了得到PMKSA
static int wpa_supplicant_init_iface(struct wpa_supplicant* wpa_s, struct wpa_interface* iface)
{
const char* ifname, * driver;
struct wpa_driver_capa capa;
if (iface->confname) {
...// CONFI_BACKEND_FILE处理,此宏指明了WPAS使用的配置项信息来源于文件
wpa_s->conf = wpa_config_read(wpa_s->confname);
}
}
struct wpa_config *wpa_config_read(const char *name)
函数就是解析刚才的配置文件,转换成数据结构