#include "btio.h"
#define DEFAULT_ACCEPT_TIMEOUT 2
+static gint opt_update_sec = 0;
struct io_data {
guint ref;
return FALSE;
}
+static void update_sec_level(struct io_data *data)
+{
+ GError *err = NULL;
+ int sec_level;
+
+ if (!bt_io_get(data->io, data->type, &err,
+ BT_IO_OPT_SEC_LEVEL, &sec_level,
+ BT_IO_OPT_INVALID)) {
+ printf("bt_io_get(OPT_SEC_LEVEL): %s\n", err->message);
+ g_clear_error(&err);
+ return;
+ }
+
+ printf("sec_level=%d\n", sec_level);
+
+ if (opt_update_sec == sec_level)
+ return;
+
+ if (!bt_io_set(data->io, data->type, &err,
+ BT_IO_OPT_SEC_LEVEL, opt_update_sec,
+ BT_IO_OPT_INVALID)) {
+ printf("bt_io_set(OPT_SEC_LEVEL): %s\n", err->message);
+ g_clear_error(&err);
+ }
+}
+
static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
{
struct io_data *data = user_data;
io_data_ref(data);
+
+ if (opt_update_sec > 0)
+ update_sec_level(data);
+
cond = G_IO_NVAL | G_IO_HUP | G_IO_ERR;
g_io_add_watch_full(io, G_PRIORITY_DEFAULT, cond, io_watch, data,
(GDestroyNotify) io_data_unref);
io_data_ref(data);
+ if (opt_update_sec > 0)
+ update_sec_level(data);
+
if (!bt_io_accept(data->io, connect_cb, data,
(GDestroyNotify) io_data_unref, NULL)) {
printf("bt_io_accept() failed\n");
"Use DEFER_SETUP for incoming connections" },
{ "sec-level", 'S', 0, G_OPTION_ARG_INT, &opt_sec,
"Security level" },
+ { "update-sec-level", 'U', 0, G_OPTION_ARG_INT, &opt_update_sec,
+ "Update security level" },
{ "dev", 'i', 0, G_OPTION_ARG_STRING, &opt_dev,
"Which HCI device to use" },
{ "reject", 'r', 0, G_OPTION_ARG_INT, &opt_reject,
g_option_context_free(context);
- 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);
+ printf("accept=%d, reject=%d, discon=%d, defer=%d, sec=%d,"
+ " update_sec=%d, prio=%d\n", opt_accept, opt_reject,
+ opt_disconn, opt_defer, opt_sec, opt_update_sec, opt_priority);
if (opt_psm || opt_cid) {
if (argc > 1)