summaryrefslogtreecommitdiff
path: root/android/handsfree-client.c
diff options
context:
space:
mode:
authorLukasz Rymanowski <lukasz.rymanowski@tieto.com>2014-11-19 10:43:48 +0100
committerSzymon Janc <szymon.janc@tieto.com>2014-11-19 15:07:32 +0100
commit3ee207f53a2ec3828413c6c9e11bee65ff6c8136 (patch)
tree1919e3124eb761206bbcae9fba8f7752f9b46a4f /android/handsfree-client.c
parent91f2d77b0c393dba325c00889da66f3d6a2fbca7 (diff)
downloadbluez-3ee207f53a2ec3828413c6c9e11bee65ff6c8136.tar.gz
android/handsfree-client: Implement codec negotiations
Diffstat (limited to 'android/handsfree-client.c')
-rw-r--r--android/handsfree-client.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/android/handsfree-client.c b/android/handsfree-client.c
index a6d7e62a2..283519f8f 100644
--- a/android/handsfree-client.c
+++ b/android/handsfree-client.c
@@ -116,6 +116,7 @@ struct device {
struct hfp_hf *hf;
uint8_t state;
+ uint8_t negotiated_codec;
uint32_t features;
struct hfp_codec codecs[2];
@@ -1022,6 +1023,55 @@ static void binp_cb(struct hfp_context *context, void *user_data)
sizeof(*ev) + ev->number_len, ev);
}
+static bool is_codec_supported_localy(struct device *dev, uint8_t codec)
+{
+ int i;
+
+ for (i = 0; i < CODECS_COUNT; i++) {
+ if (dev->codecs[i].type != codec)
+ continue;
+
+ return dev->codecs[i].local_supported;
+ }
+
+ return false;
+}
+
+static void bcs_resp(enum hfp_result result, enum hfp_error cme_err,
+ void *user_data)
+{
+ if (result != HFP_RESULT_OK)
+ error("hf-client: Error on AT+BCS (err=%u)", result);
+}
+
+static void bcs_cb(struct hfp_context *context, void *user_data)
+{
+ struct device *dev = user_data;
+ unsigned int codec;
+ char codecs_string[8];
+
+ DBG("");
+
+ if (!hfp_context_get_number(context, &codec))
+ goto failed;
+
+ if (!is_codec_supported_localy(dev, codec))
+ goto failed;
+
+ dev->negotiated_codec = codec;
+
+ hfp_hf_send_command(dev->hf, bcs_resp, dev, "AT+BCS=%u", codec);
+
+ return;
+
+failed:
+ error("hf-client: Could not get codec");
+
+ get_local_codecs_string(dev, codecs_string, sizeof(codecs_string));
+
+ hfp_hf_send_command(dev->hf, bcs_resp, dev, "AT+BCS=%s", codecs_string);
+}
+
static void slc_completed(struct device *dev)
{
int i;
@@ -1052,6 +1102,7 @@ static void slc_completed(struct device *dev)
hfp_hf_register(dev->hf, cops_cb, "+COPS", dev, NULL);
hfp_hf_register(dev->hf, cnum_cb, "+CNUM", dev, NULL);
hfp_hf_register(dev->hf, binp_cb, "+BINP", dev, NULL);
+ hfp_hf_register(dev->hf, bcs_cb, "+BCS", dev, NULL);
if (!hfp_hf_send_command(dev->hf, cmd_complete_cb, NULL, "AT+COPS=3,0"))
info("hf-client: Could not send AT+COPS=3,0");