linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yunhan Wang <yunhanw@nestlabs.com>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: Martin Turon <mturon@google.com>,
	Marcel Holtmann <marcel@holtmann.org>,
	linux-bluetooth@vger.kernel.org
Subject: Re: BLE advertisement re-enabling after ble connection goes away
Date: Thu, 13 Dec 2018 19:08:54 -0800	[thread overview]
Message-ID: <CALvjcs8gu1d4Z7Bic37wZeDjHevLmL_dZH=AHvv5iuRG9khj+A@mail.gmail.com> (raw)
In-Reply-To: <CABBYNZLvBAyOc_6NPCghDAqGV+uW-=2Y8uEcWnjAOQb1UmD36w@mail.gmail.com>

Hi, Luiz

Thanks for the clarification.

On Thu, Dec 13, 2018 at 6:32 PM Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> Hi Yunhan,
>
> On Fri, Dec 14, 2018 at 4:06 AM Yunhan Wang <yunhanw@nestlabs.com> wrote:
> >
> > Hi, Luiz
> >
> > Thanks for your reply. A little bit confused here.
> >
> > There is no code in bluez that directly re-enable advertisement, if
> > there is, could you show the code location in bluez?
>
> Isn't that what the following code does:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git/tree/net/bluetooth/hci_request.c#n1386
>

I think this link is bluetooth code in kernel, and it is not bluez
code. Now I understand you think this bluetooth code is part of
bluez..

> > Bluetooth in kernel is responsible for re-enabling advertisement? The
> > responsibility for re-enabling the advertising is kernel instead of
> > bluez and user application code.
>
> Yes it is the kernel which re-enables it and it has been doing this
> for a long while so I wonder why all of the a sudden we are discussing
> about it. Is there a bug related to it?
>
I am seeing chrome os bluetooth kernel doesn't re-enable
advertisement, so I wanna figure out if bluetooth in kernel or bluez
user space or user application needs take this responsibility to
re-enable the advertisement. Clearly you mention bluetooth kernel
needs to re-enable the advertisement, I would further figure out the
root cause in chrome os kernel...

Thanks
Best wishes
Yunhan
> > Thanks
> > Best wishes
> > Yunhan
> >
> >
> >
> > On Thu, Dec 13, 2018 at 5:21 PM Luiz Augusto von Dentz
> > <luiz.dentz@gmail.com> wrote:
> > >
> > > Hi Yunhan,
> > >
> > > You already answered your question, it is reenabled by
> > > hci_req_reenable_advertising
> > >
> > >
> > > On Fri, Dec 14, 2018 at 1:13 AM Yunhan Wang <yunhanw@nestlabs.com> wrote:
> > > >
> > > > Hi, Luiz
> > > >
> > > > Rephrasing a little bit..
> > > >
> > > > From what you describes, it seems Bluez is taking the responsibility
> > > > to reenable the advertisement in peripheral side after the previous
> > > > ble connection goes
> > > > away.
> > > >
> > > > When I did local test, the ble peripheral is using bluez, I create
> > > > gatt server and ble advertisment using Bluez DBus API,  when remote
> > > > connection in central disconnects, I see kernel in Bluez in peripheral
> > > > side do receive
> > > > HCI_EV_DISCONN_COMPLETE event, and trigger
> > > > hci_req_reenable_advertising.
> > > >
> > > > Maybe you can share the code location where Bluez is reenabling the
> > > > advertisement after ble connection goes away?
> > > >
> > > > Thanks
> > > > Best wishes
> > > > On Thu, Dec 13, 2018 at 3:10 PM Yunhan Wang <yunhanw@nestlabs.com> wrote:
> > > > >
> > > > > Hi, Luiz
> > > > >
> > > > > From what you describes, it seems Bluez is taking the responsibility
> > > > > to reenable the advertisement after the previous ble connection goes
> > > > > away.
> > > > >
> > > > > When I did local test, the ble peripheral is using bluez, I create
> > > > > gatt server and ble advertisment using Bluez DBus API,  when remote
> > > > > connection in central disconnects, I see kernel in Bluez do receive
> > > > > HCI_EV_DISCONN_COMPLETE event, and trigger
> > > > > hci_req_reenable_advertising.
> > > > >
> > > > > Maybe you can share the code location where Bluez is reenabling the
> > > > > advertisement after ble connection goes away?
> > > > >
> > > > > Thanks
> > > > > Best wishes
> > > > > Yunhan
> > > > >
> > > > > On Thu, Dec 13, 2018 at 2:30 PM Martin Turon <mturon@google.com> wrote:
> > > > > >
> > > > > > Hi Luiz,
> > > > > >
> > > > > > Is this behavior also expected on raw hci sockets?  Because my observation is that when working with raw hci over such sockets, auto-reenable does not occur.
> > > > > >
> > > > > >     #define BTPROTO_HCI                 1
> > > > > >     #define HCI_CHANNEL_USER         1
> > > > > >
> > > > > >     struct sockaddr_hci shci;
> > > > > >     shci.hci_family = AF_BLUETOOTH;
> > > > > >     shci.hci_dev = s_ble_hci_device;
> > > > > >     shci.hci_channel = HCI_CHANNEL_USER;
> > > > > >
> > > > > >     s = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
> > > > > >     rc = bind(s, (struct sockaddr *)&shci, sizeof(shci));
> > >
> > > Raw socket commands might actually work but here you are using it with
> > > a user channel which afaik disables the stack processing.
> > >
> > > > > > Also, which API allows the user to control the advertising instances you describe?  Are they automatically created by the kernel when HCI is sent to a raw socket to enable advertising?
> > >
> > > Nope you need to use the management interface to use the advertising
> > > instances, or better yet use the D-Bus API:
> > >
> > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/advertising-api.txt
> > >
> > > > > > Thanks,
> > > > > > Martin
> > > > > >
> > > > > > _____________________________
> > > > > > Martin Turon  |  Google
> > > > > >
> > > > > >
> > > > > >
> > > > > > On Thu, Dec 13, 2018 at 1:49 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote:
> > > > > >>
> > > > > >> Hi Yunhan,
> > > > > >>
> > > > > >> The BlueZ API operates a bit different than HCI, it keeps re-enabling the advertisement if there is any instance active, but the user can stop this by removing its instance once a connection is made, this is considered more convenient than having the user to reprogram the advertisement on every disconnection.
> > > > > >>
> > > > > >> On Thu, 13 Dec 2018, 18:38 Yunhan Wang <yunhanw@nestlabs.com wrote:
> > > > > >>>
> > > > > >>> +Martin
> > > > > >>>
> > > > > >>> Hi, Luiz and Marcel
> > > > > >>>
> > > > > >>> When I take a look at the bluetooth code, it seems it is re-enabling
> > > > > >>> ble advertisement after ble connection goes away. Any idea?
> > > > > >>>
> > > > > >>> https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git/tree/net/bluetooth/hci_event.c#n2634
> > > > > >>> https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git/tree/net/bluetooth/hci_event.c#n2712
> > > > > >>> https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git/tree/net/bluetooth/hci_request.c#n1386
> > > > > >>> https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git/tree/net/bluetooth/hci_request.c#n1734
> > > > > >>>
> > > > > >>> Thanks
> > > > > >>> Best wishes
> > > > > >>> Yunhan
> > > > > >>> On Wed, Dec 5, 2018 at 6:54 PM Yunhan Wang <yunhanw@nestlabs.com> wrote:
> > > > > >>> >
> > > > > >>> > Hi, Luiz and Marcel
> > > > > >>> >
> > > > > >>> > May I have a question on ble behavior on BLE re-advertisement?
> > > > > >>> >
> > > > > >>> > According to Bluetooth spec Vol. 3 (the host volume), 9.2.4.2, "The
> > > > > >>> > device shall remain in general discoverable mode until a connection is
> > > > > >>> > established or the Host terminates the mode."
> > > > > >>> >
> > > > > >>> > There is no description on re-enabling the advertising "after"
> > > > > >>> > disconnection, so the responsibility for re-enabling the advertising
> > > > > >>> > is bluez or kernel or application code? In other words, does kernel or
> > > > > >>> > bluez or application would re-enable the ble advertisement after ble
> > > > > >>> > disconnection happens?
> > > > > >>> >
> > > > > >>> > Thanks
> > > > > >>> > Best wishes
> > > > > >>> > Yunhan.
> > >
> > >
> > >
> > > --
> > > Luiz Augusto von Dentz
>
>
>
> --
> Luiz Augusto von Dentz

      reply	other threads:[~2018-12-14  3:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-06  2:54 BLE advertisement re-enabling after ble connection goes away Yunhan Wang
2018-12-13 21:38 ` Yunhan Wang
     [not found]   ` <CABBYNZLPeHRWcG78USDYHL6zzw392JuefRaD9S_+RuXhDQ9ZCw@mail.gmail.com>
     [not found]     ` <CAOOu1=BiJ9VjiMXiiPuXb=4cu-62OYmT+h1Z83ip440KwSpeAw@mail.gmail.com>
2018-12-13 23:10       ` Yunhan Wang
2018-12-13 23:13         ` Yunhan Wang
2018-12-14  1:21           ` Luiz Augusto von Dentz
2018-12-14  2:06             ` Yunhan Wang
2018-12-14  2:32               ` Luiz Augusto von Dentz
2018-12-14  3:08                 ` Yunhan Wang [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='CALvjcs8gu1d4Z7Bic37wZeDjHevLmL_dZH=AHvv5iuRG9khj+A@mail.gmail.com' \
    --to=yunhanw@nestlabs.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=mturon@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).