From: alok barsode <alokbarsode@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH 1/1] Adding start_discovery functionality to hciops plugin.
Date: Fri, 29 May 2009 19:36:32 +0530 [thread overview]
Message-ID: <8b5debfa0905290706i4a35e75cs559bf687a25a3ab9@mail.gmail.com> (raw)
In-Reply-To: <8b5debfa0905290643o45b6488cp177eafac3b629dd1@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 742 bytes --]
Hi Johan,
On Fri, May 29, 2009 at 7:13 PM, alok barsode <alokbarsode@gmail.com> wrote:
> Hi Johan,
>
> On Fri, May 29, 2009 at 6:50 PM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
>> Hi Alok,
>>
>> One minor comment:
>>
>> On Fri, May 29, 2009, alokbarsode@gmail.com wrote:
>>> +static int hciops_start_discovery(int index, gboolean periodic)
>>> +{
>>> + inquiry_cp inq_cp;
>>> + periodic_inquiry_cp cp;
>>
>> Put these two variables into the if-else statement since that's the only
>> place where they are used. Otherwise the patch looks pretty good.
> Done. attaching the modified patch.
Attaching corrected patch. fixed a whitespace and removed the
stop_discovery declaration.
>
>>
>> Johan
Alok.
[-- Attachment #2: 0001-Adding-start_discovery-functionality-to-hciops-plugi.patch --]
[-- Type: text/x-diff, Size: 5820 bytes --]
From e5e5c0c03f0b9ac20231ac937a65ef2a54756153 Mon Sep 17 00:00:00 2001
From: Alok Barsode <alok.barsode@azingo.com>
Date: Fri, 29 May 2009 19:30:26 +0530
Subject: [PATCH 1/1] Adding start_discovery functionality to hciops plugin.
---
plugins/hciops.c | 42 ++++++++++++++++++++
src/adapter.c | 113 +++++------------------------------------------------
src/adapter.h | 1 +
3 files changed, 54 insertions(+), 102 deletions(-)
diff --git a/plugins/hciops.c b/plugins/hciops.c
index 8f9ee06..d337b75 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -561,6 +561,47 @@ done:
return err;
}
+static int hciops_start_discovery(int index, gboolean periodic)
+{
+ uint8_t lap[3] = { 0x33, 0x8b, 0x9e };
+ int dd, err = 0;
+
+ dd = hci_open_dev(index);
+ if (dd < 0)
+ return -EIO;
+
+ if (periodic) {
+ periodic_inquiry_cp cp;
+
+ memset(&cp, 0, sizeof(cp));
+ memcpy(&cp.lap, lap, 3);
+ cp.max_period = htobs(24);
+ cp.min_period = htobs(16);
+ cp.length = 0x08;
+ cp.num_rsp = 0x00;
+
+ err = hci_send_cmd(dd, OGF_LINK_CTL, OCF_PERIODIC_INQUIRY,
+ PERIODIC_INQUIRY_CP_SIZE, &cp);
+ } else {
+ inquiry_cp inq_cp;
+
+ memset(&inq_cp, 0, sizeof(inq_cp));
+ memcpy(&inq_cp.lap, lap, 3);
+ inq_cp.length = 0x08;
+ inq_cp.num_rsp = 0x00;
+
+ err = hci_send_cmd(dd, OGF_LINK_CTL, OCF_INQUIRY,
+ INQUIRY_CP_SIZE, &inq_cp);
+ }
+
+ if (err < 0)
+ err = -errno;
+
+ hci_close_dev(dd);
+
+ return err;
+}
+
static struct btd_adapter_ops hci_ops = {
.setup = hciops_setup,
.cleanup = hciops_cleanup,
@@ -570,6 +611,7 @@ static struct btd_adapter_ops hci_ops = {
.set_connectable = hciops_connectable,
.set_discoverable = hciops_discoverable,
.set_limited_discoverable = hciops_set_limited_discoverable,
+ .start_discovery = hciops_start_discovery,
};
static int hciops_init(void)
diff --git a/src/adapter.c b/src/adapter.c
index 0dae860..fc9e281 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -946,106 +946,16 @@ struct btd_device *adapter_get_device(DBusConnection *conn,
return adapter_create_device(conn, adapter, address);
}
-static int start_inquiry(struct btd_adapter *adapter)
+static int adapter_start_inquiry(struct btd_adapter *adapter)
{
- inquiry_cp cp;
- evt_cmd_status rp;
- struct hci_request rq;
- uint8_t lap[3] = { 0x33, 0x8b, 0x9e };
- int dd, err;
-
- pending_remote_name_cancel(adapter);
-
- dd = hci_open_dev(adapter->dev_id);
- if (dd < 0)
- return dd;
-
- memset(&cp, 0, sizeof(cp));
- memcpy(&cp.lap, lap, 3);
- cp.length = 0x08;
- cp.num_rsp = 0x00;
-
- memset(&rq, 0, sizeof(rq));
- rq.ogf = OGF_LINK_CTL;
- rq.ocf = OCF_INQUIRY;
- rq.cparam = &cp;
- rq.clen = INQUIRY_CP_SIZE;
- rq.rparam = &rp;
- rq.rlen = EVT_CMD_STATUS_SIZE;
- rq.event = EVT_CMD_STATUS;
-
- if (hci_send_req(dd, &rq, HCI_REQ_TIMEOUT) < 0) {
- err = -errno;
- error("Unable to start inquiry: %s (%d)",
- strerror(errno), errno);
- hci_close_dev(dd);
- return err;
- }
-
- if (rp.status) {
- error("HCI_Inquiry command failed with status 0x%02x",
- rp.status);
- hci_close_dev(dd);
- return -bt_error(rp.status);
- }
-
- hci_close_dev(dd);
-
- if (main_opts.name_resolv)
- adapter->state |= RESOLVE_NAME;
-
- return 0;
-}
+ gboolean periodic = TRUE;
-static int start_periodic_inquiry(struct btd_adapter *adapter)
-{
- periodic_inquiry_cp cp;
- struct hci_request rq;
- uint8_t lap[3] = { 0x33, 0x8b, 0x9e };
- uint8_t status;
- int dd, err;
-
- dd = hci_open_dev(adapter->dev_id);
- if (dd < 0)
- return dd;
-
- memset(&cp, 0, sizeof(cp));
- memcpy(&cp.lap, lap, 3);
- cp.max_period = htobs(24);
- cp.min_period = htobs(16);
- cp.length = 0x08;
- cp.num_rsp = 0x00;
-
- memset(&rq, 0, sizeof(rq));
- rq.ogf = OGF_LINK_CTL;
- rq.ocf = OCF_PERIODIC_INQUIRY;
- rq.cparam = &cp;
- rq.clen = PERIODIC_INQUIRY_CP_SIZE;
- rq.rparam = &status;
- rq.rlen = sizeof(status);
- rq.event = EVT_CMD_COMPLETE;
-
- if (hci_send_req(dd, &rq, HCI_REQ_TIMEOUT) < 0) {
- err = -errno;
- error("Unable to start periodic inquiry: %s (%d)",
- strerror(errno), errno);
- hci_close_dev(dd);
- return err;
- }
-
- if (status) {
- error("HCI_Periodic_Inquiry_Mode failed with status 0x%02x",
- status);
- hci_close_dev(dd);
- return -bt_error(status);
- }
-
- hci_close_dev(dd);
+ if (main_opts.discov_interval)
+ periodic = FALSE;
- if (main_opts.name_resolv)
- adapter->state |= RESOLVE_NAME;
+ pending_remote_name_cancel(adapter);
- return 0;
+ return adapter_ops->start_discovery(adapter->dev_id, periodic);
}
static DBusMessage *adapter_start_discovery(DBusConnection *conn,
@@ -1068,11 +978,10 @@ static DBusMessage *adapter_start_discovery(DBusConnection *conn,
if (adapter->disc_sessions)
goto done;
- if (main_opts.discov_interval)
- err = start_inquiry(adapter);
- else
- err = start_periodic_inquiry(adapter);
+ if (main_opts.name_resolv)
+ adapter->state |= RESOLVE_NAME;
+ err = adapter_start_inquiry(adapter);
if (err < 0)
return failed_strerror(msg, -err);
@@ -2467,8 +2376,8 @@ void adapter_set_state(struct btd_adapter *adapter, int state)
else if (adapter->disc_sessions && main_opts.discov_interval)
adapter->scheduler_id = g_timeout_add_seconds(
main_opts.discov_interval,
- (GSourceFunc) start_inquiry,
- adapter);
+ (GSourceFunc) adapter_start_inquiry,
+ (gpointer) adapter);
/* Send out of range */
if (!discov_active)
diff --git a/src/adapter.h b/src/adapter.h
index 31eaea6..5c0df05 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -160,6 +160,7 @@ struct btd_adapter_ops {
int (*set_discoverable) (int index);
int (*set_limited_discoverable) (int index, const uint8_t *cls,
gboolean limited);
+ int (*start_discovery) (int index, gboolean periodic);
};
int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
--
1.5.6.3
next prev parent reply other threads:[~2009-05-29 14:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-29 12:44 [PATCH 1/1] Adding start_discovery functionality to hciops plugin alokbarsode
2009-05-29 13:20 ` Johan Hedberg
2009-05-29 13:43 ` alok barsode
2009-05-29 14:06 ` alok barsode [this message]
-- strict thread matches above, loose matches on Subject: below --
2009-05-21 13:24 alokbarsode
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=8b5debfa0905290706i4a35e75cs559bf687a25a3ab9@mail.gmail.com \
--to=alokbarsode@gmail.com \
--cc=linux-bluetooth@vger.kernel.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