diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index 1bc97aa..ee2cb18 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
noninteractive_quit(EXIT_SUCCESS);
}
-static void cmd_setting(struct mgmt *mgmt, uint16_t index, uint16_t op,
- int argc, char **argv)
+static bool parse_setting(int argc, char **argv, uint8_t *val)
{
- uint8_t val;
-
if (argc < 2) {
print("Specify \"on\" or \"off\"");
- return noninteractive_quit(EXIT_FAILURE);
+ return false;
}
if (strcasecmp(argv[1], "on") == 0 || strcasecmp(argv[1], "yes") == 0)
- val = 1;
+ *val = 1;
else if (strcasecmp(argv[1], "off") == 0)
- val = 0;
+ *val = 0;
else
- val = atoi(argv[1]);
+ *val = atoi(argv[1]);
+ return true;
+}
+
+static void cmd_setting(struct mgmt *mgmt, uint16_t index, uint16_t op,
+ int argc, char **argv)
+{
+ uint8_t val;
+
+ if (parse_setting(argc, argv, &val) == false)
+ return noninteractive_quit(EXIT_FAILURE);
if (index == MGMT_INDEX_NONE)
index = 0;
{
struct mgmt_cp_set_privacy cp;
- if (argc < 2) {
- print("Specify \"on\" or \"off\"");
+ if (parse_setting(argc, argv, &cp.privacy) == false)
return noninteractive_quit(EXIT_FAILURE);
- }
-
- if (strcasecmp(argv[1], "on") == 0 || strcasecmp(argv[1], "yes") == 0)
- cp.privacy = 0x01;
- else if (strcasecmp(argv[1], "off") == 0)
- cp.privacy = 0x00;
- else
- cp.privacy = atoi(argv[1]);
if (index == MGMT_INDEX_NONE)
index = 0;
{
struct mgmt_cp_set_external_config cp;
- if (argc < 2) {
- print("Specify \"on\" or \"off\"");
+ if (parse_setting(argc, argv, &cp.config) == false)
return noninteractive_quit(EXIT_FAILURE);
- }
-
- if (strcasecmp(argv[1], "on") == 0 || strcasecmp(argv[1], "yes") == 0)
- cp.config = 0x01;
- else if (strcasecmp(argv[1], "off") == 0)
- cp.config = 0x00;
- else
- cp.config = atoi(argv[1]);
if (index == MGMT_INDEX_NONE)
index = 0;