Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp636144ybg; Wed, 10 Jun 2020 09:40:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwd2NeUNk21gESNJYR40GnBq34Exvd6oGglNqY2kz+tTVLzyY35Gu19Td0htX8rllvFf1I X-Received: by 2002:aa7:c942:: with SMTP id h2mr3295527edt.23.1591807238487; Wed, 10 Jun 2020 09:40:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591807238; cv=none; d=google.com; s=arc-20160816; b=VOSDJCAlbuwCv2g61UhVPKPYhl7ifD2l6sG9VE/YfSezD69WVlnvNxR4moe6Ts1K6X l4xGE5wKzdG5NP/m9iJOzfjvU1YT6VMPF4IV4UXVOJsQ45fSNO2m7yRiUfc0CAXw73V/ 9KLSBwZN7Rl8vit+DT0F10wROxsYFC+qI06fDiFqycmc+zQfTSv1hmaG0bUxdCTvV3th P90FRDkpgjLW3V+ds1SOv2WFp5whyeZomiOQXaMieX3xn3042eJxujfhHEeF2MN4UT3Q OouwOk6MxXwCSRGNsDbZq1B1MvN5YlvaFg05p7mFk+T8BGVSyHBS0hv3JVdWcU9hGv7r lRpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=X7/vqMkW7Y4LTypRRKLJs6c5lcIAOMRyOUevZTP5ZRs=; b=sbsnSuhxVHZlZCko/xsqBxr7C96b4LtIZWEmPxXgwhUfo++9A55FKnryOI0Da+FbQ2 alYXv8Qs2stwx2aS6KXEvko+Z2Ccsh3HcloiWv5GfZ9Ge8exA+hYM1DgiSe7A8dVrA31 PUhwboXXbL5pOa0he/h2zeP6MYmhgyJZaM3jkwV9uwTBJ1fENauQTLXaV9Mg9JMTQw4F GWw9oSv7iUq71wtv+wBIokJW1kN8XF6UIanj39DmmF0EbEDdioxI5xdlY65zp13dzGFv Q+TcQ/H2kkwU1dkXhp9rAwR4HrEbqZJojRUVyvXih7e78bl7IPH6WwTlP3kib8mKMjcq Hfuw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id me26si317014ejb.444.2020.06.10.09.40.12; Wed, 10 Jun 2020 09:40:38 -0700 (PDT) Received-SPF: pass (google.com: 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; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726616AbgFJOCC convert rfc822-to-8bit (ORCPT + 99 others); Wed, 10 Jun 2020 10:02:02 -0400 Received: from coyote.holtmann.net ([212.227.132.17]:39195 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729701AbgFJOCB (ORCPT ); Wed, 10 Jun 2020 10:02:01 -0400 Received: from marcel-macbook.fritz.box (p5b3d2638.dip0.t-ipconnect.de [91.61.38.56]) by mail.holtmann.org (Postfix) with ESMTPSA id 550F0CECE5; Wed, 10 Jun 2020 16:11:49 +0200 (CEST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: Re: [PATCH v2] sco:Add support for BT_PKT_STATUS CMSG data From: Marcel Holtmann In-Reply-To: Date: Wed, 10 Jun 2020 16:01:59 +0200 Cc: Alain Michaud , BlueZ Content-Transfer-Encoding: 8BIT Message-Id: References: <20200603145121.124842-1-alainm@chromium.org> To: Alain Michaud X-Mailer: Apple Mail (2.3608.80.23.2.2) Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Alain, > > This change adds support for reporting the BT_PKT_STATUS to the socket > > CMSG data to allow the implementation of a packet loss correction on > > erronous data received on the SCO socket. > > > > The patch was partially developed by Marcel Holtmann and validated by > > Hsin-yu Chao > > > > Signed-off-by: Alain Michaud > > > > --- > > > > include/net/bluetooth/bluetooth.h | 8 +++++++ > > include/net/bluetooth/sco.h | 3 +++ > > net/bluetooth/af_bluetooth.c | 3 +++ > > net/bluetooth/hci_core.c | 1 + > > net/bluetooth/sco.c | 35 +++++++++++++++++++++++++++++++ > > 5 files changed, 50 insertions(+) > > I already had this patch in my tree for testing, but then realized that I gave you a bad example on how to handle this. > > So we should not use the same constants for CMSG and socket options. Fundamentally the socket semantics use SO_foo for enabling an aux data transmission and they use SCM_bar for the CMSG portion. > > > > > diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h > > index 3fa7b1e3c5d9..85e6c5754448 100644 > > --- a/include/net/bluetooth/bluetooth.h > > +++ b/include/net/bluetooth/bluetooth.h > > @@ -147,6 +147,8 @@ struct bt_voice { > > #define BT_MODE_LE_FLOWCTL 0x03 > > #define BT_MODE_EXT_FLOWCTL 0x04 > > > > +#define BT_PKT_STATUS 16 > > + > > __printf(1, 2) > > void bt_info(const char *fmt, ...); > > __printf(1, 2) > > @@ -275,6 +277,7 @@ struct bt_sock { > > struct sock *parent; > > unsigned long flags; > > void (*skb_msg_name)(struct sk_buff *, void *, int *); > > + void (*skb_put_cmsg)(struct sk_buff *, struct msghdr *, struct sock *); > > }; > > > > enum { > > @@ -324,6 +327,10 @@ struct l2cap_ctrl { > > struct l2cap_chan *chan; > > }; > > > > +struct sco_ctrl { > > + u8 pkt_status; > > +}; > > + > > struct hci_dev; > > > > typedef void (*hci_req_complete_t)(struct hci_dev *hdev, u8 status, u16 opcode); > > @@ -350,6 +357,7 @@ struct bt_skb_cb { > > u8 incoming:1; > > union { > > struct l2cap_ctrl l2cap; > > + struct sco_ctrl sco; > > struct hci_ctrl hci; > > }; > > }; > > diff --git a/include/net/bluetooth/sco.h b/include/net/bluetooth/sco.h > > index f40ddb4264fc..7f0d7bdc53f6 100644 > > --- a/include/net/bluetooth/sco.h > > +++ b/include/net/bluetooth/sco.h > > @@ -46,4 +46,7 @@ struct sco_conninfo { > > __u8 dev_class[3]; > > }; > > > > +/* CMSG flags */ > > +#define SCO_CMSG_PKT_STATUS 0x0001 > > + > > #endif /* __SCO_H */ > > diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c > > index 3fd124927d4d..d0abea8d08cc 100644 > > --- a/net/bluetooth/af_bluetooth.c > > +++ b/net/bluetooth/af_bluetooth.c > > @@ -286,6 +286,9 @@ int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, > > if (msg->msg_name && bt_sk(sk)->skb_msg_name) > > bt_sk(sk)->skb_msg_name(skb, msg->msg_name, > > &msg->msg_namelen); > > + > > + if (bt_sk(sk)->skb_put_cmsg) > > + bt_sk(sk)->skb_put_cmsg(skb, msg, sk); > > } > > > > skb_free_datagram(sk, skb); > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > > index 51d399273276..7b5e46198d99 100644 > > --- a/net/bluetooth/hci_core.c > > +++ b/net/bluetooth/hci_core.c > > @@ -4549,6 +4549,7 @@ static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) > > > > if (conn) { > > /* Send to upper protocol */ > > + bt_cb(skb)->sco.pkt_status = flags & 0x03; > > sco_recv_scodata(conn, skb); > > return; > > } else { > > diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c > > index c8c3d38cdc7b..f6b54853e547 100644 > > --- a/net/bluetooth/sco.c > > +++ b/net/bluetooth/sco.c > > @@ -66,6 +66,7 @@ struct sco_pinfo { > > bdaddr_t dst; > > __u32 flags; > > __u16 setting; > > + __u32 cmsg_mask; > > struct sco_conn *conn; > > }; > > > > @@ -449,6 +450,15 @@ static void sco_sock_close(struct sock *sk) > > sco_sock_kill(sk); > > } > > > > +static void sco_skb_put_cmsg(struct sk_buff *skb, struct msghdr *msg, > > + struct sock *sk) > > +{ > > + if (sco_pi(sk)->cmsg_mask & SCO_CMSG_PKT_STATUS) > > + put_cmsg(msg, SOL_BLUETOOTH, BT_PKT_STATUS, > > This needs an extra BT_SCM_PKT_STATUS constant. > Since we don't have this name space defined yet, I'm assuming I just start with 01 for this. hmmm. Since we used to have a few HCI ones, just for the sake of never ever conflicting, I would say start after them. /* CMSG flags */ #define HCI_CMSG_DIR 0x0001 #define HCI_CMSG_TSTAMP 0x0002 So lets start with 3. I think even for the socket numbering options we started with 4 to just make sure we never ever come into some weird conflict. Some of this code is 18+ years old ;) Regards Marcel