C语言 nl80211 库和 cfg80211 如何工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21456235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How nl80211 library & cfg80211 work?
提问by Rafal
I want to learn about how nl80211and cfg80211works in detail. Function flow, how nl80211interact with network tools like wpa_supplicant, iw.
我想了解如何nl80211与cfg80211具体工作。功能流程,如何nl80211使用网络工具进行交互一样wpa_supplicant,iw。
Plz suggest me some useful links or books to refer.
请建议我一些有用的链接或书籍以供参考。
回答by jmlemetayer
To be able to control wireless drivers from userspace, some IPC communication processes between kernel and userspace are used.
为了能够从用户空间控制无线驱动程序,使用了内核和用户空间之间的一些 IPC 通信进程。
- At first
ioctlwith vendor dependent APIs was used. - In 1996, Jean Tourrilhes creates wireless extensions(WE or WEXT).
- 最初
ioctl使用供应商依赖的 API。 - 1996 年,Jean Tourrilhes 创建了无线扩展(WE 或 WEXT)。
The Wireless Extension (WE) is a generic API allowing a driver to expose to the user space configuration and statistics specific to common Wireless LANs.
无线扩展 (WE) 是一个通用 API,允许驱动程序向用户空间公开特定于常见无线 LAN 的配置和统计信息。
In 2006, John Linville creates mac80211and Johannes Berg creates cfg80211and nl80211. Together it is intended to replace wireless extensions.
+-------------+ | | | Userspace | | | +-------------+ ^ - - - | - - - - | nl80211 v +-------------+ | | | cfg80211 | | | +-------------+ +-------------+ | | | mac80211 | | driver | | | +-------------+
2006 年,John Linville 创建了mac80211,Johannes Berg 创建了cfg80211和nl80211。它旨在共同取代无线扩展。
+-------------+ | | | Userspace | | | +-------------+ ^ - - - | - - - - | nl80211 v +-------------+ | | | cfg80211 | | | +-------------+ +-------------+ | | | mac80211 | | driver | | | +-------------+
An important point is that nl80211/cfg80211/mac80211 no longer use ioctl, they use netlink.
重要的一点是 nl80211/cfg80211/mac80211 不再使用 ioctl ,他们使用netlink。
So, tools like iw, hostapdor the wpa_supplicantuse some netlink libraries (like libnlor libnl-tiny) and the netlink interface public header which is of course nl80211.h.
因此,像iw、hostapd或wpa_supplicant这样的工具使用一些 netlink 库(如libnl或libnl-tiny)和 netlink 接口公共头文件,当然是nl80211.h。
There is not so much documentations, but I advise you to read the libnl documentationand then the iw source code(because iw use libnl).
回答by artm
A slightly more detailed picture of how nl80211and cfg80211work with other parts of the system (user space, kernel, and hardware).
一个稍微详细的图片是如何nl80211和cfg80211工作与系统的其他部分(user space,kernel,和hardware)。
nl80211is the interface between user space software (iw,wpa_supplicant, etc.) and the kernel (cfg80211andmac80211kernel modules, and specific drivers).- The WiFi drivers and hardware could be Full-MAC or Soft-MAC (see Wireless_network_interface_controller).
cfg80211_opsis a set of operations that Full-MAC drivers andmac80211module register tocfg80211module.ieee80211_opsis a set of operations that Soft-MAC drivers register tomac80211module.
nl80211是用户空间软件(iw、wpa_supplicant等)和内核(cfg80211以及mac80211内核模块和特定驱动程序)之间的接口。- WiFi 驱动程序和硬件可以是 Full-MAC 或 Soft-MAC(请参阅Wireless_network_interface_controller)。
cfg80211_ops是Full-MAC驱动和mac80211模块注册到cfg80211模块的一组操作。ieee80211_ops是一组 Soft-MAC 驱动程序注册到mac80211模块的操作。
回答by eyalsh
See my reply to How to learn the structure of Linux wireless drivers (mac80211)?
看我对如何学习Linux无线驱动的结构(mac80211)的回复 ?
In wpa_supplicant, you can follow the code in src/drivers/driver_nl80211.c. This is a wpa_supplicant driver (not a kernel driver but an abstraction used in wpa_supplicantcode) which uses libnlto communicate with the kernel cfg80211module. When wpa_supplicantissues a scan for example then wpa_driver_nl80211_scangets called. It builds the netlinkmessage with a command called NL80211_CMD_TRIGGER_SCANand with all the parameters required for the scan.
在 中wpa_supplicant,您可以按照 中的代码进行操作src/drivers/driver_nl80211.c。这是一个 wpa_supplicant 驱动程序(不是内核驱动程序,而是wpa_supplicant代码中使用的抽象),用于libnl与内核cfg80211模块进行通信。wpa_supplicant例如,当发出扫描时,就会wpa_driver_nl80211_scan被调用。它netlink使用调用的命令NL80211_CMD_TRIGGER_SCAN和扫描所需的所有参数构建消息。
回答by Akshdeep Singh
I've created a basic code flow diagram for the wireless stack in linux,
all the way from wpa_supplicant > cfg80211 > mac80211 > ath9k_htc.
我已经为 linux 中的无线堆栈创建了一个基本的代码流程图,
从 wpa_supplicant > cfg80211 > mac80211 > ath9k_htc。
The code has been traced for linux kernel 5.4.31.
该代码已针对 linux 内核 5.4.31 进行跟踪。
Here is the link.
这是链接。


