linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Bluez-devel] [PATCH] Add CancelInquiry D-BUS method
@ 2005-10-23 21:13 Johan Hedberg
  2005-10-23 21:31 ` Marcel Holtmann
  0 siblings, 1 reply; 4+ messages in thread
From: Johan Hedberg @ 2005-10-23 21:13 UTC (permalink / raw)
  To: bluez-devel

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

Hi,

Here's a patch which implements inquiry cancel functionality. The
HCI_Inquiry_Cancel command will not cause a inquiry complete HCI event
to be generated, so I also changed security.c to send the inquiry
complete D-BUS signal when it encounters a command complete event for
HCI_Inquiry_Cancel.

I've also updated the pygtk testing program to work with this new API:
http://www.iki.fi/~jhedberg/bluez-python/bluez-python-0.6.tar.gz

Johan

[-- Attachment #2: cancel-inquiry.patch --]
[-- Type: text/plain, Size: 4475 bytes --]

Index: dbus.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus.c,v
retrieving revision 1.31
diff -u -r1.31 dbus.c
--- dbus.c	22 Oct 2005 13:03:41 -0000	1.31
+++ dbus.c	23 Oct 2005 20:23:11 -0000
@@ -285,6 +285,7 @@
 static DBusMessage* handle_periodic_inq_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_cancel_periodic_inq_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_inq_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_cancel_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);
@@ -295,6 +296,7 @@
 	{ 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_CANCEL_INQ,		handle_cancel_inq_req,		HCI_CANCEL_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		},
@@ -1389,6 +1391,48 @@
 	return reply;
 }
 
+static DBusMessage* handle_cancel_inq_req(DBusMessage *msg, void *data)
+{
+	DBusMessage *reply = NULL;
+	struct hci_request rq;
+	struct hci_dbus_data *dbus_data = data;
+	int dev_id = -1, dd = -1;
+
+	if (dbus_data->id == 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 = dbus_data->id;
+
+	dd = hci_open_dev(dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "Unable to open device %d: %s", dev_id, strerror(errno));
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf = OGF_LINK_CTL;
+	rq.ocf = OCF_INQUIRY_CANCEL;
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Unable to cancel inquiry: %s", strerror(errno));
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (dd >= 0)
+		hci_close_dev(dd);
+
+	return reply;
+}
+
 static DBusMessage* handle_role_switch_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;
Index: dbus.h
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus.h,v
retrieving revision 1.7
diff -u -r1.7 dbus.h
--- dbus.h	22 Oct 2005 13:03:41 -0000	1.7
+++ dbus.h	23 Oct 2005 20:23:11 -0000
@@ -105,10 +105,11 @@
 #define HCI_PERIODIC_INQ		"PeriodicInquiry"
 #define HCI_CANCEL_PERIODIC_INQ		"CancelPeriodic"
 #define HCI_INQ				"Inquiry"
+#define HCI_CANCEL_INQ			"CancelInquiry"
 #define HCI_ROLE_SWITCH			"RoleSwitch"
 #define HCI_REMOTE_NAME			"RemoteName"
 #define HCI_CONNECTIONS			"Connections"
-#define HCI_AUTHENTICATE			"Authenticate"
+#define HCI_AUTHENTICATE		"Authenticate"
 
 
 #define HCI_PERIODIC_INQ_SIGNATURE			DBUS_TYPE_BYTE_AS_STRING\
@@ -122,6 +123,8 @@
 							DBUS_TYPE_BYTE_AS_STRING\
 							__END_SIG__
 
+#define HCI_CANCEL_INQ_SIGNATURE			__END_SIG__
+
 #define HCI_ROLE_SWITCH_SIGNATURE			DBUS_TYPE_STRING_AS_STRING\
 							DBUS_TYPE_BYTE_AS_STRING\
 							__END_SIG__
Index: security.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/security.c,v
retrieving revision 1.41
diff -u -r1.41 security.c
--- security.c	22 Oct 2005 12:56:13 -0000	1.41
+++ security.c	23 Oct 2005 20:23:12 -0000
@@ -493,6 +493,14 @@
 		hcid_dbus_inquiry_start(sba);
 }
 
+static inline void cmd_complete(int dev, bdaddr_t *sba, void *ptr)
+{
+	evt_cmd_complete *evt = ptr;
+
+	if (evt->opcode == cmd_opcode_pack(OGF_LINK_CTL, OCF_INQUIRY_CANCEL))
+		hcid_dbus_inquiry_complete(sba);
+}
+
 static inline void remote_name_information(int dev, bdaddr_t *sba, void *ptr)
 {
 	evt_remote_name_req_complete *evt = ptr;
@@ -679,6 +687,10 @@
 		cmd_status(dev, &di->bdaddr, ptr);
 		break;
 
+	case EVT_CMD_COMPLETE:
+		cmd_complete(dev, &di->bdaddr, ptr);
+		break;
+
 	case EVT_REMOTE_NAME_REQ_COMPLETE:
 		remote_name_information(dev, &di->bdaddr, ptr);
 		break;

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

* Re: [Bluez-devel] [PATCH] Add CancelInquiry D-BUS method
  2005-10-23 21:13 [Bluez-devel] [PATCH] Add CancelInquiry D-BUS method Johan Hedberg
@ 2005-10-23 21:31 ` Marcel Holtmann
  2005-10-24  7:56   ` Johan Hedberg
  0 siblings, 1 reply; 4+ messages in thread
From: Marcel Holtmann @ 2005-10-23 21:31 UTC (permalink / raw)
  To: bluez-devel

Hi Johan,

> Here's a patch which implements inquiry cancel functionality. The
> HCI_Inquiry_Cancel command will not cause a inquiry complete HCI event
> to be generated, so I also changed security.c to send the inquiry
> complete D-BUS signal when it encounters a command complete event for
> HCI_Inquiry_Cancel.

the patch is in the CVS now, thanks.

Regards

Marcel




-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
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] [PATCH] Add CancelInquiry D-BUS method
  2005-10-23 21:31 ` Marcel Holtmann
@ 2005-10-24  7:56   ` Johan Hedberg
  2005-10-24 11:04     ` Marcel Holtmann
  0 siblings, 1 reply; 4+ messages in thread
From: Johan Hedberg @ 2005-10-24  7:56 UTC (permalink / raw)
  To: bluez-devel

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

On Sun, Oct 23, 2005, ext Marcel Holtmann wrote:
> > HCI_Inquiry_Cancel command will not cause a inquiry complete HCI event
> > to be generated, so I also changed security.c to send the inquiry
> > complete D-BUS signal when it encounters a command complete event for
> > HCI_Inquiry_Cancel.
> 
> the patch is in the CVS now, thanks.

I forgot one important thing: EVT_CMD_COMPLETE should also be enabled in
the filter. Here's a patch to fix it.

Johan

[-- Attachment #2: cmd-complete.patch --]
[-- Type: text/plain, Size: 622 bytes --]

Index: hcid/security.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/security.c,v
retrieving revision 1.42
diff -u -r1.42 security.c
--- hcid/security.c	23 Oct 2005 21:27:41 -0000	1.42
+++ hcid/security.c	24 Oct 2005 07:52:55 -0000
@@ -775,6 +775,7 @@
 	hci_filter_clear(&flt);
 	hci_filter_set_ptype(HCI_EVENT_PKT, &flt);
 	hci_filter_set_event(EVT_CMD_STATUS, &flt);
+	hci_filter_set_event(EVT_CMD_COMPLETE, &flt);
 	hci_filter_set_event(EVT_PIN_CODE_REQ, &flt);
 	hci_filter_set_event(EVT_LINK_KEY_REQ, &flt);
 	hci_filter_set_event(EVT_LINK_KEY_NOTIFY, &flt);

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

* Re: [Bluez-devel] [PATCH] Add CancelInquiry D-BUS method
  2005-10-24  7:56   ` Johan Hedberg
@ 2005-10-24 11:04     ` Marcel Holtmann
  0 siblings, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2005-10-24 11:04 UTC (permalink / raw)
  To: bluez-devel

Hi Johan,

> > > HCI_Inquiry_Cancel command will not cause a inquiry complete HCI event
> > > to be generated, so I also changed security.c to send the inquiry
> > > complete D-BUS signal when it encounters a command complete event for
> > > HCI_Inquiry_Cancel.
> > 
> > the patch is in the CVS now, thanks.
> 
> I forgot one important thing: EVT_CMD_COMPLETE should also be enabled in
> the filter. Here's a patch to fix it.

this patch is in the CVS, too.

Regards

Marcel




-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
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:[~2005-10-24 11:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-23 21:13 [Bluez-devel] [PATCH] Add CancelInquiry D-BUS method Johan Hedberg
2005-10-23 21:31 ` Marcel Holtmann
2005-10-24  7:56   ` Johan Hedberg
2005-10-24 11:04     ` 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).