Change power_on & power_off adapter_ops callbacks to set_powered

The current idea is to have a single set_powered management command
which for the switching on case would leave the controller in a
non-connectable, non-pairable and non-discoverable state.
diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
index 34421ee..b76549e 100644
--- a/doc/mgmt-api.txt
+++ b/doc/mgmt-api.txt
@@ -76,14 +76,14 @@
 				0x02 802.11 (AMP)
 
 
-Read Controller Statistics Command
-==================================
+Set Powered Command
+===================
 
 	Command Code:		0x0005
 	Command Parameters:	Controller_Index (2 Octets)
-	Return Paramters:	Status (1 Octet)
-				Controller_Index (2 Octets)
-				....
+				Powered (1 Octet)
+	Return Paramters:	Controller_Index (2 Octets)
+
 
 
 Read Tracing Buffer Size Command
diff --git a/lib/mgmt.h b/lib/mgmt.h
index cc1be34..aa8f1c8 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -67,16 +67,10 @@
 	uint16_t hci_rev;
 } __packed;
 
-#define MGMT_OP_POWER_ON		0x0005
-struct mgmt_cp_power_on {
+#define MGMT_OP_SET_POWERED		0x0005
+struct mgmt_cp_set_powered {
 	uint16_t index;
-	uint8_t discoverable;
-	uint8_t pairable;
-} __packed;
-
-#define MGMT_OP_POWER_OFF		0x0006
-struct mgmt_cp_power_off {
-	uint16_t index;
+	uint8_t powered;
 } __packed;
 
 #define MGMT_EV_CMD_COMPLETE		0x0001
diff --git a/plugins/hciops.c b/plugins/hciops.c
index be143e9..38ade5e 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2452,12 +2452,15 @@
 	}
 }
 
-static int hciops_power_on(int index, gboolean discoverable)
+static int hciops_set_powered(int index, gboolean powered)
 {
 	struct dev_info *dev = &devs[index];
 	int err;
 
-	DBG("hci%d", index);
+	DBG("hci%d powered %d", index, powered);
+
+	if (powered == FALSE)
+		return hciops_power_off(index);
 
 	if (ioctl(dev->sk, HCIDEVUP, index) == 0)
 		return 0;
@@ -3164,8 +3167,7 @@
 static struct btd_adapter_ops hci_ops = {
 	.setup = hciops_setup,
 	.cleanup = hciops_cleanup,
-	.power_on = hciops_power_on,
-	.power_off = hciops_power_off,
+	.set_powered = hciops_set_powered,
 	.set_connectable = hciops_set_connectable,
 	.set_discoverable = hciops_set_discoverable,
 	.set_pairable = hciops_set_pairable,
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index a9c1b2f..7dfd3d8 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -233,26 +233,6 @@
 	}
 }
 
-static int mgmt_power_off(int index)
-{
-	char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_power_off)];
-	struct mgmt_hdr *hdr = (void *) buf;
-	struct mgmt_cp_power_off *cp = (void *) &buf[sizeof(*hdr)];
-
-	DBG("index %d", index);
-
-	memset(buf, 0, sizeof(buf));
-	hdr->opcode = MGMT_OP_POWER_OFF;
-	hdr->len = htobs(sizeof(*cp));
-
-	cp->index = htobs(index);
-
-	if (write(mgmt_sock, buf, sizeof(buf)) < 0)
-		return -errno;
-
-	return 0;
-}
-
 static int mgmt_set_discoverable(int index, gboolean discoverable)
 {
 	DBG("index %d discoverable %d", index, discoverable);
@@ -265,6 +245,27 @@
 	return -ENOSYS;
 }
 
+static int mgmt_set_powered(int index, gboolean powered)
+{
+	char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_set_powered)];
+	struct mgmt_hdr *hdr = (void *) buf;
+	struct mgmt_cp_set_powered *cp = (void *) &buf[sizeof(*hdr)];
+
+	DBG("index %d powered %d", index, powered);
+
+	memset(buf, 0, sizeof(buf));
+	hdr->opcode = MGMT_OP_SET_POWERED;
+	hdr->len = htobs(sizeof(*cp));
+
+	cp->index = htobs(index);
+	cp->powered = powered;
+
+	if (write(mgmt_sock, buf, sizeof(buf)) < 0)
+		return -errno;
+
+	return 0;
+}
+
 static void read_info_complete(int sk, void *buf, size_t len)
 {
 	struct mgmt_rp_read_info *rp = buf;
@@ -317,7 +318,7 @@
 
 	btd_adapter_get_state(adapter, &mode, NULL, &pairable);
 	if (mode == MODE_OFF) {
-		mgmt_power_off(index);
+		mgmt_set_powered(index, FALSE);
 		return;
 	}
 
@@ -526,29 +527,6 @@
 	}
 }
 
-static int mgmt_power_on(int index, gboolean discoverable)
-{
-	struct controller_info *info = &controllers[index];
-	char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_power_on)];
-	struct mgmt_hdr *hdr = (void *) buf;
-	struct mgmt_cp_power_on *cp = (void *) &buf[sizeof(*hdr)];
-
-	DBG("index %d discoverable %d", index, discoverable);
-
-	memset(buf, 0, sizeof(buf));
-	hdr->opcode = MGMT_OP_POWER_ON;
-	hdr->len = htobs(sizeof(*cp));
-
-	cp->index = htobs(index);
-	cp->discoverable = discoverable;
-	cp->pairable = info->pairable;
-
-	if (write(mgmt_sock, buf, sizeof(buf)) < 0)
-		return -errno;
-
-	return 0;
-}
-
 static int mgmt_set_connectable(int index, gboolean connectable)
 {
 	DBG("index %d connectable %d", index, connectable);
@@ -829,8 +807,7 @@
 static struct btd_adapter_ops mgmt_ops = {
 	.setup = mgmt_setup,
 	.cleanup = mgmt_cleanup,
-	.power_on = mgmt_power_on,
-	.power_off = mgmt_power_off,
+	.set_powered = mgmt_set_powered,
 	.set_connectable = mgmt_set_connectable,
 	.set_discoverable = mgmt_set_discoverable,
 	.set_pairable = mgmt_set_pairable,
diff --git a/src/adapter.c b/src/adapter.c
index ff1f0a4..69d3da0 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -459,7 +459,7 @@
 	discoverable = new_mode == MODE_DISCOVERABLE;
 
 	if (!adapter->up && new_mode != MODE_OFF) {
-		err = adapter_ops->power_on(adapter->dev_id, discoverable);
+		err = adapter_ops->set_powered(adapter->dev_id, TRUE);
 		if (err < 0)
 			return err;
 
@@ -467,7 +467,7 @@
 	}
 
 	if (adapter->up && new_mode == MODE_OFF) {
-		err = adapter_ops->power_off(adapter->dev_id);
+		err = adapter_ops->set_powered(adapter->dev_id, FALSE);
 		if (err < 0)
 			return err;
 
@@ -3318,7 +3318,7 @@
 
 	discoverable = get_mode(&adapter->bdaddr, mode) == MODE_DISCOVERABLE;
 
-	return adapter_ops->power_on(adapter->dev_id, discoverable);
+	return adapter_ops->set_powered(adapter->dev_id, TRUE);
 }
 
 int btd_adapter_switch_online(struct btd_adapter *adapter)
@@ -3333,7 +3333,7 @@
 
 	discoverable = get_mode(&adapter->bdaddr, "on") == MODE_DISCOVERABLE;
 
-	return adapter_ops->power_on(adapter->dev_id, discoverable);
+	return adapter_ops->set_powered(adapter->dev_id, TRUE);
 }
 
 int btd_adapter_switch_offline(struct btd_adapter *adapter)
@@ -3344,7 +3344,7 @@
 	if (!adapter->up)
 		return 0;
 
-	return adapter_ops->power_off(adapter->dev_id);
+	return adapter_ops->set_powered(adapter->dev_id, FALSE);
 }
 
 int btd_register_adapter_ops(struct btd_adapter_ops *ops, gboolean priority)
diff --git a/src/adapter.h b/src/adapter.h
index ebbe633..ab83011 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -199,8 +199,7 @@
 struct btd_adapter_ops {
 	int (*setup) (void);
 	void (*cleanup) (void);
-	int (*power_on) (int index, gboolean powered);
-	int (*power_off) (int index);
+	int (*set_powered) (int index, gboolean powered);
 	int (*set_connectable) (int index, gboolean connectable);
 	int (*set_discoverable) (int index, gboolean discoverable);
 	int (*set_pairable) (int index, gboolean pairable);