* [PATCH 1/2] Fix sending HCIDEVUP when adapter is already up @ 2011-02-01 15:47 Luiz Augusto von Dentz 2011-02-01 15:47 ` [PATCH 2/2] Fix stopping inquiry before adapter object is initialized Luiz Augusto von Dentz 2011-02-01 23:22 ` [PATCH 1/2] Fix sending HCIDEVUP when adapter is already up Johan Hedberg 0 siblings, 2 replies; 3+ messages in thread From: Luiz Augusto von Dentz @ 2011-02-01 15:47 UTC (permalink / raw) To: linux-bluetooth From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com> 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(-) diff --git a/plugins/hciops.c b/plugins/hciops.c index ecfcec3..80ae61a 100644 --- a/plugins/hciops.c +++ b/plugins/hciops.c @@ -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; -- 1.7.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] Fix stopping inquiry before adapter object is initialized 2011-02-01 15:47 [PATCH 1/2] Fix sending HCIDEVUP when adapter is already up Luiz Augusto von Dentz @ 2011-02-01 15:47 ` Luiz Augusto von Dentz 2011-02-01 23:22 ` [PATCH 1/2] Fix sending HCIDEVUP when adapter is already up Johan Hedberg 1 sibling, 0 replies; 3+ messages in thread From: Luiz Augusto von Dentz @ 2011-02-01 15:47 UTC (permalink / raw) To: linux-bluetooth From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com> 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(-) diff --git a/plugins/hciops.c b/plugins/hciops.c index 80ae61a..e5160ea 100644 --- a/plugins/hciops.c +++ b/plugins/hciops.c @@ -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); -- 1.7.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] Fix sending HCIDEVUP when adapter is already up 2011-02-01 15:47 [PATCH 1/2] Fix sending HCIDEVUP when adapter is already up Luiz Augusto von Dentz 2011-02-01 15:47 ` [PATCH 2/2] Fix stopping inquiry before adapter object is initialized Luiz Augusto von Dentz @ 2011-02-01 23:22 ` Johan Hedberg 1 sibling, 0 replies; 3+ messages in thread From: Johan Hedberg @ 2011-02-01 23:22 UTC (permalink / raw) To: Luiz Augusto von Dentz; +Cc: linux-bluetooth Hi Luiz, On Tue, Feb 01, 2011, Luiz Augusto von Dentz wrote: > 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 ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-02-01 23:22 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-02-01 15:47 [PATCH 1/2] Fix sending HCIDEVUP when adapter is already up Luiz Augusto von Dentz 2011-02-01 15:47 ` [PATCH 2/2] Fix stopping inquiry before adapter object is initialized Luiz Augusto von Dentz 2011-02-01 23:22 ` [PATCH 1/2] Fix sending HCIDEVUP when adapter is already up Johan Hedberg
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox