当前位置: 首页 > article >正文

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


http://www.kler.cn/a/571397.html

相关文章:

  • 【微知】如何通过mlxlink查看Mellanox网卡和光模块相关的信息?( mlxlink -d 01:00.0 -m)
  • 拥抱健康养生,开启活力生活
  • 智慧园区大数据云平台建设总体方案,平台方案架构-智慧园区大数据平台(320页原件Word)
  • Windows 11【1001问】查看Windows 11登录用户的18种方法
  • 无人机的飞行控制器技术详解
  • C++ OpenGL 帧缓冲(Framebuffer)理论与实现
  • Token设计指南:实现动态用户信息与权限管理
  • vue使用html实现的一个项目进度图
  • C语言的那点事第十二篇:动态内存分配、内存泄漏与野指针的深度剖析。
  • ==和===在不同场景下的具体区别是什么?
  • 【每日八股】MySQL篇(九):优化
  • golang程序员如何3天完成python学习
  • 【区块链 + 智慧政务】科大讯飞:省级一体化区块链平台 | FISCO BCOS 应用案例
  • 软件试用 防破解 防软件调试(C# )
  • Excel的行高、列宽单位不统一?还是LaTeX靠谱
  • 用matplotlib构建BI看板:Superset插件开发实战
  • 高并发场景下的数据库优化
  • 机器学习的半监督学习,弱监督学习,自监督学习
  • Linux : 环境变量
  • 【C语言5】函数:库函数、自定义函数、形参和实参、return语句、数组做函数参数、嵌套调用和链式访问、声明和定义