Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 00/11] android: Configuration command
@ 2014-09-15 14:49 Szymon Janc
  2014-09-15 14:49 ` [PATCH 01/11] android/hal-ipc-api: Add " Szymon Janc
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Szymon Janc @ 2014-09-15 14:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Hi,

This is a respin of serie that was send some time ago as RFC [1]

This will allow to pass Android properties over IPC and use them
in daemon for customization eg. Device Information or default adapter name.

Comments from RFC was taken into account. So now "ro.bluetooth.*"
and "sys.persist.bluetooth.*" are taken into account (former takes
precedence if both are present). Some configs also fallback to
generic properties if no bluetooth ones are present.

Comments are welcome.

BR
Szymon Janc

[1] "[RFC 0/6] android: Configuration command"


Szymon Janc (11):
  android/hal-ipc-api: Add Configuration command
  android/hal-msg: Add configuration command
  android: Add support for configuration command
  android: Add functions for getting configuration options
  android/bluetooth: Use model name for default adapter name
  android/gatt: Use configuration data for device information profile
  android/hal-bluetooth: Add support for sending configuration
  android/hal: Add helper for quering config from Android properties
  android: Use helper for accesing Android properties
  android/bluetoothd-wrapper: Fix indentation
  android/README: Update customization section

 android/Android.mk           |   3 +-
 android/README               |  14 ++++--
 android/bluetooth.c          |  17 +++++--
 android/bluetoothd-wrapper.c |  19 +++----
 android/client/if-gatt.c     |   2 +
 android/cutils/properties.h  |   1 +
 android/gatt.c               | 115 ++++++++++++++++++++++++-------------------
 android/hal-bluetooth.c      |  51 ++++++++++++++++---
 android/hal-handsfree.c      |  15 +++---
 android/hal-ipc-api.txt      |  16 ++++++
 android/hal-msg.h            |  17 +++++++
 android/hal-utils.c          |  32 ++++++++++++
 android/hal-utils.h          |   2 +
 android/main.c               |  94 +++++++++++++++++++++++++++++++++++
 android/utils.h              |   4 ++
 15 files changed, 314 insertions(+), 88 deletions(-)

-- 
1.9.3


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 01/11] android/hal-ipc-api: Add Configuration command
  2014-09-15 14:49 [PATCH 00/11] android: Configuration command Szymon Janc
@ 2014-09-15 14:49 ` Szymon Janc
  2014-09-15 14:49 ` [PATCH 02/11] android/hal-msg: Add configuration command Szymon Janc
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2014-09-15 14:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

---
 android/hal-ipc-api.txt | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index f6e1680..e7dab3b 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -90,6 +90,9 @@ the socket and register both "bluetooth" and "socket" service modules. It is
 required to register "socket" service at the same time since the HAL module
 does not have its own init() function.
 
+It is possible to send Configure command before registering any services to
+customize stack. This step is optional.
+
 When new profiles are initiated, the get_profile_interface() callback
 will load the profile and during init() of the profile, it should register the
 specific service.
@@ -143,6 +146,19 @@ Core Service (ID 0)
 
 		In case of an error, the error response will be returned.
 
+	Opcode 0x03 - Configuration
+
+		Command parameters: Num options (1 octet)
+		                    Type # (1 octet)
+		                    Value # (92 octets)
+
+		Response parameters: <none>
+
+		Valid configure option types: 0x00 = Vendor
+		                              0x01 = Model
+		                              0x02 = Name
+
+		In case of an error, the error response will be returned.
 
 Bluetooth Core HAL (ID 1)
 =========================
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 02/11] android/hal-msg: Add configuration command
  2014-09-15 14:49 [PATCH 00/11] android: Configuration command Szymon Janc
  2014-09-15 14:49 ` [PATCH 01/11] android/hal-ipc-api: Add " Szymon Janc
@ 2014-09-15 14:49 ` Szymon Janc
  2014-09-15 14:49 ` [PATCH 03/11] android: Add support for " Szymon Janc
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2014-09-15 14:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

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

diff --git a/android/hal-msg.h b/android/hal-msg.h
index 3d95e10..48d3186 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -69,6 +69,23 @@ struct hal_cmd_unregister_module {
 	uint8_t service_id;
 } __attribute__((packed));
 
+#define HAL_CONFIG_VENDOR		0x00
+#define HAL_CONFIG_MODEL		0x01
+#define HAL_CONFIG_NAME			0x02
+
+#define HAL_CONFIG_MAX_LEN		92
+
+struct hal_config_prop {
+	uint8_t type;
+	uint8_t val[HAL_CONFIG_MAX_LEN];
+} __attribute__((packed));
+
+#define HAL_OP_CONFIGURATION		0x03
+struct hal_cmd_configuration {
+	uint8_t num;
+	struct hal_config_prop props[0];
+} __attribute__((packed));
+
 /* Bluetooth Core HAL API */
 
 #define HAL_OP_ENABLE			0x01
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 03/11] android: Add support for configuration command
  2014-09-15 14:49 [PATCH 00/11] android: Configuration command Szymon Janc
  2014-09-15 14:49 ` [PATCH 01/11] android/hal-ipc-api: Add " Szymon Janc
  2014-09-15 14:49 ` [PATCH 02/11] android/hal-msg: Add configuration command Szymon Janc
@ 2014-09-15 14:49 ` Szymon Janc
  2014-09-15 14:49 ` [PATCH 04/11] android: Add functions for getting configuration options Szymon Janc
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2014-09-15 14:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

---
 android/main.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/android/main.c b/android/main.c
index b03a2df..005f24b 100644
--- a/android/main.c
+++ b/android/main.c
@@ -45,6 +45,7 @@
 
 #include "src/log.h"
 #include "src/sdpd.h"
+#include "src/shared/util.h"
 
 #include "lib/bluetooth.h"
 
@@ -64,6 +65,10 @@
 #define STARTUP_GRACE_SECONDS 5
 #define SHUTDOWN_GRACE_SECONDS 10
 
+static char *config_vendor = NULL;
+static char *config_model = NULL;
+static char *config_name = NULL;
+
 static guint bluetooth_start_timeout = 0;
 
 static bdaddr_t adapter_bdaddr;
@@ -221,11 +226,67 @@ failed:
 								status);
 }
 
+static char *get_prop(char *prop, uint16_t len, const uint8_t *val)
+{
+	/* TODO should fail if set more than once ? */
+	free(prop);
+
+	prop = malloc0(len);
+	if (!prop)
+		return NULL;
+
+	memcpy(prop, val, len);
+	prop[len - 1] = '\0';
+
+	return prop;
+}
+
+static void configuration(const void *buf, uint16_t len)
+{
+	const struct hal_cmd_configuration *cmd = buf;
+	unsigned int i;
+
+	if (len != sizeof(*cmd) + cmd->num * sizeof(cmd->props[0])) {
+		error("Invalid configuration command, terminating");
+		raise(SIGTERM);
+		return;
+	}
+
+	for (i = 0; i < cmd->num; i++) {
+		switch (cmd->props[i].type) {
+		case HAL_CONFIG_VENDOR:
+			config_vendor = get_prop(config_vendor,
+							HAL_CONFIG_MAX_LEN,
+							cmd->props[i].val);
+			break;
+		case HAL_CONFIG_NAME:
+			config_name = get_prop(config_name, HAL_CONFIG_MAX_LEN,
+							cmd->props[i].val);
+			break;
+		case HAL_CONFIG_MODEL:
+			config_model = get_prop(config_model,
+							HAL_CONFIG_MAX_LEN,
+							cmd->props[i].val);
+			break;
+		default:
+			error("Invalid configuration option (%u), terminating",
+							cmd->props[i].type);
+			raise(SIGTERM);
+			return;
+		}
+	}
+
+	ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_CORE, HAL_OP_CONFIGURATION,
+							HAL_STATUS_SUCCESS);
+}
+
 static const struct ipc_handler cmd_handlers[] = {
 	/* HAL_OP_REGISTER_MODULE */
 	{ service_register, false, sizeof(struct hal_cmd_register_module) },
 	/* HAL_OP_UNREGISTER_MODULE */
 	{ service_unregister, false, sizeof(struct hal_cmd_unregister_module) },
+	/* HAL_OP_CONFIGURATION */
+	{ configuration, true, sizeof(struct hal_cmd_configuration) },
 };
 
 static void bluetooth_stopped(void)
@@ -558,5 +619,9 @@ int main(int argc, char *argv[])
 
 	__btd_log_cleanup();
 
+	free(config_vendor);
+	free(config_model);
+	free(config_name);
+
 	return EXIT_SUCCESS;
 }
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 04/11] android: Add functions for getting configuration options
  2014-09-15 14:49 [PATCH 00/11] android: Configuration command Szymon Janc
                   ` (2 preceding siblings ...)
  2014-09-15 14:49 ` [PATCH 03/11] android: Add support for " Szymon Janc
@ 2014-09-15 14:49 ` Szymon Janc
  2014-09-15 14:49 ` [PATCH 05/11] android/bluetooth: Use model name for default adapter name Szymon Janc
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2014-09-15 14:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

---
 android/main.c  | 29 +++++++++++++++++++++++++++++
 android/utils.h |  4 ++++
 2 files changed, 33 insertions(+)

diff --git a/android/main.c b/android/main.c
index 005f24b..b0df011 100644
--- a/android/main.c
+++ b/android/main.c
@@ -61,6 +61,11 @@
 #include "handsfree.h"
 #include "gatt.h"
 #include "health.h"
+#include "utils.h"
+
+#define DEFAULT_VENDOR "BlueZ"
+#define DEFAULT_MODEL "BlueZ for Android"
+#define DEFAULT_NAME "BlueZ for Android"
 
 #define STARTUP_GRACE_SECONDS 5
 #define SHUTDOWN_GRACE_SECONDS 10
@@ -79,6 +84,30 @@ static struct ipc *hal_ipc = NULL;
 
 static bool services[HAL_SERVICE_ID_MAX + 1] = { false };
 
+const char *bt_config_get_vendor(void)
+{
+	if (config_vendor)
+		return config_vendor;
+
+	return DEFAULT_VENDOR;
+}
+
+const char *bt_config_get_name(void)
+{
+	if (config_name)
+		return config_name;
+
+	return DEFAULT_NAME;
+}
+
+const char *bt_config_get_model(void)
+{
+	if (config_model)
+		return config_model;
+
+	return DEFAULT_MODEL;
+}
+
 static void service_register(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_register_module *m = buf;
diff --git a/android/utils.h b/android/utils.h
index 560e991..c70f8cb 100644
--- a/android/utils.h
+++ b/android/utils.h
@@ -30,3 +30,7 @@ static inline void bdaddr2android(const bdaddr_t *src, void *buf)
 {
 	baswap(buf, src);
 }
+
+const char *bt_config_get_vendor(void);
+const char *bt_config_get_model(void);
+const char *bt_config_get_name(void);
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 05/11] android/bluetooth: Use model name for default adapter name
  2014-09-15 14:49 [PATCH 00/11] android: Configuration command Szymon Janc
                   ` (3 preceding siblings ...)
  2014-09-15 14:49 ` [PATCH 04/11] android: Add functions for getting configuration options Szymon Janc
@ 2014-09-15 14:49 ` Szymon Janc
  2014-09-15 14:49 ` [PATCH 06/11] android/gatt: Use configuration data for device information profile Szymon Janc
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2014-09-15 14:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

---
 android/bluetooth.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index 4646a6c..c7ccf9d 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -88,8 +88,6 @@
 /* MPMD bit dependent on HFP AG support */
 #define MPS_MPMD_HFP_AG_DEP (1ULL << 6)
 
-#define DEFAULT_ADAPTER_NAME "BlueZ for Android"
-
 #define DUT_MODE_FILE "/sys/kernel/debug/bluetooth/hci%u/dut_mode"
 
 #define SETTINGS_FILE ANDROID_STORAGEDIR"/settings"
@@ -261,7 +259,11 @@ static void store_adapter_config(void)
 	ba2str(&adapter.bdaddr, addr);
 
 	g_key_file_set_string(key_file, "General", "Address", addr);
-	g_key_file_set_string(key_file, "General", "Name", adapter.name);
+
+	if (adapter.name)
+		g_key_file_set_string(key_file, "General", "Name",
+				adapter.name);
+
 	g_key_file_set_integer(key_file, "General", "DiscoverableTimeout",
 						adapter.discoverable_timeout);
 
@@ -3401,7 +3403,6 @@ static void read_info_complete(uint8_t status, uint16_t length,
 
 	if (!bacmp(&adapter.bdaddr, BDADDR_ANY)) {
 		bacpy(&adapter.bdaddr, &rp->bdaddr);
-		adapter.name = g_strdup(DEFAULT_ADAPTER_NAME);
 		store_adapter_config();
 	} else if (bacmp(&adapter.bdaddr, &rp->bdaddr)) {
 		error("Bluetooth address mismatch");
@@ -3409,7 +3410,7 @@ static void read_info_complete(uint8_t status, uint16_t length,
 		goto failed;
 	}
 
-	if (g_strcmp0(adapter.name, (const char *) rp->name))
+	if (adapter.name && g_strcmp0(adapter.name, (const char *) rp->name))
 		set_adapter_name((uint8_t *)adapter.name, strlen(adapter.name));
 
 	set_adapter_class();
@@ -5250,6 +5251,12 @@ bool bt_bluetooth_register(struct ipc *ipc, uint8_t mode)
 		goto failed;
 	}
 
+	/* Set initial default name */
+	if (!adapter.name) {
+		adapter.name = g_strdup(bt_config_get_model());
+		set_adapter_name((uint8_t *)adapter.name, strlen(adapter.name));
+	}
+
 	hal_ipc = ipc;
 
 	ipc_register(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, cmd_handlers,
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 06/11] android/gatt: Use configuration data for device information profile
  2014-09-15 14:49 [PATCH 00/11] android: Configuration command Szymon Janc
                   ` (4 preceding siblings ...)
  2014-09-15 14:49 ` [PATCH 05/11] android/bluetooth: Use model name for default adapter name Szymon Janc
@ 2014-09-15 14:49 ` Szymon Janc
  2014-09-15 14:49 ` [PATCH 07/11] android/hal-bluetooth: Add support for sending configuration Szymon Janc
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2014-09-15 14:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

---
 android/gatt.c | 115 +++++++++++++++++++++++++++++++--------------------------
 1 file changed, 63 insertions(+), 52 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index 5a1d215..b008a1d 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -6386,23 +6386,6 @@ static void register_gap_service(void)
 		error("gatt: Failed to register GAP SDP record");
 }
 
-/* TODO: Get those data from device possible via androig/bluetooth.c */
-static struct device_info {
-	const char *manufacturer_name;
-	const char *model_number;
-	const char *serial_number;
-	const char *firmware_rev;
-	const char *hardware_rev;
-	const char *software_rev;
-} device_info = {
-	.manufacturer_name =	"BlueZ for Android",
-	.model_number =		"model no",
-	.serial_number =	"serial no",
-	.firmware_rev =		"firmware rev",
-	.hardware_rev =		"hardware rev",
-	.software_rev =		"software rev",
-};
-
 static void device_info_read_cb(uint16_t handle, uint16_t offset,
 					uint8_t att_opcode, bdaddr_t *bdaddr,
 					void *user_data)
@@ -6440,6 +6423,7 @@ static void register_device_info_service(void)
 {
 	bt_uuid_t uuid;
 	uint16_t srvc_handle, end_handle;
+	const char *data;
 
 	DBG("");
 
@@ -6448,41 +6432,68 @@ static void register_device_info_service(void)
 	srvc_handle = gatt_db_add_service(gatt_db, &uuid, true, 15);
 
 	/* User data are not const hence (void *) cast is used */
-	bt_uuid16_create(&uuid, GATT_CHARAC_MODEL_NUMBER_STRING);
-	gatt_db_add_characteristic(gatt_db, srvc_handle, &uuid, GATT_PERM_READ,
-					GATT_CHR_PROP_READ,
-					device_info_read_cb, NULL,
-					(void *) device_info.model_number);
-
-	bt_uuid16_create(&uuid, GATT_CHARAC_SERIAL_NUMBER_STRING);
-	gatt_db_add_characteristic(gatt_db, srvc_handle, &uuid, GATT_PERM_READ,
-					GATT_CHR_PROP_READ,
-					device_info_read_cb, NULL,
-					(void *) device_info.serial_number);
-
-	bt_uuid16_create(&uuid, GATT_CHARAC_FIRMWARE_REVISION_STRING);
-	gatt_db_add_characteristic(gatt_db, srvc_handle, &uuid, GATT_PERM_READ,
-					GATT_CHR_PROP_READ,
-					device_info_read_cb, NULL,
-					(void *) device_info.firmware_rev);
-
-	bt_uuid16_create(&uuid, GATT_CHARAC_HARDWARE_REVISION_STRING);
-	gatt_db_add_characteristic(gatt_db, srvc_handle, &uuid, GATT_PERM_READ,
-					GATT_CHR_PROP_READ,
-					device_info_read_cb, NULL,
-					(void *) device_info.hardware_rev);
-
-	bt_uuid16_create(&uuid, GATT_CHARAC_SOFTWARE_REVISION_STRING);
-	gatt_db_add_characteristic(gatt_db, srvc_handle, &uuid, GATT_PERM_READ,
-					GATT_CHR_PROP_READ,
-					device_info_read_cb, NULL,
-					(void *) device_info.software_rev);
-
-	bt_uuid16_create(&uuid, GATT_CHARAC_MANUFACTURER_NAME_STRING);
-	gatt_db_add_characteristic(gatt_db, srvc_handle, &uuid, GATT_PERM_READ,
-					GATT_CHR_PROP_READ,
-					device_info_read_cb, NULL,
-					(void *) device_info.manufacturer_name);
+	data = bt_config_get_name();
+	if (data) {
+		bt_uuid16_create(&uuid, GATT_CHARAC_MODEL_NUMBER_STRING);
+		gatt_db_add_characteristic(gatt_db, srvc_handle, &uuid,
+						GATT_PERM_READ,
+						GATT_CHR_PROP_READ,
+						device_info_read_cb, NULL,
+						(void *) data);
+	}
+
+	/* TODO */
+	if (data) {
+		bt_uuid16_create(&uuid, GATT_CHARAC_SERIAL_NUMBER_STRING);
+		gatt_db_add_characteristic(gatt_db, srvc_handle, &uuid,
+						GATT_PERM_READ,
+						GATT_CHR_PROP_READ,
+						device_info_read_cb, NULL,
+						(void *) data);
+	}
+
+	/* TODO */
+	data = NULL;
+	if (data) {
+		bt_uuid16_create(&uuid, GATT_CHARAC_FIRMWARE_REVISION_STRING);
+		gatt_db_add_characteristic(gatt_db, srvc_handle, &uuid,
+						GATT_PERM_READ,
+						GATT_CHR_PROP_READ,
+						device_info_read_cb, NULL,
+						(void *) data);
+	}
+
+	/* TODO */
+	data = NULL;
+	if (data) {
+		bt_uuid16_create(&uuid, GATT_CHARAC_HARDWARE_REVISION_STRING);
+		gatt_db_add_characteristic(gatt_db, srvc_handle, &uuid,
+						GATT_PERM_READ,
+						GATT_CHR_PROP_READ,
+						device_info_read_cb, NULL,
+						(void *) data);
+	}
+
+	/* TODO */
+	data = NULL;
+	if (data) {
+		bt_uuid16_create(&uuid, GATT_CHARAC_SOFTWARE_REVISION_STRING);
+		gatt_db_add_characteristic(gatt_db, srvc_handle, &uuid,
+						GATT_PERM_READ,
+						GATT_CHR_PROP_READ,
+						device_info_read_cb, NULL,
+						(void *) data);
+	}
+
+	data = bt_config_get_vendor();
+	if (data) {
+		bt_uuid16_create(&uuid, GATT_CHARAC_MANUFACTURER_NAME_STRING);
+		gatt_db_add_characteristic(gatt_db, srvc_handle, &uuid,
+						GATT_PERM_READ,
+						GATT_CHR_PROP_READ,
+						device_info_read_cb, NULL,
+						(void *) data);
+	}
 
 	gatt_db_service_set_active(gatt_db, srvc_handle, true);
 
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 07/11] android/hal-bluetooth: Add support for sending configuration
  2014-09-15 14:49 [PATCH 00/11] android: Configuration command Szymon Janc
                   ` (5 preceding siblings ...)
  2014-09-15 14:49 ` [PATCH 06/11] android/gatt: Use configuration data for device information profile Szymon Janc
@ 2014-09-15 14:49 ` Szymon Janc
  2014-09-15 14:49 ` [PATCH 08/11] android/hal: Add helper for quering config from Android properties Szymon Janc
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2014-09-15 14:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

---
 android/hal-bluetooth.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 44eddbd..275ea52 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -31,6 +31,10 @@
 
 #define MODE_PROPERTY_NAME "persist.sys.bluetooth.mode"
 
+#define CONFIG_PROP_VENDOR "ro.product.manufacturer"
+#define CONFIG_PROP_NAME "ro.product.name"
+#define CONFIG_PROP_MODEL "ro.product.model"
+
 static const bt_callbacks_t *bt_hal_cbacks = NULL;
 
 #define enum_prop_to_hal(prop, hal_prop, type) do { \
@@ -405,6 +409,37 @@ static uint8_t get_mode(void)
 	return HAL_MODE_DEFAULT;
 }
 
+static int send_configuration(void)
+{
+	char buf[IPC_MTU];
+	struct hal_cmd_configuration *cmd = (void *) buf;
+	char prop[PROPERTY_VALUE_MAX];
+
+	cmd->num = 0;
+
+	if (property_get(CONFIG_PROP_VENDOR, prop, NULL) > 0) {
+		strcpy((char *) cmd->props[cmd->num].val, prop);
+		cmd->props[cmd->num].type = HAL_CONFIG_VENDOR;
+		cmd->num++;
+	}
+
+	if (property_get(CONFIG_PROP_NAME, prop, NULL) > 0) {
+		strcpy((char *) cmd->props[cmd->num].val, prop);
+		cmd->props[cmd->num].type = HAL_CONFIG_NAME;
+		cmd->num++;
+	}
+
+	if (property_get(CONFIG_PROP_MODEL, prop, NULL) > 0) {
+		strcpy((char *) cmd->props[cmd->num].val, prop);
+		cmd->props[cmd->num].type = HAL_CONFIG_MODEL;
+		cmd->num++;
+	}
+
+	return hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_CONFIGURATION,
+				sizeof(*cmd) + cmd->num * sizeof(cmd->props[0]),
+				cmd, NULL, NULL, NULL);
+}
+
 static int init(bt_callbacks_t *callbacks)
 {
 	struct hal_cmd_register_module cmd;
@@ -437,6 +472,12 @@ static int init(bt_callbacks_t *callbacks)
 		return BT_STATUS_FAIL;
 	}
 
+	status = send_configuration();
+	if (status != BT_STATUS_SUCCESS) {
+		error("Failed to send configuration");
+		goto fail;
+	}
+
 	cmd.service_id = HAL_SERVICE_ID_BLUETOOTH;
 	cmd.mode = get_mode();
 
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 08/11] android/hal: Add helper for quering config from Android properties
  2014-09-15 14:49 [PATCH 00/11] android: Configuration command Szymon Janc
                   ` (6 preceding siblings ...)
  2014-09-15 14:49 ` [PATCH 07/11] android/hal-bluetooth: Add support for sending configuration Szymon Janc
@ 2014-09-15 14:49 ` Szymon Janc
  2014-09-15 14:49 ` [PATCH 09/11] android: Use helper for accesing " Szymon Janc
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2014-09-15 14:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Helper searches config in "persis.sys.bluetooth." and "ro.bluetooth."
namespaces and allows to fallback to custom property if none is
found.
---
 android/client/if-gatt.c    |  2 ++
 android/cutils/properties.h |  1 +
 android/hal-utils.c         | 32 ++++++++++++++++++++++++++++++++
 android/hal-utils.h         |  2 ++
 4 files changed, 37 insertions(+)

diff --git a/android/client/if-gatt.c b/android/client/if-gatt.c
index 0ceffa6..f021a8b 100644
--- a/android/client/if-gatt.c
+++ b/android/client/if-gatt.c
@@ -15,6 +15,8 @@
  *
  */
 
+#include <stdbool.h>
+
 #include <hardware/bluetooth.h>
 
 #include "../hal-utils.h"
diff --git a/android/cutils/properties.h b/android/cutils/properties.h
index 43f07f1..0163eb5 100644
--- a/android/cutils/properties.h
+++ b/android/cutils/properties.h
@@ -29,6 +29,7 @@
 #include <sys/un.h>
 
 #define PROPERTY_VALUE_MAX 32
+#define PROPERTY_KEY_MAX 32
 
 #define BLUETOOTH_MODE_PROPERTY_NAME "persist.sys.bluetooth.mode"
 #define BLUETOOTH_MODE_PROPERTY_HANDSFREE "persist.sys.bluetooth.handsfree"
diff --git a/android/hal-utils.c b/android/hal-utils.c
index ceefefc..5b1ebdf 100644
--- a/android/hal-utils.c
+++ b/android/hal-utils.c
@@ -18,6 +18,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+#include <stdbool.h>
+
+#include <cutils/properties.h>
 
 #include "hal-utils.h"
 
@@ -328,3 +331,32 @@ const char *btproperty2str(const bt_property_t *property)
 
 	return buf;
 }
+
+#define PROP_PREFIX "persist.sys.bluetooth."
+#define PROP_PREFIX_RO "ro.bluetooth."
+
+int get_config(const char *config_key, char *value, const char *fallback)
+{
+	char key[PROPERTY_KEY_MAX];
+	int ret;
+
+	if (strlen(config_key) + sizeof(PROP_PREFIX) >= sizeof(key))
+		return 0;
+
+	snprintf(key, sizeof(key), PROP_PREFIX"%s", config_key);
+
+	ret = property_get(key, value, "");
+	if (ret > 0)
+		return ret;
+
+	snprintf(key, sizeof(key), PROP_PREFIX_RO"%s", config_key);
+
+	ret = property_get(key, value, "");
+	if (ret > 0)
+		return ret;
+
+	if (!fallback)
+		return 0;
+
+	return property_get(fallback, value, "");
+}
diff --git a/android/hal-utils.h b/android/hal-utils.h
index a0aab57..a2ae0f4 100644
--- a/android/hal-utils.h
+++ b/android/hal-utils.h
@@ -36,6 +36,8 @@ void str2bt_uuid_t(const char *str, bt_uuid_t *uuid);
 const char *btproperty2str(const bt_property_t *property);
 const char *bdaddr2str(const bt_bdaddr_t *bd_addr);
 
+int get_config(const char *config_key, char *value, const char *fallback);
+
 /*
  * Begin mapping section
  *
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 09/11] android: Use helper for accesing Android properties
  2014-09-15 14:49 [PATCH 00/11] android: Configuration command Szymon Janc
                   ` (7 preceding siblings ...)
  2014-09-15 14:49 ` [PATCH 08/11] android/hal: Add helper for quering config from Android properties Szymon Janc
@ 2014-09-15 14:49 ` Szymon Janc
  2014-09-15 14:49 ` [PATCH 10/11] android/bluetoothd-wrapper: Fix indentation Szymon Janc
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2014-09-15 14:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

---
 android/Android.mk           |  3 ++-
 android/bluetoothd-wrapper.c | 13 +++++--------
 android/hal-bluetooth.c      | 24 +++++++++---------------
 android/hal-handsfree.c      | 15 +++++++--------
 4 files changed, 23 insertions(+), 32 deletions(-)

diff --git a/android/Android.mk b/android/Android.mk
index b2b55f7..bce1019 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -627,7 +627,8 @@ ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := \
-	bluez/android/bluetoothd-wrapper.c
+	bluez/android/bluetoothd-wrapper.c \
+	bluez/android/hal-utils.c
 
 LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS)
 
diff --git a/android/bluetoothd-wrapper.c b/android/bluetoothd-wrapper.c
index 90ed292..5e15dd8 100644
--- a/android/bluetoothd-wrapper.c
+++ b/android/bluetoothd-wrapper.c
@@ -19,14 +19,11 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <stdbool.h>
 
 #include <cutils/properties.h>
 
-#define PROPERTY_VALGRIND_NAME "persist.sys.bluetooth.valgrind"
-
-#define PROPERTY_DEBUG_NAME "persist.sys.bluetooth.debug"
-
-#define PROPERTY_MGMT_DEBUG_NAME "persist.sys.bluetooth.mgmtdbg"
+#include "hal-utils.h"
 
 #define VALGRIND_BIN "/system/bin/valgrind"
 
@@ -73,17 +70,17 @@ int main(int argc, char *argv[])
 	int debug = 0;
 	int mgmt_dbg = 0;
 
-	if (property_get(PROPERTY_DEBUG_NAME, value, "") > 0 &&
+	if (get_config("debug", value, NULL) > 0 &&
 			(!strcasecmp(value, "true") || atoi(value) > 0))
 			debug = 1;
 
-	if (property_get(PROPERTY_MGMT_DEBUG_NAME, value, "") > 0 &&
+	if (get_config("mgmtdbg", value, NULL) > 0 &&
 			(!strcasecmp(value, "true") || atoi(value) > 0)) {
 			debug = 1;
 			mgmt_dbg = 1;
 	}
 
-	if (property_get(PROPERTY_VALGRIND_NAME, value, "") > 0 &&
+	if (get_config("valgrind", value, NULL) > 0 &&
 			(!strcasecmp(value, "true") || atoi(value) > 0))
 		run_valgrind(debug, mgmt_dbg);
 
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 275ea52..5eac39b 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -29,12 +29,6 @@
 #include "hal-ipc.h"
 #include "hal-utils.h"
 
-#define MODE_PROPERTY_NAME "persist.sys.bluetooth.mode"
-
-#define CONFIG_PROP_VENDOR "ro.product.manufacturer"
-#define CONFIG_PROP_NAME "ro.product.name"
-#define CONFIG_PROP_MODEL "ro.product.model"
-
 static const bt_callbacks_t *bt_hal_cbacks = NULL;
 
 #define enum_prop_to_hal(prop, hal_prop, type) do { \
@@ -398,13 +392,13 @@ static uint8_t get_mode(void)
 {
 	char value[PROPERTY_VALUE_MAX];
 
-	if (property_get(MODE_PROPERTY_NAME, value, "") > 0 &&
-					(!strcasecmp(value, "bredr")))
-		return HAL_MODE_BREDR;
+	if (get_config("mode", value, NULL) > 0) {
+		if (!strcasecmp(value, "bredr"))
+			return HAL_MODE_BREDR;
 
-	if (property_get(MODE_PROPERTY_NAME, value, "") > 0 &&
-					(!strcasecmp(value, "le")))
-		return HAL_MODE_LE;
+		if (!strcasecmp(value, "le"))
+			return HAL_MODE_LE;
+	}
 
 	return HAL_MODE_DEFAULT;
 }
@@ -417,19 +411,19 @@ static int send_configuration(void)
 
 	cmd->num = 0;
 
-	if (property_get(CONFIG_PROP_VENDOR, prop, NULL) > 0) {
+	if (get_config("vendor", prop, "ro.product.manufacturer") > 0) {
 		strcpy((char *) cmd->props[cmd->num].val, prop);
 		cmd->props[cmd->num].type = HAL_CONFIG_VENDOR;
 		cmd->num++;
 	}
 
-	if (property_get(CONFIG_PROP_NAME, prop, NULL) > 0) {
+	if (get_config("name", prop, "ro.product.name") > 0) {
 		strcpy((char *) cmd->props[cmd->num].val, prop);
 		cmd->props[cmd->num].type = HAL_CONFIG_NAME;
 		cmd->num++;
 	}
 
-	if (property_get(CONFIG_PROP_MODEL, prop, NULL) > 0) {
+	if (get_config("model", prop, "ro.product.model") > 0) {
 		strcpy((char *) cmd->props[cmd->num].val, prop);
 		cmd->props[cmd->num].type = HAL_CONFIG_MODEL;
 		cmd->num++;
diff --git a/android/hal-handsfree.c b/android/hal-handsfree.c
index 986e745..0c51789 100644
--- a/android/hal-handsfree.c
+++ b/android/hal-handsfree.c
@@ -27,8 +27,7 @@
 #include "hal-msg.h"
 #include "ipc-common.h"
 #include "hal-ipc.h"
-
-#define MODE_PROPERTY_NAME "persist.sys.bluetooth.handsfree"
+#include "hal-utils.h"
 
 static const bthf_callbacks_t *cbs = NULL;
 
@@ -216,13 +215,13 @@ static uint8_t get_mode(void)
 {
 	char value[PROPERTY_VALUE_MAX];
 
-	if (property_get(MODE_PROPERTY_NAME, value, "") > 0 &&
-					(!strcasecmp(value, "hfp")))
-		return HAL_MODE_HANDSFREE_HFP;
+	if (get_config("handsfree", value, NULL) > 0) {
+		if (!strcasecmp(value, "hfp"))
+			return HAL_MODE_HANDSFREE_HFP;
 
-	if (property_get(MODE_PROPERTY_NAME, value, "") > 0 &&
-					(!strcasecmp(value, "hfp_wbs")))
-		return HAL_MODE_HANDSFREE_HFP_WBS;
+		if (!strcasecmp(value, "hfp_wbs"))
+			return HAL_MODE_HANDSFREE_HFP_WBS;
+	}
 
 	return HAL_MODE_HANDSFREE_HSP_ONLY;
 }
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 10/11] android/bluetoothd-wrapper: Fix indentation
  2014-09-15 14:49 [PATCH 00/11] android: Configuration command Szymon Janc
                   ` (8 preceding siblings ...)
  2014-09-15 14:49 ` [PATCH 09/11] android: Use helper for accesing " Szymon Janc
@ 2014-09-15 14:49 ` Szymon Janc
  2014-09-15 14:49 ` [PATCH 11/11] android/README: Update customization section Szymon Janc
  2014-09-22 14:44 ` [PATCH 00/11] android: Configuration command Szymon Janc
  11 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2014-09-15 14:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

---
 android/bluetoothd-wrapper.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/android/bluetoothd-wrapper.c b/android/bluetoothd-wrapper.c
index 5e15dd8..7f668da 100644
--- a/android/bluetoothd-wrapper.c
+++ b/android/bluetoothd-wrapper.c
@@ -72,12 +72,12 @@ int main(int argc, char *argv[])
 
 	if (get_config("debug", value, NULL) > 0 &&
 			(!strcasecmp(value, "true") || atoi(value) > 0))
-			debug = 1;
+		debug = 1;
 
 	if (get_config("mgmtdbg", value, NULL) > 0 &&
 			(!strcasecmp(value, "true") || atoi(value) > 0)) {
-			debug = 1;
-			mgmt_dbg = 1;
+		debug = 1;
+		mgmt_dbg = 1;
 	}
 
 	if (get_config("valgrind", value, NULL) > 0 &&
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 11/11] android/README: Update customization section
  2014-09-15 14:49 [PATCH 00/11] android: Configuration command Szymon Janc
                   ` (9 preceding siblings ...)
  2014-09-15 14:49 ` [PATCH 10/11] android/bluetoothd-wrapper: Fix indentation Szymon Janc
@ 2014-09-15 14:49 ` Szymon Janc
  2014-09-22 14:44 ` [PATCH 00/11] android: Configuration command Szymon Janc
  11 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2014-09-15 14:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

---
 android/README | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/android/README b/android/README
index 20b61a6..bbbcb5f 100644
--- a/android/README
+++ b/android/README
@@ -190,9 +190,11 @@ It is possible to customize BlueZ for Android through Android system properties.
 This may include enabling extra profiles or features inside HALs implementation
 These properties are read on Bluetooth stack startup only and require stack
 restart if changed. All customization properties names start with
-"persist.sys.bluetooth." followed by specific HAL name e.g.
-"persist.sys.bluetooth.handsfree". This section list available customization
-options.
+"persist.sys.bluetooth." or "ro.bluerooth." followed by specific HAL name e.g.
+"persist.sys.bluetooth.handsfree". If both are present "persist.sys.bluetooth."
+takes precedence. This allows for read only properties to be set during build
+leaving enough flexibility for developing or debugging purposes.
+This section list available customization options.
 
 Property	Value		Description
 -------------------------------------------
@@ -205,6 +207,12 @@ handsfree	hfp		Enable Handsfree Profile (HFP) with narrowband
 		hfp_wbs		Enable Handsfree Profile (HFP) with narrowband
 				and wideband speech support
 		<none>		Don't enable Handsfree Profile (HFP)
+vendor		<any>		Set vendor name in DIS. If not set fallback to
+				"ro.product.manufacturer".
+model		<any>		Set model name used as default adapter name.
+				If not set fallback to "ro.product.model".
+name		<any>		Set model number in DIS. If not set fallback to
+				"ro.product.name".
 
 
 Building and running on Linux
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 00/11] android: Configuration command
  2014-09-15 14:49 [PATCH 00/11] android: Configuration command Szymon Janc
                   ` (10 preceding siblings ...)
  2014-09-15 14:49 ` [PATCH 11/11] android/README: Update customization section Szymon Janc
@ 2014-09-22 14:44 ` Szymon Janc
  11 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2014-09-22 14:44 UTC (permalink / raw)
  To: linux-bluetooth

On Monday 15 of September 2014 16:49:04 Szymon Janc wrote:
> Hi,
> 
> This is a respin of serie that was send some time ago as RFC [1]
> 
> This will allow to pass Android properties over IPC and use them
> in daemon for customization eg. Device Information or default adapter name.
> 
> Comments from RFC was taken into account. So now "ro.bluetooth.*"
> and "sys.persist.bluetooth.*" are taken into account (former takes
> precedence if both are present). Some configs also fallback to
> generic properties if no bluetooth ones are present.
> 
> Comments are welcome.
> 
> BR
> Szymon Janc
> 
> [1] "[RFC 0/6] android: Configuration command"
> 
> 
> Szymon Janc (11):
>   android/hal-ipc-api: Add Configuration command
>   android/hal-msg: Add configuration command
>   android: Add support for configuration command
>   android: Add functions for getting configuration options
>   android/bluetooth: Use model name for default adapter name
>   android/gatt: Use configuration data for device information profile
>   android/hal-bluetooth: Add support for sending configuration
>   android/hal: Add helper for quering config from Android properties
>   android: Use helper for accesing Android properties
>   android/bluetoothd-wrapper: Fix indentation
>   android/README: Update customization section
> 
>  android/Android.mk           |   3 +-
>  android/README               |  14 ++++--
>  android/bluetooth.c          |  17 +++++--
>  android/bluetoothd-wrapper.c |  19 +++----
>  android/client/if-gatt.c     |   2 +
>  android/cutils/properties.h  |   1 +
>  android/gatt.c               | 115 ++++++++++++++++++++++++-------------------
>  android/hal-bluetooth.c      |  51 ++++++++++++++++---
>  android/hal-handsfree.c      |  15 +++---
>  android/hal-ipc-api.txt      |  16 ++++++
>  android/hal-msg.h            |  17 +++++++
>  android/hal-utils.c          |  32 ++++++++++++
>  android/hal-utils.h          |   2 +
>  android/main.c               |  94 +++++++++++++++++++++++++++++++++++
>  android/utils.h              |   4 ++
>  15 files changed, 314 insertions(+), 88 deletions(-)
> 

Applied with some changes to make configure options TLV instead of fixed size
arrays.

-- 
Best regards, 
Szymon Janc

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-09-22 14:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-15 14:49 [PATCH 00/11] android: Configuration command Szymon Janc
2014-09-15 14:49 ` [PATCH 01/11] android/hal-ipc-api: Add " Szymon Janc
2014-09-15 14:49 ` [PATCH 02/11] android/hal-msg: Add configuration command Szymon Janc
2014-09-15 14:49 ` [PATCH 03/11] android: Add support for " Szymon Janc
2014-09-15 14:49 ` [PATCH 04/11] android: Add functions for getting configuration options Szymon Janc
2014-09-15 14:49 ` [PATCH 05/11] android/bluetooth: Use model name for default adapter name Szymon Janc
2014-09-15 14:49 ` [PATCH 06/11] android/gatt: Use configuration data for device information profile Szymon Janc
2014-09-15 14:49 ` [PATCH 07/11] android/hal-bluetooth: Add support for sending configuration Szymon Janc
2014-09-15 14:49 ` [PATCH 08/11] android/hal: Add helper for quering config from Android properties Szymon Janc
2014-09-15 14:49 ` [PATCH 09/11] android: Use helper for accesing " Szymon Janc
2014-09-15 14:49 ` [PATCH 10/11] android/bluetoothd-wrapper: Fix indentation Szymon Janc
2014-09-15 14:49 ` [PATCH 11/11] android/README: Update customization section Szymon Janc
2014-09-22 14:44 ` [PATCH 00/11] android: Configuration command Szymon Janc

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