Skip to contentSkip to conversation

dbus.c: use hci_send_req for periodic inquiry commands

PATCH In review Johan Hedberg 2 participants 2 messages Nov 9, 2005 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dbus.c: use hci_send_req for periodic inquiry commands

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

Index: hcid/dbus.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus.c,v
retrieving revision 1.52

dbus.c +41 -12
diff -u -r1.52 dbus.c
@@ -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:
maintainer
#1 lore raw

Hi Johan,

Quoted 1 line

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
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel