]> git.sur5r.net Git - i3/i3status/commitdiff
i3status: Support %frequency for wireless interfaces
authorTuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Mon, 1 Dec 2014 16:30:30 +0000 (18:30 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 3 Dec 2014 07:14:21 +0000 (08:14 +0100)
In many public WiFis, the 2.4 GHz wireless band is slow due to
congestion, while there is still plenty of bandwidth available on the
5 GHz area. So when debugging wireless issues it's convenient to have
i3status display the frequency of the access point that the interface is
connected to.

This patch adds support for the %frequency tag for wireless interfaces,
so for example:
    format_up = "WLAN: %essid - %quality / %frequency"
would result in:
    "WLAN: eduroam - 074% / 2.4 GHz"

man/i3status.man
src/print_wireless_info.c

index 504cf16fd329ba874c4c768ad0f36b72e091ba2d..06dc4a64cc1842520375027e1dbd568ef2d1b512 100644 (file)
@@ -270,13 +270,13 @@ something is active, like for example a VPN tunnel managed by NetworkManager.
 
 === Wireless
 
-Gets the link quality and ESSID of the given wireless network interface. You
-can specify different format strings for the network being connected or not
-connected.
+Gets the link quality, frequency and ESSID of the given wireless network
+interface. You can specify different format strings for the network being
+connected or not connected.
 
 *Example order*: +wireless wlan0+
 
-*Example format*: +W: (%quality at %essid, %bitrate) %ip+
+*Example format*: +W: (%quality at %essid, %bitrate / %frequency) %ip+
 
 === Ethernet
 
index 18f658073619ca408406968c6fc24d6d2dfe9022..7f7c52e3f615e9cdf159dc81785b00c0304df7d7 100644 (file)
@@ -55,6 +55,7 @@
 #define WIRELESS_INFO_FLAG_HAS_QUALITY                  (1 << 1)
 #define WIRELESS_INFO_FLAG_HAS_SIGNAL                   (1 << 2)
 #define WIRELESS_INFO_FLAG_HAS_NOISE                    (1 << 3)
+#define WIRELESS_INFO_FLAG_HAS_FREQUENCY                (1 << 4)
 
 #define PERCENT_VALUE(value, total) ((int)(value * 100 / (float)total + 0.5f))
 
@@ -69,6 +70,7 @@ typedef struct {
         int noise_level;
         int noise_level_max;
         int bitrate;
+        double frequency;
 } wireless_info_t;
 
 static int get_wireless_info(const char *interface, wireless_info_t *info) {
@@ -93,6 +95,11 @@ static int get_wireless_info(const char *interface, wireless_info_t *info) {
                 info->essid[IW_ESSID_MAX_SIZE] = '\0';
         }
 
+        if (wcfg.has_freq) {
+                info->frequency = wcfg.freq;
+                info->flags |= WIRELESS_INFO_FLAG_HAS_FREQUENCY;
+        }
+
         /* If the function iw_get_stats does not return proper stats, the
            wifi is considered as down.
            Since ad-hoc network does not have theses stats, we need to return
@@ -395,6 +402,14 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
                         walk += strlen("essid");
                 }
 
+                if (BEGINS_WITH(walk+1, "frequency")) {
+                        if (info.flags & WIRELESS_INFO_FLAG_HAS_FREQUENCY)
+                                outwalk += sprintf(outwalk, "%1.1f GHz", info.frequency / 1e9);
+                        else
+                                *(outwalk++) = '?';
+                        walk += strlen("frequency");
+                }
+
                 if (BEGINS_WITH(walk+1, "ip")) {
                        outwalk += sprintf(outwalk, "%s", ip_address);
                        walk += strlen("ip");