首页 > 其他 > 详细

二、wpa_supplicant 初始化的关键函数

时间:2014-07-29 12:34:06      阅读:582      评论:0      收藏:0      [点我收藏+]
  • struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
  • struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,struct wpa_interface *iface)

1. wpa_supplicant_init()

 

 

/**
 * wpa_supplicant_init - Initialize %wpa_supplicant
 * @params: Parameters for %wpa_supplicant
 * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
 *
 * This function is used to initialize %wpa_supplicant. After successful
 * initialization, the returned data pointer can be used to add and remove
 * network interfaces, and eventually, to deinitialize %wpa_supplicant.
 */
struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
{
    struct wpa_global *global;
    int ret, i;

    if (params == NULL)
        return NULL;

#ifdef CONFIG_DRIVER_NDIS
    {
        void driver_ndis_init_ops(void);
        driver_ndis_init_ops();
    }
#endif /* CONFIG_DRIVER_NDIS */

#ifndef CONFIG_NO_WPA_MSG
    wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb);
#endif /* CONFIG_NO_WPA_MSG */

    wpa_debug_open_file(params->wpa_debug_file_path);
    if (params->wpa_debug_syslog)
        wpa_debug_open_syslog();
    if (params->wpa_debug_tracing) {
        ret = wpa_debug_open_linux_tracing();
        if (ret) {
            wpa_printf(MSG_ERROR,
                   "Failed to enable trace logging");
            return NULL;
        }
    }

    ret = eap_register_methods();
    if (ret) {
        wpa_printf(MSG_ERROR, "Failed to register EAP methods");
        if (ret == -2)
            wpa_printf(MSG_ERROR, "Two or more EAP methods used "
                   "the same EAP type.");
        return NULL;
    }

    global = os_zalloc(sizeof(*global));
    if (global == NULL)
        return NULL;
    dl_list_init(&global->p2p_srv_bonjour);
    dl_list_init(&global->p2p_srv_upnp);
    global->params.daemonize = params->daemonize;
    global->params.wait_for_monitor = params->wait_for_monitor;
    global->params.dbus_ctrl_interface = params->dbus_ctrl_interface;
    if (params->pid_file)
        global->params.pid_file = os_strdup(params->pid_file);
    if (params->ctrl_interface)
        global->params.ctrl_interface =
            os_strdup(params->ctrl_interface);
    if (params->override_driver)
        global->params.override_driver =
            os_strdup(params->override_driver);
    if (params->override_ctrl_interface)
        global->params.override_ctrl_interface =
            os_strdup(params->override_ctrl_interface);
    wpa_debug_level = global->params.wpa_debug_level =
        params->wpa_debug_level;
    wpa_debug_show_keys = global->params.wpa_debug_show_keys =
        params->wpa_debug_show_keys;
    wpa_debug_timestamp = global->params.wpa_debug_timestamp =
        params->wpa_debug_timestamp;

    wpa_printf(MSG_DEBUG, "wpa_supplicant v" VERSION_STR);

    if (eloop_init()) {
        wpa_printf(MSG_ERROR, "Failed to initialize event loop");
        wpa_supplicant_deinit(global);
        return NULL;
    }

    random_init(params->entropy_file);

    global->ctrl_iface = wpa_supplicant_global_ctrl_iface_init(global);
    if (global->ctrl_iface == NULL) {
        wpa_supplicant_deinit(global);
        return NULL;
    }

    if (wpas_notify_supplicant_initialized(global)) {
        wpa_supplicant_deinit(global);
        return NULL;
    }

    for (i = 0; wpa_drivers[i]; i++)
        global->drv_count++;
    if (global->drv_count == 0) {
        wpa_printf(MSG_ERROR, "No drivers enabled");
        wpa_supplicant_deinit(global);
        return NULL;
    }
    global->drv_priv = os_zalloc(global->drv_count * sizeof(void *));
    if (global->drv_priv == NULL) {
        wpa_supplicant_deinit(global);
        return NULL;
    }

#ifdef CONFIG_WIFI_DISPLAY
    if (wifi_display_init(global) < 0) {
        wpa_printf(MSG_ERROR, "Failed to initialize Wi-Fi Display");
        wpa_supplicant_deinit(global);
        return NULL;
    }
#endif /* CONFIG_WIFI_DISPLAY */

    return global;
}

2. wpa_supplicant_add_iface()

在结构体wpa_interface 的注释中提到,wpa_interface将作为此函数的参数。

/** * struct wpa_interface - Parameters for wpa_supplicant_add_iface() *

/ struct wpa_interface { …… }

 

二、wpa_supplicant 初始化的关键函数,布布扣,bubuko.com

二、wpa_supplicant 初始化的关键函数

原文:http://www.cnblogs.com/leino11121/p/3874813.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!