summaryrefslogtreecommitdiff
path: root/tools/btgatt-client.c
diff options
context:
space:
mode:
authorLukasz Rymanowski <lukasz.rymanowski@tieto.com>2015-02-12 18:00:08 +0100
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2015-02-13 14:39:37 +0200
commit191f4b663978493004239a03ec8d543c15341cd6 (patch)
treef475fbbcdcc5ef6a8a6b78d4a938ceafe1d87780 /tools/btgatt-client.c
parentc21c706a50c50ab97ad266e9e33044eba4f26e04 (diff)
downloadbluez-191f4b663978493004239a03ec8d543c15341cd6.tar.gz
tools/btgatt-client: Add support for set/get security on the link
Diffstat (limited to 'tools/btgatt-client.c')
-rw-r--r--tools/btgatt-client.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index 75ea1ae6c..cca3e2c9e 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
@@ -938,6 +938,66 @@ static void cmd_unregister_notify(struct client *cli, char *cmd_str)
printf("Unregistered notify handler with id: %u\n", id);
}
+static void set_sec_level_usage(void)
+{
+ printf("Usage: set_sec_level <level>\n"
+ "level: 1-3\n"
+ "e.g.:\n"
+ "\tset-sec-level 2\n");
+}
+
+static void cmd_set_sec_level(struct client *cli, char *cmd_str)
+{
+ char *argvbuf[1];
+ char **argv = argvbuf;
+ int argc = 0;
+ char *endptr = NULL;
+ int level;
+
+ if (!bt_gatt_client_is_ready(cli->gatt)) {
+ printf("GATT client not initialized\n");
+ return;
+ }
+
+ if (!parse_args(cmd_str, 1, argv, &argc)) {
+ printf("Too many arguments\n");
+ set_sec_level_usage();
+ return;
+ }
+
+ if (argc < 1) {
+ set_sec_level_usage();
+ return;
+ }
+
+ level = strtol(argv[0], &endptr, 0);
+ if (!endptr || *endptr != '\0' || level < 1 || level > 3) {
+ printf("Invalid level: %s\n", argv[0]);
+ return;
+ }
+
+ if (bt_gatt_client_set_sec_level(cli->gatt, level) < 0)
+ printf("Could not set sec level\n");
+ else
+ printf("Setting security level %d success\n", level);
+}
+
+static void cmd_get_sec_level(struct client *cli, char *cmd_str)
+{
+ int level;
+
+ if (!bt_gatt_client_is_ready(cli->gatt)) {
+ printf("GATT client not initialized\n");
+ return;
+ }
+
+ level = bt_gatt_client_get_sec_level(cli->gatt);
+ if (level < 0)
+ printf("Could not set sec level\n");
+ else
+ printf("Security level: %u\n", level);
+}
+
static void cmd_help(struct client *cli, char *cmd_str);
typedef void (*command_func_t)(struct client *cli, char *cmd_str);
@@ -962,6 +1022,10 @@ static struct {
"\tSubscribe to not/ind from a characteristic" },
{ "unregister-notify", cmd_unregister_notify,
"Unregister a not/ind session"},
+ { "set-sec-level", cmd_set_sec_level,
+ "Set security level on le connection"},
+ { "get-sec-level", cmd_get_sec_level,
+ "Get security level on le connection"},
{ }
};