linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 0/3] Use BT policy option in l2test
@ 2012-02-24  8:44 Andrei Emeltchenko
  2012-02-24  8:44 ` [PATCHv2 1/3] bluez: Copy L2CAP chan policy defines from kernel Andrei Emeltchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Andrei Emeltchenko @ 2012-02-24  8:44 UTC (permalink / raw)
  To: linux-bluetooth

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

Adds support for policy socket option for l2test. Will be used
for some PTS tests.

Changes:
	* PATCHv2: Fixed checkpatch warnings, added help.

Andrei Emeltchenko (3):
  bluez: Copy L2CAP chan policy defines from kernel
  l2test: Clean up lookup table code
  l2test: Add BT Channel Policy option

 lib/bluetooth.h |   27 ++++++++++++++++++++
 test/l2test.c   |   72 ++++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 83 insertions(+), 16 deletions(-)

-- 
1.7.9


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

* [PATCHv2 1/3] bluez: Copy L2CAP chan policy defines from kernel
  2012-02-24  8:44 [PATCHv2 0/3] Use BT policy option in l2test Andrei Emeltchenko
@ 2012-02-24  8:44 ` Andrei Emeltchenko
  2012-02-24  8:44 ` [PATCHv2 2/3] l2test: Clean up lookup table code Andrei Emeltchenko
  2012-02-24  8:44 ` [PATCHv2 3/3] l2test: Add BT Channel Policy option Andrei Emeltchenko
  2 siblings, 0 replies; 6+ messages in thread
From: Andrei Emeltchenko @ 2012-02-24  8:44 UTC (permalink / raw)
  To: linux-bluetooth

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

Those defines will be used by user space.
---
 lib/bluetooth.h |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 1dee6df..52606e6 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -77,6 +77,33 @@ struct bt_security {
 #define BT_FLUSHABLE_OFF	0
 #define BT_FLUSHABLE_ON		1
 
+#define BT_CHANNEL_POLICY	10
+
+/* BR/EDR only (default policy)
+ *   AMP controllers cannot be used.
+ *   Channel move requests from the remote device are denied.
+ *   If the L2CAP channel is currently using AMP, move the channel to BR/EDR.
+ */
+#define BT_CHANNEL_POLICY_BREDR_ONLY		0
+
+/* BR/EDR Preferred
+ *   Allow use of AMP controllers.
+ *   If the L2CAP channel is currently on AMP, move it to BR/EDR.
+ *   Channel move requests from the remote device are allowed.
+ */
+#define BT_CHANNEL_POLICY_BREDR_PREFERRED	1
+
+/* AMP Preferred
+ *   Allow use of AMP controllers
+ *   If the L2CAP channel is currently on BR/EDR and AMP controller
+ *     resources are available, initiate a channel move to AMP.
+ *   Channel move requests from the remote device are allowed.
+ *   If the L2CAP socket has not been connected yet, try to create
+ *     and configure the channel directly on an AMP controller rather
+ *     than BR/EDR.
+ */
+#define BT_CHANNEL_POLICY_AMP_PREFERRED		2
+
 /* Connection and socket states */
 enum {
 	BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
-- 
1.7.9


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

* [PATCHv2 2/3] l2test: Clean up lookup table code
  2012-02-24  8:44 [PATCHv2 0/3] Use BT policy option in l2test Andrei Emeltchenko
  2012-02-24  8:44 ` [PATCHv2 1/3] bluez: Copy L2CAP chan policy defines from kernel Andrei Emeltchenko
@ 2012-02-24  8:44 ` Andrei Emeltchenko
  2012-02-24  8:44 ` [PATCHv2 3/3] l2test: Add BT Channel Policy option Andrei Emeltchenko
  2 siblings, 0 replies; 6+ messages in thread
From: Andrei Emeltchenko @ 2012-02-24  8:44 UTC (permalink / raw)
  To: linux-bluetooth

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

Make lookup table code available for others and create
common functions.
---
 test/l2test.c |   40 ++++++++++++++++++++++++++--------------
 1 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/test/l2test.c b/test/l2test.c
index c5bc3d3..3705fdc 100644
--- a/test/l2test.c
+++ b/test/l2test.c
@@ -117,10 +117,12 @@ static int defer_setup = 0;
 static int priority = -1;
 static int rcvbuf = 0;
 
-static struct {
+struct lookup_table {
 	char	*name;
 	int	flag;
-} l2cap_modes[] = {
+};
+
+static struct lookup_table l2cap_modes[] = {
 	{ "basic",	L2CAP_MODE_BASIC	},
 	/* Not implemented
 	{ "flowctl",	L2CAP_MODE_FLOWCTL	},
@@ -131,14 +133,25 @@ static struct {
 	{ 0 }
 };
 
-static void list_l2cap_modes(void)
+static int get_lookup_flag(struct lookup_table *table, char *name)
 {
 	int i;
 
-	printf("l2test - L2CAP testing\n"
-		"List L2CAP modes:\n");
-	for (i=0; l2cap_modes[i].name; i++)
-		printf("\t%s\n", l2cap_modes[i].name);
+	for (i = 0; table[i].name; i++)
+		if (!strcasecmp(table[i].name, name))
+			return table[i].flag;
+
+	return -1;
+}
+
+static void print_lookup_values(struct lookup_table *table, char *header)
+{
+	int i;
+
+	printf("%s\n", header);
+
+	for (i = 0; table[i].name; i++)
+		printf("\t%s\n", table[i].name);
 }
 
 static float tv2fl(struct timeval tv)
@@ -1199,7 +1212,7 @@ static void usage(void)
 int main(int argc, char *argv[])
 {
 	struct sigaction sa;
-	int opt, sk, i, mode = RECV, need_addr = 0;
+	int opt, sk, mode = RECV, need_addr = 0;
 
 	bacpy(&bdaddr, BDADDR_ANY);
 
@@ -1321,14 +1334,13 @@ int main(int argc, char *argv[])
 			break;
 
 		case 'X':
-			rfcmode = -1;
+			rfcmode = get_lookup_flag(l2cap_modes, optarg);
+
+			if (rfcmode == -1) {
+				print_lookup_values(l2cap_modes,
+						"List L2CAP modes:");
 
-			for (i = 0; l2cap_modes[i].name; i++)
-				if (!strcasecmp(l2cap_modes[i].name, optarg))
-					rfcmode = l2cap_modes[i].flag;
 
-			if (!strcasecmp(optarg, "help") || rfcmode == -1) {
-				list_l2cap_modes();
 				exit(1);
 			}
 
-- 
1.7.9


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

* [PATCHv2 3/3] l2test: Add BT Channel Policy option
  2012-02-24  8:44 [PATCHv2 0/3] Use BT policy option in l2test Andrei Emeltchenko
  2012-02-24  8:44 ` [PATCHv2 1/3] bluez: Copy L2CAP chan policy defines from kernel Andrei Emeltchenko
  2012-02-24  8:44 ` [PATCHv2 2/3] l2test: Clean up lookup table code Andrei Emeltchenko
@ 2012-02-24  8:44 ` Andrei Emeltchenko
  2012-02-24 12:41   ` Andrei Emeltchenko
  2 siblings, 1 reply; 6+ messages in thread
From: Andrei Emeltchenko @ 2012-02-24  8:44 UTC (permalink / raw)
  To: linux-bluetooth

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

Make l2test able to set channel policy socket option.
---
 test/l2test.c |   32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/test/l2test.c b/test/l2test.c
index 3705fdc..9f615a2 100644
--- a/test/l2test.c
+++ b/test/l2test.c
@@ -116,6 +116,7 @@ static int timestamp = 0;
 static int defer_setup = 0;
 static int priority = -1;
 static int rcvbuf = 0;
+static int chan_policy;
 
 struct lookup_table {
 	char	*name;
@@ -133,6 +134,13 @@ static struct lookup_table l2cap_modes[] = {
 	{ 0 }
 };
 
+static struct lookup_table chan_policies[] = {
+	{ "bredr",	BT_CHANNEL_POLICY_BREDR_ONLY		},
+	{ "bredr_pref",	BT_CHANNEL_POLICY_BREDR_PREFERRED	},
+	{ "amp_pref",	BT_CHANNEL_POLICY_AMP_PREFERRED		},
+	{ NULL,		0					},
+};
+
 static int get_lookup_flag(struct lookup_table *table, char *name)
 {
 	int i;
@@ -296,6 +304,15 @@ static int do_connect(char *svr)
 	}
 #endif
 
+	if (chan_policy != -1) {
+		if (setsockopt(sk, SOL_BLUETOOTH, BT_CHANNEL_POLICY,
+				&chan_policy, sizeof(chan_policy)) < 0) {
+			syslog(LOG_ERR, "Can't enable chan policy : %s (%d)",
+							strerror(errno), errno);
+			goto error;
+		}
+	}
+
 	/* Enable SO_LINGER */
 	if (linger) {
 		struct linger l = { .l_onoff = 1, .l_linger = linger };
@@ -1194,6 +1211,7 @@ static void usage(void)
 		"\t[-D milliseconds] delay after sending num frames (default = 0)\n"
 		"\t[-K milliseconds] delay before receiving (default = 0)\n"
 		"\t[-X mode] l2cap mode (help for list, default = basic)\n"
+		"\t[-a policy] chan policy (help for list, default = bredr)\n"
 		"\t[-F fcs] use CRC16 check (default = 1)\n"
 		"\t[-Q num] Max Transmit value (default = 3)\n"
 		"\t[-Z size] Transmission Window size (default = 63)\n"
@@ -1216,8 +1234,9 @@ int main(int argc, char *argv[])
 
 	bacpy(&bdaddr, BDADDR_ANY);
 
-	while ((opt=getopt(argc,argv,"rdscuwmntqxyzpb:i:P:I:O:J:B:N:L:W:C:D:X:F:Q:Z:Y:H:K:RUGAESMT")) != EOF) {
-		switch(opt) {
+	while ((opt = getopt(argc, argv, "rdscuwmntqxyzpb:a:"
+		"i:P:I:O:J:B:N:L:W:C:D:X:F:Q:Z:Y:H:K:RUGAESMT")) != EOF) {
+		switch (opt) {
 		case 'r':
 			mode = RECV;
 			break;
@@ -1339,8 +1358,17 @@ int main(int argc, char *argv[])
 			if (rfcmode == -1) {
 				print_lookup_values(l2cap_modes,
 						"List L2CAP modes:");
+				exit(1);
+			}
+
+			break;
 
+		case 'a':
+			chan_policy = get_lookup_flag(chan_policies, optarg);
 
+			if (chan_policy == -1) {
+				print_lookup_values(chan_policies,
+						"List L2CAP chan policies:");
 				exit(1);
 			}
 
-- 
1.7.9


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

* Re: [PATCHv2 3/3] l2test: Add BT Channel Policy option
  2012-02-24  8:44 ` [PATCHv2 3/3] l2test: Add BT Channel Policy option Andrei Emeltchenko
@ 2012-02-24 12:41   ` Andrei Emeltchenko
  2012-02-26 17:10     ` Johan Hedberg
  0 siblings, 1 reply; 6+ messages in thread
From: Andrei Emeltchenko @ 2012-02-24 12:41 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Fri, Feb 24, 2012 at 10:44:25AM +0200, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> 
> Make l2test able to set channel policy socket option.
> ---
>  test/l2test.c |   32 ++++++++++++++++++++++++++++++--
>  1 files changed, 30 insertions(+), 2 deletions(-)
> 
> diff --git a/test/l2test.c b/test/l2test.c
> index 3705fdc..9f615a2 100644
> --- a/test/l2test.c
> +++ b/test/l2test.c
> @@ -116,6 +116,7 @@ static int timestamp = 0;
>  static int defer_setup = 0;
>  static int priority = -1;
>  static int rcvbuf = 0;
> +static int chan_policy;

Sorry shall be:

-static int chan_policy;
+static int chan_policy = -1;

Best regards 
Andrei Emeltchenko 


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

* Re: [PATCHv2 3/3] l2test: Add BT Channel Policy option
  2012-02-24 12:41   ` Andrei Emeltchenko
@ 2012-02-26 17:10     ` Johan Hedberg
  0 siblings, 0 replies; 6+ messages in thread
From: Johan Hedberg @ 2012-02-26 17:10 UTC (permalink / raw)
  To: Andrei Emeltchenko, linux-bluetooth

Hi Andrei,

On Fri, Feb 24, 2012, Andrei Emeltchenko wrote:
> On Fri, Feb 24, 2012 at 10:44:25AM +0200, Andrei Emeltchenko wrote:
> > From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> > 
> > Make l2test able to set channel policy socket option.
> > ---
> >  test/l2test.c |   32 ++++++++++++++++++++++++++++++--
> >  1 files changed, 30 insertions(+), 2 deletions(-)
> > 
> > diff --git a/test/l2test.c b/test/l2test.c
> > index 3705fdc..9f615a2 100644
> > --- a/test/l2test.c
> > +++ b/test/l2test.c
> > @@ -116,6 +116,7 @@ static int timestamp = 0;
> >  static int defer_setup = 0;
> >  static int priority = -1;
> >  static int rcvbuf = 0;
> > +static int chan_policy;
> 
> Sorry shall be:
> 
> -static int chan_policy;
> +static int chan_policy = -1;

You could have just sent a v3 for that. Anyway, I went ahead and fixed
it now myself and all three patches have been pushed upstream. Thanks.

Johan:w


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

end of thread, other threads:[~2012-02-26 17:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-24  8:44 [PATCHv2 0/3] Use BT policy option in l2test Andrei Emeltchenko
2012-02-24  8:44 ` [PATCHv2 1/3] bluez: Copy L2CAP chan policy defines from kernel Andrei Emeltchenko
2012-02-24  8:44 ` [PATCHv2 2/3] l2test: Clean up lookup table code Andrei Emeltchenko
2012-02-24  8:44 ` [PATCHv2 3/3] l2test: Add BT Channel Policy option Andrei Emeltchenko
2012-02-24 12:41   ` Andrei Emeltchenko
2012-02-26 17:10     ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).