Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4385509ybb; Tue, 14 Apr 2020 06:20:57 -0700 (PDT) X-Google-Smtp-Source: APiQypICh5jwlK9W0TCDvGJSwUB+An5ygDqDGav+cB79I/t5sw50phxWufQo5B/rqH2gMa5IlG01 X-Received: by 2002:a50:f095:: with SMTP id v21mr12410182edl.103.1586870457553; Tue, 14 Apr 2020 06:20:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586870457; cv=none; d=google.com; s=arc-20160816; b=Qu+HVl1tXmkWoE/pv5NKvh1wiQaPkzfWHFv84QvHpeTaZXmSPjJfjdXo+6JkonzINN lbI8DPtg9XGsaiLiqRFZ5We/+TeNfu3HmrkEvD2F05HoqJCieRbuD+CvdvATnDPnDIs5 Tg8J0E1fg5R+WeGMSsoX7oTDRnzoeLU7e5swHYsFmYd1BKEXLUrigx9m7vnfSLBGlJcY XFIsRDa+tQtsjL6xzeeoZCDtsd6yz8Xamxz1FZWhRwNH1tVHJjv444WNWePFZdrJBgWK +zHc9DsXEXmf4SxIjmojv1HsX/XAEYEfMoG7aqFs+xdfH+mthrltYGr5bwI9xsCpW5ZW humg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LPehKwERNw71THHekQ14JAZ98RmhLApxny5QcBwdagQ=; b=sfoSwIj6Qc92VNfvpIj16y4eSSa4TTEfZKVlQAJOqbh6OymBcJZO94cRxSCjJPVFMv bjjPVIgFNh+HKLBF2zlMdxi/eylliNaJDxFPEK72yfcVgcK41Q6TWVTLF8DcJfzzbCHm jgYnhJHgdiIrL3HuvGc3pV+mH6bW0X3MwC7KIC7OwI6AiG+DKC+BW3KWmVf1dvQdFBP6 2dpFi8LlWCkIbOsO1ya5fMnnBGNmGQQ7sb3qLZcLNDBmzrxnRAXRGK+sZOiL1w8rFr8h U5gX0vTaJ8qY5ZpZ/msspb5h+9alrmv7pekb2aJ5eYAa2J1vLmmUZtxFkmjGklE3SxQP 0jJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FKa3fNh5; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j8si8141854edl.317.2020.04.14.06.20.33; Tue, 14 Apr 2020 06:20:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FKa3fNh5; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731528AbgDMQZp (ORCPT + 99 others); Mon, 13 Apr 2020 12:25:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:52028 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731515AbgDMQZn (ORCPT ); Mon, 13 Apr 2020 12:25:43 -0400 Received: from pali.im (pali.im [31.31.79.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DE13B20692; Mon, 13 Apr 2020 16:25:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586795143; bh=blYamwkQ3jtD5fZD4JKrWUYh8MlY3zYYDPawuIR/ZBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FKa3fNh5iUns7ho/DlDexcaBK/jk90dLbeaVHh32lUaZSWXTdWG/8u33+FZrMaG3r fokFw9CsRkBstHlBucpWAPmAMJTgMjBSyvD4xtZmgUiXAUoGvQrFLhXdabIITaYC8d 74D04+njLtt025piKulubW0b/WnDLdAwALYCX3k8= Received: by pali.im (Postfix) id 45937895; Mon, 13 Apr 2020 18:25:41 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Luiz Augusto von Dentz Cc: linux-bluetooth@vger.kernel.org, David Heidelberg Subject: [PATCH 1/3] src/profile: Distinguish between zero-set HFP AG features and unset HFP AG features Date: Mon, 13 Apr 2020 18:25:11 +0200 Message-Id: <20200413162513.2221-2-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200413162513.2221-1-pali@kernel.org> References: <20200321195404.fvyku5hmcuqxt7sg@pali> <20200413162513.2221-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org When HFP AG features are not set then according to HFP 1.7.2 specification it has value 0b001001. But when HFP AG features were explicitly set to zero, bluez did not propagated this value via NewConnection() DBus call, so callee used default value 0b001001 (according to HFP 1.7.2 specification) as bluez did not provided explicit zero value. To fix this problem add a new boolean variable have_features which indicates if SDP features were provided (with possible zero value) or not (when default value needs to be used). Code for generating SDP XML records were also updated to handle this fact. Signed-off-by: Pali Rohár --- src/profile.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/profile.c b/src/profile.c index 192fd0245..884440408 100644 --- a/src/profile.c +++ b/src/profile.c @@ -647,6 +647,7 @@ struct ext_profile { uint16_t version; uint16_t features; + bool have_features; GSList *records; GSList *servers; @@ -669,6 +670,7 @@ struct ext_io { uint16_t version; uint16_t features; + bool have_features; uint16_t psm; uint8_t chan; @@ -920,14 +922,18 @@ static void append_prop(gpointer a, gpointer b) dbus_message_iter_close_container(dict, &entry); } -static uint16_t get_supported_features(const sdp_record_t *rec) +static uint16_t get_supported_features(const sdp_record_t *rec, + bool *have_features) { sdp_data_t *data; data = sdp_data_get(rec, SDP_ATTR_SUPPORTED_FEATURES); - if (!data || data->dtd != SDP_UINT16) + if (!data || data->dtd != SDP_UINT16) { + *have_features = false; return 0; + } + *have_features = true; return data->val.uint16; } @@ -972,7 +978,8 @@ static bool send_new_connection(struct ext_profile *ext, struct ext_io *conn) if (remote_uuid) { rec = btd_device_get_record(conn->device, remote_uuid); if (rec) { - conn->features = get_supported_features(rec); + conn->features = get_supported_features(rec, + &conn->have_features); conn->version = get_profile_version(rec); } } @@ -991,7 +998,7 @@ static bool send_new_connection(struct ext_profile *ext, struct ext_io *conn) dict_append_entry(&dict, "Version", DBUS_TYPE_UINT16, &conn->version); - if (conn->features) + if (conn->have_features) dict_append_entry(&dict, "Features", DBUS_TYPE_UINT16, &conn->features); @@ -1589,7 +1596,8 @@ static void record_cb(sdp_list_t *recs, int err, gpointer user_data) if (conn->psm == 0 && sdp_get_proto_desc(protos, OBEX_UUID)) conn->psm = get_goep_l2cap_psm(rec); - conn->features = get_supported_features(rec); + conn->features = get_supported_features(rec, + &conn->have_features); conn->version = get_profile_version(rec); sdp_list_foreach(protos, (sdp_list_func_t) sdp_list_free, @@ -1750,15 +1758,19 @@ static int ext_disconnect_dev(struct btd_service *service) static char *get_hfp_hf_record(struct ext_profile *ext, struct ext_io *l2cap, struct ext_io *rfcomm) { + /* HFP 1.7.2: By default features bitfield is 0b000000 */ return g_strdup_printf(HFP_HF_RECORD, rfcomm->chan, ext->version, - ext->name, ext->features); + ext->name, + ext->have_features ? ext->features : 0x0); } static char *get_hfp_ag_record(struct ext_profile *ext, struct ext_io *l2cap, struct ext_io *rfcomm) { + /* HFP 1.7.2: By default features bitfield is 0b001001 */ return g_strdup_printf(HFP_AG_RECORD, rfcomm->chan, ext->version, - ext->name, ext->features); + ext->name, + ext->have_features ? ext->features : 0x9); } static char *get_hsp_ag_record(struct ext_profile *ext, struct ext_io *l2cap, @@ -1948,6 +1960,7 @@ static struct default_settings { struct ext_io *rfcomm); uint16_t version; uint16_t features; + bool have_features; } defaults[] = { { .uuid = SPP_UUID, @@ -2107,8 +2120,10 @@ static void ext_set_defaults(struct ext_profile *ext) if (settings->version) ext->version = settings->version; - if (settings->features) + if (settings->have_features) { ext->features = settings->features; + ext->have_features = true; + } if (settings->name) ext->name = g_strdup(settings->name); @@ -2198,6 +2213,7 @@ static int parse_ext_opt(struct ext_profile *ext, const char *key, dbus_message_iter_get_basic(value, &feat); ext->features = feat; + ext->have_features = true; } else if (strcasecmp(key, "Service") == 0) { if (type != DBUS_TYPE_STRING) return -EINVAL; -- 2.20.1