feat(net): Add nl80211 support#1009
Conversation
| #include <netlink/genl/genl.h> | ||
| #include <netlink/genl/mngt.h> | ||
| #include <netlink/netlink.h> | ||
|
|
There was a problem hiding this comment.
These aren't needed; you could forward declare nl_msg and nlattr instead.
| #include "common.hpp" | ||
| #include "settings.hpp" | ||
| #include "errors.hpp" | ||
| #include "settings.hpp" |
| #include <netlink/genl/genl.h> | ||
| #include <netlink/netlink.h> | ||
| #include <iostream> | ||
|
|
There was a problem hiding this comment.
netlink/netlink.h and iostream aren't needed.
|
|
||
| private: | ||
| shared_ptr<wireless_info> m_info{}; | ||
| unsigned int m_ifid; |
There was a problem hiding this comment.
Might as well use brace initialization here to be consistent.
| if (ies_len < hdr_len || ies_len < ies[1] + hdr_len) { | ||
| m_essid.clear(); | ||
| } else { | ||
| m_essid = string(reinterpret_cast<char*>(ies + hdr_len)); |
There was a problem hiding this comment.
We can cast ies to char * from the beginning (line 419) and avoid having to cast it again. Also, we should pass the ESSID length (ies[1]) to the string constructor so we don't include the data after the ESSID as part of the name.
There was a problem hiding this comment.
On top of that, ies can contain non-printable characters. So isprint should be used to test ies.
| // For a more intuitive result, clamp the result to a | ||
| // signal range, where 100% are reachable without directly | ||
| // sitting on top of the AP | ||
| const int hardware_max = -40; |
There was a problem hiding this comment.
IMO if we modify the values too much it might confuse users if they compare it to other sources.
From nl80211_xbm_to_percent it seems like -20 and -90 dBm are the commonly used values, so it might be best to use those instead.
There was a problem hiding this comment.
This just came up in #1834. Though nl80211_xbm_to_percent in the NetworkManager code says it goes from -20 to -90, the way the percentage is calculated, it actually goes from -120dBm to -20dBm. -90dBm corresponds to 30%.
But I think the -20 to -90 range is good.
|
@taschenb Do you have any interest in continuing this PR? |
|
I think we should, for the time being, have both wireless_tools and nl80211 available side by side and have a config option to enable nl80211. This way we don't leave users with a broken bar, if something doesn't work. |
|
|
||
| // Ignore interfaces in ad-hoc mode | ||
| if (req.u.mode == IW_MODE_ADHOC) { | ||
| nl_socket_modify_cb(sk, NL_CB_VALID, NL_CB_CUSTOM, scan_cb, this); |
There was a problem hiding this comment.
if (0 != (nl_socket_modify_cb ...)) {
handle_error
}| m_linkquality.val = stats.qual.qual; | ||
| m_linkquality.max = range.max_qual.qual; | ||
| } | ||
| return status == NL80211_BSS_STATUS_ASSOCIATED || status == NL80211_BSS_STATUS_IBSS_JOINED; |
There was a problem hiding this comment.
NL80211_BSS_STATUS_AUTHENTICATED should be tested too.
There was a problem hiding this comment.
Also a switch() or & operator will be better to test against multiple cases.
|
I am deeply sorry for the late response. As for the coexistence with Wext, what approach would you suggest to select the interface to use? Would a simple CMake option or fallback-search for libnl in case libiw isn't found be sufficient for the time being? Or should we cleanup the network interface and expose a option in the network module? |
|
A compile option should suffice. We should probably have libnl as the default and use libiw as a fallback in case the former isn't found. One of the builds failed when doing |
|
In the latest update, nl80211 is now the preferred interface. In case libnl-genl-3.0 is not preset or -DWITH_LIBNL=OFF, it will fall back to Wext. |
NBonaparte
left a comment
There was a problem hiding this comment.
Code looks good; I think README and build.sh should still mention both libnl and wireless_tools.
|
You are right, totally forgot about readding it. Is now in there as well. |
|
A little nitpicky, but could you extend the other prompts to be the same length by adding more |
fb99001 to
0329703
Compare
|
Good catch and not nitpicky. Everything should be and look consistent. |
Prepare for different implementations of wireless_network
|
We could probably shorten it to |
This patch enables support for nl80211. In case the libnl-genl-3.0 library isn't found, it will fall back to Wext instead. The library to use can also be manually set with the CMake option WITH_LIBNL. The Wireless-Extensions (WE or Wext) are deprecated and long replaced by cfg80211. Although Wext isn't used by WiFi drivers anymore, CFG80211_WEXT allows old tools to communicate with modern drivers by providing a wrapper API.
Breaking Changes: * `0 < label-NAME-maxlen < 3` will now throw an exception and disable the containing module, if ellipsis is enabled for that label. (#1198) Changelog: Deprecations: * `internal/volume` is now called `internal/alsa` (#967) * temperature: The `%temperature%` is deprecated in favor of `%temperature-c%`(#897) * mpd: `icon-repeatone` is deprecated in favor of `icon-single` (#1295), see #1279 Features: * feat(mpd): Add support for icon-consume (#861) * feat(bspwm): Add workspace separator (#942) * feat(i3): Add workspace separator (#938), see #929 * feat(build): Make polybar build on FreeBSD (#931, polybar/xpp#8), see #239 * feat(volume): Add pulseaudio backend (#779) * feat(script): Add %pid% token for tail commands (#934) * feat(temp): Add temperature tokens without unit (#897) * feat(memory): Add memory used/free ramp (#1038), see #1037 * feat(memory): Add swap tokens (#1018) * feat(net): Add unknown-as-up option (#1077), see #457 * feat(config): Support fractional size and offset (#972), see #953 * feat(xwindow): Add label-empty (#1136) * feat(battery): Add animation-discharging (analog to animation-charging) (#1190) * feat(config): Support pixel offset for bar size and offset values (#1224) * feat(mpd): Add `%album-artist%` token (#1263) * feat(net): Add local_ip6 token (#1239), see #1234 * feat(net): Add nl80211 support (#1009), see #277 Fixes: * fix(mpd): Wrong elapsed time when after standby (#921), see #915 * fix(config): Wrong min, maxlen when using the same token multiple times (#974), see #971 * fix(battery): use power_now correctly (#958), see #928 * fix(mpd): Crash when mpd isn't running (#983), see #979 * fix(xworkspaces): Respect 'enable-scroll' (#1002) * fix(xbacklight): Respect 'enable-scroll' (#1014) * fix(build): support xcb-proto >=1.13 (polybar/xpp#11), see #973 * fix(mpd): Respect MPD_HOST env variable (#1025), see #1007 * fix(i3): Reconnect i3 IPC socket on restart/error (#1099), see #762 * fix(cursor): Occasional crash on mouseover (#1124), see #1117 * fix(net): Mark 'not connected' on querying failure (#1171), see #1163 * fix(gcc): Fix -Wstringop-truncation warning (#1216, polybar/i3ipcpp#7), see #1215 * fix(builder): Don't truncate colors with same channels (#1217), see #1183 * fix(bspwm): Consistent behavior when scrolling through multiple desktops (#986), see #981 * fix(builder): Respect label-ellipsis option (#1198), see #1194
This replaces the deprecated Wireless Extensions with nl80211.
Fixes #277