---
 plugins/hfp_hf_bluez5.c | 41 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index a6cc156..4c8f412 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -67,6 +67,8 @@ struct hfp {
        struct hfp_slc_info info;
        DBusMessage *msg;
        struct ofono_handsfree_card *card;
+       ofono_handsfree_card_connect_cb_t cb;
+       void *user_data;
 };
 
 static GDBusClient *bluez = NULL;
@@ -324,11 +326,48 @@ static void hfp16_card_remove(struct ofono_handsfree_card 
*card)
 
 }
 
+static void bcc_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+       struct hfp *hfp = user_data;
+       struct hfp_slc_info *info = &hfp->info;
+
+       if (ok)
+               CALLBACK_WITH_SUCCESS(hfp->cb, hfp->user_data);
+       else
+               CALLBACK_WITH_FAILURE(hfp->cb, hfp->user_data);
+
+       g_at_chat_unref(info->chat);
+}
+
 static void hfp16_card_connect(struct ofono_handsfree_card *card,
                                        ofono_handsfree_card_connect_cb_t cb,
                                        void *data)
 {
-       CALLBACK_WITH_FAILURE(cb, data);
+       struct hfp *hfp = ofono_handsfree_card_get_data(card);
+       struct hfp_slc_info *info = &hfp->info;
+
+       if (info->chat == NULL) {
+               CALLBACK_WITH_FAILURE(cb, data);
+               return;
+       }
+
+       if (!(info->hf_features & HFP_HF_FEATURE_CODEC_NEGOTIATION &&
+                       info->ag_features & HFP_AG_FEATURE_CODEC_NEGOTIATION)) {
+               /*
+                * If both sides don't support codec negotiation,
+                * fallback to direct SCO connection. Calling
+                * connect_sco() hands the connection responsability
+                * to the core, so no need to call the callback
+                */
+               ofono_handsfree_card_connect_sco(card);
+               return;
+       }
+
+       info->chat = g_at_chat_ref(info->chat);
+       hfp->cb = cb;
+       hfp->user_data = data;
+
+       g_at_chat_send(info->chat, "AT+BCC", NULL, bcc_cb, hfp, NULL);
 }
 
 static struct ofono_handsfree_card_driver hfp16_hf_driver = {
-- 
1.8.2

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to