2018-08-09 16:38:24 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <net/if.h>
|
2018-11-13 21:31:26 +01:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <ifaddrs.h>
|
2018-08-09 16:38:24 +02:00
|
|
|
#include <netlink/netlink.h>
|
|
|
|
#include <netlink/genl/genl.h>
|
|
|
|
#include <netlink/genl/ctrl.h>
|
|
|
|
#include <linux/nl80211.h>
|
2018-12-26 11:13:36 +01:00
|
|
|
#include <sys/epoll.h>
|
2018-08-09 16:38:24 +02:00
|
|
|
#include <fmt/format.h>
|
2018-12-26 11:13:36 +01:00
|
|
|
#include "util/sleeper_thread.hpp"
|
2018-08-18 11:43:48 +02:00
|
|
|
#include "ALabel.hpp"
|
2018-08-09 16:38:24 +02:00
|
|
|
|
|
|
|
namespace waybar::modules {
|
|
|
|
|
2018-08-18 11:43:48 +02:00
|
|
|
class Network : public ALabel {
|
2018-08-16 14:29:41 +02:00
|
|
|
public:
|
2018-12-18 17:30:54 +01:00
|
|
|
Network(const std::string&, const Json::Value&);
|
2018-08-19 13:39:57 +02:00
|
|
|
~Network();
|
2018-08-16 14:29:41 +02:00
|
|
|
auto update() -> void;
|
|
|
|
private:
|
2019-02-11 19:06:39 +01:00
|
|
|
static const uint8_t MAX_RETRY = 5;
|
2019-03-18 11:07:36 +01:00
|
|
|
static const uint8_t EPOLL_MAX = 255;
|
2019-02-06 10:33:12 +01:00
|
|
|
|
2019-03-30 09:03:31 +01:00
|
|
|
static int handleEvents(struct nl_msg*, void*);
|
2018-12-26 11:13:36 +01:00
|
|
|
static int handleScan(struct nl_msg*, void*);
|
2018-08-16 14:29:41 +02:00
|
|
|
|
2018-11-16 10:02:12 +01:00
|
|
|
void worker();
|
2018-08-17 14:24:00 +02:00
|
|
|
void disconnected();
|
2018-12-26 11:13:36 +01:00
|
|
|
void createInfoSocket();
|
|
|
|
void createEventSocket();
|
2018-08-17 14:24:00 +02:00
|
|
|
int getExternalInterface();
|
2018-11-13 21:31:26 +01:00
|
|
|
void getInterfaceAddress();
|
2018-12-26 11:13:36 +01:00
|
|
|
int netlinkRequest(void*, uint32_t, uint32_t groups = 0);
|
|
|
|
int netlinkResponse(void*, uint32_t, uint32_t groups = 0);
|
2018-08-16 14:29:41 +02:00
|
|
|
void parseEssid(struct nlattr**);
|
|
|
|
void parseSignal(struct nlattr**);
|
|
|
|
bool associatedOrJoined(struct nlattr**);
|
|
|
|
auto getInfo() -> void;
|
|
|
|
|
|
|
|
waybar::util::SleeperThread thread_;
|
2018-11-16 10:02:12 +01:00
|
|
|
waybar::util::SleeperThread thread_timer_;
|
2018-08-17 14:24:00 +02:00
|
|
|
int ifid_;
|
|
|
|
sa_family_t family_;
|
2018-11-16 10:02:12 +01:00
|
|
|
struct sockaddr_nl nladdr_ = {0};
|
2018-08-24 15:32:06 +02:00
|
|
|
struct nl_sock* sk_ = nullptr;
|
2019-03-30 09:03:31 +01:00
|
|
|
struct nl_sock* info_sock_ = nullptr;
|
2018-12-26 11:13:36 +01:00
|
|
|
int efd_;
|
|
|
|
int ev_fd_;
|
2018-08-24 15:32:06 +02:00
|
|
|
int nl80211_id_;
|
2018-08-17 14:24:00 +02:00
|
|
|
|
2018-08-16 14:29:41 +02:00
|
|
|
std::string essid_;
|
2018-08-17 14:24:00 +02:00
|
|
|
std::string ifname_;
|
2018-11-13 21:31:26 +01:00
|
|
|
std::string ipaddr_;
|
|
|
|
std::string netmask_;
|
|
|
|
int cidr_;
|
2018-12-27 11:41:43 +01:00
|
|
|
int32_t signal_strength_dbm_;
|
|
|
|
uint8_t signal_strength_;
|
2018-08-16 14:29:41 +02:00
|
|
|
};
|
2018-08-09 16:38:24 +02:00
|
|
|
|
|
|
|
}
|