1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
From 32b8adc895fa4cf76cb4fc4c4eed3f39aaa72654 Mon Sep 17 00:00:00 2001
From: Johannes Berg <johannes@sipsolutions.net>
Date: Fri, 23 May 2008 17:31:51 +0200
Subject: [PATCH 02/48] use wext ioctl instead of sysfs to detect wireless
The canonical way to check whether a network interface has wireless
extensions is to try calling the SIOCGIWNAME ioctl on it.
---
hald/linux/device.c | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/hald/linux/device.c b/hald/linux/device.c
index 596e113..cf884e1 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -45,6 +45,10 @@
#include <linux/input.h>
#endif
+/* for wireless extensions */
+#include <linux/if.h>
+#include <linux/wireless.h>
+
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
@@ -532,10 +536,14 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
const char *addr;
const char *parent_subsys;
char bridge_path[HAL_PATH_MAX];
- char wireless_path[HAL_PATH_MAX];
char phy80211_path[HAL_PATH_MAX];
struct stat s;
dbus_uint64_t mac_address = 0;
+ int ioctl_fd;
+ struct iwreq iwr;
+
+ ioctl_fd = socket (PF_INET, SOCK_DGRAM, 0);
+ strncpy (iwr.ifr_ifrn.ifrn_name, ifname, IFNAMSIZ);
addr = hal_device_property_get_string (d, "net.address");
if (addr != NULL) {
@@ -554,8 +562,6 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
}
snprintf (bridge_path, HAL_PATH_MAX, "%s/bridge", sysfs_path);
- /* wireless extensions */
- snprintf (wireless_path, HAL_PATH_MAX, "%s/wireless", sysfs_path);
/* cfg80211 */
snprintf (phy80211_path, HAL_PATH_MAX, "%s/phy80211", sysfs_path);
parent_subsys = hal_device_property_get_string (parent_dev, "info.subsystem");
@@ -565,7 +571,7 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
hal_device_property_set_string (d, "info.category", "net.bluetooth");
hal_device_add_capability (d, "net.bluetooth");
hal_device_property_set_uint64 (d, "net.bluetooth.mac_address", mac_address);
- } else if ((stat (wireless_path, &s) == 0 && (s.st_mode & S_IFDIR)) ||
+ } else if ((ioctl (ioctl_fd, SIOCGIWNAME, &iwr) == 0) ||
(stat (phy80211_path, &s) == 0 && (s.st_mode & S_IFDIR))) {
hal_device_property_set_string (d, "info.product", "WLAN Interface");
hal_device_property_set_string (d, "info.category", "net.80211");
@@ -582,6 +588,8 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
hal_device_add_capability (d, "net.80203");
hal_device_property_set_uint64 (d, "net.80203.mac_address", mac_address);
}
+
+ close (ioctl_fd);
} else if (media_type == ARPHRD_IRDA) {
hal_device_property_set_string (d, "info.product", "Networking Interface");
hal_device_property_set_string (d, "info.category", "net.irda");
--
1.6.1.2
|