From: alokbarsode@gmail.com
To: linux-bluetooth@vger.kernel.org
Cc: marcel@holtmann.org, Alok Barsode <alok.barsode@azingo.com>
Subject: [PATCH 2/2] Adding stop() functionality to hciops plugin.
Date: Wed, 6 May 2009 14:07:57 +0530 [thread overview]
Message-ID: <1241599077-26438-2-git-send-email-alok.barsode@azingo.com> (raw)
In-Reply-To: <1241599077-26438-1-git-send-email-alok.barsode@azingo.com>
From: Alok Barsode <alok.barsode@azingo.com>
---
plugins/hciops.c | 24 ++++++++++++++++++++++++
src/adapter.c | 23 ++++++++++-------------
src/adapter.h | 1 +
3 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/plugins/hciops.c b/plugins/hciops.c
index ba4b69d..2e91129 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -439,10 +439,34 @@ done:
return err;
}
+static int hciops_stop(int index)
+{
+ int dd;
+ int err = 0;
+
+ dd = hci_open_dev(index);
+ if (dd < 0)
+ return -EIO;
+
+ if (ioctl(dd, HCIDEVDOWN, index) == 0)
+ goto done; /* on success */
+
+ if (errno != EALREADY) {
+ err = -errno;
+ error("Can't stop device hci%d: %s (%d)",
+ index, strerror(errno), errno);
+ }
+
+done:
+ hci_close_dev(dd);
+ return err;
+}
+
static struct btd_adapter_ops hci_ops = {
.setup = hciops_setup,
.cleanup = hciops_cleanup,
.start = hciops_start,
+ .stop = hciops_stop,
};
static int hciops_init(void)
diff --git a/src/adapter.c b/src/adapter.c
index 99dd2eb..eecca34 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -424,18 +424,21 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
};
hci_send_req(dd, &rq, HCI_REQ_TIMEOUT);
+ hci_close_dev(dd);
- if (ioctl(dd, HCIDEVDOWN, adapter->dev_id) < 0) {
- err = -errno;
- hci_close_dev(dd);
+ err = adapter_ops->stop(adapter->dev_id);
+ if (err < 0)
return err;
- }
adapter->off_requested = TRUE;
goto done;
}
+ dd = hci_open_dev(adapter->dev_id);
+ if (dd < 0)
+ return -EIO;
+
if (current_scan != scan_enable) {
err = hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE,
1, &scan_enable);
@@ -2082,7 +2085,7 @@ proceed:
}
if (dev_down) {
- ioctl(dd, HCIDEVDOWN, adapter->dev_id);
+ adapter_ops->stop(adapter->dev_id);
adapter->off_requested = TRUE;
return 1;
} else
@@ -2465,14 +2468,8 @@ void adapter_remove(struct btd_adapter *adapter)
unload_drivers(adapter);
/* Return adapter to down state if it was not up on init */
- if (adapter->up && !adapter->already_up) {
- int dd = hci_open_dev(adapter->dev_id);
- if (dd < 0)
- goto done;
-
- ioctl(dd, HCIDEVDOWN, adapter->dev_id);
- hci_close_dev(dd);
- }
+ if (adapter->up && !adapter->already_up)
+ adapter_ops->stop(adapter->dev_id);
done:
g_dbus_unregister_interface(connection, path, ADAPTER_INTERFACE);
diff --git a/src/adapter.h b/src/adapter.h
index 67db648..acf680b 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -153,6 +153,7 @@ struct btd_adapter_ops {
int (*setup) (void);
void (*cleanup) (void);
int (*start) (int index);
+ int (*stop) (int index);
};
int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
--
1.5.6.3
next prev parent reply other threads:[~2009-05-06 8:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-06 8:37 [PATCH 1/2] Code cleanup in adapter.c alokbarsode
2009-05-06 8:37 ` alokbarsode [this message]
2009-05-06 9:42 ` [PATCH 2/2] Adding stop() functionality to hciops plugin Johan Hedberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1241599077-26438-2-git-send-email-alok.barsode@azingo.com \
--to=alokbarsode@gmail.com \
--cc=alok.barsode@azingo.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=marcel@holtmann.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox