diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index 75ea1ae..cca3e2c 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
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);
"\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"},
{ }
};