linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Bluez-devel] [D-BUS PATCH] Authentication
@ 2005-10-20 17:45 Claudio Takahasi
  2005-10-22 13:08 ` Marcel Holtmann
  0 siblings, 1 reply; 13+ messages in thread
From: Claudio Takahasi @ 2005-10-20 17:45 UTC (permalink / raw)
  To: bluez-devel; +Cc: Claudio Takahasi


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

Hi folks,

This is the initial patch to support authentication. There are improving
points
that I am planning send soon if everybody agree with my proposal.

The authentication function of this patch is not checking the authentication

complete event status. Clients should not use a blocking send method because

NO reply is being sent if the hci_send_req returns success.

There two possible solutions:
1. Change the security.c file to filter for authentication event and send a
SIGNAL with the bdaddr and the status
1. Change the security.c file to filter for authentication event and send a
METHOD REPLY with the bdaddr and the status. For this case will be required
keep the method_call message received in the service request.

>>>How test it:
- remove the linkkeys file :)
- use hcitool cc AA:BB:CC:DD:EE:FF to establish a connection
- send the D-BUS msg
$ dbus-send --system --dest='org.bluez' --type=method_call
/org/bluez/Manager/default/Controller
org.bluez.Manager.Authenticatestring:"AA:BB:CC:DD:EE:FF"

>>> Next action:
1. Change the reply
2. Change the pin helper to avoid blocking operation. Pipe should be
avoided. Maybe it's
possible add the file descriptor in the main loop instead of wait for data.
3. Support for re-authentication - It will be required add functions to
remove an entry from
the linkkey file.


Regards,
Claudio.

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

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

[-- Attachment #2: auth_01.patch --]
[-- Type: application/octet-stream, Size: 3855 bytes --]

--- bluez-utils-cvs.orig/hcid/dbus.h	2005-10-19 16:48:36.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.h	2005-10-20 14:20:21.000000000 -0200
@@ -128,6 +128,7 @@
 #define HCI_ROLE_SWITCH			"RoleSwitch"
 #define HCI_REMOTE_NAME			"RemoteName"
 #define HCI_CONNECTIONS			"Connections"
+#define HCI_AUTHENTICATE			"Authenticate"
 
 
 #define HCI_PERIODIC_INQ_SIGNATURE			DBUS_TYPE_BYTE_AS_STRING\
@@ -172,6 +173,9 @@
 							DBUS_STRUCT_END_CHAR_AS_STRING\
 							__END_SIG__
 
+#define HCI_AUTHENTICATE_SIGNATURE			DBUS_TYPE_STRING_AS_STRING\
+							__END_SIG__
+
 
 /* BLUEZ_DBUS_ERROR 
  * EFailed error messages signature is : su
--- bluez-utils-cvs.orig/hcid/dbus.c	2005-10-19 16:48:15.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.c	2005-10-20 14:18:57.000000000 -0200
@@ -225,6 +225,7 @@
 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 DBusMessage* handle_auth_req(DBusMessage *msg, void *data);
 
 static const struct service_data hci_services[] = {
 	{ HCI_PERIODIC_INQ,		handle_periodic_inq_req,	HCI_PERIODIC_INQ_SIGNATURE		},
@@ -233,6 +234,7 @@
 	{ 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		},
+	{ HCI_AUTHENTICATE,		handle_auth_req,		HCI_AUTHENTICATE_SIGNATURE		},
 	{ NULL,				NULL,				NULL					}
 };
 
@@ -1443,6 +1445,92 @@
 	return reply;
 }
 
+static DBusMessage* handle_auth_req(DBusMessage *msg, void *data)
+{
+	struct hci_request rq;
+	auth_requested_cp cp;
+	evt_cmd_status rp;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	char *str_bdaddr = NULL;
+	struct hci_dbus_data *dbus_data = data;
+	struct hci_conn_info_req *cr = NULL;
+	bdaddr_t bdaddr;
+	int dev_id = -1;
+	int sock = -1;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_get_basic(&iter, &str_bdaddr);
+	str2ba(str_bdaddr, &bdaddr);
+
+	dev_id = hci_for_each_dev(HCI_UP, find_conn, (long) &bdaddr);
+
+	if (dev_id < 0) {
+		reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_CONN_NOT_FOUND);
+		goto failed;
+	}
+
+	if (dbus_data->id != DEFAULT_DEVICE_PATH_ID && dbus_data->id != dev_id) {
+		reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_CONN_NOT_FOUND);
+		goto failed;
+	}
+
+	sock = hci_open_dev(dev_id);
+	if (sock < 0) {
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+
+	cr = malloc(sizeof(*cr) + sizeof(struct hci_conn_info));
+	if (!cr) {
+		reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
+		goto failed;
+	}
+
+	bacpy(&cr->bdaddr, &bdaddr);
+	cr->type = ACL_LINK;
+
+	if (ioctl(sock, HCIGETCONNINFO, (unsigned long) cr) < 0) {
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	memset(&cp, 0, sizeof(cp));
+	cp.handle = cr->conn_info->handle;
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf = OGF_LINK_CTL;
+	rq.ocf = OCF_AUTH_REQUESTED;
+	rq.cparam = &cp;
+	rq.clen = AUTH_REQUESTED_CP_SIZE;
+	rq.rparam = &rp;
+	rq.rlen = EVT_CMD_STATUS_SIZE;
+	rq.event = EVT_CMD_STATUS;
+
+	if (hci_send_req(sock, &rq, 25000) < 0) {
+		syslog(LOG_ERR, "Unable to send authentication request: %s", strerror(errno));
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (rp.status) {
+		syslog(LOG_ERR, "Authentication command failed with status 0x%02X", rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + EIO);
+		goto failed;
+	}
+
+failed:
+
+	if (sock > 0)
+		close (sock);
+
+	if (cr)
+		free (cr);
+
+	return reply;
+
+}
+
 /*****************************************************************
  *  
  *  Section reserved to Manager D-Bus message handlers

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

end of thread, other threads:[~2005-10-31 15:42 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-20 17:45 [Bluez-devel] [D-BUS PATCH] Authentication Claudio Takahasi
2005-10-22 13:08 ` Marcel Holtmann
2005-10-24 13:06   ` Claudio Takahasi
2005-10-24 13:19     ` Marcel Holtmann
2005-10-25 19:03       ` Claudio Takahasi
2005-10-27  0:37         ` Marcel Holtmann
2005-10-27 14:33           ` Claudio Takahasi
2005-10-27 14:39             ` Claudio Takahasi
2005-10-27 14:53             ` Marcel Holtmann
2005-10-27 16:33               ` Claudio Takahasi
2005-10-27 17:11                 ` Marcel Holtmann
2005-10-31 14:53                   ` Eduardo Rocha
2005-10-31 15:42                     ` 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).