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

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).