• 二、wpa_supplicant 初始化的关键函数


    • 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 { …… }

     

  • 相关阅读:
    LeetCode--342--4的幂
    LeetCode--326--3的幂
    python3-
    LeetCode--303--区域和检索
    LeetCode--292--Nim游戏
    《Cracking the Coding Interview》——第16章:线程与锁——题目6
    《Cracking the Coding Interview》——第16章:线程与锁——题目5
    《Cracking the Coding Interview》——第16章:线程与锁——题目4
    《Cracking the Coding Interview》——第16章:线程与锁——题目3
    《Cracking the Coding Interview》——第16章:线程与锁——题目2
  • 原文地址:https://www.cnblogs.com/leino11121/p/3874813.html
Copyright © 2020-2023  润新知