linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Bluez-devel] [DBUS PATCH] SetMinorClass
@ 2006-02-23 14:35 Claudio Takahasi
  2006-02-23 17:18 ` Marcel Holtmann
  2006-02-23 19:05 ` Marcel Holtmann
  0 siblings, 2 replies; 3+ messages in thread
From: Claudio Takahasi @ 2006-02-23 14:35 UTC (permalink / raw)
  To: bluez-devel

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

Hi Marcel,

Here is the patch to set the computer minor class.

Regards,
Claudio.
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: set-minor01.patch --]
[-- Type: text/x-patch, Size: 3929 bytes --]

Index: hcid/dbus-device.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-device.c,v
retrieving revision 1.10
diff -u -r1.10 dbus-device.c
--- hcid/dbus-device.c	22 Feb 2006 23:41:17 -0000	1.10
+++ hcid/dbus-device.c	23 Feb 2006 14:33:17 -0000
@@ -41,6 +41,16 @@
 
 #include "textfile.h"
 
+static const char *computer_minor_cls[] = {
+	"uncategorized",
+	"desktop",
+	"server",
+	"laptop",
+	"handheld",
+	"palm",
+	"wearable"
+};
+
 static char *get_peer_name(const bdaddr_t *local, const bdaddr_t *peer)
 {
 	char filename[PATH_MAX + 1], addr[18];
@@ -343,6 +353,67 @@
 	return reply;
 }
 
+static DBusMessage* handle_dev_set_minor_class_req(DBusMessage *msg, void *data)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessage *reply = NULL;
+	DBusMessageIter iter;
+	const char *minor;
+	int dd = -1, i;
+	uint8_t cls[3];
+	uint32_t minor_value = 0xFFFFFFFF;
+
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_get_basic(&iter, &minor);
+
+	if (!minor)
+		return bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
+
+	/* FIXME: currently, only computer minor classes are allowed */
+	for (i = 0; i < sizeof(computer_minor_cls)/sizeof(*computer_minor_cls); i++) {
+		if (strcasecmp(minor, computer_minor_cls[i]) == 0) {
+			/* remove the format type */
+			minor_value = i << 2;
+			break;
+		}
+	}
+
+	/* check if it's a valid minor class */
+	if (minor_value == 0xFFFFFFFF) {
+		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);
+		return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+	}
+
+	if (hci_read_class_of_dev(dd, cls, 1000) < 0) {
+		syslog(LOG_ERR, "Can't read class of device on hci%d: %s(%d)",
+		       			dbus_data->dev_id, strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | errno);
+		goto failed;
+	}
+
+	minor_value |= (cls[2] << 16) | (cls[1] << 8);
+
+	if (hci_write_class_of_dev(dd, minor_value, 2000) < 0) {
+		syslog(LOG_ERR, "Can't write class of device on hci%d: %s(%d)",
+		       			dbus_data->dev_id, strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | errno);
+		goto failed;
+
+	}
+
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	return reply;
+}
+
 static DBusMessage* handle_dev_set_mode_req(DBusMessage *msg, void *data)
 {
 	const struct hci_dbus_data *dbus_data = data;
@@ -818,6 +889,7 @@
 
 	{ DEV_SET_CLASS,		handle_dev_set_class_req,		DEV_SET_CLASS_SIGNATURE			},
 	{ DEV_SET_DISCOVERABLE_TO,	handle_dev_set_discoverable_to_req,	DEV_SET_DISCOVERABLE_TO_SIGNATURE	},
+	{ DEV_SET_MINOR_CLASS,		handle_dev_set_minor_class_req,		DEV_SET_MINOR_CLASS_SIGNATURE		},
 	{ DEV_SET_MODE,			handle_dev_set_mode_req,		DEV_SET_MODE_SIGNATURE			},
 	{ DEV_SET_NAME,			handle_dev_set_name_req,		DEV_SET_NAME_SIGNATURE			},
 
Index: hcid/dbus.h
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus.h,v
retrieving revision 1.28
diff -u -r1.28 dbus.h
--- hcid/dbus.h	22 Feb 2006 23:41:17 -0000	1.28
+++ hcid/dbus.h	23 Feb 2006 14:33:17 -0000
@@ -121,6 +121,7 @@
 #define DEV_IS_DISCOVERABLE		"IsDiscoverable"
 #define DEV_SET_CLASS			"SetClass"
 #define DEV_SET_DISCOVERABLE_TO		"SetDiscoverableTimeout"
+#define DEV_SET_MINOR_CLASS		"SetMinorClass"
 #define DEV_SET_MODE			"SetMode"
 #define DEV_SET_NAME			"SetName"
 #define DEV_DISCOVER			"Discover"
@@ -158,6 +159,8 @@
 							__END_SIG__
 #define DEV_SET_DISCOVERABLE_TO_SIGNATURE		DBUS_TYPE_UINT32_AS_STRING \
 							__END_SIG__
+#define DEV_SET_MINOR_CLASS_SIGNATURE			DBUS_TYPE_STRING_AS_STRING \
+							__END_SIG__
 #define DEV_SET_MODE_SIGNATURE				DBUS_TYPE_STRING_AS_STRING \
 							__END_SIG__
 #define DEV_SET_NAME_SIGNATURE				DBUS_TYPE_STRING_AS_STRING \

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

* Re: [Bluez-devel] [DBUS PATCH] SetMinorClass
  2006-02-23 14:35 [Bluez-devel] [DBUS PATCH] SetMinorClass Claudio Takahasi
@ 2006-02-23 17:18 ` Marcel Holtmann
  2006-02-23 19:05 ` Marcel Holtmann
  1 sibling, 0 replies; 3+ messages in thread
From: Marcel Holtmann @ 2006-02-23 17:18 UTC (permalink / raw)
  To: bluez-devel

Hi Claudio,

> Here is the patch to set the computer minor class.

I changing the variable naming a little bit and added a missing
hci_close_dev() command.

Regards

Marcel




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

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

* Re: [Bluez-devel] [DBUS PATCH] SetMinorClass
  2006-02-23 14:35 [Bluez-devel] [DBUS PATCH] SetMinorClass Claudio Takahasi
  2006-02-23 17:18 ` Marcel Holtmann
@ 2006-02-23 19:05 ` Marcel Holtmann
  1 sibling, 0 replies; 3+ messages in thread
From: Marcel Holtmann @ 2006-02-23 19:05 UTC (permalink / raw)
  To: bluez-devel

Hi Claudio,

> Here is the patch to set the computer minor class.

can I also get a patch for reading the minor class?

Regards

Marcel




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

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

end of thread, other threads:[~2006-02-23 19:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-23 14:35 [Bluez-devel] [DBUS PATCH] SetMinorClass Claudio Takahasi
2006-02-23 17:18 ` Marcel Holtmann
2006-02-23 19:05 ` Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).