Skip to contentSkip to conversation

patch for d-bus support in hcid

Bluez-devel Philip Blundell 7 participants 13 messages Jun 19, 2003 – Sep 4, 2003 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

This patch adds support to hcid for PIN requests using D-BUS. (See
http://www.freedesktop.org/software/dbus/ if you don't know what D-BUS is about.)

The advantage of this is that the UI for PIN entry runs as the logged-in user, rather than root. There's then no need for the helper application to try to guess the value for $DISPLAY or anything like that.

To use this mechanism, you need to configure bluez-utils with --enable-dbus, and set pin-helper to "*dbus" in hcid.conf.

Thanks

p.

configure.in renamed from bluez-utils-2.3/configure.in +15 -0
diff -uprN clean/bluez-utils-2.3/configure.in bluez-utils-2.3/configure.in
@@ -44,6 +44,12 @@ AC_ARG_WITH(bluez-includes,
 	BLUEZ_INCDIR='../libs/include /usr/include'
 )
 
+AC_ARG_ENABLE(dbus,
+	--enable-dbus		  use D-BUS,
+	BLUEZ_DBUS="$enableval",
+	BLUEZ_DBUS="no"
+)
+
 AC_SEARCH_HEADERS(bluetooth/bluetooth.h, $BLUEZ_INCDIR,,
 	AC_MSG_ERROR(Bluetooth headers not found.
 		Please compile and install bluez-libs package.)
@@ -71,4 +77,13 @@ AC_ARG_ENABLE(pcmcia,
            AC_TEST_DIR(/etc/pcmcia, PCMCIA=pcmcia, PCMCIA=)
     fi ])
 
+if test x"$BLUEZ_DBUS" == "xyes"; then
+  PKG_CHECK_MODULES(DBUS, dbus-1, have_dbus=yes, have_dbus=no)
+
+  CFLAGS="$CFLAGS $DBUS_CFLAGS -DDBUS_API_SUBJECT_TO_CHANGE -DENABLE_DBUS"
+  LIBS="$LIBS $DBUS_LIBS"
+fi
+
+AM_CONDITIONAL(ENABLE_DBUS, test x$BLUEZ_DBUS = xyes)
+
 AC_OUTPUT(Makefile hcid/Makefile tools/Makefile rfcomm/Makefile test/Makefile scripts/Makefile pcmcia/Makefile)
hcid/Makefile.am renamed from bluez-utils-2.3/hcid/Makefile.am +7 -1
diff -uprN clean/bluez-utils-2.3/hcid/Makefile.am bluez-utils-2.3/hcid/Makefile.am
@@ -4,7 +4,13 @@
 
 sbin_PROGRAMS = hcid
 
-hcid_SOURCES = main.c security.c hcid.h lib.c lib.h parser.h parser.y lexer.l kword.h kword.c glib-ectomy.h glib-ectomy.c
+if ENABLE_DBUS
+dbus_hcid_sources = dbus.c
+else
+dbus_hcid_sources =
+endif
+
+hcid_SOURCES = main.c security.c hcid.h lib.c lib.h parser.h parser.y lexer.l kword.h kword.c glib-ectomy.h glib-ectomy.c $(dbus_hcid_sources)
 hcid_CONFIG  = hcid.conf
 
 YFLAGS   = -d
hcid/glib-ectomy.h renamed from bluez-utils-2.3/hcid/glib-ectomy.h +2 -0
diff -uprN clean/bluez-utils-2.3/hcid/glib-ectomy.h bluez-utils-2.3/hcid/glib-ectomy.h
@@ -87,6 +87,8 @@ guint     g_io_add_watch        (GIOChan
 				 GIOCondition     condition,
 				 GIOFunc          func,
 				 gpointer         user_data);
+void  g_io_remove_watch (guint id);
+
 
 
 GMainLoop *g_main_loop_new        (GMainContext *context,
hcid/hcid.h renamed from bluez-utils-2.3/hcid/hcid.h +5 -0
diff -uprN clean/bluez-utils-2.3/hcid/hcid.h bluez-utils-2.3/hcid/hcid.h
@@ -91,3 +91,8 @@ void init_security_data(void);
 void start_security_manager(int hdev);
 void stop_security_manager(int hdev);
 void toggle_pairing(int enable);
+#ifdef ENABLE_DBUS
+struct hci_conn_info;
+void hcid_dbus_request_pin(int dev, struct hci_conn_info *ci);
+gboolean hcid_dbus_init(void);
+#endif
hcid/main.c renamed from bluez-utils-2.3/hcid/main.c +7 -0
diff -uprN clean/bluez-utils-2.3/hcid/main.c bluez-utils-2.3/hcid/main.c
@@ -451,6 +451,13 @@ int main(int argc, char *argv[], char *e
 	if (read_config(hcid.config_file) < 0)
 		syslog(LOG_ERR, "Config load failed");
 
+#ifdef ENABLE_DBUS
+	if (hcid_dbus_init () == FALSE) {
+		syslog (LOG_ERR, "Unable to get on D-BUS");
+		exit (1);
+	}
+#endif
+
 	init_security_data();
 
 	/* Create event loop */
hcid/parser.y renamed from bluez-utils-2.3/hcid/parser.y +1 -1
diff -uprN clean/bluez-utils-2.3/hcid/parser.y bluez-utils-2.3/hcid/parser.y
@@ -97,7 +97,7 @@ hcid_opt: 
 				hcid.pairing = $2;
 			}
 
-  | K_PINHELP  PATH	{
+  | K_PINHELP  WORD	{
 				if (hcid.pin_helper)
 					free(hcid.pin_helper);
 				hcid.pin_helper = strdup($2);
hcid/security.c renamed from bluez-utils-2.3/hcid/security.c +13 -2
diff -uprN clean/bluez-utils-2.3/hcid/security.c bluez-utils-2.3/hcid/security.c
@@ -289,6 +289,17 @@ reject:
 	exit(0);
 }
 
+static void request_pin(int dev, struct hci_conn_info *ci)
+{
+#ifdef ENABLE_DBUS
+	if (!strcmp (hcid.pin_helper, "*dbus")) {
+		hcid_dbus_request_pin (dev, ci);
+		return;
+	}
+#endif
+	call_pin_helper (dev, ci);
+}
+
 static void pin_code_request(int dev, bdaddr_t *sba, bdaddr_t *dba)
 {
 	struct hci_conn_info_req *cr;
@@ -335,11 +346,11 @@ static void pin_code_request(int dev, bd
 			/* Outgoing connection */
 		
 			/* Let PIN helper handle that */ 
-			call_pin_helper(dev, ci);
+			request_pin(dev, ci);
 		}
 	} else {
 		/* Let PIN helper handle that */ 
-		call_pin_helper(dev, ci);
+		request_pin(dev, ci);
 	}	
 	free(cr);
 	return;
hcid/glib-ectomy.c renamed from bluez-utils-2.3/hcid/glib-ectomy.c +13 -0
@@ -84,6 +84,19 @@
 
 static struct watch watch_head = { .id = 0, .next = 0 };
 
+void  g_io_remove_watch (guint id)
+{
+	struct watch *w, *p;
+
+	for (p = &watch_head, w = watch_head.next; w; w = w->next) {
+		if (w->id == id) {
+			p->next = w->next;
+			free (w);
+			return;
+		}
+	}
+}
+
 guint     g_io_add_watch        (GIOChannel      *channel,
 				 GIOCondition     condition,
 				 GIOFunc          func,
hcid/dbus.c renamed from bluez-utils-2.3/hcid/dbus.c +232 -0

232 lines not on this page · raw message

#1 lore raw
Quoted 3 lines · Philip Blundell

This patch adds support to hcid for PIN requests using D-BUS. (See
http://www.freedesktop.org/software/dbus/ if you don't know what D-BUS is about.)

Cute.

+#define REQUEST_NAME "org.handhelds.gpe.bluez.pin-request"

Better suggestions welcome.

Signature · 13 lines
dwmw2



-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
#2 lore raw
In reply to Philip Blundell
Quoted 10 lines · Philip Blundell

This patch adds support to hcid for PIN requests using D-BUS. (See
http://www.freedesktop.org/software/dbus/ if you don't know what D-BUS is about.)

The advantage of this is that the UI for PIN entry runs as the logged-in user, rather than root. There's then no need for the helper application to try to guess the value for $DISPLAY or anything like that.

To use this mechanism, you need to configure bluez-utils with --enable-dbus, and set pin-helper to "*dbus" in hcid.conf.

Cool.
We should really start working on 3.x libs and utils. There are so many things and ideas that we want to put in.

Max

-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner. Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#4 lore raw
In reply to Philip Blundell
Quoted 10 lines · Philip Blundell

This patch adds support to hcid for PIN requests using D-BUS. (See
http://www.freedesktop.org/software/dbus/ if you don't know what D-BUS is about.)

The advantage of this is that the UI for PIN entry runs as the logged-in user, rather than root. There's then no need for the helper application to try to guess the value for $DISPLAY or anything like that.

To use this mechanism, you need to configure bluez-utils with --enable-dbus, and set pin-helper to "*dbus" in hcid.conf.

Thanks for doing this. There are now packages in Red Hat Rawhide with this enabled.... volunteers to provide the GNOME and KDE GUI side for this welcomed...

Signature · 12 lines
dwmw2


-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
#5 lore raw
Quoted 3 lines · David Woodhouse

Thanks for doing this. There are now packages in Red Hat Rawhide with this enabled.... volunteers to provide the GNOME and KDE GUI side for this welcomed...

Great. I made a GTK-based GUI for use in GPE; it should work fine in a desktop environment too.

ftp://ftp.handhelds.org/pub/projects/gpe/source/bluez-pin-0.20.tar.gz

p.

-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner. Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#3 lore raw

Version 3 libs/utils (was: Re: [Bluez-devel] patch for d-bus support in hcid)

In reply to Max Krasnyansky
Quoted 2 lines · Max Krasnyansky

We should really start working on 3.x libs and utils. There are so many things and ideas that we want to put in.

I've backed out the unwanted changes to SDP in CVS.

How do you want to start version 3? We'll need to keep the old utils and libs around for a while. However I'd like to merge SDP in early:
there's a lot of duplicated effort (lists, etc.) which can be stripped out.

I have the first-cut at this merge in my local tree. However I don't want to check it in on top of the old utils and libs --- unless you think that's OK.

So maybe the best way to proceed is to start a new branch in CVS?

Steve

Signature · 14 lines
Stephen Crane, Rococo Software Ltd. http://www.rococosoft.com
[email protected] +353-1-6601315 (ext 209)



-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
#8 lore raw

Re: Version 3 libs/utils (was: Re: [Bluez-devel] patch for d-bus support in hcid)

Quoted 10 lines · Stephen Crane

How do you want to start version 3? We'll need to keep the old utils and libs around for a while. However I'd like to merge SDP in early:
there's a lot of duplicated effort (lists, etc.) which can be stripped out.

I have the first-cut at this merge in my local tree. However I don't want to check it in on top of the old utils and libs --- unless you think that's OK.

So maybe the best way to proceed is to start a new branch in CVS?

I think branch is CVS branch is probably a bad idea. Because we want to change a lot of things like command names, etc. Which means lots of file renames, CVS does not handle that.

How about creating completely new modules
libs2
utils2
and start with the clean history.
We'll keep old ones around for a while but will only make minor fixes to them.

Comments ?

Max

-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner. Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#9 lore raw

Re: Version 3 libs/utils (was: Re: [Bluez-devel] patch for d-bus support in hcid)

Quoted 16 lines · Max Krasnyansky
Quoted 10 lines · Stephen Crane

How do you want to start version 3? We'll need to keep the old utils and libs around for a while. However I'd like to merge SDP in early:
there's a lot of duplicated effort (lists, etc.) which can be stripped out.

I have the first-cut at this merge in my local tree. However I don't want to check it in on top of the old utils and libs --- unless you think that's OK.

So maybe the best way to proceed is to start a new branch in CVS?

I think branch is CVS branch is probably a bad idea. Because we want to change a lot of things like command names, etc. Which means lots of file renames, CVS does not handle that.

Quoted 6 lines

How about creating completely new modules
libs2
utils2
and start with the clean history.
We'll keep old ones around for a while but will only make minor fixes to them.

That works for me. You want to go first?

Steve

Signature · 14 lines
Stephen Crane, Rococo Software Ltd. http://www.rococosoft.com
[email protected] +353-1-6601315 (ext 209)



-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
#10 lore raw

Re: Version 3 libs/utils (was: Re: [Bluez-devel] patch for d-bus support in hcid)

In reply to Max Krasnyansky

Hi Max,
Hi Stephen,

Quoted 10 lines

I think branch is CVS branch is probably a bad idea. Because we want to change a lot of things like command names, etc. Which means lots of file renames, CVS does not handle that.

How about creating completely new modules
libs2
utils2
and start with the clean history.
We'll keep old ones around for a while but will only make minor fixes to them.

we have already discussed this and starting with new modules seemed to be the cleanest way. But we shouldn't name them libs2 and utils2, because we are already at version 2.x with the others. We should use libs3 and utils3 or maybe an unrelated to the version number suffix like "-ng".

If we agree on the new name, I will start to create the framework for the new modules.

Regards

Marcel

-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner. Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#11 lore raw

Re: Version 3 libs/utils

Quoted 14 lines · Marcel Holtmann

Hi Max,
Hi Stephen,

Quoted 10 lines

I think branch is CVS branch is probably a bad idea. Because we want to change a lot of things like command names, etc. Which means lots of file renames, CVS does not handle that.

How about creating completely new modules
libs2
utils2
and start with the clean history.
We'll keep old ones around for a while but will only make minor fixes to them.

Quoted 5 lines

we have already discussed this and starting with new modules seemed to be the cleanest way. But we shouldn't name them libs2 and utils2, because we are already at version 2.x with the others. We should use libs3 and utils3 or maybe an unrelated to the version number suffix like "-ng".

I think version number of the current packages and '2' in libs2,utils2 are unrelated. '2' just means second generation or something. New packages will have new version numbers anyway.

So I vote for utils2 and libs2. People are used to things like glib2, libxml2. libs3 would be something unusual :)

Quoted 1 line

If we agree on the new name, I will start to create the framework for the new modules.

Let's talk about the goals and objectives first.

Here is the list of things that I have in mind

1. API cleanup and redesign if necessary
Better function names, etc.

2. Better hotplug support
Device initialization via hotplug scripts /etc/hotplug/bluetooth.agent, /etc/sysconfig/bluetooth, etc.

3. Neighborhood and security databases and API for them Device names, PIN codes, Link keys, etc Tools to access and modify those databases

4. Integrated SDP.

5. Better (more appropriate) names for Bluetooth command line utilities and daemons.

        hciconfig -> btconfig
        rfcomm -> btport
        sdpd -> btsdpd
        etc

6. Improved PIN helper support
D-Bus or something similar.

7. Improved documentation.
At least DoxyGen on headers and sources.

Comments ? Other ideas ?

Max

#12 lore raw

Re: Version 3 libs/utils (was: Re: [Bluez-devel] patch for d-bus support in hcid)

In reply to Max Krasnyansky
Quoted 4 lines · Max Krasnyansky

I think branch is CVS branch is probably a bad idea. Because we want to change a lot of things like command names, etc. Which means lots of file renames, CVS does not handle that.

Yea. Time to move to arch/tla from CVS.

--
Paul

-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine. WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#6 lore raw
In reply to Philip Blundell
Quoted 3 lines · Philip Blundell

This patch adds support to hcid for PIN requests using D-BUS. (See
http://www.freedesktop.org/software/dbus/ if you don't know what D-BUS is about.)

 -  | K_PINHELP  PATH    {
 +  | K_PINHELP  WORD    {

It also removes support for actually configuring a pin helper as before. Reverting the above removes support for the magic '*dbus' value.

+ if (hcid_dbus_init () == FALSE) {
+ syslog (LOG_ERR, "Unable to get on D-BUS");
+ exit (1);

... and then it disables support for running hcid on any system on which dbus isn't actually active, even if not configured to _use_ dbus. :)

I suspect we should just be using a script wrapper around dbus-send, or a simple external program, rather than putting support for dbus directly into hcid.

Signature · 12 lines
dwmw2



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
#7 lore raw
Quoted 6 lines · David Woodhouse

On Thu, 2003-06-19 at 17:42 +0100, Philip Blundell wrote:

 -  | K_PINHELP  PATH    {
 +  | K_PINHELP  WORD    {

It also removes support for actually configuring a pin helper as before. Reverting the above removes support for the magic '*dbus' value.

Hm, right. I was under the impression that WORD was a superset of PATH, but looking at the code again it seems I was mistaken about that.

Making the lexer more permissive about what characters can go in a PATH would probably clear it up, and might not be a bad thing to do on general principle, but the "*dbus" thing was always a bit of a crock anyway. I've modified the patch to use a completely different keyword, so you now replace the whole pin_helper ... line with a "dbus_pin_helper" statement. That should remove any chance of ambiguity and avoid altering the behaviour of existing config files.

Quoted 3 lines

I suspect we should just be using a script wrapper around dbus-send, or a simple external program, rather than putting support for dbus directly into hcid.

For PIN entry that would be a reasonable solution, but there are other ways in which I think it would be useful for hcid to support D-BUS directly; for example, manipulating the list of paired devices and turning discoverability on and off.

I don't think it should be hard to arrange for hcid to tolerate failure to connect to dbus a little better. Try
http://handhelds.org/~pb/bluez-dbus-20030904.diff.gz and see if you get on any better with that one.

p.

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel