From: Andrei Emeltchenko <[email protected]>
This is small chunk form my previous patch series splitted for easy review.
I need to understand what is current coding style for our project, so far it seems
very different from BlueZ I took as example first. Please comment.
Andrei Emeltchenko (4):
android: Add Adapter Bluetooth HAL template
android: Add Socket Bluetooth HAL template
android: Enable Socket interface
android: Start Android Bluetooth daemon
android/Android.mk | 20 +++
android/hal.h | 18 +++
android/hal_bluetooth.c | 389 +++++++++++++++++++++++++++++++++++++++++++++++
android/hal_bt_sock.c | 85 +++++++++++
4 files changed, 512 insertions(+)
create mode 100644 android/hal.h
create mode 100644 android/hal_bluetooth.c
create mode 100644 android/hal_bt_sock.c
--
1.7.10.4
Hi Andrei,
On Fri, Oct 11, 2013, Andrei Emeltchenko wrote:
> This is small chunk form my previous patch series splitted for easy review.
> I need to understand what is current coding style for our project, so far it seems
> very different from BlueZ I took as example first. Please comment.
>
> Changes:
> * PATCHv2: removed unused function
>
> Andrei Emeltchenko (4):
> android: Add Adapter Bluetooth HAL template
> android: Add Socket Bluetooth HAL template
> android: Enable Socket interface
> android: Start Android Bluetooth daemon
>
> android/Android.mk | 20 +++
> android/hal.h | 18 +++
> android/hal_bluetooth.c | 384 +++++++++++++++++++++++++++++++++++++++++++++++
> android/hal_bt_sock.c | 85 +++++++++++
> 4 files changed, 507 insertions(+)
> create mode 100644 android/hal.h
> create mode 100644 android/hal_bluetooth.c
> create mode 100644 android/hal_bt_sock.c
All four patches have been applied to bluez.git.
Johan
From: Andrei Emeltchenko <[email protected]>
Start Android Bluetooth daemon from HAL init(). Make sure
that daemon is in "running" state.
---
android/hal_bluetooth.c | 41 ++++++++++++++++++++++++++++++++++++++---
1 file changed, 38 insertions(+), 3 deletions(-)
diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
index 517f0b4..9bb9dcf 100644
--- a/android/hal_bluetooth.c
+++ b/android/hal_bluetooth.c
@@ -23,11 +23,16 @@
#include <hardware/bluetooth.h>
#include <hardware/bt_sock.h>
+#include <cutils/sockets.h>
+#include <cutils/properties.h>
+
#define LOG_TAG "BlueZ"
#include <cutils/log.h>
#include "hal.h"
+#define SERVICE_NAME "bluetoothd"
+
bt_callbacks_t *bt_hal_cbacks = NULL;
static bool interface_ready(void)
@@ -35,6 +40,33 @@ 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__);
@@ -42,10 +74,13 @@ static int init(bt_callbacks_t *callbacks)
if (interface_ready())
return BT_STATUS_SUCCESS;
- /* store reference to user callbacks */
- bt_hal_cbacks = callbacks;
+ if (start_bt_daemon()) {
+ /* TODO: open channel */
+
+ bt_hal_cbacks = callbacks;
- /* TODO: Init here bluezd task */
+ return BT_STATUS_SUCCESS;
+ }
return BT_STATUS_UNSUPPORTED;
}
--
1.7.10.4
From: Andrei Emeltchenko <[email protected]>
bt_sock HAL handles Bluetooth sockets for Android.
---
android/Android.mk | 1 +
android/hal_bt_sock.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 86 insertions(+)
create mode 100644 android/hal_bt_sock.c
diff --git a/android/Android.mk b/android/Android.mk
index 553b673..0e025ac 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -38,6 +38,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
hal_bluetooth.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;
+}
--
1.7.10.4
From: Andrei Emeltchenko <[email protected]>
Add template for bluetooth.h Android HAL.
---
android/Android.mk | 19 +++
android/hal_bluetooth.c | 343 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 362 insertions(+)
create mode 100644 android/hal_bluetooth.c
diff --git a/android/Android.mk b/android/Android.mk
index ec820ac..553b673 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -29,3 +29,22 @@ LOCAL_SHARED_LIBRARIES := \
LOCAL_MODULE := bluetoothd
include $(BUILD_EXECUTABLE)
+
+#
+# bluetooth.default.so HAL
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ hal_bluetooth.c \
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+
+LOCAL_MODULE := bluetooth.default
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
new file mode 100644
index 0000000..48638a5
--- /dev/null
+++ b/android/hal_bluetooth.c
@@ -0,0 +1,343 @@
+/*
+ * 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>
+
+#define LOG_TAG "BlueZ"
+#include <cutils/log.h>
+
+bt_callbacks_t *bt_hal_cbacks = NULL;
+
+static bool interface_ready(void)
+{
+ return bt_hal_cbacks != NULL;
+}
+
+static int init(bt_callbacks_t *callbacks)
+{
+ ALOGD(__func__);
+
+ if (interface_ready())
+ return BT_STATUS_SUCCESS;
+
+ /* store reference to user callbacks */
+ bt_hal_cbacks = callbacks;
+
+ /* TODO: Init here bluezd task */
+
+ 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;
+
+ 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 = {
+ 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
+};
+
+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
From: Andrei Emeltchenko <[email protected]>
Returns socket interface, use header hal.h to avoid externs.
---
android/hal.h | 18 ++++++++++++++++++
android/hal_bluetooth.c | 6 ++++++
2 files changed, 24 insertions(+)
create mode 100644 android/hal.h
diff --git a/android/hal.h b/android/hal.h
new file mode 100644
index 0000000..40fbf03
--- /dev/null
+++ b/android/hal.h
@@ -0,0 +1,18 @@
+/*
+ * 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.
+ *
+ */
+
+btsock_interface_t *bt_get_sock_interface(void);
diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
index 48638a5..517f0b4 100644
--- a/android/hal_bluetooth.c
+++ b/android/hal_bluetooth.c
@@ -21,10 +21,13 @@
#include <stdbool.h>
#include <hardware/bluetooth.h>
+#include <hardware/bt_sock.h>
#define LOG_TAG "BlueZ"
#include <cutils/log.h>
+#include "hal.h"
+
bt_callbacks_t *bt_hal_cbacks = NULL;
static bool interface_ready(void)
@@ -244,6 +247,9 @@ static const void *get_profile_interface(const char *profile_id)
if (!interface_ready())
return NULL;
+ if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
+ return bt_get_sock_interface();
+
return NULL;
}
--
1.7.10.4
From: Andrei Emeltchenko <[email protected]>
Start Android Bluetooth daemon from HAL init(). Make sure
that daemon is in "running" state.
Change-Id: I6f26d8167c0633f009f5805f0c8dd515461cae2a
---
android/hal_bluetooth.c | 41 ++++++++++++++++++++++++++++++++++++++---
1 file changed, 38 insertions(+), 3 deletions(-)
diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
index 517f0b4..9bb9dcf 100644
--- a/android/hal_bluetooth.c
+++ b/android/hal_bluetooth.c
@@ -23,11 +23,16 @@
#include <hardware/bluetooth.h>
#include <hardware/bt_sock.h>
+#include <cutils/sockets.h>
+#include <cutils/properties.h>
+
#define LOG_TAG "BlueZ"
#include <cutils/log.h>
#include "hal.h"
+#define SERVICE_NAME "bluetoothd"
+
bt_callbacks_t *bt_hal_cbacks = NULL;
static bool interface_ready(void)
@@ -35,6 +40,33 @@ 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__);
@@ -42,10 +74,13 @@ static int init(bt_callbacks_t *callbacks)
if (interface_ready())
return BT_STATUS_SUCCESS;
- /* store reference to user callbacks */
- bt_hal_cbacks = callbacks;
+ if (start_bt_daemon()) {
+ /* TODO: open channel */
+
+ bt_hal_cbacks = callbacks;
- /* TODO: Init here bluezd task */
+ return BT_STATUS_SUCCESS;
+ }
return BT_STATUS_UNSUPPORTED;
}
--
1.7.10.4
From: Andrei Emeltchenko <[email protected]>
This is small chunk form my previous patch series splitted for easy review.
I need to understand what is current coding style for our project, so far it seems
very different from BlueZ I took as example first. Please comment.
Changes:
* PATCHv2: removed unused function
Andrei Emeltchenko (4):
android: Add Adapter Bluetooth HAL template
android: Add Socket Bluetooth HAL template
android: Enable Socket interface
android: Start Android Bluetooth daemon
android/Android.mk | 20 +++
android/hal.h | 18 +++
android/hal_bluetooth.c | 384 +++++++++++++++++++++++++++++++++++++++++++++++
android/hal_bt_sock.c | 85 +++++++++++
4 files changed, 507 insertions(+)
create mode 100644 android/hal.h
create mode 100644 android/hal_bluetooth.c
create mode 100644 android/hal_bt_sock.c
--
1.7.10.4
Hi Andrei,
> From: Andrei Emeltchenko <[email protected]>
>
> Returns socket interface, use header hal.h to avoid externs.
> ---
> android/hal.h | 18 ++++++++++++++++++
> android/hal_bluetooth.c | 11 +++++++++++
> 2 files changed, 29 insertions(+)
> create mode 100644 android/hal.h
>
> diff --git a/android/hal.h b/android/hal.h
> new file mode 100644
> index 0000000..40fbf03
> --- /dev/null
> +++ b/android/hal.h
> @@ -0,0 +1,18 @@
> +/*
> + * 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.
> + *
> + */
> +
> +btsock_interface_t *bt_get_sock_interface(void);
> diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
> index 48638a5..688314b 100644
> --- a/android/hal_bluetooth.c
> +++ b/android/hal_bluetooth.c
> @@ -21,10 +21,13 @@
> #include <stdbool.h>
>
> #include <hardware/bluetooth.h>
> +#include <hardware/bt_sock.h>
>
> #define LOG_TAG "BlueZ"
> #include <cutils/log.h>
>
> +#include "hal.h"
> +
> bt_callbacks_t *bt_hal_cbacks = NULL;
>
> static bool interface_ready(void)
> @@ -32,6 +35,11 @@ static bool interface_ready(void)
> return bt_hal_cbacks != NULL;
> }
>
> +static bool is_profile(const char *profile, const char *str)
> +{
> + return strcmp(profile, str) == 0;
> +}
This is not used since you use strcmp directly and should be removed.
> +
> static int init(bt_callbacks_t *callbacks)
> {
> ALOGD(__func__);
> @@ -244,6 +252,9 @@ static const void *get_profile_interface(const char *profile_id)
> if (!interface_ready())
> return NULL;
>
> + if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
> + return bt_get_sock_interface();
> +
> return NULL;
> }
>
>
--
BR
Szymon Janc
From: Andrei Emeltchenko <[email protected]>
Returns socket interface, use header hal.h to avoid externs.
---
android/hal.h | 18 ++++++++++++++++++
android/hal_bluetooth.c | 11 +++++++++++
2 files changed, 29 insertions(+)
create mode 100644 android/hal.h
diff --git a/android/hal.h b/android/hal.h
new file mode 100644
index 0000000..40fbf03
--- /dev/null
+++ b/android/hal.h
@@ -0,0 +1,18 @@
+/*
+ * 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.
+ *
+ */
+
+btsock_interface_t *bt_get_sock_interface(void);
diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
index 48638a5..688314b 100644
--- a/android/hal_bluetooth.c
+++ b/android/hal_bluetooth.c
@@ -21,10 +21,13 @@
#include <stdbool.h>
#include <hardware/bluetooth.h>
+#include <hardware/bt_sock.h>
#define LOG_TAG "BlueZ"
#include <cutils/log.h>
+#include "hal.h"
+
bt_callbacks_t *bt_hal_cbacks = NULL;
static bool interface_ready(void)
@@ -32,6 +35,11 @@ static bool interface_ready(void)
return bt_hal_cbacks != NULL;
}
+static bool is_profile(const char *profile, const char *str)
+{
+ return strcmp(profile, str) == 0;
+}
+
static int init(bt_callbacks_t *callbacks)
{
ALOGD(__func__);
@@ -244,6 +252,9 @@ static const void *get_profile_interface(const char *profile_id)
if (!interface_ready())
return NULL;
+ if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
+ return bt_get_sock_interface();
+
return NULL;
}
--
1.7.10.4
From: Andrei Emeltchenko <[email protected]>
Add template for bluetooth.h Android HAL.
---
android/Android.mk | 19 +++
android/hal_bluetooth.c | 343 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 362 insertions(+)
create mode 100644 android/hal_bluetooth.c
diff --git a/android/Android.mk b/android/Android.mk
index ec820ac..553b673 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -29,3 +29,22 @@ LOCAL_SHARED_LIBRARIES := \
LOCAL_MODULE := bluetoothd
include $(BUILD_EXECUTABLE)
+
+#
+# bluetooth.default.so HAL
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ hal_bluetooth.c \
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+
+LOCAL_MODULE := bluetooth.default
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
new file mode 100644
index 0000000..48638a5
--- /dev/null
+++ b/android/hal_bluetooth.c
@@ -0,0 +1,343 @@
+/*
+ * 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>
+
+#define LOG_TAG "BlueZ"
+#include <cutils/log.h>
+
+bt_callbacks_t *bt_hal_cbacks = NULL;
+
+static bool interface_ready(void)
+{
+ return bt_hal_cbacks != NULL;
+}
+
+static int init(bt_callbacks_t *callbacks)
+{
+ ALOGD(__func__);
+
+ if (interface_ready())
+ return BT_STATUS_SUCCESS;
+
+ /* store reference to user callbacks */
+ bt_hal_cbacks = callbacks;
+
+ /* TODO: Init here bluezd task */
+
+ 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;
+
+ 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 = {
+ 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
+};
+
+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
From: Andrei Emeltchenko <[email protected]>
bt_sock HAL handles Bluetooth sockets for Android.
---
android/Android.mk | 1 +
android/hal_bt_sock.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 86 insertions(+)
create mode 100644 android/hal_bt_sock.c
diff --git a/android/Android.mk b/android/Android.mk
index 553b673..0e025ac 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -38,6 +38,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
hal_bluetooth.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;
+}
--
1.7.10.4
From: Andrei Emeltchenko <[email protected]>
Start Android Bluetooth daemon from HAL init(). Make sure
that daemon is in "running" state.
---
android/hal_bluetooth.c | 41 ++++++++++++++++++++++++++++++++++++++---
1 file changed, 38 insertions(+), 3 deletions(-)
diff --git a/android/hal_bluetooth.c b/android/hal_bluetooth.c
index 688314b..a5dd090 100644
--- a/android/hal_bluetooth.c
+++ b/android/hal_bluetooth.c
@@ -23,11 +23,16 @@
#include <hardware/bluetooth.h>
#include <hardware/bt_sock.h>
+#include <cutils/sockets.h>
+#include <cutils/properties.h>
+
#define LOG_TAG "BlueZ"
#include <cutils/log.h>
#include "hal.h"
+#define SERVICE_NAME "bluetoothd"
+
bt_callbacks_t *bt_hal_cbacks = NULL;
static bool interface_ready(void)
@@ -35,6 +40,33 @@ 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 bool is_profile(const char *profile, const char *str)
{
return strcmp(profile, str) == 0;
@@ -47,10 +79,13 @@ static int init(bt_callbacks_t *callbacks)
if (interface_ready())
return BT_STATUS_SUCCESS;
- /* store reference to user callbacks */
- bt_hal_cbacks = callbacks;
+ if (start_bt_daemon()) {
+ /* TODO: open channel */
+
+ bt_hal_cbacks = callbacks;
- /* TODO: Init here bluezd task */
+ return BT_STATUS_SUCCESS;
+ }
return BT_STATUS_UNSUPPORTED;
}
--
1.7.10.4