Skip to contentSkip to conversation

Fix sending HCIDEVUP when adapter is already up

PATCH In review Luiz Augusto von Dentz 2 participants 3 messages Feb 1, 2011 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/2 Fix sending HCIDEVUP when adapter is already up

From: Luiz Augusto von Dentz <[email protected]>

There is no need for HCIDEVUP/fork in such cases it will just consume more resources for no reason.

To fix this HCI_DEV_REG is no longer generate for adapter already up instead init_device is called directly which simplify the code path.

---
 plugins/hciops.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
plugins/hciops.c +11 -4
index ecfcec3..80ae61a 100644
@@ -2458,7 +2458,7 @@ static void init_pending(int index)
 	hci_set_bit(PENDING_NAME, &dev->pending);
 }
 
-static void init_device(int index)
+static void init_device(int index, gboolean already_up)
 {
 	struct hci_dev_req dr;
 	int dd;
@@ -2482,6 +2482,10 @@ static void init_device(int index)
 	init_pending(index);
 	start_hci_dev(index);
 
+	/* Avoid forking if nothing else has to be done */
+	if (already_up)
+		return;
+
 	/* Do initialization in the separate process */
 	pid = fork();
 	switch (pid) {
@@ -2562,7 +2566,7 @@ static void device_event(int event, int index)
 	switch (event) {
 	case HCI_DEV_REG:
 		info("HCI dev %d registered", index);
-		init_device(index);
+		init_device(index, FALSE);
 		break;
 
 	case HCI_DEV_UNREG:
@@ -2648,12 +2652,15 @@ static gboolean init_known_adapters(gpointer user_data)
 
 	for (i = 0; i < dl->dev_num; i++, dr++) {
 		struct dev_info *dev;
+		gboolean already_up;
+
+		already_up = hci_test_bit(HCI_UP, &dr->dev_opt);
 
-		device_event(HCI_DEV_REG, dr->dev_id);
+		init_device(dr->dev_id, already_up);
 
 		dev = &devs[dr->dev_id];
 
-		dev->already_up = hci_test_bit(HCI_UP, &dr->dev_opt);
+		dev->already_up = already_up;
 
 		if (!dev->already_up)
 			continue;
Signature · 1 line
1.7.1
author maintainer
#1 lore raw

PATCH 2/2 Fix stopping inquiry before adapter object is initialized

From: Luiz Augusto von Dentz <[email protected]>

This can cause errors on command complete since the adapter object could not be found to set its mode.

---
 plugins/hciops.c |   50 ++++++++++++++++++++++++++------------------------
 1 files changed, 26 insertions(+), 24 deletions(-)
plugins/hciops.c +26 -24
index 80ae61a..e5160ea 100644
@@ -455,6 +455,29 @@ static void start_adapter(int index)
 	memset(dev->eir, 0, sizeof(dev->eir));
 }
 
+static int hciops_stop_inquiry(int index)
+{
+	struct dev_info *dev = &devs[index];
+	struct hci_dev_info di;
+	int err;
+
+	DBG("hci%d", index);
+
+	if (hci_devinfo(index, &di) < 0)
+		return -errno;
+
+	if (hci_test_bit(HCI_INQUIRY, &di.flags))
+		err = hci_send_cmd(dev->sk, OGF_LINK_CTL,
+						OCF_INQUIRY_CANCEL, 0, 0);
+	else
+		err = hci_send_cmd(dev->sk, OGF_LINK_CTL,
+					OCF_EXIT_PERIODIC_INQUIRY, 0, 0);
+	if (err < 0)
+		err = -errno;
+
+	return err;
+}
+
 static gboolean init_adapter(int index)
 {
 	struct dev_info *dev = &devs[index];
@@ -494,6 +517,9 @@ static gboolean init_adapter(int index)
 	hciops_set_discoverable(index, discoverable);
 	hciops_set_pairable(index, pairable);
 
+	if (dev->already_up)
+		hciops_stop_inquiry(index);
+
 done:
 	btd_adapter_unref(adapter);
 	return TRUE;
@@ -2600,29 +2626,6 @@ static void device_event(int event, int index)
 	}
 }
 
-static int hciops_stop_inquiry(int index)
-{
-	struct dev_info *dev = &devs[index];
-	struct hci_dev_info di;
-	int err;
-
-	DBG("hci%d", index);
-
-	if (hci_devinfo(index, &di) < 0)
-		return -errno;
-
-	if (hci_test_bit(HCI_INQUIRY, &di.flags))
-		err = hci_send_cmd(dev->sk, OGF_LINK_CTL,
-						OCF_INQUIRY_CANCEL, 0, 0);
-	else
-		err = hci_send_cmd(dev->sk, OGF_LINK_CTL,
-					OCF_EXIT_PERIODIC_INQUIRY, 0, 0);
-	if (err < 0)
-		err = -errno;
-
-	return err;
-}
-
 static gboolean init_known_adapters(gpointer user_data)
 {
 	struct hci_dev_list_req *dl;
@@ -2666,7 +2669,6 @@ static gboolean init_known_adapters(gpointer user_data)
 			continue;
 
 		init_conn_list(dr->dev_id);
-		hciops_stop_inquiry(dr->dev_id);
 
 		dev->pending = 0;
 		hci_set_bit(PENDING_VERSION, &dev->pending);
Signature · 1 line
1.7.1
#2 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 8 lines · Luiz Augusto von Dentz

There is no need for HCIDEVUP/fork in such cases it will just consume more resources for no reason.

To fix this HCI_DEV_REG is no longer generate for adapter already up instead init_device is called directly which simplify the code path.

---
 plugins/hciops.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

Both patches have been pushed upstream. Thanks.

Johan