Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 1/3] android/avdtptest: Add option to enable stream configuration
@ 2014-09-02 13:53 Szymon Janc
  2014-09-02 13:53 ` [PATCH 2/3] android/avdtptest: Add support for sending commands Szymon Janc
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Szymon Janc @ 2014-09-02 13:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Instead of specifing initiator role use option that allows to perform
stream configuration.
---
 android/avdtptest.c | 50 ++++++++++----------------------------------------
 1 file changed, 10 insertions(+), 40 deletions(-)

diff --git a/android/avdtptest.c b/android/avdtptest.c
index adbf7af..c8f7340 100644
--- a/android/avdtptest.c
+++ b/android/avdtptest.c
@@ -44,7 +44,7 @@
 
 static GMainLoop *mainloop = NULL;
 static int dev_role = AVDTP_SEP_TYPE_SOURCE;
-static bool initiator = false;
+static bool preconf = false;
 static struct avdtp *avdtp = NULL;
 struct avdtp_stream *avdtp_stream = NULL;
 struct avdtp_local_sep *local_sep = NULL;
@@ -237,7 +237,7 @@ static void set_configuration_cfm(struct avdtp *session,
 {
 	printf("%s\n", __func__);
 
-	if (initiator)
+	if (preconf)
 		avdtp_open(avdtp, avdtp_stream);
 }
 
@@ -289,21 +289,6 @@ static void discover_cb(struct avdtp *session, GSList *seps,
 	}
 }
 
-static gboolean idle_timeout(gpointer user_data)
-{
-	int err;
-
-	idle_id = 0;
-
-	err = avdtp_discover(avdtp, discover_cb, NULL);
-	if (err < 0) {
-		printf("avdtp_discover failed: %s", strerror(-err));
-		g_main_loop_quit(mainloop);
-	}
-
-	return FALSE;
-}
-
 static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
 {
 	uint16_t imtu, omtu;
@@ -339,9 +324,6 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
 
 		g_io_channel_set_close_on_unref(chan, FALSE);
 
-		if (initiator)
-			avdtp_start(avdtp, avdtp_stream);
-
 		return;
 	}
 
@@ -355,7 +337,7 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
 
 	avdtp_add_disconnect_cb(avdtp, disconnect_cb, NULL);
 
-	if (initiator) {
+	if (preconf) {
 		int ret;
 
 		ret = avdtp_discover(avdtp, discover_cb, NULL);
@@ -363,8 +345,6 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
 			printf("avdtp_discover failed: %s", strerror(-ret));
 			g_main_loop_quit(mainloop);
 		}
-	} else {
-		idle_id = g_timeout_add_seconds(1, idle_timeout, NULL);
 	}
 }
 
@@ -395,9 +375,6 @@ static void open_cfm(struct avdtp *session, struct avdtp_local_sep *lsep,
 
 	printf("%s\n", __func__);
 
-	if (!initiator)
-		return;
-
 	do_connect(&gerr);
 	if (gerr) {
 		printf("connect failed: %s\n", gerr->message);
@@ -685,23 +662,23 @@ static void usage(void)
 		"\tavdtptest [options]\n");
 	printf("options:\n"
 		"\t-d <device_role>   SRC (source) or SINK (sink)\n"
-		"\t-s <stream_role>   INT (initiator) or ACP (acceptor)\n"
 		"\t-i <hcidev>        HCI adapter\n"
 		"\t-c <bdaddr>        connect\n"
 		"\t-l                 listen\n"
 		"\t-r                 reject commands\n"
-		"\t-f                 fragment\n");
+		"\t-f                 fragment\n"
+		"-t-p                 configure stream\n");
 }
 
 static struct option main_options[] = {
 	{ "help",		0, 0, 'h' },
 	{ "device_role",	1, 0, 'd' },
-	{ "stream_role",	1, 0, 's' },
 	{ "adapter",		1, 0, 'i' },
 	{ "connect",		1, 0, 'c' },
 	{ "listen",		0, 0, 'l' },
 	{ "reject",		0, 0, 'r' },
 	{ "fragment",		0, 0, 'f' },
+	{ "preconf",		0, 0, 'p' },
 	{ 0, 0, 0, 0 }
 };
 
@@ -737,7 +714,7 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	while ((opt = getopt_long(argc, argv, "d:hi:s:c:lrf",
+	while ((opt = getopt_long(argc, argv, "d:hi:c:lrfp",
 						main_options, NULL)) != EOF) {
 		switch (opt) {
 		case 'i':
@@ -757,16 +734,6 @@ int main(int argc, char *argv[])
 				exit(0);
 			}
 			break;
-		case 's':
-			if (!strncasecmp(optarg, "INT", sizeof("INT"))) {
-				initiator = true;
-			} else if (!strncasecmp(optarg, "ACP", sizeof("ACP"))) {
-				initiator = false;
-			} else {
-				usage();
-				exit(0);
-			}
-			break;
 		case 'c':
 			if (str2ba(optarg, &dst) < 0) {
 				usage();
@@ -782,6 +749,9 @@ int main(int argc, char *argv[])
 		case 'f':
 			fragment = true;
 			break;
+		case 'p':
+			preconf = true;
+			break;
 		case 'h':
 		default:
 			usage();
-- 
1.9.1


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

* [PATCH 2/3] android/avdtptest: Add support for sending commands
  2014-09-02 13:53 [PATCH 1/3] android/avdtptest: Add option to enable stream configuration Szymon Janc
@ 2014-09-02 13:53 ` Szymon Janc
  2014-09-02 13:53 ` [PATCH 3/3] android/avdtptest: Add option for setting protocol version Szymon Janc
  2014-09-02 15:56 ` [PATCH 1/3] android/avdtptest: Add option to enable stream configuration Szymon Janc
  2 siblings, 0 replies; 4+ messages in thread
From: Szymon Janc @ 2014-09-02 13:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

---
 android/avdtptest.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 89 insertions(+), 3 deletions(-)

diff --git a/android/avdtptest.c b/android/avdtptest.c
index c8f7340..58168be 100644
--- a/android/avdtptest.c
+++ b/android/avdtptest.c
@@ -60,6 +60,17 @@ static guint idle_id = 0;
 
 static bool fragment = false;
 
+static enum {
+	CMD_GET_CONF,
+	CMD_OPEN,
+	CMD_START,
+	CMD_SUSPEND,
+	CMD_CLOSE,
+	CMD_ABORT,
+	CMD_DELAY,
+	CMD_NONE,
+} command = CMD_NONE;
+
 static const char sbc_codec[] = {0x00, 0x00, 0x11, 0x15, 0x02, 0x40};
 static const char sbc_media_frame[] = {
 	0x00, 0x60, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
@@ -77,6 +88,64 @@ static const char sbc_media_frame[] = {
 	0x3b, 0x3b, 0xaf, 0xc6, 0xd4, 0x37, 0x68, 0x94, 0x0a, 0xbb
 	};
 
+static void parse_command(const char *cmd)
+{
+	if (!strncmp(cmd, "getconf", sizeof("getconf"))) {
+		command = CMD_GET_CONF;
+	} else if (!strncmp(cmd, "open", sizeof("open"))) {
+		command = CMD_OPEN;
+	} else if (!strncmp(cmd, "start", sizeof("start"))) {
+		command = CMD_START;
+	} else if (!strncmp(cmd, "suspend", sizeof("suspend"))) {
+		command = CMD_SUSPEND;
+	} else if (!strncmp(cmd, "close", sizeof("close"))) {
+		command = CMD_CLOSE;
+	} else if (!strncmp(cmd, "abort", sizeof("abort"))) {
+		command = CMD_ABORT;
+	} else if (!strncmp(cmd, "delay", sizeof("delay"))) {
+		command = CMD_DELAY;
+	} else {
+		printf("Unknown command '%s'\n", cmd);
+		printf("(getconf open start suspend close abort delay)\n");
+		exit(1);
+	}
+}
+
+static void send_command(void)
+{
+	avdtp_state_t state = avdtp_sep_get_state(local_sep);
+
+	switch (command) {
+	case CMD_GET_CONF:
+		avdtp_get_configuration(avdtp, avdtp_stream);
+		break;
+	case CMD_OPEN:
+		if (state == AVDTP_STATE_CONFIGURED)
+			avdtp_open(avdtp, avdtp_stream);
+		break;
+	case CMD_START:
+		if (state == AVDTP_STATE_OPEN)
+			avdtp_start(avdtp, avdtp_stream);
+		break;
+	case CMD_SUSPEND:
+		if (state == AVDTP_STATE_STREAMING)
+			avdtp_suspend(avdtp , avdtp_stream);
+		break;
+	case CMD_CLOSE:
+		if (state == AVDTP_STATE_STREAMING)
+			avdtp_close(avdtp, avdtp_stream, FALSE);
+		break;
+	case CMD_ABORT:
+		avdtp_abort(avdtp , avdtp_stream);
+		break;
+	case CMD_DELAY:
+		avdtp_delay_report(avdtp , avdtp_stream , 250);
+		break;
+	default:
+		break;
+	}
+}
+
 static gboolean media_writer(gpointer user_data)
 {
 	uint16_t omtu;
@@ -91,9 +160,11 @@ static gboolean media_writer(gpointer user_data)
 	else
 		to_write = sizeof(sbc_media_frame);
 
-	if (write(fd, sbc_media_frame, to_write))
+	if (write(fd, sbc_media_frame, to_write) < 0)
 		return TRUE;
 
+	send_command();
+
 	return TRUE;
 }
 
@@ -190,6 +261,8 @@ static gboolean media_reader(GIOChannel *source, GIOCondition condition,
 		decode = true;
 	}
 
+	send_command();
+
 	return TRUE;
 }
 
@@ -324,6 +397,8 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
 
 		g_io_channel_set_close_on_unref(chan, FALSE);
 
+		send_command();
+
 		return;
 	}
 
@@ -522,6 +597,8 @@ static gboolean set_configuration_ind(struct avdtp *session,
 
 	cb(session, stream, NULL);
 
+	send_command();
+
 	return TRUE;
 }
 
@@ -546,6 +623,8 @@ static gboolean open_ind(struct avdtp *session, struct avdtp_local_sep *lsep,
 	if (reject)
 		return FALSE;
 
+	send_command();
+
 	return TRUE;
 }
 
@@ -563,6 +642,8 @@ static gboolean start_ind(struct avdtp *session, struct avdtp_local_sep *lsep,
 	else
 		start_media_recorder();
 
+	send_command();
+
 	return TRUE;
 }
 
@@ -667,7 +748,8 @@ static void usage(void)
 		"\t-l                 listen\n"
 		"\t-r                 reject commands\n"
 		"\t-f                 fragment\n"
-		"-t-p                 configure stream\n");
+		"\t-p                 configure stream\n"
+		"\t-s <command>       send command\n");
 }
 
 static struct option main_options[] = {
@@ -679,6 +761,7 @@ static struct option main_options[] = {
 	{ "reject",		0, 0, 'r' },
 	{ "fragment",		0, 0, 'f' },
 	{ "preconf",		0, 0, 'p' },
+	{ "send",		1, 0, 's' },
 	{ 0, 0, 0, 0 }
 };
 
@@ -714,7 +797,7 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	while ((opt = getopt_long(argc, argv, "d:hi:c:lrfp",
+	while ((opt = getopt_long(argc, argv, "d:hi:s:c:lrfp",
 						main_options, NULL)) != EOF) {
 		switch (opt) {
 		case 'i':
@@ -752,6 +835,9 @@ int main(int argc, char *argv[])
 		case 'p':
 			preconf = true;
 			break;
+		case 's':
+			parse_command(optarg);
+			break;
 		case 'h':
 		default:
 			usage();
-- 
1.9.1


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

* [PATCH 3/3] android/avdtptest: Add option for setting protocol version
  2014-09-02 13:53 [PATCH 1/3] android/avdtptest: Add option to enable stream configuration Szymon Janc
  2014-09-02 13:53 ` [PATCH 2/3] android/avdtptest: Add support for sending commands Szymon Janc
@ 2014-09-02 13:53 ` Szymon Janc
  2014-09-02 15:56 ` [PATCH 1/3] android/avdtptest: Add option to enable stream configuration Szymon Janc
  2 siblings, 0 replies; 4+ messages in thread
From: Szymon Janc @ 2014-09-02 13:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

---
 android/avdtptest.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/android/avdtptest.c b/android/avdtptest.c
index 58168be..d1f2ef4 100644
--- a/android/avdtptest.c
+++ b/android/avdtptest.c
@@ -53,7 +53,7 @@ static GIOChannel *io = NULL;
 static bool reject = false;
 static bdaddr_t src;
 static bdaddr_t dst;
-
+static uint16_t version = 0x0103;
 static guint media_player = 0;
 static guint media_recorder = 0;
 static guint idle_id = 0;
@@ -402,8 +402,7 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
 		return;
 	}
 
-	/* TODO allow to set version from command line? */
-	avdtp = avdtp_new(fd, imtu, omtu, 0x0103);
+	avdtp = avdtp_new(fd, imtu, omtu, version);
 	if (!avdtp) {
 		printf("Failed to create avdtp instance\n");
 		g_main_loop_quit(mainloop);
@@ -749,7 +748,8 @@ static void usage(void)
 		"\t-r                 reject commands\n"
 		"\t-f                 fragment\n"
 		"\t-p                 configure stream\n"
-		"\t-s <command>       send command\n");
+		"\t-s <command>       send command\n"
+		"\t-v <version>       set version (0x0100, 0x0102, 0x0103\n");
 }
 
 static struct option main_options[] = {
@@ -762,6 +762,7 @@ static struct option main_options[] = {
 	{ "fragment",		0, 0, 'f' },
 	{ "preconf",		0, 0, 'p' },
 	{ "send",		1, 0, 's' },
+	{ "version",		1, 0, 'v' },
 	{ 0, 0, 0, 0 }
 };
 
@@ -797,7 +798,7 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	while ((opt = getopt_long(argc, argv, "d:hi:s:c:lrfp",
+	while ((opt = getopt_long(argc, argv, "d:hi:s:c:v:lrfp",
 						main_options, NULL)) != EOF) {
 		switch (opt) {
 		case 'i':
@@ -838,6 +839,15 @@ int main(int argc, char *argv[])
 		case 's':
 			parse_command(optarg);
 			break;
+		case 'v':
+			version = strtol(optarg, NULL, 0);
+			if (version != 0x0100 && version != 0x0102 &&
+							version != 0x0103) {
+				printf("invalid version\n");
+				exit(0);
+			}
+
+			break;
 		case 'h':
 		default:
 			usage();
-- 
1.9.1


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

* Re: [PATCH 1/3] android/avdtptest: Add option to enable stream configuration
  2014-09-02 13:53 [PATCH 1/3] android/avdtptest: Add option to enable stream configuration Szymon Janc
  2014-09-02 13:53 ` [PATCH 2/3] android/avdtptest: Add support for sending commands Szymon Janc
  2014-09-02 13:53 ` [PATCH 3/3] android/avdtptest: Add option for setting protocol version Szymon Janc
@ 2014-09-02 15:56 ` Szymon Janc
  2 siblings, 0 replies; 4+ messages in thread
From: Szymon Janc @ 2014-09-02 15:56 UTC (permalink / raw)
  To: linux-bluetooth

On Tuesday 02 of September 2014 15:53:56 Szymon Janc wrote:
> Instead of specifing initiator role use option that allows to perform
> stream configuration.
> ---
>  android/avdtptest.c | 50 ++++++++++----------------------------------------
>  1 file changed, 10 insertions(+), 40 deletions(-)
> 
> diff --git a/android/avdtptest.c b/android/avdtptest.c
> index adbf7af..c8f7340 100644
> --- a/android/avdtptest.c
> +++ b/android/avdtptest.c
> @@ -44,7 +44,7 @@
>  
>  static GMainLoop *mainloop = NULL;
>  static int dev_role = AVDTP_SEP_TYPE_SOURCE;
> -static bool initiator = false;
> +static bool preconf = false;
>  static struct avdtp *avdtp = NULL;
>  struct avdtp_stream *avdtp_stream = NULL;
>  struct avdtp_local_sep *local_sep = NULL;
> @@ -237,7 +237,7 @@ static void set_configuration_cfm(struct avdtp *session,
>  {
>  	printf("%s\n", __func__);
>  
> -	if (initiator)
> +	if (preconf)
>  		avdtp_open(avdtp, avdtp_stream);
>  }
>  
> @@ -289,21 +289,6 @@ static void discover_cb(struct avdtp *session, GSList *seps,
>  	}
>  }
>  
> -static gboolean idle_timeout(gpointer user_data)
> -{
> -	int err;
> -
> -	idle_id = 0;
> -
> -	err = avdtp_discover(avdtp, discover_cb, NULL);
> -	if (err < 0) {
> -		printf("avdtp_discover failed: %s", strerror(-err));
> -		g_main_loop_quit(mainloop);
> -	}
> -
> -	return FALSE;
> -}
> -
>  static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
>  {
>  	uint16_t imtu, omtu;
> @@ -339,9 +324,6 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
>  
>  		g_io_channel_set_close_on_unref(chan, FALSE);
>  
> -		if (initiator)
> -			avdtp_start(avdtp, avdtp_stream);
> -
>  		return;
>  	}
>  
> @@ -355,7 +337,7 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
>  
>  	avdtp_add_disconnect_cb(avdtp, disconnect_cb, NULL);
>  
> -	if (initiator) {
> +	if (preconf) {
>  		int ret;
>  
>  		ret = avdtp_discover(avdtp, discover_cb, NULL);
> @@ -363,8 +345,6 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
>  			printf("avdtp_discover failed: %s", strerror(-ret));
>  			g_main_loop_quit(mainloop);
>  		}
> -	} else {
> -		idle_id = g_timeout_add_seconds(1, idle_timeout, NULL);
>  	}
>  }
>  
> @@ -395,9 +375,6 @@ static void open_cfm(struct avdtp *session, struct avdtp_local_sep *lsep,
>  
>  	printf("%s\n", __func__);
>  
> -	if (!initiator)
> -		return;
> -
>  	do_connect(&gerr);
>  	if (gerr) {
>  		printf("connect failed: %s\n", gerr->message);
> @@ -685,23 +662,23 @@ static void usage(void)
>  		"\tavdtptest [options]\n");
>  	printf("options:\n"
>  		"\t-d <device_role>   SRC (source) or SINK (sink)\n"
> -		"\t-s <stream_role>   INT (initiator) or ACP (acceptor)\n"
>  		"\t-i <hcidev>        HCI adapter\n"
>  		"\t-c <bdaddr>        connect\n"
>  		"\t-l                 listen\n"
>  		"\t-r                 reject commands\n"
> -		"\t-f                 fragment\n");
> +		"\t-f                 fragment\n"
> +		"-t-p                 configure stream\n");
>  }
>  
>  static struct option main_options[] = {
>  	{ "help",		0, 0, 'h' },
>  	{ "device_role",	1, 0, 'd' },
> -	{ "stream_role",	1, 0, 's' },
>  	{ "adapter",		1, 0, 'i' },
>  	{ "connect",		1, 0, 'c' },
>  	{ "listen",		0, 0, 'l' },
>  	{ "reject",		0, 0, 'r' },
>  	{ "fragment",		0, 0, 'f' },
> +	{ "preconf",		0, 0, 'p' },
>  	{ 0, 0, 0, 0 }
>  };
>  
> @@ -737,7 +714,7 @@ int main(int argc, char *argv[])
>  		exit(1);
>  	}
>  
> -	while ((opt = getopt_long(argc, argv, "d:hi:s:c:lrf",
> +	while ((opt = getopt_long(argc, argv, "d:hi:c:lrfp",
>  						main_options, NULL)) != EOF) {
>  		switch (opt) {
>  		case 'i':
> @@ -757,16 +734,6 @@ int main(int argc, char *argv[])
>  				exit(0);
>  			}
>  			break;
> -		case 's':
> -			if (!strncasecmp(optarg, "INT", sizeof("INT"))) {
> -				initiator = true;
> -			} else if (!strncasecmp(optarg, "ACP", sizeof("ACP"))) {
> -				initiator = false;
> -			} else {
> -				usage();
> -				exit(0);
> -			}
> -			break;
>  		case 'c':
>  			if (str2ba(optarg, &dst) < 0) {
>  				usage();
> @@ -782,6 +749,9 @@ int main(int argc, char *argv[])
>  		case 'f':
>  			fragment = true;
>  			break;
> +		case 'p':
> +			preconf = true;
> +			break;
>  		case 'h':
>  		default:
>  			usage();
> 

Pushed.

-- 
Best regards, 
Szymon Janc

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

end of thread, other threads:[~2014-09-02 15:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-02 13:53 [PATCH 1/3] android/avdtptest: Add option to enable stream configuration Szymon Janc
2014-09-02 13:53 ` [PATCH 2/3] android/avdtptest: Add support for sending commands Szymon Janc
2014-09-02 13:53 ` [PATCH 3/3] android/avdtptest: Add option for setting protocol version Szymon Janc
2014-09-02 15:56 ` [PATCH 1/3] android/avdtptest: Add option to enable stream configuration Szymon Janc

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