2014-01-25 00:55:06

by Petri Gynther

[permalink] [raw]
Subject: [PATCH] Rename adapter_remove_device to btd_adapter_remove_device

Allow this symbol to be exported and usable from external plugins.
---
src/adapter.c | 14 +++++++-------
src/adapter.h | 3 +++
2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 570a5bf..649fc7a 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1036,8 +1036,8 @@ static void service_auth_cancel(struct service_auth *auth)
g_free(auth);
}

-static void adapter_remove_device(struct btd_adapter *adapter,
- struct btd_device *dev)
+void btd_adapter_remove_device(struct btd_adapter *adapter,
+ struct btd_device *dev)
{
GList *l;

@@ -1531,7 +1531,7 @@ static gboolean remove_temp_devices(gpointer user_data)
next = g_slist_next(l);

if (device_is_temporary(dev))
- adapter_remove_device(adapter, dev);
+ btd_adapter_remove_device(adapter, dev);
}

return FALSE;
@@ -2159,7 +2159,7 @@ static DBusMessage *remove_device(DBusConnection *conn,
btd_device_set_temporary(device, TRUE);

if (!btd_device_is_connected(device)) {
- adapter_remove_device(adapter, device);
+ btd_adapter_remove_device(adapter, device);
return dbus_message_new_method_return(msg);
}

@@ -4268,7 +4268,7 @@ static void adapter_remove_connection(struct btd_adapter *adapter,
const char *path = device_get_path(device);

DBG("Removing temporary device %s", path);
- adapter_remove_device(adapter, device);
+ btd_adapter_remove_device(adapter, device);
}
}

@@ -5834,7 +5834,7 @@ static void connect_failed_callback(uint16_t index, uint16_t length,
* when it is temporary. */
if (device && !device_is_bonding(device, NULL)
&& device_is_temporary(device))
- adapter_remove_device(adapter, device);
+ btd_adapter_remove_device(adapter, device);
}

static void unpaired_callback(uint16_t index, uint16_t length,
@@ -5865,7 +5865,7 @@ static void unpaired_callback(uint16_t index, uint16_t length,
if (btd_device_is_connected(device))
device_request_disconnect(device, NULL);
else
- adapter_remove_device(adapter, device);
+ btd_adapter_remove_device(adapter, device);
}

static void read_info_complete(uint8_t status, uint16_t length,
diff --git a/src/adapter.h b/src/adapter.h
index de5b07d..e2e73dc 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -36,6 +36,7 @@
#define INVALID_PASSKEY 0xffffffff

struct btd_adapter;
+struct btd_device;

struct btd_adapter *btd_adapter_get_default(void);
bool btd_adapter_is_default(struct btd_adapter *adapter);
@@ -90,6 +91,8 @@ bool btd_adapter_get_connectable(struct btd_adapter *adapter);

uint32_t btd_adapter_get_class(struct btd_adapter *adapter);
const char *btd_adapter_get_name(struct btd_adapter *adapter);
+void btd_adapter_remove_device(struct btd_adapter *adapter,
+ struct btd_device *dev);
struct btd_device *btd_adapter_get_device(struct btd_adapter *adapter,
const bdaddr_t *addr,
uint8_t addr_type);
--
1.8.5.3



2014-01-27 19:45:24

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH] Rename adapter_remove_device to btd_adapter_remove_device

Hi Petri,

On Mon, Jan 27, 2014, Petri Gynther wrote:
> Once BlueZ host and the remote have been paired successfully the first
> time, the remote has a key combination available that allows it to be
> unpaired and reset to initial state. But, BlueZ won't know about that.
> It still considers the remote paired. Thus, when the BD address
> arrives to the IR-assist plugin again, the plugin needs to clear all
> old state from BlueZ side and start over as if the device had never
> been discovered before.
>
> The old device removal and new device creation are handled in the
> plugin, since the device creation part is not possible over D-Bus.
> However, once the device is created, the pairing is handled in a
> separate Python script.

Fair enough. I've now applied the patch.

Btw, please don't use top-posting on this list. It makes it difficult to
track the discussion when we've got inline quoting and top posting mixed
together.

Johan

2014-01-27 19:31:52

by Petri Gynther

[permalink] [raw]
Subject: Re: [PATCH] Rename adapter_remove_device to btd_adapter_remove_device

Hi Johan,

Once BlueZ host and the remote have been paired successfully the first
time, the remote has a key combination available that allows it to be
unpaired and reset to initial state. But, BlueZ won't know about that.
It still considers the remote paired. Thus, when the BD address
arrives to the IR-assist plugin again, the plugin needs to clear all
old state from BlueZ side and start over as if the device had never
been discovered before.

The old device removal and new device creation are handled in the
plugin, since the device creation part is not possible over D-Bus.
However, once the device is created, the pairing is handled in a
separate Python script.

-- Petri

On Mon, Jan 27, 2014 at 10:13 AM, Johan Hedberg <[email protected]> wrote:
> Hi Petri,
>
> On Sun, Jan 26, 2014, Petri Gynther wrote:
>> I would need this for the IR-assist device discovery plugin that I'm
>> writing. Basically, I have a HID remote control which is not
>> discoverable (but it is connectable). When this HID remote is in
>> unpaired state, it sends its BD address to the host via IR. The plugin
>> will get the BD address and do the following:
>>
>> device = btd_adapter_find_device(adapter, &device_bdaddr);
>> if (device) {
>> /* remove old pairing and device info */
>> btd_device_set_temporary(device, TRUE);
>> btd_adapter_remove_device(adapter, device);
>> }
>
> If the device is only discoverable through IR why would there be an
> existing device object for it? And if there does exist a device object
> doesn't it mean it's already paired and you don't need to repair?
>
> Johan

2014-01-27 18:13:07

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH] Rename adapter_remove_device to btd_adapter_remove_device

Hi Petri,

On Sun, Jan 26, 2014, Petri Gynther wrote:
> I would need this for the IR-assist device discovery plugin that I'm
> writing. Basically, I have a HID remote control which is not
> discoverable (but it is connectable). When this HID remote is in
> unpaired state, it sends its BD address to the host via IR. The plugin
> will get the BD address and do the following:
>
> device = btd_adapter_find_device(adapter, &device_bdaddr);
> if (device) {
> /* remove old pairing and device info */
> btd_device_set_temporary(device, TRUE);
> btd_adapter_remove_device(adapter, device);
> }

If the device is only discoverable through IR why would there be an
existing device object for it? And if there does exist a device object
doesn't it mean it's already paired and you don't need to repair?

Johan

2014-01-27 04:07:50

by Petri Gynther

[permalink] [raw]
Subject: Re: [PATCH] Rename adapter_remove_device to btd_adapter_remove_device

Hi Johan,

I would need this for the IR-assist device discovery plugin that I'm
writing. Basically, I have a HID remote control which is not
discoverable (but it is connectable). When this HID remote is in
unpaired state, it sends its BD address to the host via IR. The plugin
will get the BD address and do the following:

device = btd_adapter_find_device(adapter, &device_bdaddr);
if (device) {
/* remove old pairing and device info */
btd_device_set_temporary(device, TRUE);
btd_adapter_remove_device(adapter, device);
}

/* (re)create the device */
device = btd_adapter_get_device(adapter, &device_bdaddr, BDADDR_BREDR);
btd_device_device_set_name(device, ...);
btd_device_set_pnpid(device, ...);
btd_device_set_temporary(device, FALSE);

-- Petri

On Sat, Jan 25, 2014 at 2:13 PM, Johan Hedberg <[email protected]> wrote:
> Hi Petri,
>
> On Fri, Jan 24, 2014, Petri Gynther wrote:
>> Allow this symbol to be exported and usable from external plugins.
>> ---
>> src/adapter.c | 14 +++++++-------
>> src/adapter.h | 3 +++
>> 2 files changed, 10 insertions(+), 7 deletions(-)
>
> The patch looks fine, but we usually don't export symbols without
> knowing that there exists a valid use case for it. So could you perhaps
> give some background (or even a follow-up patch) to explain what you
> need this for?
>
> Johan

2014-01-25 22:13:29

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH] Rename adapter_remove_device to btd_adapter_remove_device

Hi Petri,

On Fri, Jan 24, 2014, Petri Gynther wrote:
> Allow this symbol to be exported and usable from external plugins.
> ---
> src/adapter.c | 14 +++++++-------
> src/adapter.h | 3 +++
> 2 files changed, 10 insertions(+), 7 deletions(-)

The patch looks fine, but we usually don't export symbols without
knowing that there exists a valid use case for it. So could you perhaps
give some background (or even a follow-up patch) to explain what you
need this for?

Johan