aboutsummaryrefslogtreecommitdiff
path: root/hardinfo2/arch
diff options
context:
space:
mode:
authorLeandro A. F. Pereira <leandro@hardinfo.org>2008-05-24 13:27:57 +0000
committerLeandro A. F. Pereira <leandro@hardinfo.org>2008-05-24 13:27:57 +0000
commitac1d892607eb0e94a3ee7c8b900aed62791df73c (patch)
treed24ea7552835004aa08365d25f351b40c2687a76 /hardinfo2/arch
parent47008902ec4a72dba45a5f57098e68785564dc48 (diff)
Cleanups.
Add wireless operation mode, wireless transmission power.
Diffstat (limited to 'hardinfo2/arch')
-rw-r--r--hardinfo2/arch/linux/common/net.h53
-rw-r--r--hardinfo2/arch/linux/common/usb.h8
2 files changed, 53 insertions, 8 deletions
diff --git a/hardinfo2/arch/linux/common/net.h b/hardinfo2/arch/linux/common/net.h
index 9eed6fe3..06dc85ca 100644
--- a/hardinfo2/arch/linux/common/net.h
+++ b/hardinfo2/arch/linux/common/net.h
@@ -52,13 +52,18 @@ struct _NetInfo {
#ifdef HAS_LINUX_WE
char wi_essid[IW_ESSID_MAX_SIZE + 1];
- int wi_rate, wi_status;
+ int wi_rate;
+ int wi_mode, wi_status;
+ gboolean wi_has_txpower;
+ struct iw_param wi_txpower;
int wi_quality_level, wi_signal_level, wi_noise_level;
gboolean is_wireless;
#endif
};
#ifdef HAS_LINUX_WE
+const gchar *wi_operation_modes[] = { "Auto", "Ad-Hoc", "Managed", "Master", "Repeater", "Secondary", "Unknown" };
+
void get_wireless_info(int fd, NetInfo *netinfo)
{
FILE *wrls;
@@ -66,6 +71,8 @@ void get_wireless_info(int fd, NetInfo *netinfo)
struct iwreq wi_req;
int r, trash;
+ netinfo->is_wireless = FALSE;
+
if ((wrls = fopen("/proc/net/wireless", "r"))) {
while (fgets(wbuf, 256, wrls)) {
if (strchr(wbuf, ':') && strstr(wbuf, netinfo->name)) {
@@ -115,11 +122,33 @@ void get_wireless_info(int fd, NetInfo *netinfo)
}
/* obtain bit rate */
- if ((r =ioctl(fd, SIOCGIWRATE, &wi_req) < 0)) {
+ if ((r = ioctl(fd, SIOCGIWRATE, &wi_req) < 0)) {
netinfo->wi_rate = 0;
} else {
netinfo->wi_rate = wi_req.u.bitrate.value;
- }
+ }
+
+ /* obtain operation mode */
+ if ((r = ioctl(fd, SIOCGIWMODE, &wi_req) < 0)) {
+ netinfo->wi_mode = 0;
+ } else {
+ if (wi_req.u.mode >= 0 && wi_req.u.mode < 6) {
+ netinfo->wi_mode = wi_req.u.mode;
+ } else {
+ netinfo->wi_mode = 6;
+ }
+ }
+
+#if WIRELESS_EXT >= 10
+ /* obtain txpower */
+ if ((r = ioctl(fd, SIOCGIWTXPOW, &wi_req) < 0)) {
+ netinfo->wi_has_txpower = FALSE;
+ } else {
+ netinfo->wi_has_txpower = TRUE;
+
+ memcpy(&netinfo->wi_txpower, &wi_req.u.txpower, sizeof(struct iw_param));
+ }
+#endif /* WIRELESS_EXT >= 10 */
}
#endif /* HAS_LINUX_WE */
@@ -181,7 +210,6 @@ void get_net_info(char *if_name, NetInfo * netinfo)
}
#ifdef HAS_LINUX_WE
- netinfo->is_wireless = FALSE;
get_wireless_info(fd, netinfo);
#endif
@@ -338,19 +366,36 @@ static void scan_net_interfaces_24(void)
#ifdef HAS_LINUX_WE
if (ni.is_wireless) {
+ gchar *txpower;
+
+ if (ni.wi_has_txpower) {
+ if (ni.wi_txpower.flags & IW_TXPOW_MWATT)
+ txpower = g_strdup_printf("%d mW", ni.wi_txpower.value);
+ else
+ txpower = g_strdup_printf("%d dBm", ni.wi_txpower.value);
+ } else {
+ txpower = g_strdup("Radio Off");
+ }
+
detailed = h_strdup_cprintf("\n[Wireless Properties]\n"
"Network Name (SSID)=%s\n"
"Bit Rate=%dMb/s\n"
+ "Transmission Power=%s\n"
+ "Mode=%s\n"
"Status=%d\n"
"Link Quality=%d\n"
"Signal / Noise=%d / %d\n",
detailed,
ni.wi_essid,
ni.wi_rate / 1000000,
+ txpower,
+ wi_operation_modes[ni.wi_mode],
ni.wi_status,
ni.wi_quality_level,
ni.wi_signal_level,
ni.wi_noise_level);
+
+ g_free(txpower);
}
#endif
diff --git a/hardinfo2/arch/linux/common/usb.h b/hardinfo2/arch/linux/common/usb.h
index 9e6980fe..a102e6d0 100644
--- a/hardinfo2/arch/linux/common/usb.h
+++ b/hardinfo2/arch/linux/common/usb.h
@@ -98,16 +98,16 @@ void __scan_usb_sysfs(void)
const gchar *sysfs_path = "/sys/class/usb_endpoint";
gint usb_device_number = 0;
+ if (!(sysfs = g_dir_open(sysfs_path, 0, NULL))) {
+ return;
+ }
+
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);