From: Szymon Janc <szymon.janc@tieto.com>
To: Lukasz Rymanowski <lukasz.rymanowski@tieto.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH 14/14] android/handsfree-client: Implement codec negotiations
Date: Tue, 18 Nov 2014 22:58:52 +0100 [thread overview]
Message-ID: <3758767.CHCAAQ9We3@leonov> (raw)
In-Reply-To: <1415789377-20458-15-git-send-email-lukasz.rymanowski@tieto.com>
Hi Łukasz,
On Wednesday 12 of November 2014 11:49:37 Lukasz Rymanowski wrote:
> ---
> android/handsfree-client.c | 62
> ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62
> insertions(+)
>
> diff --git a/android/handsfree-client.c b/android/handsfree-client.c
> index 4338c11..74d1547 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];
>
> @@ -1034,6 +1035,66 @@ 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)
> +{
> + DBG("%d", result);
Shouldn't we handle error response?
> +}
> +
> +static void bcs_cb(struct hfp_context *context, void *user_data)
> +{
> + struct device *dev = user_data;
> + uint32_t codec;
unsigned int
> + char codecs_string[2 * CODECS_COUNT + 1];
> + char cmd[sizeof(codecs_string) + 7];
Those really deserve some comment.
> +
> + DBG("");
> +
> + if (!context) {
> + error("hf-client: incorrect BCS response");
> + return;
> + }
Not needed.
> +
> + memset(cmd, 0, sizeof(cmd));
> +
> + if (!hfp_context_get_number(context, &codec))
> + goto failed;
> +
> + if (!is_codec_supported_localy(dev, codec))
> + goto failed;
> +
> + sprintf(cmd, "AT+BCS=%d", codec);
> +
> + dev->negotiated_codec = codec;
> +
> + goto done;
> +
> +failed:
I'd avoid this mixed labels jump, those make code hard to read.
I'd make failed label handle only fail case. Just call hfp_hf_send_command
instead of those sprintfs. This will also make cmd not needed.
> + error("hf-client: Could not get codec");
> +
> + strcpy(cmd, "AT+BCS=");
> +
> + get_local_codecs_string(dev, codecs_string, sizeof(codecs_string));
> + strcat(cmd, codecs_string);
maybe this is not really needed since hfp_hf_send_command accepts format
string?
hfp_hf_send_command(dev->hf, bcs_resp, dev, "AT+BCS=%s", codecs_string);
> +
> +done:
> + hfp_hf_send_command(dev->hf, bcs_resp, dev, cmd);
> +}
> +
> static void slc_completed(struct device *dev)
> {
> int i;
> @@ -1064,6 +1125,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");
--
BR
Szymon Janc
prev parent reply other threads:[~2014-11-18 21:58 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-12 10:49 [PATCH 00/14] android/handsfree-clien: Second set of HFP HF Lukasz Rymanowski
2014-11-12 10:49 ` [PATCH 01/14] android/handsfree-client: Add handle start/stop vr Lukasz Rymanowski
2014-11-18 16:04 ` Szymon Janc
2014-11-12 10:49 ` [PATCH 02/14] android/handsfree-client: Add volume control handling Lukasz Rymanowski
2014-11-18 16:12 ` Szymon Janc
2014-11-12 10:49 ` [PATCH 03/14] android/handsfree-client: Add handling dial command Lukasz Rymanowski
2014-11-18 16:18 ` Szymon Janc
2014-11-12 10:49 ` [PATCH 04/14] android/handsfree-client: Add call action implementation Lukasz Rymanowski
2014-11-18 16:24 ` Szymon Janc
2014-11-12 10:49 ` [PATCH 05/14] android/handsfree-client: Implement query current calls Lukasz Rymanowski
2014-11-12 10:49 ` [PATCH 06/14] android/handsfree-client: Add handling +CLCC Lukasz Rymanowski
2014-11-18 16:29 ` Szymon Janc
2014-11-12 10:49 ` [PATCH 07/14] android/handsfree-client: Add support for +CIEV events Lukasz Rymanowski
2014-11-18 19:54 ` Szymon Janc
2014-11-12 10:49 ` [PATCH 08/14] android/handsfree-client: Send indicators val we got during SLC setup Lukasz Rymanowski
2014-11-18 19:55 ` Szymon Janc
2014-11-12 10:49 ` [PATCH 09/14] android/handsfree-client: Add support to get operator name Lukasz Rymanowski
2014-11-18 20:17 ` Szymon Janc
2014-11-12 10:49 ` [PATCH 10/14] android/handsfree-client: Send to AG that we do support long name Lukasz Rymanowski
2014-11-12 10:49 ` [PATCH 11/14] android/handsfree-client: Retrieve subscriber number information Lukasz Rymanowski
2014-11-18 20:52 ` Szymon Janc
2014-11-12 10:49 ` [PATCH 12/14] android/handsfree-client: Implement send DTMF codes Lukasz Rymanowski
2014-11-12 10:49 ` [PATCH 13/14] android/handsfree-client: Implement handling AT+BIND and +BIND Lukasz Rymanowski
2014-11-18 21:09 ` Szymon Janc
2014-11-12 10:49 ` [PATCH 14/14] android/handsfree-client: Implement codec negotiations Lukasz Rymanowski
2014-11-18 21:58 ` Szymon Janc [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3758767.CHCAAQ9We3@leonov \
--to=szymon.janc@tieto.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=lukasz.rymanowski@tieto.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.