linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Bluez-devel] [DBUS PATH] RemoveBonding
@ 2006-02-21 14:49 Claudio Takahasi
  2006-02-21 17:05 ` Marcel Holtmann
  0 siblings, 1 reply; 4+ messages in thread
From: Claudio Takahasi @ 2006-02-21 14:49 UTC (permalink / raw)
  To: bluez-devel

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

Hi Marcel,

Here is the patch to remove bondings.

Please check the logic. I read the BlueZ D-Bus API and the Bluetooth
Spec, but I am not complete sure if I am covering all scenarios.

Regarding the HCI disconnect complete event, I think we need notify
the connected applications sending a D-Bus signal. What do you think?

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

[-- Attachment #2: remove-bonding01.patch --]
[-- Type: text/x-patch, Size: 3681 bytes --]

--- bluez-utils-cvs.orig/hcid/dbus-device.c	2006-02-20 14:52:10.000000000 -0300
+++ bluez-utils-cvs-remove-bonding/hcid/dbus-device.c	2006-02-21 08:38:21.000000000 -0300
@@ -791,8 +791,121 @@
 
 static DBusMessage* handle_dev_remove_bonding_req(DBusMessage *msg, void *data)
 {
-	/*FIXME: */
-	return bluez_new_failure_msg(msg, BLUEZ_EDBUS_NOT_IMPLEMENTED);
+	evt_disconn_complete dis_rp;
+	delete_stored_link_key_rp del_rp;
+	disconnect_cp dis_cp;
+	delete_stored_link_key_cp del_cp;
+	struct hci_request rq;
+	struct hci_dbus_data *dbus_data = data;
+	struct hci_conn_info_req *cr = NULL;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	char filename[PATH_MAX + 1];
+	char addr[18], *addr_ptr, *str;
+	bdaddr_t bdaddr;
+	int dd;
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0)
+		return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+
+	get_device_address(dbus_data->dev_id, addr, sizeof(addr));
+
+	snprintf(filename, PATH_MAX, "%s/%s/linkkeys", STORAGEDIR, addr);
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_get_basic(&iter, &addr_ptr);
+
+	str = textfile_get(filename, addr_ptr);
+	if (str) {
+		/* delete the link key from linkkeys file */
+		textfile_del(filename, addr_ptr);
+		free(str);
+	}
+
+	str2ba(addr_ptr, &bdaddr);
+	
+	/* Send HCI Delete Stored Link Keys */
+	memset(&del_cp, 0, sizeof(del_cp));
+	memcpy(&del_cp.bdaddr, &bdaddr, sizeof(bdaddr));
+	del_cp.delete_all = 0; /* delete only bdaddr keys */
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_DELETE_STORED_LINK_KEY;
+	rq.event  = EVT_CMD_COMPLETE;
+	rq.cparam = &del_cp;
+	rq.clen   = DELETE_STORED_LINK_KEY_CP_SIZE;
+	rq.rparam = &del_rp;
+	rq.rlen   = DELETE_STORED_LINK_KEY_RP_SIZE;
+	
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		/* if fail, try disconnect */
+		syslog(LOG_ERR, "Can't send delete stored link key command");
+		goto disconnect;
+	}
+
+	if (del_rp.status) {
+		/* if fail, try disconnect */
+		syslog(LOG_ERR, "Delete store key failed with status: 0x%X", del_rp.status);
+		goto disconnect;
+	}
+
+disconnect:
+	/* close active connections for the remote device */
+	cr = malloc(sizeof(*cr) + sizeof(struct hci_conn_info));
+	if (!cr) {
+		syslog(LOG_ERR, "Can't allocate memory");
+		reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
+		goto failed;
+	}
+
+	bacpy(&cr->bdaddr, &bdaddr);
+	cr->type = ACL_LINK;
+	if (ioctl(dd, HCIGETCONNINFO, (unsigned long) cr) < 0) {
+		/* Ignore when there isn't active connections, return success */
+		syslog(LOG_INFO, "skipping: there isn't active connections or get connection info failed");
+		reply = dbus_message_new_method_return(msg);
+		goto failed;
+	}
+
+	/* send the disconnect HCI command */
+	memset(&dis_cp, 0, sizeof(dis_cp));
+	dis_cp.handle = cr->conn_info->handle;
+	dis_cp.reason = HCI_OE_USER_ENDED_CONNECTION;
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf    = OGF_LINK_CTL;
+	rq.ocf    = OCF_DISCONNECT;
+	rq.event  = EVT_DISCONN_COMPLETE;
+	rq.cparam = &dis_cp;
+	rq.clen   = DISCONNECT_CP_SIZE;
+	rq.rparam = &dis_rp;
+	rq.rlen   = EVT_DISCONN_COMPLETE_SIZE;
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Can't send disconnect command");
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | errno);
+		goto failed;
+	}
+
+	if (dis_rp.status) {
+		syslog(LOG_ERR, "Disconnect failed with status:0x%X", dis_rp.status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET | dis_rp.status);
+		goto failed;
+	}
+
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+
+	if (cr)
+		free(cr);
+
+	return reply;
+
 }
 
 static DBusMessage* handle_dev_pin_code_length_req(DBusMessage *msg, void *data)




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

* Re: [Bluez-devel] [DBUS PATH] RemoveBonding
  2006-02-21 14:49 [Bluez-devel] [DBUS PATH] RemoveBonding Claudio Takahasi
@ 2006-02-21 17:05 ` Marcel Holtmann
  2006-02-21 18:09   ` [Bluez-devel] [DBUS PATCH] RemoveBonding Claudio Takahasi
  0 siblings, 1 reply; 4+ messages in thread
From: Marcel Holtmann @ 2006-02-21 17:05 UTC (permalink / raw)
  To: bluez-devel

Hi Claudio,

> Here is the patch to remove bondings.
> 
> Please check the logic. I read the BlueZ D-Bus API and the Bluetooth
> Spec, but I am not complete sure if I am covering all scenarios.

the logic looks fine to me. However it is not that important at the
moment, because we can sort out the details later.

Some small notes. The textfile_get() is not needed. Simply delete the
link key. If it fails, because it doesn't exists, this is fine. And use
hci_disconnect() instead of implementing it by yourself.

> Regarding the HCI disconnect complete event, I think we need notify
> the connected applications sending a D-Bus signal. What do you think?

We need to inform applications about the disconnect, but this is not the
job of this method. It will be done by other routines inside hcid.

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://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

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

* Re: [Bluez-devel] [DBUS PATCH] RemoveBonding
  2006-02-21 17:05 ` Marcel Holtmann
@ 2006-02-21 18:09   ` Claudio Takahasi
  2006-02-21 23:57     ` Marcel Holtmann
  0 siblings, 1 reply; 4+ messages in thread
From: Claudio Takahasi @ 2006-02-21 18:09 UTC (permalink / raw)
  To: bluez-devel

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

Hi Marcel,

Your suggestions are done!

Regarding the disconnect timeout, I tested with 100ms. It is working,
but is it enough?


On 2/21/06, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Claudio,
>
> > Here is the patch to remove bondings.
> >
> > Please check the logic. I read the BlueZ D-Bus API and the Bluetooth
> > Spec, but I am not complete sure if I am covering all scenarios.
>
> the logic looks fine to me. However it is not that important at the
> moment, because we can sort out the details later.
>
> Some small notes. The textfile_get() is not needed. Simply delete the
> link key. If it fails, because it doesn't exists, this is fine. And use
> hci_disconnect() instead of implementing it by yourself.
[Claudio Takahasi]
I didn't use hci_disconnect and hci_delete_stored_link_keys to get the
error reason.


>
> > Regarding the HCI disconnect complete event, I think we need notify
> > the connected applications sending a D-Bus signal. What do you think?
>
> We need to inform applications about the disconnect, but this is not the
> job of this method. It will be done by other routines inside hcid.
[Claudio Takahasi]
Ok. I will write in my TODO list.


Regards,
Claudio
>
> 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://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


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

[-- Attachment #2: remove-bonding02.patch --]
[-- Type: text/x-patch, Size: 2357 bytes --]

--- bluez-utils-cvs.orig/hcid/dbus-device.c	2006-02-20 14:52:10.000000000 -0300
+++ bluez-utils-cvs-remove-bonding/hcid/dbus-device.c	2006-02-21 11:58:16.000000000 -0300
@@ -791,8 +791,73 @@
 
 static DBusMessage* handle_dev_remove_bonding_req(DBusMessage *msg, void *data)
 {
-	/*FIXME: */
-	return bluez_new_failure_msg(msg, BLUEZ_EDBUS_NOT_IMPLEMENTED);
+	char filename[PATH_MAX + 1];
+	char addr[18];
+	DBusMessageIter iter;
+	bdaddr_t bdaddr;
+	struct hci_dbus_data *dbus_data = data;
+	struct hci_conn_info_req *cr = NULL;
+	DBusMessage *reply = NULL;
+	const char *addr_ptr;
+	int dd;
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0)
+		return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+
+	get_device_address(dbus_data->dev_id, addr, sizeof(addr));
+
+	snprintf(filename, PATH_MAX, "%s/%s/linkkeys", STORAGEDIR, addr);
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_get_basic(&iter, &addr_ptr);
+
+	/* delete the link key from linkkeys file */
+	textfile_del(filename, addr_ptr);
+
+	str2ba(addr_ptr, &bdaddr);
+
+	/* delete the key stored in the Bluetooth Controller */
+	if (hci_delete_stored_link_key(dd, &bdaddr, 0, 100) < 0) {
+		syslog(LOG_ERR, "Can't delete stored link keys");
+		/* ignore failures and try disconnect */
+	}
+
+	/* close active connections for the remote device */
+	cr = malloc(sizeof(*cr) + sizeof(struct hci_conn_info));
+	if (!cr) {
+		syslog(LOG_ERR, "Can't allocate memory");
+		reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
+		goto failed;
+	}
+
+	bacpy(&cr->bdaddr, &bdaddr);
+	cr->type = ACL_LINK;
+	if (ioctl(dd, HCIGETCONNINFO, (unsigned long) cr) < 0) {
+		/* Ignore when there isn't active connections, return success */
+		syslog(LOG_INFO, "skipping: there isn't active connections or get connection info failed");
+		reply = dbus_message_new_method_return(msg);
+		goto failed;
+	}
+
+	/* send the disconnect HCI command */
+	if (hci_disconnect(dd, htobs(cr->conn_info->handle), HCI_OE_USER_ENDED_CONNECTION, 100) < 0) {
+		syslog(LOG_ERR, "Disconnect failed");
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | errno);
+		goto failed;
+	}
+
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+
+	if (cr)
+		free(cr);
+
+	return reply;
+
 }
 
 static DBusMessage* handle_dev_pin_code_length_req(DBusMessage *msg, void *data)

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

* Re: [Bluez-devel] [DBUS PATCH] RemoveBonding
  2006-02-21 18:09   ` [Bluez-devel] [DBUS PATCH] RemoveBonding Claudio Takahasi
@ 2006-02-21 23:57     ` Marcel Holtmann
  0 siblings, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2006-02-21 23:57 UTC (permalink / raw)
  To: bluez-devel

Hi Claudio,

> Regarding the disconnect timeout, I tested with 100ms. It is working,
> but is it enough?

your patch has been applied to the CVS. However I removed some of the
syslog messages, because they are to talky. You can expect that the
normal case is that the device is not connected and that the key is not
stored on the chip.

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://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-21 14:49 [Bluez-devel] [DBUS PATH] RemoveBonding Claudio Takahasi
2006-02-21 17:05 ` Marcel Holtmann
2006-02-21 18:09   ` [Bluez-devel] [DBUS PATCH] RemoveBonding Claudio Takahasi
2006-02-21 23:57     ` 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).