Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 1/3] android/hal-utils: Refactor btproperty2str
@ 2014-11-27 17:04 Szymon Janc
  2014-11-27 17:04 ` [PATCH 2/3] android/client: Add option to initialize only IVI roles Szymon Janc
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Szymon Janc @ 2014-11-27 17:04 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This function grown to big. Factor out more complex properties to
separate helper functions.
---
 android/hal-utils.c | 168 ++++++++++++++++++++++++----------------------------
 1 file changed, 76 insertions(+), 92 deletions(-)

diff --git a/android/hal-utils.c b/android/hal-utils.c
index f18a82c..3c640b7 100644
--- a/android/hal-utils.c
+++ b/android/hal-utils.c
@@ -258,8 +258,77 @@ const char *bdaddr2str(const bt_bdaddr_t *bd_addr)
 	return bt_bdaddr_t2str(bd_addr, buf);
 }
 
+static void bonded_devices2string(char *str, void *prop, int prop_len)
+{
+	int count = prop_len / sizeof(bt_bdaddr_t);
+	bt_bdaddr_t *addr = prop;
+
+	strcat(str, "{");
+
+	while (count--) {
+		strcat(str, bdaddr2str(addr));
+		if (count)
+			strcat(str, ", ");
+		addr++;
+	}
+
+	strcat(str, "}");
+}
+
+static void uuids2string(char *str, void *prop, int prop_len)
+{
+	int count = prop_len / sizeof(bt_uuid_t);
+	bt_uuid_t *uuid = prop;
+
+	strcat(str, "{");
+
+	while (count--) {
+		strcat(str, btuuid2str(uuid->uu));
+		if (count)
+			strcat(str, ", ");
+		uuid++;
+	}
+
+	strcat(str, "}");
+}
+
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void local_le_feat2string(char *str, const bt_local_le_features_t *f)
+{
+	uint16_t scan_num;
+
+	str += sprintf(str, "{\n");
+
+	str += sprintf(str, "Privacy supported: %s,\n",
+				f->local_privacy_enabled ? "TRUE" : "FALSE");
+
+	str += sprintf(str, "Num of advertising instances: %u,\n",
+							f->max_adv_instance);
+
+	str += sprintf(str, "PRA offloading support: %s,\n",
+				f->rpa_offload_supported ? "TRUE" : "FALSE");
+
+	str += sprintf(str, "Num of offloaded IRKs: %u,\n",
+							f->max_irk_list_size);
+
+	str += sprintf(str, "Num of offloaded scan filters: %u,\n",
+						f->max_adv_filter_supported);
+
+	scan_num = (f->scan_result_storage_size_hibyte << 8) +
+					f->scan_result_storage_size_lobyte;
+
+	str += sprintf(str, "Num of offloaded scan results: %u,\n", scan_num);
+
+	str += sprintf(str, "Activity & energy report support: %s\n",
+			f->activity_energy_info_supported ? "TRUE" : "FALSE");
+
+	sprintf(str, "}");
+}
+#endif
+
 const char *btproperty2str(const bt_property_t *property)
 {
+	bt_service_record_t *rec;
 	static char buf[4096];
 	char *p;
 
@@ -273,130 +342,45 @@ const char *btproperty2str(const bt_property_t *property)
 		snprintf(p, property->len + 1, "%s",
 					((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)));
+					*((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, "}");
-
-		}
+		bonded_devices2string(p, property->val, property->len);
 		break;
-
 	case BT_PROPERTY_UUIDS:
-		{
-			int count = property->len / sizeof(bt_uuid_t);
-			uint8_t *ptr = property->val;
-
-			strcat(p, "{");
-
-			while (count--) {
-				strcat(p, btuuid2str(ptr));
-				if (count)
-					strcat(p, ", ");
-				ptr += sizeof(bt_uuid_t);
-			}
-
-			strcat(p, "}");
-
-		}
+		uuids2string(p, property->val, property->len);
 		break;
-
 	case BT_PROPERTY_SERVICE_RECORD:
-		{
-			bt_service_record_t *rec = property->val;
-
-			sprintf(p, "{%s, %d, %s}", btuuid2str(rec->uuid.uu),
+		rec = property->val;
+		sprintf(p, "{%s, %d, %s}", btuuid2str(rec->uuid.uu),
 						rec->channel, rec->name);
-		}
 		break;
 #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
 	case BT_PROPERTY_LOCAL_LE_FEATURES:
-		{
-			bt_local_le_features_t *f = property->val;
-			int l;
-			uint16_t s;
-
-			l = sprintf(p, "{\n");
-			p += l;
-
-			l = sprintf(p, "Privacy supported: %s,\n",
-						f->local_privacy_enabled ?
-						"TRUE" : "FALSE");
-			p += l;
-
-			l = sprintf(p, "Num of advertising instances: %u,\n",
-							f->max_adv_instance);
-			p += l;
-
-			l = sprintf(p, "PRA offloading support: %s,\n",
-						f->rpa_offload_supported ?
-						"TRUE" : "FALSE");
-
-			p += l;
-
-			l = sprintf(p, "Num of offloaded IRKs: %u,\n",
-							f->max_irk_list_size);
-			p += l;
-
-			l = sprintf(p, "Num of offloaded scan filters: %u,\n",
-						f->max_adv_filter_supported);
-			p += l;
-
-			s = (f->scan_result_storage_size_hibyte << 8) +
-					f->scan_result_storage_size_lobyte;
-
-			l = sprintf(p, "Num of offloaded scan results: %u,\n",
-									s);
-			p += l;
-
-			l = sprintf(p, "Activity & energy report support: %s\n",
-					f->activity_energy_info_supported ?
-					"TRUE" : "FALSE");
-			p += l;
-
-			sprintf(p, "}");
-		}
+		local_le_feat2string(p, property->val);
 		break;
 #endif
 	default:
 		sprintf(p, "%p", property->val);
+		break;
 	}
 
 	return buf;
-- 
1.9.1


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

* [PATCH 2/3] android/client: Add option to initialize only IVI roles
  2014-11-27 17:04 [PATCH 1/3] android/hal-utils: Refactor btproperty2str Szymon Janc
@ 2014-11-27 17:04 ` Szymon Janc
  2014-11-27 17:04 ` [PATCH 3/3] android/client: Add short option for printing version Szymon Janc
  2014-12-15 11:41 ` [PATCH 1/3] android/hal-utils: Refactor btproperty2str Szymon Janc
  2 siblings, 0 replies; 4+ messages in thread
From: Szymon Janc @ 2014-11-27 17:04 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This adds 'ivi' option for haltest. With this option only IVI roles
will be initialized. Running haltest without options will initialize
only non-ivi roles.
---
 android/client/haltest.c | 59 +++++++++++++++++++++++++++++++-----------------
 1 file changed, 38 insertions(+), 21 deletions(-)

diff --git a/android/client/haltest.c b/android/client/haltest.c
index add1978..0eaa43d 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -336,7 +336,8 @@ static void usage(void)
 		"Usage:\n");
 	printf("\thaltest [options]\n");
 	printf("options:\n"
-		"\t-n, --no-init          Don't call init for interfaces\n"
+		"\t-i  --ivi              Initialize only IVI interfaces\n"
+		"\t-n, --no-init          Don't initialize any interfaces\n"
 		"\t    --version          Print version\n"
 		"\t-h, --help             Show help options\n");
 }
@@ -352,19 +353,21 @@ static void print_version(void)
 
 static const struct option main_options[] = {
 	{ "no-init", no_argument, NULL, 'n' },
+	{ "ivi",     no_argument, NULL, 'i' },
 	{ "help",    no_argument, NULL, 'h' },
 	{ "version", no_argument, NULL, PRINT_VERSION },
 	{ NULL }
 };
 
 static bool no_init = false;
+static bool ivi_only = false;
 
 static void parse_command_line(int argc, char *argv[])
 {
 	for (;;) {
 		int opt;
 
-		opt = getopt_long(argc, argv, "nh", main_options, NULL);
+		opt = getopt_long(argc, argv, "inh", main_options, NULL);
 		if (opt < 0)
 			break;
 
@@ -372,6 +375,9 @@ static void parse_command_line(int argc, char *argv[])
 		case 'n':
 			no_init = true;
 			break;
+		case 'i':
+			ivi_only = true;
+			break;
 		case 'h':
 			usage();
 			exit(0);
@@ -386,23 +392,29 @@ static void parse_command_line(int argc, char *argv[])
 	}
 }
 
-static void init(void)
-{
-	static const char * const inames[] = {
-		BT_PROFILE_HANDSFREE_ID,
-		BT_PROFILE_ADVANCED_AUDIO_ID,
-		BT_PROFILE_AV_RC_ID,
-		BT_PROFILE_HEALTH_ID,
-		BT_PROFILE_HIDHOST_ID,
-		BT_PROFILE_PAN_ID,
-		BT_PROFILE_GATT_ID,
-		BT_PROFILE_SOCKETS_ID,
+static const char * const interface_names[] = {
+	BT_PROFILE_HANDSFREE_ID,
+	BT_PROFILE_ADVANCED_AUDIO_ID,
+	BT_PROFILE_AV_RC_ID,
+	BT_PROFILE_HEALTH_ID,
+	BT_PROFILE_HIDHOST_ID,
+	BT_PROFILE_PAN_ID,
+	BT_PROFILE_GATT_ID,
+	BT_PROFILE_SOCKETS_ID,
+	NULL
+};
+
+static const char * const ivi_interface_inames[] = {
 #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
-		BT_PROFILE_HANDSFREE_CLIENT_ID,
-		BT_PROFILE_MAP_CLIENT_ID,
-		BT_PROFILE_AV_RC_CTRL_ID,
+	BT_PROFILE_HANDSFREE_CLIENT_ID,
+	BT_PROFILE_MAP_CLIENT_ID,
+	BT_PROFILE_AV_RC_CTRL_ID,
 #endif
-	};
+	NULL
+};
+
+static void init(const char * const *inames)
+{
 	const struct method *m;
 	const char *argv[4];
 	char init_audio[] = "audio init";
@@ -416,9 +428,10 @@ static void init(void)
 
 	m = get_interface_method("bluetooth", "get_profile_interface");
 
-	for (i = 0; i < NELEM(inames); ++i) {
-		argv[2] = inames[i];
+	while (*inames) {
+		argv[2] = *inames;
 		m->func(3, argv);
+		inames++;
 	}
 
 	/* Init what is available to init */
@@ -437,8 +450,12 @@ int main(int argc, char **argv)
 
 	terminal_setup();
 
-	if (!no_init)
-		init();
+	if (!no_init) {
+		if (ivi_only)
+			init(ivi_interface_inames);
+		else
+			init(interface_names);
+	}
 
 	history_restore(".haltest_history");
 
-- 
1.9.1


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

* [PATCH 3/3] android/client: Add short option for printing version
  2014-11-27 17:04 [PATCH 1/3] android/hal-utils: Refactor btproperty2str Szymon Janc
  2014-11-27 17:04 ` [PATCH 2/3] android/client: Add option to initialize only IVI roles Szymon Janc
@ 2014-11-27 17:04 ` Szymon Janc
  2014-12-15 11:41 ` [PATCH 1/3] android/hal-utils: Refactor btproperty2str Szymon Janc
  2 siblings, 0 replies; 4+ messages in thread
From: Szymon Janc @ 2014-11-27 17:04 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This makes haltest options consistent.
---
 android/client/haltest.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/android/client/haltest.c b/android/client/haltest.c
index 0eaa43d..d514122 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -338,14 +338,10 @@ static void usage(void)
 	printf("options:\n"
 		"\t-i  --ivi              Initialize only IVI interfaces\n"
 		"\t-n, --no-init          Don't initialize any interfaces\n"
-		"\t    --version          Print version\n"
+		"\t-v  --version          Print version\n"
 		"\t-h, --help             Show help options\n");
 }
 
-enum {
-	PRINT_VERSION = 1000
-};
-
 static void print_version(void)
 {
 	printf("haltest version %s\n", VERSION);
@@ -355,7 +351,7 @@ static const struct option main_options[] = {
 	{ "no-init", no_argument, NULL, 'n' },
 	{ "ivi",     no_argument, NULL, 'i' },
 	{ "help",    no_argument, NULL, 'h' },
-	{ "version", no_argument, NULL, PRINT_VERSION },
+	{ "version", no_argument, NULL, 'v' },
 	{ NULL }
 };
 
@@ -367,7 +363,7 @@ static void parse_command_line(int argc, char *argv[])
 	for (;;) {
 		int opt;
 
-		opt = getopt_long(argc, argv, "inh", main_options, NULL);
+		opt = getopt_long(argc, argv, "inhv", main_options, NULL);
 		if (opt < 0)
 			break;
 
@@ -381,7 +377,7 @@ static void parse_command_line(int argc, char *argv[])
 		case 'h':
 			usage();
 			exit(0);
-		case PRINT_VERSION:
+		case 'v':
 			print_version();
 			exit(0);
 		default:
-- 
1.9.1


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

* Re: [PATCH 1/3] android/hal-utils: Refactor btproperty2str
  2014-11-27 17:04 [PATCH 1/3] android/hal-utils: Refactor btproperty2str Szymon Janc
  2014-11-27 17:04 ` [PATCH 2/3] android/client: Add option to initialize only IVI roles Szymon Janc
  2014-11-27 17:04 ` [PATCH 3/3] android/client: Add short option for printing version Szymon Janc
@ 2014-12-15 11:41 ` Szymon Janc
  2 siblings, 0 replies; 4+ messages in thread
From: Szymon Janc @ 2014-12-15 11:41 UTC (permalink / raw)
  To: linux-bluetooth

On Thursday 27 of November 2014 18:04:38 Szymon Janc wrote:
> This function grown to big. Factor out more complex properties to
> separate helper functions.
> ---
>  android/hal-utils.c | 168 ++++++++++++++++++++++++----------------------------
>  1 file changed, 76 insertions(+), 92 deletions(-)
> 
> diff --git a/android/hal-utils.c b/android/hal-utils.c
> index f18a82c..3c640b7 100644
> --- a/android/hal-utils.c
> +++ b/android/hal-utils.c
> @@ -258,8 +258,77 @@ const char *bdaddr2str(const bt_bdaddr_t *bd_addr)
>  	return bt_bdaddr_t2str(bd_addr, buf);
>  }
>  
> +static void bonded_devices2string(char *str, void *prop, int prop_len)
> +{
> +	int count = prop_len / sizeof(bt_bdaddr_t);
> +	bt_bdaddr_t *addr = prop;
> +
> +	strcat(str, "{");
> +
> +	while (count--) {
> +		strcat(str, bdaddr2str(addr));
> +		if (count)
> +			strcat(str, ", ");
> +		addr++;
> +	}
> +
> +	strcat(str, "}");
> +}
> +
> +static void uuids2string(char *str, void *prop, int prop_len)
> +{
> +	int count = prop_len / sizeof(bt_uuid_t);
> +	bt_uuid_t *uuid = prop;
> +
> +	strcat(str, "{");
> +
> +	while (count--) {
> +		strcat(str, btuuid2str(uuid->uu));
> +		if (count)
> +			strcat(str, ", ");
> +		uuid++;
> +	}
> +
> +	strcat(str, "}");
> +}
> +
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +static void local_le_feat2string(char *str, const bt_local_le_features_t *f)
> +{
> +	uint16_t scan_num;
> +
> +	str += sprintf(str, "{\n");
> +
> +	str += sprintf(str, "Privacy supported: %s,\n",
> +				f->local_privacy_enabled ? "TRUE" : "FALSE");
> +
> +	str += sprintf(str, "Num of advertising instances: %u,\n",
> +							f->max_adv_instance);
> +
> +	str += sprintf(str, "PRA offloading support: %s,\n",
> +				f->rpa_offload_supported ? "TRUE" : "FALSE");
> +
> +	str += sprintf(str, "Num of offloaded IRKs: %u,\n",
> +							f->max_irk_list_size);
> +
> +	str += sprintf(str, "Num of offloaded scan filters: %u,\n",
> +						f->max_adv_filter_supported);
> +
> +	scan_num = (f->scan_result_storage_size_hibyte << 8) +
> +					f->scan_result_storage_size_lobyte;
> +
> +	str += sprintf(str, "Num of offloaded scan results: %u,\n", scan_num);
> +
> +	str += sprintf(str, "Activity & energy report support: %s\n",
> +			f->activity_energy_info_supported ? "TRUE" : "FALSE");
> +
> +	sprintf(str, "}");
> +}
> +#endif
> +
>  const char *btproperty2str(const bt_property_t *property)
>  {
> +	bt_service_record_t *rec;
>  	static char buf[4096];
>  	char *p;
>  
> @@ -273,130 +342,45 @@ const char *btproperty2str(const bt_property_t *property)
>  		snprintf(p, property->len + 1, "%s",
>  					((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)));
> +					*((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, "}");
> -
> -		}
> +		bonded_devices2string(p, property->val, property->len);
>  		break;
> -
>  	case BT_PROPERTY_UUIDS:
> -		{
> -			int count = property->len / sizeof(bt_uuid_t);
> -			uint8_t *ptr = property->val;
> -
> -			strcat(p, "{");
> -
> -			while (count--) {
> -				strcat(p, btuuid2str(ptr));
> -				if (count)
> -					strcat(p, ", ");
> -				ptr += sizeof(bt_uuid_t);
> -			}
> -
> -			strcat(p, "}");
> -
> -		}
> +		uuids2string(p, property->val, property->len);
>  		break;
> -
>  	case BT_PROPERTY_SERVICE_RECORD:
> -		{
> -			bt_service_record_t *rec = property->val;
> -
> -			sprintf(p, "{%s, %d, %s}", btuuid2str(rec->uuid.uu),
> +		rec = property->val;
> +		sprintf(p, "{%s, %d, %s}", btuuid2str(rec->uuid.uu),
>  						rec->channel, rec->name);
> -		}
>  		break;
>  #if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
>  	case BT_PROPERTY_LOCAL_LE_FEATURES:
> -		{
> -			bt_local_le_features_t *f = property->val;
> -			int l;
> -			uint16_t s;
> -
> -			l = sprintf(p, "{\n");
> -			p += l;
> -
> -			l = sprintf(p, "Privacy supported: %s,\n",
> -						f->local_privacy_enabled ?
> -						"TRUE" : "FALSE");
> -			p += l;
> -
> -			l = sprintf(p, "Num of advertising instances: %u,\n",
> -							f->max_adv_instance);
> -			p += l;
> -
> -			l = sprintf(p, "PRA offloading support: %s,\n",
> -						f->rpa_offload_supported ?
> -						"TRUE" : "FALSE");
> -
> -			p += l;
> -
> -			l = sprintf(p, "Num of offloaded IRKs: %u,\n",
> -							f->max_irk_list_size);
> -			p += l;
> -
> -			l = sprintf(p, "Num of offloaded scan filters: %u,\n",
> -						f->max_adv_filter_supported);
> -			p += l;
> -
> -			s = (f->scan_result_storage_size_hibyte << 8) +
> -					f->scan_result_storage_size_lobyte;
> -
> -			l = sprintf(p, "Num of offloaded scan results: %u,\n",
> -									s);
> -			p += l;
> -
> -			l = sprintf(p, "Activity & energy report support: %s\n",
> -					f->activity_energy_info_supported ?
> -					"TRUE" : "FALSE");
> -			p += l;
> -
> -			sprintf(p, "}");
> -		}
> +		local_le_feat2string(p, property->val);
>  		break;
>  #endif
>  	default:
>  		sprintf(p, "%p", property->val);
> +		break;
>  	}
>  
>  	return buf;
> 

Pushed.

-- 
Best regards, 
Szymon Janc

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

end of thread, other threads:[~2014-12-15 11:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-27 17:04 [PATCH 1/3] android/hal-utils: Refactor btproperty2str Szymon Janc
2014-11-27 17:04 ` [PATCH 2/3] android/client: Add option to initialize only IVI roles Szymon Janc
2014-11-27 17:04 ` [PATCH 3/3] android/client: Add short option for printing version Szymon Janc
2014-12-15 11:41 ` [PATCH 1/3] android/hal-utils: Refactor btproperty2str Szymon Janc

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