* Re: [PATCHv2 4/6] android: Add adapter and device struct for BlueZ daemon
From: Johan Hedberg @ 2013-10-16 10:31 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1381913215-17957-5-git-send-email-Andrei.Emeltchenko.news@gmail.com>
On Wed, Oct 16, 2013, Andrei Emeltchenko wrote:
> +struct bt_adapter {
> + struct mgmt *mgmt;
> + bdaddr_t bdaddr;
> + uint32_t dev_class;
> +
> + char *name;
> +
> + uint32_t supported_settings;
> + uint32_t current_settings;
> +
> + GList *found_devices;
> +};
Please don't add variables this way if you don't have code that actually
uses them at least later in the patch set. Just add them when they
eventually are needed.
> +struct bt_device {
> + bdaddr_t bdaddr;
> + uint8_t bdaddr_type;
> + uint32_t cod;
> + char *name;
> +};
Same thing here.
Johan
^ permalink raw reply
* [PATCH] Bluetooth: Expose inquiry_cache debugfs only on BR/EDR controllers
From: Marcel Holtmann @ 2013-10-16 10:28 UTC (permalink / raw)
To: linux-bluetooth
The inquiry_cache debugfs entry is only valid for BR/EDR capable
controllers. In case of single mode LE-only controllers that
entry is not valid.
Move the creating of the debugfs entries to the end of controller
init and only create the inquiry_cache entry if BR/EDR is actually
supported.
At the same time this avoids creating any debugfs entries for
AMP controllers since none of the entries are valid there.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
net/bluetooth/hci_core.c | 57 +++++++++++++++++++++++++++++++++++++++++++++--
net/bluetooth/hci_sysfs.c | 39 --------------------------------
2 files changed, 55 insertions(+), 41 deletions(-)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 2af0bac..73c8def 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -27,8 +27,8 @@
#include <linux/export.h>
#include <linux/idr.h>
-
#include <linux/rfkill.h>
+#include <linux/debugfs.h>
#include <net/bluetooth/bluetooth.h>
#include <net/bluetooth/hci_core.h>
@@ -55,6 +55,44 @@ static void hci_notify(struct hci_dev *hdev, int event)
hci_sock_dev_event(hdev, event);
}
+/* ---- HCI debugfs entries ---- */
+
+static int inquiry_cache_show(struct seq_file *f, void *p)
+{
+ struct hci_dev *hdev = f->private;
+ struct discovery_state *cache = &hdev->discovery;
+ struct inquiry_entry *e;
+
+ hci_dev_lock(hdev);
+
+ list_for_each_entry(e, &cache->all, all) {
+ struct inquiry_data *data = &e->data;
+ seq_printf(f, "%pMR %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
+ &data->bdaddr,
+ data->pscan_rep_mode, data->pscan_period_mode,
+ data->pscan_mode, data->dev_class[2],
+ data->dev_class[1], data->dev_class[0],
+ __le16_to_cpu(data->clock_offset),
+ data->rssi, data->ssp_mode, e->timestamp);
+ }
+
+ hci_dev_unlock(hdev);
+
+ return 0;
+}
+
+static int inquiry_cache_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, inquiry_cache_show, inode->i_private);
+}
+
+static const struct file_operations inquiry_cache_fops = {
+ .open = inquiry_cache_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
/* ---- HCI requests ---- */
static void hci_req_sync_complete(struct hci_dev *hdev, u8 result)
@@ -734,7 +772,22 @@ static int __hci_init(struct hci_dev *hdev)
if (err < 0)
return err;
- return __hci_req_sync(hdev, hci_init4_req, 0, HCI_INIT_TIMEOUT);
+ err = __hci_req_sync(hdev, hci_init4_req, 0, HCI_INIT_TIMEOUT);
+ if (err < 0)
+ return err;
+
+ /* Only create debugfs entries during the initial setup
+ * phase and not every time the controller gets powered on.
+ */
+ if (!test_bit(HCI_SETUP, &hdev->dev_flags))
+ return 0;
+
+ if (lmp_bredr_capable(hdev)) {
+ debugfs_create_file("inquiry_cache", 0444, hdev->debugfs,
+ hdev, &inquiry_cache_fops);
+ }
+
+ return 0;
}
static void hci_scan_req(struct hci_request *req, unsigned long opt)
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index edf623a..65ecb9e 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -396,42 +396,6 @@ static struct device_type bt_host = {
.release = bt_host_release,
};
-static int inquiry_cache_show(struct seq_file *f, void *p)
-{
- struct hci_dev *hdev = f->private;
- struct discovery_state *cache = &hdev->discovery;
- struct inquiry_entry *e;
-
- hci_dev_lock(hdev);
-
- list_for_each_entry(e, &cache->all, all) {
- struct inquiry_data *data = &e->data;
- seq_printf(f, "%pMR %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
- &data->bdaddr,
- data->pscan_rep_mode, data->pscan_period_mode,
- data->pscan_mode, data->dev_class[2],
- data->dev_class[1], data->dev_class[0],
- __le16_to_cpu(data->clock_offset),
- data->rssi, data->ssp_mode, e->timestamp);
- }
-
- hci_dev_unlock(hdev);
-
- return 0;
-}
-
-static int inquiry_cache_open(struct inode *inode, struct file *file)
-{
- return single_open(file, inquiry_cache_show, inode->i_private);
-}
-
-static const struct file_operations inquiry_cache_fops = {
- .open = inquiry_cache_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
-
static int blacklist_show(struct seq_file *f, void *p)
{
struct hci_dev *hdev = f->private;
@@ -562,9 +526,6 @@ int hci_add_sysfs(struct hci_dev *hdev)
if (!hdev->debugfs)
return 0;
- debugfs_create_file("inquiry_cache", 0444, hdev->debugfs,
- hdev, &inquiry_cache_fops);
-
debugfs_create_file("blacklist", 0444, hdev->debugfs,
hdev, &blacklist_fops);
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCHv2 3/6] android: Add basic mgmt initialization sequence
From: Johan Hedberg @ 2013-10-16 10:28 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1381913215-17957-4-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Wed, Oct 16, 2013, Andrei Emeltchenko wrote:
> +static void read_index_list_complete(uint8_t status, uint16_t length,
> + const void *param, void *user_data)
> +{
> + const struct mgmt_rp_read_index_list *rp = param;
> + uint16_t num;
> + int i;
> +
> + info(__func__);
Seems like this one should just be a DBG("") (or just remove it
completely).
> + num = btohs(rp->num_controllers);
> +
> + DBG("%s: Number of controllers: %u", __func__, num);
Again, the __func__ seems redundant since this is a DBG() call.
Johan
^ permalink raw reply
* Re: [PATCHv2 2/6] android: Create HAL API header skeleton
From: Johan Hedberg @ 2013-10-16 10:23 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1381913215-17957-3-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Wed, Oct 16, 2013, Andrei Emeltchenko wrote:
> Header describes the protocol between Android HAL threads and BlueZ
> daemon.
> ---
> android/hal-msg.h | 246 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 246 insertions(+)
> create mode 100644 android/hal-msg.h
Where's the code/patch that adds this to "make dist"?
Johan
^ permalink raw reply
* Re: [PATCHv2 1/6] sdp: Check that correct packet received in recv
From: Johan Hedberg @ 2013-10-16 10:21 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1381913215-17957-2-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Wed, Oct 16, 2013, Andrei Emeltchenko wrote:
> ---
> unit/test-sdp.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
This patch has been applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH] Bluetooth: Remove enable_hs declaration
From: Johan Hedberg @ 2013-10-16 9:29 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1381914541-48086-1-git-send-email-marcel@holtmann.org>
Hi Marcel,
On Wed, Oct 16, 2013, Marcel Holtmann wrote:
> This seems to be a left-over. The module parameter enable_hs has
> been removed, but its extern declaration is still present. It is
> not needed anymore, so just remove it.
>
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
> include/net/bluetooth/hci.h | 2 --
> 1 file changed, 2 deletions(-)
Applied to bluetooth-next. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH 1/2] Bluetooth: Ignore A2MP data on non-BR/EDR links
From: Marcel Holtmann @ 2013-10-16 9:10 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: johan.hedberg, linux-bluetooth
In-Reply-To: <20131016085445.GL2861@aemeltch-MOBL1>
Hi Andrei,
>> The A2MP CID is only valid for BR/EDR transports. We should ignore A2MP
>> data on non-BR/EDR links and refuse to create an amp_mgr object.
>>
>> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
>> ---
>> net/bluetooth/a2mp.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c
>> index fe32a33..efcd108 100644
>> --- a/net/bluetooth/a2mp.c
>> +++ b/net/bluetooth/a2mp.c
>> @@ -836,6 +836,9 @@ struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn,
>> {
>> struct amp_mgr *mgr;
>>
>> + if (conn->hcon->type != ACL_LINK)
>> + return NULL;
>> +
>
> Have you experienced this ever happened?
this is how good software is written. You check that your input is valid first. Otherwise you open yourself up to vulnerabilities.
Regards
Marcel
^ permalink raw reply
* [PATCH] Bluetooth: Remove enable_hs declaration
From: Marcel Holtmann @ 2013-10-16 9:09 UTC (permalink / raw)
To: linux-bluetooth
This seems to be a left-over. The module parameter enable_hs has
been removed, but its extern declaration is still present. It is
not needed anymore, so just remove it.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
include/net/bluetooth/hci.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index c8bc7bf..77a971a 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -1787,6 +1787,4 @@ struct hci_inquiry_req {
};
#define IREQ_CACHE_FLUSH 0x0001
-extern bool enable_hs;
-
#endif /* __HCI_H */
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCH 1/2] Bluetooth: Ignore A2MP data on non-BR/EDR links
From: Andrei Emeltchenko @ 2013-10-16 8:54 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
In-Reply-To: <1381912621-10238-1-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
On Wed, Oct 16, 2013 at 11:37:00AM +0300, johan.hedberg@gmail.com wrote:
> From: Johan Hedberg <johan.hedberg@intel.com>
>
> The A2MP CID is only valid for BR/EDR transports. We should ignore A2MP
> data on non-BR/EDR links and refuse to create an amp_mgr object.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/a2mp.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c
> index fe32a33..efcd108 100644
> --- a/net/bluetooth/a2mp.c
> +++ b/net/bluetooth/a2mp.c
> @@ -836,6 +836,9 @@ struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn,
> {
> struct amp_mgr *mgr;
>
> + if (conn->hcon->type != ACL_LINK)
> + return NULL;
> +
Have you experienced this ever happened?
Best regards
Andrei Emeltchenko
^ permalink raw reply
* [PATCHv2 6/6] android: Add cap to bind to port < 1024
From: Andrei Emeltchenko @ 2013-10-16 8:46 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1381913215-17957-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
For SDP server we need to bind to lower port, acquire this capability.
---
android/main.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 4 ++++
2 files changed, 75 insertions(+)
diff --git a/android/main.c b/android/main.c
index 2b8675d..19d382a 100644
--- a/android/main.c
+++ b/android/main.c
@@ -32,6 +32,22 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/prctl.h>
+#include <linux/capability.h>
+
+/**
+ * Include <sys/capability.h> for host build and
+ * also for Android 4.3 when it is added to bionic
+ */
+#if !defined(ANDROID) || (PLATFORM_SDK_VERSION > 17)
+#include <sys/capability.h>
+#endif
+
+#if defined(ANDROID)
+#include <private/android_filesystem_config.h>
+#endif
#include <glib.h>
@@ -232,6 +248,58 @@ static void cleanup_mgmt_interface(void)
mgmt_if = NULL;
}
+static bool set_capabilities(void)
+{
+ struct __user_cap_header_struct header;
+ struct __user_cap_data_struct cap;
+#if defined(ANDROID)
+ gid_t groups[] = {AID_NET_BT, AID_NET_BT_ADMIN, AID_NET_ADMIN};
+#endif
+
+ DBG("pid %d uid %d gid %d", getpid(), getuid(), getgid());
+
+ header.version = _LINUX_CAPABILITY_VERSION;
+
+ prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
+
+#if defined(ANDROID)
+ if (setgid(AID_BLUETOOTH) < 0)
+ warn("%s: setgid(): %s", __func__, strerror(errno));
+
+ if (setuid(AID_BLUETOOTH) < 0)
+ warn("%s: setuid(): %s", __func__, strerror(errno));
+#endif
+
+ header.version = _LINUX_CAPABILITY_VERSION;
+ header.pid = 0;
+
+ cap.effective = cap.permitted =
+ CAP_TO_MASK(CAP_SETGID) |
+ CAP_TO_MASK(CAP_NET_RAW) |
+ CAP_TO_MASK(CAP_NET_ADMIN) |
+ CAP_TO_MASK(CAP_NET_BIND_SERVICE);
+ cap.inheritable = 0;
+
+ if (capset(&header, &cap) < 0) {
+ error("%s: capset(): %s", __func__, strerror(errno));
+ return false;
+ }
+
+#if defined(ANDROID)
+ if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) < 0)
+ warn("%s: setgroups: %s", __func__, strerror(errno));
+#endif
+ if (capget(&header, &cap) < 0)
+ error("%s: capget(): %s", __func__, strerror(errno));
+ else
+ DBG("Caps: eff: 0x%x, perm: 0x%x, inh: 0x%x", cap.effective,
+ cap.permitted, cap.inheritable);
+
+ DBG("pid %d uid %d gid %d", getpid(), getuid(), getgid());
+
+ return true;
+}
+
int main(int argc, char *argv[])
{
GOptionContext *context;
@@ -265,6 +333,9 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
+ if (!set_capabilities())
+ return EXIT_FAILURE;
+
if (!init_mgmt_interface())
return EXIT_FAILURE;
diff --git a/configure.ac b/configure.ac
index 7b1f64a..a14264f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -247,4 +247,8 @@ AC_ARG_ENABLE(android, AC_HELP_STRING([--enable-android],
[enable_android=${enableval}])
AM_CONDITIONAL(ANDROID, test "${enable_android}" = "yes")
+if (test "${enable_android}" = "yes"); then
+ AC_CHECK_LIB(cap, capget, dummy=yes, AC_MSG_ERROR(libcap is required))
+fi
+
AC_OUTPUT(Makefile src/bluetoothd.8 lib/bluez.pc)
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 5/6] android: sdp: Reuse BlueZ SDP server in Android
From: Andrei Emeltchenko @ 2013-10-16 8:46 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1381913215-17957-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Reuse existing SDP server code in Android GPL daemon.
---
Makefile.android | 4 +++-
android/Android.mk | 8 ++++++++
android/main.c | 5 +++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/Makefile.android b/Makefile.android
index 7371a77..48af2e2 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -2,9 +2,11 @@ if ANDROID
noinst_PROGRAMS += android/bluetoothd
android_bluetoothd_SOURCES = android/main.c src/log.c \
+ src/sdpd-database.c src/sdpd-server.c \
+ src/sdpd-service.c src/sdpd-request.c \
src/shared/util.h src/shared/util.c \
src/shared/mgmt.h src/shared/mgmt.c
-android_bluetoothd_LDADD = @GLIB_LIBS@
+android_bluetoothd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
endif
EXTRA_DIST += android/Android.mk android/log.c
diff --git a/android/Android.mk b/android/Android.mk
index 4996080..560fb0a 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -17,6 +17,13 @@ LOCAL_SRC_FILES := \
log.c \
../src/shared/mgmt.c \
../src/shared/util.c \
+ ../src/sdpd-database.c \
+ ../src/sdpd-service.c \
+ ../src/sdpd-request.c \
+ ../src/sdpd-server.c \
+ ../lib/sdp.c \
+ ../lib/bluetooth.c \
+ ../lib/hci.c \
LOCAL_C_INCLUDES := \
$(call include-path-for, glib) \
@@ -25,6 +32,7 @@ LOCAL_C_INCLUDES := \
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../src \
+ $(LOCAL_PATH)/../lib \
LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"
diff --git a/android/main.c b/android/main.c
index ba25b84..2b8675d 100644
--- a/android/main.c
+++ b/android/main.c
@@ -36,6 +36,7 @@
#include <glib.h>
#include "log.h"
+#include "sdpd.h"
#include "lib/bluetooth.h"
#include "lib/mgmt.h"
@@ -267,10 +268,14 @@ int main(int argc, char *argv[])
if (!init_mgmt_interface())
return EXIT_FAILURE;
+ /* Use params: mtu = 0, flags = 0 */
+ start_sdp_server(0, 0);
+
DBG("Entering main loop");
g_main_loop_run(event_loop);
+ stop_sdp_server();
cleanup_mgmt_interface();
g_main_loop_unref(event_loop);
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 4/6] android: Add adapter and device struct for BlueZ daemon
From: Andrei Emeltchenko @ 2013-10-16 8:46 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1381913215-17957-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Adapter structure in BlueZ daemon keeps track of default adapter
and device structure keeps track about found devices.
---
android/adapter.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
android/adapter.h | 36 ++++++++++++++++++++++++++++++
android/device.c | 29 ++++++++++++++++++++++++
android/device.h | 24 ++++++++++++++++++++
4 files changed, 152 insertions(+)
create mode 100644 android/adapter.c
create mode 100644 android/adapter.h
create mode 100644 android/device.c
create mode 100644 android/device.h
diff --git a/android/adapter.c b/android/adapter.c
new file mode 100644
index 0000000..b97a7c7
--- /dev/null
+++ b/android/adapter.c
@@ -0,0 +1,63 @@
+/*
+ *
+ * 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
+ *
+ */
+
+#include "src/shared/mgmt.h"
+#include "log.h"
+#include "adapter.h"
+
+struct bt_adapter {
+ struct mgmt *mgmt;
+ bdaddr_t bdaddr;
+ uint32_t dev_class;
+
+ char *name;
+
+ uint32_t supported_settings;
+ uint32_t current_settings;
+
+ GList *found_devices;
+};
+
+struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if)
+{
+ struct bt_adapter *adapter;
+
+ adapter = g_new0(struct bt_adapter, 1);
+
+ adapter->mgmt = mgmt_ref(mgmt_if);
+
+ return adapter;
+}
+
+void bt_adapter_start(struct bt_adapter *adapter)
+{
+ DBG("");
+
+ /* TODO: CB: report scan mode */
+ /* TODO: CB: report state on */
+}
+
+void bt_adapter_stop(struct bt_adapter *adapter)
+{
+ DBG("");
+}
diff --git a/android/adapter.h b/android/adapter.h
new file mode 100644
index 0000000..0f1445a
--- /dev/null
+++ b/android/adapter.h
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <glib.h>
+
+#include "lib/bluetooth.h"
+
+struct bt_adapter;
+
+struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if);
+
+void bt_adapter_start(struct bt_adapter *adapter);
+void bt_adapter_stop(struct bt_adapter *adapter);
diff --git a/android/device.c b/android/device.c
new file mode 100644
index 0000000..224a317
--- /dev/null
+++ b/android/device.c
@@ -0,0 +1,29 @@
+/*
+ *
+ * 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
+ *
+ */
+
+struct bt_device {
+ bdaddr_t bdaddr;
+ uint8_t bdaddr_type;
+ uint32_t cod;
+ char *name;
+};
diff --git a/android/device.h b/android/device.h
new file mode 100644
index 0000000..f5b1da6
--- /dev/null
+++ b/android/device.h
@@ -0,0 +1,24 @@
+/*
+ *
+ * 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
+ *
+ */
+
+struct bt_device;
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 3/6] android: Add basic mgmt initialization sequence
From: Andrei Emeltchenko @ 2013-10-16 8:46 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1381913215-17957-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Initialize bluetooth controller via mgmt interface.
---
Makefile.android | 4 +-
android/Android.mk | 5 ++
android/main.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 176 insertions(+), 1 deletion(-)
diff --git a/Makefile.android b/Makefile.android
index 3ceefd8..7371a77 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -1,7 +1,9 @@
if ANDROID
noinst_PROGRAMS += android/bluetoothd
-android_bluetoothd_SOURCES = android/main.c src/log.c
+android_bluetoothd_SOURCES = android/main.c src/log.c \
+ src/shared/util.h src/shared/util.c \
+ src/shared/mgmt.h src/shared/mgmt.c
android_bluetoothd_LDADD = @GLIB_LIBS@
endif
diff --git a/android/Android.mk b/android/Android.mk
index 0e025ac..4996080 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -15,10 +15,15 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
main.c \
log.c \
+ ../src/shared/mgmt.c \
+ ../src/shared/util.c \
LOCAL_C_INCLUDES := \
$(call include-path-for, glib) \
$(call include-path-for, glib)/glib \
+
+LOCAL_C_INCLUDES += \
+ $(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../src \
LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"
diff --git a/android/main.c b/android/main.c
index f75b0a8..ba25b84 100644
--- a/android/main.c
+++ b/android/main.c
@@ -25,6 +25,7 @@
#include <config.h>
#endif
+#include <stdbool.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
@@ -36,9 +37,17 @@
#include "log.h"
+#include "lib/bluetooth.h"
+#include "lib/mgmt.h"
+#include "src/shared/mgmt.h"
+
#define SHUTDOWN_GRACE_SECONDS 10
static GMainLoop *event_loop;
+static struct mgmt *mgmt_if = NULL;
+
+static uint8_t mgmt_version = 0;
+static uint8_t mgmt_revision = 0;
static gboolean quit_eventloop(gpointer user_data)
{
@@ -67,6 +76,161 @@ static GOptionEntry options[] = {
{ NULL }
};
+static void read_info_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ /* TODO: Store Controller information */
+
+ /* TODO: Register all event notification handlers */
+}
+
+
+static void mgmt_index_added_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("index %u", index);
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
+ read_info_complete, NULL, NULL) > 0)
+ return;
+
+ error("Failed to read adapter info for index %u", index);
+
+}
+
+static void mgmt_index_removed_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("index %u", index);
+}
+
+static void read_index_list_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_index_list *rp = param;
+ uint16_t num;
+ int i;
+
+ info(__func__);
+
+ if (!status) {
+ error("%s: Failed to read index list: %s (0x%02x)",
+ __func__, mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("%s: Wrong size of read index list response", __func__);
+ return;
+ }
+
+ num = btohs(rp->num_controllers);
+
+ DBG("%s: Number of controllers: %u", __func__, num);
+
+ if (num * sizeof(uint16_t) + sizeof(*rp) != length) {
+ error("%s: Incorrect pkt size for index list rsp", __func__);
+ return;
+ }
+
+ for (i = 0; i < num; i++) {
+ uint16_t index;
+
+ index = btohs(rp->index[i]);
+
+ /**
+ * Use index added event notification.
+ */
+ mgmt_index_added_event(index, 0, NULL, NULL);
+ }
+}
+
+static void read_commands_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_commands *rp = param;
+
+ DBG("");
+
+ if (!status) {
+ error("Failed to read supported commands: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("Wrong size response");
+ return;
+ }
+}
+
+static void read_version_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_version *rp = param;
+
+ DBG("");
+
+ if (!status) {
+ error("Failed to read version information: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("Wrong size response");
+ return;
+ }
+
+ mgmt_version = rp->version;
+ mgmt_revision = btohs(rp->revision);
+
+ info("Bluetooth management interface %u.%u initialized",
+ mgmt_version, mgmt_revision);
+
+ if (mgmt_version < 1) {
+ error("Version 1.0 or later of management interface required");
+ abort();
+ }
+
+ mgmt_send(mgmt_if, MGMT_OP_READ_COMMANDS, MGMT_INDEX_NONE, 0, NULL,
+ read_commands_complete, NULL, NULL);
+
+ mgmt_register(mgmt_if, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE,
+ mgmt_index_added_event, NULL, NULL);
+ mgmt_register(mgmt_if, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE,
+ mgmt_index_removed_event, NULL, NULL);
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0,
+ NULL, read_index_list_complete, NULL, NULL) > 0)
+ return;
+
+ error("Failed to read controller index list");
+}
+
+static bool init_mgmt_interface(void)
+{
+ mgmt_if = mgmt_new_default();
+ if (!mgmt_if) {
+ error("Failed to access management interface");
+ return false;
+ }
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_VERSION, MGMT_INDEX_NONE, 0, NULL,
+ read_version_complete, NULL, NULL) == 0) {
+ error("Error sending READ_VERSION mgmt command");
+ return false;
+ }
+
+ return true;
+}
+
+static void cleanup_mgmt_interface(void)
+{
+ mgmt_unref(mgmt_if);
+ mgmt_if = NULL;
+}
+
int main(int argc, char *argv[])
{
GOptionContext *context;
@@ -100,10 +264,14 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
+ if (!init_mgmt_interface())
+ return EXIT_FAILURE;
+
DBG("Entering main loop");
g_main_loop_run(event_loop);
+ cleanup_mgmt_interface();
g_main_loop_unref(event_loop);
info("Exit");
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 2/6] android: Create HAL API header skeleton
From: Andrei Emeltchenko @ 2013-10-16 8:46 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1381913215-17957-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Header describes the protocol between Android HAL threads and BlueZ
daemon.
---
android/hal-msg.h | 246 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 246 insertions(+)
create mode 100644 android/hal-msg.h
diff --git a/android/hal-msg.h b/android/hal-msg.h
new file mode 100644
index 0000000..4c5ca69
--- /dev/null
+++ b/android/hal-msg.h
@@ -0,0 +1,246 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+struct hal_msg_hdr {
+ uint8_t service_id;
+ uint8_t opcode;
+ uint16_t len;
+} __attribute__((packed));
+
+#define HAL_SERVICE_ID_CORE 0
+#define HAL_SERVICE_ID_BLUETOOTH 1
+#define HAL_SERVICE_ID_SOCK 2
+#define HAL_SERVICE_ID_HIDHOST 3
+#define HAL_SERVICE_ID_PAN 4
+#define HAL_SERVICE_ID_HANDSFREE 5
+#define HAL_SERVICE_ID_AD2P 6
+#define HAL_SERVICE_ID_HEALTH 7
+#define HAL_SERVICE_ID_AVRCP 8
+#define HAL_SERVICE_ID_GATT 9
+
+/* Core Service */
+
+#define HAL_MSG_OP_ERROR 0x00
+struct hal_msg_rsp_error {
+ uint8_t status;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_REGISTER_MODULE 0x01
+struct hal_msg_cmd_register_module {
+ uint8_t service_id;
+} __attribute__((packed));
+struct hal_msg_rsp_register_module {
+ uint8_t service_id;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_UNREGISTER_MODULE 0x02
+struct hal_msg_cmd_unregister_module {
+ uint8_t service_id;
+} __attribute__((packed));
+
+/* Bluetooth Core HAL API */
+
+#define HAL_MSG_OP_BT_ENABLE 0x01
+
+#define HAL_MSG_OP_BT_DISABLE 0x02
+
+#define HAL_MSG_OP_BT_GET_ADAPTER_PROPS 0x03
+
+#define HAL_MSG_OP_BT_GET_ADAPTER_PROP 0x04
+struct hal_msg_cmd_bt_get_adapter_prop {
+ uint8_t type;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SET_ADAPTER_PROP 0x05
+struct hal_msg_cmd_bt_set_adapter_prop {
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_DEVICE_PROPS 0x06
+struct hal_msg_cmd_bt_get_remote_device_props {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_DEVICE_PROP 0x07
+struct hal_msg_cmd_bt_get_remote_device_prop {
+ uint8_t bdaddr[6];
+ uint8_t type;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SET_REMOTE_DEVICE_PROP 0x08
+struct hal_msg_cmd_bt_set_remote_device_prop {
+ uint8_t bdaddr[6];
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_SERVICE_REC 0x09
+struct hal_msg_cmd_bt_get_remote_service_rec {
+ uint8_t bdaddr[6];
+ uint8_t uuid[16];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_SERVICE 0x0a
+struct hal_msg_cmd_bt_get_remote_service {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_START_DISCOVERY 0x0b
+
+#define HAL_MSG_OP_BT_CANCEL_DISCOVERY 0x0c
+
+#define HAL_MSG_OP_BT_CREATE_BOND 0x0d
+struct hal_msg_cmd_bt_create_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_REMOVE_BOND 0x0d
+struct hal_msg_cmd_bt_remove_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_CANCEL_BOND 0x0f
+struct hal_msg_cmd_bt_cancel_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_PIN_REPLY 0x10
+struct hal_msg_cmd_bt_pin_reply {
+ uint8_t bdaddr[6];
+ uint8_t accept;
+ uint8_t pin_len;
+ uint8_t pin_code[16];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SSP_REPLY 0x11
+struct hal_msg_cmd_bt_ssp_reply {
+ uint8_t bdaddr[6];
+ uint8_t ssp_variant;
+ uint8_t accept;
+ uint32_t passkey;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_DUT_MODE_CONF 0x12
+struct hal_msg_cmd_bt_dut_mode_conf {
+ uint8_t enable;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_DUT_MODE_SEND 0x13
+struct hal_msg_cmd_bt_dut_mode_send {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_LE_TEST_MODE 0x14
+struct hal_msg_cmd_bt_le_test_mode {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+/* Notifications and confirmations */
+
+#define HAL_MSG_EV_BT_ERROR 0x80
+
+#define HAL_MSG_EV_BT_ADAPTER_STATE_CHANGED 0x81
+struct hal_msg_ev_bt_adapter_state_changed {
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_ADAPTER_PROPS_CHANGED 0x82
+struct hal_property {
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+struct hal_msg_ev_bt_adapter_props_changed {
+ uint8_t status;
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_REMOTE_DEVICE_PROPS 0x83
+struct hal_msg_ev_bt_remote_device_props {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DEVICE_FOUND 0x84
+struct hal_msg_ev_bt_device_found {
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DISCOVERY_STATE_CHANGED 0x85
+struct hal_msg_ev_bt_discovery_state_changed {
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_PIN_REQUEST 0x86
+struct hal_msg_ev_bt_pin_request {
+ uint8_t bdaddr[6];
+ uint8_t name[249 - 1];
+ uint8_t class_of_dev[3];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_SSP_REQUEST 0x87
+struct hal_msg_ev_bt_ssp_request {
+ uint8_t bdaddr[6];
+ uint8_t name[249 - 1];
+ uint8_t class_of_dev[3];
+ uint8_t pairing_variant;
+ uint32_t passkey;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_BOND_STATE_CHANGED 0x88
+struct hal_msg_ev_bt_bond_state_changed {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_ACL_STATE_CHANGED 0x89
+struct hal_msg_ev_bt_acl_state_changed {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DUT_MODE_RECEIVE 0x8a
+struct hal_msg_ev_bt_dut_mode_receive {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_LE_TEST_MODE 0x8b
+struct hal_msg_ev_bt_le_test_mode {
+ uint8_t status;
+ uint16_t num_packets;
+} __attribute__((packed));
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 1/6] sdp: Check that correct packet received in recv
From: Andrei Emeltchenko @ 2013-10-16 8:46 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1381913215-17957-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
unit/test-sdp.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/unit/test-sdp.c b/unit/test-sdp.c
index 6d699e2..4726b8b 100644
--- a/unit/test-sdp.c
+++ b/unit/test-sdp.c
@@ -145,8 +145,7 @@ static gboolean server_handler(GIOChannel *channel, GIOCondition cond,
struct context *context = user_data;
sdp_pdu_hdr_t hdr;
void *buf;
- size_t size;
- ssize_t len;
+ ssize_t len, size;
int fd;
fd = g_io_channel_unix_get_fd(channel);
@@ -169,7 +168,7 @@ static gboolean server_handler(GIOChannel *channel, GIOCondition cond,
return TRUE;
len = recv(fd, buf, size, 0);
- if (len <= 0) {
+ if (len != size) {
sdp_svcdb_collect_all(fd);
free(buf);
return FALSE;
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 0/6] Android BlueZ patches, second chunk
From: Andrei Emeltchenko @ 2013-10-16 8:46 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1381833423-862-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This is second chunk from my initial big patch set. Fixed style issues commented
by Marcel.
Changes:
* v2: Corrected android_daemon -> enable_android autoconf stuff, better name for acquiring caps,
renamed hal_msg.h to hal-msg.h due to Johan's comment. Added small test-sdp fix.
Note that due to Marcel comment this cannot be built unless you include my patch
for Android bionic library:
http://code.google.com/p/android-bluez/source/detail?r=77a07e7703b63e280d9880baad30b3375e7df079&repo=bionic#
Andrei Emeltchenko (6):
sdp: Check that correct packet received in recv
android: Create HAL API header skeleton
android: Add basic mgmt initialization sequence
android: Add adapter and device struct for BlueZ daemon
android: sdp: Reuse BlueZ SDP server in Android
android: Add cap to bind to port < 1024
Makefile.android | 8 +-
android/Android.mk | 13 +++
android/adapter.c | 63 ++++++++++++++
android/adapter.h | 36 ++++++++
android/device.c | 29 +++++++
android/device.h | 24 +++++
android/hal-msg.h | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++++
android/main.c | 244 +++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 4 +
unit/test-sdp.c | 5 +-
10 files changed, 667 insertions(+), 5 deletions(-)
create mode 100644 android/adapter.c
create mode 100644 android/adapter.h
create mode 100644 android/device.c
create mode 100644 android/device.h
create mode 100644 android/hal-msg.h
--
1.7.10.4
^ permalink raw reply
* Re: [PATCH 2/2] Bluetooth: Ignore SMP data on non-LE links
From: Marcel Holtmann @ 2013-10-16 8:42 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
In-Reply-To: <1381912621-10238-2-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
> The SMP CID is only defined for LE transports. Instead of returning an
> error from smp_sig_channel() in this case (which would cause a
> disconnection) just return 0 to ignore the data, which is consistent
> with the behavior for other unknown CIDs.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/smp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH 1/2] Bluetooth: Ignore A2MP data on non-BR/EDR links
From: Marcel Holtmann @ 2013-10-16 8:42 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
In-Reply-To: <1381912621-10238-1-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
> The A2MP CID is only valid for BR/EDR transports. We should ignore A2MP
> data on non-BR/EDR links and refuse to create an amp_mgr object.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/a2mp.c | 3 +++
> 1 file changed, 3 insertions(+)
patch has been applied to bluetooth-next tree.
Regards
Marcel
^ permalink raw reply
* [PATCH 2/2] Bluetooth: Ignore SMP data on non-LE links
From: johan.hedberg @ 2013-10-16 8:37 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1381912621-10238-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
The SMP CID is only defined for LE transports. Instead of returning an
error from smp_sig_channel() in this case (which would cause a
disconnection) just return 0 to ignore the data, which is consistent
with the behavior for other unknown CIDs.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/smp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 463e50c..fc200e0 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -856,7 +856,7 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
if (hcon->type != LE_LINK) {
kfree_skb(skb);
- return -ENOTSUPP;
+ return 0;
}
if (skb->len < 1) {
--
1.8.3.1
^ permalink raw reply related
* [PATCH 1/2] Bluetooth: Ignore A2MP data on non-BR/EDR links
From: johan.hedberg @ 2013-10-16 8:37 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
The A2MP CID is only valid for BR/EDR transports. We should ignore A2MP
data on non-BR/EDR links and refuse to create an amp_mgr object.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/a2mp.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c
index fe32a33..efcd108 100644
--- a/net/bluetooth/a2mp.c
+++ b/net/bluetooth/a2mp.c
@@ -836,6 +836,9 @@ struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn,
{
struct amp_mgr *mgr;
+ if (conn->hcon->type != ACL_LINK)
+ return NULL;
+
mgr = amp_mgr_create(conn, false);
if (!mgr) {
BT_ERR("Could not create AMP manager");
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCH 0/3] Fix L2CAP command reject PDUs
From: Marcel Holtmann @ 2013-10-16 8:16 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
In-Reply-To: <1381910801-3130-1-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
> The L2CAP command reject PDU is required to have some extra data for
> "invalid MTU" and "invalid CID" cases. These patches fixes the code to
> always return the right kind of PDU.
>
> Johan
>
> ----------------------------------------------------------------
> Johan Hedberg (3):
> Bluetooth: Fix L2CAP "Command Reject: Invalid CID" response
> Bluetooth: Remove unused command reject mapping for EMSGSIZE
> Bluetooth: Remove useless l2cap_err_to_reason function
>
> net/bluetooth/l2cap_core.c | 54 +++++++++++++++++++++------------------------
> 1 file changed, 25 insertions(+), 29 deletions(-)
all 3 patches have been applied to bluetooth-next tree.
Regards
Marcel
^ permalink raw reply
* [PATCH 3/3] Bluetooth: Remove useless l2cap_err_to_reason function
From: johan.hedberg @ 2013-10-16 8:06 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1381910801-3130-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
Now that the only reason code this function can return is
L2CAP_REJ_NOT_UNDERSTOOD we can just do the necessary assignment without
needing a separate function at all.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/l2cap_core.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 5f2720c..5cbcd4a 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -5313,16 +5313,6 @@ static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn,
}
}
-static __le16 l2cap_err_to_reason(int err)
-{
- switch (err) {
- case -EINVAL:
- case -EPROTO:
- default:
- return __constant_cpu_to_le16(L2CAP_REJ_NOT_UNDERSTOOD);
- }
-}
-
static inline void l2cap_le_sig_channel(struct l2cap_conn *conn,
struct sk_buff *skb)
{
@@ -5355,7 +5345,7 @@ static inline void l2cap_le_sig_channel(struct l2cap_conn *conn,
BT_ERR("Wrong link type (%d)", err);
- rej.reason = l2cap_err_to_reason(err);
+ rej.reason = __constant_cpu_to_le16(L2CAP_REJ_NOT_UNDERSTOOD);
l2cap_send_cmd(conn, cmd->ident, L2CAP_COMMAND_REJ,
sizeof(rej), &rej);
}
@@ -5400,7 +5390,7 @@ static inline void l2cap_sig_channel(struct l2cap_conn *conn,
BT_ERR("Wrong link type (%d)", err);
- rej.reason = l2cap_err_to_reason(err);
+ rej.reason = __constant_cpu_to_le16(L2CAP_REJ_NOT_UNDERSTOOD);
l2cap_send_cmd(conn, cmd.ident, L2CAP_COMMAND_REJ,
sizeof(rej), &rej);
}
--
1.8.3.1
^ permalink raw reply related
* [PATCH 2/3] Bluetooth: Remove unused command reject mapping for EMSGSIZE
From: johan.hedberg @ 2013-10-16 8:06 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1381910801-3130-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
There is no command handler that would return an EMSGSIZE error, so just
remove this mapping from the l2cap_err_to_reason function.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/l2cap_core.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 7d25ec5..5f2720c 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -5316,8 +5316,6 @@ static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn,
static __le16 l2cap_err_to_reason(int err)
{
switch (err) {
- case -EMSGSIZE:
- return __constant_cpu_to_le16(L2CAP_REJ_MTU_EXCEEDED);
case -EINVAL:
case -EPROTO:
default:
--
1.8.3.1
^ permalink raw reply related
* [PATCH 1/3] Bluetooth: Fix L2CAP "Command Reject: Invalid CID" response
From: johan.hedberg @ 2013-10-16 8:06 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1381910801-3130-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
When the reason code in the L2CAP command reject is "invalid CID" there
should be four additional bytes of data in the PDU, namely the source
and destination CIDs (which should be zero if one or both are not
applicable). This patch fixes all occurrences of such errors to return
the right kind of PDU.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/l2cap_core.c | 38 +++++++++++++++++++++++---------------
1 file changed, 23 insertions(+), 15 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 72ce21a..7d25ec5 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -3971,6 +3971,18 @@ static void l2cap_send_efs_conf_rsp(struct l2cap_chan *chan, void *data,
L2CAP_CONF_SUCCESS, flags), data);
}
+static void cmd_reject_invalid_cid(struct l2cap_conn *conn, u8 ident,
+ u16 scid, u16 dcid)
+{
+ struct l2cap_cmd_rej_cid rej;
+
+ rej.reason = __constant_cpu_to_le16(L2CAP_REJ_INVALID_CID);
+ rej.scid = __cpu_to_le16(scid);
+ rej.dcid = __cpu_to_le16(dcid);
+
+ l2cap_send_cmd(conn, ident, L2CAP_COMMAND_REJ, sizeof(rej), &rej);
+}
+
static inline int l2cap_config_req(struct l2cap_conn *conn,
struct l2cap_cmd_hdr *cmd, u16 cmd_len,
u8 *data)
@@ -3990,18 +4002,14 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,
BT_DBG("dcid 0x%4.4x flags 0x%2.2x", dcid, flags);
chan = l2cap_get_chan_by_scid(conn, dcid);
- if (!chan)
- return -EBADSLT;
+ if (!chan) {
+ cmd_reject_invalid_cid(conn, cmd->ident, dcid, 0);
+ return 0;
+ }
if (chan->state != BT_CONFIG && chan->state != BT_CONNECT2) {
- struct l2cap_cmd_rej_cid rej;
-
- rej.reason = __constant_cpu_to_le16(L2CAP_REJ_INVALID_CID);
- rej.scid = cpu_to_le16(chan->scid);
- rej.dcid = cpu_to_le16(chan->dcid);
-
- l2cap_send_cmd(conn, cmd->ident, L2CAP_COMMAND_REJ,
- sizeof(rej), &rej);
+ cmd_reject_invalid_cid(conn, cmd->ident, chan->scid,
+ chan->dcid);
goto unlock;
}
@@ -4217,8 +4225,8 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn,
chan = __l2cap_get_chan_by_scid(conn, dcid);
if (!chan) {
- mutex_unlock(&conn->chan_lock);
- return -EBADSLT;
+ cmd_reject_invalid_cid(conn, cmd->ident, dcid, scid);
+ return 0;
}
l2cap_chan_lock(chan);
@@ -4447,7 +4455,9 @@ static int l2cap_create_channel_req(struct l2cap_conn *conn,
&conn->hcon->dst);
if (!hs_hcon) {
hci_dev_put(hdev);
- return -EBADSLT;
+ cmd_reject_invalid_cid(conn, cmd->ident, chan->scid,
+ chan->dcid);
+ return 0;
}
BT_DBG("mgr %p bredr_chan %p hs_hcon %p", mgr, chan, hs_hcon);
@@ -5306,8 +5316,6 @@ static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn,
static __le16 l2cap_err_to_reason(int err)
{
switch (err) {
- case -EBADSLT:
- return __constant_cpu_to_le16(L2CAP_REJ_INVALID_CID);
case -EMSGSIZE:
return __constant_cpu_to_le16(L2CAP_REJ_MTU_EXCEEDED);
case -EINVAL:
--
1.8.3.1
^ permalink raw reply related
* [PATCH 0/3] Fix L2CAP command reject PDUs
From: johan.hedberg @ 2013-10-16 8:06 UTC (permalink / raw)
To: linux-bluetooth
Hi,
The L2CAP command reject PDU is required to have some extra data for
"invalid MTU" and "invalid CID" cases. These patches fixes the code to
always return the right kind of PDU.
Johan
----------------------------------------------------------------
Johan Hedberg (3):
Bluetooth: Fix L2CAP "Command Reject: Invalid CID" response
Bluetooth: Remove unused command reject mapping for EMSGSIZE
Bluetooth: Remove useless l2cap_err_to_reason function
net/bluetooth/l2cap_core.c | 54 +++++++++++++++++++++------------------------
1 file changed, 25 insertions(+), 29 deletions(-)
^ permalink raw reply
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