Skip to contentSkip to conversation

Adapter D-Bus path on raw mode

PATCH In review Claudio Takahasi 1 participant 2 messages Jul 31, 2007 – Aug 1, 2007 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Adapter D-Bus path on raw mode

Hi Marcel,

here is the patch to avoid register the D-Bus adapter path when the RAW flag is active.

ListAdapters and FindAdapter were fixed too.

Claudio

Signature · 3 lines
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT

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

dbus-manager.c +6 -1
diff -u -r1.68 dbus-manager.c
@@ -103,6 +103,7 @@
 {
 	DBusMessage *reply;
 	char path[MAX_PATH_LENGTH], *path_ptr = path;
+	struct hci_dev_info di;
 	const char *pattern;
 	int dev_id;
 
@@ -115,6 +116,9 @@
 	if (dev_id < 0)
 		return error_no_such_adapter(conn, msg);
 
+	if ((hci_devinfo(dev_id, &di) < 0) || hci_test_bit(HCI_RAW, &di.flags))
+		return error_no_such_adapter(conn, msg);
+
 	reply = dbus_message_new_method_return(msg);
 	if (!reply)
 		return DBUS_HANDLER_RESULT_NEED_MEMORY;
@@ -174,7 +178,8 @@
 		char path[MAX_PATH_LENGTH], *path_ptr = path;
 		struct hci_dev_info di;
 
-		if (hci_devinfo(dr->dev_id, &di) < 0)
+		if ((hci_devinfo(dr->dev_id, &di) < 0) ||
+			hci_test_bit(HCI_RAW, &di.flags))
 			continue;
 
 		snprintf(path, sizeof(path), "%s/%s", BASE_PATH, di.name);

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

main.c +22 -18
diff -u -r1.98 main.c
@@ -495,9 +495,8 @@
 	exit(0);
 }
 
-static void init_device(int dev_id)
+static void init_device(struct hci_dev_info *di)
 {
-	struct hci_dev_info di;
 	int dd;
 
 	/* Do initialization in the separate process */
@@ -507,41 +506,39 @@
 			break;
 		case -1:
 			error("Fork failed. Can't init device hci%d: %s (%d)",
-					dev_id, strerror(errno), errno);
+					di->dev_id, strerror(errno), errno);
 		default:
 			return;
 	}
 
-	dd = hci_open_dev(dev_id);
+	dd = hci_open_dev(di->dev_id);
 	if (dd < 0) {
 		error("Can't open device hci%d: %s (%d)",
-					dev_id, strerror(errno), errno);
+					di->dev_id, strerror(errno), errno);
 		exit(1);
 	}
 
 	/* Start HCI device */
-	if (ioctl(dd, HCIDEVUP, dev_id) < 0 && errno != EALREADY) {
+	if (ioctl(dd, HCIDEVUP, di->dev_id) < 0 && errno != EALREADY) {
 		error("Can't init device hci%d: %s (%d)",
-					dev_id, strerror(errno), errno);
+					di->dev_id, strerror(errno), errno);
+		hci_close_dev(dd);
 		exit(1);
 	}
 
-	if (hci_devinfo(dev_id, &di) < 0)
-		exit(1);
-
-	if (hci_test_bit(HCI_RAW, &di.flags))
-		exit(0);
+	if (hci_test_bit(HCI_RAW, &di->flags))
+		goto done;
 
 	if (hcid.offmode == HCID_OFFMODE_DEVDOWN) {
 		char mode[16];
 
-		if (read_device_mode(&di.bdaddr, mode, sizeof(mode)) == 0 &&
+		if (read_device_mode(&di->bdaddr, mode, sizeof(mode)) == 0 &&
 						strcmp(mode, "off") == 0) {
-			ioctl(dd, HCIDEVDOWN, dev_id);
-			exit(0);
+			ioctl(dd, HCIDEVDOWN, di->dev_id);
+			goto done;
 		}
 	}
-
+done:
 	hci_close_dev(dd);
 
 	exit(0);
@@ -549,9 +546,16 @@
 
 static void device_devreg_setup(int dev_id)
 {
+	struct hci_dev_info di;
+
+	if (hci_devinfo(dev_id, &di) < 0)
+		return;
+
 	if (hcid.auto_init)
-		init_device(dev_id);
-	hcid_dbus_register_device(dev_id);
+		init_device(&di);
+
+	if (!hci_test_bit(HCI_RAW, &di.flags))
+		hcid_dbus_register_device(dev_id);
 }
 
 static void device_devup_setup(int dev_id)

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#1 lore raw
Quoted 5 lines · Claudio Takahasi

Hi Marcel,

here is the patch to avoid register the D-Bus adapter path when the RAW flag is active.

Quoted 8 lines

ListAdapters and FindAdapter were fixed too.

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

Hi Marcel,

here is a new version based on your suggestions.

BR,
Claudio.

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

dbus-manager.c +10 -0
diff -u -r1.68 dbus-manager.c
@@ -103,6 +103,7 @@
 {
 	DBusMessage *reply;
 	char path[MAX_PATH_LENGTH], *path_ptr = path;
+	struct hci_dev_info di;
 	const char *pattern;
 	int dev_id;
 
@@ -115,6 +116,12 @@
 	if (dev_id < 0)
 		return error_no_such_adapter(conn, msg);
 
+	if (hci_devinfo(dev_id, &di) < 0)
+		return error_no_such_adapter(conn, msg);
+
+	if (hci_test_bit(HCI_RAW, &di.flags))
+		return error_no_such_adapter(conn, msg);
+
 	reply = dbus_message_new_method_return(msg);
 	if (!reply)
 		return DBUS_HANDLER_RESULT_NEED_MEMORY;
@@ -177,6 +184,9 @@
 		if (hci_devinfo(dr->dev_id, &di) < 0)
 			continue;
 
+		if (hci_test_bit(HCI_RAW, &di.flags))
+			continue;
+
 		snprintf(path, sizeof(path), "%s/%s", BASE_PATH, di.name);
 
 		dbus_message_iter_append_basic(&array_iter,

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

main.c +16 -7
diff -u -r1.98 main.c
@@ -523,14 +523,14 @@
 	if (ioctl(dd, HCIDEVUP, dev_id) < 0 && errno != EALREADY) {
 		error("Can't init device hci%d: %s (%d)",
 					dev_id, strerror(errno), errno);
-		exit(1);
+		goto fail;
 	}
 
 	if (hci_devinfo(dev_id, &di) < 0)
-		exit(1);
+		goto fail;
 
 	if (hci_test_bit(HCI_RAW, &di.flags))
-		exit(0);
+		goto done;
 
 	if (hcid.offmode == HCID_OFFMODE_DEVDOWN) {
 		char mode[16];
@@ -538,20 +538,29 @@
 		if (read_device_mode(&di.bdaddr, mode, sizeof(mode)) == 0 &&
 						strcmp(mode, "off") == 0) {
 			ioctl(dd, HCIDEVDOWN, dev_id);
-			exit(0);
+			goto done;
 		}
 	}
-
+done:
 	hci_close_dev(dd);
-
 	exit(0);
+fail:
+	hci_close_dev(dd);
+	exit(1);
 }
 
 static void device_devreg_setup(int dev_id)
 {
+	struct hci_dev_info di;
+
 	if (hcid.auto_init)
 		init_device(dev_id);
-	hcid_dbus_register_device(dev_id);
+
+	if (hci_devinfo(dev_id, &di) < 0)
+		return;
+
+	if (!hci_test_bit(HCI_RAW, &di.flags))
+		hcid_dbus_register_device(dev_id);
 }
 
 static void device_devup_setup(int dev_id)

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel