2013-10-15 10:36:58

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv1 0/5] Initial Android BlueZ patches

From: Andrei Emeltchenko <[email protected]>

This is second chunk from my initial big patch set. Fixed style issues commented
by Marcel.

Note that due to Marcel comment this cannot be built unless you include my patch
for Android bionic library:
http://code.google.com/p/android-bluez/source/detail?r=77a07e7703b63e280d9880baad30b3375e7df079&repo=bionic#

Andrei Emeltchenko (5):
android: Create HAL API header skeleton
android: Add basic mgmt initialization sequence
android: Add adapter and device struct for BlueZ daemon
android: sdp: Reuse BlueZ SDP server in Android
android: Add cap to bind to port < 1024

Makefile.android | 8 +-
android/Android.mk | 13 +++
android/adapter.c | 63 ++++++++++++++
android/adapter.h | 36 ++++++++
android/device.c | 29 +++++++
android/device.h | 24 +++++
android/hal_msg.h | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++++
android/main.c | 244 +++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 4 +
9 files changed, 665 insertions(+), 2 deletions(-)
create mode 100644 android/adapter.c
create mode 100644 android/adapter.h
create mode 100644 android/device.c
create mode 100644 android/device.h
create mode 100644 android/hal_msg.h

--
1.7.10.4



2013-10-18 11:36:32

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCHv5 0/7] Android BlueZ patches, second chunk

Hi Andrei,

On Thu, Oct 17, 2013, Andrei Emeltchenko wrote:
> This is second chunk from my initial big patch set. Fixed style issues
> commented by Marcel.
>
> Changes:
> * v5: Rebased against upstream, hid and pan now uses explicit struct initialization,
> adapter-related functionality moved to adapter.c, fixed issues reported by Johan.
> * v4: Fixes several typos and missing style issues commented by Marcel earlier.
> * v3: Following upstream comments file names are changed from "_" to "-", added kernel style
> struct initialization, fixed bug checking status for mgmt commands, added 2 HALs skeletons.
> * v2: Corrected android_daemon -> enable_android autoconf stuff, better name for acquiring caps,
> renamed hal_msg.h to hal-msg.h due to Johan's comment. Added small test-sdp fix.
>
> Note that due to Marcel comment this cannot be built unless you include my patch
> for Android bionic library:
> http://code.google.com/p/android-bluez/source/detail?r=77a07e7703b63e280d9880baad30b3375e7df079&repo=bionic#
>
> Andrei Emeltchenko (7):
> android: Add capabilities and set userid
> android: Implement read_info_complete callback
> android: Use kernel style to initialize struct fields
> android: Rename hal_bluetooth.c to hal-bluetooth.c
> android: Rename hal_bt_sock.c to hal-bt-sock.c
> android: Add HID Host skeleton
> android: Add PAN skeleton
>
> Makefile.android | 3 +-
> android/Android.mk | 7 +-
> android/adapter.c | 108 +++++++++++--
> android/hal-bluetooth.c | 392 +++++++++++++++++++++++++++++++++++++++++++++++
> android/hal-bt-sock.c | 85 ++++++++++
> android/hal-hidhost.c | 204 ++++++++++++++++++++++++
> android/hal-pan.c | 120 +++++++++++++++
> android/hal.h | 2 +
> android/hal_bluetooth.c | 384 ----------------------------------------------
> android/hal_bt_sock.c | 85 ----------
> android/main.c | 77 ++++++++--
> configure.ac | 4 +
> 12 files changed, 980 insertions(+), 491 deletions(-)
> create mode 100644 android/hal-bluetooth.c
> create mode 100644 android/hal-bt-sock.c
> create mode 100644 android/hal-hidhost.c
> create mode 100644 android/hal-pan.c
> delete mode 100644 android/hal_bluetooth.c
> delete mode 100644 android/hal_bt_sock.c

After quite heavy fixing and additional patches of my own, these are now
upstream.

Johan

2013-10-17 11:53:07

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCHv5 2/7] android: Implement read_info_complete callback

Hi Andrei,

On Thu, Oct 17, 2013, Andrei Emeltchenko wrote:
> +static void read_info_complete(uint8_t status, uint16_t length, const void *param,
> + void *user_data)
> +{
> + struct bt_adapter *adapter = user_data;
> + const struct mgmt_rp_read_info *rp = param;
> +
> + DBG("");
> +
> + if (status) {
> + error("Failed to read info for index %u: %s (0x%02x)",
> + 0, mgmt_errstr(status), status);
> + goto failed;
> + }
> +
> + if (length < sizeof(*rp)) {
> + error("Too small read info complete response");
> + goto failed;
> + }
> +
> + if (!bacmp(&rp->bdaddr, BDADDR_ANY)) {
> + error("No Bluetooth address");
> + goto failed;
> + }
> +
> + /* Store adapter information */
> + bacpy(&adapter->bdaddr, &rp->bdaddr);
> + adapter->dev_class = rp->dev_class[0] | (rp->dev_class[1] << 8) |
> + (rp->dev_class[2] << 16);
> + adapter->name = g_strdup((const char *) rp->name);
> +
> + adapter->supported_settings = btohs(rp->supported_settings);
> + adapter->current_settings = btohs(rp->current_settings);
> +
> + /* TODO: Register all event notification handlers */
> +
> + if (adapter->current_settings & MGMT_SETTING_POWERED)
> + bt_adapter_start(adapter);
> +
> + load_link_keys(adapter, NULL);
> +
> + return;
> +
> +failed:
> + default_adapter = NULL;
> +}

This way of setting a variable in main.c to NULL without any other way
of notifying failure seems a bit messed up to me. You'll probably just
want to keep the adapter pointer private (static) to adapter.c.

>From where were you planning to initialize the UNIX socket towards the
HAL? I suppose it makes sense to do that once you've completed the basic
init with the read_info, load_link_keys, etc. If you want adapter.c to
do that there's not much needed, but if you need to notify back to
main.c you'll probably need some kind of callback mechanism.

Johan

2013-10-17 11:26:30

by Andrei Emeltchenko

[permalink] [raw]
Subject: Re: [PATCHv5 1/7] android: Add capabilities and set userid

Hi Johan,

On Thu, Oct 17, 2013 at 02:20:10PM +0300, Johan Hedberg wrote:
> Hi Andrei,
>
> On Thu, Oct 17, 2013, Andrei Emeltchenko wrote:
> > The patch set UID as standard Bluetooth user for Android (AID_BLUETOOTH).
> > For SDP server we need to bind to lower port, acquire this capability.
>
> Which POSIX capability is "this capability" exactly?
>
> > + cap.effective = cap.permitted =
> > + CAP_TO_MASK(CAP_SETGID) |
> > + CAP_TO_MASK(CAP_NET_RAW) |
> > + CAP_TO_MASK(CAP_NET_ADMIN) |
> > + CAP_TO_MASK(CAP_NET_BIND_SERVICE);
>
> I just checked the kernel L2CAP socket code and all it requires for
> binding to a low L2CAP PSM (needed e.g. by SDP) is CAP_NET_BIND_SERVICE.
> So you'll need to explain what you need these other capabilities for.
>

Have you checked also Android PARANOID kernel code?

Best regards
Andrei Emeltchenko

2013-10-17 11:20:10

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCHv5 1/7] android: Add capabilities and set userid

Hi Andrei,

On Thu, Oct 17, 2013, Andrei Emeltchenko wrote:
> The patch set UID as standard Bluetooth user for Android (AID_BLUETOOTH).
> For SDP server we need to bind to lower port, acquire this capability.

Which POSIX capability is "this capability" exactly?

> + cap.effective = cap.permitted =
> + CAP_TO_MASK(CAP_SETGID) |
> + CAP_TO_MASK(CAP_NET_RAW) |
> + CAP_TO_MASK(CAP_NET_ADMIN) |
> + CAP_TO_MASK(CAP_NET_BIND_SERVICE);

I just checked the kernel L2CAP socket code and all it requires for
binding to a low L2CAP PSM (needed e.g. by SDP) is CAP_NET_BIND_SERVICE.
So you'll need to explain what you need these other capabilities for.

Johan

2013-10-17 09:04:54

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCHv5 3/7] android: Use kernel style to initialize struct fields

Hi Andrei,

> ---
> android/hal_bluetooth.c | 46 +++++++++++++++++++++++-----------------------
> 1 file changed, 23 insertions(+), 23 deletions(-)
>
> diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
> index 9bb9dcf..89b8ebb 100644
> --- a/android/hal_bluetooth.c
> +++ b/android/hal_bluetooth.c
> @@ -309,29 +309,29 @@ static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t len)
> }
>
> static const bt_interface_t bluetooth_if = {
> - sizeof(bt_interface_t),
> - init,
> - enable,
> - disable,
> - cleanup,
> - get_adapter_properties,
> - get_adapter_property,
> - set_adapter_property,
> - get_remote_device_properties,
> - get_remote_device_property,
> - set_remote_device_property,
> - get_remote_service_record,
> - get_remote_services,
> - start_discovery,
> - cancel_discovery,
> - create_bond,
> - remove_bond,
> - cancel_bond,
> - pin_reply,
> - ssp_reply,
> - get_profile_interface,
> - dut_mode_configure,
> - dut_mode_send
> + .size = sizeof(bt_interface_t),
> + .init = init,
> + .enable = enable,
> + .disable = disable,
> + .cleanup = cleanup,
> + .get_adapter_properties = get_adapter_properties,
> + .get_adapter_property = get_adapter_property,
> + .set_adapter_property = set_adapter_property,
> + .get_remote_device_properties = get_remote_device_properties,
> + .get_remote_device_property = get_remote_device_property,
> + .set_remote_device_property = set_remote_device_property,
> + .get_remote_service_record = get_remote_service_record,
> + .get_remote_services = get_remote_services,
> + .start_discovery = start_discovery,
> + .cancel_discovery = cancel_discovery,
> + .create_bond = create_bond,
> + .remove_bond = remove_bond,
> + .cancel_bond = cancel_bond,
> + .pin_reply = pin_reply,
> + .ssp_reply = ssp_reply,
> + .get_profile_interface = get_profile_interface,
> + .dut_mode_configure = dut_mode_configure,
> + .dut_mode_send = dut_mode_send
> };

we could also leave it as is here. Since this does not give any visible improvement for anybody. Also these structure are ABI. So no unintentional reordering will ever happen.

Regards

Marcel


2013-10-17 08:26:39

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv5 0/7] Android BlueZ patches, second chunk

From: Andrei Emeltchenko <[email protected]>

This is second chunk from my initial big patch set. Fixed style issues commented
by Marcel.

Changes:
* v5: Rebased against upstream, hid and pan now uses explicit struct initialization,
adapter-related functionality moved to adapter.c, fixed issues reported by Johan.
* v4: Fixes several typos and missing style issues commented by Marcel earlier.
* v3: Following upstream comments file names are changed from "_" to "-", added kernel style
struct initialization, fixed bug checking status for mgmt commands, added 2 HALs skeletons.
* v2: Corrected android_daemon -> enable_android autoconf stuff, better name for acquiring caps,
renamed hal_msg.h to hal-msg.h due to Johan's comment. Added small test-sdp fix.

Note that due to Marcel comment this cannot be built unless you include my patch
for Android bionic library:
http://code.google.com/p/android-bluez/source/detail?r=77a07e7703b63e280d9880baad30b3375e7df079&repo=bionic#

Andrei Emeltchenko (7):
android: Add capabilities and set userid
android: Implement read_info_complete callback
android: Use kernel style to initialize struct fields
android: Rename hal_bluetooth.c to hal-bluetooth.c
android: Rename hal_bt_sock.c to hal-bt-sock.c
android: Add HID Host skeleton
android: Add PAN skeleton

Makefile.android | 3 +-
android/Android.mk | 7 +-
android/adapter.c | 108 +++++++++++--
android/hal-bluetooth.c | 392 +++++++++++++++++++++++++++++++++++++++++++++++
android/hal-bt-sock.c | 85 ++++++++++
android/hal-hidhost.c | 204 ++++++++++++++++++++++++
android/hal-pan.c | 120 +++++++++++++++
android/hal.h | 2 +
android/hal_bluetooth.c | 384 ----------------------------------------------
android/hal_bt_sock.c | 85 ----------
android/main.c | 77 ++++++++--
configure.ac | 4 +
12 files changed, 980 insertions(+), 491 deletions(-)
create mode 100644 android/hal-bluetooth.c
create mode 100644 android/hal-bt-sock.c
create mode 100644 android/hal-hidhost.c
create mode 100644 android/hal-pan.c
delete mode 100644 android/hal_bluetooth.c
delete mode 100644 android/hal_bt_sock.c

--
1.7.10.4


2013-10-17 08:26:40

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv5 1/7] android: Add capabilities and set userid

From: Andrei Emeltchenko <[email protected]>

The patch set UID as standard Bluetooth user for Android (AID_BLUETOOTH).
For SDP server we need to bind to lower port, acquire this capability.
Other capabilities are required to access management interface.
---
android/main.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 4 ++++
2 files changed, 62 insertions(+)

diff --git a/android/main.c b/android/main.c
index 3a20148..2b2e4d8 100644
--- a/android/main.c
+++ b/android/main.c
@@ -32,6 +32,13 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#if defined(ANDROID)
+#include <sys/prctl.h>
+#include <private/android_filesystem_config.h>
+#endif

#include <glib.h>

@@ -230,6 +237,54 @@ static void cleanup_mgmt_interface(void)
mgmt_if = NULL;
}

+static bool set_capabilities(void)
+{
+#if defined(ANDROID)
+ struct __user_cap_header_struct header;
+ struct __user_cap_data_struct cap;
+ gid_t groups[] = {AID_NET_BT, AID_NET_BT_ADMIN, AID_NET_ADMIN};
+
+ 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_SETGID) |
+ CAP_TO_MASK(CAP_NET_RAW) |
+ CAP_TO_MASK(CAP_NET_ADMIN) |
+ CAP_TO_MASK(CAP_NET_BIND_SERVICE);
+ cap.inheritable = 0;
+
+ if (capset(&header, &cap) < 0) {
+ error("%s: capset(): %s", __func__, strerror(errno));
+ return false;
+ }
+
+ if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) < 0)
+ warn("%s: setgroups: %s", __func__, strerror(errno));
+
+ 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;
@@ -263,6 +318,9 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);

+ if (!set_capabilities())
+ return EXIT_FAILURE;
+
if (!init_mgmt_interface())
return EXIT_FAILURE;

diff --git a/configure.ac b/configure.ac
index 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.7.10.4


2013-10-17 08:26:43

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv5 4/7] android: Rename hal_bluetooth.c to hal-bluetooth.c

From: Andrei Emeltchenko <[email protected]>

---
android/Android.mk | 2 +-
android/hal-bluetooth.c | 384 +++++++++++++++++++++++++++++++++++++++++++++++
android/hal_bluetooth.c | 384 -----------------------------------------------
3 files changed, 385 insertions(+), 385 deletions(-)
create mode 100644 android/hal-bluetooth.c
delete mode 100644 android/hal_bluetooth.c

diff --git a/android/Android.mk b/android/Android.mk
index 22f8b92..753267a 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -51,7 +51,7 @@ include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
- hal_bluetooth.c \
+ hal-bluetooth.c \
hal_bt_sock.c \

LOCAL_SHARED_LIBRARIES := \
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
new file mode 100644
index 0000000..89b8ebb
--- /dev/null
+++ b/android/hal-bluetooth.c
@@ -0,0 +1,384 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+#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 SERVICE_NAME "bluetoothd"
+
+bt_callbacks_t *bt_hal_cbacks = NULL;
+
+static bool interface_ready(void)
+{
+ return bt_hal_cbacks != NULL;
+}
+
+static bool start_bt_daemon(void)
+{
+ int tries = 40; /* wait 4 seconds for completion */
+
+ ALOGD(__func__);
+
+ /* Start Android Bluetooth daemon service */
+ property_set("ctl.start", SERVICE_NAME);
+
+ while (tries-- > 0) {
+ char val[PROPERTY_VALUE_MAX];
+
+ if (property_get("init.svc." SERVICE_NAME, val, NULL)) {
+ if (!strcmp(val, "running")) {
+ ALOGI("Android BlueZ daemon started");
+ return true;
+ }
+ } else {
+ return false;
+ }
+
+ usleep(100000);
+ }
+
+ return false;
+}
+
+static int init(bt_callbacks_t *callbacks)
+{
+ ALOGD(__func__);
+
+ if (interface_ready())
+ return BT_STATUS_SUCCESS;
+
+ if (start_bt_daemon()) {
+ /* TODO: open channel */
+
+ bt_hal_cbacks = callbacks;
+
+ return BT_STATUS_SUCCESS;
+ }
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int enable(void)
+{
+ ALOGD(__func__);
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int disable(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static void cleanup(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return;
+
+ bt_hal_cbacks = NULL;
+}
+
+static int get_adapter_properties(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_adapter_property(bt_property_type_t type)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int set_adapter_property(const bt_property_t *property)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (property == NULL)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_device_property(bt_bdaddr_t *remote_addr,
+ bt_property_type_t type)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int set_remote_device_property(bt_bdaddr_t *remote_addr,
+ const bt_property_t *property)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_services(bt_bdaddr_t *remote_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int start_discovery(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int cancel_discovery(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int create_bond(const bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int cancel_bond(const bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int remove_bond(const bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
+ uint8_t pin_len, bt_pin_code_t *pin_code)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
+ uint8_t accept, uint32_t passkey)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static const void *get_profile_interface(const char *profile_id)
+{
+ ALOGD("%s: %s", __func__, profile_id);
+
+ if (!interface_ready())
+ return NULL;
+
+ if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
+ return bt_get_sock_interface();
+
+ return NULL;
+}
+
+static int dut_mode_configure(uint8_t enable)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t len)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static const bt_interface_t bluetooth_if = {
+ .size = sizeof(bt_interface_t),
+ .init = init,
+ .enable = enable,
+ .disable = disable,
+ .cleanup = cleanup,
+ .get_adapter_properties = get_adapter_properties,
+ .get_adapter_property = get_adapter_property,
+ .set_adapter_property = set_adapter_property,
+ .get_remote_device_properties = get_remote_device_properties,
+ .get_remote_device_property = get_remote_device_property,
+ .set_remote_device_property = set_remote_device_property,
+ .get_remote_service_record = get_remote_service_record,
+ .get_remote_services = get_remote_services,
+ .start_discovery = start_discovery,
+ .cancel_discovery = cancel_discovery,
+ .create_bond = create_bond,
+ .remove_bond = remove_bond,
+ .cancel_bond = cancel_bond,
+ .pin_reply = pin_reply,
+ .ssp_reply = ssp_reply,
+ .get_profile_interface = get_profile_interface,
+ .dut_mode_configure = dut_mode_configure,
+ .dut_mode_send = dut_mode_send
+};
+
+static const bt_interface_t *get_bluetooth_interface(void)
+{
+ ALOGD(__func__);
+
+ return &bluetooth_if;
+}
+
+static int close_bluetooth(struct hw_device_t *device)
+{
+ ALOGD(__func__);
+
+ cleanup();
+
+ return 0;
+}
+
+static int open_bluetooth(const struct hw_module_t *module, char const *name,
+ struct hw_device_t **device)
+{
+ bluetooth_device_t *dev = malloc(sizeof(bluetooth_device_t));
+
+ ALOGD(__func__);
+
+ memset(dev, 0, sizeof(bluetooth_device_t));
+ dev->common.tag = HARDWARE_DEVICE_TAG;
+ dev->common.version = 0;
+ dev->common.module = (struct hw_module_t *) module;
+ dev->common.close = close_bluetooth;
+ dev->get_bluetooth_interface = get_bluetooth_interface;
+
+ *device = (struct hw_device_t *) dev;
+
+ return 0;
+}
+
+static struct hw_module_methods_t bluetooth_module_methods = {
+ .open = open_bluetooth,
+};
+
+struct hw_module_t HAL_MODULE_INFO_SYM = {
+ .tag = HARDWARE_MODULE_TAG,
+ .version_major = 1,
+ .version_minor = 0,
+ .id = BT_HARDWARE_MODULE_ID,
+ .name = "BlueZ Bluetooth stack",
+ .author = "Intel Corporation",
+ .methods = &bluetooth_module_methods
+};
diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
deleted file mode 100644
index 89b8ebb..0000000
--- a/android/hal_bluetooth.c
+++ /dev/null
@@ -1,384 +0,0 @@
-/*
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdbool.h>
-
-#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 SERVICE_NAME "bluetoothd"
-
-bt_callbacks_t *bt_hal_cbacks = NULL;
-
-static bool interface_ready(void)
-{
- return bt_hal_cbacks != NULL;
-}
-
-static bool start_bt_daemon(void)
-{
- int tries = 40; /* wait 4 seconds for completion */
-
- ALOGD(__func__);
-
- /* Start Android Bluetooth daemon service */
- property_set("ctl.start", SERVICE_NAME);
-
- while (tries-- > 0) {
- char val[PROPERTY_VALUE_MAX];
-
- if (property_get("init.svc." SERVICE_NAME, val, NULL)) {
- if (!strcmp(val, "running")) {
- ALOGI("Android BlueZ daemon started");
- return true;
- }
- } else {
- return false;
- }
-
- usleep(100000);
- }
-
- return false;
-}
-
-static int init(bt_callbacks_t *callbacks)
-{
- ALOGD(__func__);
-
- if (interface_ready())
- return BT_STATUS_SUCCESS;
-
- if (start_bt_daemon()) {
- /* TODO: open channel */
-
- bt_hal_cbacks = callbacks;
-
- return BT_STATUS_SUCCESS;
- }
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int enable(void)
-{
- ALOGD(__func__);
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int disable(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static void cleanup(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return;
-
- bt_hal_cbacks = NULL;
-}
-
-static int get_adapter_properties(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_adapter_property(bt_property_type_t type)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int set_adapter_property(const bt_property_t *property)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- if (property == NULL)
- return BT_STATUS_PARM_INVALID;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_remote_device_property(bt_bdaddr_t *remote_addr,
- bt_property_type_t type)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int set_remote_device_property(bt_bdaddr_t *remote_addr,
- const bt_property_t *property)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_remote_services(bt_bdaddr_t *remote_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int start_discovery(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int cancel_discovery(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int create_bond(const bt_bdaddr_t *bd_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- if (!bd_addr)
- return BT_STATUS_PARM_INVALID;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int cancel_bond(const bt_bdaddr_t *bd_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int remove_bond(const bt_bdaddr_t *bd_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
- uint8_t pin_len, bt_pin_code_t *pin_code)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
- uint8_t accept, uint32_t passkey)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- if (!bd_addr)
- return BT_STATUS_PARM_INVALID;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static const void *get_profile_interface(const char *profile_id)
-{
- ALOGD("%s: %s", __func__, profile_id);
-
- if (!interface_ready())
- return NULL;
-
- if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
- return bt_get_sock_interface();
-
- return NULL;
-}
-
-static int dut_mode_configure(uint8_t enable)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t len)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static const bt_interface_t bluetooth_if = {
- .size = sizeof(bt_interface_t),
- .init = init,
- .enable = enable,
- .disable = disable,
- .cleanup = cleanup,
- .get_adapter_properties = get_adapter_properties,
- .get_adapter_property = get_adapter_property,
- .set_adapter_property = set_adapter_property,
- .get_remote_device_properties = get_remote_device_properties,
- .get_remote_device_property = get_remote_device_property,
- .set_remote_device_property = set_remote_device_property,
- .get_remote_service_record = get_remote_service_record,
- .get_remote_services = get_remote_services,
- .start_discovery = start_discovery,
- .cancel_discovery = cancel_discovery,
- .create_bond = create_bond,
- .remove_bond = remove_bond,
- .cancel_bond = cancel_bond,
- .pin_reply = pin_reply,
- .ssp_reply = ssp_reply,
- .get_profile_interface = get_profile_interface,
- .dut_mode_configure = dut_mode_configure,
- .dut_mode_send = dut_mode_send
-};
-
-static const bt_interface_t *get_bluetooth_interface(void)
-{
- ALOGD(__func__);
-
- return &bluetooth_if;
-}
-
-static int close_bluetooth(struct hw_device_t *device)
-{
- ALOGD(__func__);
-
- cleanup();
-
- return 0;
-}
-
-static int open_bluetooth(const struct hw_module_t *module, char const *name,
- struct hw_device_t **device)
-{
- bluetooth_device_t *dev = malloc(sizeof(bluetooth_device_t));
-
- ALOGD(__func__);
-
- memset(dev, 0, sizeof(bluetooth_device_t));
- dev->common.tag = HARDWARE_DEVICE_TAG;
- dev->common.version = 0;
- dev->common.module = (struct hw_module_t *) module;
- dev->common.close = close_bluetooth;
- dev->get_bluetooth_interface = get_bluetooth_interface;
-
- *device = (struct hw_device_t *) dev;
-
- return 0;
-}
-
-static struct hw_module_methods_t bluetooth_module_methods = {
- .open = open_bluetooth,
-};
-
-struct hw_module_t HAL_MODULE_INFO_SYM = {
- .tag = HARDWARE_MODULE_TAG,
- .version_major = 1,
- .version_minor = 0,
- .id = BT_HARDWARE_MODULE_ID,
- .name = "BlueZ Bluetooth stack",
- .author = "Intel Corporation",
- .methods = &bluetooth_module_methods
-};
--
1.7.10.4


2013-10-17 08:26:45

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv5 6/7] android: Add HID Host skeleton

From: Andrei Emeltchenko <[email protected]>

Add skeleton for hidhost Android HAL. This is modified version
from Frederic Danis earlier patch set.
---
android/Android.mk | 1 +
android/hal-bluetooth.c | 4 +
android/hal-hidhost.c | 204 +++++++++++++++++++++++++++++++++++++++++++++++
android/hal.h | 1 +
4 files changed, 210 insertions(+)
create mode 100644 android/hal-hidhost.c

diff --git a/android/Android.mk b/android/Android.mk
index afd445a..25b4048 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -53,6 +53,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
hal-bluetooth.c \
hal-bt-sock.c \
+ hal-hidhost.c \

LOCAL_SHARED_LIBRARIES := \
libcutils \
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 89b8ebb..488606d 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -22,6 +22,7 @@

#include <hardware/bluetooth.h>
#include <hardware/bt_sock.h>
+#include <hardware/bt_hh.h>

#include <cutils/sockets.h>
#include <cutils/properties.h>
@@ -285,6 +286,9 @@ static const void *get_profile_interface(const char *profile_id)
if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
return bt_get_sock_interface();

+ if (!strcmp(profile_id, BT_PROFILE_HIDHOST_ID))
+ return bt_get_hidhost_interface();
+
return NULL;
}

diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
new file mode 100644
index 0000000..f040cba
--- /dev/null
+++ b/android/hal-hidhost.c
@@ -0,0 +1,204 @@
+/*
+ * 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 <stdbool.h>
+
+#include <hardware/bluetooth.h>
+#include <hardware/bt_hh.h>
+
+#define LOG_TAG "BlueZ"
+#include <cutils/log.h>
+
+bthh_callbacks_t *bt_hh_cbacks;
+
+static bool interface_ready(void)
+{
+ return bt_hh_cbacks != NULL;
+}
+
+static bt_status_t bt_hidhost_connect(bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_disconnect(bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_virtual_unplug(bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_set_info(bt_bdaddr_t *bd_addr,
+ bthh_hid_info_t hid_info)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_get_protocol(bt_bdaddr_t *bd_addr,
+ bthh_protocol_mode_t protocolMode)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_set_protocol(bt_bdaddr_t *bd_addr,
+ bthh_protocol_mode_t protocolMode)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_get_report(bt_bdaddr_t *bd_addr,
+ bthh_report_type_t reportType,
+ uint8_t reportId,
+ int bufferSize)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_set_report(bt_bdaddr_t *bd_addr,
+ bthh_report_type_t reportType,
+ char *report)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr || !report)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_send_data(bt_bdaddr_t *bd_addr, char *data)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr || !data)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_init(bthh_callbacks_t *callbacks)
+{
+ ALOGI(__func__);
+
+ /* store reference to user callbacks */
+ bt_hh_cbacks = callbacks;
+
+ /* TODO: start HID Host thread */
+
+ /* TODO: enable service */
+
+ return BT_STATUS_SUCCESS;
+}
+
+static void bt_hidhost_cleanup(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return;
+
+ /* TODO: disable service */
+
+ /* TODO: stop HID Host thread */
+
+ bt_hh_cbacks = NULL;
+}
+
+static bthh_interface_t bt_hidhost_if = {
+ .size = sizeof(bt_hidhost_if),
+ .init = bt_hidhost_init,
+ .connect = bt_hidhost_connect,
+ .disconnect = bt_hidhost_disconnect,
+ .virtual_unplug = bt_hidhost_virtual_unplug,
+ .set_info = bt_hidhost_set_info,
+ .get_protocol = bt_hidhost_get_protocol,
+ .set_protocol = bt_hidhost_set_protocol,
+ .get_report = bt_hidhost_get_report,
+ .set_report = bt_hidhost_set_report,
+ .send_data = bt_hidhost_send_data,
+ .cleanup = bt_hidhost_cleanup
+};
+
+bthh_interface_t *bt_get_hidhost_interface(void)
+{
+ return &bt_hidhost_if;
+}
diff --git a/android/hal.h b/android/hal.h
index 40fbf03..be69339 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -16,3 +16,4 @@
*/

btsock_interface_t *bt_get_sock_interface(void);
+bthh_interface_t *bt_get_hidhost_interface(void);
--
1.7.10.4


2013-10-17 08:26:46

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv5 7/7] android: Add PAN skeleton

From: Andrei Emeltchenko <[email protected]>

Add skeleton for pan Android HAL. This is modified version
from Frederic Danis earlier patch set.
---
android/Android.mk | 1 +
android/hal-bluetooth.c | 4 ++
android/hal-pan.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++
android/hal.h | 1 +
4 files changed, 126 insertions(+)
create mode 100644 android/hal-pan.c

diff --git a/android/Android.mk b/android/Android.mk
index 25b4048..f273094 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -54,6 +54,7 @@ LOCAL_SRC_FILES := \
hal-bluetooth.c \
hal-bt-sock.c \
hal-hidhost.c \
+ hal-pan.c \

LOCAL_SHARED_LIBRARIES := \
libcutils \
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 488606d..5f9d00b 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -23,6 +23,7 @@
#include <hardware/bluetooth.h>
#include <hardware/bt_sock.h>
#include <hardware/bt_hh.h>
+#include <hardware/bt_pan.h>

#include <cutils/sockets.h>
#include <cutils/properties.h>
@@ -289,6 +290,9 @@ static const void *get_profile_interface(const char *profile_id)
if (!strcmp(profile_id, BT_PROFILE_HIDHOST_ID))
return bt_get_hidhost_interface();

+ if (!strcmp(profile_id, BT_PROFILE_PAN_ID))
+ return bt_get_pan_interface();
+
return NULL;
}

diff --git a/android/hal-pan.c b/android/hal-pan.c
new file mode 100644
index 0000000..2f5c256
--- /dev/null
+++ b/android/hal-pan.c
@@ -0,0 +1,120 @@
+/*
+ * 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 <stdbool.h>
+
+#include <hardware/bluetooth.h>
+#include <hardware/bt_pan.h>
+
+#define LOG_TAG "BlueZ"
+#include <cutils/log.h>
+
+const btpan_callbacks_t *bt_pan_cbacks = NULL;
+
+static bool interface_ready(void)
+{
+ return bt_pan_cbacks != NULL;
+}
+
+static bt_status_t bt_pan_enable(int local_role)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int bt_pan_get_local_role(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BTPAN_ROLE_NONE;
+
+ return BTPAN_ROLE_NONE;
+}
+
+static bt_status_t bt_pan_connect(const bt_bdaddr_t *bd_addr, int local_role,
+ int remote_role)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_pan_disconnect(const bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_pan_init(const btpan_callbacks_t *callbacks)
+{
+ ALOGI(__func__);
+
+ bt_pan_cbacks = callbacks;
+
+ /* TODO: start HID Host thread */
+
+ /* TODO: enable service */
+
+ return BT_STATUS_SUCCESS;
+}
+
+static void bt_pan_cleanup()
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return;
+
+ /* TODO: disable service */
+
+ /* TODO: stop PAN thread */
+
+ bt_pan_cbacks = NULL;
+}
+
+static btpan_interface_t bt_pan_if = {
+ .size = sizeof(bt_pan_if),
+ .init = bt_pan_init,
+ .enable = bt_pan_enable,
+ .get_local_role = bt_pan_get_local_role,
+ .connect = bt_pan_connect,
+ .disconnect = bt_pan_disconnect,
+ .cleanup = bt_pan_cleanup
+};
+
+btpan_interface_t *bt_get_pan_interface()
+{
+ return &bt_pan_if;
+}
diff --git a/android/hal.h b/android/hal.h
index be69339..38b90b2 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -17,3 +17,4 @@

btsock_interface_t *bt_get_sock_interface(void);
bthh_interface_t *bt_get_hidhost_interface(void);
+btpan_interface_t *bt_get_pan_interface(void);
--
1.7.10.4


2013-10-17 08:26:44

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv5 5/7] android: Rename hal_bt_sock.c to hal-bt-sock.c

From: Andrei Emeltchenko <[email protected]>

---
android/Android.mk | 2 +-
android/hal-bt-sock.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++
android/hal_bt_sock.c | 85 -------------------------------------------------
3 files changed, 86 insertions(+), 86 deletions(-)
create mode 100644 android/hal-bt-sock.c
delete mode 100644 android/hal_bt_sock.c

diff --git a/android/Android.mk b/android/Android.mk
index 753267a..afd445a 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -52,7 +52,7 @@ include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
hal-bluetooth.c \
- hal_bt_sock.c \
+ hal-bt-sock.c \

LOCAL_SHARED_LIBRARIES := \
libcutils \
diff --git a/android/hal-bt-sock.c b/android/hal-bt-sock.c
new file mode 100644
index 0000000..3a6d173
--- /dev/null
+++ b/android/hal-bt-sock.c
@@ -0,0 +1,85 @@
+/*
+ * 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 <stdlib.h>
+
+#include <hardware/bluetooth.h>
+#include <hardware/bt_sock.h>
+
+#define LOG_TAG "BlueZ"
+#include <cutils/log.h>
+
+static bt_status_t btsock_listen_rfcomm(const char *service_name,
+ const uint8_t *uuid, int chan,
+ int *sock, int flags)
+{
+ ALOGD(__func__);
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t listen(btsock_type_t type, const char *service_name,
+ const uint8_t *uuid, int chan,
+ int *sock, int flags)
+{
+ if ((!uuid && chan <= 0) || !sock) {
+ ALOGE("%s: invalid params: uuid %p, chan %d, sock %p",
+ __func__, uuid, chan, sock);
+ return BT_STATUS_PARM_INVALID;
+ }
+
+ ALOGD("%s: uuid %p chan %d sock %p type %d service_name %s",
+ __func__, uuid, chan, sock, type, service_name);
+
+ switch (type) {
+ case BTSOCK_RFCOMM:
+ return btsock_listen_rfcomm(service_name, uuid, chan,
+ sock, flags);
+ default:
+ ALOGE("%s: Socket type %d not supported", __func__, type);
+ break;
+ }
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t connect(const bt_bdaddr_t *bdaddr, btsock_type_t type,
+ const uint8_t *uuid, int chan,
+ int *sock, int flags)
+{
+ if ((!uuid && chan <= 0) || !bdaddr || !sock) {
+ ALOGE("invalid params: bd_addr %p, uuid %p, chan %d, sock %p",
+ bdaddr, uuid, chan, sock);
+ return BT_STATUS_PARM_INVALID;
+ }
+
+ ALOGD("%s: uuid %p chan %d sock %p type %d", __func__, uuid, chan,
+ sock, type);
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static btsock_interface_t btsock_if = {
+ sizeof(btsock_if),
+ listen,
+ connect
+};
+
+btsock_interface_t *bt_get_sock_interface(void)
+{
+ return &btsock_if;
+}
diff --git a/android/hal_bt_sock.c b/android/hal_bt_sock.c
deleted file mode 100644
index 3a6d173..0000000
--- a/android/hal_bt_sock.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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 <stdlib.h>
-
-#include <hardware/bluetooth.h>
-#include <hardware/bt_sock.h>
-
-#define LOG_TAG "BlueZ"
-#include <cutils/log.h>
-
-static bt_status_t btsock_listen_rfcomm(const char *service_name,
- const uint8_t *uuid, int chan,
- int *sock, int flags)
-{
- ALOGD(__func__);
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static bt_status_t listen(btsock_type_t type, const char *service_name,
- const uint8_t *uuid, int chan,
- int *sock, int flags)
-{
- if ((!uuid && chan <= 0) || !sock) {
- ALOGE("%s: invalid params: uuid %p, chan %d, sock %p",
- __func__, uuid, chan, sock);
- return BT_STATUS_PARM_INVALID;
- }
-
- ALOGD("%s: uuid %p chan %d sock %p type %d service_name %s",
- __func__, uuid, chan, sock, type, service_name);
-
- switch (type) {
- case BTSOCK_RFCOMM:
- return btsock_listen_rfcomm(service_name, uuid, chan,
- sock, flags);
- default:
- ALOGE("%s: Socket type %d not supported", __func__, type);
- break;
- }
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static bt_status_t connect(const bt_bdaddr_t *bdaddr, btsock_type_t type,
- const uint8_t *uuid, int chan,
- int *sock, int flags)
-{
- if ((!uuid && chan <= 0) || !bdaddr || !sock) {
- ALOGE("invalid params: bd_addr %p, uuid %p, chan %d, sock %p",
- bdaddr, uuid, chan, sock);
- return BT_STATUS_PARM_INVALID;
- }
-
- ALOGD("%s: uuid %p chan %d sock %p type %d", __func__, uuid, chan,
- sock, type);
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static btsock_interface_t btsock_if = {
- sizeof(btsock_if),
- listen,
- connect
-};
-
-btsock_interface_t *bt_get_sock_interface(void)
-{
- return &btsock_if;
-}
--
1.7.10.4


2013-10-17 08:26:41

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv5 2/7] android: Implement read_info_complete callback

From: Andrei Emeltchenko <[email protected]>

Handle read info complete callback from mgmt interface.
---
Makefile.android | 3 +-
android/Android.mk | 1 +
android/adapter.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++-----
android/main.c | 19 +++++----
4 files changed, 111 insertions(+), 20 deletions(-)

diff --git a/Makefile.android b/Makefile.android
index 4d7da39..11eadc2 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -7,7 +7,8 @@ android_bluetoothd_SOURCES = android/main.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
+ src/shared/mgmt.h src/shared/mgmt.c \
+ android/adapter.h android/adapter.c

android_bluetoothd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
endif
diff --git a/android/Android.mk b/android/Android.mk
index d6bd5b8..22f8b92 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -15,6 +15,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
main.c \
log.c \
+ adapter.c \
../src/shared/mgmt.c \
../src/shared/util.c \
../src/sdpd-database.c \
diff --git a/android/adapter.c b/android/adapter.c
index 9763530..b384c5d 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -21,24 +21,24 @@
*
*/

+#include "lib/bluetooth.h"
#include "src/shared/mgmt.h"
+#include "lib/mgmt.h"
#include "log.h"
#include "adapter.h"

struct bt_adapter {
struct mgmt *mgmt;
-};
+ bdaddr_t bdaddr;
+ uint32_t dev_class;

-struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if)
-{
- struct bt_adapter *adapter;
+ char *name;

- adapter = g_new0(struct bt_adapter, 1);
-
- adapter->mgmt = mgmt_ref(mgmt_if);
+ uint32_t supported_settings;
+ uint32_t current_settings;
+};

- return adapter;
-}
+extern struct bt_adapter *default_adapter;

void bt_adapter_start(struct bt_adapter *adapter)
{
@@ -52,3 +52,93 @@ void bt_adapter_stop(struct bt_adapter *adapter)
{
DBG("");
}
+
+static void load_link_keys_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("status %u", status);
+}
+
+static void load_link_keys(struct bt_adapter *adapter, GSList *keys)
+{
+ struct mgmt_cp_load_link_keys *cp;
+ size_t key_len = g_slist_length(keys);
+ struct mgmt_link_key_info *key;
+ size_t len;
+
+ DBG("");
+
+ len = sizeof(*cp) + key_len * sizeof(*key);
+ cp = g_malloc0(len);
+
+ cp->debug_keys = 0;
+ cp->key_count = htobs(key_len);
+
+ mgmt_send(adapter->mgmt, MGMT_OP_LOAD_LINK_KEYS, 0, len,
+ cp, load_link_keys_complete, adapter, NULL);
+
+ free(cp);
+}
+
+static void read_info_complete(uint8_t status, uint16_t length, const void *param,
+ void *user_data)
+{
+ struct bt_adapter *adapter = user_data;
+ const struct mgmt_rp_read_info *rp = param;
+
+ DBG("");
+
+ if (status) {
+ error("Failed to read info for index %u: %s (0x%02x)",
+ 0, mgmt_errstr(status), status);
+ goto failed;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("Too small read info complete response");
+ goto failed;
+ }
+
+ if (!bacmp(&rp->bdaddr, BDADDR_ANY)) {
+ error("No Bluetooth address");
+ goto failed;
+ }
+
+ /* Store adapter information */
+ bacpy(&adapter->bdaddr, &rp->bdaddr);
+ adapter->dev_class = rp->dev_class[0] | (rp->dev_class[1] << 8) |
+ (rp->dev_class[2] << 16);
+ adapter->name = g_strdup((const char *) rp->name);
+
+ adapter->supported_settings = btohs(rp->supported_settings);
+ adapter->current_settings = btohs(rp->current_settings);
+
+ /* TODO: Register all event notification handlers */
+
+ if (adapter->current_settings & MGMT_SETTING_POWERED)
+ bt_adapter_start(adapter);
+
+ load_link_keys(adapter, NULL);
+
+ return;
+
+failed:
+ default_adapter = NULL;
+}
+
+struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if)
+{
+ struct bt_adapter *adapter;
+
+ adapter = g_new0(struct bt_adapter, 1);
+
+ adapter->mgmt = mgmt_ref(mgmt_if);
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
+ read_info_complete, adapter, NULL) > 0) {
+ mgmt_unref(mgmt_if);
+ return NULL;
+ }
+
+ return adapter;
+}
diff --git a/android/main.c b/android/main.c
index 2b2e4d8..cc09ecd 100644
--- a/android/main.c
+++ b/android/main.c
@@ -49,6 +49,8 @@
#include "lib/mgmt.h"
#include "src/shared/mgmt.h"

+#include "adapter.h"
+
#define SHUTDOWN_GRACE_SECONDS 10

static GMainLoop *event_loop;
@@ -57,6 +59,8 @@ static struct mgmt *mgmt_if = NULL;
static uint8_t mgmt_version = 0;
static uint8_t mgmt_revision = 0;

+struct bt_adapter *default_adapter = NULL;
+
static gboolean quit_eventloop(gpointer user_data)
{
g_main_loop_quit(event_loop);
@@ -84,22 +88,17 @@ static GOptionEntry options[] = {
{ NULL }
};

-static void read_info_complete(uint8_t status, uint16_t length,
- const void *param, void *user_data)
-{
- /* TODO: Store Controller information */
-
- /* TODO: Register all event notification handlers */
-}
-
static void mgmt_index_added_event(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
DBG("index %u", index);

- if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
- read_info_complete, NULL, NULL) > 0)
+ if (default_adapter) {
+ DBG("skip event for index %u", index);
return;
+ }
+
+ default_adapter = bt_adapter_new(index, mgmt_if);

error("Failed to read adapter info for index %u", index);
}
--
1.7.10.4


2013-10-17 08:26:42

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv5 3/7] android: Use kernel style to initialize struct fields

From: Andrei Emeltchenko <[email protected]>

---
android/hal_bluetooth.c | 46 +++++++++++++++++++++++-----------------------
1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
index 9bb9dcf..89b8ebb 100644
--- a/android/hal_bluetooth.c
+++ b/android/hal_bluetooth.c
@@ -309,29 +309,29 @@ static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t len)
}

static const bt_interface_t bluetooth_if = {
- sizeof(bt_interface_t),
- init,
- enable,
- disable,
- cleanup,
- get_adapter_properties,
- get_adapter_property,
- set_adapter_property,
- get_remote_device_properties,
- get_remote_device_property,
- set_remote_device_property,
- get_remote_service_record,
- get_remote_services,
- start_discovery,
- cancel_discovery,
- create_bond,
- remove_bond,
- cancel_bond,
- pin_reply,
- ssp_reply,
- get_profile_interface,
- dut_mode_configure,
- dut_mode_send
+ .size = sizeof(bt_interface_t),
+ .init = init,
+ .enable = enable,
+ .disable = disable,
+ .cleanup = cleanup,
+ .get_adapter_properties = get_adapter_properties,
+ .get_adapter_property = get_adapter_property,
+ .set_adapter_property = set_adapter_property,
+ .get_remote_device_properties = get_remote_device_properties,
+ .get_remote_device_property = get_remote_device_property,
+ .set_remote_device_property = set_remote_device_property,
+ .get_remote_service_record = get_remote_service_record,
+ .get_remote_services = get_remote_services,
+ .start_discovery = start_discovery,
+ .cancel_discovery = cancel_discovery,
+ .create_bond = create_bond,
+ .remove_bond = remove_bond,
+ .cancel_bond = cancel_bond,
+ .pin_reply = pin_reply,
+ .ssp_reply = ssp_reply,
+ .get_profile_interface = get_profile_interface,
+ .dut_mode_configure = dut_mode_configure,
+ .dut_mode_send = dut_mode_send
};

static const bt_interface_t *get_bluetooth_interface(void)
--
1.7.10.4


2013-10-16 15:48:18

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCHv4 04/11] android: sdp: Reuse BlueZ SDP server in Android

Hi Andrei,

On Wed, Oct 16, 2013, Andrei Emeltchenko wrote:
> Reuse existing SDP server code in Android GPL daemon.
> ---
> Makefile.android | 4 +++-
> android/Android.mk | 8 ++++++++
> android/main.c | 5 +++++
> 3 files changed, 16 insertions(+), 1 deletion(-)

I've applied patches 1-4 upstream, however from there onwards there were
some issues that will still need to be resolved.

Johan

2013-10-16 15:47:28

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCHv4 06/11] android: Implement read_info_complete callback

Hi Andrei,

On Wed, Oct 16, 2013, Andrei Emeltchenko wrote:
> --- a/android/adapter.h
> +++ b/android/adapter.h
> @@ -34,3 +34,7 @@ struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if);
>
> void bt_adapter_start(struct bt_adapter *adapter);
> void bt_adapter_stop(struct bt_adapter *adapter);
> +
> +void read_info_complete(uint8_t status, uint16_t length, const void *param,
> + void *user_data);
> +void load_link_keys(struct bt_adapter *adapter, GSList *keys);

Shouldn't you be following the appropriate name space for this header
file? I.e. bt_adapter_*.

That said, it seems to me like you don't need to have any public
functions like this at all if you just do the read_info from the
bt_adapter_new function since you get the mgmt context there anyway.

Johan

2013-10-16 15:44:50

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCHv4 05/11] android: Add cap to bind to port < 1024

Hi Andrei,

On Wed, Oct 16, 2013, Andrei Emeltchenko wrote:
> For SDP server we need to bind to lower port, acquire this capability.

You might want to mention here exactly which capability it is instead of
just saying "this" :)

The patch also seems to do more than just related to POSIX capabilities
so you should also mention these things in the commit message.

> diff --git a/android/main.c b/android/main.c
> index 3a20148..091ef20 100644
> --- a/android/main.c
> +++ b/android/main.c
> @@ -32,6 +32,21 @@
> #include <stdlib.h>
> #include <stdbool.h>
> #include <string.h>
> +#include <unistd.h>
> +#include <errno.h>
> +#include <sys/prctl.h>
> +
> +/**
> + * Include <sys/capability.h> for host build and
> + * also for Android 4.3 when it is added to bionic
> + */
> +#if !defined(ANDROID) || (PLATFORM_SDK_VERSION > 17)
> +#include <sys/capability.h>
> +#endif
> +
> +#if defined(ANDROID)
> +#include <private/android_filesystem_config.h>
> +#endif
>
> #include <glib.h>
>
> @@ -230,6 +245,58 @@ static void cleanup_mgmt_interface(void)
> mgmt_if = NULL;
> }
>
> +static bool set_capabilities(void)

This whole function seems to me like something that's not needed on
non-android (since we can just execute the daemon as root if necessary),
so I'd consider putting its entire contents behind #if defined(ANDROID)

2013-10-16 14:36:36

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv4 09/11] android: Rename hal_bt_sock.c to hal-bt-sock.c

From: Andrei Emeltchenko <[email protected]>

---
android/Android.mk | 2 +-
android/hal-bt-sock.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++
android/hal_bt_sock.c | 85 -------------------------------------------------
3 files changed, 86 insertions(+), 86 deletions(-)
create mode 100644 android/hal-bt-sock.c
delete mode 100644 android/hal_bt_sock.c

diff --git a/android/Android.mk b/android/Android.mk
index 021bb91..fb4383d 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -52,7 +52,7 @@ include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
hal-bluetooth.c \
- hal_bt_sock.c \
+ hal-bt-sock.c \

LOCAL_SHARED_LIBRARIES := \
libcutils \
diff --git a/android/hal-bt-sock.c b/android/hal-bt-sock.c
new file mode 100644
index 0000000..3a6d173
--- /dev/null
+++ b/android/hal-bt-sock.c
@@ -0,0 +1,85 @@
+/*
+ * 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 <stdlib.h>
+
+#include <hardware/bluetooth.h>
+#include <hardware/bt_sock.h>
+
+#define LOG_TAG "BlueZ"
+#include <cutils/log.h>
+
+static bt_status_t btsock_listen_rfcomm(const char *service_name,
+ const uint8_t *uuid, int chan,
+ int *sock, int flags)
+{
+ ALOGD(__func__);
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t listen(btsock_type_t type, const char *service_name,
+ const uint8_t *uuid, int chan,
+ int *sock, int flags)
+{
+ if ((!uuid && chan <= 0) || !sock) {
+ ALOGE("%s: invalid params: uuid %p, chan %d, sock %p",
+ __func__, uuid, chan, sock);
+ return BT_STATUS_PARM_INVALID;
+ }
+
+ ALOGD("%s: uuid %p chan %d sock %p type %d service_name %s",
+ __func__, uuid, chan, sock, type, service_name);
+
+ switch (type) {
+ case BTSOCK_RFCOMM:
+ return btsock_listen_rfcomm(service_name, uuid, chan,
+ sock, flags);
+ default:
+ ALOGE("%s: Socket type %d not supported", __func__, type);
+ break;
+ }
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t connect(const bt_bdaddr_t *bdaddr, btsock_type_t type,
+ const uint8_t *uuid, int chan,
+ int *sock, int flags)
+{
+ if ((!uuid && chan <= 0) || !bdaddr || !sock) {
+ ALOGE("invalid params: bd_addr %p, uuid %p, chan %d, sock %p",
+ bdaddr, uuid, chan, sock);
+ return BT_STATUS_PARM_INVALID;
+ }
+
+ ALOGD("%s: uuid %p chan %d sock %p type %d", __func__, uuid, chan,
+ sock, type);
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static btsock_interface_t btsock_if = {
+ sizeof(btsock_if),
+ listen,
+ connect
+};
+
+btsock_interface_t *bt_get_sock_interface(void)
+{
+ return &btsock_if;
+}
diff --git a/android/hal_bt_sock.c b/android/hal_bt_sock.c
deleted file mode 100644
index 3a6d173..0000000
--- a/android/hal_bt_sock.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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 <stdlib.h>
-
-#include <hardware/bluetooth.h>
-#include <hardware/bt_sock.h>
-
-#define LOG_TAG "BlueZ"
-#include <cutils/log.h>
-
-static bt_status_t btsock_listen_rfcomm(const char *service_name,
- const uint8_t *uuid, int chan,
- int *sock, int flags)
-{
- ALOGD(__func__);
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static bt_status_t listen(btsock_type_t type, const char *service_name,
- const uint8_t *uuid, int chan,
- int *sock, int flags)
-{
- if ((!uuid && chan <= 0) || !sock) {
- ALOGE("%s: invalid params: uuid %p, chan %d, sock %p",
- __func__, uuid, chan, sock);
- return BT_STATUS_PARM_INVALID;
- }
-
- ALOGD("%s: uuid %p chan %d sock %p type %d service_name %s",
- __func__, uuid, chan, sock, type, service_name);
-
- switch (type) {
- case BTSOCK_RFCOMM:
- return btsock_listen_rfcomm(service_name, uuid, chan,
- sock, flags);
- default:
- ALOGE("%s: Socket type %d not supported", __func__, type);
- break;
- }
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static bt_status_t connect(const bt_bdaddr_t *bdaddr, btsock_type_t type,
- const uint8_t *uuid, int chan,
- int *sock, int flags)
-{
- if ((!uuid && chan <= 0) || !bdaddr || !sock) {
- ALOGE("invalid params: bd_addr %p, uuid %p, chan %d, sock %p",
- bdaddr, uuid, chan, sock);
- return BT_STATUS_PARM_INVALID;
- }
-
- ALOGD("%s: uuid %p chan %d sock %p type %d", __func__, uuid, chan,
- sock, type);
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static btsock_interface_t btsock_if = {
- sizeof(btsock_if),
- listen,
- connect
-};
-
-btsock_interface_t *bt_get_sock_interface(void)
-{
- return &btsock_if;
-}
--
1.7.10.4


2013-10-16 14:36:38

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv4 11/11] android: Add PAN skeleton

From: Andrei Emeltchenko <[email protected]>

Add skeleton for pan Android HAL. This is modified version
from Frederic Danis earlier patch set.
---
android/Android.mk | 1 +
android/hal-bluetooth.c | 4 ++
android/hal-pan.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++
android/hal.h | 1 +
4 files changed, 126 insertions(+)
create mode 100644 android/hal-pan.c

diff --git a/android/Android.mk b/android/Android.mk
index ab2171c..f369e34 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -54,6 +54,7 @@ LOCAL_SRC_FILES := \
hal-bluetooth.c \
hal-bt-sock.c \
hal-hidhost.c \
+ hal-pan.c \

LOCAL_SHARED_LIBRARIES := \
libcutils \
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 488606d..5f9d00b 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -23,6 +23,7 @@
#include <hardware/bluetooth.h>
#include <hardware/bt_sock.h>
#include <hardware/bt_hh.h>
+#include <hardware/bt_pan.h>

#include <cutils/sockets.h>
#include <cutils/properties.h>
@@ -289,6 +290,9 @@ static const void *get_profile_interface(const char *profile_id)
if (!strcmp(profile_id, BT_PROFILE_HIDHOST_ID))
return bt_get_hidhost_interface();

+ if (!strcmp(profile_id, BT_PROFILE_PAN_ID))
+ return bt_get_pan_interface();
+
return NULL;
}

diff --git a/android/hal-pan.c b/android/hal-pan.c
new file mode 100644
index 0000000..373494e
--- /dev/null
+++ b/android/hal-pan.c
@@ -0,0 +1,120 @@
+/*
+ * 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 <stdbool.h>
+
+#include <hardware/bluetooth.h>
+#include <hardware/bt_pan.h>
+
+#define LOG_TAG "BlueZ"
+#include <cutils/log.h>
+
+const btpan_callbacks_t *bt_pan_cbacks = NULL;
+
+static bool interface_ready(void)
+{
+ return bt_pan_cbacks != NULL;
+}
+
+static bt_status_t bt_pan_enable(int local_role)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int bt_pan_get_local_role(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BTPAN_ROLE_NONE;
+
+ return BTPAN_ROLE_NONE;
+}
+
+static bt_status_t bt_pan_connect(const bt_bdaddr_t *bd_addr, int local_role,
+ int remote_role)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_pan_disconnect(const bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_pan_init(const btpan_callbacks_t *callbacks)
+{
+ ALOGI(__func__);
+
+ bt_pan_cbacks = callbacks;
+
+ /* TODO: start HID Host thread */
+
+ /* TODO: enable service */
+
+ return BT_STATUS_SUCCESS;
+}
+
+static void bt_pan_cleanup()
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return;
+
+ /* TODO: disable service */
+
+ /* TODO: stop PAN thread */
+
+ bt_pan_cbacks = NULL;
+}
+
+static btpan_interface_t bt_pan_if = {
+ sizeof(bt_pan_if),
+ bt_pan_init,
+ bt_pan_enable,
+ bt_pan_get_local_role,
+ bt_pan_connect,
+ bt_pan_disconnect,
+ bt_pan_cleanup
+};
+
+btpan_interface_t *bt_get_pan_interface()
+{
+ return &bt_pan_if;
+}
diff --git a/android/hal.h b/android/hal.h
index be69339..38b90b2 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -17,3 +17,4 @@

btsock_interface_t *bt_get_sock_interface(void);
bthh_interface_t *bt_get_hidhost_interface(void);
+btpan_interface_t *bt_get_pan_interface(void);
--
1.7.10.4


2013-10-16 14:36:30

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv4 03/11] android: Add adapter and device struct for BlueZ daemon

From: Andrei Emeltchenko <[email protected]>

Adapter structure in BlueZ daemon keeps track of default adapter
and device structure keeps track about found devices.
---
android/adapter.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
android/adapter.h | 36 +++++++++++++++++++++++++++++++++++
android/device.c | 25 +++++++++++++++++++++++++
android/device.h | 24 ++++++++++++++++++++++++
4 files changed, 139 insertions(+)
create mode 100644 android/adapter.c
create mode 100644 android/adapter.h
create mode 100644 android/device.c
create mode 100644 android/device.h

diff --git a/android/adapter.c b/android/adapter.c
new file mode 100644
index 0000000..9763530
--- /dev/null
+++ b/android/adapter.c
@@ -0,0 +1,54 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "src/shared/mgmt.h"
+#include "log.h"
+#include "adapter.h"
+
+struct bt_adapter {
+ struct mgmt *mgmt;
+};
+
+struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if)
+{
+ struct bt_adapter *adapter;
+
+ adapter = g_new0(struct bt_adapter, 1);
+
+ adapter->mgmt = mgmt_ref(mgmt_if);
+
+ return adapter;
+}
+
+void bt_adapter_start(struct bt_adapter *adapter)
+{
+ DBG("");
+
+ /* TODO: CB: report scan mode */
+ /* TODO: CB: report state on */
+}
+
+void bt_adapter_stop(struct bt_adapter *adapter)
+{
+ DBG("");
+}
diff --git a/android/adapter.h b/android/adapter.h
new file mode 100644
index 0000000..0f1445a
--- /dev/null
+++ b/android/adapter.h
@@ -0,0 +1,36 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <glib.h>
+
+#include "lib/bluetooth.h"
+
+struct bt_adapter;
+
+struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if);
+
+void bt_adapter_start(struct bt_adapter *adapter);
+void bt_adapter_stop(struct bt_adapter *adapter);
diff --git a/android/device.c b/android/device.c
new file mode 100644
index 0000000..f9ca3ec
--- /dev/null
+++ b/android/device.c
@@ -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
+ *
+ */
+
+struct bt_device {
+};
diff --git a/android/device.h b/android/device.h
new file mode 100644
index 0000000..f5b1da6
--- /dev/null
+++ b/android/device.h
@@ -0,0 +1,24 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+struct bt_device;
--
1.7.10.4


2013-10-16 14:36:28

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv4 01/11] android: Create HAL API header skeleton

From: Andrei Emeltchenko <[email protected]>

Header describes the protocol between Android HAL threads and BlueZ
daemon. The header is added to host build and not to Android since
it is smart enough to include it automatically.
---
Makefile.android | 5 +-
android/hal-msg.h | 246 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 250 insertions(+), 1 deletion(-)
create mode 100644 android/hal-msg.h

diff --git a/Makefile.android b/Makefile.android
index 3ceefd8..02f3341 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -1,7 +1,10 @@
if ANDROID
noinst_PROGRAMS += android/bluetoothd

-android_bluetoothd_SOURCES = android/main.c src/log.c
+android_bluetoothd_SOURCES = android/main.c \
+ src/log.c \
+ android/hal-msg.h
+
android_bluetoothd_LDADD = @GLIB_LIBS@
endif

diff --git a/android/hal-msg.h b/android/hal-msg.h
new file mode 100644
index 0000000..4c5ca69
--- /dev/null
+++ b/android/hal-msg.h
@@ -0,0 +1,246 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+struct hal_msg_hdr {
+ uint8_t service_id;
+ uint8_t opcode;
+ uint16_t len;
+} __attribute__((packed));
+
+#define HAL_SERVICE_ID_CORE 0
+#define HAL_SERVICE_ID_BLUETOOTH 1
+#define HAL_SERVICE_ID_SOCK 2
+#define HAL_SERVICE_ID_HIDHOST 3
+#define HAL_SERVICE_ID_PAN 4
+#define HAL_SERVICE_ID_HANDSFREE 5
+#define HAL_SERVICE_ID_AD2P 6
+#define HAL_SERVICE_ID_HEALTH 7
+#define HAL_SERVICE_ID_AVRCP 8
+#define HAL_SERVICE_ID_GATT 9
+
+/* Core Service */
+
+#define HAL_MSG_OP_ERROR 0x00
+struct hal_msg_rsp_error {
+ uint8_t status;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_REGISTER_MODULE 0x01
+struct hal_msg_cmd_register_module {
+ uint8_t service_id;
+} __attribute__((packed));
+struct hal_msg_rsp_register_module {
+ uint8_t service_id;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_UNREGISTER_MODULE 0x02
+struct hal_msg_cmd_unregister_module {
+ uint8_t service_id;
+} __attribute__((packed));
+
+/* Bluetooth Core HAL API */
+
+#define HAL_MSG_OP_BT_ENABLE 0x01
+
+#define HAL_MSG_OP_BT_DISABLE 0x02
+
+#define HAL_MSG_OP_BT_GET_ADAPTER_PROPS 0x03
+
+#define HAL_MSG_OP_BT_GET_ADAPTER_PROP 0x04
+struct hal_msg_cmd_bt_get_adapter_prop {
+ uint8_t type;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SET_ADAPTER_PROP 0x05
+struct hal_msg_cmd_bt_set_adapter_prop {
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_DEVICE_PROPS 0x06
+struct hal_msg_cmd_bt_get_remote_device_props {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_DEVICE_PROP 0x07
+struct hal_msg_cmd_bt_get_remote_device_prop {
+ uint8_t bdaddr[6];
+ uint8_t type;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SET_REMOTE_DEVICE_PROP 0x08
+struct hal_msg_cmd_bt_set_remote_device_prop {
+ uint8_t bdaddr[6];
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_SERVICE_REC 0x09
+struct hal_msg_cmd_bt_get_remote_service_rec {
+ uint8_t bdaddr[6];
+ uint8_t uuid[16];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_SERVICE 0x0a
+struct hal_msg_cmd_bt_get_remote_service {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_START_DISCOVERY 0x0b
+
+#define HAL_MSG_OP_BT_CANCEL_DISCOVERY 0x0c
+
+#define HAL_MSG_OP_BT_CREATE_BOND 0x0d
+struct hal_msg_cmd_bt_create_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_REMOVE_BOND 0x0d
+struct hal_msg_cmd_bt_remove_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_CANCEL_BOND 0x0f
+struct hal_msg_cmd_bt_cancel_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_PIN_REPLY 0x10
+struct hal_msg_cmd_bt_pin_reply {
+ uint8_t bdaddr[6];
+ uint8_t accept;
+ uint8_t pin_len;
+ uint8_t pin_code[16];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SSP_REPLY 0x11
+struct hal_msg_cmd_bt_ssp_reply {
+ uint8_t bdaddr[6];
+ uint8_t ssp_variant;
+ uint8_t accept;
+ uint32_t passkey;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_DUT_MODE_CONF 0x12
+struct hal_msg_cmd_bt_dut_mode_conf {
+ uint8_t enable;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_DUT_MODE_SEND 0x13
+struct hal_msg_cmd_bt_dut_mode_send {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_LE_TEST_MODE 0x14
+struct hal_msg_cmd_bt_le_test_mode {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+/* Notifications and confirmations */
+
+#define HAL_MSG_EV_BT_ERROR 0x80
+
+#define HAL_MSG_EV_BT_ADAPTER_STATE_CHANGED 0x81
+struct hal_msg_ev_bt_adapter_state_changed {
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_ADAPTER_PROPS_CHANGED 0x82
+struct hal_property {
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+struct hal_msg_ev_bt_adapter_props_changed {
+ uint8_t status;
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_REMOTE_DEVICE_PROPS 0x83
+struct hal_msg_ev_bt_remote_device_props {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DEVICE_FOUND 0x84
+struct hal_msg_ev_bt_device_found {
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DISCOVERY_STATE_CHANGED 0x85
+struct hal_msg_ev_bt_discovery_state_changed {
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_PIN_REQUEST 0x86
+struct hal_msg_ev_bt_pin_request {
+ uint8_t bdaddr[6];
+ uint8_t name[249 - 1];
+ uint8_t class_of_dev[3];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_SSP_REQUEST 0x87
+struct hal_msg_ev_bt_ssp_request {
+ uint8_t bdaddr[6];
+ uint8_t name[249 - 1];
+ uint8_t class_of_dev[3];
+ uint8_t pairing_variant;
+ uint32_t passkey;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_BOND_STATE_CHANGED 0x88
+struct hal_msg_ev_bt_bond_state_changed {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_ACL_STATE_CHANGED 0x89
+struct hal_msg_ev_bt_acl_state_changed {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DUT_MODE_RECEIVE 0x8a
+struct hal_msg_ev_bt_dut_mode_receive {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_LE_TEST_MODE 0x8b
+struct hal_msg_ev_bt_le_test_mode {
+ uint8_t status;
+ uint16_t num_packets;
+} __attribute__((packed));
--
1.7.10.4


2013-10-16 14:36:35

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv4 08/11] android: Rename hal_bluetooth.c to hal-bluetooth.c

From: Andrei Emeltchenko <[email protected]>

---
android/Android.mk | 2 +-
android/hal-bluetooth.c | 384 +++++++++++++++++++++++++++++++++++++++++++++++
android/hal_bluetooth.c | 384 -----------------------------------------------
3 files changed, 385 insertions(+), 385 deletions(-)
create mode 100644 android/hal-bluetooth.c
delete mode 100644 android/hal_bluetooth.c

diff --git a/android/Android.mk b/android/Android.mk
index 821f1dc..021bb91 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -51,7 +51,7 @@ include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
- hal_bluetooth.c \
+ hal-bluetooth.c \
hal_bt_sock.c \

LOCAL_SHARED_LIBRARIES := \
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
new file mode 100644
index 0000000..89b8ebb
--- /dev/null
+++ b/android/hal-bluetooth.c
@@ -0,0 +1,384 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+#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 SERVICE_NAME "bluetoothd"
+
+bt_callbacks_t *bt_hal_cbacks = NULL;
+
+static bool interface_ready(void)
+{
+ return bt_hal_cbacks != NULL;
+}
+
+static bool start_bt_daemon(void)
+{
+ int tries = 40; /* wait 4 seconds for completion */
+
+ ALOGD(__func__);
+
+ /* Start Android Bluetooth daemon service */
+ property_set("ctl.start", SERVICE_NAME);
+
+ while (tries-- > 0) {
+ char val[PROPERTY_VALUE_MAX];
+
+ if (property_get("init.svc." SERVICE_NAME, val, NULL)) {
+ if (!strcmp(val, "running")) {
+ ALOGI("Android BlueZ daemon started");
+ return true;
+ }
+ } else {
+ return false;
+ }
+
+ usleep(100000);
+ }
+
+ return false;
+}
+
+static int init(bt_callbacks_t *callbacks)
+{
+ ALOGD(__func__);
+
+ if (interface_ready())
+ return BT_STATUS_SUCCESS;
+
+ if (start_bt_daemon()) {
+ /* TODO: open channel */
+
+ bt_hal_cbacks = callbacks;
+
+ return BT_STATUS_SUCCESS;
+ }
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int enable(void)
+{
+ ALOGD(__func__);
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int disable(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static void cleanup(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return;
+
+ bt_hal_cbacks = NULL;
+}
+
+static int get_adapter_properties(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_adapter_property(bt_property_type_t type)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int set_adapter_property(const bt_property_t *property)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (property == NULL)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_device_property(bt_bdaddr_t *remote_addr,
+ bt_property_type_t type)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int set_remote_device_property(bt_bdaddr_t *remote_addr,
+ const bt_property_t *property)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_services(bt_bdaddr_t *remote_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int start_discovery(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int cancel_discovery(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int create_bond(const bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int cancel_bond(const bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int remove_bond(const bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
+ uint8_t pin_len, bt_pin_code_t *pin_code)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
+ uint8_t accept, uint32_t passkey)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static const void *get_profile_interface(const char *profile_id)
+{
+ ALOGD("%s: %s", __func__, profile_id);
+
+ if (!interface_ready())
+ return NULL;
+
+ if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
+ return bt_get_sock_interface();
+
+ return NULL;
+}
+
+static int dut_mode_configure(uint8_t enable)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t len)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static const bt_interface_t bluetooth_if = {
+ .size = sizeof(bt_interface_t),
+ .init = init,
+ .enable = enable,
+ .disable = disable,
+ .cleanup = cleanup,
+ .get_adapter_properties = get_adapter_properties,
+ .get_adapter_property = get_adapter_property,
+ .set_adapter_property = set_adapter_property,
+ .get_remote_device_properties = get_remote_device_properties,
+ .get_remote_device_property = get_remote_device_property,
+ .set_remote_device_property = set_remote_device_property,
+ .get_remote_service_record = get_remote_service_record,
+ .get_remote_services = get_remote_services,
+ .start_discovery = start_discovery,
+ .cancel_discovery = cancel_discovery,
+ .create_bond = create_bond,
+ .remove_bond = remove_bond,
+ .cancel_bond = cancel_bond,
+ .pin_reply = pin_reply,
+ .ssp_reply = ssp_reply,
+ .get_profile_interface = get_profile_interface,
+ .dut_mode_configure = dut_mode_configure,
+ .dut_mode_send = dut_mode_send
+};
+
+static const bt_interface_t *get_bluetooth_interface(void)
+{
+ ALOGD(__func__);
+
+ return &bluetooth_if;
+}
+
+static int close_bluetooth(struct hw_device_t *device)
+{
+ ALOGD(__func__);
+
+ cleanup();
+
+ return 0;
+}
+
+static int open_bluetooth(const struct hw_module_t *module, char const *name,
+ struct hw_device_t **device)
+{
+ bluetooth_device_t *dev = malloc(sizeof(bluetooth_device_t));
+
+ ALOGD(__func__);
+
+ memset(dev, 0, sizeof(bluetooth_device_t));
+ dev->common.tag = HARDWARE_DEVICE_TAG;
+ dev->common.version = 0;
+ dev->common.module = (struct hw_module_t *) module;
+ dev->common.close = close_bluetooth;
+ dev->get_bluetooth_interface = get_bluetooth_interface;
+
+ *device = (struct hw_device_t *) dev;
+
+ return 0;
+}
+
+static struct hw_module_methods_t bluetooth_module_methods = {
+ .open = open_bluetooth,
+};
+
+struct hw_module_t HAL_MODULE_INFO_SYM = {
+ .tag = HARDWARE_MODULE_TAG,
+ .version_major = 1,
+ .version_minor = 0,
+ .id = BT_HARDWARE_MODULE_ID,
+ .name = "BlueZ Bluetooth stack",
+ .author = "Intel Corporation",
+ .methods = &bluetooth_module_methods
+};
diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
deleted file mode 100644
index 89b8ebb..0000000
--- a/android/hal_bluetooth.c
+++ /dev/null
@@ -1,384 +0,0 @@
-/*
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdbool.h>
-
-#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 SERVICE_NAME "bluetoothd"
-
-bt_callbacks_t *bt_hal_cbacks = NULL;
-
-static bool interface_ready(void)
-{
- return bt_hal_cbacks != NULL;
-}
-
-static bool start_bt_daemon(void)
-{
- int tries = 40; /* wait 4 seconds for completion */
-
- ALOGD(__func__);
-
- /* Start Android Bluetooth daemon service */
- property_set("ctl.start", SERVICE_NAME);
-
- while (tries-- > 0) {
- char val[PROPERTY_VALUE_MAX];
-
- if (property_get("init.svc." SERVICE_NAME, val, NULL)) {
- if (!strcmp(val, "running")) {
- ALOGI("Android BlueZ daemon started");
- return true;
- }
- } else {
- return false;
- }
-
- usleep(100000);
- }
-
- return false;
-}
-
-static int init(bt_callbacks_t *callbacks)
-{
- ALOGD(__func__);
-
- if (interface_ready())
- return BT_STATUS_SUCCESS;
-
- if (start_bt_daemon()) {
- /* TODO: open channel */
-
- bt_hal_cbacks = callbacks;
-
- return BT_STATUS_SUCCESS;
- }
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int enable(void)
-{
- ALOGD(__func__);
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int disable(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static void cleanup(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return;
-
- bt_hal_cbacks = NULL;
-}
-
-static int get_adapter_properties(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_adapter_property(bt_property_type_t type)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int set_adapter_property(const bt_property_t *property)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- if (property == NULL)
- return BT_STATUS_PARM_INVALID;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_remote_device_property(bt_bdaddr_t *remote_addr,
- bt_property_type_t type)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int set_remote_device_property(bt_bdaddr_t *remote_addr,
- const bt_property_t *property)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_remote_services(bt_bdaddr_t *remote_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int start_discovery(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int cancel_discovery(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int create_bond(const bt_bdaddr_t *bd_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- if (!bd_addr)
- return BT_STATUS_PARM_INVALID;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int cancel_bond(const bt_bdaddr_t *bd_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int remove_bond(const bt_bdaddr_t *bd_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
- uint8_t pin_len, bt_pin_code_t *pin_code)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
- uint8_t accept, uint32_t passkey)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- if (!bd_addr)
- return BT_STATUS_PARM_INVALID;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static const void *get_profile_interface(const char *profile_id)
-{
- ALOGD("%s: %s", __func__, profile_id);
-
- if (!interface_ready())
- return NULL;
-
- if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
- return bt_get_sock_interface();
-
- return NULL;
-}
-
-static int dut_mode_configure(uint8_t enable)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t len)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static const bt_interface_t bluetooth_if = {
- .size = sizeof(bt_interface_t),
- .init = init,
- .enable = enable,
- .disable = disable,
- .cleanup = cleanup,
- .get_adapter_properties = get_adapter_properties,
- .get_adapter_property = get_adapter_property,
- .set_adapter_property = set_adapter_property,
- .get_remote_device_properties = get_remote_device_properties,
- .get_remote_device_property = get_remote_device_property,
- .set_remote_device_property = set_remote_device_property,
- .get_remote_service_record = get_remote_service_record,
- .get_remote_services = get_remote_services,
- .start_discovery = start_discovery,
- .cancel_discovery = cancel_discovery,
- .create_bond = create_bond,
- .remove_bond = remove_bond,
- .cancel_bond = cancel_bond,
- .pin_reply = pin_reply,
- .ssp_reply = ssp_reply,
- .get_profile_interface = get_profile_interface,
- .dut_mode_configure = dut_mode_configure,
- .dut_mode_send = dut_mode_send
-};
-
-static const bt_interface_t *get_bluetooth_interface(void)
-{
- ALOGD(__func__);
-
- return &bluetooth_if;
-}
-
-static int close_bluetooth(struct hw_device_t *device)
-{
- ALOGD(__func__);
-
- cleanup();
-
- return 0;
-}
-
-static int open_bluetooth(const struct hw_module_t *module, char const *name,
- struct hw_device_t **device)
-{
- bluetooth_device_t *dev = malloc(sizeof(bluetooth_device_t));
-
- ALOGD(__func__);
-
- memset(dev, 0, sizeof(bluetooth_device_t));
- dev->common.tag = HARDWARE_DEVICE_TAG;
- dev->common.version = 0;
- dev->common.module = (struct hw_module_t *) module;
- dev->common.close = close_bluetooth;
- dev->get_bluetooth_interface = get_bluetooth_interface;
-
- *device = (struct hw_device_t *) dev;
-
- return 0;
-}
-
-static struct hw_module_methods_t bluetooth_module_methods = {
- .open = open_bluetooth,
-};
-
-struct hw_module_t HAL_MODULE_INFO_SYM = {
- .tag = HARDWARE_MODULE_TAG,
- .version_major = 1,
- .version_minor = 0,
- .id = BT_HARDWARE_MODULE_ID,
- .name = "BlueZ Bluetooth stack",
- .author = "Intel Corporation",
- .methods = &bluetooth_module_methods
-};
--
1.7.10.4


2013-10-16 14:36:34

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv4 07/11] android: Use kernel style to initialize struct fields

From: Andrei Emeltchenko <[email protected]>

---
android/hal_bluetooth.c | 46 +++++++++++++++++++++++-----------------------
1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
index 9bb9dcf..89b8ebb 100644
--- a/android/hal_bluetooth.c
+++ b/android/hal_bluetooth.c
@@ -309,29 +309,29 @@ static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t len)
}

static const bt_interface_t bluetooth_if = {
- sizeof(bt_interface_t),
- init,
- enable,
- disable,
- cleanup,
- get_adapter_properties,
- get_adapter_property,
- set_adapter_property,
- get_remote_device_properties,
- get_remote_device_property,
- set_remote_device_property,
- get_remote_service_record,
- get_remote_services,
- start_discovery,
- cancel_discovery,
- create_bond,
- remove_bond,
- cancel_bond,
- pin_reply,
- ssp_reply,
- get_profile_interface,
- dut_mode_configure,
- dut_mode_send
+ .size = sizeof(bt_interface_t),
+ .init = init,
+ .enable = enable,
+ .disable = disable,
+ .cleanup = cleanup,
+ .get_adapter_properties = get_adapter_properties,
+ .get_adapter_property = get_adapter_property,
+ .set_adapter_property = set_adapter_property,
+ .get_remote_device_properties = get_remote_device_properties,
+ .get_remote_device_property = get_remote_device_property,
+ .set_remote_device_property = set_remote_device_property,
+ .get_remote_service_record = get_remote_service_record,
+ .get_remote_services = get_remote_services,
+ .start_discovery = start_discovery,
+ .cancel_discovery = cancel_discovery,
+ .create_bond = create_bond,
+ .remove_bond = remove_bond,
+ .cancel_bond = cancel_bond,
+ .pin_reply = pin_reply,
+ .ssp_reply = ssp_reply,
+ .get_profile_interface = get_profile_interface,
+ .dut_mode_configure = dut_mode_configure,
+ .dut_mode_send = dut_mode_send
};

static const bt_interface_t *get_bluetooth_interface(void)
--
1.7.10.4


2013-10-16 14:36:29

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv4 02/11] android: Add basic mgmt initialization sequence

From: Andrei Emeltchenko <[email protected]>

Initialize bluetooth controller via mgmt interface.
---
Makefile.android | 4 +-
android/Android.mk | 5 ++
android/main.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 174 insertions(+), 1 deletion(-)

diff --git a/Makefile.android b/Makefile.android
index 02f3341..ab328a9 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -3,7 +3,9 @@ noinst_PROGRAMS += android/bluetoothd

android_bluetoothd_SOURCES = android/main.c \
src/log.c \
- android/hal-msg.h
+ android/hal-msg.h \
+ src/shared/util.h src/shared/util.c \
+ src/shared/mgmt.h src/shared/mgmt.c

android_bluetoothd_LDADD = @GLIB_LIBS@
endif
diff --git a/android/Android.mk b/android/Android.mk
index 0e025ac..4996080 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -15,10 +15,15 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
main.c \
log.c \
+ ../src/shared/mgmt.c \
+ ../src/shared/util.c \

LOCAL_C_INCLUDES := \
$(call include-path-for, glib) \
$(call include-path-for, glib)/glib \
+
+LOCAL_C_INCLUDES += \
+ $(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../src \

LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"
diff --git a/android/main.c b/android/main.c
index f75b0a8..512bfd9 100644
--- a/android/main.c
+++ b/android/main.c
@@ -25,6 +25,7 @@
#include <config.h>
#endif

+#include <stdbool.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
@@ -36,9 +37,17 @@

#include "log.h"

+#include "lib/bluetooth.h"
+#include "lib/mgmt.h"
+#include "src/shared/mgmt.h"
+
#define SHUTDOWN_GRACE_SECONDS 10

static GMainLoop *event_loop;
+static struct mgmt *mgmt_if = NULL;
+
+static uint8_t mgmt_version = 0;
+static uint8_t mgmt_revision = 0;

static gboolean quit_eventloop(gpointer user_data)
{
@@ -67,6 +76,159 @@ static GOptionEntry options[] = {
{ NULL }
};

+static void read_info_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ /* TODO: Store Controller information */
+
+ /* TODO: Register all event notification handlers */
+}
+
+static void mgmt_index_added_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("index %u", index);
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
+ read_info_complete, NULL, NULL) > 0)
+ return;
+
+ error("Failed to read adapter info for index %u", index);
+}
+
+static void mgmt_index_removed_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("index %u", index);
+}
+
+static void read_index_list_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_index_list *rp = param;
+ uint16_t num;
+ int i;
+
+ DBG("");
+
+ if (status) {
+ error("%s: Failed to read index list: %s (0x%02x)",
+ __func__, mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("%s: Wrong size of read index list response", __func__);
+ return;
+ }
+
+ num = btohs(rp->num_controllers);
+
+ DBG("Number of controllers: %u", num);
+
+ if (num * sizeof(uint16_t) + sizeof(*rp) != length) {
+ error("%s: Incorrect pkt size for index list rsp", __func__);
+ return;
+ }
+
+ for (i = 0; i < num; i++) {
+ uint16_t index;
+
+ index = btohs(rp->index[i]);
+
+ /**
+ * Use index added event notification.
+ */
+ mgmt_index_added_event(index, 0, NULL, NULL);
+ }
+}
+
+static void read_commands_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_commands *rp = param;
+
+ DBG("");
+
+ if (status) {
+ error("Failed to read supported commands: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("Wrong size response");
+ return;
+ }
+}
+
+static void read_version_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_version *rp = param;
+
+ DBG("");
+
+ if (status) {
+ error("Failed to read version information: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("Wrong size response");
+ return;
+ }
+
+ mgmt_version = rp->version;
+ mgmt_revision = btohs(rp->revision);
+
+ info("Bluetooth management interface %u.%u initialized",
+ mgmt_version, mgmt_revision);
+
+ if (mgmt_version < 1) {
+ error("Version 1.0 or later of management interface required");
+ abort();
+ }
+
+ mgmt_send(mgmt_if, MGMT_OP_READ_COMMANDS, MGMT_INDEX_NONE, 0, NULL,
+ read_commands_complete, NULL, NULL);
+
+ mgmt_register(mgmt_if, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE,
+ mgmt_index_added_event, NULL, NULL);
+ mgmt_register(mgmt_if, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE,
+ mgmt_index_removed_event, NULL, NULL);
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0,
+ NULL, read_index_list_complete, NULL, NULL) > 0)
+ return;
+
+ error("Failed to read controller index list");
+}
+
+static bool init_mgmt_interface(void)
+{
+ mgmt_if = mgmt_new_default();
+ if (!mgmt_if) {
+ error("Failed to access management interface");
+ return false;
+ }
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_VERSION, MGMT_INDEX_NONE, 0, NULL,
+ read_version_complete, NULL, NULL) == 0) {
+ error("Error sending READ_VERSION mgmt command");
+ return false;
+ }
+
+ return true;
+}
+
+static void cleanup_mgmt_interface(void)
+{
+ mgmt_unref(mgmt_if);
+ mgmt_if = NULL;
+}
+
int main(int argc, char *argv[])
{
GOptionContext *context;
@@ -100,10 +262,14 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);

+ if (!init_mgmt_interface())
+ return EXIT_FAILURE;
+
DBG("Entering main loop");

g_main_loop_run(event_loop);

+ cleanup_mgmt_interface();
g_main_loop_unref(event_loop);

info("Exit");
--
1.7.10.4


2013-10-16 14:36:33

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv4 06/11] android: Implement read_info_complete callback

From: Andrei Emeltchenko <[email protected]>

Handle read info complete callback from mgmt interface.
---
Makefile.android | 3 +-
android/Android.mk | 1 +
android/adapter.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++
android/adapter.h | 4 +++
android/main.c | 21 +++++++------
5 files changed, 103 insertions(+), 10 deletions(-)

diff --git a/Makefile.android b/Makefile.android
index 4d7da39..11eadc2 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -7,7 +7,8 @@ android_bluetoothd_SOURCES = android/main.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
+ src/shared/mgmt.h src/shared/mgmt.c \
+ android/adapter.h android/adapter.c

android_bluetoothd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
endif
diff --git a/android/Android.mk b/android/Android.mk
index 560fb0a..821f1dc 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -15,6 +15,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
main.c \
log.c \
+ adapter.c \
../src/shared/mgmt.c \
../src/shared/util.c \
../src/sdpd-database.c \
diff --git a/android/adapter.c b/android/adapter.c
index 9763530..a660ed0 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -21,14 +21,25 @@
*
*/

+#include "lib/bluetooth.h"
#include "src/shared/mgmt.h"
+#include "lib/mgmt.h"
#include "log.h"
#include "adapter.h"

struct bt_adapter {
struct mgmt *mgmt;
+ bdaddr_t bdaddr;
+ uint32_t dev_class;
+
+ char *name;
+
+ uint32_t supported_settings;
+ uint32_t current_settings;
};

+extern struct bt_adapter *default_adapter;
+
struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if)
{
struct bt_adapter *adapter;
@@ -52,3 +63,76 @@ void bt_adapter_stop(struct bt_adapter *adapter)
{
DBG("");
}
+
+static void load_link_keys_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("status %u", status);
+}
+
+void load_link_keys(struct bt_adapter *adapter, GSList *keys)
+{
+ struct mgmt_cp_load_link_keys *cp;
+ size_t key_len = g_slist_length(keys);
+ struct mgmt_link_key_info *key;
+ size_t len;
+
+ DBG("");
+
+ len = sizeof(*cp) + key_len * sizeof(*key);
+ cp = g_malloc0(len);
+
+ cp->debug_keys = 0;
+ cp->key_count = htobs(key_len);
+
+ mgmt_send(adapter->mgmt, MGMT_OP_LOAD_LINK_KEYS, 0, len,
+ cp, load_link_keys_complete, adapter, NULL);
+
+ free(cp);
+}
+
+void read_info_complete(uint8_t status, uint16_t length, const void *param,
+ void *user_data)
+{
+ struct bt_adapter *adapter = user_data;
+ const struct mgmt_rp_read_info *rp = param;
+
+ DBG("");
+
+ if (status) {
+ error("Failed to read info for index %u: %s (0x%02x)",
+ 0, mgmt_errstr(status), status);
+ goto failed;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("Too small read info complete response");
+ goto failed;
+ }
+
+ if (!bacmp(&rp->bdaddr, BDADDR_ANY)) {
+ error("No Bluetooth address");
+ goto failed;
+ }
+
+ /* Store adapter information */
+ bacpy(&adapter->bdaddr, &rp->bdaddr);
+ adapter->dev_class = rp->dev_class[0] | (rp->dev_class[1] << 8) |
+ (rp->dev_class[2] << 16);
+ adapter->name = g_strdup((const char *) rp->name);
+
+ adapter->supported_settings = btohs(rp->supported_settings);
+ adapter->current_settings = btohs(rp->current_settings);
+
+ /* TODO: Register all event notification handlers */
+
+ if (adapter->current_settings & MGMT_SETTING_POWERED)
+ bt_adapter_start(adapter);
+
+ load_link_keys(adapter, NULL);
+
+ return;
+
+failed:
+ default_adapter = NULL;
+}
diff --git a/android/adapter.h b/android/adapter.h
index 0f1445a..3025f89 100644
--- a/android/adapter.h
+++ b/android/adapter.h
@@ -34,3 +34,7 @@ struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if);

void bt_adapter_start(struct bt_adapter *adapter);
void bt_adapter_stop(struct bt_adapter *adapter);
+
+void read_info_complete(uint8_t status, uint16_t length, const void *param,
+ void *user_data);
+void load_link_keys(struct bt_adapter *adapter, GSList *keys);
diff --git a/android/main.c b/android/main.c
index 091ef20..39d6266 100644
--- a/android/main.c
+++ b/android/main.c
@@ -57,6 +57,8 @@
#include "lib/mgmt.h"
#include "src/shared/mgmt.h"

+#include "adapter.h"
+
#define SHUTDOWN_GRACE_SECONDS 10

static GMainLoop *event_loop;
@@ -65,6 +67,8 @@ static struct mgmt *mgmt_if = NULL;
static uint8_t mgmt_version = 0;
static uint8_t mgmt_revision = 0;

+struct bt_adapter *default_adapter = NULL;
+
static gboolean quit_eventloop(gpointer user_data)
{
g_main_loop_quit(event_loop);
@@ -92,21 +96,20 @@ static GOptionEntry options[] = {
{ NULL }
};

-static void read_info_complete(uint8_t status, uint16_t length,
- const void *param, void *user_data)
-{
- /* TODO: Store Controller information */
-
- /* TODO: Register all event notification handlers */
-}
-
static void mgmt_index_added_event(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
DBG("index %u", index);

+ if (default_adapter) {
+ DBG("skip event for index %u", index);
+ return;
+ }
+
+ default_adapter = bt_adapter_new(index, mgmt_if);
+
if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
- read_info_complete, NULL, NULL) > 0)
+ read_info_complete, default_adapter, NULL) > 0)
return;

error("Failed to read adapter info for index %u", index);
--
1.7.10.4


2013-10-16 14:36:37

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv4 10/11] android: Add HID Host skeleton

From: Andrei Emeltchenko <[email protected]>

Add skeleton for hidhost Android HAL. This is modified version
from Frederic Danis earlier patch set.
---
android/Android.mk | 1 +
android/hal-bluetooth.c | 4 +
android/hal-hidhost.c | 204 +++++++++++++++++++++++++++++++++++++++++++++++
android/hal.h | 1 +
4 files changed, 210 insertions(+)
create mode 100644 android/hal-hidhost.c

diff --git a/android/Android.mk b/android/Android.mk
index fb4383d..ab2171c 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -53,6 +53,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
hal-bluetooth.c \
hal-bt-sock.c \
+ hal-hidhost.c \

LOCAL_SHARED_LIBRARIES := \
libcutils \
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 89b8ebb..488606d 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -22,6 +22,7 @@

#include <hardware/bluetooth.h>
#include <hardware/bt_sock.h>
+#include <hardware/bt_hh.h>

#include <cutils/sockets.h>
#include <cutils/properties.h>
@@ -285,6 +286,9 @@ static const void *get_profile_interface(const char *profile_id)
if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
return bt_get_sock_interface();

+ if (!strcmp(profile_id, BT_PROFILE_HIDHOST_ID))
+ return bt_get_hidhost_interface();
+
return NULL;
}

diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
new file mode 100644
index 0000000..27cd1be
--- /dev/null
+++ b/android/hal-hidhost.c
@@ -0,0 +1,204 @@
+/*
+ * 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 <stdbool.h>
+
+#include <hardware/bluetooth.h>
+#include <hardware/bt_hh.h>
+
+#define LOG_TAG "BlueZ"
+#include <cutils/log.h>
+
+bthh_callbacks_t *bt_hh_cbacks;
+
+static bool interface_ready(void)
+{
+ return bt_hh_cbacks != NULL;
+}
+
+static bt_status_t bt_hidhost_connect(bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_disconnect(bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_virtual_unplug(bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_set_info(bt_bdaddr_t *bd_addr,
+ bthh_hid_info_t hid_info)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_get_protocol(bt_bdaddr_t *bd_addr,
+ bthh_protocol_mode_t protocolMode)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_set_protocol(bt_bdaddr_t *bd_addr,
+ bthh_protocol_mode_t protocolMode)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_get_report(bt_bdaddr_t *bd_addr,
+ bthh_report_type_t reportType,
+ uint8_t reportId,
+ int bufferSize)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_set_report(bt_bdaddr_t *bd_addr,
+ bthh_report_type_t reportType,
+ char *report)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr || !report)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_send_data(bt_bdaddr_t *bd_addr, char *data)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr || !data)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_init(bthh_callbacks_t *callbacks)
+{
+ ALOGI(__func__);
+
+ /* store reference to user callbacks */
+ bt_hh_cbacks = callbacks;
+
+ /* TODO: start HID Host thread */
+
+ /* TODO: enable service */
+
+ return BT_STATUS_SUCCESS;
+}
+
+static void bt_hidhost_cleanup(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return;
+
+ /* TODO: disable service */
+
+ /* TODO: stop HID Host thread */
+
+ bt_hh_cbacks = NULL;
+}
+
+static bthh_interface_t bt_hidhost_if = {
+ sizeof(bt_hidhost_if),
+ bt_hidhost_init,
+ bt_hidhost_connect,
+ bt_hidhost_disconnect,
+ bt_hidhost_virtual_unplug,
+ bt_hidhost_set_info,
+ bt_hidhost_get_protocol,
+ bt_hidhost_set_protocol,
+ bt_hidhost_get_report,
+ bt_hidhost_set_report,
+ bt_hidhost_send_data,
+ bt_hidhost_cleanup
+};
+
+bthh_interface_t *bt_get_hidhost_interface(void)
+{
+ return &bt_hidhost_if;
+}
diff --git a/android/hal.h b/android/hal.h
index 40fbf03..be69339 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -16,3 +16,4 @@
*/

btsock_interface_t *bt_get_sock_interface(void);
+bthh_interface_t *bt_get_hidhost_interface(void);
--
1.7.10.4


2013-10-16 14:36:27

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv4 00/11] Android BlueZ patches, second chunk

From: Andrei Emeltchenko <[email protected]>

This is second chunk from my initial big patch set. Fixed style issues commented
by Marcel.

Changes:
* v4: Fixes several typos and missing style issues commented by Marcel earlier.
* v3: Following upstream comments file names are changed from "_" to "-", added kernel style
struct initialization, fixed bug checking status for mgmt commands, added 2 HALs skeletons.
* v2: Corrected android_daemon -> enable_android autoconf stuff, better name for acquiring caps,
renamed hal_msg.h to hal-msg.h due to Johan's comment. Added small test-sdp fix.

Note that due to Marcel comment this cannot be built unless you include my patch
for Android bionic library:
http://code.google.com/p/android-bluez/source/detail?r=77a07e7703b63e280d9880baad30b3375e7df079&repo=bionic#

Andrei Emeltchenko (11):
android: Create HAL API header skeleton
android: Add basic mgmt initialization sequence
android: Add adapter and device struct for BlueZ daemon
android: sdp: Reuse BlueZ SDP server in Android
android: Add cap to bind to port < 1024
android: Implement read_info_complete callback
android: Use kernel style to initialize struct fields
android: Rename hal_bluetooth.c to hal-bluetooth.c
android: Rename hal_bt_sock.c to hal-bt-sock.c
android: Add HID Host skeleton
android: Add PAN skeleton

Makefile.android | 12 +-
android/Android.mk | 20 ++-
android/adapter.c | 138 +++++++++++++++++
android/adapter.h | 40 +++++
android/device.c | 25 +++
android/device.h | 24 +++
android/hal-bluetooth.c | 392 +++++++++++++++++++++++++++++++++++++++++++++++
android/hal-bt-sock.c | 85 ++++++++++
android/hal-hidhost.c | 204 ++++++++++++++++++++++++
android/hal-msg.h | 246 +++++++++++++++++++++++++++++
android/hal-pan.c | 120 +++++++++++++++
android/hal.h | 2 +
android/hal_bluetooth.c | 384 ----------------------------------------------
android/hal_bt_sock.c | 85 ----------
android/main.c | 244 +++++++++++++++++++++++++++++
configure.ac | 4 +
16 files changed, 1552 insertions(+), 473 deletions(-)
create mode 100644 android/adapter.c
create mode 100644 android/adapter.h
create mode 100644 android/device.c
create mode 100644 android/device.h
create mode 100644 android/hal-bluetooth.c
create mode 100644 android/hal-bt-sock.c
create mode 100644 android/hal-hidhost.c
create mode 100644 android/hal-msg.h
create mode 100644 android/hal-pan.c
delete mode 100644 android/hal_bluetooth.c
delete mode 100644 android/hal_bt_sock.c

--
1.7.10.4


2013-10-16 14:36:32

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv4 05/11] android: Add cap to bind to port < 1024

From: Andrei Emeltchenko <[email protected]>

For SDP server we need to bind to lower port, acquire this capability.
---
android/main.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 4 ++++
2 files changed, 74 insertions(+)

diff --git a/android/main.c b/android/main.c
index 3a20148..091ef20 100644
--- a/android/main.c
+++ b/android/main.c
@@ -32,6 +32,21 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/prctl.h>
+
+/**
+ * Include <sys/capability.h> for host build and
+ * also for Android 4.3 when it is added to bionic
+ */
+#if !defined(ANDROID) || (PLATFORM_SDK_VERSION > 17)
+#include <sys/capability.h>
+#endif
+
+#if defined(ANDROID)
+#include <private/android_filesystem_config.h>
+#endif

#include <glib.h>

@@ -230,6 +245,58 @@ static void cleanup_mgmt_interface(void)
mgmt_if = NULL;
}

+static bool set_capabilities(void)
+{
+ struct __user_cap_header_struct header;
+ struct __user_cap_data_struct cap;
+#if defined(ANDROID)
+ gid_t groups[] = {AID_NET_BT, AID_NET_BT_ADMIN, AID_NET_ADMIN};
+#endif
+
+ DBG("pid %d uid %d gid %d", getpid(), getuid(), getgid());
+
+ header.version = _LINUX_CAPABILITY_VERSION;
+
+ prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
+
+#if defined(ANDROID)
+ if (setgid(AID_BLUETOOTH) < 0)
+ warn("%s: setgid(): %s", __func__, strerror(errno));
+
+ if (setuid(AID_BLUETOOTH) < 0)
+ warn("%s: setuid(): %s", __func__, strerror(errno));
+#endif
+
+ header.version = _LINUX_CAPABILITY_VERSION;
+ header.pid = 0;
+
+ cap.effective = cap.permitted =
+ CAP_TO_MASK(CAP_SETGID) |
+ CAP_TO_MASK(CAP_NET_RAW) |
+ CAP_TO_MASK(CAP_NET_ADMIN) |
+ CAP_TO_MASK(CAP_NET_BIND_SERVICE);
+ cap.inheritable = 0;
+
+ if (capset(&header, &cap) < 0) {
+ error("%s: capset(): %s", __func__, strerror(errno));
+ return false;
+ }
+
+#if defined(ANDROID)
+ if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) < 0)
+ warn("%s: setgroups: %s", __func__, strerror(errno));
+#endif
+ if (capget(&header, &cap) < 0)
+ error("%s: capget(): %s", __func__, strerror(errno));
+ else
+ DBG("Caps: eff: 0x%x, perm: 0x%x, inh: 0x%x", cap.effective,
+ cap.permitted, cap.inheritable);
+
+ DBG("pid %d uid %d gid %d", getpid(), getuid(), getgid());
+
+ return true;
+}
+
int main(int argc, char *argv[])
{
GOptionContext *context;
@@ -263,6 +330,9 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);

+ if (!set_capabilities())
+ return EXIT_FAILURE;
+
if (!init_mgmt_interface())
return EXIT_FAILURE;

diff --git a/configure.ac b/configure.ac
index 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.7.10.4


2013-10-16 14:36:31

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv4 04/11] android: sdp: Reuse BlueZ SDP server in Android

From: Andrei Emeltchenko <[email protected]>

Reuse existing SDP server code in Android GPL daemon.
---
Makefile.android | 4 +++-
android/Android.mk | 8 ++++++++
android/main.c | 5 +++++
3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/Makefile.android b/Makefile.android
index ab328a9..4d7da39 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -4,10 +4,12 @@ noinst_PROGRAMS += android/bluetoothd
android_bluetoothd_SOURCES = android/main.c \
src/log.c \
android/hal-msg.h \
+ src/sdpd-database.c src/sdpd-server.c \
+ src/sdpd-service.c src/sdpd-request.c \
src/shared/util.h src/shared/util.c \
src/shared/mgmt.h src/shared/mgmt.c

-android_bluetoothd_LDADD = @GLIB_LIBS@
+android_bluetoothd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
endif

EXTRA_DIST += android/Android.mk android/log.c
diff --git a/android/Android.mk b/android/Android.mk
index 4996080..560fb0a 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -17,6 +17,13 @@ LOCAL_SRC_FILES := \
log.c \
../src/shared/mgmt.c \
../src/shared/util.c \
+ ../src/sdpd-database.c \
+ ../src/sdpd-service.c \
+ ../src/sdpd-request.c \
+ ../src/sdpd-server.c \
+ ../lib/sdp.c \
+ ../lib/bluetooth.c \
+ ../lib/hci.c \

LOCAL_C_INCLUDES := \
$(call include-path-for, glib) \
@@ -25,6 +32,7 @@ LOCAL_C_INCLUDES := \
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../src \
+ $(LOCAL_PATH)/../lib \

LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"

diff --git a/android/main.c b/android/main.c
index 512bfd9..3a20148 100644
--- a/android/main.c
+++ b/android/main.c
@@ -36,6 +36,7 @@
#include <glib.h>

#include "log.h"
+#include "src/sdpd.h"

#include "lib/bluetooth.h"
#include "lib/mgmt.h"
@@ -265,10 +266,14 @@ int main(int argc, char *argv[])
if (!init_mgmt_interface())
return EXIT_FAILURE;

+ /* Use params: mtu = 0, flags = 0 */
+ start_sdp_server(0, 0);
+
DBG("Entering main loop");

g_main_loop_run(event_loop);

+ stop_sdp_server();
cleanup_mgmt_interface();
g_main_loop_unref(event_loop);

--
1.7.10.4


2013-10-16 14:08:42

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv3 05/11] android: Add cap to bind to port < 1024

From: Andrei Emeltchenko <[email protected]>

For SDP server we need to bind to lower port, acquire this capability.
---
android/main.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 4 ++++
2 files changed, 74 insertions(+)

diff --git a/android/main.c b/android/main.c
index 5dd359c..2eecec9 100644
--- a/android/main.c
+++ b/android/main.c
@@ -32,6 +32,21 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/prctl.h>
+
+/**
+ * Include <sys/capability.h> for host build and
+ * also for Android 4.3 when it is added to bionic
+ */
+#if !defined(ANDROID) || (PLATFORM_SDK_VERSION > 17)
+#include <sys/capability.h>
+#endif
+
+#if defined(ANDROID)
+#include <private/android_filesystem_config.h>
+#endif

#include <glib.h>

@@ -232,6 +247,58 @@ static void cleanup_mgmt_interface(void)
mgmt_if = NULL;
}

+static bool set_capabilities(void)
+{
+ struct __user_cap_header_struct header;
+ struct __user_cap_data_struct cap;
+#if defined(ANDROID)
+ gid_t groups[] = {AID_NET_BT, AID_NET_BT_ADMIN, AID_NET_ADMIN};
+#endif
+
+ DBG("pid %d uid %d gid %d", getpid(), getuid(), getgid());
+
+ header.version = _LINUX_CAPABILITY_VERSION;
+
+ prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
+
+#if defined(ANDROID)
+ if (setgid(AID_BLUETOOTH) < 0)
+ warn("%s: setgid(): %s", __func__, strerror(errno));
+
+ if (setuid(AID_BLUETOOTH) < 0)
+ warn("%s: setuid(): %s", __func__, strerror(errno));
+#endif
+
+ header.version = _LINUX_CAPABILITY_VERSION;
+ header.pid = 0;
+
+ cap.effective = cap.permitted =
+ CAP_TO_MASK(CAP_SETGID) |
+ CAP_TO_MASK(CAP_NET_RAW) |
+ CAP_TO_MASK(CAP_NET_ADMIN) |
+ CAP_TO_MASK(CAP_NET_BIND_SERVICE);
+ cap.inheritable = 0;
+
+ if (capset(&header, &cap) < 0) {
+ error("%s: capset(): %s", __func__, strerror(errno));
+ return false;
+ }
+
+#if defined(ANDROID)
+ if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) < 0)
+ warn("%s: setgroups: %s", __func__, strerror(errno));
+#endif
+ if (capget(&header, &cap) < 0)
+ error("%s: capget(): %s", __func__, strerror(errno));
+ else
+ DBG("Caps: eff: 0x%x, perm: 0x%x, inh: 0x%x", cap.effective,
+ cap.permitted, cap.inheritable);
+
+ DBG("pid %d uid %d gid %d", getpid(), getuid(), getgid());
+
+ return true;
+}
+
int main(int argc, char *argv[])
{
GOptionContext *context;
@@ -265,6 +332,9 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);

+ if (!set_capabilities())
+ return EXIT_FAILURE;
+
if (!init_mgmt_interface())
return EXIT_FAILURE;

diff --git a/configure.ac b/configure.ac
index 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.7.10.4


2013-10-16 14:08:48

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv3 11/11] android: Add PAN skeleton

From: Andrei Emeltchenko <[email protected]>

Add skeleton for pan Android HAL. This is modified version
from Frederic Danis earlier patch set.
---
android/Android.mk | 1 +
android/hal-bluetooth.c | 4 ++
android/hal-pan.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++
android/hal.h | 1 +
4 files changed, 126 insertions(+)
create mode 100644 android/hal-pan.c

diff --git a/android/Android.mk b/android/Android.mk
index ab2171c..f369e34 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -54,6 +54,7 @@ LOCAL_SRC_FILES := \
hal-bluetooth.c \
hal-bt-sock.c \
hal-hidhost.c \
+ hal-pan.c \

LOCAL_SHARED_LIBRARIES := \
libcutils \
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 488606d..5f9d00b 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -23,6 +23,7 @@
#include <hardware/bluetooth.h>
#include <hardware/bt_sock.h>
#include <hardware/bt_hh.h>
+#include <hardware/bt_pan.h>

#include <cutils/sockets.h>
#include <cutils/properties.h>
@@ -289,6 +290,9 @@ static const void *get_profile_interface(const char *profile_id)
if (!strcmp(profile_id, BT_PROFILE_HIDHOST_ID))
return bt_get_hidhost_interface();

+ if (!strcmp(profile_id, BT_PROFILE_PAN_ID))
+ return bt_get_pan_interface();
+
return NULL;
}

diff --git a/android/hal-pan.c b/android/hal-pan.c
new file mode 100644
index 0000000..373494e
--- /dev/null
+++ b/android/hal-pan.c
@@ -0,0 +1,120 @@
+/*
+ * 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 <stdbool.h>
+
+#include <hardware/bluetooth.h>
+#include <hardware/bt_pan.h>
+
+#define LOG_TAG "BlueZ"
+#include <cutils/log.h>
+
+const btpan_callbacks_t *bt_pan_cbacks = NULL;
+
+static bool interface_ready(void)
+{
+ return bt_pan_cbacks != NULL;
+}
+
+static bt_status_t bt_pan_enable(int local_role)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int bt_pan_get_local_role(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BTPAN_ROLE_NONE;
+
+ return BTPAN_ROLE_NONE;
+}
+
+static bt_status_t bt_pan_connect(const bt_bdaddr_t *bd_addr, int local_role,
+ int remote_role)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_pan_disconnect(const bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_pan_init(const btpan_callbacks_t *callbacks)
+{
+ ALOGI(__func__);
+
+ bt_pan_cbacks = callbacks;
+
+ /* TODO: start HID Host thread */
+
+ /* TODO: enable service */
+
+ return BT_STATUS_SUCCESS;
+}
+
+static void bt_pan_cleanup()
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return;
+
+ /* TODO: disable service */
+
+ /* TODO: stop PAN thread */
+
+ bt_pan_cbacks = NULL;
+}
+
+static btpan_interface_t bt_pan_if = {
+ sizeof(bt_pan_if),
+ bt_pan_init,
+ bt_pan_enable,
+ bt_pan_get_local_role,
+ bt_pan_connect,
+ bt_pan_disconnect,
+ bt_pan_cleanup
+};
+
+btpan_interface_t *bt_get_pan_interface()
+{
+ return &bt_pan_if;
+}
diff --git a/android/hal.h b/android/hal.h
index be69339..38b90b2 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -17,3 +17,4 @@

btsock_interface_t *bt_get_sock_interface(void);
bthh_interface_t *bt_get_hidhost_interface(void);
+btpan_interface_t *bt_get_pan_interface(void);
--
1.7.10.4


2013-10-16 14:08:38

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv3 01/11] android: Create HAL API header skeleton

From: Andrei Emeltchenko <[email protected]>

Header describes the protocol between Android HAL threads and BlueZ
daemon. The header is added to host build and not to Android since
it is smart enough to include it automatically.
---
Makefile.android | 5 +-
android/hal-msg.h | 246 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 250 insertions(+), 1 deletion(-)
create mode 100644 android/hal-msg.h

diff --git a/Makefile.android b/Makefile.android
index 3ceefd8..02f3341 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -1,7 +1,10 @@
if ANDROID
noinst_PROGRAMS += android/bluetoothd

-android_bluetoothd_SOURCES = android/main.c src/log.c
+android_bluetoothd_SOURCES = android/main.c \
+ src/log.c \
+ android/hal-msg.h
+
android_bluetoothd_LDADD = @GLIB_LIBS@
endif

diff --git a/android/hal-msg.h b/android/hal-msg.h
new file mode 100644
index 0000000..4c5ca69
--- /dev/null
+++ b/android/hal-msg.h
@@ -0,0 +1,246 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+struct hal_msg_hdr {
+ uint8_t service_id;
+ uint8_t opcode;
+ uint16_t len;
+} __attribute__((packed));
+
+#define HAL_SERVICE_ID_CORE 0
+#define HAL_SERVICE_ID_BLUETOOTH 1
+#define HAL_SERVICE_ID_SOCK 2
+#define HAL_SERVICE_ID_HIDHOST 3
+#define HAL_SERVICE_ID_PAN 4
+#define HAL_SERVICE_ID_HANDSFREE 5
+#define HAL_SERVICE_ID_AD2P 6
+#define HAL_SERVICE_ID_HEALTH 7
+#define HAL_SERVICE_ID_AVRCP 8
+#define HAL_SERVICE_ID_GATT 9
+
+/* Core Service */
+
+#define HAL_MSG_OP_ERROR 0x00
+struct hal_msg_rsp_error {
+ uint8_t status;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_REGISTER_MODULE 0x01
+struct hal_msg_cmd_register_module {
+ uint8_t service_id;
+} __attribute__((packed));
+struct hal_msg_rsp_register_module {
+ uint8_t service_id;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_UNREGISTER_MODULE 0x02
+struct hal_msg_cmd_unregister_module {
+ uint8_t service_id;
+} __attribute__((packed));
+
+/* Bluetooth Core HAL API */
+
+#define HAL_MSG_OP_BT_ENABLE 0x01
+
+#define HAL_MSG_OP_BT_DISABLE 0x02
+
+#define HAL_MSG_OP_BT_GET_ADAPTER_PROPS 0x03
+
+#define HAL_MSG_OP_BT_GET_ADAPTER_PROP 0x04
+struct hal_msg_cmd_bt_get_adapter_prop {
+ uint8_t type;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SET_ADAPTER_PROP 0x05
+struct hal_msg_cmd_bt_set_adapter_prop {
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_DEVICE_PROPS 0x06
+struct hal_msg_cmd_bt_get_remote_device_props {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_DEVICE_PROP 0x07
+struct hal_msg_cmd_bt_get_remote_device_prop {
+ uint8_t bdaddr[6];
+ uint8_t type;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SET_REMOTE_DEVICE_PROP 0x08
+struct hal_msg_cmd_bt_set_remote_device_prop {
+ uint8_t bdaddr[6];
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_SERVICE_REC 0x09
+struct hal_msg_cmd_bt_get_remote_service_rec {
+ uint8_t bdaddr[6];
+ uint8_t uuid[16];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_SERVICE 0x0a
+struct hal_msg_cmd_bt_get_remote_service {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_START_DISCOVERY 0x0b
+
+#define HAL_MSG_OP_BT_CANCEL_DISCOVERY 0x0c
+
+#define HAL_MSG_OP_BT_CREATE_BOND 0x0d
+struct hal_msg_cmd_bt_create_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_REMOVE_BOND 0x0d
+struct hal_msg_cmd_bt_remove_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_CANCEL_BOND 0x0f
+struct hal_msg_cmd_bt_cancel_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_PIN_REPLY 0x10
+struct hal_msg_cmd_bt_pin_reply {
+ uint8_t bdaddr[6];
+ uint8_t accept;
+ uint8_t pin_len;
+ uint8_t pin_code[16];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SSP_REPLY 0x11
+struct hal_msg_cmd_bt_ssp_reply {
+ uint8_t bdaddr[6];
+ uint8_t ssp_variant;
+ uint8_t accept;
+ uint32_t passkey;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_DUT_MODE_CONF 0x12
+struct hal_msg_cmd_bt_dut_mode_conf {
+ uint8_t enable;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_DUT_MODE_SEND 0x13
+struct hal_msg_cmd_bt_dut_mode_send {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_LE_TEST_MODE 0x14
+struct hal_msg_cmd_bt_le_test_mode {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+/* Notifications and confirmations */
+
+#define HAL_MSG_EV_BT_ERROR 0x80
+
+#define HAL_MSG_EV_BT_ADAPTER_STATE_CHANGED 0x81
+struct hal_msg_ev_bt_adapter_state_changed {
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_ADAPTER_PROPS_CHANGED 0x82
+struct hal_property {
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+struct hal_msg_ev_bt_adapter_props_changed {
+ uint8_t status;
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_REMOTE_DEVICE_PROPS 0x83
+struct hal_msg_ev_bt_remote_device_props {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DEVICE_FOUND 0x84
+struct hal_msg_ev_bt_device_found {
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DISCOVERY_STATE_CHANGED 0x85
+struct hal_msg_ev_bt_discovery_state_changed {
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_PIN_REQUEST 0x86
+struct hal_msg_ev_bt_pin_request {
+ uint8_t bdaddr[6];
+ uint8_t name[249 - 1];
+ uint8_t class_of_dev[3];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_SSP_REQUEST 0x87
+struct hal_msg_ev_bt_ssp_request {
+ uint8_t bdaddr[6];
+ uint8_t name[249 - 1];
+ uint8_t class_of_dev[3];
+ uint8_t pairing_variant;
+ uint32_t passkey;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_BOND_STATE_CHANGED 0x88
+struct hal_msg_ev_bt_bond_state_changed {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_ACL_STATE_CHANGED 0x89
+struct hal_msg_ev_bt_acl_state_changed {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DUT_MODE_RECEIVE 0x8a
+struct hal_msg_ev_bt_dut_mode_receive {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_LE_TEST_MODE 0x8b
+struct hal_msg_ev_bt_le_test_mode {
+ uint8_t status;
+ uint16_t num_packets;
+} __attribute__((packed));
--
1.7.10.4


2013-10-16 14:08:45

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv3 08/11] android: Rename hal_bluetooth.c to hal-bluetooth.c

From: Andrei Emeltchenko <[email protected]>

---
android/Android.mk | 2 +-
android/hal-bluetooth.c | 384 +++++++++++++++++++++++++++++++++++++++++++++++
android/hal_bluetooth.c | 384 -----------------------------------------------
3 files changed, 385 insertions(+), 385 deletions(-)
create mode 100644 android/hal-bluetooth.c
delete mode 100644 android/hal_bluetooth.c

diff --git a/android/Android.mk b/android/Android.mk
index 821f1dc..021bb91 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -51,7 +51,7 @@ include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
- hal_bluetooth.c \
+ hal-bluetooth.c \
hal_bt_sock.c \

LOCAL_SHARED_LIBRARIES := \
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
new file mode 100644
index 0000000..89b8ebb
--- /dev/null
+++ b/android/hal-bluetooth.c
@@ -0,0 +1,384 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+#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 SERVICE_NAME "bluetoothd"
+
+bt_callbacks_t *bt_hal_cbacks = NULL;
+
+static bool interface_ready(void)
+{
+ return bt_hal_cbacks != NULL;
+}
+
+static bool start_bt_daemon(void)
+{
+ int tries = 40; /* wait 4 seconds for completion */
+
+ ALOGD(__func__);
+
+ /* Start Android Bluetooth daemon service */
+ property_set("ctl.start", SERVICE_NAME);
+
+ while (tries-- > 0) {
+ char val[PROPERTY_VALUE_MAX];
+
+ if (property_get("init.svc." SERVICE_NAME, val, NULL)) {
+ if (!strcmp(val, "running")) {
+ ALOGI("Android BlueZ daemon started");
+ return true;
+ }
+ } else {
+ return false;
+ }
+
+ usleep(100000);
+ }
+
+ return false;
+}
+
+static int init(bt_callbacks_t *callbacks)
+{
+ ALOGD(__func__);
+
+ if (interface_ready())
+ return BT_STATUS_SUCCESS;
+
+ if (start_bt_daemon()) {
+ /* TODO: open channel */
+
+ bt_hal_cbacks = callbacks;
+
+ return BT_STATUS_SUCCESS;
+ }
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int enable(void)
+{
+ ALOGD(__func__);
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int disable(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static void cleanup(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return;
+
+ bt_hal_cbacks = NULL;
+}
+
+static int get_adapter_properties(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_adapter_property(bt_property_type_t type)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int set_adapter_property(const bt_property_t *property)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (property == NULL)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_device_property(bt_bdaddr_t *remote_addr,
+ bt_property_type_t type)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int set_remote_device_property(bt_bdaddr_t *remote_addr,
+ const bt_property_t *property)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_services(bt_bdaddr_t *remote_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int start_discovery(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int cancel_discovery(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int create_bond(const bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int cancel_bond(const bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int remove_bond(const bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
+ uint8_t pin_len, bt_pin_code_t *pin_code)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
+ uint8_t accept, uint32_t passkey)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static const void *get_profile_interface(const char *profile_id)
+{
+ ALOGD("%s: %s", __func__, profile_id);
+
+ if (!interface_ready())
+ return NULL;
+
+ if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
+ return bt_get_sock_interface();
+
+ return NULL;
+}
+
+static int dut_mode_configure(uint8_t enable)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t len)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static const bt_interface_t bluetooth_if = {
+ .size = sizeof(bt_interface_t),
+ .init = init,
+ .enable = enable,
+ .disable = disable,
+ .cleanup = cleanup,
+ .get_adapter_properties = get_adapter_properties,
+ .get_adapter_property = get_adapter_property,
+ .set_adapter_property = set_adapter_property,
+ .get_remote_device_properties = get_remote_device_properties,
+ .get_remote_device_property = get_remote_device_property,
+ .set_remote_device_property = set_remote_device_property,
+ .get_remote_service_record = get_remote_service_record,
+ .get_remote_services = get_remote_services,
+ .start_discovery = start_discovery,
+ .cancel_discovery = cancel_discovery,
+ .create_bond = create_bond,
+ .remove_bond = remove_bond,
+ .cancel_bond = cancel_bond,
+ .pin_reply = pin_reply,
+ .ssp_reply = ssp_reply,
+ .get_profile_interface = get_profile_interface,
+ .dut_mode_configure = dut_mode_configure,
+ .dut_mode_send = dut_mode_send
+};
+
+static const bt_interface_t *get_bluetooth_interface(void)
+{
+ ALOGD(__func__);
+
+ return &bluetooth_if;
+}
+
+static int close_bluetooth(struct hw_device_t *device)
+{
+ ALOGD(__func__);
+
+ cleanup();
+
+ return 0;
+}
+
+static int open_bluetooth(const struct hw_module_t *module, char const *name,
+ struct hw_device_t **device)
+{
+ bluetooth_device_t *dev = malloc(sizeof(bluetooth_device_t));
+
+ ALOGD(__func__);
+
+ memset(dev, 0, sizeof(bluetooth_device_t));
+ dev->common.tag = HARDWARE_DEVICE_TAG;
+ dev->common.version = 0;
+ dev->common.module = (struct hw_module_t *) module;
+ dev->common.close = close_bluetooth;
+ dev->get_bluetooth_interface = get_bluetooth_interface;
+
+ *device = (struct hw_device_t *) dev;
+
+ return 0;
+}
+
+static struct hw_module_methods_t bluetooth_module_methods = {
+ .open = open_bluetooth,
+};
+
+struct hw_module_t HAL_MODULE_INFO_SYM = {
+ .tag = HARDWARE_MODULE_TAG,
+ .version_major = 1,
+ .version_minor = 0,
+ .id = BT_HARDWARE_MODULE_ID,
+ .name = "BlueZ Bluetooth stack",
+ .author = "Intel Corporation",
+ .methods = &bluetooth_module_methods
+};
diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
deleted file mode 100644
index 89b8ebb..0000000
--- a/android/hal_bluetooth.c
+++ /dev/null
@@ -1,384 +0,0 @@
-/*
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdbool.h>
-
-#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 SERVICE_NAME "bluetoothd"
-
-bt_callbacks_t *bt_hal_cbacks = NULL;
-
-static bool interface_ready(void)
-{
- return bt_hal_cbacks != NULL;
-}
-
-static bool start_bt_daemon(void)
-{
- int tries = 40; /* wait 4 seconds for completion */
-
- ALOGD(__func__);
-
- /* Start Android Bluetooth daemon service */
- property_set("ctl.start", SERVICE_NAME);
-
- while (tries-- > 0) {
- char val[PROPERTY_VALUE_MAX];
-
- if (property_get("init.svc." SERVICE_NAME, val, NULL)) {
- if (!strcmp(val, "running")) {
- ALOGI("Android BlueZ daemon started");
- return true;
- }
- } else {
- return false;
- }
-
- usleep(100000);
- }
-
- return false;
-}
-
-static int init(bt_callbacks_t *callbacks)
-{
- ALOGD(__func__);
-
- if (interface_ready())
- return BT_STATUS_SUCCESS;
-
- if (start_bt_daemon()) {
- /* TODO: open channel */
-
- bt_hal_cbacks = callbacks;
-
- return BT_STATUS_SUCCESS;
- }
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int enable(void)
-{
- ALOGD(__func__);
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int disable(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static void cleanup(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return;
-
- bt_hal_cbacks = NULL;
-}
-
-static int get_adapter_properties(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_adapter_property(bt_property_type_t type)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int set_adapter_property(const bt_property_t *property)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- if (property == NULL)
- return BT_STATUS_PARM_INVALID;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_remote_device_property(bt_bdaddr_t *remote_addr,
- bt_property_type_t type)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int set_remote_device_property(bt_bdaddr_t *remote_addr,
- const bt_property_t *property)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int get_remote_services(bt_bdaddr_t *remote_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int start_discovery(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int cancel_discovery(void)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int create_bond(const bt_bdaddr_t *bd_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- if (!bd_addr)
- return BT_STATUS_PARM_INVALID;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int cancel_bond(const bt_bdaddr_t *bd_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int remove_bond(const bt_bdaddr_t *bd_addr)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
- uint8_t pin_len, bt_pin_code_t *pin_code)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
- uint8_t accept, uint32_t passkey)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- if (!bd_addr)
- return BT_STATUS_PARM_INVALID;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static const void *get_profile_interface(const char *profile_id)
-{
- ALOGD("%s: %s", __func__, profile_id);
-
- if (!interface_ready())
- return NULL;
-
- if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
- return bt_get_sock_interface();
-
- return NULL;
-}
-
-static int dut_mode_configure(uint8_t enable)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t len)
-{
- ALOGD(__func__);
-
- if (!interface_ready())
- return BT_STATUS_NOT_READY;
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static const bt_interface_t bluetooth_if = {
- .size = sizeof(bt_interface_t),
- .init = init,
- .enable = enable,
- .disable = disable,
- .cleanup = cleanup,
- .get_adapter_properties = get_adapter_properties,
- .get_adapter_property = get_adapter_property,
- .set_adapter_property = set_adapter_property,
- .get_remote_device_properties = get_remote_device_properties,
- .get_remote_device_property = get_remote_device_property,
- .set_remote_device_property = set_remote_device_property,
- .get_remote_service_record = get_remote_service_record,
- .get_remote_services = get_remote_services,
- .start_discovery = start_discovery,
- .cancel_discovery = cancel_discovery,
- .create_bond = create_bond,
- .remove_bond = remove_bond,
- .cancel_bond = cancel_bond,
- .pin_reply = pin_reply,
- .ssp_reply = ssp_reply,
- .get_profile_interface = get_profile_interface,
- .dut_mode_configure = dut_mode_configure,
- .dut_mode_send = dut_mode_send
-};
-
-static const bt_interface_t *get_bluetooth_interface(void)
-{
- ALOGD(__func__);
-
- return &bluetooth_if;
-}
-
-static int close_bluetooth(struct hw_device_t *device)
-{
- ALOGD(__func__);
-
- cleanup();
-
- return 0;
-}
-
-static int open_bluetooth(const struct hw_module_t *module, char const *name,
- struct hw_device_t **device)
-{
- bluetooth_device_t *dev = malloc(sizeof(bluetooth_device_t));
-
- ALOGD(__func__);
-
- memset(dev, 0, sizeof(bluetooth_device_t));
- dev->common.tag = HARDWARE_DEVICE_TAG;
- dev->common.version = 0;
- dev->common.module = (struct hw_module_t *) module;
- dev->common.close = close_bluetooth;
- dev->get_bluetooth_interface = get_bluetooth_interface;
-
- *device = (struct hw_device_t *) dev;
-
- return 0;
-}
-
-static struct hw_module_methods_t bluetooth_module_methods = {
- .open = open_bluetooth,
-};
-
-struct hw_module_t HAL_MODULE_INFO_SYM = {
- .tag = HARDWARE_MODULE_TAG,
- .version_major = 1,
- .version_minor = 0,
- .id = BT_HARDWARE_MODULE_ID,
- .name = "BlueZ Bluetooth stack",
- .author = "Intel Corporation",
- .methods = &bluetooth_module_methods
-};
--
1.7.10.4


2013-10-16 14:08:44

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv3 07/11] android: Use kernel style to initialize struct fields

From: Andrei Emeltchenko <[email protected]>

---
android/hal_bluetooth.c | 46 +++++++++++++++++++++++-----------------------
1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
index 9bb9dcf..89b8ebb 100644
--- a/android/hal_bluetooth.c
+++ b/android/hal_bluetooth.c
@@ -309,29 +309,29 @@ static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t len)
}

static const bt_interface_t bluetooth_if = {
- sizeof(bt_interface_t),
- init,
- enable,
- disable,
- cleanup,
- get_adapter_properties,
- get_adapter_property,
- set_adapter_property,
- get_remote_device_properties,
- get_remote_device_property,
- set_remote_device_property,
- get_remote_service_record,
- get_remote_services,
- start_discovery,
- cancel_discovery,
- create_bond,
- remove_bond,
- cancel_bond,
- pin_reply,
- ssp_reply,
- get_profile_interface,
- dut_mode_configure,
- dut_mode_send
+ .size = sizeof(bt_interface_t),
+ .init = init,
+ .enable = enable,
+ .disable = disable,
+ .cleanup = cleanup,
+ .get_adapter_properties = get_adapter_properties,
+ .get_adapter_property = get_adapter_property,
+ .set_adapter_property = set_adapter_property,
+ .get_remote_device_properties = get_remote_device_properties,
+ .get_remote_device_property = get_remote_device_property,
+ .set_remote_device_property = set_remote_device_property,
+ .get_remote_service_record = get_remote_service_record,
+ .get_remote_services = get_remote_services,
+ .start_discovery = start_discovery,
+ .cancel_discovery = cancel_discovery,
+ .create_bond = create_bond,
+ .remove_bond = remove_bond,
+ .cancel_bond = cancel_bond,
+ .pin_reply = pin_reply,
+ .ssp_reply = ssp_reply,
+ .get_profile_interface = get_profile_interface,
+ .dut_mode_configure = dut_mode_configure,
+ .dut_mode_send = dut_mode_send
};

static const bt_interface_t *get_bluetooth_interface(void)
--
1.7.10.4


2013-10-16 14:08:46

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv3 09/11] android: Rename hal_bt_sock.c to hal-bt-sock.c

From: Andrei Emeltchenko <[email protected]>

---
android/Android.mk | 2 +-
android/hal-bt-sock.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++
android/hal_bt_sock.c | 85 -------------------------------------------------
3 files changed, 86 insertions(+), 86 deletions(-)
create mode 100644 android/hal-bt-sock.c
delete mode 100644 android/hal_bt_sock.c

diff --git a/android/Android.mk b/android/Android.mk
index 021bb91..fb4383d 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -52,7 +52,7 @@ include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
hal-bluetooth.c \
- hal_bt_sock.c \
+ hal-bt-sock.c \

LOCAL_SHARED_LIBRARIES := \
libcutils \
diff --git a/android/hal-bt-sock.c b/android/hal-bt-sock.c
new file mode 100644
index 0000000..3a6d173
--- /dev/null
+++ b/android/hal-bt-sock.c
@@ -0,0 +1,85 @@
+/*
+ * 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 <stdlib.h>
+
+#include <hardware/bluetooth.h>
+#include <hardware/bt_sock.h>
+
+#define LOG_TAG "BlueZ"
+#include <cutils/log.h>
+
+static bt_status_t btsock_listen_rfcomm(const char *service_name,
+ const uint8_t *uuid, int chan,
+ int *sock, int flags)
+{
+ ALOGD(__func__);
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t listen(btsock_type_t type, const char *service_name,
+ const uint8_t *uuid, int chan,
+ int *sock, int flags)
+{
+ if ((!uuid && chan <= 0) || !sock) {
+ ALOGE("%s: invalid params: uuid %p, chan %d, sock %p",
+ __func__, uuid, chan, sock);
+ return BT_STATUS_PARM_INVALID;
+ }
+
+ ALOGD("%s: uuid %p chan %d sock %p type %d service_name %s",
+ __func__, uuid, chan, sock, type, service_name);
+
+ switch (type) {
+ case BTSOCK_RFCOMM:
+ return btsock_listen_rfcomm(service_name, uuid, chan,
+ sock, flags);
+ default:
+ ALOGE("%s: Socket type %d not supported", __func__, type);
+ break;
+ }
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t connect(const bt_bdaddr_t *bdaddr, btsock_type_t type,
+ const uint8_t *uuid, int chan,
+ int *sock, int flags)
+{
+ if ((!uuid && chan <= 0) || !bdaddr || !sock) {
+ ALOGE("invalid params: bd_addr %p, uuid %p, chan %d, sock %p",
+ bdaddr, uuid, chan, sock);
+ return BT_STATUS_PARM_INVALID;
+ }
+
+ ALOGD("%s: uuid %p chan %d sock %p type %d", __func__, uuid, chan,
+ sock, type);
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static btsock_interface_t btsock_if = {
+ sizeof(btsock_if),
+ listen,
+ connect
+};
+
+btsock_interface_t *bt_get_sock_interface(void)
+{
+ return &btsock_if;
+}
diff --git a/android/hal_bt_sock.c b/android/hal_bt_sock.c
deleted file mode 100644
index 3a6d173..0000000
--- a/android/hal_bt_sock.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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 <stdlib.h>
-
-#include <hardware/bluetooth.h>
-#include <hardware/bt_sock.h>
-
-#define LOG_TAG "BlueZ"
-#include <cutils/log.h>
-
-static bt_status_t btsock_listen_rfcomm(const char *service_name,
- const uint8_t *uuid, int chan,
- int *sock, int flags)
-{
- ALOGD(__func__);
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static bt_status_t listen(btsock_type_t type, const char *service_name,
- const uint8_t *uuid, int chan,
- int *sock, int flags)
-{
- if ((!uuid && chan <= 0) || !sock) {
- ALOGE("%s: invalid params: uuid %p, chan %d, sock %p",
- __func__, uuid, chan, sock);
- return BT_STATUS_PARM_INVALID;
- }
-
- ALOGD("%s: uuid %p chan %d sock %p type %d service_name %s",
- __func__, uuid, chan, sock, type, service_name);
-
- switch (type) {
- case BTSOCK_RFCOMM:
- return btsock_listen_rfcomm(service_name, uuid, chan,
- sock, flags);
- default:
- ALOGE("%s: Socket type %d not supported", __func__, type);
- break;
- }
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static bt_status_t connect(const bt_bdaddr_t *bdaddr, btsock_type_t type,
- const uint8_t *uuid, int chan,
- int *sock, int flags)
-{
- if ((!uuid && chan <= 0) || !bdaddr || !sock) {
- ALOGE("invalid params: bd_addr %p, uuid %p, chan %d, sock %p",
- bdaddr, uuid, chan, sock);
- return BT_STATUS_PARM_INVALID;
- }
-
- ALOGD("%s: uuid %p chan %d sock %p type %d", __func__, uuid, chan,
- sock, type);
-
- return BT_STATUS_UNSUPPORTED;
-}
-
-static btsock_interface_t btsock_if = {
- sizeof(btsock_if),
- listen,
- connect
-};
-
-btsock_interface_t *bt_get_sock_interface(void)
-{
- return &btsock_if;
-}
--
1.7.10.4


2013-10-16 14:08:39

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv3 02/11] android: Add basic mgmt initialization sequence

From: Andrei Emeltchenko <[email protected]>

Initialize bluetooth controller via mgmt interface.
---
Makefile.android | 4 +-
android/Android.mk | 5 ++
android/main.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 176 insertions(+), 1 deletion(-)

diff --git a/Makefile.android b/Makefile.android
index 02f3341..ab328a9 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -3,7 +3,9 @@ noinst_PROGRAMS += android/bluetoothd

android_bluetoothd_SOURCES = android/main.c \
src/log.c \
- android/hal-msg.h
+ android/hal-msg.h \
+ src/shared/util.h src/shared/util.c \
+ src/shared/mgmt.h src/shared/mgmt.c

android_bluetoothd_LDADD = @GLIB_LIBS@
endif
diff --git a/android/Android.mk b/android/Android.mk
index 0e025ac..4996080 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -15,10 +15,15 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
main.c \
log.c \
+ ../src/shared/mgmt.c \
+ ../src/shared/util.c \

LOCAL_C_INCLUDES := \
$(call include-path-for, glib) \
$(call include-path-for, glib)/glib \
+
+LOCAL_C_INCLUDES += \
+ $(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../src \

LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"
diff --git a/android/main.c b/android/main.c
index f75b0a8..64f1a02 100644
--- a/android/main.c
+++ b/android/main.c
@@ -25,6 +25,7 @@
#include <config.h>
#endif

+#include <stdbool.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
@@ -36,9 +37,17 @@

#include "log.h"

+#include "lib/bluetooth.h"
+#include "lib/mgmt.h"
+#include "src/shared/mgmt.h"
+
#define SHUTDOWN_GRACE_SECONDS 10

static GMainLoop *event_loop;
+static struct mgmt *mgmt_if = NULL;
+
+static uint8_t mgmt_version = 0;
+static uint8_t mgmt_revision = 0;

static gboolean quit_eventloop(gpointer user_data)
{
@@ -67,6 +76,161 @@ static GOptionEntry options[] = {
{ NULL }
};

+static void read_info_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ /* TODO: Store Controller information */
+
+ /* TODO: Register all event notification handlers */
+}
+
+
+static void mgmt_index_added_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("index %u", index);
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
+ read_info_complete, NULL, NULL) > 0)
+ return;
+
+ error("Failed to read adapter info for index %u", index);
+
+}
+
+static void mgmt_index_removed_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("index %u", index);
+}
+
+static void read_index_list_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_index_list *rp = param;
+ uint16_t num;
+ int i;
+
+ DBG("");
+
+ if (status) {
+ error("%s: Failed to read index list: %s (0x%02x)",
+ __func__, mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("%s: Wrong size of read index list response", __func__);
+ return;
+ }
+
+ num = btohs(rp->num_controllers);
+
+ DBG("Number of controllers: %u", num);
+
+ if (num * sizeof(uint16_t) + sizeof(*rp) != length) {
+ error("%s: Incorrect pkt size for index list rsp", __func__);
+ return;
+ }
+
+ for (i = 0; i < num; i++) {
+ uint16_t index;
+
+ index = btohs(rp->index[i]);
+
+ /**
+ * Use index added event notification.
+ */
+ mgmt_index_added_event(index, 0, NULL, NULL);
+ }
+}
+
+static void read_commands_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_commands *rp = param;
+
+ DBG("");
+
+ if (status) {
+ error("Failed to read supported commands: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("Wrong size response");
+ return;
+ }
+}
+
+static void read_version_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_version *rp = param;
+
+ DBG("");
+
+ if (status) {
+ error("Failed to read version information: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("Wrong size response");
+ return;
+ }
+
+ mgmt_version = rp->version;
+ mgmt_revision = btohs(rp->revision);
+
+ info("Bluetooth management interface %u.%u initialized",
+ mgmt_version, mgmt_revision);
+
+ if (mgmt_version < 1) {
+ error("Version 1.0 or later of management interface required");
+ abort();
+ }
+
+ mgmt_send(mgmt_if, MGMT_OP_READ_COMMANDS, MGMT_INDEX_NONE, 0, NULL,
+ read_commands_complete, NULL, NULL);
+
+ mgmt_register(mgmt_if, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE,
+ mgmt_index_added_event, NULL, NULL);
+ mgmt_register(mgmt_if, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE,
+ mgmt_index_removed_event, NULL, NULL);
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0,
+ NULL, read_index_list_complete, NULL, NULL) > 0)
+ return;
+
+ error("Failed to read controller index list");
+}
+
+static bool init_mgmt_interface(void)
+{
+ mgmt_if = mgmt_new_default();
+ if (!mgmt_if) {
+ error("Failed to access management interface");
+ return false;
+ }
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_VERSION, MGMT_INDEX_NONE, 0, NULL,
+ read_version_complete, NULL, NULL) == 0) {
+ error("Error sending READ_VERSION mgmt command");
+ return false;
+ }
+
+ return true;
+}
+
+static void cleanup_mgmt_interface(void)
+{
+ mgmt_unref(mgmt_if);
+ mgmt_if = NULL;
+}
+
int main(int argc, char *argv[])
{
GOptionContext *context;
@@ -100,10 +264,14 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);

+ if (!init_mgmt_interface())
+ return EXIT_FAILURE;
+
DBG("Entering main loop");

g_main_loop_run(event_loop);

+ cleanup_mgmt_interface();
g_main_loop_unref(event_loop);

info("Exit");
--
1.7.10.4


2013-10-16 14:08:43

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv3 06/11] android: Implement read_info_complete callback

From: Andrei Emeltchenko <[email protected]>

Handle read info complete callback from mgmt interface.
---
Makefile.android | 3 +-
android/Android.mk | 1 +
android/adapter.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++
android/adapter.h | 4 +++
android/main.c | 27 ++++++++++-------
5 files changed, 107 insertions(+), 12 deletions(-)

diff --git a/Makefile.android b/Makefile.android
index 4d7da39..11eadc2 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -7,7 +7,8 @@ android_bluetoothd_SOURCES = android/main.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
+ src/shared/mgmt.h src/shared/mgmt.c \
+ android/adapter.h android/adapter.c

android_bluetoothd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
endif
diff --git a/android/Android.mk b/android/Android.mk
index 560fb0a..821f1dc 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -15,6 +15,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
main.c \
log.c \
+ adapter.c \
../src/shared/mgmt.c \
../src/shared/util.c \
../src/sdpd-database.c \
diff --git a/android/adapter.c b/android/adapter.c
index 9763530..a660ed0 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -21,14 +21,25 @@
*
*/

+#include "lib/bluetooth.h"
#include "src/shared/mgmt.h"
+#include "lib/mgmt.h"
#include "log.h"
#include "adapter.h"

struct bt_adapter {
struct mgmt *mgmt;
+ bdaddr_t bdaddr;
+ uint32_t dev_class;
+
+ char *name;
+
+ uint32_t supported_settings;
+ uint32_t current_settings;
};

+extern struct bt_adapter *default_adapter;
+
struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if)
{
struct bt_adapter *adapter;
@@ -52,3 +63,76 @@ void bt_adapter_stop(struct bt_adapter *adapter)
{
DBG("");
}
+
+static void load_link_keys_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("status %u", status);
+}
+
+void load_link_keys(struct bt_adapter *adapter, GSList *keys)
+{
+ struct mgmt_cp_load_link_keys *cp;
+ size_t key_len = g_slist_length(keys);
+ struct mgmt_link_key_info *key;
+ size_t len;
+
+ DBG("");
+
+ len = sizeof(*cp) + key_len * sizeof(*key);
+ cp = g_malloc0(len);
+
+ cp->debug_keys = 0;
+ cp->key_count = htobs(key_len);
+
+ mgmt_send(adapter->mgmt, MGMT_OP_LOAD_LINK_KEYS, 0, len,
+ cp, load_link_keys_complete, adapter, NULL);
+
+ free(cp);
+}
+
+void read_info_complete(uint8_t status, uint16_t length, const void *param,
+ void *user_data)
+{
+ struct bt_adapter *adapter = user_data;
+ const struct mgmt_rp_read_info *rp = param;
+
+ DBG("");
+
+ if (status) {
+ error("Failed to read info for index %u: %s (0x%02x)",
+ 0, mgmt_errstr(status), status);
+ goto failed;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("Too small read info complete response");
+ goto failed;
+ }
+
+ if (!bacmp(&rp->bdaddr, BDADDR_ANY)) {
+ error("No Bluetooth address");
+ goto failed;
+ }
+
+ /* Store adapter information */
+ bacpy(&adapter->bdaddr, &rp->bdaddr);
+ adapter->dev_class = rp->dev_class[0] | (rp->dev_class[1] << 8) |
+ (rp->dev_class[2] << 16);
+ adapter->name = g_strdup((const char *) rp->name);
+
+ adapter->supported_settings = btohs(rp->supported_settings);
+ adapter->current_settings = btohs(rp->current_settings);
+
+ /* TODO: Register all event notification handlers */
+
+ if (adapter->current_settings & MGMT_SETTING_POWERED)
+ bt_adapter_start(adapter);
+
+ load_link_keys(adapter, NULL);
+
+ return;
+
+failed:
+ default_adapter = NULL;
+}
diff --git a/android/adapter.h b/android/adapter.h
index 0f1445a..3025f89 100644
--- a/android/adapter.h
+++ b/android/adapter.h
@@ -34,3 +34,7 @@ struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if);

void bt_adapter_start(struct bt_adapter *adapter);
void bt_adapter_stop(struct bt_adapter *adapter);
+
+void read_info_complete(uint8_t status, uint16_t length, const void *param,
+ void *user_data);
+void load_link_keys(struct bt_adapter *adapter, GSList *keys);
diff --git a/android/main.c b/android/main.c
index 2eecec9..0747a0e 100644
--- a/android/main.c
+++ b/android/main.c
@@ -57,6 +57,8 @@
#include "lib/mgmt.h"
#include "src/shared/mgmt.h"

+#include "adapter.h"
+
#define SHUTDOWN_GRACE_SECONDS 10

static GMainLoop *event_loop;
@@ -65,6 +67,8 @@ static struct mgmt *mgmt_if = NULL;
static uint8_t mgmt_version = 0;
static uint8_t mgmt_revision = 0;

+struct bt_adapter *default_adapter = NULL;
+
static gboolean quit_eventloop(gpointer user_data)
{
g_main_loop_quit(event_loop);
@@ -92,26 +96,27 @@ static GOptionEntry options[] = {
{ NULL }
};

-static void read_info_complete(uint8_t status, uint16_t length,
- const void *param, void *user_data)
-{
- /* TODO: Store Controller information */
-
- /* TODO: Register all event notification handlers */
-}
-
-
static void mgmt_index_added_event(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
DBG("index %u", index);

+ if (default_adapter) {
+ DBG("skip event for index %d", index);
+ return;
+ }
+
+ default_adapter = bt_adapter_new(index, mgmt_if);
+ if (default_adapter == NULL) {
+ error("Unable to create new adapter for index %u", index);
+ return;
+ }
+
if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
- read_info_complete, NULL, NULL) > 0)
+ read_info_complete, default_adapter, NULL) > 0)
return;

error("Failed to read adapter info for index %u", index);
-
}

static void mgmt_index_removed_event(uint16_t index, uint16_t length,
--
1.7.10.4


2013-10-16 14:08:47

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv3 10/11] android: Add HID Host skeleton

From: Andrei Emeltchenko <[email protected]>

Add skeleton for hidhost Android HAL. This is modified version
from Frederic Danis earlier patch set.
---
android/Android.mk | 1 +
android/hal-bluetooth.c | 4 +
android/hal-hidhost.c | 204 +++++++++++++++++++++++++++++++++++++++++++++++
android/hal.h | 1 +
4 files changed, 210 insertions(+)
create mode 100644 android/hal-hidhost.c

diff --git a/android/Android.mk b/android/Android.mk
index fb4383d..ab2171c 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -53,6 +53,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
hal-bluetooth.c \
hal-bt-sock.c \
+ hal-hidhost.c \

LOCAL_SHARED_LIBRARIES := \
libcutils \
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 89b8ebb..488606d 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -22,6 +22,7 @@

#include <hardware/bluetooth.h>
#include <hardware/bt_sock.h>
+#include <hardware/bt_hh.h>

#include <cutils/sockets.h>
#include <cutils/properties.h>
@@ -285,6 +286,9 @@ static const void *get_profile_interface(const char *profile_id)
if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
return bt_get_sock_interface();

+ if (!strcmp(profile_id, BT_PROFILE_HIDHOST_ID))
+ return bt_get_hidhost_interface();
+
return NULL;
}

diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
new file mode 100644
index 0000000..27cd1be
--- /dev/null
+++ b/android/hal-hidhost.c
@@ -0,0 +1,204 @@
+/*
+ * 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 <stdbool.h>
+
+#include <hardware/bluetooth.h>
+#include <hardware/bt_hh.h>
+
+#define LOG_TAG "BlueZ"
+#include <cutils/log.h>
+
+bthh_callbacks_t *bt_hh_cbacks;
+
+static bool interface_ready(void)
+{
+ return bt_hh_cbacks != NULL;
+}
+
+static bt_status_t bt_hidhost_connect(bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_disconnect(bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_virtual_unplug(bt_bdaddr_t *bd_addr)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_set_info(bt_bdaddr_t *bd_addr,
+ bthh_hid_info_t hid_info)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_get_protocol(bt_bdaddr_t *bd_addr,
+ bthh_protocol_mode_t protocolMode)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_set_protocol(bt_bdaddr_t *bd_addr,
+ bthh_protocol_mode_t protocolMode)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_get_report(bt_bdaddr_t *bd_addr,
+ bthh_report_type_t reportType,
+ uint8_t reportId,
+ int bufferSize)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_set_report(bt_bdaddr_t *bd_addr,
+ bthh_report_type_t reportType,
+ char *report)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr || !report)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_send_data(bt_bdaddr_t *bd_addr, char *data)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return BT_STATUS_NOT_READY;
+
+ if (!bd_addr || !data)
+ return BT_STATUS_PARM_INVALID;
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t bt_hidhost_init(bthh_callbacks_t *callbacks)
+{
+ ALOGI(__func__);
+
+ /* store reference to user callbacks */
+ bt_hh_cbacks = callbacks;
+
+ /* TODO: start HID Host thread */
+
+ /* TODO: enable service */
+
+ return BT_STATUS_SUCCESS;
+}
+
+static void bt_hidhost_cleanup(void)
+{
+ ALOGD(__func__);
+
+ if (!interface_ready())
+ return;
+
+ /* TODO: disable service */
+
+ /* TODO: stop HID Host thread */
+
+ bt_hh_cbacks = NULL;
+}
+
+static bthh_interface_t bt_hidhost_if = {
+ sizeof(bt_hidhost_if),
+ bt_hidhost_init,
+ bt_hidhost_connect,
+ bt_hidhost_disconnect,
+ bt_hidhost_virtual_unplug,
+ bt_hidhost_set_info,
+ bt_hidhost_get_protocol,
+ bt_hidhost_set_protocol,
+ bt_hidhost_get_report,
+ bt_hidhost_set_report,
+ bt_hidhost_send_data,
+ bt_hidhost_cleanup
+};
+
+bthh_interface_t *bt_get_hidhost_interface(void)
+{
+ return &bt_hidhost_if;
+}
diff --git a/android/hal.h b/android/hal.h
index 40fbf03..be69339 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -16,3 +16,4 @@
*/

btsock_interface_t *bt_get_sock_interface(void);
+bthh_interface_t *bt_get_hidhost_interface(void);
--
1.7.10.4


2013-10-16 14:08:41

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv3 04/11] android: sdp: Reuse BlueZ SDP server in Android

From: Andrei Emeltchenko <[email protected]>

Reuse existing SDP server code in Android GPL daemon.
---
Makefile.android | 4 +++-
android/Android.mk | 8 ++++++++
android/main.c | 5 +++++
3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/Makefile.android b/Makefile.android
index ab328a9..4d7da39 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -4,10 +4,12 @@ noinst_PROGRAMS += android/bluetoothd
android_bluetoothd_SOURCES = android/main.c \
src/log.c \
android/hal-msg.h \
+ src/sdpd-database.c src/sdpd-server.c \
+ src/sdpd-service.c src/sdpd-request.c \
src/shared/util.h src/shared/util.c \
src/shared/mgmt.h src/shared/mgmt.c

-android_bluetoothd_LDADD = @GLIB_LIBS@
+android_bluetoothd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
endif

EXTRA_DIST += android/Android.mk android/log.c
diff --git a/android/Android.mk b/android/Android.mk
index 4996080..560fb0a 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -17,6 +17,13 @@ LOCAL_SRC_FILES := \
log.c \
../src/shared/mgmt.c \
../src/shared/util.c \
+ ../src/sdpd-database.c \
+ ../src/sdpd-service.c \
+ ../src/sdpd-request.c \
+ ../src/sdpd-server.c \
+ ../lib/sdp.c \
+ ../lib/bluetooth.c \
+ ../lib/hci.c \

LOCAL_C_INCLUDES := \
$(call include-path-for, glib) \
@@ -25,6 +32,7 @@ LOCAL_C_INCLUDES := \
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../src \
+ $(LOCAL_PATH)/../lib \

LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"

diff --git a/android/main.c b/android/main.c
index 64f1a02..5dd359c 100644
--- a/android/main.c
+++ b/android/main.c
@@ -36,6 +36,7 @@
#include <glib.h>

#include "log.h"
+#include "src/sdpd.h"

#include "lib/bluetooth.h"
#include "lib/mgmt.h"
@@ -267,10 +268,14 @@ int main(int argc, char *argv[])
if (!init_mgmt_interface())
return EXIT_FAILURE;

+ /* Use params: mtu = 0, flags = 0 */
+ start_sdp_server(0, 0);
+
DBG("Entering main loop");

g_main_loop_run(event_loop);

+ stop_sdp_server();
cleanup_mgmt_interface();
g_main_loop_unref(event_loop);

--
1.7.10.4


2013-10-16 14:08:40

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv3 03/11] android: Add adapter and device struct for BlueZ daemon

From: Andrei Emeltchenko <[email protected]>

Adapter structure in BlueZ daemon keeps track of default adapter
and device structure keeps track about found devices.
---
android/adapter.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
android/adapter.h | 36 +++++++++++++++++++++++++++++++++++
android/device.c | 25 +++++++++++++++++++++++++
android/device.h | 24 ++++++++++++++++++++++++
4 files changed, 139 insertions(+)
create mode 100644 android/adapter.c
create mode 100644 android/adapter.h
create mode 100644 android/device.c
create mode 100644 android/device.h

diff --git a/android/adapter.c b/android/adapter.c
new file mode 100644
index 0000000..9763530
--- /dev/null
+++ b/android/adapter.c
@@ -0,0 +1,54 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "src/shared/mgmt.h"
+#include "log.h"
+#include "adapter.h"
+
+struct bt_adapter {
+ struct mgmt *mgmt;
+};
+
+struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if)
+{
+ struct bt_adapter *adapter;
+
+ adapter = g_new0(struct bt_adapter, 1);
+
+ adapter->mgmt = mgmt_ref(mgmt_if);
+
+ return adapter;
+}
+
+void bt_adapter_start(struct bt_adapter *adapter)
+{
+ DBG("");
+
+ /* TODO: CB: report scan mode */
+ /* TODO: CB: report state on */
+}
+
+void bt_adapter_stop(struct bt_adapter *adapter)
+{
+ DBG("");
+}
diff --git a/android/adapter.h b/android/adapter.h
new file mode 100644
index 0000000..0f1445a
--- /dev/null
+++ b/android/adapter.h
@@ -0,0 +1,36 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <glib.h>
+
+#include "lib/bluetooth.h"
+
+struct bt_adapter;
+
+struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if);
+
+void bt_adapter_start(struct bt_adapter *adapter);
+void bt_adapter_stop(struct bt_adapter *adapter);
diff --git a/android/device.c b/android/device.c
new file mode 100644
index 0000000..f9ca3ec
--- /dev/null
+++ b/android/device.c
@@ -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
+ *
+ */
+
+struct bt_device {
+};
diff --git a/android/device.h b/android/device.h
new file mode 100644
index 0000000..f5b1da6
--- /dev/null
+++ b/android/device.h
@@ -0,0 +1,24 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+struct bt_device;
--
1.7.10.4


2013-10-16 14:08:37

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv3 00/11] Android BlueZ patches, second chunk

From: Andrei Emeltchenko <[email protected]>

This is second chunk from my initial big patch set. Fixed style issues commented
by Marcel.

Changes:
* v3: Following upstream comments file names are changed from "_" to "-", added kernel style
struct initialization, fixed bug checking status for mgmt commands, added 2 HALs skeletons.
* v2: Corrected android_daemon -> enable_android autoconf stuff, better name for acquiring caps,
renamed hal_msg.h to hal-msg.h due to Johan's comment. Added small test-sdp fix.

Note that due to Marcel comment this cannot be built unless you include my patch
for Android bionic library:
http://code.google.com/p/android-bluez/source/detail?r=77a07e7703b63e280d9880baad30b3375e7df079&repo=bionic#

Andrei Emeltchenko (11):
android: Create HAL API header skeleton
android: Add basic mgmt initialization sequence
android: Add adapter and device struct for BlueZ daemon
android: sdp: Reuse BlueZ SDP server in Android
android: Add cap to bind to port < 1024
android: Implement read_info_complete callback
android: Use kernel style to initialize struct fields
android: Rename hal_bluetooth.c to hal-bluetooth.c
android: Rename hal_bt_sock.c to hal-bt-sock.c
android: Add HID Host skeleton
android: Add PAN skeleton

Makefile.android | 12 +-
android/Android.mk | 20 ++-
android/adapter.c | 138 +++++++++++++++++
android/adapter.h | 40 +++++
android/device.c | 25 +++
android/device.h | 24 +++
android/hal-bluetooth.c | 392 +++++++++++++++++++++++++++++++++++++++++++++++
android/hal-bt-sock.c | 85 ++++++++++
android/hal-hidhost.c | 204 ++++++++++++++++++++++++
android/hal-msg.h | 246 +++++++++++++++++++++++++++++
android/hal-pan.c | 120 +++++++++++++++
android/hal.h | 2 +
android/hal_bluetooth.c | 384 ----------------------------------------------
android/hal_bt_sock.c | 85 ----------
android/main.c | 248 ++++++++++++++++++++++++++++++
configure.ac | 4 +
16 files changed, 1556 insertions(+), 473 deletions(-)
create mode 100644 android/adapter.c
create mode 100644 android/adapter.h
create mode 100644 android/device.c
create mode 100644 android/device.h
create mode 100644 android/hal-bluetooth.c
create mode 100644 android/hal-bt-sock.c
create mode 100644 android/hal-hidhost.c
create mode 100644 android/hal-msg.h
create mode 100644 android/hal-pan.c
delete mode 100644 android/hal_bluetooth.c
delete mode 100644 android/hal_bt_sock.c

--
1.7.10.4


2013-10-16 12:24:27

by Andrei Emeltchenko

[permalink] [raw]
Subject: Re: [PATCHv2 3/6] android: Add basic mgmt initialization sequence

Hi Szymon,

On Wed, Oct 16, 2013 at 02:03:54PM +0200, Szymon Janc wrote:
> Hi Andrei,
>
> > From: Andrei Emeltchenko <[email protected]>
> >
> > Initialize bluetooth controller via mgmt interface.
> > ---
> > Makefile.android | 4 +-
> > android/Android.mk | 5 ++
> > android/main.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> > 3 files changed, 176 insertions(+), 1 deletion(-)
> >
> > diff --git a/Makefile.android b/Makefile.android
> > index 3ceefd8..7371a77 100644
> > --- a/Makefile.android
> > +++ b/Makefile.android
> > @@ -1,7 +1,9 @@
> > if ANDROID
> > noinst_PROGRAMS += android/bluetoothd
> >
> > -android_bluetoothd_SOURCES = android/main.c src/log.c
> > +android_bluetoothd_SOURCES = android/main.c src/log.c \
> > + src/shared/util.h src/shared/util.c \
> > + src/shared/mgmt.h src/shared/mgmt.c
> > android_bluetoothd_LDADD = @GLIB_LIBS@
> > endif
> >
> > diff --git a/android/Android.mk b/android/Android.mk
> > index 0e025ac..4996080 100644
> > --- a/android/Android.mk
> > +++ b/android/Android.mk
> > @@ -15,10 +15,15 @@ include $(CLEAR_VARS)
> > LOCAL_SRC_FILES := \
> > main.c \
> > log.c \
> > + ../src/shared/mgmt.c \
> > + ../src/shared/util.c \
> >
> > LOCAL_C_INCLUDES := \
> > $(call include-path-for, glib) \
> > $(call include-path-for, glib)/glib \
> > +
> > +LOCAL_C_INCLUDES += \
> > + $(LOCAL_PATH)/../ \
> > $(LOCAL_PATH)/../src \
> >
> > LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"
> > diff --git a/android/main.c b/android/main.c
> > index f75b0a8..ba25b84 100644
> > --- a/android/main.c
> > +++ b/android/main.c
> > @@ -25,6 +25,7 @@
> > #include <config.h>
> > #endif
> >
> > +#include <stdbool.h>
> > #include <signal.h>
> > #include <stdint.h>
> > #include <stdio.h>
> > @@ -36,9 +37,17 @@
> >
> > #include "log.h"
> >
> > +#include "lib/bluetooth.h"
> > +#include "lib/mgmt.h"
> > +#include "src/shared/mgmt.h"
> > +
> > #define SHUTDOWN_GRACE_SECONDS 10
> >
> > static GMainLoop *event_loop;
> > +static struct mgmt *mgmt_if = NULL;
> > +
> > +static uint8_t mgmt_version = 0;
> > +static uint8_t mgmt_revision = 0;
> >
> > static gboolean quit_eventloop(gpointer user_data)
> > {
> > @@ -67,6 +76,161 @@ static GOptionEntry options[] = {
> > { NULL }
> > };
> >
> > +static void read_info_complete(uint8_t status, uint16_t length,
> > + const void *param, void *user_data)
> > +{
> > + /* TODO: Store Controller information */
> > +
> > + /* TODO: Register all event notification handlers */
> > +}
> > +
> > +
> > +static void mgmt_index_added_event(uint16_t index, uint16_t length,
> > + const void *param, void *user_data)
> > +{
> > + DBG("index %u", index);
> > +
> > + if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
> > + read_info_complete, NULL, NULL) > 0)
> > + return;
> > +
> > + error("Failed to read adapter info for index %u", index);
> > +
> > +}
> > +
> > +static void mgmt_index_removed_event(uint16_t index, uint16_t length,
> > + const void *param, void *user_data)
> > +{
> > + DBG("index %u", index);
> > +}
> > +
> > +static void read_index_list_complete(uint8_t status, uint16_t length,
> > + const void *param, void *user_data)
> > +{
> > + const struct mgmt_rp_read_index_list *rp = param;
> > + uint16_t num;
> > + int i;
> > +
> > + info(__func__);
> > +
> > + if (!status) {
> > + error("%s: Failed to read index list: %s (0x%02x)",
> > + __func__, mgmt_errstr(status), status);
> > + return;
> > + }
> > +
> > + if (length < sizeof(*rp)) {
> > + error("%s: Wrong size of read index list response", __func__);
> > + return;
> > + }
> > +
> > + num = btohs(rp->num_controllers);
> > +
> > + DBG("%s: Number of controllers: %u", __func__, num);
> > +
> > + if (num * sizeof(uint16_t) + sizeof(*rp) != length) {
> > + error("%s: Incorrect pkt size for index list rsp", __func__);
> > + return;
> > + }
> > +
> > + for (i = 0; i < num; i++) {
> > + uint16_t index;
> > +
> > + index = btohs(rp->index[i]);
> > +
> > + /**
> > + * Use index added event notification.
> > + */
> > + mgmt_index_added_event(index, 0, NULL, NULL);
> > + }
> > +}
> > +
> > +static void read_commands_complete(uint8_t status, uint16_t length,
> > + const void *param, void *user_data)
> > +{
> > + const struct mgmt_rp_read_commands *rp = param;
> > +
> > + DBG("");
> > +
> > + if (!status) {
> > + error("Failed to read supported commands: %s (0x%02x)",
> > + mgmt_errstr(status), status);
> > + return;
> > + }
>
> This will always fail... I would use explicit comparison to MGMT status code
> if (status != MGMT_STATUS_SUCCESS) { ... }

Yes, sorry this was automatic style change :( I just check for status
then.

Best regards
Andrei Emeltchenko

>
> > +
> > + if (length < sizeof(*rp)) {
> > + error("Wrong size response");
> > + return;
> > + }
> > +}
> > +
> > +static void read_version_complete(uint8_t status, uint16_t length,
> > + const void *param, void *user_data)
> > +{
> > + const struct mgmt_rp_read_version *rp = param;
> > +
> > + DBG("");
> > +
> > + if (!status) {
> > + error("Failed to read version information: %s (0x%02x)",
> > + mgmt_errstr(status), status);
> > + return;
> > + }
>
> Ditto.
>
> > +
> > + if (length < sizeof(*rp)) {
> > + error("Wrong size response");
> > + return;
> > + }
> > +
> > + mgmt_version = rp->version;
> > + mgmt_revision = btohs(rp->revision);
> > +
> > + info("Bluetooth management interface %u.%u initialized",
> > + mgmt_version, mgmt_revision);
> > +
> > + if (mgmt_version < 1) {
> > + error("Version 1.0 or later of management interface required");
> > + abort();
> > + }
> > +
> > + mgmt_send(mgmt_if, MGMT_OP_READ_COMMANDS, MGMT_INDEX_NONE, 0, NULL,
> > + read_commands_complete, NULL, NULL);
> > +
> > + mgmt_register(mgmt_if, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE,
> > + mgmt_index_added_event, NULL, NULL);
> > + mgmt_register(mgmt_if, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE,
> > + mgmt_index_removed_event, NULL, NULL);
> > +
> > + if (mgmt_send(mgmt_if, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0,
> > + NULL, read_index_list_complete, NULL, NULL) > 0)
> > + return;
> > +
> > + error("Failed to read controller index list");
> > +}
> > +
> > +static bool init_mgmt_interface(void)
> > +{
> > + mgmt_if = mgmt_new_default();
> > + if (!mgmt_if) {
> > + error("Failed to access management interface");
> > + return false;
> > + }
> > +
> > + if (mgmt_send(mgmt_if, MGMT_OP_READ_VERSION, MGMT_INDEX_NONE, 0, NULL,
> > + read_version_complete, NULL, NULL) == 0) {
> > + error("Error sending READ_VERSION mgmt command");
> > + return false;
> > + }
> > +
> > + return true;
> > +}
> > +
> > +static void cleanup_mgmt_interface(void)
> > +{
> > + mgmt_unref(mgmt_if);
> > + mgmt_if = NULL;
> > +}
> > +
> > int main(int argc, char *argv[])
> > {
> > GOptionContext *context;
> > @@ -100,10 +264,14 @@ int main(int argc, char *argv[])
> > sigaction(SIGINT, &sa, NULL);
> > sigaction(SIGTERM, &sa, NULL);
> >
> > + if (!init_mgmt_interface())
> > + return EXIT_FAILURE;
> > +
> > DBG("Entering main loop");
> >
> > g_main_loop_run(event_loop);
> >
> > + cleanup_mgmt_interface();
> > g_main_loop_unref(event_loop);
> >
> > info("Exit");
> >
>
> --
> BR
> Szymon Janc
>

2013-10-16 12:03:54

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCHv2 3/6] android: Add basic mgmt initialization sequence

Hi Andrei,

> From: Andrei Emeltchenko <[email protected]>
>
> Initialize bluetooth controller via mgmt interface.
> ---
> Makefile.android | 4 +-
> android/Android.mk | 5 ++
> android/main.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 176 insertions(+), 1 deletion(-)
>
> diff --git a/Makefile.android b/Makefile.android
> index 3ceefd8..7371a77 100644
> --- a/Makefile.android
> +++ b/Makefile.android
> @@ -1,7 +1,9 @@
> if ANDROID
> noinst_PROGRAMS += android/bluetoothd
>
> -android_bluetoothd_SOURCES = android/main.c src/log.c
> +android_bluetoothd_SOURCES = android/main.c src/log.c \
> + src/shared/util.h src/shared/util.c \
> + src/shared/mgmt.h src/shared/mgmt.c
> android_bluetoothd_LDADD = @GLIB_LIBS@
> endif
>
> diff --git a/android/Android.mk b/android/Android.mk
> index 0e025ac..4996080 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -15,10 +15,15 @@ include $(CLEAR_VARS)
> LOCAL_SRC_FILES := \
> main.c \
> log.c \
> + ../src/shared/mgmt.c \
> + ../src/shared/util.c \
>
> LOCAL_C_INCLUDES := \
> $(call include-path-for, glib) \
> $(call include-path-for, glib)/glib \
> +
> +LOCAL_C_INCLUDES += \
> + $(LOCAL_PATH)/../ \
> $(LOCAL_PATH)/../src \
>
> LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"
> diff --git a/android/main.c b/android/main.c
> index f75b0a8..ba25b84 100644
> --- a/android/main.c
> +++ b/android/main.c
> @@ -25,6 +25,7 @@
> #include <config.h>
> #endif
>
> +#include <stdbool.h>
> #include <signal.h>
> #include <stdint.h>
> #include <stdio.h>
> @@ -36,9 +37,17 @@
>
> #include "log.h"
>
> +#include "lib/bluetooth.h"
> +#include "lib/mgmt.h"
> +#include "src/shared/mgmt.h"
> +
> #define SHUTDOWN_GRACE_SECONDS 10
>
> static GMainLoop *event_loop;
> +static struct mgmt *mgmt_if = NULL;
> +
> +static uint8_t mgmt_version = 0;
> +static uint8_t mgmt_revision = 0;
>
> static gboolean quit_eventloop(gpointer user_data)
> {
> @@ -67,6 +76,161 @@ static GOptionEntry options[] = {
> { NULL }
> };
>
> +static void read_info_complete(uint8_t status, uint16_t length,
> + const void *param, void *user_data)
> +{
> + /* TODO: Store Controller information */
> +
> + /* TODO: Register all event notification handlers */
> +}
> +
> +
> +static void mgmt_index_added_event(uint16_t index, uint16_t length,
> + const void *param, void *user_data)
> +{
> + DBG("index %u", index);
> +
> + if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
> + read_info_complete, NULL, NULL) > 0)
> + return;
> +
> + error("Failed to read adapter info for index %u", index);
> +
> +}
> +
> +static void mgmt_index_removed_event(uint16_t index, uint16_t length,
> + const void *param, void *user_data)
> +{
> + DBG("index %u", index);
> +}
> +
> +static void read_index_list_complete(uint8_t status, uint16_t length,
> + const void *param, void *user_data)
> +{
> + const struct mgmt_rp_read_index_list *rp = param;
> + uint16_t num;
> + int i;
> +
> + info(__func__);
> +
> + if (!status) {
> + error("%s: Failed to read index list: %s (0x%02x)",
> + __func__, mgmt_errstr(status), status);
> + return;
> + }
> +
> + if (length < sizeof(*rp)) {
> + error("%s: Wrong size of read index list response", __func__);
> + return;
> + }
> +
> + num = btohs(rp->num_controllers);
> +
> + DBG("%s: Number of controllers: %u", __func__, num);
> +
> + if (num * sizeof(uint16_t) + sizeof(*rp) != length) {
> + error("%s: Incorrect pkt size for index list rsp", __func__);
> + return;
> + }
> +
> + for (i = 0; i < num; i++) {
> + uint16_t index;
> +
> + index = btohs(rp->index[i]);
> +
> + /**
> + * Use index added event notification.
> + */
> + mgmt_index_added_event(index, 0, NULL, NULL);
> + }
> +}
> +
> +static void read_commands_complete(uint8_t status, uint16_t length,
> + const void *param, void *user_data)
> +{
> + const struct mgmt_rp_read_commands *rp = param;
> +
> + DBG("");
> +
> + if (!status) {
> + error("Failed to read supported commands: %s (0x%02x)",
> + mgmt_errstr(status), status);
> + return;
> + }

This will always fail... I would use explicit comparison to MGMT status code
if (status != MGMT_STATUS_SUCCESS) { ... }

> +
> + if (length < sizeof(*rp)) {
> + error("Wrong size response");
> + return;
> + }
> +}
> +
> +static void read_version_complete(uint8_t status, uint16_t length,
> + const void *param, void *user_data)
> +{
> + const struct mgmt_rp_read_version *rp = param;
> +
> + DBG("");
> +
> + if (!status) {
> + error("Failed to read version information: %s (0x%02x)",
> + mgmt_errstr(status), status);
> + return;
> + }

Ditto.

> +
> + if (length < sizeof(*rp)) {
> + error("Wrong size response");
> + return;
> + }
> +
> + mgmt_version = rp->version;
> + mgmt_revision = btohs(rp->revision);
> +
> + info("Bluetooth management interface %u.%u initialized",
> + mgmt_version, mgmt_revision);
> +
> + if (mgmt_version < 1) {
> + error("Version 1.0 or later of management interface required");
> + abort();
> + }
> +
> + mgmt_send(mgmt_if, MGMT_OP_READ_COMMANDS, MGMT_INDEX_NONE, 0, NULL,
> + read_commands_complete, NULL, NULL);
> +
> + mgmt_register(mgmt_if, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE,
> + mgmt_index_added_event, NULL, NULL);
> + mgmt_register(mgmt_if, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE,
> + mgmt_index_removed_event, NULL, NULL);
> +
> + if (mgmt_send(mgmt_if, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0,
> + NULL, read_index_list_complete, NULL, NULL) > 0)
> + return;
> +
> + error("Failed to read controller index list");
> +}
> +
> +static bool init_mgmt_interface(void)
> +{
> + mgmt_if = mgmt_new_default();
> + if (!mgmt_if) {
> + error("Failed to access management interface");
> + return false;
> + }
> +
> + if (mgmt_send(mgmt_if, MGMT_OP_READ_VERSION, MGMT_INDEX_NONE, 0, NULL,
> + read_version_complete, NULL, NULL) == 0) {
> + error("Error sending READ_VERSION mgmt command");
> + return false;
> + }
> +
> + return true;
> +}
> +
> +static void cleanup_mgmt_interface(void)
> +{
> + mgmt_unref(mgmt_if);
> + mgmt_if = NULL;
> +}
> +
> int main(int argc, char *argv[])
> {
> GOptionContext *context;
> @@ -100,10 +264,14 @@ int main(int argc, char *argv[])
> sigaction(SIGINT, &sa, NULL);
> sigaction(SIGTERM, &sa, NULL);
>
> + if (!init_mgmt_interface())
> + return EXIT_FAILURE;
> +
> DBG("Entering main loop");
>
> g_main_loop_run(event_loop);
>
> + cleanup_mgmt_interface();
> g_main_loop_unref(event_loop);
>
> info("Exit");
>

--
BR
Szymon Janc


2013-10-16 10:31:40

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCHv2 4/6] android: Add adapter and device struct for BlueZ daemon

On Wed, Oct 16, 2013, Andrei Emeltchenko wrote:
> +struct bt_adapter {
> + struct mgmt *mgmt;
> + bdaddr_t bdaddr;
> + uint32_t dev_class;
> +
> + char *name;
> +
> + uint32_t supported_settings;
> + uint32_t current_settings;
> +
> + GList *found_devices;
> +};

Please don't add variables this way if you don't have code that actually
uses them at least later in the patch set. Just add them when they
eventually are needed.

> +struct bt_device {
> + bdaddr_t bdaddr;
> + uint8_t bdaddr_type;
> + uint32_t cod;
> + char *name;
> +};

Same thing here.

Johan

2013-10-16 10:28:09

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCHv2 3/6] android: Add basic mgmt initialization sequence

Hi Andrei,

On Wed, Oct 16, 2013, Andrei Emeltchenko wrote:
> +static void read_index_list_complete(uint8_t status, uint16_t length,
> + const void *param, void *user_data)
> +{
> + const struct mgmt_rp_read_index_list *rp = param;
> + uint16_t num;
> + int i;
> +
> + info(__func__);

Seems like this one should just be a DBG("") (or just remove it
completely).

> + num = btohs(rp->num_controllers);
> +
> + DBG("%s: Number of controllers: %u", __func__, num);

Again, the __func__ seems redundant since this is a DBG() call.

Johan

2013-10-16 10:23:20

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCHv2 2/6] android: Create HAL API header skeleton

Hi Andrei,

On Wed, Oct 16, 2013, Andrei Emeltchenko wrote:
> Header describes the protocol between Android HAL threads and BlueZ
> daemon.
> ---
> android/hal-msg.h | 246 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 246 insertions(+)
> create mode 100644 android/hal-msg.h

Where's the code/patch that adds this to "make dist"?

Johan

2013-10-16 10:21:39

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCHv2 1/6] sdp: Check that correct packet received in recv

Hi Andrei,

On Wed, Oct 16, 2013, Andrei Emeltchenko wrote:
> ---
> unit/test-sdp.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)

This patch has been applied. Thanks.

Johan

2013-10-16 08:46:49

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 0/6] Android BlueZ patches, second chunk

From: Andrei Emeltchenko <[email protected]>

This is second chunk from my initial big patch set. Fixed style issues commented
by Marcel.

Changes:
* v2: Corrected android_daemon -> enable_android autoconf stuff, better name for acquiring caps,
renamed hal_msg.h to hal-msg.h due to Johan's comment. Added small test-sdp fix.

Note that due to Marcel comment this cannot be built unless you include my patch
for Android bionic library:
http://code.google.com/p/android-bluez/source/detail?r=77a07e7703b63e280d9880baad30b3375e7df079&repo=bionic#

Andrei Emeltchenko (6):
sdp: Check that correct packet received in recv
android: Create HAL API header skeleton
android: Add basic mgmt initialization sequence
android: Add adapter and device struct for BlueZ daemon
android: sdp: Reuse BlueZ SDP server in Android
android: Add cap to bind to port < 1024

Makefile.android | 8 +-
android/Android.mk | 13 +++
android/adapter.c | 63 ++++++++++++++
android/adapter.h | 36 ++++++++
android/device.c | 29 +++++++
android/device.h | 24 +++++
android/hal-msg.h | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++++
android/main.c | 244 +++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 4 +
unit/test-sdp.c | 5 +-
10 files changed, 667 insertions(+), 5 deletions(-)
create mode 100644 android/adapter.c
create mode 100644 android/adapter.h
create mode 100644 android/device.c
create mode 100644 android/device.h
create mode 100644 android/hal-msg.h

--
1.7.10.4


2013-10-16 08:46:55

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 6/6] android: Add cap to bind to port < 1024

From: Andrei Emeltchenko <[email protected]>

For SDP server we need to bind to lower port, acquire this capability.
---
android/main.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 4 ++++
2 files changed, 75 insertions(+)

diff --git a/android/main.c b/android/main.c
index 2b8675d..19d382a 100644
--- a/android/main.c
+++ b/android/main.c
@@ -32,6 +32,22 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/prctl.h>
+#include <linux/capability.h>
+
+/**
+ * Include <sys/capability.h> for host build and
+ * also for Android 4.3 when it is added to bionic
+ */
+#if !defined(ANDROID) || (PLATFORM_SDK_VERSION > 17)
+#include <sys/capability.h>
+#endif
+
+#if defined(ANDROID)
+#include <private/android_filesystem_config.h>
+#endif

#include <glib.h>

@@ -232,6 +248,58 @@ static void cleanup_mgmt_interface(void)
mgmt_if = NULL;
}

+static bool set_capabilities(void)
+{
+ struct __user_cap_header_struct header;
+ struct __user_cap_data_struct cap;
+#if defined(ANDROID)
+ gid_t groups[] = {AID_NET_BT, AID_NET_BT_ADMIN, AID_NET_ADMIN};
+#endif
+
+ DBG("pid %d uid %d gid %d", getpid(), getuid(), getgid());
+
+ header.version = _LINUX_CAPABILITY_VERSION;
+
+ prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
+
+#if defined(ANDROID)
+ if (setgid(AID_BLUETOOTH) < 0)
+ warn("%s: setgid(): %s", __func__, strerror(errno));
+
+ if (setuid(AID_BLUETOOTH) < 0)
+ warn("%s: setuid(): %s", __func__, strerror(errno));
+#endif
+
+ header.version = _LINUX_CAPABILITY_VERSION;
+ header.pid = 0;
+
+ cap.effective = cap.permitted =
+ CAP_TO_MASK(CAP_SETGID) |
+ CAP_TO_MASK(CAP_NET_RAW) |
+ CAP_TO_MASK(CAP_NET_ADMIN) |
+ CAP_TO_MASK(CAP_NET_BIND_SERVICE);
+ cap.inheritable = 0;
+
+ if (capset(&header, &cap) < 0) {
+ error("%s: capset(): %s", __func__, strerror(errno));
+ return false;
+ }
+
+#if defined(ANDROID)
+ if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) < 0)
+ warn("%s: setgroups: %s", __func__, strerror(errno));
+#endif
+ if (capget(&header, &cap) < 0)
+ error("%s: capget(): %s", __func__, strerror(errno));
+ else
+ DBG("Caps: eff: 0x%x, perm: 0x%x, inh: 0x%x", cap.effective,
+ cap.permitted, cap.inheritable);
+
+ DBG("pid %d uid %d gid %d", getpid(), getuid(), getgid());
+
+ return true;
+}
+
int main(int argc, char *argv[])
{
GOptionContext *context;
@@ -265,6 +333,9 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);

+ if (!set_capabilities())
+ return EXIT_FAILURE;
+
if (!init_mgmt_interface())
return EXIT_FAILURE;

diff --git a/configure.ac b/configure.ac
index 7b1f64a..a14264f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -247,4 +247,8 @@ AC_ARG_ENABLE(android, AC_HELP_STRING([--enable-android],
[enable_android=${enableval}])
AM_CONDITIONAL(ANDROID, test "${enable_android}" = "yes")

+if (test "${enable_android}" = "yes"); then
+ AC_CHECK_LIB(cap, capget, dummy=yes, AC_MSG_ERROR(libcap is required))
+fi
+
AC_OUTPUT(Makefile src/bluetoothd.8 lib/bluez.pc)
--
1.7.10.4


2013-10-16 08:46:50

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 1/6] sdp: Check that correct packet received in recv

From: Andrei Emeltchenko <[email protected]>

---
unit/test-sdp.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/unit/test-sdp.c b/unit/test-sdp.c
index 6d699e2..4726b8b 100644
--- a/unit/test-sdp.c
+++ b/unit/test-sdp.c
@@ -145,8 +145,7 @@ static gboolean server_handler(GIOChannel *channel, GIOCondition cond,
struct context *context = user_data;
sdp_pdu_hdr_t hdr;
void *buf;
- size_t size;
- ssize_t len;
+ ssize_t len, size;
int fd;

fd = g_io_channel_unix_get_fd(channel);
@@ -169,7 +168,7 @@ static gboolean server_handler(GIOChannel *channel, GIOCondition cond,
return TRUE;

len = recv(fd, buf, size, 0);
- if (len <= 0) {
+ if (len != size) {
sdp_svcdb_collect_all(fd);
free(buf);
return FALSE;
--
1.7.10.4


2013-10-16 08:46:52

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 3/6] android: Add basic mgmt initialization sequence

From: Andrei Emeltchenko <[email protected]>

Initialize bluetooth controller via mgmt interface.
---
Makefile.android | 4 +-
android/Android.mk | 5 ++
android/main.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 176 insertions(+), 1 deletion(-)

diff --git a/Makefile.android b/Makefile.android
index 3ceefd8..7371a77 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -1,7 +1,9 @@
if ANDROID
noinst_PROGRAMS += android/bluetoothd

-android_bluetoothd_SOURCES = android/main.c src/log.c
+android_bluetoothd_SOURCES = android/main.c src/log.c \
+ src/shared/util.h src/shared/util.c \
+ src/shared/mgmt.h src/shared/mgmt.c
android_bluetoothd_LDADD = @GLIB_LIBS@
endif

diff --git a/android/Android.mk b/android/Android.mk
index 0e025ac..4996080 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -15,10 +15,15 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
main.c \
log.c \
+ ../src/shared/mgmt.c \
+ ../src/shared/util.c \

LOCAL_C_INCLUDES := \
$(call include-path-for, glib) \
$(call include-path-for, glib)/glib \
+
+LOCAL_C_INCLUDES += \
+ $(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../src \

LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"
diff --git a/android/main.c b/android/main.c
index f75b0a8..ba25b84 100644
--- a/android/main.c
+++ b/android/main.c
@@ -25,6 +25,7 @@
#include <config.h>
#endif

+#include <stdbool.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
@@ -36,9 +37,17 @@

#include "log.h"

+#include "lib/bluetooth.h"
+#include "lib/mgmt.h"
+#include "src/shared/mgmt.h"
+
#define SHUTDOWN_GRACE_SECONDS 10

static GMainLoop *event_loop;
+static struct mgmt *mgmt_if = NULL;
+
+static uint8_t mgmt_version = 0;
+static uint8_t mgmt_revision = 0;

static gboolean quit_eventloop(gpointer user_data)
{
@@ -67,6 +76,161 @@ static GOptionEntry options[] = {
{ NULL }
};

+static void read_info_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ /* TODO: Store Controller information */
+
+ /* TODO: Register all event notification handlers */
+}
+
+
+static void mgmt_index_added_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("index %u", index);
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
+ read_info_complete, NULL, NULL) > 0)
+ return;
+
+ error("Failed to read adapter info for index %u", index);
+
+}
+
+static void mgmt_index_removed_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("index %u", index);
+}
+
+static void read_index_list_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_index_list *rp = param;
+ uint16_t num;
+ int i;
+
+ info(__func__);
+
+ if (!status) {
+ error("%s: Failed to read index list: %s (0x%02x)",
+ __func__, mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("%s: Wrong size of read index list response", __func__);
+ return;
+ }
+
+ num = btohs(rp->num_controllers);
+
+ DBG("%s: Number of controllers: %u", __func__, num);
+
+ if (num * sizeof(uint16_t) + sizeof(*rp) != length) {
+ error("%s: Incorrect pkt size for index list rsp", __func__);
+ return;
+ }
+
+ for (i = 0; i < num; i++) {
+ uint16_t index;
+
+ index = btohs(rp->index[i]);
+
+ /**
+ * Use index added event notification.
+ */
+ mgmt_index_added_event(index, 0, NULL, NULL);
+ }
+}
+
+static void read_commands_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_commands *rp = param;
+
+ DBG("");
+
+ if (!status) {
+ error("Failed to read supported commands: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("Wrong size response");
+ return;
+ }
+}
+
+static void read_version_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_version *rp = param;
+
+ DBG("");
+
+ if (!status) {
+ error("Failed to read version information: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("Wrong size response");
+ return;
+ }
+
+ mgmt_version = rp->version;
+ mgmt_revision = btohs(rp->revision);
+
+ info("Bluetooth management interface %u.%u initialized",
+ mgmt_version, mgmt_revision);
+
+ if (mgmt_version < 1) {
+ error("Version 1.0 or later of management interface required");
+ abort();
+ }
+
+ mgmt_send(mgmt_if, MGMT_OP_READ_COMMANDS, MGMT_INDEX_NONE, 0, NULL,
+ read_commands_complete, NULL, NULL);
+
+ mgmt_register(mgmt_if, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE,
+ mgmt_index_added_event, NULL, NULL);
+ mgmt_register(mgmt_if, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE,
+ mgmt_index_removed_event, NULL, NULL);
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0,
+ NULL, read_index_list_complete, NULL, NULL) > 0)
+ return;
+
+ error("Failed to read controller index list");
+}
+
+static bool init_mgmt_interface(void)
+{
+ mgmt_if = mgmt_new_default();
+ if (!mgmt_if) {
+ error("Failed to access management interface");
+ return false;
+ }
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_VERSION, MGMT_INDEX_NONE, 0, NULL,
+ read_version_complete, NULL, NULL) == 0) {
+ error("Error sending READ_VERSION mgmt command");
+ return false;
+ }
+
+ return true;
+}
+
+static void cleanup_mgmt_interface(void)
+{
+ mgmt_unref(mgmt_if);
+ mgmt_if = NULL;
+}
+
int main(int argc, char *argv[])
{
GOptionContext *context;
@@ -100,10 +264,14 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);

+ if (!init_mgmt_interface())
+ return EXIT_FAILURE;
+
DBG("Entering main loop");

g_main_loop_run(event_loop);

+ cleanup_mgmt_interface();
g_main_loop_unref(event_loop);

info("Exit");
--
1.7.10.4


2013-10-16 08:46:53

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 4/6] android: Add adapter and device struct for BlueZ daemon

From: Andrei Emeltchenko <[email protected]>

Adapter structure in BlueZ daemon keeps track of default adapter
and device structure keeps track about found devices.
---
android/adapter.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
android/adapter.h | 36 ++++++++++++++++++++++++++++++
android/device.c | 29 ++++++++++++++++++++++++
android/device.h | 24 ++++++++++++++++++++
4 files changed, 152 insertions(+)
create mode 100644 android/adapter.c
create mode 100644 android/adapter.h
create mode 100644 android/device.c
create mode 100644 android/device.h

diff --git a/android/adapter.c b/android/adapter.c
new file mode 100644
index 0000000..b97a7c7
--- /dev/null
+++ b/android/adapter.c
@@ -0,0 +1,63 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "src/shared/mgmt.h"
+#include "log.h"
+#include "adapter.h"
+
+struct bt_adapter {
+ struct mgmt *mgmt;
+ bdaddr_t bdaddr;
+ uint32_t dev_class;
+
+ char *name;
+
+ uint32_t supported_settings;
+ uint32_t current_settings;
+
+ GList *found_devices;
+};
+
+struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if)
+{
+ struct bt_adapter *adapter;
+
+ adapter = g_new0(struct bt_adapter, 1);
+
+ adapter->mgmt = mgmt_ref(mgmt_if);
+
+ return adapter;
+}
+
+void bt_adapter_start(struct bt_adapter *adapter)
+{
+ DBG("");
+
+ /* TODO: CB: report scan mode */
+ /* TODO: CB: report state on */
+}
+
+void bt_adapter_stop(struct bt_adapter *adapter)
+{
+ DBG("");
+}
diff --git a/android/adapter.h b/android/adapter.h
new file mode 100644
index 0000000..0f1445a
--- /dev/null
+++ b/android/adapter.h
@@ -0,0 +1,36 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <glib.h>
+
+#include "lib/bluetooth.h"
+
+struct bt_adapter;
+
+struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if);
+
+void bt_adapter_start(struct bt_adapter *adapter);
+void bt_adapter_stop(struct bt_adapter *adapter);
diff --git a/android/device.c b/android/device.c
new file mode 100644
index 0000000..224a317
--- /dev/null
+++ b/android/device.c
@@ -0,0 +1,29 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+struct bt_device {
+ bdaddr_t bdaddr;
+ uint8_t bdaddr_type;
+ uint32_t cod;
+ char *name;
+};
diff --git a/android/device.h b/android/device.h
new file mode 100644
index 0000000..f5b1da6
--- /dev/null
+++ b/android/device.h
@@ -0,0 +1,24 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+struct bt_device;
--
1.7.10.4


2013-10-16 08:46:51

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 2/6] android: Create HAL API header skeleton

From: Andrei Emeltchenko <[email protected]>

Header describes the protocol between Android HAL threads and BlueZ
daemon.
---
android/hal-msg.h | 246 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 246 insertions(+)
create mode 100644 android/hal-msg.h

diff --git a/android/hal-msg.h b/android/hal-msg.h
new file mode 100644
index 0000000..4c5ca69
--- /dev/null
+++ b/android/hal-msg.h
@@ -0,0 +1,246 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+struct hal_msg_hdr {
+ uint8_t service_id;
+ uint8_t opcode;
+ uint16_t len;
+} __attribute__((packed));
+
+#define HAL_SERVICE_ID_CORE 0
+#define HAL_SERVICE_ID_BLUETOOTH 1
+#define HAL_SERVICE_ID_SOCK 2
+#define HAL_SERVICE_ID_HIDHOST 3
+#define HAL_SERVICE_ID_PAN 4
+#define HAL_SERVICE_ID_HANDSFREE 5
+#define HAL_SERVICE_ID_AD2P 6
+#define HAL_SERVICE_ID_HEALTH 7
+#define HAL_SERVICE_ID_AVRCP 8
+#define HAL_SERVICE_ID_GATT 9
+
+/* Core Service */
+
+#define HAL_MSG_OP_ERROR 0x00
+struct hal_msg_rsp_error {
+ uint8_t status;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_REGISTER_MODULE 0x01
+struct hal_msg_cmd_register_module {
+ uint8_t service_id;
+} __attribute__((packed));
+struct hal_msg_rsp_register_module {
+ uint8_t service_id;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_UNREGISTER_MODULE 0x02
+struct hal_msg_cmd_unregister_module {
+ uint8_t service_id;
+} __attribute__((packed));
+
+/* Bluetooth Core HAL API */
+
+#define HAL_MSG_OP_BT_ENABLE 0x01
+
+#define HAL_MSG_OP_BT_DISABLE 0x02
+
+#define HAL_MSG_OP_BT_GET_ADAPTER_PROPS 0x03
+
+#define HAL_MSG_OP_BT_GET_ADAPTER_PROP 0x04
+struct hal_msg_cmd_bt_get_adapter_prop {
+ uint8_t type;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SET_ADAPTER_PROP 0x05
+struct hal_msg_cmd_bt_set_adapter_prop {
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_DEVICE_PROPS 0x06
+struct hal_msg_cmd_bt_get_remote_device_props {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_DEVICE_PROP 0x07
+struct hal_msg_cmd_bt_get_remote_device_prop {
+ uint8_t bdaddr[6];
+ uint8_t type;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SET_REMOTE_DEVICE_PROP 0x08
+struct hal_msg_cmd_bt_set_remote_device_prop {
+ uint8_t bdaddr[6];
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_SERVICE_REC 0x09
+struct hal_msg_cmd_bt_get_remote_service_rec {
+ uint8_t bdaddr[6];
+ uint8_t uuid[16];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_SERVICE 0x0a
+struct hal_msg_cmd_bt_get_remote_service {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_START_DISCOVERY 0x0b
+
+#define HAL_MSG_OP_BT_CANCEL_DISCOVERY 0x0c
+
+#define HAL_MSG_OP_BT_CREATE_BOND 0x0d
+struct hal_msg_cmd_bt_create_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_REMOVE_BOND 0x0d
+struct hal_msg_cmd_bt_remove_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_CANCEL_BOND 0x0f
+struct hal_msg_cmd_bt_cancel_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_PIN_REPLY 0x10
+struct hal_msg_cmd_bt_pin_reply {
+ uint8_t bdaddr[6];
+ uint8_t accept;
+ uint8_t pin_len;
+ uint8_t pin_code[16];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SSP_REPLY 0x11
+struct hal_msg_cmd_bt_ssp_reply {
+ uint8_t bdaddr[6];
+ uint8_t ssp_variant;
+ uint8_t accept;
+ uint32_t passkey;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_DUT_MODE_CONF 0x12
+struct hal_msg_cmd_bt_dut_mode_conf {
+ uint8_t enable;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_DUT_MODE_SEND 0x13
+struct hal_msg_cmd_bt_dut_mode_send {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_LE_TEST_MODE 0x14
+struct hal_msg_cmd_bt_le_test_mode {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+/* Notifications and confirmations */
+
+#define HAL_MSG_EV_BT_ERROR 0x80
+
+#define HAL_MSG_EV_BT_ADAPTER_STATE_CHANGED 0x81
+struct hal_msg_ev_bt_adapter_state_changed {
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_ADAPTER_PROPS_CHANGED 0x82
+struct hal_property {
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+struct hal_msg_ev_bt_adapter_props_changed {
+ uint8_t status;
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_REMOTE_DEVICE_PROPS 0x83
+struct hal_msg_ev_bt_remote_device_props {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DEVICE_FOUND 0x84
+struct hal_msg_ev_bt_device_found {
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DISCOVERY_STATE_CHANGED 0x85
+struct hal_msg_ev_bt_discovery_state_changed {
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_PIN_REQUEST 0x86
+struct hal_msg_ev_bt_pin_request {
+ uint8_t bdaddr[6];
+ uint8_t name[249 - 1];
+ uint8_t class_of_dev[3];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_SSP_REQUEST 0x87
+struct hal_msg_ev_bt_ssp_request {
+ uint8_t bdaddr[6];
+ uint8_t name[249 - 1];
+ uint8_t class_of_dev[3];
+ uint8_t pairing_variant;
+ uint32_t passkey;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_BOND_STATE_CHANGED 0x88
+struct hal_msg_ev_bt_bond_state_changed {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_ACL_STATE_CHANGED 0x89
+struct hal_msg_ev_bt_acl_state_changed {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DUT_MODE_RECEIVE 0x8a
+struct hal_msg_ev_bt_dut_mode_receive {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_LE_TEST_MODE 0x8b
+struct hal_msg_ev_bt_le_test_mode {
+ uint8_t status;
+ uint16_t num_packets;
+} __attribute__((packed));
--
1.7.10.4


2013-10-16 08:46:54

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 5/6] android: sdp: Reuse BlueZ SDP server in Android

From: Andrei Emeltchenko <[email protected]>

Reuse existing SDP server code in Android GPL daemon.
---
Makefile.android | 4 +++-
android/Android.mk | 8 ++++++++
android/main.c | 5 +++++
3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/Makefile.android b/Makefile.android
index 7371a77..48af2e2 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -2,9 +2,11 @@ if ANDROID
noinst_PROGRAMS += android/bluetoothd

android_bluetoothd_SOURCES = android/main.c src/log.c \
+ src/sdpd-database.c src/sdpd-server.c \
+ src/sdpd-service.c src/sdpd-request.c \
src/shared/util.h src/shared/util.c \
src/shared/mgmt.h src/shared/mgmt.c
-android_bluetoothd_LDADD = @GLIB_LIBS@
+android_bluetoothd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
endif

EXTRA_DIST += android/Android.mk android/log.c
diff --git a/android/Android.mk b/android/Android.mk
index 4996080..560fb0a 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -17,6 +17,13 @@ LOCAL_SRC_FILES := \
log.c \
../src/shared/mgmt.c \
../src/shared/util.c \
+ ../src/sdpd-database.c \
+ ../src/sdpd-service.c \
+ ../src/sdpd-request.c \
+ ../src/sdpd-server.c \
+ ../lib/sdp.c \
+ ../lib/bluetooth.c \
+ ../lib/hci.c \

LOCAL_C_INCLUDES := \
$(call include-path-for, glib) \
@@ -25,6 +32,7 @@ LOCAL_C_INCLUDES := \
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../src \
+ $(LOCAL_PATH)/../lib \

LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"

diff --git a/android/main.c b/android/main.c
index ba25b84..2b8675d 100644
--- a/android/main.c
+++ b/android/main.c
@@ -36,6 +36,7 @@
#include <glib.h>

#include "log.h"
+#include "sdpd.h"

#include "lib/bluetooth.h"
#include "lib/mgmt.h"
@@ -267,10 +268,14 @@ int main(int argc, char *argv[])
if (!init_mgmt_interface())
return EXIT_FAILURE;

+ /* Use params: mtu = 0, flags = 0 */
+ start_sdp_server(0, 0);
+
DBG("Entering main loop");

g_main_loop_run(event_loop);

+ stop_sdp_server();
cleanup_mgmt_interface();
g_main_loop_unref(event_loop);

--
1.7.10.4


2013-10-15 10:37:03

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv1 5/5] android: Add cap to bind to port < 1024

From: Andrei Emeltchenko <[email protected]>

For SDP server we need to bind to lower port, acquire this capability.
---
android/main.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 4 ++++
2 files changed, 75 insertions(+)

diff --git a/android/main.c b/android/main.c
index 2b8675d..5206d3d 100644
--- a/android/main.c
+++ b/android/main.c
@@ -32,6 +32,22 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/prctl.h>
+#include <linux/capability.h>
+
+/**
+ * Include <sys/capability.h> for host build and
+ * also for Android 4.3 when it is added to bionic
+ */
+#if !defined(ANDROID) || (PLATFORM_SDK_VERSION > 17)
+#include <sys/capability.h>
+#endif
+
+#if defined(ANDROID)
+#include <private/android_filesystem_config.h>
+#endif

#include <glib.h>

@@ -232,6 +248,58 @@ static void cleanup_mgmt_interface(void)
mgmt_if = NULL;
}

+static bool android_set_aid_and_cap(void)
+{
+ struct __user_cap_header_struct header;
+ struct __user_cap_data_struct cap;
+#if defined(ANDROID)
+ gid_t groups[] = {AID_NET_BT, AID_NET_BT_ADMIN, AID_NET_ADMIN};
+#endif
+
+ DBG("pid %d uid %d gid %d", getpid(), getuid(), getgid());
+
+ header.version = _LINUX_CAPABILITY_VERSION;
+
+ prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
+
+#if defined(ANDROID)
+ if (setgid(AID_BLUETOOTH) < 0)
+ warn("%s: setgid(): %s", __func__, strerror(errno));
+
+ if (setuid(AID_BLUETOOTH) < 0)
+ warn("%s: setuid(): %s", __func__, strerror(errno));
+#endif
+
+ header.version = _LINUX_CAPABILITY_VERSION;
+ header.pid = 0;
+
+ cap.effective = cap.permitted =
+ CAP_TO_MASK(CAP_SETGID) |
+ CAP_TO_MASK(CAP_NET_RAW) |
+ CAP_TO_MASK(CAP_NET_ADMIN) |
+ CAP_TO_MASK(CAP_NET_BIND_SERVICE);
+ cap.inheritable = 0;
+
+ if (capset(&header, &cap) < 0) {
+ error("%s: capset(): %s", __func__, strerror(errno));
+ return false;
+ }
+
+#if defined(ANDROID)
+ if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) < 0)
+ warn("%s: setgroups: %s", __func__, strerror(errno));
+#endif
+ if (capget(&header, &cap) < 0)
+ error("%s: capget(): %s", __func__, strerror(errno));
+ else
+ DBG("Caps: eff: 0x%x, perm: 0x%x, inh: 0x%x", cap.effective,
+ cap.permitted, cap.inheritable);
+
+ DBG("pid %d uid %d gid %d", getpid(), getuid(), getgid());
+
+ return true;
+}
+
int main(int argc, char *argv[])
{
GOptionContext *context;
@@ -265,6 +333,9 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);

+ if (!android_set_aid_and_cap())
+ return EXIT_FAILURE;
+
if (!init_mgmt_interface())
return EXIT_FAILURE;

diff --git a/configure.ac b/configure.ac
index 7b1f64a..5406434 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 "${android_daemon}" = "yes"); then
+ AC_CHECK_LIB(cap, capget, dummy=yes, AC_MSG_ERROR(libcap is required))
+fi
+
AC_OUTPUT(Makefile src/bluetoothd.8 lib/bluez.pc)
--
1.7.10.4


2013-10-15 10:37:01

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv1 3/5] android: Add adapter and device struct for BlueZ daemon

From: Andrei Emeltchenko <[email protected]>

Adapter structure in BlueZ daemon keeps track of default adapter
and device structure keeps track about found devices.
---
android/adapter.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
android/adapter.h | 36 ++++++++++++++++++++++++++++++
android/device.c | 29 ++++++++++++++++++++++++
android/device.h | 24 ++++++++++++++++++++
4 files changed, 152 insertions(+)
create mode 100644 android/adapter.c
create mode 100644 android/adapter.h
create mode 100644 android/device.c
create mode 100644 android/device.h

diff --git a/android/adapter.c b/android/adapter.c
new file mode 100644
index 0000000..b97a7c7
--- /dev/null
+++ b/android/adapter.c
@@ -0,0 +1,63 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "src/shared/mgmt.h"
+#include "log.h"
+#include "adapter.h"
+
+struct bt_adapter {
+ struct mgmt *mgmt;
+ bdaddr_t bdaddr;
+ uint32_t dev_class;
+
+ char *name;
+
+ uint32_t supported_settings;
+ uint32_t current_settings;
+
+ GList *found_devices;
+};
+
+struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if)
+{
+ struct bt_adapter *adapter;
+
+ adapter = g_new0(struct bt_adapter, 1);
+
+ adapter->mgmt = mgmt_ref(mgmt_if);
+
+ return adapter;
+}
+
+void bt_adapter_start(struct bt_adapter *adapter)
+{
+ DBG("");
+
+ /* TODO: CB: report scan mode */
+ /* TODO: CB: report state on */
+}
+
+void bt_adapter_stop(struct bt_adapter *adapter)
+{
+ DBG("");
+}
diff --git a/android/adapter.h b/android/adapter.h
new file mode 100644
index 0000000..0f1445a
--- /dev/null
+++ b/android/adapter.h
@@ -0,0 +1,36 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <glib.h>
+
+#include "lib/bluetooth.h"
+
+struct bt_adapter;
+
+struct bt_adapter *bt_adapter_new(uint16_t index, struct mgmt *mgmt_if);
+
+void bt_adapter_start(struct bt_adapter *adapter);
+void bt_adapter_stop(struct bt_adapter *adapter);
diff --git a/android/device.c b/android/device.c
new file mode 100644
index 0000000..224a317
--- /dev/null
+++ b/android/device.c
@@ -0,0 +1,29 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+struct bt_device {
+ bdaddr_t bdaddr;
+ uint8_t bdaddr_type;
+ uint32_t cod;
+ char *name;
+};
diff --git a/android/device.h b/android/device.h
new file mode 100644
index 0000000..f5b1da6
--- /dev/null
+++ b/android/device.h
@@ -0,0 +1,24 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+struct bt_device;
--
1.7.10.4


2013-10-15 10:37:02

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv1 4/5] android: sdp: Reuse BlueZ SDP server in Android

From: Andrei Emeltchenko <[email protected]>

Reuse existing SDP server code in Android GPL daemon.
---
Makefile.android | 4 +++-
android/Android.mk | 8 ++++++++
android/main.c | 5 +++++
3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/Makefile.android b/Makefile.android
index 7371a77..48af2e2 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -2,9 +2,11 @@ if ANDROID
noinst_PROGRAMS += android/bluetoothd

android_bluetoothd_SOURCES = android/main.c src/log.c \
+ src/sdpd-database.c src/sdpd-server.c \
+ src/sdpd-service.c src/sdpd-request.c \
src/shared/util.h src/shared/util.c \
src/shared/mgmt.h src/shared/mgmt.c
-android_bluetoothd_LDADD = @GLIB_LIBS@
+android_bluetoothd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
endif

EXTRA_DIST += android/Android.mk android/log.c
diff --git a/android/Android.mk b/android/Android.mk
index 4996080..560fb0a 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -17,6 +17,13 @@ LOCAL_SRC_FILES := \
log.c \
../src/shared/mgmt.c \
../src/shared/util.c \
+ ../src/sdpd-database.c \
+ ../src/sdpd-service.c \
+ ../src/sdpd-request.c \
+ ../src/sdpd-server.c \
+ ../lib/sdp.c \
+ ../lib/bluetooth.c \
+ ../lib/hci.c \

LOCAL_C_INCLUDES := \
$(call include-path-for, glib) \
@@ -25,6 +32,7 @@ LOCAL_C_INCLUDES := \
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../src \
+ $(LOCAL_PATH)/../lib \

LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"

diff --git a/android/main.c b/android/main.c
index ba25b84..2b8675d 100644
--- a/android/main.c
+++ b/android/main.c
@@ -36,6 +36,7 @@
#include <glib.h>

#include "log.h"
+#include "sdpd.h"

#include "lib/bluetooth.h"
#include "lib/mgmt.h"
@@ -267,10 +268,14 @@ int main(int argc, char *argv[])
if (!init_mgmt_interface())
return EXIT_FAILURE;

+ /* Use params: mtu = 0, flags = 0 */
+ start_sdp_server(0, 0);
+
DBG("Entering main loop");

g_main_loop_run(event_loop);

+ stop_sdp_server();
cleanup_mgmt_interface();
g_main_loop_unref(event_loop);

--
1.7.10.4


2013-10-15 10:37:00

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv1 2/5] android: Add basic mgmt initialization sequence

From: Andrei Emeltchenko <[email protected]>

Initialize bluetooth controller via mgmt interface.
---
Makefile.android | 4 +-
android/Android.mk | 5 ++
android/main.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 176 insertions(+), 1 deletion(-)

diff --git a/Makefile.android b/Makefile.android
index 3ceefd8..7371a77 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -1,7 +1,9 @@
if ANDROID
noinst_PROGRAMS += android/bluetoothd

-android_bluetoothd_SOURCES = android/main.c src/log.c
+android_bluetoothd_SOURCES = android/main.c src/log.c \
+ src/shared/util.h src/shared/util.c \
+ src/shared/mgmt.h src/shared/mgmt.c
android_bluetoothd_LDADD = @GLIB_LIBS@
endif

diff --git a/android/Android.mk b/android/Android.mk
index 0e025ac..4996080 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -15,10 +15,15 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
main.c \
log.c \
+ ../src/shared/mgmt.c \
+ ../src/shared/util.c \

LOCAL_C_INCLUDES := \
$(call include-path-for, glib) \
$(call include-path-for, glib)/glib \
+
+LOCAL_C_INCLUDES += \
+ $(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../src \

LOCAL_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\"
diff --git a/android/main.c b/android/main.c
index f75b0a8..ba25b84 100644
--- a/android/main.c
+++ b/android/main.c
@@ -25,6 +25,7 @@
#include <config.h>
#endif

+#include <stdbool.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
@@ -36,9 +37,17 @@

#include "log.h"

+#include "lib/bluetooth.h"
+#include "lib/mgmt.h"
+#include "src/shared/mgmt.h"
+
#define SHUTDOWN_GRACE_SECONDS 10

static GMainLoop *event_loop;
+static struct mgmt *mgmt_if = NULL;
+
+static uint8_t mgmt_version = 0;
+static uint8_t mgmt_revision = 0;

static gboolean quit_eventloop(gpointer user_data)
{
@@ -67,6 +76,161 @@ static GOptionEntry options[] = {
{ NULL }
};

+static void read_info_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ /* TODO: Store Controller information */
+
+ /* TODO: Register all event notification handlers */
+}
+
+
+static void mgmt_index_added_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("index %u", index);
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
+ read_info_complete, NULL, NULL) > 0)
+ return;
+
+ error("Failed to read adapter info for index %u", index);
+
+}
+
+static void mgmt_index_removed_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("index %u", index);
+}
+
+static void read_index_list_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_index_list *rp = param;
+ uint16_t num;
+ int i;
+
+ info(__func__);
+
+ if (!status) {
+ error("%s: Failed to read index list: %s (0x%02x)",
+ __func__, mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("%s: Wrong size of read index list response", __func__);
+ return;
+ }
+
+ num = btohs(rp->num_controllers);
+
+ DBG("%s: Number of controllers: %u", __func__, num);
+
+ if (num * sizeof(uint16_t) + sizeof(*rp) != length) {
+ error("%s: Incorrect pkt size for index list rsp", __func__);
+ return;
+ }
+
+ for (i = 0; i < num; i++) {
+ uint16_t index;
+
+ index = btohs(rp->index[i]);
+
+ /**
+ * Use index added event notification.
+ */
+ mgmt_index_added_event(index, 0, NULL, NULL);
+ }
+}
+
+static void read_commands_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_commands *rp = param;
+
+ DBG("");
+
+ if (!status) {
+ error("Failed to read supported commands: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("Wrong size response");
+ return;
+ }
+}
+
+static void read_version_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_rp_read_version *rp = param;
+
+ DBG("");
+
+ if (!status) {
+ error("Failed to read version information: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ if (length < sizeof(*rp)) {
+ error("Wrong size response");
+ return;
+ }
+
+ mgmt_version = rp->version;
+ mgmt_revision = btohs(rp->revision);
+
+ info("Bluetooth management interface %u.%u initialized",
+ mgmt_version, mgmt_revision);
+
+ if (mgmt_version < 1) {
+ error("Version 1.0 or later of management interface required");
+ abort();
+ }
+
+ mgmt_send(mgmt_if, MGMT_OP_READ_COMMANDS, MGMT_INDEX_NONE, 0, NULL,
+ read_commands_complete, NULL, NULL);
+
+ mgmt_register(mgmt_if, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE,
+ mgmt_index_added_event, NULL, NULL);
+ mgmt_register(mgmt_if, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE,
+ mgmt_index_removed_event, NULL, NULL);
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0,
+ NULL, read_index_list_complete, NULL, NULL) > 0)
+ return;
+
+ error("Failed to read controller index list");
+}
+
+static bool init_mgmt_interface(void)
+{
+ mgmt_if = mgmt_new_default();
+ if (!mgmt_if) {
+ error("Failed to access management interface");
+ return false;
+ }
+
+ if (mgmt_send(mgmt_if, MGMT_OP_READ_VERSION, MGMT_INDEX_NONE, 0, NULL,
+ read_version_complete, NULL, NULL) == 0) {
+ error("Error sending READ_VERSION mgmt command");
+ return false;
+ }
+
+ return true;
+}
+
+static void cleanup_mgmt_interface(void)
+{
+ mgmt_unref(mgmt_if);
+ mgmt_if = NULL;
+}
+
int main(int argc, char *argv[])
{
GOptionContext *context;
@@ -100,10 +264,14 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);

+ if (!init_mgmt_interface())
+ return EXIT_FAILURE;
+
DBG("Entering main loop");

g_main_loop_run(event_loop);

+ cleanup_mgmt_interface();
g_main_loop_unref(event_loop);

info("Exit");
--
1.7.10.4


2013-10-15 10:36:59

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv1 1/5] android: Create HAL API header skeleton

From: Andrei Emeltchenko <[email protected]>

Header describes the protocol between Android HAL threads and BlueZ
daemon.

Change-Id: Idfba8c6ebe6234340d1b0258756ee2bedfc315d7
---
android/hal_msg.h | 246 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 246 insertions(+)
create mode 100644 android/hal_msg.h

diff --git a/android/hal_msg.h b/android/hal_msg.h
new file mode 100644
index 0000000..4c5ca69
--- /dev/null
+++ b/android/hal_msg.h
@@ -0,0 +1,246 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+struct hal_msg_hdr {
+ uint8_t service_id;
+ uint8_t opcode;
+ uint16_t len;
+} __attribute__((packed));
+
+#define HAL_SERVICE_ID_CORE 0
+#define HAL_SERVICE_ID_BLUETOOTH 1
+#define HAL_SERVICE_ID_SOCK 2
+#define HAL_SERVICE_ID_HIDHOST 3
+#define HAL_SERVICE_ID_PAN 4
+#define HAL_SERVICE_ID_HANDSFREE 5
+#define HAL_SERVICE_ID_AD2P 6
+#define HAL_SERVICE_ID_HEALTH 7
+#define HAL_SERVICE_ID_AVRCP 8
+#define HAL_SERVICE_ID_GATT 9
+
+/* Core Service */
+
+#define HAL_MSG_OP_ERROR 0x00
+struct hal_msg_rsp_error {
+ uint8_t status;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_REGISTER_MODULE 0x01
+struct hal_msg_cmd_register_module {
+ uint8_t service_id;
+} __attribute__((packed));
+struct hal_msg_rsp_register_module {
+ uint8_t service_id;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_UNREGISTER_MODULE 0x02
+struct hal_msg_cmd_unregister_module {
+ uint8_t service_id;
+} __attribute__((packed));
+
+/* Bluetooth Core HAL API */
+
+#define HAL_MSG_OP_BT_ENABLE 0x01
+
+#define HAL_MSG_OP_BT_DISABLE 0x02
+
+#define HAL_MSG_OP_BT_GET_ADAPTER_PROPS 0x03
+
+#define HAL_MSG_OP_BT_GET_ADAPTER_PROP 0x04
+struct hal_msg_cmd_bt_get_adapter_prop {
+ uint8_t type;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SET_ADAPTER_PROP 0x05
+struct hal_msg_cmd_bt_set_adapter_prop {
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_DEVICE_PROPS 0x06
+struct hal_msg_cmd_bt_get_remote_device_props {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_DEVICE_PROP 0x07
+struct hal_msg_cmd_bt_get_remote_device_prop {
+ uint8_t bdaddr[6];
+ uint8_t type;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SET_REMOTE_DEVICE_PROP 0x08
+struct hal_msg_cmd_bt_set_remote_device_prop {
+ uint8_t bdaddr[6];
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_SERVICE_REC 0x09
+struct hal_msg_cmd_bt_get_remote_service_rec {
+ uint8_t bdaddr[6];
+ uint8_t uuid[16];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_GET_REMOTE_SERVICE 0x0a
+struct hal_msg_cmd_bt_get_remote_service {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_START_DISCOVERY 0x0b
+
+#define HAL_MSG_OP_BT_CANCEL_DISCOVERY 0x0c
+
+#define HAL_MSG_OP_BT_CREATE_BOND 0x0d
+struct hal_msg_cmd_bt_create_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_REMOVE_BOND 0x0d
+struct hal_msg_cmd_bt_remove_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_CANCEL_BOND 0x0f
+struct hal_msg_cmd_bt_cancel_bond {
+ uint8_t bdaddr[6];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_PIN_REPLY 0x10
+struct hal_msg_cmd_bt_pin_reply {
+ uint8_t bdaddr[6];
+ uint8_t accept;
+ uint8_t pin_len;
+ uint8_t pin_code[16];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_SSP_REPLY 0x11
+struct hal_msg_cmd_bt_ssp_reply {
+ uint8_t bdaddr[6];
+ uint8_t ssp_variant;
+ uint8_t accept;
+ uint32_t passkey;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_DUT_MODE_CONF 0x12
+struct hal_msg_cmd_bt_dut_mode_conf {
+ uint8_t enable;
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_DUT_MODE_SEND 0x13
+struct hal_msg_cmd_bt_dut_mode_send {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+#define HAL_MSG_OP_BT_LE_TEST_MODE 0x14
+struct hal_msg_cmd_bt_le_test_mode {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+/* Notifications and confirmations */
+
+#define HAL_MSG_EV_BT_ERROR 0x80
+
+#define HAL_MSG_EV_BT_ADAPTER_STATE_CHANGED 0x81
+struct hal_msg_ev_bt_adapter_state_changed {
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_ADAPTER_PROPS_CHANGED 0x82
+struct hal_property {
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+struct hal_msg_ev_bt_adapter_props_changed {
+ uint8_t status;
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_REMOTE_DEVICE_PROPS 0x83
+struct hal_msg_ev_bt_remote_device_props {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DEVICE_FOUND 0x84
+struct hal_msg_ev_bt_device_found {
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DISCOVERY_STATE_CHANGED 0x85
+struct hal_msg_ev_bt_discovery_state_changed {
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_PIN_REQUEST 0x86
+struct hal_msg_ev_bt_pin_request {
+ uint8_t bdaddr[6];
+ uint8_t name[249 - 1];
+ uint8_t class_of_dev[3];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_SSP_REQUEST 0x87
+struct hal_msg_ev_bt_ssp_request {
+ uint8_t bdaddr[6];
+ uint8_t name[249 - 1];
+ uint8_t class_of_dev[3];
+ uint8_t pairing_variant;
+ uint32_t passkey;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_BOND_STATE_CHANGED 0x88
+struct hal_msg_ev_bt_bond_state_changed {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_ACL_STATE_CHANGED 0x89
+struct hal_msg_ev_bt_acl_state_changed {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_DUT_MODE_RECEIVE 0x8a
+struct hal_msg_ev_bt_dut_mode_receive {
+ uint16_t opcode;
+ uint8_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
+#define HAL_MSG_EV_BT_LE_TEST_MODE 0x8b
+struct hal_msg_ev_bt_le_test_mode {
+ uint8_t status;
+ uint16_t num_packets;
+} __attribute__((packed));
--
1.7.10.4