* [PATCH 2/3] Bluetooth: Replace BDADDR_LOCAL with BDADDR_NONE
From: Marcel Holtmann @ 2013-09-30 4:11 UTC (permalink / raw)
To: linux-bluetooth
The BDADDR_LOCAL is a relict from userspace and has never been used
within the kernel. So remove that constant and replace it with a new
BDADDR_NONE that is similar to HCI_DEV_NONE with all bits set.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Acked-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/bluetooth.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index afbc711..5fd5106 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -197,8 +197,8 @@ static inline bool bdaddr_type_is_le(__u8 type)
return false;
}
-#define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0} })
-#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff} })
+#define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
+#define BDADDR_NONE (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
/* Copy, swap, convert BD Address */
static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
--
1.8.3.1
^ permalink raw reply related
* [PATCH 1/3] Bluetooth: Use only 2 bits for controller type information
From: Marcel Holtmann @ 2013-09-30 4:10 UTC (permalink / raw)
To: linux-bluetooth
The controller type is limited to BR/EDR/LE and AMP controllers. This
can be easily encoded with just 2 bits and still leave enough room
for future controller types.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
net/bluetooth/hci_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 4549b5c..dd2528c5 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1610,7 +1610,7 @@ int hci_get_dev_info(void __user *arg)
strcpy(di.name, hdev->name);
di.bdaddr = hdev->bdaddr;
- di.type = (hdev->bus & 0x0f) | (hdev->dev_type << 4);
+ di.type = (hdev->bus & 0x0f) | ((hdev->dev_type & 0x03) << 4);
di.flags = hdev->flags;
di.pkt_type = hdev->pkt_type;
if (lmp_bredr_capable(hdev)) {
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCH] Bluetooth: Use only 2 bits for controller type information
From: Marcel Holtmann @ 2013-09-30 4:01 UTC (permalink / raw)
To: Anderson Lizardo; +Cc: BlueZ development
In-Reply-To: <CAJdJm_Ova_rzJy8pnO2VJRki7N=L=PEk=r=D5Zk1oPDkA=2mOA@mail.gmail.com>
Hi Anderson,
>> The controller type is limited to BR/EDR/LE and AMP controllers. This
>> can be easily encoded with just 2 bits and still leave enough room
>> for future controller types.
>>
>> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
>> ---
>> net/bluetooth/hci_core.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
>> index 4549b5c..ebba5a6 100644
>> --- a/net/bluetooth/hci_core.c
>> +++ b/net/bluetooth/hci_core.c
>> @@ -1610,7 +1610,7 @@ int hci_get_dev_info(void __user *arg)
>>
>> strcpy(di.name, hdev->name);
>> di.bdaddr = hdev->bdaddr;
>> - di.type = (hdev->bus & 0x0f) | (hdev->dev_type << 4);
>> + di.type = (hdev->bus & 0x0f) | ((hdev->dev_type & 0x30) << 4);
>
> Shouldn't it be (hdev->dev_type & 0x03) here?
yes, this it should be 0x03 here. My mistake.
Regards
Marcel
^ permalink raw reply
* Re: [RFC] Bluetooth: Add command for setting static address
From: Marcel Holtmann @ 2013-09-30 3:42 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth
In-Reply-To: <20130929191102.GA32665@x220.p-661hnu-f1>
Hi Johan,
>> Add command for setting static address for use as LE random address.
>>
>> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
>> ---
>> include/net/bluetooth/hci.h | 2 ++
>> include/net/bluetooth/hci_core.h | 1 +
>> include/net/bluetooth/mgmt.h | 6 ++++++
>> net/bluetooth/hci_core.c | 5 +++++
>> net/bluetooth/mgmt.c | 43 +++++++++++++++++++++++++++++++++++++++-
>> 5 files changed, 56 insertions(+), 1 deletion(-)
>
> This looks all pretty good to me. Did you have any particular thoughts
> on resolvable private address generation (which we have to support as
> soon as we support the privacy feature as a central) or is that
> completely orthogonal to this feature? I suppose we'll be implementing
> that through a "privacy" mgmt settings bit and leave the rest up to the
> kernel?
originally I called this random address and had the idea to let userspace program the addresses all by itself. Then I got into reading on how they are defined and realized that it might be better to separate static addresses from private addresses.
The kernel can easily generate a static address by itself during the initial setup of the controller and that would satisfy the requirement from the specification to only ever change and power cycle. Which would be essentially when you remove the controller or reboot the kernel.
However as we discussed in New Orleans, we might want to provide a way for userspace to generate a static address and keep it. So that this becomes more deterministic. It would also make it a bit simpler for testing since you can have a "fixed" address.
I limited this command to by only available when the controller is powered off so that we do not have to deal with changing the address at runtime. Since that is clearly against the specification that it should only change at power cycle.
For private addresses, the resolvable ones involve our own IRK and that is something that we should provide to the kernel somehow. And then the kernel should create the key for us. Providing the IRK one way and then having userspace to generate the random address for it seemed like a bad idea.
The non-resolvable private addresses are kinda funky on how they work. And I am not even sure they will be useful at all. They really only make sense for LE only controllers that do not have a public address. I am not sure anybody actually uses them at all. So we have to think about on how we use these addresses. If we want to use them at all.
One thing that still bugs me is the case that when we encounter an LE only controller with no public address, then we return 00:00:00:00:00:00 to the management interface and also the legacy ioctl. The management interface can happily handle it, the ioctl and its command line tools break badly. bluetoothd also has some issues on how to actually use such a controller and store persistent data with it. That is where a "fixed" static address might be useful. We can just generate one, keep it and program it in the next LE only controller with no public address. At that point it does not really matter which hardware it is since they are all the same. But we need an address for it and here the static addresses come in handy.
The current command already has the magic 00:00:00:00:00:00 that will disable static address again. By itself BDADDR_ANY is not a valid random address. I am thinking of adding 11:11:11:11:11:11 as another special case (since that is not valid either) and let the kernel generate a static random address for us. It can easily generate one that is not conflicting with any other controller in the system. Not sure if this is really worth it. This can be as easily achieved in userspace.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH] Bluetooth: Provide high speed configuration option
From: Marcel Holtmann @ 2013-09-30 3:20 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth
In-Reply-To: <20130929192209.GA1115@x220.p-661hnu-f1>
Hi Johan,
>> --- a/net/bluetooth/mgmt.c
>> +++ b/net/bluetooth/mgmt.c
>> @@ -32,8 +32,6 @@
>> #include <net/bluetooth/mgmt.h>
>> #include <net/bluetooth/smp.h>
>>
>> -bool enable_hs;
>> -
>> #define MGMT_VERSION 1
>> #define MGMT_REVISION 3
>>
>> @@ -382,8 +380,7 @@ static u32 get_supported_settings(struct hci_dev *hdev)
>> settings |= MGMT_SETTING_LINK_SECURITY;
>> }
>>
>> - if (enable_hs)
>> - settings |= MGMT_SETTING_HS;
>> + settings |= MGMT_SETTING_HS;
>
> I know it's a bug in the original code, but we may as well fix it in the
> same go: I suppose this setting should be behind the lmp_bredr_capable
> check as LE-only controllers would not support it. That said, we might
> also want to be looking at the controller version.
that is a good point since there is really no point in exposing this for LE only controllers.
Version vise we could be extremely strict and limit it to 2.1 or later, but I am not sure if this matters. The Bluetooth SIG defined Bluetooth 3.0 + HS as minimum 2.1 BR/EDR controller + AMP. With that combination you are allowed to brand it as 3.0 + HS. They never defined anything for 2.0 and earlier controllers, but technically speaking it is possible to do high speed with these as well. The reason why it was not defined is because at that time only two specification were allowed to be active for qualification. So nobody bothered to look back past 2.1.
>> if (lmp_le_capable(hdev)) {
>> settings |= MGMT_SETTING_LE;
>> @@ -1344,10 +1341,6 @@ static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
>>
>> BT_DBG("request for %s", hdev->name);
>>
>> - if (!enable_hs)
>> - return cmd_status(sk, hdev->id, MGMT_OP_SET_HS,
>> - MGMT_STATUS_NOT_SUPPORTED);
>> -
>> if (cp->val != 0x00 && cp->val != 0x01)
>> return cmd_status(sk, hdev->id, MGMT_OP_SET_HS,
>> MGMT_STATUS_INVALID_PARAMS);
>
> It seems like the command handler is also missing a check for
> lmp_bredr_capable and a NOT_SUPPORTED return in that case. This should
> probably be part of a separate patch though.
I think that I do that in the same patch. I completely overlooked the fact that we should have limited this to BR/EDR capable controllers.
> Some mgmt-tester cases for all this would be nice too :)
Yes of course, once I get to it. If anybody wants to beat me to it, I am fine with that as well.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH] Bluetooth: Replace BDADDR_LOCAL with BDADDR_NONE
From: Johan Hedberg @ 2013-09-29 19:34 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1380441711-55190-1-git-send-email-marcel@holtmann.org>
Hi Marcel,
On Sun, Sep 29, 2013, Marcel Holtmann wrote:
> The BDADDR_LOCAL is a relict from userspace and has never been used
> within the kernel. So remove that constant and replace it with a new
> BDADDR_NONE that is similar to HCI_DEV_NONE with all bits set.
>
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
> include/net/bluetooth/bluetooth.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Acked-by: Johan Hedberg <johan.hedberg@intel.com>
Johan
^ permalink raw reply
* Re: [PATCH] Bluetooth: Provide high speed configuration option
From: Johan Hedberg @ 2013-09-29 19:22 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1380452005-7211-1-git-send-email-marcel@holtmann.org>
Hi Marcel,
On Sun, Sep 29, 2013, Marcel Holtmann wrote:
> --- a/net/bluetooth/mgmt.c
> +++ b/net/bluetooth/mgmt.c
> @@ -32,8 +32,6 @@
> #include <net/bluetooth/mgmt.h>
> #include <net/bluetooth/smp.h>
>
> -bool enable_hs;
> -
> #define MGMT_VERSION 1
> #define MGMT_REVISION 3
>
> @@ -382,8 +380,7 @@ static u32 get_supported_settings(struct hci_dev *hdev)
> settings |= MGMT_SETTING_LINK_SECURITY;
> }
>
> - if (enable_hs)
> - settings |= MGMT_SETTING_HS;
> + settings |= MGMT_SETTING_HS;
I know it's a bug in the original code, but we may as well fix it in the
same go: I suppose this setting should be behind the lmp_bredr_capable
check as LE-only controllers would not support it. That said, we might
also want to be looking at the controller version.
>
> if (lmp_le_capable(hdev)) {
> settings |= MGMT_SETTING_LE;
> @@ -1344,10 +1341,6 @@ static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
>
> BT_DBG("request for %s", hdev->name);
>
> - if (!enable_hs)
> - return cmd_status(sk, hdev->id, MGMT_OP_SET_HS,
> - MGMT_STATUS_NOT_SUPPORTED);
> -
> if (cp->val != 0x00 && cp->val != 0x01)
> return cmd_status(sk, hdev->id, MGMT_OP_SET_HS,
> MGMT_STATUS_INVALID_PARAMS);
It seems like the command handler is also missing a check for
lmp_bredr_capable and a NOT_SUPPORTED return in that case. This should
probably be part of a separate patch though.
Some mgmt-tester cases for all this would be nice too :)
Johan
^ permalink raw reply
* Re: [RFC] Bluetooth: Add command for setting static address
From: Johan Hedberg @ 2013-09-29 19:11 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1380441937-55298-1-git-send-email-marcel@holtmann.org>
Hi Marcel,
On Sun, Sep 29, 2013, Marcel Holtmann wrote:
> Add command for setting static address for use as LE random address.
>
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
> include/net/bluetooth/hci.h | 2 ++
> include/net/bluetooth/hci_core.h | 1 +
> include/net/bluetooth/mgmt.h | 6 ++++++
> net/bluetooth/hci_core.c | 5 +++++
> net/bluetooth/mgmt.c | 43 +++++++++++++++++++++++++++++++++++++++-
> 5 files changed, 56 insertions(+), 1 deletion(-)
This looks all pretty good to me. Did you have any particular thoughts
on resolvable private address generation (which we have to support as
soon as we support the privacy feature as a central) or is that
completely orthogonal to this feature? I suppose we'll be implementing
that through a "privacy" mgmt settings bit and leave the rest up to the
kernel?
Johan
^ permalink raw reply
* Re: [RFC 16/16] android: Add HAL message helpers
From: Johan Hedberg @ 2013-09-29 15:00 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1380291161-10232-17-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Fri, Sep 27, 2013, Andrei Emeltchenko wrote:
> +int open_hal_chan(void)
> +{
> + int tries = 10;
> + int sock;
> +
> + while (tries-- > 0) {
> + sock = socket_local_client(BLUEZ_SOCKET,
> + ANDROID_SOCKET_NAMESPACE_RESERVED,
> + SOCK_STREAM);
Again, should be s/STREAM/SEQPACKET/ here.
Johan
^ permalink raw reply
* Re: [RFC 15/16] android: Implement basic HAL server
From: Johan Hedberg @ 2013-09-29 14:59 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1380291161-10232-16-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Fri, Sep 27, 2013, Andrei Emeltchenko wrote:
> + sock = socket(AF_UNIX, SOCK_STREAM, 0);
> + if (sock < 0) {
> + error("%s: socket(): %s", __func__, strerror(errno));
> + return sock;
> + }
This should be SOCK_SEQPACKET. It has been mentioned several times in
our (offline) conversations and is also clearly stated in the IPC
document we'll soon push upstream.
> + /* Since daemon would be run also on host we have to grant perms */
> + chmod(sock_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH |
> + S_IWOTH);
Is this really necessary? On the host (by which I presume you mean the
system where you build BlueZ, i.e. a non-android system) couldn't the
test tool that's used just exec the daemon and then you have the same
context for both processes that need to access the socket.
> @@ -646,11 +648,13 @@ int main(int argc, char *argv[])
> exit(1);
>
> init_mgmt_interface();
> + start_hal_srv("/dev/socket/bluez_hal");
Isn't /var/run the right place for stuff like this? Alternatively we
could also go with an abstract socket and then not care about any
associations with the file system at all.
Johan
^ permalink raw reply
* Re: [PATCH BlueZ 1/2] gobex: Fix crash on g_obex_pending_req_abort
From: Luiz Augusto von Dentz @ 2013-09-29 14:15 UTC (permalink / raw)
To: linux-bluetooth@vger.kernel.org; +Cc: Jaganath Kanakkassery
In-Reply-To: <1380034036-25143-1-git-send-email-luiz.dentz@gmail.com>
Hi,
On Tue, Sep 24, 2013 at 5:47 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> 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
I went ahead an pushed this set upstream.
--
Luiz Augusto von Dentz
^ permalink raw reply
* Re: [RFC 12/16] android: Add cap to bind to port < 1024
From: Marcel Holtmann @ 2013-09-29 13:40 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1380291161-10232-13-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
> For SDP server we need to bind to lower port, acquire this capability.
> ---
> android/main.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> configure.ac | 4 ++++
> 2 files changed, 57 insertions(+)
>
> diff --git a/android/main.c b/android/main.c
> index 5fef095..649867d 100644
> --- a/android/main.c
> +++ b/android/main.c
> @@ -31,6 +31,19 @@
> #include <stdio.h>
> #include <stdlib.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_API__) && (__ANDROID_API__ > 17)) || \
> + !defined(__ANDROID_API__)
> +#include <sys/capability.h>
> +#endif
>
> #include <glib.h>
>
> @@ -319,6 +332,43 @@ static void cleanup_mgmt_interface(void)
> mgmt_if = NULL;
> }
>
> +static bool android_set_aid_and_cap()
> +{
> + struct __user_cap_header_struct header;
> + struct __user_cap_data_struct cap;
> +
> + DBG("%s: pid %d uid %d gid %d", __func__, getpid(), getuid(), getgid());
> +
> + header.version = _LINUX_CAPABILITY_VERSION;
> + header.pid = getpid();
> + if (capget(&header, &cap) < 0)
> + error("%s: capget(): %s", __func__, strerror(errno));
> +
> + DBG("%s: Cap data 0x%x, 0x%x, 0x%x\n", __func__, cap.effective,
> + cap.permitted, cap.inheritable);
> +
> + prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
> +
> + header.version = _LINUX_CAPABILITY_VERSION;
> + header.pid = 0;
> +
> + cap.effective = cap.permitted = cap.inheritable =
> + 1 << CAP_NET_RAW |
the CAP_NET_RAW should not be needed for the daemon.
> + 1 << CAP_NET_ADMIN |
> + 1 << CAP_NET_BIND_SERVICE |
> + 1 << CAP_SYS_RAWIO |
What kind of RAWIO are planning to do?
> + 1 << CAP_SYS_NICE |
Do we need to renice ourselves?
> + 1 << CAP_SETGID;
> +
> + if (capset(&header, &cap)) {
> + error("%s: capset(): %s", __func__, strerror(errno));
> + return false;
> + }
> +
> + DBG("%s: capset(): Success", __func__);
> + return true;
> +}
> +
> int main(int argc, char *argv[])
> {
> GOptionContext *context;
> @@ -357,6 +407,9 @@ int main(int argc, char *argv[])
> /* no need to keep parsed option in memory */
> free_options();
>
> + if (android_set_aid_and_cap() == false)
> + exit(1);
> +
> init_mgmt_interface();
>
> DBG("Entering main loop");
> diff --git a/configure.ac b/configure.ac
> index 3b7a5d9..af418d3 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -247,4 +247,8 @@ AC_ARG_ENABLE(android-daemon, AC_HELP_STRING([--enable-android-daemon],
> [android_daemon=${enableval}])
> AM_CONDITIONAL(ANDROID_DAEMON, test "${android_daemon}" = "yes")
>
> +if (test "${android_daemon}" = "yes"); then
> + AC_CHECK_LIB(cap, capget, dummy=yes, AC_MSG_ERROR(libcap is required))
> +fi
> +
The configure option should be --enable-android.
> AC_OUTPUT(Makefile src/bluetoothd.8 lib/bluez.pc)
Regards
Marcel
^ permalink raw reply
* Re: [RFC 09/16] android: Add adapter and device struct for BlueZ daemon
From: Marcel Holtmann @ 2013-09-29 13:38 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1380291161-10232-10-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
> Adapter structure in BlueZ daemon keeps track of default adapter
> and device structure keeps track about found devices.
> ---
> android/bt_adapter.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++
> android/bt_adapter.h | 68 ++++++++++++++++++++++++++
> 2 files changed, 197 insertions(+)
> create mode 100644 android/bt_adapter.c
> create mode 100644 android/bt_adapter.h
>
> diff --git a/android/bt_adapter.c b/android/bt_adapter.c
> new file mode 100644
> index 0000000..9f64839
> --- /dev/null
> +++ b/android/bt_adapter.c
> @@ -0,0 +1,129 @@
> +/*
> + *
> + * 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 "bt_adapter.h"
> +#include "log.h"
> +#include "src/shared/mgmt.h"
> +
> +struct bt_device *bt_device_ref(struct bt_device *device)
> +{
> + DBG("");
> +
> + __sync_fetch_and_add(&device->refcnt, 1);
> +
> + return device;
> +}
> +
> +void bt_device_unref(struct bt_device *device)
> +{
> + DBG("");
> +
> + if (__sync_sub_and_fetch(&device->refcnt, 1))
> + return;
> +
> + /* TODO: */
> + DBG("%s: Freeing device %p name %s", __func__, device, device->name);
> +
> + free(device->name);
> + free(device);
> +}
> +
> +struct bt_adapter *bt_adapter_lookup(uint16_t index)
> +{
> + GList *list;
> +
> + for (list = g_list_first(adapter_list); list;
> + list = g_list_next(list)) {
> + struct bt_adapter *adapter = list->data;
> +
> + if (adapter->dev_id == index)
> + return adapter;
> + }
> +
> + return NULL;
> +}
> +
> +struct bt_adapter *bt_adapter_ref(struct bt_adapter *adapter)
> +{
> + DBG("");
> +
> + __sync_fetch_and_add(&adapter->refcnt, 1);
> +
> + return adapter;
> +}
> +
> +static void bt_adapter_free(struct bt_adapter *adapter)
> +{
> + DBG("");
> +
> + while (adapter->found_devices) {
> + struct bt_device *device = adapter->found_devices->data;
> +
> + adapter->found_devices = g_list_remove(adapter->found_devices,
> + device);
> + bt_device_unref(device);
> + }
> +
> + mgmt_unref(adapter->mgmt);
> + free(adapter);
> +}
> +
> +void bt_adapter_unref(struct bt_adapter *adapter)
> +{
> + DBG("");
> +
> + if (__sync_sub_and_fetch(&adapter->refcnt, 1))
> + return;
> +
> + bt_adapter_free(adapter);
> +}
> +
> +struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if)
> +{
> + struct bt_adapter *adapter;
> +
> + adapter = g_try_new0(struct bt_adapter, 1);
> + if (!adapter)
> + return NULL;
> +
> + adapter->dev_id = index;
> + adapter->mgmt = mgmt_ref(mgmt_if);
> +
> + return bt_adapter_ref(adapter);
> +}
> +
> +void adapter_start(struct bt_adapter *adapter)
> +{
> + DBG("enabled %u", adapter->dev_id);
> +
> + /* TODO: CB: report scan mode */
> +
> + /* TODO: SDP start here */
> +
> + /* TODO: CB: report state on */
> +}
> +
> +void adapter_stop(struct bt_adapter *adapter)
> +{
> + DBG("disabled %u", adapter->dev_id);
> +}
> diff --git a/android/bt_adapter.h b/android/bt_adapter.h
> new file mode 100644
> index 0000000..5634729
> --- /dev/null
> +++ b/android/bt_adapter.h
> @@ -0,0 +1,68 @@
> +/*
> + *
> + * 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_device {
> + int refcnt;
> +
> + bdaddr_t bdaddr;
> + uint8_t bdaddr_type;
> + uint32_t cod;
> + char *name;
> +};
> +
> +struct bt_adapter {
> + int refcnt;
> +
> + uint16_t dev_id;
> + struct mgmt *mgmt;
> + bdaddr_t bdaddr;
> + uint32_t dev_class;
> +
> + char *name;
> + char *short_name;
> +
> + uint32_t supported_settings;
> + uint32_t current_settings;
> +
> + GList *found_devices;
> +};
> +
> +extern GList *adapter_list;
> +
> +struct bt_adapter *bt_adapter_lookup(uint16_t index);
> +struct bt_adapter *bt_adapter_ref(struct bt_adapter *adapter);
> +void bt_adapter_unref(struct bt_adapter *adapter);
> +struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if);
> +
> +struct bt_device *bt_device_ref(struct bt_device *device);
> +void bt_device_unref(struct bt_device *device);
> +
> +void adapter_start(struct bt_adapter *adapter);
> +void adapter_stop(struct bt_adapter *adapter);
since we only support one single controller and will ignore all others, why are we building such a complicate abstraction. We could make this functionality part of the core daemon and no need to create an adapter abstraction.
Just copying bluetoothd is not helping us here since at its core, it works way different. We do not need all that logic here.
Regards
Marcel
^ permalink raw reply
* Re: [RFC 05/16] android: Add Android Makefile for mgmt library
From: Marcel Holtmann @ 2013-09-29 13:34 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1380291161-10232-6-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
> Build libbluez shared library for Android.
> ---
> android/Android.mk | 30 ++++++++++++++++++++++++++++++
> 1 file changed, 30 insertions(+)
>
> diff --git a/android/Android.mk b/android/Android.mk
> index 93de803..40cff9a 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -43,3 +43,33 @@ LOCAL_MODULE_TAGS := optional
> LOCAL_MODULE_CLASS := SHARED_LIBRARIES
>
> include $(BUILD_SHARED_LIBRARY)
> +
> +#
> +# mgmt library libbluez
> +#
> +
> +include $(CLEAR_VARS)
> +
> +LOCAL_SRC_FILES := \
> + ../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_SHARED_LIBRARIES := \
> + libglib \
> +
> +# to suppress the "pointer of type 'void *' used in arithmetic" warning
> +LOCAL_CFLAGS := -Wno-pointer-arith
> +
> +# Define missing flags for Android 4.2
> +LOCAL_CFLAGS += -DSOCK_CLOEXEC=02000000 -DSOCK_NONBLOCK=04000
> +
> +LOCAL_MODULE := libbluez
> +
> +include $(BUILD_SHARED_LIBRARY)
why are we building a shared library here. We could just link the source files into the daemon code. bluetoothd is just compiling these files and not bothering with a shared library.
Regards
Marcel
^ permalink raw reply
* Re: [RFC 11/16] android: sdp: Reuse BlueZ SDP server in Android
From: Marcel Holtmann @ 2013-09-29 13:31 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1380291161-10232-12-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
> Reuse existing SDP server code in Android GPL daemon.
> ---
> Makefile.android | 7 +++++--
> android/Android.mk | 6 ++++++
> android/bt_adapter.c | 5 ++++-
> android/main.c | 27 +++++++++++++++++++++++++++
> android/main.h | 25 +++++++++++++++++++++++++
> 5 files changed, 67 insertions(+), 3 deletions(-)
> create mode 100644 android/main.h
>
> diff --git a/Makefile.android b/Makefile.android
> index 3e6fec0..bf82928 100644
> --- a/Makefile.android
> +++ b/Makefile.android
> @@ -3,7 +3,10 @@ if ANDROID_DAEMON
> noinst_PROGRAMS += android/bluezd
>
> android_bluezd_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_bluezd_LDADD = @GLIB_LIBS@
> + src/shared/mgmt.h src/shared/mgmt.c \
> + android/bt_adapter.h android/bt_adapter.c
> +android_bluezd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
> endif
> diff --git a/android/Android.mk b/android/Android.mk
> index 36f8798..08e35e4 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -9,6 +9,11 @@ include $(CLEAR_VARS)
> LOCAL_SRC_FILES := \
> log.c \
> main.c \
> + bt_adapter.c \
> + ../src/sdpd-database.c \
> + ../src/sdpd-service.c \
> + ../src/sdpd-request.c \
> + ../src/sdpd-server.c \
>
> LOCAL_C_INCLUDES := \
> $(call include-path-for, glib) \
> @@ -24,6 +29,7 @@ LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"
> LOCAL_SHARED_LIBRARIES := \
> libglib \
> libbluez \
> + libbluetooth \
>
> LOCAL_MODULE := bluezd
>
> diff --git a/android/bt_adapter.c b/android/bt_adapter.c
> index 9f64839..42facb6 100644
> --- a/android/bt_adapter.c
> +++ b/android/bt_adapter.c
> @@ -23,6 +23,7 @@
>
> #include "bt_adapter.h"
> #include "log.h"
> +#include "main.h"
> #include "src/shared/mgmt.h"
>
> struct bt_device *bt_device_ref(struct bt_device *device)
> @@ -118,7 +119,7 @@ void adapter_start(struct bt_adapter *adapter)
>
> /* TODO: CB: report scan mode */
>
> - /* TODO: SDP start here */
> + sdp_start();
>
> /* TODO: CB: report state on */
> }
> @@ -126,4 +127,6 @@ void adapter_start(struct bt_adapter *adapter)
> void adapter_stop(struct bt_adapter *adapter)
> {
> DBG("disabled %u", adapter->dev_id);
> +
> + sdp_stop();
> }
> diff --git a/android/main.c b/android/main.c
> index 4792919..5fef095 100644
> --- a/android/main.c
> +++ b/android/main.c
> @@ -36,6 +36,8 @@
>
> #include "log.h"
> #include "hcid.h"
> +#include "sdpd.h"
> +#include "main.h"
>
> #include "lib/bluetooth.h"
> #include "lib/mgmt.h"
> @@ -43,12 +45,37 @@
>
> #define SHUTDOWN_GRACE_SECONDS 10
>
> +struct main_opts main_opts;
> +
where is this main_opts coming from. I rather not have this.
> static GMainLoop *event_loop;
> static struct mgmt *mgmt_if = NULL;
>
> static uint8_t mgmt_version = 0;
> static uint8_t mgmt_revision = 0;
>
> +GList *adapter_list = NULL;
> +struct bt_adapter *default_adapter = NULL;
Why are this public variables.
> +
> +int sdp_start(void)
> +{
> + uint16_t mtu = 0;
> + uint32_t flags = 0;
> +
> + DBG("");
> +
> + /* sdpd-server use these settings */
> + memset(&main_opts, 0, sizeof(main_opts));
> +
> + return start_sdp_server(mtu, flags);
Just fill in mtu and flags manually here. No need for variable declaration above.
> +}
> +
> +void sdp_stop(void)
> +{
> + DBG("");
> +
> + stop_sdp_server();
> +}
> +
> void btd_exit(void)
> {
> g_main_loop_quit(event_loop);
> diff --git a/android/main.h b/android/main.h
> new file mode 100644
> index 0000000..6ecad14
> --- /dev/null
> +++ b/android/main.h
> @@ -0,0 +1,25 @@
> +/*
> + *
> + * 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
> + *
> + */
> +
> +int sdp_start(void);
> +void sdp_stop(void);
Regards
Marcel
^ permalink raw reply
* Re: [RFC 04/16] android: Start Android Bluetooth daemon
From: Marcel Holtmann @ 2013-09-29 13:28 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1380291161-10232-5-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
> Start Android Bluetooth daemon from HAL init(). Make sure
> that daemon is in "running" state.
> ---
> android/hal_bluetooth.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 53 insertions(+), 1 deletion(-)
>
> diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
> index 5298618..036091e 100644
> --- a/android/hal_bluetooth.c
> +++ b/android/hal_bluetooth.c
> @@ -23,11 +23,16 @@
> #include <hardware/bluetooth.h>
> #include <hardware/bt_sock.h>
>
> +#include <cutils/sockets.h>
> +#include <cutils/properties.h>
> +
> #define LOG_TAG "BlueZ"
> #include <cutils/log.h>
>
> #include "hal.h"
>
> +#define ANDROID_BLUEZ "bluezd"
> +
the name changes to either "btd" or "bluetoothd". We need to pick one, but it is not suppose to be "bluezd".
> bt_callbacks_t *bt_hal_cbacks = NULL;
This needs to be public?
> static bool interface_ready(void)
> @@ -35,6 +40,49 @@ static bool interface_ready(void)
> return bt_hal_cbacks != NULL;
> }
>
> +static bool is_running(const char *service_name)
> +{
> + char val[PROPERTY_VALUE_MAX];
> + char name[PROPERTY_KEY_MAX];
> + int ret;
No double spaces here.
> +
> + ALOGI(__func__);
> +
> + ret = snprintf(name, sizeof(name), "init.svc.%s", service_name);
> + if (ret > (int) sizeof(name) - 1) {
Can you not just use PROPERTY_KEY_MAX and avoid the casting?
> + ALOGD("Service name '%s' is too long", service_name);
> + return false;
> + }
> +
> + if (property_get(name, val, NULL)) {
> + if (strcmp(val, "running") == 0)
> + return true;
> + }
> +
> + return false;
> +}
> +
> +static bool start_bt_daemon(void)
> +{
> + int tries = 40; /* wait 4 seconds for completion */
> +
> + ALOGI(__func__);
> +
> + /* Start Android Bluetooth daemon service */
> + property_set("ctl.start", ANDROID_BLUEZ);
> +
> + while (tries-- > 0) {
> + if (is_running(ANDROID_BLUEZ) == true) {
> + ALOGI("Android BlueZ daemon started");
> + return true;
> + }
> +
> + usleep(100000);
> + }
> +
> + return false;
> +}
> +
> static bool is_profile(const char *profile, const char *str)
> {
> return (strlen(str) == strlen(profile)) &&
> @@ -51,7 +99,11 @@ static int init(bt_callbacks_t *callbacks)
> /* store reference to user callbacks */
> bt_hal_cbacks = callbacks;
>
> - /* TODO: Init here bluezd task */
> + if (start_bt_daemon() == true) {
> + /* TODO: open channel */
> +
> + return BT_STATUS_SUCCESS;
> + }
>
> return BT_STATUS_UNSUPPORTED;
> }
Regards
Marcel
^ permalink raw reply
* Re: [RFC 08/16] android: Add Android HAL callback task
From: Marcel Holtmann @ 2013-09-29 13:22 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1380291161-10232-9-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
> Android HAL callback task listens for messages from BlueZ GPL daemon.
> ---
> android/Android.mk | 6 ++
> android/hal_cb_thread.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 150 insertions(+)
> create mode 100644 android/hal_cb_thread.c
>
> diff --git a/android/Android.mk b/android/Android.mk
> index f9c73a2..e892249 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -37,10 +37,16 @@ include $(CLEAR_VARS)
>
> LOCAL_SRC_FILES := \
> hal_bluetooth.c \
> + hal_cb_thread.c \
> hal_bt_sock.c \
>
> LOCAL_SHARED_LIBRARIES := \
> libcutils \
> + libglib \
> +
> +LOCAL_C_INCLUDES := \
> + $(call include-path-for, glib) \
> + $(call include-path-for, glib)/glib \
>
> LOCAL_MODULE := bluetooth.default
> LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
> diff --git a/android/hal_cb_thread.c b/android/hal_cb_thread.c
> new file mode 100644
> index 0000000..b7aebe8
> --- /dev/null
> +++ b/android/hal_cb_thread.c
> @@ -0,0 +1,144 @@
> +/*
> + * Copyright (C) 2013 Intel Corporation
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + *
> + */
> +
> +#include <glib.h>
> +#include <stdbool.h>
> +#include <sys/socket.h>
> +#include <sys/stat.h>
> +#include <sys/un.h>
> +#include <errno.h>
> +
> +#include <hardware/bluetooth.h>
> +
> +#define LOG_TAG "BlueZ"
> +#include <cutils/log.h>
> +
> +#include "hal_msg.h"
> +
> +#define HAL_CBACK(base, cb_function, ...) \
> + do { \
> + if (base && base->cb_function) { \
> + ALOGI("CB %s->%s", #base, #cb_function); \
> + base->cb_function(__VA_ARGS__); \
> + } else { \
> + ALOGE("%s: Callback is NULL", __func__); \
> + } \
> + } while (0)
> +
> +static GMainLoop *event_loop;
> +
> +extern bt_callbacks_t *bt_hal_cbacks;
> +
> +static void bthal_thread_associate(void)
> +{
> + ALOGI(__func__);
> +
> + HAL_CBACK(bt_hal_cbacks, thread_evt_cb, ASSOCIATE_JVM);
> +}
> +
> +static void bthal_thread_disassociate(void)
> +{
> + ALOGI(__func__);
> +
> + HAL_CBACK(bt_hal_cbacks, thread_evt_cb, DISASSOCIATE_JVM);
> +
> + bt_hal_cbacks = NULL;
> +}
> +
> +void process_msg(struct hal_msg_hdr *msg)
> +{
> + ALOGI(__func__);
> +
> + /* TODO: Process messages from daemon */
> +}
> +
> +static gboolean hal_session_event(GIOChannel *iochan, GIOCondition cond,
> + gpointer data)
> +{
> + struct hal_msg_hdr msg;
> + int sock, len, size;
> + uint8_t *buf;
> +
> + if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
> + ALOGE("%s: error condition %d", __func__, cond);
> + return FALSE;
> + }
> +
> + sock = g_io_channel_unix_get_fd(iochan);
> +
> + len = recv(sock, &msg, sizeof(msg), MSG_PEEK);
> + if (len <= 0) {
> + ALOGE("%s: recv(): %s %d", __func__, strerror(errno), sock);
> + return FALSE;
> + }
> +
> + size = sizeof(msg) + msg.len;
> +
> + ALOGD("%s: Read first %d bytes, total %d", __func__, len, size);
> +
> + buf = malloc(size);
> + if (buf == NULL)
> + return FALSE;
> +
> + len = recv(sock, buf, size, 0);
> + if (len != size) {
> + ALOGE("%s: recv(): %s %d", __func__, strerror(errno), sock);
> + free(buf);
> + return FALSE;
> + }
> +
> + process_msg((struct hal_msg_hdr *) buf);
> +
> + free(buf);
> +
> + return TRUE;
> +}
> +
> +int hal_cb_init_sock(int sock)
> +{
> + GIOChannel *iochan;
> + int id;
> +
> + ALOGD("%s: sock %d", __func__, sock);
> +
> + iochan = g_io_channel_unix_new(sock);
> + g_io_channel_set_close_on_unref(iochan, TRUE);
> +
> + id = g_io_add_watch(iochan, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
> + hal_session_event, &sock);
> +
> + ALOGD("%s: Add chan %p watch id %d", __func__, iochan, id);
why are we bothering with a GLib mainloop here. We are in a threaded environment anyway, so lets just use threads for reader and writer IO.
In addition, I prefer to have the HAL code GLib free. There is really no point in linking GLib into that one.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH] Bluetooth: Use only 2 bits for controller type information
From: Anderson Lizardo @ 2013-09-29 12:59 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: BlueZ development
In-Reply-To: <1380427749-14427-1-git-send-email-marcel@holtmann.org>
Hi Marcel,
On Sun, Sep 29, 2013 at 12:09 AM, Marcel Holtmann <marcel@holtmann.org> wrote:
> The controller type is limited to BR/EDR/LE and AMP controllers. This
> can be easily encoded with just 2 bits and still leave enough room
> for future controller types.
>
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
> net/bluetooth/hci_core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index 4549b5c..ebba5a6 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -1610,7 +1610,7 @@ int hci_get_dev_info(void __user *arg)
>
> strcpy(di.name, hdev->name);
> di.bdaddr = hdev->bdaddr;
> - di.type = (hdev->bus & 0x0f) | (hdev->dev_type << 4);
> + di.type = (hdev->bus & 0x0f) | ((hdev->dev_type & 0x30) << 4);
Shouldn't it be (hdev->dev_type & 0x03) here?
Best Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* [PATCH] Bluetooth: Provide high speed configuration option
From: Marcel Holtmann @ 2013-09-29 10:53 UTC (permalink / raw)
To: linux-bluetooth
Hiding the Bluetooth high speed support behind a module parameter is
not really useful. This can be enabled and disabled at runtime via
the management interface. This also has the advantage that his can
now be changed per controller and not just global.
This patch removes the module parameter and exposes the high speed
setting of the management interface to all controllers.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
include/net/bluetooth/l2cap.h | 1 +
net/bluetooth/hci_core.c | 6 ------
net/bluetooth/l2cap_core.c | 35 +++++++++++++++++++----------------
net/bluetooth/l2cap_sock.c | 10 ----------
net/bluetooth/mgmt.c | 12 +-----------
5 files changed, 21 insertions(+), 43 deletions(-)
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 1a966af..f141b5f 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -564,6 +564,7 @@ struct l2cap_conn {
__u32 feat_mask;
__u8 fixed_chan_mask;
+ bool hs_enabled;
__u8 info_state;
__u8 info_ident;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 4549b5c..450a6c8 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1222,12 +1222,6 @@ int hci_dev_open(__u16 dev)
ret = hdev->setup(hdev);
if (!ret) {
- /* Treat all non BR/EDR controllers as raw devices if
- * enable_hs is not set.
- */
- if (hdev->dev_type != HCI_BREDR && !enable_hs)
- set_bit(HCI_RAW, &hdev->flags);
-
if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks))
set_bit(HCI_RAW, &hdev->flags);
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index d1f1e78..6d42498 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1016,13 +1016,12 @@ static bool __amp_capable(struct l2cap_chan *chan)
{
struct l2cap_conn *conn = chan->conn;
- if (enable_hs &&
- hci_amp_capable() &&
+ if (conn->hs_enabled && hci_amp_capable() &&
chan->chan_policy == BT_CHANNEL_POLICY_AMP_PREFERRED &&
conn->fixed_chan_mask & L2CAP_FC_A2MP)
return true;
- else
- return false;
+
+ return false;
}
static bool l2cap_check_efs(struct l2cap_chan *chan)
@@ -1638,6 +1637,10 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon)
conn->feat_mask = 0;
+ if (hcon->type == ACL_LINK)
+ conn->hs_enabled = test_bit(HCI_HS_ENABLED,
+ &hcon->hdev->dev_flags);
+
spin_lock_init(&conn->lock);
mutex_init(&conn->chan_lock);
@@ -3084,14 +3087,14 @@ static inline __u8 l2cap_select_mode(__u8 mode, __u16 remote_feat_mask)
}
}
-static inline bool __l2cap_ews_supported(struct l2cap_chan *chan)
+static inline bool __l2cap_ews_supported(struct l2cap_conn *conn)
{
- return enable_hs && chan->conn->feat_mask & L2CAP_FEAT_EXT_WINDOW;
+ return conn->hs_enabled && conn->feat_mask & L2CAP_FEAT_EXT_WINDOW;
}
-static inline bool __l2cap_efs_supported(struct l2cap_chan *chan)
+static inline bool __l2cap_efs_supported(struct l2cap_conn *conn)
{
- return enable_hs && chan->conn->feat_mask & L2CAP_FEAT_EXT_FLOW;
+ return conn->hs_enabled && conn->feat_mask & L2CAP_FEAT_EXT_FLOW;
}
static void __l2cap_set_ertm_timeouts(struct l2cap_chan *chan,
@@ -3135,7 +3138,7 @@ static void __l2cap_set_ertm_timeouts(struct l2cap_chan *chan,
static inline void l2cap_txwin_setup(struct l2cap_chan *chan)
{
if (chan->tx_win > L2CAP_DEFAULT_TX_WINDOW &&
- __l2cap_ews_supported(chan)) {
+ __l2cap_ews_supported(chan->conn)) {
/* use extended control field */
set_bit(FLAG_EXT_CTRL, &chan->flags);
chan->tx_win_max = L2CAP_DEFAULT_EXT_WINDOW;
@@ -3165,7 +3168,7 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)
if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state))
break;
- if (__l2cap_efs_supported(chan))
+ if (__l2cap_efs_supported(chan->conn))
set_bit(FLAG_EFS_ENABLE, &chan->flags);
/* fall through */
@@ -3317,7 +3320,7 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
break;
case L2CAP_CONF_EWS:
- if (!enable_hs)
+ if (!chan->conn->hs_enabled)
return -ECONNREFUSED;
set_bit(FLAG_EXT_CTRL, &chan->flags);
@@ -3349,7 +3352,7 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
}
if (remote_efs) {
- if (__l2cap_efs_supported(chan))
+ if (__l2cap_efs_supported(chan->conn))
set_bit(FLAG_EFS_ENABLE, &chan->flags);
else
return -ECONNREFUSED;
@@ -4303,7 +4306,7 @@ static inline int l2cap_information_req(struct l2cap_conn *conn,
if (!disable_ertm)
feat_mask |= L2CAP_FEAT_ERTM | L2CAP_FEAT_STREAMING
| L2CAP_FEAT_FCS;
- if (enable_hs)
+ if (conn->hs_enabled)
feat_mask |= L2CAP_FEAT_EXT_FLOW
| L2CAP_FEAT_EXT_WINDOW;
@@ -4314,7 +4317,7 @@ static inline int l2cap_information_req(struct l2cap_conn *conn,
u8 buf[12];
struct l2cap_info_rsp *rsp = (struct l2cap_info_rsp *) buf;
- if (enable_hs)
+ if (conn->hs_enabled)
l2cap_fixed_chan[0] |= L2CAP_FC_A2MP;
else
l2cap_fixed_chan[0] &= ~L2CAP_FC_A2MP;
@@ -4411,7 +4414,7 @@ static int l2cap_create_channel_req(struct l2cap_conn *conn,
if (cmd_len != sizeof(*req))
return -EPROTO;
- if (!enable_hs)
+ if (!conn->hs_enabled)
return -EINVAL;
psm = le16_to_cpu(req->psm);
@@ -4838,7 +4841,7 @@ static inline int l2cap_move_channel_req(struct l2cap_conn *conn,
BT_DBG("icid 0x%4.4x, dest_amp_id %d", icid, req->dest_amp_id);
- if (!enable_hs)
+ if (!conn->hs_enabled)
return -EINVAL;
chan = l2cap_get_chan_by_dcid(conn, icid);
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index c85537c..9119898 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -445,11 +445,6 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,
break;
case BT_CHANNEL_POLICY:
- if (!enable_hs) {
- err = -ENOPROTOOPT;
- break;
- }
-
if (put_user(chan->chan_policy, (u32 __user *) optval))
err = -EFAULT;
break;
@@ -720,11 +715,6 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
break;
case BT_CHANNEL_POLICY:
- if (!enable_hs) {
- err = -ENOPROTOOPT;
- break;
- }
-
if (get_user(opt, (u32 __user *) optval)) {
err = -EFAULT;
break;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 1b5b10f..035744d 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -32,8 +32,6 @@
#include <net/bluetooth/mgmt.h>
#include <net/bluetooth/smp.h>
-bool enable_hs;
-
#define MGMT_VERSION 1
#define MGMT_REVISION 3
@@ -382,8 +380,7 @@ static u32 get_supported_settings(struct hci_dev *hdev)
settings |= MGMT_SETTING_LINK_SECURITY;
}
- if (enable_hs)
- settings |= MGMT_SETTING_HS;
+ settings |= MGMT_SETTING_HS;
if (lmp_le_capable(hdev)) {
settings |= MGMT_SETTING_LE;
@@ -1344,10 +1341,6 @@ static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
BT_DBG("request for %s", hdev->name);
- if (!enable_hs)
- return cmd_status(sk, hdev->id, MGMT_OP_SET_HS,
- MGMT_STATUS_NOT_SUPPORTED);
-
if (cp->val != 0x00 && cp->val != 0x01)
return cmd_status(sk, hdev->id, MGMT_OP_SET_HS,
MGMT_STATUS_INVALID_PARAMS);
@@ -4396,6 +4389,3 @@ int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
return mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &ev, sizeof(ev),
cmd ? cmd->sk : NULL);
}
-
-module_param(enable_hs, bool, 0644);
-MODULE_PARM_DESC(enable_hs, "Enable High Speed support");
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCH 2/2] obexd:Add get_address property to transfer properties
From: Luiz Augusto von Dentz @ 2013-09-29 8:40 UTC (permalink / raw)
To: Wu Zheng; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1380008250-30536-1-git-send-email-wu.zheng@intel.com>
Hi,
On Tue, Sep 24, 2013 at 10:37 AM, Wu Zheng <wu.zheng@intel.com> wrote:
> Sometime, address is needed by the Bluetooth OBEX APP.
> Therefore, add the property to transfer properties
> ---
> obexd/src/manager.c | 37 +++++++++++++++++++++++++++++++++++++
> 1 files changed, 37 insertions(+), 0 deletions(-)
>
> diff --git a/obexd/src/manager.c b/obexd/src/manager.c
> index 96976ec..b338a72 100644
> --- a/obexd/src/manager.c
> +++ b/obexd/src/manager.c
> @@ -551,6 +551,41 @@ static gboolean transfer_get_operation(const GDBusPropertyTable *property,
> return TRUE;
> }
>
> +static gboolean transfer_address_exists(const GDBusPropertyTable *property,
> + void *data)
> +{
> + struct obex_transfer *transfer = data;
> + struct obex_session *session = transfer->session;
> + char *address;
> + int err;
> +
> + err = obex_getpeername(session, &address);
> + if (err < 0)
> + return FALSE;
> +
> + g_free(address);
> +
> + return TRUE;
> +}
> +
> +static gboolean transfer_get_address(const GDBusPropertyTable *property,
> + DBusMessageIter *iter, void *data)
> +{
> + struct obex_transfer *transfer = data;
> + struct obex_session *session = transfer->session;
> + char *address;
> + int err;
> +
> + err = obex_getpeername(session, &address);
> + if (err < 0)
> + return FALSE;
> +
> + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &address);
> + g_free(address);
> +
> + return TRUE;
> +}
> +
> static gboolean transfer_get_transferred(const GDBusPropertyTable *property,
> DBusMessageIter *iter, void *data)
> {
> @@ -587,6 +622,8 @@ static const GDBusPropertyTable transfer_properties[] = {
> transfer_filename_exists },
> { "Operation", "s", transfer_get_operation, NULL,
> transfer_operation_exists },
> + { "Address", "s", transfer_get_address, NULL,
> + transfer_address_exists },
> { "Transferred", "t", transfer_get_transferred },
> { }
> };
> --
> 1.7.7
Nack, you can already access the Address via Session interface.
--
Luiz Augusto von Dentz
^ permalink raw reply
* Re: FW: [PATCH 1/2] obexd:Add Operation property to transfer properties
From: Luiz Augusto von Dentz @ 2013-09-29 8:38 UTC (permalink / raw)
To: Zheng, Wu
Cc: Von Dentz, Luiz, Hedberg, Johan, linux-bluetooth@vger.kernel.org
In-Reply-To: <2CF57A644018A745B8FE029C7223E16E1179670E@SHSMSX104.ccr.corp.intel.com>
Hi,
On Sun, Sep 29, 2013 at 6:03 AM, Zheng, Wu <wu.zheng@intel.com> wrote:
> Hi Luiz,
>
> Can you help review the patches? Thanks
First, please do not top post.
> Best Regards
> Zheng Wu
>
>>-----Original Message-----
>>From: linux-bluetooth-owner@vger.kernel.org
>>[mailto:linux-bluetooth-owner@vger.kernel.org] On Behalf Of Wu Zheng
>>Sent: Tuesday, September 24, 2013 3:37 PM
>>To: linux-bluetooth@vger.kernel.org
>>Cc: Zheng, Wu
>>Subject: [PATCH 1/2] obexd:Add Operation property to transfer properties
>>
>>Sometime, operation property is needed by the Bluetooth APP.
>>Therefore, add the property to transfer properties
>>---
You probably need to work on to why we need such property, I have no
idea what you are reference to a Bluetooth APP, obviously is not the
application that have created the transfer since that know should know
what operation will be used.
If this is for some kind of download manager application that you are
talking about Im not sure why it would like to know the operation? Is
that to display the direction? Im not really sure this will be
convenient for a download manager but I would not expose the operation
itself probably upload/download or add new status
uploading/downloading.
--
Luiz Augusto von Dentz
^ permalink raw reply
* [RFC] Bluetooth: Add command for setting static address
From: Marcel Holtmann @ 2013-09-29 8:05 UTC (permalink / raw)
To: linux-bluetooth
Add command for setting static address for use as LE random address.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
include/net/bluetooth/hci.h | 2 ++
include/net/bluetooth/hci_core.h | 1 +
include/net/bluetooth/mgmt.h | 6 ++++++
net/bluetooth/hci_core.c | 5 +++++
net/bluetooth/mgmt.c | 43 +++++++++++++++++++++++++++++++++++++++-
5 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 7ede266..809bdf8 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -977,6 +977,8 @@ struct hci_rp_le_read_local_features {
__u8 features[8];
} __packed;
+#define HCI_OP_LE_SET_RANDOM_ADDR 0x2005
+
#define HCI_OP_LE_READ_ADV_TX_POWER 0x2007
struct hci_rp_le_read_adv_tx_power {
__u8 status;
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 26cc9f7..e09c305 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -140,6 +140,7 @@ struct hci_dev {
__u8 bus;
__u8 dev_type;
bdaddr_t bdaddr;
+ bdaddr_t static_addr;
__u8 dev_name[HCI_MAX_NAME_LENGTH];
__u8 short_name[HCI_MAX_SHORT_NAME_LENGTH];
__u8 eir[HCI_MAX_EIR_LENGTH];
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 421d763..823ec2d 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -354,6 +354,12 @@ struct mgmt_cp_set_device_id {
#define MGMT_OP_SET_ADVERTISING 0x0029
+#define MGMT_OP_SET_STATIC_ADDRESS 0x002B
+struct mgmt_cp_set_static_address {
+ bdaddr_t bdaddr;
+} __packed;
+#define MGMT_SET_STATIC_ADDRESS_SIZE 6
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 4549b5c..3f1fb1b 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -393,6 +393,11 @@ static void le_setup(struct hci_request *req)
/* LE-only controllers have LE implicitly enabled */
if (!lmp_bredr_capable(hdev))
set_bit(HCI_LE_ENABLED, &hdev->dev_flags);
+
+ /* Set random address to static address if configured */
+ if (bacmp(&hdev->static_addr, BDADDR_ANY))
+ hci_req_add(req, HCI_OP_LE_SET_RANDOM_ADDR, 6,
+ &hdev->static_addr);
}
static u8 hci_get_inquiry_mode(struct hci_dev *hdev)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 1b5b10f..fdc591b 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -77,6 +77,7 @@ static const u16 mgmt_commands[] = {
MGMT_OP_UNBLOCK_DEVICE,
MGMT_OP_SET_DEVICE_ID,
MGMT_OP_SET_ADVERTISING,
+ MGMT_OP_SET_STATIC_ADDRESS,
};
static const u16 mgmt_events[] = {
@@ -3230,6 +3231,46 @@ unlock:
return err;
}
+static int set_static_address(struct sock *sk, struct hci_dev *hdev,
+ void *data, u16 len)
+{
+ struct mgmt_cp_set_static_address *cp = data;
+ int err;
+
+ BT_DBG("%s", hdev->name);
+
+ if (!lmp_le_capable(hdev))
+ return cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS,
+ MGMT_STATUS_NOT_SUPPORTED);
+
+ if (hdev_is_powered(hdev))
+ return cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS,
+ MGMT_STATUS_BUSY);
+
+ if (bacmp(&cp->bdaddr, BDADDR_ANY)) {
+ if (!bacmp(&cp->bdaddr, BDADDR_NONE))
+ return cmd_status(sk, hdev->id,
+ MGMT_OP_SET_STATIC_ADDRESS,
+ MGMT_STATUS_INVALID_PARAMS);
+
+ /* Two most significant bits shall be set */
+ if ((cp->bdaddr.b[5] & 0xc0) != 0xc0)
+ return cmd_status(sk, hdev->id,
+ MGMT_OP_SET_STATIC_ADDRESS,
+ MGMT_STATUS_INVALID_PARAMS);
+ }
+
+ hci_dev_lock(hdev);
+
+ bacpy(&hdev->static_addr, &cp->bdaddr);
+
+ err = cmd_complete(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, 0, NULL, 0);
+
+ hci_dev_unlock(hdev);
+
+ return err;
+}
+
static void fast_connectable_complete(struct hci_dev *hdev, u8 status)
{
struct pending_cmd *cmd;
@@ -3442,9 +3483,9 @@ static const struct mgmt_handler {
{ unblock_device, false, MGMT_UNBLOCK_DEVICE_SIZE },
{ set_device_id, false, MGMT_SET_DEVICE_ID_SIZE },
{ set_advertising, false, MGMT_SETTING_SIZE },
+ { set_static_address, false, MGMT_SET_STATIC_ADDRESS_SIZE },
};
-
int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
{
void *buf;
--
1.8.3.1
^ permalink raw reply related
* [PATCH] Bluetooth: Replace BDADDR_LOCAL with BDADDR_NONE
From: Marcel Holtmann @ 2013-09-29 8:01 UTC (permalink / raw)
To: linux-bluetooth
The BDADDR_LOCAL is a relict from userspace and has never been used
within the kernel. So remove that constant and replace it with a new
BDADDR_NONE that is similar to HCI_DEV_NONE with all bits set.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
include/net/bluetooth/bluetooth.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index afbc711..5fd5106 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -197,8 +197,8 @@ static inline bool bdaddr_type_is_le(__u8 type)
return false;
}
-#define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0} })
-#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff} })
+#define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
+#define BDADDR_NONE (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
/* Copy, swap, convert BD Address */
static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
--
1.8.3.1
^ permalink raw reply related
* [PATCH] Bluetooth: Use only 2 bits for controller type information
From: Marcel Holtmann @ 2013-09-29 4:09 UTC (permalink / raw)
To: linux-bluetooth
The controller type is limited to BR/EDR/LE and AMP controllers. This
can be easily encoded with just 2 bits and still leave enough room
for future controller types.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
net/bluetooth/hci_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 4549b5c..ebba5a6 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1610,7 +1610,7 @@ int hci_get_dev_info(void __user *arg)
strcpy(di.name, hdev->name);
di.bdaddr = hdev->bdaddr;
- di.type = (hdev->bus & 0x0f) | (hdev->dev_type << 4);
+ di.type = (hdev->bus & 0x0f) | ((hdev->dev_type & 0x30) << 4);
di.flags = hdev->flags;
di.pkt_type = hdev->pkt_type;
if (lmp_bredr_capable(hdev)) {
--
1.8.3.1
^ permalink raw reply related
* FW: [PATCH 1/2] obexd:Add Operation property to transfer properties
From: Zheng, Wu @ 2013-09-29 3:03 UTC (permalink / raw)
To: Von Dentz, Luiz; +Cc: Hedberg, Johan, linux-bluetooth@vger.kernel.org
In-Reply-To: <1380008221-30501-1-git-send-email-wu.zheng@intel.com>
Hi Luiz,
Can you help review the patches? Thanks
Best Regards
Zheng Wu
>-----Original Message-----
>From: linux-bluetooth-owner@vger.kernel.org
>[mailto:linux-bluetooth-owner@vger.kernel.org] On Behalf Of Wu Zheng
>Sent: Tuesday, September 24, 2013 3:37 PM
>To: linux-bluetooth@vger.kernel.org
>Cc: Zheng, Wu
>Subject: [PATCH 1/2] obexd:Add Operation property to transfer properties
>
>Sometime, operation property is needed by the Bluetooth APP.
>Therefore, add the property to transfer properties
>---
> obexd/src/manager.c | 38
>++++++++++++++++++++++++++++++++++++++
> 1 files changed, 38 insertions(+), 0 deletions(-)
>
>diff --git a/obexd/src/manager.c b/obexd/src/manager.c index
>f64b7b9..96976ec 100644
>--- a/obexd/src/manager.c
>+++ b/obexd/src/manager.c
>@@ -35,6 +35,7 @@
>
> #include <btio/btio.h>
> #include <gobex/gobex.h>
>+#include <gobex/gobex-packet.h>
>
> #include "obexd.h"
> #include "obex.h"
>@@ -515,6 +516,41 @@ static gboolean transfer_get_filename(const
>GDBusPropertyTable *property,
> return TRUE;
> }
>
>+static gboolean transfer_operation_exists(const GDBusPropertyTable
>*property,
>+ void *data)
>+{
>+ struct obex_transfer *transfer = data;
>+ struct obex_session *session = transfer->session;
>+
>+ if (session->cmd == G_OBEX_OP_PUT &&
>+ session->size != OBJECT_SIZE_DELETE)
>+ return TRUE;
>+ else if (session->cmd == G_OBEX_OP_GET)
>+ return TRUE;
>+ else
>+ return FALSE;
>+}
>+
>+static gboolean transfer_get_operation(const GDBusPropertyTable
>*property,
>+ DBusMessageIter *iter, void *data) {
>+ struct obex_transfer *transfer = data;
>+ struct obex_session *session = transfer->session;
>+ const char *operation;
>+
>+ if (session->cmd == G_OBEX_OP_PUT &&
>+ session->size != OBJECT_SIZE_DELETE)
>+ operation = "PUT";
>+ else if (session->cmd == G_OBEX_OP_GET)
>+ operation = "GET";
>+ else
>+ return FALSE;
>+
>+ dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
>&operation);
>+
>+ return TRUE;
>+}
>+
> static gboolean transfer_get_transferred(const GDBusPropertyTable
>*property,
> DBusMessageIter *iter, void *data) { @@ -549,6
>+585,8 @@ static const GDBusPropertyTable transfer_properties[] = {
> { "Time", "t", transfer_get_time, NULL, transfer_time_exists },
> { "Filename", "s", transfer_get_filename, NULL,
> transfer_filename_exists },
>+ { "Operation", "s", transfer_get_operation, NULL,
>+ transfer_operation_exists },
> { "Transferred", "t", transfer_get_transferred },
> { }
> };
>--
>1.7.7
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
>the body of a message to majordomo@vger.kernel.org More majordomo
>info at http://vger.kernel.org/majordomo-info.html
^ 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