wpa_supplicant源码剖析-main.c解析
这里记录了 wpa_supplicant 的命令行用法
static void usage(void)
{
int i;
printf("%s\n\n%s\n"
"usage:\n"
" wpa_supplicant [-BddhKLqq"
#ifdef CONFIG_DEBUG_SYSLOG
"s"
#endif /* CONFIG_DEBUG_SYSLOG */
"t"
#ifdef CONFIG_CTRL_IFACE_DBUS_NEW
"u"
#endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
"vW] [-P<pid file>] "
"[-g<global ctrl>] \\\n"
" [-G<group>] \\\n"
" -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
"[-p<driver_param>] \\\n"
" [-b<br_ifname>] [-e<entropy file>]"
#ifdef CONFIG_DEBUG_FILE
" [-f<debug file>]"
#endif /* CONFIG_DEBUG_FILE */
" \\\n"
" [-o<override driver>] [-O<override ctrl>] \\\n"
" [-N -i<ifname> -c<conf> [-C<ctrl>] "
"[-D<driver>] \\\n"
#ifdef CONFIG_P2P
" [-m<P2P Device config file>] \\\n"
#endif /* CONFIG_P2P */
" [-p<driver_param>] [-b<br_ifname>] [-I<config file>] "
"...]\n"
"\n"
"drivers:\n",
wpa_supplicant_version, wpa_supplicant_license);
for (i = 0; wpa_drivers[i]; i++) {
printf(" %s = %s\n",
wpa_drivers[i]->name,
wpa_drivers[i]->desc);
}
#ifndef CONFIG_NO_STDOUT_DEBUG
printf("options:\n"
" -b = optional bridge interface name\n"
" -B = run daemon in the background\n"
" -c = Configuration file\n"
" -C = ctrl_interface parameter (only used if -c is not)\n"
" -d = increase debugging verbosity (-dd even more)\n"
" -D = driver name (can be multiple drivers: nl80211,wext)\n"
" -e = entropy file\n"
#ifdef CONFIG_DEBUG_FILE
" -f = log output to debug file instead of stdout\n"
#endif /* CONFIG_DEBUG_FILE */
" -g = global ctrl_interface\n"
" -G = global ctrl_interface group\n"
" -h = show this help text\n"
" -i = interface name\n"
" -I = additional configuration file\n"
" -K = include keys (passwords, etc.) in debug output\n"
" -L = show license (BSD)\n"
#ifdef CONFIG_P2P
" -m = Configuration file for the P2P Device interface\n"
#endif /* CONFIG_P2P */
#ifdef CONFIG_MATCH_IFACE
" -M = start describing new matching interface\n"
#endif /* CONFIG_MATCH_IFACE */
" -N = start describing new interface\n"
" -o = override driver parameter for new interfaces\n"
" -O = override ctrl_interface parameter for new interfaces\n"
" -p = driver parameters\n"
" -P = PID file\n"
" -q = decrease debugging verbosity (-qq even less)\n"
#ifdef CONFIG_DEBUG_SYSLOG
" -s = log output to syslog instead of stdout\n"
#endif /* CONFIG_DEBUG_SYSLOG */
" -t = include timestamp in debug messages\n"
#ifdef CONFIG_DEBUG_LINUX_TRACING
" -T = record to Linux tracing in addition to logging\n"
" (records all messages regardless of debug verbosity)\n"
#endif /* CONFIG_DEBUG_LINUX_TRACING */
#ifdef CONFIG_CTRL_IFACE_DBUS_NEW
" -u = enable DBus control interface\n"
#endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
" -v = show version\n"
" -W = wait for a control interface monitor before starting\n");
printf("example:\n"
" wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
wpa_drivers[0] ? wpa_drivers[0]->name : "nl80211");
#endif /* CONFIG_NO_STDOUT_DEBUG */
}
这里会将 0,1,2 文件描述符指向/dev/null,相当于关闭标准输入,标准输出,标准错误
将输入的参数处理完之后,使用参数对 wpa_supplicant 进行初始化
\wpa_supplicant\wpa_supplicant.c
日志相关初始化
注册 eap 协议相关回调函数
填充完用户传下来的参数之后初始化 eloop
这里主要是得到 epollfd 和 kqueuefd
这里进行 random 初始化,random 的作用是生成高质量随机数,可以用于会话加密
初始化全局控制接口
通知 wpa_supplicant 初始化了,这里主要是对 binder 进行初始化,以便于后续进行 rpc,通常手机厂商会在这里将 binder 去掉,加入 hidl 和 aidl 的初始化,一般通过 hidl 接口去调用 wpa_supplicant 的功能
回到 main 函数
这里初始化 fst,fst 是做 ap 切换时会话保持的
添加所有的 wlan 接口
这里面主要是进行驱动初始化及 wpa_supplicant 上下文初始化,后续作者会更新驱动初始化的内容
这里面是注册 wlan 上下文到 dbus,但是手机一般注册到 hidl
回到wpa_supplicant_add_iface
这里是将连接状态机设置为WPA_DISCONNECTED 状态
main 函数的最后去启动 wpa_supplicant