P2P在wpa_supplicant中的初始化流程
WIFI-Driect在WPA_S中的初始化流程:
小白一枚,有冗余以及理解不到位的地方多有体谅
直接从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;
}
.......
}
- 初始化一个p2p对象,其结构体类型是p2p_config
- 判断p2p_disabled,是否启用P2P功能,这个是上层framework行为
- 判断wifi驱动是否支持p2p功能,判断是否有