WiFi Direct 在wpa_supplicant中的流程一(初始化P2P)

本文详细介绍了P2P在wpa_supplicant中的初始化过程,包括从添加接口开始,到注册action帧处理,设置设备能力,以及配置信道和参数。重点讨论了wpas_p2p_init()函数及其相关代码段,阐述了如何构建P2P设备的能力和配置,并通过nl80211接口进行注册和管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

WIFI-Driect在WPA_S中的初始化流程:

小白一枚,有冗余以及理解不到位的地方多有体谅

Alt
直接从wpa_supplicant开始,上面的framework的流程就不跟流程了,有兴趣的可以自己跟下上面的流程,

struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
						 struct wpa_interface *iface,
						 struct wpa_supplicant *parent)
{
   
......
	if (wpa_supplicant_init_iface(wpa_s, &t_iface)) {
   
	}
......
	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 */
}
static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
				     const struct wpa_interface *iface)
{
   
......
	if ((!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) ||
	     wpa_s->p2p_mgmt) &&
	    wpas_p2p_init(wpa_s->global, wpa_s) < 0) {
   
		wpa_msg(wpa_s, MSG_ERROR, "Failed to init P2P");
		return -1;
	}
......
}

注册action

static int wpa_driver_nl80211_set_mode_impl(
		struct i802_bss *bss,
		enum nl80211_iftype nlmode,
		struct hostapd_freq_params *desired_freq_params)
{
   
.......

	mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
	if (mode_switch_res && nlmode == nl80211_get_ifmode(bss))
		mode_switch_res = 0;
		
	if (mode_switch_res == 0) {
   
		drv->nlmode = nlmode;
		ret = 0;
		goto done;
	}
	
.......

done:

........

	if (!bss->in_deinit && !is_ap_interface(nlmode) &&
	    !is_mesh_interface(nlmode) &&
	    nl80211_mgmt_subscribe_non_ap(bss) < 0)
		wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action "
			   "frame processing - ignore for now");

	return 0;
}

该函数通过使用nl80211内核接口将非接入点(non-AP)事件添加到当前订阅列表中,并开始接收与其相关的通知。这些事件可能包括信道扫描、帧注入、关联和认证等操作

static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss)
{
   
.......
	wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP "
		   "handle %p", bss->nl_mgmt);
......
#if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP)
	/* GAS Initial Request */
	if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0)
		ret = -1;
..............
}


nl80211_mgmt_subscribe_non_ap 通过使用nl80211内核接口向驱动程序发送注册请求,以便在接收到特定类型的Action帧时通知用户空间应用程序
作用是当P2P设备收到对应的Action帧后,WIFI 驱动会将相应的消息传递给wpa_supplciant进行处理

wpas_p2p_init() 代码段1

int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
{
   
	struct p2p_config p2p;
	int i;

	if (wpa_s->conf->p2p_disabled)
		return 0;

	if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
		return 0;

	if (global->p2p)
		return 0;

	if (wpas_p2p_mac_setup(wpa_s) < 0) {
   
		wpa_msg(wpa_s, MSG_ERROR,
			"Failed to initialize P2P random MAC address.");
		return -1;
	}
.......
}
  1. 初始化一个p2p对象,其结构体类型是p2p_config
  2. 判断p2p_disabled,是否启用P2P功能,这个是上层framework行为
  3. 判断wifi驱动是否支持p2p功能,判断是否有
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值