summaryrefslogtreecommitdiff
path: root/tools/btpclient.c
diff options
context:
space:
mode:
authorSzymon Janc <szymon.janc@codecoup.pl>2017-12-08 14:56:22 +0100
committerSzymon Janc <szymon.janc@codecoup.pl>2017-12-14 10:08:32 +0100
commit31c97a2a0634fdf70a7aab1f0ebbc58c4a51162e (patch)
treeaf1428111aabe16547a846c9a8a2854fbf772e3c /tools/btpclient.c
parentb285313db39e535c8de6a5702fcef79c90b42448 (diff)
downloadbluez-31c97a2a0634fdf70a7aab1f0ebbc58c4a51162e.tar.gz
tools/btpclient: Add support for reseting adapter
For now this means only removing all bonded devices.
Diffstat (limited to 'tools/btpclient.c')
-rw-r--r--tools/btpclient.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/tools/btpclient.c b/tools/btpclient.c
index e94fc18a5..eafa9d960 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -189,6 +189,77 @@ failed:
btp_send_error(btp, BTP_GAP_SERVICE, index, status);
}
+static void remove_device_setup(struct l_dbus_message *message,
+ void *user_data)
+{
+ struct btp_device *device = user_data;
+
+ l_dbus_message_set_arguments(message, "o",
+ l_dbus_proxy_get_path(device->proxy));
+}
+
+static void remove_device_reply(struct l_dbus_proxy *proxy,
+ struct l_dbus_message *result,
+ void *user_data)
+{
+ struct btp_device *device = user_data;
+ struct btp_adapter *adapter = find_adapter_by_proxy(proxy);
+
+ if (!adapter)
+ return;
+
+ if (l_dbus_message_is_error(result)) {
+ const char *name;
+
+ l_dbus_message_get_error(result, &name, NULL);
+
+ l_error("Failed to remove device %s (%s)",
+ l_dbus_proxy_get_path(device->proxy),
+ name);
+ return;
+ }
+
+ l_queue_remove(adapter->devices, device);
+}
+
+static void btp_gap_reset(uint8_t index, const void *param, uint16_t length,
+ void *user_data)
+{
+ struct btp_adapter *adapter = find_adapter_by_index(index);
+ const struct l_queue_entry *entry;
+ uint8_t status;
+ bool prop;
+
+ if (!adapter) {
+ status = BTP_ERROR_INVALID_INDEX;
+ goto failed;
+ }
+
+ /* Adapter needs to be powered to be able to remove devices */
+ if (!l_dbus_proxy_get_property(adapter->proxy, "Powered", "b", &prop) ||
+ !prop) {
+ status = BTP_ERROR_FAIL;
+ goto failed;
+ }
+
+ for (entry = l_queue_get_entries(adapter->devices); entry;
+ entry = entry->next) {
+ struct btp_device *device = entry->data;
+
+ l_dbus_proxy_method_call(adapter->proxy, "RemoveDevice",
+ remove_device_setup,
+ remove_device_reply, device,
+ NULL);
+ }
+
+ /* TODO for we assume all went well */
+ btp_send(btp, BTP_GAP_SERVICE, BTP_OP_GAP_RESET, index, 0, NULL);
+ return;
+
+failed:
+ btp_send_error(btp, BTP_GAP_SERVICE, index, status);
+}
+
struct set_setting_data {
struct btp_adapter *adapter;
uint8_t opcode;
@@ -331,6 +402,9 @@ static void register_gap_service(void)
btp_register(btp, BTP_GAP_SERVICE, BTP_OP_GAP_READ_COTROLLER_INFO,
btp_gap_read_info, NULL, NULL);
+ btp_register(btp, BTP_GAP_SERVICE, BTP_OP_GAP_RESET,
+ btp_gap_reset, NULL, NULL);
+
btp_register(btp, BTP_GAP_SERVICE, BTP_OP_GAP_SET_POWERED,
btp_gap_set_powered, NULL, NULL);