linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Bluez-devel] [PATCH] dbus.c: use hci_send_req for periodic inquiry commands
@ 2005-11-09 12:16 Johan Hedberg
  2005-11-09 15:44 ` Marcel Holtmann
  0 siblings, 1 reply; 2+ messages in thread
From: Johan Hedberg @ 2005-11-09 12:16 UTC (permalink / raw)
  To: bluez-devel

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

Hi,

Here's a patch for the following changes:

1. Remove setting inquiry mode inte period inquiry mode function
This should be done at device initialization and when the appropriate
SetProperty method is called.

2. Use hci_send_req instead of hci_send_cmd for periodic inquiry and
exit periodic inquiry commands. This way a failure status in command
complete event can be catched and the apropriate error code returned.

Johan

[-- Attachment #2: periodic-inq.patch --]
[-- Type: text/plain, Size: 3676 bytes --]

Index: hcid/dbus.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus.c,v
retrieving revision 1.52
diff -u -r1.52 dbus.c
--- hcid/dbus.c	8 Nov 2005 14:54:58 -0000	1.52
+++ hcid/dbus.c	9 Nov 2005 12:08:18 -0000
@@ -1310,8 +1310,9 @@
 
 static DBusMessage* handle_periodic_inq_req(DBusMessage *msg, void *data)
 {
-	write_inquiry_mode_cp inq_mode;
 	periodic_inquiry_cp inq_param;
+	struct hci_request rq;
+	uint8_t status;
 	DBusMessage *reply = NULL;
 	struct hci_dbus_data *dbus_data = data;
 	uint8_t length, num_rsp = 0;
@@ -1359,19 +1360,23 @@
 	inq_param.lap[1] = (lap >> 8) & 0xff;
 	inq_param.lap[2] = (lap >> 16) & 0xff;
 
-	inq_mode.mode = 1;	// INQUIRY_WITH_RSSI
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf = OGF_LINK_CTL;
+	rq.ocf = OCF_PERIODIC_INQUIRY;
+	rq.cparam = &inq_param;
+	rq.clen = PERIODIC_INQUIRY_CP_SIZE;
+	rq.rparam = &status;
+	rq.rlen = sizeof(status);
 
-	if (hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_INQUIRY_MODE,
-				WRITE_INQUIRY_MODE_CP_SIZE, &inq_mode) < 0) {
-		syslog(LOG_ERR, "Can't set inquiry mode: %s", strerror(errno));
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Sending periodic inquiry command failed: %s", strerror(errno));
 		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
 		goto failed;
 	}
 
-	if (hci_send_cmd(dd, OGF_LINK_CTL, OCF_PERIODIC_INQUIRY,
-				PERIODIC_INQUIRY_CP_SIZE, &inq_param) < 0) {
-		syslog(LOG_ERR, "Can't send HCI commands: %s", strerror(errno));
-		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+	if (status) {
+		syslog(LOG_ERR, "Periodic inquiry failed with status %02X", status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + status);
 		goto failed;
 	}
 
@@ -1387,7 +1392,9 @@
 static DBusMessage* handle_cancel_periodic_inq_req(DBusMessage *msg, void *data)
 {
 	DBusMessage *reply = NULL;
+	struct hci_request rq;
 	struct hci_dbus_data *dbus_data = data;
+	uint8_t status;
 	int dd = -1;
 
 	dd = hci_open_dev(dbus_data->dev_id);
@@ -1397,12 +1404,25 @@
 		goto failed;
 	}
 
-	if (hci_send_cmd(dd, OGF_LINK_CTL, OCF_EXIT_PERIODIC_INQUIRY, 0 , NULL) < 0) {
-		syslog(LOG_ERR, "Send HCI command failed");
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf = OGF_LINK_CTL;
+	rq.ocf = OCF_EXIT_PERIODIC_INQUIRY;
+	rq.rparam = &status;
+	rq.rlen = sizeof(status);
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Sending exit periodic inquiry command failed: %s",
+				strerror(errno));
 		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
 		goto failed;
 	}
 
+	if (status) {
+		syslog(LOG_ERR, "Exit periodic inquiry failed with status %02X", status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + status);
+		goto failed;
+	}
+
 	reply = dbus_message_new_method_return(msg);
 
 failed:
@@ -1479,6 +1499,7 @@
 	DBusMessage *reply = NULL;
 	struct hci_request rq;
 	struct hci_dbus_data *dbus_data = data;
+	uint8_t status;
 	int dd = -1;
 
 	dd = hci_open_dev(dbus_data->dev_id);
@@ -1492,13 +1513,21 @@
 	memset(&rq, 0, sizeof(rq));
 	rq.ogf = OGF_LINK_CTL;
 	rq.ocf = OCF_INQUIRY_CANCEL;
+	rq.rparam = &status;
+	rq.rlen = sizeof(status);
 
 	if (hci_send_req(dd, &rq, 100) < 0) {
-		syslog(LOG_ERR, "Unable to cancel inquiry: %s", strerror(errno));
+		syslog(LOG_ERR, "Sending cancel inquiry failed: %s", strerror(errno));
 		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
 		goto failed;
 	}
 
+	if (status) {
+		syslog(LOG_ERR, "Cancel inquiry failed with status %02X", status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + status);
+		goto failed;
+	}
+
 	reply = dbus_message_new_method_return(msg);
 
 failed:

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

* Re: [Bluez-devel] [PATCH] dbus.c: use hci_send_req for periodic inquiry commands
  2005-11-09 12:16 [Bluez-devel] [PATCH] dbus.c: use hci_send_req for periodic inquiry commands Johan Hedberg
@ 2005-11-09 15:44 ` Marcel Holtmann
  0 siblings, 0 replies; 2+ messages in thread
From: Marcel Holtmann @ 2005-11-09 15:44 UTC (permalink / raw)
  To: bluez-devel

Hi Johan,

> Here's a patch for the following changes:

I applied the patch, but I have some small general comments.

Use "0x%02x" or "0x%04x" if you need to display a value in hex in any
kind of message. Include the errno clear text value in an error message,
because they might be different on different architectures.

Regards

Marcel




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

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

end of thread, other threads:[~2005-11-09 15:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-09 12:16 [Bluez-devel] [PATCH] dbus.c: use hci_send_req for periodic inquiry commands Johan Hedberg
2005-11-09 15:44 ` 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).