Diff between f45ee9ff351880f673a5ce7f7644477e0a7df826 and 1b0a4291d16e1cc87831487a61bee5a493a27ef2

Changed Files

File Additions Deletions Status
doc/mgmt-api.txt +7 -1 modified
lib/mgmt.h +5 -0 modified
monitor/control.c +2 -1 modified
src/mgmt.c +4 -4 modified
tools/btmgmt.c +27 -1 modified

Full Patch

diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
index 202c055..63284e0 100644
--- a/doc/mgmt-api.txt
+++ b/doc/mgmt-api.txt
@@ -303,9 +303,15 @@ Set Low Energy Command
 
 	Command Code:		0x000D
 	Controller Index:	<controller id>
-	Command Parameters:	Low_Energy (1 Octet)
+	Command Parameters:	Mode (1 Octet)
 	Return Parameters:	Current_Settings (4 Octets)
 
+	Possible mode values:
+
+			0x00	Off
+			0x01	Central
+			0x02	Peripheral
+
 	This command can be used when the controller is not powered and
 	all settings will be programmed once powered.
 
diff --git a/lib/mgmt.h b/lib/mgmt.h
index 6c7e44a..e196c78 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -92,6 +92,7 @@ struct mgmt_rp_read_index_list {
 #define MGMT_SETTING_BREDR		0x00000080
 #define MGMT_SETTING_HS			0x00000100
 #define MGMT_SETTING_LE			0x00000200
+#define MGMT_SETTING_LE_PERIPHERAL	0x00000400
 
 #define MGMT_OP_READ_INFO		0x0004
 struct mgmt_rp_read_info {
@@ -135,6 +136,10 @@ struct mgmt_cp_set_discoverable {
 
 #define MGMT_OP_SET_LE			0x000D
 
+#define MGMT_LE_OFF			0x00
+#define MGMT_LE_CENTRAL			0x01
+#define MGMT_LE_PERIPHERAL		0x02
+
 #define MGMT_OP_SET_DEV_CLASS		0x000E
 struct mgmt_cp_set_dev_class {
 	uint8_t major;
diff --git a/monitor/control.c b/monitor/control.c
index c300ae9..a6dc086 100644
--- a/monitor/control.c
+++ b/monitor/control.c
@@ -92,7 +92,8 @@ static void mgmt_controller_error(uint16_t len, const void *buf)
 
 static const char *settings_str[] = {
 	"powered", "connectable", "fast-connectable", "discoverable",
-	"pairable", "link-security", "ssp", "br/edr", "hs", "le"
+	"pairable", "link-security", "ssp", "br/edr", "hs", "le",
+	"le-peripheral"
 };
 
 static void mgmt_new_settings(uint16_t len, const void *buf)
diff --git a/src/mgmt.c b/src/mgmt.c
index 627fb4b..bef66cd 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -247,10 +247,10 @@ static int mgmt_set_ssp(int index, gboolean ssp)
 	return mgmt_set_mode(index, MGMT_OP_SET_SSP, ssp);
 }
 
-static int mgmt_set_low_energy(int index, gboolean le)
+static int mgmt_set_low_energy(int index, uint8_t mode)
 {
-	DBG("index %d le %d", index, le);
-	return mgmt_set_mode(index, MGMT_OP_SET_LE, le);
+	DBG("index %d mode %d", index, mode);
+	return mgmt_set_mode(index, MGMT_OP_SET_LE, mode);
 }
 
 static inline int mgmt_powered(uint32_t settings)
@@ -345,7 +345,7 @@ static void update_settings(struct btd_adapter *adapter, uint32_t settings)
 
 	if (mgmt_low_energy(info->supported_settings) &&
 						!mgmt_low_energy(settings))
-		mgmt_set_low_energy(index, TRUE);
+		mgmt_set_low_energy(index, MGMT_LE_CENTRAL);
 }
 
 static void mgmt_update_powered(struct btd_adapter *adapter,
diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index 2084b59..d20a966 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -235,6 +235,7 @@ static const char *settings_str[] = {
 				"br/edr",
 				"hs",
 				"le" ,
+				"le-peripheral",
 };
 
 static void print_settings(uint32_t settings)
@@ -1108,7 +1109,32 @@ static void cmd_hs(int mgmt_sk, uint16_t index, int argc, char **argv)
 
 static void cmd_le(int mgmt_sk, uint16_t index, int argc, char **argv)
 {
-	cmd_setting(mgmt_sk, index, MGMT_OP_SET_LE, argc, argv);
+	uint8_t val;
+
+	if (argc < 2) {
+		printf("Specify \"off\", \"central\" or \"peripheral\"\n");
+		exit(EXIT_FAILURE);
+	}
+
+	if (strcasecmp(argv[1], "on") == 0 ||
+			strcasecmp(argv[1], "yes") == 0 ||
+			strcasecmp(argv[1], "central") == 0)
+		val = MGMT_LE_CENTRAL;
+	else if (strcasecmp(argv[1], "peripheral") == 0)
+		val = MGMT_LE_PERIPHERAL;
+	else if (strcasecmp(argv[1], "off") == 0)
+		val = MGMT_LE_OFF;
+	else
+		val = atoi(argv[1]);
+
+	if (index == MGMT_INDEX_NONE)
+		index = 0;
+
+	if (mgmt_send_cmd(mgmt_sk, MGMT_OP_SET_LE, index, &val, sizeof(val),
+						setting_rsp, NULL) < 0) {
+		fprintf(stderr, "Unable to send set_le cmd\n");
+		exit(EXIT_FAILURE);
+	}
 }
 
 static void class_rsp(int mgmt_sk, uint16_t op, uint16_t id, uint8_t status,