Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] Add device/intel repository
From: Andrei Emeltchenko @ 2013-10-11 10:37 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

In device/intel we need to disable blacklisting bluetooth kernel modules.

Change-Id: I84a742ad75035bf5d3238cd632fe875aa5f97143
---
 topics/local_manifest.xml |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/topics/local_manifest.xml b/topics/local_manifest.xml
index 360f5f5..3ad60c4 100644
--- a/topics/local_manifest.xml
+++ b/topics/local_manifest.xml
@@ -19,4 +19,8 @@
   <project path="bionic" name="android-bluez.bionic"
     remote="android-bluez" revision="master" />
 
+  <remove-project name="device/intel" />
+  <project path="device/intel" name="android-bluez.device-intel"
+    remote="android-bluez" revision="master" />
+
 </manifest>
-- 
1.7.10.4


^ permalink raw reply related

* [PATCH] android: Create HAL API header skeleton
From: Andrei Emeltchenko @ 2013-10-11 10:17 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


^ permalink raw reply related

* [PATCHv2 4/4] android: Start Android Bluetooth daemon
From: Andrei Emeltchenko @ 2013-10-11 10:02 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1381485723-15898-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


^ permalink raw reply related

* [PATCHv2 3/4] android: Enable Socket interface
From: Andrei Emeltchenko @ 2013-10-11 10:02 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1381485723-15898-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


^ permalink raw reply related

* [PATCHv2 2/4] android: Add Socket Bluetooth HAL template
From: Andrei Emeltchenko @ 2013-10-11 10:02 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1381485723-15898-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


^ permalink raw reply related

* [PATCHv2 1/4] android: Add Adapter Bluetooth HAL template
From: Andrei Emeltchenko @ 2013-10-11 10:02 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1381485723-15898-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


^ permalink raw reply related

* [PATCHv2 0/4] Initial patches splitted
From: Andrei Emeltchenko @ 2013-10-11 10:01 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <172688778.UF0VyY4IqK@uw000953>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


^ permalink raw reply

* Re: [PATCHv1 3/4] android: Enable Socket interface
From: Szymon Janc @ 2013-10-11  9:31 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1381477555-11319-4-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> 
> 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


^ permalink raw reply

* [PATCHv1 4/4] android: Start Android Bluetooth daemon
From: Andrei Emeltchenko @ 2013-10-11  7:45 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1381477555-11319-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


^ permalink raw reply related

* [PATCHv1 3/4] android: Enable Socket interface
From: Andrei Emeltchenko @ 2013-10-11  7:45 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1381477555-11319-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


^ permalink raw reply related

* [PATCHv1 2/4] android: Add Socket Bluetooth HAL template
From: Andrei Emeltchenko @ 2013-10-11  7:45 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1381477555-11319-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


^ permalink raw reply related

* [PATCHv1 1/4] android: Add Adapter Bluetooth HAL template
From: Andrei Emeltchenko @ 2013-10-11  7:45 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1381477555-11319-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


^ permalink raw reply related

* [PATCHv1 0/4] Initial patches splitted
From: Andrei Emeltchenko @ 2013-10-11  7:45 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


^ permalink raw reply

* Re: [PATCH 1/2] Bluetooth: Remove unused h4_check_data_len() function
From: Johan Hedberg @ 2013-10-11  5:54 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1381449163-19932-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Thu, Oct 10, 2013, Marcel Holtmann wrote:
> The function h4_check_data_len() is actually not used. So just
> remove it.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  drivers/bluetooth/hci_h4.c | 24 ------------------------
>  1 file changed, 24 deletions(-)

Both patches in this set have been applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* [PATCH 2/2] Bluetooth: Provide hdev parameter to hci_recv_frame() driver callback
From: Marcel Holtmann @ 2013-10-10 23:52 UTC (permalink / raw)
  To: linux-bluetooth

To avoid casting skb->dev into hdev, just let the drivers provide
the hdev directly when calling hci_recv_frame() function.

This patch also fixes up all drivers to provide the hdev.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 drivers/bluetooth/bfusb.c        |  3 +--
 drivers/bluetooth/bluecard_cs.c  |  3 +--
 drivers/bluetooth/bpa10x.c       |  4 +---
 drivers/bluetooth/bt3c_cs.c      |  3 +--
 drivers/bluetooth/btmrvl_sdio.c  |  8 +++-----
 drivers/bluetooth/btsdio.c       |  3 +--
 drivers/bluetooth/btuart_cs.c    |  3 +--
 drivers/bluetooth/btwilink.c     |  4 +---
 drivers/bluetooth/dtl1_cs.c      |  3 +--
 drivers/bluetooth/hci_bcsp.c     |  5 ++---
 drivers/bluetooth/hci_h5.c       |  2 +-
 drivers/bluetooth/hci_ll.c       | 13 ++++++-------
 drivers/bluetooth/hci_vhci.c     |  3 +--
 include/net/bluetooth/hci_core.h |  2 +-
 net/bluetooth/hci_core.c         |  6 ++----
 15 files changed, 24 insertions(+), 41 deletions(-)

diff --git a/drivers/bluetooth/bfusb.c b/drivers/bluetooth/bfusb.c
index 66faad0..b7b5bb8 100644
--- a/drivers/bluetooth/bfusb.c
+++ b/drivers/bluetooth/bfusb.c
@@ -318,7 +318,6 @@ static inline int bfusb_recv_block(struct bfusb_data *data, int hdr, unsigned ch
 			return -ENOMEM;
 		}
 
-		skb->dev = (void *) data->hdev;
 		bt_cb(skb)->pkt_type = pkt_type;
 
 		data->reassembly = skb;
@@ -333,7 +332,7 @@ static inline int bfusb_recv_block(struct bfusb_data *data, int hdr, unsigned ch
 		memcpy(skb_put(data->reassembly, len), buf, len);
 
 	if (hdr & 0x08) {
-		hci_recv_frame(data->reassembly);
+		hci_recv_frame(data->hdev, data->reassembly);
 		data->reassembly = NULL;
 	}
 
diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
index aa872c9..395acde 100644
--- a/drivers/bluetooth/bluecard_cs.c
+++ b/drivers/bluetooth/bluecard_cs.c
@@ -399,7 +399,6 @@ static void bluecard_receive(bluecard_info_t *info, unsigned int offset)
 
 		if (info->rx_state == RECV_WAIT_PACKET_TYPE) {
 
-			info->rx_skb->dev = (void *) info->hdev;
 			bt_cb(info->rx_skb)->pkt_type = buf[i];
 
 			switch (bt_cb(info->rx_skb)->pkt_type) {
@@ -477,7 +476,7 @@ static void bluecard_receive(bluecard_info_t *info, unsigned int offset)
 					break;
 
 				case RECV_WAIT_DATA:
-					hci_recv_frame(info->rx_skb);
+					hci_recv_frame(info->hdev, info->rx_skb);
 					info->rx_skb = NULL;
 					break;
 
diff --git a/drivers/bluetooth/bpa10x.c b/drivers/bluetooth/bpa10x.c
index 2fe4a80..3188fb4 100644
--- a/drivers/bluetooth/bpa10x.c
+++ b/drivers/bluetooth/bpa10x.c
@@ -129,8 +129,6 @@ static int bpa10x_recv(struct hci_dev *hdev, int queue, void *buf, int count)
 				return -ENOMEM;
 			}
 
-			skb->dev = (void *) hdev;
-
 			data->rx_skb[queue] = skb;
 
 			scb = (void *) skb->cb;
@@ -155,7 +153,7 @@ static int bpa10x_recv(struct hci_dev *hdev, int queue, void *buf, int count)
 			data->rx_skb[queue] = NULL;
 
 			bt_cb(skb)->pkt_type = scb->type;
-			hci_recv_frame(skb);
+			hci_recv_frame(hdev, skb);
 		}
 
 		count -= len; buf += len;
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index 673455c..d8e4b0d 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -247,7 +247,6 @@ static void bt3c_receive(bt3c_info_t *info)
 
 		if (info->rx_state == RECV_WAIT_PACKET_TYPE) {
 
-			info->rx_skb->dev = (void *) info->hdev;
 			bt_cb(info->rx_skb)->pkt_type = inb(iobase + DATA_L);
 			inb(iobase + DATA_H);
 			//printk("bt3c: PACKET_TYPE=%02x\n", bt_cb(info->rx_skb)->pkt_type);
@@ -318,7 +317,7 @@ static void bt3c_receive(bt3c_info_t *info)
 					break;
 
 				case RECV_WAIT_DATA:
-					hci_recv_frame(info->rx_skb);
+					hci_recv_frame(info->hdev, info->rx_skb);
 					info->rx_skb = NULL;
 					break;
 
diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
index 332475e..fabcf5b 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -600,15 +600,14 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 	case HCI_SCODATA_PKT:
 	case HCI_EVENT_PKT:
 		bt_cb(skb)->pkt_type = type;
-		skb->dev = (void *)hdev;
 		skb_put(skb, buf_len);
 		skb_pull(skb, SDIO_HEADER_LEN);
 
 		if (type == HCI_EVENT_PKT) {
 			if (btmrvl_check_evtpkt(priv, skb))
-				hci_recv_frame(skb);
+				hci_recv_frame(hdev, skb);
 		} else {
-			hci_recv_frame(skb);
+			hci_recv_frame(hdev, skb);
 		}
 
 		hdev->stat.byte_rx += buf_len;
@@ -616,12 +615,11 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
 
 	case MRVL_VENDOR_PKT:
 		bt_cb(skb)->pkt_type = HCI_VENDOR_PKT;
-		skb->dev = (void *)hdev;
 		skb_put(skb, buf_len);
 		skb_pull(skb, SDIO_HEADER_LEN);
 
 		if (btmrvl_process_event(priv, skb))
-			hci_recv_frame(skb);
+			hci_recv_frame(hdev, skb);
 
 		hdev->stat.byte_rx += buf_len;
 		break;
diff --git a/drivers/bluetooth/btsdio.c b/drivers/bluetooth/btsdio.c
index 4a99097..5df403d 100644
--- a/drivers/bluetooth/btsdio.c
+++ b/drivers/bluetooth/btsdio.c
@@ -157,10 +157,9 @@ static int btsdio_rx_packet(struct btsdio_data *data)
 
 	data->hdev->stat.byte_rx += len;
 
-	skb->dev = (void *) data->hdev;
 	bt_cb(skb)->pkt_type = hdr[3];
 
-	err = hci_recv_frame(skb);
+	err = hci_recv_frame(hdev, skb);
 	if (err < 0)
 		return err;
 
diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c
index 970e2d3..d0b89ec 100644
--- a/drivers/bluetooth/btuart_cs.c
+++ b/drivers/bluetooth/btuart_cs.c
@@ -198,7 +198,6 @@ static void btuart_receive(btuart_info_t *info)
 
 		if (info->rx_state == RECV_WAIT_PACKET_TYPE) {
 
-			info->rx_skb->dev = (void *) info->hdev;
 			bt_cb(info->rx_skb)->pkt_type = inb(iobase + UART_RX);
 
 			switch (bt_cb(info->rx_skb)->pkt_type) {
@@ -265,7 +264,7 @@ static void btuart_receive(btuart_info_t *info)
 					break;
 
 				case RECV_WAIT_DATA:
-					hci_recv_frame(info->rx_skb);
+					hci_recv_frame(info->hdev, info->rx_skb);
 					info->rx_skb = NULL;
 					break;
 
diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
index 60abf59..5e10fb0 100644
--- a/drivers/bluetooth/btwilink.c
+++ b/drivers/bluetooth/btwilink.c
@@ -108,10 +108,8 @@ static long st_receive(void *priv_data, struct sk_buff *skb)
 		return -EFAULT;
 	}
 
-	skb->dev = (void *) lhst->hdev;
-
 	/* Forward skb to HCI core layer */
-	err = hci_recv_frame(skb);
+	err = hci_recv_frame(lhst->hdev, skb);
 	if (err < 0) {
 		BT_ERR("Unable to push skb to HCI core(%d)", err);
 		return err;
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
index c43aff8..2945141 100644
--- a/drivers/bluetooth/dtl1_cs.c
+++ b/drivers/bluetooth/dtl1_cs.c
@@ -256,9 +256,8 @@ static void dtl1_receive(dtl1_info_t *info)
 				case 0x83:
 				case 0x84:
 					/* send frame to the HCI layer */
-					info->rx_skb->dev = (void *) info->hdev;
 					bt_cb(info->rx_skb)->pkt_type &= 0x0f;
-					hci_recv_frame(info->rx_skb);
+					hci_recv_frame(info->hdev, info->rx_skb);
 					break;
 				default:
 					/* unknown packet */
diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
index 57e502e..0bc87f7 100644
--- a/drivers/bluetooth/hci_bcsp.c
+++ b/drivers/bluetooth/hci_bcsp.c
@@ -522,7 +522,7 @@ static void bcsp_complete_rx_pkt(struct hci_uart *hu)
 				memcpy(skb_push(bcsp->rx_skb, HCI_EVENT_HDR_SIZE), &hdr, HCI_EVENT_HDR_SIZE);
 				bt_cb(bcsp->rx_skb)->pkt_type = HCI_EVENT_PKT;
 
-				hci_recv_frame(bcsp->rx_skb);
+				hci_recv_frame(hu->hdev, bcsp->rx_skb);
 			} else {
 				BT_ERR ("Packet for unknown channel (%u %s)",
 					bcsp->rx_skb->data[1] & 0x0f,
@@ -536,7 +536,7 @@ static void bcsp_complete_rx_pkt(struct hci_uart *hu)
 		/* Pull out BCSP hdr */
 		skb_pull(bcsp->rx_skb, 4);
 
-		hci_recv_frame(bcsp->rx_skb);
+		hci_recv_frame(hu->hdev, bcsp->rx_skb);
 	}
 
 	bcsp->rx_state = BCSP_W4_PKT_DELIMITER;
@@ -655,7 +655,6 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
 					bcsp->rx_count = 0;
 					return 0;
 				}
-				bcsp->rx_skb->dev = (void *) hu->hdev;
 				break;
 			}
 			break;
diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
index b6154d5..f6f4974 100644
--- a/drivers/bluetooth/hci_h5.c
+++ b/drivers/bluetooth/hci_h5.c
@@ -340,7 +340,7 @@ static void h5_complete_rx_pkt(struct hci_uart *hu)
 		/* Remove Three-wire header */
 		skb_pull(h5->rx_skb, 4);
 
-		hci_recv_frame(h5->rx_skb);
+		hci_recv_frame(hu->hdev, h5->rx_skb);
 		h5->rx_skb = NULL;
 
 		break;
diff --git a/drivers/bluetooth/hci_ll.c b/drivers/bluetooth/hci_ll.c
index cfc7679..58a9541 100644
--- a/drivers/bluetooth/hci_ll.c
+++ b/drivers/bluetooth/hci_ll.c
@@ -346,14 +346,14 @@ static int ll_enqueue(struct hci_uart *hu, struct sk_buff *skb)
 	return 0;
 }
 
-static inline int ll_check_data_len(struct ll_struct *ll, int len)
+static inline int ll_check_data_len(struct hci_dev *hdev, struct ll_struct *ll, int len)
 {
 	int room = skb_tailroom(ll->rx_skb);
 
 	BT_DBG("len %d room %d", len, room);
 
 	if (!len) {
-		hci_recv_frame(ll->rx_skb);
+		hci_recv_frame(hdev, ll->rx_skb);
 	} else if (len > room) {
 		BT_ERR("Data length is too large");
 		kfree_skb(ll->rx_skb);
@@ -395,7 +395,7 @@ static int ll_recv(struct hci_uart *hu, void *data, int count)
 			switch (ll->rx_state) {
 			case HCILL_W4_DATA:
 				BT_DBG("Complete data");
-				hci_recv_frame(ll->rx_skb);
+				hci_recv_frame(hu->hdev, ll->rx_skb);
 
 				ll->rx_state = HCILL_W4_PACKET_TYPE;
 				ll->rx_skb = NULL;
@@ -406,7 +406,7 @@ static int ll_recv(struct hci_uart *hu, void *data, int count)
 
 				BT_DBG("Event header: evt 0x%2.2x plen %d", eh->evt, eh->plen);
 
-				ll_check_data_len(ll, eh->plen);
+				ll_check_data_len(hu->hdev, ll, eh->plen);
 				continue;
 
 			case HCILL_W4_ACL_HDR:
@@ -415,7 +415,7 @@ static int ll_recv(struct hci_uart *hu, void *data, int count)
 
 				BT_DBG("ACL header: dlen %d", dlen);
 
-				ll_check_data_len(ll, dlen);
+				ll_check_data_len(hu->hdev, ll, dlen);
 				continue;
 
 			case HCILL_W4_SCO_HDR:
@@ -423,7 +423,7 @@ static int ll_recv(struct hci_uart *hu, void *data, int count)
 
 				BT_DBG("SCO header: dlen %d", sh->dlen);
 
-				ll_check_data_len(ll, sh->dlen);
+				ll_check_data_len(hu->hdev, ll, sh->dlen);
 				continue;
 			}
 		}
@@ -494,7 +494,6 @@ static int ll_recv(struct hci_uart *hu, void *data, int count)
 			return -ENOMEM;
 		}
 
-		ll->rx_skb->dev = (void *) hu->hdev;
 		bt_cb(ll->rx_skb)->pkt_type = type;
 	}
 
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index c04a3e6..0fd522e 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -179,10 +179,9 @@ static inline ssize_t vhci_get_user(struct vhci_data *data,
 			return -ENODEV;
 		}
 
-		skb->dev = (void *) data->hdev;
 		bt_cb(skb)->pkt_type = pkt_type;
 
-		ret = hci_recv_frame(skb);
+		ret = hci_recv_frame(data->hdev, skb);
 		break;
 
 	case HCI_VENDOR_PKT:
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 237bf8c..29b8147 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -755,7 +755,7 @@ int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
 
 void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
 
-int hci_recv_frame(struct sk_buff *skb);
+int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb);
 int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count);
 int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count);
 
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 6cc2f86..4f0d4b4 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2485,9 +2485,8 @@ int hci_resume_dev(struct hci_dev *hdev)
 EXPORT_SYMBOL(hci_resume_dev);
 
 /* Receive frame from HCI drivers */
-int hci_recv_frame(struct sk_buff *skb)
+int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb)
 {
-	struct hci_dev *hdev = (struct hci_dev *) skb->dev;
 	if (!hdev || (!test_bit(HCI_UP, &hdev->flags)
 		      && !test_bit(HCI_INIT, &hdev->flags))) {
 		kfree_skb(skb);
@@ -2546,7 +2545,6 @@ static int hci_reassembly(struct hci_dev *hdev, int type, void *data,
 		scb->expect = hlen;
 		scb->pkt_type = type;
 
-		skb->dev = (void *) hdev;
 		hdev->reassembly[index] = skb;
 	}
 
@@ -2606,7 +2604,7 @@ static int hci_reassembly(struct hci_dev *hdev, int type, void *data,
 			/* Complete frame */
 
 			bt_cb(skb)->pkt_type = type;
-			hci_recv_frame(skb);
+			hci_recv_frame(hdev, skb);
 
 			hdev->reassembly[index] = NULL;
 			return remain;
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH 1/2] Bluetooth: Remove unused h4_check_data_len() function
From: Marcel Holtmann @ 2013-10-10 23:52 UTC (permalink / raw)
  To: linux-bluetooth

The function h4_check_data_len() is actually not used. So just
remove it.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 drivers/bluetooth/hci_h4.c | 24 ------------------------
 1 file changed, 24 deletions(-)

diff --git a/drivers/bluetooth/hci_h4.c b/drivers/bluetooth/hci_h4.c
index 8ae9f1e..7048a58 100644
--- a/drivers/bluetooth/hci_h4.c
+++ b/drivers/bluetooth/hci_h4.c
@@ -124,30 +124,6 @@ static int h4_enqueue(struct hci_uart *hu, struct sk_buff *skb)
 	return 0;
 }
 
-static inline int h4_check_data_len(struct h4_struct *h4, int len)
-{
-	int room = skb_tailroom(h4->rx_skb);
-
-	BT_DBG("len %d room %d", len, room);
-
-	if (!len) {
-		hci_recv_frame(h4->rx_skb);
-	} else if (len > room) {
-		BT_ERR("Data length is too large");
-		kfree_skb(h4->rx_skb);
-	} else {
-		h4->rx_state = H4_W4_DATA;
-		h4->rx_count = len;
-		return len;
-	}
-
-	h4->rx_state = H4_W4_PACKET_TYPE;
-	h4->rx_skb   = NULL;
-	h4->rx_count = 0;
-
-	return 0;
-}
-
 /* Recv data */
 static int h4_recv(struct hci_uart *hu, void *data, int count)
 {
-- 
1.8.3.1


^ permalink raw reply related

* Re: [PATCH] Bluetooth: Remote return value from hci_send_frame() function
From: Johan Hedberg @ 2013-10-10 22:21 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1381437360-55235-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Thu, Oct 10, 2013, Marcel Holtmann wrote:
> The return value of hci_send_frame() is never checked. So just make
> this function void and print an error when the hdev->send driver
> callback returns a negative value.
> 
> Having the error printed is actually an improvement over the
> current situation where any driver error just gets ignored.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  net/bluetooth/hci_core.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH] Bluetooth: Remove pointless check of hci_send_frame parameter
From: Johan Hedberg @ 2013-10-10 22:21 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1381436997-51094-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Thu, Oct 10, 2013, Marcel Holtmann wrote:
> The hdev parameter of hci_send_frame must be always valid. If the hdev
> is not valid, it would not even make it to this stage. The callers
> will have already accessed hdev at that point many times.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  net/bluetooth/hci_core.c | 5 -----
>  1 file changed, 5 deletions(-)

Applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH] Bluetooth: Move skb->dev assignment for hdev->send into central place
From: Johan Hedberg @ 2013-10-10 22:21 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1381436787-50948-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Thu, Oct 10, 2013, Marcel Holtmann wrote:
> The assignement of skb->dev is done all over the place. So it makes it
> hard to eventually get rid of it. Move it all in one central place so
> it gets assigned right before calling hdev->send driver callback.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  net/bluetooth/hci_core.c | 25 ++++++++++---------------
>  net/bluetooth/hci_sock.c |  2 --
>  2 files changed, 10 insertions(+), 17 deletions(-)

Applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH 1/3] Bluetooth: Move amp.h header file into net/bluetooth/
From: Johan Hedberg @ 2013-10-10 22:21 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1381434976-36296-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Thu, Oct 10, 2013, Marcel Holtmann wrote:
> The amp.h header file is only used internally by the bluetooth.ko
> module and is not a public API. So make it local to the core
> Bluetooth module.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  include/net/bluetooth/amp.h | 54 ---------------------------------------------
>  net/bluetooth/a2mp.c        |  3 ++-
>  net/bluetooth/amp.c         |  3 ++-
>  net/bluetooth/amp.h         | 54 +++++++++++++++++++++++++++++++++++++++++++++
>  net/bluetooth/hci_event.c   |  3 ++-
>  net/bluetooth/l2cap_core.c  |  3 ++-
>  6 files changed, 62 insertions(+), 58 deletions(-)
>  delete mode 100644 include/net/bluetooth/amp.h
>  create mode 100644 net/bluetooth/amp.h

All three patches in this set have been applied to bluetooth-next.

Johan

^ permalink raw reply

* Re: [PATCH v2] Don't register Device ID record on sdp server start
From: Johan Hedberg @ 2013-10-10 20:38 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1381397929-7817-1-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Thu, Oct 10, 2013, Szymon Janc wrote:
> This makes SDP code no longer depends on main_opts. DID record is now
> registered from main() after sdp server was started. This is OK since
> mainloop is not yet running and record will be present when first
> request comes.
> ---
> 
> v2 - commit message improved
> 
>  src/main.c        | 4 ++++
>  src/sdpd-server.c | 5 -----
>  2 files changed, 4 insertions(+), 5 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH 1/6] avdtp: Fix typos in errors from avdtp_strerror
From: Johan Hedberg @ 2013-10-10 20:37 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1381395221-5067-1-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Thu, Oct 10, 2013, Szymon Janc wrote:
> ---
>  profiles/audio/avdtp.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

All six patches have been applied. Thanks.

Johan

^ permalink raw reply

* [PATCH] Bluetooth: Remote return value from hci_send_frame() function
From: Marcel Holtmann @ 2013-10-10 20:36 UTC (permalink / raw)
  To: linux-bluetooth

The return value of hci_send_frame() is never checked. So just make
this function void and print an error when the hdev->send driver
callback returns a negative value.

Having the error printed is actually an improvement over the
current situation where any driver error just gets ignored.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/hci_core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 47cf3a9..6cc2f86 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2697,7 +2697,7 @@ int hci_unregister_cb(struct hci_cb *cb)
 }
 EXPORT_SYMBOL(hci_unregister_cb);
 
-static int hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
+static void hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	BT_DBG("%s type %d len %d", hdev->name, bt_cb(skb)->pkt_type, skb->len);
 
@@ -2717,7 +2717,8 @@ static int hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
 
 	skb->dev = (void *) hdev;
 
-	return hdev->send(skb);
+	if (hdev->send(skb) < 0)
+		BT_ERR("%s sending frame failed", hdev->name);
 }
 
 void hci_req_init(struct hci_request *req, struct hci_dev *hdev)
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH] Bluetooth: Remove pointless check of hci_send_frame parameter
From: Marcel Holtmann @ 2013-10-10 20:29 UTC (permalink / raw)
  To: linux-bluetooth

The hdev parameter of hci_send_frame must be always valid. If the hdev
is not valid, it would not even make it to this stage. The callers
will have already accessed hdev at that point many times.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/hci_core.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 925bd47..47cf3a9 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2699,11 +2699,6 @@ EXPORT_SYMBOL(hci_unregister_cb);
 
 static int hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
 {
-	if (!hdev) {
-		kfree_skb(skb);
-		return -ENODEV;
-	}
-
 	BT_DBG("%s type %d len %d", hdev->name, bt_cb(skb)->pkt_type, skb->len);
 
 	/* Time stamp */
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH] Bluetooth: Move skb->dev assignment for hdev->send into central place
From: Marcel Holtmann @ 2013-10-10 20:26 UTC (permalink / raw)
  To: linux-bluetooth

The assignement of skb->dev is done all over the place. So it makes it
hard to eventually get rid of it. Move it all in one central place so
it gets assigned right before calling hdev->send driver callback.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/hci_core.c | 25 ++++++++++---------------
 net/bluetooth/hci_sock.c |  2 --
 2 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 593b4ef..925bd47 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2697,10 +2697,8 @@ int hci_unregister_cb(struct hci_cb *cb)
 }
 EXPORT_SYMBOL(hci_unregister_cb);
 
-static int hci_send_frame(struct sk_buff *skb)
+static int hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
 {
-	struct hci_dev *hdev = (struct hci_dev *) skb->dev;
-
 	if (!hdev) {
 		kfree_skb(skb);
 		return -ENODEV;
@@ -2722,6 +2720,8 @@ static int hci_send_frame(struct sk_buff *skb)
 	/* Get rid of skb owner, prior to sending to the driver. */
 	skb_orphan(skb);
 
+	skb->dev = (void *) hdev;
+
 	return hdev->send(skb);
 }
 
@@ -2785,7 +2785,6 @@ static struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode,
 	BT_DBG("skb len %d", skb->len);
 
 	bt_cb(skb)->pkt_type = HCI_COMMAND_PKT;
-	skb->dev = (void *) hdev;
 
 	return skb;
 }
@@ -2929,7 +2928,6 @@ static void hci_queue_acl(struct hci_chan *chan, struct sk_buff_head *queue,
 		do {
 			skb = list; list = list->next;
 
-			skb->dev = (void *) hdev;
 			bt_cb(skb)->pkt_type = HCI_ACLDATA_PKT;
 			hci_add_acl_hdr(skb, conn->handle, flags);
 
@@ -2948,8 +2946,6 @@ void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags)
 
 	BT_DBG("%s chan %p flags 0x%4.4x", hdev->name, chan, flags);
 
-	skb->dev = (void *) hdev;
-
 	hci_queue_acl(chan, &chan->data_q, skb, flags);
 
 	queue_work(hdev->workqueue, &hdev->tx_work);
@@ -2970,7 +2966,6 @@ void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb)
 	skb_reset_transport_header(skb);
 	memcpy(skb_transport_header(skb), &hdr, HCI_SCO_HDR_SIZE);
 
-	skb->dev = (void *) hdev;
 	bt_cb(skb)->pkt_type = HCI_SCODATA_PKT;
 
 	skb_queue_tail(&conn->data_q, skb);
@@ -3235,7 +3230,7 @@ static void hci_sched_acl_pkt(struct hci_dev *hdev)
 			hci_conn_enter_active_mode(chan->conn,
 						   bt_cb(skb)->force_active);
 
-			hci_send_frame(skb);
+			hci_send_frame(hdev, skb);
 			hdev->acl_last_tx = jiffies;
 
 			hdev->acl_cnt--;
@@ -3287,7 +3282,7 @@ static void hci_sched_acl_blk(struct hci_dev *hdev)
 			hci_conn_enter_active_mode(chan->conn,
 						   bt_cb(skb)->force_active);
 
-			hci_send_frame(skb);
+			hci_send_frame(hdev, skb);
 			hdev->acl_last_tx = jiffies;
 
 			hdev->block_cnt -= blocks;
@@ -3340,7 +3335,7 @@ static void hci_sched_sco(struct hci_dev *hdev)
 	while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, &quote))) {
 		while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
 			BT_DBG("skb %p len %d", skb, skb->len);
-			hci_send_frame(skb);
+			hci_send_frame(hdev, skb);
 
 			conn->sent++;
 			if (conn->sent == ~0)
@@ -3364,7 +3359,7 @@ static void hci_sched_esco(struct hci_dev *hdev)
 						     &quote))) {
 		while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
 			BT_DBG("skb %p len %d", skb, skb->len);
-			hci_send_frame(skb);
+			hci_send_frame(hdev, skb);
 
 			conn->sent++;
 			if (conn->sent == ~0)
@@ -3406,7 +3401,7 @@ static void hci_sched_le(struct hci_dev *hdev)
 
 			skb = skb_dequeue(&chan->data_q);
 
-			hci_send_frame(skb);
+			hci_send_frame(hdev, skb);
 			hdev->le_last_tx = jiffies;
 
 			cnt--;
@@ -3442,7 +3437,7 @@ static void hci_tx_work(struct work_struct *work)
 
 	/* Send next queued raw (unknown type) packet */
 	while ((skb = skb_dequeue(&hdev->raw_q)))
-		hci_send_frame(skb);
+		hci_send_frame(hdev, skb);
 }
 
 /* ----- HCI RX task (incoming data processing) ----- */
@@ -3688,7 +3683,7 @@ static void hci_cmd_work(struct work_struct *work)
 		hdev->sent_cmd = skb_clone(skb, GFP_KERNEL);
 		if (hdev->sent_cmd) {
 			atomic_dec(&hdev->cmd_cnt);
-			hci_send_frame(skb);
+			hci_send_frame(hdev, skb);
 			if (test_bit(HCI_RESET, &hdev->flags))
 				del_timer(&hdev->cmd_timer);
 			else
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 3beaa05..97f96eb 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -387,7 +387,6 @@ static void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data)
 	__net_timestamp(skb);
 
 	bt_cb(skb)->pkt_type = HCI_EVENT_PKT;
-	skb->dev = (void *) hdev;
 	hci_send_to_sock(hdev, skb);
 	kfree_skb(skb);
 }
@@ -942,7 +941,6 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
 
 	bt_cb(skb)->pkt_type = *((unsigned char *) skb->data);
 	skb_pull(skb, 1);
-	skb->dev = (void *) hdev;
 
 	if (hci_pi(sk)->channel == HCI_CHANNEL_RAW &&
 	    bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) {
-- 
1.8.3.1


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox