All of lore.kernel.org
 help / color / mirror / Atom feed
* [Bluez-devel] [DBUS Patch] Device Property
@ 2005-11-04 14:03 Eduardo Rocha
  2005-11-04 15:44 ` Marcel Holtmann
  0 siblings, 1 reply; 37+ messages in thread
From: Eduardo Rocha @ 2005-11-04 14:03 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 265 bytes --]

Hi Marcel,

here is the patch with the initial development of setproperty and
getproperty for /org/bluez/Device/hciX. As this is only the fundation,
I didn't update the python script.

BR,
Eduardo.

--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: dbus_devices_prop.patch --]
[-- Type: text/x-patch, Size: 8716 bytes --]

--- utils.orig/hcid/dbus.h	2005-11-03 14:34:02.798246064 -0300
+++ utils/hcid/dbus.h	2005-11-04 10:30:18.051748984 -0300
@@ -120,15 +120,49 @@
 /* Control interface methods */
 #define DEV_UP				"Up"
 #define DEV_DOWN			"Down"
-#define DEV_RESET			"Reset"
 #define DEV_SET_PROPERTY		"SetProperty"
 #define DEV_GET_PROPERTY		"GetProperty"
 
+#define DEV_PROPERTY_AUTH		"auth"
+#define DEV_PROPERTY_ENCRYPT		"encrypt"
+#define DEV_PROPERTY_SECMGR		"secmgr"
+#define DEV_PROPERTY_PISCAN		"piscan"
+#define DEV_PROPERTY_PSCAN		"pscan"
+#define DEV_PROPERTY_ISCAN		"iscan"
+#define DEV_PROPERTY_PTYPE		"ptype"
+#define DEV_PROPERTY_LM			"lm"
+#define DEV_PROPERTY_LP			"lp"
+#define DEV_PROPERTY_NAME		"name"
+#define DEV_PROPERTY_CLASS		"class"
+#define DEV_PROPERTY_VOICE		"voice"
+#define DEV_PROPERTY_IAC		"iac"
+#define DEV_PROPERTY_INCMODE		"incmode"
+#define DEV_PROPERTY_INCTYPE		"inctype"
+#define DEV_PROPERTY_INCPARMS		"incparms"
+#define DEV_PROPERTY_PAGEPARMS		"pageparms"
+#define DEV_PROPERTY_PAGETO		"pageto"
+#define DEV_PROPERTY_AFHMODE		"afhmode"
+#define DEV_PROPERTY_ACLMTU		"aclmtu"
+#define DEV_PROPERTY_SCOMTU		"scomtu"
+#define DEV_PROPERTY_PUTKEY		"putkey"
+#define DEV_PROPERTY_DELKEY		"delkey"
+#define DEV_PROPERTY_DEV_INFO		"info"
+
 #define DEV_UP_SIGNATURE			__END_SIG__
 #define DEV_DOWN_SIGNATURE			__END_SIG__
 #define DEV_RESET_SIGNATURE			__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE		__END_SIG__
-#define DEV_GET_PROPERTY_SIGNATURE		__END_SIG__
+#define DEV_SET_PROPERTY_SIGNATURE_1		DBUS_TYPE_STRING_AS_STRING \
+						DBUS_TYPE_BOOLEAN_AS_STRING \
+						__END_SIG__
+#define DEV_SET_PROPERTY_SIGNATURE_2		DBUS_TYPE_STRING_AS_STRING \
+						DBUS_TYPE_STRING_AS_STRING \
+						__END_SIG__
+#define DEV_SET_PROPERTY_SIGNATURE_3		DBUS_TYPE_STRING_AS_STRING \
+						DBUS_TYPE_UINT16_AS_STRING \
+						__END_SIG__
+
+#define DEV_GET_PROPERTY_SIGNATURE		DBUS_TYPE_STRING_AS_STRING \
+						__END_SIG__
 
 
 #define HCI_PERIODIC_INQ_SIGNATURE			DBUS_TYPE_BYTE_AS_STRING \
--- utils.orig/hcid/dbus.c	2005-11-03 14:34:02.798246064 -0300
+++ utils/hcid/dbus.c	2005-11-04 10:36:19.361821504 -0300
@@ -268,13 +268,61 @@
  */
 static DBusMessage* handle_device_up_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_down_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data);
 
 static const struct service_data device_services[] = {
 	{ DEV_UP,		handle_device_up_req,		DEV_UP_SIGNATURE		},
 	{ DEV_DOWN,		handle_device_down_req,		DEV_DOWN_SIGNATURE		},
-	{ DEV_RESET,		handle_not_implemented_req,	DEV_RESET_SIGNATURE		},
-	{ DEV_SET_PROPERTY,	handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE	},
-	{ DEV_GET_PROPERTY,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_1	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_2	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_3	},
+	{ DEV_GET_PROPERTY,	handle_device_get_propety_req,	DEV_GET_PROPERTY_SIGNATURE	},
+	{ NULL, NULL, NULL}
+};
+
+static const struct service_data set_property_services[] = {
+	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_SECMGR,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_PISCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_PTYPE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_LM,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_LP,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_NAME,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_CLASS,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_VOICE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_IAC,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_INCTYPE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_INCPARMS,	handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_PAGEPARMS,	handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_PAGETO,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_AFHMODE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_ACLMTU,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_SCOMTU,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_PUTKEY,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_DELKEY,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ NULL, NULL, NULL}
+};
+
+static const struct service_data get_property_services[] = {
+	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_PTYPE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_LM,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_LP,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_NAME,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_CLASS,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_VOICE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_IAC,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_INCTYPE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_INCPARMS,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_PAGEPARMS,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_PAGETO,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_AFHMODE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
 	{ NULL, NULL, NULL}
 };
 
@@ -1174,16 +1222,16 @@
 	}
 
 	if (handlers) {
+		error = BLUEZ_EDBUS_WRONG_SIGNATURE;
 		for (; handlers->name != NULL; handlers++) {
 			if (strcmp(handlers->name, method) == 0) {
-				if (strcmp(handlers->signature, signature) != 0)
-					error = BLUEZ_EDBUS_WRONG_SIGNATURE;
-				else {
+				if (strcmp(handlers->signature, signature) == 0) {
 					reply = handlers->handler_func(msg, data);
 					error = 0;
+					ret = DBUS_HANDLER_RESULT_HANDLED;
+					break;
 				}
 
-				ret = DBUS_HANDLER_RESULT_HANDLED;
 			}
 		}
 	}
@@ -1768,6 +1816,66 @@
 	return reply;
 }
 
+static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data)
+{
+	const struct service_data *handlers = set_property_services;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	const char *signature;
+	char *str_name;
+	uint32_t error = BLUEZ_EDBUS_UNKNOWN_METHOD;
+
+	signature = dbus_message_get_signature(msg);
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_get_basic(&iter, &str_name);
+
+	for (; handlers->name != NULL; handlers++) {
+		if (strcasecmp(handlers->name, str_name) == 0) {
+			if (strcmp(handlers->signature, signature) == 0) {
+				reply = handlers->handler_func(msg, data);
+				error = 0;
+				break;
+			} else {
+				error = BLUEZ_EDBUS_WRONG_SIGNATURE;
+				break;
+			}
+
+		}
+	}
+
+	if (error)
+		reply = bluez_new_failure_msg(msg, error);
+
+	return reply;
+}
+
+static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data)
+{
+	const struct service_data *handlers = get_property_services;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	char *str_name;
+	uint32_t error = BLUEZ_EDBUS_UNKNOWN_METHOD;
+
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_get_basic(&iter, &str_name);
+
+	for (; handlers->name != NULL; handlers++) {
+		if (strcasecmp(handlers->name, str_name) == 0) {
+			reply = handlers->handler_func(msg, data);
+			error = 0;
+			break;
+		}
+	}
+
+	if (error)
+		reply = bluez_new_failure_msg(msg, error);
+
+	return reply;
+}
+
 static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-04 14:03 [Bluez-devel] [DBUS Patch] Device Property Eduardo Rocha
@ 2005-11-04 15:44 ` Marcel Holtmann
  2005-11-08 20:41   ` Claudio Takahasi
  0 siblings, 1 reply; 37+ messages in thread
From: Marcel Holtmann @ 2005-11-04 15:44 UTC (permalink / raw)
  To: bluez-devel

Hi Eduardo,

> here is the patch with the initial development of setproperty and
> getproperty for /org/bluez/Device/hciX. As this is only the fundation,

I applied the patch to the CVS, but I don't wanna have a simply
hciconfig replacement. We need to think about the functions that we
wanna support over D-Bus.

> I didn't update the python script.

Please do so.

Regards

Marcel




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-04 15:44 ` Marcel Holtmann
@ 2005-11-08 20:41   ` Claudio Takahasi
  2005-11-08 22:20     ` Marcel Holtmann
  2005-11-08 22:20     ` Johan Hedberg
  0 siblings, 2 replies; 37+ messages in thread
From: Claudio Takahasi @ 2005-11-08 20:41 UTC (permalink / raw)
  To: bluez-devel

Hi,

In my opinion we can start playing with the feature below:

  up                      Open and initialize HCI device
  down                  Close HCI device

  name       [name]  Get/Set local name

  auth                   Enable/Disable Authentication
  encrypt               Enable/Disable Encryption
  secmgr               Enable/Disable Security Manager
  piscan                Enable/Disable Page and Inquiry scan
  iscan                  Enable/Disable Inquiry scan
  pscan                 Enable/Disable Page scan


Maybe we could analise the possibility of make the configuration
permanent updating these values in the 'hcid.conf' configuration file.

Regards,
Claudio.


On 11/4/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Eduardo,
>
> > here is the patch with the initial development of setproperty and
> > getproperty for /org/bluez/Device/hciX. As this is only the fundation,
>
> I applied the patch to the CVS, but I don't wanna have a simply
> hciconfig replacement. We need to think about the functions that we
> wanna support over D-Bus.
>
> > I didn't update the python script.
>
> Please do so.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App Server. Downl=
oad
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-08 20:41   ` Claudio Takahasi
@ 2005-11-08 22:20     ` Marcel Holtmann
  2005-11-08 22:20     ` Johan Hedberg
  1 sibling, 0 replies; 37+ messages in thread
From: Marcel Holtmann @ 2005-11-08 22:20 UTC (permalink / raw)
  To: bluez-devel

Hi Claudio,

> In my opinion we can start playing with the feature below:
> 
>   up                      Open and initialize HCI device
>   down                  Close HCI device

leave this for some other time. It is not that easy to do the up and
down properly.

>   name       [name]  Get/Set local name

And include the inquiry mode. We need to configure the name and the
inquiry mode. I also wanna remove the inquiry mode setting inside the
periodic inquiry call.

>   auth                   Enable/Disable Authentication
>   encrypt               Enable/Disable Encryption
>   secmgr               Enable/Disable Security Manager

This is a no. We don't need to configure it. I am not going to support
security mode 3 over the D-Bus interface. People are already doing
enough mistakes right now with it.

>   piscan                Enable/Disable Page and Inquiry scan
>   iscan                  Enable/Disable Inquiry scan
>   pscan                 Enable/Disable Page scan

This is all the same setting and the correct names for it are
"connectable" and "discoverable". There is no need to expose the
Bluetooth crappy names over the D-Bus interface.

> Maybe we could analise the possibility of make the configuration
> permanent updating these values in the 'hcid.conf' configuration file.

Maybe or maybe not. Convince me that you can do it in sane way.

Regards

Marcel




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-08 20:41   ` Claudio Takahasi
  2005-11-08 22:20     ` Marcel Holtmann
@ 2005-11-08 22:20     ` Johan Hedberg
  2005-11-08 22:38       ` Marcel Holtmann
  1 sibling, 1 reply; 37+ messages in thread
From: Johan Hedberg @ 2005-11-08 22:20 UTC (permalink / raw)
  To: bluez-devel

On Tue, Nov 08, 2005, Claudio Takahasi wrote:
> In my opinion we can start playing with the feature below:
> 
>   up                      Open and initialize HCI device
>   down                  Close HCI device

These we already have (through the Up and Down methods).

>   name       [name]  Get/Set local name

This is good to have. A "local name changed" signal might also be useful
so that other applications can update their UI. Actually now that I
think about it, maybe thare should be a generic "property changed"
signal for all properties.

>   auth                   Enable/Disable Authentication
>   encrypt               Enable/Disable Encryption
>   secmgr               Enable/Disable Security Manager
>   piscan                Enable/Disable Page and Inquiry scan
>   iscan                  Enable/Disable Inquiry scan
>   pscan                 Enable/Disable Page scan

I think the piscan can be dropped so that we have two boolean
properties: iscan and pscan.

Also, I think it would be good to have the possibility to set the
inquiry mode (standard, with RSSI, RSSI + extended inq. result).
Currently the mode is always set inquiry with rssi when PeriodicInquiry
is called (I'm thinking of sending a patch to remove it), but it should
probably be set once at device initialization and then changed only by
the SetProperty method call.

Johan


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-08 22:20     ` Johan Hedberg
@ 2005-11-08 22:38       ` Marcel Holtmann
  2005-11-17 19:16         ` Eduardo Rocha
  0 siblings, 1 reply; 37+ messages in thread
From: Marcel Holtmann @ 2005-11-08 22:38 UTC (permalink / raw)
  To: bluez-devel

Hi Johan,

> >   name       [name]  Get/Set local name
> 
> This is good to have. A "local name changed" signal might also be useful
> so that other applications can update their UI. Actually now that I
> think about it, maybe thare should be a generic "property changed"
> signal for all properties.

sounds like a good idea and easy to extend in the future.

> >   auth                   Enable/Disable Authentication
> >   encrypt               Enable/Disable Encryption
> >   secmgr               Enable/Disable Security Manager
> >   piscan                Enable/Disable Page and Inquiry scan
> >   iscan                  Enable/Disable Inquiry scan
> >   pscan                 Enable/Disable Page scan
> 
> I think the piscan can be dropped so that we have two boolean
> properties: iscan and pscan.
> 
> Also, I think it would be good to have the possibility to set the
> inquiry mode (standard, with RSSI, RSSI + extended inq. result).
> Currently the mode is always set inquiry with rssi when PeriodicInquiry
> is called (I'm thinking of sending a patch to remove it), but it should
> probably be set once at device initialization and then changed only by
> the SetProperty method call.

Totally agree.

Regards

Marcel




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-08 22:38       ` Marcel Holtmann
@ 2005-11-17 19:16         ` Eduardo Rocha
  2005-11-17 20:52           ` Eduardo Rocha
  0 siblings, 1 reply; 37+ messages in thread
From: Eduardo Rocha @ 2005-11-17 19:16 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 2265 bytes --]

Hi all,

here is a patch with SetProperty and GetProperty for Name. I've also
updated the dbus-test.
Marcel, in the hciconfig you set the ext inquire parameter in the
cmd_name function. Is this needed here?
The "local name changed"  signal is still missing. I'll do that for
the next patch.

BR,
Eduardo.

--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT


On 11/8/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Johan,
>
> > >   name       [name]  Get/Set local name
> >
> > This is good to have. A "local name changed" signal might also be useful
> > so that other applications can update their UI. Actually now that I
> > think about it, maybe thare should be a generic "property changed"
> > signal for all properties.
>
> sounds like a good idea and easy to extend in the future.
>
> > >   auth                   Enable/Disable Authentication
> > >   encrypt               Enable/Disable Encryption
> > >   secmgr               Enable/Disable Security Manager
> > >   piscan                Enable/Disable Page and Inquiry scan
> > >   iscan                  Enable/Disable Inquiry scan
> > >   pscan                 Enable/Disable Page scan
> >
> > I think the piscan can be dropped so that we have two boolean
> > properties: iscan and pscan.
> >
> > Also, I think it would be good to have the possibility to set the
> > inquiry mode (standard, with RSSI, RSSI + extended inq. result).
> > Currently the mode is always set inquiry with rssi when PeriodicInquiry
> > is called (I'm thinking of sending a patch to remove it), but it should
> > probably be set once at device initialization and then changed only by
> > the SetProperty method call.
>
> Totally agree.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App Server. Download
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>

[-- Attachment #2: dbus_device_name.patch --]
[-- Type: text/x-patch, Size: 13214 bytes --]

--- utils.17112005.orig/hcid/dbus.h	2005-11-17 12:57:42.000000000 -0300
+++ utils.17112005/hcid/dbus.h	2005-11-17 13:04:05.000000000 -0300
@@ -126,39 +126,23 @@
 #define DEV_PROPERTY_AUTH		"auth"
 #define DEV_PROPERTY_ENCRYPT		"encrypt"
 #define DEV_PROPERTY_SECMGR		"secmgr"
-#define DEV_PROPERTY_PISCAN		"piscan"
 #define DEV_PROPERTY_PSCAN		"pscan"
 #define DEV_PROPERTY_ISCAN		"iscan"
-#define DEV_PROPERTY_PTYPE		"ptype"
-#define DEV_PROPERTY_LM			"lm"
-#define DEV_PROPERTY_LP			"lp"
 #define DEV_PROPERTY_NAME		"name"
-#define DEV_PROPERTY_CLASS		"class"
-#define DEV_PROPERTY_VOICE		"voice"
-#define DEV_PROPERTY_IAC		"iac"
 #define DEV_PROPERTY_INCMODE		"incmode"
-#define DEV_PROPERTY_INCTYPE		"inctype"
-#define DEV_PROPERTY_INCPARMS		"incparms"
-#define DEV_PROPERTY_PAGEPARMS		"pageparms"
-#define DEV_PROPERTY_PAGETO		"pageto"
-#define DEV_PROPERTY_AFHMODE		"afhmode"
-#define DEV_PROPERTY_ACLMTU		"aclmtu"
-#define DEV_PROPERTY_SCOMTU		"scomtu"
-#define DEV_PROPERTY_PUTKEY		"putkey"
-#define DEV_PROPERTY_DELKEY		"delkey"
 #define DEV_PROPERTY_DEV_INFO		"info"
 
 #define DEV_UP_SIGNATURE			__END_SIG__
 #define DEV_DOWN_SIGNATURE			__END_SIG__
 #define DEV_RESET_SIGNATURE			__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_1		DBUS_TYPE_STRING_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_BOOL		DBUS_TYPE_STRING_AS_STRING \
 						DBUS_TYPE_BOOLEAN_AS_STRING \
 						__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_2		DBUS_TYPE_STRING_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_STR		DBUS_TYPE_STRING_AS_STRING \
 						DBUS_TYPE_STRING_AS_STRING \
 						__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_3		DBUS_TYPE_STRING_AS_STRING \
-						DBUS_TYPE_UINT16_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_BYTE		DBUS_TYPE_STRING_AS_STRING \
+						DBUS_TYPE_BYTE_AS_STRING \
 						__END_SIG__
 
 #define DEV_GET_PROPERTY_SIGNATURE		DBUS_TYPE_STRING_AS_STRING \
--- utils.17112005.orig/hcid/dbus.c	2005-11-17 12:57:42.000000000 -0300
+++ utils.17112005/hcid/dbus.c	2005-11-17 13:04:05.000000000 -0300
@@ -272,59 +272,34 @@
 static DBusMessage* handle_device_down_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data);
 
 static const struct service_data device_services[] = {
 	{ DEV_UP,		handle_device_up_req,		DEV_UP_SIGNATURE		},
 	{ DEV_DOWN,		handle_device_down_req,		DEV_DOWN_SIGNATURE		},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_1	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_2	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_3	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BOOL	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_STR	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BYTE	},
 	{ DEV_GET_PROPERTY,	handle_device_get_propety_req,	DEV_GET_PROPERTY_SIGNATURE	},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data set_property_services[] = {
-	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_SECMGR,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PISCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PTYPE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_LM,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_LP,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_NAME,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_CLASS,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_VOICE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_IAC,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCTYPE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCPARMS,	handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PAGEPARMS,	handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PAGETO,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_AFHMODE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ACLMTU,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_SCOMTU,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PUTKEY,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_DELKEY,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_SECMGR,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_NAME,		handle_device_set_propety_req_name,	DEV_SET_PROPERTY_SIGNATURE_STR	 	},
+	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BYTE 	},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data get_property_services[] = {
-	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PTYPE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_LM,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_LP,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_NAME,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_CLASS,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_VOICE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_IAC,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCTYPE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCPARMS,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PAGEPARMS,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PAGETO,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_AFHMODE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_NAME,		handle_device_get_propety_req_name,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
 	{ NULL, NULL, NULL}
 };
 
@@ -1976,7 +1951,7 @@
 	DBusMessage *reply = NULL;
 	const char *signature;
 	char *str_name;
-	uint32_t error = BLUEZ_EDBUS_UNKNOWN_METHOD;
+	uint32_t error = BLUEZ_EDBUS_WRONG_PARAM;
 
 	signature = dbus_message_get_signature(msg);
 
@@ -2009,7 +1984,7 @@
 	DBusMessageIter iter;
 	DBusMessage *reply = NULL;
 	char *str_name;
-	uint32_t error = BLUEZ_EDBUS_UNKNOWN_METHOD;
+	uint32_t error = BLUEZ_EDBUS_WRONG_PARAM;
 
 
 	dbus_message_iter_init(msg, &iter);
@@ -2029,6 +2004,123 @@
 	return reply;
 }
 
+static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	char *str_name;
+	int dd = -1;
+	uint8_t status;
+	change_local_name_cp cp;
+	struct hci_request rq;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &str_name);
+
+	syslog(LOG_INFO, "Setting hci%d name: %s",
+					dbus_data->dev_id, str_name);
+
+	if(strlen(str_name) == 0) {
+		syslog(LOG_ERR, "HCI change name failed - Invalid Name!");
+		reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
+	}
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	strncpy((char *) cp.name, str_name, sizeof(cp.name));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_CHANGE_LOCAL_NAME;
+	rq.cparam = &cp;
+	rq.clen   = CHANGE_LOCAL_NAME_CP_SIZE;
+	rq.rparam = &status;
+	rq.rlen   = sizeof(status);
+
+	if (hci_send_req(dd, &rq, 2000) < 0) {
+		syslog(LOG_ERR, "Sending change name command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (status) {
+		syslog(LOG_ERR, "Periodic inquiry failed with status 0x%02x", status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + status);
+		goto failed;
+	}
+
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+
+	return reply;
+}
+
+static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	int dd = -1;
+        read_local_name_rp rp;
+        struct hci_request rq;
+	const char *pname = rp.name;
+	char name[249];
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+        memset(&rq, 0, sizeof(rq));
+        rq.ogf    = OGF_HOST_CTL;
+        rq.ocf    = OCF_READ_LOCAL_NAME;
+        rq.rparam = &rp;
+        rq.rlen   = READ_LOCAL_NAME_RP_SIZE;
+
+        if (hci_send_req(dd, &rq, 1000) < 0) {
+		syslog(LOG_ERR, "Getting name command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+        if (rp.status) {
+		syslog(LOG_ERR, "Getting name failed with status 0x%02x", rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + rp.status);
+		goto failed;
+        }
+	syslog(LOG_INFO, "Got hci%d name: %s",dbus_data->dev_id, rp.name);
+	reply = dbus_message_new_method_return(msg);
+	if (reply == NULL) {
+		syslog(LOG_ERR, "Out of memory while calling dbus_message_new_method_return");
+		goto failed;
+	}
+
+	strncpy(name,pname,sizeof(name)-1);
+	name[248]='\0';
+	pname = name;
+
+	dbus_message_iter_init_append(reply, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &pname);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+
+	return reply;
+}
+
 static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;
--- utils.17112005.orig/hcid/dbus-test	2005-11-17 12:57:42.000000000 -0300
+++ utils.17112005/hcid/dbus-test	2005-11-17 13:04:05.000000000 -0300
@@ -8,7 +8,7 @@
 from signal import *
 
 mgr_cmds = [ "DeviceList", "DefaultDevice" ]
-dev_cmds = [ "Up", "Down", "Inquiry", "CancelInquiry", "PeriodicInquiry",
+dev_cmds = [ "Up", "Down", "SetProperty", "GetProperty", "Inquiry", "CancelInquiry", "PeriodicInquiry",
              "CancelPeriodic", "RemoteName", "Connections", "Authenticate",
              "RoleSwitch" ]
 
@@ -179,7 +179,29 @@
             except dbus.DBusException, e:
                 print 'Sending %s failed: %s' % (self.cmd, e)
                 sys.exit(1)
-
+	elif self.cmd == 'SetProperty':
+            if len(self.cmd_args) < 2:
+	        print 'Usage: %s -i <dev> SetProperty strPropName arg' % self.name
+                sys.exit(1)
+            try:
+	    	if self.cmd_args[0].lower() == 'name': 
+	            self.dev.SetProperty(dbus.String("name"), dbus.String(self.cmd_args[1]))
+                else:
+	            self.dev.SetProperty(dbus.String(self.cmd_args[0]), dbus.String(self.cmd_args[1]));
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
+        # Device.Controller methods
+	elif self.cmd == 'GetProperty':
+            if len(self.cmd_args) < 1:
+	        print 'Usage: %s -i <dev> GetProperty strPropName' % self.name
+                sys.exit(1)
+            try:
+	        name = self.cmd_args[0]
+	        print self.dev.GetProperty(name)
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
         # Device.Controller methods
         elif self.cmd == 'Inquiry':
             try:

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-17 19:16         ` Eduardo Rocha
@ 2005-11-17 20:52           ` Eduardo Rocha
  2005-11-18  8:28             ` Johan Hedberg
  0 siblings, 1 reply; 37+ messages in thread
From: Eduardo Rocha @ 2005-11-17 20:52 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 2634 bytes --]

Hi Marcel,

sorry about my last patch. I've left some syslog entries. Here is a new patch.

br,
Eduardo.


On 11/17/05, Eduardo Rocha <folhabranca@gmail.com> wrote:
> Hi all,
>
> here is a patch with SetProperty and GetProperty for Name. I've also
> updated the dbus-test.
> Marcel, in the hciconfig you set the ext inquire parameter in the
> cmd_name function. Is this needed here?
> The "local name changed"  signal is still missing. I'll do that for
> the next patch.
>
> BR,
> Eduardo.
>
> --
> Eduardo Rocha
> Instituto Nokia de Tecnologia - INdT
>
>
> On 11/8/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> > Hi Johan,
> >
> > > >   name       [name]  Get/Set local name
> > >
> > > This is good to have. A "local name changed" signal might also be useful
> > > so that other applications can update their UI. Actually now that I
> > > think about it, maybe thare should be a generic "property changed"
> > > signal for all properties.
> >
> > sounds like a good idea and easy to extend in the future.
> >
> > > >   auth                   Enable/Disable Authentication
> > > >   encrypt               Enable/Disable Encryption
> > > >   secmgr               Enable/Disable Security Manager
> > > >   piscan                Enable/Disable Page and Inquiry scan
> > > >   iscan                  Enable/Disable Inquiry scan
> > > >   pscan                 Enable/Disable Page scan
> > >
> > > I think the piscan can be dropped so that we have two boolean
> > > properties: iscan and pscan.
> > >
> > > Also, I think it would be good to have the possibility to set the
> > > inquiry mode (standard, with RSSI, RSSI + extended inq. result).
> > > Currently the mode is always set inquiry with rssi when PeriodicInquiry
> > > is called (I'm thinking of sending a patch to remove it), but it should
> > > probably be set once at device initialization and then changed only by
> > > the SetProperty method call.
> >
> > Totally agree.
> >
> > Regards
> >
> > Marcel
> >
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net email is sponsored by:
> > Tame your development challenges with Apache's Geronimo App Server. Download
> > it for free - -and be entered to win a 42" plasma tv or your very own
> > Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
> > _______________________________________________
> > Bluez-devel mailing list
> > Bluez-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/bluez-devel
> >
>
>
>


--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: dbus_device_name.patch --]
[-- Type: text/x-patch, Size: 13058 bytes --]

--- utils.17112005.orig/hcid/dbus.h	2005-11-17 12:57:42.000000000 -0300
+++ utils.17112005/hcid/dbus.h	2005-11-17 13:04:05.000000000 -0300
@@ -126,39 +126,23 @@
 #define DEV_PROPERTY_AUTH		"auth"
 #define DEV_PROPERTY_ENCRYPT		"encrypt"
 #define DEV_PROPERTY_SECMGR		"secmgr"
-#define DEV_PROPERTY_PISCAN		"piscan"
 #define DEV_PROPERTY_PSCAN		"pscan"
 #define DEV_PROPERTY_ISCAN		"iscan"
-#define DEV_PROPERTY_PTYPE		"ptype"
-#define DEV_PROPERTY_LM			"lm"
-#define DEV_PROPERTY_LP			"lp"
 #define DEV_PROPERTY_NAME		"name"
-#define DEV_PROPERTY_CLASS		"class"
-#define DEV_PROPERTY_VOICE		"voice"
-#define DEV_PROPERTY_IAC		"iac"
 #define DEV_PROPERTY_INCMODE		"incmode"
-#define DEV_PROPERTY_INCTYPE		"inctype"
-#define DEV_PROPERTY_INCPARMS		"incparms"
-#define DEV_PROPERTY_PAGEPARMS		"pageparms"
-#define DEV_PROPERTY_PAGETO		"pageto"
-#define DEV_PROPERTY_AFHMODE		"afhmode"
-#define DEV_PROPERTY_ACLMTU		"aclmtu"
-#define DEV_PROPERTY_SCOMTU		"scomtu"
-#define DEV_PROPERTY_PUTKEY		"putkey"
-#define DEV_PROPERTY_DELKEY		"delkey"
 #define DEV_PROPERTY_DEV_INFO		"info"
 
 #define DEV_UP_SIGNATURE			__END_SIG__
 #define DEV_DOWN_SIGNATURE			__END_SIG__
 #define DEV_RESET_SIGNATURE			__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_1		DBUS_TYPE_STRING_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_BOOL		DBUS_TYPE_STRING_AS_STRING \
 						DBUS_TYPE_BOOLEAN_AS_STRING \
 						__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_2		DBUS_TYPE_STRING_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_STR		DBUS_TYPE_STRING_AS_STRING \
 						DBUS_TYPE_STRING_AS_STRING \
 						__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_3		DBUS_TYPE_STRING_AS_STRING \
-						DBUS_TYPE_UINT16_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_BYTE		DBUS_TYPE_STRING_AS_STRING \
+						DBUS_TYPE_BYTE_AS_STRING \
 						__END_SIG__
 
 #define DEV_GET_PROPERTY_SIGNATURE		DBUS_TYPE_STRING_AS_STRING \
--- utils.17112005.orig/hcid/dbus.c	2005-11-17 12:57:42.000000000 -0300
+++ utils.17112005/hcid/dbus.c	2005-11-17 14:48:45.000000000 -0300
@@ -272,59 +272,34 @@
 static DBusMessage* handle_device_down_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data);
 
 static const struct service_data device_services[] = {
 	{ DEV_UP,		handle_device_up_req,		DEV_UP_SIGNATURE		},
 	{ DEV_DOWN,		handle_device_down_req,		DEV_DOWN_SIGNATURE		},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_1	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_2	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_3	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BOOL	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_STR	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BYTE	},
 	{ DEV_GET_PROPERTY,	handle_device_get_propety_req,	DEV_GET_PROPERTY_SIGNATURE	},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data set_property_services[] = {
-	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_SECMGR,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PISCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PTYPE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_LM,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_LP,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_NAME,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_CLASS,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_VOICE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_IAC,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCTYPE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCPARMS,	handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PAGEPARMS,	handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PAGETO,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_AFHMODE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ACLMTU,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_SCOMTU,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PUTKEY,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_DELKEY,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_SECMGR,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_NAME,		handle_device_set_propety_req_name,	DEV_SET_PROPERTY_SIGNATURE_STR	 	},
+	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BYTE 	},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data get_property_services[] = {
-	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PTYPE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_LM,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_LP,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_NAME,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_CLASS,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_VOICE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_IAC,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCTYPE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCPARMS,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PAGEPARMS,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PAGETO,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_AFHMODE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_NAME,		handle_device_get_propety_req_name,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
 	{ NULL, NULL, NULL}
 };
 
@@ -1976,7 +1951,7 @@
 	DBusMessage *reply = NULL;
 	const char *signature;
 	char *str_name;
-	uint32_t error = BLUEZ_EDBUS_UNKNOWN_METHOD;
+	uint32_t error = BLUEZ_EDBUS_WRONG_PARAM;
 
 	signature = dbus_message_get_signature(msg);
 
@@ -2009,7 +1984,7 @@
 	DBusMessageIter iter;
 	DBusMessage *reply = NULL;
 	char *str_name;
-	uint32_t error = BLUEZ_EDBUS_UNKNOWN_METHOD;
+	uint32_t error = BLUEZ_EDBUS_WRONG_PARAM;
 
 
 	dbus_message_iter_init(msg, &iter);
@@ -2029,6 +2004,120 @@
 	return reply;
 }
 
+static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	char *str_name;
+	int dd = -1;
+	uint8_t status;
+	change_local_name_cp cp;
+	struct hci_request rq;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &str_name);
+
+	if(strlen(str_name) == 0) {
+		syslog(LOG_ERR, "HCI change name failed - Invalid Name!");
+		reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
+	}
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	strncpy((char *) cp.name, str_name, sizeof(cp.name));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_CHANGE_LOCAL_NAME;
+	rq.cparam = &cp;
+	rq.clen   = CHANGE_LOCAL_NAME_CP_SIZE;
+	rq.rparam = &status;
+	rq.rlen   = sizeof(status);
+
+	if (hci_send_req(dd, &rq, 2000) < 0) {
+		syslog(LOG_ERR, "Sending change name command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (status) {
+		syslog(LOG_ERR, "Periodic inquiry failed with status 0x%02x", status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + status);
+		goto failed;
+	}
+
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+
+	return reply;
+}
+
+static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	int dd = -1;
+	read_local_name_rp rp;
+	struct hci_request rq;
+	const char *pname = (char*) rp.name;
+	char name[249];
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+        memset(&rq, 0, sizeof(rq));
+        rq.ogf    = OGF_HOST_CTL;
+        rq.ocf    = OCF_READ_LOCAL_NAME;
+        rq.rparam = &rp;
+        rq.rlen   = READ_LOCAL_NAME_RP_SIZE;
+
+        if (hci_send_req(dd, &rq, 1000) < 0) {
+		syslog(LOG_ERR, "Getting name command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+        if (rp.status) {
+		syslog(LOG_ERR, "Getting name failed with status 0x%02x", rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + rp.status);
+		goto failed;
+        }
+
+	reply = dbus_message_new_method_return(msg);
+	if (reply == NULL) {
+		syslog(LOG_ERR, "Out of memory while calling dbus_message_new_method_return");
+		goto failed;
+	}
+
+	strncpy(name,pname,sizeof(name)-1);
+	name[248]='\0';
+	pname = name;
+
+	dbus_message_iter_init_append(reply, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &pname);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+
+	return reply;
+}
+
 static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;
--- utils.17112005.orig/hcid/dbus-test	2005-11-17 12:57:42.000000000 -0300
+++ utils.17112005/hcid/dbus-test	2005-11-17 13:04:05.000000000 -0300
@@ -8,7 +8,7 @@
 from signal import *
 
 mgr_cmds = [ "DeviceList", "DefaultDevice" ]
-dev_cmds = [ "Up", "Down", "Inquiry", "CancelInquiry", "PeriodicInquiry",
+dev_cmds = [ "Up", "Down", "SetProperty", "GetProperty", "Inquiry", "CancelInquiry", "PeriodicInquiry",
              "CancelPeriodic", "RemoteName", "Connections", "Authenticate",
              "RoleSwitch" ]
 
@@ -179,7 +179,29 @@
             except dbus.DBusException, e:
                 print 'Sending %s failed: %s' % (self.cmd, e)
                 sys.exit(1)
-
+	elif self.cmd == 'SetProperty':
+            if len(self.cmd_args) < 2:
+	        print 'Usage: %s -i <dev> SetProperty strPropName arg' % self.name
+                sys.exit(1)
+            try:
+	    	if self.cmd_args[0].lower() == 'name': 
+	            self.dev.SetProperty(dbus.String("name"), dbus.String(self.cmd_args[1]))
+                else:
+	            self.dev.SetProperty(dbus.String(self.cmd_args[0]), dbus.String(self.cmd_args[1]));
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
+        # Device.Controller methods
+	elif self.cmd == 'GetProperty':
+            if len(self.cmd_args) < 1:
+	        print 'Usage: %s -i <dev> GetProperty strPropName' % self.name
+                sys.exit(1)
+            try:
+	        name = self.cmd_args[0]
+	        print self.dev.GetProperty(name)
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
         # Device.Controller methods
         elif self.cmd == 'Inquiry':
             try:

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-17 20:52           ` Eduardo Rocha
@ 2005-11-18  8:28             ` Johan Hedberg
  2005-11-18 10:51               ` Eduardo Rocha
  0 siblings, 1 reply; 37+ messages in thread
From: Johan Hedberg @ 2005-11-18  8:28 UTC (permalink / raw)
  To: bluez-devel

Hi Eduardo,

Your patch looks ok in general, however there are a couple of issues I'd
like to comment on:

1. The string given to the syslog call in the "if (status)" part of the
handle_device_set_propety_req_name function is wrong (just a simple
copy-paste mistake).

2. The list assigned to the dev_cmds variable in the dbus-test app could
be reformated to be max 80 chars wide.

3. There are several places in dbus-test where the indentation is wrong:
some places there are extra spaces, others have too few. You have also
mixed tabs and spaces in a couple of places (the indentation should, at
least for now, use 4 spaces).

4. You don't need to use dbus.String(var) when giving a string variable
to a method call using the python bindings.

5. We should think of how to allow giving different types (bool, byte,
string) to the SetProperty method using dbus-test. One way to do it
would be to give four parameters in the command line (e.g. "SetProperty
connectable b true" or "SetProperty name s MyName"). Another option is
to change to the HAL way of doing properties (by having
SetPropertyString, SetPropertyBoolean, etc).

Johan


-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-18  8:28             ` Johan Hedberg
@ 2005-11-18 10:51               ` Eduardo Rocha
  2005-11-18 11:26                 ` Johan Hedberg
  0 siblings, 1 reply; 37+ messages in thread
From: Eduardo Rocha @ 2005-11-18 10:51 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 2230 bytes --]

Hi Johan,

sorry about the tabs. Here is the new patch. Could you give any
comments about the hci_send_req timeout (maybe is too high) and the
extended inquire parameters that is set cmd_name function in hciconfig
app (is that needed here?).
About the parameters, I've done an if to detect each property name so
we can treat  the parameter diferently.

BR,
Eduardo.


On 11/18/05, Johan Hedberg <johan.hedberg@nokia.com> wrote:
> Hi Eduardo,
>
> Your patch looks ok in general, however there are a couple of issues I'd
> like to comment on:
>
> 1. The string given to the syslog call in the "if (status)" part of the
> handle_device_set_propety_req_name function is wrong (just a simple
> copy-paste mistake).
>
> 2. The list assigned to the dev_cmds variable in the dbus-test app could
> be reformated to be max 80 chars wide.
>
> 3. There are several places in dbus-test where the indentation is wrong:
> some places there are extra spaces, others have too few. You have also
> mixed tabs and spaces in a couple of places (the indentation should, at
> least for now, use 4 spaces).
>
> 4. You don't need to use dbus.String(var) when giving a string variable
> to a method call using the python bindings.
>
> 5. We should think of how to allow giving different types (bool, byte,
> string) to the SetProperty method using dbus-test. One way to do it
> would be to give four parameters in the command line (e.g. "SetProperty
> connectable b true" or "SetProperty name s MyName"). Another option is
> to change to the HAL way of doing properties (by having
> SetPropertyString, SetPropertyBoolean, etc).
>
> Johan
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
> Register for a JBoss Training Course.  Free Certification Exam
> for All Training Attendees Through End of 2005. For more info visit:
> http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: dbus_device_name.patch --]
[-- Type: text/x-patch, Size: 13298 bytes --]

--- utils.17112005.orig/hcid/dbus.h	2005-11-17 12:57:42.000000000 -0300
+++ utils.17112005/hcid/dbus.h	2005-11-17 13:04:05.000000000 -0300
@@ -126,39 +126,23 @@
 #define DEV_PROPERTY_AUTH		"auth"
 #define DEV_PROPERTY_ENCRYPT		"encrypt"
 #define DEV_PROPERTY_SECMGR		"secmgr"
-#define DEV_PROPERTY_PISCAN		"piscan"
 #define DEV_PROPERTY_PSCAN		"pscan"
 #define DEV_PROPERTY_ISCAN		"iscan"
-#define DEV_PROPERTY_PTYPE		"ptype"
-#define DEV_PROPERTY_LM			"lm"
-#define DEV_PROPERTY_LP			"lp"
 #define DEV_PROPERTY_NAME		"name"
-#define DEV_PROPERTY_CLASS		"class"
-#define DEV_PROPERTY_VOICE		"voice"
-#define DEV_PROPERTY_IAC		"iac"
 #define DEV_PROPERTY_INCMODE		"incmode"
-#define DEV_PROPERTY_INCTYPE		"inctype"
-#define DEV_PROPERTY_INCPARMS		"incparms"
-#define DEV_PROPERTY_PAGEPARMS		"pageparms"
-#define DEV_PROPERTY_PAGETO		"pageto"
-#define DEV_PROPERTY_AFHMODE		"afhmode"
-#define DEV_PROPERTY_ACLMTU		"aclmtu"
-#define DEV_PROPERTY_SCOMTU		"scomtu"
-#define DEV_PROPERTY_PUTKEY		"putkey"
-#define DEV_PROPERTY_DELKEY		"delkey"
 #define DEV_PROPERTY_DEV_INFO		"info"
 
 #define DEV_UP_SIGNATURE			__END_SIG__
 #define DEV_DOWN_SIGNATURE			__END_SIG__
 #define DEV_RESET_SIGNATURE			__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_1		DBUS_TYPE_STRING_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_BOOL		DBUS_TYPE_STRING_AS_STRING \
 						DBUS_TYPE_BOOLEAN_AS_STRING \
 						__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_2		DBUS_TYPE_STRING_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_STR		DBUS_TYPE_STRING_AS_STRING \
 						DBUS_TYPE_STRING_AS_STRING \
 						__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_3		DBUS_TYPE_STRING_AS_STRING \
-						DBUS_TYPE_UINT16_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_BYTE		DBUS_TYPE_STRING_AS_STRING \
+						DBUS_TYPE_BYTE_AS_STRING \
 						__END_SIG__
 
 #define DEV_GET_PROPERTY_SIGNATURE		DBUS_TYPE_STRING_AS_STRING \
--- utils.17112005.orig/hcid/dbus.c	2005-11-17 12:57:42.000000000 -0300
+++ utils.17112005/hcid/dbus.c	2005-11-18 04:38:07.000000000 -0300
@@ -272,59 +272,34 @@
 static DBusMessage* handle_device_down_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data);
 
 static const struct service_data device_services[] = {
 	{ DEV_UP,		handle_device_up_req,		DEV_UP_SIGNATURE		},
 	{ DEV_DOWN,		handle_device_down_req,		DEV_DOWN_SIGNATURE		},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_1	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_2	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_3	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BOOL	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_STR	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BYTE	},
 	{ DEV_GET_PROPERTY,	handle_device_get_propety_req,	DEV_GET_PROPERTY_SIGNATURE	},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data set_property_services[] = {
-	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_SECMGR,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PISCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PTYPE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_LM,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_LP,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_NAME,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_CLASS,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_VOICE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_IAC,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCTYPE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCPARMS,	handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PAGEPARMS,	handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PAGETO,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_AFHMODE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ACLMTU,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_SCOMTU,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PUTKEY,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_DELKEY,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_SECMGR,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_NAME,		handle_device_set_propety_req_name,	DEV_SET_PROPERTY_SIGNATURE_STR	 	},
+	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BYTE 	},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data get_property_services[] = {
-	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PTYPE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_LM,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_LP,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_NAME,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_CLASS,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_VOICE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_IAC,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCTYPE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCPARMS,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PAGEPARMS,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PAGETO,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_AFHMODE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_NAME,		handle_device_get_propety_req_name,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
 	{ NULL, NULL, NULL}
 };
 
@@ -1976,7 +1951,7 @@
 	DBusMessage *reply = NULL;
 	const char *signature;
 	char *str_name;
-	uint32_t error = BLUEZ_EDBUS_UNKNOWN_METHOD;
+	uint32_t error = BLUEZ_EDBUS_WRONG_PARAM;
 
 	signature = dbus_message_get_signature(msg);
 
@@ -2009,7 +1984,7 @@
 	DBusMessageIter iter;
 	DBusMessage *reply = NULL;
 	char *str_name;
-	uint32_t error = BLUEZ_EDBUS_UNKNOWN_METHOD;
+	uint32_t error = BLUEZ_EDBUS_WRONG_PARAM;
 
 
 	dbus_message_iter_init(msg, &iter);
@@ -2029,6 +2004,120 @@
 	return reply;
 }
 
+static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	char *str_name;
+	int dd = -1;
+	uint8_t status;
+	change_local_name_cp cp;
+	struct hci_request rq;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &str_name);
+
+	if(strlen(str_name) == 0) {
+		syslog(LOG_ERR, "HCI change name failed - Invalid Name!");
+		reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
+	}
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	strncpy((char *) cp.name, str_name, sizeof(cp.name));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_CHANGE_LOCAL_NAME;
+	rq.cparam = &cp;
+	rq.clen   = CHANGE_LOCAL_NAME_CP_SIZE;
+	rq.rparam = &status;
+	rq.rlen   = sizeof(status);
+
+	if (hci_send_req(dd, &rq, 2000) < 0) {
+		syslog(LOG_ERR, "Sending change name command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (status) {
+		syslog(LOG_ERR, "Setting name failed with status 0x%02x", status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + status);
+		goto failed;
+	}
+
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+
+	return reply;
+}
+
+static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	int dd = -1;
+	read_local_name_rp rp;
+	struct hci_request rq;
+	const char *pname = (char*) rp.name;
+	char name[249];
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+        memset(&rq, 0, sizeof(rq));
+        rq.ogf    = OGF_HOST_CTL;
+        rq.ocf    = OCF_READ_LOCAL_NAME;
+        rq.rparam = &rp;
+        rq.rlen   = READ_LOCAL_NAME_RP_SIZE;
+
+        if (hci_send_req(dd, &rq, 1000) < 0) {
+		syslog(LOG_ERR, "Sending getting name command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+        if (rp.status) {
+		syslog(LOG_ERR, "Getting name failed with status 0x%02x", rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + rp.status);
+		goto failed;
+        }
+
+	reply = dbus_message_new_method_return(msg);
+	if (reply == NULL) {
+		syslog(LOG_ERR, "Out of memory while calling dbus_message_new_method_return");
+		goto failed;
+	}
+
+	strncpy(name,pname,sizeof(name)-1);
+	name[248]='\0';
+	pname = name;
+
+	dbus_message_iter_init_append(reply, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &pname);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+
+	return reply;
+}
+
 static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;
--- utils.17112005.orig/hcid/dbus-test	2005-11-17 12:57:42.000000000 -0300
+++ utils.17112005/hcid/dbus-test	2005-11-18 04:35:32.000000000 -0300
@@ -8,9 +8,9 @@
 from signal import *
 
 mgr_cmds = [ "DeviceList", "DefaultDevice" ]
-dev_cmds = [ "Up", "Down", "Inquiry", "CancelInquiry", "PeriodicInquiry",
-             "CancelPeriodic", "RemoteName", "Connections", "Authenticate",
-             "RoleSwitch" ]
+dev_cmds = [ "Up", "Down", "SetProperty", "GetProperty", "Inquiry",
+             "CancelInquiry", "PeriodicInquiry","CancelPeriodic", "RemoteName",
+             "Connections", "Authenticate", "RoleSwitch" ]
 
 class Tester:
     exit_events = []
@@ -179,7 +179,29 @@
             except dbus.DBusException, e:
                 print 'Sending %s failed: %s' % (self.cmd, e)
                 sys.exit(1)
-
+        elif self.cmd == 'SetProperty':
+            if len(self.cmd_args) < 2:
+                print 'Usage: %s -i <dev> SetProperty strPropName arg' % self.name
+                sys.exit(1)
+            try:
+                if self.cmd_args[0].lower() == 'name':
+                    self.dev.SetProperty(dbus.String("name"),
+                                              dbus.String(self.cmd_args[1]))
+                else:
+                    self.dev.SetProperty(dbus.String(self.cmd_args[0]),
+                                              dbus.String(self.cmd_args[1]))
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
+        elif self.cmd == 'GetProperty':
+            if len(self.cmd_args) < 1:
+                print 'Usage: %s -i <dev> GetProperty strPropName' % self.name
+                sys.exit(1)
+            try:
+                print self.dev.GetProperty(self.cmd_args[0])
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
         # Device.Controller methods
         elif self.cmd == 'Inquiry':
             try:



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-18 10:51               ` Eduardo Rocha
@ 2005-11-18 11:26                 ` Johan Hedberg
  2005-11-18 13:00                   ` Eduardo Rocha
  0 siblings, 1 reply; 37+ messages in thread
From: Johan Hedberg @ 2005-11-18 11:26 UTC (permalink / raw)
  To: bluez-devel

On Fri, Nov 18, 2005, Eduardo Rocha wrote:
> Could you give any comments about the hci_send_req timeout (maybe is
> too high)

I'd guess that the command should take max. 100ms, so 2s timeout is
probably unnecessarely big. However, Marcel might have had a good reason
to use the current timeout in hciconfig.

> and the extended inquire parameters that is set cmd_name function in
> hciconfig app (is that needed here?).

If it's not there, then we should at least provide a D-BUS method to set
the extended inquiry parameters (which is probably a good thing as the
user might want to have other informantion there besides the name, e.g.
SDP UUID list).

> About the parameters, I've done an if to detect each property name so
> we can treat  the parameter diferently.

Yeah, you're right, that works also. However, I was thinking of
solutions where dbus-send wouldn't need to know the property name -
property type mapping.

Johan


-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-18 11:26                 ` Johan Hedberg
@ 2005-11-18 13:00                   ` Eduardo Rocha
  2005-11-22 11:51                     ` Marcel Holtmann
  0 siblings, 1 reply; 37+ messages in thread
From: Eduardo Rocha @ 2005-11-18 13:00 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 1817 bytes --]

Hi all,

here is the patch with a better implementation of dbus-test
SetProperty. I've also changed the "pscan" to "connectable" and
"iscan" to "discoverable".

BR,
Eduardo

On 11/18/05, Johan Hedberg <johan.hedberg@nokia.com> wrote:
> On Fri, Nov 18, 2005, Eduardo Rocha wrote:
> > Could you give any comments about the hci_send_req timeout (maybe is
> > too high)
>
> I'd guess that the command should take max. 100ms, so 2s timeout is
> probably unnecessarely big. However, Marcel might have had a good reason
> to use the current timeout in hciconfig.
>
> > and the extended inquire parameters that is set cmd_name function in
> > hciconfig app (is that needed here?).
>
> If it's not there, then we should at least provide a D-BUS method to set
> the extended inquiry parameters (which is probably a good thing as the
> user might want to have other informantion there besides the name, e.g.
> SDP UUID list).
>
> > About the parameters, I've done an if to detect each property name so
> > we can treat  the parameter diferently.
>
> Yeah, you're right, that works also. However, I was thinking of
> solutions where dbus-send wouldn't need to know the property name -
> property type mapping.
>
> Johan
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
> Register for a JBoss Training Course.  Free Certification Exam
> for All Training Attendees Through End of 2005. For more info visit:
> http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: dbus_device_name.patch --]
[-- Type: text/x-patch, Size: 13448 bytes --]

--- utils.17112005.orig/hcid/dbus.h	2005-11-17 12:57:42.000000000 -0300
+++ utils.17112005/hcid/dbus.h	2005-11-18 06:50:55.000000000 -0300
@@ -125,40 +125,23 @@
 
 #define DEV_PROPERTY_AUTH		"auth"
 #define DEV_PROPERTY_ENCRYPT		"encrypt"
-#define DEV_PROPERTY_SECMGR		"secmgr"
-#define DEV_PROPERTY_PISCAN		"piscan"
-#define DEV_PROPERTY_PSCAN		"pscan"
-#define DEV_PROPERTY_ISCAN		"iscan"
-#define DEV_PROPERTY_PTYPE		"ptype"
-#define DEV_PROPERTY_LM			"lm"
-#define DEV_PROPERTY_LP			"lp"
+#define DEV_PROPERTY_PSCAN		"connectable"
+#define DEV_PROPERTY_ISCAN		"discoverable"
 #define DEV_PROPERTY_NAME		"name"
-#define DEV_PROPERTY_CLASS		"class"
-#define DEV_PROPERTY_VOICE		"voice"
-#define DEV_PROPERTY_IAC		"iac"
 #define DEV_PROPERTY_INCMODE		"incmode"
-#define DEV_PROPERTY_INCTYPE		"inctype"
-#define DEV_PROPERTY_INCPARMS		"incparms"
-#define DEV_PROPERTY_PAGEPARMS		"pageparms"
-#define DEV_PROPERTY_PAGETO		"pageto"
-#define DEV_PROPERTY_AFHMODE		"afhmode"
-#define DEV_PROPERTY_ACLMTU		"aclmtu"
-#define DEV_PROPERTY_SCOMTU		"scomtu"
-#define DEV_PROPERTY_PUTKEY		"putkey"
-#define DEV_PROPERTY_DELKEY		"delkey"
 #define DEV_PROPERTY_DEV_INFO		"info"
 
 #define DEV_UP_SIGNATURE			__END_SIG__
 #define DEV_DOWN_SIGNATURE			__END_SIG__
 #define DEV_RESET_SIGNATURE			__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_1		DBUS_TYPE_STRING_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_BOOL		DBUS_TYPE_STRING_AS_STRING \
 						DBUS_TYPE_BOOLEAN_AS_STRING \
 						__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_2		DBUS_TYPE_STRING_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_STR		DBUS_TYPE_STRING_AS_STRING \
 						DBUS_TYPE_STRING_AS_STRING \
 						__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_3		DBUS_TYPE_STRING_AS_STRING \
-						DBUS_TYPE_UINT16_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_BYTE		DBUS_TYPE_STRING_AS_STRING \
+						DBUS_TYPE_BYTE_AS_STRING \
 						__END_SIG__
 
 #define DEV_GET_PROPERTY_SIGNATURE		DBUS_TYPE_STRING_AS_STRING \
--- utils.17112005.orig/hcid/dbus.c	2005-11-17 12:57:42.000000000 -0300
+++ utils.17112005/hcid/dbus.c	2005-11-18 06:50:21.000000000 -0300
@@ -272,59 +272,33 @@
 static DBusMessage* handle_device_down_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data);
 
 static const struct service_data device_services[] = {
 	{ DEV_UP,		handle_device_up_req,		DEV_UP_SIGNATURE		},
 	{ DEV_DOWN,		handle_device_down_req,		DEV_DOWN_SIGNATURE		},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_1	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_2	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_3	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BOOL	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_STR	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BYTE	},
 	{ DEV_GET_PROPERTY,	handle_device_get_propety_req,	DEV_GET_PROPERTY_SIGNATURE	},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data set_property_services[] = {
-	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_SECMGR,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PISCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PTYPE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_LM,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_LP,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_NAME,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_CLASS,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_VOICE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_IAC,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCTYPE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCPARMS,	handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PAGEPARMS,	handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PAGETO,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_AFHMODE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ACLMTU,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_SCOMTU,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PUTKEY,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_DELKEY,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL 	},
+	{ DEV_PROPERTY_NAME,		handle_device_set_propety_req_name,	DEV_SET_PROPERTY_SIGNATURE_STR	 	},
+	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BYTE 	},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data get_property_services[] = {
-	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PTYPE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_LM,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_LP,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_NAME,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_CLASS,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_VOICE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_IAC,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCTYPE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCPARMS,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PAGEPARMS,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PAGETO,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_AFHMODE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_NAME,		handle_device_get_propety_req_name,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
 	{ NULL, NULL, NULL}
 };
 
@@ -1976,7 +1950,7 @@
 	DBusMessage *reply = NULL;
 	const char *signature;
 	char *str_name;
-	uint32_t error = BLUEZ_EDBUS_UNKNOWN_METHOD;
+	uint32_t error = BLUEZ_EDBUS_WRONG_PARAM;
 
 	signature = dbus_message_get_signature(msg);
 
@@ -2009,7 +1983,7 @@
 	DBusMessageIter iter;
 	DBusMessage *reply = NULL;
 	char *str_name;
-	uint32_t error = BLUEZ_EDBUS_UNKNOWN_METHOD;
+	uint32_t error = BLUEZ_EDBUS_WRONG_PARAM;
 
 
 	dbus_message_iter_init(msg, &iter);
@@ -2029,6 +2003,120 @@
 	return reply;
 }
 
+static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	char *str_name;
+	int dd = -1;
+	uint8_t status;
+	change_local_name_cp cp;
+	struct hci_request rq;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &str_name);
+
+	if(strlen(str_name) == 0) {
+		syslog(LOG_ERR, "HCI change name failed - Invalid Name!");
+		reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
+	}
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	strncpy((char *) cp.name, str_name, sizeof(cp.name));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_CHANGE_LOCAL_NAME;
+	rq.cparam = &cp;
+	rq.clen   = CHANGE_LOCAL_NAME_CP_SIZE;
+	rq.rparam = &status;
+	rq.rlen   = sizeof(status);
+
+	if (hci_send_req(dd, &rq, 2000) < 0) {
+		syslog(LOG_ERR, "Sending change name command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (status) {
+		syslog(LOG_ERR, "Setting name failed with status 0x%02x", status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + status);
+		goto failed;
+	}
+
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+
+	return reply;
+}
+
+static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	int dd = -1;
+	read_local_name_rp rp;
+	struct hci_request rq;
+	const char *pname = (char*) rp.name;
+	char name[249];
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+        memset(&rq, 0, sizeof(rq));
+        rq.ogf    = OGF_HOST_CTL;
+        rq.ocf    = OCF_READ_LOCAL_NAME;
+        rq.rparam = &rp;
+        rq.rlen   = READ_LOCAL_NAME_RP_SIZE;
+
+        if (hci_send_req(dd, &rq, 1000) < 0) {
+		syslog(LOG_ERR, "Sending getting name command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+        if (rp.status) {
+		syslog(LOG_ERR, "Getting name failed with status 0x%02x", rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + rp.status);
+		goto failed;
+        }
+
+	reply = dbus_message_new_method_return(msg);
+	if (reply == NULL) {
+		syslog(LOG_ERR, "Out of memory while calling dbus_message_new_method_return");
+		goto failed;
+	}
+
+	strncpy(name,pname,sizeof(name)-1);
+	name[248]='\0';
+	pname = name;
+
+	dbus_message_iter_init_append(reply, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &pname);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+
+	return reply;
+}
+
 static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;
--- utils.17112005.orig/hcid/dbus-test	2005-11-17 12:57:42.000000000 -0300
+++ utils.17112005/hcid/dbus-test	2005-11-18 06:39:06.000000000 -0300
@@ -8,9 +8,11 @@
 from signal import *
 
 mgr_cmds = [ "DeviceList", "DefaultDevice" ]
-dev_cmds = [ "Up", "Down", "Inquiry", "CancelInquiry", "PeriodicInquiry",
-             "CancelPeriodic", "RemoteName", "Connections", "Authenticate",
-             "RoleSwitch" ]
+dev_cmds = [ "Up", "Down", "SetProperty", "GetProperty", "Inquiry",
+             "CancelInquiry", "PeriodicInquiry","CancelPeriodic", "RemoteName",
+             "Connections", "Authenticate", "RoleSwitch" ]
+dev_setprop_bool = [ "auth", "encrypt", "discoverable", "connectable" ]
+dev_setprop_byte = [ "incmode" ]
 
 class Tester:
     exit_events = []
@@ -179,7 +181,29 @@
             except dbus.DBusException, e:
                 print 'Sending %s failed: %s' % (self.cmd, e)
                 sys.exit(1)
-
+        elif self.cmd == 'SetProperty':
+            if len(self.cmd_args) < 2:
+                print 'Usage: %s -i <dev> SetProperty strPropName arg' % self.name
+                sys.exit(1)
+            try:
+                if self.cmd_args[0].lower() in dev_setprop_bool:
+                    self.dev.SetProperty(self.cmd_args[0], dbus.Boolean(self.cmd_args[1]))
+                elif self.cmd_args[0].lower() in dev_setprop_byte:
+                    self.dev.SetProperty(self.cmd_args[0], dbus.Byte(self.cmd_args[1]))
+                else:
+                    self.dev.SetProperty(self.cmd_args[0], self.cmd_args[1])
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
+        elif self.cmd == 'GetProperty':
+            if len(self.cmd_args) < 1:
+                print 'Usage: %s -i <dev> GetProperty strPropName' % self.name
+                sys.exit(1)
+            try:
+                print self.dev.GetProperty(self.cmd_args[0])
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
         # Device.Controller methods
         elif self.cmd == 'Inquiry':
             try:


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-18 13:00                   ` Eduardo Rocha
@ 2005-11-22 11:51                     ` Marcel Holtmann
  2005-11-22 19:52                       ` Eduardo Rocha
  0 siblings, 1 reply; 37+ messages in thread
From: Marcel Holtmann @ 2005-11-22 11:51 UTC (permalink / raw)
  To: bluez-devel

Hi Eduardo,

> here is the patch with a better implementation of dbus-test
> SetProperty. I've also changed the "pscan" to "connectable" and
> "iscan" to "discoverable".

I basically missed this thread, but from a first look at the attached
patch, I can tell that the coding style is wrong. Fix it and re-send it.

Turn the whitespace visualization of editor on ;)

Regards

Marcel




-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-22 11:51                     ` Marcel Holtmann
@ 2005-11-22 19:52                       ` Eduardo Rocha
  2005-11-24  4:17                         ` Marcel Holtmann
  0 siblings, 1 reply; 37+ messages in thread
From: Eduardo Rocha @ 2005-11-22 19:52 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 1410 bytes --]

Hi Marcel,

here is the new patch. I've removed the spaces (I hope so). I've also
included the code for the dbus signal for the local name change event.
One thing that remainded open was the timeout for hci_send_req for
name write and name read ops. In the hciconfig this was 2s and 1s. Is
there a reason for this big number?

BR,
Eduardo

On 11/22/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Eduardo,
>
> > here is the patch with a better implementation of dbus-test
> > SetProperty. I've also changed the "pscan" to "connectable" and
> > "iscan" to "discoverable".
>
> I basically missed this thread, but from a first look at the attached
> patch, I can tell that the coding style is wrong. Fix it and re-send it.
>
> Turn the whitespace visualization of editor on ;)
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
> Register for a JBoss Training Course.  Free Certification Exam
> for All Training Attendees Through End of 2005. For more info visit:
> http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: dbus_device_nameV2.patch --]
[-- Type: text/x-patch, Size: 19523 bytes --]

--- utils.17112005.orig/hcid/hcid.h	2005-11-17 12:57:42.000000000 -0300
+++ utils.22112005/hcid/hcid.h	2005-11-22 15:03:20.000000000 -0300
@@ -134,6 +134,7 @@
 void hcid_dbus_conn_complete(bdaddr_t *local, bdaddr_t *peer);
 void hcid_dbus_disconn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t reason);
 void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status);
+void hcid_dbus_setname_complete(bdaddr_t *local);
 #else
 static inline void hcid_dbus_inquiry_start(bdaddr_t *local) {}
 static inline void hcid_dbus_inquiry_complete(bdaddr_t *local) {}
@@ -143,6 +144,7 @@
 static inline void hcid_dbus_conn_complete(bdaddr_t *local, bdaddr_t *peer) {}
 static inline void hcid_dbus_disconn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t reason) {}
 static inline void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status) {}
+static inline void hcid_dbus_setname_complete(bdaddr_t *local) {}
 #endif
 
 int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name);
--- utils.17112005.orig/hcid/security.c	2005-11-17 12:57:42.000000000 -0300
+++ utils.22112005/hcid/security.c	2005-11-22 15:03:20.000000000 -0300
@@ -491,9 +491,14 @@
 static inline void cmd_complete(int dev, bdaddr_t *sba, void *ptr)
 {
 	evt_cmd_complete *evt = ptr;
-
-	if (evt->opcode == cmd_opcode_pack(OGF_LINK_CTL, OCF_INQUIRY_CANCEL))
+	switch (evt->opcode) {
+	case cmd_opcode_pack(OGF_LINK_CTL, OCF_INQUIRY_CANCEL):
 		hcid_dbus_inquiry_complete(sba);
+		break;
+	case cmd_opcode_pack(OGF_HOST_CTL, OCF_CHANGE_LOCAL_NAME):
+		hcid_dbus_setname_complete(sba);
+		break;
+	};
 }
 
 static inline void remote_name_information(int dev, bdaddr_t *sba, void *ptr)
--- utils.17112005.orig/hcid/dbus.h	2005-11-17 12:57:42.000000000 -0300
+++ utils.22112005/hcid/dbus.h	2005-11-22 15:03:20.000000000 -0300
@@ -99,6 +99,9 @@
 #define BLUEZ_HCI			"Controller"
 #define DEV_HCI_INTERFACE		DEVICE_INTERFACE "." BLUEZ_HCI
 
+/* /org/bluez/Device signals */
+#define BLUEZ_HCI_SET_NAME		"DeviceNameChanged"
+
 /* Control interface signals */
 #define BLUEZ_HCI_INQ_START		"InquiryStart"
 #define BLUEZ_HCI_INQ_COMPLETE		"InquiryComplete"
@@ -125,40 +128,23 @@
 
 #define DEV_PROPERTY_AUTH		"auth"
 #define DEV_PROPERTY_ENCRYPT		"encrypt"
-#define DEV_PROPERTY_SECMGR		"secmgr"
-#define DEV_PROPERTY_PISCAN		"piscan"
-#define DEV_PROPERTY_PSCAN		"pscan"
-#define DEV_PROPERTY_ISCAN		"iscan"
-#define DEV_PROPERTY_PTYPE		"ptype"
-#define DEV_PROPERTY_LM			"lm"
-#define DEV_PROPERTY_LP			"lp"
+#define DEV_PROPERTY_PSCAN		"connectable"
+#define DEV_PROPERTY_ISCAN		"discoverable"
 #define DEV_PROPERTY_NAME		"name"
-#define DEV_PROPERTY_CLASS		"class"
-#define DEV_PROPERTY_VOICE		"voice"
-#define DEV_PROPERTY_IAC		"iac"
 #define DEV_PROPERTY_INCMODE		"incmode"
-#define DEV_PROPERTY_INCTYPE		"inctype"
-#define DEV_PROPERTY_INCPARMS		"incparms"
-#define DEV_PROPERTY_PAGEPARMS		"pageparms"
-#define DEV_PROPERTY_PAGETO		"pageto"
-#define DEV_PROPERTY_AFHMODE		"afhmode"
-#define DEV_PROPERTY_ACLMTU		"aclmtu"
-#define DEV_PROPERTY_SCOMTU		"scomtu"
-#define DEV_PROPERTY_PUTKEY		"putkey"
-#define DEV_PROPERTY_DELKEY		"delkey"
 #define DEV_PROPERTY_DEV_INFO		"info"
 
 #define DEV_UP_SIGNATURE			__END_SIG__
 #define DEV_DOWN_SIGNATURE			__END_SIG__
 #define DEV_RESET_SIGNATURE			__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_1		DBUS_TYPE_STRING_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_BOOL		DBUS_TYPE_STRING_AS_STRING \
 						DBUS_TYPE_BOOLEAN_AS_STRING \
 						__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_2		DBUS_TYPE_STRING_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_STR		DBUS_TYPE_STRING_AS_STRING \
 						DBUS_TYPE_STRING_AS_STRING \
 						__END_SIG__
-#define DEV_SET_PROPERTY_SIGNATURE_3		DBUS_TYPE_STRING_AS_STRING \
-						DBUS_TYPE_UINT16_AS_STRING \
+#define DEV_SET_PROPERTY_SIGNATURE_BYTE		DBUS_TYPE_STRING_AS_STRING \
+						DBUS_TYPE_BYTE_AS_STRING \
 						__END_SIG__
 
 #define DEV_GET_PROPERTY_SIGNATURE		DBUS_TYPE_STRING_AS_STRING \
--- utils.17112005.orig/hcid/dbus.c	2005-11-17 12:57:42.000000000 -0300
+++ utils.22112005/hcid/dbus.c	2005-11-22 16:31:26.000000000 -0300
@@ -272,59 +272,33 @@
 static DBusMessage* handle_device_down_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data);
 
 static const struct service_data device_services[] = {
 	{ DEV_UP,		handle_device_up_req,		DEV_UP_SIGNATURE		},
 	{ DEV_DOWN,		handle_device_down_req,		DEV_DOWN_SIGNATURE		},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_1	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_2	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_3	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BOOL	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_STR	},
+	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BYTE	},
 	{ DEV_GET_PROPERTY,	handle_device_get_propety_req,	DEV_GET_PROPERTY_SIGNATURE	},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data set_property_services[] = {
-	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_SECMGR,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PISCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PTYPE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_LM,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_LP,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_NAME,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_CLASS,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_VOICE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_IAC,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCTYPE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_INCPARMS,	handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PAGEPARMS,	handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PAGETO,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_AFHMODE,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_ACLMTU,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_SCOMTU,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_PUTKEY,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
-	{ DEV_PROPERTY_DELKEY,		handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE_1 	},
+	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
+	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
+	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
+	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
+	{ DEV_PROPERTY_NAME,		handle_device_set_propety_req_name,	DEV_SET_PROPERTY_SIGNATURE_STR		},
+	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BYTE		},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data get_property_services[] = {
-	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PTYPE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_LM,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_LP,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_NAME,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_CLASS,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_VOICE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_IAC,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCTYPE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_INCPARMS,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PAGEPARMS,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_PAGETO,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_AFHMODE,		handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_NAME,		handle_device_get_propety_req_name,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
 	{ NULL, NULL, NULL}
 };
 
@@ -435,8 +409,6 @@
 	gboolean ret = FALSE;
 	struct hci_dbus_data *data = NULL;
 
-	syslog(LOG_INFO, "Registering DBUS Path: %s", path);
-
 	data = malloc(sizeof(struct hci_dbus_data));
 	if (data == NULL) {
 		syslog(LOG_ERR, "Failed to alloc memory to DBUS path register data (%s)", path);
@@ -471,9 +443,7 @@
 {
 	void *data;
 
-	syslog(LOG_INFO, "Unregistering DBUS Path: %s", path);
-
-	if (dbus_connection_get_object_path_data(connection, path, &data) && data) 
+	if (dbus_connection_get_object_path_data(connection, path, &data) && data)
 		free(data);
 
 	if (!dbus_connection_unregister_object_path (connection, path)) {
@@ -1296,9 +1266,6 @@
 	method = dbus_message_get_member(msg);
 	signature = dbus_message_get_signature(msg);
 
-	syslog(LOG_INFO, "%s - path:%s, path_id:0x%04x dev_id:0x%04x", __PRETTY_FUNCTION__,
-			path, dbus_data->path_id, dbus_data->dev_id);
-
 	if (dbus_data->path_id == DEVICE_ROOT_ID) {
 		/* Device is down(path unregistered) or the path is wrong */
 		ret = DBUS_HANDLER_RESULT_HANDLED;
@@ -1369,8 +1336,6 @@
 	method = dbus_message_get_member(msg);
 	signature = dbus_message_get_signature(msg);
 
-	syslog (LOG_INFO, "%s - path:%s", __PRETTY_FUNCTION__, path);
-
 	if (strcmp(iface, MANAGER_INTERFACE) != 0)
 		return ret;
 
@@ -1976,7 +1941,7 @@
 	DBusMessage *reply = NULL;
 	const char *signature;
 	char *str_name;
-	uint32_t error = BLUEZ_EDBUS_UNKNOWN_METHOD;
+	uint32_t error = BLUEZ_EDBUS_WRONG_PARAM;
 
 	signature = dbus_message_get_signature(msg);
 
@@ -2009,7 +1974,7 @@
 	DBusMessageIter iter;
 	DBusMessage *reply = NULL;
 	char *str_name;
-	uint32_t error = BLUEZ_EDBUS_UNKNOWN_METHOD;
+	uint32_t error = BLUEZ_EDBUS_WRONG_PARAM;
 
 
 	dbus_message_iter_init(msg, &iter);
@@ -2029,6 +1994,195 @@
 	return reply;
 }
 
+static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	char *str_name;
+	int dd = -1;
+	uint8_t status;
+	change_local_name_cp cp;
+	struct hci_request rq;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &str_name);
+
+	if(strlen(str_name) == 0) {
+		syslog(LOG_ERR, "HCI change name failed - Invalid Name!");
+		reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
+		goto failed;
+	}
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	strncpy((char *) cp.name, str_name, sizeof(cp.name));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_CHANGE_LOCAL_NAME;
+	rq.cparam = &cp;
+	rq.clen   = CHANGE_LOCAL_NAME_CP_SIZE;
+	rq.rparam = &status;
+	rq.rlen   = sizeof(status);
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Sending change name command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (status) {
+		syslog(LOG_ERR, "Setting name failed with status 0x%02x", status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + status);
+		goto failed;
+	}
+
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+
+	return reply;
+}
+
+void hcid_dbus_setname_complete(bdaddr_t *local)
+{
+	DBusMessage *message = NULL;
+	char path[MAX_PATH_LENGTH];
+	char *local_addr;
+	bdaddr_t tmp;
+	int id;
+	int dd = -1;
+	read_local_name_rp rp;
+	struct hci_request rq;
+	const char *pname = (char*) rp.name;
+	char name[249];
+
+	baswap(&tmp, local); local_addr = batostr(&tmp);
+
+	id = hci_devid(local_addr);
+	if (id < 0) {
+		syslog(LOG_ERR, "No matching device id for %s", local_addr);
+		goto failed;
+	}
+
+	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, id);
+
+	message = dbus_message_new_signal(path, DEVICE_INTERFACE,
+						BLUEZ_HCI_SET_NAME);
+	if (message == NULL) {
+		syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
+		goto failed;
+	}
+
+	dd = hci_open_dev(id);
+	memset(&rq, 0, sizeof(rq));
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", id);
+	} else {
+		rq.ogf    = OGF_HOST_CTL;
+		rq.ocf    = OCF_READ_LOCAL_NAME;
+		rq.rparam = &rp;
+		rq.rlen   = READ_LOCAL_NAME_RP_SIZE;
+		if (hci_send_req(dd, &rq, 100) < 0) {
+			syslog(LOG_ERR,
+				"Sending getting name command failed: %s (%d)",
+				strerror(errno), errno);
+			rp.name[0] = '\0';
+		}
+		if (rp.status) {
+			syslog(LOG_ERR,
+				"Getting name failed with status 0x%02x",
+				rp.status);
+			rp.name[0] = '\0';
+		}
+	}
+
+	strncpy(name,pname,sizeof(name)-1);
+	name[248]='\0';
+	pname = name;
+
+	dbus_message_append_args(message,
+				DBUS_TYPE_STRING, &pname,
+				DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send(connection, message, NULL) == FALSE) {
+		syslog(LOG_ERR, "Can't send D-BUS NameChanged signal");
+		goto failed;
+	}
+	dbus_connection_flush(connection);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+	dbus_message_unref(message);
+	bt_free(local_addr);
+}
+
+static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessage *reply = NULL;
+	int dd = -1;
+	read_local_name_rp rp;
+	struct hci_request rq;
+	const char *pname = (char*) rp.name;
+	char name[249];
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_READ_LOCAL_NAME;
+	rq.rparam = &rp;
+	rq.rlen   = READ_LOCAL_NAME_RP_SIZE;
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Sending getting name command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (rp.status) {
+		syslog(LOG_ERR, "Getting name failed with status 0x%02x", rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + rp.status);
+		goto failed;
+        }
+
+	reply = dbus_message_new_method_return(msg);
+	if (reply == NULL) {
+		syslog(LOG_ERR, "Out of memory while calling dbus_message_new_method_return");
+		goto failed;
+	}
+
+	strncpy(name,pname,sizeof(name)-1);
+	name[248]='\0';
+	pname = name;
+
+	dbus_message_append_args(reply,
+				DBUS_TYPE_STRING, &pname,
+				DBUS_TYPE_INVALID);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+
+	return reply;
+}
+
 static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;
--- utils.17112005.orig/hcid/dbus-test	2005-11-17 12:57:42.000000000 -0300
+++ utils.22112005/hcid/dbus-test	2005-11-22 15:21:53.000000000 -0300
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 
 import dbus
+import dbus.decorators
 import dbus.glib
 import gobject
 import sys
@@ -8,9 +9,11 @@
 from signal import *
 
 mgr_cmds = [ "DeviceList", "DefaultDevice" ]
-dev_cmds = [ "Up", "Down", "Inquiry", "CancelInquiry", "PeriodicInquiry",
-             "CancelPeriodic", "RemoteName", "Connections", "Authenticate",
-             "RoleSwitch" ]
+dev_cmds = [ "Up", "Down", "SetProperty", "GetProperty", "Inquiry",
+             "CancelInquiry", "PeriodicInquiry","CancelPeriodic", "RemoteName",
+             "Connections", "Authenticate", "RoleSwitch" ]
+dev_setprop_bool = [ "auth", "encrypt", "discoverable", "connectable" ]
+dev_setprop_byte = [ "incmode" ]
 
 class Tester:
     exit_events = []
@@ -78,6 +81,9 @@
 
                 self.dev.connect_to_signal('Up', self.dev_up)
                 self.dev.connect_to_signal('Down', self.dev_down)
+                self.bus.add_signal_receiver(self.dev_name_changed, 'DeviceNameChanged',
+                                             'org.bluez.Device', 'org.bluez',
+                                             '/org/bluez/Device/hci0')
 
                 obj = self.bus.get_object('org.bluez', '%s/Controller' % self.dev_path)
                 self.ctl = dbus.Interface(obj, 'org.bluez.Device.Controller')
@@ -150,6 +156,12 @@
     def dev_down(self):
         print 'Down'
 
+    @dbus.decorators.explicitly_pass_message
+    def dev_name_changed(*args, **keywords):
+        name = args[1]
+        dbus_message = keywords["dbus_message"]
+        print 'Device %s name changed: %s' % (dbus_message.get_path(), name)
+
     def signal_cb(self, sig, frame):
         print 'Caught signal, exiting'
         if self.at_interrupt:
@@ -179,7 +191,29 @@
             except dbus.DBusException, e:
                 print 'Sending %s failed: %s' % (self.cmd, e)
                 sys.exit(1)
-
+        elif self.cmd == 'SetProperty':
+            if len(self.cmd_args) < 2:
+                print 'Usage: %s -i <dev> SetProperty strPropName arg' % self.name
+                sys.exit(1)
+            try:
+                if self.cmd_args[0].lower() in dev_setprop_bool:
+                    self.dev.SetProperty(self.cmd_args[0], dbus.Boolean(self.cmd_args[1]))
+                elif self.cmd_args[0].lower() in dev_setprop_byte:
+                    self.dev.SetProperty(self.cmd_args[0], dbus.Byte(self.cmd_args[1]))
+                else:
+                    self.dev.SetProperty(self.cmd_args[0], self.cmd_args[1])
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
+        elif self.cmd == 'GetProperty':
+            if len(self.cmd_args) < 1:
+                print 'Usage: %s -i <dev> GetProperty strPropName' % self.name
+                sys.exit(1)
+            try:
+                print self.dev.GetProperty(self.cmd_args[0])
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
         # Device.Controller methods
         elif self.cmd == 'Inquiry':
             try:

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-22 19:52                       ` Eduardo Rocha
@ 2005-11-24  4:17                         ` Marcel Holtmann
  2005-11-24 18:50                           ` Eduardo Rocha
  0 siblings, 1 reply; 37+ messages in thread
From: Marcel Holtmann @ 2005-11-24  4:17 UTC (permalink / raw)
  To: bluez-devel

Hi Eduardo,

> here is the new patch. I've removed the spaces (I hope so). I've also
> included the code for the dbus signal for the local name change event.
> One thing that remainded open was the timeout for hci_send_req for
> name write and name read ops. In the hciconfig this was 2s and 1s. Is
> there a reason for this big number?

you missed one whitespace/tab clash, but I fixed it. Opening a patch
inside an editor with whitespace visualization helps a lot.

The patch has been applied to the CVS and we should talk about some
serious security setting for the D-Bus interface. Question is what a
session user should be able to change?

The timeout is not really crucial for most local configuration settings
and I think it was a bad idea to have it in the API anyhow. However the
change local name command is tricky. Some older CSR chips for example
are storing the name in the PS keys, which results writing it to flash
or EEPROM. This simply can take time.

Regards

Marcel




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-24  4:17                         ` Marcel Holtmann
@ 2005-11-24 18:50                           ` Eduardo Rocha
  2005-11-24 22:54                             ` Marcel Holtmann
  0 siblings, 1 reply; 37+ messages in thread
From: Eduardo Rocha @ 2005-11-24 18:50 UTC (permalink / raw)
  To: bluez-devel

Hi Marcel,

maybe we should create a bluetooth group and only allow users of that
group to make write operations. I'll also check eht dbus auth to see
if that can help. Do you have in mind any operation->"security level"
map?

BR,
Eduardo.


On 11/24/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Eduardo,
>
> > here is the new patch. I've removed the spaces (I hope so). I've also
> > included the code for the dbus signal for the local name change event.
> > One thing that remainded open was the timeout for hci_send_req for
> > name write and name read ops. In the hciconfig this was 2s and 1s. Is
> > there a reason for this big number?
>
> you missed one whitespace/tab clash, but I fixed it. Opening a patch
> inside an editor with whitespace visualization helps a lot.
>
> The patch has been applied to the CVS and we should talk about some
> serious security setting for the D-Bus interface. Question is what a
> session user should be able to change?
>
> The timeout is not really crucial for most local configuration settings
> and I think it was a bad idea to have it in the API anyhow. However the
> change local name command is tricky. Some older CSR chips for example
> are storing the name in the PS keys, which results writing it to flash
> or EEPROM. This simply can take time.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log fi=
les
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-24 18:50                           ` Eduardo Rocha
@ 2005-11-24 22:54                             ` Marcel Holtmann
  2005-11-25 13:47                               ` Claudio Takahasi
  2005-11-25 16:51                               ` Johan Hedberg
  0 siblings, 2 replies; 37+ messages in thread
From: Marcel Holtmann @ 2005-11-24 22:54 UTC (permalink / raw)
  To: bluez-devel

Hi Eduardo,

> maybe we should create a bluetooth group and only allow users of that
> group to make write operations. I'll also check eht dbus auth to see
> if that can help. Do you have in mind any operation->"security level"
> map?

come up with some proposals. I have real clue, but we should have some
special rights for the current session user.

Regards

Marcel




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-24 22:54                             ` Marcel Holtmann
@ 2005-11-25 13:47                               ` Claudio Takahasi
  2005-11-25 14:32                                 ` Eduardo Rocha
  2005-11-25 18:08                                 ` Marcel Holtmann
  2005-11-25 16:51                               ` Johan Hedberg
  1 sibling, 2 replies; 37+ messages in thread
From: Claudio Takahasi @ 2005-11-25 13:47 UTC (permalink / raw)
  To: bluez-devel

Hi,

IMHO, it's enough two level of security. My suggestion is create a
bluezadmin group to
allow the device setup operations(write operations). Read operations
can be allowed to
bluezusers and bluezadmin. Another point is only the root can own the
service, I mean,
Only the root can run the hcid daemon.

/org/bluez/Manager
    - get default device
    - list adapters
/org/bluez/Device/hciX
    - UP  (*)
    - Down (*)
    - SetProperty (*)
    - GetProperty
/org/bluez/Device/hciX/Controller
/org/bluez/Device/hciX/Network
/org/bluez/Device/hciX/Serial

Configuration file suggestion:
<!DOCTYPE busconfig PUBLIC
 "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>

  <!-- This configuration file specifies the required security policies
       for the BlueZ to work. -->

  <!-- Only root can own the BlueZ service -->
  <policy user=3D"root">
    <allow own=3D"org.bluez"/>
  </policy>

  <policy group=3D"bluezadmin">
    <allow receive_interface=3D"org.bluez.Manager"/>
    <allow receive_interface=3D"org.bluez.Device"/>
    <allow send_interface=3D"org.bluez.Manager"/>
    <allow send_interface=3D"org.bluez.Device"/>
  </policy>

  <policy group=3D"bluezusers">
    <allow receive_interface=3D"org.bluez.Manager"/>
    <allow receive_interface=3D"org.bluez.Device"/>
    <allow send_interface=3D"org.bluez.Manager"/>
    <allow send_interface=3D"org.bluez.Device"/>
    <deny send_interface=3D"org.bluez.Device" send_member=3D"Up"/>
    <deny send_interface=3D"org.bluez.Device" send_member=3D"Down"/>
    <deny send_interface=3D"org.bluez.Device" send_member=3D"SetProperty"/>
  </policy>

  <!-- Deny anyone to invoke methods on the Manager and Device interfaces -=
->
  <policy context=3D"default">
    <deny own=3D"org.bluez"/>
    <deny send_interface=3D"org.bluez.Manager"/>
    <deny send_interface=3D"org.bluez.Device"/>
    <deny receive_interface=3D"org.bluez.Manager"/>
    <deny receive_interface=3D"org.bluez.Device"/>
  </policy>

</busconfig>

Regards,
Claudio

On 11/24/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Eduardo,
>
> > maybe we should create a bluetooth group and only allow users of that
> > group to make write operations. I'll also check eht dbus auth to see
> > if that can help. Do you have in mind any operation->"security level"
> > map?
>
> come up with some proposals. I have real clue, but we should have some
> special rights for the current session user.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log fi=
les
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-25 13:47                               ` Claudio Takahasi
@ 2005-11-25 14:32                                 ` Eduardo Rocha
  2005-11-25 18:08                                 ` Marcel Holtmann
  1 sibling, 0 replies; 37+ messages in thread
From: Eduardo Rocha @ 2005-11-25 14:32 UTC (permalink / raw)
  To: bluez-devel

Hi Claudio,

in the last email you mean 3 levels of security (bluezadmin,
bluezusers, and default). I think is a good idea for the client to
have local user id and not root (not use setuid for root). Making one
or more groups I think is more flexibe. With the current operations, I
only don't see the poit to have a Manager path. I think this
operations can be mapped by Device path.

BR,
Eduardo.


On 11/25/05, Claudio Takahasi <cktakahasi@gmail.com> wrote:
> Hi,
>
> IMHO, it's enough two level of security. My suggestion is create a
> bluezadmin group to
> allow the device setup operations(write operations). Read operations
> can be allowed to
> bluezusers and bluezadmin. Another point is only the root can own the
> service, I mean,
> Only the root can run the hcid daemon.
>
> /org/bluez/Manager
>     - get default device
>     - list adapters
> /org/bluez/Device/hciX
>     - UP  (*)
>     - Down (*)
>     - SetProperty (*)
>     - GetProperty
> /org/bluez/Device/hciX/Controller
> /org/bluez/Device/hciX/Network
> /org/bluez/Device/hciX/Serial
>
> Configuration file suggestion:
> <!DOCTYPE busconfig PUBLIC
>  "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
>  "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
> <busconfig>
>
>   <!-- This configuration file specifies the required security policies
>        for the BlueZ to work. -->
>
>   <!-- Only root can own the BlueZ service -->
>   <policy user=3D"root">
>     <allow own=3D"org.bluez"/>
>   </policy>
>
>   <policy group=3D"bluezadmin">
>     <allow receive_interface=3D"org.bluez.Manager"/>
>     <allow receive_interface=3D"org.bluez.Device"/>
>     <allow send_interface=3D"org.bluez.Manager"/>
>     <allow send_interface=3D"org.bluez.Device"/>
>   </policy>
>
>   <policy group=3D"bluezusers">
>     <allow receive_interface=3D"org.bluez.Manager"/>
>     <allow receive_interface=3D"org.bluez.Device"/>
>     <allow send_interface=3D"org.bluez.Manager"/>
>     <allow send_interface=3D"org.bluez.Device"/>
>     <deny send_interface=3D"org.bluez.Device" send_member=3D"Up"/>
>     <deny send_interface=3D"org.bluez.Device" send_member=3D"Down"/>
>     <deny send_interface=3D"org.bluez.Device" send_member=3D"SetProperty"=
/>
>   </policy>
>
>   <!-- Deny anyone to invoke methods on the Manager and Device interfaces=
 -->
>   <policy context=3D"default">
>     <deny own=3D"org.bluez"/>
>     <deny send_interface=3D"org.bluez.Manager"/>
>     <deny send_interface=3D"org.bluez.Device"/>
>     <deny receive_interface=3D"org.bluez.Manager"/>
>     <deny receive_interface=3D"org.bluez.Device"/>
>   </policy>
>
> </busconfig>
>
> Regards,
> Claudio
>
> On 11/24/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> > Hi Eduardo,
> >
> > > maybe we should create a bluetooth group and only allow users of that
> > > group to make write operations. I'll also check eht dbus auth to see
> > > if that can help. Do you have in mind any operation->"security level"
> > > map?
> >
> > come up with some proposals. I have real clue, but we should have some
> > special rights for the current session user.
> >
> > Regards
> >
> > Marcel
> >
> >
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: Splunk Inc. Do you grep through log =
files
> > for problems?  Stop!  Download the new AJAX search engine that makes
> > searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> > http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick
> > _______________________________________________
> > Bluez-devel mailing list
> > Bluez-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/bluez-devel
> >
>
>
> --
> ---------------------------------------------------------
> Claudio Takahasi
> Instituto Nokia de Tecnologia - INdT
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log fi=
les
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_idv37&alloc_id=16865&opclick
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-24 22:54                             ` Marcel Holtmann
  2005-11-25 13:47                               ` Claudio Takahasi
@ 2005-11-25 16:51                               ` Johan Hedberg
  2005-11-25 18:12                                 ` Marcel Holtmann
  1 sibling, 1 reply; 37+ messages in thread
From: Johan Hedberg @ 2005-11-25 16:51 UTC (permalink / raw)
  To: bluez-devel

Hi Marcel,

On Thu, Nov 24, 2005, Marcel Holtmann wrote:
> come up with some proposals. I have real clue, but we should have some
> special rights for the current session user.

What do you mean by "current session user"?

I'd propose essentially a two level system where you have a level which
is allowed to do everything, and another one which only allows "normal
user" operations. root and users belonging to the "bluetooth" (or
"btadmin" or whatever) group would be on the "everyting allowed" level,
while everyone else would be on the other.

Of course this doesn't mean that distributions couldn't replace the
policy with a more flexible (and complex) one to suit their needs. I'm
just proposing this to be the default that comes with bluez-utils.

Also, I don't think it makes sense for the default D-BUS policy (which
comes with upstream with bluez-utils) to deny a normal user things that
can anyway be done using libbluetooth directly (e.g. using the command
line tools).

Johan


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-25 13:47                               ` Claudio Takahasi
  2005-11-25 14:32                                 ` Eduardo Rocha
@ 2005-11-25 18:08                                 ` Marcel Holtmann
  2005-11-25 18:34                                   ` Eduardo Rocha
  1 sibling, 1 reply; 37+ messages in thread
From: Marcel Holtmann @ 2005-11-25 18:08 UTC (permalink / raw)
  To: bluez-devel

Hi Claudio,

> IMHO, it's enough two level of security. My suggestion is create a
> bluezadmin group to
> allow the device setup operations(write operations). Read operations
> can be allowed to
> bluezusers and bluezadmin. Another point is only the root can own the
> service, I mean,
> Only the root can run the hcid daemon.

I don't see any need of having a bluezusers group. There are tasks that
everybody can execute and I don't see any problem with it.

For what do we need a special bluezadmin group? I think that the user
should enter the root password for configuration or it should be console
or session user.

And yes, hcid will always need to be run as root.

Regards

Marcel




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-25 16:51                               ` Johan Hedberg
@ 2005-11-25 18:12                                 ` Marcel Holtmann
  0 siblings, 0 replies; 37+ messages in thread
From: Marcel Holtmann @ 2005-11-25 18:12 UTC (permalink / raw)
  To: bluez-devel

Hi Johan,

> > come up with some proposals. I have real clue, but we should have some
> > special rights for the current session user.
> 
> What do you mean by "current session user"?

the currently logged in user can modify settings etc. I think the D-Bus
speaks about at_console or something like that. The idea behind this is
that a local user can use the Bluetooth device, but a remote user can't.
For me that is enough for a default security.

> I'd propose essentially a two level system where you have a level which
> is allowed to do everything, and another one which only allows "normal
> user" operations. root and users belonging to the "bluetooth" (or
> "btadmin" or whatever) group would be on the "everyting allowed" level,
> while everyone else would be on the other.
> 
> Of course this doesn't mean that distributions couldn't replace the
> policy with a more flexible (and complex) one to suit their needs. I'm
> just proposing this to be the default that comes with bluez-utils.
> 
> Also, I don't think it makes sense for the default D-BUS policy (which
> comes with upstream with bluez-utils) to deny a normal user things that
> can anyway be done using libbluetooth directly (e.g. using the command
> line tools).

This will be done by the security settings inside the kernel. The
general rule was to allow all reads, but no writes to normal users.

Regards

Marcel




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-25 18:08                                 ` Marcel Holtmann
@ 2005-11-25 18:34                                   ` Eduardo Rocha
  2005-11-25 18:41                                     ` Marcel Holtmann
  0 siblings, 1 reply; 37+ messages in thread
From: Eduardo Rocha @ 2005-11-25 18:34 UTC (permalink / raw)
  To: bluez-devel

Hi Marcel,

On 11/25/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> For what do we need a special bluezadmin group? I think that the user
> should enter the root password for configuration or it should be console
> or session user.

a group is needed for better dbus client security. If only root is
allowed, the client will have to be run as root (by sudo or suid). In
this case the machine security can be compromised by a buffer overflow
in the client. If we use a group, users that can change bluetooth
props should be added to that group, and the client application can be
run as a normal user. So if the dbus client app has a flaw, it will
not compromise the whole machine.
Of course the dbus server need to be executed as root.

BR,
Eduardo.


> Hi Claudio,
>
> > IMHO, it's enough two level of security. My suggestion is create a
> > bluezadmin group to
> > allow the device setup operations(write operations). Read operations
> > can be allowed to
> > bluezusers and bluezadmin. Another point is only the root can own the
> > service, I mean,
> > Only the root can run the hcid daemon.
>
> I don't see any need of having a bluezusers group. There are tasks that
> everybody can execute and I don't see any problem with it.
>
> For what do we need a special bluezadmin group? I think that the user
> should enter the root password for configuration or it should be console
> or session user.
>
> And yes, hcid will always need to be run as root.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log fi=
les
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-25 18:34                                   ` Eduardo Rocha
@ 2005-11-25 18:41                                     ` Marcel Holtmann
  2005-11-25 19:52                                       ` Claudio Takahasi
  0 siblings, 1 reply; 37+ messages in thread
From: Marcel Holtmann @ 2005-11-25 18:41 UTC (permalink / raw)
  To: bluez-devel

Hi Eduardo,

> > For what do we need a special bluezadmin group? I think that the user
> > should enter the root password for configuration or it should be console
> > or session user.
> 
> a group is needed for better dbus client security. If only root is
> allowed, the client will have to be run as root (by sudo or suid). In
> this case the machine security can be compromised by a buffer overflow
> in the client. If we use a group, users that can change bluetooth
> props should be added to that group, and the client application can be
> run as a normal user. So if the dbus client app has a flaw, it will
> not compromise the whole machine.

I would prefer not to add a new group and use the at_console identify of
D-Bus (if possible) instead. We need to identify the session user.

Regards

Marcel




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-25 18:41                                     ` Marcel Holtmann
@ 2005-11-25 19:52                                       ` Claudio Takahasi
  2005-11-25 20:06                                         ` Marcel Holtmann
  0 siblings, 1 reply; 37+ messages in thread
From: Claudio Takahasi @ 2005-11-25 19:52 UTC (permalink / raw)
  To: bluez-devel

Hi,

I think we are confusing some D-Bus concepts.

Currently, hcid is connected to the "system" bus, because the
Bluetooth adapter is a shared resource and it can be used by any
logged-in user or remote users. As long as I known the "system bus"
should be used for notification from the system to user sessions(it's
accessible to all applications on the system). The "session bus"
should be used to implement desktop environments communication. The
address of the per-session bus daemon is automatically discovered by
reading an environment variable. A login session message bus is
started each time a user logs in.

If we choose use the session bus, probably it will required huge code
modification in order to support multiple bus session connection or
start a new BlueZ D-Bus daemon for each user session. In my opinion,
this approach is not feasible.

If you want provide BlueZ D-Bus services only for the logged-in user,
we can try analise the modifications required to control the D-Bus
connections and its drawbacks.


Regards,
Claudio.



On 11/25/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Eduardo,
>
> > > For what do we need a special bluezadmin group? I think that the user
> > > should enter the root password for configuration or it should be cons=
ole
> > > or session user.
> >
> > a group is needed for better dbus client security. If only root is
> > allowed, the client will have to be run as root (by sudo or suid). In
> > this case the machine security can be compromised by a buffer overflow
> > in the client. If we use a group, users that can change bluetooth
> > props should be added to that group, and the client application can be
> > run as a normal user. So if the dbus client app has a flaw, it will
> > not compromise the whole machine.
>
> I would prefer not to add a new group and use the at_console identify of
> D-Bus (if possible) instead. We need to identify the session user.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log fi=
les
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-25 19:52                                       ` Claudio Takahasi
@ 2005-11-25 20:06                                         ` Marcel Holtmann
  2005-12-01 16:55                                           ` Eduardo Rocha
  0 siblings, 1 reply; 37+ messages in thread
From: Marcel Holtmann @ 2005-11-25 20:06 UTC (permalink / raw)
  To: bluez-devel

Hi Claudio,

> I think we are confusing some D-Bus concepts.
> 
> Currently, hcid is connected to the "system" bus, because the
> Bluetooth adapter is a shared resource and it can be used by any
> logged-in user or remote users. As long as I known the "system bus"
> should be used for notification from the system to user sessions(it's
> accessible to all applications on the system). The "session bus"
> should be used to implement desktop environments communication. The
> address of the per-session bus daemon is automatically discovered by
> reading an environment variable. A login session message bus is
> started each time a user logs in.

this is my understanding, too.

> If we choose use the session bus, probably it will required huge code
> modification in order to support multiple bus session connection or
> start a new BlueZ D-Bus daemon for each user session. In my opinion,
> this approach is not feasible.

This will simply not work, because there can be only one daemon at a
time and it must run all the time.

> If you want provide BlueZ D-Bus services only for the logged-in user,
> we can try analise the modifications required to control the D-Bus
> connections and its drawbacks.

The D-Bus services are available in general, but I wanna restrict the
methods that are actually modifying settings to the root user and/or the
currently logged in user. The hal.conf uses "<policy at_console="true">"
to provide this (if I am not mistaken).

Remember that we are talking about the default configuration. We don't
need to provide the best security model, but at least a decent one. For
me this means that the root user and the currently logged in user have
full control over the device. All other users are restricted.

Regards

Marcel




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-11-25 20:06                                         ` Marcel Holtmann
@ 2005-12-01 16:55                                           ` Eduardo Rocha
  2005-12-01 21:05                                             ` Marcel Holtmann
  0 siblings, 1 reply; 37+ messages in thread
From: Eduardo Rocha @ 2005-12-01 16:55 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 3091 bytes --]

Hi Marcel,

here is a patch for scan SetProperty of /org/bluez/Device/hciX and to
correct some function names.
Johan said on an early email that would be nice to have each changed
property to send a "PropertyChanged" signal with "Property name" and
"property specific info" params. But for "discoverable" and
"connectable" properties, how can we know what changed as both of them
trigger a command_complete event with HCI_write_scan_enable OCF?  Or
should we trigger a unique signal for pscan and iscan, sending the new
scan status?

BR,
Eduardo.


On 11/25/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Claudio,
>
> > I think we are confusing some D-Bus concepts.
> >
> > Currently, hcid is connected to the "system" bus, because the
> > Bluetooth adapter is a shared resource and it can be used by any
> > logged-in user or remote users. As long as I known the "system bus"
> > should be used for notification from the system to user sessions(it's
> > accessible to all applications on the system). The "session bus"
> > should be used to implement desktop environments communication. The
> > address of the per-session bus daemon is automatically discovered by
> > reading an environment variable. A login session message bus is
> > started each time a user logs in.
>
> this is my understanding, too.
>
> > If we choose use the session bus, probably it will required huge code
> > modification in order to support multiple bus session connection or
> > start a new BlueZ D-Bus daemon for each user session. In my opinion,
> > this approach is not feasible.
>
> This will simply not work, because there can be only one daemon at a
> time and it must run all the time.
>
> > If you want provide BlueZ D-Bus services only for the logged-in user,
> > we can try analise the modifications required to control the D-Bus
> > connections and its drawbacks.
>
> The D-Bus services are available in general, but I wanna restrict the
> methods that are actually modifying settings to the root user and/or the
> currently logged in user. The hal.conf uses "<policy at_console="true">"
> to provide this (if I am not mistaken).
>
> Remember that we are talking about the default configuration. We don't
> need to provide the best security model, but at least a decent one. For
> me this means that the root user and the currently logged in user have
> full control over the device. All other users are restricted.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: dbus_device_scan.patch --]
[-- Type: text/x-patch, Size: 8569 bytes --]

--- utils.01122005.orig/hcid/dbus.h	2005-11-24 01:10:46.000000000 -0300
+++ utils.01122005/hcid/dbus.h	2005-12-01 13:14:01.000000000 -0300
@@ -227,6 +227,7 @@
 #define BLUEZ_EDBUS_NO_MEM   		(0x05 + BLUEZ_EDBUS_OFFSET)
 #define BLUEZ_EDBUS_CONN_NOT_FOUND	(0x06 + BLUEZ_EDBUS_OFFSET)
 #define BLUEZ_EDBUS_UNKNOWN_PATH	(0x07 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_NOT_IMPLEMENTED	(0x08 + BLUEZ_EDBUS_OFFSET)
 
 /* D-Bus error code, class BLUEZ_ESYSTEM_OFFSET */
 #define BLUEZ_ESYSTEM_ENODEV		(ENODEV + BLUEZ_ESYSTEM_OFFSET)
--- utils.01122005.orig/hcid/dbus.c	2005-11-24 01:10:46.000000000 -0300
+++ utils.01122005/hcid/dbus.c	2005-12-01 13:22:23.000000000 -0300
@@ -132,6 +132,7 @@
 	{ BLUEZ_EDBUS_NO_MEM,		"No memory"			},
 	{ BLUEZ_EDBUS_CONN_NOT_FOUND,	"Connection not found"		},
 	{ BLUEZ_EDBUS_UNKNOWN_PATH,	"Unknown D-BUS path"		},
+	{ BLUEZ_EDBUS_NOT_IMPLEMENTED,	"Method not implemented"	},
 	{ 0, NULL }
 };
 
@@ -270,34 +271,36 @@
  */
 static DBusMessage* handle_device_up_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_down_req(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_get_property_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_get_property_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req_pscan(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req_iscan(DBusMessage *msg, void *data);
 
 static const struct service_data device_services[] = {
 	{ DEV_UP,		handle_device_up_req,		DEV_UP_SIGNATURE		},
 	{ DEV_DOWN,		handle_device_down_req,		DEV_DOWN_SIGNATURE		},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BOOL	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_STR	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BYTE	},
-	{ DEV_GET_PROPERTY,	handle_device_get_propety_req,	DEV_GET_PROPERTY_SIGNATURE	},
+	{ DEV_SET_PROPERTY,	handle_device_set_property_req,	DEV_SET_PROPERTY_SIGNATURE_BOOL	},
+	{ DEV_SET_PROPERTY,	handle_device_set_property_req,	DEV_SET_PROPERTY_SIGNATURE_STR	},
+	{ DEV_SET_PROPERTY,	handle_device_set_property_req,	DEV_SET_PROPERTY_SIGNATURE_BYTE	},
+	{ DEV_GET_PROPERTY,	handle_device_get_property_req,	DEV_GET_PROPERTY_SIGNATURE	},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data set_property_services[] = {
 	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
 	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
-	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
-	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
-	{ DEV_PROPERTY_NAME,		handle_device_set_propety_req_name,	DEV_SET_PROPERTY_SIGNATURE_STR		},
+	{ DEV_PROPERTY_PSCAN,		handle_device_set_property_req_pscan,	DEV_SET_PROPERTY_SIGNATURE_BOOL		},
+	{ DEV_PROPERTY_ISCAN,		handle_device_set_property_req_iscan,	DEV_SET_PROPERTY_SIGNATURE_BOOL		},
+	{ DEV_PROPERTY_NAME,		handle_device_set_property_req_name,	DEV_SET_PROPERTY_SIGNATURE_STR		},
 	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BYTE		},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data get_property_services[] = {
 	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_NAME,		handle_device_get_propety_req_name,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_NAME,		handle_device_get_property_req_name,	DEV_GET_PROPERTY_SIGNATURE 	},
 	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
 	{ NULL, NULL, NULL}
 };
@@ -1934,7 +1937,7 @@
 	return reply;
 }
 
-static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_set_property_req(DBusMessage *msg, void *data)
 {
 	const struct service_data *handlers = set_property_services;
 	DBusMessageIter iter;
@@ -1968,7 +1971,7 @@
 	return reply;
 }
 
-static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_get_property_req(DBusMessage *msg, void *data)
 {
 	const struct service_data *handlers = get_property_services;
 	DBusMessageIter iter;
@@ -1994,7 +1997,7 @@
 	return reply;
 }
 
-static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_set_property_req_name(DBusMessage *msg, void *data)
 {
 	struct hci_dbus_data *dbus_data = data;
 	DBusMessageIter iter;
@@ -2127,7 +2130,7 @@
 	bt_free(local_addr);
 }
 
-static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_get_property_req_name(DBusMessage *msg, void *data)
 {
 	struct hci_dbus_data *dbus_data = data;
 	DBusMessage *reply = NULL;
@@ -2183,6 +2186,107 @@
 	return reply;
 }
 
+static DBusMessage* write_scan_enable(DBusMessage *msg, void *data, gboolean ispscan)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	int dd = -1;
+	read_scan_enable_rp rp;
+	uint8_t enable;
+	uint8_t status;
+	struct hci_request rq;
+	gboolean scan;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &scan);
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_READ_SCAN_ENABLE;
+	rq.rparam = &rp;
+	rq.rlen   = READ_SCAN_ENABLE_RP_SIZE;
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Sending read scan enable command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (rp.status) {
+		syslog(LOG_ERR, "Getting scan enable failed with status 0x%02x",
+								 	rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + rp.status);
+		goto failed;
+        }
+
+	if (ispscan) {
+		if (scan && !(rp.enable & SCAN_PAGE))
+			enable = (rp.enable & SCAN_INQUIRY) | SCAN_PAGE;
+		else if (!scan && (rp.enable & SCAN_PAGE))
+			enable = (rp.enable & SCAN_INQUIRY);
+		else {
+			reply = dbus_message_new_method_return(msg);
+			goto failed;
+		}
+	} else {
+		if (scan && !(rp.enable & SCAN_INQUIRY))
+			enable = (rp.enable & SCAN_PAGE) | SCAN_INQUIRY;
+		else if (!scan && (rp.enable & SCAN_INQUIRY))
+			enable = (rp.enable & SCAN_PAGE);
+		else {
+			reply = dbus_message_new_method_return(msg);
+			goto failed;
+		}
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_WRITE_SCAN_ENABLE;
+	rq.cparam = &enable;
+	rq.clen   = sizeof(enable);
+	rq.rparam = &status;
+	rq.rlen   = sizeof(status);
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Sending write scan enable command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+	if (status) {
+		syslog(LOG_ERR, "Setting scan enable failed with status 0x%02x", rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + rp.status);
+		goto failed;
+	}
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+	return reply;
+
+}
+
+static DBusMessage* handle_device_set_property_req_pscan(DBusMessage *msg, void *data)
+{
+	return write_scan_enable(msg, data, TRUE);
+}
+
+static DBusMessage* handle_device_set_property_req_iscan(DBusMessage *msg, void *data)
+{
+	return write_scan_enable(msg, data, FALSE);
+}
+
 static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;
@@ -2328,5 +2432,5 @@
 	syslog(LOG_INFO, "Not Implemented - path %s iface %s method %s",
 							path, iface, method);
 
-	return NULL;
+	return bluez_new_failure_msg(msg, BLUEZ_EDBUS_NOT_IMPLEMENTED);
 }

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-12-01 16:55                                           ` Eduardo Rocha
@ 2005-12-01 21:05                                             ` Marcel Holtmann
  2005-12-07 12:29                                               ` Eduardo Rocha
  0 siblings, 1 reply; 37+ messages in thread
From: Marcel Holtmann @ 2005-12-01 21:05 UTC (permalink / raw)
  To: bluez-devel

Hi Eduardo,

> Johan said on an early email that would be nice to have each changed
> property to send a "PropertyChanged" signal with "Property name" and
> "property specific info" params. But for "discoverable" and
> "connectable" properties, how can we know what changed as both of them
> trigger a command_complete event with HCI_write_scan_enable OCF?  Or
> should we trigger a unique signal for pscan and iscan, sending the new
> scan status?

you need to track the HCI write scan enable command. You issue it with
specific values and you need to keep this transition state until you
receive the HCI command complete event. This is how the kernel is doing
it for some of the commands.

And I like the idea of a PropertyChanged signal.

Regards

Marcel




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-12-01 21:05                                             ` Marcel Holtmann
@ 2005-12-07 12:29                                               ` Eduardo Rocha
  2005-12-07 12:55                                                 ` Johan Hedberg
  0 siblings, 1 reply; 37+ messages in thread
From: Eduardo Rocha @ 2005-12-07 12:29 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 1682 bytes --]

Hi Marcel,

here is the patch with the scan property change. Maybe we should
consider improving the syslog error messages to include some more info
to give some clue of where it happened.

BR,
Eduardo.


On 12/1/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Eduardo,
>
> > Johan said on an early email that would be nice to have each changed
> > property to send a "PropertyChanged" signal with "Property name" and
> > "property specific info" params. But for "discoverable" and
> > "connectable" properties, how can we know what changed as both of them
> > trigger a command_complete event with HCI_write_scan_enable OCF?  Or
> > should we trigger a unique signal for pscan and iscan, sending the new
> > scan status?
>
> you need to track the HCI write scan enable command. You issue it with
> specific values and you need to keep this transition state until you
> receive the HCI command complete event. This is how the kernel is doing
> it for some of the commands.
>
> And I like the idea of a PropertyChanged signal.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: dbus_device_scan.patch --]
[-- Type: text/x-patch, Size: 18551 bytes --]

--- utils.05122005.orig/hcid/hcid.h	2005-12-05 11:28:17.000000000 -0300
+++ utils.05122005/hcid/hcid.h	2005-12-07 09:08:05.000000000 -0300
@@ -135,6 +135,7 @@
 void hcid_dbus_disconn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t reason);
 void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status);
 void hcid_dbus_setname_complete(bdaddr_t *local);
+void hcid_dbus_setscan_enable_complete(bdaddr_t *local);
 #else
 static inline void hcid_dbus_inquiry_start(bdaddr_t *local) {}
 static inline void hcid_dbus_inquiry_complete(bdaddr_t *local) {}
@@ -145,6 +146,7 @@
 static inline void hcid_dbus_disconn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t reason) {}
 static inline void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status) {}
 static inline void hcid_dbus_setname_complete(bdaddr_t *local) {}
+static inline void hcid_dbus_setscan_enable_complete(bdaddr_t *local) {}
 #endif
 
 int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name);
--- utils.05122005.orig/hcid/security.c	2005-12-05 11:28:17.000000000 -0300
+++ utils.05122005/hcid/security.c	2005-12-05 15:24:50.000000000 -0300
@@ -498,6 +498,8 @@
 	case cmd_opcode_pack(OGF_HOST_CTL, OCF_CHANGE_LOCAL_NAME):
 		hcid_dbus_setname_complete(sba);
 		break;
+	case cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE):
+		hcid_dbus_setscan_enable_complete(sba);
 	};
 }
 
--- utils.05122005.orig/hcid/dbus.h	2005-12-05 11:28:17.000000000 -0300
+++ utils.05122005/hcid/dbus.h	2005-12-05 15:21:57.000000000 -0300
@@ -100,7 +100,7 @@
 #define DEV_HCI_INTERFACE		DEVICE_INTERFACE "." BLUEZ_HCI
 
 /* /org/bluez/Device signals */
-#define BLUEZ_HCI_SET_NAME		"DeviceNameChanged"
+#define BLUEZ_HCI_PROPERTY_CHANGED	"PropertyChanged"
 
 /* Control interface signals */
 #define BLUEZ_HCI_INQ_START		"InquiryStart"
@@ -227,6 +227,7 @@
 #define BLUEZ_EDBUS_NO_MEM   		(0x05 + BLUEZ_EDBUS_OFFSET)
 #define BLUEZ_EDBUS_CONN_NOT_FOUND	(0x06 + BLUEZ_EDBUS_OFFSET)
 #define BLUEZ_EDBUS_UNKNOWN_PATH	(0x07 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_NOT_IMPLEMENTED	(0x08 + BLUEZ_EDBUS_OFFSET)
 
 /* D-Bus error code, class BLUEZ_ESYSTEM_OFFSET */
 #define BLUEZ_ESYSTEM_ENODEV		(ENODEV + BLUEZ_ESYSTEM_OFFSET)
--- utils.05122005.orig/hcid/dbus.c	2005-12-05 11:28:17.000000000 -0300
+++ utils.05122005/hcid/dbus.c	2005-12-07 09:16:40.000000000 -0300
@@ -75,6 +75,7 @@
 struct hci_dbus_data {
 	uint16_t dev_id;
 	uint16_t path_id;
+	uint32_t path_data;
 };
 
 typedef int register_function_t(DBusConnection *conn, uint16_t id);
@@ -132,6 +133,7 @@
 	{ BLUEZ_EDBUS_NO_MEM,		"No memory"			},
 	{ BLUEZ_EDBUS_CONN_NOT_FOUND,	"Connection not found"		},
 	{ BLUEZ_EDBUS_UNKNOWN_PATH,	"Unknown D-BUS path"		},
+	{ BLUEZ_EDBUS_NOT_IMPLEMENTED,	"Method not implemented"	},
 	{ 0, NULL }
 };
 
@@ -270,34 +272,36 @@
  */
 static DBusMessage* handle_device_up_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_down_req(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_get_property_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_get_property_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req_pscan(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req_iscan(DBusMessage *msg, void *data);
 
 static const struct service_data device_services[] = {
 	{ DEV_UP,		handle_device_up_req,		DEV_UP_SIGNATURE		},
 	{ DEV_DOWN,		handle_device_down_req,		DEV_DOWN_SIGNATURE		},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BOOL	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_STR	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BYTE	},
-	{ DEV_GET_PROPERTY,	handle_device_get_propety_req,	DEV_GET_PROPERTY_SIGNATURE	},
+	{ DEV_SET_PROPERTY,	handle_device_set_property_req,	DEV_SET_PROPERTY_SIGNATURE_BOOL	},
+	{ DEV_SET_PROPERTY,	handle_device_set_property_req,	DEV_SET_PROPERTY_SIGNATURE_STR	},
+	{ DEV_SET_PROPERTY,	handle_device_set_property_req,	DEV_SET_PROPERTY_SIGNATURE_BYTE	},
+	{ DEV_GET_PROPERTY,	handle_device_get_property_req,	DEV_GET_PROPERTY_SIGNATURE	},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data set_property_services[] = {
 	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
 	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
-	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
-	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
-	{ DEV_PROPERTY_NAME,		handle_device_set_propety_req_name,	DEV_SET_PROPERTY_SIGNATURE_STR		},
+	{ DEV_PROPERTY_PSCAN,		handle_device_set_property_req_pscan,	DEV_SET_PROPERTY_SIGNATURE_BOOL		},
+	{ DEV_PROPERTY_ISCAN,		handle_device_set_property_req_iscan,	DEV_SET_PROPERTY_SIGNATURE_BOOL		},
+	{ DEV_PROPERTY_NAME,		handle_device_set_property_req_name,	DEV_SET_PROPERTY_SIGNATURE_STR		},
 	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BYTE		},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data get_property_services[] = {
 	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_NAME,		handle_device_get_propety_req_name,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_NAME,		handle_device_get_property_req_name,	DEV_GET_PROPERTY_SIGNATURE 	},
 	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
 	{ NULL, NULL, NULL}
 };
@@ -936,12 +940,44 @@
 	char *pptr = path;
 	gboolean ret;
 	DBusMessage *message = NULL;
+	int dd = -1;
+	read_scan_enable_rp rp;
+	struct hci_request rq;
+	struct hci_dbus_data* pdata;
 
 	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, id);
+	ret = register_dbus_path(path, DEVICE_PATH_ID, id, &obj_dev_vtable, FALSE);
+
+	dd = hci_open_dev(id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", id);
+		rp.enable = SCAN_PAGE|SCAN_INQUIRY;
+	} else {
+		memset(&rq, 0, sizeof(rq));
+		rq.ogf    = OGF_HOST_CTL;
+		rq.ocf    = OCF_READ_SCAN_ENABLE;
+		rq.rparam = &rp;
+		rq.rlen   = READ_SCAN_ENABLE_RP_SIZE;
+	
+		if (hci_send_req(dd, &rq, 500) < 0) {
+			syslog(LOG_ERR, "Sending read scan enable command failed: %s (%d)",
+								strerror(errno), errno);
+			rp.enable = SCAN_PAGE|SCAN_INQUIRY;
+		} else if (rp.status) {
+			syslog(LOG_ERR, "Getting scan enable failed with status 0x%02x",
+										rp.status);
+			rp.enable = SCAN_PAGE|SCAN_INQUIRY;
+		}
+	}
+
+	if (!dbus_connection_get_object_path_data(connection, path, (void*)&pdata))
+		syslog(LOG_ERR, "Getting path data failed!");
+	else
+		pdata->path_data = rp.enable; /* Keep the current scan status */
+
 
 	message = dbus_message_new_signal(MANAGER_PATH, MANAGER_INTERFACE,
 							BLUEZ_MGR_DEV_ADDED);
-
 	if (message == NULL) {
 		syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
 		goto failed;
@@ -959,12 +995,13 @@
 	dbus_connection_flush(connection);
 
 failed:
-	dbus_message_unref(message);
-
-	ret = register_dbus_path(path, DEVICE_PATH_ID, id, &obj_dev_vtable, FALSE);
-
+	if (message)
+		dbus_message_unref(message);
+	
 	if (ret && default_dev < 0)
 		default_dev = id;
+	if (dd >= 0)
+		close(dd);
 
 	return ret;
 }
@@ -1934,7 +1971,7 @@
 	return reply;
 }
 
-static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_set_property_req(DBusMessage *msg, void *data)
 {
 	const struct service_data *handlers = set_property_services;
 	DBusMessageIter iter;
@@ -1968,7 +2005,7 @@
 	return reply;
 }
 
-static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_get_property_req(DBusMessage *msg, void *data)
 {
 	const struct service_data *handlers = get_property_services;
 	DBusMessageIter iter;
@@ -1994,7 +2031,7 @@
 	return reply;
 }
 
-static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_set_property_req_name(DBusMessage *msg, void *data)
 {
 	struct hci_dbus_data *dbus_data = data;
 	DBusMessageIter iter;
@@ -2065,7 +2102,8 @@
 	struct hci_request rq;
 	const char *pname = (char*) rp.name;
 	char name[249];
-
+	char prop_name[64];
+	char *pprop_name = prop_name;
 	baswap(&tmp, local); local_addr = batostr(&tmp);
 
 	id = hci_devid(local_addr);
@@ -2077,7 +2115,7 @@
 	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, id);
 
 	message = dbus_message_new_signal(path, DEVICE_INTERFACE,
-						BLUEZ_HCI_SET_NAME);
+						BLUEZ_HCI_PROPERTY_CHANGED);
 	if (message == NULL) {
 		syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
 		goto failed;
@@ -2107,11 +2145,14 @@
 	}
 
 	strncpy(name,pname,sizeof(name)-1);
-	name[248]='\0';
+	name[248] = '\0';
 	pname = name;
+	strncpy(prop_name, DEV_PROPERTY_NAME, sizeof(prop_name)-1);
+	prop_name[63] = '\0';
 
 	dbus_message_append_args(message,
 				DBUS_TYPE_STRING, &pname,
+				DBUS_TYPE_STRING, &pprop_name,
 				DBUS_TYPE_INVALID);
 
 	if (dbus_connection_send(connection, message, NULL) == FALSE) {
@@ -2123,11 +2164,12 @@
 failed:
 	if (dd >= 0)
 		close(dd);
-	dbus_message_unref(message);
+	if (message)
+		dbus_message_unref(message);
 	bt_free(local_addr);
 }
 
-static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_get_property_req_name(DBusMessage *msg, void *data)
 {
 	struct hci_dbus_data *dbus_data = data;
 	DBusMessage *reply = NULL;
@@ -2183,6 +2225,220 @@
 	return reply;
 }
 
+static DBusMessage* write_scan_enable(DBusMessage *msg, void *data, gboolean ispscan)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	int dd = -1;
+	read_scan_enable_rp rp;
+	uint8_t enable;
+	uint8_t status;
+	struct hci_request rq;
+	gboolean scan;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &scan);
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_READ_SCAN_ENABLE;
+	rq.rparam = &rp;
+	rq.rlen   = READ_SCAN_ENABLE_RP_SIZE;
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Sending read scan enable command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (rp.status) {
+		syslog(LOG_ERR, "Getting scan enable failed with status 0x%02x",
+								 	rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + rp.status);
+		goto failed;
+        }
+
+	if (ispscan) {
+		if (scan && !(rp.enable & SCAN_PAGE))
+			enable = (rp.enable & SCAN_INQUIRY) | SCAN_PAGE;
+		else if (!scan && (rp.enable & SCAN_PAGE))
+			enable = (rp.enable & SCAN_INQUIRY);
+		else {
+			reply = dbus_message_new_method_return(msg);
+			goto failed;
+		}
+	} else {
+		if (scan && !(rp.enable & SCAN_INQUIRY))
+			enable = (rp.enable & SCAN_PAGE) | SCAN_INQUIRY;
+		else if (!scan && (rp.enable & SCAN_INQUIRY))
+			enable = (rp.enable & SCAN_PAGE);
+		else {
+			reply = dbus_message_new_method_return(msg);
+			goto failed;
+		}
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_WRITE_SCAN_ENABLE;
+	rq.cparam = &enable;
+	rq.clen   = sizeof(enable);
+	rq.rparam = &status;
+	rq.rlen   = sizeof(status);
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Sending write scan enable command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+	if (status) {
+		syslog(LOG_ERR, "Setting scan enable failed with status 0x%02x", rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + rp.status);
+		goto failed;
+	}
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+	return reply;
+
+}
+
+void hcid_dbus_setscan_enable_complete(bdaddr_t *local)
+{
+	DBusMessage *message = NULL;
+	char path[MAX_PATH_LENGTH];
+	char *local_addr;
+	bdaddr_t tmp;
+	int id;
+	int dd = -1;
+	char prop_name[64];
+	char *pprop_name = prop_name;
+	gboolean se;
+	read_scan_enable_rp rp;
+	struct hci_request rq;
+	struct hci_dbus_data *pdata = NULL;
+	uint32_t old_data;
+
+	baswap(&tmp, local); local_addr = batostr(&tmp);
+	id = hci_devid(local_addr);
+	if (id < 0) {
+		syslog(LOG_ERR, "No matching device id for %s", local_addr);
+		goto failed;
+	}
+
+	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, id);
+
+	dd = hci_open_dev(id);
+	memset(&rq, 0, sizeof(rq));
+
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", id);
+		goto failed;
+	} else {
+		rq.ogf    = OGF_HOST_CTL;
+		rq.ocf    = OCF_READ_SCAN_ENABLE;
+		rq.rparam = &rp;
+		rq.rlen   = READ_SCAN_ENABLE_RP_SIZE;
+		if (hci_send_req(dd, &rq, 100) < 0) {
+			syslog(LOG_ERR,
+				"Sending read scan enable command failed: %s (%d)",
+				strerror(errno), errno);
+			goto failed;
+		}
+		if (rp.status) {
+			syslog(LOG_ERR,
+				"Getting scan enable failed with status 0x%02x",
+				rp.status);
+			goto failed;
+		}
+	}
+
+	if (!dbus_connection_get_object_path_data(connection, path, (void*)&pdata)) {
+		syslog(LOG_ERR, "Getting path data failed!");
+		goto failed;
+	}
+
+	old_data = pdata->path_data;
+	pdata->path_data = rp.enable;
+
+	if((rp.enable & SCAN_PAGE) != (old_data & SCAN_PAGE)) {
+		message = dbus_message_new_signal(path, DEVICE_INTERFACE,
+							BLUEZ_HCI_PROPERTY_CHANGED);
+		if (message == NULL) {
+			syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
+			goto failed;
+		}
+
+		strncpy(prop_name,DEV_PROPERTY_PSCAN,sizeof(prop_name)-1);
+		prop_name[sizeof(prop_name)-1]='\0';
+
+		se = (rp.enable & SCAN_PAGE)?1:0;
+
+		dbus_message_append_args(message,
+					DBUS_TYPE_STRING, &pprop_name,
+					DBUS_TYPE_BOOLEAN, &se,
+					DBUS_TYPE_INVALID);
+
+		if (dbus_connection_send(connection, message, NULL) == FALSE) {
+			syslog(LOG_ERR, "Can't send D-BUS NameChanged signal");
+		}
+		dbus_message_unref(message);
+
+	}
+	if ((rp.enable & SCAN_INQUIRY) != (old_data & SCAN_INQUIRY)) {
+		message = dbus_message_new_signal(path, DEVICE_INTERFACE,
+							BLUEZ_HCI_PROPERTY_CHANGED);
+		if (message == NULL) {
+			syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
+			goto failed;
+		}
+
+		strncpy(prop_name,DEV_PROPERTY_ISCAN,sizeof(prop_name)-1);
+		prop_name[sizeof(prop_name)-1]='\0';
+
+		se = (rp.enable & SCAN_INQUIRY)?1:0;
+
+		dbus_message_append_args(message,
+					DBUS_TYPE_STRING, &pprop_name,
+					DBUS_TYPE_BOOLEAN, &se,
+					DBUS_TYPE_INVALID);
+
+		if (dbus_connection_send(connection, message, NULL) == FALSE) {
+			syslog(LOG_ERR, "Can't send D-BUS NameChanged signal");
+		}
+		dbus_message_unref(message);
+	}
+	dbus_connection_flush(connection);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+	bt_free(local_addr);
+}
+
+static DBusMessage* handle_device_set_property_req_pscan(DBusMessage *msg, void *data)
+{
+	return write_scan_enable(msg, data, TRUE);
+}
+
+static DBusMessage* handle_device_set_property_req_iscan(DBusMessage *msg, void *data)
+{
+	return write_scan_enable(msg, data, FALSE);
+}
+
 static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;
@@ -2328,5 +2584,5 @@
 	syslog(LOG_INFO, "Not Implemented - path %s iface %s method %s",
 							path, iface, method);
 
-	return NULL;
+	return bluez_new_failure_msg(msg, BLUEZ_EDBUS_NOT_IMPLEMENTED);
 }
--- utils.05122005.orig/hcid/dbus-test	2005-12-05 11:28:17.000000000 -0300
+++ utils.05122005/hcid/dbus-test	2005-12-07 08:47:23.000000000 -0300
@@ -14,6 +14,9 @@
              "Connections", "Authenticate", "RoleSwitch" ]
 dev_setprop_bool = [ "auth", "encrypt", "discoverable", "connectable" ]
 dev_setprop_byte = [ "incmode" ]
+dev_prop_filter = ["/org/bluez/Device/hci0", "/org/bluez/Device/hci1",
+                   "/org/bluez/Device/hci2", "/org/bluez/Device/hci3",
+                   "/org/bluez/Device/hci4", "/org/bluez/Device/hci5"]
 
 class Tester:
     exit_events = []
@@ -81,10 +84,10 @@
 
                 self.dev.connect_to_signal('Up', self.dev_up)
                 self.dev.connect_to_signal('Down', self.dev_down)
-                self.bus.add_signal_receiver(self.dev_name_changed, 'DeviceNameChanged',
-                                             'org.bluez.Device', 'org.bluez',
-                                             '/org/bluez/Device/hci0')
-
+                for path in dev_prop_filter:
+                    self.bus.add_signal_receiver(self.dev_property_changed,
+                                             'PropertyChanged','org.bluez.Device',
+                                             'org.bluez',path)
                 obj = self.bus.get_object('org.bluez', '%s/Controller' % self.dev_path)
                 self.ctl = dbus.Interface(obj, 'org.bluez.Device.Controller')
 
@@ -157,10 +160,17 @@
         print 'Down'
 
     @dbus.decorators.explicitly_pass_message
-    def dev_name_changed(*args, **keywords):
-        name = args[1]
+    def dev_property_changed(*args, **keywords):
+        property = args[1]
+        param = args[2]
         dbus_message = keywords["dbus_message"]
-        print 'Device %s name changed: %s' % (dbus_message.get_path(), name)
+        if property == 'name':
+            print 'Device %s name changed: %s' % (dbus_message.get_path(), param)
+        elif property == 'connectable':
+            print 'Device %s connectable scan property changed: %d' % (dbus_message.get_path(), param)
+        elif property == 'discoverable':
+            print 'Device %s discoverable scan property changed: %d' % (dbus_message.get_path(), param)
+
 
     def signal_cb(self, sig, frame):
         print 'Caught signal, exiting'



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-12-07 12:29                                               ` Eduardo Rocha
@ 2005-12-07 12:55                                                 ` Johan Hedberg
  2005-12-07 13:02                                                   ` Marcel Holtmann
  0 siblings, 1 reply; 37+ messages in thread
From: Johan Hedberg @ 2005-12-07 12:55 UTC (permalink / raw)
  To: bluez-devel

Hi Eduardo,

Your patch looks ok, except that you seem to append the arguments in
the wrong order to the "name" property changed signal:

On Wed, Dec 07, 2005, Eduardo Rocha wrote:
>  	dbus_message_append_args(message,
>  				DBUS_TYPE_STRING, &pname,
> +				DBUS_TYPE_STRING, &pprop_name,

Btw, maybe we should have a common function for sending property changed
signals, e.g:
send_property_changed(const char *prop_name, int prop_type, void *value);

Johan


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-12-07 12:55                                                 ` Johan Hedberg
@ 2005-12-07 13:02                                                   ` Marcel Holtmann
  2005-12-07 16:01                                                     ` Eduardo Rocha
  0 siblings, 1 reply; 37+ messages in thread
From: Marcel Holtmann @ 2005-12-07 13:02 UTC (permalink / raw)
  To: bluez-devel

Hi Johan,

> Your patch looks ok, except that you seem to append the arguments in
> the wrong order to the "name" property changed signal:
> 
> On Wed, Dec 07, 2005, Eduardo Rocha wrote:
> >  	dbus_message_append_args(message,
> >  				DBUS_TYPE_STRING, &pname,
> > +				DBUS_TYPE_STRING, &pprop_name,

and some coding style issues :(

> Btw, maybe we should have a common function for sending property changed
> signals, e.g:
> send_property_changed(const char *prop_name, int prop_type, void *value);

Sounds like a good idea to me. Please integrate this and if needed split
the patch into two separate patches.

Regards

Marcel




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-12-07 13:02                                                   ` Marcel Holtmann
@ 2005-12-07 16:01                                                     ` Eduardo Rocha
  2005-12-13 17:27                                                       ` Eduardo Rocha
  0 siblings, 1 reply; 37+ messages in thread
From: Eduardo Rocha @ 2005-12-07 16:01 UTC (permalink / raw)
  To: bluez-devel

Hi Johan and Marcel,

I'll do that. Maybe should be a good idea to think how to split dbus.c
into 2 or 3 files.
Also, we should improve the debug messages.

BR,
Eduardo.



On 12/7/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Johan,
>
> > Your patch looks ok, except that you seem to append the arguments in
> > the wrong order to the "name" property changed signal:
> >
> > On Wed, Dec 07, 2005, Eduardo Rocha wrote:
> > >     dbus_message_append_args(message,
> > >                             DBUS_TYPE_STRING, &pname,
> > > +                           DBUS_TYPE_STRING, &pprop_name,
>
> and some coding style issues :(
>
> > Btw, maybe we should have a common function for sending property change=
d
> > signals, e.g:
> > send_property_changed(const char *prop_name, int prop_type, void *value=
);
>
> Sounds like a good idea to me. Please integrate this and if needed split
> the patch into two separate patches.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log fi=
les
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-12-07 16:01                                                     ` Eduardo Rocha
@ 2005-12-13 17:27                                                       ` Eduardo Rocha
  2005-12-13 22:03                                                         ` Marcel Holtmann
  0 siblings, 1 reply; 37+ messages in thread
From: Eduardo Rocha @ 2005-12-13 17:27 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 1650 bytes --]

Hi Marcel,

here is the patch with the send_property_changed_signal function included.

BR,
Eduardo.


> On 12/7/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> > Hi Johan,
> >
> > > Your patch looks ok, except that you seem to append the arguments in
> > > the wrong order to the "name" property changed signal:
> > >
> > > On Wed, Dec 07, 2005, Eduardo Rocha wrote:
> > > >     dbus_message_append_args(message,
> > > >                             DBUS_TYPE_STRING, &pname,
> > > > +                           DBUS_TYPE_STRING, &pprop_name,
> >
> > and some coding style issues :(
> >
> > > Btw, maybe we should have a common function for sending property changed
> > > signals, e.g:
> > > send_property_changed(const char *prop_name, int prop_type, void *value);
> >
> > Sounds like a good idea to me. Please integrate this and if needed split
> > the patch into two separate patches.
> >
> > Regards
> >
> > Marcel
> >
> >
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> > for problems?  Stop!  Download the new AJAX search engine that makes
> > searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> > http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> > _______________________________________________
> > Bluez-devel mailing list
> > Bluez-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/bluez-devel
> >
>
>
> --
> Eduardo Rocha
> Instituto Nokia de Tecnologia - INdT
>


--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: dbus_device_scan.patch --]
[-- Type: text/x-patch, Size: 18234 bytes --]

--- utils.13122005.orig/hcid/hcid.h	2005-11-24 01:10:47.000000000 -0300
+++ utils.13122005/hcid/hcid.h	2005-12-13 14:10:50.000000000 -0300
@@ -135,6 +135,7 @@
 void hcid_dbus_disconn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t reason);
 void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status);
 void hcid_dbus_setname_complete(bdaddr_t *local);
+void hcid_dbus_setscan_enable_complete(bdaddr_t *local);
 #else
 static inline void hcid_dbus_inquiry_start(bdaddr_t *local) {}
 static inline void hcid_dbus_inquiry_complete(bdaddr_t *local) {}
@@ -145,6 +146,7 @@
 static inline void hcid_dbus_disconn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t reason) {}
 static inline void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status) {}
 static inline void hcid_dbus_setname_complete(bdaddr_t *local) {}
+static inline void hcid_dbus_setscan_enable_complete(bdaddr_t *local) {}
 #endif
 
 int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name);
--- utils.13122005.orig/hcid/security.c	2005-11-24 01:10:47.000000000 -0300
+++ utils.13122005/hcid/security.c	2005-12-13 14:10:50.000000000 -0300
@@ -498,6 +498,8 @@
 	case cmd_opcode_pack(OGF_HOST_CTL, OCF_CHANGE_LOCAL_NAME):
 		hcid_dbus_setname_complete(sba);
 		break;
+	case cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE):
+		hcid_dbus_setscan_enable_complete(sba);
 	};
 }
 
--- utils.13122005.orig/hcid/dbus.h	2005-11-24 01:10:46.000000000 -0300
+++ utils.13122005/hcid/dbus.h	2005-12-13 14:10:50.000000000 -0300
@@ -100,7 +100,7 @@
 #define DEV_HCI_INTERFACE		DEVICE_INTERFACE "." BLUEZ_HCI
 
 /* /org/bluez/Device signals */
-#define BLUEZ_HCI_SET_NAME		"DeviceNameChanged"
+#define BLUEZ_HCI_PROPERTY_CHANGED	"PropertyChanged"
 
 /* Control interface signals */
 #define BLUEZ_HCI_INQ_START		"InquiryStart"
@@ -227,6 +227,7 @@
 #define BLUEZ_EDBUS_NO_MEM   		(0x05 + BLUEZ_EDBUS_OFFSET)
 #define BLUEZ_EDBUS_CONN_NOT_FOUND	(0x06 + BLUEZ_EDBUS_OFFSET)
 #define BLUEZ_EDBUS_UNKNOWN_PATH	(0x07 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_NOT_IMPLEMENTED	(0x08 + BLUEZ_EDBUS_OFFSET)
 
 /* D-Bus error code, class BLUEZ_ESYSTEM_OFFSET */
 #define BLUEZ_ESYSTEM_ENODEV		(ENODEV + BLUEZ_ESYSTEM_OFFSET)
--- utils.13122005.orig/hcid/dbus.c	2005-11-24 01:10:46.000000000 -0300
+++ utils.13122005/hcid/dbus.c	2005-12-13 14:17:41.000000000 -0300
@@ -75,6 +75,7 @@
 struct hci_dbus_data {
 	uint16_t dev_id;
 	uint16_t path_id;
+	uint32_t path_data;
 };
 
 typedef int register_function_t(DBusConnection *conn, uint16_t id);
@@ -132,6 +133,7 @@
 	{ BLUEZ_EDBUS_NO_MEM,		"No memory"			},
 	{ BLUEZ_EDBUS_CONN_NOT_FOUND,	"Connection not found"		},
 	{ BLUEZ_EDBUS_UNKNOWN_PATH,	"Unknown D-BUS path"		},
+	{ BLUEZ_EDBUS_NOT_IMPLEMENTED,	"Method not implemented"	},
 	{ 0, NULL }
 };
 
@@ -270,34 +272,36 @@
  */
 static DBusMessage* handle_device_up_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_down_req(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_get_property_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_get_property_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req_pscan(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req_iscan(DBusMessage *msg, void *data);
 
 static const struct service_data device_services[] = {
 	{ DEV_UP,		handle_device_up_req,		DEV_UP_SIGNATURE		},
 	{ DEV_DOWN,		handle_device_down_req,		DEV_DOWN_SIGNATURE		},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BOOL	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_STR	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BYTE	},
-	{ DEV_GET_PROPERTY,	handle_device_get_propety_req,	DEV_GET_PROPERTY_SIGNATURE	},
+	{ DEV_SET_PROPERTY,	handle_device_set_property_req,	DEV_SET_PROPERTY_SIGNATURE_BOOL	},
+	{ DEV_SET_PROPERTY,	handle_device_set_property_req,	DEV_SET_PROPERTY_SIGNATURE_STR	},
+	{ DEV_SET_PROPERTY,	handle_device_set_property_req,	DEV_SET_PROPERTY_SIGNATURE_BYTE	},
+	{ DEV_GET_PROPERTY,	handle_device_get_property_req,	DEV_GET_PROPERTY_SIGNATURE	},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data set_property_services[] = {
 	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
 	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
-	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
-	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
-	{ DEV_PROPERTY_NAME,		handle_device_set_propety_req_name,	DEV_SET_PROPERTY_SIGNATURE_STR		},
+	{ DEV_PROPERTY_PSCAN,		handle_device_set_property_req_pscan,	DEV_SET_PROPERTY_SIGNATURE_BOOL		},
+	{ DEV_PROPERTY_ISCAN,		handle_device_set_property_req_iscan,	DEV_SET_PROPERTY_SIGNATURE_BOOL		},
+	{ DEV_PROPERTY_NAME,		handle_device_set_property_req_name,	DEV_SET_PROPERTY_SIGNATURE_STR		},
 	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BYTE		},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data get_property_services[] = {
 	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_NAME,		handle_device_get_propety_req_name,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_NAME,		handle_device_get_property_req_name,	DEV_GET_PROPERTY_SIGNATURE 	},
 	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
 	{ NULL, NULL, NULL}
 };
@@ -936,12 +940,44 @@
 	char *pptr = path;
 	gboolean ret;
 	DBusMessage *message = NULL;
+	int dd = -1;
+	read_scan_enable_rp rp;
+	struct hci_request rq;
+	struct hci_dbus_data* pdata;
 
 	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, id);
+	ret = register_dbus_path(path, DEVICE_PATH_ID, id, &obj_dev_vtable, FALSE);
+
+	dd = hci_open_dev(id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", id);
+		rp.enable = SCAN_PAGE|SCAN_INQUIRY;
+	} else {
+		memset(&rq, 0, sizeof(rq));
+		rq.ogf    = OGF_HOST_CTL;
+		rq.ocf    = OCF_READ_SCAN_ENABLE;
+		rq.rparam = &rp;
+		rq.rlen   = READ_SCAN_ENABLE_RP_SIZE;
+	
+		if (hci_send_req(dd, &rq, 500) < 0) {
+			syslog(LOG_ERR, "Sending read scan enable command failed: %s (%d)",
+								strerror(errno), errno);
+			rp.enable = SCAN_PAGE|SCAN_INQUIRY;
+		} else if (rp.status) {
+			syslog(LOG_ERR, "Getting scan enable failed with status 0x%02x",
+										rp.status);
+			rp.enable = SCAN_PAGE|SCAN_INQUIRY;
+		}
+	}
+
+	if (!dbus_connection_get_object_path_data(connection, path, (void*)&pdata))
+		syslog(LOG_ERR, "Getting path data failed!");
+	else
+		pdata->path_data = rp.enable; /* Keep the current scan status */
+
 
 	message = dbus_message_new_signal(MANAGER_PATH, MANAGER_INTERFACE,
 							BLUEZ_MGR_DEV_ADDED);
-
 	if (message == NULL) {
 		syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
 		goto failed;
@@ -959,12 +995,13 @@
 	dbus_connection_flush(connection);
 
 failed:
-	dbus_message_unref(message);
-
-	ret = register_dbus_path(path, DEVICE_PATH_ID, id, &obj_dev_vtable, FALSE);
-
+	if (message)
+		dbus_message_unref(message);
+	
 	if (ret && default_dev < 0)
 		default_dev = id;
+	if (dd >= 0)
+		close(dd);
 
 	return ret;
 }
@@ -1934,7 +1971,7 @@
 	return reply;
 }
 
-static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_set_property_req(DBusMessage *msg, void *data)
 {
 	const struct service_data *handlers = set_property_services;
 	DBusMessageIter iter;
@@ -1968,7 +2005,7 @@
 	return reply;
 }
 
-static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_get_property_req(DBusMessage *msg, void *data)
 {
 	const struct service_data *handlers = get_property_services;
 	DBusMessageIter iter;
@@ -1994,7 +2031,36 @@
 	return reply;
 }
 
-static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data)
+static void send_property_changed_signal(const int devid, const char *prop_name, const int prop_type, void *value)
+{
+	DBusMessage *message = NULL;
+	char path[MAX_PATH_LENGTH];
+
+	snprintf(path, sizeof(path)-1, "%s/hci%d", DEVICE_PATH, devid);
+	path[MAX_PATH_LENGTH-1]='\0';
+
+	message = dbus_message_new_signal(path, DEVICE_INTERFACE,
+						BLUEZ_HCI_PROPERTY_CHANGED);
+	if (message == NULL) {
+		syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
+		goto failed;
+	}
+	dbus_message_append_args(message,
+				DBUS_TYPE_STRING, &prop_name,
+				prop_type, value,
+				DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send(connection, message, NULL) == FALSE) {
+		syslog(LOG_ERR, "Can't send D-BUS PropertChanged(%s) signal",prop_name);
+		goto failed;
+	}
+
+failed:
+	if (message)
+		dbus_message_unref(message);
+}
+
+static DBusMessage* handle_device_set_property_req_name(DBusMessage *msg, void *data)
 {
 	struct hci_dbus_data *dbus_data = data;
 	DBusMessageIter iter;
@@ -2055,8 +2121,6 @@
 
 void hcid_dbus_setname_complete(bdaddr_t *local)
 {
-	DBusMessage *message = NULL;
-	char path[MAX_PATH_LENGTH];
 	char *local_addr;
 	bdaddr_t tmp;
 	int id;
@@ -2074,15 +2138,6 @@
 		goto failed;
 	}
 
-	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, id);
-
-	message = dbus_message_new_signal(path, DEVICE_INTERFACE,
-						BLUEZ_HCI_SET_NAME);
-	if (message == NULL) {
-		syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
-		goto failed;
-	}
-
 	dd = hci_open_dev(id);
 	memset(&rq, 0, sizeof(rq));
 	if (dd < 0) {
@@ -2107,27 +2162,19 @@
 	}
 
 	strncpy(name,pname,sizeof(name)-1);
-	name[248]='\0';
+	name[248] = '\0';
 	pname = name;
 
-	dbus_message_append_args(message,
-				DBUS_TYPE_STRING, &pname,
-				DBUS_TYPE_INVALID);
-
-	if (dbus_connection_send(connection, message, NULL) == FALSE) {
-		syslog(LOG_ERR, "Can't send D-BUS NameChanged signal");
-		goto failed;
-	}
+	send_property_changed_signal(id, DEV_PROPERTY_NAME, DBUS_TYPE_STRING, &pname);
 	dbus_connection_flush(connection);
 
 failed:
 	if (dd >= 0)
 		close(dd);
-	dbus_message_unref(message);
 	bt_free(local_addr);
 }
 
-static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_get_property_req_name(DBusMessage *msg, void *data)
 {
 	struct hci_dbus_data *dbus_data = data;
 	DBusMessage *reply = NULL;
@@ -2183,6 +2230,178 @@
 	return reply;
 }
 
+static DBusMessage* write_scan_enable(DBusMessage *msg, void *data, gboolean ispscan)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	int dd = -1;
+	read_scan_enable_rp rp;
+	uint8_t enable;
+	uint8_t status;
+	struct hci_request rq;
+	gboolean scan;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &scan);
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_READ_SCAN_ENABLE;
+	rq.rparam = &rp;
+	rq.rlen   = READ_SCAN_ENABLE_RP_SIZE;
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Sending read scan enable command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (rp.status) {
+		syslog(LOG_ERR, "Getting scan enable failed with status 0x%02x",
+								 	rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + rp.status);
+		goto failed;
+        }
+
+	if (ispscan) {
+		if (scan && !(rp.enable & SCAN_PAGE))
+			enable = (rp.enable & SCAN_INQUIRY) | SCAN_PAGE;
+		else if (!scan && (rp.enable & SCAN_PAGE))
+			enable = (rp.enable & SCAN_INQUIRY);
+		else {
+			reply = dbus_message_new_method_return(msg);
+			goto failed;
+		}
+	} else {
+		if (scan && !(rp.enable & SCAN_INQUIRY))
+			enable = (rp.enable & SCAN_PAGE) | SCAN_INQUIRY;
+		else if (!scan && (rp.enable & SCAN_INQUIRY))
+			enable = (rp.enable & SCAN_PAGE);
+		else {
+			reply = dbus_message_new_method_return(msg);
+			goto failed;
+		}
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_WRITE_SCAN_ENABLE;
+	rq.cparam = &enable;
+	rq.clen   = sizeof(enable);
+	rq.rparam = &status;
+	rq.rlen   = sizeof(status);
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Sending write scan enable command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+	if (status) {
+		syslog(LOG_ERR, "Setting scan enable failed with status 0x%02x", rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + rp.status);
+		goto failed;
+	}
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+	return reply;
+
+}
+
+void hcid_dbus_setscan_enable_complete(bdaddr_t *local)
+{
+	char *local_addr;
+	char path[MAX_PATH_LENGTH];
+	bdaddr_t tmp;
+	int id;
+	int dd = -1;
+	gboolean se;
+	read_scan_enable_rp rp;
+	struct hci_request rq;
+	struct hci_dbus_data *pdata = NULL;
+	uint32_t old_data;
+
+	baswap(&tmp, local); local_addr = batostr(&tmp);
+	id = hci_devid(local_addr);
+	if (id < 0) {
+		syslog(LOG_ERR, "No matching device id for %s", local_addr);
+		goto failed;
+	}
+
+	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, id);
+
+	dd = hci_open_dev(id);
+	memset(&rq, 0, sizeof(rq));
+
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", id);
+		goto failed;
+	} else {
+		rq.ogf    = OGF_HOST_CTL;
+		rq.ocf    = OCF_READ_SCAN_ENABLE;
+		rq.rparam = &rp;
+		rq.rlen   = READ_SCAN_ENABLE_RP_SIZE;
+		if (hci_send_req(dd, &rq, 100) < 0) {
+			syslog(LOG_ERR,
+				"Sending read scan enable command failed: %s (%d)",
+				strerror(errno), errno);
+			goto failed;
+		}
+		if (rp.status) {
+			syslog(LOG_ERR,
+				"Getting scan enable failed with status 0x%02x",
+				rp.status);
+			goto failed;
+		}
+	}
+
+	if (!dbus_connection_get_object_path_data(connection, path, (void*)&pdata)) {
+		syslog(LOG_ERR, "Getting path data failed!");
+		goto failed;
+	}
+
+	old_data = pdata->path_data;
+	pdata->path_data = rp.enable;
+
+	if((rp.enable & SCAN_PAGE) != (old_data & SCAN_PAGE)) {
+		se = (rp.enable & SCAN_PAGE)?1:0;
+		send_property_changed_signal(id, DEV_PROPERTY_PSCAN, DBUS_TYPE_BOOLEAN, &se);
+	}
+	if ((rp.enable & SCAN_INQUIRY) != (old_data & SCAN_INQUIRY)) {
+		se = (rp.enable & SCAN_INQUIRY)?1:0;
+		send_property_changed_signal(id, DEV_PROPERTY_ISCAN, DBUS_TYPE_BOOLEAN, &se);
+	}
+	dbus_connection_flush(connection);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+	bt_free(local_addr);
+}
+
+static DBusMessage* handle_device_set_property_req_pscan(DBusMessage *msg, void *data)
+{
+	return write_scan_enable(msg, data, TRUE);
+}
+
+static DBusMessage* handle_device_set_property_req_iscan(DBusMessage *msg, void *data)
+{
+	return write_scan_enable(msg, data, FALSE);
+}
+
 static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;
@@ -2328,5 +2547,5 @@
 	syslog(LOG_INFO, "Not Implemented - path %s iface %s method %s",
 							path, iface, method);
 
-	return NULL;
+	return bluez_new_failure_msg(msg, BLUEZ_EDBUS_NOT_IMPLEMENTED);
 }
--- utils.13122005.orig/hcid/dbus-test	2005-11-24 01:10:46.000000000 -0300
+++ utils.13122005/hcid/dbus-test	2005-12-13 14:10:50.000000000 -0300
@@ -14,6 +14,9 @@
              "Connections", "Authenticate", "RoleSwitch" ]
 dev_setprop_bool = [ "auth", "encrypt", "discoverable", "connectable" ]
 dev_setprop_byte = [ "incmode" ]
+dev_prop_filter = ["/org/bluez/Device/hci0", "/org/bluez/Device/hci1",
+                   "/org/bluez/Device/hci2", "/org/bluez/Device/hci3",
+                   "/org/bluez/Device/hci4", "/org/bluez/Device/hci5"]
 
 class Tester:
     exit_events = []
@@ -81,10 +84,10 @@
 
                 self.dev.connect_to_signal('Up', self.dev_up)
                 self.dev.connect_to_signal('Down', self.dev_down)
-                self.bus.add_signal_receiver(self.dev_name_changed, 'DeviceNameChanged',
-                                             'org.bluez.Device', 'org.bluez',
-                                             '/org/bluez/Device/hci0')
-
+                for path in dev_prop_filter:
+                    self.bus.add_signal_receiver(self.dev_property_changed,
+                                             'PropertyChanged','org.bluez.Device',
+                                             'org.bluez',path)
                 obj = self.bus.get_object('org.bluez', '%s/Controller' % self.dev_path)
                 self.ctl = dbus.Interface(obj, 'org.bluez.Device.Controller')
 
@@ -157,10 +160,17 @@
         print 'Down'
 
     @dbus.decorators.explicitly_pass_message
-    def dev_name_changed(*args, **keywords):
-        name = args[1]
+    def dev_property_changed(*args, **keywords):
+        property = args[1]
+        param = args[2]
         dbus_message = keywords["dbus_message"]
-        print 'Device %s name changed: %s' % (dbus_message.get_path(), name)
+        if property == 'name':
+            print 'Device %s name changed: %s' % (dbus_message.get_path(), param)
+        elif property == 'connectable':
+            print 'Device %s connectable scan property changed: %d' % (dbus_message.get_path(), param)
+        elif property == 'discoverable':
+            print 'Device %s discoverable scan property changed: %d' % (dbus_message.get_path(), param)
+
 
     def signal_cb(self, sig, frame):
         print 'Caught signal, exiting'

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-12-13 17:27                                                       ` Eduardo Rocha
@ 2005-12-13 22:03                                                         ` Marcel Holtmann
  2005-12-14 19:02                                                           ` Eduardo Rocha
  0 siblings, 1 reply; 37+ messages in thread
From: Marcel Holtmann @ 2005-12-13 22:03 UTC (permalink / raw)
  To: bluez-devel

Hi Eduardo,

> here is the patch with the send_property_changed_signal function included.

nice, but please follow the coding style. I don't wanna correct the
whitespaces in all patches. Some examples what should be changed:

(void*)&pdata				==> (void *) &pdata
= SCAN_PAGE|SCAN_INQUIRY;		==> = SCAN_PAGE | SCAN_INQUIRY;
se = (rp.enable & SCAN_PAGE)?1:0;	se = (rp.enable & SCAN_PAGE) ? 1 : 0;

This is also bad coding style:

       if (dd < 0) {
               syslog(LOG_ERR, "HCI device open failed: hci%d", id);
               goto failed;
       } else {

We don't need the else branch. I results in an needless indentation.

I also think that we need some more newlines in your code, but I am
going to fix it when applying the patch.

This part might work, but I don't like it:

       if (ispscan) {
               if (scan && !(rp.enable & SCAN_PAGE))
                       enable = (rp.enable & SCAN_INQUIRY) | SCAN_PAGE;
               else if (!scan && (rp.enable & SCAN_PAGE))
                       enable = (rp.enable & SCAN_INQUIRY);
               else {
                       reply = dbus_message_new_method_return(msg);
                       goto failed;
               }
       } else {
               if (scan && !(rp.enable & SCAN_INQUIRY))
                       enable = (rp.enable & SCAN_PAGE) | SCAN_INQUIRY;
               else if (!scan && (rp.enable & SCAN_INQUIRY))
                       enable = (rp.enable & SCAN_PAGE);
               else {
                       reply = dbus_message_new_method_return(msg);
                       goto failed;
               }
       }

And this includes this:

       if((rp.enable & SCAN_PAGE) != (old_data & SCAN_PAGE)) {
               se = (rp.enable & SCAN_PAGE)?1:0;
               send_property_changed_signal(id, DEV_PROPERTY_PSCAN, DBUS_TYPE_BOOLEAN, &se);
       }
       if ((rp.enable & SCAN_INQUIRY) != (old_data & SCAN_INQUIRY)) {
               se = (rp.enable & SCAN_INQUIRY)?1:0;
               send_property_changed_signal(id, DEV_PROPERTY_ISCAN, DBUS_TYPE_BOOLEAN, &se);
       }
       dbus_connection_flush(connection);

I don't have any better idea to solve this at the moment, but if you
read this code it takes too much time too understand what it is actually
doing. And normally this is not a good idea. However we might fix it
later and get the patch in now for further testing. So please correct
the other parts and resend it.

Regards

Marcel




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-12-13 22:03                                                         ` Marcel Holtmann
@ 2005-12-14 19:02                                                           ` Eduardo Rocha
  2005-12-16 18:37                                                             ` Eduardo Rocha
  0 siblings, 1 reply; 37+ messages in thread
From: Eduardo Rocha @ 2005-12-14 19:02 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 3385 bytes --]

Hi Marcel,

here is the new patch.

BR,
Eduardo.


On 12/13/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Eduardo,
>
> > here is the patch with the send_property_changed_signal function included.
>
> nice, but please follow the coding style. I don't wanna correct the
> whitespaces in all patches. Some examples what should be changed:
>
> (void*)&pdata                           ==> (void *) &pdata
> = SCAN_PAGE|SCAN_INQUIRY;               ==> = SCAN_PAGE | SCAN_INQUIRY;
> se = (rp.enable & SCAN_PAGE)?1:0;       se = (rp.enable & SCAN_PAGE) ? 1 : 0;
>
> This is also bad coding style:
>
>        if (dd < 0) {
>                syslog(LOG_ERR, "HCI device open failed: hci%d", id);
>                goto failed;
>        } else {
>
> We don't need the else branch. I results in an needless indentation.
>
> I also think that we need some more newlines in your code, but I am
> going to fix it when applying the patch.
>
> This part might work, but I don't like it:
>
>        if (ispscan) {
>                if (scan && !(rp.enable & SCAN_PAGE))
>                        enable = (rp.enable & SCAN_INQUIRY) | SCAN_PAGE;
>                else if (!scan && (rp.enable & SCAN_PAGE))
>                        enable = (rp.enable & SCAN_INQUIRY);
>                else {
>                        reply = dbus_message_new_method_return(msg);
>                        goto failed;
>                }
>        } else {
>                if (scan && !(rp.enable & SCAN_INQUIRY))
>                        enable = (rp.enable & SCAN_PAGE) | SCAN_INQUIRY;
>                else if (!scan && (rp.enable & SCAN_INQUIRY))
>                        enable = (rp.enable & SCAN_PAGE);
>                else {
>                        reply = dbus_message_new_method_return(msg);
>                        goto failed;
>                }
>        }
>
> And this includes this:
>
>        if((rp.enable & SCAN_PAGE) != (old_data & SCAN_PAGE)) {
>                se = (rp.enable & SCAN_PAGE)?1:0;
>                send_property_changed_signal(id, DEV_PROPERTY_PSCAN, DBUS_TYPE_BOOLEAN, &se);
>        }
>        if ((rp.enable & SCAN_INQUIRY) != (old_data & SCAN_INQUIRY)) {
>                se = (rp.enable & SCAN_INQUIRY)?1:0;
>                send_property_changed_signal(id, DEV_PROPERTY_ISCAN, DBUS_TYPE_BOOLEAN, &se);
>        }
>        dbus_connection_flush(connection);
>
> I don't have any better idea to solve this at the moment, but if you
> read this code it takes too much time too understand what it is actually
> doing. And normally this is not a good idea. However we might fix it
> later and get the patch in now for further testing. So please correct
> the other parts and resend it.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: dbus_device_scan.patch --]
[-- Type: text/x-patch, Size: 18721 bytes --]

--- utils.13122005.orig/hcid/hcid.h	2005-11-24 01:10:47.000000000 -0300
+++ utils.13122005/hcid/hcid.h	2005-12-13 14:10:50.000000000 -0300
@@ -135,6 +135,7 @@
 void hcid_dbus_disconn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t reason);
 void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status);
 void hcid_dbus_setname_complete(bdaddr_t *local);
+void hcid_dbus_setscan_enable_complete(bdaddr_t *local);
 #else
 static inline void hcid_dbus_inquiry_start(bdaddr_t *local) {}
 static inline void hcid_dbus_inquiry_complete(bdaddr_t *local) {}
@@ -145,6 +146,7 @@
 static inline void hcid_dbus_disconn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t reason) {}
 static inline void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status) {}
 static inline void hcid_dbus_setname_complete(bdaddr_t *local) {}
+static inline void hcid_dbus_setscan_enable_complete(bdaddr_t *local) {}
 #endif
 
 int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name);
--- utils.13122005.orig/hcid/security.c	2005-11-24 01:10:47.000000000 -0300
+++ utils.13122005/hcid/security.c	2005-12-13 14:10:50.000000000 -0300
@@ -498,6 +498,8 @@
 	case cmd_opcode_pack(OGF_HOST_CTL, OCF_CHANGE_LOCAL_NAME):
 		hcid_dbus_setname_complete(sba);
 		break;
+	case cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE):
+		hcid_dbus_setscan_enable_complete(sba);
 	};
 }
 
--- utils.13122005.orig/hcid/dbus.h	2005-11-24 01:10:46.000000000 -0300
+++ utils.13122005/hcid/dbus.h	2005-12-13 14:10:50.000000000 -0300
@@ -100,7 +100,7 @@
 #define DEV_HCI_INTERFACE		DEVICE_INTERFACE "." BLUEZ_HCI
 
 /* /org/bluez/Device signals */
-#define BLUEZ_HCI_SET_NAME		"DeviceNameChanged"
+#define BLUEZ_HCI_PROPERTY_CHANGED	"PropertyChanged"
 
 /* Control interface signals */
 #define BLUEZ_HCI_INQ_START		"InquiryStart"
@@ -227,6 +227,7 @@
 #define BLUEZ_EDBUS_NO_MEM   		(0x05 + BLUEZ_EDBUS_OFFSET)
 #define BLUEZ_EDBUS_CONN_NOT_FOUND	(0x06 + BLUEZ_EDBUS_OFFSET)
 #define BLUEZ_EDBUS_UNKNOWN_PATH	(0x07 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_NOT_IMPLEMENTED	(0x08 + BLUEZ_EDBUS_OFFSET)
 
 /* D-Bus error code, class BLUEZ_ESYSTEM_OFFSET */
 #define BLUEZ_ESYSTEM_ENODEV		(ENODEV + BLUEZ_ESYSTEM_OFFSET)
--- utils.13122005.orig/hcid/dbus.c	2005-11-24 01:10:46.000000000 -0300
+++ utils.13122005/hcid/dbus.c	2005-12-14 12:39:43.000000000 -0300
@@ -75,6 +75,7 @@
 struct hci_dbus_data {
 	uint16_t dev_id;
 	uint16_t path_id;
+	uint32_t path_data;
 };
 
 typedef int register_function_t(DBusConnection *conn, uint16_t id);
@@ -132,6 +133,7 @@
 	{ BLUEZ_EDBUS_NO_MEM,		"No memory"			},
 	{ BLUEZ_EDBUS_CONN_NOT_FOUND,	"Connection not found"		},
 	{ BLUEZ_EDBUS_UNKNOWN_PATH,	"Unknown D-BUS path"		},
+	{ BLUEZ_EDBUS_NOT_IMPLEMENTED,	"Method not implemented"	},
 	{ 0, NULL }
 };
 
@@ -270,34 +272,36 @@
  */
 static DBusMessage* handle_device_up_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_down_req(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data);
-static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_get_property_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_get_property_req_name(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req_pscan(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req_iscan(DBusMessage *msg, void *data);
 
 static const struct service_data device_services[] = {
 	{ DEV_UP,		handle_device_up_req,		DEV_UP_SIGNATURE		},
 	{ DEV_DOWN,		handle_device_down_req,		DEV_DOWN_SIGNATURE		},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BOOL	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_STR	},
-	{ DEV_SET_PROPERTY,	handle_device_set_propety_req,	DEV_SET_PROPERTY_SIGNATURE_BYTE	},
-	{ DEV_GET_PROPERTY,	handle_device_get_propety_req,	DEV_GET_PROPERTY_SIGNATURE	},
+	{ DEV_SET_PROPERTY,	handle_device_set_property_req,	DEV_SET_PROPERTY_SIGNATURE_BOOL	},
+	{ DEV_SET_PROPERTY,	handle_device_set_property_req,	DEV_SET_PROPERTY_SIGNATURE_STR	},
+	{ DEV_SET_PROPERTY,	handle_device_set_property_req,	DEV_SET_PROPERTY_SIGNATURE_BYTE	},
+	{ DEV_GET_PROPERTY,	handle_device_get_property_req,	DEV_GET_PROPERTY_SIGNATURE	},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data set_property_services[] = {
 	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
 	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
-	{ DEV_PROPERTY_PSCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
-	{ DEV_PROPERTY_ISCAN,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
-	{ DEV_PROPERTY_NAME,		handle_device_set_propety_req_name,	DEV_SET_PROPERTY_SIGNATURE_STR		},
+	{ DEV_PROPERTY_PSCAN,		handle_device_set_property_req_pscan,	DEV_SET_PROPERTY_SIGNATURE_BOOL		},
+	{ DEV_PROPERTY_ISCAN,		handle_device_set_property_req_iscan,	DEV_SET_PROPERTY_SIGNATURE_BOOL		},
+	{ DEV_PROPERTY_NAME,		handle_device_set_property_req_name,	DEV_SET_PROPERTY_SIGNATURE_STR		},
 	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BYTE		},
 	{ NULL, NULL, NULL}
 };
 
 static const struct service_data get_property_services[] = {
 	{ DEV_PROPERTY_DEV_INFO,	handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
-	{ DEV_PROPERTY_NAME,		handle_device_get_propety_req_name,	DEV_GET_PROPERTY_SIGNATURE 	},
+	{ DEV_PROPERTY_NAME,		handle_device_get_property_req_name,	DEV_GET_PROPERTY_SIGNATURE 	},
 	{ DEV_PROPERTY_INCMODE,		handle_not_implemented_req,		DEV_GET_PROPERTY_SIGNATURE 	},
 	{ NULL, NULL, NULL}
 };
@@ -936,12 +940,44 @@
 	char *pptr = path;
 	gboolean ret;
 	DBusMessage *message = NULL;
+	int dd = -1;
+	read_scan_enable_rp rp;
+	struct hci_request rq;
+	struct hci_dbus_data* pdata;
 
 	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, id);
+	ret = register_dbus_path(path, DEVICE_PATH_ID, id, &obj_dev_vtable, FALSE);
+
+	dd = hci_open_dev(id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", id);
+		rp.enable = SCAN_PAGE | SCAN_INQUIRY;
+	} else {
+		memset(&rq, 0, sizeof(rq));
+		rq.ogf    = OGF_HOST_CTL;
+		rq.ocf    = OCF_READ_SCAN_ENABLE;
+		rq.rparam = &rp;
+		rq.rlen   = READ_SCAN_ENABLE_RP_SIZE;
+	
+		if (hci_send_req(dd, &rq, 500) < 0) {
+			syslog(LOG_ERR, "Sending read scan enable command failed: %s (%d)",
+								strerror(errno), errno);
+			rp.enable = SCAN_PAGE | SCAN_INQUIRY;
+		} else if (rp.status) {
+			syslog(LOG_ERR, "Getting scan enable failed with status 0x%02x",
+										rp.status);
+			rp.enable = SCAN_PAGE | SCAN_INQUIRY;
+		}
+	}
+
+	if (!dbus_connection_get_object_path_data(connection, path, (void*) &pdata))
+		syslog(LOG_ERR, "Getting path data failed!");
+	else
+		pdata->path_data = rp.enable; /* Keep the current scan status */
+
 
 	message = dbus_message_new_signal(MANAGER_PATH, MANAGER_INTERFACE,
 							BLUEZ_MGR_DEV_ADDED);
-
 	if (message == NULL) {
 		syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
 		goto failed;
@@ -959,12 +995,13 @@
 	dbus_connection_flush(connection);
 
 failed:
-	dbus_message_unref(message);
-
-	ret = register_dbus_path(path, DEVICE_PATH_ID, id, &obj_dev_vtable, FALSE);
-
+	if (message)
+		dbus_message_unref(message);
+	
 	if (ret && default_dev < 0)
 		default_dev = id;
+	if (dd >= 0)
+		close(dd);
 
 	return ret;
 }
@@ -1934,7 +1971,7 @@
 	return reply;
 }
 
-static DBusMessage* handle_device_set_propety_req(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_set_property_req(DBusMessage *msg, void *data)
 {
 	const struct service_data *handlers = set_property_services;
 	DBusMessageIter iter;
@@ -1968,7 +2005,7 @@
 	return reply;
 }
 
-static DBusMessage* handle_device_get_propety_req(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_get_property_req(DBusMessage *msg, void *data)
 {
 	const struct service_data *handlers = get_property_services;
 	DBusMessageIter iter;
@@ -1994,7 +2031,36 @@
 	return reply;
 }
 
-static DBusMessage* handle_device_set_propety_req_name(DBusMessage *msg, void *data)
+static void send_property_changed_signal(const int devid, const char *prop_name, const int prop_type, void *value)
+{
+	DBusMessage *message = NULL;
+	char path[MAX_PATH_LENGTH];
+
+	snprintf(path, sizeof(path)-1, "%s/hci%d", DEVICE_PATH, devid);
+	path[MAX_PATH_LENGTH-1]='\0';
+
+	message = dbus_message_new_signal(path, DEVICE_INTERFACE,
+						BLUEZ_HCI_PROPERTY_CHANGED);
+	if (message == NULL) {
+		syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
+		goto failed;
+	}
+	dbus_message_append_args(message,
+				DBUS_TYPE_STRING, &prop_name,
+				prop_type, value,
+				DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send(connection, message, NULL) == FALSE) {
+		syslog(LOG_ERR, "Can't send D-BUS PropertChanged(%s) signal",prop_name);
+		goto failed;
+	}
+
+failed:
+	if (message)
+		dbus_message_unref(message);
+}
+
+static DBusMessage* handle_device_set_property_req_name(DBusMessage *msg, void *data)
 {
 	struct hci_dbus_data *dbus_data = data;
 	DBusMessageIter iter;
@@ -2055,8 +2121,6 @@
 
 void hcid_dbus_setname_complete(bdaddr_t *local)
 {
-	DBusMessage *message = NULL;
-	char path[MAX_PATH_LENGTH];
 	char *local_addr;
 	bdaddr_t tmp;
 	int id;
@@ -2074,15 +2138,6 @@
 		goto failed;
 	}
 
-	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, id);
-
-	message = dbus_message_new_signal(path, DEVICE_INTERFACE,
-						BLUEZ_HCI_SET_NAME);
-	if (message == NULL) {
-		syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
-		goto failed;
-	}
-
 	dd = hci_open_dev(id);
 	memset(&rq, 0, sizeof(rq));
 	if (dd < 0) {
@@ -2107,27 +2162,19 @@
 	}
 
 	strncpy(name,pname,sizeof(name)-1);
-	name[248]='\0';
+	name[248] = '\0';
 	pname = name;
 
-	dbus_message_append_args(message,
-				DBUS_TYPE_STRING, &pname,
-				DBUS_TYPE_INVALID);
-
-	if (dbus_connection_send(connection, message, NULL) == FALSE) {
-		syslog(LOG_ERR, "Can't send D-BUS NameChanged signal");
-		goto failed;
-	}
+	send_property_changed_signal(id, DEV_PROPERTY_NAME, DBUS_TYPE_STRING, &pname);
 	dbus_connection_flush(connection);
 
 failed:
 	if (dd >= 0)
 		close(dd);
-	dbus_message_unref(message);
 	bt_free(local_addr);
 }
 
-static DBusMessage* handle_device_get_propety_req_name(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_get_property_req_name(DBusMessage *msg, void *data)
 {
 	struct hci_dbus_data *dbus_data = data;
 	DBusMessage *reply = NULL;
@@ -2183,6 +2230,184 @@
 	return reply;
 }
 
+static DBusMessage* write_scan_enable(DBusMessage *msg, void *data, gboolean ispscan)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	int dd = -1;
+	read_scan_enable_rp rp;
+	uint8_t enable;
+	uint8_t status;
+	uint8_t scan_change, scan_keep;
+	struct hci_request rq;
+	gboolean prop_value; /* new requested value for the iscan or pscan */
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &prop_value);
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_READ_SCAN_ENABLE;
+	rq.rparam = &rp;
+	rq.rlen   = READ_SCAN_ENABLE_RP_SIZE;
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Sending read scan enable command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (rp.status) {
+		syslog(LOG_ERR, "Getting scan enable failed with status 0x%02x",
+								 	rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + rp.status);
+		goto failed;
+        }
+
+	if (ispscan) { /* Page scan */
+		scan_change = SCAN_PAGE;
+		scan_keep = SCAN_INQUIRY;
+	} else { /* Inquiry scan */
+		scan_change = SCAN_INQUIRY;
+		scan_keep = SCAN_PAGE;
+	}
+
+	/* This is an optimization. We want to avoid overwrite the value
+	if the requested scan property will not change. */
+	if (prop_value && !(rp.enable & scan_change))
+		/* Enable the requested scan type (e.g. page scan). Keep the
+		the other type untouched. */
+		enable = (rp.enable & scan_keep) | scan_change;
+	else if (!prop_value && (rp.enable & scan_change))
+		/* Disable the requested scan type (e.g. page scan). Keep the
+		the other type untouched. */
+		enable = (rp.enable & scan_keep);
+	else { /* Property not changed. Do nothing. Return ok. */
+		reply = dbus_message_new_method_return(msg);
+		goto failed;
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_WRITE_SCAN_ENABLE;
+	rq.cparam = &enable;
+	rq.clen   = sizeof(enable);
+	rq.rparam = &status;
+	rq.rlen   = sizeof(status);
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Sending write scan enable command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+	if (status) {
+		syslog(LOG_ERR, "Setting scan enable failed with status 0x%02x", rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + rp.status);
+		goto failed;
+	}
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+	return reply;
+
+}
+
+void hcid_dbus_setscan_enable_complete(bdaddr_t *local)
+{
+	char *local_addr;
+	char path[MAX_PATH_LENGTH];
+	bdaddr_t tmp;
+	int id;
+	int dd = -1;
+	gboolean se;
+	read_scan_enable_rp rp;
+	struct hci_request rq;
+	struct hci_dbus_data *pdata = NULL;
+	uint32_t old_data;
+
+	baswap(&tmp, local); local_addr = batostr(&tmp);
+	id = hci_devid(local_addr);
+	if (id < 0) {
+		syslog(LOG_ERR, "No matching device id for %s", local_addr);
+		goto failed;
+	}
+
+	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, id);
+
+	dd = hci_open_dev(id);
+	memset(&rq, 0, sizeof(rq));
+
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", id);
+		goto failed;
+	}
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_READ_SCAN_ENABLE;
+	rq.rparam = &rp;
+	rq.rlen   = READ_SCAN_ENABLE_RP_SIZE;
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR,
+			"Sending read scan enable command failed: %s (%d)",
+			strerror(errno), errno);
+		goto failed;
+	}
+	if (rp.status) {
+		syslog(LOG_ERR,
+			"Getting scan enable failed with status 0x%02x",
+			rp.status);
+		goto failed;
+	}
+
+	if (!dbus_connection_get_object_path_data(connection, path, (void*) &pdata)) {
+		syslog(LOG_ERR, "Getting path data failed!");
+		goto failed;
+	}
+
+	old_data = pdata->path_data;
+	pdata->path_data = rp.enable;
+
+	/* If the new page scan flag is different from what we had, send a signal. */
+	if((rp.enable & SCAN_PAGE) != (old_data & SCAN_PAGE)) {
+		se = (rp.enable & SCAN_PAGE);
+		send_property_changed_signal(id, DEV_PROPERTY_PSCAN, DBUS_TYPE_BOOLEAN, &se);
+	}
+	/* If the new inquity scan flag is different from what we had, send a signal. */
+	if ((rp.enable & SCAN_INQUIRY) != (old_data & SCAN_INQUIRY)) {
+		se = (rp.enable & SCAN_INQUIRY);
+		send_property_changed_signal(id, DEV_PROPERTY_ISCAN, DBUS_TYPE_BOOLEAN, &se);
+	}
+
+	dbus_connection_flush(connection);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+	bt_free(local_addr);
+}
+
+static DBusMessage* handle_device_set_property_req_pscan(DBusMessage *msg, void *data)
+{
+	return write_scan_enable(msg, data, TRUE);
+}
+
+static DBusMessage* handle_device_set_property_req_iscan(DBusMessage *msg, void *data)
+{
+	return write_scan_enable(msg, data, FALSE);
+}
+
 static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;
@@ -2328,5 +2553,5 @@
 	syslog(LOG_INFO, "Not Implemented - path %s iface %s method %s",
 							path, iface, method);
 
-	return NULL;
+	return bluez_new_failure_msg(msg, BLUEZ_EDBUS_NOT_IMPLEMENTED);
 }
--- utils.13122005.orig/hcid/dbus-test	2005-11-24 01:10:46.000000000 -0300
+++ utils.13122005/hcid/dbus-test	2005-12-13 14:10:50.000000000 -0300
@@ -14,6 +14,9 @@
              "Connections", "Authenticate", "RoleSwitch" ]
 dev_setprop_bool = [ "auth", "encrypt", "discoverable", "connectable" ]
 dev_setprop_byte = [ "incmode" ]
+dev_prop_filter = ["/org/bluez/Device/hci0", "/org/bluez/Device/hci1",
+                   "/org/bluez/Device/hci2", "/org/bluez/Device/hci3",
+                   "/org/bluez/Device/hci4", "/org/bluez/Device/hci5"]
 
 class Tester:
     exit_events = []
@@ -81,10 +84,10 @@
 
                 self.dev.connect_to_signal('Up', self.dev_up)
                 self.dev.connect_to_signal('Down', self.dev_down)
-                self.bus.add_signal_receiver(self.dev_name_changed, 'DeviceNameChanged',
-                                             'org.bluez.Device', 'org.bluez',
-                                             '/org/bluez/Device/hci0')
-
+                for path in dev_prop_filter:
+                    self.bus.add_signal_receiver(self.dev_property_changed,
+                                             'PropertyChanged','org.bluez.Device',
+                                             'org.bluez',path)
                 obj = self.bus.get_object('org.bluez', '%s/Controller' % self.dev_path)
                 self.ctl = dbus.Interface(obj, 'org.bluez.Device.Controller')
 
@@ -157,10 +160,17 @@
         print 'Down'
 
     @dbus.decorators.explicitly_pass_message
-    def dev_name_changed(*args, **keywords):
-        name = args[1]
+    def dev_property_changed(*args, **keywords):
+        property = args[1]
+        param = args[2]
         dbus_message = keywords["dbus_message"]
-        print 'Device %s name changed: %s' % (dbus_message.get_path(), name)
+        if property == 'name':
+            print 'Device %s name changed: %s' % (dbus_message.get_path(), param)
+        elif property == 'connectable':
+            print 'Device %s connectable scan property changed: %d' % (dbus_message.get_path(), param)
+        elif property == 'discoverable':
+            print 'Device %s discoverable scan property changed: %d' % (dbus_message.get_path(), param)
+
 
     def signal_cb(self, sig, frame):
         print 'Caught signal, exiting'

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-12-14 19:02                                                           ` Eduardo Rocha
@ 2005-12-16 18:37                                                             ` Eduardo Rocha
  2005-12-16 18:40                                                               ` Marcel Holtmann
  0 siblings, 1 reply; 37+ messages in thread
From: Eduardo Rocha @ 2005-12-16 18:37 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 3862 bytes --]

Hi Marcel,

here is the patch for set auth enable. This patch should be applied
after the last scan patch. Let me know if there is any problem.

BR,
Eduardo

On 12/14/05, Eduardo Rocha <folhabranca@gmail.com> wrote:
> Hi Marcel,
>
> here is the new patch.
>
> BR,
> Eduardo.
>
>
> On 12/13/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> > Hi Eduardo,
> >
> > > here is the patch with the send_property_changed_signal function included.
> >
> > nice, but please follow the coding style. I don't wanna correct the
> > whitespaces in all patches. Some examples what should be changed:
> >
> > (void*)&pdata                           ==> (void *) &pdata
> > = SCAN_PAGE|SCAN_INQUIRY;               ==> = SCAN_PAGE | SCAN_INQUIRY;
> > se = (rp.enable & SCAN_PAGE)?1:0;       se = (rp.enable & SCAN_PAGE) ? 1 : 0;
> >
> > This is also bad coding style:
> >
> >        if (dd < 0) {
> >                syslog(LOG_ERR, "HCI device open failed: hci%d", id);
> >                goto failed;
> >        } else {
> >
> > We don't need the else branch. I results in an needless indentation.
> >
> > I also think that we need some more newlines in your code, but I am
> > going to fix it when applying the patch.
> >
> > This part might work, but I don't like it:
> >
> >        if (ispscan) {
> >                if (scan && !(rp.enable & SCAN_PAGE))
> >                        enable = (rp.enable & SCAN_INQUIRY) | SCAN_PAGE;
> >                else if (!scan && (rp.enable & SCAN_PAGE))
> >                        enable = (rp.enable & SCAN_INQUIRY);
> >                else {
> >                        reply = dbus_message_new_method_return(msg);
> >                        goto failed;
> >                }
> >        } else {
> >                if (scan && !(rp.enable & SCAN_INQUIRY))
> >                        enable = (rp.enable & SCAN_PAGE) | SCAN_INQUIRY;
> >                else if (!scan && (rp.enable & SCAN_INQUIRY))
> >                        enable = (rp.enable & SCAN_PAGE);
> >                else {
> >                        reply = dbus_message_new_method_return(msg);
> >                        goto failed;
> >                }
> >        }
> >
> > And this includes this:
> >
> >        if((rp.enable & SCAN_PAGE) != (old_data & SCAN_PAGE)) {
> >                se = (rp.enable & SCAN_PAGE)?1:0;
> >                send_property_changed_signal(id, DEV_PROPERTY_PSCAN, DBUS_TYPE_BOOLEAN, &se);
> >        }
> >        if ((rp.enable & SCAN_INQUIRY) != (old_data & SCAN_INQUIRY)) {
> >                se = (rp.enable & SCAN_INQUIRY)?1:0;
> >                send_property_changed_signal(id, DEV_PROPERTY_ISCAN, DBUS_TYPE_BOOLEAN, &se);
> >        }
> >        dbus_connection_flush(connection);
> >
> > I don't have any better idea to solve this at the moment, but if you
> > read this code it takes too much time too understand what it is actually
> > doing. And normally this is not a good idea. However we might fix it
> > later and get the patch in now for further testing. So please correct
> > the other parts and resend it.
> >
> > Regards
> >
> > Marcel
> >
> >
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> > for problems?  Stop!  Download the new AJAX search engine that makes
> > searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> > http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> > _______________________________________________
> > Bluez-devel mailing list
> > Bluez-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/bluez-devel
> >
>
>
> --
> Eduardo Rocha
> Instituto Nokia de Tecnologia - INdT
>
>
>


--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: dbus_device_auth.patch --]
[-- Type: text/x-patch, Size: 7133 bytes --]

--- utils.15122005.orig/hcid/hcid.h	2005-12-15 10:38:12.000000000 -0300
+++ utils.15122005/hcid/hcid.h	2005-12-15 12:13:31.000000000 -0300
@@ -136,6 +136,7 @@
 void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status);
 void hcid_dbus_setname_complete(bdaddr_t *local);
 void hcid_dbus_setscan_enable_complete(bdaddr_t *local);
+void hcid_dbus_setauth_enable_complete(bdaddr_t *local);
 #else
 static inline void hcid_dbus_inquiry_start(bdaddr_t *local) {}
 static inline void hcid_dbus_inquiry_complete(bdaddr_t *local) {}
@@ -147,6 +148,7 @@
 static inline void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status) {}
 static inline void hcid_dbus_setname_complete(bdaddr_t *local) {}
 static inline void hcid_dbus_setscan_enable_complete(bdaddr_t *local) {}
+static inline void hcid_dbus_setauth_enable_complete(bdaddr_t *local) {}
 #endif
 
 int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name);
--- utils.15122005.orig/hcid/security.c	2005-12-15 10:38:12.000000000 -0300
+++ utils.15122005/hcid/security.c	2005-12-15 12:15:00.000000000 -0300
@@ -500,6 +500,10 @@
 		break;
 	case cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE):
 		hcid_dbus_setscan_enable_complete(sba);
+		break;
+	case cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_AUTH_ENABLE):
+		hcid_dbus_setauth_enable_complete(sba);
+		break;
 	};
 }
 
--- utils.15122005.orig/hcid/dbus.h	2005-12-15 10:38:12.000000000 -0300
+++ utils.15122005/hcid/dbus.h	2005-12-15 12:11:46.000000000 -0300
@@ -131,7 +131,7 @@
 #define DEV_PROPERTY_PSCAN		"connectable"
 #define DEV_PROPERTY_ISCAN		"discoverable"
 #define DEV_PROPERTY_NAME		"name"
-#define DEV_PROPERTY_INCMODE		"incmode"
+#define DEV_PROPERTY_INCMODE		"inqmode"
 #define DEV_PROPERTY_DEV_INFO		"info"
 
 #define DEV_UP_SIGNATURE			__END_SIG__
--- utils.15122005.orig/hcid/dbus.c	2005-12-15 10:38:12.000000000 -0300
+++ utils.15122005/hcid/dbus.c	2005-12-16 12:24:29.000000000 -0300
@@ -112,6 +112,12 @@
 	unsigned int val;
 } hci_map;
 
+typedef struct {
+	uint8_t status;
+	uint8_t enable;
+} __attribute__ ((packed)) read_auth_enable_rp;
+#define READ_AUTH_ENABLE_RP_SIZE 2
+
 static hci_map dev_flags_map[] = {
 	{ "INIT",	HCI_INIT	},
 	{ "RUNNING",	HCI_RUNNING	},
@@ -278,6 +284,7 @@
 static DBusMessage* handle_device_get_property_req_name(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_set_property_req_pscan(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_set_property_req_iscan(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req_auth(DBusMessage *msg, void *data);
 
 static const struct service_data device_services[] = {
 	{ DEV_UP,		handle_device_up_req,		DEV_UP_SIGNATURE		},
@@ -290,7 +297,7 @@
 };
 
 static const struct service_data set_property_services[] = {
-	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
+	{ DEV_PROPERTY_AUTH,		handle_device_set_property_req_auth,	DEV_SET_PROPERTY_SIGNATURE_BOOL		},
 	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
 	{ DEV_PROPERTY_PSCAN,		handle_device_set_property_req_pscan,	DEV_SET_PROPERTY_SIGNATURE_BOOL		},
 	{ DEV_PROPERTY_ISCAN,		handle_device_set_property_req_iscan,	DEV_SET_PROPERTY_SIGNATURE_BOOL		},
@@ -2241,7 +2248,7 @@
 	uint8_t status;
 	uint8_t scan_change, scan_keep;
 	struct hci_request rq;
-	gboolean prop_value; /* new requested value for the iscan or pscan */
+	dbus_bool_t prop_value; /* new requested value for the iscan or pscan */
 
 	dbus_message_iter_init(msg, &iter);
 	dbus_message_iter_next(&iter);
@@ -2332,7 +2339,7 @@
 	bdaddr_t tmp;
 	int id;
 	int dd = -1;
-	gboolean se;
+	dbus_bool_t se;
 	read_scan_enable_rp rp;
 	struct hci_request rq;
 	struct hci_dbus_data *pdata = NULL;
@@ -2408,6 +2415,130 @@
 	return write_scan_enable(msg, data, FALSE);
 }
 
+static DBusMessage* handle_device_set_property_req_auth(DBusMessage *msg, void *data)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	int dd = -1;
+	uint8_t enable;
+	uint8_t status;
+	struct hci_request rq;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &enable);
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_WRITE_AUTH_ENABLE;
+	rq.cparam = &enable;
+	rq.clen   = sizeof(enable);
+	rq.rparam = &status;
+	rq.rlen   = sizeof(status);
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Sending auth enable command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (status) {
+		syslog(LOG_ERR, "Enable authentication command failed with status 0x%02x",
+								 	status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + status);
+		goto failed;
+        }
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+	return reply;
+}
+
+void hcid_dbus_setauth_enable_complete(bdaddr_t *local)
+{
+	DBusMessage *message = NULL;
+	char *local_addr;
+	char path[MAX_PATH_LENGTH];
+	char *ppath = path;
+	bdaddr_t tmp;
+	int id;
+	int dd = -1;
+	read_auth_enable_rp rp;
+	struct hci_request rq;
+	dbus_bool_t outparam;
+
+	baswap(&tmp, local); local_addr = batostr(&tmp);
+	id = hci_devid(local_addr);
+	if (id < 0) {
+		syslog(LOG_ERR, "No matching device id for %s", local_addr);
+		goto failed;
+	}
+
+	snprintf(path, sizeof(path) - 1, "%s/hci%d", DEVICE_PATH, id);
+	path[MAX_PATH_LENGTH-1]='\0';
+
+	dd = hci_open_dev(id);
+	memset(&rq, 0, sizeof(rq));
+
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", id);
+		goto failed;
+	}
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_READ_AUTH_ENABLE;
+	rq.rparam = &rp;
+	rq.rlen   = READ_AUTH_ENABLE_RP_SIZE;
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR,
+			"Sending read auth enable command failed: %s (%d)",
+			strerror(errno), errno);
+		goto failed;
+	}
+	if (rp.status) {
+		syslog(LOG_ERR,
+			"Getting auth enable failed with status 0x%02x",
+			rp.status);
+		goto failed;
+	}
+
+	message = dbus_message_new_signal(path, DEVICE_INTERFACE,
+						BLUEZ_HCI_PROPERTY_CHANGED);
+	if (message == NULL) {
+		syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
+		goto failed;
+	}
+
+	strcpy(path, DEV_PROPERTY_AUTH);
+	outparam = rp.enable;
+	dbus_message_append_args(message,
+				DBUS_TYPE_STRING, &ppath,
+				DBUS_TYPE_BOOLEAN, &outparam,
+				DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send(connection, message, NULL) == FALSE) {
+		syslog(LOG_ERR, "Can't send D-BUS PropertChanged(%s) signal", DEV_PROPERTY_AUTH);
+		goto failed;
+	}
+
+	dbus_connection_flush(connection);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+	bt_free(local_addr);
+}
+
 static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Bluez-devel] [DBUS Patch] Device Property
  2005-12-16 18:37                                                             ` Eduardo Rocha
@ 2005-12-16 18:40                                                               ` Marcel Holtmann
  0 siblings, 0 replies; 37+ messages in thread
From: Marcel Holtmann @ 2005-12-16 18:40 UTC (permalink / raw)
  To: bluez-devel

Hi Eduardo,

> here is the patch for set auth enable. This patch should be applied
> after the last scan patch. Let me know if there is any problem.

we don't need to set auth or encrypt at all, because the support for
setting a device into Security Mode 3 from within the D-Bus interface is
useless.

Regards

Marcel




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2005-12-16 18:40 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-04 14:03 [Bluez-devel] [DBUS Patch] Device Property Eduardo Rocha
2005-11-04 15:44 ` Marcel Holtmann
2005-11-08 20:41   ` Claudio Takahasi
2005-11-08 22:20     ` Marcel Holtmann
2005-11-08 22:20     ` Johan Hedberg
2005-11-08 22:38       ` Marcel Holtmann
2005-11-17 19:16         ` Eduardo Rocha
2005-11-17 20:52           ` Eduardo Rocha
2005-11-18  8:28             ` Johan Hedberg
2005-11-18 10:51               ` Eduardo Rocha
2005-11-18 11:26                 ` Johan Hedberg
2005-11-18 13:00                   ` Eduardo Rocha
2005-11-22 11:51                     ` Marcel Holtmann
2005-11-22 19:52                       ` Eduardo Rocha
2005-11-24  4:17                         ` Marcel Holtmann
2005-11-24 18:50                           ` Eduardo Rocha
2005-11-24 22:54                             ` Marcel Holtmann
2005-11-25 13:47                               ` Claudio Takahasi
2005-11-25 14:32                                 ` Eduardo Rocha
2005-11-25 18:08                                 ` Marcel Holtmann
2005-11-25 18:34                                   ` Eduardo Rocha
2005-11-25 18:41                                     ` Marcel Holtmann
2005-11-25 19:52                                       ` Claudio Takahasi
2005-11-25 20:06                                         ` Marcel Holtmann
2005-12-01 16:55                                           ` Eduardo Rocha
2005-12-01 21:05                                             ` Marcel Holtmann
2005-12-07 12:29                                               ` Eduardo Rocha
2005-12-07 12:55                                                 ` Johan Hedberg
2005-12-07 13:02                                                   ` Marcel Holtmann
2005-12-07 16:01                                                     ` Eduardo Rocha
2005-12-13 17:27                                                       ` Eduardo Rocha
2005-12-13 22:03                                                         ` Marcel Holtmann
2005-12-14 19:02                                                           ` Eduardo Rocha
2005-12-16 18:37                                                             ` Eduardo Rocha
2005-12-16 18:40                                                               ` Marcel Holtmann
2005-11-25 16:51                               ` Johan Hedberg
2005-11-25 18:12                                 ` Marcel Holtmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.