Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 2/4] android/client: Add code for handsfree callbacks
From: Jerzy Kasenberg @ 2013-10-28 11:39 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jerzy Kasenberg
In-Reply-To: <1382960343-10765-1-git-send-email-jerzy.kasenberg@tieto.com>

This adds implementation for handsfree callbacks.
---
 android/client/if-hf.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/android/client/if-hf.c b/android/client/if-hf.c
index e4065df..43c7f47 100644
--- a/android/client/if-hf.c
+++ b/android/client/if-hf.c
@@ -106,6 +106,8 @@ ENDMAP
 
 /* Callbacks */
 
+static char last_addr[MAX_ADDR_STR_LEN];
+
 /*
  * Callback for connection state change.
  * state will have one of the values from BtHfConnectionState
@@ -113,6 +115,9 @@ ENDMAP
 static void connection_state_cb(bthf_connection_state_t state,
 							bt_bdaddr_t *bd_addr)
 {
+	haltest_info("%s: state=%s bd_addr=%s\n", __func__,
+					bthf_connection_state_t2str(state),
+					bt_bdaddr_t2str(bd_addr, last_addr));
 }
 
 /*
@@ -121,6 +126,9 @@ static void connection_state_cb(bthf_connection_state_t state,
  */
 static void audio_state_cb(bthf_audio_state_t state, bt_bdaddr_t *bd_addr)
 {
+	haltest_info("%s: state=%s bd_addr=%s\n", __func__,
+					bthf_audio_state_t2str(state),
+					bt_bdaddr_t2str(bd_addr, last_addr));
 }
 
 /*
@@ -129,16 +137,19 @@ static void audio_state_cb(bthf_audio_state_t state, bt_bdaddr_t *bd_addr)
  */
 static void vr_cmd_cb(bthf_vr_state_t state)
 {
+	haltest_info("%s: state=%s\n", __func__, bthf_vr_state_t2str(state));
 }
 
 /* Callback for answer incoming call (ATA) */
 static void answer_call_cmd_cb(void)
 {
+	haltest_info("%s\n", __func__);
 }
 
 /* Callback for disconnect call (AT+CHUP) */
 static void hangup_call_cmd_cb(void)
 {
+	haltest_info("%s\n", __func__);
 }
 
 /*
@@ -147,6 +158,8 @@ static void hangup_call_cmd_cb(void)
  */
 static void volume_cmd_cb(bthf_volume_type_t type, int volume)
 {
+	haltest_info("%s: type=%s volume=%d\n", __func__,
+					bthf_volume_type_t2str(type), volume);
 }
 
 /*
@@ -155,6 +168,7 @@ static void volume_cmd_cb(bthf_volume_type_t type, int volume)
  */
 static void dial_call_cmd_cb(char *number)
 {
+	haltest_info("%s: number=%s\n", __func__, number);
 }
 
 /*
@@ -163,6 +177,7 @@ static void dial_call_cmd_cb(char *number)
  */
 static void dtmf_cmd_cb(char tone)
 {
+	haltest_info("%s: tone=%d\n", __func__, tone);
 }
 
 /*
@@ -171,6 +186,7 @@ static void dtmf_cmd_cb(char tone)
  */
 static void nrec_cmd_cb(bthf_nrec_t nrec)
 {
+	haltest_info("%s: nrec=%s\n", __func__, bthf_nrec_t2str(nrec));
 }
 
 /*
@@ -179,26 +195,31 @@ static void nrec_cmd_cb(bthf_nrec_t nrec)
  */
 static void chld_cmd_cb(bthf_chld_type_t chld)
 {
+	haltest_info("%s: chld=%s\n", __func__, bthf_chld_type_t2str(chld));
 }
 
 /* Callback for CNUM (subscriber number) */
 static void cnum_cmd_cb(void)
 {
+	haltest_info("%s\n", __func__);
 }
 
 /* Callback for indicators (CIND) */
 static void cind_cmd_cb(void)
 {
+	haltest_info("%s\n", __func__);
 }
 
 /* Callback for operator selection (COPS) */
 static void cops_cmd_cb(void)
 {
+	haltest_info("%s\n", __func__);
 }
 
 /* Callback for call list (AT+CLCC) */
 static void clcc_cmd_cb(void)
 {
+	haltest_info("%s\n", __func__);
 }
 
 /*
@@ -207,11 +228,13 @@ static void clcc_cmd_cb(void)
  */
 static void unknown_at_cmd_cb(char *at_string)
 {
+	haltest_info("%s: at_string=%s\n", __func__, at_string);
 }
 
 /* Callback for keypressed (HSP) event. */
 static void key_pressed_cmd_cb(void)
 {
+	haltest_info("%s\n", __func__);
 }
 
 static bthf_callbacks_t hf_cbacks = {
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 1/4] android/client: Add skeleton for handsfree calls
From: Jerzy Kasenberg @ 2013-10-28 11:39 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jerzy Kasenberg
In-Reply-To: <1382960343-10765-1-git-send-email-jerzy.kasenberg@tieto.com>

This patch adds skeleton for all methods of handsfree along with
all callbacks.
---
 Makefile.android         |    2 +
 android/Android.mk       |    1 +
 android/client/haltest.c |    1 +
 android/client/if-bt.c   |    2 +-
 android/client/if-hf.c   |  368 ++++++++++++++++++++++++++++++++++++++++++++++
 android/client/if-main.h |    2 +
 6 files changed, 375 insertions(+), 1 deletion(-)
 create mode 100644 android/client/if-hf.c

diff --git a/Makefile.android b/Makefile.android
index 01b3cea..fd8043c 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -51,6 +51,7 @@ android_haltest_SOURCES = android/client/haltest.c \
 				android/client/tabcompletion.c \
 				android/client/if-av.c \
 				android/client/if-bt.c \
+				android/client/if-hf.c \
 				android/client/if-hh.c \
 				android/client/if-pan.c \
 				android/client/if-sock.c \
@@ -81,6 +82,7 @@ EXTRA_DIST += android/client/terminal.c \
 		android/client/history.c \
 		android/client/if-av.c \
 		android/client/if-bt.c \
+		android/client/if-hf.c \
 		android/client/if-hh.c \
 		android/client/if-pan.c \
 		android/client/if-sock.c \
diff --git a/android/Android.mk b/android/Android.mk
index 56c43cb..22208e0 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -104,6 +104,7 @@ LOCAL_SRC_FILES := \
 	client/tabcompletion.c \
 	client/if-av.c \
 	client/if-bt.c \
+	client/if-hf.c \
 	client/if-hh.c \
 	client/if-pan.c \
 	client/if-sock.c \
diff --git a/android/client/haltest.c b/android/client/haltest.c
index 6b4030b..7fe0436 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -32,6 +32,7 @@
 const struct interface *interfaces[] = {
 	&bluetooth_if,
 	&av_if,
+	&hf_if,
 	&hh_if,
 	&pan_if,
 	&sock_if,
diff --git a/android/client/if-bt.c b/android/client/if-bt.c
index dd5d12e..a20a7c6 100644
--- a/android/client/if-bt.c
+++ b/android/client/if-bt.c
@@ -811,7 +811,7 @@ static void get_profile_interface_p(int argc, const char **argv)
 	RETURN_IF_NULL(if_bluetooth);
 
 	if (strcmp(BT_PROFILE_HANDSFREE_ID, id) == 0)
-		pif = &dummy; /* TODO: change when if_hf is there */
+		pif = (const void **) &if_hf;
 	else if (strcmp(BT_PROFILE_ADVANCED_AUDIO_ID, id) == 0)
 		pif = (const void **) &if_av;
 	else if (strcmp(BT_PROFILE_HEALTH_ID, id) == 0)
diff --git a/android/client/if-hf.c b/android/client/if-hf.c
new file mode 100644
index 0000000..e4065df
--- /dev/null
+++ b/android/client/if-hf.c
@@ -0,0 +1,368 @@
+/*
+ * 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 "if-main.h"
+
+const bthf_interface_t *if_hf = NULL;
+
+SINTMAP(bthf_at_response_t, -1, "(unknown)")
+	DELEMENT(BTHF_AT_RESPONSE_ERROR),
+	DELEMENT(BTHF_AT_RESPONSE_OK),
+ENDMAP
+
+SINTMAP(bthf_connection_state_t, -1, "(unknown)")
+	DELEMENT(BTHF_CONNECTION_STATE_DISCONNECTED),
+	DELEMENT(BTHF_CONNECTION_STATE_CONNECTING),
+	DELEMENT(BTHF_CONNECTION_STATE_CONNECTED),
+	DELEMENT(BTHF_CONNECTION_STATE_SLC_CONNECTED),
+	DELEMENT(BTHF_CONNECTION_STATE_DISCONNECTING),
+ENDMAP
+
+SINTMAP(bthf_audio_state_t, -1, "(unknown)")
+	DELEMENT(BTHF_AUDIO_STATE_DISCONNECTED),
+	DELEMENT(BTHF_AUDIO_STATE_CONNECTING),
+	DELEMENT(BTHF_AUDIO_STATE_CONNECTED),
+	DELEMENT(BTHF_AUDIO_STATE_DISCONNECTING),
+ENDMAP
+
+SINTMAP(bthf_vr_state_t, -1, "(unknown)")
+	DELEMENT(BTHF_VR_STATE_STOPPED),
+	DELEMENT(BTHF_VR_STATE_STARTED),
+ENDMAP
+
+SINTMAP(bthf_volume_type_t, -1, "(unknown)")
+	DELEMENT(BTHF_VOLUME_TYPE_SPK),
+	DELEMENT(BTHF_VOLUME_TYPE_MIC),
+ENDMAP
+
+SINTMAP(bthf_nrec_t, -1, "(unknown)")
+	DELEMENT(BTHF_NREC_STOP),
+	DELEMENT(BTHF_NREC_START),
+ENDMAP
+
+SINTMAP(bthf_chld_type_t, -1, "(unknown)")
+	DELEMENT(BTHF_CHLD_TYPE_RELEASEHELD),
+	DELEMENT(BTHF_CHLD_TYPE_RELEASEACTIVE_ACCEPTHELD),
+	DELEMENT(BTHF_CHLD_TYPE_HOLDACTIVE_ACCEPTHELD),
+	DELEMENT(BTHF_CHLD_TYPE_ADDHELDTOCONF),
+ENDMAP
+
+/* Network Status */
+SINTMAP(bthf_network_state_t, -1, "(unknown)")
+	DELEMENT(BTHF_NETWORK_STATE_NOT_AVAILABLE),
+	DELEMENT(BTHF_NETWORK_STATE_AVAILABLE),
+ENDMAP
+
+/* Service type */
+SINTMAP(bthf_service_type_t, -1, "(unknown)")
+	DELEMENT(BTHF_SERVICE_TYPE_HOME),
+	DELEMENT(BTHF_SERVICE_TYPE_ROAMING),
+ENDMAP
+
+SINTMAP(bthf_call_state_t, -1, "(unknown)")
+	DELEMENT(BTHF_CALL_STATE_ACTIVE),
+	DELEMENT(BTHF_CALL_STATE_HELD),
+	DELEMENT(BTHF_CALL_STATE_DIALING),
+	DELEMENT(BTHF_CALL_STATE_ALERTING),
+	DELEMENT(BTHF_CALL_STATE_INCOMING),
+	DELEMENT(BTHF_CALL_STATE_WAITING),
+	DELEMENT(BTHF_CALL_STATE_IDLE),
+ENDMAP
+
+SINTMAP(bthf_call_direction_t, -1, "(unknown)")
+	DELEMENT(BTHF_CALL_DIRECTION_OUTGOING),
+	DELEMENT(BTHF_CALL_DIRECTION_INCOMING),
+ENDMAP
+
+SINTMAP(bthf_call_mode_t, -1, "(unknown)")
+	DELEMENT(BTHF_CALL_TYPE_VOICE),
+	DELEMENT(BTHF_CALL_TYPE_DATA),
+	DELEMENT(BTHF_CALL_TYPE_FAX),
+ENDMAP
+
+SINTMAP(bthf_call_mpty_type_t, -1, "(unknown)")
+	DELEMENT(BTHF_CALL_MPTY_TYPE_SINGLE),
+	DELEMENT(BTHF_CALL_MPTY_TYPE_MULTI),
+ENDMAP
+
+SINTMAP(bthf_call_addrtype_t, -1, "(unknown)")
+	DELEMENT(BTHF_CALL_ADDRTYPE_UNKNOWN),
+	DELEMENT(BTHF_CALL_ADDRTYPE_INTERNATIONAL),
+ENDMAP
+
+/* Callbacks */
+
+/*
+ * Callback for connection state change.
+ * state will have one of the values from BtHfConnectionState
+ */
+static void connection_state_cb(bthf_connection_state_t state,
+							bt_bdaddr_t *bd_addr)
+{
+}
+
+/*
+ * Callback for audio connection state change.
+ * state will have one of the values from BtHfAudioState
+ */
+static void audio_state_cb(bthf_audio_state_t state, bt_bdaddr_t *bd_addr)
+{
+}
+
+/*
+ * Callback for VR connection state change.
+ * state will have one of the values from BtHfVRState
+ */
+static void vr_cmd_cb(bthf_vr_state_t state)
+{
+}
+
+/* Callback for answer incoming call (ATA) */
+static void answer_call_cmd_cb(void)
+{
+}
+
+/* Callback for disconnect call (AT+CHUP) */
+static void hangup_call_cmd_cb(void)
+{
+}
+
+/*
+ * Callback for disconnect call (AT+CHUP)
+ * type will denote Speaker/Mic gain (BtHfVolumeControl).
+ */
+static void volume_cmd_cb(bthf_volume_type_t type, int volume)
+{
+}
+
+/*
+ * Callback for dialing an outgoing call
+ * If number is NULL, redial
+ */
+static void dial_call_cmd_cb(char *number)
+{
+}
+
+/*
+ * Callback for sending DTMF tones
+ * tone contains the dtmf character to be sent
+ */
+static void dtmf_cmd_cb(char tone)
+{
+}
+
+/*
+ * Callback for enabling/disabling noise reduction/echo cancellation
+ * value will be 1 to enable, 0 to disable
+ */
+static void nrec_cmd_cb(bthf_nrec_t nrec)
+{
+}
+
+/*
+ * Callback for call hold handling (AT+CHLD)
+ * value will contain the call hold command (0, 1, 2, 3)
+ */
+static void chld_cmd_cb(bthf_chld_type_t chld)
+{
+}
+
+/* Callback for CNUM (subscriber number) */
+static void cnum_cmd_cb(void)
+{
+}
+
+/* Callback for indicators (CIND) */
+static void cind_cmd_cb(void)
+{
+}
+
+/* Callback for operator selection (COPS) */
+static void cops_cmd_cb(void)
+{
+}
+
+/* Callback for call list (AT+CLCC) */
+static void clcc_cmd_cb(void)
+{
+}
+
+/*
+ * Callback for unknown AT command recd from HF
+ * at_string will contain the unparsed AT string
+ */
+static void unknown_at_cmd_cb(char *at_string)
+{
+}
+
+/* Callback for keypressed (HSP) event. */
+static void key_pressed_cmd_cb(void)
+{
+}
+
+static bthf_callbacks_t hf_cbacks = {
+
+	.size = sizeof(hf_cbacks),
+	.connection_state_cb = connection_state_cb,
+	.audio_state_cb = audio_state_cb,
+	.vr_cmd_cb = vr_cmd_cb,
+	.answer_call_cmd_cb = answer_call_cmd_cb,
+	.hangup_call_cmd_cb = hangup_call_cmd_cb,
+	.volume_cmd_cb = volume_cmd_cb,
+	.dial_call_cmd_cb = dial_call_cmd_cb,
+	.dtmf_cmd_cb = dtmf_cmd_cb,
+	.nrec_cmd_cb = nrec_cmd_cb,
+	.chld_cmd_cb = chld_cmd_cb,
+	.cnum_cmd_cb = cnum_cmd_cb,
+	.cind_cmd_cb = cind_cmd_cb,
+	.cops_cmd_cb = cops_cmd_cb,
+	.clcc_cmd_cb = clcc_cmd_cb,
+	.unknown_at_cmd_cb = unknown_at_cmd_cb,
+	.key_pressed_cmd_cb = key_pressed_cmd_cb,
+};
+
+/* init */
+
+static void init_p(int argc, const char **argv)
+{
+	RETURN_IF_NULL(if_hf);
+
+	EXEC(if_hf->init, &hf_cbacks);
+}
+
+/* connect */
+
+
+static void connect_p(int argc, const char **argv)
+{
+}
+
+/* disconnect */
+
+static void disconnect_p(int argc, const char **argv)
+{
+}
+
+/* create an audio connection */
+
+static void connect_audio_p(int argc, const char **argv)
+{
+}
+
+/* close the audio connection */
+
+static void disconnect_audio_p(int argc, const char **argv)
+{
+}
+
+/* start voice recognition */
+
+static void start_voice_recognition_p(int argc, const char **argv)
+{
+}
+
+/* stop voice recognition */
+
+static void stop_voice_recognition_p(int argc, const char **argv)
+{
+}
+
+/* volume control */
+
+static void volume_control_p(int argc, const char **argv)
+{
+}
+
+/* Combined device status change notification */
+
+static void device_status_notification_p(int argc, const char **argv)
+{
+}
+
+/* Response for COPS command */
+
+static void cops_response_p(int argc, const char **argv)
+{
+}
+
+/* Response for CIND command */
+
+static void cind_response_p(int argc, const char **argv)
+{
+}
+
+/* Pre-formatted AT response, typically in response to unknown AT cmd */
+
+static void formatted_at_response_p(int argc, const char **argv)
+{
+}
+
+/* at_response */
+
+static void at_response_p(int argc, const char **argv)
+{
+}
+
+/* response for CLCC command */
+
+static void clcc_response_p(int argc, const char **argv)
+{
+}
+
+/* phone state change */
+static void phone_state_change_p(int argc, const char **argv)
+{
+}
+
+/* cleanup */
+
+static void cleanup_p(int argc, const char **argv)
+{
+	RETURN_IF_NULL(if_hf);
+
+	EXECV(if_hf->cleanup);
+	if_hf = NULL;
+}
+
+static struct method methods[] = {
+	STD_METHOD(init),
+	STD_METHODH(connect, "<addr>"),
+	STD_METHODH(disconnect, "<addr>"),
+	STD_METHODH(connect_audio, "<addr>"),
+	STD_METHODH(disconnect_audio, "<addr>"),
+	STD_METHOD(start_voice_recognition),
+	STD_METHOD(stop_voice_recognition),
+	STD_METHODH(volume_control, "<vol_type> <volume>"),
+	STD_METHODH(device_status_notification,
+			"<ntk_state> <svt_type> <signal> <batt_chg>"),
+	STD_METHODH(cops_response, "<cops string>"),
+	STD_METHODH(cind_response,
+			"<svc> <num_active> <num_held> <setup_state> <signal> <roam> <batt_chg>"),
+	STD_METHODH(formatted_at_response, "<at_response>"),
+	STD_METHODH(at_response, "<response_code> [<error_code>]"),
+	STD_METHODH(clcc_response,
+			"<index> <direction> <state> <mode> <mpty> <number> <type>"),
+	STD_METHODH(phone_state_change,
+			"<num_active> <num_held> <setup_state> <number> <type>"),
+	STD_METHOD(cleanup),
+	END_METHOD
+};
+
+const struct interface hf_if = {
+	.name = "handsfree",
+	.methods = methods
+};
diff --git a/android/client/if-main.h b/android/client/if-main.h
index eaee914..37086dd 100644
--- a/android/client/if-main.h
+++ b/android/client/if-main.h
@@ -45,6 +45,7 @@
 /* Interfaces from hal that can be populated during application lifetime */
 extern const bt_interface_t *if_bluetooth;
 extern const btav_interface_t *if_av;
+extern const bthf_interface_t *if_hf;
 extern const bthh_interface_t *if_hh;
 extern const btpan_interface_t *if_pan;
 extern const btsock_interface_t *if_sock;
@@ -62,6 +63,7 @@ extern const struct interface bluetooth_if;
 extern const struct interface av_if;
 extern const struct interface pan_if;
 extern const struct interface sock_if;
+extern const struct interface hf_if;
 extern const struct interface hh_if;
 
 /* Interfaces that will show up in tool (first part of command line) */
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 0/4] Add handsfree interface methods to haltest
From: Jerzy Kasenberg @ 2013-10-28 11:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jerzy Kasenberg

With this patchset handsfree interface is available in haltest.

Jerzy Kasenberg (4):
  android/client: Add skeleton for handsfree calls
  android/client: Add code for handsfree callbacks
  android/client: Add code for handsfree methods
  android/client: Add completion for hf methods

 Makefile.android         |    2 +
 android/Android.mk       |    1 +
 android/client/haltest.c |    1 +
 android/client/if-bt.c   |    2 +-
 android/client/if-hf.c   |  784 ++++++++++++++++++++++++++++++++++++++++++++++
 android/client/if-main.h |    2 +
 6 files changed, 791 insertions(+), 1 deletion(-)
 create mode 100644 android/client/if-hf.c

-- 
1.7.9.5


^ permalink raw reply

* [PATCHv1 4/4] android/hal: Add extra logs
From: Andrei Emeltchenko @ 2013-10-28 10:44 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1382957047-31775-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

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

Add extra log prints for printing properties and bluetooth addresses.
---
 android/hal-bluetooth.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index da96202..81e23cb 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -251,7 +251,7 @@ static int set_adapter_property(const bt_property_t *property)
 
 static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
 {
-	DBG("");
+	DBG("bdaddr: %s", bdaddr2str(remote_addr));
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
@@ -262,7 +262,8 @@ static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
 static int get_remote_device_property(bt_bdaddr_t *remote_addr,
 						bt_property_type_t type)
 {
-	DBG("");
+	DBG("bdaddr: %s prop: %s", bdaddr2str(remote_addr),
+						bt_property_type_t2str(type));
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
@@ -273,7 +274,8 @@ static int get_remote_device_property(bt_bdaddr_t *remote_addr,
 static int set_remote_device_property(bt_bdaddr_t *remote_addr,
 						const bt_property_t *property)
 {
-	DBG("");
+	DBG("bdaddr: %s prop: %s", bdaddr2str(remote_addr),
+						btproperty2str(property));
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
@@ -283,7 +285,7 @@ static int set_remote_device_property(bt_bdaddr_t *remote_addr,
 
 static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
 {
-	DBG("");
+	DBG("bdaddr: %s", bdaddr2str(remote_addr));
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
@@ -293,7 +295,7 @@ static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
 
 static int get_remote_services(bt_bdaddr_t *remote_addr)
 {
-	DBG("");
+	DBG("bdaddr: %s", bdaddr2str(remote_addr));
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
@@ -325,7 +327,7 @@ static int create_bond(const bt_bdaddr_t *bd_addr)
 {
 	struct hal_cmd_create_bond cmd;
 
-	DBG("");
+	DBG("bdaddr: %s", bdaddr2str(bd_addr));
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
@@ -340,7 +342,7 @@ static int cancel_bond(const bt_bdaddr_t *bd_addr)
 {
 	struct hal_cmd_cancel_bond cmd;
 
-	DBG("");
+	DBG("bdaddr: %s", bdaddr2str(bd_addr));
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
@@ -355,7 +357,7 @@ static int remove_bond(const bt_bdaddr_t *bd_addr)
 {
 	struct hal_cmd_remove_bond cmd;
 
-	DBG("");
+	DBG("bdaddr: %s", bdaddr2str(bd_addr));
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
@@ -371,7 +373,7 @@ static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
 {
 	struct hal_cmd_pin_reply cmd;
 
-	DBG("");
+	DBG("bdaddr: %s", bdaddr2str(bd_addr));
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
@@ -390,7 +392,7 @@ static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
 {
 	struct hal_cmd_ssp_reply cmd;
 
-	DBG("");
+	DBG("bdaddr: %s", bdaddr2str(bd_addr));
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
-- 
1.7.10.4


^ permalink raw reply related

* [PATCHv1 3/4] android/hal: Print full property in debug
From: Andrei Emeltchenko @ 2013-10-28 10:44 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1382957047-31775-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

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

Instead of printing property type print type and value. Use exported
function from hal test tool.
---
 android/hal-bluetooth.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 5929fff..da96202 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -226,7 +226,7 @@ static int set_adapter_property(const bt_property_t *property)
 	char buf[sizeof(struct hal_cmd_set_adapter_prop) + property->len];
 	struct hal_cmd_set_adapter_prop *cmd = (void *) buf;
 
-	DBG("prop: %s", bt_property_type_t2str(property->type));
+	DBG("prop: %s", btproperty2str(property));
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
-- 
1.7.10.4


^ permalink raw reply related

* [PATCHv1 2/4] android/haltest: Use pointer as parameter for debug
From: Andrei Emeltchenko @ 2013-10-28 10:44 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1382957047-31775-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

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

Pass structure as pointer. This makes it consistent with the rest of
the code and helps to reuse this function in other parts.
---
 android/client/if-bt.c    |    2 +-
 android/client/textconv.c |   36 ++++++++++++++++++------------------
 android/client/textconv.h |    2 +-
 3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/android/client/if-bt.c b/android/client/if-bt.c
index 304ab28..d20feb3 100644
--- a/android/client/if-bt.c
+++ b/android/client/if-bt.c
@@ -74,7 +74,7 @@ static void dump_properties(int num_properties, bt_property_t *properties)
 		bt_property_t prop;
 		memcpy(&prop, properties + i, sizeof(prop));
 
-		haltest_info("prop: %s\n", btproperty2str(prop));
+		haltest_info("prop: %s\n", btproperty2str(&prop));
 	}
 }
 
diff --git a/android/client/textconv.c b/android/client/textconv.c
index a3e10ee..16392c2 100644
--- a/android/client/textconv.c
+++ b/android/client/textconv.c
@@ -241,52 +241,52 @@ char *btuuid2str(const bt_uuid_t *uuid)
 	return bt_uuid_t2str(uuid, buf);
 }
 
-char *btproperty2str(bt_property_t property)
+char *btproperty2str(const bt_property_t *property)
 {
 	static char buf[4096];
 	char *p;
 
 	p = buf + sprintf(buf, "type=%s len=%d val=",
-					bt_property_type_t2str(property.type),
-					property.len);
+					bt_property_type_t2str(property->type),
+					property->len);
 
-	switch (property.type) {
+	switch (property->type) {
 	case BT_PROPERTY_BDNAME:
 	case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
-		sprintf(p, "%*s", property.len,
-					((bt_bdname_t *) property.val)->name);
+		sprintf(p, "%*s", property->len,
+					((bt_bdname_t *) property->val)->name);
 		break;
 
 	case BT_PROPERTY_BDADDR:
-		sprintf(p, "%s", bdaddr2str((bt_bdaddr_t *) property.val));
+		sprintf(p, "%s", bdaddr2str((bt_bdaddr_t *) property->val));
 		break;
 
 	case BT_PROPERTY_CLASS_OF_DEVICE:
-		sprintf(p, "%06x", *((int *) property.val));
+		sprintf(p, "%06x", *((int *) property->val));
 		break;
 
 	case BT_PROPERTY_TYPE_OF_DEVICE:
 		sprintf(p, "%s", bt_device_type_t2str(
-					*((bt_device_type_t *) property.val)));
+				*((bt_device_type_t *) property->val)));
 		break;
 
 	case BT_PROPERTY_REMOTE_RSSI:
-		sprintf(p, "%d", *((char *) property.val));
+		sprintf(p, "%d", *((char *) property->val));
 		break;
 
 	case BT_PROPERTY_ADAPTER_SCAN_MODE:
 		sprintf(p, "%s",
-			bt_scan_mode_t2str(*((bt_scan_mode_t *) property.val)));
+			bt_scan_mode_t2str(*((bt_scan_mode_t *) property->val)));
 		break;
 
 	case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
-		sprintf(p, "%d", *((int *) property.val));
+		sprintf(p, "%d", *((int *) property->val));
 		break;
 
 	case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
 		{
-			int count = property.len / sizeof(bt_bdaddr_t);
-			char *ptr = property.val;
+			int count = property->len / sizeof(bt_bdaddr_t);
+			char *ptr = property->val;
 
 			strcat(p, "{");
 
@@ -304,8 +304,8 @@ char *btproperty2str(bt_property_t property)
 
 	case BT_PROPERTY_UUIDS:
 		{
-			int count = property.len / sizeof(bt_uuid_t);
-			char *ptr = property.val;
+			int count = property->len / sizeof(bt_uuid_t);
+			char *ptr = property->val;
 
 			strcat(p, "{");
 
@@ -323,7 +323,7 @@ char *btproperty2str(bt_property_t property)
 
 	case BT_PROPERTY_SERVICE_RECORD:
 		{
-			bt_service_record_t *rec = property.val;
+			bt_service_record_t *rec = property->val;
 
 			sprintf(p, "{%s, %d, %s}", btuuid2str(&rec->uuid),
 						rec->channel, rec->name);
@@ -331,7 +331,7 @@ char *btproperty2str(bt_property_t property)
 		break;
 
 	default:
-		sprintf(p, "%p", property.val);
+		sprintf(p, "%p", property->val);
 	}
 
 	return buf;
diff --git a/android/client/textconv.h b/android/client/textconv.h
index 89b29c6..1c848ef 100644
--- a/android/client/textconv.h
+++ b/android/client/textconv.h
@@ -107,7 +107,7 @@ void str2bt_bdaddr_t(const char *str, bt_bdaddr_t *bd_addr);
 char *bt_uuid_t2str(const bt_uuid_t *uuid, char *buf);
 void str2bt_uuid_t(const char *str, bt_uuid_t *uuid);
 
-char *btproperty2str(bt_property_t property);
+char *btproperty2str(const bt_property_t *property);
 char *bdaddr2str(const bt_bdaddr_t *bd_addr);
 
 DECINTMAP(bt_status_t);
-- 
1.7.10.4


^ permalink raw reply related

* [PATCHv1 1/4] android/haltest: Export print property
From: Andrei Emeltchenko @ 2013-10-28 10:44 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1382957047-31775-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

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

Export property printing debug function.
---
 android/client/if-bt.c    |  110 ---------------------------------------------
 android/client/textconv.c |  110 +++++++++++++++++++++++++++++++++++++++++++++
 android/client/textconv.h |    3 ++
 3 files changed, 113 insertions(+), 110 deletions(-)

diff --git a/android/client/if-bt.c b/android/client/if-bt.c
index dd5d12e..304ab28 100644
--- a/android/client/if-bt.c
+++ b/android/client/if-bt.c
@@ -29,20 +29,6 @@ const bt_interface_t *if_bluetooth;
 		} \
 	} while (0)
 
-static char *bdaddr2str(const bt_bdaddr_t *bd_addr)
-{
-	static char buf[MAX_ADDR_STR_LEN];
-
-	return bt_bdaddr_t2str(bd_addr, buf);
-}
-
-static char *btuuid2str(const bt_uuid_t *uuid)
-{
-	static char buf[MAX_UUID_STR_LEN];
-
-	return bt_uuid_t2str(uuid, buf);
-}
-
 static bt_scan_mode_t str2btscanmode(const char *str)
 {
 	bt_scan_mode_t v = str2bt_scan_mode_t(str);
@@ -76,102 +62,6 @@ static bt_property_type_t str2btpropertytype(const char *str)
 	return (bt_property_type_t) atoi(str);
 }
 
-static char *btproperty2str(bt_property_t property)
-{
-	static char buf[4096];
-	char *p;
-
-	p = buf + sprintf(buf, "type=%s len=%d val=",
-					bt_property_type_t2str(property.type),
-					property.len);
-
-	switch (property.type) {
-	case BT_PROPERTY_BDNAME:
-	case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
-		sprintf(p, "%*s", property.len,
-					((bt_bdname_t *) property.val)->name);
-		break;
-
-	case BT_PROPERTY_BDADDR:
-		sprintf(p, "%s", bdaddr2str((bt_bdaddr_t *) property.val));
-		break;
-
-	case BT_PROPERTY_CLASS_OF_DEVICE:
-		sprintf(p, "%06x", *((int *) property.val));
-		break;
-
-	case BT_PROPERTY_TYPE_OF_DEVICE:
-		sprintf(p, "%s", bt_device_type_t2str(
-					*((bt_device_type_t *) property.val)));
-		break;
-
-	case BT_PROPERTY_REMOTE_RSSI:
-		sprintf(p, "%d", *((char *) property.val));
-		break;
-
-	case BT_PROPERTY_ADAPTER_SCAN_MODE:
-		sprintf(p, "%s",
-			bt_scan_mode_t2str(*((bt_scan_mode_t *) property.val)));
-		break;
-
-	case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
-		sprintf(p, "%d", *((int *) property.val));
-		break;
-
-	case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
-		{
-			int count = property.len / sizeof(bt_bdaddr_t);
-			char *ptr = property.val;
-
-			strcat(p, "{");
-
-			while (count--) {
-				strcat(p, bdaddr2str((bt_bdaddr_t *) ptr));
-				if (count)
-					strcat(p, ", ");
-				ptr += sizeof(bt_bdaddr_t);
-			}
-
-			strcat(p, "}");
-
-		}
-		break;
-
-	case BT_PROPERTY_UUIDS:
-		{
-			int count = property.len / sizeof(bt_uuid_t);
-			char *ptr = property.val;
-
-			strcat(p, "{");
-
-			while (count--) {
-				strcat(p, btuuid2str((bt_uuid_t *) ptr));
-				if (count)
-					strcat(p, ", ");
-				ptr += sizeof(bt_uuid_t);
-			}
-
-			strcat(p, "}");
-
-		}
-		break;
-
-	case BT_PROPERTY_SERVICE_RECORD:
-		{
-			bt_service_record_t *rec = property.val;
-
-			sprintf(p, "{%s, %d, %s}", btuuid2str(&rec->uuid),
-						rec->channel, rec->name);
-		}
-		break;
-
-	default:
-		sprintf(p, "%p", property.val);
-	}
-
-	return buf;
-}
-
 static void dump_properties(int num_properties, bt_property_t *properties)
 {
 	int i;
diff --git a/android/client/textconv.c b/android/client/textconv.c
index 32b1cab..a3e10ee 100644
--- a/android/client/textconv.c
+++ b/android/client/textconv.c
@@ -226,3 +226,113 @@ const char *enum_one_string(void *v, int i)
 
 	return (i == 0) && (m[0] != 0) ? m : NULL;
 }
+
+char *bdaddr2str(const bt_bdaddr_t *bd_addr)
+{
+	static char buf[MAX_ADDR_STR_LEN];
+
+	return bt_bdaddr_t2str(bd_addr, buf);
+}
+
+char *btuuid2str(const bt_uuid_t *uuid)
+{
+	static char buf[MAX_UUID_STR_LEN];
+
+	return bt_uuid_t2str(uuid, buf);
+}
+
+char *btproperty2str(bt_property_t property)
+{
+	static char buf[4096];
+	char *p;
+
+	p = buf + sprintf(buf, "type=%s len=%d val=",
+					bt_property_type_t2str(property.type),
+					property.len);
+
+	switch (property.type) {
+	case BT_PROPERTY_BDNAME:
+	case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
+		sprintf(p, "%*s", property.len,
+					((bt_bdname_t *) property.val)->name);
+		break;
+
+	case BT_PROPERTY_BDADDR:
+		sprintf(p, "%s", bdaddr2str((bt_bdaddr_t *) property.val));
+		break;
+
+	case BT_PROPERTY_CLASS_OF_DEVICE:
+		sprintf(p, "%06x", *((int *) property.val));
+		break;
+
+	case BT_PROPERTY_TYPE_OF_DEVICE:
+		sprintf(p, "%s", bt_device_type_t2str(
+					*((bt_device_type_t *) property.val)));
+		break;
+
+	case BT_PROPERTY_REMOTE_RSSI:
+		sprintf(p, "%d", *((char *) property.val));
+		break;
+
+	case BT_PROPERTY_ADAPTER_SCAN_MODE:
+		sprintf(p, "%s",
+			bt_scan_mode_t2str(*((bt_scan_mode_t *) property.val)));
+		break;
+
+	case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
+		sprintf(p, "%d", *((int *) property.val));
+		break;
+
+	case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
+		{
+			int count = property.len / sizeof(bt_bdaddr_t);
+			char *ptr = property.val;
+
+			strcat(p, "{");
+
+			while (count--) {
+				strcat(p, bdaddr2str((bt_bdaddr_t *) ptr));
+				if (count)
+					strcat(p, ", ");
+				ptr += sizeof(bt_bdaddr_t);
+			}
+
+			strcat(p, "}");
+
+		}
+		break;
+
+	case BT_PROPERTY_UUIDS:
+		{
+			int count = property.len / sizeof(bt_uuid_t);
+			char *ptr = property.val;
+
+			strcat(p, "{");
+
+			while (count--) {
+				strcat(p, btuuid2str((bt_uuid_t *) ptr));
+				if (count)
+					strcat(p, ", ");
+				ptr += sizeof(bt_uuid_t);
+			}
+
+			strcat(p, "}");
+
+		}
+		break;
+
+	case BT_PROPERTY_SERVICE_RECORD:
+		{
+			bt_service_record_t *rec = property.val;
+
+			sprintf(p, "{%s, %d, %s}", btuuid2str(&rec->uuid),
+						rec->channel, rec->name);
+		}
+		break;
+
+	default:
+		sprintf(p, "%p", property.val);
+	}
+
+	return buf;
+}
diff --git a/android/client/textconv.h b/android/client/textconv.h
index 085b141..89b29c6 100644
--- a/android/client/textconv.h
+++ b/android/client/textconv.h
@@ -107,6 +107,9 @@ void str2bt_bdaddr_t(const char *str, bt_bdaddr_t *bd_addr);
 char *bt_uuid_t2str(const bt_uuid_t *uuid, char *buf);
 void str2bt_uuid_t(const char *str, bt_uuid_t *uuid);
 
+char *btproperty2str(bt_property_t property);
+char *bdaddr2str(const bt_bdaddr_t *bd_addr);
+
 DECINTMAP(bt_status_t);
 DECINTMAP(bt_state_t);
 DECINTMAP(bt_device_type_t);
-- 
1.7.10.4


^ permalink raw reply related

* [PATCHv1 0/4] Improve logging for Android
From: Andrei Emeltchenko @ 2013-10-28 10:44 UTC (permalink / raw)
  To: linux-bluetooth

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

This patch series uses debug functions defined already for haltest and
allows to print very helpful logs on Android target like shown below:

...
hal-bluetooth.c:set_adapter_property() prop: type=BT_PROPERTY_ADAPTER_SCAN_MODE len=4 val=BT_SCAN_MODE_NONE
...

Andrei Emeltchenko (4):
  android/haltest: Export print property
  android/haltest: Use pointer as parameter for debug
  android/hal: Print full property in debug
  android/hal: Add extra logs

 android/client/if-bt.c    |  112 +--------------------------------------------
 android/client/textconv.c |  110 ++++++++++++++++++++++++++++++++++++++++++++
 android/client/textconv.h |    3 ++
 android/hal-bluetooth.c   |   24 +++++-----
 4 files changed, 127 insertions(+), 122 deletions(-)

-- 
1.7.10.4


^ permalink raw reply

* Re: [PATCH 1/6] android/hal: Fix typo in A2DP HAL service name
From: Luiz Augusto von Dentz @ 2013-10-28  9:53 UTC (permalink / raw)
  To: Grzegorz Kolodziejczyk; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1382716327-25283-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

Hi Grzegorz,

On Fri, Oct 25, 2013 at 6:52 PM, Grzegorz Kolodziejczyk
<grzegorz.kolodziejczyk@tieto.com> wrote:
> A2DP was misspelled as AD2P
> ---
>  android/hal-ipc-api.txt | 2 +-
>  android/hal-msg.h       | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
> index 0c2fd25..dc0d067 100644
> --- a/android/hal-ipc-api.txt
> +++ b/android/hal-ipc-api.txt
> @@ -1023,7 +1023,7 @@ Notifications:
>  Bluetooth Advanced Audio HAL (ID 6)
>  ===================================
>
> -Android HAL name: "ad2p" (BT_PROFILE_ADVANCED_AUDIO_ID)
> +Android HAL name: "a2dp" (BT_PROFILE_ADVANCED_AUDIO_ID)
>
>  Commands and responses:
>
> diff --git a/android/hal-msg.h b/android/hal-msg.h
> index 172cecb..5de8eb2 100644
> --- a/android/hal-msg.h
> +++ b/android/hal-msg.h
> @@ -40,7 +40,7 @@ struct hal_hdr {
>  #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_A2DP            6
>  #define HAL_SERVICE_ID_HEALTH          7
>  #define HAL_SERVICE_ID_AVRCP           8
>  #define HAL_SERVICE_ID_GATT            9
> --
> 1.8.4.1

Applied, thanks.


-- 
Luiz Augusto von Dentz

^ permalink raw reply

* Re: [PATCH 1/6] android: Use common exit path for commands in bt_adapter_handle_cmd
From: Luiz Augusto von Dentz @ 2013-10-27 12:03 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1382714103-27689-1-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Fri, Oct 25, 2013 at 6:14 PM, Szymon Janc <szymon.janc@tieto.com> wrote:
> All adapter commands return no parameters so putting error and success
> response on common exit path. This will make function easier to follow
> when more commands support will be added.
> ---
>  android/adapter.c | 34 ++++++++++++++++------------------
>  1 file changed, 16 insertions(+), 18 deletions(-)
>
> diff --git a/android/adapter.c b/android/adapter.c
> index ec90cca..685b00d 100644
> --- a/android/adapter.c
> +++ b/android/adapter.c
> @@ -374,39 +374,37 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
>         case HAL_OP_ENABLE:
>                 if (adapter->current_settings & MGMT_SETTING_POWERED) {
>                         status = HAL_STATUS_DONE;
> -                       break;
> +                       goto error;
>                 }
>
> -               if (set_mode(MGMT_OP_SET_POWERED, 0x01)) {
> -                       ipc_send(io, HAL_SERVICE_ID_BLUETOOTH, opcode, 0, NULL,
> -                                                                       -1);
> -                       return;
> -               }
> +               if (!set_mode(MGMT_OP_SET_POWERED, 0x01))
> +                       goto error;
> +
>                 break;
>         case HAL_OP_DISABLE:
>                 if (!(adapter->current_settings & MGMT_SETTING_POWERED)) {
>                         status = HAL_STATUS_DONE;
> -                       break;
> +                       goto error;
>                 }
>
> -               if (set_mode(MGMT_OP_SET_POWERED, 0x00)) {
> -                       ipc_send(io, HAL_SERVICE_ID_BLUETOOTH, opcode, 0, NULL,
> -                                                                       -1);
> -                       return;
> -               }
> +               if (!set_mode(MGMT_OP_SET_POWERED, 0x00))
> +                       goto error;
> +
>                 break;
>         case HAL_OP_GET_ADAPTER_PROP:
> -               if (get_property(buf, len)) {
> -                       ipc_send(io, HAL_SERVICE_ID_BLUETOOTH, opcode, 0, NULL,
> -                                                                       -1);
> -                       return;
> -               }
> +               if (!get_property(buf, len))
> +                       goto error;
> +
>                 break;
>         default:
>                 DBG("Unhandled command, opcode 0x%x", opcode);
> -               break;
> +               goto error;
>         }
>
> +       ipc_send(io, HAL_SERVICE_ID_BLUETOOTH, opcode, 0, NULL, -1);
> +       return;
> +
> +error:
>         ipc_send_rsp(io, HAL_SERVICE_ID_BLUETOOTH, status);
>  }
>
> --
> 1.8.4.1

Pushed, thanks.


-- 
Luiz Augusto von Dentz

^ permalink raw reply

* Re: [PATCH 1/2] android/hal: Use defined function to check that interface is ready
From: Luiz Augusto von Dentz @ 2013-10-27 11:21 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1382707726-20118-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

On Fri, Oct 25, 2013 at 4:28 PM, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> ---
>  android/hal-bluetooth.c |   12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
> index 894f5b5..282a680 100644
> --- a/android/hal-bluetooth.c
> +++ b/android/hal-bluetooth.c
> @@ -78,10 +78,15 @@ void bt_thread_disassociate(void)
>                 bt_hal_cbacks->thread_evt_cb(DISASSOCIATE_JVM);
>  }
>
> +static bool interface_ready(void)
> +{
> +       return bt_hal_cbacks != NULL;
> +}
> +
>  /* will be called from notification thread context */
>  void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
>  {
> -       if (!bt_hal_cbacks)
> +       if (!interface_ready())
>                 return;
>
>         switch (opcode) {
> @@ -97,11 +102,6 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
>         }
>  }
>
> -static bool interface_ready(void)
> -{
> -       return bt_hal_cbacks != NULL;
> -}
> -
>  static int init(bt_callbacks_t *callbacks)
>  {
>         struct hal_cmd_register_module cmd;
> --
> 1.7.10.4
>
> --

Pushed, thanks.



-- 
Luiz Augusto von Dentz

^ permalink raw reply

* Re: [PATCH] Bluetooth: Add hci_h4p driver
From: Pali Rohár @ 2013-10-26 19:28 UTC (permalink / raw)
  To: Joe Perches
  Cc: Marcel Holtmann, Gustavo Padovan, Johan Hedberg, Pavel Machek,
	linux-kernel, linux-bluetooth,
	Ивайло Димитров,
	Joni Lapilainen, Sebastian Reichel, Aaro Koskinen
In-Reply-To: <1382640113.22433.69.camel@joe-AO722>

[-- Attachment #1: Type: Text/Plain, Size: 3175 bytes --]

On Thursday 24 October 2013 20:41:53 Joe Perches wrote:
> On Fri, 2013-10-18 at 12:30 +0200, Pali Rohár wrote:
> > I rebased patch on top of
> > https://git.kernel.org/cgit/linux/kernel/git/bluetooth/blue
> > tooth-next.git branch master
> 
> Hi Pali, just some trivial notes:
> 
> []
> 
> +static ssize_t hci_h4p_show_bdaddr(struct device *dev,
> 
> > +                                  struct device_attribute
> > *attr, char *buf) +{
> > +       struct hci_h4p_info *info = dev_get_drvdata(dev);
> > +
> > +       return sprintf(buf,
> > "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", +                     
> > info->bd_addr[0], info->bd_addr[1], info->bd_addr[2], +    
> >                  info->bd_addr[3], info->bd_addr[4],
> > info->bd_addr[5]);
> 
> sprintf(buf, "%pM", info->bd_addr)
> 

"%pM" modifier printing mac address?

> and if this is really bluetooth, does the output need to
> be emitted in reverse order?  ie: %pMR
> 

I'm sure that actual order of above code is correct.
So what to use? "%pM" or "%pMR"?

> []
> 
> > +#define NBT_DBG(fmt, arg...) \
> > +               pr_debug("%s: " fmt "" , __func__ , ## arg)
> > +
> > +#define NBT_DBG_FW(fmt, arg...) \
> > +               pr_debug("%s: " fmt "" , __func__ , ## arg)
> > +
> > +#define NBT_DBG_POWER(fmt, arg...) \
> > +               pr_debug("%s: " fmt "" , __func__ , ## arg)
> > +
> > +#define NBT_DBG_TRANSFER(fmt, arg...) \
> > +               pr_debug("%s: " fmt "" , __func__ , ## arg)
> > +
> > +#define NBT_DBG_TRANSFER_NF(fmt, arg...) \
> > +               pr_debug(fmt "" , ## arg)
> > +
> > +#define NBT_DBG_DMA(fmt, arg...) \
> > +               pr_debug("%s: " fmt "" , __func__ , ## arg)
> 
> The "" isn't useful.
> 
> dynamic_debugging can add __func__ to each message output
> with +f.
> 
> I think all of these should be converted to pr_debug
> where used or consolidated into a single
> #define nbt_dbg(mask, fmt, ...)			\
> do {						\
> 	if (mask & debug)			\
> 		pr_debug(fmt, ##__VA_ARGS__);
> } while (0)
> 
> and used like:
> 	nbt_dbg(TRANSFER, fmt, etc...);
> where debug is some static.
> 
> Also there are many uses missing "\n" which can
> cause interleaving problems with other printks.
> 
> []
> 
> > +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int
> > active, +                        int timeout_ms)
> > +{
> > +       unsigned long timeout;
> > +       int state;
> > +
> > +       timeout = jiffies + msecs_to_jiffies(timeout_ms);
> > +       for (;;) {
> 
> 	while (time_before(jiffies, timeout)) {
> 
> > +               state = hci_h4p_inb(info, UART_MSR) &
> > UART_MSR_CTS; +               if (active) {
> > +                       if (state)
> > +                               return 0;
> > +               } else {
> > +                       if (!state)
> > +                               return 0;
> > +               }
> > +               if (time_after(jiffies, timeout))
> > +                       return -ETIMEDOUT;
> > 
> > +               msleep(1);
> > +       }
> 
> 	return -ETIMEDOUT;
> 
> > +}

-- 
Pali Rohár
pali.rohar@gmail.com

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply

* Bluetooth tools
From: Kevin Wilson @ 2013-10-26  6:40 UTC (permalink / raw)
  To: linux-bluetooth

Hello,

I saw that bluetoothctl and btmon are the newer tool of Bluetooth.

What are the advantages of bluetoothctl over hciconfig/hcitool?

What are the advantages of btmon over hcidump ?


Regards,
Kevin

^ permalink raw reply

* [PATCH 6/6] android/hal: Add support for send av disconnect command
From: Grzegorz Kolodziejczyk @ 2013-10-25 15:52 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1382716327-25283-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

This allows HAL to send av disconnect command
---
 android/hal-av.c  | 8 +++++---
 android/hal-msg.h | 5 +++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/android/hal-av.c b/android/hal-av.c
index 239088f..483dcf1 100644
--- a/android/hal-av.c
+++ b/android/hal-av.c
@@ -84,15 +84,17 @@ static bt_status_t av_connect(bt_bdaddr_t *bd_addr)
 
 static bt_status_t av_disconnect(bt_bdaddr_t *bd_addr)
 {
+	struct hal_msg_op_bt_av_disconnect cmd;
+
 	DBG("");
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
 
-	if (!bd_addr)
-		return BT_STATUS_PARM_INVALID;
+	memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
 
-	return BT_STATUS_UNSUPPORTED;
+	return hal_ipc_cmd(HAL_SERVICE_ID_A2DP, HAL_MSG_OP_BT_AV_DISCONNECT,
+					sizeof(cmd), &cmd, NULL, NULL, NULL);
 }
 
 static bt_status_t av_init(btav_callbacks_t *callbacks)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 66486f1..193ecae 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -281,6 +281,11 @@ struct hal_msg_op_bt_av_connect {
 	uint8_t bdaddr[6];
 } __attribute__((packed));
 
+#define HAL_MSG_OP_BT_AV_DISCONNECT	0x02
+struct hal_msg_op_bt_av_disconnect {
+	uint8_t bdaddr[6];
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 5/6] android/hal: Add support for send av connect command
From: Grzegorz Kolodziejczyk @ 2013-10-25 15:52 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1382716327-25283-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

This allows HAL to send av connect command
---
 android/hal-av.c  | 10 +++++++---
 android/hal-msg.h |  5 +++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/android/hal-av.c b/android/hal-av.c
index d537e84..239088f 100644
--- a/android/hal-av.c
+++ b/android/hal-av.c
@@ -17,10 +17,12 @@
 
 #include <stdbool.h>
 #include <stddef.h>
+#include <string.h>
 
 #include "hal-log.h"
 #include "hal.h"
 #include "hal-msg.h"
+#include "hal-ipc.h"
 
 static const btav_callbacks_t *cbs = NULL;
 
@@ -67,15 +69,17 @@ void bt_notify_av(uint16_t opcode, void *buf, uint16_t len)
 
 static bt_status_t av_connect(bt_bdaddr_t *bd_addr)
 {
+	struct hal_msg_op_bt_av_connect cmd;
+
 	DBG("");
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
 
-	if (!bd_addr)
-		return BT_STATUS_PARM_INVALID;
+	memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
 
-	return BT_STATUS_UNSUPPORTED;
+	return hal_ipc_cmd(HAL_SERVICE_ID_A2DP, HAL_MSG_OP_BT_AV_CONNECT,
+					sizeof(cmd), &cmd, NULL, NULL, NULL);
 }
 
 static bt_status_t av_disconnect(bt_bdaddr_t *bd_addr)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 2206f47..66486f1 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -276,6 +276,11 @@ struct hal_cmd_hid_send_data {
 	uint8_t bdaddr[6];
 } __attribute__((packed));
 
+#define HAL_MSG_OP_BT_AV_CONNECT	0x01
+struct hal_msg_op_bt_av_connect {
+	uint8_t bdaddr[6];
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 4/6] android/hal: Add support for handling av audio state event
From: Grzegorz Kolodziejczyk @ 2013-10-25 15:52 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1382716327-25283-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-av.c  | 11 +++++++++++
 android/hal-msg.h |  6 ++++++
 2 files changed, 17 insertions(+)

diff --git a/android/hal-av.c b/android/hal-av.c
index 8aa096d..d537e84 100644
--- a/android/hal-av.c
+++ b/android/hal-av.c
@@ -38,6 +38,14 @@ static void handle_connection_state(void *buf)
 						(bt_bdaddr_t *) (ev->bdaddr));
 }
 
+static void handle_audio_state(void *buf)
+{
+	struct hal_msg_ev_bt_av_audio_state *ev = buf;
+
+	if (cbs->audio_state_cb)
+		cbs->audio_state_cb(ev->state, (bt_bdaddr_t *)(ev->bdaddr));
+}
+
 /* will be called from notification thread context */
 void bt_notify_av(uint16_t opcode, void *buf, uint16_t len)
 {
@@ -48,6 +56,9 @@ void bt_notify_av(uint16_t opcode, void *buf, uint16_t len)
 	case HAL_MSG_EV_BT_AV_CONNECTION_STATE:
 		handle_connection_state(buf);
 		break;
+	case HAL_MSG_EV_BT_AV_AUDIO_STATE:
+		handle_audio_state(buf);
+		break;
 	default:
 		DBG("Unhandled callback opcode=0x%x", opcode);
 		break;
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 558e030..2206f47 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -366,3 +366,9 @@ struct hal_msg_ev_bt_av_connection_state {
 	uint8_t state;
 	uint8_t bdaddr[6];
 } __attribute__((packed));
+
+#define HAL_MSG_EV_BT_AV_AUDIO_STATE	0x82
+struct hal_msg_ev_bt_av_audio_state {
+	uint8_t state;
+	uint8_t bdaddr[6];
+} __attribute__((packed));
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 3/6] android/hal: Add support for handling av connection state event
From: Grzegorz Kolodziejczyk @ 2013-10-25 15:52 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1382716327-25283-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-av.c  | 13 +++++++++++++
 android/hal-msg.h |  6 ++++++
 2 files changed, 19 insertions(+)

diff --git a/android/hal-av.c b/android/hal-av.c
index 051fc3e..8aa096d 100644
--- a/android/hal-av.c
+++ b/android/hal-av.c
@@ -20,6 +20,7 @@
 
 #include "hal-log.h"
 #include "hal.h"
+#include "hal-msg.h"
 
 static const btav_callbacks_t *cbs = NULL;
 
@@ -28,6 +29,15 @@ static bool interface_ready(void)
 	return cbs != NULL;
 }
 
+static void handle_connection_state(void *buf)
+{
+	struct hal_msg_ev_bt_av_connection_state *ev = buf;
+
+	if (cbs->connection_state_cb)
+		cbs->connection_state_cb(ev->state,
+						(bt_bdaddr_t *) (ev->bdaddr));
+}
+
 /* will be called from notification thread context */
 void bt_notify_av(uint16_t opcode, void *buf, uint16_t len)
 {
@@ -35,6 +45,9 @@ void bt_notify_av(uint16_t opcode, void *buf, uint16_t len)
 		return;
 
 	switch (opcode) {
+	case HAL_MSG_EV_BT_AV_CONNECTION_STATE:
+		handle_connection_state(buf);
+		break;
 	default:
 		DBG("Unhandled callback opcode=0x%x", opcode);
 		break;
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 5de8eb2..558e030 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -360,3 +360,9 @@ struct hal_ev_le_test_mode {
 	uint8_t  status;
 	uint16_t num_packets;
 } __attribute__((packed));
+
+#define HAL_MSG_EV_BT_AV_CONNECTION_STATE	0x81
+struct hal_msg_ev_bt_av_connection_state {
+	uint8_t state;
+	uint8_t bdaddr[6];
+} __attribute__((packed));
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 2/6] android/hal: Add skeleton for handling av notifications
From: Grzegorz Kolodziejczyk @ 2013-10-25 15:52 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1382716327-25283-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

Only default case is handled in skeleton
---
 android/hal-av.c  | 13 +++++++++++++
 android/hal-ipc.c |  3 +++
 android/hal.h     |  1 +
 3 files changed, 17 insertions(+)

diff --git a/android/hal-av.c b/android/hal-av.c
index 0fe1b74..051fc3e 100644
--- a/android/hal-av.c
+++ b/android/hal-av.c
@@ -28,6 +28,19 @@ static bool interface_ready(void)
 	return cbs != NULL;
 }
 
+/* will be called from notification thread context */
+void bt_notify_av(uint16_t opcode, void *buf, uint16_t len)
+{
+	if (!interface_ready())
+		return;
+
+	switch (opcode) {
+	default:
+		DBG("Unhandled callback opcode=0x%x", opcode);
+		break;
+	}
+}
+
 static bt_status_t av_connect(bt_bdaddr_t *bd_addr)
 {
 	DBG("");
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 5723841..f68e789 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -49,6 +49,9 @@ static void notification_dispatch(struct hal_hdr *msg, int fd)
 	case HAL_SERVICE_ID_BLUETOOTH:
 		bt_notify_adapter(msg->opcode, msg->payload, msg->len);
 		break;
+	case HAL_SERVICE_ID_A2DP:
+		bt_notify_av(msg->opcode, msg->payload, msg->len);
+		break;
 	default:
 		DBG("Unhandled notification service=%d opcode=0x%x",
 						msg->service_id, msg->opcode);
diff --git a/android/hal.h b/android/hal.h
index 5cd5cab..a377649 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -29,3 +29,4 @@ btav_interface_t *bt_get_av_interface(void);
 void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len);
 void bt_thread_associate(void);
 void bt_thread_disassociate(void);
+void bt_notify_av(uint16_t opcode, void *buf, uint16_t len);
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 1/6] android/hal: Fix typo in A2DP HAL service name
From: Grzegorz Kolodziejczyk @ 2013-10-25 15:52 UTC (permalink / raw)
  To: linux-bluetooth

A2DP was misspelled as AD2P
---
 android/hal-ipc-api.txt | 2 +-
 android/hal-msg.h       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 0c2fd25..dc0d067 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -1023,7 +1023,7 @@ Notifications:
 Bluetooth Advanced Audio HAL (ID 6)
 ===================================
 
-Android HAL name: "ad2p" (BT_PROFILE_ADVANCED_AUDIO_ID)
+Android HAL name: "a2dp" (BT_PROFILE_ADVANCED_AUDIO_ID)
 
 Commands and responses:
 
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 172cecb..5de8eb2 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -40,7 +40,7 @@ struct hal_hdr {
 #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_A2DP		6
 #define HAL_SERVICE_ID_HEALTH		7
 #define HAL_SERVICE_ID_AVRCP		8
 #define HAL_SERVICE_ID_GATT		9
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 6/6] android: Add support for notifying HAL about scan mode change
From: Szymon Janc @ 2013-10-25 15:15 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382714103-27689-1-git-send-email-szymon.janc@tieto.com>

If connectable or discoverable setting changes property change is send
to HAL.
---
 android/adapter.c | 54 ++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 40 insertions(+), 14 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index eebe45e..a6e5129 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -86,19 +86,52 @@ static void settings_changed_powered(void)
 			HAL_EV_ADAPTER_STATE_CHANGED, sizeof(ev), &ev, -1);
 }
 
-static void settings_changed_connectable(void)
+static uint8_t settings2scan_mode(void)
 {
-	/* TODO */
+	bool connectable, discoverable;
+
+	connectable = adapter->current_settings & MGMT_SETTING_CONNECTABLE;
+	discoverable = adapter->current_settings & MGMT_SETTING_DISCOVERABLE;
+
+	if (connectable && discoverable)
+		return HAL_ADAPTER_SCAN_MODE_CONN_DISC;
+
+	if (connectable)
+		return HAL_ADAPTER_SCAN_MODE_CONN;
+
+	return HAL_ADAPTER_SCAN_MODE_NONE;
 }
 
-static void settings_changed_discoverable(void)
+static void settings_changed_scan_mode(void)
 {
-	/* TODO */
+	struct hal_ev_adapter_props_changed *ev;
+	uint8_t *mode;
+	int len;
+	len = sizeof(*ev) + sizeof(struct hal_property) + 1;
+
+	ev = g_malloc(len);
+
+	ev->num_props = 1;
+	ev->status = HAL_STATUS_SUCCESS;
+
+	ev->props[0].type = HAL_PROP_ADAPTER_SCAN_MODE;
+	ev->props[0].len = 1;
+
+	mode = ev->props[0].val;
+	*mode = settings2scan_mode();
+
+	DBG("mode %u", *mode);
+
+	ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+				HAL_EV_ADAPTER_PROPS_CHANGED, len, ev, -1);
+
+	g_free(ev);
 }
 
 static void settings_changed(uint32_t settings)
 {
 	uint32_t changed_mask;
+	uint32_t scan_mode_mask;
 
 	changed_mask = adapter->current_settings ^ settings;
 
@@ -109,17 +142,10 @@ static void settings_changed(uint32_t settings)
 	if (changed_mask & MGMT_SETTING_POWERED)
 		settings_changed_powered();
 
-	if (changed_mask & MGMT_SETTING_CONNECTABLE) {
-		DBG("Connectable");
-
-		settings_changed_connectable();
-	}
+	scan_mode_mask = MGMT_SETTING_CONNECTABLE | MGMT_SETTING_DISCOVERABLE;
 
-	if (changed_mask & MGMT_SETTING_DISCOVERABLE) {
-		DBG("Discoverable");
-
-		settings_changed_discoverable();
-	}
+	if (changed_mask & scan_mode_mask)
+		settings_changed_scan_mode();
 }
 
 static void new_settings_callback(uint16_t index, uint16_t length,
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 5/6] android: Always set adapter to pairable on init
From: Szymon Janc @ 2013-10-25 15:15 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382714103-27689-1-git-send-email-szymon.janc@tieto.com>

There is no operation to enable/disable pairable mode in Android HAL.
---
 android/adapter.c | 72 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 37 insertions(+), 35 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index a6c5704..eebe45e 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -224,6 +224,41 @@ static void load_link_keys(GSList *keys)
 	g_free(cp);
 }
 
+static void set_mode_complete(uint8_t status, uint16_t length,
+					const void *param, void *user_data)
+{
+	if (status != MGMT_STATUS_SUCCESS) {
+		error("Failed to set mode: %s (0x%02x)",
+						mgmt_errstr(status), status);
+		return;
+	}
+
+	/*
+	 * The parameters are identical and also the task that is
+	 * required in both cases. So it is safe to just call the
+	 * event handling functions here.
+	 */
+	new_settings_callback(adapter->index, length, param, NULL);
+}
+
+static bool set_mode(uint16_t opcode, uint8_t mode)
+{
+	struct mgmt_mode cp;
+
+	memset(&cp, 0, sizeof(cp));
+	cp.val = mode;
+
+	DBG("opcode=0x%x mode=0x%x", opcode, mode);
+
+	if (mgmt_send(adapter->mgmt, opcode, adapter->index, sizeof(cp), &cp,
+					set_mode_complete, NULL, NULL) > 0)
+		return true;
+
+	error("Failed to set mode");
+
+	return false;
+}
+
 static void read_info_complete(uint8_t status, uint16_t length, const void *param,
 							void *user_data)
 {
@@ -265,6 +300,8 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
 
 	load_link_keys(NULL);
 
+	set_mode(MGMT_OP_SET_PAIRABLE, 0x01);
+
 	return;
 
 failed:
@@ -287,41 +324,6 @@ void bt_adapter_init(uint16_t index, struct mgmt *mgmt, bt_adapter_ready cb)
 	adapter->ready(-EIO);
 }
 
-static void set_mode_complete(uint8_t status, uint16_t length,
-					const void *param, void *user_data)
-{
-	if (status != MGMT_STATUS_SUCCESS) {
-		error("Failed to set mode: %s (0x%02x)",
-						mgmt_errstr(status), status);
-		return;
-	}
-
-	/*
-	 * The parameters are identical and also the task that is
-	 * required in both cases. So it is safe to just call the
-	 * event handling functions here.
-	 */
-	new_settings_callback(adapter->index, length, param, NULL);
-}
-
-static bool set_mode(uint16_t opcode, uint8_t mode)
-{
-	struct mgmt_mode cp;
-
-	memset(&cp, 0, sizeof(cp));
-	cp.val = mode;
-
-	DBG("opcode=0x%x mode=0x%x", opcode, mode);
-
-	if (mgmt_send(adapter->mgmt, opcode, adapter->index, sizeof(cp), &cp,
-					set_mode_complete, NULL, NULL) > 0)
-		return true;
-
-	error("Failed to set mode");
-
-	return false;
-}
-
 static bool set_discoverable(uint8_t mode, uint16_t timeout)
 {
 	struct mgmt_cp_set_discoverable cp;
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 4/6] android: Add support for setting adapter scan mode
From: Szymon Janc @ 2013-10-25 15:15 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382714103-27689-1-git-send-email-szymon.janc@tieto.com>

This allows to set all modes defined: none, connectable and
'connectable and discoverable'.
---
 android/adapter.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 72 insertions(+), 1 deletion(-)

diff --git a/android/adapter.c b/android/adapter.c
index 13cce8f..a6c5704 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -322,6 +322,26 @@ static bool set_mode(uint16_t opcode, uint8_t mode)
 	return false;
 }
 
+static bool set_discoverable(uint8_t mode, uint16_t timeout)
+{
+	struct mgmt_cp_set_discoverable cp;
+
+	memset(&cp, 0, sizeof(cp));
+	cp.val = mode;
+	cp.timeout = htobs(timeout);
+
+	DBG("mode %u timeout %u", mode, timeout);
+
+	if (mgmt_send(adapter->mgmt, MGMT_OP_SET_DISCOVERABLE,
+				adapter->index, sizeof(cp), &cp,
+				set_mode_complete, adapter, NULL) > 0)
+		return true;
+
+	error("Failed to set mode discoverable");
+
+	return false;
+}
+
 static void send_adapter_name(void)
 {
 	struct hal_ev_adapter_props_changed *ev;
@@ -365,13 +385,64 @@ static bool get_property(void *buf, uint16_t len)
 	}
 }
 
+static uint8_t set_scan_mode(void *buf, uint16_t len)
+{
+	uint8_t *mode = buf;
+	bool conn, disc, cur_conn, cur_disc;
+
+	cur_conn = adapter->current_settings & MGMT_SETTING_CONNECTABLE;
+	cur_disc = adapter->current_settings & MGMT_SETTING_DISCOVERABLE;
+
+	DBG("connectable %u discoverable %d mode %u", cur_conn, cur_disc,
+								*mode);
+
+	switch (*mode) {
+	case HAL_ADAPTER_SCAN_MODE_NONE:
+		if (!cur_conn && !cur_disc)
+			return HAL_STATUS_DONE;
+
+		conn = false;
+		disc = false;
+		break;
+	case HAL_ADAPTER_SCAN_MODE_CONN:
+		if (cur_conn && !cur_disc)
+			return HAL_STATUS_DONE;
+
+		conn = true;
+		disc = false;
+		break;
+	case HAL_ADAPTER_SCAN_MODE_CONN_DISC:
+		if (cur_conn && cur_disc)
+			return HAL_STATUS_DONE;
+
+		conn = true;
+		disc = true;
+		break;
+	default:
+		return HAL_STATUS_FAILED;
+	}
+
+	if (cur_conn != conn) {
+		if (!set_mode(MGMT_OP_SET_CONNECTABLE, conn ? 0x01 : 0x00))
+			return HAL_STATUS_FAILED;
+	}
+
+	if (cur_disc != disc) {
+		if (!set_discoverable(disc ? 0x01 : 0x00, 0))
+			return HAL_STATUS_FAILED;
+	}
+
+	return HAL_STATUS_SUCCESS;
+}
+
 static uint8_t set_property(void *buf, uint16_t len)
 {
 	struct hal_cmd_set_adapter_prop *cmd = buf;
 
 	switch (cmd->type) {
-	case HAL_PROP_ADAPTER_NAME:
 	case HAL_PROP_ADAPTER_SCAN_MODE:
+		return set_scan_mode(cmd->val, cmd->len);
+	case HAL_PROP_ADAPTER_NAME:
 	case HAL_PROP_ADAPTER_DISC_TIMEOUT:
 	default:
 		DBG("Unhandled property type 0x%x", cmd->type);
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 3/6] android: Add missing scan mode difinitions to IPC header
From: Szymon Janc @ 2013-10-25 15:15 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382714103-27689-1-git-send-email-szymon.janc@tieto.com>

---
 android/hal-msg.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/android/hal-msg.h b/android/hal-msg.h
index 172cecb..677b00b 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -113,6 +113,10 @@ struct hal_cmd_get_adapter_prop {
 #define HAL_PROP_DEVICE_VERSION_INFO		0x0c
 #define HAL_PROP_DEVICE_TIMESTAMP		0xFF
 
+#define HAL_ADAPTER_SCAN_MODE_NONE		0x00
+#define HAL_ADAPTER_SCAN_MODE_CONN		0x01
+#define HAL_ADAPTER_SCAN_MODE_CONN_DISC	0x02
+
 #define HAL_OP_SET_ADAPTER_PROP		0x05
 struct hal_cmd_set_adapter_prop {
 	uint8_t  type;
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 2/6] android: Add initial code for handling adapter set property command
From: Szymon Janc @ 2013-10-25 15:14 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382714103-27689-1-git-send-email-szymon.janc@tieto.com>

No commands are handled yet.
---
 android/adapter.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/android/adapter.c b/android/adapter.c
index 685b00d..13cce8f 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -365,6 +365,20 @@ static bool get_property(void *buf, uint16_t len)
 	}
 }
 
+static uint8_t set_property(void *buf, uint16_t len)
+{
+	struct hal_cmd_set_adapter_prop *cmd = buf;
+
+	switch (cmd->type) {
+	case HAL_PROP_ADAPTER_NAME:
+	case HAL_PROP_ADAPTER_SCAN_MODE:
+	case HAL_PROP_ADAPTER_DISC_TIMEOUT:
+	default:
+		DBG("Unhandled property type 0x%x", cmd->type);
+		return HAL_STATUS_FAILED;
+	}
+}
+
 void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
 								uint16_t len)
 {
@@ -396,6 +410,12 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
 			goto error;
 
 		break;
+	case HAL_OP_SET_ADAPTER_PROP:
+		status = set_property(buf, len);
+		if (status != HAL_STATUS_SUCCESS)
+			goto error;
+
+		break;
 	default:
 		DBG("Unhandled command, opcode 0x%x", opcode);
 		goto error;
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 1/6] android: Use common exit path for commands in bt_adapter_handle_cmd
From: Szymon Janc @ 2013-10-25 15:14 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

All adapter commands return no parameters so putting error and success
response on common exit path. This will make function easier to follow
when more commands support will be added.
---
 android/adapter.c | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index ec90cca..685b00d 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -374,39 +374,37 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
 	case HAL_OP_ENABLE:
 		if (adapter->current_settings & MGMT_SETTING_POWERED) {
 			status = HAL_STATUS_DONE;
-			break;
+			goto error;
 		}
 
-		if (set_mode(MGMT_OP_SET_POWERED, 0x01)) {
-			ipc_send(io, HAL_SERVICE_ID_BLUETOOTH, opcode, 0, NULL,
-									-1);
-			return;
-		}
+		if (!set_mode(MGMT_OP_SET_POWERED, 0x01))
+			goto error;
+
 		break;
 	case HAL_OP_DISABLE:
 		if (!(adapter->current_settings & MGMT_SETTING_POWERED)) {
 			status = HAL_STATUS_DONE;
-			break;
+			goto error;
 		}
 
-		if (set_mode(MGMT_OP_SET_POWERED, 0x00)) {
-			ipc_send(io, HAL_SERVICE_ID_BLUETOOTH, opcode, 0, NULL,
-									-1);
-			return;
-		}
+		if (!set_mode(MGMT_OP_SET_POWERED, 0x00))
+			goto error;
+
 		break;
 	case HAL_OP_GET_ADAPTER_PROP:
-		if (get_property(buf, len)) {
-			ipc_send(io, HAL_SERVICE_ID_BLUETOOTH, opcode, 0, NULL,
-									-1);
-			return;
-		}
+		if (!get_property(buf, len))
+			goto error;
+
 		break;
 	default:
 		DBG("Unhandled command, opcode 0x%x", opcode);
-		break;
+		goto error;
 	}
 
+	ipc_send(io, HAL_SERVICE_ID_BLUETOOTH, opcode, 0, NULL, -1);
+	return;
+
+error:
 	ipc_send_rsp(io, HAL_SERVICE_ID_BLUETOOTH, status);
 }
 
-- 
1.8.4.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