linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Bluez-devel] hcid patch (remote name and connections)
@ 2005-10-11 14:26 Claudio Takahasi
  2005-10-11 14:49 ` [Bluez-devel] " Claudio Takahasi
  2005-10-11 18:01 ` [Bluez-devel] " Marcel Holtmann
  0 siblings, 2 replies; 14+ messages in thread
From: Claudio Takahasi @ 2005-10-11 14:26 UTC (permalink / raw)
  To: bluez-devel


[-- Attachment #1.1: Type: text/plain, Size: 371 bytes --]

Hi folks/Marcel,

I added the support to remote name and display connections.
This patch is based on dbus.c revision 1.20

There is a command line client attached to test the added services.

Regards,
Claudio

--
---------------------------------------------------------
Claudio Takahasi
Nokia's Institute of Technology - INdT
claudio.takahasi@indt.org.br

[-- Attachment #1.2: Type: text/html, Size: 500 bytes --]

[-- Attachment #2: bluez-hcid-dbus-client.tar.gz --]
[-- Type: application/x-gzip, Size: 388546 bytes --]

[-- Attachment #3: rem_name_connections_01.patch --]
[-- Type: application/octet-stream, Size: 7599 bytes --]

--- bluez-utils-cvs.orig/hcid/dbus.h	2005-10-09 19:15:22.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.h	2005-10-10 17:37:57.000000000 -0300
@@ -122,6 +122,8 @@
 #define HCI_CANCEL_PERIODIC_INQ		"CancelPeriodic"
 #define HCI_INQ				"Inquiry"
 #define HCI_ROLE_SWITCH			"RoleSwitch"
+#define HCI_REMOTE_NAME			"RemoteName"
+#define HCI_CONNECTIONS			"Connections"
 
 
 #define HCI_PERIODIC_INQ_SIGNATURE			DBUS_TYPE_BYTE_AS_STRING\
@@ -139,6 +141,21 @@
 #define HCI_ROLE_SWITCH_SIGNATURE			DBUS_TYPE_STRING_AS_STRING\
 							DBUS_TYPE_BYTE_AS_STRING\
 							__END_SIG__
+							
+#define HCI_REMOTE_NAME_SIGNATURE			DBUS_TYPE_STRING_AS_STRING\
+							__END_SIG__
+							
+#define HCI_CONNECTIONS_SIGNATURE			__END_SIG__
+
+#define HCI_CONN_INFO_STRUCT_SIGNATURE			DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
+							DBUS_TYPE_UINT16_AS_STRING\
+							DBUS_TYPE_STRING_AS_STRING\
+							DBUS_TYPE_BYTE_AS_STRING\
+							DBUS_TYPE_BYTE_AS_STRING\
+							DBUS_TYPE_UINT16_AS_STRING\
+							DBUS_TYPE_UINT32_AS_STRING\
+							DBUS_STRUCT_END_CHAR_AS_STRING\
+							__END_SIG__
 
 #define HCI_DEVICE_STRUCT_SIGNATURE			DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
 							DBUS_TYPE_STRING_AS_STRING\
--- bluez-utils-cvs.orig/hcid/dbus.c	2005-10-11 11:10:21.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.c	2005-10-11 11:20:40.000000000 -0300
@@ -58,6 +58,7 @@
 #define BLUETOOTH_DEVICE_NAME_LEN    (18)
 #define BLUETOOTH_DEVICE_ADDR_LEN    (18)
 #define MAX_PATH_LENGTH   (64)
+#define READ_REMOTE_NAME_TIMEOUT	25000
 
 #define PINAGENT_SERVICE_NAME BASE_INTERFACE ".PinAgent"
 #define PINAGENT_INTERFACE PINAGENT_SERVICE_NAME
@@ -125,14 +126,12 @@
 
 	if (ecode & BLUEZ_ESYSTEM_OFFSET) {
 		/* System error */
-		raw_code = (!BLUEZ_ESYSTEM_OFFSET) & ecode;
-		syslog(LOG_INFO, "%s - msg:%s", __PRETTY_FUNCTION__, strerror(raw_code));
+		raw_code = (~BLUEZ_ESYSTEM_OFFSET) & ecode;
 		return strerror(raw_code);
 	} else if (ecode & BLUEZ_EDBUS_OFFSET) { 
 		/* D-Bus error */
 		for (ptr = error_array; ptr->code; ptr++) {
 			if (ptr->code == ecode) {
-				syslog(LOG_INFO, "%s - msg:%s", __PRETTY_FUNCTION__, ptr->str);
 				return ptr->str;
 			}
 		}
@@ -217,12 +216,16 @@
 static DBusMessage* handle_cancel_periodic_inq_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_inq_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_role_switch_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_remote_name_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_display_conn_req(DBusMessage *msg, void *data);
 
 static const struct service_data hci_services[] = {
 	{ HCI_PERIODIC_INQ,		handle_periodic_inq_req,	HCI_PERIODIC_INQ_SIGNATURE		},
 	{ HCI_CANCEL_PERIODIC_INQ,	handle_cancel_periodic_inq_req,	HCI_CANCEL_PERIODIC_INQ_SIGNATURE	},
 	{ HCI_ROLE_SWITCH,		handle_role_switch_req,		HCI_ROLE_SWITCH_SIGNATURE		},
 	{ HCI_INQ,			handle_inq_req,			HCI_INQ_SIGNATURE			},
+	{ HCI_REMOTE_NAME,		handle_remote_name_req,		HCI_REMOTE_NAME_SIGNATURE		},
+	{ HCI_CONNECTIONS,		handle_display_conn_req,	HCI_CONNECTIONS_SIGNATURE		},
 	{ NULL,				NULL,				NULL					}
 };
 
@@ -838,7 +841,6 @@
 	signature = dbus_message_get_signature(msg);
 
 	syslog (LOG_INFO, "%s - path:%s, udata:0x%X", __PRETTY_FUNCTION__, path, (guint) udata);
-
 	if (strcmp(path, DEVICE_PATH) == 0) {
 		ptr_handlers = dev_services;
 		tmp_iface = DEVICE_INTERFACE;
@@ -898,17 +900,18 @@
 			reply = bluez_new_failure_msg(msg, result);
 		}
 
-		/* send an error or the success reply*/
-		if (reply) {
-			if (!dbus_connection_send (conn, reply, NULL)) { 
-				syslog(LOG_ERR, "%s line:%d Can't send reply message!",
-					__PRETTY_FUNCTION__, __LINE__) ;
-			}
-			dbus_message_unref (reply);
-		}
 
 		ret = DBUS_HANDLER_RESULT_HANDLED;
 	}
+
+	/* send an error or the success reply*/
+	if (reply) {
+		if (!dbus_connection_send (conn, reply, NULL)) { 
+			syslog(LOG_ERR, "Can't send reply message!");
+		}
+		dbus_message_unref (reply);
+	}
+	
 	return ret;
 }
 
@@ -1162,6 +1165,126 @@
 	return reply;
 }
 
+static DBusMessage* handle_remote_name_req(DBusMessage *msg, void *data)
+{
+	char name[64];
+	const char *pname = name;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	long udata = (long) data;
+	int dev_id = -1;
+	int dd = -1;
+	const char *str_bdaddr;
+	bdaddr_t bdaddr;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_get_basic(&iter, &str_bdaddr);
+	
+	str2ba(str_bdaddr, &bdaddr);
+
+	if (udata == DEFAULT_DEVICE_PATH_ID) {
+		if ((dev_id = hci_get_route(&bdaddr)) < 0) {
+			syslog(LOG_ERR, "Bluetooth device is not available");
+			reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+			goto failed;
+		}
+	} else  {
+		dev_id = (int) udata;
+	}
+
+	if ((dd = hci_open_dev(dev_id)) > 0) {
+	
+		if (hci_read_remote_name(dd, &bdaddr, sizeof(name), name, READ_REMOTE_NAME_TIMEOUT) ==0) {
+			reply = dbus_message_new_method_return(msg);
+			dbus_message_iter_init_append(reply, &iter);
+			dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &pname);
+		} else {
+			reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		}
+	} else {
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+	}
+	
+	if (dd > 0)
+		close (dd);
+
+failed:
+	return reply;
+}
+
+static DBusMessage* handle_display_conn_req(DBusMessage *msg, void *data)
+{
+	struct hci_conn_list_req *cl = NULL;
+	struct hci_conn_info *ci = NULL;
+	DBusMessage *reply = NULL;
+	DBusMessageIter iter;
+	DBusMessageIter array_iter;
+	DBusMessageIter  struct_iter;
+	char addr[18];
+	const char array_sig[] = HCI_CONN_INFO_STRUCT_SIGNATURE;
+	const char *paddr = addr;
+	long udata = (long) data;
+	int i;
+	int dev_id = -1;
+	int sk;
+
+	if (udata == DEFAULT_DEVICE_PATH_ID) {
+		if ((dev_id = hci_get_route(NULL)) < 0) {
+			syslog(LOG_ERR, "Bluetooth device is not available");
+			reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+			goto failed;
+		}
+	} else  {
+		dev_id = (int) udata;
+	}
+
+	sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+
+	if (sk < 0) {
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (!(cl = malloc(10 * sizeof(*ci) + sizeof(*cl)))) { 
+		reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
+		goto failed;
+	}
+
+	cl->dev_id = dev_id;
+	cl->conn_num = 10;
+	ci = cl->conn_info;
+
+	if (ioctl(sk, HCIGETCONNLIST, (void *) cl)) {
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	reply = dbus_message_new_method_return(msg);
+	dbus_message_iter_init_append(reply, &iter);
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, array_sig, &array_iter);
+	
+	for (i = 0; i < cl->conn_num; i++, ci++) {
+		ba2str(&ci->bdaddr, addr);
+
+		dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter);
+		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT16 ,&(ci->handle));
+		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING ,&paddr);
+		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_BYTE ,&(ci->type));
+		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_BYTE ,&(ci->out));
+		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT16 ,&(ci->state));
+		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT32 ,&(ci->link_mode));
+		dbus_message_iter_close_container(&array_iter, &struct_iter);
+	}
+	
+	dbus_message_iter_close_container(&iter, &array_iter);
+failed:
+
+	if (cl)
+		free (cl);
+	
+	return reply;
+}
+
 /*****************************************************************
  *  
  *  Section reserved to Device D-Bus message handlers

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

end of thread, other threads:[~2005-10-13  9:38 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-11 14:26 [Bluez-devel] hcid patch (remote name and connections) Claudio Takahasi
2005-10-11 14:49 ` [Bluez-devel] " Claudio Takahasi
2005-10-11 19:47   ` Steven Singer
2005-10-11 20:07     ` Claudio Takahasi
2005-10-11 21:14       ` Steven Singer
2005-10-11 22:37         ` Marcel Holtmann
2005-10-11 18:01 ` [Bluez-devel] " Marcel Holtmann
2005-10-11 19:28   ` Johan Hedberg
2005-10-11 19:45     ` Steven Singer
2005-10-11 19:55       ` Johan Hedberg
2005-10-11 22:48         ` Marcel Holtmann
2005-10-12 19:38           ` Johan Hedberg
2005-10-12 21:14             ` Claudio Takahasi
2005-10-13  9:38               ` 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).