2018-08-09 16:38:24 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2018-11-13 21:31:26 +01:00
|
|
|
#include <arpa/inet.h>
|
2018-08-09 16:38:24 +02:00
|
|
|
#include <fmt/format.h>
|
2019-04-18 17:52:00 +02:00
|
|
|
#include <linux/nl80211.h>
|
|
|
|
|
#include <netlink/genl/ctrl.h>
|
|
|
|
|
#include <netlink/genl/genl.h>
|
|
|
|
|
#include <netlink/netlink.h>
|
|
|
|
|
#include <sys/epoll.h>
|
2022-04-06 08:37:19 +02:00
|
|
|
|
2022-04-06 08:43:31 +02:00
|
|
|
#include <optional>
|
2025-07-25 18:19:14 -04:00
|
|
|
#include <vector>
|
2022-04-06 08:43:31 +02:00
|
|
|
|
2022-11-24 12:28:52 +01:00
|
|
|
#include "ALabel.hpp"
|
2019-04-18 17:52:00 +02:00
|
|
|
#include "util/sleeper_thread.hpp"
|
2020-08-14 20:58:48 +02:00
|
|
|
#ifdef WANT_RFKILL
|
2020-01-23 17:17:29 +01:00
|
|
|
#include "util/rfkill.hpp"
|
2020-08-14 20:58:48 +02:00
|
|
|
#endif
|
2018-08-09 16:38:24 +02:00
|
|
|
|
2025-02-26 15:59:33 +05:30
|
|
|
enum ip_addr_pref : uint8_t { IPV4, IPV6, IPV4_6 };
|
|
|
|
|
|
2018-08-09 16:38:24 +02:00
|
|
|
namespace waybar::modules {
|
|
|
|
|
|
2022-11-24 12:28:52 +01:00
|
|
|
class Network : public ALabel {
|
2019-04-18 17:52:00 +02:00
|
|
|
public:
|
|
|
|
|
Network(const std::string&, const Json::Value&);
|
2023-03-02 16:57:07 +03:00
|
|
|
virtual ~Network();
|
|
|
|
|
auto update() -> void override;
|
2019-02-06 10:33:12 +01:00
|
|
|
|
2019-04-18 17:52:00 +02:00
|
|
|
private:
|
2025-07-03 16:35:18 -04:00
|
|
|
static const uint8_t MAX_RETRY{5};
|
|
|
|
|
static const uint8_t EPOLL_MAX{200};
|
2018-08-16 14:29:41 +02:00
|
|
|
|
2019-04-18 17:52:00 +02:00
|
|
|
static int handleEvents(struct nl_msg*, void*);
|
2021-05-15 16:38:00 +01:00
|
|
|
static int handleEventsDone(struct nl_msg*, void*);
|
2019-04-18 17:52:00 +02:00
|
|
|
static int handleScan(struct nl_msg*, void*);
|
2018-08-16 14:29:41 +02:00
|
|
|
|
2021-05-15 16:38:00 +01:00
|
|
|
void askForStateDump(void);
|
|
|
|
|
|
2022-04-06 08:37:19 +02:00
|
|
|
void worker();
|
|
|
|
|
void createInfoSocket();
|
|
|
|
|
void createEventSocket();
|
|
|
|
|
void parseEssid(struct nlattr**);
|
|
|
|
|
void parseSignal(struct nlattr**);
|
|
|
|
|
void parseFreq(struct nlattr**);
|
2024-07-12 20:46:26 -05:00
|
|
|
void parseBssid(struct nlattr**);
|
2022-04-06 08:37:19 +02:00
|
|
|
bool associatedOrJoined(struct nlattr**);
|
2025-07-25 18:19:14 -04:00
|
|
|
bool matchInterface(const std::string& ifname, const std::vector<std::string>& altnames,
|
|
|
|
|
std::string& matched) const;
|
2022-04-06 08:37:19 +02:00
|
|
|
auto getInfo() -> void;
|
2019-05-24 09:49:56 +02:00
|
|
|
const std::string getNetworkState() const;
|
2022-04-06 08:37:19 +02:00
|
|
|
void clearIface();
|
2021-08-25 14:47:51 -07:00
|
|
|
std::optional<std::pair<unsigned long long, unsigned long long>> readBandwidthUsage();
|
2018-08-17 14:24:00 +02:00
|
|
|
|
2025-07-03 16:35:18 -04:00
|
|
|
int ifid_{-1};
|
|
|
|
|
ip_addr_pref addr_pref_{ip_addr_pref::IPV4};
|
|
|
|
|
struct sockaddr_nl nladdr_{0};
|
|
|
|
|
struct nl_sock* sock_{nullptr};
|
|
|
|
|
struct nl_sock* ev_sock_{nullptr};
|
|
|
|
|
int efd_{-1};
|
|
|
|
|
int ev_fd_{-1};
|
|
|
|
|
int nl80211_id_{-1};
|
2022-04-06 08:37:19 +02:00
|
|
|
std::mutex mutex_;
|
2019-04-18 17:52:00 +02:00
|
|
|
|
2025-07-03 16:35:18 -04:00
|
|
|
bool want_route_dump_{false};
|
|
|
|
|
bool want_link_dump_{false};
|
|
|
|
|
bool want_addr_dump_{false};
|
|
|
|
|
bool dump_in_progress_{false};
|
|
|
|
|
bool is_p2p_{false};
|
2021-05-15 16:38:00 +01:00
|
|
|
|
2025-07-03 16:35:18 -04:00
|
|
|
unsigned long long bandwidth_down_total_{0};
|
|
|
|
|
unsigned long long bandwidth_up_total_{0};
|
2019-05-17 23:39:51 -04:00
|
|
|
|
2019-05-24 09:49:56 +02:00
|
|
|
std::string state_;
|
2019-04-18 17:52:00 +02:00
|
|
|
std::string essid_;
|
2024-07-12 20:46:26 -05:00
|
|
|
std::string bssid_;
|
2025-07-03 16:35:18 -04:00
|
|
|
bool carrier_{false};
|
2019-04-18 17:52:00 +02:00
|
|
|
std::string ifname_;
|
|
|
|
|
std::string ipaddr_;
|
2025-02-26 15:59:33 +05:30
|
|
|
std::string ipaddr6_;
|
2021-09-09 20:05:18 +02:00
|
|
|
std::string gwaddr_;
|
2019-04-18 17:52:00 +02:00
|
|
|
std::string netmask_;
|
2025-03-04 19:09:21 +05:30
|
|
|
std::string netmask6_;
|
2025-07-03 16:35:18 -04:00
|
|
|
int cidr_{0};
|
|
|
|
|
int cidr6_{0};
|
2022-04-06 08:37:19 +02:00
|
|
|
int32_t signal_strength_dbm_;
|
|
|
|
|
uint8_t signal_strength_;
|
2021-12-14 11:37:39 -07:00
|
|
|
std::string signal_strength_app_;
|
2022-04-06 08:37:19 +02:00
|
|
|
uint32_t route_priority;
|
2019-05-29 17:53:22 +02:00
|
|
|
|
|
|
|
|
util::SleeperThread thread_;
|
|
|
|
|
util::SleeperThread thread_timer_;
|
2020-08-14 20:58:48 +02:00
|
|
|
#ifdef WANT_RFKILL
|
2025-07-03 16:35:18 -04:00
|
|
|
util::Rfkill rfkill_{RFKILL_TYPE_WLAN};
|
2020-08-14 20:58:48 +02:00
|
|
|
#endif
|
2025-07-03 16:35:18 -04:00
|
|
|
float frequency_{0};
|
2018-08-16 14:29:41 +02:00
|
|
|
};
|
2018-08-09 16:38:24 +02:00
|
|
|
|
2019-04-18 17:52:00 +02:00
|
|
|
} // namespace waybar::modules
|