2009-06-23 14:50:19

by alok barsode

[permalink] [raw]
Subject: [PATCH 1/3] Renaming found_device_req_name to adapter_resolve_names

From: Alok Barsode <[email protected]>

---
src/adapter.c | 52 ++++++++++++++++++++++++++++++++++++++++
src/adapter.h | 2 +
src/dbus-hci.c | 72 +------------------------------------------------------
3 files changed, 56 insertions(+), 70 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 8d277ba..9a913ac 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -258,6 +258,58 @@ int pending_remote_name_cancel(struct btd_adapter *adapter)
return err;
}

+int adapter_resolve_names(struct btd_adapter *adapter)
+{
+ remote_name_req_cp cp;
+ struct remote_dev_info *dev, match;
+ int dd, err;
+
+ memset(&match, 0, sizeof(struct remote_dev_info));
+ bacpy(&match.bdaddr, BDADDR_ANY);
+ match.name_status = NAME_REQUIRED;
+
+ dev = adapter_search_found_devices(adapter, &match);
+ if (!dev)
+ return -ENODATA;
+
+ dd = hci_open_dev(adapter->dev_id);
+ if (dd < 0)
+ return -errno;
+
+ /* send at least one request or return failed if the list is empty */
+ do {
+ /* flag to indicate the current remote name requested */
+ dev->name_status = NAME_REQUESTED;
+
+ memset(&cp, 0, sizeof(cp));
+ bacpy(&cp.bdaddr, &dev->bdaddr);
+ cp.pscan_rep_mode = 0x02;
+
+ err = hci_send_cmd(dd, OGF_LINK_CTL, OCF_REMOTE_NAME_REQ,
+ REMOTE_NAME_REQ_CP_SIZE, &cp);
+
+ if (!err)
+ break;
+
+ error("Unable to send HCI remote name req: %s (%d)",
+ strerror(errno), errno);
+
+ /* if failed, request the next element */
+ /* remove the element from the list */
+ adapter_remove_found_device(adapter, &dev->bdaddr);
+
+ /* get the next element */
+ dev = adapter_search_found_devices(adapter, &match);
+ } while (dev);
+
+ hci_close_dev(dd);
+
+ if (err < 0)
+ err = errno;
+
+ return err;
+}
+
static const char *mode2str(uint8_t mode)
{
switch(mode) {
diff --git a/src/adapter.h b/src/adapter.h
index 2356743..fca34eb 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -95,6 +95,8 @@ struct btd_device *adapter_create_device(DBusConnection *conn,

int pending_remote_name_cancel(struct btd_adapter *adapter);

+int adapter_resolve_names(struct btd_adapter *adapter);
+
void clear_found_devices_list(struct btd_adapter *adapter);

struct btd_adapter *adapter_create(DBusConnection *conn, int id,
diff --git a/src/dbus-hci.c b/src/dbus-hci.c
index 8718465..ca391c5 100644
--- a/src/dbus-hci.c
+++ b/src/dbus-hci.c
@@ -466,74 +466,6 @@ void hcid_dbus_inquiry_start(bdaddr_t *local)
}
}

-static int found_device_req_name(struct btd_adapter *adapter)
-{
- struct hci_request rq;
- evt_cmd_status rp;
- remote_name_req_cp cp;
- struct remote_dev_info *dev, match;
- int dd, req_sent = 0;
- uint16_t dev_id = adapter_get_dev_id(adapter);
-
- memset(&match, 0, sizeof(struct remote_dev_info));
- bacpy(&match.bdaddr, BDADDR_ANY);
- match.name_status = NAME_REQUIRED;
-
- dev = adapter_search_found_devices(adapter, &match);
- if (!dev)
- return -ENODATA;
-
- dd = hci_open_dev(dev_id);
- if (dd < 0)
- return -errno;
-
- memset(&rq, 0, sizeof(rq));
- rq.ogf = OGF_LINK_CTL;
- rq.ocf = OCF_REMOTE_NAME_REQ;
- rq.cparam = &cp;
- rq.clen = REMOTE_NAME_REQ_CP_SIZE;
- rq.rparam = &rp;
- rq.rlen = EVT_CMD_STATUS_SIZE;
- rq.event = EVT_CMD_STATUS;
-
- /* send at least one request or return failed if the list is empty */
- do {
- /* flag to indicate the current remote name requested */
- dev->name_status = NAME_REQUESTED;
-
- memset(&rp, 0, sizeof(rp));
- memset(&cp, 0, sizeof(cp));
- bacpy(&cp.bdaddr, &dev->bdaddr);
- cp.pscan_rep_mode = 0x02;
-
- if (hci_send_req(dd, &rq, HCI_REQ_TIMEOUT) < 0)
- error("Unable to send HCI remote name req: %s (%d)",
- strerror(errno), errno);
-
- if (!rp.status) {
- req_sent = 1;
- break;
- }
-
- error("Remote name request failed with status 0x%02x",
- rp.status);
-
- /* if failed, request the next element */
- /* remove the element from the list */
- adapter_remove_found_device(adapter, &dev->bdaddr);
-
- /* get the next element */
- dev = adapter_search_found_devices(adapter, &match);
- } while (dev);
-
- hci_close_dev(dd);
-
- if (!req_sent)
- return -ENODATA;
-
- return 0;
-}
-
void hcid_dbus_inquiry_complete(bdaddr_t *local)
{
struct btd_adapter *adapter;
@@ -556,7 +488,7 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local)
*
* Keep in mind that non D-Bus requests can arrive.
*/
- if (found_device_req_name(adapter) == 0)
+ if (adapter_resolve_names(adapter) == 0)
return;

state = adapter_get_state(adapter);
@@ -791,7 +723,7 @@ proceed:
adapter_remove_found_device(adapter, peer);

/* check if there is more devices to request names */
- if (found_device_req_name(adapter) == 0)
+ if (adapter_resolve_names(adapter) == 0)
return;

state = adapter_get_state(adapter);
--
1.5.6.3



2009-06-30 15:11:58

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 1/3] Renaming found_device_req_name to adapter_resolve_names

Hi Alok,

On Tue, Jun 23, 2009, [email protected] wrote:
> From: Alok Barsode <[email protected]>
>
> ---
> src/adapter.c | 52 ++++++++++++++++++++++++++++++++++++++++
> src/adapter.h | 2 +
> src/dbus-hci.c | 72 +------------------------------------------------------
> 3 files changed, 56 insertions(+), 70 deletions(-)

This one doesn't apply anymore cleanly to upstream git. Could you please
rebase it (and the other two patches in this set as well) against latest
upstream git?

Johan

2009-06-23 14:50:20

by alok barsode

[permalink] [raw]
Subject: [PATCH 2/3] Adding resolve name functionality to hciops plugin.

From: Alok Barsode <[email protected]>

---
plugins/hciops.c | 24 ++++++++++++++++++++++++
src/adapter.c | 19 ++-----------------
src/adapter.h | 1 +
3 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index dae79b3..9a873fd 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -628,6 +628,29 @@ static int hciops_stop_discovery(int index)
return err;
}

+static int hciops_resolve_name(int index, bdaddr_t *bdaddr)
+{
+ remote_name_req_cp cp;
+ int dd, err = 0;
+
+ dd = hci_open_dev(index);
+ if (dd < 0)
+ return -EIO;
+
+ memset(&cp, 0, sizeof(cp));
+ bacpy(&cp.bdaddr, bdaddr);
+ cp.pscan_rep_mode = 0x02;
+
+ err = hci_send_cmd(dd, OGF_LINK_CTL, OCF_REMOTE_NAME_REQ,
+ REMOTE_NAME_REQ_CP_SIZE, &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,
@@ -639,6 +662,7 @@ static struct btd_adapter_ops hci_ops = {
.set_limited_discoverable = hciops_set_limited_discoverable,
.start_discovery = hciops_start_discovery,
.stop_discovery = hciops_stop_discovery,
+ .resolve_name = hciops_resolve_name,
};

static int hciops_init(void)
diff --git a/src/adapter.c b/src/adapter.c
index 9a913ac..cd5c1d0 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -260,9 +260,8 @@ int pending_remote_name_cancel(struct btd_adapter *adapter)

int adapter_resolve_names(struct btd_adapter *adapter)
{
- remote_name_req_cp cp;
struct remote_dev_info *dev, match;
- int dd, err;
+ int err;

memset(&match, 0, sizeof(struct remote_dev_info));
bacpy(&match.bdaddr, BDADDR_ANY);
@@ -272,21 +271,12 @@ int adapter_resolve_names(struct btd_adapter *adapter)
if (!dev)
return -ENODATA;

- dd = hci_open_dev(adapter->dev_id);
- if (dd < 0)
- return -errno;
-
/* send at least one request or return failed if the list is empty */
do {
/* flag to indicate the current remote name requested */
dev->name_status = NAME_REQUESTED;

- memset(&cp, 0, sizeof(cp));
- bacpy(&cp.bdaddr, &dev->bdaddr);
- cp.pscan_rep_mode = 0x02;
-
- err = hci_send_cmd(dd, OGF_LINK_CTL, OCF_REMOTE_NAME_REQ,
- REMOTE_NAME_REQ_CP_SIZE, &cp);
+ err = adapter_ops->resolve_name(adapter->dev_id, &dev->bdaddr);

if (!err)
break;
@@ -302,11 +292,6 @@ int adapter_resolve_names(struct btd_adapter *adapter)
dev = adapter_search_found_devices(adapter, &match);
} while (dev);

- hci_close_dev(dd);
-
- if (err < 0)
- err = errno;
-
return err;
}

diff --git a/src/adapter.h b/src/adapter.h
index fca34eb..e087bb0 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -164,6 +164,7 @@ struct btd_adapter_ops {
gboolean limited);
int (*start_discovery) (int index, gboolean periodic);
int (*stop_discovery) (int index);
+ int (*resolve_name) (int index, bdaddr_t *bdaddr);
};

int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
--
1.5.6.3


2009-06-23 14:50:21

by alok barsode

[permalink] [raw]
Subject: [PATCH 3/3] Adding cancel_resolve_name functionality to hciops plugin.

From: Alok Barsode <[email protected]>

---
plugins/hciops.c | 23 +++++++++++++++++++++++
src/adapter.c | 25 ++++++-------------------
src/adapter.h | 1 +
3 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 9a873fd..7e34b12 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -651,6 +651,28 @@ static int hciops_resolve_name(int index, bdaddr_t *bdaddr)
return err;
}

+static int hciops_cancel_resolve_name(int index, bdaddr_t *bdaddr)
+{
+ remote_name_req_cancel_cp cp;
+ int dd, err = 0;
+
+ dd = hci_open_dev(index);
+ if (dd < 0)
+ return -EIO;
+
+ memset(&cp, 0, sizeof(cp));
+ bacpy(&cp.bdaddr, bdaddr);
+
+ err = hci_send_cmd(dd, OGF_LINK_CTL, OCF_REMOTE_NAME_REQ_CANCEL,
+ REMOTE_NAME_REQ_CANCEL_CP_SIZE, &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,
@@ -663,6 +685,7 @@ static struct btd_adapter_ops hci_ops = {
.start_discovery = hciops_start_discovery,
.stop_discovery = hciops_stop_discovery,
.resolve_name = hciops_resolve_name,
+ .cancel_resolve_name = hciops_cancel_resolve_name,
};

static int hciops_init(void)
diff --git a/src/adapter.c b/src/adapter.c
index cd5c1d0..e9bd1d8 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -227,34 +227,21 @@ void clear_found_devices_list(struct btd_adapter *adapter)
int pending_remote_name_cancel(struct btd_adapter *adapter)
{
struct remote_dev_info *dev, match;
- GSList *l;
- int dd, err = 0;
+ int err = 0;

/* find the pending remote name request */
memset(&match, 0, sizeof(struct remote_dev_info));
bacpy(&match.bdaddr, BDADDR_ANY);
match.name_status = NAME_REQUESTED;

- l = g_slist_find_custom(adapter->found_devices, &match,
- (GCompareFunc) found_device_cmp);
- if (!l) /* no pending request */
- return 0;
-
- dd = hci_open_dev(adapter->dev_id);
- if (dd < 0)
- return -ENODEV;
-
- dev = l->data;
+ dev = adapter_search_found_devices(adapter, &match);
+ if (!dev) /* no pending request */
+ return -ENODATA;

- if (hci_read_remote_name_cancel(dd, &dev->bdaddr,
- HCI_REQ_TIMEOUT) < 0) {
- err = -errno;
+ err = adapter_ops->cancel_resolve_name(adapter->dev_id, &dev->bdaddr);
+ if (err < 0)
error("Remote name cancel failed: %s(%d)",
strerror(errno), errno);
- }
-
- hci_close_dev(dd);
-
return err;
}

diff --git a/src/adapter.h b/src/adapter.h
index e087bb0..f631576 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -165,6 +165,7 @@ struct btd_adapter_ops {
int (*start_discovery) (int index, gboolean periodic);
int (*stop_discovery) (int index);
int (*resolve_name) (int index, bdaddr_t *bdaddr);
+ int (*cancel_resolve_name) (int index, bdaddr_t *bdaddr);
};

int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
--
1.5.6.3


2009-07-02 14:21:29

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 1/3] Renaming found_device_req_name to adapter_resolve_names

Hi Alok,

On Tue, Jun 30, 2009, Johan Hedberg wrote:
> On Tue, Jun 23, 2009, [email protected] wrote:
> > From: Alok Barsode <[email protected]>
> >
> > ---
> > src/adapter.c | 52 ++++++++++++++++++++++++++++++++++++++++
> > src/adapter.h | 2 +
> > src/dbus-hci.c | 72 +------------------------------------------------------
> > 3 files changed, 56 insertions(+), 70 deletions(-)
>
> This one doesn't apply anymore cleanly to upstream git. Could you please
> rebase it (and the other two patches in this set as well) against latest
> upstream git?

The updated patches have now been pulled from your tree and merged
upstream. Thanks!

Johan