aboutsummaryrefslogtreecommitdiffstats
path: root/iw_if.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--iw_if.h234
1 files changed, 65 insertions, 169 deletions
diff --git a/iw_if.h b/iw_if.h
index 494afa0..cc9e886 100644
--- a/iw_if.h
+++ b/iw_if.h
@@ -18,7 +18,9 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "wavemon.h"
+#include "nl80211.h"
#include <netdb.h>
+#include <stdbool.h>
#include <pthread.h>
#include <arpa/inet.h>
#include <netinet/in.h>
@@ -33,22 +35,24 @@
#ifndef IW_POWER_SAVING
#define IW_POWER_SAVING 0x4000 /* version 20 -> 21 */
#endif
-#ifndef IW_MODE_MESH
-#define IW_MODE_MESH 7 /* introduced in 2.6.26-rc1 */
-#endif
-/* Maximum length of a MAC address: 2 * 6 hex digits, 6 - 1 colons, plus '\0' */
-#define MAC_ADDR_MAX 18
+/* Definitions from linux/ieee80211.h (not necessarily part of distro headers) */
+#define WLAN_CAPABILITY_ESS (1<<0)
+#define WLAN_CAPABILITY_IBSS (1<<1)
+#define WLAN_CAPABILITY_IS_STA_BSS(cap) \
+ (!((cap) & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)))
+#define WLAN_CAPABILITY_PRIVACY (1<<4)
+
+/* 802.11h */
+#define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8)
+#define WLAN_CAPABILITY_QOS (1<<9)
+#define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
+#define WLAN_CAPABILITY_APSD (1<<11)
+#define WLAN_CAPABILITY_RADIO_MEASURE (1<<12)
+#define WLAN_CAPABILITY_DSSS_OFDM (1<<13)
+#define WLAN_CAPABILITY_DEL_BACK (1<<14)
+#define WLAN_CAPABILITY_IMM_BACK (1<<15)
-/*
- * Threshold for 'sane' noise levels.
- *
- * Some drivers simply set an arbitrary minimum noise level to mean 'invalid',
- * but do not set IW_QUAL_NOISE_INVALID so that the display gets stuck at a
- * "house number". The value below is suggested by and taken from the iwl3945
- * driver (constant IWL_NOISE_MEAS_NOT_AVAILABLE in iwl-3945.h).
- */
-#define NOISE_DBM_SANE_MIN -127
/**
* struct if_info - wireless interface network information
@@ -70,6 +74,7 @@ struct if_info {
uint16_t txqlen;
uint16_t flags;
};
+extern bool if_is_up(const char *ifname);
extern int if_set_up(const char *ifname);
extern void if_getinf(const char *ifname, struct if_info *info);
@@ -95,7 +100,6 @@ struct iw_key {
* @essid: Extended Service Set ID (network name)
* @essid_ct: index number of the @essid (starts at 1, 0 = off)
* @nickname: optional station nickname
- * @nwid: Network ID (pre-802.11 hardware only)
* @ap_addr: BSSID or IBSSID
*
* @retry: MAC-retransmission retry behaviour
@@ -118,7 +122,6 @@ struct iw_dyn_info {
uint8_t mode;
bool cap_essid:1,
- cap_nwid:1,
cap_nickname:1,
cap_freq:1,
cap_sens:1,
@@ -134,7 +137,6 @@ struct iw_dyn_info {
char essid[IW_ESSID_MAX_SIZE+2];
uint8_t essid_ct;
char nickname[IW_ESSID_MAX_SIZE+2];
- struct iw_param nwid;
struct sockaddr ap_addr;
struct iw_param retry;
@@ -202,28 +204,10 @@ struct iw_levelstat {
#define IW_LSTAT_INIT { 0, 0, IW_QUAL_LEVEL_INVALID | IW_QUAL_NOISE_INVALID }
extern void iw_getinf_range(const char *ifname, struct iw_range *range);
-extern void iw_sanitize(struct iw_range *range,
- struct iw_quality *qual,
- struct iw_levelstat *dbm);
-
-/**
- * struct iw_stat - record current WiFi state
- * @range: current range information
- * @stats: current signal level statistics
- * @dbm: the noise/signal of @stats in dBm
- */
-struct iw_stat {
- struct iw_range range;
- struct iw_statistics stat;
- struct iw_levelstat dbm;
-};
/*
* Periodic sampling of wireless statistics via timer alarm
*/
-extern void iw_getstat(struct iw_stat *stat);
-extern void iw_cache_update(struct iw_stat *stat);
-
extern void sampling_init(void (*sampling_handler)(int));
extern void sampling_do_poll(void);
static inline void sampling_stop(void) { alarm(0); }
@@ -233,27 +217,35 @@ static inline void sampling_stop(void) { alarm(0); }
*/
/**
* struct scan_entry - Representation of a single scan result.
- * @ap_addr: MAC address
- * @essid: station SSID (may be empty)
- * @mode: operation mode (type of station)
- * @freq: frequency/channel information
- * @chan: channel corresponding to @freq (where applicable)
- * @qual: signal quality information
- * @has_key: whether using encryption or not
- * @flags: properties gathered from Information Elements
- * @next: next entry in list
+ * @ap_addr: MAC address
+ * @essid: station SSID (may be empty)
+ * @freq: frequency in MHz
+ * @chan: channel corresponding to @freq (where applicable)
+ * @has_key: whether using encryption or not
+ * @last_seen: time station was last seen in seconds
+ * @tsf: value of the Timing Synchronisation Function counter
+ * @bss_signal: signal strength of BSS probe in dBm (or 0)
+ * @bss_signal_qual: unitless signal strength of BSS probe, 0..100
+ * @bss_capa: BSS capability flags
+ * @bss_sta_count: BSS station count
+ * @bss_chan_usage: BSS channel utilisation
+ * @next: next entry in list
*/
struct scan_entry {
struct ether_addr ap_addr;
char essid[IW_ESSID_MAX_SIZE + 2];
- int mode;
- double freq;
+ uint32_t freq;
int chan;
- struct iw_quality qual;
- struct iw_levelstat dbm;
+ uint8_t has_key:1;
- int has_key:1;
- uint32_t flags;
+ uint32_t last_seen;
+ uint64_t tsf;
+
+ int8_t bss_signal;
+ uint8_t bss_signal_qual;
+ uint16_t bss_capa;
+ uint8_t bss_sta_count,
+ bss_chan_usage;
struct scan_entry *next;
};
@@ -280,7 +272,6 @@ struct cnt {
* @num.two_gig: number of 2.4GHz stations among @num.total
* @num.five_gig: number of 5 GHz stations among @num.total
* @num.ch_stats: length of @channel_stats array
- * @range: range data associated with scan interface
* @mutex: protects against concurrent consumer/producer access
*/
struct scan_result {
@@ -297,7 +288,6 @@ struct scan_result {
#define MAX_CH_STATS 3
size_t ch_stats;
} num;
- struct iw_range range;
pthread_mutex_t mutex;
};
@@ -306,125 +296,31 @@ extern void scan_result_fini(struct scan_result *sr);
extern void *do_scan(void *sr_ptr);
/*
- * General helper routines
+ * utils.c
*/
-static inline const char *iw_opmode(const uint8_t mode)
-{
- static char *modes[] = {
- [IW_MODE_AUTO] = "Auto",
- [IW_MODE_ADHOC] = "Ad-Hoc",
- [IW_MODE_INFRA] = "Managed",
- [IW_MODE_MASTER] = "Master",
- [IW_MODE_REPEAT] = "Repeater",
- [IW_MODE_SECOND] = "Secondary",
- [IW_MODE_MONITOR] = "Monitor",
- [IW_MODE_MESH] = "Mesh"
- };
-
- return mode < ARRAY_SIZE(modes) ? modes[mode] : "Unknown/bug";
-}
-
-/* Print a mac-address, include leading zeroes (unlike ether_ntoa(3)) */
-static inline char *ether_addr(const struct ether_addr *ea)
-{
- static char mac[MAC_ADDR_MAX];
- char *d = mac, *a = ether_ntoa(ea);
-next_chunk:
- if (a[0] == '\0' || a[1] == '\0' || a[1] == ':')
- *d++ = '0';
- while ((*d++ = conf.cisco_mac ? (*a == ':' ? '.' : *a) : toupper(*a)))
- if (*a++ == ':')
- goto next_chunk;
- return mac;
-}
-
-/* Print mac-address translation from /etc/ethers if available */
-static inline char *ether_lookup(const struct ether_addr *ea)
-{
- static char hostname[BUFSIZ];
-
- if (ether_ntohost(hostname, ea) == 0)
- return hostname;
- return ether_addr(ea);
-}
-
-/* Format an Ethernet mac address */
-static inline char *mac_addr(const struct sockaddr *sa)
-{
- if (sa->sa_family != ARPHRD_ETHER)
- return "00:00:00:00:00:00";
- return ether_lookup((const struct ether_addr *)sa->sa_data);
-}
-
-/* Format a (I)BSSID */
-static inline char *format_bssid(const struct sockaddr *ap)
-{
- uint8_t bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
- uint8_t zero_addr[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
- if (memcmp(ap->sa_data, zero_addr, ETH_ALEN) == 0)
- return "Not-Associated";
- if (memcmp(ap->sa_data, bcast_addr, ETH_ALEN) == 0)
- return "Invalid";
- return mac_addr(ap);
-}
-
-/* count bits set in @mask the Brian Kernighan way */
-static inline uint8_t bit_count(uint32_t mask)
-{
- uint8_t bits_set;
-
- for (bits_set = 0; mask; bits_set++)
- mask &= mask - 1;
-
- return bits_set;
-}
-
-/* netmask = contiguous 1's followed by contiguous 0's */
-static inline uint8_t prefix_len(const struct in_addr *netmask)
-{
- return bit_count(netmask->s_addr);
-}
-
-/* Absolute power measurement in dBm (IW_QUAL_DBM): map into -192 .. 63 range */
-static inline int u8_to_dbm(const int power)
-{
- return power > 63 ? power - 0x100 : power;
-}
-static inline uint8_t dbm_to_u8(const int dbm)
-{
- return dbm < 0 ? dbm + 0x100 : dbm;
-}
-
-/* Convert log dBm values to linear mW */
-static inline double dbm2mw(const double in)
-{
- return pow(10.0, in / 10.0);
-}
-
-static inline char *dbm2units(const double in)
-{
- static char with_units[0x100];
- double val = dbm2mw(in);
-
- if (val < 0.00000001) {
- sprintf(with_units, "%.2f pW", val * 1e9);
- } else if (val < 0.00001) {
- sprintf(with_units, "%.2f nW", val * 1e6);
- } else if (val < 0.01) {
- sprintf(with_units, "%.2f uW", val * 1e3);
- } else {
- sprintf(with_units, "%.2f mW", val);
- }
- return with_units;
-}
-
-/* Convert linear mW values to log dBm */
-static inline double mw2dbm(const double in)
-{
- return 10.0 * log10(in);
-}
+extern char *ether_addr(const struct ether_addr *ea);
+extern char *ether_lookup(const struct ether_addr *ea);
+extern char *mac_addr(const struct sockaddr *sa);
+extern char *format_bssid(const struct sockaddr *ap);
+extern uint8_t bit_count(uint32_t mask);
+extern uint8_t prefix_len(const struct in_addr *netmask);
+extern const char *pretty_time(const unsigned sec);
+extern const char *pretty_time_ms(const unsigned msec);
+extern int u8_to_dbm(const int power);
+extern uint8_t dbm_to_u8(const int dbm);
+extern double dbm2mw(const double in);
+extern char *dbm2units(const double in);
+extern double mw2dbm(const double in);
+
+extern const char *dfs_domain_name(enum nl80211_dfs_regions region);
+extern int ieee80211_frequency_to_channel(int freq);
+extern const char *channel_width_name(enum nl80211_chan_width width);
+extern const char *channel_type_name(enum nl80211_channel_type channel_type);
+extern const char *iftype_name(enum nl80211_iftype iftype);
+/*
+ * WEXT helper routines
+ */
/* Format driver TX power information */
static inline char *format_txpower(const struct iw_param *txpwr)
{