Skip to contentSkip to conversation

NetworkManager and mac80211_hwsim

DISCUSSION Daniel Wagner 4 participants 10 messages Feb 16, 2009 – Feb 20, 2009

lore
Share & tools
lore
#0 lore raw

Hi

I'd like to setup a simple test scenario with mac80211_hwsim in order to check some corner cases in the scanning behaviour in NetworkManager. Though the problem is that NM doesn't see the mac8011_hwsim devices. I found out that the problem is that hald won't notifiy on dbus there is a new wireless device available. After a bit debugging I can tell that the problem is that there isn't a parent device available:

hal/hald/device.c:

hotplug_event_begin_add_dev (..., parent_dev = NULL, ...)
net_add(..., parent_dev = NULL, ...)
{
if (parent_dev == NULL)

		goto error;

}

Before I go deeper into that thing, does someone has an idea what could go wrong here with mac80211_hwsim?

thanks,
daniel

#1 lore raw
Quoted 9 lines · Daniel Wagner

hotplug_event_begin_add_dev (..., parent_dev = NULL, ...)
net_add(..., parent_dev = NULL, ...)
{
if (parent_dev == NULL)

		goto error;

}

Before I go deeper into that thing, does someone has an idea what could go wrong here with mac80211_hwsim?

hwsim phys have no parents in sysfs since they're virtual.

johannes

#2 lore raw
Quoted 9 lines · Johannes Berg
Quoted 7 lines · Daniel Wagner

hotplug_event_begin_add_dev (..., parent_dev = NULL, ...)
net_add(..., parent_dev = NULL, ...)
{
if (parent_dev == NULL)

		goto error;

}

Quoted 4 lines
Quoted 2 lines

Before I go deeper into that thing, does someone has an idea what could go wrong here with mac80211_hwsim?

hwsim phys have no parents in sysfs since they're virtual.

Do you propose to patch hald to handle this situation then?

daniel

#3 lore raw
Quoted 10 lines · Daniel Wagner
Quoted 9 lines · Johannes Berg
Quoted 7 lines · Daniel Wagner

hotplug_event_begin_add_dev (..., parent_dev = NULL, ...)
net_add(..., parent_dev = NULL, ...)
{
if (parent_dev == NULL)

		goto error;

}

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Before I go deeper into that thing, does someone has an idea what could go wrong here with mac80211_hwsim?

hwsim phys have no parents in sysfs since they're virtual.

Do you propose to patch hald to handle this situation then?

The patch (for now) would have to go in hal, since obviously if HAL can't see it, NM won't. Until we port over to DeviceKit of course.

dan

#4 lore raw
Quoted 14 lines · Dan Williams
Quoted 13 lines · Daniel Wagner
Quoted 12 lines · Johannes Berg
Quoted 9 lines · Daniel Wagner

hotplug_event_begin_add_dev (..., parent_dev = NULL, ...)
net_add(..., parent_dev = NULL, ...)
{
if (parent_dev == NULL)

		goto error;

}

Before I go deeper into that thing, does someone has an idea what could go wrong here with mac80211_hwsim?

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

hwsim phys have no parents in sysfs since they're virtual.

Do you propose to patch hald to handle this situation then?

The patch (for now) would have to go in hal, since obviously if HAL can't see it, NM won't. Until we port over to DeviceKit of course.

Thanks for the information. After looking at HAL for a while and knowing that it will be replaced in the near future I decided not to write a proper patch. Instead I came up with a big hack. With this hack NM sees the mac80211_hwsim devices :)

daniel

---
 hald/linux/device.c |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)
hald/linux/device.c +13 -10
index e48548e..699d26b 100644
@@ -497,20 +497,22 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
 	guint media_type;
 	gint flags;
 
-	d = NULL;
-
-	if (parent_dev == NULL)
-		goto error;
-
 	d = hal_device_new ();
 	hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path);
-	hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev));
+	if (parent_dev != NULL) {
+		hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev));
+		hal_device_property_set_string (d, "net.originating_device", hal_device_get_udi (parent_dev));
+	} else {
+		hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer");
+		hal_device_property_set_string (d, "net.originating_device", "/org/freedesktop/Hal/devices/computer");
+		hal_device_property_set_string (d, "info.linux.driver", "mac80211_hwsim");
+		parent_dev = hal_device_store_find (hald_get_gdl (), "/org/freedesktop/Hal/devices/computer");
+		hal_device_property_set_string (parent_dev, "info.linux.driver", "mac80211");
+	}
 
 	hal_device_property_set_string (d, "info.category", "net");
 	hal_device_add_capability (d, "net");
 
-	hal_device_property_set_string (d, "net.originating_device", hal_device_get_udi (parent_dev));
-
 	ifname = hal_util_get_last_element (sysfs_path);
 	hal_device_property_set_string (d, "net.interface", ifname);
 
@@ -530,7 +532,7 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
 	media_type = hal_device_property_get_int (d, "net.arp_proto_hw_id");
 	if (media_type == ARPHRD_ETHER) {
 		const char *addr;
-		const char *parent_subsys;
+		const char *parent_subsys = 0;
 		char bridge_path[HAL_PATH_MAX];
 		char wireless_path[HAL_PATH_MAX];
 		char wiphy_path[HAL_PATH_MAX];
@@ -557,7 +559,8 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
 		snprintf (wireless_path, HAL_PATH_MAX, "%s/wireless", sysfs_path);
 		/* wireless dscape stack e.g. from rt2500pci driver*/
 		snprintf (wiphy_path, HAL_PATH_MAX, "%s/wiphy", sysfs_path);
-		parent_subsys = hal_device_property_get_string (parent_dev, "info.subsystem");
+		if (parent_dev)
+			parent_subsys = hal_device_property_get_string (parent_dev, "info.subsystem");
 
 		if (parent_subsys && strcmp(parent_subsys, "bluetooth") == 0) {
 			hal_device_property_set_string (d, "info.product", "Bluetooth Interface");
Signature · 1 line
1.6.0.2.GIT
#5 lore raw

hald/linux/device.c net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de · line 511

Quoted 10 lines · Daniel Wagner
hald/linux/device.c +10 -0
+	if (parent_dev != NULL) {
+		hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev));
+		hal_device_property_set_string (d, "net.originating_device", hal_device_get_udi (parent_dev));
+	} else {
+		hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer");
+		hal_device_property_set_string (d, "net.originating_device", "/org/freedesktop/Hal/devices/computer");
+		hal_device_property_set_string (d, "info.linux.driver", "mac80211_hwsim");
+		parent_dev = hal_device_store_find (hald_get_gdl (), "/org/freedesktop/Hal/devices/computer");
+		hal_device_property_set_string (parent_dev, "info.linux.driver", "mac80211");
+	}

This is actually not _that_ bad an idea, because it makes sure everybody else will properly link up their parent pointer in sysfs. An alternative that doesn't guarantee that would be to check "is it in the ieee80211 class".

johannes

#6 lore raw
Quoted 15 lines · Johannes Berg

hald/linux/device.c net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de · line 511

Quoted 10 lines · Daniel Wagner
hald/linux/device.c +10 -0
+	if (parent_dev != NULL) {
+		hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev));
+		hal_device_property_set_string (d, "net.originating_device", hal_device_get_udi (parent_dev));
+	} else {
+		hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer");
+		hal_device_property_set_string (d, "net.originating_device", "/org/freedesktop/Hal/devices/computer");
+		hal_device_property_set_string (d, "info.linux.driver", "mac80211_hwsim");
+		parent_dev = hal_device_store_find (hald_get_gdl (), "/org/freedesktop/Hal/devices/computer");
+		hal_device_property_set_string (parent_dev, "info.linux.driver", "mac80211");
+	}

This is actually not _that_ bad an idea, because it makes sure everybody else will properly link up their parent pointer in sysfs.

That was exactly the problem. HAL creates only a 'correct' dbus tree if the sysfs parent pointers exists. The patch just fakes the parent 'computer'. This 'computer' node holds all parent-less nodes (eg alsa_sequencer, alsa_timer). One further problem is that the 'computer' node doesn't have a 'info.linux.driver' property which NM wants to read. Setting this property to 'mac80211' is not correct for all children of this node.

Quoted 3 lines

An alternative
that doesn't guarantee that would be to check "is it in the ieee80211 class".

At the moment NM wants a proper parent->child construct to work. Adding something like /org/freedesktop/Hal/devices/virtual/mac80211_hwsim as parent for the child would propably be a solution. As I said I was not really ready for fixing this up. But if this is something worth to fix I'll do it.

daniel

#7 lore raw
In reply to Daniel Wagner

Hello,

Can you please tell against which version of hal source you made this patch ? I tried it against the hal sources in my fedora distro and got errors when patching.
Rgs,
Kevin

Quoted 95 lines · Daniel Wagner
Quoted 14 lines · Dan Williams
Quoted 13 lines · Daniel Wagner
Quoted 12 lines · Johannes Berg
Quoted 9 lines · Daniel Wagner

hotplug_event_begin_add_dev (..., parent_dev = NULL, ...)
net_add(..., parent_dev = NULL, ...)

  {
        if (parent_dev == NULL)
                goto error;

}

Before I go deeper into that thing, does someone has an idea what could go wrong here with mac80211_hwsim?

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

hwsim phys have no parents in sysfs since they're virtual.

Do you propose to patch hald to handle this situation then?

The patch (for now) would have to go in hal, since obviously if HAL can't see it, NM won't. Until we port over to DeviceKit of course.

Thanks for the information. After looking at HAL for a while and knowing that it will be replaced in the near future I decided not to write a proper patch. Instead I came up with a big hack. With this hack NM sees the mac80211_hwsim devices :)

daniel

---
 hald/linux/device.c |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)
hald/linux/device.c +13 -11
index e48548e..699d26b 100644
@@ -497,20 +497,22 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
       guint media_type;
       gint flags;
 
-       d = NULL;
-
-       if (parent_dev == NULL)
-               goto error;
-
       d = hal_device_new ();
       hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path);
-       hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev));
+       if (parent_dev != NULL) {
+               hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev));
+               hal_device_property_set_string (d, "net.originating_device", hal_device_get_udi (parent_dev));
+       } else {
+               hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer");
+               hal_device_property_set_string (d, "net.originating_device", "/org/freedesktop/Hal/devices/computer");
+               hal_device_property_set_string (d, "info.linux.driver", "mac80211_hwsim");
+               parent_dev = hal_device_store_find (hald_get_gdl (), "/org/freedesktop/Hal/devices/computer");
+               hal_device_property_set_string (parent_dev, "info.linux.driver", "mac80211");
+       }
 
       hal_device_property_set_string (d, "info.category", "net");
       hal_device_add_capability (d, "net");
 
-       hal_device_property_set_string (d, "net.originating_device", hal_device_get_udi (parent_dev));
-
       ifname = hal_util_get_last_element (sysfs_path);
       hal_device_property_set_string (d, "net.interface", ifname);
 
@@ -530,7 +532,7 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
       media_type = hal_device_property_get_int (d, "net.arp_proto_hw_id");
       if (media_type == ARPHRD_ETHER) {
               const char *addr;
-               const char *parent_subsys;
+               const char *parent_subsys = 0;
               char bridge_path[HAL_PATH_MAX];
               char wireless_path[HAL_PATH_MAX];
               char wiphy_path[HAL_PATH_MAX];
@@ -557,7 +559,8 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
               snprintf (wireless_path, HAL_PATH_MAX, "%s/wireless", sysfs_path);
               /* wireless dscape stack e.g. from rt2500pci driver*/
               snprintf (wiphy_path, HAL_PATH_MAX, "%s/wiphy", sysfs_path);
-               parent_subsys = hal_device_property_get_string (parent_dev, "info.subsystem");
+               if (parent_dev)
+                       parent_subsys = hal_device_property_get_string (parent_dev, "info.subsystem");
 
               if (parent_subsys && strcmp(parent_subsys, "bluetooth") == 0) {
                       hal_device_property_set_string (d, "info.product", "Bluetooth Interface");
--

1.6.0.2.GIT

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw
Quoted 5 lines · Kevin Wilson

Hello,

Can you please tell against which version of hal source you made this patch ? I tried it against the hal sources in my fedora distro and got errors when patching.

Argh, I'm stupid. I created the patch against the last 0.5.11 release. I didn't see there is a 0.5.12rc on the fly. Anyway here is a new version against the head. I think it could be send upstream. It doesn`t look that bad anymore. What do you think?

daniel

---

Quoted 1 line

From 14c76a6642a1ed4f93b6dfed96af6d7513102c88 Mon Sep 17 00:00:00 2001

From: Daniel Wagner <[email protected]>
Date: Thu, 19 Feb 2009 18:14:09 +0100
Subject: [PATCH] Add info.linux.driver property for mac80211_hwsim devices

NetworkManager wants to read info.linux.driver for all devices. Since a mac80211_hwsim device doesn't have a real parent the property is not added. So let's add this property if there is no proper parent and it is a 80211 device.

---
 hald/linux/device.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
hald/linux/device.c +7 -0
index 21b9176..b68d3ef 100644
@@ -1576,6 +1576,7 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
 	guint media_type;
 	gint flags;
 	gint addr_len;
+	gboolean real_parent = TRUE;
 
 	d = NULL;
 	d = hal_device_new ();
@@ -1588,6 +1589,7 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
 				HAL_ERROR (("Device '%s' has no parent and couldn't find computer root object."));
 				goto error;
 			}
+			real_parent = FALSE;
 		}
         }
 
@@ -1662,6 +1664,11 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
 			hal_device_property_set_string (d, "info.category", "net.80211");
 			hal_device_add_capability (d, "net.80211");
 			hal_device_property_set_uint64 (d, "net.80211.mac_address", mac_address);
+
+			if (!real_parent) {
+				/* This is must be a mac80211_hwsim device */
+				hal_device_property_set_string (parent_dev, "info.linux.driver", "mac80211_hwsim");
+			}
 		} else if (stat (bridge_path, &s) == 0 && (s.st_mode & S_IFDIR)) {
 			hal_device_property_set_string (d, "info.product", "Bridge Interface");
 			hal_device_property_set_string (d, "info.category", "net.bridge");
Signature · 1 line
1.6.0.2.GIT
#9 lore raw

As it seems some more tweaking was needed to get it running with the current HAL head. Does this work for you?

daniel

---

NetworkManager wants to read info.linux.driver for all devices. Since a mac80211_hwsim device doesn't have a real parent the property is not added. So let's add this property if there is no proper parent and it is a 80211 device.

---
v2: Set address for wmaster devices to nil. Otherwise the real
networking device is overwritten.

 hald/linux/device.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
hald/linux/device.c +8 -0
index 21b9176..83b4a30 100644
@@ -1576,6 +1576,7 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
 	guint media_type;
 	gint flags;
 	gint addr_len;
+	gboolean real_parent = TRUE;
 
 	d = NULL;
 	d = hal_device_new ();
@@ -1588,6 +1589,7 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
 				HAL_ERROR (("Device '%s' has no parent and couldn't find computer root object."));
 				goto error;
 			}
+			real_parent = FALSE;
 		}
         }
 
@@ -1662,6 +1664,11 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
 			hal_device_property_set_string (d, "info.category", "net.80211");
 			hal_device_add_capability (d, "net.80211");
 			hal_device_property_set_uint64 (d, "net.80211.mac_address", mac_address);
+
+			if (!real_parent) {
+				/* This is must be a mac80211_hwsim device */
+				hal_device_property_set_string (parent_dev, "info.linux.driver", "mac80211_hwsim");
+			}
 		} else if (stat (bridge_path, &s) == 0 && (s.st_mode & S_IFDIR)) {
 			hal_device_property_set_string (d, "info.product", "Bridge Interface");
 			hal_device_property_set_string (d, "info.category", "net.bridge");
@@ -1691,6 +1698,7 @@ net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_de
 		hal_device_property_set_string (d, "info.product", "Networking Wireless Control Interface");
 		hal_device_property_set_string (d, "info.category", "net.80211control");
 		hal_device_add_capability (d, "net.80211control");
+		hal_device_property_set_string (d, "net.address", "00:00:00:00:00:00");
 	}
 #else
 #warning ARPHRD_IEEE80211_RADIOTAP and/or ARPHRD_IEEE80211_PRISM not defined!
Signature · 1 line
1.6.0.2.GIT