* Re: [PATCH] Bluetooth: Add function name to debug prints
From: Johan Hedberg @ 2013-10-22 7:29 UTC (permalink / raw)
To: Jukka Rissanen; +Cc: linux-bluetooth
In-Reply-To: <1382425751-9018-1-git-send-email-jukka.rissanen@linux.intel.com>
Hi Jukka,
On Tue, Oct 22, 2013, Jukka Rissanen wrote:
> the debug prints are quite useless without the function name.
> Without this patch one sees lot of "hci0" lines which is not
> very helpful.
>
> Cheers,
> Jukka
>
> include/net/bluetooth/bluetooth.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
> index bf2ddff..0b1eacd 100644
> --- a/include/net/bluetooth/bluetooth.h
> +++ b/include/net/bluetooth/bluetooth.h
> @@ -122,7 +122,7 @@ int bt_err(const char *fmt, ...);
>
> #define BT_INFO(fmt, ...) bt_info(fmt "\n", ##__VA_ARGS__)
> #define BT_ERR(fmt, ...) bt_err(fmt "\n", ##__VA_ARGS__)
> -#define BT_DBG(fmt, ...) pr_debug(fmt "\n", ##__VA_ARGS__)
> +#define BT_DBG(fmt, ...) pr_debug("%s():" fmt "\n", __FUNCTION__, ##__VA_ARGS__)
This shouldn't be necessary since you can ask the function name to be
printed using standard dynamic debug control syntax, e.g:
echo "file hci_event.c +pf" > /sys/kernel/debug/dynamic_debug/control
Johan
^ permalink raw reply
* [PATCH] android: Improve hal_ipc_cmd helper
From: Szymon Janc @ 2013-10-22 7:17 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Handle error response inside helper so that users don't expecting any
response don't need to provide dummy buffer only for error (which is
already return value of helper).
---
android/hal-bluetooth.c | 7 ++-----
android/hal-ipc.c | 6 ++++++
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index f408a7d..5b07070 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -40,7 +40,6 @@ static bool interface_ready(void)
static int init(bt_callbacks_t *callbacks)
{
struct hal_msg_cmd_register_module cmd;
- struct hal_msg_rsp_error rsp;
DBG("");
@@ -55,8 +54,7 @@ static int init(bt_callbacks_t *callbacks)
cmd.service_id = HAL_SERVICE_ID_BLUETOOTH;
if (hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_MSG_OP_REGISTER_MODULE,
- sizeof(cmd), &cmd,
- sizeof(rsp), &rsp, NULL) < 0) {
+ sizeof(cmd), &cmd, 0, NULL, NULL) < 0) {
error("Failed to register 'bluetooth' service");
goto fail;
}
@@ -64,8 +62,7 @@ static int init(bt_callbacks_t *callbacks)
cmd.service_id = HAL_SERVICE_ID_SOCK;
if (hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_MSG_OP_REGISTER_MODULE,
- sizeof(cmd), &cmd,
- sizeof(rsp), &rsp, NULL) < 0) {
+ sizeof(cmd), &cmd, 0, NULL, NULL) < 0) {
error("Failed to register 'socket' service");
goto fail;
}
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 5b77adf..8d40271 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -146,10 +146,16 @@ int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,
struct iovec iv[2];
struct hal_msg_hdr hal_msg;
char cmsgbuf[CMSG_SPACE(sizeof(int))];
+ struct hal_msg_rsp_error err;
if (cmd_sk < 0)
return -EBADF;
+ if (!rsp || rsp_len == 0) {
+ memset(&err, 0, sizeof(err));
+ rsp = &err;
+ }
+
memset(&msg, 0, sizeof(msg));
memset(&hal_msg, 0, sizeof(hal_msg));
--
1.8.4
^ permalink raw reply related
* [PATCH] Bluetooth: Add function name to debug prints
From: Jukka Rissanen @ 2013-10-22 7:09 UTC (permalink / raw)
To: linux-bluetooth
---
Hi,
the debug prints are quite useless without the function name.
Without this patch one sees lot of "hci0" lines which is not
very helpful.
Cheers,
Jukka
include/net/bluetooth/bluetooth.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index bf2ddff..0b1eacd 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -122,7 +122,7 @@ int bt_err(const char *fmt, ...);
#define BT_INFO(fmt, ...) bt_info(fmt "\n", ##__VA_ARGS__)
#define BT_ERR(fmt, ...) bt_err(fmt "\n", ##__VA_ARGS__)
-#define BT_DBG(fmt, ...) pr_debug(fmt "\n", ##__VA_ARGS__)
+#define BT_DBG(fmt, ...) pr_debug("%s():" fmt "\n", __FUNCTION__, ##__VA_ARGS__)
/* Connection and socket states */
enum {
--
1.7.11.7
^ permalink raw reply related
* Re: [PATCH] android: Add missing HAL IPC error status definitions
From: Johan Hedberg @ 2013-10-22 7:03 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1382424852-8049-1-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
On Tue, Oct 22, 2013, Szymon Janc wrote:
> ---
> android/hal-msg.h | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/android/hal-msg.h b/android/hal-msg.h
> index 1f77586..7d91ed1 100644
> --- a/android/hal-msg.h
> +++ b/android/hal-msg.h
> @@ -47,6 +47,15 @@ struct hal_msg_hdr {
> /* Core Service */
>
> #define HAL_ERROR_FAILED 0x01
> +#define HAL_ERROR_NOT_READY 0x02
> +#define HAL_ERROR_NOMEM 0x03
> +#define HAL_ERROR_BUSY 0x04
> +#define HAL_ERROR_DONE 0x05
> +#define HAL_ERROR_UNSUPPORTED 0x06
> +#define HAL_ERROR_INVALID 0x07
> +#define HAL_ERROR_UNHANDLED 0x08
> +#define HAL_ERROR_AUTH_FAILURE 0x09
> +#define HAL_ERROR_REMOTE_DEVICE_DOWN 0x0A
Applied after a minor s/0A/0a/ change to make this consistent with the
rest of the header file.
Johan
^ permalink raw reply
* [PATCH] android: Add missing HAL IPC error status definitions
From: Szymon Janc @ 2013-10-22 6:54 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
android/hal-msg.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 1f77586..7d91ed1 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -47,6 +47,15 @@ struct hal_msg_hdr {
/* Core Service */
#define HAL_ERROR_FAILED 0x01
+#define HAL_ERROR_NOT_READY 0x02
+#define HAL_ERROR_NOMEM 0x03
+#define HAL_ERROR_BUSY 0x04
+#define HAL_ERROR_DONE 0x05
+#define HAL_ERROR_UNSUPPORTED 0x06
+#define HAL_ERROR_INVALID 0x07
+#define HAL_ERROR_UNHANDLED 0x08
+#define HAL_ERROR_AUTH_FAILURE 0x09
+#define HAL_ERROR_REMOTE_DEVICE_DOWN 0x0A
#define HAL_MSG_OP_ERROR 0x00
struct hal_msg_rsp_error {
--
1.8.4
^ permalink raw reply related
* [PATCH] android: Add capabilities and set userid
From: Andrei Emeltchenko @ 2013-10-22 6:35 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
The patch set UID as standard Bluetooth user for Android (AID_BLUETOOTH).
It also sets the same capability needed for systemd service (found
in src/bluetooth.service.
---
android/main.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 4 ++++
2 files changed, 57 insertions(+)
diff --git a/android/main.c b/android/main.c
index fac1003..e7f842e 100644
--- a/android/main.c
+++ b/android/main.c
@@ -33,10 +33,17 @@
#include <stdbool.h>
#include <string.h>
#include <errno.h>
+#include <unistd.h>
+
#include <sys/signalfd.h>
#include <sys/socket.h>
#include <sys/un.h>
+#if defined(ANDROID)
+#include <sys/prctl.h>
+#include <private/android_filesystem_config.h>
+#endif
+
#include <glib.h>
#include "log.h"
@@ -409,6 +416,49 @@ static void cleanup_hal_connection(void)
}
}
+static bool set_capabilities(void)
+{
+#if defined(ANDROID)
+ struct __user_cap_header_struct header;
+ struct __user_cap_data_struct cap;
+
+ DBG("pid %d uid %d gid %d", getpid(), getuid(), getgid());
+
+ header.version = _LINUX_CAPABILITY_VERSION;
+
+ prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
+
+ if (setgid(AID_BLUETOOTH) < 0)
+ warn("%s: setgid(): %s", __func__, strerror(errno));
+
+ if (setuid(AID_BLUETOOTH) < 0)
+ warn("%s: setuid(): %s", __func__, strerror(errno));
+
+ header.version = _LINUX_CAPABILITY_VERSION;
+ header.pid = 0;
+
+ cap.effective = cap.permitted =
+ 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 (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());
+#endif
+ return true;
+}
+
int main(int argc, char *argv[])
{
GOptionContext *context;
@@ -442,6 +492,9 @@ int main(int argc, char *argv[])
__btd_log_init("*", 0);
+ if (!set_capabilities())
+ return EXIT_FAILURE;
+
if (!init_mgmt_interface())
return EXIT_FAILURE;
diff --git a/configure.ac b/configure.ac
index b4d3998..e3b5220 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.8.1.2
^ permalink raw reply related
* [PATCH] android: Add capabilities and set userid
From: Andrei Emeltchenko @ 2013-10-22 6:28 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
The patch set UID as standard Bluetooth user for Android (AID_BLUETOOTH).
It also sets the same capability needed for systemd service (found
in src/bluetooth.service.
---
android/main.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 4 ++++
2 files changed, 57 insertions(+)
diff --git a/android/main.c b/android/main.c
index fac1003..e7f842e 100644
--- a/android/main.c
+++ b/android/main.c
@@ -33,10 +33,17 @@
#include <stdbool.h>
#include <string.h>
#include <errno.h>
+#include <unistd.h>
+
#include <sys/signalfd.h>
#include <sys/socket.h>
#include <sys/un.h>
+#if defined(ANDROID)
+#include <sys/prctl.h>
+#include <private/android_filesystem_config.h>
+#endif
+
#include <glib.h>
#include "log.h"
@@ -409,6 +416,49 @@ static void cleanup_hal_connection(void)
}
}
+static bool set_capabilities(void)
+{
+#if defined(ANDROID)
+ struct __user_cap_header_struct header;
+ struct __user_cap_data_struct cap;
+
+ DBG("pid %d uid %d gid %d", getpid(), getuid(), getgid());
+
+ header.version = _LINUX_CAPABILITY_VERSION;
+
+ prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
+
+ if (setgid(AID_BLUETOOTH) < 0)
+ warn("%s: setgid(): %s", __func__, strerror(errno));
+
+ if (setuid(AID_BLUETOOTH) < 0)
+ warn("%s: setuid(): %s", __func__, strerror(errno));
+
+ header.version = _LINUX_CAPABILITY_VERSION;
+ header.pid = 0;
+
+ cap.effective = cap.permitted =
+ 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 (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());
+#endif
+ return true;
+}
+
int main(int argc, char *argv[])
{
GOptionContext *context;
@@ -442,6 +492,9 @@ int main(int argc, char *argv[])
__btd_log_init("*", 0);
+ if (!set_capabilities())
+ return EXIT_FAILURE;
+
if (!init_mgmt_interface())
return EXIT_FAILURE;
diff --git a/configure.ac b/configure.ac
index b4d3998..e3b5220 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.8.1.2
^ permalink raw reply related
* Re: GATT - How to mark an attribute as requiring encryption
From: Anderson Lizardo @ 2013-10-22 1:31 UTC (permalink / raw)
To: Scott James Remnant; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <CAHZ1yC=vh0PUS7ZgZ_zUff_gPzLwjYx8EABxbT71uU5zQAChTQ@mail.gmail.com>
Hi Scott,
On Mon, Oct 21, 2013 at 9:01 PM, Scott James Remnant <keybuk@google.com> wrote:
> While there is a way to mark an attribute as needing authentication
> and/or authorization, there does not seem to be a way to mark an
> attribute as requiring encryption (or a particular key size), and I
> couldn't find any code that would return the ATT_ECODE_INSUFF_ENC or
> ATT_ECODE_INSUFF_ENCR_KEY_SIZE responses.
There is a FIXME for this on function att_check_reqs()
(src/attrib-server.c). Feel free to fix it :)
Note that, as part of the ongoing implementation of a D-Bus API for
implementing external GATT services, we have patches (currently being
cleaned up for upstream submission) that will refactor the internal C
API for creating GATT services. If you are interested, take a look at
(note that it is work-in-progress code):
git://git.infradead.org/users/cktakahasi/bluez.git (branch gatt-api-devel)
Also take a look at the API document sent by Claudio a few days ago:
"[RFC BlueZ v0] doc: Add GATT API"
Best Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* GATT - How to mark an attribute as requiring encryption
From: Scott James Remnant @ 2013-10-22 1:01 UTC (permalink / raw)
To: linux-bluetooth@vger.kernel.org
While there is a way to mark an attribute as needing authentication
and/or authorization, there does not seem to be a way to mark an
attribute as requiring encryption (or a particular key size), and I
couldn't find any code that would return the ATT_ECODE_INSUFF_ENC or
ATT_ECODE_INSUFF_ENCR_KEY_SIZE responses.
There is an explicit test case in the GATT TS for this:
TP/GAR/SR/BI-05-C [Read Characteristic Value - Insufficient
Encryption Key Size]
The TRCL maps this:
(GATT:3/8 AND ATT:5/2)
OR
(ATT:3/1 AND ATT:3/10 AND ATT:5/2)
GATT:3/8 [Read Characteristic Value] is Mandatory
ATT:5/2 - [LE Security Mode 1] is Optional, but without it none of the
authentication or authorization stuff makes sense either
Reference:
GATT 4.8.1
ATT 3.4.11, 3.4.4.3
Thoughts?
Scott
--
Scott James Remnant | Chrome OS Systems | keybuk@google.com | Google
^ permalink raw reply
* pull request: bluetooth-next 2013-10-21
From: Gustavo Padovan @ 2013-10-21 22:37 UTC (permalink / raw)
To: linville; +Cc: linux-wireless, linux-bluetooth, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 8588 bytes --]
Hi John,
One more big pull request for 3.13. These are the patches we queued during
last week. Here you will find a lot of improvements to the HCI and L2CAP and
MGMT layers with the main ones being a better debugfs support and end of work
of splitting L2CAP into Core and Socket parts.
Please pull!
Gustavo
---
The following changes since commit 4b836f393bd8ed111857a6ee1865e44627266ec6:
Bluetooth: Read current IAC LAP on controller setup (2013-10-14 19:31:18 -0300)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next for-upstream
for you to fetch changes up to d78a32a8fcf775111ccc9ba611a08ca5c29784b6:
Bluetooth: Remove sk member from struct l2cap_chan (2013-10-21 13:50:56 -0700)
----------------------------------------------------------------
Gustavo Padovan (14):
Bluetooth: Extend state_change() call to report errors too
Bluetooth: Add l2cap_state_change_and_error()
Bluetooth: Access sk_sndtimeo indirectly in l2cap_core.c
Bluetooth: Add chan->ops->set_shutdown()
Bluetooth: Move l2cap_wait_ack() to l2cap_sock.c
Bluetooth: use l2cap_chan_ready() instead of duplicate code
Bluetooth: Remove not used struct sock
Bluetooth: Do not access chan->sk directly
Bluetooth: Hold socket in defer callback in L2CAP socket
Bluetooth: Remove socket lock from l2cap_state_change()
Bluetooth: Remove parent socket usage from l2cap_core.c
Bluetooth: Add L2CAP channel to skb private data
Bluetooth: Use bt_cb(skb)->chan to send raw data back
Bluetooth: Remove sk member from struct l2cap_chan
Johan Hedberg (20):
Bluetooth: Fix L2CAP "Command Reject: Invalid CID" response
Bluetooth: Remove unused command reject mapping for EMSGSIZE
Bluetooth: Remove useless l2cap_err_to_reason function
Bluetooth: Ignore A2MP data on non-BR/EDR links
Bluetooth: Ignore SMP data on non-LE links
Bluetooth: Fix updating the right variable in update_scan_rsp_data()
Bluetooth: Reintroduce socket restrictions for LE sockets
Bluetooth: Convert auto accept timer to use delayed work
Bluetooth: Convert idle timer to use delayed work
Bluetooth: Fix ATT socket backwards compatibility with user space
Bluetooth: Check for flag instead of features in update_scan_rsp_data()
Bluetooth: Check for flag instead of features in update_adv_data()
Bluetooth: Add missing check for BREDR_ENABLED flag in update_class()
Bluetooth: Refactor set_connectable settings update to separate function
Bluetooth: Fix updating settings when there are no HCI commands to send
Bluetooth: Move mgmt_pending_find to avoid forward declarations
Bluetooth: Fix sending write_scan_enable when BR/EDR is disabled
Bluetooth: Move HCI_LIMITED_DISCOVERABLE changes to a general place
Bluetooth: Update Set Discoverable to support LE
Bluetooth: Fix enabling fast connectable on LE-only controllers
Marcel Holtmann (71):
Bluetooth: Fix minor coding style issue in set_connectable()
Bluetooth: Use hci_request for discoverable timeout handling
Bluetooth: Update advertising data based on management commands
Bluetooth: Introduce flag for limited discoverable mode
Bluetooth: Make mgmt_discoverable() return void
Bluetooth: Make mgmt_connectable() return void
Bluetooth: Make mgmt_write_scan_failed() return void
Bluetooth: Update class of device after changing discoverable mode
Bluetooth: Move arming of discoverable timeout to complete handler
Bluetooth: Simplify the code for re-arming discoverable timeout
Bluetooth: Add HCI command structure for writing current IAC LAP
Bluetooth: Add support for entering limited discoverable mode
Bluetooth: Make mgmt_new_link_key() return void
Bluetooth: Move eir_append_data() function into mgmt.c
Bluetooth: Move eir_get_length() function into hci_event.c
Bluetooth: Update class of device on discoverable timeout
Bluetooth: Add l2cap_chan_no_resume stub for A2MP
Bluetooth: Make mgmt_pin_code_request() return void
Bluetooth: Make mgmt_pin_code_reply_complete() return void
Bluetooth: Make mgmt_pin_code_neg_reply_complete() return void
Bluetooth: Make mgmt_auth_failed() return void
Bluetooth: Make mgmt_auth_enable_complete() return void
Bluetooth: Make mgmt_ssp_enable_complete() return void
Bluetooth: Make mgmt_set_class_of_dev_complete() return void
Bluetooth: Make mgmt_set_local_name_complete() return void
Bluetooth: Make mgmt_read_local_oob_data_reply_complete() return void
Bluetooth: Make mgmt_new_ltk() return void
Bluetooth: Rename create_ad into create_adv_data
Bluetooth: Store scan response data in HCI device
Bluetooth: Set the scan response data when needed
Bluetooth: Store device name in scan response data
Bluetooth: Rename update_ad into update_adv_data
Bluetooth: Remove duplicate definitions for advertising event types
Bluetooth: Remove enable_hs declaration
Bluetooth: Socket address parameter for CID is in little endian
Bluetooth: Expose inquiry_cache debugfs only on BR/EDR controllers
Bluetooth: Expose auto_accept_delay debugfs only when SSP is supported
Bluetooth: Expose static address value for LE capable controllers
Bluetooth: Expose current voice setting in debugfs
Bluetooth: Add address type to device blacklist table
Bluetooth: Move blacklist debugfs entry creation into hci_core.c
Bluetooth: Move uuids debugfs entry creation into hci_core.c
Bluetooth: Use IS_ERR_OR_NULL for checking bt_debugfs
Bluetooth: Create HCI device debugfs directory in hci_register_dev
Bluetooth: Create root debugfs directory during module init
Bluetooth: Move device_add handling into hci_register_dev
Bluetooth: Include address type in blacklist debugfs data
Bluetooth: Move idle_timeout and sniff_{min,max}_interval to hci_core.c
Bluetooth: Use BDADDR_BREDR type for old blacklist ioctl interface
Bluetooth: Use hcon directly instead of conn->hcon where possible
Bluetooth: Block ATT connection on LE when device is blocked
Bluetooth: Move HCI device features into hci_core.c
Bluetooth: Add workaround for buggy max_page features page value
Bluetooth: Remove debug entry for connection features
Bluetooth: Move manufacturer, hci_ver and hci_rev into hci_core.c
Bluetooth: Store local version information only during setup phase
Bluetooth: Move export of class of device information into hci_core.c
Bluetooth: Expose current list of link keys via debugfs
Bluetooth: Remove bus attribute in favor of hierarchy
Bluetooth: Expose white list size information in debugfs
Bluetooth: Expose current list of long term keys via debugfs
Bluetooth: Select the own address type during initial setup phase
Bluetooth: Expose debugfs entry read/write own address type
Bluetooth: Expose setting if debug keys are used or not
Bluetooth: Add LE features to debugfs if available
Bluetooth: Remove interval parameter from HCI connection
Bluetooth: Add support for setting SSP debug mode
Bluetooth: Expose debugfs settings for LE connection interval
Bluetooth: Add support for setting DUT mode
Bluetooth: Fix UUID values in debugfs file
Bluetooth: Fix minor coding style issue in hci_core.c
include/net/bluetooth/bluetooth.h | 1 +
include/net/bluetooth/hci.h | 35 ++-
include/net/bluetooth/hci_core.h | 89 +++----
include/net/bluetooth/l2cap.h | 20 +-
net/bluetooth/a2mp.c | 9 +-
net/bluetooth/af_bluetooth.c | 9 +-
net/bluetooth/hci_conn.c | 48 ++--
net/bluetooth/hci_core.c | 803 +++++++++++++++++++++++++++++++++++++++++++++++++--------
net/bluetooth/hci_event.c | 59 +++--
net/bluetooth/hci_sock.c | 4 +-
net/bluetooth/hci_sysfs.c | 373 ---------------------------
net/bluetooth/l2cap_core.c | 227 ++++++----------
net/bluetooth/l2cap_sock.c | 120 ++++++++-
net/bluetooth/mgmt.c | 637 ++++++++++++++++++++++++++++++++-------------
net/bluetooth/rfcomm/core.c | 14 +-
net/bluetooth/rfcomm/sock.c | 14 +-
net/bluetooth/sco.c | 13 +-
net/bluetooth/smp.c | 4 +-
18 files changed, 1506 insertions(+), 973 deletions(-)
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply
* Re: Issue with the kernel bluetooth HCI_Delete_Stored_Link_Key command patch
From: Pavel Machek @ 2013-10-21 21:58 UTC (permalink / raw)
To: alexandre@maloteaux.net, marcel, gustavo, linux-bluetooth
In-Reply-To: <20131021192021.GA19575@x220.p-661hnu-f1>
Hi!
> > > old 2.0 as it was written "Vista Compatible" on the box : Bus 004
> > > Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth
> > > Dongle (HCI mode)
> <snip>
> > > < HCI Command: Read Local Version Information (0x04|0x0001) plen 0
> > > > HCI Event: Command Complete (0x0e) plen 12
> > > Read Local Version Information (0x04|0x0001) ncmd 1
> > > status 0x00
> > > HCI Version: 2.0 (0x3) HCI Revision: 0x3000
> > > LMP Version: 2.0 (0x3) LMP Subversion: 0x420b
> > > Manufacturer: Broadcom Corporation (15)
> > > < HCI Command: Read BD ADDR (0x04|0x0009) plen 0
> > > > HCI Event: Command Complete (0x0e) plen 10
> > > Read BD ADDR (0x04|0x0009) ncmd 1
> > > status 0x00 bdaddr 00:19:86:00:19:C2
> > > < HCI Command: Read Buffer Size (0x04|0x0005) plen 0
> > > > HCI Event: Command Complete (0x0e) plen 11
> > > Read Buffer Size (0x04|0x0005) ncmd 1
> > > status 0x00
> > > ACL MTU 1017:8 SCO MTU 64:0
> > > < HCI Command: Read Class of Device (0x03|0x0023) plen 0
> > > > HCI Event: Command Complete (0x0e) plen 7
> > > Read Class of Device (0x03|0x0023) ncmd 1
> > > status 0x00 class 0x000000
> > > < HCI Command: Read Local Name (0x03|0x0014) plen 0
> > > > HCI Event: Command Complete (0x0e) plen 252
> > > Read Local Name (0x03|0x0014) ncmd 1
> > > status 0x00 name 'BCM2045B'
>
> There is something very strange in this hardware if it's reporting
> Broadcom on HCI but CSR over USB. Considering that these two companies
> are competitors I'd be inclined to think this HW is by neither one, i.e.
> possibly counterfeit. This, combined with the fact that it's not
> compliant with the Bluetooth specification, is not very likely to
> inspire efforts to get it fixed.
Actually, could you verify that it worked ok in some older kernel? If
so, it definitely _needs_ to be fixed.
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
^ permalink raw reply
* Re: [PATCH 1/3] Bluetooth: Add L2CAP channel to skb private data
From: Marcel Holtmann @ 2013-10-21 20:53 UTC (permalink / raw)
To: Gustavo Padovan; +Cc: linux-bluetooth, Gustavo Padovan
In-Reply-To: <1382386946-19797-1-git-send-email-gustavo@padovan.org>
Hi Gustavo,
> Adding the channel to the skb private data makes possible to us know which
> channel the skb we have came from.
>
> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk
> ---
> include/net/bluetooth/bluetooth.h | 1 +
> net/bluetooth/l2cap_sock.c | 2 ++
> 2 files changed, 3 insertions(+)
all 3 patches have been applied bluetooth-next tree.
Regards
Marcel
^ permalink raw reply
* [PATCH 3/3] Bluetooth: Remove sk member from struct l2cap_chan
From: Gustavo Padovan @ 2013-10-21 20:22 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1382386946-19797-1-git-send-email-gustavo@padovan.org>
From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
There is no access to chan->sk in L2CAP core now. This change marks the
end of the task of splitting L2CAP between Core and Socket, thus sk is now
gone from struct l2cap_chan.
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
include/net/bluetooth/l2cap.h | 2 --
net/bluetooth/l2cap_sock.c | 2 --
2 files changed, 4 deletions(-)
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 3d922b9..5132990 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -435,8 +435,6 @@ struct l2cap_seq_list {
#define L2CAP_SEQ_LIST_TAIL 0x8000
struct l2cap_chan {
- struct sock *sk;
-
struct l2cap_conn *conn;
struct hci_conn *hs_hcon;
struct hci_chan *hs_hchan;
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index cba3162..7cc24d2 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1374,8 +1374,6 @@ static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
l2cap_chan_hold(chan);
- chan->sk = sk;
-
l2cap_pi(sk)->chan = chan;
return sk;
--
1.8.3.1
^ permalink raw reply related
* [PATCH 2/3] Bluetooth: Use bt_cb(skb)->chan to send raw data back
From: Gustavo Padovan @ 2013-10-21 20:22 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1382386946-19797-1-git-send-email-gustavo@padovan.org>
From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Instead of accessing skb->sk in L2CAP core we now compare the channel
a skb belongs to and not send it back if the channel is same. This change
removes another struct socket usage from L2CAP core.
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
net/bluetooth/l2cap_core.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index bb6d35e..0cef677 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -2813,17 +2813,16 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
mutex_lock(&conn->chan_lock);
list_for_each_entry(chan, &conn->chan_l, list) {
- struct sock *sk = chan->sk;
if (chan->chan_type != L2CAP_CHAN_RAW)
continue;
- /* Don't send frame to the socket it came from */
- if (skb->sk == sk)
+ /* Don't send frame to the channel it came from */
+ if (bt_cb(skb)->chan == chan)
continue;
+
nskb = skb_clone(skb, GFP_KERNEL);
if (!nskb)
continue;
-
if (chan->ops->recv(chan, nskb))
kfree_skb(nskb);
}
--
1.8.3.1
^ permalink raw reply related
* [PATCH 1/3] Bluetooth: Add L2CAP channel to skb private data
From: Gustavo Padovan @ 2013-10-21 20:22 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Gustavo Padovan
From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Adding the channel to the skb private data makes possible to us know which
channel the skb we have came from.
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk
---
include/net/bluetooth/bluetooth.h | 1 +
net/bluetooth/l2cap_sock.c | 2 ++
2 files changed, 3 insertions(+)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index bf2ddff..a707a02 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -282,6 +282,7 @@ struct bt_skb_cb {
__u8 incoming;
__u16 expect;
__u8 force_active;
+ struct l2cap_chan *chan;
struct l2cap_ctrl control;
struct hci_req_ctrl req;
bdaddr_t bdaddr;
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index a159b0e..cba3162 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1174,6 +1174,8 @@ static struct sk_buff *l2cap_sock_alloc_skb_cb(struct l2cap_chan *chan,
if (!skb)
return ERR_PTR(err);
+ bt_cb(skb)->chan = chan;
+
return skb;
}
--
1.8.3.1
^ permalink raw reply related
* Re: Issue with the kernel bluetooth HCI_Delete_Stored_Link_Key command patch
From: alexandre @ 2013-10-21 20:06 UTC (permalink / raw)
To: Pavel Machek, Johan Hedberg; +Cc: gustavo, marcel, linux-bluetooth
In-Reply-To: <20131021192021.GA19575@x220.p-661hnu-f1>
[-- Attachment #1: Type: text/plain, Size: 2033 bytes --]
Hi
It seems that i m not the only one in this situation and i managed to fix it by
applying this pending patch :
https://bugzilla.kernel.org/show_bug.cgi?id=60824
Thanks for your answer and time.
> On October 21, 2013 at 3:20 PM Johan Hedberg <johan.hedberg@gmail.com> wrote:
>
>
> Hi,
>
> On Mon, Oct 21, 2013, Pavel Machek wrote:
> > > old 2.0 as it was written "Vista Compatible" on the box : Bus 004
> > > Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth
> > > Dongle (HCI mode)
> <snip>
> > > < HCI Command: Read Local Version Information (0x04|0x0001) plen 0
> > > > HCI Event: Command Complete (0x0e) plen 12
> > > Read Local Version Information (0x04|0x0001) ncmd 1
> > > status 0x00
> > > HCI Version: 2.0 (0x3) HCI Revision: 0x3000
> > > LMP Version: 2.0 (0x3) LMP Subversion: 0x420b
> > > Manufacturer: Broadcom Corporation (15)
> > > < HCI Command: Read BD ADDR (0x04|0x0009) plen 0
> > > > HCI Event: Command Complete (0x0e) plen 10
> > > Read BD ADDR (0x04|0x0009) ncmd 1
> > > status 0x00 bdaddr 00:19:86:00:19:C2
> > > < HCI Command: Read Buffer Size (0x04|0x0005) plen 0
> > > > HCI Event: Command Complete (0x0e) plen 11
> > > Read Buffer Size (0x04|0x0005) ncmd 1
> > > status 0x00
> > > ACL MTU 1017:8 SCO MTU 64:0
> > > < HCI Command: Read Class of Device (0x03|0x0023) plen 0
> > > > HCI Event: Command Complete (0x0e) plen 7
> > > Read Class of Device (0x03|0x0023) ncmd 1
> > > status 0x00 class 0x000000
> > > < HCI Command: Read Local Name (0x03|0x0014) plen 0
> > > > HCI Event: Command Complete (0x0e) plen 252
> > > Read Local Name (0x03|0x0014) ncmd 1
> > > status 0x00 name 'BCM2045B'
>
> There is something very strange in this hardware if it's reporting
> Broadcom on HCI but CSR over USB. Considering that these two companies
> are competitors I'd be inclined to think this HW is by neither one, i.e.
> possibly counterfeit. This, combined with the fact that it's not
> compliant with the Bluetooth specification, is not very likely to
> inspire efforts to get it fixed.
>
> Johan
[-- Attachment #2: Type: text/html, Size: 3721 bytes --]
^ permalink raw reply
* Re: [PATCH -v2 1/5] Bluetooth: Remove not used struct sock
From: Marcel Holtmann @ 2013-10-21 20:01 UTC (permalink / raw)
To: Gustavo Padovan; +Cc: linux-bluetooth, Gustavo Padovan
In-Reply-To: <1382372501-28562-1-git-send-email-gustavo@padovan.org>
Hi Gustavo,
> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>
> It is a leftover from the recent effort of remove sk usage from L2CAP
> core.
>
> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> ---
> net/bluetooth/l2cap_core.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
all 5 patches have been applied to bluetooth-next tree.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH v3 01/11] android/hal: Move IPC and sockets related code to separate file
From: Johan Hedberg @ 2013-10-21 19:58 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1382381811-28123-1-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
On Mon, Oct 21, 2013, Szymon Janc wrote:
> hal-ipc will provide functionality related to IPC initialization and
> sockets handling (including upcoming callbacks thread).
>
> This allow to remove code from bluetooth HAL not related to adapter.
> ---
> Makefile.android | 3 +-
> android/Android.mk | 1 +
> android/hal-bluetooth.c | 118 ++---------------------------------------
> android/hal-ipc.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++
> android/hal-ipc.h | 19 +++++++
> 5 files changed, 163 insertions(+), 115 deletions(-)
> create mode 100644 android/hal-ipc.c
> create mode 100644 android/hal-ipc.h
All patches, except 5/11 (which was unnecessary) have been applied along
with minor fixes. Thanks.
Johan
^ permalink raw reply
* [PATCH] android: Add README file with instructions
From: Szymon Janc @ 2013-10-21 19:47 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This file cotains help on how BlueZ for Android should be build, run
and test.
---
Makefile.android | 2 +-
android/README | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 1 deletion(-)
create mode 100644 android/README
diff --git a/Makefile.android b/Makefile.android
index f5a5834..1252682 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -79,7 +79,7 @@ EXTRA_DIST += android/client/terminal.c \
android/client/history.h \
android/client/terminal.h
-EXTRA_DIST += android/hal-ipc-api.txt
+EXTRA_DIST += android/hal-ipc-api.txt android/README
EXTRA_DIST += android/hardware/bluetooth.h \
android/hardware/bt_av.h \
diff --git a/android/README b/android/README
new file mode 100644
index 0000000..21690d4
--- /dev/null
+++ b/android/README
@@ -0,0 +1,83 @@
+BlueZ for Android
+*****************
+
+Since Android 4.2 there exists a well standardized HAL interface that the
+Bluetooth stack is expected to provide and which enables the easy replacement
+of the stack of choice on Android. Android BlueZ is intended as a drop-in
+replacement to Android provided Bluetooth stack.
+
+More details about BlueZ for Android architecture and components can be found
+in android/hal-apc-api.txt file.
+
+===============================
+Building and running on Android
+===============================
+
+Build requirements
+==================
+
+- GLib - Android 4.2 or later don't provide GLib and one must provide it in
+'external/bluetooth/glib' folder of Android tree. Sample Android GLib port
+is available at https://code.google.com/p/android-bluez.glib/
+
+- Bionic support - BlueZ requires signalfd and timerfd APIs to be provided
+by libc library. Currently only 'master' branch available at
+https://android.googlesource.com/platform/bionic provides all required
+functionality and running BlueZ on older branch requires backporting missing
+features. Sample Bionic for Android on Intel Architecture (Android-IA) with all
+required features backported is available at
+https://code.google.com/p/android-bluez.bionic/
+
+Runtime requirements
+====================
+
+BlueZ HAL library requires 'bluetoothd' service to be available on Android
+system. This can be done by defining service in init.rc file of targeted board:
+
+service bluetoothd logwrapper /system/bin/bluetoothd
+ class main
+ group bluetooth net_bt_stack
+ disabled
+ oneshot
+
+Sample can be found at https://code.google.com/p/android-bluez.system-core/
+
+Downloading and building
+========================
+
+Building for Android requires full Android AOSP source tree. Sample Android-IA
+tree with all required components present is available at
+http://code.google.com/p/android-bluez/
+
+Downloading:
+repo init -u https://code.google.com/p/android-bluez.manifest/ -m topics/bluez
+repo sync
+
+Build for Intel ultrabook:
+'source build/envsetup.sh'
+'lunch core_mesa-eng'
+'make allimages -j8'
+
+After full build is done it is possible to rebuild only BlueZ:
+'cd external/bluetooth/bluez/android/'
+'mm' (or 'mm -B' to force rebuilding of all files)
+'adb sync' to update target device.
+
+=============================
+Building and running on Linux
+=============================
+It is possible to build and test BlueZ for Android daemon on Linux (eg. PC).
+Simply follow instructions available at README file in BlueZ top directory.
+Android daemon binary is located at android/bluetoothd.
+
+=======
+Testing
+=======
+
+BT HAL test tools located in android/haltest is provided for HAL level testing
+of both Android daemon and HAL library. Start it and type 'adapter init' in
+prompt to initialize HAL library. On Android required bluetoothd service will
+be started automatically. On Linux it is required to start android/bluetoothd
+manually before init command timeout. To deinitialize HAL library and stop
+daemon type 'adapter cleanup'. Type 'help' for more information. Tab completion
+is also supported.
\ No newline at end of file
--
1.8.4
^ permalink raw reply related
* Re: Issue with the kernel bluetooth HCI_Delete_Stored_Link_Key command patch
From: Johan Hedberg @ 2013-10-21 19:20 UTC (permalink / raw)
To: Pavel Machek; +Cc: alexandre@maloteaux.net, marcel, gustavo, linux-bluetooth
In-Reply-To: <20131021184839.GA10592@amd.pavel.ucw.cz>
Hi,
On Mon, Oct 21, 2013, Pavel Machek wrote:
> > old 2.0 as it was written "Vista Compatible" on the box : Bus 004
> > Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth
> > Dongle (HCI mode)
<snip>
> > < HCI Command: Read Local Version Information (0x04|0x0001) plen 0
> > > HCI Event: Command Complete (0x0e) plen 12
> > Read Local Version Information (0x04|0x0001) ncmd 1
> > status 0x00
> > HCI Version: 2.0 (0x3) HCI Revision: 0x3000
> > LMP Version: 2.0 (0x3) LMP Subversion: 0x420b
> > Manufacturer: Broadcom Corporation (15)
> > < HCI Command: Read BD ADDR (0x04|0x0009) plen 0
> > > HCI Event: Command Complete (0x0e) plen 10
> > Read BD ADDR (0x04|0x0009) ncmd 1
> > status 0x00 bdaddr 00:19:86:00:19:C2
> > < HCI Command: Read Buffer Size (0x04|0x0005) plen 0
> > > HCI Event: Command Complete (0x0e) plen 11
> > Read Buffer Size (0x04|0x0005) ncmd 1
> > status 0x00
> > ACL MTU 1017:8 SCO MTU 64:0
> > < HCI Command: Read Class of Device (0x03|0x0023) plen 0
> > > HCI Event: Command Complete (0x0e) plen 7
> > Read Class of Device (0x03|0x0023) ncmd 1
> > status 0x00 class 0x000000
> > < HCI Command: Read Local Name (0x03|0x0014) plen 0
> > > HCI Event: Command Complete (0x0e) plen 252
> > Read Local Name (0x03|0x0014) ncmd 1
> > status 0x00 name 'BCM2045B'
There is something very strange in this hardware if it's reporting
Broadcom on HCI but CSR over USB. Considering that these two companies
are competitors I'd be inclined to think this HW is by neither one, i.e.
possibly counterfeit. This, combined with the fact that it's not
compliant with the Bluetooth specification, is not very likely to
inspire efforts to get it fixed.
Johan
^ permalink raw reply
* [PATCH v3 11/11] android: Implement core service functionality
From: Szymon Janc @ 2013-10-21 18:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382381811-28123-1-git-send-email-szymon.janc@tieto.com>
This allows HAL to register and unregister of services.
---
android/main.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/android/main.c b/android/main.c
index 72a1272..9bf2aea 100644
--- a/android/main.c
+++ b/android/main.c
@@ -64,6 +64,57 @@ static GIOChannel *hal_notif_io = NULL;
static volatile sig_atomic_t __terminated = 0;
+static bool services[HAL_SERVICE_ID_MAX + 1] = {false};
+
+static void service_register(void *buf, uint16_t len)
+{
+ struct hal_msg_cmd_register_module *m = buf;
+
+ if (m->service_id > HAL_SERVICE_ID_MAX || services[m->service_id]) {
+ ipc_send_error(hal_cmd_io, HAL_SERVICE_ID_CORE, 0x01);
+ return;
+ }
+
+ services[m->service_id] = true;
+
+ ipc_send(hal_cmd_io, HAL_SERVICE_ID_CORE, HAL_MSG_OP_REGISTER_MODULE, 0,
+ NULL, -1);
+
+ info("Service ID=%u registered", m->service_id);
+}
+
+static void service_unregister(void *buf, uint16_t len)
+{
+ struct hal_msg_cmd_unregister_module *m = buf;
+
+ if (m->service_id > HAL_SERVICE_ID_MAX || !services[m->service_id]) {
+ ipc_send_error(hal_cmd_io, HAL_SERVICE_ID_CORE, 0x01);
+ return;
+ }
+
+ services[m->service_id] = false;
+
+ ipc_send(hal_cmd_io, HAL_SERVICE_ID_CORE, HAL_MSG_OP_UNREGISTER_MODULE,
+ 0, NULL, -1);
+
+ info("Service ID=%u unregistered", m->service_id);
+}
+
+static void handle_service_core(uint8_t opcode, void *buf, uint16_t len)
+{
+ switch (opcode) {
+ case HAL_MSG_OP_REGISTER_MODULE:
+ service_register(buf, len);
+ break;
+ case HAL_MSG_OP_UNREGISTER_MODULE:
+ service_unregister(buf, len);
+ break;
+ default:
+ ipc_send_error(hal_cmd_io, HAL_SERVICE_ID_CORE, 0x01);
+ break;
+ }
+}
+
static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
gpointer user_data)
{
@@ -97,6 +148,9 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
}
switch (msg->service_id) {
+ case HAL_SERVICE_ID_CORE:
+ handle_service_core(msg->opcode, buf + sizeof(*msg), msg->len);
+ break;
default:
ipc_send_error(hal_cmd_io, msg->service_id, 0x01);
break;
--
1.8.4
^ permalink raw reply related
* [PATCH v3 10/11] android: Add initial code for handling HAL commands
From: Szymon Janc @ 2013-10-21 18:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382381811-28123-1-git-send-email-szymon.janc@tieto.com>
This enable watch for input and do basic sanity checks on received
command. If there is protocol error mainloop is stopped and daemon
exits.
---
android/main.c | 43 ++++++++++++++++++++++++++++++++++++++++---
1 file changed, 40 insertions(+), 3 deletions(-)
diff --git a/android/main.c b/android/main.c
index 04e8a48..72a1272 100644
--- a/android/main.c
+++ b/android/main.c
@@ -48,6 +48,7 @@
#include "adapter.h"
#include "hal-msg.h"
+#include "ipc.h"
#include "main.h"
static GMainLoop *event_loop;
@@ -66,9 +67,45 @@ static volatile sig_atomic_t __terminated = 0;
static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
gpointer user_data)
{
- info("HAL command socket closed, terminating");
- g_main_loop_quit(event_loop);
+ int fd;
+ ssize_t ret;
+ char buf[BLUEZ_HAL_MTU];
+ struct hal_msg_hdr *msg = (void *) buf;
+
+ if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+ info("HAL command socket closed, terminating");
+ goto fail;
+ }
+
+ fd = g_io_channel_unix_get_fd(io);
+
+ ret = read(fd, buf, sizeof(buf));
+ if (ret < 0) {
+ error("HAL command read failed, terminating (%s)",
+ strerror(errno));
+ goto fail;
+ }
+
+ if (ret < (ssize_t) sizeof(*msg)) {
+ error("HAL command too small, terminating (%zd)", ret);
+ goto fail;
+ }
+
+ if (ret != (ssize_t) (sizeof(*msg) + msg->len)) {
+ error("Malformed HAL command (%zd bytes), terminating", ret);
+ goto fail;
+ }
+
+ switch (msg->service_id) {
+ default:
+ ipc_send_error(hal_cmd_io, msg->service_id, 0x01);
+ break;
+ }
+
+ return TRUE;
+fail:
+ g_main_loop_quit(event_loop);
return FALSE;
}
@@ -152,7 +189,7 @@ static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
return FALSE;
}
- cond = G_IO_ERR | G_IO_HUP | G_IO_NVAL;
+ cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
g_io_add_watch(io, cond, cmd_watch_cb, NULL);
--
1.8.4
^ permalink raw reply related
* [PATCH v3 09/11] android: Add IPC helper for convenient error sending
From: Szymon Janc @ 2013-10-21 18:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382381811-28123-1-git-send-email-szymon.janc@tieto.com>
This simple helper will simplify error paths in code.
---
android/ipc.c | 9 +++++++++
android/ipc.h | 1 +
2 files changed, 10 insertions(+)
diff --git a/android/ipc.c b/android/ipc.c
index 449ba23..406a19b 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -78,3 +78,12 @@ void ipc_send(GIOChannel *io, uint8_t service_id, uint8_t opcode, uint16_t len,
main_quit();
}
}
+
+void ipc_send_error(GIOChannel *io, uint8_t service_id, uint8_t status)
+{
+ struct hal_msg_rsp_error err;
+
+ err.status = status;
+
+ ipc_send(io, service_id, HAL_MSG_OP_ERROR, sizeof(err), &err, -1);
+}
diff --git a/android/ipc.h b/android/ipc.h
index db92c97..4b0ee2a 100644
--- a/android/ipc.h
+++ b/android/ipc.h
@@ -23,3 +23,4 @@
void ipc_send(GIOChannel *io, uint8_t service_id, uint8_t opcode, uint16_t len,
void *param, int fd);
+void ipc_send_error(GIOChannel *io, uint8_t service_id, uint8_t status);
--
1.8.4
^ permalink raw reply related
* [PATCH v3 08/11] android: Add IPC helper for sending command responses and notification
From: Szymon Janc @ 2013-10-21 18:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382381811-28123-1-git-send-email-szymon.janc@tieto.com>
If send failed mainloop is stopped.
---
Makefile.android | 3 +-
android/Android.mk | 1 +
android/ipc.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
android/ipc.h | 25 +++++++++++++++++
4 files changed, 108 insertions(+), 1 deletion(-)
create mode 100644 android/ipc.c
create mode 100644 android/ipc.h
diff --git a/Makefile.android b/Makefile.android
index c2010b3..aebc715 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -8,7 +8,8 @@ android_bluetoothd_SOURCES = android/main.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/adapter.h android/adapter.c
+ android/adapter.h android/adapter.c \
+ android/ipc.h android/ipc.c
android_bluetoothd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
diff --git a/android/Android.mk b/android/Android.mk
index bd3d48a..679c12b 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -16,6 +16,7 @@ LOCAL_SRC_FILES := \
main.c \
log.c \
adapter.c \
+ ipc.c ipc.h \
../src/shared/mgmt.c \
../src/shared/util.c \
../src/sdpd-database.c \
diff --git a/android/ipc.c b/android/ipc.c
new file mode 100644
index 0000000..449ba23
--- /dev/null
+++ b/android/ipc.c
@@ -0,0 +1,80 @@
+/*
+ *
+ * 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 <stddef.h>
+#include <errno.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/socket.h>
+
+#include <glib.h>
+
+#include "hal-msg.h"
+#include "ipc.h"
+#include "log.h"
+#include "main.h"
+
+void ipc_send(GIOChannel *io, uint8_t service_id, uint8_t opcode, uint16_t len,
+ void *param, int fd)
+{
+ struct msghdr msg;
+ struct iovec iv[2];
+ struct hal_msg_hdr hal_msg;
+ char cmsgbuf[CMSG_SPACE(sizeof(int))];
+ struct cmsghdr *cmsg;
+
+
+ memset(&msg, 0, sizeof(msg));
+ memset(&hal_msg, 0, sizeof(hal_msg));
+
+ hal_msg.service_id = service_id;
+ hal_msg.opcode = opcode;
+ hal_msg.len = len;
+
+ iv[0].iov_base = &hal_msg;
+ iv[0].iov_len = sizeof(hal_msg);
+
+ iv[1].iov_base = param;
+ iv[1].iov_len = len;
+
+ msg.msg_iov = iv;
+ msg.msg_iovlen = 2;
+
+ if (fd >= 0) {
+ cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(int));
+
+ /* Initialize the payload */
+ memcpy(CMSG_DATA(cmsg), &fd, sizeof(int));
+
+ msg.msg_control = cmsgbuf;
+ msg.msg_controllen = sizeof(cmsgbuf);
+ }
+
+ if (sendmsg(g_io_channel_unix_get_fd(io), &msg, 0) < 0) {
+ error("IPC send failed, terminating :%s", strerror(errno));
+ main_quit();
+ }
+}
diff --git a/android/ipc.h b/android/ipc.h
new file mode 100644
index 0000000..db92c97
--- /dev/null
+++ b/android/ipc.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
+ *
+ */
+
+void ipc_send(GIOChannel *io, uint8_t service_id, uint8_t opcode, uint16_t len,
+ void *param, int fd);
--
1.8.4
^ permalink raw reply related
* [PATCH v3 07/11] android: Add main_quit function
From: Szymon Janc @ 2013-10-21 18:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382381811-28123-1-git-send-email-szymon.janc@tieto.com>
This will allow to stop mainloop from outside of main.c.
---
android/main.c | 6 ++++++
android/main.h | 24 ++++++++++++++++++++++++
2 files changed, 30 insertions(+)
create mode 100644 android/main.h
diff --git a/android/main.c b/android/main.c
index b24451e..04e8a48 100644
--- a/android/main.c
+++ b/android/main.c
@@ -48,6 +48,7 @@
#include "adapter.h"
#include "hal-msg.h"
+#include "main.h"
static GMainLoop *event_loop;
static struct mgmt *mgmt_if = NULL;
@@ -418,6 +419,11 @@ static void cleanup_hal_connection(void)
}
}
+void main_quit(void)
+{
+ g_main_loop_quit(event_loop);
+}
+
int main(int argc, char *argv[])
{
GOptionContext *context;
diff --git a/android/main.h b/android/main.h
new file mode 100644
index 0000000..4aa2557
--- /dev/null
+++ b/android/main.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
+ *
+ */
+
+void main_quit(void);
--
1.8.4
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox