* [PATCH 1/3] bluez: Copy L2CAP chan policy defines from kernel
@ 2012-02-23 15:20 Andrei Emeltchenko
2012-02-23 15:20 ` [PATCH 2/3] l2test: Clean up lookup table code Andrei Emeltchenko
2012-02-23 15:20 ` [PATCH 3/3] l2test: Add BT Channel Policy option Andrei Emeltchenko
0 siblings, 2 replies; 3+ messages in thread
From: Andrei Emeltchenko @ 2012-02-23 15:20 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] 3+ messages in thread
* [PATCH 2/3] l2test: Clean up lookup table code
2012-02-23 15:20 [PATCH 1/3] bluez: Copy L2CAP chan policy defines from kernel Andrei Emeltchenko
@ 2012-02-23 15:20 ` Andrei Emeltchenko
2012-02-23 15:20 ` [PATCH 3/3] l2test: Add BT Channel Policy option Andrei Emeltchenko
1 sibling, 0 replies; 3+ messages in thread
From: Andrei Emeltchenko @ 2012-02-23 15:20 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Make lookup table code available for others
---
test/l2test.c | 40 ++++++++++++++++++++++++++--------------
1 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/test/l2test.c b/test/l2test.c
index c5bc3d3..ce20bb3 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] 3+ messages in thread
* [PATCH 3/3] l2test: Add BT Channel Policy option
2012-02-23 15:20 [PATCH 1/3] bluez: Copy L2CAP chan policy defines from kernel Andrei Emeltchenko
2012-02-23 15:20 ` [PATCH 2/3] l2test: Clean up lookup table code Andrei Emeltchenko
@ 2012-02-23 15:20 ` Andrei Emeltchenko
1 sibling, 0 replies; 3+ messages in thread
From: Andrei Emeltchenko @ 2012-02-23 15:20 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 | 28 +++++++++++++++++++++++++++-
1 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/test/l2test.c b/test/l2test.c
index ce20bb3..7f97774 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 = 0;
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 };
@@ -1216,7 +1233,7 @@ 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) {
+ while ((opt=getopt(argc,argv,"rdscuwmntqxyzpb:i:P:I:O:J:B:N:L:W:C:D:X:F:Q:Z:Y:H:K:RUGAESMTa:")) != EOF) {
switch(opt) {
case 'r':
mode = RECV;
@@ -1339,8 +1356,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] 3+ messages in thread
end of thread, other threads:[~2012-02-23 15:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-23 15:20 [PATCH 1/3] bluez: Copy L2CAP chan policy defines from kernel Andrei Emeltchenko
2012-02-23 15:20 ` [PATCH 2/3] l2test: Clean up lookup table code Andrei Emeltchenko
2012-02-23 15:20 ` [PATCH 3/3] l2test: Add BT Channel Policy option Andrei Emeltchenko
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).