summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2012-10-22 12:43:43 +0300
committerJohan Hedberg <johan.hedberg@intel.com>2012-10-22 17:36:51 +0300
commit1b0a4291d16e1cc87831487a61bee5a493a27ef2 (patch)
tree9097ab0e158f38d0c9c11da28520ce0cfe443b23
parentf45ee9ff351880f673a5ce7f7644477e0a7df826 (diff)
mgmt: Add support for LE peripheral mode
-rw-r--r--doc/mgmt-api.txt8
-rw-r--r--lib/mgmt.h5
-rw-r--r--monitor/control.c3
-rw-r--r--src/mgmt.c8
-rw-r--r--tools/btmgmt.c28
5 files changed, 45 insertions, 7 deletions
diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
index 202c0550..63284e0d 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 6c7e44a5..e196c787 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 c300ae9e..a6dc0861 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 627fb4b3..bef66cd8 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 2084b59f..d20a966d 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,