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