You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

117 lines
3.1 KiB

#ifndef LIBIP_WIRELESS_H
#define LIBIP_WIRELESS_H
#include <QObject>
#include <QMap>
#include "libip_global.h"
#include <linux/nl80211.h>
#include <QRegularExpression>
class LIBIP_EXPORT Wireless : public QObject {
//Q_OBJECT
// no Q_OBJECT macro here because clang linker complains about missing vtable, probably because we aren't using any signals/slots
public:
Wireless(QString interface = QString());
~Wireless();
struct ChannelInfo {
int chan;
int freq;
// these boolean values may change depending on the current regulatory domain set
bool disabled; // both TX/RX disabled
bool passive; // RX-only channel
bool radar; // DFS (radar detection) required
int max_txpower; // in millibels (mBm); 100 mBm = 1 dBm
ChannelInfo() :
chan(0),
freq(0),
disabled(false),
passive(false),
radar(false),
max_txpower(0)
{
}
};
struct BandInfo {
int band;
int width;
int protocols;
QList<ChannelInfo> channels;
BandInfo() :
band(0),
width(0),
protocols(0),
channels()
{
}
};
enum Bands {
BAND_2GHZ = (1 << 0),
BAND_5GHZ = (1 << 1),
BAND_60GHZ = (1 << 2)
};
enum Protocols {
PROTOCOL_80211_A = (1 << 0),
PROTOCOL_80211_B = (1 << 1),
PROTOCOL_80211_G = (1 << 2),
PROTOCOL_80211_N = (1 << 3)
};
enum Direction {
Direction_RX = (1 << 0),
Direction_Both = (1 << 1)
};
enum ChannelWidth {
WIDTH_20MHZ = (1 << 0),
WIDTH_40MHZ = (1 << 1),
WIDTH_80MHZ = (1 << 2),
WIDTH_160MHZ = (1 << 3)
};
const QString& name() const;
const QList<BandInfo>& bandMap() const;
QList<int> allChannels() const;
QList<int> allowedChannels(Direction direction) const;
QList<int> allFrequencies() const;
QList<int> allowedFrequencies(Direction direction) const;
static int ChanToFreq(int channel);
static QString ChanToFreq(QString channel, QString outputFormat = QString());
static int FreqToChan(int frequency);
static QString FreqToChan(QString frequency, QString outputFormat = QString());
static QStringList interfaceList();
bool isValid() const;
bool isNL80211() const;
bool channelSupported(int channel) const;
bool frequencySupported(int frequency) const;
nl80211_iftype getInterfaceTypeRaw();
const QString& getInterfaceType() const;
private:
QString m_interface;
QString m_interfaceType;
QList<BandInfo> m_bands;
bool m_isValid;
bool m_isNL80211;
nl80211_iftype m_iftype;
bool parseBands();
bool parseInterface();
static int nl80211_interface_cb(struct nl_msg *msg, void *arg);
static int nl80211_freqlist_cb(struct nl_msg *msg, void *arg);
static int nl80211_error_cb(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg);
static int nl80211_finish_cb(struct nl_msg *msg, void *arg);
char* nl80211_find_parent(const char *interface) const;
void nl80211_disconnect(void *handle, struct nl_cache *cache, struct genl_family *family) const;
int nl80211_connect(const char *interface, void **handle, struct nl_cache **cache, struct genl_family **family) const;
};
#endif // LIBIP_WIRELESS_H