Chapter 4 Part 3 WPAS源码走读

1 wpa_supplicant_add_iface

用于向WPAS添加接口设备,其实就是初始化这些设备

wpa_supplicant.c

struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
						 struct wpa_interface *iface,
						 struct wpa_supplicant *parent) {
	struct wpa_supplicant *wpa_s;
	struct wpa_interface t_iface;
	struct wpa_ssid *ssid;

	if (global == NULL || iface == NULL)
		return NULL;

	wpa_s = wpa_supplicant_alloc(parent);
	if (wpa_s == NULL)
		return NULL;

	wpa_s->global = global;

	t_iface = *iface;
	if (global->params.override_driver) {
		wpa_printf(MSG_DEBUG, "Override interface parameter: driver "
			   "('%s' -> '%s')",
			   iface->driver, global->params.override_driver);
		t_iface.driver = global->params.override_driver;
	}
	if (global->params.override_ctrl_interface) {
		wpa_printf(MSG_DEBUG, "Override interface parameter: "
			   "ctrl_interface ('%s' -> '%s')",
			   iface->ctrl_interface,
			   global->params.override_ctrl_interface);
		t_iface.ctrl_interface =
			global->params.override_ctrl_interface;
	}
    //wpa_supplicant_init_iface极其重要
	if (wpa_supplicant_init_iface(wpa_s, &t_iface)) {
		wpa_printf(MSG_DEBUG, "Failed to add interface %s",
			   iface->ifname);
		wpa_supplicant_deinit_iface(wpa_s, 0, 0);
		return NULL;
	}

    //通过dbus通知外界有新的iface加入
	/* Notify the control interfaces about new iface */
	if (wpas_notify_iface_added(wpa_s)) {
		wpa_supplicant_deinit_iface(wpa_s, 1, 0);
		return NULL;
	}

	/* Notify the control interfaces about new networks for non p2p mgmt
	 * ifaces. */
	if (iface->p2p_mgmt == 0) {
        //通过dbus通知外界有新的无线网络加入
		for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
			wpas_notify_network_added(wpa_s, ssid);
	}

	wpa_s->next = global->ifaces;
	global->ifaces = wpa_s;

	wpa_dbg(wpa_s, MSG_DEBUG, "Added interface %s", wpa_s->ifname);
	wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);

#ifdef CONFIG_P2P
	if (wpa_s->global->p2p == NULL &&
	    !wpa_s->global->p2p_disabled && !wpa_s->conf->p2p_disabled &&
	    (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
	    wpas_p2p_add_p2pdev_interface(
		    wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
		wpa_printf(MSG_INFO,
			   "P2P: Failed to enable P2P Device interface");
		/* Try to continue without. P2P will be disabled. */
	}
#endif /* CONFIG_P2P */

	return wpa_s;
}
2 wpa_ssid

用于存储某个无线网络的配置信息(如所支持的安全类型、优先级等)
实际上是wpa_supplicant.conf中无线网络配置项在代码中的反映(conf中每一个network项都对应一个wpa_ssid对象)
在这里插入图片描述

3 安全相关成员变量及背景知识

1.passphrase
只与WPA/WPA2-PSK模式有关,用于存储我们输入的字符串密码
实际上,规范要求使用的是psk变量
用户一般只设置字符串形式的password,WPAS将根据它和ssid进行一定的计算得到最终使用的psk
2.pairwise_cipher和group_cipher
和规范中的cipher suite(加密套件)定义有关,cipher suite用于指明数据收发两方使用的数据加密方法
pairwise_cipher和group_cipher分别代表该无线网络设置的单播和组播数据加密方法
3.key_mgmt
和802.11中的AKM suite有关
AKM(Authentication and Key Management) suite定义了一套算法用于在Supplicant和Authenticator之间交换身份和密钥信息
4.proto
代表该无线网络支持的安全协议类型
5.auth_alg
代表该无线网络所支持的身份验证算法
6.eapol_flags
和动态WEP Key有关

4 其他成员变量及背景知识

1.disable
取值为0代表该无线网络可用
取值为1代表该无线网络被禁止使用,但可以通过命令来启用它
取值为2代表该无线网络和P2P有关
2.mode

5 wpa_supplicant

在这里插入图片描述

1.drv_priv和global_drv_priv
WPAS为driver wrapper一共定义了两个上下文信息
driver i/f接口定义了两个初始化函数,返回值均为driver wrapper全局上下文信息
分别保存在wpa_global的drv_priv数组中和wpa_supplicant的driv_priv中
2.current_bss
变量类型为wpa_bss,是无线网络在wpa_supplicant中的代表
wpa_bss的成员主要描述了无线网络的bssid、ssid、频率、Beacon心跳时间、capability、信号强度等

6 wpa_supplicant结构体中功能相关成员变量

1.sched_scan_timeout
和计划扫描(scheduled scan)功能有关
计划扫描即定时扫描,启用该功能时,需要为驱动设置定时扫描的间隔(以毫秒为单位)
2.bgscan
和后台扫描及漫游(background scan and roaming)技术有关
为了增强切换AP时的无缝体验(扫描过程中,STA不能收发数据帧,从用户角度看, 相当于网络不能使用),STA可采用
background scan(定时扫描一小段时间或者当网络空闲时才扫描)技术来监视周围AP的信号强度等信息
一旦之前使用的AP信号强度低于某个阈值,STA则可快速切换到某个信号更强的AP

7 wpa_states的取值

WPA_DISCONNECTED 未连接到任何无线网络
WPA_INTERFACE_DISABLED 此wpa_supplicant所使用的网络设备被禁用
WPA_INACTIVE 此wpa_supllicant没有可连接的无线网络
WPA_SCANNING 扫描无线网络
WPA_AUTHENTICATING 身份验证
WPA_ASSOCIATING 关联过程
WPA_ASSOCIATED 成功关联
WPA_4WAY_HANDSHAKE 四次握手
WPA_GROUP_HANDSHAKE 处于组密钥握手协议处理过程中
WPA_COMPLETED 所有认证过程完成

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值