* Re: [PATCH 1/8] Bluetooth: Add clarifying comment to bt_sock_wait_state()
From: Marcel Holtmann @ 2013-09-24 18:11 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
In-Reply-To: <1380031363-1266-2-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
> The bt_sock_wait_state requires the sk lock to be held (through
> lock_sock) so document it clearly in the code.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/af_bluetooth.c | 1 +
> 1 file changed, 1 insertion(+)
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Regards
Marcel
^ permalink raw reply
* Re: [PATCH 5/8] Bluetooth: Move mgmt response convenience functions to a better location
From: Marcel Holtmann @ 2013-09-24 18:11 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
In-Reply-To: <1380031363-1266-6-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
> The settings_rsp and cmd_status_rsp functions can be useful for all mgmt
> command handlers when asynchronous request callbacks are used. They will
> e.g. be used by subsequent patches to change set_le to use an async
> request as well as a new set_advertising command. Therefore, move them
> higher up in the mgmt.c file to avoid unnecessary forward declarations
> or mixing this trivial change with other patches.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/mgmt.c | 60 ++++++++++++++++++++++++++--------------------------
> 1 file changed, 30 insertions(+), 30 deletions(-)
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Regards
Marcel
^ permalink raw reply
* Re: [PATCH 7/8] Bluetooth: Add new mgmt setting for LE advertising
From: Johan Hedberg @ 2013-09-24 17:21 UTC (permalink / raw)
To: Anderson Lizardo; +Cc: BlueZ development
In-Reply-To: <CAJdJm_MDoR2ed6++x5JAxaG2=0+zUdAGztL_L3i-ObtaM+WbRA@mail.gmail.com>
Hi Lizardo,
On Tue, Sep 24, 2013, Anderson Lizardo wrote:
> On Tue, Sep 24, 2013 at 10:02 AM, <johan.hedberg@gmail.com> wrote:
> > This patch adds a new mgmt setting for LE advertising and hooks up the
> > necessary places in the mgmt code to operate on the HCI_LE_PERIPHERAL
> > flag (which corresponds to this setting). This patch does not yet add
> > any new command for enabling the setting - that is left for a subsequent
> > patch.
>
> How this code behaves if we enable/disable LE advertising using
> hciconfig hci0 leadv/noleadv? IIRC the LE_SET_ADV_ENABLE command will
> fail if advertising is already set on the controller.
You're right that a mix of mgmt and hciconfig will mix things up on the
kernel side. This is something I was aware of but didn't investigate
much further since I was assuming it would add too much complexity to
the code. The principle has always been that we keep compatibility/good
behavior with mixed mgmg/raw HCI access only as long as it doesn't
needlessly complicate the code.
That said, I'll take a another look if the flag setting could be moved
to a hci_event.c handler from the request callback without requiring the
addition of a second flag or state variable. This issue is not unique to
this new setting but actually exists for many of them. What we probably
need is a generic mgmt_send_new_settings function that hci_event.c
handlers can call when they know that new_settings should be emitted. I
suspect that might solve the issue.
Johan
^ permalink raw reply
* [PATCH v3 3/3] android: Android version of log.c
From: Frederic Danis @ 2013-09-24 16:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380039070-825-1-git-send-email-frederic.danis@linux.intel.com>
Add logging system to BlueZ Android daemon.
Android build will use android/log.c file while autotools build will use
src/log.c instead.
---
Makefile.android | 4 +-
android/Android.mk | 1 +
android/log.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++
android/main.c | 34 +++++++++++
4 files changed, 209 insertions(+), 2 deletions(-)
create mode 100644 android/log.c
diff --git a/Makefile.android b/Makefile.android
index e056dce..1184e5f 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -2,8 +2,8 @@
if ANDROID
noinst_PROGRAMS += android/bluetoothd
-android_bluetoothd_SOURCES = android/main.c
+android_bluetoothd_SOURCES = android/main.c src/log.c
android_bluetoothd_LDADD = @GLIB_LIBS@
-EXTRA_DIST += android/Android.mk
+EXTRA_DIST += android/Android.mk android/log.c
endif
diff --git a/android/Android.mk b/android/Android.mk
index fc3d6c2..e3f0fd7 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -14,6 +14,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
main.c \
+ log.c \
LOCAL_C_INCLUDES := \
$(call include-path-for, glib) \
diff --git a/android/log.c b/android/log.c
new file mode 100644
index 0000000..908f883
--- /dev/null
+++ b/android/log.c
@@ -0,0 +1,172 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <sys/uio.h>
+
+#include <glib.h>
+
+#include "log.h"
+
+#define LOG_DEBUG 3
+#define LOG_INFO 4
+#define LOG_WARN 5
+#define LOG_ERR 6
+
+static const char tag[] = "BlueZ";
+static int system_fd;
+
+static void android_log(int pri, const char *fmt, va_list ap)
+{
+ char *msg;
+ struct iovec vec[3];
+
+ if (system_fd == -1)
+ return;
+
+ msg = g_strdup_vprintf(fmt, ap);
+
+ vec[0].iov_base = (unsigned char *) &pri;
+ vec[0].iov_len = 1;
+ vec[1].iov_base = (void *) tag;
+ vec[1].iov_len = strlen(tag) + 1;
+ vec[2].iov_base = (void *) msg;
+ vec[2].iov_len = strlen(msg) + 1;
+
+ writev(system_fd, vec, 3);
+
+ g_free(msg);
+}
+
+void info(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+
+ android_log(LOG_INFO, format, ap);
+
+ va_end(ap);
+}
+
+void warn(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+
+ android_log(LOG_WARN, format, ap);
+
+ va_end(ap);
+}
+
+void error(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+
+ android_log(LOG_ERR, format, ap);
+
+ va_end(ap);
+}
+
+void btd_debug(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+
+ android_log(LOG_DEBUG, format, ap);
+
+ va_end(ap);
+}
+
+extern struct btd_debug_desc __start___debug[];
+extern struct btd_debug_desc __stop___debug[];
+
+static char **enabled = NULL;
+
+static gboolean is_enabled(struct btd_debug_desc *desc)
+{
+ int i;
+
+ if (enabled == NULL)
+ return 0;
+
+ for (i = 0; enabled[i] != NULL; i++)
+ if (desc->file != NULL && g_pattern_match_simple(enabled[i],
+ desc->file) == TRUE)
+ return 1;
+
+ return 0;
+}
+
+void __btd_enable_debug(struct btd_debug_desc *start,
+ struct btd_debug_desc *stop)
+{
+ struct btd_debug_desc *desc;
+
+ if (start == NULL || stop == NULL)
+ return;
+
+ for (desc = start; desc < stop; desc++) {
+ if (is_enabled(desc))
+ desc->flags |= BTD_DEBUG_FLAG_PRINT;
+ }
+}
+
+void __btd_toggle_debug(void)
+{
+ struct btd_debug_desc *desc;
+
+ for (desc = __start___debug; desc < __stop___debug; desc++)
+ desc->flags |= BTD_DEBUG_FLAG_PRINT;
+}
+
+void __btd_log_init(const char *debug, int detach)
+{
+ if (debug != NULL)
+ enabled = g_strsplit_set(debug, ":, ", 0);
+
+ __btd_enable_debug(__start___debug, __stop___debug);
+
+ system_fd = open("/dev/log/system", O_WRONLY);
+
+ info("Bluetooth daemon %s", VERSION);
+}
+
+void __btd_log_cleanup(void)
+{
+ close(system_fd);
+ system_fd = -1;
+
+ g_strfreev(enabled);
+}
diff --git a/android/main.c b/android/main.c
index 1dba2d4..c0a56b1 100644
--- a/android/main.c
+++ b/android/main.c
@@ -34,6 +34,8 @@
#include <glib.h>
+#include "log.h"
+
#define SHUTDOWN_GRACE_SECONDS 10
static GMainLoop *event_loop;
@@ -57,10 +59,31 @@ static void sig_term(int sig)
__terminated = true;
}
+static char *option_debug = NULL;
static gboolean option_detach = TRUE;
static gboolean option_version = FALSE;
+static void free_options(void)
+{
+ g_free(option_debug);
+ option_debug = NULL;
+}
+
+static gboolean parse_debug(const char *key, const char *value,
+ gpointer user_data, GError **error)
+{
+ if (value)
+ option_debug = g_strdup(value);
+ else
+ option_debug = g_strdup("*");
+
+ return TRUE;
+}
+
static GOptionEntry options[] = {
+ { "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
+ G_OPTION_ARG_CALLBACK, parse_debug,
+ "Specify debug options to enable", "DEBUG" },
{ "nodetach", 'n', G_OPTION_FLAG_REVERSE,
G_OPTION_ARG_NONE, &option_detach,
"Run with logging in foreground", NULL },
@@ -102,9 +125,20 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
+ __btd_log_init(option_debug, option_detach);
+
+ /* no need to keep parsed option in memory */
+ free_options();
+
+ DBG("Entering main loop");
+
g_main_loop_run(event_loop);
g_main_loop_unref(event_loop);
+ info("Exit");
+
+ __btd_log_cleanup();
+
return EXIT_SUCCESS;
}
--
1.7.9.5
^ permalink raw reply related
* [PATCH v3 2/3] android: Add skeleton of BlueZ Android daemon
From: Frederic Danis @ 2013-09-24 16:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380039070-825-1-git-send-email-frederic.danis@linux.intel.com>
Define local mapping to glib path, otherwise this has to be inside central
place in the build repository.
Retrieve Bluetooth version from configure.ac.
---
.gitignore | 2 +
Makefile.android | 5 +++
android/Android.mk | 24 ++++++++++++
android/main.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 141 insertions(+)
create mode 100644 android/main.c
diff --git a/.gitignore b/.gitignore
index 8a25a3e..3707209 100644
--- a/.gitignore
+++ b/.gitignore
@@ -98,3 +98,5 @@ unit/test-gobex-packet
unit/test-gobex-transfer
unit/test-*.log
unit/test-*.trs
+
+android/bluetoothd
diff --git a/Makefile.android b/Makefile.android
index 5e43730..e056dce 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -1,4 +1,9 @@
if ANDROID
+noinst_PROGRAMS += android/bluetoothd
+
+android_bluetoothd_SOURCES = android/main.c
+android_bluetoothd_LDADD = @GLIB_LIBS@
+
EXTRA_DIST += android/Android.mk
endif
diff --git a/android/Android.mk b/android/Android.mk
index 31e2c1e..fc3d6c2 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -3,3 +3,27 @@ LOCAL_PATH := $(call my-dir)
# Retrieve BlueZ version from configure.ac file
BLUEZ_VERSION := $(shell grep ^AC_INIT $(LOCAL_PATH)/../configure.ac | cpp -P -D'AC_INIT(_,v)=v')
+# Specify pathmap for glib
+pathmap_INCL += glib:external/bluetooth/glib
+
+#
+# Android BlueZ daemon (bluetoothd)
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ main.c \
+
+LOCAL_C_INCLUDES := \
+ $(call include-path-for, glib) \
+ $(call include-path-for, glib)/glib \
+
+LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"
+
+LOCAL_SHARED_LIBRARIES := \
+ libglib \
+
+LOCAL_MODULE := bluetoothd
+
+include $(BUILD_EXECUTABLE)
diff --git a/android/main.c b/android/main.c
new file mode 100644
index 0000000..1dba2d4
--- /dev/null
+++ b/android/main.c
@@ -0,0 +1,110 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include <glib.h>
+
+#define SHUTDOWN_GRACE_SECONDS 10
+
+static GMainLoop *event_loop;
+
+static gboolean quit_eventloop(gpointer user_data)
+{
+ g_main_loop_quit(event_loop);
+
+ return FALSE;
+}
+
+static void sig_term(int sig)
+{
+ static bool __terminated = false;
+
+ if (!__terminated) {
+ g_timeout_add_seconds(SHUTDOWN_GRACE_SECONDS,
+ quit_eventloop, NULL);
+ }
+
+ __terminated = true;
+}
+
+static gboolean option_detach = TRUE;
+static gboolean option_version = FALSE;
+
+static GOptionEntry options[] = {
+ { "nodetach", 'n', G_OPTION_FLAG_REVERSE,
+ G_OPTION_ARG_NONE, &option_detach,
+ "Run with logging in foreground", NULL },
+ { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
+ "Show version information and exit", NULL },
+ { NULL }
+};
+
+int main(int argc, char *argv[])
+{
+ GOptionContext *context;
+ GError *err = NULL;
+ struct sigaction sa;
+
+ context = g_option_context_new(NULL);
+ g_option_context_add_main_entries(context, options, NULL);
+
+ if (g_option_context_parse(context, &argc, &argv, &err) == FALSE) {
+ if (err != NULL) {
+ g_printerr("%s\n", err->message);
+ g_error_free(err);
+ } else
+ g_printerr("An unknown error occurred\n");
+
+ exit(EXIT_FAILURE);
+ }
+
+ g_option_context_free(context);
+
+ if (option_version == TRUE) {
+ printf("%s\n", VERSION);
+ exit(EXIT_SUCCESS);
+ }
+
+ event_loop = g_main_loop_new(NULL, FALSE);
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = sig_term;
+ sigaction(SIGINT, &sa, NULL);
+ sigaction(SIGTERM, &sa, NULL);
+
+ g_main_loop_run(event_loop);
+
+ g_main_loop_unref(event_loop);
+
+ return EXIT_SUCCESS;
+}
--
1.7.9.5
^ permalink raw reply related
* [PATCH v3 1/3] build: Add skeleton for BlueZ Android
From: Frederic Danis @ 2013-09-24 16:11 UTC (permalink / raw)
To: linux-bluetooth
---
Makefile.am | 4 +++-
Makefile.android | 4 ++++
android/Android.mk | 5 +++++
bootstrap-configure | 3 ++-
configure.ac | 4 ++++
5 files changed, 18 insertions(+), 2 deletions(-)
create mode 100644 Makefile.android
create mode 100644 android/Android.mk
diff --git a/Makefile.am b/Makefile.am
index 4e4b1c5..51204f4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -179,6 +179,7 @@ test_scripts =
include Makefile.tools
include Makefile.obexd
+include Makefile.android
if HID2HCI
rulesdir = @UDEV_DIR@/rules.d
@@ -293,7 +294,8 @@ pkgconfig_DATA = lib/bluez.pc
endif
DISTCHECK_CONFIGURE_FLAGS = --disable-datafiles --enable-library \
- --disable-systemd --disable-udev
+ --disable-systemd --disable-udev \
+ --enable-android
DISTCLEANFILES = $(pkgconfig_DATA)
diff --git a/Makefile.android b/Makefile.android
new file mode 100644
index 0000000..5e43730
--- /dev/null
+++ b/Makefile.android
@@ -0,0 +1,4 @@
+
+if ANDROID
+EXTRA_DIST += android/Android.mk
+endif
diff --git a/android/Android.mk b/android/Android.mk
new file mode 100644
index 0000000..31e2c1e
--- /dev/null
+++ b/android/Android.mk
@@ -0,0 +1,5 @@
+LOCAL_PATH := $(call my-dir)
+
+# Retrieve BlueZ version from configure.ac file
+BLUEZ_VERSION := $(shell grep ^AC_INIT $(LOCAL_PATH)/../configure.ac | cpp -P -D'AC_INIT(_,v)=v')
+
diff --git a/bootstrap-configure b/bootstrap-configure
index 7a6e7d1..8bde920 100755
--- a/bootstrap-configure
+++ b/bootstrap-configure
@@ -12,4 +12,5 @@ fi
--sysconfdir=/etc \
--localstatedir=/var \
--enable-experimental \
- --disable-datafiles $*
+ --disable-datafiles \
+ --enable-android $*
diff --git a/configure.ac b/configure.ac
index 41c2935..22ab240 100644
--- a/configure.ac
+++ b/configure.ac
@@ -242,4 +242,8 @@ AC_DEFINE_UNQUOTED(CONFIGDIR, "${configdir}",
[Directory for the configuration files])
AC_SUBST(CONFIGDIR, "${configdir}")
+AC_ARG_ENABLE(android, AC_HELP_STRING([--enable-android],
+ [enable BlueZ Android]), [android=${enableval}])
+AM_CONDITIONAL(ANDROID, test "${android}" = "yes")
+
AC_OUTPUT(Makefile src/bluetoothd.8 lib/bluez.pc)
--
1.7.9.5
^ permalink raw reply related
* Re: [PATCH 7/8] Bluetooth: Add new mgmt setting for LE advertising
From: Anderson Lizardo @ 2013-09-24 15:45 UTC (permalink / raw)
To: Johan Hedberg; +Cc: BlueZ development
In-Reply-To: <1380031363-1266-8-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
On Tue, Sep 24, 2013 at 10:02 AM, <johan.hedberg@gmail.com> wrote:
> From: Johan Hedberg <johan.hedberg@intel.com>
>
> This patch adds a new mgmt setting for LE advertising and hooks up the
> necessary places in the mgmt code to operate on the HCI_LE_PERIPHERAL
> flag (which corresponds to this setting). This patch does not yet add
> any new command for enabling the setting - that is left for a subsequent
> patch.
How this code behaves if we enable/disable LE advertising using
hciconfig hci0 leadv/noleadv? IIRC the LE_SET_ADV_ENABLE command will
fail if advertising is already set on the controller.
Best Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [PATCH 8/8] Bluetooth: Add new mgmt_set_advertising command
From: Johan Hedberg @ 2013-09-24 15:42 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380031363-1266-9-git-send-email-johan.hedberg@gmail.com>
Hi,
On Tue, Sep 24, 2013, johan.hedberg@gmail.com wrote:
> This patch adds a new mgmt command for enabling and disabling
> LE advertising.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> include/net/bluetooth/mgmt.h | 2 +
> net/bluetooth/mgmt.c | 99 +++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 100 insertions(+), 1 deletion(-)
Apologies for this really short commit message. I was going to fill this
in before sending but seems I forgot. I'll fix this for the next
revision but I'll first wait at least for some feedback before that.
Johan
^ permalink raw reply
* [PATCH BlueZ 2/2] gobex: Revert g_obex_pending_req_abort to static pending_req_abort
From: Luiz Augusto von Dentz @ 2013-09-24 14:47 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Jaganath Kanakkassery
In-Reply-To: <1380034036-25143-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This reverts the changes introduced in
9095deb82572112fc0870095bf2222964610eafe that made pending_req_abort
public which is not necessary considering g_obex_cancel_req can do the
same and is safe to call even if the request is not pending.
---
gobex/gobex.c | 4 ++--
gobex/gobex.h | 2 --
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/gobex/gobex.c b/gobex/gobex.c
index deeab40..8c08b1e 100644
--- a/gobex/gobex.c
+++ b/gobex/gobex.c
@@ -685,7 +685,7 @@ static int pending_pkt_cmp(gconstpointer a, gconstpointer b)
return (p->id - id);
}
-gboolean g_obex_pending_req_abort(GObex *obex, GError **err)
+static gboolean pending_req_abort(GObex *obex, GError **err)
{
struct pending_pkt *p = obex->pending_req;
GObexPacket *req;
@@ -729,7 +729,7 @@ gboolean g_obex_cancel_req(GObex *obex, guint req_id, gboolean remove_callback)
struct pending_pkt *p;
if (obex->pending_req && obex->pending_req->id == req_id) {
- if (!g_obex_pending_req_abort(obex, NULL)) {
+ if (!pending_req_abort(obex, NULL)) {
p = obex->pending_req;
obex->pending_req = NULL;
goto immediate_completion;
diff --git a/gobex/gobex.h b/gobex/gobex.h
index 3ac7b13..76a224e 100644
--- a/gobex/gobex.h
+++ b/gobex/gobex.h
@@ -50,8 +50,6 @@ guint g_obex_send_req(GObex *obex, GObexPacket *req, int timeout,
gboolean g_obex_cancel_req(GObex *obex, guint req_id,
gboolean remove_callback);
-gboolean g_obex_pending_req_abort(GObex *obex, GError **err);
-
gboolean g_obex_send_rsp(GObex *obex, guint8 rspcode, GError **err,
guint8 first_hdr_type, ...);
--
1.8.3.1
^ permalink raw reply related
* [PATCH BlueZ 1/2] gobex: Fix crash on g_obex_pending_req_abort
From: Luiz Augusto von Dentz @ 2013-09-24 14:47 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Jaganath Kanakkassery
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
It is not safe to call g_obex_pending_req_abort directly as pending_req
can be NULL:
Invalid read of size 4
at 0x41231E: g_obex_pending_req_abort (gobex.c:693)
by 0x416A8A: g_obex_cancel_transfer (gobex-transfer.c:647)
by 0x42DEF2: obc_transfer_cancel (transfer.c:180)
by 0x43D833: process_message.isra.5 (object.c:259)
by 0x3B0701CE85: ??? (in /usr/lib64/libdbus-1.so.3.7.4)
by 0x3B0700FA30: dbus_connection_dispatch (in /usr/lib64/libdbus-1.so.3.7.4)
by 0x43A5B7: message_dispatch (mainloop.c:76)
by 0x3B03C48962: ??? (in /usr/lib64/libglib-2.0.so.0.3600.3)
by 0x3B03C47E05: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3600.3)
by 0x3B03C48157: ??? (in /usr/lib64/libglib-2.0.so.0.3600.3)
by 0x3B03C48559: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3600.3)
by 0x40D53C: main (main.c:319)
Address 0x30 is not stack'd, malloc'd or (recently) free'd
---
gobex/gobex-transfer.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c
index 4203fec..b815d60 100644
--- a/gobex/gobex-transfer.c
+++ b/gobex/gobex-transfer.c
@@ -644,7 +644,10 @@ gboolean g_obex_cancel_transfer(guint id, GObexFunc complete_func,
transfer->complete_func = complete_func;
transfer->user_data = user_data;
- ret = g_obex_pending_req_abort(transfer->obex, NULL);
+ if (transfer->req_id == 0)
+ goto done;
+
+ ret = g_obex_cancel_req(transfer->obex, transfer->req_id, FALSE);
if (ret)
return TRUE;
--
1.8.3.1
^ permalink raw reply related
* [PATCH 7/7] obexd: Prefix folders in event reports with leading slash
From: Christian Fetzer @ 2013-09-24 14:16 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380032167-6440-1-git-send-email-christian.fetzer@oss.bmw-carit.de>
From: Christian Fetzer <christian.fetzer@bmw-carit.de>
The internal representation of folder paths starts with a leading slash.
Therefore we have to prepend it to the folders received in event reports.
---
obexd/client/mns.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/obexd/client/mns.c b/obexd/client/mns.c
index 76a5e24..ca44e5f 100644
--- a/obexd/client/mns.c
+++ b/obexd/client/mns.c
@@ -188,13 +188,25 @@ static void parse_event_report_handle(struct map_event *event,
static void parse_event_report_folder(struct map_event *event,
const char *value)
{
- event->folder = g_strdup(value);
+ if (!value)
+ return;
+
+ if (g_str_has_prefix(value, "/"))
+ event->folder = g_strdup(value);
+ else
+ event->folder = g_strconcat("/", value, NULL);
}
static void parse_event_report_old_folder(struct map_event *event,
const char *value)
{
- event->old_folder = g_strdup(value);
+ if (!value)
+ return;
+
+ if (g_str_has_prefix(value, "/"))
+ event->old_folder = g_strdup(value);
+ else
+ event->old_folder = g_strconcat("/", value, NULL);
}
static void parse_event_report_msg_type(struct map_event *event,
--
1.8.3.4
^ permalink raw reply related
* [PATCH 6/7] obexd: Handle message shift and message deleted events
From: Christian Fetzer @ 2013-09-24 14:16 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380032167-6440-1-git-send-email-christian.fetzer@oss.bmw-carit.de>
From: Christian Fetzer <christian.fetzer@bmw-carit.de>
For already existing messages, the folder property needs to be updated.
Non existing messages are created only if they are moved into the
current folder. Otherwise, the event will be ignored.
A message deleted event signals that a message has been moved into the
folder /telecom/msg/deleted.
---
obexd/client/map.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/obexd/client/map.c b/obexd/client/map.c
index 8ddbc46..ee8d488 100644
--- a/obexd/client/map.c
+++ b/obexd/client/map.c
@@ -1875,6 +1875,25 @@ static void map_handle_status(struct map_data *map, struct map_event *event,
set_reception_status(msg, status);
}
+static void map_handle_message_shift(struct map_data *map,
+ struct map_event *event,
+ const char *dest)
+{
+ struct map_msg *msg;
+
+ if (!dest)
+ return;
+
+ msg = g_hash_table_lookup(map->messages, event->handle);
+
+ /* Change folder for existing messages; create non existing messages
+ * only when they are moved into the current folder. */
+ if (msg)
+ set_folder(msg, dest);
+ else if (g_strcmp0(obc_session_get_folder(map->session), dest) == 0)
+ map_msg_create_from_event(map, event, dest);
+}
+
static void map_handle_notification(struct map_event *event, void *user_data)
{
struct map_data *map = user_data;
@@ -1901,6 +1920,12 @@ static void map_handle_notification(struct map_event *event, void *user_data)
case MAP_ET_SENDING_FAILURE:
map_handle_status(map, event, "sending-failure");
break;
+ case MAP_ET_MESSAGE_DELETED:
+ map_handle_message_shift(map, event, "/telecom/msg/deleted");
+ break;
+ case MAP_ET_MESSAGE_SHIFT:
+ map_handle_message_shift(map, event, event->folder);
+ break;
default:
break;
}
--
1.8.3.4
^ permalink raw reply related
* [PATCH 5/7] obexd: Add function set_folder to MAP client
From: Christian Fetzer @ 2013-09-24 14:16 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380032167-6440-1-git-send-email-christian.fetzer@oss.bmw-carit.de>
From: Christian Fetzer <christian.fetzer@bmw-carit.de>
The function allows to change the folder a message belongs to.
---
obexd/client/map.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/obexd/client/map.c b/obexd/client/map.c
index 3b0f662..8ddbc46 100644
--- a/obexd/client/map.c
+++ b/obexd/client/map.c
@@ -1830,6 +1830,18 @@ static void map_msg_create_from_event(struct map_data *map,
parse_type(msg, event->msg_type);
}
+static void set_folder(struct map_msg *msg, const char *folder)
+{
+ if (g_strcmp0(msg->folder, folder) == 0)
+ return;
+
+ g_free(msg->folder);
+ msg->folder = g_strdup(folder);
+
+ g_dbus_emit_property_changed(conn, msg->path, MAP_MSG_INTERFACE,
+ "Folder");
+}
+
static void set_reception_status(struct map_msg *msg, const char *status)
{
if (g_strcmp0(msg->status, status) == 0)
--
1.8.3.4
^ permalink raw reply related
* [PATCH 4/7] obexd: Update Status property in map documentation
From: Christian Fetzer @ 2013-09-24 14:16 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380032167-6440-1-git-send-email-christian.fetzer@oss.bmw-carit.de>
From: Christian Fetzer <christian.fetzer@bmw-carit.de>
For outgoing messages, the status field values are:
"delivery-success", "sending-success", "delivery-failure", "sending-failure"
---
doc/obex-api.txt | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/doc/obex-api.txt b/doc/obex-api.txt
index eda7cb9..c3f5243 100644
--- a/doc/obex-api.txt
+++ b/doc/obex-api.txt
@@ -598,10 +598,14 @@ Methods void SetFolder(string name)
string Status:
- Message reception status
+ Message status
- Possible values: "complete",
- "fractioned" and "notification"
+ Possible values for received messages:
+ "complete", "fractioned", "notification"
+
+ Possible values for sent messages:
+ "delivery-success", "sending-success",
+ "delivery-failure", "sending-failure"
uint64 AttachmentSize:
--
1.8.3.4
^ permalink raw reply related
* [PATCH 3/7] obexd: Handle message status events
From: Christian Fetzer @ 2013-09-24 14:16 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380032167-6440-1-git-send-email-christian.fetzer@oss.bmw-carit.de>
From: Christian Fetzer <christian.fetzer@bmw-carit.de>
For outgoing messages, the message status is changed when an event
indicates that the sending/delivery has failed or succeeded.
---
obexd/client/map.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/obexd/client/map.c b/obexd/client/map.c
index ae7a334..3b0f662 100644
--- a/obexd/client/map.c
+++ b/obexd/client/map.c
@@ -1854,6 +1854,15 @@ static void map_handle_new_message(struct map_data *map,
map_msg_create_from_event(map, event, event->folder);
}
+static void map_handle_status(struct map_data *map, struct map_event *event,
+ const char *status)
+{
+ struct map_msg *msg = g_hash_table_lookup(map->messages, event->handle);
+
+ if (msg)
+ set_reception_status(msg, status);
+}
+
static void map_handle_notification(struct map_event *event, void *user_data)
{
struct map_data *map = user_data;
@@ -1868,6 +1877,18 @@ static void map_handle_notification(struct map_event *event, void *user_data)
case MAP_ET_NEW_MESSAGE:
map_handle_new_message(map, event);
break;
+ case MAP_ET_DELIVERY_SUCCESS:
+ map_handle_status(map, event, "delivery-success");
+ break;
+ case MAP_ET_SENDING_SUCCESS:
+ map_handle_status(map, event, "sending-success");
+ break;
+ case MAP_ET_DELIVERY_FAILURE:
+ map_handle_status(map, event, "delivery-failure");
+ break;
+ case MAP_ET_SENDING_FAILURE:
+ map_handle_status(map, event, "sending-failure");
+ break;
default:
break;
}
--
1.8.3.4
^ permalink raw reply related
* [PATCH 2/7] obexd: Add function set_reception_status to MAP client
From: Christian Fetzer @ 2013-09-24 14:16 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380032167-6440-1-git-send-email-christian.fetzer@oss.bmw-carit.de>
From: Christian Fetzer <christian.fetzer@bmw-carit.de>
The function allows to change the status of a message.
---
obexd/client/map.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/obexd/client/map.c b/obexd/client/map.c
index 74c826e..ae7a334 100644
--- a/obexd/client/map.c
+++ b/obexd/client/map.c
@@ -1830,6 +1830,18 @@ static void map_msg_create_from_event(struct map_data *map,
parse_type(msg, event->msg_type);
}
+static void set_reception_status(struct map_msg *msg, const char *status)
+{
+ if (g_strcmp0(msg->status, status) == 0)
+ return;
+
+ g_free(msg->status);
+ msg->status = g_strdup(status);
+
+ g_dbus_emit_property_changed(conn, msg->path, MAP_MSG_INTERFACE,
+ "Status");
+}
+
static void map_handle_new_message(struct map_data *map,
struct map_event *event)
{
--
1.8.3.4
^ permalink raw reply related
* [PATCH 1/7] obexd: Handle new message event
From: Christian Fetzer @ 2013-09-24 14:16 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380032167-6440-1-git-send-email-christian.fetzer@oss.bmw-carit.de>
From: Christian Fetzer <christian.fetzer@bmw-carit.de>
Register new org.bluez.obex.Message1 D-Bus object when a NewMessage
event report has arrived.
---
obexd/client/map.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/obexd/client/map.c b/obexd/client/map.c
index 45b4ef1..74c826e 100644
--- a/obexd/client/map.c
+++ b/obexd/client/map.c
@@ -1821,6 +1821,27 @@ static void map_msg_remove(void *data)
g_free(path);
}
+static void map_msg_create_from_event(struct map_data *map,
+ struct map_event *event,
+ const char *folder)
+{
+ struct map_msg *msg = map_msg_create(map, event->handle, folder);
+ if (msg)
+ parse_type(msg, event->msg_type);
+}
+
+static void map_handle_new_message(struct map_data *map,
+ struct map_event *event)
+{
+ struct map_msg *msg = g_hash_table_lookup(map->messages, event->handle);
+
+ /* New message event can be used if a new message replaces an old one */
+ if (msg)
+ g_hash_table_remove(map->messages, event->handle);
+
+ map_msg_create_from_event(map, event, event->folder);
+}
+
static void map_handle_notification(struct map_event *event, void *user_data)
{
struct map_data *map = user_data;
@@ -1830,6 +1851,14 @@ static void map_handle_notification(struct map_event *event, void *user_data)
DBG("type=%x, handle=%s, folder=%s, old_folder=%s, msg_type=%s",
event->type, event->handle, event->folder,
event->old_folder, event->msg_type);
+
+ switch (event->type) {
+ case MAP_ET_NEW_MESSAGE:
+ map_handle_new_message(map, event);
+ break;
+ default:
+ break;
+ }
}
static bool set_notification_registration(struct map_data *map, bool status)
--
1.8.3.4
^ permalink raw reply related
* [PATCH 0/7] MAP notification API
From: Christian Fetzer @ 2013-09-24 14:16 UTC (permalink / raw)
To: linux-bluetooth
From: Christian Fetzer <christian.fetzer@bmw-carit.de>
This patchset adds the event handlers for new message, message shift/deleted
and message status update events.
New messages are signaled by registering a corresponding message event, that
is announced using the ObjectManager.
For moved / deleted messages:
- If we have the Message interface, we simply update property 'Folder'.
- If the message was moved into the current folder, we register its
Message interface.
The status update events change the property 'Status'.
Note that this patchset depends on the changed map_msg_create function from
'obexd: Fix setting message folder' sent on 23.09.2013.
Christian Fetzer (7):
obexd: Handle new message event
obexd: Add function set_reception_status to MAP client
obexd: Handle message status events
obexd: Update Status property in map documentation
obexd: Add function set_folder to MAP client
obexd: Handle message shift and message deleted events
obexd: Prefix folders in event reports with leading slash
doc/obex-api.txt | 10 ++++--
obexd/client/map.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
obexd/client/mns.c | 16 +++++++--
3 files changed, 120 insertions(+), 5 deletions(-)
--
1.8.3.4
^ permalink raw reply
* [PATCH 8/8] Bluetooth: Add new mgmt_set_advertising command
From: johan.hedberg @ 2013-09-24 14:02 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380031363-1266-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
This patch adds a new mgmt command for enabling and disabling
LE advertising.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/mgmt.h | 2 +
net/bluetooth/mgmt.c | 99 +++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 100 insertions(+), 1 deletion(-)
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 6cc72b6..421d763 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -352,6 +352,8 @@ struct mgmt_cp_set_device_id {
} __packed;
#define MGMT_SET_DEVICE_ID_SIZE 8
+#define MGMT_OP_SET_ADVERTISING 0x0029
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index d11899d..4f5b0f3 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -76,6 +76,7 @@ static const u16 mgmt_commands[] = {
MGMT_OP_BLOCK_DEVICE,
MGMT_OP_UNBLOCK_DEVICE,
MGMT_OP_SET_DEVICE_ID,
+ MGMT_OP_SET_ADVERTISING,
};
static const u16 mgmt_events[] = {
@@ -1436,7 +1437,8 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
goto unlock;
}
- if (mgmt_pending_find(MGMT_OP_SET_LE, hdev)) {
+ if (mgmt_pending_find(MGMT_OP_SET_LE, hdev) ||
+ mgmt_pending_find(MGMT_OP_SET_ADVERTISING, hdev)) {
err = cmd_status(sk, hdev->id, MGMT_OP_SET_LE,
MGMT_STATUS_BUSY);
goto unlock;
@@ -3141,6 +3143,100 @@ static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data,
return err;
}
+static void set_advertising_complete(struct hci_dev *hdev, u8 status)
+{
+ struct cmd_lookup match = { NULL, hdev };
+
+ if (status) {
+ u8 mgmt_err = mgmt_status(status);
+
+ mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev,
+ cmd_status_rsp, &mgmt_err);
+ return;
+ }
+
+ change_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
+
+ mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, settings_rsp,
+ &match);
+
+ new_settings(hdev, match.sk);
+
+ if (match.sk)
+ sock_put(match.sk);
+}
+
+static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
+{
+ struct mgmt_mode *cp = data;
+ struct pending_cmd *cmd;
+ struct hci_request req;
+ u8 val, enabled;
+ int err;
+
+ BT_DBG("request for %s", hdev->name);
+
+ if (!lmp_le_capable(hdev))
+ return cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING,
+ MGMT_STATUS_NOT_SUPPORTED);
+
+ if (!test_bit(HCI_LE_ENABLED, &hdev->dev_flags))
+ return cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING,
+ MGMT_STATUS_REJECTED);
+
+ if (cp->val != 0x00 && cp->val != 0x01)
+ return cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING,
+ MGMT_STATUS_INVALID_PARAMS);
+
+ hci_dev_lock(hdev);
+
+ val = !!cp->val;
+ enabled = test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
+
+ if (!hdev_is_powered(hdev) || val == enabled) {
+ bool changed = false;
+
+ if (val != test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags)) {
+ change_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
+ changed = true;
+ }
+
+ err = send_settings_rsp(sk, MGMT_OP_SET_ADVERTISING, hdev);
+ if (err < 0)
+ goto unlock;
+
+ if (changed)
+ err = new_settings(hdev, sk);
+
+ goto unlock;
+ }
+
+ if (mgmt_pending_find(MGMT_OP_SET_ADVERTISING, hdev) ||
+ mgmt_pending_find(MGMT_OP_SET_LE, hdev)) {
+ err = cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING,
+ MGMT_STATUS_BUSY);
+ goto unlock;
+ }
+
+ cmd = mgmt_pending_add(sk, MGMT_OP_SET_ADVERTISING, hdev, data, len);
+ if (!cmd) {
+ err = -ENOMEM;
+ goto unlock;
+ }
+
+ hci_req_init(&req, hdev);
+
+ hci_req_add(&req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(val), &val);
+
+ err = hci_req_run(&req, set_advertising_complete);
+ if (err < 0)
+ mgmt_pending_remove(cmd);
+
+unlock:
+ hci_dev_unlock(hdev);
+ return err;
+}
+
static void fast_connectable_complete(struct hci_dev *hdev, u8 status)
{
struct pending_cmd *cmd;
@@ -3352,6 +3448,7 @@ static const struct mgmt_handler {
{ block_device, false, MGMT_BLOCK_DEVICE_SIZE },
{ unblock_device, false, MGMT_UNBLOCK_DEVICE_SIZE },
{ set_device_id, false, MGMT_SET_DEVICE_ID_SIZE },
+ { set_advertising, false, MGMT_SETTING_SIZE },
};
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 7/8] Bluetooth: Add new mgmt setting for LE advertising
From: johan.hedberg @ 2013-09-24 14:02 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380031363-1266-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
This patch adds a new mgmt setting for LE advertising and hooks up the
necessary places in the mgmt code to operate on the HCI_LE_PERIPHERAL
flag (which corresponds to this setting). This patch does not yet add
any new command for enabling the setting - that is left for a subsequent
patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/mgmt.h | 1 +
net/bluetooth/mgmt.c | 24 +++++++++++++++++++++++-
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 9944c3e..6cc72b6 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -93,6 +93,7 @@ struct mgmt_rp_read_index_list {
#define MGMT_SETTING_BREDR 0x00000080
#define MGMT_SETTING_HS 0x00000100
#define MGMT_SETTING_LE 0x00000200
+#define MGMT_SETTING_ADVERTISING 0x00000400
#define MGMT_OP_READ_INFO 0x0004
#define MGMT_READ_INFO_SIZE 0
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index e595b59..d11899d 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -384,8 +384,10 @@ static u32 get_supported_settings(struct hci_dev *hdev)
if (enable_hs)
settings |= MGMT_SETTING_HS;
- if (lmp_le_capable(hdev))
+ if (lmp_le_capable(hdev)) {
settings |= MGMT_SETTING_LE;
+ settings |= MGMT_SETTING_ADVERTISING;
+ }
return settings;
}
@@ -424,6 +426,9 @@ static u32 get_current_settings(struct hci_dev *hdev)
if (test_bit(HCI_HS_ENABLED, &hdev->dev_flags))
settings |= MGMT_SETTING_HS;
+ if (test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags))
+ settings |= MGMT_SETTING_ADVERTISING;
+
return settings;
}
@@ -1368,6 +1373,9 @@ static void le_enable_complete(struct hci_dev *hdev, u8 status)
change_bit(HCI_LE_ENABLED, &hdev->dev_flags);
+ if (!test_bit(HCI_LE_ENABLED, &hdev->dev_flags))
+ clear_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
+
mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match);
new_settings(hdev, match.sk);
@@ -1413,6 +1421,11 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
changed = true;
}
+ if (!val && test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags)) {
+ clear_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
+ changed = true;
+ }
+
err = send_settings_rsp(sk, MGMT_OP_SET_LE, hdev);
if (err < 0)
goto unlock;
@@ -1444,6 +1457,9 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
hci_req_init(&req, hdev);
+ if (test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags) && !val)
+ hci_req_add(&req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(val), &val);
+
hci_req_add(&req, HCI_OP_WRITE_LE_HOST_SUPPORTED, sizeof(hci_cp),
&hci_cp);
@@ -3519,6 +3535,12 @@ static int powered_update_hci(struct hci_dev *hdev)
sizeof(cp), &cp);
}
+ if (test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags)) {
+ u8 adv = 0x01;
+
+ hci_req_add(&req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(adv), &adv);
+ }
+
link_sec = test_bit(HCI_LINK_SECURITY, &hdev->dev_flags);
if (link_sec != test_bit(HCI_AUTH, &hdev->flags))
hci_req_add(&req, HCI_OP_WRITE_AUTH_ENABLE,
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 6/8] Bluetooth: Use async request for LE enable/disable
From: johan.hedberg @ 2013-09-24 14:02 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380031363-1266-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
This patch updates the code to use an asynchronous request for handling
the enabling and disabling of LE support. This refactoring is necessary
as a preparation for adding advertising support, since when LE is
disabled we should also disable advertising, and the cleanest way to do
this is to perform the two respective HCI commands in the same
asynchronous request.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/hci_core.h | 1 -
net/bluetooth/hci_event.c | 11 -------
net/bluetooth/mgmt.c | 69 +++++++++++++++++-----------------------
3 files changed, 29 insertions(+), 52 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 3ede820..26cc9f7 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1168,7 +1168,6 @@ int mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
u8 *randomizer, u8 status);
-int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name,
u8 ssp, u8 *eir, u16 eir_len);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 94aab73..835a384 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -911,13 +911,6 @@ static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb)
hci_dev_lock(hdev);
- if (!status) {
- if (*sent)
- set_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
- else
- clear_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
- }
-
if (!test_bit(HCI_INIT, &hdev->flags)) {
struct hci_request req;
@@ -1004,10 +997,6 @@ static void hci_cc_write_le_host_supported(struct hci_dev *hdev,
else
hdev->features[1][0] &= ~LMP_HOST_LE_BREDR;
}
-
- if (test_bit(HCI_MGMT, &hdev->dev_flags) &&
- !test_bit(HCI_INIT, &hdev->flags))
- mgmt_le_enable_complete(hdev, sent->le, status);
}
static void hci_cc_write_remote_amp_assoc(struct hci_dev *hdev,
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 47f4c07..e595b59 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1354,11 +1354,34 @@ static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
return send_settings_rsp(sk, MGMT_OP_SET_HS, hdev);
}
+static void le_enable_complete(struct hci_dev *hdev, u8 status)
+{
+ struct cmd_lookup match = { NULL, hdev };
+
+ if (status) {
+ u8 mgmt_err = mgmt_status(status);
+
+ mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, cmd_status_rsp,
+ &mgmt_err);
+ return;
+ }
+
+ change_bit(HCI_LE_ENABLED, &hdev->dev_flags);
+
+ mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match);
+
+ new_settings(hdev, match.sk);
+
+ if (match.sk)
+ sock_put(match.sk);
+}
+
static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
{
struct mgmt_mode *cp = data;
struct hci_cp_write_le_host_supported hci_cp;
struct pending_cmd *cmd;
+ struct hci_request req;
int err;
u8 val, enabled;
@@ -1419,8 +1442,12 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
hci_cp.simul = lmp_le_br_capable(hdev);
}
- err = hci_send_cmd(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, sizeof(hci_cp),
- &hci_cp);
+ hci_req_init(&req, hdev);
+
+ hci_req_add(&req, HCI_OP_WRITE_LE_HOST_SUPPORTED, sizeof(hci_cp),
+ &hci_cp);
+
+ err = hci_req_run(&req, le_enable_complete);
if (err < 0)
mgmt_pending_remove(cmd);
@@ -4141,44 +4168,6 @@ int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
return err;
}
-int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status)
-{
- struct cmd_lookup match = { NULL, hdev };
- bool changed = false;
- int err = 0;
-
- if (status) {
- u8 mgmt_err = mgmt_status(status);
-
- if (enable && test_and_clear_bit(HCI_LE_ENABLED,
- &hdev->dev_flags))
- err = new_settings(hdev, NULL);
-
- mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, cmd_status_rsp,
- &mgmt_err);
-
- return err;
- }
-
- if (enable) {
- if (!test_and_set_bit(HCI_LE_ENABLED, &hdev->dev_flags))
- changed = true;
- } else {
- if (test_and_clear_bit(HCI_LE_ENABLED, &hdev->dev_flags))
- changed = true;
- }
-
- mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match);
-
- if (changed)
- err = new_settings(hdev, match.sk);
-
- if (match.sk)
- sock_put(match.sk);
-
- return err;
-}
-
int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name, u8
ssp, u8 *eir, u16 eir_len)
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 5/8] Bluetooth: Move mgmt response convenience functions to a better location
From: johan.hedberg @ 2013-09-24 14:02 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380031363-1266-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
The settings_rsp and cmd_status_rsp functions can be useful for all mgmt
command handlers when asynchronous request callbacks are used. They will
e.g. be used by subsequent patches to change set_le to use an async
request as well as a new set_advertising command. Therefore, move them
higher up in the mgmt.c file to avoid unnecessary forward declarations
or mixing this trivial change with other patches.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/mgmt.c | 60 ++++++++++++++++++++++++++--------------------------
1 file changed, 30 insertions(+), 30 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 2a91346..47f4c07 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -886,6 +886,36 @@ static int new_settings(struct hci_dev *hdev, struct sock *skip)
return mgmt_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, sizeof(ev), skip);
}
+struct cmd_lookup {
+ struct sock *sk;
+ struct hci_dev *hdev;
+ u8 mgmt_status;
+};
+
+static void settings_rsp(struct pending_cmd *cmd, void *data)
+{
+ struct cmd_lookup *match = data;
+
+ send_settings_rsp(cmd->sk, cmd->opcode, match->hdev);
+
+ list_del(&cmd->list);
+
+ if (match->sk == NULL) {
+ match->sk = cmd->sk;
+ sock_hold(match->sk);
+ }
+
+ mgmt_pending_free(cmd);
+}
+
+static void cmd_status_rsp(struct pending_cmd *cmd, void *data)
+{
+ u8 *status = data;
+
+ cmd_status(cmd->sk, cmd->index, cmd->opcode, *status);
+ mgmt_pending_remove(cmd);
+}
+
static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data,
u16 len)
{
@@ -3374,14 +3404,6 @@ done:
return err;
}
-static void cmd_status_rsp(struct pending_cmd *cmd, void *data)
-{
- u8 *status = data;
-
- cmd_status(cmd->sk, cmd->index, cmd->opcode, *status);
- mgmt_pending_remove(cmd);
-}
-
int mgmt_index_added(struct hci_dev *hdev)
{
if (!mgmt_valid_hdev(hdev))
@@ -3402,28 +3424,6 @@ int mgmt_index_removed(struct hci_dev *hdev)
return mgmt_event(MGMT_EV_INDEX_REMOVED, hdev, NULL, 0, NULL);
}
-struct cmd_lookup {
- struct sock *sk;
- struct hci_dev *hdev;
- u8 mgmt_status;
-};
-
-static void settings_rsp(struct pending_cmd *cmd, void *data)
-{
- struct cmd_lookup *match = data;
-
- send_settings_rsp(cmd->sk, cmd->opcode, match->hdev);
-
- list_del(&cmd->list);
-
- if (match->sk == NULL) {
- match->sk = cmd->sk;
- sock_hold(match->sk);
- }
-
- mgmt_pending_free(cmd);
-}
-
static void set_bredr_scan(struct hci_request *req)
{
struct hci_dev *hdev = req->hdev;
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 4/8] Bluetooth: Fix busy return for mgmt_set_powered in some cases
From: johan.hedberg @ 2013-09-24 14:02 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380031363-1266-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
We should return a "busy" error always when there is another
mgmt_set_powered operation in progress. Previously when powering on
while the auto off timer was still set the code could have let two or
more pending power on commands to be queued. This patch fixes the issue
by moving the check for duplicate commands to an earlier point in the
set_powered handler.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/mgmt.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 5319a94..2a91346 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -807,6 +807,12 @@ static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data,
hci_dev_lock(hdev);
+ if (mgmt_pending_find(MGMT_OP_SET_POWERED, hdev)) {
+ err = cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED,
+ MGMT_STATUS_BUSY);
+ goto failed;
+ }
+
if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->dev_flags)) {
cancel_delayed_work(&hdev->power_off);
@@ -823,12 +829,6 @@ static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data,
goto failed;
}
- if (mgmt_pending_find(MGMT_OP_SET_POWERED, hdev)) {
- err = cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED,
- MGMT_STATUS_BUSY);
- goto failed;
- }
-
cmd = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, hdev, data, len);
if (!cmd) {
err = -ENOMEM;
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 3/8] Bluetooth: Test for HCI_SETUP and HCI_USER_CHANNEL in mgmt_valid_hdev()
From: johan.hedberg @ 2013-09-24 14:02 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380031363-1266-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
If either one of the HCI_SETUP or HCI_USER_CHANNEL flags is set the
device is not considered valid for mgmt. By having these checks inside
the mgmt_valid_hdev function the a couple of places using it can be
simplified.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/hci_core.c | 4 +---
net/bluetooth/mgmt.c | 12 ++++++------
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 3d9f02b..1940147 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1238,9 +1238,7 @@ int hci_dev_open(__u16 dev)
hci_dev_hold(hdev);
set_bit(HCI_UP, &hdev->flags);
hci_notify(hdev, HCI_DEV_UP);
- if (!test_bit(HCI_SETUP, &hdev->dev_flags) &&
- !test_bit(HCI_USER_CHANNEL, &hdev->dev_flags) &&
- mgmt_valid_hdev(hdev)) {
+ if (mgmt_valid_hdev(hdev)) {
hci_dev_lock(hdev);
mgmt_powered(hdev, 1);
hci_dev_unlock(hdev);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 3070e77..5319a94 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -183,6 +183,12 @@ static u8 mgmt_status_table[] = {
bool mgmt_valid_hdev(struct hci_dev *hdev)
{
+ if (test_bit(HCI_SETUP, &hdev->dev_flags))
+ return false;
+
+ if (test_bit(HCI_USER_CHANNEL, &hdev->dev_flags))
+ return false;
+
return hdev->dev_type == HCI_BREDR;
}
@@ -336,12 +342,6 @@ static int read_index_list(struct sock *sk, struct hci_dev *hdev, void *data,
count = 0;
list_for_each_entry(d, &hci_dev_list, list) {
- if (test_bit(HCI_SETUP, &d->dev_flags))
- continue;
-
- if (test_bit(HCI_USER_CHANNEL, &d->dev_flags))
- continue;
-
if (!mgmt_valid_hdev(d))
continue;
--
1.8.4.rc3
^ permalink raw reply related
* [PATCH 2/8] Bluetooth: Clean up socket locking in l2cap_sock_recvmsg
From: johan.hedberg @ 2013-09-24 14:02 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1380031363-1266-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
This patch cleans up the locking login in l2cap_sock_recvmsg by pairing
up each lock_sock call with a release_sock call. The function already
has a "done" label that handles releasing the socket and returning from
the function so the fix is rather simple.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/l2cap_sock.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index ad95b42..5853c1e 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -795,7 +795,7 @@ static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
{
struct sock *sk = sock->sk;
struct l2cap_pinfo *pi = l2cap_pi(sk);
- int err;
+ int err = 0;
lock_sock(sk);
@@ -805,8 +805,7 @@ static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
pi->chan->state = BT_CONFIG;
__l2cap_connect_rsp_defer(pi->chan);
- release_sock(sk);
- return 0;
+ goto done;
}
release_sock(sk);
--
1.8.4.rc3
^ 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