From 979a048e34bf6449e43cda34505fe3cccb9cffc0 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Mon, 7 Mar 2011 09:46:39 +0530 Subject: bluetooth: Handle configuration failures more gracefully This should help make configuration failures not necessitate a bluetoothd restart. --- src/modules/bluetooth/module-bluetooth-device.c | 50 ++++++++++++++----------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c index 42a7ffea2..3ce878d7c 100644 --- a/src/modules/bluetooth/module-bluetooth-device.c +++ b/src/modules/bluetooth/module-bluetooth-device.c @@ -530,6 +530,28 @@ static int get_caps(struct userdata *u, uint8_t seid) { return 0; } +static int close_stream(struct userdata *u) { + union { + struct bt_close_req close_req; + struct bt_close_rsp close_rsp; + bt_audio_error_t error; + uint8_t buf[BT_SUGGESTED_BUFFER_SIZE]; + } msg; + + memset(&msg, 0, sizeof(msg)); + msg.close_req.h.type = BT_REQUEST; + msg.close_req.h.name = BT_CLOSE; + msg.close_req.h.length = sizeof(msg.close_req); + + if (service_send(u, &msg.close_req.h) < 0) + return -1; + + if (service_expect(u, &msg.close_rsp.h, sizeof(msg), BT_CLOSE, sizeof(msg.close_rsp)) < 0) + return -1; + + return 0; +} + /* Run from main thread */ static uint8_t a2dp_default_bitpool(uint8_t freq, uint8_t mode) { @@ -887,11 +909,15 @@ static int set_conf(struct userdata *u) { } msg.setconf_req.h.length += msg.setconf_req.codec.length - sizeof(msg.setconf_req.codec); - if (service_send(u, &msg.setconf_req.h) < 0) + if (service_send(u, &msg.setconf_req.h) < 0) { + close_stream(u); return -1; + } - if (service_expect(u, &msg.setconf_rsp.h, sizeof(msg), BT_SET_CONFIGURATION, sizeof(msg.setconf_rsp)) < 0) + if (service_expect(u, &msg.setconf_rsp.h, sizeof(msg), BT_SET_CONFIGURATION, sizeof(msg.setconf_rsp)) < 0) { + close_stream(u); return -1; + } u->link_mtu = msg.setconf_rsp.link_mtu; @@ -1068,26 +1094,6 @@ static int stop_stream_fd(struct userdata *u) { return r; } -static int close_stream(struct userdata *u) { - union { - struct bt_close_req close_req; - struct bt_close_rsp close_rsp; - bt_audio_error_t error; - uint8_t buf[BT_SUGGESTED_BUFFER_SIZE]; - } msg; - - memset(&msg, 0, sizeof(msg)); - msg.close_req.h.type = BT_REQUEST; - msg.close_req.h.name = BT_CLOSE; - msg.close_req.h.length = sizeof(msg.close_req); - - if (service_send(u, &msg.close_req.h) < 0) - return -1; - - if (service_expect(u, &msg.close_rsp.h, sizeof(msg), BT_CLOSE, sizeof(msg.close_rsp)) < 0) - return -1; -} - static void bt_transport_release(struct userdata *u) { const char *accesstype = "rw"; const pa_bluetooth_transport *t; -- cgit v1.2.3