* Re: [PATCH BlueZ 1/2] audio: Fix memory leak of AVDTP buffer
From: Johan Hedberg @ 2012-10-09 16:44 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1349798633-28071-1-git-send-email-luiz.dentz@gmail.com>
Hi Luiz,
On Tue, Oct 09, 2012, Luiz Augusto von Dentz wrote:
> Upon disconnection all references to AVDTP session should be release
> otherwise the data associate with it cannot be freed and new connection
> may overwrite the buf pointer causing it to leak.
> ---
> audio/sink.c | 8 ++++++++
> audio/source.c | 8 ++++++++
> 2 files changed, 16 insertions(+)
Both patches have been applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH 0/9] Remove some old code
From: Johan Hedberg @ 2012-10-09 16:39 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1349784722-14578-1-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
On Tue, Oct 09, 2012, Szymon Janc wrote:
> This removes some unused or not needed old code.
>
> Szymon Janc (9):
> Simplify checking if found device is legacy
> Pass confirm name as gboolean value
> event: Don't store EIR in btd_event_device_found
> storage: Remove not used read_remote_eir
> storage: Remove not used write_version_info
> storage: Remove not used write_features_info
> storage: Remove not used read_remote_features
> adapter: Remove not used btd_adapter_switch_{online,offline}
> functions
> device: Remove not used device_set_class function
>
> src/adapter.c | 95 +++++------------------------------
> src/adapter.h | 8 ++-
> src/device.c | 12 -----
> src/device.h | 1 -
> src/event.c | 27 ++--------
> src/event.h | 6 +--
> src/mgmt.c | 13 ++---
> src/storage.c | 156 ---------------------------------------------------------
> src/storage.h | 11 ----
> 9 files changed, 26 insertions(+), 303 deletions(-)
All patches except the gboolean/bool one have been applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH 0/7] Move adapter config file to ini-file format
From: Marcel Holtmann @ 2012-10-09 16:21 UTC (permalink / raw)
To: Frederic Danis; +Cc: linux-bluetooth
In-Reply-To: <50744EB5.90900@linux.intel.com>
Hi Fred,
> >> Adapter saved configuration will be saved to /var/lib/bluetooth/<adapter address>/adapter
> >> in ini-file format for BlueZ 5.
> >> If this file does not exist, we try to convert old config file to it.
> >
> > since we are already using /config as file name, I propose we convert
> > this to /settings. I do not like the file name /adapter.
>
> OK, I will change it.
>
> > We need to make sure that once the new file exists, that we do not keep
> > converting over and over again.
>
> /config file is converted only if loading of new /settings file failed.
good. And then check if it got marked as converted yes and then just do
not convert twice.
> > I would also propose to add an extra entry to the old file that marks it
> > as converted. Then we can at some point in the future, start cleaning
> > out the leftovers.
>
> OK, I will add "converted yes" at end of /config file after conversion.
>
> Btw, should not we remove /config file after conversion ?
No. In case you go for and back between 4.x and 5.x we need to keep this
around for a bit. We should put a notice in the TODO file for some 5.x
version in lets say 6-8 month to start removing leftover config files.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH 0/7] Move adapter config file to ini-file format
From: Frederic Danis @ 2012-10-09 16:20 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1349798898.27233.97.camel@aeonflux>
Hello Marcel,
On 09/10/2012 18:08, Marcel Holtmann wrote:
> Hi Fred,
>
>> Adapter saved configuration will be saved to /var/lib/bluetooth/<adapter address>/adapter
>> in ini-file format for BlueZ 5.
>> If this file does not exist, we try to convert old config file to it.
>
> since we are already using /config as file name, I propose we convert
> this to /settings. I do not like the file name /adapter.
OK, I will change it.
> We need to make sure that once the new file exists, that we do not keep
> converting over and over again.
/config file is converted only if loading of new /settings file failed.
> I would also propose to add an extra entry to the old file that marks it
> as converted. Then we can at some point in the future, start cleaning
> out the leftovers.
OK, I will add "converted yes" at end of /config file after conversion.
Btw, should not we remove /config file after conversion ?
Regards
Fred
--
Frederic Danis Open Source Technology Center
frederic.danis@intel.com Intel Corporation
^ permalink raw reply
* Re: [PATCH 2/9] Pass confirm name as gboolean value
From: Marcel Holtmann @ 2012-10-09 16:12 UTC (permalink / raw)
To: Lucas De Marchi; +Cc: Szymon Janc, linux-bluetooth
In-Reply-To: <CAMOw1v51MT6AsyCB5X7GVRzbdDsXFJL=Gr5EO9ctJBT=vsBPHA@mail.gmail.com>
Hi Lucas,
> >> confirm_name is a boolean value and can be pass as such instead of
> >> uint8_t.
> >
> > actually long term I want to move to bool usage. So maybe this is a good
> > start to get this going.
>
> agreed... on new code that I'm adding I'm using bool.
>
> Btw, could we already use bool in gdbus/ ?
actually that one is heavily GLib specific. However if you are willing
to also clean up things like guint32, I have no problem with actually
converting that as well.
Getting rid of #include <glib/glib.h> in gdbus.h might be actually nice.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH 0/7] Move adapter config file to ini-file format
From: Marcel Holtmann @ 2012-10-09 16:08 UTC (permalink / raw)
To: Frédéric Danis; +Cc: linux-bluetooth
In-Reply-To: <1349798318-12689-1-git-send-email-frederic.danis@linux.intel.com>
Hi Fred,
> Adapter saved configuration will be saved to /var/lib/bluetooth/<adapter address>/adapter
> in ini-file format for BlueZ 5.
> If this file does not exist, we try to convert old config file to it.
since we are already using /config as file name, I propose we convert
this to /settings. I do not like the file name /adapter.
We need to make sure that once the new file exists, that we do not keep
converting over and over again.
I would also propose to add an extra entry to the old file that marks it
as converted. Then we can at some point in the future, start cleaning
out the leftovers.
Regards
Marcel
^ permalink raw reply
* [PATCH BlueZ 2/2] sink: Remove deprecated code
From: Luiz Augusto von Dentz @ 2012-10-09 16:03 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349798633-28071-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Remove decrecated properties and signals
---
audio/sink.c | 52 ----------------------------------------------------
doc/audio-api.txt | 29 +----------------------------
2 files changed, 1 insertion(+), 80 deletions(-)
diff --git a/audio/sink.c b/audio/sink.c
index 0628fd2..d45185c 100644
--- a/audio/sink.c
+++ b/audio/sink.c
@@ -148,15 +148,6 @@ static void avdtp_state_callback(struct audio_device *dev,
switch (new_state) {
case AVDTP_SESSION_STATE_DISCONNECTED:
- if (sink->state != SINK_STATE_CONNECTING) {
- gboolean value = FALSE;
- g_dbus_emit_signal(btd_get_dbus_connection(), dev->path,
- AUDIO_SINK_INTERFACE, "Disconnected",
- DBUS_TYPE_INVALID);
- emit_property_changed(dev->path,
- AUDIO_SINK_INTERFACE, "Connected",
- DBUS_TYPE_BOOLEAN, &value);
- }
sink_set_state(dev, SINK_STATE_DISCONNECTED);
break;
case AVDTP_SESSION_STATE_CONNECTING:
@@ -189,7 +180,6 @@ static void stream_state_changed(struct avdtp_stream *stream,
DBusConnection *conn = btd_get_dbus_connection();
struct audio_device *dev = user_data;
struct sink *sink = dev->sink;
- gboolean value;
if (err)
return;
@@ -216,38 +206,9 @@ static void stream_state_changed(struct avdtp_stream *stream,
sink->cb_id = 0;
break;
case AVDTP_STATE_OPEN:
- if (old_state == AVDTP_STATE_CONFIGURED &&
- sink->state == SINK_STATE_CONNECTING) {
- value = TRUE;
- g_dbus_emit_signal(conn, dev->path,
- AUDIO_SINK_INTERFACE,
- "Connected",
- DBUS_TYPE_INVALID);
- emit_property_changed(dev->path,
- AUDIO_SINK_INTERFACE,
- "Connected",
- DBUS_TYPE_BOOLEAN, &value);
- } else if (old_state == AVDTP_STATE_STREAMING) {
- value = FALSE;
- g_dbus_emit_signal(conn, dev->path,
- AUDIO_SINK_INTERFACE,
- "Stopped",
- DBUS_TYPE_INVALID);
- emit_property_changed(dev->path,
- AUDIO_SINK_INTERFACE,
- "Playing",
- DBUS_TYPE_BOOLEAN, &value);
- }
sink_set_state(dev, SINK_STATE_CONNECTED);
break;
case AVDTP_STATE_STREAMING:
- value = TRUE;
- g_dbus_emit_signal(conn, dev->path,
- AUDIO_SINK_INTERFACE, "Playing",
- DBUS_TYPE_INVALID);
- emit_property_changed(dev->path,
- AUDIO_SINK_INTERFACE, "Playing",
- DBUS_TYPE_BOOLEAN, &value);
sink_set_state(dev, SINK_STATE_PLAYING);
break;
case AVDTP_STATE_CONFIGURED:
@@ -505,7 +466,6 @@ static DBusMessage *sink_get_properties(DBusConnection *conn,
DBusMessageIter iter;
DBusMessageIter dict;
const char *state;
- gboolean value;
reply = dbus_message_new_method_return(msg);
if (!reply)
@@ -518,14 +478,6 @@ static DBusMessage *sink_get_properties(DBusConnection *conn,
DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
- /* Playing */
- value = (sink->stream_state == AVDTP_STATE_STREAMING);
- dict_append_entry(&dict, "Playing", DBUS_TYPE_BOOLEAN, &value);
-
- /* Connected */
- value = (sink->stream_state >= AVDTP_STATE_CONFIGURED);
- dict_append_entry(&dict, "Connected", DBUS_TYPE_BOOLEAN, &value);
-
/* State */
state = state2str(sink->state);
if (state)
@@ -546,10 +498,6 @@ static const GDBusMethodTable sink_methods[] = {
};
static const GDBusSignalTable sink_signals[] = {
- { GDBUS_DEPRECATED_SIGNAL("Connected", NULL) },
- { GDBUS_DEPRECATED_SIGNAL("Disconnected", NULL) },
- { GDBUS_DEPRECATED_SIGNAL("Playing", NULL) },
- { GDBUS_DEPRECATED_SIGNAL("Stopped", NULL) },
{ GDBUS_SIGNAL("PropertyChanged",
GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
{ }
diff --git a/doc/audio-api.txt b/doc/audio-api.txt
index ca430fc..72129fc 100644
--- a/doc/audio-api.txt
+++ b/doc/audio-api.txt
@@ -200,24 +200,7 @@ Methods void Connect()
Possible Errors: org.bluez.Error.InvalidArguments
-Signals void Connected() {deprecated}
-
- Sent when a successful connection has been made to the
- remote A2DP Sink
-
- void Disconnected() {deprecated}
-
- Sent when the device has been disconnected from.
-
- void Playing() {deprecated}
-
- Sent when a stream with remote device is started.
-
- void Stopped() {deprecated}
-
- Sent when a stream with remote device is suspended.
-
- PropertyChanged(string name, variant value)
+Signals PropertyChanged(string name, variant value)
This signal indicates a changed value of the given
property.
@@ -247,16 +230,6 @@ properties string State [readonly]
"playing" -> "disconnected"
Disconnected from the remote device
- boolean Connected [readonly]
-
- Indicates if a stream is setup to a A2DP sink on
- the remote device.
-
- boolean Playing [readonly]
-
- Indicates if a stream is active to a A2DP sink on
- the remote device.
-
AudioSource hierarchy
=====================
--
1.7.11.4
^ permalink raw reply related
* [PATCH BlueZ 1/2] audio: Fix memory leak of AVDTP buffer
From: Luiz Augusto von Dentz @ 2012-10-09 16:03 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Upon disconnection all references to AVDTP session should be release
otherwise the data associate with it cannot be freed and new connection
may overwrite the buf pointer causing it to leak.
---
audio/sink.c | 8 ++++++++
audio/source.c | 8 ++++++++
2 files changed, 16 insertions(+)
diff --git a/audio/sink.c b/audio/sink.c
index 4eb2c61..0628fd2 100644
--- a/audio/sink.c
+++ b/audio/sink.c
@@ -125,6 +125,14 @@ static void sink_set_state(struct audio_device *dev, sink_state_t new_state)
struct sink_state_callback *cb = l->data;
cb->cb(dev, old_state, new_state, cb->user_data);
}
+
+ if (new_state != SINK_STATE_DISCONNECTED)
+ return;
+
+ if (sink->session) {
+ avdtp_unref(sink->session);
+ sink->session = NULL;
+ }
}
static void avdtp_state_callback(struct audio_device *dev,
diff --git a/audio/source.c b/audio/source.c
index 41aedd2..e111954 100644
--- a/audio/source.c
+++ b/audio/source.c
@@ -116,6 +116,14 @@ static void source_set_state(struct audio_device *dev, source_state_t new_state)
struct source_state_callback *cb = l->data;
cb->cb(dev, old_state, new_state, cb->user_data);
}
+
+ if (new_state != SOURCE_STATE_DISCONNECTED)
+ return;
+
+ if (source->session) {
+ avdtp_unref(source->session);
+ source->session = NULL;
+ }
}
static void avdtp_state_callback(struct audio_device *dev,
--
1.7.11.4
^ permalink raw reply related
* Re: [PATCH v3 00/15] Thermometer watchers API change + fixes
From: Johan Hedberg @ 2012-10-09 16:03 UTC (permalink / raw)
To: Andrzej Kaczmarek; +Cc: linux-bluetooth
In-Reply-To: <1349781598-22580-1-git-send-email-andrzej.kaczmarek@tieto.com>
Hi Andrzej,
On Tue, Oct 09, 2012, Andrzej Kaczmarek wrote:
> Changes since v2:
> - restored special values for exponent and mantissa in API document
> and added note about IEEE spec
> - fixed parameters parsing for incoming measurement (memset was placed
> in wrong place)
>
> Also this was tested with PTS 4.5.3 and works fine now after memset fix,
> except for TP/THF/CO/BI-07-I which seems to have issue in PTS (there should
> be reserved value for temperature type but PTS sends 0x02 which is
> perfectly valid value thus it won't be discarded on our side).
>
>
> Andrzej Kaczmarek (15):
> thermometer: Store thermometer devices per-adapter
> thermometer: Register ThermometerManager interface on adapter path
> thermometer: Move watcher logic to adapter interface
> thermometer: Include remote device information in MeasurementReceived
> thermometer: Update API document
> thermometer: Update test script
> thermometer: Reformat MeasurementReceived description
> thermometer: Change string properties to lower-case
> thermometer: Update driver naming style
> thermometer: Add constant definition for watcher interface name
> thermometer: Add common function to write characteristics CCC
> thermometer: Refactor processing of measurement characteristic value
> thermometer: Fix whitespace
> thermometer: Fix indentation
> thermometer: Fix missing braces
>
> doc/thermometer-api.txt | 136 +++++-----
> profiles/thermometer/manager.c | 24 +-
> profiles/thermometer/thermometer.c | 512 +++++++++++++++++++++----------------
> profiles/thermometer/thermometer.h | 2 +
> test/test-thermometer | 16 +-
> 5 files changed, 395 insertions(+), 295 deletions(-)
All patches in this set have been applied. Thanks.
Johan
^ permalink raw reply
* [PATCH 7/7] adapter: Move saved config to ini-file format
From: Frédéric Danis @ 2012-10-09 15:58 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349798318-12689-1-git-send-email-frederic.danis@linux.intel.com>
Read and write config file in ini-file format.
If the file can not be loaded, try to convert legacy configuration.
---
src/adapter.c | 189 +++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 157 insertions(+), 32 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 8582a0e..63c4c84 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -33,6 +33,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <sys/ioctl.h>
+#include <sys/file.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/uuid.h>
@@ -222,6 +223,54 @@ static uint8_t get_mode(const char *mode)
return MODE_UNKNOWN;
}
+static void write_config(struct btd_adapter *adapter)
+{
+ GKeyFile *key_file;
+ char filename[PATH_MAX + 1];
+ char address[18];
+ char *str;
+ gsize length = 0;
+
+ key_file = g_key_file_new();
+
+ g_key_file_set_string(key_file, "General", "Name",
+ adapter->config.name);
+
+ str = g_strdup_printf("0x%2.2x%2.2x%2.2x", adapter->config.class[2],
+ adapter->config.class[1],
+ adapter->config.class[0]);
+ g_key_file_set_string(key_file, "General", "Class", str);
+ g_free(str);
+
+ g_key_file_set_boolean(key_file, "General", "Pairable",
+ adapter->pairable);
+
+ if (adapter->pairable_timeout != main_opts.pairto)
+ g_key_file_set_integer(key_file, "General", "PairableTimeout",
+ adapter->pairable_timeout);
+
+ if (adapter->discov_timeout != main_opts.discovto)
+ g_key_file_set_integer(key_file, "General",
+ "DiscoverableTimeout",
+ adapter->discov_timeout);
+
+ g_key_file_set_string(key_file, "General", "Mode",
+ mode2str(adapter->config.mode));
+ g_key_file_set_string(key_file, "General", "OnMode",
+ mode2str(adapter->config.on_mode));
+
+ ba2str(&adapter->bdaddr, address);
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/adapter", address);
+
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ str = g_key_file_to_data(key_file, &length, NULL);
+ g_file_set_contents(filename, str, length, NULL);
+ g_free(str);
+
+ g_key_file_free(key_file);
+}
+
static struct session_req *session_ref(struct session_req *req)
{
req->refcount++;
@@ -291,7 +340,6 @@ static struct session_req *find_session_by_msg(GSList *list, const DBusMessage *
static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
{
int err;
- const char *modestr;
if (adapter->pending_mode != NULL)
return -EALREADY;
@@ -327,10 +375,9 @@ done:
if (new_mode != MODE_OFF)
adapter->config.on_mode = new_mode;
- modestr = mode2str(new_mode);
- write_device_mode(&adapter->bdaddr, modestr);
+ write_config(adapter);
- DBG("%s", modestr);
+ DBG("%s", mode2str(new_mode));
return 0;
}
@@ -473,7 +520,7 @@ void btd_adapter_pairable_changed(struct btd_adapter *adapter,
{
adapter->pairable = pairable;
- write_device_pairable(&adapter->bdaddr, pairable);
+ write_config(adapter);
g_dbus_emit_property_changed(btd_get_dbus_connection(), adapter->path,
ADAPTER_INTERFACE, "Pairable");
@@ -690,7 +737,7 @@ static void set_discoverable_timeout(struct btd_adapter *adapter,
adapter->discov_timeout = timeout;
- write_discoverable_timeout(&adapter->bdaddr, timeout);
+ write_config(adapter);
g_dbus_emit_property_changed(conn, adapter->path, ADAPTER_INTERFACE,
"DiscoverableTimeout");
@@ -710,7 +757,7 @@ static void set_pairable_timeout(struct btd_adapter *adapter,
adapter->pairable_timeout = timeout;
- write_pairable_timeout(&adapter->bdaddr, timeout);
+ write_config(adapter);
g_dbus_emit_property_changed(conn, adapter->path, ADAPTER_INTERFACE,
"PairableTimeout");
@@ -730,7 +777,7 @@ void btd_adapter_class_changed(struct btd_adapter *adapter, uint8_t *new_class)
adapter->config.class[1] = new_class[1];
adapter->config.class[2] = new_class[2];
- write_local_class(&adapter->bdaddr, new_class);
+ write_config(adapter);
adapter->dev_class = class;
@@ -790,7 +837,7 @@ int adapter_set_name(struct btd_adapter *adapter, const char *name)
g_free(adapter->config.name);
adapter->config.name = g_strdup(maxname);
- write_local_name(&adapter->bdaddr, maxname);
+ write_config(adapter);
return 0;
}
@@ -2475,17 +2522,15 @@ static void set_mode_complete(struct btd_adapter *adapter)
{
DBusConnection *conn = btd_get_dbus_connection();
struct session_req *pending;
- const char *modestr;
int err;
adapter->config.mode = adapter->mode;
if (adapter->mode != MODE_OFF)
adapter->config.on_mode = adapter->mode;
- modestr = mode2str(adapter->mode);
- write_device_mode(&adapter->bdaddr, modestr);
+ write_config(adapter);
- DBG("%s", modestr);
+ DBG("%s", mode2str(adapter->mode));
if (adapter->mode == MODE_OFF) {
g_slist_free_full(adapter->mode_sessions, session_free);
@@ -2652,56 +2697,136 @@ void btd_adapter_unref(struct btd_adapter *adapter)
g_free(path);
}
-static void load_config(struct btd_adapter *adapter)
+static void convert_config(struct btd_adapter *adapter, const char *filename,
+ GKeyFile *key_file)
{
- char name[MAX_NAME_LENGTH + 1];
char address[18];
- char mode[14];
+ char str[MAX_NAME_LENGTH + 1];
+ uint8_t class[3];
+ gboolean flag;
int timeout;
+ char *data;
+ gsize length = 0;
ba2str(&adapter->bdaddr, address);
+ if (read_local_name(&adapter->bdaddr, str) == 0)
+ g_key_file_set_string(key_file, "General", "Name", str);
+
+ if (read_local_class(&adapter->bdaddr, class) == 0) {
+ sprintf(str, "0x%2.2x%2.2x%2.2x", class[2], class[1], class[0]);
+ g_key_file_set_string(key_file, "General", "Class", str);
+ }
+
+ if (read_device_pairable(&adapter->bdaddr, &flag) == 0)
+ g_key_file_set_boolean(key_file, "General", "Pairable", flag);
+
+ if (read_pairable_timeout(address, &timeout) == 0)
+ g_key_file_set_integer(key_file, "General",
+ "PairableTimeout", timeout);
+
+ if (read_pairable_timeout(address, &timeout) == 0)
+ g_key_file_set_integer(key_file, "General",
+ "DiscoverableTimeout", timeout);
+
+ if (read_device_mode(address, str, sizeof(str)) == 0)
+ g_key_file_set_string(key_file, "General", "Mode", str);
+
+ if (read_on_mode(address, str, sizeof(str)) == 0)
+ g_key_file_set_string(key_file, "General", "OnMode", str);
+
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ data = g_key_file_to_data(key_file, &length, NULL);
+ g_file_set_contents(filename, data, length, NULL);
+ g_free(data);
+}
+
+static void load_config(struct btd_adapter *adapter)
+{
+ GKeyFile *key_file;
+ char filename[PATH_MAX + 1];
+ char address[18];
+ char *str;
+ GError *gerr = NULL;
+
+ ba2str(&adapter->bdaddr, address);
+
+ key_file = g_key_file_new();
+
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/adapter", address);
+
+ if (!g_key_file_load_from_file(key_file, filename, 0, NULL))
+ convert_config(adapter, filename, key_file);
+
/* Get name */
- if (read_local_name(&adapter->bdaddr, name) < 0)
- adapter->config.name = NULL;
- else
- adapter->config.name = g_strdup(name);
+ adapter->config.name = g_key_file_get_string(key_file, "General",
+ "Name", NULL);
/* Get class */
- if (read_local_class(&adapter->bdaddr, adapter->config.class) < 0) {
+ str = g_key_file_get_string(key_file, "General", "Class", NULL);
+ if (str) {
+ char tmp[3];
+ int i;
+ uint8_t *class = adapter->config.class;
+
+ memset(tmp, 0, sizeof(tmp));
+ for (i = 0; i < 3; i++) {
+ memcpy(tmp, str + (i * 2) + 2, 2);
+ class[2 - i] = (uint8_t) strtol(tmp, NULL, 16);
+ }
+ } else {
uint32_t class = htobl(main_opts.class);
memcpy(adapter->config.class, &class, 3);
}
+ g_free(str);
/* Get pairable mode */
- if (read_device_pairable(&adapter->bdaddr, &adapter->pairable) < 0)
+ adapter->pairable = g_key_file_get_boolean(key_file, "General",
+ "Pairable", &gerr);
+ if (gerr) {
adapter->pairable = TRUE;
+ g_error_free(gerr);
+ gerr = NULL;
+ }
/* Get pairable timeout */
- if (read_pairable_timeout(address, &timeout) < 0)
+ adapter->pairable_timeout = g_key_file_get_integer(key_file, "General",
+ "PairableTimeout", &gerr);
+ if (gerr) {
adapter->pairable_timeout = main_opts.pairto;
- else
- adapter->pairable_timeout = timeout;
+ g_error_free(gerr);
+ gerr = NULL;
+ }
/* Get discoverable timeout */
- if (read_discoverable_timeout(address, &timeout) < 0)
+ adapter->discov_timeout = g_key_file_get_integer(key_file, "General",
+ "DiscoverableTimeout", &gerr);
+ if (gerr) {
adapter->discov_timeout = main_opts.discovto;
- else
- adapter->discov_timeout = timeout;
+ g_error_free(gerr);
+ gerr = NULL;
+ }
/* Get mode */
+ str = g_key_file_get_string(key_file, "General", "Mode", NULL);
if (main_opts.remember_powered == FALSE)
adapter->config.mode = main_opts.mode;
- else if (read_device_mode(address, mode, sizeof(mode)) == 0)
- adapter->config.mode = get_mode(mode);
+ else if (str)
+ adapter->config.mode = get_mode(str);
else
adapter->config.mode = main_opts.mode;
+ g_free(str);
/* Get on mode */
- if (read_on_mode(address, mode, sizeof(mode)) == 0)
- adapter->config.on_mode = get_mode(mode);
+ str = g_key_file_get_string(key_file, "General", "OnMode", NULL);
+ if (str)
+ adapter->config.on_mode = get_mode(str);
else
adapter->config.on_mode = MODE_CONNECTABLE;
+ g_free(str);
+
+ g_key_file_free(key_file);
}
gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
--
1.7.9.5
^ permalink raw reply related
* [PATCH 6/7] adapter: Read mode in storage at init
From: Frédéric Danis @ 2012-10-09 15:58 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349798318-12689-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 61 ++++++++++++++++++++++++++++++++-------------------------
1 file changed, 34 insertions(+), 27 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 03ed0f0..8582a0e 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -116,6 +116,8 @@ struct service_auth {
struct btd_adapter_config {
char *name;
uint8_t class[3];
+ uint8_t mode;
+ uint8_t on_mode;
};
struct btd_adapter {
@@ -208,7 +210,7 @@ static const char *mode2str(uint8_t mode)
}
}
-static uint8_t get_mode(const bdaddr_t *bdaddr, const char *mode)
+static uint8_t get_mode(const char *mode)
{
if (strcasecmp("off", mode) == 0)
return MODE_OFF;
@@ -216,15 +218,7 @@ static uint8_t get_mode(const bdaddr_t *bdaddr, const char *mode)
return MODE_CONNECTABLE;
else if (strcasecmp("discoverable", mode) == 0)
return MODE_DISCOVERABLE;
- else if (strcasecmp("on", mode) == 0) {
- char onmode[14], srcaddr[18];
-
- ba2str(bdaddr, srcaddr);
- if (read_on_mode(srcaddr, onmode, sizeof(onmode)) < 0)
- return MODE_CONNECTABLE;
-
- return get_mode(bdaddr, onmode);
- } else
+ else
return MODE_UNKNOWN;
}
@@ -329,6 +323,10 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
return err;
done:
+ adapter->config.mode = new_mode;
+ if (new_mode != MODE_OFF)
+ adapter->config.on_mode = new_mode;
+
modestr = mode2str(new_mode);
write_device_mode(&adapter->bdaddr, modestr);
@@ -388,7 +386,7 @@ static void set_powered(struct btd_adapter *adapter, gboolean powered,
int err;
if (powered) {
- mode = get_mode(&adapter->bdaddr, "on");
+ mode = adapter->config.on_mode;
return set_discoverable(adapter, mode == MODE_DISCOVERABLE,
id);
}
@@ -1401,7 +1399,7 @@ static DBusMessage *request_session(DBusConnection *conn,
if (!adapter->mode_sessions)
adapter->global_mode = adapter->mode;
- new_mode = get_mode(&adapter->bdaddr, "on");
+ new_mode = adapter->config.on_mode;
req = find_session(adapter->mode_sessions, sender);
if (req) {
@@ -2310,21 +2308,15 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
uint16_t *discoverable_timeout,
gboolean *pairable)
{
- char str[14], address[18];
+ char address[18];
ba2str(&adapter->bdaddr, address);
- if (mode) {
- if (main_opts.remember_powered == FALSE)
- *mode = main_opts.mode;
- else if (read_device_mode(address, str, sizeof(str)) == 0)
- *mode = get_mode(&adapter->bdaddr, str);
- else
- *mode = main_opts.mode;
- }
+ if (mode)
+ *mode = adapter->config.mode;
if (on_mode)
- *on_mode = get_mode(&adapter->bdaddr, "on");
+ *on_mode = adapter->config.on_mode;
if (discoverable_timeout)
*discoverable_timeout = adapter->discov_timeout;
@@ -2486,6 +2478,10 @@ static void set_mode_complete(struct btd_adapter *adapter)
const char *modestr;
int err;
+ adapter->config.mode = adapter->mode;
+ if (adapter->mode != MODE_OFF)
+ adapter->config.on_mode = adapter->mode;
+
modestr = mode2str(adapter->mode);
write_device_mode(&adapter->bdaddr, modestr);
@@ -2660,6 +2656,7 @@ static void load_config(struct btd_adapter *adapter)
{
char name[MAX_NAME_LENGTH + 1];
char address[18];
+ char mode[14];
int timeout;
ba2str(&adapter->bdaddr, address);
@@ -2691,6 +2688,20 @@ static void load_config(struct btd_adapter *adapter)
adapter->discov_timeout = main_opts.discovto;
else
adapter->discov_timeout = timeout;
+
+ /* Get mode */
+ if (main_opts.remember_powered == FALSE)
+ adapter->config.mode = main_opts.mode;
+ else if (read_device_mode(address, mode, sizeof(mode)) == 0)
+ adapter->config.mode = get_mode(mode);
+ else
+ adapter->config.mode = main_opts.mode;
+
+ /* Get on mode */
+ if (read_on_mode(address, mode, sizeof(mode)) == 0)
+ adapter->config.on_mode = get_mode(mode);
+ else
+ adapter->config.on_mode = MODE_CONNECTABLE;
}
gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
@@ -3625,17 +3636,13 @@ gboolean adapter_powering_down(struct btd_adapter *adapter)
int btd_adapter_restore_powered(struct btd_adapter *adapter)
{
- char mode[14], address[18];
-
if (!main_opts.remember_powered)
return -EINVAL;
if (adapter->up)
return 0;
- ba2str(&adapter->bdaddr, address);
- if (read_device_mode(address, mode, sizeof(mode)) == 0 &&
- g_str_equal(mode, "off"))
+ if (adapter->config.mode == MODE_OFF)
return 0;
return mgmt_set_powered(adapter->dev_id, TRUE);
--
1.7.9.5
^ permalink raw reply related
* [PATCH 5/7] adapter: Read discoverable timeout in storage at init
From: Frédéric Danis @ 2012-10-09 15:58 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349798318-12689-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index ed9f848..03ed0f0 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2266,16 +2266,6 @@ static void load_connections(struct btd_adapter *adapter)
g_slist_free_full(conns, g_free);
}
-static int get_discoverable_timeout(const char *src)
-{
- int timeout;
-
- if (read_discoverable_timeout(src, &timeout) == 0)
- return timeout;
-
- return main_opts.discovto;
-}
-
static void set_auto_connect(gpointer data, gpointer user_data)
{
struct btd_device *device = data;
@@ -2337,7 +2327,7 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
*on_mode = get_mode(&adapter->bdaddr, "on");
if (discoverable_timeout)
- *discoverable_timeout = get_discoverable_timeout(address);
+ *discoverable_timeout = adapter->discov_timeout;
if (pairable)
*pairable = adapter->pairable;
@@ -2418,7 +2408,6 @@ void btd_adapter_start(struct btd_adapter *adapter)
adapter->dev_class = 0;
adapter->off_requested = FALSE;
adapter->up = TRUE;
- adapter->discov_timeout = get_discoverable_timeout(address);
adapter->off_timer = 0;
if (adapter->scan_mode & SCAN_INQUIRY)
@@ -2696,6 +2685,12 @@ static void load_config(struct btd_adapter *adapter)
adapter->pairable_timeout = main_opts.pairto;
else
adapter->pairable_timeout = timeout;
+
+ /* Get discoverable timeout */
+ if (read_discoverable_timeout(address, &timeout) < 0)
+ adapter->discov_timeout = main_opts.discovto;
+ else
+ adapter->discov_timeout = timeout;
}
gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
--
1.7.9.5
^ permalink raw reply related
* [PATCH 4/7] adapter: Read pairable timeout in storage at init
From: Frédéric Danis @ 2012-10-09 15:58 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349798318-12689-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 3dc91df..ed9f848 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2276,16 +2276,6 @@ static int get_discoverable_timeout(const char *src)
return main_opts.discovto;
}
-static int get_pairable_timeout(const char *src)
-{
- int timeout;
-
- if (read_pairable_timeout(src, &timeout) == 0)
- return timeout;
-
- return main_opts.pairto;
-}
-
static void set_auto_connect(gpointer data, gpointer user_data)
{
struct btd_device *device = data;
@@ -2429,7 +2419,6 @@ void btd_adapter_start(struct btd_adapter *adapter)
adapter->off_requested = FALSE;
adapter->up = TRUE;
adapter->discov_timeout = get_discoverable_timeout(address);
- adapter->pairable_timeout = get_pairable_timeout(address);
adapter->off_timer = 0;
if (adapter->scan_mode & SCAN_INQUIRY)
@@ -2681,6 +2670,10 @@ void btd_adapter_unref(struct btd_adapter *adapter)
static void load_config(struct btd_adapter *adapter)
{
char name[MAX_NAME_LENGTH + 1];
+ char address[18];
+ int timeout;
+
+ ba2str(&adapter->bdaddr, address);
/* Get name */
if (read_local_name(&adapter->bdaddr, name) < 0)
@@ -2697,6 +2690,12 @@ static void load_config(struct btd_adapter *adapter)
/* Get pairable mode */
if (read_device_pairable(&adapter->bdaddr, &adapter->pairable) < 0)
adapter->pairable = TRUE;
+
+ /* Get pairable timeout */
+ if (read_pairable_timeout(address, &timeout) < 0)
+ adapter->pairable_timeout = main_opts.pairto;
+ else
+ adapter->pairable_timeout = timeout;
}
gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
--
1.7.9.5
^ permalink raw reply related
* [PATCH 3/7] adapter: Move pairable read to load_config()
From: Frédéric Danis @ 2012-10-09 15:58 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349798318-12689-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index f66d2ab..3dc91df 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2693,6 +2693,10 @@ static void load_config(struct btd_adapter *adapter)
uint32_t class = htobl(main_opts.class);
memcpy(adapter->config.class, &class, 3);
}
+
+ /* Get pairable mode */
+ if (read_device_pairable(&adapter->bdaddr, &adapter->pairable) < 0)
+ adapter->pairable = TRUE;
}
gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
@@ -2720,10 +2724,6 @@ gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
clear_blocked(adapter);
load_devices(adapter);
- /* Set pairable mode */
- if (read_device_pairable(&adapter->bdaddr, &adapter->pairable) < 0)
- adapter->pairable = TRUE;
-
/* retrieve the active connections: address the scenario where
* the are active connections before the daemon've started */
load_connections(adapter);
--
1.7.9.5
^ permalink raw reply related
* [PATCH 2/7] adapter: Read device class in storage at init
From: Frédéric Danis @ 2012-10-09 15:58 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349798318-12689-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index d5379c1..f66d2ab 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -115,6 +115,7 @@ struct service_auth {
struct btd_adapter_config {
char *name;
+ uint8_t class[3];
};
struct btd_adapter {
@@ -727,6 +728,10 @@ void btd_adapter_class_changed(struct btd_adapter *adapter, uint8_t *new_class)
if (class == adapter->dev_class)
return;
+ adapter->config.class[0] = new_class[0];
+ adapter->config.class[1] = new_class[1];
+ adapter->config.class[2] = new_class[2];
+
write_local_class(&adapter->bdaddr, new_class);
adapter->dev_class = class;
@@ -2351,15 +2356,8 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
void btd_adapter_read_class(struct btd_adapter *adapter, uint8_t *major,
uint8_t *minor)
{
- uint8_t cls[3];
-
- if (read_local_class(&adapter->bdaddr, cls) < 0) {
- uint32_t class = htobl(main_opts.class);
- memcpy(cls, &class, 3);
- }
-
- *major = cls[1];
- *minor = cls[0];
+ *major = adapter->config.class[1];
+ *minor = adapter->config.class[0];
}
uint32_t btd_adapter_get_class(struct btd_adapter *adapter)
@@ -2690,6 +2688,11 @@ static void load_config(struct btd_adapter *adapter)
else
adapter->config.name = g_strdup(name);
+ /* Get class */
+ if (read_local_class(&adapter->bdaddr, adapter->config.class) < 0) {
+ uint32_t class = htobl(main_opts.class);
+ memcpy(adapter->config.class, &class, 3);
+ }
}
gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
--
1.7.9.5
^ permalink raw reply related
* [PATCH 1/7] adapter: Read name in storage at init
From: Frédéric Danis @ 2012-10-09 15:58 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349798318-12689-1-git-send-email-frederic.danis@linux.intel.com>
---
plugins/adaptername.c | 9 ++++++---
src/adapter.c | 34 ++++++++++++++++++++++++++++++++++
src/adapter.h | 1 +
3 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/plugins/adaptername.c b/plugins/adaptername.c
index f58fb0f..46dbbe8 100644
--- a/plugins/adaptername.c
+++ b/plugins/adaptername.c
@@ -198,7 +198,8 @@ static void set_pretty_name(struct btd_adapter *adapter,
static int adaptername_probe(struct btd_adapter *adapter)
{
int current_id;
- char name[MAX_NAME_LENGTH + 1];
+ char *name;
+ char str[MAX_NAME_LENGTH + 1];
char *pretty_hostname;
pretty_hostname = read_pretty_host_name();
@@ -211,8 +212,10 @@ static int adaptername_probe(struct btd_adapter *adapter)
adapter_set_allow_name_changes(adapter, TRUE);
current_id = adapter_get_dev_id(adapter);
- if (read_local_name(adapter_get_address(adapter), name) < 0)
- expand_name(name, MAX_NAME_LENGTH, main_opts.name, current_id);
+ if (adapter_get_config_name(adapter, &name) < 0) {
+ expand_name(str, MAX_NAME_LENGTH, main_opts.name, current_id);
+ name = str;
+ }
DBG("Setting name '%s' for device 'hci%d'", name, current_id);
adapter_set_name(adapter, name);
diff --git a/src/adapter.c b/src/adapter.c
index 6b28651..d5379c1 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -113,6 +113,10 @@ struct service_auth {
struct agent *agent; /* NULL for queued auths */
};
+struct btd_adapter_config {
+ char *name;
+};
+
struct btd_adapter {
uint16_t dev_id;
gboolean up;
@@ -153,6 +157,8 @@ struct btd_adapter {
gboolean pairable; /* pairable state */
gboolean initialized;
+ struct btd_adapter_config config;
+
gboolean off_requested; /* DEVDOWN ioctl was called */
gint ref;
@@ -778,11 +784,24 @@ int adapter_set_name(struct btd_adapter *adapter, const char *name)
adapter->name = g_strdup(maxname);
}
+ g_free(adapter->config.name);
+ adapter->config.name = g_strdup(maxname);
+
write_local_name(&adapter->bdaddr, maxname);
return 0;
}
+int adapter_get_config_name(struct btd_adapter *adapter, char **name)
+{
+ if (adapter->config.name == NULL)
+ return -EINVAL;
+
+ *name = adapter->config.name;
+
+ return 0;
+}
+
static void set_name(struct btd_adapter *adapter, const char *name,
GDBusPendingPropertySet id)
{
@@ -2661,6 +2680,18 @@ void btd_adapter_unref(struct btd_adapter *adapter)
g_free(path);
}
+static void load_config(struct btd_adapter *adapter)
+{
+ char name[MAX_NAME_LENGTH + 1];
+
+ /* Get name */
+ if (read_local_name(&adapter->bdaddr, name) < 0)
+ adapter->config.name = NULL;
+ else
+ adapter->config.name = g_strdup(name);
+
+}
+
gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
{
adapter->up = up;
@@ -2680,6 +2711,7 @@ gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
if (main_opts.gatt_enabled)
btd_adapter_gatt_server_start(adapter);
+ load_config(adapter);
load_drivers(adapter);
btd_profile_foreach(probe_profile, adapter);
clear_blocked(adapter);
@@ -2748,6 +2780,8 @@ void adapter_remove(struct btd_adapter *adapter)
/* Return adapter to down state if it was not up on init */
if (!adapter->already_up && adapter->up)
mgmt_set_powered(adapter->dev_id, FALSE);
+
+ g_free(adapter->config.name);
}
uint16_t adapter_get_dev_id(struct btd_adapter *adapter)
diff --git a/src/adapter.h b/src/adapter.h
index 72a9988..3e00f4f 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -133,6 +133,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
void adapter_emit_device_found(struct btd_adapter *adapter,
struct remote_dev_info *dev);
void adapter_mode_changed(struct btd_adapter *adapter, uint8_t scan_mode);
+int adapter_get_config_name(struct btd_adapter *adapter, char **name);
int adapter_set_name(struct btd_adapter *adapter, const char *name);
void adapter_name_changed(struct btd_adapter *adapter, const char *name);
void adapter_service_insert(struct btd_adapter *adapter, void *rec);
--
1.7.9.5
^ permalink raw reply related
* [PATCH 0/7] Move adapter config file to ini-file format
From: Frédéric Danis @ 2012-10-09 15:58 UTC (permalink / raw)
To: linux-bluetooth
Adapter saved configuration will be saved to /var/lib/bluetooth/<adapter address>/adapter
in ini-file format for BlueZ 5.
If this file does not exist, we try to convert old config file to it.
Access to variables during run-time is performed in adapter structure which is populated by loading saved configuration during initialization.
First 6 patches remove access to config file from run-time.
Last patch move to ini-file format style (load, save and convert).
Frédéric Danis (7):
adapter: Read name in storage at init
adapter: Read device class in storage at init
adapter: Move pairable read to load_config()
adapter: Read pairable timeout in storage at init
adapter: Read discoverable timeout in storage at init
adapter: Read mode in storage at init
adapter: Move saved config to ini-file format
plugins/adaptername.c | 9 +-
src/adapter.c | 313 +++++++++++++++++++++++++++++++++++++------------
src/adapter.h | 1 +
3 files changed, 245 insertions(+), 78 deletions(-)
--
1.7.9.5
^ permalink raw reply
* Re: [PATCH 2/9] Pass confirm name as gboolean value
From: Lucas De Marchi @ 2012-10-09 15:49 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: Szymon Janc, linux-bluetooth
In-Reply-To: <1349794286.27233.95.camel@aeonflux>
On Tue, Oct 9, 2012 at 11:51 AM, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Szymon,
>
>> confirm_name is a boolean value and can be pass as such instead of
>> uint8_t.
>
> actually long term I want to move to bool usage. So maybe this is a good
> start to get this going.
agreed... on new code that I'm adding I'm using bool.
Btw, could we already use bool in gdbus/ ?
Lucas De Marchi
^ permalink raw reply
* Re: [PATCH 2/9] Pass confirm name as gboolean value
From: Marcel Holtmann @ 2012-10-09 14:51 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1349784722-14578-3-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
> confirm_name is a boolean value and can be pass as such instead of
> uint8_t.
actually long term I want to move to bool usage. So maybe this is a good
start to get this going.
Regards
Marcel
^ permalink raw reply
* Re: [RFCv1 4/6] Bluetooth: Handle number of compl blocks for AMP_LINK
From: Marcel Holtmann @ 2012-10-09 14:49 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1349707932-10006-5-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
> Add handling blocks count for AMP link.
>
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> ---
> net/bluetooth/hci_event.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index 82e478a..c479732 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -2698,13 +2698,21 @@ static void hci_num_comp_blocks_evt(struct hci_dev *hdev, struct sk_buff *skb)
>
> for (i = 0; i < ev->num_hndl; i++) {
> struct hci_comp_blocks_info *info = &ev->handles[i];
> - struct hci_conn *conn;
> + struct hci_conn *conn = NULL;
> + struct hci_chan *chan;
> __u16 handle, block_count;
>
> handle = __le16_to_cpu(info->handle);
> block_count = __le16_to_cpu(info->blocks);
>
> - conn = hci_conn_hash_lookup_handle(hdev, handle);
> + if (hdev->dev_type == HCI_BREDR) {
> + conn = hci_conn_hash_lookup_handle(hdev, handle);
> + } else {
> + chan = hci_chan_lookup_handle_all(hdev, handle);
> + if (chan)
> + conn = chan->conn;
Just in case, we better use a switch statement here.
And now coming to think about it, do we ever need the hci_chan anyway.
Then why not have a function that looks up the hci_conn.
Maybe introduce a new hci_conn_lookup_handle(hdev, handle) and it will
do the right thing depending on what the device type is.
> + }
> +
> if (!conn)
> continue;
>
Regards
Marcel
^ permalink raw reply
* Re: [RFCv1 3/6] Bluetooth: AMP: Add handle to hci_chan structure
From: Marcel Holtmann @ 2012-10-09 14:46 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1349707932-10006-4-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
> hci_chan will be identified by handle used in logical link creation
> process. This handle is used in AMP ACL-U packet handle field.
>
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> ---
> include/net/bluetooth/hci_core.h | 6 ++++--
> net/bluetooth/hci_conn.c | 34 ++++++++++++++++++++++++++++++++++
> 2 files changed, 38 insertions(+), 2 deletions(-)
>
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index 90ae4f0..951f604 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -348,7 +348,7 @@ struct hci_conn {
>
> struct hci_chan {
> struct list_head list;
> -
> + __u16 handle;
> struct hci_conn *conn;
> struct sk_buff_head data_q;
> unsigned int sent;
> @@ -565,7 +565,9 @@ void hci_conn_check_pending(struct hci_dev *hdev);
> struct hci_chan *hci_chan_create(struct hci_conn *conn);
> void hci_chan_del(struct hci_chan *chan);
> void hci_chan_list_flush(struct hci_conn *conn);
> -
> +struct hci_chan *hci_chan_lookup_handle(struct hci_conn *hcon, __u16 handle);
> +struct hci_chan *hci_chan_lookup_handle_all(struct hci_dev *hdev,
> + __u16 handle);
this naming is pretty bad. I have no idea what one function does
different compared to the other. Especially since none of them take a
hci_chan as argument, but start with that prefix.
Would be the naming hci_conn_lookup_chan be a lot clearer? Or maybe
hci_chan_lookup_from_dev or similar.
> struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
> __u8 dst_type, __u8 sec_level, __u8 auth_type);
> int hci_conn_check_link_mode(struct hci_conn *conn);
> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
> index 3584f58..7387516 100644
> --- a/net/bluetooth/hci_conn.c
> +++ b/net/bluetooth/hci_conn.c
> @@ -992,3 +992,37 @@ void hci_chan_list_flush(struct hci_conn *conn)
> list_for_each_entry_safe(chan, n, &conn->chan_list, list)
> hci_chan_del(chan);
> }
> +
> +struct hci_chan *hci_chan_lookup_handle(struct hci_conn *hcon, __u16 handle)
> +{
> + struct hci_chan *hchan;
> +
> + list_for_each_entry(hchan, &hcon->chan_list, list) {
> + if (hchan->handle == handle)
> + return hchan;
> + }
> +
> + return NULL;
> +}
Since this function is unprotected, you better make this __hci_....
And on a different note. It is not used at all. So why is this public
anyway?
> +
> +struct hci_chan *hci_chan_lookup_handle_all(struct hci_dev *hdev, __u16 handle)
> +{
> + struct hci_conn_hash *h = &hdev->conn_hash;
> + struct hci_conn *hcon;
> +
> + rcu_read_lock();
> +
> + list_for_each_entry_rcu(hcon, &h->list, list) {
> + struct hci_chan *hchan;
> +
> + hchan = hci_chan_lookup_handle(hcon, handle);
> + if (hchan) {
> + rcu_read_unlock();
> + return hchan;
Please use break here. Have a global hchan variable assigned to NULL and
just break here.
> + }
> + }
> +
> + rcu_read_unlock();
> +
> + return NULL;
> +}
Regards
Marcel
^ permalink raw reply
* Re: [RFCv1 2/6] Bluetooth: AMP: Handle AMP_LINK timeout
From: Marcel Holtmann @ 2012-10-09 14:39 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1349707932-10006-3-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
> When AMP_LINK timeouts execute HCI_OP_DISCONN_PHY_LINK as analog to
> HCI_OP_DISCONNECT for ACL_LINK.
>
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> ---
> net/bluetooth/hci_conn.c | 35 ++++++++++++++++++++++++++++++++---
> 1 file changed, 32 insertions(+), 3 deletions(-)
>
> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
> index 53202f6..3584f58 100644
> --- a/net/bluetooth/hci_conn.c
> +++ b/net/bluetooth/hci_conn.c
> @@ -130,6 +130,20 @@ void hci_acl_disconn(struct hci_conn *conn, __u8 reason)
> hci_send_cmd(conn->hdev, HCI_OP_DISCONNECT, sizeof(cp), &cp);
> }
>
> +static void hci_amp_disconn(struct hci_conn *conn, __u8 reason)
> +{
> + struct hci_cp_disconn_phy_link cp;
> +
> + BT_DBG("hcon %p", conn);
> +
> + conn->state = BT_DISCONN;
> +
> + cp.phy_handle = (u8) conn->handle;
I rather not do this cast. Maybe having conn->phy_handle is cleaner or
some helper macro like HCI_PHY_HANDLE(conn->handle) or something. Or
just do conn->handle & 0xff.
> + cp.reason = reason;
> + hci_send_cmd(conn->hdev, HCI_OP_DISCONN_PHY_LINK,
> + sizeof(cp), &cp);
> +}
> +
> static void hci_add_sco(struct hci_conn *conn, __u16 handle)
> {
> struct hci_dev *hdev = conn->hdev;
> @@ -230,11 +244,27 @@ void hci_sco_setup(struct hci_conn *conn, __u8 status)
> }
> }
>
> +static void hci_conn_disconnect(struct hci_conn *conn)
> +{
> + u8 reason;
> +
> + reason = hci_proto_disconn_ind(conn);
Please keep using __u8 and in this case just make it one line.
__u8 reason = hci_proto_disconn_ind(conn);
> +
> + switch (conn->type) {
> + case ACL_LINK:
> + hci_acl_disconn(conn, reason);
> + break;
> +
Don't bother with this empty line.
> + case AMP_LINK:
> + hci_amp_disconn(conn, reason);
> + break;
> + }
> +}
> +
> static void hci_conn_timeout(struct work_struct *work)
> {
> struct hci_conn *conn = container_of(work, struct hci_conn,
> disc_work.work);
> - __u8 reason;
>
> BT_DBG("hcon %p state %s", conn, state_to_string(conn->state));
>
> @@ -253,8 +283,7 @@ static void hci_conn_timeout(struct work_struct *work)
> break;
> case BT_CONFIG:
> case BT_CONNECTED:
> - reason = hci_proto_disconn_ind(conn);
> - hci_acl_disconn(conn, reason);
> + hci_conn_disconnect(conn);
> break;
> default:
> conn->state = BT_CLOSED;
Regards
Marcel
^ permalink raw reply
* Re: [PATCH 0/9] Remove some old code
From: Vinicius Costa Gomes @ 2012-10-09 14:30 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1349784722-14578-1-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
On 14:11 Tue 09 Oct, Szymon Janc wrote:
> This removes some unused or not needed old code.
>
> Szymon Janc (9):
> Simplify checking if found device is legacy
> Pass confirm name as gboolean value
> event: Don't store EIR in btd_event_device_found
> storage: Remove not used read_remote_eir
> storage: Remove not used write_version_info
> storage: Remove not used write_features_info
> storage: Remove not used read_remote_features
> adapter: Remove not used btd_adapter_switch_{online,offline}
> functions
> device: Remove not used device_set_class function
>
> src/adapter.c | 95 +++++------------------------------
> src/adapter.h | 8 ++-
> src/device.c | 12 -----
> src/device.h | 1 -
> src/event.c | 27 ++--------
> src/event.h | 6 +--
> src/mgmt.c | 13 ++---
> src/storage.c | 156 ---------------------------------------------------------
> src/storage.h | 11 ----
> 9 files changed, 26 insertions(+), 303 deletions(-)
Ack.
>
> --
> 1.7.9.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
Cheers,
--
Vinicius
^ permalink raw reply
* Re: [PATCH v3 00/15] Thermometer watchers API change + fixes
From: Anderson Lizardo @ 2012-10-09 14:15 UTC (permalink / raw)
To: Andrzej Kaczmarek; +Cc: linux-bluetooth
In-Reply-To: <1349781598-22580-1-git-send-email-andrzej.kaczmarek@tieto.com>
Hi Andrzej,
On Tue, Oct 9, 2012 at 7:19 AM, Andrzej Kaczmarek
<andrzej.kaczmarek@tieto.com> wrote:
> Also this was tested with PTS 4.5.3 and works fine now after memset fix,
> except for TP/THF/CO/BI-07-I which seems to have issue in PTS (there should
> be reserved value for temperature type but PTS sends 0x02 which is
> perfectly valid value thus it won't be discarded on our side).
BTW, you can open a ticket for fixing this in PTS. They are usually
fast in fixing things (but not so fast on delivering new releases).
Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* [PATCH] build: Add missing documentation files to EXTRA_DIST
From: Andrzej Kaczmarek @ 2012-10-09 13:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Andrzej Kaczmarek
This patch adds missing documentation files to EXTRA_DIST variable so they
are included when creating tarball.
---
Makefile.am | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am
index 3b08f9a..dbbd794 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -401,7 +401,9 @@ EXTRA_DIST += doc/manager-api.txt \
doc/network-api.txt doc/input-api.txt doc/audio-api.txt \
doc/control-api.txt doc/hfp-api.txt doc/health-api.txt \
doc/sap-api.txt doc/media-api.txt doc/assigned-numbers.txt \
- doc/supported-features.txt doc/alert-api.txt
+ doc/supported-features.txt doc/alert-api.txt doc/mgmt-api.txt \
+ doc/oob-api.txt doc/proximity-api.txt doc/heartrate-api.txt \
+ doc/thermometer-api.txt
AM_YFLAGS = -d
--
1.7.11.3
^ 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