From 6ccde5e7e72d07605743a540556d27c66292e3b7 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Mon, 7 Jun 2010 09:54:25 +0200 Subject: [PATCH] Add support for $wireless_channel (based on a patch by Timothy Ball) --- src/core.cc | 3 +++ src/linux.cc | 8 ++++++++ src/net_stat.cc | 13 +++++++++++++ src/net_stat.h | 2 ++ 4 files changed, 26 insertions(+) diff --git a/src/core.cc b/src/core.cc index 04e8b9db..99a25a59 100644 --- a/src/core.cc +++ b/src/core.cc @@ -360,6 +360,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long END OBJ(wireless_essid, &update_net_stats) obj->data.opaque = get_net_stat(arg, obj, free_at_crash); obj->callbacks.print = &print_wireless_essid; + END OBJ(wireless_channel, &update_net_stats) + parse_net_stat_arg(obj, arg, free_at_crash); + obj->callbacks.print = &print_wireless_channel; END OBJ(wireless_mode, &update_net_stats) parse_net_stat_arg(obj, arg, free_at_crash); obj->callbacks.print = &print_wireless_mode; diff --git a/src/linux.cc b/src/linux.cc index 965f9909..4e7db594 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -546,6 +546,14 @@ int update_net_stats(void) snprintf(ns->essid, 32, "off/any"); } } + // get channel + if (winfo->b.has_freq) { + if(winfo->has_range == 1) { + ns->channel = iw_freq_to_channel(winfo->b.freq, &(winfo->range)); + } else { + ns->channel = 0; + } + } snprintf(ns->mode, 16, "%s", iw_operation_mode[winfo->b.mode]); } diff --git a/src/net_stat.cc b/src/net_stat.cc index a1963850..ba7054f8 100644 --- a/src/net_stat.cc +++ b/src/net_stat.cc @@ -247,6 +247,19 @@ void print_wireless_mode(struct text_object *obj, char *p, int p_max_size) snprintf(p, p_max_size, "%s", ns->mode); } +void print_wireless_channel(struct text_object *obj, char *p, int p_max_size) +{ + struct net_stat *ns = (struct net_stat *)obj->data.opaque; + + if (!ns) + return; + + if(ns->channel != 0) { + snprintf(p, p_max_size, "%i", ns->channel); + } else { + snprintf(p, p_max_size, "/"); + } +} void print_wireless_bitrate(struct text_object *obj, char *p, int p_max_size) { struct net_stat *ns = (struct net_stat *)obj->data.opaque; diff --git a/src/net_stat.h b/src/net_stat.h index 52e638a0..b583ca2f 100644 --- a/src/net_stat.h +++ b/src/net_stat.h @@ -46,6 +46,7 @@ struct net_stat { double net_rec[15], net_trans[15]; // wireless extensions char essid[32]; + int channel; char bitrate[16]; char mode[16]; int link_qual; @@ -76,6 +77,7 @@ double upspeedgraphval(struct text_object *); #endif /* BUILD_X11 */ #ifdef BUILD_WLAN void print_wireless_essid(struct text_object *, char *, int); +void print_wireless_channel(struct text_object *, char *, int); void print_wireless_mode(struct text_object *, char *, int); void print_wireless_bitrate(struct text_object *, char *, int); void print_wireless_ap(struct text_object *, char *, int);