summaryrefslogtreecommitdiff
path: root/hardinfo2
diff options
context:
space:
mode:
authorLeandro A. F. Pereira <leandro@hardinfo.org>2008-05-23 20:02:56 +0000
committerLeandro A. F. Pereira <leandro@hardinfo.org>2008-05-23 20:02:56 +0000
commiteed6d43e0604dd1ecb6c6cce937454fb962ce7f0 (patch)
tree40cc315ea076aeab70660b9daad465f56a6d1db5 /hardinfo2
parenta41c29b935c4950124bbd4b34f4867f71dd45a6e (diff)
More WiFi information.
List USB devices even if /proc/bus/usb is not mounted (by using sysfs as a fallback). Add one vendor.
Diffstat (limited to 'hardinfo2')
-rw-r--r--hardinfo2/arch/linux/common/net.h165
-rw-r--r--hardinfo2/arch/linux/common/usb.h205
-rwxr-xr-xhardinfo2/configure21
-rw-r--r--hardinfo2/hardinfo.h4
-rw-r--r--hardinfo2/util.c52
-rw-r--r--hardinfo2/vendor.c1
6 files changed, 349 insertions, 99 deletions
diff --git a/hardinfo2/arch/linux/common/net.h b/hardinfo2/arch/linux/common/net.h
index f445430a..dd3928f1 100644
--- a/hardinfo2/arch/linux/common/net.h
+++ b/hardinfo2/arch/linux/common/net.h
@@ -15,23 +15,31 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
+/*
+ * Wireless Extension Example
+ * http://www.krugle.org/examples/p-OZYzuisV6gyQIaTu/iwconfig.c
+ */
static gchar *network_interfaces = NULL, *network_icons = NULL;
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <linux/sockios.h>
-#include <sys/socket.h>
-
#include <stdio.h>
#include <unistd.h>
-#include <string.h> /* for strncpy */
+#include <string.h>
+
+#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
+
#include <netinet/in.h>
+#include <linux/sockios.h>
+
#include <arpa/inet.h>
+#ifdef HAS_LINUX_WE
+#include <linux/if.h>
+#include <linux/wireless.h>
+#else
+#include <net/if.h>
+#endif /* HAS_LINUX_WE */
typedef struct _NetInfo NetInfo;
struct _NetInfo {
@@ -41,8 +49,80 @@ struct _NetInfo {
char ip[16];
char mask[16];
char broadcast[16];
+
+#ifdef HAS_LINUX_WE
+ char wi_essid[IW_ESSID_MAX_SIZE + 1];
+ int wi_rate, wi_status;
+ int wi_quality_level, wi_signal_level, wi_noise_level;
+ gboolean is_wireless;
+#endif
};
+#ifdef HAS_LINUX_WE
+void get_wireless_info(int fd, NetInfo *netinfo)
+{
+ FILE *wrls;
+ char wbuf[256];
+ struct iwreq wi_req;
+ int r, trash;
+
+ if ((wrls = fopen("/proc/net/wireless", "r"))) {
+ while (fgets(wbuf, 256, wrls)) {
+ if (strchr(wbuf, ':') && strstr(wbuf, netinfo->name)) {
+ gchar *buf1 = wbuf;
+
+ netinfo->is_wireless = TRUE;
+
+ buf1 = strchr(buf1, ':') + 1;
+
+ if (strstr(buf1, ".")) {
+ sscanf(buf1, "%d %d. %d %d %d %d %d %d %d %d",
+ &(netinfo->wi_status),
+ &(netinfo->wi_quality_level),
+ &(netinfo->wi_signal_level),
+ &(netinfo->wi_noise_level),
+ &trash, &trash, &trash, &trash, &trash, &trash);
+ } else {
+ sscanf(buf1, "%d %d %d %d %d %d %d %d %d %d",
+ &(netinfo->wi_status),
+ &(netinfo->wi_quality_level),
+ &(netinfo->wi_signal_level),
+ &(netinfo->wi_noise_level),
+ &trash, &trash, &trash, &trash, &trash,
+ &trash);
+ }
+
+ break;
+ }
+ }
+ fclose(wrls);
+ }
+
+ if (!netinfo->is_wireless)
+ return;
+
+ strncpy(wi_req.ifr_name, netinfo->name, 16);
+
+ /* obtain essid */
+ wi_req.u.essid.pointer = netinfo->wi_essid;
+ wi_req.u.essid.length = IW_ESSID_MAX_SIZE + 1;
+ wi_req.u.essid.flags = 0;
+
+ if ((r = ioctl(fd, SIOCGIWESSID, &wi_req) < 0)) {
+ strcpy(netinfo->wi_essid, "");
+ } else {
+ netinfo->wi_essid[wi_req.u.essid.length] = '\0';
+ }
+
+ /* obtain bit rate */
+ if ((r =ioctl(fd, SIOCGIWRATE, &wi_req) < 0)) {
+ netinfo->wi_rate = 0;
+ } else {
+ netinfo->wi_rate = wi_req.u.bitrate.value;
+ }
+}
+#endif /* HAS_LINUX_WE */
+
void get_net_info(char *if_name, NetInfo * netinfo)
{
struct ifreq ifr;
@@ -100,6 +180,10 @@ void get_net_info(char *if_name, NetInfo * netinfo)
sin_addr));
}
+#ifdef HAS_LINUX_WE
+ get_wireless_info(fd, netinfo);
+#endif
+
shutdown(fd, 0);
}
@@ -163,10 +247,6 @@ static void scan_net_interfaces_24(void)
gdouble trans_errors;
gdouble trans_packets;
- /* Variables for wireless connections */
- gint wstatus;
- gint wqlink, wqlevel, wqnoise;
-
if (!g_file_test("/proc/net/dev", G_FILE_TEST_EXISTS)) {
if (network_interfaces) {
g_free(network_interfaces);
@@ -191,8 +271,6 @@ static void scan_net_interfaces_24(void)
proc_net = fopen("/proc/net/dev", "r");
while (fgets(buffer, 256, proc_net)) {
if (strchr(buffer, ':')) {
- gchar wbuf[256], *wdetailed = NULL;
- FILE *wrls;
gint trash;
gchar ifacename[16];
gchar *buf = buffer;
@@ -219,6 +297,12 @@ static void scan_net_interfaces_24(void)
gdouble trans_mb = trans_bytes / 1048576.0;
get_net_info(ifacename, &ni);
+#ifdef HAS_LINUX_WE
+ if (ni.is_wireless) {
+ iface_type = "Wireless";
+ iface_icon = "wireless";
+ }
+#endif
devid = g_strdup_printf("NET%s", ifacename);
@@ -231,44 +315,11 @@ static void scan_net_interfaces_24(void)
g_free(ip);
net_get_iface_type(ifacename, &iface_type, &iface_icon);
+
network_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n",
network_icons, devid,
ifacename, iface_icon);
- if ((wrls = fopen("/proc/net/wireless", "r"))) {
- while (fgets(wbuf, 256, wrls)) {
- if (strchr(wbuf, ':') && strstr(wbuf, ifacename)) {
- gchar *buf1 = wbuf;
-
- iface_type = "Wireless";
- iface_icon = "wireless";
-
- buf1 = strchr(buf1, ':') + 1;
-
- if (strstr(buf1, ".")) {
- sscanf(buf1, "%d %d. %d %d %d %d %d %d %d %d",
- &wstatus, &wqlink, &wqlevel, &wqnoise,
- &trash, &trash, &trash, &trash, &trash,
- &trash);
- } else {
- sscanf(buf1, "%d %d %d %d %d %d %d %d %d %d",
- &wstatus, &wqlink, &wqlevel, &wqnoise,
- &trash, &trash, &trash, &trash, &trash,
- &trash);
- }
- wdetailed =
- g_strdup_printf("\n[Wireless Information]\n"
- "Status=%d\n"
- "Quality Level=%d%%\n"
- "Signal Level=%d\n"
- "Noise Level=%d\n",
- wstatus, wqlink, wqlevel,
- wqnoise);
- }
- }
- fclose(wrls);
- }
-
detailed = g_strdup_printf("[Network Adapter Properties]\n"
"Interface Type=%s\n"
"Hardware Address (MAC)=%02x:%02x:%02x:%02x:%02x:%02x\n"
@@ -284,9 +335,23 @@ static void scan_net_interfaces_24(void)
recv_bytes, recv_mb,
trans_bytes, trans_mb);
- if (wdetailed) {
- detailed = h_strconcat(detailed, wdetailed, NULL);
+#ifdef HAS_LINUX_WE
+ if (ni.is_wireless) {
+ detailed = h_strdup_cprintf("\n[Wireless Properties]\n"
+ "Network Name (SSID)=%s\n"
+ "Bit Rate=%dMb/s\n"
+ "Status=%d\n"
+ "Link Quality=%d\n"
+ "Signal / Noise=%d / %d\n",
+ detailed,
+ ni.wi_essid,
+ ni.wi_rate / 1000000,
+ ni.wi_status,
+ ni.wi_quality_level,
+ ni.wi_signal_level,
+ ni.wi_noise_level);
}
+#endif
if (ni.ip[0] || ni.mask[0] || ni.broadcast[0]) {
detailed =
diff --git a/hardinfo2/arch/linux/common/usb.h b/hardinfo2/arch/linux/common/usb.h
index 5cb31729..f7886cb6 100644
--- a/hardinfo2/arch/linux/common/usb.h
+++ b/hardinfo2/arch/linux/common/usb.h
@@ -23,8 +23,104 @@ remove_usb_devices(gpointer key, gpointer value, gpointer data)
}
static gchar *usb_list = NULL;
-void
-__scan_usb(void)
+
+void __scan_usb_sysfs_add_device(gchar * endpoint, int n)
+{
+ gchar *manufacturer, *product, *mxpwr, *tmp, *strhash;
+ gint bus, classid, vendor, prodid;
+ gfloat version, speed;
+
+ classid = h_sysfs_read_int(endpoint, "bDeviceClass");
+ vendor = h_sysfs_read_int(endpoint, "idVendor");
+ prodid = h_sysfs_read_int(endpoint, "idProduct");
+ bus = h_sysfs_read_int(endpoint, "busnum");
+ speed = h_sysfs_read_float(endpoint, "speed");
+ version = h_sysfs_read_float(endpoint, "version");
+
+ if (!(mxpwr = h_sysfs_read_string(endpoint, "bMaxPower"))) {
+ mxpwr = g_strdup("0 mA");
+ }
+
+ if (!(manufacturer = h_sysfs_read_string(endpoint, "manufacturer"))) {
+ manufacturer = g_strdup("Unknown");
+ }
+
+ if (!(product = h_sysfs_read_string(endpoint, "product"))) {
+ product =
+ g_strdup_printf("Unknown USB %.2f device (class %d)", version,
+ classid);
+ }
+
+ const gchar *url = vendor_get_url(manufacturer);
+ if (url) {
+ tmp = g_strdup_printf("%s (%s)", vendor_get_name(manufacturer), url);
+
+ g_free(manufacturer);
+ manufacturer = tmp;
+ }
+
+ tmp = g_strdup_printf("USB%d", n);
+ usb_list = h_strdup_cprintf("$%s$%s=\n", usb_list, tmp, product);
+
+ strhash = g_strdup_printf("[Device Information]\n"
+ "Product=%s\n"
+ "Manufacturer=%s\n"
+ "Speed=%.2fMbit/s\n"
+ "Max Current=%s\n"
+ "[Misc]\n"
+ "USB Version=%.2f\n"
+ "Class=0x%x\n"
+ "Vendor=0x%x\n"
+ "Product ID=0x%x\n"
+ "Bus=%d\n",
+ product,
+ manufacturer,
+ speed,
+ mxpwr,
+ version, classid, vendor, prodid, bus);
+
+ g_hash_table_insert(moreinfo, tmp, strhash);
+
+ g_free(manufacturer);
+ g_free(product);
+ g_free(mxpwr);
+}
+
+void __scan_usb_sysfs(void)
+{
+ GDir *sysfs;
+ gchar *filename;
+ const gchar *sysfs_path = "/sys/class/usb_endpoint";
+ gint usb_device_number = 0;
+
+ if (usb_list) {
+ g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL);
+ g_free(usb_list);
+ }
+ usb_list = g_strdup("[USB Devices]\n");
+
+ if (!(sysfs = g_dir_open(sysfs_path, 0, NULL))) {
+ return;
+ }
+
+ while ((filename = (gchar *) g_dir_read_name(sysfs))) {
+ gchar *endpoint =
+ g_build_filename(sysfs_path, filename, "device", NULL);
+ gchar *temp;
+
+ temp = g_build_filename(endpoint, "idVendor", NULL);
+ if (g_file_test(temp, G_FILE_TEST_EXISTS)) {
+ __scan_usb_sysfs_add_device(endpoint, ++usb_device_number);
+ }
+
+ g_free(temp);
+ g_free(endpoint);
+ }
+
+ g_dir_close(sysfs);
+}
+
+int __scan_usb_procfs(void)
{
FILE *dev;
gchar buffer[128];
@@ -36,7 +132,7 @@ __scan_usb(void)
dev = fopen("/proc/bus/usb/devices", "r");
if (!dev)
- return;
+ return 0;
if (usb_list) {
g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL);
@@ -73,57 +169,60 @@ __scan_usb(void)
mxpwr = strstr(buffer, "MxPwr=") + 6;
tmp = g_strdup_printf("USB%d", ++n);
-
+
if (*product == '\0') {
- g_free(product);
- if (classid == 9) {
- product = g_strdup_printf("USB %.2f Hub", ver);
- } else {
- product = g_strdup_printf("Unknown USB %.2f Device (class %d)",
- ver, classid);
- }
+ g_free(product);
+ if (classid == 9) {
+ product = g_strdup_printf("USB %.2f Hub", ver);
+ } else {
+ product =
+ g_strdup_printf
+ ("Unknown USB %.2f Device (class %d)", ver,
+ classid);
+ }
}
-
+
if (classid == 9) { /* hub */
- usb_list = h_strdup_cprintf("[%s#%d]\n",
- usb_list, product, n);
- } else { /* everything else */
- usb_list = h_strdup_cprintf("$%s$%s=\n",
- usb_list, tmp, product);
-
- const gchar *url = vendor_get_url(manuf);
- if (url) {
- gchar *tmp = g_strdup_printf("%s (%s)", vendor_get_name(manuf), url);
- g_free(manuf);
- manuf = tmp;
- }
-
- gchar *strhash = g_strdup_printf("[Device Information]\n"
- "Product=%s\n",
- product);
+ usb_list = h_strdup_cprintf("[%s#%d]\n",
+ usb_list, product, n);
+ } else { /* everything else */
+ usb_list = h_strdup_cprintf("$%s$%s=\n",
+ usb_list, tmp, product);
+
+ const gchar *url = vendor_get_url(manuf);
+ if (url) {
+ gchar *tmp =
+ g_strdup_printf("%s (%s)", vendor_get_name(manuf),
+ url);
+ g_free(manuf);
+ manuf = tmp;
+ }
+
+ gchar *strhash = g_strdup_printf("[Device Information]\n"
+ "Product=%s\n",
+ product);
if (manuf && strlen(manuf))
- strhash = h_strdup_cprintf("Manufacturer=%s\n",
- strhash,
- manuf);
-
- strhash = h_strdup_cprintf("[Port #%d]\n"
- "Speed=%.2fMbit/s\n"
- "Max Current=%s\n"
- "[Misc]\n"
- "USB Version=%.2f\n"
- "Revision=%.2f\n"
- "Class=0x%x\n"
- "Vendor=0x%x\n"
- "Product ID=0x%x\n"
- "Bus=%d\n" "Level=%d\n",
- strhash,
- port, speed, mxpwr,
- ver, rev, classid,
- vendor, prodid, bus, level);
-
- g_hash_table_insert(moreinfo, tmp, strhash);
- }
+ strhash = h_strdup_cprintf("Manufacturer=%s\n",
+ strhash, manuf);
+
+ strhash = h_strdup_cprintf("[Port #%d]\n"
+ "Speed=%.2fMbit/s\n"
+ "Max Current=%s\n"
+ "[Misc]\n"
+ "USB Version=%.2f\n"
+ "Revision=%.2f\n"
+ "Class=0x%x\n"
+ "Vendor=0x%x\n"
+ "Product ID=0x%x\n"
+ "Bus=%d\n" "Level=%d\n",
+ strhash,
+ port, speed, mxpwr,
+ ver, rev, classid,
+ vendor, prodid, bus, level);
+
+ g_hash_table_insert(moreinfo, tmp, strhash);
+ }
g_free(manuf);
g_free(product);
@@ -133,4 +232,12 @@ __scan_usb(void)
}
fclose(dev);
+
+ return n;
+}
+
+void __scan_usb(void)
+{
+ if (!__scan_usb_procfs())
+ __scan_usb_sysfs();
}
diff --git a/hardinfo2/configure b/hardinfo2/configure
index 9ad12b2d..96e54179 100755
--- a/hardinfo2/configure
+++ b/hardinfo2/configure
@@ -178,6 +178,23 @@ fi
# --------------------------------------------------------------------------
+echo -n "Checking for Linux Wireless Extensions (CONFIG_NET_RADIO)... "
+if [ -e /proc/net/wireless ]; then
+ echo "found."
+ LINUX_WE=1
+else
+ echo "not found."
+ LINUX_WE=-1
+fi
+
+# --------------------------------------------------------------------------
+
+if [ $LINUX_WE -eq -1 ]; then
+ echo "Disabling Linux Wireless Extensions support."
+fi
+
+# --------------------------------------------------------------------------
+
echo -e "\nWriting config.h..."
rm -f config.h
echo -e "#ifndef __CONFIG_H__\n#define __CONFIG_H__\n" > config.h
@@ -199,6 +216,10 @@ if [ "$SOUP" == "1" ]; then
echo "#define HAS_LIBSOUP" >> config.h
fi
+if [ "$LINUX_WE" == "1" ]; then
+ echo "#define HAS_LINUX_WE" >> config.h
+fi
+
if [ "$RELEASE" == "1" ]; then
echo "#define DEBUG(...)" >> config.h
else
diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h
index 36dbb6d6..3a928416 100644
--- a/hardinfo2/hardinfo.h
+++ b/hardinfo2/hardinfo.h
@@ -119,6 +119,10 @@ extern ProgramParameters params;
/* Module stuff */
gchar *module_call_method(gchar *method);
+/* Sysfs stuff */
+gfloat h_sysfs_read_float(gchar *endpoint, gchar *entry);
+gint h_sysfs_read_int(gchar *endpoint, gchar *entry);
+gchar *h_sysfs_read_string(gchar *endpoint, gchar *entry);
#define SCAN_START() static gboolean scanned = FALSE; if (reload) scanned = FALSE; if (scanned) return;
#define SCAN_END() scanned = TRUE;
diff --git a/hardinfo2/util.c b/hardinfo2/util.c
index 79f4aef3..c4c16a0d 100644
--- a/hardinfo2/util.c
+++ b/hardinfo2/util.c
@@ -1048,3 +1048,55 @@ h_hash_table_remove_all(GHashTable *hash_table)
h_hash_table_remove_all_true,
NULL);
}
+
+gfloat
+h_sysfs_read_float(gchar *endpoint, gchar *entry)
+{
+ gchar *tmp, *buffer;
+ gfloat return_value = 0.0f;
+
+ tmp = g_build_filename(endpoint, entry, NULL);
+ if (g_file_get_contents(tmp, &buffer, NULL, NULL))
+ return_value = atof(buffer);
+
+ g_free(tmp);
+ g_free(buffer);
+
+ return return_value;
+}
+
+gint
+h_sysfs_read_int(gchar *endpoint, gchar *entry)
+{
+ gchar *tmp, *buffer;
+ gint return_value = 0.0f;
+
+ tmp = g_build_filename(endpoint, entry, NULL);
+ if (g_file_get_contents(tmp, &buffer, NULL, NULL))
+ return_value = atoi(buffer);
+
+ g_free(tmp);
+ g_free(buffer);
+
+ return return_value;
+}
+
+gchar *
+h_sysfs_read_string(gchar *endpoint, gchar *entry)
+{
+ gchar *tmp, *return_value;
+
+ tmp = g_build_filename(endpoint, entry, NULL);
+ if (!g_file_get_contents(tmp, &return_value, NULL, NULL)) {
+ g_free(return_value);
+
+ return_value = NULL;
+ } else {
+ return_value = g_strstrip(return_value);
+ }
+
+ g_free(tmp);
+
+ return return_value;
+}
+
diff --git a/hardinfo2/vendor.c b/hardinfo2/vendor.c
index aa860c68..92988eaa 100644
--- a/hardinfo2/vendor.c
+++ b/hardinfo2/vendor.c
@@ -70,6 +70,7 @@ static const Vendor vendors[] = {
{"HP", "Hewlett-Packard", "www.hp.com"},
{"Hewlett-Packard", "Hewlett-Packard", "www.hp.com"},
{"TEAC", "TEAC America Inc.", "www.teac.com"},
+ {"Microsoft", "Microsoft Corp.", "www.microsoft.com"},
{NULL, NULL, NULL},
};