Patchwork [OpenWrt-Devel,packages] mini_snmpd: Add wireless signal and noise data

login
register
Submitter Jack Bates
Date 2012-12-21 08:24:48
Message ID <50D41CD0.9060306@nottheoilrig.com>
Download mbox | patch
Permalink /patch/3061/
State Changes Requested
Delegated to: John Crispin
Headers show

Comments

Jack Bates - 2012-12-21 08:24:48
Support monitoring wireless signal and noise with SNMP. This is based on
the demo example distributed with Mini SNMP Daemon. Here is a recipe for
configuring Cacti to graph this data:
http://jdbates.blogspot.com/2012/12/heres-patch-for-mini-snmp-daemon-to.html

Signed-off-by: Jack Bates <jack@nottheoilrig.com>
---
We have been successfully running this patch on 32 devices for a month,
to monitor signal and noise with Cacti. I am happy to make any changes
that you request.
ZioPRoTo (Saverio Proto) - 2013-01-03 13:34:34
Hello Jack,

did you send this patch also to the mini_snmpd developers to have this
patch in the next releases ?

thanks

Saverio Proto


2012/12/21 Jack Bates <k15tb2@nottheoilrig.com>:
> Support monitoring wireless signal and noise with SNMP. This is based on
> the demo example distributed with Mini SNMP Daemon. Here is a recipe for
> configuring Cacti to graph this data:
> http://jdbates.blogspot.com/2012/12/heres-patch-for-mini-snmp-daemon-to.html
>
> Signed-off-by: Jack Bates <jack@nottheoilrig.com>
> ---
> We have been successfully running this patch on 32 devices for a month,
> to monitor signal and noise with Cacti. I am happy to make any changes
> that you request.
>
> Index: packages/net/mini_snmpd/patches/104-wireless.patch
> ===================================================================
> --- packages/net/mini_snmpd/patches/104-wireless.patch  (revision 0)
> +++ packages/net/mini_snmpd/patches/104-wireless.patch  (working copy)
> @@ -0,0 +1,223 @@
> +--- a/globals.c
> ++++ b/globals.c
> +@@ -47,6 +47,10 @@
> + int g_disk_list_length = 0;
> + char *g_interface_list[MAX_NR_INTERFACES];
> + int g_interface_list_length = 0;
> ++#ifdef __WIRELESS__
> ++char *g_wireless_list[MAX_NR_INTERFACES];
> ++int g_wireless_list_length = 0;
> ++#endif
> + client_t g_udp_client = { 0, };
> + client_t *g_tcp_client_list[MAX_NR_CLIENTS];
> + int g_tcp_client_list_length = 0;
> +--- a/Makefile
> ++++ b/Makefile
> +@@ -34,7 +34,7 @@
> + VENDOR        = .1.3.6.1.4.1
> + OFLAGS        = -O2
> + CFLAGS        = -Wall -Werror -DVERSION="\"$(VERSION)\"" -DVENDOR="\"$(VENDOR)\"" \
> +-        $(OFLAGS) -D__TRAPS__ -D__LINUX__
> ++        $(OFLAGS) -D__TRAPS__ -D__LINUX__ -D__WIRELESS__
> + LDFLAGS       = $(OFLAGS)
> + TARGET        = mini_snmpd
> + MAN   = mini_snmpd.8
> +--- a/mib.c
> ++++ b/mib.c
> +@@ -46,6 +46,9 @@
> + static const oid_t m_if_1_oid         = { { 1, 3, 6, 1, 2, 1, 2                       }, 7, 8  };
> + static const oid_t m_if_2_oid         = { { 1, 3, 6, 1, 2, 1, 2, 2, 1         }, 9, 10 };
> + static const oid_t m_host_oid         = { { 1, 3, 6, 1, 2, 1, 25, 1           }, 8, 9  };
> ++#ifdef __WIRELESS__
> ++static const oid_t m_wireless_oid     = { { 1, 3, 6, 1, 4, 1, 762, 2, 5, 2, 1 }, 11, 13 };
> ++#endif
> + static const oid_t m_memory_oid               = { { 1, 3, 6, 1, 4, 1, 2021, 4,        }, 8, 10 };
> + static const oid_t m_disk_oid         = { { 1, 3, 6, 1, 4, 1, 2021, 9, 1      }, 9, 11 };
> + static const oid_t m_load_oid         = { { 1, 3, 6, 1, 4, 1, 2021, 10, 1     }, 9, 11 };
> +@@ -527,6 +530,25 @@
> +               return -1;
> +       }
> +
> ++#ifdef __WIRELESS__
> ++      if (g_wireless_list_length > 0) {
> ++              for (i = 0; i < g_wireless_list_length; i++) {
> ++                      if (mib_build_entry(&m_wireless_oid, 1, i + 1, BER_TYPE_INTEGER, (const void *)(i + 1)) == -1) {
> ++                              return -1;
> ++                      }
> ++              }
> ++              for (i = 0; i < g_wireless_list_length; i++) {
> ++                      if (mib_build_entry(&m_wireless_oid, 3, i + 1, BER_TYPE_OCTET_STRING, g_wireless_list[i]) == -1) {
> ++                              return -1;
> ++                      }
> ++              }
> ++              if (mib_build_entries(&m_wireless_oid, 7, 1, g_wireless_list_length, BER_TYPE_INTEGER, (const void *)0) == -1
> ++                      || mib_build_entries(&m_wireless_oid, 8, 1, g_wireless_list_length, BER_TYPE_INTEGER, (const void *)0) == -1) {
> ++                      return -1;
> ++              }
> ++      }
> ++#endif
> ++
> +       /* The memory MIB: total/free memory (UCD-SNMP-MIB.txt)
> +        * Caution: on changes, adapt the corresponding mib_update() section too!
> +        */
> +@@ -621,6 +643,9 @@
> +               meminfo_t meminfo;
> +               cpuinfo_t cpuinfo;
> +               netinfo_t netinfo;
> ++#ifdef __WIRELESS__
> ++              wirelessinfo_t wirelessinfo;
> ++#endif
> + #ifdef __DEMO__
> +               demoinfo_t demoinfo;
> + #endif
> +@@ -700,6 +725,24 @@
> +               return -1;
> +       }
> +
> ++#ifdef __WIRELESS__
> ++      if (full) {
> ++              if (g_wireless_list_length > 0) {
> ++                      get_wirelessinfo(&u.wirelessinfo);
> ++                      for (i = 0; i < g_wireless_list_length; i++) {
> ++                              if (mib_update_entry(&m_wireless_oid, 7, i + 1, &pos, BER_TYPE_INTEGER, (const void *)u.wirelessinfo.noise[i]) == -1) {
> ++                                      return -1;
> ++                              }
> ++                      }
> ++                      for (i = 0; i < g_wireless_list_length; i++) {
> ++                              if (mib_update_entry(&m_wireless_oid, 8, i + 1, &pos, BER_TYPE_INTEGER, (const void *)u.wirelessinfo.signal[i]) == -1) {
> ++                                      return -1;
> ++                              }
> ++                      }
> ++              }
> ++      }
> ++#endif
> ++
> +       /* The memory MIB: total/free memory (UCD-SNMP-MIB.txt)
> +        * Caution: on changes, adapt the corresponding mib_build() section too!
> +        */
> +--- a/mini_snmpd.c
> ++++ b/mini_snmpd.c
> +@@ -29,6 +29,7 @@
> + #include <string.h>
> + #include <stdlib.h>
> + #include <stdio.h>
> ++#include <ctype.h>
> + #include <errno.h>
> + #include <time.h>
> +
> +@@ -431,6 +432,33 @@
> +               }
> +       }
> +
> ++#ifdef __WIRELESS__
> ++      char buffer[BUFSIZ];
> ++      char *ptr;
> ++      int len;
> ++
> ++      if (read_file("/proc/net/wireless", buffer, sizeof (buffer)) != -1) {
> ++              ptr = buffer;
> ++              while (g_wireless_list_length < MAX_NR_INTERFACES) {
> ++                      while (isspace(*ptr)) {
> ++                              ptr++;
> ++                      }
> ++                      len = strcspn(ptr, "\n:");
> ++                      if (ptr[len] == '\n') {
> ++                              ptr += len;
> ++                      } else if (ptr[len] == ':') {
> ++                              g_wireless_list[g_wireless_list_length++] = strndup(ptr, len);
> ++                              ptr = strchr(ptr + len, '\n');
> ++                              if (ptr == NULL) {
> ++                                      break;
> ++                              }
> ++                      } else {
> ++                              break;
> ++                      }
> ++              }
> ++      }
> ++#endif
> ++
> +       /* Print a starting message (so the user knows the args were ok) */
> +       if (g_bind_to_device[0] != '\0') {
> +               lprintf(LOG_INFO, "started, listening on port %d/udp and %d/tcp on interface %s\n",
> +--- a/mini_snmpd.h
> ++++ b/mini_snmpd.h
> +@@ -240,6 +240,13 @@
> +       unsigned int tx_drops[MAX_NR_INTERFACES];
> + } netinfo_t;
> +
> ++#ifdef __WIRELESS__
> ++typedef struct wirelessinfo_s {
> ++      unsigned int signal[MAX_NR_INTERFACES];
> ++      unsigned int noise[MAX_NR_INTERFACES];
> ++} wirelessinfo_t;
> ++#endif
> ++
> + #ifdef __DEMO__
> + typedef struct demoinfo_s {
> +       unsigned int random_value_1;
> +@@ -274,6 +281,10 @@
> + extern int g_disk_list_length;
> + extern char *g_interface_list[MAX_NR_INTERFACES];
> + extern int g_interface_list_length;
> ++#ifdef __WIRELESS__
> ++extern char *g_wireless_list[MAX_NR_INTERFACES];
> ++extern int g_wireless_list_length;
> ++#endif
> + extern client_t g_udp_client;
> + extern client_t *g_tcp_client_list[MAX_NR_CLIENTS];
> + extern int g_tcp_client_list_length;
> +@@ -309,6 +320,9 @@
> + void get_cpuinfo(cpuinfo_t *cpuinfo);
> + void get_diskinfo(diskinfo_t *diskinfo);
> + void get_netinfo(netinfo_t *netinfo);
> ++#ifdef __WIRELESS__
> ++void get_wirelessinfo(wirelessinfo_t *wirelessinfo);
> ++#endif
> + #ifdef __DEMO__
> + void get_demoinfo(demoinfo_t *demoinfo);
> + #endif
> +--- a/utils.c
> ++++ b/utils.c
> +@@ -266,6 +266,42 @@
> +       return (pos != -1) ? g_tcp_client_list[i] : NULL;
> + }
> +
> ++#ifdef __WIRELESS__
> ++void get_wirelessinfo(wirelessinfo_t *wirelessinfo)
> ++{
> ++      char buffer[BUFSIZ];
> ++      char name[16];
> ++      char *ptr;
> ++      int i;
> ++
> ++      if (read_file("/proc/net/wireless", buffer, sizeof (buffer)) == -1) {
> ++              buffer[0] = '\0';
> ++      }
> ++      for (i = 0; i < g_wireless_list_length; i++) {
> ++              if (buffer[0] != '\0') {
> ++                      snprintf(name, sizeof (name), "%s:", g_wireless_list[i]);
> ++                      ptr = strstr(buffer, name);
> ++                      if (ptr != NULL) {
> ++                              ptr += strlen(name);
> ++                              strtoul(ptr, &ptr, 0); /* Status */
> ++
> ++                              /* When the Quality values have been updated
> ++                               * since the last read of the entry, a dot will
> ++                               * follow that value
> ++                               */
> ++                              strtoul(ptr, &ptr, 0); /* Quality */
> ++                              wirelessinfo->signal[i] = strtoul(ptr + 1, &ptr, 0); /* Signal */
> ++                              wirelessinfo->noise[i] = strtoul(ptr + 1, &ptr, 0); /* Noise */
> ++                      } else {
> ++                              wirelessinfo->signal[i] = wirelessinfo->noise[i] = 0;
> ++                      }
> ++              } else {
> ++                      wirelessinfo->signal[i] = wirelessinfo->noise[i] = 0;
> ++              }
> ++      }
> ++}
> ++#endif
> ++
> + #ifdef __DEMO__
> + void get_demoinfo(demoinfo_t *demoinfo)
> + {
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Jo-Philipp Wich - 2013-01-03 13:36:45
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I'm not sure if this patch makes much sense. The /proc/net/wireless
file is part of the legacy wext api which is scheduled for removal
soon, also the signal and noise values in ap mode are mostly
meaningless, if set at all.

~ Jow
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with undefined - http://www.enigmail.net/

iEYEARECAAYFAlDliWkACgkQdputYINPTPPYzQCgiCVXhTdTtIZu66QyZ5L3rHwI
tUkAoI2bzkeVhwXWWN+W0VhUzi+NIpnf
=RJaj
-----END PGP SIGNATURE-----
Jack Bates - 2013-03-17 17:34:27
Thank you for your reply Saverio, I did also send this patch to Robert 
Ernst, the Mini SNMP Daemon developer, but I haven't heard back from him 
yet. I contacted him again just now.

On 03/01/13 05:34 AM, Saverio Proto wrote:
> Hello Jack,
>
> did you send this patch also to the mini_snmpd developers to have this
> patch in the next releases ?
>
> thanks
>
> Saverio Proto
>
>
> 2012/12/21 Jack Bates <k15tb2@nottheoilrig.com>:
>> Support monitoring wireless signal and noise with SNMP. This is based on
>> the demo example distributed with Mini SNMP Daemon. Here is a recipe for
>> configuring Cacti to graph this data:
>> http://jdbates.blogspot.com/2012/12/heres-patch-for-mini-snmp-daemon-to.html
>>
>> Signed-off-by: Jack Bates <jack@nottheoilrig.com>
>> ---
>> We have been successfully running this patch on 32 devices for a month,
>> to monitor signal and noise with Cacti. I am happy to make any changes
>> that you request.
>>
>> Index: packages/net/mini_snmpd/patches/104-wireless.patch
>> ===================================================================
>> --- packages/net/mini_snmpd/patches/104-wireless.patch  (revision 0)
>> +++ packages/net/mini_snmpd/patches/104-wireless.patch  (working copy)
>> @@ -0,0 +1,223 @@
>> +--- a/globals.c
>> ++++ b/globals.c
>> +@@ -47,6 +47,10 @@
>> + int g_disk_list_length = 0;
>> + char *g_interface_list[MAX_NR_INTERFACES];
>> + int g_interface_list_length = 0;
>> ++#ifdef __WIRELESS__
>> ++char *g_wireless_list[MAX_NR_INTERFACES];
>> ++int g_wireless_list_length = 0;
>> ++#endif
>> + client_t g_udp_client = { 0, };
>> + client_t *g_tcp_client_list[MAX_NR_CLIENTS];
>> + int g_tcp_client_list_length = 0;
>> +--- a/Makefile
>> ++++ b/Makefile
>> +@@ -34,7 +34,7 @@
>> + VENDOR        = .1.3.6.1.4.1
>> + OFLAGS        = -O2
>> + CFLAGS        = -Wall -Werror -DVERSION="\"$(VERSION)\"" -DVENDOR="\"$(VENDOR)\"" \
>> +-        $(OFLAGS) -D__TRAPS__ -D__LINUX__
>> ++        $(OFLAGS) -D__TRAPS__ -D__LINUX__ -D__WIRELESS__
>> + LDFLAGS       = $(OFLAGS)
>> + TARGET        = mini_snmpd
>> + MAN   = mini_snmpd.8
>> +--- a/mib.c
>> ++++ b/mib.c
>> +@@ -46,6 +46,9 @@
>> + static const oid_t m_if_1_oid         = { { 1, 3, 6, 1, 2, 1, 2                       }, 7, 8  };
>> + static const oid_t m_if_2_oid         = { { 1, 3, 6, 1, 2, 1, 2, 2, 1         }, 9, 10 };
>> + static const oid_t m_host_oid         = { { 1, 3, 6, 1, 2, 1, 25, 1           }, 8, 9  };
>> ++#ifdef __WIRELESS__
>> ++static const oid_t m_wireless_oid     = { { 1, 3, 6, 1, 4, 1, 762, 2, 5, 2, 1 }, 11, 13 };
>> ++#endif
>> + static const oid_t m_memory_oid               = { { 1, 3, 6, 1, 4, 1, 2021, 4,        }, 8, 10 };
>> + static const oid_t m_disk_oid         = { { 1, 3, 6, 1, 4, 1, 2021, 9, 1      }, 9, 11 };
>> + static const oid_t m_load_oid         = { { 1, 3, 6, 1, 4, 1, 2021, 10, 1     }, 9, 11 };
>> +@@ -527,6 +530,25 @@
>> +               return -1;
>> +       }
>> +
>> ++#ifdef __WIRELESS__
>> ++      if (g_wireless_list_length > 0) {
>> ++              for (i = 0; i < g_wireless_list_length; i++) {
>> ++                      if (mib_build_entry(&m_wireless_oid, 1, i + 1, BER_TYPE_INTEGER, (const void *)(i + 1)) == -1) {
>> ++                              return -1;
>> ++                      }
>> ++              }
>> ++              for (i = 0; i < g_wireless_list_length; i++) {
>> ++                      if (mib_build_entry(&m_wireless_oid, 3, i + 1, BER_TYPE_OCTET_STRING, g_wireless_list[i]) == -1) {
>> ++                              return -1;
>> ++                      }
>> ++              }
>> ++              if (mib_build_entries(&m_wireless_oid, 7, 1, g_wireless_list_length, BER_TYPE_INTEGER, (const void *)0) == -1
>> ++                      || mib_build_entries(&m_wireless_oid, 8, 1, g_wireless_list_length, BER_TYPE_INTEGER, (const void *)0) == -1) {
>> ++                      return -1;
>> ++              }
>> ++      }
>> ++#endif
>> ++
>> +       /* The memory MIB: total/free memory (UCD-SNMP-MIB.txt)
>> +        * Caution: on changes, adapt the corresponding mib_update() section too!
>> +        */
>> +@@ -621,6 +643,9 @@
>> +               meminfo_t meminfo;
>> +               cpuinfo_t cpuinfo;
>> +               netinfo_t netinfo;
>> ++#ifdef __WIRELESS__
>> ++              wirelessinfo_t wirelessinfo;
>> ++#endif
>> + #ifdef __DEMO__
>> +               demoinfo_t demoinfo;
>> + #endif
>> +@@ -700,6 +725,24 @@
>> +               return -1;
>> +       }
>> +
>> ++#ifdef __WIRELESS__
>> ++      if (full) {
>> ++              if (g_wireless_list_length > 0) {
>> ++                      get_wirelessinfo(&u.wirelessinfo);
>> ++                      for (i = 0; i < g_wireless_list_length; i++) {
>> ++                              if (mib_update_entry(&m_wireless_oid, 7, i + 1, &pos, BER_TYPE_INTEGER, (const void *)u.wirelessinfo.noise[i]) == -1) {
>> ++                                      return -1;
>> ++                              }
>> ++                      }
>> ++                      for (i = 0; i < g_wireless_list_length; i++) {
>> ++                              if (mib_update_entry(&m_wireless_oid, 8, i + 1, &pos, BER_TYPE_INTEGER, (const void *)u.wirelessinfo.signal[i]) == -1) {
>> ++                                      return -1;
>> ++                              }
>> ++                      }
>> ++              }
>> ++      }
>> ++#endif
>> ++
>> +       /* The memory MIB: total/free memory (UCD-SNMP-MIB.txt)
>> +        * Caution: on changes, adapt the corresponding mib_build() section too!
>> +        */
>> +--- a/mini_snmpd.c
>> ++++ b/mini_snmpd.c
>> +@@ -29,6 +29,7 @@
>> + #include <string.h>
>> + #include <stdlib.h>
>> + #include <stdio.h>
>> ++#include <ctype.h>
>> + #include <errno.h>
>> + #include <time.h>
>> +
>> +@@ -431,6 +432,33 @@
>> +               }
>> +       }
>> +
>> ++#ifdef __WIRELESS__
>> ++      char buffer[BUFSIZ];
>> ++      char *ptr;
>> ++      int len;
>> ++
>> ++      if (read_file("/proc/net/wireless", buffer, sizeof (buffer)) != -1) {
>> ++              ptr = buffer;
>> ++              while (g_wireless_list_length < MAX_NR_INTERFACES) {
>> ++                      while (isspace(*ptr)) {
>> ++                              ptr++;
>> ++                      }
>> ++                      len = strcspn(ptr, "\n:");
>> ++                      if (ptr[len] == '\n') {
>> ++                              ptr += len;
>> ++                      } else if (ptr[len] == ':') {
>> ++                              g_wireless_list[g_wireless_list_length++] = strndup(ptr, len);
>> ++                              ptr = strchr(ptr + len, '\n');
>> ++                              if (ptr == NULL) {
>> ++                                      break;
>> ++                              }
>> ++                      } else {
>> ++                              break;
>> ++                      }
>> ++              }
>> ++      }
>> ++#endif
>> ++
>> +       /* Print a starting message (so the user knows the args were ok) */
>> +       if (g_bind_to_device[0] != '\0') {
>> +               lprintf(LOG_INFO, "started, listening on port %d/udp and %d/tcp on interface %s\n",
>> +--- a/mini_snmpd.h
>> ++++ b/mini_snmpd.h
>> +@@ -240,6 +240,13 @@
>> +       unsigned int tx_drops[MAX_NR_INTERFACES];
>> + } netinfo_t;
>> +
>> ++#ifdef __WIRELESS__
>> ++typedef struct wirelessinfo_s {
>> ++      unsigned int signal[MAX_NR_INTERFACES];
>> ++      unsigned int noise[MAX_NR_INTERFACES];
>> ++} wirelessinfo_t;
>> ++#endif
>> ++
>> + #ifdef __DEMO__
>> + typedef struct demoinfo_s {
>> +       unsigned int random_value_1;
>> +@@ -274,6 +281,10 @@
>> + extern int g_disk_list_length;
>> + extern char *g_interface_list[MAX_NR_INTERFACES];
>> + extern int g_interface_list_length;
>> ++#ifdef __WIRELESS__
>> ++extern char *g_wireless_list[MAX_NR_INTERFACES];
>> ++extern int g_wireless_list_length;
>> ++#endif
>> + extern client_t g_udp_client;
>> + extern client_t *g_tcp_client_list[MAX_NR_CLIENTS];
>> + extern int g_tcp_client_list_length;
>> +@@ -309,6 +320,9 @@
>> + void get_cpuinfo(cpuinfo_t *cpuinfo);
>> + void get_diskinfo(diskinfo_t *diskinfo);
>> + void get_netinfo(netinfo_t *netinfo);
>> ++#ifdef __WIRELESS__
>> ++void get_wirelessinfo(wirelessinfo_t *wirelessinfo);
>> ++#endif
>> + #ifdef __DEMO__
>> + void get_demoinfo(demoinfo_t *demoinfo);
>> + #endif
>> +--- a/utils.c
>> ++++ b/utils.c
>> +@@ -266,6 +266,42 @@
>> +       return (pos != -1) ? g_tcp_client_list[i] : NULL;
>> + }
>> +
>> ++#ifdef __WIRELESS__
>> ++void get_wirelessinfo(wirelessinfo_t *wirelessinfo)
>> ++{
>> ++      char buffer[BUFSIZ];
>> ++      char name[16];
>> ++      char *ptr;
>> ++      int i;
>> ++
>> ++      if (read_file("/proc/net/wireless", buffer, sizeof (buffer)) == -1) {
>> ++              buffer[0] = '\0';
>> ++      }
>> ++      for (i = 0; i < g_wireless_list_length; i++) {
>> ++              if (buffer[0] != '\0') {
>> ++                      snprintf(name, sizeof (name), "%s:", g_wireless_list[i]);
>> ++                      ptr = strstr(buffer, name);
>> ++                      if (ptr != NULL) {
>> ++                              ptr += strlen(name);
>> ++                              strtoul(ptr, &ptr, 0); /* Status */
>> ++
>> ++                              /* When the Quality values have been updated
>> ++                               * since the last read of the entry, a dot will
>> ++                               * follow that value
>> ++                               */
>> ++                              strtoul(ptr, &ptr, 0); /* Quality */
>> ++                              wirelessinfo->signal[i] = strtoul(ptr + 1, &ptr, 0); /* Signal */
>> ++                              wirelessinfo->noise[i] = strtoul(ptr + 1, &ptr, 0); /* Noise */
>> ++                      } else {
>> ++                              wirelessinfo->signal[i] = wirelessinfo->noise[i] = 0;
>> ++                      }
>> ++              } else {
>> ++                      wirelessinfo->signal[i] = wirelessinfo->noise[i] = 0;
>> ++              }
>> ++      }
>> ++}
>> ++#endif
>> ++
>> + #ifdef __DEMO__
>> + void get_demoinfo(demoinfo_t *demoinfo)
>> + {
>> _______________________________________________
>> openwrt-devel mailing list
>> openwrt-devel@lists.openwrt.org
>> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Jack Bates - 2013-03-17 17:46:53
On 03/01/13 05:36 AM, Jo-Philipp Wich wrote:
> I'm not sure if this patch makes much sense. The /proc/net/wireless
> file is part of the legacy wext api which is scheduled for removal
> soon, also the signal and noise values in ap mode are mostly
> meaningless, if set at all.

Thank you very much for this feedback Jow. Can you please recommend the 
current alternatives for accessing wireless signal and noise data (from 
such as Mini SNMP Daemon)?
gtolon@inti.gob.ar - 2013-04-11 14:57:00
Hi, I'm monitoring some specific parameters like busy, active, receiving 
and transmitting time from iw survey; number of connected users from iw 
station, etc. I'm running a script on routers using snmpd to get the 
data and cacti to receive it. I didn't use mini-snmpd because i couldn't 
find a way to execute scripts in the routers, the exec command in 
mini-snmpd.conf didn't work for me as it works in snmpd.

Now reading this thread i don't know if I'm using a good approach. First 
I'm not sure if it's possible or not to run scripts from mini-snmd, but 
on the other hand, i don't know if there's already some mini-snmpd 
features that allow to monitor the stuff mentioned without the need of 
scripts. I'd appreciate some help on this.

By the way, it would be great to monitor also signal and noise, maybe an 
alternative to /proc/net/wireless could be the noise from survey dump 
and the signal from station dump for each station? Anyway, I'm not sure 
how accurate are these noise and signal measurements, i've read some 
threads in ath9k lists regarding this topic:

http://www.mail-archive.com/ath9k-devel@lists.ath9k.org/msg05777.html




El 17/03/13 14:46, Jack Bates escribió:
> On 03/01/13 05:36 AM, Jo-Philipp Wich wrote:
>> I'm not sure if this patch makes much sense. The /proc/net/wireless
>> file is part of the legacy wext api which is scheduled for removal
>> soon, also the signal and noise values in ap mode are mostly
>> meaningless, if set at all.
>
> Thank you very much for this feedback Jow. Can you please recommend 
> the current alternatives for accessing wireless signal and noise data 
> (from such as Mini SNMP Daemon)?
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
>

Patch

Index: packages/net/mini_snmpd/patches/104-wireless.patch
===================================================================
--- packages/net/mini_snmpd/patches/104-wireless.patch	(revision 0)
+++ packages/net/mini_snmpd/patches/104-wireless.patch	(working copy)
@@ -0,0 +1,223 @@ 
+--- a/globals.c
++++ b/globals.c
+@@ -47,6 +47,10 @@
+ int g_disk_list_length = 0;
+ char *g_interface_list[MAX_NR_INTERFACES];
+ int g_interface_list_length = 0;
++#ifdef __WIRELESS__
++char *g_wireless_list[MAX_NR_INTERFACES];
++int g_wireless_list_length = 0;
++#endif
+ client_t g_udp_client = { 0, };
+ client_t *g_tcp_client_list[MAX_NR_CLIENTS];
+ int g_tcp_client_list_length = 0;
+--- a/Makefile
++++ b/Makefile
+@@ -34,7 +34,7 @@
+ VENDOR	= .1.3.6.1.4.1
+ OFLAGS	= -O2
+ CFLAGS	= -Wall -Werror -DVERSION="\"$(VERSION)\"" -DVENDOR="\"$(VENDOR)\"" \
+-	  $(OFLAGS) -D__TRAPS__ -D__LINUX__
++	  $(OFLAGS) -D__TRAPS__ -D__LINUX__ -D__WIRELESS__
+ LDFLAGS	= $(OFLAGS)
+ TARGET	= mini_snmpd
+ MAN 	= mini_snmpd.8
+--- a/mib.c
++++ b/mib.c
+@@ -46,6 +46,9 @@
+ static const oid_t m_if_1_oid		= { { 1, 3, 6, 1, 2, 1, 2			}, 7, 8  };
+ static const oid_t m_if_2_oid		= { { 1, 3, 6, 1, 2, 1, 2, 2, 1		}, 9, 10 };
+ static const oid_t m_host_oid		= { { 1, 3, 6, 1, 2, 1, 25, 1		}, 8, 9  };
++#ifdef __WIRELESS__
++static const oid_t m_wireless_oid	= { { 1, 3, 6, 1, 4, 1, 762, 2, 5, 2, 1	}, 11, 13 };
++#endif
+ static const oid_t m_memory_oid		= { { 1, 3, 6, 1, 4, 1, 2021, 4,	}, 8, 10 };
+ static const oid_t m_disk_oid		= { { 1, 3, 6, 1, 4, 1, 2021, 9, 1	}, 9, 11 };
+ static const oid_t m_load_oid		= { { 1, 3, 6, 1, 4, 1, 2021, 10, 1	}, 9, 11 };
+@@ -527,6 +530,25 @@
+ 		return -1;
+ 	}
+ 
++#ifdef __WIRELESS__
++	if (g_wireless_list_length > 0) {
++		for (i = 0; i < g_wireless_list_length; i++) {
++			if (mib_build_entry(&m_wireless_oid, 1, i + 1, BER_TYPE_INTEGER, (const void *)(i + 1)) == -1) {
++				return -1;
++			}
++		}
++		for (i = 0; i < g_wireless_list_length; i++) {
++			if (mib_build_entry(&m_wireless_oid, 3, i + 1, BER_TYPE_OCTET_STRING, g_wireless_list[i]) == -1) {
++				return -1;
++			}
++		}
++		if (mib_build_entries(&m_wireless_oid, 7, 1, g_wireless_list_length, BER_TYPE_INTEGER, (const void *)0) == -1
++			|| mib_build_entries(&m_wireless_oid, 8, 1, g_wireless_list_length, BER_TYPE_INTEGER, (const void *)0) == -1) {
++			return -1;
++		}
++	}
++#endif
++
+ 	/* The memory MIB: total/free memory (UCD-SNMP-MIB.txt)
+ 	 * Caution: on changes, adapt the corresponding mib_update() section too!
+ 	 */
+@@ -621,6 +643,9 @@
+ 		meminfo_t meminfo;
+ 		cpuinfo_t cpuinfo;
+ 		netinfo_t netinfo;
++#ifdef __WIRELESS__
++		wirelessinfo_t wirelessinfo;
++#endif
+ #ifdef __DEMO__
+ 		demoinfo_t demoinfo;
+ #endif
+@@ -700,6 +725,24 @@
+ 		return -1;
+ 	}
+ 
++#ifdef __WIRELESS__
++	if (full) {
++		if (g_wireless_list_length > 0) {
++			get_wirelessinfo(&u.wirelessinfo);
++			for (i = 0; i < g_wireless_list_length; i++) {
++				if (mib_update_entry(&m_wireless_oid, 7, i + 1, &pos, BER_TYPE_INTEGER, (const void *)u.wirelessinfo.noise[i]) == -1) {
++					return -1;
++				}
++			}
++			for (i = 0; i < g_wireless_list_length; i++) {
++				if (mib_update_entry(&m_wireless_oid, 8, i + 1, &pos, BER_TYPE_INTEGER, (const void *)u.wirelessinfo.signal[i]) == -1) {
++					return -1;
++				}
++			}
++		}
++	}
++#endif
++
+ 	/* The memory MIB: total/free memory (UCD-SNMP-MIB.txt)
+ 	 * Caution: on changes, adapt the corresponding mib_build() section too!
+ 	 */
+--- a/mini_snmpd.c
++++ b/mini_snmpd.c
+@@ -29,6 +29,7 @@
+ #include <string.h>
+ #include <stdlib.h>
+ #include <stdio.h>
++#include <ctype.h>
+ #include <errno.h>
+ #include <time.h>
+ 
+@@ -431,6 +432,33 @@
+ 		}
+ 	}
+ 
++#ifdef __WIRELESS__
++	char buffer[BUFSIZ];
++	char *ptr;
++	int len;
++
++	if (read_file("/proc/net/wireless", buffer, sizeof (buffer)) != -1) {
++		ptr = buffer;
++		while (g_wireless_list_length < MAX_NR_INTERFACES) {
++			while (isspace(*ptr)) {
++				ptr++;
++			}
++			len = strcspn(ptr, "\n:");
++			if (ptr[len] == '\n') {
++				ptr += len;
++			} else if (ptr[len] == ':') {
++				g_wireless_list[g_wireless_list_length++] = strndup(ptr, len);
++				ptr = strchr(ptr + len, '\n');
++				if (ptr == NULL) {
++					break;
++				}
++			} else {
++				break;
++			}
++		}
++	}
++#endif
++
+ 	/* Print a starting message (so the user knows the args were ok) */
+ 	if (g_bind_to_device[0] != '\0') {
+ 		lprintf(LOG_INFO, "started, listening on port %d/udp and %d/tcp on interface %s\n",
+--- a/mini_snmpd.h
++++ b/mini_snmpd.h
+@@ -240,6 +240,13 @@
+ 	unsigned int tx_drops[MAX_NR_INTERFACES];
+ } netinfo_t;
+ 
++#ifdef __WIRELESS__
++typedef struct wirelessinfo_s {
++	unsigned int signal[MAX_NR_INTERFACES];
++	unsigned int noise[MAX_NR_INTERFACES];
++} wirelessinfo_t;
++#endif
++
+ #ifdef __DEMO__
+ typedef struct demoinfo_s {
+ 	unsigned int random_value_1;
+@@ -274,6 +281,10 @@
+ extern int g_disk_list_length;
+ extern char *g_interface_list[MAX_NR_INTERFACES];
+ extern int g_interface_list_length;
++#ifdef __WIRELESS__
++extern char *g_wireless_list[MAX_NR_INTERFACES];
++extern int g_wireless_list_length;
++#endif
+ extern client_t g_udp_client;
+ extern client_t *g_tcp_client_list[MAX_NR_CLIENTS];
+ extern int g_tcp_client_list_length;
+@@ -309,6 +320,9 @@
+ void get_cpuinfo(cpuinfo_t *cpuinfo);
+ void get_diskinfo(diskinfo_t *diskinfo);
+ void get_netinfo(netinfo_t *netinfo);
++#ifdef __WIRELESS__
++void get_wirelessinfo(wirelessinfo_t *wirelessinfo);
++#endif
+ #ifdef __DEMO__
+ void get_demoinfo(demoinfo_t *demoinfo);
+ #endif
+--- a/utils.c
++++ b/utils.c
+@@ -266,6 +266,42 @@
+ 	return (pos != -1) ? g_tcp_client_list[i] : NULL;
+ }
+ 
++#ifdef __WIRELESS__
++void get_wirelessinfo(wirelessinfo_t *wirelessinfo)
++{
++	char buffer[BUFSIZ];
++	char name[16];
++	char *ptr;
++	int i;
++
++	if (read_file("/proc/net/wireless", buffer, sizeof (buffer)) == -1) {
++		buffer[0] = '\0';
++	}
++	for (i = 0; i < g_wireless_list_length; i++) {
++		if (buffer[0] != '\0') {
++			snprintf(name, sizeof (name), "%s:", g_wireless_list[i]);
++			ptr = strstr(buffer, name);
++			if (ptr != NULL) {
++				ptr += strlen(name);
++				strtoul(ptr, &ptr, 0); /* Status */
++
++				/* When the Quality values have been updated
++				 * since the last read of the entry, a dot will
++				 * follow that value
++				 */
++				strtoul(ptr, &ptr, 0); /* Quality */
++				wirelessinfo->signal[i] = strtoul(ptr + 1, &ptr, 0); /* Signal */
++				wirelessinfo->noise[i] = strtoul(ptr + 1, &ptr, 0); /* Noise */
++			} else {
++				wirelessinfo->signal[i] = wirelessinfo->noise[i] = 0;
++			}
++		} else {
++			wirelessinfo->signal[i] = wirelessinfo->noise[i] = 0;
++		}
++	}
++}
++#endif
++
+ #ifdef __DEMO__
+ void get_demoinfo(demoinfo_t *demoinfo)
+ {