hal: Branch 'master' - 2 commits

David Zeuthen david at kemper.freedesktop.org
Mon Apr 23 12:35:54 PDT 2007


 doc/spec/hal-spec-properties.xml         |   62 ++++++++
 hald/linux/device.c                      |   77 ++++++----
 hald/linux/probing/Makefile.am           |    5 
 hald/linux/probing/probe-net-bluetooth.c |  233 +++++++++++++++++++++++++++++++
 4 files changed, 346 insertions(+), 31 deletions(-)

New commits:
diff-tree bf29b2f07dc05cf8b95463ad76b0b2ebe4ed596a (from 192f5284c77846f4537209fde4a945f7d2159eee)
Author: David Zeuthen <davidz at redhat.com>
Date:   Mon Apr 23 15:35:53 2007 -0400

    change namespace for bluez-specific properties

diff --git a/doc/spec/hal-spec-properties.xml b/doc/spec/hal-spec-properties.xml
index bce99f1..726fef7 100644
--- a/doc/spec/hal-spec-properties.xml
+++ b/doc/spec/hal-spec-properties.xml
@@ -4334,23 +4334,23 @@ org.freedesktop.Hal.Device.Volume.method
             </row>
            <row>
               <entry>
-                <literal>net.bluetooth.name</literal> (string)
+                <literal>net.bluetooth.bluez_name</literal> (string)
               </entry>
               <entry>example: Network Access Point Service</entry>
               <entry>
-                Only if the <literal>net.bluetooth</literal> capability is set
+                Only if the <literal>net.bluetooth</literal> capability is set and Bluez is being used.
               </entry>
-              <entry>Displayable Name</entry>
+              <entry>Displayable Name according to Bluez</entry>
             </row>
             <row>
               <entry>
-                <literal>net.bluetooth.uuid</literal> (string)
+                <literal>net.bluetooth.bluez_uuid</literal> (string)
               </entry>
               <entry>example: 00001116-0000-1000-8000-00805f9b34fb</entry>
               <entry>
-                Only if the <literal>net.bluetooth</literal> capability is set
+                Only if the <literal>net.bluetooth</literal> capability is set and Bluez is being used.
               </entry>
-              <entry>Universal Unique IDentifier</entry>
+              <entry>Universal Unique Identifier</entry>
             </row>
           </tbody>
         </tgroup>
diff --git a/hald/linux/probing/probe-net-bluetooth.c b/hald/linux/probing/probe-net-bluetooth.c
index 2abaa70..7f576b6 100644
--- a/hald/linux/probing/probe-net-bluetooth.c
+++ b/hald/linux/probing/probe-net-bluetooth.c
@@ -88,7 +88,7 @@ get_properties (DBusConnection *conn, Li
 		dbus_message_iter_next (&dict_entry_iter);
 		dbus_message_iter_recurse (&dict_entry_iter, &var_iter);
 
-		snprintf(prop, 32, "net.bluetooth.%s", key);
+                snprintf(prop, sizeof (prop), "net.bluetooth.bluez_%s", key);
 
 		/* Make any property found annouced by hal */
 		switch (dbus_message_iter_get_arg_type (&var_iter)) {
@@ -151,8 +151,7 @@ main (int argc, char *argv[])
 	if ((ctx = libhal_ctx_init_direct (&error)) == NULL)
 		goto out;
 
-	iface = libhal_device_get_property_string (ctx, udi, "net.interface",
-												NULL);
+	iface = libhal_device_get_property_string (ctx, udi, "net.interface", NULL);
 
 	HAL_INFO (("Investigating '%s'", iface));
 
@@ -162,9 +161,7 @@ main (int argc, char *argv[])
 	if ((conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error)) == NULL)
 		goto out;
 
-	msg = dbus_message_new_method_call (BLUEZ_SERVICE, BLUEZ_PATH,
-										BLUEZ_MANAGER_IFACE,
-										"ActivateService");
+	msg = dbus_message_new_method_call (BLUEZ_SERVICE, BLUEZ_PATH, BLUEZ_MANAGER_IFACE, "ActivateService");
 
 	if (msg == NULL)
 		goto out;
@@ -174,8 +171,7 @@ main (int argc, char *argv[])
 								DBUS_TYPE_INVALID);
 	reply = dbus_connection_send_with_reply_and_block (conn, msg, -1, &error);
 
-	if (dbus_error_is_set (&error) || dbus_set_error_from_message (&error,
-		reply)) {
+	if (dbus_error_is_set (&error) || dbus_set_error_from_message (&error, reply)) {
 		dbus_error_free (&error);
 		goto out;
 	}
@@ -183,8 +179,7 @@ main (int argc, char *argv[])
 	dbus_message_unref (msg);
 	msg = NULL;
 
-	dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &id,
-							DBUS_TYPE_INVALID);
+	dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &id, DBUS_TYPE_INVALID);
 	if (dbus_error_is_set (&error)) {
 		dbus_error_free (&error);
 		goto out;
@@ -195,9 +190,7 @@ main (int argc, char *argv[])
 
 	HAL_INFO (("Found Bluez Network service '%s'", id));
 
-	msg = dbus_message_new_method_call (id, BLUEZ_NET_PATH,
-										BLUEZ_NET_MANAGER_IFACE,
-										"FindConnection");
+	msg = dbus_message_new_method_call (id, BLUEZ_NET_PATH, BLUEZ_NET_MANAGER_IFACE, "FindConnection");
 
 	if (msg == NULL)
 		goto out;
diff-tree 192f5284c77846f4537209fde4a945f7d2159eee (from f849652ff11b22b8685c9bd4728e8eb2299a4c96)
Author: Luiz Augusto von Dentz <luiz.dentz at gmail.com>
Date:   Mon Apr 23 15:25:35 2007 -0400

    recognize bluetooth network capabilities
    
    This is fd.o #10577
    
    http://bugs.freedesktop.org/show_bug.cgi?id=10577

diff --git a/doc/spec/hal-spec-properties.xml b/doc/spec/hal-spec-properties.xml
index 3917360..bce99f1 100644
--- a/doc/spec/hal-spec-properties.xml
+++ b/doc/spec/hal-spec-properties.xml
@@ -4117,7 +4117,8 @@ org.freedesktop.Hal.Device.Volume.method
         capability <literal>net</literal> and they will export the
         properties below. This namespace only describe the generic
         aspect of networking devices; specific networking technologies
-        such as IEEE 802.3 and IEEE 802.11 have separate namespaces.
+        such as IEEE 802.3, IEEE 802.11 and Bluetooth have separate
+	namespaces.
       </para>
       <informaltable>
         <tgroup cols="2">
@@ -4298,6 +4299,65 @@ org.freedesktop.Hal.Device.Volume.method
       <para>
       </para>
     </sect2>
+    <sect2 id="device-properties-net-bluetooth">
+      <title>
+        net.bluetooth namespace
+      </title>
+      <para>
+        Bluetooth ethernet networking devices is described in this namespace
+        for device objects with the capability
+        <literal>net.bluetooth</literal>.
+        Note that device
+        objects can only have the <literal>net.bluetooth</literal> capability
+        if they already have the capability <literal>net</literal>.
+      </para>
+      <informaltable>
+        <tgroup cols="2">
+          <thead>
+            <row>
+              <entry>Key (type)</entry>
+              <entry>Values</entry>
+              <entry>Mandatory</entry>
+              <entry>Description</entry>
+            </row>
+          </thead>
+          <tbody>
+            <row>
+              <entry>
+                <literal>net.bluetooth.mac_address</literal> (uint64)
+              </entry>
+              <entry>example: 0x0010605d8ef4</entry>
+              <entry>
+                Only if the <literal>net.bluetooth</literal> capability is set
+              </entry>
+              <entry>48-bit address</entry>
+            </row>
+           <row>
+              <entry>
+                <literal>net.bluetooth.name</literal> (string)
+              </entry>
+              <entry>example: Network Access Point Service</entry>
+              <entry>
+                Only if the <literal>net.bluetooth</literal> capability is set
+              </entry>
+              <entry>Displayable Name</entry>
+            </row>
+            <row>
+              <entry>
+                <literal>net.bluetooth.uuid</literal> (string)
+              </entry>
+              <entry>example: 00001116-0000-1000-8000-00805f9b34fb</entry>
+              <entry>
+                Only if the <literal>net.bluetooth</literal> capability is set
+              </entry>
+              <entry>Universal Unique IDentifier</entry>
+            </row>
+          </tbody>
+        </tgroup>
+      </informaltable>
+      <para>
+      </para>
+    </sect2>
     <sect2 id="device-properties-net-irda">
       <title>
         net.irda namespace
diff --git a/hald/linux/device.c b/hald/linux/device.c
index e5c78ff..8540658 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -480,48 +480,49 @@ net_add (const gchar *sysfs_path, const 
 	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;
 		char wireless_path[HAL_PATH_MAX];
 		char wiphy_path[HAL_PATH_MAX];
-		gboolean is_wireless;
 		struct stat s;
+		dbus_uint64_t mac_address = 0;
+
+		addr = hal_device_property_get_string (d, "net.address");
+		if (addr != NULL) {
+			unsigned int a5, a4, a3, a2, a1, a0;
+
+			if (sscanf (addr, "%x:%x:%x:%x:%x:%x",
+				    &a5, &a4, &a3, &a2, &a1, &a0) == 6) {
+				mac_address =
+					((dbus_uint64_t)a5<<40) |
+					((dbus_uint64_t)a4<<32) |
+					((dbus_uint64_t)a3<<24) |
+					((dbus_uint64_t)a2<<16) |
+					((dbus_uint64_t)a1<< 8) |
+					((dbus_uint64_t)a0<< 0);
+			}
+		}
 
 		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, "linux.subsystem");
 
-                if ((stat (wireless_path, &s) == 0 && (s.st_mode & S_IFDIR)) ||
-		    (stat (wiphy_path, &s) == 0 && (s.st_mode & S_IFDIR))) { 
+		if (parent_subsys && strcmp(parent_subsys, "bluetooth") == 0) {
+			hal_device_property_set_string (d, "info.product", "Bluetooth Interface");
+			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)) ||
+			(stat (wiphy_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");
 			hal_device_add_capability (d, "net.80211");
-			is_wireless = TRUE;
+			hal_device_property_set_uint64 (d, "net.80211.mac_address", mac_address);
 		} else {
 			hal_device_property_set_string (d, "info.product", "Networking Interface");
 			hal_device_property_set_string (d, "info.category", "net.80203");
 			hal_device_add_capability (d, "net.80203");
-			is_wireless = FALSE;
-		}
-
-		addr = hal_device_property_get_string (d, "net.address");
-		if (addr != NULL) {
-			unsigned int a5, a4, a3, a2, a1, a0;
-			
-			if (sscanf (addr, "%x:%x:%x:%x:%x:%x",
-				    &a5, &a4, &a3, &a2, &a1, &a0) == 6) {
-				dbus_uint64_t mac_address;
-				
-				mac_address = 
-					((dbus_uint64_t)a5<<40) |
-					((dbus_uint64_t)a4<<32) | 
-					((dbus_uint64_t)a3<<24) | 
-					((dbus_uint64_t)a2<<16) | 
-					((dbus_uint64_t)a1<< 8) | 
-					((dbus_uint64_t)a0<< 0);
-				
-				hal_device_property_set_uint64 (d, is_wireless ? "net.80211.mac_address" : 
-								"net.80203.mac_address",
-								mac_address);
-			}
+			hal_device_property_set_uint64 (d, "net.80203.mac_address", mac_address);
 		}
 	} else if (media_type == ARPHRD_IRDA) {
 		hal_device_property_set_string (d, "info.product", "Networking Interface");
@@ -549,6 +550,24 @@ error:
 
 	return d;
 }
+static const char *
+net_get_prober (HalDevice *d)
+{
+	const char *prober = NULL;
+
+	/* run prober only for bluetooth devices */
+	if (hal_device_has_capability (d, "net.bluetooth")) {
+		prober = "hald-probe-net-bluetooth";
+	}
+
+	return prober;
+}
+
+static gboolean
+net_post_probing (HalDevice *d)
+{
+	return TRUE;
+}
 
 static gboolean
 net_compute_udi (HalDevice *d)
@@ -2978,8 +2997,8 @@ static DevHandler dev_handler_net = 
 { 
 	.subsystem    = "net",
 	.add          = net_add,
-	.get_prober   = NULL,
-	.post_probing = NULL,
+	.get_prober   = net_get_prober,
+	.post_probing = net_post_probing,
 	.compute_udi  = net_compute_udi,
 	.remove       = dev_remove
 };
diff --git a/hald/linux/probing/Makefile.am b/hald/linux/probing/Makefile.am
index b081e48..64eb058 100644
--- a/hald/linux/probing/Makefile.am
+++ b/hald/linux/probing/Makefile.am
@@ -10,7 +10,7 @@ INCLUDES = \
 
 if HALD_COMPILE_LINUX
 libexec_PROGRAMS = hald-probe-input hald-probe-hiddev hald-probe-storage hald-probe-volume hald-probe-printer \
-	           hald-probe-pc-floppy hald-probe-smbios hald-probe-serial hald-probe-ieee1394-unit
+	           hald-probe-pc-floppy hald-probe-smbios hald-probe-serial hald-probe-ieee1394-unit hald-probe-net-bluetooth
 endif
 
 hald_probe_smbios_SOURCES = probe-smbios.c ../../logger.c
@@ -39,3 +39,6 @@ hald_probe_volume_LDADD = $(top_builddir
 
 hald_probe_ieee1394_unit_SOURCES = probe-ieee1394-unit.c ../../logger.c
 hald_probe_ieee1394_unit_LDADD = $(top_builddir)/libhal/libhal.la
+
+hald_probe_net_bluetooth_SOURCES = probe-net-bluetooth.c ../../logger.c
+hald_probe_net_bluetooth_LDADD = $(top_builddir)/libhal/libhal.la
diff --git a/hald/linux/probing/probe-net-bluetooth.c b/hald/linux/probing/probe-net-bluetooth.c
new file mode 100644
index 0000000..2abaa70
--- /dev/null
+++ b/hald/linux/probing/probe-net-bluetooth.c
@@ -0,0 +1,240 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * probe-net-bluetooth.c : Probe bluetooth network devices
+ *
+ * Copyright (C) 2007 Luiz Augusto von Dentz, <luiz.dentz at indt.org.br>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <string.h>
+
+#include "../../logger.h"
+#include "libhal/libhal.h"
+
+#define BLUEZ_SERVICE "org.bluez"
+#define BLUEZ_PATH "/org/bluez"
+#define BLUEZ_MANAGER_IFACE "org.bluez.Manager"
+#define BLUEZ_NET_PATH "/org/bluez/network"
+#define BLUEZ_NET_MANAGER_IFACE "org.bluez.network.Manager"
+#define BLUEZ_NET_CONNECTION_IFACE "org.bluez.network.Connection"
+#define BLUEZ_NET_SERVER_IFACE "org.bluez.network.Server"
+
+static void
+get_properties (DBusConnection *conn, LibHalContext *ctx, const char *udi,
+				const char *id, const char *path)
+{
+	DBusMessage *msg;
+	DBusMessage *reply = NULL;
+	DBusMessageIter reply_iter;
+	DBusMessageIter dict_iter;
+	DBusError error;
+
+	dbus_error_init (&error);
+
+	msg = dbus_message_new_method_call (id, path,
+										BLUEZ_NET_CONNECTION_IFACE,
+										"GetInfo");
+
+	if (msg == NULL)
+		goto out;
+
+	HAL_INFO (("%s.GetInfo()", BLUEZ_NET_CONNECTION_IFACE));
+	reply = dbus_connection_send_with_reply_and_block (conn, msg, -1, &error);
+
+	if (dbus_error_is_set (&error) || dbus_set_error_from_message (&error,
+		reply)) {
+		dbus_error_free (&error);
+		goto out;
+	}
+
+	dbus_message_iter_init (reply, &reply_iter);
+
+	if (dbus_message_iter_get_arg_type (&reply_iter) != DBUS_TYPE_ARRAY  &&
+	    dbus_message_iter_get_element_type (&reply_iter) != DBUS_TYPE_DICT_ENTRY) {
+		goto out;
+	}
+
+	dbus_message_iter_recurse (&reply_iter, &dict_iter);
+
+	while (dbus_message_iter_get_arg_type (&dict_iter) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter dict_entry_iter, var_iter;
+		const char *key;
+		char prop[32];
+
+		dbus_message_iter_recurse (&dict_iter, &dict_entry_iter);
+		dbus_message_iter_get_basic (&dict_entry_iter, &key);
+
+		dbus_message_iter_next (&dict_entry_iter);
+		dbus_message_iter_recurse (&dict_entry_iter, &var_iter);
+
+		snprintf(prop, 32, "net.bluetooth.%s", key);
+
+		/* Make any property found annouced by hal */
+		switch (dbus_message_iter_get_arg_type (&var_iter)) {
+		case DBUS_TYPE_STRING:
+		{
+			const char *value;
+
+			dbus_message_iter_get_basic (&var_iter, &value);
+
+			HAL_INFO (("reply: %s:%s", key, value));
+
+			libhal_device_set_property_string (ctx, udi, prop, value, &error);
+			break;
+		}
+		case DBUS_TYPE_INT32:
+		{
+			dbus_int32_t value;
+
+			dbus_message_iter_get_basic (&var_iter, &value);
+
+			HAL_INFO (("reply: %s:%d", key, value));
+
+			libhal_device_set_property_int (ctx, udi, prop, value, &error);
+			break;
+		}
+		default:
+			break;
+		}
+		dbus_message_iter_next (&dict_iter);
+	}
+
+out:
+	if (msg)
+		dbus_message_unref (msg);
+	if (reply)
+		dbus_message_unref (reply);
+	return;
+}
+
+int
+main (int argc, char *argv[])
+{
+	char *udi;
+	char *iface;
+	char *id;
+	const char *connection;
+	char network[8] = "network";
+	const char *pnetwork = network;
+	LibHalContext *ctx = NULL;
+	DBusConnection *conn;
+	DBusMessage *msg = NULL;
+	DBusMessage *reply = NULL;
+	DBusError error;
+
+	udi = getenv ("UDI");
+	if (udi == NULL)
+		goto out;
+
+	dbus_error_init (&error);
+	if ((ctx = libhal_ctx_init_direct (&error)) == NULL)
+		goto out;
+
+	iface = libhal_device_get_property_string (ctx, udi, "net.interface",
+												NULL);
+
+	HAL_INFO (("Investigating '%s'", iface));
+
+	if (iface == NULL)
+		goto out;
+
+	if ((conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error)) == NULL)
+		goto out;
+
+	msg = dbus_message_new_method_call (BLUEZ_SERVICE, BLUEZ_PATH,
+										BLUEZ_MANAGER_IFACE,
+										"ActivateService");
+
+	if (msg == NULL)
+		goto out;
+
+	HAL_INFO (("%s.ActivateService('%s')", BLUEZ_MANAGER_IFACE, pnetwork));
+	dbus_message_append_args (msg, DBUS_TYPE_STRING, &pnetwork,
+								DBUS_TYPE_INVALID);
+	reply = dbus_connection_send_with_reply_and_block (conn, msg, -1, &error);
+
+	if (dbus_error_is_set (&error) || dbus_set_error_from_message (&error,
+		reply)) {
+		dbus_error_free (&error);
+		goto out;
+	}
+
+	dbus_message_unref (msg);
+	msg = NULL;
+
+	dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &id,
+							DBUS_TYPE_INVALID);
+	if (dbus_error_is_set (&error)) {
+		dbus_error_free (&error);
+		goto out;
+	}
+
+	dbus_message_unref (reply);
+	reply = NULL;
+
+	HAL_INFO (("Found Bluez Network service '%s'", id));
+
+	msg = dbus_message_new_method_call (id, BLUEZ_NET_PATH,
+										BLUEZ_NET_MANAGER_IFACE,
+										"FindConnection");
+
+	if (msg == NULL)
+		goto out;
+
+	HAL_INFO (("%s.FindConnection('%s')", BLUEZ_NET_MANAGER_IFACE, iface));
+	dbus_message_append_args (msg, DBUS_TYPE_STRING, &iface,
+							DBUS_TYPE_INVALID);
+	reply = dbus_connection_send_with_reply_and_block (conn, msg, -1, &error);
+
+	if (dbus_error_is_set (&error) || dbus_set_error_from_message (&error,
+		reply)) {
+		dbus_error_free (&error);
+		goto out;
+	}
+
+	dbus_message_unref (msg);
+	msg = NULL;
+
+	dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &connection,
+							DBUS_TYPE_INVALID);
+	if (dbus_error_is_set (&error)) {
+		dbus_error_free (&error);
+		goto out;
+	}
+
+	get_properties (conn, ctx, udi, id, connection);
+
+out:
+	if (msg)
+		dbus_message_unref (msg);
+	if (reply)
+		dbus_message_unref (reply);
+	if (ctx != NULL) {
+		dbus_error_init (&error);
+		libhal_ctx_shutdown (ctx, &error);
+		libhal_ctx_free (ctx);
+	}
+
+	return 0;
+}


More information about the hal-commit mailing list