Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(net): Add nl80211 support#1009

Merged
NBonaparte merged 5 commits into
polybar:masterfrom
taschenb:nl80211
Jun 19, 2018
Merged

feat(net): Add nl80211 support#1009
NBonaparte merged 5 commits into
polybar:masterfrom
taschenb:nl80211

Conversation

@taschenb

@taschenb taschenb commented Feb 9, 2018

Copy link
Copy Markdown
Contributor

This replaces the deprecated Wireless Extensions with nl80211.

Fixes #277

Comment thread include/adapters/net.hpp
#include <netlink/genl/genl.h>
#include <netlink/genl/mngt.h>
#include <netlink/netlink.h>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't needed; you could forward declare nl_msg and nlattr instead.

Comment thread include/adapters/net.hpp
#include "common.hpp"
#include "settings.hpp"
#include "errors.hpp"
#include "settings.hpp"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Comment thread src/adapters/net.cpp
#include <netlink/genl/genl.h>
#include <netlink/netlink.h>
#include <iostream>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

netlink/netlink.h and iostream aren't needed.

Comment thread include/adapters/net.hpp Outdated

private:
shared_ptr<wireless_info> m_info{};
unsigned int m_ifid;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well use brace initialization here to be consistent.

Comment thread src/adapters/net.cpp Outdated
if (ies_len < hdr_len || ies_len < ies[1] + hdr_len) {
m_essid.clear();
} else {
m_essid = string(reinterpret_cast<char*>(ies + hdr_len));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On top of that, ies can contain non-printable characters. So isprint should be used to test ies.

Comment thread src/adapters/net.cpp Outdated
// 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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@NBonaparte

Copy link
Copy Markdown
Member

@taschenb Do you have any interest in continuing this PR?

@patrick96

Copy link
Copy Markdown
Member

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.

Comment thread src/adapters/net.cpp Outdated

// 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);

@su8 su8 May 5, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (0 != (nl_socket_modify_cb ...)) {
handle_error
}

Comment thread src/adapters/net.cpp Outdated
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NL80211_BSS_STATUS_AUTHENTICATED should be tested too.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a switch() or & operator will be better to test against multiple cases.

@taschenb

taschenb commented Jun 8, 2018

Copy link
Copy Markdown
Contributor Author

I am deeply sorry for the late response.
I addressed the feedback from the code review. Thank you for that so far.

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?

@NBonaparte

NBonaparte commented Jun 8, 2018

Copy link
Copy Markdown
Member

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 apt-get install so I restarted it, and it successfully completed this time.

@taschenb

taschenb commented Jun 9, 2018

Copy link
Copy Markdown
Contributor Author

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.

@taschenb taschenb changed the title feat(net): Replace Wext with nl80211 feat(net): Add nl80211 support Jun 9, 2018

@NBonaparte NBonaparte left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good; I think README and build.sh should still mention both libnl and wireless_tools.

@taschenb

Copy link
Copy Markdown
Contributor Author

You are right, totally forgot about readding it. Is now in there as well.

@NBonaparte

Copy link
Copy Markdown
Member

A little nitpicky, but could you extend the other prompts to be the same length by adding more -s?

@taschenb taschenb force-pushed the nl80211 branch 2 times, most recently from fb99001 to 0329703 Compare June 15, 2018 13:30
@taschenb

Copy link
Copy Markdown
Contributor Author

Good catch and not nitpicky. Everything should be and look consistent.
But the length of the prompt is still OK in general or should we try to limit this?

@NBonaparte

Copy link
Copy Markdown
Member

We could probably shorten it to Include support for "internal/network" (requires libnl/libiw) -- [y/N]: unless there's an even shorter way.

taschenb added 2 commits June 16, 2018 08:45
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.
patrick96 added a commit that referenced this pull request Jul 23, 2018
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants