* [PATCH BlueZ 2/4] Add option 'Y' to set socket priority for rctest
2011-11-03 15:15 [PATCH BlueZ 1/4] Add option 'Y' to set socket priority for l2test Luiz Augusto von Dentz
@ 2011-11-03 15:15 ` Luiz Augusto von Dentz
2011-11-03 15:15 ` [PATCH BlueZ 3/4] btio: add BT_IO_OPT_PRIORITY option Luiz Augusto von Dentz
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2011-11-03 15:15 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Priority is set using SO_PRIORITY, see man 7 socket for more details.
---
test/rctest.c | 48 +++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 41 insertions(+), 7 deletions(-)
diff --git a/test/rctest.c b/test/rctest.c
index 9754f52..b8acfb7 100644
--- a/test/rctest.c
+++ b/test/rctest.c
@@ -85,6 +85,7 @@ static int socktype = SOCK_STREAM;
static int linger = 0;
static int timestamp = 0;
static int defer_setup = 0;
+static int priority = -1;
static float tv2fl(struct timeval tv)
{
@@ -232,9 +233,22 @@ static int do_connect(const char *svr)
//goto error;
}
- syslog(LOG_INFO, "Connected [handle %d, class 0x%02x%02x%02x]",
- conn.hci_handle,
- conn.dev_class[2], conn.dev_class[1], conn.dev_class[0]);
+ if (priority > 0 && setsockopt(sk, SOL_SOCKET, SO_PRIORITY, &priority,
+ sizeof(priority)) < 0) {
+ syslog(LOG_ERR, "Can't set socket priority: %s (%d)",
+ strerror(errno), errno);
+ goto error;
+ }
+
+ if (getsockopt(sk, SOL_SOCKET, SO_PRIORITY, &opt, &optlen) < 0) {
+ syslog(LOG_ERR, "Can't get socket priority: %s (%d)",
+ strerror(errno), errno);
+ goto error;
+ }
+
+ syslog(LOG_INFO, "Connected [handle %d, class 0x%02x%02x%02x, "
+ "priority %d]", conn.hci_handle, conn.dev_class[2],
+ conn.dev_class[1], conn.dev_class[0], opt);
return sk;
@@ -298,6 +312,13 @@ static void do_listen(void (*handler)(int sk))
goto error;
}
+ if (priority > 0 && setsockopt(sk, SOL_SOCKET, SO_PRIORITY, &priority,
+ sizeof(priority)) < 0) {
+ syslog(LOG_ERR, "Can't set socket priority: %s (%d)",
+ strerror(errno), errno);
+ goto error;
+ }
+
/* Listen for connections */
if (listen(sk, 10)) {
syslog(LOG_ERR,"Can not listen on the socket: %s (%d)",
@@ -348,10 +369,18 @@ static void do_listen(void (*handler)(int sk))
//goto error;
}
+ optlen = sizeof(priority);
+ if (getsockopt(nsk, SOL_SOCKET, SO_PRIORITY, &opt, &optlen) < 0) {
+ syslog(LOG_ERR, "Can't get socket priority: %s (%d)",
+ strerror(errno), errno);
+ goto error;
+ }
+
ba2str(&addr.rc_bdaddr, ba);
- syslog(LOG_INFO, "Connect from %s [handle %d, class 0x%02x%02x%02x]",
- ba, conn.hci_handle,
- conn.dev_class[2], conn.dev_class[1], conn.dev_class[0]);
+ syslog(LOG_INFO, "Connect from %s [handle %d, "
+ "class 0x%02x%02x%02x, priority %d]",
+ ba, conn.hci_handle, conn.dev_class[2],
+ conn.dev_class[1], conn.dev_class[0], opt);
#if 0
/* Enable SO_TIMESTAMP */
@@ -584,6 +613,7 @@ static void usage(void)
"\t[-N num] number of frames to send\n"
"\t[-C num] send num frames before delay (default = 1)\n"
"\t[-D milliseconds] delay after sending num frames (default = 0)\n"
+ "\t[-Y priority] socket priority\n"
"\t[-A] request authentication\n"
"\t[-E] request encryption\n"
"\t[-S] secure connection\n"
@@ -598,7 +628,7 @@ int main(int argc, char *argv[])
bacpy(&bdaddr, BDADDR_ANY);
- while ((opt=getopt(argc,argv,"rdscuwmnb:i:P:U:B:N:MAESL:W:C:D:T")) != EOF) {
+ while ((opt=getopt(argc,argv,"rdscuwmnb:i:P:U:B:N:MAESL:W:C:D:Y:T")) != EOF) {
switch (opt) {
case 'r':
mode = RECV;
@@ -701,6 +731,10 @@ int main(int argc, char *argv[])
delay = atoi(optarg) * 1000;
break;
+ case 'Y':
+ priority = atoi(optarg);
+ break;
+
case 'T':
timestamp = 1;
break;
--
1.7.6.4
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH BlueZ 3/4] btio: add BT_IO_OPT_PRIORITY option
2011-11-03 15:15 [PATCH BlueZ 1/4] Add option 'Y' to set socket priority for l2test Luiz Augusto von Dentz
2011-11-03 15:15 ` [PATCH BlueZ 2/4] Add option 'Y' to set socket priority for rctest Luiz Augusto von Dentz
@ 2011-11-03 15:15 ` Luiz Augusto von Dentz
2011-11-03 15:15 ` [PATCH BlueZ 4/4] Add option to set priority for btiotest Luiz Augusto von Dentz
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2011-11-03 15:15 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
BT_IO_OPT_PRIORITY uses SO_PRIORITY to set the priority of the socket
---
btio/btio.c | 47 +++++++++++++++++++++++++++++++++++++++++++----
btio/btio.h | 1 +
2 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/btio/btio.c b/btio/btio.c
index 2cc9082..6db1756 100644
--- a/btio/btio.c
+++ b/btio/btio.c
@@ -64,6 +64,7 @@ struct set_opts {
int master;
uint8_t mode;
int flushable;
+ uint32_t priority;
};
struct connect {
@@ -502,9 +503,17 @@ static int l2cap_set_flushable(int sock, gboolean flushable)
return 0;
}
+static int set_priority(int sock, uint32_t prio)
+{
+ if (setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio)) < 0)
+ return -errno;
+
+ return 0;
+}
+
static gboolean l2cap_set(int sock, int sec_level, uint16_t imtu,
uint16_t omtu, uint8_t mode, int master,
- int flushable, GError **err)
+ int flushable, uint32_t priority, GError **err)
{
if (imtu || omtu || mode) {
struct l2cap_options l2o;
@@ -542,6 +551,11 @@ static gboolean l2cap_set(int sock, int sec_level, uint16_t imtu,
return FALSE;
}
+ if (priority > 0 && set_priority(sock, priority) < 0) {
+ ERROR_FAILED(err, "set_priority", errno);
+ return FALSE;
+ }
+
if (sec_level && !set_sec_level(sock, BT_IO_L2CAP, sec_level, err))
return FALSE;
@@ -669,6 +683,7 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,
opts->sec_level = BT_IO_SEC_MEDIUM;
opts->mode = L2CAP_MODE_BASIC;
opts->flushable = -1;
+ opts->priority = 0;
while (opt != BT_IO_OPT_INVALID) {
switch (opt) {
@@ -727,6 +742,9 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,
case BT_IO_OPT_FLUSHABLE:
opts->flushable = va_arg(args, gboolean);
break;
+ case BT_IO_OPT_PRIORITY:
+ opts->priority = va_arg(args, int);
+ break;
default:
g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
"Unknown option %d", opt);
@@ -797,6 +815,17 @@ static int l2cap_get_flushable(int sock, gboolean *flushable)
return 0;
}
+static int get_priority(int sock, uint32_t *prio)
+{
+ socklen_t len;
+
+ len = sizeof(*prio);
+ if (getsockopt(sock, SOL_SOCKET, SO_PRIORITY, prio, &len) < 0)
+ return -errno;
+
+ return 0;
+}
+
static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1,
va_list args)
{
@@ -808,6 +837,7 @@ static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1,
uint16_t handle;
socklen_t len;
gboolean flushable = FALSE;
+ uint32_t priority;
len = sizeof(l2o);
memset(&l2o, 0, len);
@@ -897,6 +927,13 @@ static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1,
}
*(va_arg(args, gboolean *)) = flushable;
break;
+ case BT_IO_OPT_PRIORITY:
+ if (get_priority(sock, &priority) < 0) {
+ ERROR_FAILED(err, "get_priority", errno);
+ return FALSE;
+ }
+ *(va_arg(args, uint32_t *)) = priority;
+ break;
default:
g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
"Unknown option %d", opt);
@@ -1172,7 +1209,8 @@ gboolean bt_io_set(GIOChannel *io, BtIOType type, GError **err,
case BT_IO_L2RAW:
case BT_IO_L2CAP:
return l2cap_set(sock, opts.sec_level, opts.imtu, opts.omtu,
- opts.mode, opts.master, opts.flushable, err);
+ opts.mode, opts.master, opts.flushable,
+ opts.priority, err);
case BT_IO_RFCOMM:
return rfcomm_set(sock, opts.sec_level, opts.master, err);
case BT_IO_SCO:
@@ -1213,7 +1251,7 @@ static GIOChannel *create_io(BtIOType type, gboolean server,
if (l2cap_bind(sock, &opts->src, server ? opts->psm : 0,
opts->cid, err) < 0)
goto failed;
- if (!l2cap_set(sock, opts->sec_level, 0, 0, 0, -1, -1, err))
+ if (!l2cap_set(sock, opts->sec_level, 0, 0, 0, -1, -1, 0, err))
goto failed;
break;
case BT_IO_L2CAP:
@@ -1226,7 +1264,8 @@ static GIOChannel *create_io(BtIOType type, gboolean server,
opts->cid, err) < 0)
goto failed;
if (!l2cap_set(sock, opts->sec_level, opts->imtu, opts->omtu,
- opts->mode, opts->master, opts->flushable, err))
+ opts->mode, opts->master, opts->flushable,
+ opts->priority, err))
goto failed;
break;
case BT_IO_RFCOMM:
diff --git a/btio/btio.h b/btio/btio.h
index c6b736f..c026f8d 100644
--- a/btio/btio.h
+++ b/btio/btio.h
@@ -65,6 +65,7 @@ typedef enum {
BT_IO_OPT_CLASS,
BT_IO_OPT_MODE,
BT_IO_OPT_FLUSHABLE,
+ BT_IO_OPT_PRIORITY
} BtIOOption;
typedef enum {
--
1.7.6.4
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH BlueZ 4/4] Add option to set priority for btiotest
2011-11-03 15:15 [PATCH BlueZ 1/4] Add option 'Y' to set socket priority for l2test Luiz Augusto von Dentz
2011-11-03 15:15 ` [PATCH BlueZ 2/4] Add option 'Y' to set socket priority for rctest Luiz Augusto von Dentz
2011-11-03 15:15 ` [PATCH BlueZ 3/4] btio: add BT_IO_OPT_PRIORITY option Luiz Augusto von Dentz
@ 2011-11-03 15:15 ` Luiz Augusto von Dentz
2011-11-04 13:43 ` [PATCH BlueZ 1/4] Add option 'Y' to set socket priority for l2test Johan Hedberg
2011-11-04 20:47 ` Marcel Holtmann
4 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2011-11-03 15:15 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Setting a priority outside the range 0 to 6 requires the CAP_NET_ADMIN
capability.
---
test/btiotest.c | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/test/btiotest.c b/test/btiotest.c
index c02a25a..91fc1d5 100644
--- a/test/btiotest.c
+++ b/test/btiotest.c
@@ -225,7 +225,8 @@ static void confirm_cb(GIOChannel *io, gpointer user_data)
}
static void l2cap_connect(const char *src, const char *dst, uint16_t psm,
- gint disconn, gint sec)
+ gint disconn, gint sec,
+ gint prio)
{
struct io_data *data;
GError *err = NULL;
@@ -242,6 +243,7 @@ static void l2cap_connect(const char *src, const char *dst, uint16_t psm,
BT_IO_OPT_DEST, dst,
BT_IO_OPT_PSM, psm,
BT_IO_OPT_SEC_LEVEL, sec,
+ BT_IO_OPT_PRIORITY, prio,
BT_IO_OPT_INVALID);
else
data->io = bt_io_connect(BT_IO_L2CAP, connect_cb, data,
@@ -250,6 +252,7 @@ static void l2cap_connect(const char *src, const char *dst, uint16_t psm,
BT_IO_OPT_DEST, dst,
BT_IO_OPT_PSM, psm,
BT_IO_OPT_SEC_LEVEL, sec,
+ BT_IO_OPT_PRIORITY, prio,
BT_IO_OPT_INVALID);
if (!data->io) {
@@ -466,6 +469,7 @@ static gint opt_disconn = -1;
static gint opt_accept = DEFAULT_ACCEPT_TIMEOUT;
static gint opt_sec = 0;
static gboolean opt_master = FALSE;
+static gint opt_priority = 0;
static GMainLoop *main_loop;
@@ -490,6 +494,10 @@ static GOptionEntry options[] = {
"Accept connection after N seconds" },
{ "master", 'm', 0, G_OPTION_ARG_NONE, &opt_master,
"Master role switch (incoming connections)" },
+ { "priority", 'P', 0, G_OPTION_ARG_INT, &opt_priority,
+ "Transmission priority: Setting a priority "
+ "outside the range 0 to 6 requires the"
+ "CAP_NET_ADMIN capability." },
{ NULL },
};
@@ -510,13 +518,15 @@ int main(int argc, char *argv[])
g_option_context_free(context);
- printf("accept=%d, reject=%d, discon=%d, defer=%d, sec=%d\n",
- opt_accept, opt_reject, opt_disconn, opt_defer, opt_sec);
+ printf("accept=%d, reject=%d, discon=%d, defer=%d, sec=%d, prio=%d\n",
+ opt_accept, opt_reject, opt_disconn, opt_defer, opt_sec,
+ opt_priority);
if (opt_psm) {
if (argc > 1)
l2cap_connect(opt_dev, argv[1], opt_psm,
- opt_disconn, opt_sec);
+ opt_disconn, opt_sec,
+ opt_priority);
else
l2cap_listen(opt_dev, opt_psm, opt_defer, opt_reject,
opt_disconn, opt_accept, opt_sec,
--
1.7.6.4
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH BlueZ 1/4] Add option 'Y' to set socket priority for l2test
2011-11-03 15:15 [PATCH BlueZ 1/4] Add option 'Y' to set socket priority for l2test Luiz Augusto von Dentz
` (2 preceding siblings ...)
2011-11-03 15:15 ` [PATCH BlueZ 4/4] Add option to set priority for btiotest Luiz Augusto von Dentz
@ 2011-11-04 13:43 ` Johan Hedberg
2011-11-04 20:47 ` Marcel Holtmann
4 siblings, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2011-11-04 13:43 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hi Luiz,
On Thu, Nov 03, 2011, Luiz Augusto von Dentz wrote:
> Priority is set using SO_PRIORITY, see man 7 socket for more details.
> ---
> test/l2test.c | 50 +++++++++++++++++++++++++++++++++++++++++++-------
> 1 files changed, 43 insertions(+), 7 deletions(-)
All four patches have been applied. Thanks.
Johan
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH BlueZ 1/4] Add option 'Y' to set socket priority for l2test
2011-11-03 15:15 [PATCH BlueZ 1/4] Add option 'Y' to set socket priority for l2test Luiz Augusto von Dentz
` (3 preceding siblings ...)
2011-11-04 13:43 ` [PATCH BlueZ 1/4] Add option 'Y' to set socket priority for l2test Johan Hedberg
@ 2011-11-04 20:47 ` Marcel Holtmann
2011-11-04 21:38 ` Gustavo Padovan
4 siblings, 1 reply; 7+ messages in thread
From: Marcel Holtmann @ 2011-11-04 20:47 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hi Luiz,
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> Priority is set using SO_PRIORITY, see man 7 socket for more details.
why are we using the letter 'Y'?
Regards
Marcel
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH BlueZ 1/4] Add option 'Y' to set socket priority for l2test
2011-11-04 20:47 ` Marcel Holtmann
@ 2011-11-04 21:38 ` Gustavo Padovan
0 siblings, 0 replies; 7+ messages in thread
From: Gustavo Padovan @ 2011-11-04 21:38 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: Luiz Augusto von Dentz, linux-bluetooth
Hi Marcel,
* Marcel Holtmann <marcel@holtmann.org> [2011-11-04 21:47:57 +0100]:
> Hi Luiz,
>
> > From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> >
> > Priority is set using SO_PRIORITY, see man 7 socket for more details.
>
> why are we using the letter 'Y'?
Probably because we are running out of letters in l2test, almost of them are
already taken.
Gustavo
^ permalink raw reply [flat|nested] 7+ messages in thread