* Re: [PATCH BlueZ] test: Update simple-agent to new API
From: Marcel Holtmann @ 2012-12-17 23:23 UTC (permalink / raw)
To: João Paulo Rechi Vita; +Cc: linux-bluetooth
In-Reply-To: <1355784500-28062-1-git-send-email-jprvita@openbossa.org>
Hi Joao Paulo,
> The method org.bluez.Device.Pair() doesn't have arguments anymore. This
> commit fixes the following error:
>
> $ test/simple-agent hci0 4C:B1:99:F1:BC:E9
> Agent registered
> ERROR:dbus.connection:Unable to set arguments (u'/test/agent', u'Keybo
> ardDisplay') according to signature '': <type 'exceptions.TypeError'>:
> Fewer items found in D-Bus signature than in Python arguments
> Traceback (most recent call last):
> File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 586
> , in msg_reply_handler
> reply_handler(*message.get_args_list(**get_args_opts))
> File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 391, i
> n _introspect_reply_handler
> self._introspect_execute_queue()
> File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 378, i
> n _introspect_execute_queue
> proxy_method(*args, **keywords)
> File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 132, i
> n __call__
> **keywords)
> File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 566
> , in call_async
> message.append(signature=signature, *args)
> TypeError: Fewer items found in D-Bus signature than in Python argumen
> ts
> ---
> test/simple-agent | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
patch has been applied.
Regards
Marcel
^ permalink raw reply
* [PATCH BlueZ] test: Update simple-agent to new API
From: João Paulo Rechi Vita @ 2012-12-17 22:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: João Paulo Rechi Vita
The method org.bluez.Device.Pair() doesn't have arguments anymore. This
commit fixes the following error:
$ test/simple-agent hci0 4C:B1:99:F1:BC:E9
Agent registered
ERROR:dbus.connection:Unable to set arguments (u'/test/agent', u'Keybo
ardDisplay') according to signature '': <type 'exceptions.TypeError'>:
Fewer items found in D-Bus signature than in Python arguments
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 586
, in msg_reply_handler
reply_handler(*message.get_args_list(**get_args_opts))
File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 391, i
n _introspect_reply_handler
self._introspect_execute_queue()
File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 378, i
n _introspect_execute_queue
proxy_method(*args, **keywords)
File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 132, i
n __call__
**keywords)
File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 566
, in call_async
message.append(signature=signature, *args)
TypeError: Fewer items found in D-Bus signature than in Python argumen
ts
---
test/simple-agent | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/test/simple-agent b/test/simple-agent
index deb6497..bb40eae 100755
--- a/test/simple-agent
+++ b/test/simple-agent
@@ -169,9 +169,7 @@ if __name__ == '__main__':
options.adapter_pattern)
dev_path = device.object_path
agent.set_exit_on_release(False)
- device.Pair(path, capability, timeout=options.timeout,
- reply_handler=pair_reply,
- error_handler=pair_error)
+ device.Pair(reply_handler=pair_reply, error_handler=pair_error)
device_obj = device
else:
manager.RequestDefault()
--
1.7.11.7
^ permalink raw reply related
* Re: [PATCH BlueZ] hog: Fix removing HoG device bug
From: Andre Guedes @ 2012-12-17 20:20 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355771003-2518-1-git-send-email-andre.guedes@openbossa.org>
Please ignore this patch. I'll do some code refactoring in HoG code
before fixing the bug.
On Mon, Dec 17, 2012 at 4:03 PM, Andre Guedes
<andre.guedes@openbossa.org> wrote:
> We should remove only hog_devices from the given btd_device.
> Otherwise, all hog_devices will be removed.
> ---
> profiles/input/hog_device.c | 5 +++++
> profiles/input/hog_device.h | 1 +
> profiles/input/hog_manager.c | 5 ++++-
> 3 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/profiles/input/hog_device.c b/profiles/input/hog_device.c
> index 06dab6d..cc68080 100644
> --- a/profiles/input/hog_device.c
> +++ b/profiles/input/hog_device.c
> @@ -789,3 +789,8 @@ int hog_device_set_control_point(struct hog_device *hogdev, gboolean suspend)
>
> return 0;
> }
> +
> +struct btd_device *hog_device_get_device(struct hog_device *hogdev)
> +{
> + return hogdev->device;
> +}
> diff --git a/profiles/input/hog_device.h b/profiles/input/hog_device.h
> index d1bfc08..60c4f12 100644
> --- a/profiles/input/hog_device.h
> +++ b/profiles/input/hog_device.h
> @@ -31,3 +31,4 @@ struct hog_device *hog_device_register(struct btd_device *device,
> struct gatt_primary *prim);
> int hog_device_unregister(struct hog_device *hogdev);
> int hog_device_set_control_point(struct hog_device *hogdev, gboolean suspend);
> +struct btd_device *hog_device_get_device(struct hog_device *hogdev);
> diff --git a/profiles/input/hog_manager.c b/profiles/input/hog_manager.c
> index 595b160..c7b98c5 100644
> --- a/profiles/input/hog_manager.c
> +++ b/profiles/input/hog_manager.c
> @@ -106,6 +106,9 @@ static int hog_device_probe(struct btd_profile *p, struct btd_device *device,
>
> static void remove_device(gpointer hogdev, gpointer b)
> {
> + if (hog_device_get_device(hogdev) != b)
> + return;
> +
> devices = g_slist_remove(devices, hogdev);
> hog_device_unregister(hogdev);
> }
> @@ -116,7 +119,7 @@ static void hog_device_remove(struct btd_profile *p, struct btd_device *device)
>
> DBG("path %s", path);
>
> - g_slist_foreach(devices, remove_device, NULL);
> + g_slist_foreach(devices, remove_device, device);
> }
>
> static struct btd_profile hog_profile = {
> --
> 1.8.0.1
>
^ permalink raw reply
* [PATCH BlueZ] hog: Fix removing HoG device bug
From: Andre Guedes @ 2012-12-17 19:03 UTC (permalink / raw)
To: linux-bluetooth
We should remove only hog_devices from the given btd_device.
Otherwise, all hog_devices will be removed.
---
profiles/input/hog_device.c | 5 +++++
profiles/input/hog_device.h | 1 +
profiles/input/hog_manager.c | 5 ++++-
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/profiles/input/hog_device.c b/profiles/input/hog_device.c
index 06dab6d..cc68080 100644
--- a/profiles/input/hog_device.c
+++ b/profiles/input/hog_device.c
@@ -789,3 +789,8 @@ int hog_device_set_control_point(struct hog_device *hogdev, gboolean suspend)
return 0;
}
+
+struct btd_device *hog_device_get_device(struct hog_device *hogdev)
+{
+ return hogdev->device;
+}
diff --git a/profiles/input/hog_device.h b/profiles/input/hog_device.h
index d1bfc08..60c4f12 100644
--- a/profiles/input/hog_device.h
+++ b/profiles/input/hog_device.h
@@ -31,3 +31,4 @@ struct hog_device *hog_device_register(struct btd_device *device,
struct gatt_primary *prim);
int hog_device_unregister(struct hog_device *hogdev);
int hog_device_set_control_point(struct hog_device *hogdev, gboolean suspend);
+struct btd_device *hog_device_get_device(struct hog_device *hogdev);
diff --git a/profiles/input/hog_manager.c b/profiles/input/hog_manager.c
index 595b160..c7b98c5 100644
--- a/profiles/input/hog_manager.c
+++ b/profiles/input/hog_manager.c
@@ -106,6 +106,9 @@ static int hog_device_probe(struct btd_profile *p, struct btd_device *device,
static void remove_device(gpointer hogdev, gpointer b)
{
+ if (hog_device_get_device(hogdev) != b)
+ return;
+
devices = g_slist_remove(devices, hogdev);
hog_device_unregister(hogdev);
}
@@ -116,7 +119,7 @@ static void hog_device_remove(struct btd_profile *p, struct btd_device *device)
DBG("path %s", path);
- g_slist_foreach(devices, remove_device, NULL);
+ g_slist_foreach(devices, remove_device, device);
}
static struct btd_profile hog_profile = {
--
1.8.0.1
^ permalink raw reply related
* Re: [PATCH BlueZ 3/5] core: Simplify set_powered to not use set_mode
From: Johan Hedberg @ 2012-12-17 18:30 UTC (permalink / raw)
To: Anderson Lizardo; +Cc: Luiz Augusto von Dentz, linux-bluetooth
In-Reply-To: <CAJdJm_N+5_wcvGw7wkgx+Ryr3EkB-Mcd0hfGmK4u=42LL9=fHg@mail.gmail.com>
Hi Lizardo,
On Mon, Dec 17, 2012, Anderson Lizardo wrote:
> On Mon, Dec 17, 2012 at 11:45 AM, Luiz Augusto von Dentz
> <luiz.dentz@gmail.com> wrote:
> > - err = set_mode(adapter, mode);
> > + err = mgmt_set_powered(adapter->dev_id, powered);
> > if (err < 0)
> > return g_dbus_pending_property_error(id,
> > ERROR_INTERFACE ".Failed",
> > - strerror(-err));
> > + strerror(err));
>
> Looks like you changed the line above by mistake, err is negative and
> thus need to be made positive to pass to strerror().
Since I missed this one and already pushed the patch set I went ahead
and applied a separate fix for it.
Johan
^ permalink raw reply
* Re: [PATCH BlueZ 3/5] core: Simplify set_powered to not use set_mode
From: Anderson Lizardo @ 2012-12-17 15:55 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1355759155-27921-3-git-send-email-luiz.dentz@gmail.com>
Hi Luiz,
On Mon, Dec 17, 2012 at 11:45 AM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> - err = set_mode(adapter, mode);
> + err = mgmt_set_powered(adapter->dev_id, powered);
> if (err < 0)
> return g_dbus_pending_property_error(id,
> ERROR_INTERFACE ".Failed",
> - strerror(-err));
> + strerror(err));
Looks like you changed the line above by mistake, err is negative and
thus need to be made positive to pass to strerror().
Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [PATCH 01/13] adapter: Add btd_adapter_for_each_device()
From: Johan Hedberg @ 2012-12-17 15:54 UTC (permalink / raw)
To: Frédéric Danis; +Cc: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>
Hi Frédéric,
On Mon, Dec 17, 2012, Frédéric Danis wrote:
> ---
> src/adapter.c | 7 +++++++
> src/adapter.h | 4 ++++
> 2 files changed, 11 insertions(+)
All patches in this set have been applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH BlueZ 1/5] core: Fix set_pairable to not attempt to power on the adapter
From: Johan Hedberg @ 2012-12-17 15:51 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1355759155-27921-1-git-send-email-luiz.dentz@gmail.com>
Hi Luiz,
On Mon, Dec 17, 2012, Luiz Augusto von Dentz wrote:
> Pairable flag is completely independent flag for the kernel so we can
> reflect this in the D-Bus API.
> ---
> src/adapter.c | 20 --------------------
> 1 file changed, 20 deletions(-)
All five patches have been applied. Thanks.
Johan
^ permalink raw reply
* [PATCH BlueZ 5/5] core: Fix emitting changes to properties on power off
From: Luiz Augusto von Dentz @ 2012-12-17 15:45 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355759155-27921-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Discoverable and pairable are independent to the powered state so they
should not be changed just because the controller power state is set to
off.
---
src/adapter.c | 15 ---------------
1 file changed, 15 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index b15c8b7..5fe3010 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1688,7 +1688,6 @@ static void unload_drivers(struct btd_adapter *adapter)
int btd_adapter_stop(struct btd_adapter *adapter)
{
DBusConnection *conn = btd_get_dbus_connection();
- bool emit_discoverable = false, emit_pairable = false;
bool emit_discovering = false;
/* check pending requests */
@@ -1711,24 +1710,10 @@ int btd_adapter_stop(struct btd_adapter *adapter)
adapter_remove_connection(adapter, device);
}
- if (adapter->discoverable)
- emit_discoverable = true;
-
- if (adapter->connectable && adapter->pairable == TRUE)
- emit_pairable = true;
-
- adapter->discoverable = FALSE;
adapter->connectable = false;
adapter->off_requested = FALSE;
- if (emit_discoverable)
- g_dbus_emit_property_changed(conn, adapter->path,
- ADAPTER_INTERFACE, "Discoverable");
- if (emit_pairable)
- g_dbus_emit_property_changed(conn, adapter->path,
- ADAPTER_INTERFACE, "Pairable");
-
if (emit_discovering)
g_dbus_emit_property_changed(conn, adapter->path,
ADAPTER_INTERFACE, "Discovering");
--
1.7.11.7
^ permalink raw reply related
* [PATCH BlueZ 4/5] core: Remove mode session code
From: Luiz Augusto von Dentz @ 2012-12-17 15:45 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355759155-27921-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mode session no longer are needed since RequestSession is gone
---
src/adapter.c | 210 +++++-----------------------------------------------------
1 file changed, 15 insertions(+), 195 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 2d81f66..b15c8b7 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -89,8 +89,6 @@ static const char *base_path = "/org/bluez";
static GSList *adapter_drivers = NULL;
enum session_req_type {
- SESSION_TYPE_MODE_GLOBAL = 0,
- SESSION_TYPE_MODE_SESSION,
SESSION_TYPE_DISC_INTERLEAVED,
SESSION_TYPE_DISC_LE_SCAN
};
@@ -99,10 +97,8 @@ struct session_req {
struct btd_adapter *adapter;
enum session_req_type type;
DBusMessage *msg; /* Unreplied message ref */
- GDBusPendingPropertySet prop_id; /* Pending Properties.Set() */
char *owner; /* Bus name of the owner */
guint id; /* Listener id */
- uint8_t mode; /* Requested mode */
int refcount; /* Session refcount */
gboolean got_reply; /* Agent reply received */
};
@@ -135,16 +131,12 @@ struct btd_adapter {
uint32_t discov_timeout; /* discoverable time(sec) */
guint pairable_timeout_id; /* pairable timeout id */
uint32_t pairable_timeout; /* pairable time(sec) */
- uint8_t mode; /* off, connectable, discoverable,
- * limited */
- uint8_t global_mode; /* last valid global mode */
struct session_req *pending_mode;
guint auth_idle_id; /* Pending authorization dequeue */
GQueue *auths; /* Ongoing and pending auths */
GSList *connections; /* Connected devices */
GSList *devices; /* Devices structure pointers */
guint remove_temp; /* Remove devices timer */
- GSList *mode_sessions; /* Request Mode sessions */
GSList *disc_sessions; /* Discovery sessions */
struct session_req *scanning_session;
GSList *connect_list; /* Devices to connect when found */
@@ -181,20 +173,6 @@ int btd_adapter_set_class(struct btd_adapter *adapter, uint8_t major,
return mgmt_set_dev_class(adapter->dev_id, major, minor);
}
-static const char *mode2str(uint8_t mode)
-{
- switch(mode) {
- case MODE_OFF:
- return "off";
- case MODE_CONNECTABLE:
- return "connectable";
- case MODE_DISCOVERABLE:
- return "discoverable";
- default:
- return "unknown";
- }
-}
-
static uint8_t get_mode(const char *mode)
{
if (strcasecmp("off", mode) == 0)
@@ -288,16 +266,15 @@ static struct session_req *session_ref(struct session_req *req)
}
static struct session_req *create_session(struct btd_adapter *adapter,
- DBusMessage *msg, uint8_t mode,
- enum session_req_type type,
- GDBusWatchFunction cb)
+ DBusMessage *msg,
+ enum session_req_type type,
+ GDBusWatchFunction cb)
{
const char *sender;
struct session_req *req;
req = g_new0(struct session_req, 1);
req->adapter = adapter;
- req->mode = mode;
req->type = type;
if (msg == NULL)
@@ -313,56 +290,11 @@ static struct session_req *create_session(struct btd_adapter *adapter,
req->id = g_dbus_add_disconnect_watch(btd_get_dbus_connection(),
sender, cb, req, NULL);
- info("%s session %p with %s activated",
- req->mode ? "Mode" : "Discovery", req, sender);
+ info("session %p with %s activated", req, sender);
return session_ref(req);
}
-static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
-{
- int err;
-
- if (adapter->pending_mode != NULL)
- return -EALREADY;
-
- if (!adapter->powered && new_mode != MODE_OFF) {
- err = mgmt_set_powered(adapter->dev_id, TRUE);
- if (err < 0)
- return err;
-
- goto done;
- }
-
- if (adapter->powered && new_mode == MODE_OFF) {
- err = mgmt_set_powered(adapter->dev_id, FALSE);
- if (err < 0)
- return err;
-
- adapter->off_requested = TRUE;
-
- goto done;
- }
-
- if (new_mode == adapter->mode)
- return 0;
-
- if (new_mode == MODE_CONNECTABLE)
- err = mgmt_set_discoverable(adapter->dev_id, FALSE, 0);
- else
- err = mgmt_set_discoverable(adapter->dev_id, TRUE,
- adapter->discov_timeout);
- if (err < 0)
- return err;
-
-done:
- store_adapter_info(adapter);
-
- DBG("%s", mode2str(new_mode));
-
- return 0;
-}
-
static void set_discoverable(struct btd_adapter *adapter,
gboolean discoverable, GDBusPendingPropertySet id)
{
@@ -386,6 +318,8 @@ static void set_powered(struct btd_adapter *adapter, gboolean powered,
if (powered == FALSE)
adapter->off_requested = TRUE;
+
+ g_dbus_pending_property_success(id);
}
static void set_pairable(struct btd_adapter *adapter, gboolean pairable,
@@ -453,23 +387,6 @@ static struct session_req *find_session(GSList *list, const char *sender)
return NULL;
}
-static uint8_t get_needed_mode(struct btd_adapter *adapter, uint8_t mode)
-{
- GSList *l;
-
- if (adapter->global_mode > mode)
- mode = adapter->global_mode;
-
- for (l = adapter->mode_sessions; l; l = l->next) {
- struct session_req *req = l->data;
-
- if (req->mode > mode)
- mode = req->mode;
- }
-
- return mode;
-}
-
static void send_devices_found(struct btd_adapter *adapter)
{
struct discovery *discovery = adapter->discovery;
@@ -565,38 +482,16 @@ static void session_remove(struct session_req *req)
{
struct btd_adapter *adapter = req->adapter;
- /* Ignore global requests */
- if (req->type == SESSION_TYPE_MODE_GLOBAL)
- return;
-
- DBG("%s session %p with %s deactivated",
- req->mode ? "Mode" : "Discovery", req, req->owner);
-
- if (req->mode) {
- uint8_t mode;
+ DBG("session %p with %s deactivated", req, req->owner);
- adapter->mode_sessions = g_slist_remove(adapter->mode_sessions,
- req);
+ adapter->disc_sessions = g_slist_remove(adapter->disc_sessions, req);
- mode = get_needed_mode(adapter, adapter->global_mode);
-
- if (mode == adapter->mode)
- return;
-
- DBG("Switching to '%s' mode", mode2str(mode));
-
- set_mode(adapter, mode);
- } else {
- adapter->disc_sessions = g_slist_remove(adapter->disc_sessions,
- req);
-
- if (adapter->disc_sessions)
- return;
+ if (adapter->disc_sessions)
+ return;
- DBG("Stopping discovery");
+ DBG("Stopping discovery");
- stop_discovery(adapter);
- }
+ stop_discovery(adapter);
}
static void session_free(void *data)
@@ -1000,7 +895,7 @@ static DBusMessage *adapter_start_discovery(DBusConnection *conn,
return btd_error_failed(msg, strerror(-err));
done:
- req = create_session(adapter, msg, 0, SESSION_TYPE_DISC_INTERLEAVED,
+ req = create_session(adapter, msg, SESSION_TYPE_DISC_INTERLEAVED,
session_owner_exit);
adapter->disc_sessions = g_slist_append(adapter->disc_sessions, req);
@@ -1701,8 +1596,7 @@ void adapter_connect_list_add(struct btd_adapter *adapter,
if (adapter->disc_sessions == NULL)
adapter->discov_id = g_idle_add(discovery_cb, adapter);
- req = create_session(adapter, NULL, 0, SESSION_TYPE_DISC_LE_SCAN,
- NULL);
+ req = create_session(adapter, NULL, SESSION_TYPE_DISC_LE_SCAN, NULL);
adapter->disc_sessions = g_slist_append(adapter->disc_sessions, req);
adapter->scanning_session = req;
}
@@ -1738,8 +1632,7 @@ void btd_adapter_start(struct btd_adapter *adapter)
adapter->disc_sessions != NULL)
return;
- req = create_session(adapter, NULL, 0, SESSION_TYPE_DISC_LE_SCAN,
- NULL);
+ req = create_session(adapter, NULL, SESSION_TYPE_DISC_LE_SCAN, NULL);
adapter->disc_sessions = g_slist_append(adapter->disc_sessions, req);
adapter->scanning_session = req;
@@ -1792,57 +1685,6 @@ static void unload_drivers(struct btd_adapter *adapter)
adapter->profiles = NULL;
}
-static void set_mode_complete(struct btd_adapter *adapter)
-{
- DBusConnection *conn = btd_get_dbus_connection();
- struct session_req *pending;
- int err;
-
- DBG("%s", mode2str(adapter->mode));
-
- if (adapter->mode == MODE_OFF) {
- g_slist_free_full(adapter->mode_sessions, session_free);
- adapter->mode_sessions = NULL;
- }
-
- if (adapter->pending_mode == NULL)
- return;
-
- pending = adapter->pending_mode;
- adapter->pending_mode = NULL;
-
- err = (pending->mode != adapter->mode) ? -EINVAL : 0;
-
- if (pending->type == SESSION_TYPE_MODE_GLOBAL) {
- if (err < 0)
- g_dbus_pending_property_error(pending->prop_id,
- ERROR_INTERFACE ".Failed",
- strerror(-err));
- else {
- adapter->global_mode = adapter->mode;
- g_dbus_pending_property_success(pending->prop_id);
- }
- } else if (pending->msg != NULL) {
- DBusMessage *msg = pending->msg;
- DBusMessage *reply;
-
- if (err < 0)
- reply = btd_error_failed(msg, strerror(-err));
- else
- reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
-
- g_dbus_send_message(conn, reply);
- }
-
- if (err != 0)
- error("unable to set mode: %s", mode2str(pending->mode));
-
- if (adapter->mode != MODE_DISCOVERABLE || adapter->discov_timeout == 0)
- store_adapter_info(adapter);
-
- session_unref(pending);
-}
-
int btd_adapter_stop(struct btd_adapter *adapter)
{
DBusConnection *conn = btd_get_dbus_connection();
@@ -1878,7 +1720,6 @@ int btd_adapter_stop(struct btd_adapter *adapter)
adapter->discoverable = FALSE;
adapter->connectable = false;
- adapter->mode = MODE_OFF;
adapter->off_requested = FALSE;
if (emit_discoverable)
@@ -1897,8 +1738,6 @@ int btd_adapter_stop(struct btd_adapter *adapter)
info("Adapter %s has been disabled", adapter->path);
- set_mode_complete(adapter);
-
return 0;
}
@@ -2710,8 +2549,6 @@ static void load_config(struct btd_adapter *adapter)
gerr = NULL;
}
- adapter->mode = MODE_OFF;
-
mgmt_set_connectable(adapter->dev_id, TRUE);
mgmt_set_discoverable(adapter->dev_id, adapter->discoverable,
adapter->discov_timeout);
@@ -3089,17 +2926,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
}
}
-static uint8_t create_mode(bool connectable, bool discoverable)
-{
- if (connectable && discoverable)
- return MODE_DISCOVERABLE;
-
- if (connectable && !discoverable)
- return MODE_CONNECTABLE;
-
- return MODE_OFF;
-}
-
void adapter_mode_changed(struct btd_adapter *adapter, bool connectable,
bool discoverable)
{
@@ -3118,7 +2944,6 @@ void adapter_mode_changed(struct btd_adapter *adapter, bool connectable,
adapter->connectable = connectable;
adapter->discoverable = discoverable;
- adapter->mode = create_mode(connectable, discoverable);
if (emit_pairable)
g_dbus_emit_property_changed(btd_get_dbus_connection(),
@@ -3126,8 +2951,6 @@ void adapter_mode_changed(struct btd_adapter *adapter, bool connectable,
g_dbus_emit_property_changed(btd_get_dbus_connection(), adapter->path,
ADAPTER_INTERFACE, "Discoverable");
-
- set_mode_complete(adapter);
}
struct agent *adapter_get_agent(struct btd_adapter *adapter)
@@ -3385,9 +3208,6 @@ int btd_adapter_restore_powered(struct btd_adapter *adapter)
if (adapter->powered)
return 0;
- if (adapter->mode == MODE_OFF)
- return 0;
-
return mgmt_set_powered(adapter->dev_id, TRUE);
}
--
1.7.11.7
^ permalink raw reply related
* [PATCH BlueZ 3/5] core: Simplify set_powered to not use set_mode
From: Luiz Augusto von Dentz @ 2012-12-17 15:45 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355759155-27921-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
src/adapter.c | 19 +++++--------------
1 file changed, 5 insertions(+), 14 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index ce4e44e..2d81f66 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -373,28 +373,19 @@ static void set_discoverable(struct btd_adapter *adapter,
static void set_powered(struct btd_adapter *adapter, gboolean powered,
GDBusPendingPropertySet id)
{
- uint8_t mode;
int err;
- if (powered)
- return set_discoverable(adapter, adapter->discoverable, id);
-
- mode = MODE_OFF;
-
- if (mode == adapter->mode) {
- adapter->global_mode = mode;
+ if (adapter->powered == powered)
return g_dbus_pending_property_success(id);
- }
- err = set_mode(adapter, mode);
+ err = mgmt_set_powered(adapter->dev_id, powered);
if (err < 0)
return g_dbus_pending_property_error(id,
ERROR_INTERFACE ".Failed",
- strerror(-err));
+ strerror(err));
- adapter->pending_mode = create_session(adapter, NULL, mode,
- SESSION_TYPE_MODE_GLOBAL, NULL);
- adapter->pending_mode->prop_id = id;
+ if (powered == FALSE)
+ adapter->off_requested = TRUE;
}
static void set_pairable(struct btd_adapter *adapter, gboolean pairable,
--
1.7.11.7
^ permalink raw reply related
* [PATCH BlueZ 2/5] core: Fix set_discoverable to not attempt to power on the adapter
From: Luiz Augusto von Dentz @ 2012-12-17 15:45 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355759155-27921-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Discoverable flag is completely independent flag for the kernel so we
can reflect this in the D-Bus API.
---
src/adapter.c | 21 ++-------------------
1 file changed, 2 insertions(+), 19 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 375bff4..ce4e44e 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -366,25 +366,8 @@ done:
static void set_discoverable(struct btd_adapter *adapter,
gboolean discoverable, GDBusPendingPropertySet id)
{
- uint8_t mode;
- int err;
-
- mode = discoverable ? MODE_DISCOVERABLE : MODE_CONNECTABLE;
-
- if (mode == adapter->mode) {
- adapter->global_mode = mode;
- return g_dbus_pending_property_success(id);
- }
-
- err = set_mode(adapter, mode);
- if (err < 0)
- return g_dbus_pending_property_error(id,
- ERROR_INTERFACE ".Failed",
- strerror(-err));
-
- adapter->pending_mode = create_session(adapter, NULL, mode,
- SESSION_TYPE_MODE_GLOBAL, NULL);
- adapter->pending_mode->prop_id = id;
+ mgmt_set_discoverable(adapter->dev_id, discoverable, 0);
+ g_dbus_pending_property_success(id);
}
static void set_powered(struct btd_adapter *adapter, gboolean powered,
--
1.7.11.7
^ permalink raw reply related
* [PATCH BlueZ 1/5] core: Fix set_pairable to not attempt to power on the adapter
From: Luiz Augusto von Dentz @ 2012-12-17 15:45 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Pairable flag is completely independent flag for the kernel so we can
reflect this in the D-Bus API.
---
src/adapter.c | 20 --------------------
1 file changed, 20 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 96a23e9..375bff4 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -417,29 +417,9 @@ static void set_powered(struct btd_adapter *adapter, gboolean powered,
static void set_pairable(struct btd_adapter *adapter, gboolean pairable,
bool reply, GDBusPendingPropertySet id)
{
- int err;
-
- if (!adapter->connectable)
- return g_dbus_pending_property_error(id,
- ERROR_INTERFACE ".NotReady",
- "Resource Not Ready");
-
if (pairable == adapter->pairable)
goto done;
- if (!adapter->discoverable)
- goto store;
-
- err = set_mode(adapter, MODE_DISCOVERABLE);
- if (err < 0) {
- if (reply)
- g_dbus_pending_property_error(id,
- ERROR_INTERFACE ".Failed",
- strerror(-err));
- return;
- }
-
-store:
mgmt_set_pairable(adapter->dev_id, pairable);
done:
--
1.7.11.7
^ permalink raw reply related
* [PATCH 13/13] TODO: Mark convert storage to ini-file item as done
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>
---
TODO | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/TODO b/TODO
index 5a70e40..f0e494f 100644
--- a/TODO
+++ b/TODO
@@ -60,11 +60,10 @@ BlueZ 5
Priority/Complexity omitted as all items are required before 5.0 is
released.
-- [pending] Convert storage to user per-remote device directories and
- ini-file format
-
Completed items:
+- Convert storage to user per-remote device directories and ini-file format
+
- Don't install libbluetooth by default (put it behind a configure switch)
- Switch plugins to standard D-Bus properties interface
--
1.7.9.5
^ permalink raw reply related
* [PATCH 12/13] bluetoothd: Remove storage info from man page
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>
---
src/bluetoothd.8.in | 50 --------------------------------------------------
1 file changed, 50 deletions(-)
diff --git a/src/bluetoothd.8.in b/src/bluetoothd.8.in
index a7ae77b..a89f02c 100644
--- a/src/bluetoothd.8.in
+++ b/src/bluetoothd.8.in
@@ -37,55 +37,5 @@ Use specific MTU size for SDP server.
.I @CONFIGDIR@/main.conf
Default location of the global configuration file.
-.TP
-.I @STORAGEDIR@/nn:nn:nn:nn:nn:nn/linkkeys
-Default location for link keys of paired devices. The directory
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP
-is the address of the local device. The file is line separated, with
-the following columns separated by whitespace:
-
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP Remote device address.
-
-\fInnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn\fP Link key.
-
-\fIn\fP Link type integer.
-
-.TP
-.I @STORAGEDIR@/nn:nn:nn:nn:nn:nn/names
-Default location for the device name cache. The directory
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP
-is the address of the local device. The file is line separated, with
-the following columns separated by whitespace:
-
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP Remote device address.
-
-\fIname\fP Remote device name, terminated with newline.
-
-.TP
-.I @STORAGEDIR@/nn:nn:nn:nn:nn:nn/features
-Default location for the features cache. The directory
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP
-is the address of the local device. The file is line separated, with
-the following columns separated by whitespace:
-
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP Remote device address.
-
-\fInnnnnnnnnnnnnnnn\fP Remote device LMP features coded as an 8 byte bitfield.
-
-.TP
-.I @STORAGEDIR@/nn:nn:nn:nn:nn:nn/manufacturers
-Default location for the manufacturers cache. The directory
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP
-is the address of the local device. The file is line separated, with
-the following columns separated by whitespace:
-
-\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP Remote device address.
-
-\fIn\fP Remote device manufacturer integer.
-
-\fIn\fP Remote device LMP version integer.
-
-\fIn\fP Remote device LMP sub-version integer.
-
.SH "AUTHOR"
This manual page was written by Marcel Holtmann, Philipp Matthias Hahn and Fredrik Noring.
--
1.7.9.5
^ permalink raw reply related
* [PATCH 11/13] adapter: Fix invalid read in conversions
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>
==8664== Invalid read of size 1
==8664== at 0x45B214: convert_entry (adapter.c:2325)
==8664== by 0x456A44: textfile_foreach (textfile.c:464)
==8664== by 0x45A823: convert_file (adapter.c:2387)
==8664== by 0x45ABDE: convert_device_storage (adapter.c:2869)
==8664== by 0x45F6CE: adapter_init (adapter.c:3043)
==8664== by 0x4594D9: btd_manager_register_adapter (manager.c:176)
==8664== by 0x46DB3E: mgmt_event.part.38 (mgmt.c:1206)
==8664== by 0x4E79D52: g_main_context_dispatch (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
==8664== by 0x4E7A09F: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
==8664== by 0x4E7A499: g_main_loop_run (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
==8664== by 0x409D53: main (main.c:513)
==8664== Address 0x60b99c1 is not stack'd, malloc'd or (recently) free'd
==8664==
---
src/adapter.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index dd1b0b1..ab86b83 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2204,7 +2204,7 @@ static void convert_entry(char *key, char *value, void *user_data)
char *data;
gsize length = 0;
- if (key[17] == '#') {
+ if (strchr(key, '#')) {
key[17] = '\0';
type = key[18] - '0';
}
@@ -2446,7 +2446,7 @@ static void convert_primaries_entry(char *key, char *value, void *user_data)
char *data;
gsize length = 0;
- if (key[17] == '#') {
+ if (strchr(key, '#')) {
key[17] = '\0';
device_type = key[18] - '0';
}
--
1.7.9.5
^ permalink raw reply related
* [PATCH 10/13] adapter: Remove support of pincodes storage file
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>
This is no more supported in new storage.
---
src/adapter.c | 3 +--
src/storage.c | 20 --------------------
src/storage.h | 1 -
3 files changed, 1 insertion(+), 23 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 581c528..dd1b0b1 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3594,8 +3594,7 @@ ssize_t btd_adapter_get_pin(struct btd_adapter *adapter, struct btd_device *dev,
return ret;
}
- return read_pin_code(&adapter->bdaddr, device_get_address(dev),
- pin_buf);
+ return -1;
}
int btd_adapter_set_fast_connectable(struct btd_adapter *adapter,
diff --git a/src/storage.c b/src/storage.c
index 35049f1..375974a 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -144,26 +144,6 @@ int read_local_name(const bdaddr_t *bdaddr, char *name)
return 0;
}
-ssize_t read_pin_code(const bdaddr_t *local, const bdaddr_t *peer, char *pin)
-{
- char filename[PATH_MAX + 1], addr[18], *str;
- ssize_t len;
-
- create_filename(filename, PATH_MAX, local, "pincodes");
-
- ba2str(peer, addr);
- str = textfile_get(filename, addr);
- if (!str)
- return -ENOENT;
-
- strncpy(pin, str, 16);
- len = strlen(pin);
-
- free(str);
-
- return len;
-}
-
sdp_record_t *record_from_string(const gchar *str)
{
sdp_record_t *rec;
diff --git a/src/storage.h b/src/storage.h
index 9a9c82f..8d171b0 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -27,7 +27,6 @@ int read_discoverable_timeout(const char *src, int *timeout);
int read_pairable_timeout(const char *src, int *timeout);
int read_on_mode(const char *src, char *mode, int length);
int read_local_name(const bdaddr_t *bdaddr, char *name);
-ssize_t read_pin_code(const bdaddr_t *local, const bdaddr_t *peer, char *pin);
sdp_record_t *record_from_string(const gchar *str);
sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid);
int read_device_pairable(const bdaddr_t *local, gboolean *mode);
--
1.7.9.5
^ permalink raw reply related
* [PATCH 09/13] proximity: Use new storage architecture
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>
---
profiles/proximity/monitor.c | 72 ++++++++++++++++++++----------------------
1 file changed, 34 insertions(+), 38 deletions(-)
diff --git a/profiles/proximity/monitor.c b/profiles/proximity/monitor.c
index d9ed3ff..0be0ae4 100644
--- a/profiles/proximity/monitor.c
+++ b/profiles/proximity/monitor.c
@@ -83,51 +83,52 @@ struct monitor {
guint attioid;
};
-static inline int create_filename(char *buf, size_t size,
- const bdaddr_t *bdaddr, const char *name)
+static void write_proximity_config(struct btd_device *device, const char *alert,
+ const char *level)
{
- char addr[18];
+ char *filename;
+ GKeyFile *key_file;
+ char *data;
+ gsize length = 0;
- ba2str(bdaddr, addr);
+ filename = btd_device_get_storage_path(device, "proximity");
- return create_name(buf, size, STORAGEDIR, addr, name);
-}
-
-static int write_proximity_config(const bdaddr_t *sba, const bdaddr_t *dba,
- const char *alert, const char *level)
-{
- char filename[PATH_MAX + 1], addr[18], key[38];
-
- create_filename(filename, PATH_MAX, sba, "proximity");
+ key_file = g_key_file_new();
+ g_key_file_load_from_file(key_file, filename, 0, NULL);
- create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (level)
+ g_key_file_set_string(key_file, alert, "Level", level);
+ else
+ g_key_file_remove_group(key_file, alert, NULL);
- ba2str(dba, addr);
-
- snprintf(key, sizeof(key), "%17s#%s", addr, alert);
+ data = g_key_file_to_data(key_file, &length, NULL);
+ if (length > 0) {
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ g_file_set_contents(filename, data, length, NULL);
+ }
- return textfile_put(filename, key, level);
+ g_free(data);
+ g_free(filename);
+ g_key_file_free(key_file);
}
-static char *read_proximity_config(const bdaddr_t *sba, const bdaddr_t *dba,
- const char *alert)
+static char *read_proximity_config(struct btd_device *device, const char *alert)
{
- char filename[PATH_MAX + 1], addr[18], key[38];
- char *str, *strnew;
+ char *filename;
+ GKeyFile *key_file;
+ char *str;
- create_filename(filename, PATH_MAX, sba, "proximity");
+ filename = btd_device_get_storage_path(device, "proximity");
- ba2str(dba, addr);
- snprintf(key, sizeof(key), "%17s#%s", addr, alert);
+ key_file = g_key_file_new();
+ g_key_file_load_from_file(key_file, filename, 0, NULL);
- str = textfile_caseget(filename, key);
- if (str == NULL)
- return NULL;
+ str = g_key_file_get_string(key_file, alert, "Level", NULL);
- strnew = g_strdup(str);
- free(str);
+ g_free(filename);
+ g_key_file_free(key_file);
- return strnew;
+ return str;
}
static uint8_t str2level(const char *level)
@@ -417,7 +418,6 @@ static void property_set_link_loss_level(const GDBusPropertyTable *property,
DBusMessageIter *iter, GDBusPendingPropertySet id, void *data)
{
struct monitor *monitor = data;
- struct btd_device *device = monitor->device;
const char *level;
if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
@@ -438,9 +438,7 @@ static void property_set_link_loss_level(const GDBusPropertyTable *property,
g_free(monitor->linklosslevel);
monitor->linklosslevel = g_strdup(level);
- write_proximity_config(adapter_get_address(device_get_adapter(device)),
- device_get_address(device),
- "LinkLossAlertLevel", level);
+ write_proximity_config(monitor->device, "LinkLossAlertLevel", level);
if (monitor->attrib)
write_alert_level(monitor);
@@ -601,9 +599,7 @@ int monitor_register(struct btd_device *device,
struct monitor *monitor;
char *level;
- level = read_proximity_config(
- adapter_get_address(device_get_adapter(device)),
- device_get_address(device), "LinkLossAlertLevel");
+ level = read_proximity_config(device, "LinkLossAlertLevel");
monitor = g_new0(struct monitor, 1);
monitor->device = btd_device_ref(device);
--
1.7.9.5
^ permalink raw reply related
* [PATCH 08/13] adapter: Convert proximity file
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/src/adapter.c b/src/adapter.c
index 1417a85..581c528 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2614,6 +2614,54 @@ static void convert_gatt_entry(char *key, char *value, void *user_data)
g_key_file_free(key_file);
}
+static void convert_proximity_entry(char *key, char *value, void *user_data)
+{
+ char *src_addr = user_data;
+ char *alert;
+ char filename[PATH_MAX + 1];
+ GKeyFile *key_file;
+ struct stat st;
+ int err;
+ char *data;
+ gsize length = 0;
+
+ if (!strchr(key, '#'))
+ return;
+
+ key[17] = '\0';
+ alert = &key[18];
+
+ if (bachk(key) != 0)
+ return;
+
+ /* Check if the device directory has been created as records should
+ * only be converted for known devices */
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s", src_addr, key);
+ filename[PATH_MAX] = '\0';
+
+ err = stat(filename, &st);
+ if (err || !S_ISDIR(st.st_mode))
+ return;
+
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/proximity", src_addr,
+ key);
+ filename[PATH_MAX] = '\0';
+
+ key_file = g_key_file_new();
+ g_key_file_load_from_file(key_file, filename, 0, NULL);
+
+ g_key_file_set_string(key_file, alert, "Level", value);
+
+ data = g_key_file_to_data(key_file, &length, NULL);
+ if (length > 0) {
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ g_file_set_contents(filename, data, length, NULL);
+ }
+
+ g_free(data);
+ g_key_file_free(key_file);
+}
+
static void convert_device_storage(struct btd_adapter *adapter)
{
char filename[PATH_MAX + 1];
@@ -2713,6 +2761,19 @@ static void convert_device_storage(struct btd_adapter *adapter)
textfile_put(filename, "converted", "yes");
}
free(str);
+
+ /* Convert proximity */
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/proximity", address);
+ filename[PATH_MAX] = '\0';
+
+ str = textfile_get(filename, "converted");
+ if (str && strcmp(str, "yes") == 0) {
+ DBG("Legacy %s file already converted", filename);
+ } else {
+ textfile_foreach(filename, convert_proximity_entry, address);
+ textfile_put(filename, "converted", "yes");
+ }
+ free(str);
}
static void convert_config(struct btd_adapter *adapter, const char *filename,
--
1.7.9.5
^ permalink raw reply related
* [PATCH 07/13] gatt: Use new storage architecture
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>
---
profiles/gatt/gas.c | 80 +++++++++++++++++++++++----------------------------
1 file changed, 36 insertions(+), 44 deletions(-)
diff --git a/profiles/gatt/gas.c b/profiles/gatt/gas.c
index 2c1dc83..c9353f6 100644
--- a/profiles/gatt/gas.c
+++ b/profiles/gatt/gas.c
@@ -77,60 +77,58 @@ static gint cmp_device(gconstpointer a, gconstpointer b)
return (gas->device == device ? 0 : -1);
}
-static inline int create_filename(char *buf, size_t size,
- const bdaddr_t *bdaddr, const char *name)
-{
- char addr[18];
-
- ba2str(bdaddr, addr);
-
- return create_name(buf, size, STORAGEDIR, addr, name);
-}
-
-static int write_ctp_handle(const bdaddr_t *sba, const bdaddr_t *dba,
- uint8_t bdaddr_type, uint16_t uuid,
+static void write_ctp_handle(struct btd_device *device, uint16_t uuid,
uint16_t handle)
{
- char filename[PATH_MAX + 1], addr[18], key[27], value[7];
+ char *filename, group[6], value[7];
+ GKeyFile *key_file;
+ char *data;
+ gsize length = 0;
- create_filename(filename, PATH_MAX, sba, "gatt");
+ filename = btd_device_get_storage_path(device, "gatt");
- create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ key_file = g_key_file_new();
+ g_key_file_load_from_file(key_file, filename, 0, NULL);
- ba2str(dba, addr);
+ snprintf(group, sizeof(group), "%hu", uuid);
+ snprintf(value, sizeof(value), "0x%4.4X", handle);
+ g_key_file_set_string(key_file, group, "Value", value);
- snprintf(key, sizeof(key), "%17s#%hhu#0x%4.4x", addr, bdaddr_type,
- uuid);
- snprintf(value, sizeof(value), "0x%4.4x", handle);
+ data = g_key_file_to_data(key_file, &length, NULL);
+ if (length > 0) {
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ g_file_set_contents(filename, data, length, NULL);
+ }
- return textfile_put(filename, key, value);
+ g_free(data);
+ g_free(filename);
+ g_key_file_free(key_file);
}
-static int read_ctp_handle(const bdaddr_t *sba, const bdaddr_t *dba,
- uint8_t bdaddr_type, uint16_t uuid,
+static int read_ctp_handle(struct btd_device *device, uint16_t uuid,
uint16_t *value)
{
- char filename[PATH_MAX + 1], addr[18], key[27];
+ char *filename, group[6];
+ GKeyFile *key_file;
char *str;
+ int err = 0;
- create_filename(filename, PATH_MAX, sba, "gatt");
+ filename = btd_device_get_storage_path(device, "gatt");
- ba2str(dba, addr);
- snprintf(key, sizeof(key), "%17s#%hhu#0x%04x", addr, bdaddr_type,
- uuid);
+ snprintf(group, sizeof(group), "%hu", uuid);
- str = textfile_get(filename, key);
- if (str == NULL)
- return -errno;
+ key_file = g_key_file_new();
+ g_key_file_load_from_file(key_file, filename, 0, NULL);
- if (sscanf(str, "%hx", value) != 1) {
- free(str);
- return -ENOENT;
- }
+ str = g_key_file_get_string(key_file, group, "Value", NULL);
+ if (str == NULL || sscanf(str, "%hx", value) != 1)
+ err = -ENOENT;
- free(str);
+ g_free(str);
+ g_free(filename);
+ g_key_file_free(key_file);
- return 0;
+ return err;
}
static void gap_appearance_cb(guint8 status, const guint8 *pdu, guint16 plen,
@@ -214,10 +212,7 @@ static void ccc_written_cb(guint8 status, const guint8 *pdu, guint16 plen,
gas->changed_handle,
indication_cb, gas, NULL);
- write_ctp_handle(adapter_get_address(device_get_adapter(gas->device)),
- device_get_address(gas->device),
- device_get_addr_type(gas->device),
- GATT_CHARAC_SERVICE_CHANGED,
+ write_ctp_handle(gas->device, GATT_CHARAC_SERVICE_CHANGED,
gas->changed_handle);
}
@@ -391,10 +386,7 @@ int gas_register(struct btd_device *device, struct att_range *gap,
attio_connected_cb,
attio_disconnected_cb, gas);
- read_ctp_handle(adapter_get_address(device_get_adapter(gas->device)),
- device_get_address(gas->device),
- device_get_addr_type(gas->device),
- GATT_CHARAC_SERVICE_CHANGED,
+ read_ctp_handle(gas->device, GATT_CHARAC_SERVICE_CHANGED,
&gas->changed_handle);
return 0;
--
1.7.9.5
^ permalink raw reply related
* [PATCH 06/13] adapter: Convert gatt file
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/src/adapter.c b/src/adapter.c
index 26950b7..1417a85 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2564,6 +2564,56 @@ static void convert_ccc_entry(char *key, char *value, void *user_data)
g_key_file_free(key_file);
}
+static void convert_gatt_entry(char *key, char *value, void *user_data)
+{
+ char *src_addr = user_data;
+ char dst_addr[18];
+ char type = BDADDR_BREDR;
+ int handle, ret;
+ char filename[PATH_MAX + 1];
+ GKeyFile *key_file;
+ struct stat st;
+ int err;
+ char group[6];
+ char *data;
+ gsize length = 0;
+
+ ret = sscanf(key, "%17s#%hhu#%04X", dst_addr, &type, &handle);
+ if (ret < 3)
+ return;
+
+ if (bachk(dst_addr) != 0)
+ return;
+
+ /* Check if the device directory has been created as records should
+ * only be converted for known devices */
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s", src_addr, dst_addr);
+ filename[PATH_MAX] = '\0';
+
+ err = stat(filename, &st);
+ if (err || !S_ISDIR(st.st_mode))
+ return;
+
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/gatt", src_addr,
+ dst_addr);
+ filename[PATH_MAX] = '\0';
+
+ key_file = g_key_file_new();
+ g_key_file_load_from_file(key_file, filename, 0, NULL);
+
+ sprintf(group, "%hu", handle);
+ g_key_file_set_string(key_file, group, "Value", value);
+
+ data = g_key_file_to_data(key_file, &length, NULL);
+ if (length > 0) {
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ g_file_set_contents(filename, data, length, NULL);
+ }
+
+ g_free(data);
+ g_key_file_free(key_file);
+}
+
static void convert_device_storage(struct btd_adapter *adapter)
{
char filename[PATH_MAX + 1];
@@ -2650,6 +2700,19 @@ static void convert_device_storage(struct btd_adapter *adapter)
/* Convert appearances */
convert_file("appearances", address, convert_appearances_entry, FALSE);
+
+ /* Convert gatt */
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/gatt", address);
+ filename[PATH_MAX] = '\0';
+
+ str = textfile_get(filename, "converted");
+ if (str && strcmp(str, "yes") == 0) {
+ DBG("Legacy %s file already converted", filename);
+ } else {
+ textfile_foreach(filename, convert_gatt_entry, address);
+ textfile_put(filename, "converted", "yes");
+ }
+ free(str);
}
static void convert_config(struct btd_adapter *adapter, const char *filename,
--
1.7.9.5
^ permalink raw reply related
* [PATCH 05/13] device: Load appearance from storage
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>
Update adapter_update_found_devices() to store appearance in device.
Remove no more used functions in storage.[ch].
---
src/adapter.c | 7 +++----
src/device.c | 37 +++++++++++++++++++++++--------------
src/storage.c | 41 -----------------------------------------
src/storage.h | 4 ----
4 files changed, 26 insertions(+), 63 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index c95e341..26950b7 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3074,10 +3074,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
return;
}
- if (eir_data.appearance != 0)
- write_remote_appearance(&adapter->bdaddr, bdaddr, bdaddr_type,
- eir_data.appearance);
-
if (eir_data.name != NULL && eir_data.name_complete)
adapter_store_cached_name(&adapter->bdaddr, bdaddr,
eir_data.name);
@@ -3101,6 +3097,9 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
device_set_legacy(dev, legacy);
device_set_rssi(dev, rssi);
+ if (eir_data.appearance != 0)
+ device_set_appearance(dev, eir_data.appearance);
+
if (eir_data.name)
device_set_name(dev, eir_data.name);
diff --git a/src/device.c b/src/device.c
index 30d5eb9..047c26a 100644
--- a/src/device.c
+++ b/src/device.c
@@ -149,6 +149,7 @@ struct btd_device {
uint16_t vendor;
uint16_t product;
uint16_t version;
+ uint16_t appearance;
struct btd_adapter *adapter;
GSList *uuids;
GSList *primaries; /* List of primary services */
@@ -241,6 +242,13 @@ static gboolean store_device_info_cb(gpointer user_data)
g_key_file_remove_key(key_file, "General", "Class", NULL);
}
+ if (device->appearance) {
+ sprintf(class, "0x%4.4x", device->appearance);
+ g_key_file_set_string(key_file, "General", "Appearance", class);
+ } else {
+ g_key_file_remove_key(key_file, "General", "Appearance", NULL);
+ }
+
switch (device->bdaddr_type) {
case BDADDR_BREDR:
g_key_file_set_string(key_file, "General",
@@ -564,10 +572,10 @@ static gboolean get_appearance(const GDBusPropertyTable *property, void *data,
if (dev_property_exists_class(property, data))
return FALSE;
- if (read_remote_appearance(adapter_get_address(device->adapter),
- &device->bdaddr, device->bdaddr_type,
- appearance) == 0)
+ if (device->appearance) {
+ *appearance = device->appearance;
return TRUE;
+ }
return FALSE;
}
@@ -1745,6 +1753,13 @@ static void load_info(struct btd_device *device, const gchar *local,
g_free(str);
}
+ /* Load appearance */
+ str = g_key_file_get_string(key_file, "General", "Appearance", NULL);
+ if (str) {
+ device->appearance = strtol(str, NULL, 16);
+ g_free(str);
+ }
+
/* Load device technology */
techno = g_key_file_get_string_list(key_file, "General",
"SupportedTechnologies", NULL, NULL);
@@ -4093,17 +4108,11 @@ void btd_device_unref(struct btd_device *device)
int device_get_appearance(struct btd_device *device, uint16_t *value)
{
- uint16_t app;
- int err;
-
- err = read_remote_appearance(adapter_get_address(device->adapter),
- &device->bdaddr, device->bdaddr_type,
- &app);
- if (err < 0)
- return err;
+ if (device->appearance == 0)
+ return -1;
if (value)
- *value = app;
+ *value = device->appearance;
return 0;
}
@@ -4119,8 +4128,8 @@ void device_set_appearance(struct btd_device *device, uint16_t value)
g_dbus_emit_property_changed(btd_get_dbus_connection(),
device->path, DEVICE_INTERFACE, "Icon");
- write_remote_appearance(adapter_get_address(device->adapter),
- &device->bdaddr, device->bdaddr_type, value);
+ device->appearance = value;
+ store_device_info(device);
}
static gboolean notify_attios(gpointer user_data)
diff --git a/src/storage.c b/src/storage.c
index 38e5897..35049f1 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -144,47 +144,6 @@ int read_local_name(const bdaddr_t *bdaddr, char *name)
return 0;
}
-int read_remote_appearance(const bdaddr_t *local, const bdaddr_t *peer,
- uint8_t bdaddr_type, uint16_t *appearance)
-{
- char filename[PATH_MAX + 1], key[20], *str;
-
- create_filename(filename, PATH_MAX, local, "appearances");
-
- ba2str(peer, key);
- sprintf(&key[17], "#%hhu", bdaddr_type);
-
- str = textfile_get(filename, key);
- if (!str)
- return -ENOENT;
-
- if (sscanf(str, "%hx", appearance) != 1) {
- free(str);
- return -ENOENT;
- }
-
- free(str);
-
- return 0;
-}
-
-int write_remote_appearance(const bdaddr_t *local, const bdaddr_t *peer,
- uint8_t bdaddr_type, uint16_t appearance)
-{
- char filename[PATH_MAX + 1], key[20], str[7];
-
- create_filename(filename, PATH_MAX, local, "appearances");
-
- create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
- ba2str(peer, key);
- sprintf(&key[17], "#%hhu", bdaddr_type);
-
- sprintf(str, "0x%4.4x", appearance);
-
- return textfile_put(filename, key, str);
-}
-
ssize_t read_pin_code(const bdaddr_t *local, const bdaddr_t *peer, char *pin)
{
char filename[PATH_MAX + 1], addr[18], *str;
diff --git a/src/storage.h b/src/storage.h
index cc7f930..9a9c82f 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -27,10 +27,6 @@ int read_discoverable_timeout(const char *src, int *timeout);
int read_pairable_timeout(const char *src, int *timeout);
int read_on_mode(const char *src, char *mode, int length);
int read_local_name(const bdaddr_t *bdaddr, char *name);
-int write_remote_appearance(const bdaddr_t *local, const bdaddr_t *peer,
- uint8_t bdaddr_type, uint16_t appearance);
-int read_remote_appearance(const bdaddr_t *local, const bdaddr_t *peer,
- uint8_t bdaddr_type, uint16_t *appearance);
ssize_t read_pin_code(const bdaddr_t *local, const bdaddr_t *peer, char *pin);
sdp_record_t *record_from_string(const gchar *str);
sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid);
--
1.7.9.5
^ permalink raw reply related
* [PATCH 04/13] adapter: Convert appearances file
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/adapter.c b/src/adapter.c
index 1279145..c95e341 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2190,6 +2190,11 @@ static void convert_profiles_entry(GKeyFile *key_file, void *value)
g_key_file_set_string(key_file, "General", "Services", value);
}
+static void convert_appearances_entry(GKeyFile *key_file, void *value)
+{
+ g_key_file_set_string(key_file, "General", "Appearance", value);
+}
+
static void convert_entry(char *key, char *value, void *user_data)
{
struct device_converter *converter = user_data;
@@ -2642,6 +2647,9 @@ static void convert_device_storage(struct btd_adapter *adapter)
textfile_put(filename, "converted", "yes");
}
free(str);
+
+ /* Convert appearances */
+ convert_file("appearances", address, convert_appearances_entry, FALSE);
}
static void convert_config(struct btd_adapter *adapter, const char *filename,
--
1.7.9.5
^ permalink raw reply related
* [PATCH 03/13] doc: Add device appearance in settings-storage doc
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>
---
doc/settings-storage.txt | 3 +++
1 file changed, 3 insertions(+)
diff --git a/doc/settings-storage.txt b/doc/settings-storage.txt
index 037e14f..bc60709 100644
--- a/doc/settings-storage.txt
+++ b/doc/settings-storage.txt
@@ -165,6 +165,9 @@ Long term key) related to a remote device.
Class String Device class in hexadecimal,
i.e. 0x000000
+ Appearance String Device appearance in hexadecimal,
+ i.e. 0x0000
+
SupportedTechnologies List of List of technologies supported by
strings device, separated by ";"
Technologies can be BR/EDR or LE
--
1.7.9.5
^ permalink raw reply related
* [PATCH 02/13] alert: Use ccc file from device storage
From: Frédéric Danis @ 2012-12-17 15:09 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>
---
profiles/alert/server.c | 69 +++++++++++++++++++++++------------------------
1 file changed, 34 insertions(+), 35 deletions(-)
diff --git a/profiles/alert/server.c b/profiles/alert/server.c
index 3f7b37e..3736a0b 100644
--- a/profiles/alert/server.c
+++ b/profiles/alert/server.c
@@ -322,29 +322,41 @@ static void watcher_disconnect(DBusConnection *conn, void *user_data)
g_slist_foreach(alert_adapters, update_supported_categories, NULL);
}
-static struct btd_device *get_notifiable_device(struct btd_adapter *adapter,
- char *key, char *value,
- uint16_t ccc)
+static gboolean is_notifiable_device(struct btd_device *device, uint16_t ccc)
{
- struct btd_device *device;
- char addr[18];
- uint16_t hnd, val;
- uint8_t bdaddr_type;
+ char *filename;
+ GKeyFile *key_file;
+ char handle[6];
+ char *str;
+ uint16_t val;
+ gboolean result;
+
+ sprintf(handle, "%hu", ccc);
- sscanf(key, "%17s#%hhu#%04hX", addr, &bdaddr_type, &hnd);
+ filename = btd_device_get_storage_path(device, "ccc");
- if (hnd != ccc)
- return NULL;
+ key_file = g_key_file_new();
+ g_key_file_load_from_file(key_file, filename, 0, NULL);
- val = strtol(value, NULL, 16);
- if (!(val & 0x0001))
- return NULL;
+ str = g_key_file_get_string(key_file, handle, "Value", NULL);
+ if (!str) {
+ result = FALSE;
+ goto end;
+ }
+
+ val = strtol(str, NULL, 16);
+ if (!(val & 0x0001)) {
+ result = FALSE;
+ goto end;
+ }
- device = adapter_find_device(adapter, addr);
- if (device == NULL)
- return NULL;
+ result = TRUE;
+end:
+ g_free(str);
+ g_free(filename);
+ g_key_file_free(key_file);
- return btd_device_ref(device);
+ return result;
}
static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
@@ -392,40 +404,27 @@ end:
g_free(cb);
}
-static void filter_devices_notify(char *key, char *value, void *user_data)
+static void filter_devices_notify(struct btd_device *device, void *user_data)
{
struct notify_data *notify_data = user_data;
struct alert_adapter *al_adapter = notify_data->al_adapter;
enum notify_type type = notify_data->type;
- struct btd_device *device;
struct notify_callback *cb;
- device = get_notifiable_device(al_adapter->adapter, key, value,
- al_adapter->hnd_ccc[type]);
- if (device == NULL)
+ if (!is_notifiable_device(device, al_adapter->hnd_ccc[type]))
return;
cb = g_new0(struct notify_callback, 1);
cb->notify_data = notify_data;
- cb->device = device;
+ cb->device = btd_device_ref(device);
cb->id = btd_device_add_attio_callback(device,
attio_connected_cb, NULL, cb);
}
-static void create_filename(char *filename, struct btd_adapter *adapter)
-{
- char srcaddr[18];
-
- ba2str(adapter_get_address(adapter), srcaddr);
-
- create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "ccc");
-}
-
static void notify_devices(struct alert_adapter *al_adapter,
enum notify_type type, uint8_t *value, size_t len)
{
struct notify_data *notify_data;
- char filename[PATH_MAX + 1];
notify_data = g_new0(struct notify_data, 1);
notify_data->al_adapter = al_adapter;
@@ -433,8 +432,8 @@ static void notify_devices(struct alert_adapter *al_adapter,
notify_data->value = g_memdup(value, len);
notify_data->len = len;
- create_filename(filename, al_adapter->adapter);
- textfile_foreach(filename, filter_devices_notify, notify_data);
+ btd_adapter_for_each_device(al_adapter->adapter, filter_devices_notify,
+ notify_data);
}
static void pasp_notification(enum notify_type type)
--
1.7.9.5
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox