2018-12-06 02:55:07

by Yunhan Wang

[permalink] [raw]
Subject: BLE advertisement re-enabling after ble connection goes away

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.


2018-12-13 21:38:32

by Yunhan Wang

[permalink] [raw]
Subject: Re: BLE advertisement re-enabling after ble connection goes away

+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 <[email protected]> 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.

2018-12-13 23:10:39

by Yunhan Wang

[permalink] [raw]
Subject: Re: BLE advertisement re-enabling after ble connection goes away

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 <[email protected]> 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));
>
> 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?
>
> Thanks,
> Martin
>
> _____________________________
> Martin Turon | Google
>
>
>
> On Thu, Dec 13, 2018 at 1:49 PM Luiz Augusto von Dentz <[email protected]> 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 <[email protected] 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 <[email protected]> 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.

2018-12-13 23:13:40

by Yunhan Wang

[permalink] [raw]
Subject: Re: BLE advertisement re-enabling after ble connection goes away

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 <[email protected]> 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 <[email protected]> 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));
> >
> > 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?
> >
> > Thanks,
> > Martin
> >
> > _____________________________
> > Martin Turon | Google
> >
> >
> >
> > On Thu, Dec 13, 2018 at 1:49 PM Luiz Augusto von Dentz <[email protected]> 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 <[email protected] 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 <[email protected]> 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.

2018-12-14 01:21:42

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: BLE advertisement re-enabling after ble connection goes away

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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected] 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 <[email protected]> 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

2018-12-14 02:06:35

by Yunhan Wang

[permalink] [raw]
Subject: Re: BLE advertisement re-enabling after ble connection goes away

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?

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.

Thanks
Best wishes
Yunhan



On Thu, Dec 13, 2018 at 5:21 PM Luiz Augusto von Dentz
<[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected] 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 <[email protected]> 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

2018-12-14 02:32:42

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: BLE advertisement re-enabling after ble connection goes away

Hi Yunhan,

On Fri, Dec 14, 2018 at 4:06 AM Yunhan Wang <[email protected]> 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

> 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?

> Thanks
> Best wishes
> Yunhan
>
>
>
> On Thu, Dec 13, 2018 at 5:21 PM Luiz Augusto von Dentz
> <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected] 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 <[email protected]> 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

2018-12-14 03:09:08

by Yunhan Wang

[permalink] [raw]
Subject: Re: BLE advertisement re-enabling after ble connection goes away

Hi, Luiz

Thanks for the clarification.

On Thu, Dec 13, 2018 at 6:32 PM Luiz Augusto von Dentz
<[email protected]> wrote:
>
> Hi Yunhan,
>
> On Fri, Dec 14, 2018 at 4:06 AM Yunhan Wang <[email protected]> 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
> > <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected] 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 <[email protected]> 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