2016-05-11 12:51:02

by Arthur Lambert

[permalink] [raw]
Subject: gatt server and reset of hci device

Hi,

I am working with bluez 5.39. I have a custom gatt server which used c api from
btgatt-server from bluez source. Eveything is working great exept when I reset
hci device. I need to disable bluetooth for few hours for specific use case.

If I run hci down/up and try again to connect to gatt server, the client is able
to connect but services are not available. Moreover my server does not see the
client connexion.

Do I need to make a specific stuff to be able to make it work this use case ?

Output from btgatt-client :

[arthur ] ./btgatt-client -d 00:AE:FA:BC:77:69
Connecting to device... Done
[GATT client]# services
GATT client not initialized

Output from server :

[arthur ] ./mygatt_server
Started listening on ATT channel. Waiting for connections

Thanks,
Arthur.


2016-05-12 09:56:25

by Arthur Lambert

[permalink] [raw]
Subject: Re: gatt server and reset of hci device

Le Thursday 12 May 2016 ? 11:39:44 (+0300), Luiz Augusto von Dentz a ?crit :

> Is that something preventing you to use bluetoothd and just create a
> plugin or use the GATT API for your server? Manually using hciconfig
> is not recommended since it may interfere with other users, for manual
> testing it is actually recommended to use btmgmt or bluetoothd +
> bluetoothctl.

I need to have the ble server in my stand alone binary. That's why I am not using
bluetoothd plugin. About GATT API, you are probably talking about dbus api to
create custom service instead of using private c API. I am not very familiar
with dbus, I was not able to find a working example of dbus example with bluez5.
I have some delay issue to release my code, that's why I am using c api to gain
some precious time.

> Also note that having btgatt-server along side with
> bluetoothctl. Also note that having btgatt-server along side with
> bluetoothd will not work because both listen on the same channel and
> the kernel can only redirect the packets to one process.

I know that bluetoothd cannot run with my custom gatt server. Problem is that
I am not able to set hci friendly name with hciconfig without bluetoothd. So
I have a very dirty way to do it : run bluetoothd few seconds, kill it and then
run my code. Thanks to that I am able to update the hci friendly name (I guess
that some init which are missing in my code are running in bluetoothd)

So your advise is to use btmgmt instead of hciconfig to play with hci device ?

Thanks,
Arthur.

2016-05-12 08:39:44

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: gatt server and reset of hci device

Hi Arthur,

On Wed, May 11, 2016 at 3:51 PM, Arthur LAMBERT
<[email protected]> wrote:
> Hi,
>
> I am working with bluez 5.39. I have a custom gatt server which used c api from
> btgatt-server from bluez source. Eveything is working great exept when I reset
> hci device. I need to disable bluetooth for few hours for specific use case.
>
> If I run hci down/up and try again to connect to gatt server, the client is able
> to connect but services are not available. Moreover my server does not see the
> client connexion.
>
> Do I need to make a specific stuff to be able to make it work this use case ?

Is that something preventing you to use bluetoothd and just create a
plugin or use the GATT API for your server? Manually using hciconfig
is not recommended since it may interfere with other users, for manual
testing it is actually recommended to use btmgmt or bluetoothd +
bluetoothctl. Also note that having btgatt-server along side with
bluetoothd will not work because both listen on the same channel and
the kernel can only redirect the packets to one process.

2016-06-29 13:39:51

by Tobias Svehagen

[permalink] [raw]
Subject: Re: gatt server and reset of hci device

> [arthur * dev] uname -a
> Linux arthur-bzh 3.13.0-88-generic #135-Ubuntu SMP Wed Jun 8 21:10:42 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
That kernel doesn't support the MGMT_OP_READ_ADV_FEATURES. You should
try updating your kernel. Ubuntu 14.04.4 uses kernel 4.2.

2016-06-29 13:31:59

by Arthur Lambert

[permalink] [raw]
Subject: Re: gatt server and reset of hci device

> Okay, the 'Unknown Command' lines don't look so good, what kernel are
> you running?

[arthur * dev] uname -a
Linux arthur-bzh 3.13.0-88-generic #135-Ubuntu SMP Wed Jun 8 21:10:42 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

2016-06-29 13:22:52

by Tobias Svehagen

[permalink] [raw]
Subject: Re: gatt server and reset of hci device

> [arthur ] sudo ./bluetoothd -nE -d src/gatt-database.
> bluetoothd[11131]: Bluetooth daemon 5.39
> bluetoothd[11131]: Starting SDP server
> bluetoothd[11131]: Bluetooth management interface 1.4 initialized
> bluetoothd[11131]: Failed to obtain handles for "Service Changed" characteristic
> bluetoothd[11131]: Failed to read advertising features: Unknown Command (0x01)
> bluetoothd[11131]: hci0 Load Connection Parameters failed: Unknown Command (0x01)
>
> This test is running on ubuntu 14.04. We stop bluetooth service before starting bluetoothd.
> We also run the test on arm target but without trouble this time.

Okay, the 'Unknown Command' lines don't look so good, what kernel are
you running?

2016-06-29 12:33:10

by Arthur Lambert

[permalink] [raw]
Subject: Re: gatt server and reset of hci device

> What version of bluez are you using?

5.37 & 5.39 & 5.40. Same result for all these versions.

> Yes you can also look at tools/gatt-service.c for a C example of using
> the GATT dbus API.

Ok thanks. I will check that.

> Can you run 'bluetoothd -nE -d src/gatt-database.c'. Do you see
> something like 'GATT Manager registered for adapter: /org/bluez/hci0'?

[arthur ] sudo ./bluetoothd -nE -d src/gatt-database.
[sudo] password for arthur:
bluetoothd[9754]: Bluetooth daemon 5.39
bluetoothd[9754]: Unknown key PageTimeout in main.conf
bluetoothd[9754]: Unknown key InitiallyPowered in main.conf
bluetoothd[9754]: Unknown key RememberPowered in main.conf
bluetoothd[9754]: Unknown key EnableGatt in main.conf
bluetoothd[9754]: Starting SDP server
bluetoothd[9754]: Bluetooth management interface 1.4 initialized
bluetoothd[9754]: Failed to obtain handles for "Service Changed" characteristic
bluetoothd[9754]: Failed to read advertising features: Unknown Command (0x01)
bluetoothd[9754]: hci0 Load Connection Parameters failed: Unknown Command (0x01)

I replace the main.conf from source in /etc and retry the test :

[arthur ] sudo ./bluetoothd -nE -d src/gatt-database.
bluetoothd[11131]: Bluetooth daemon 5.39
bluetoothd[11131]: Starting SDP server
bluetoothd[11131]: Bluetooth management interface 1.4 initialized
bluetoothd[11131]: Failed to obtain handles for "Service Changed" characteristic
bluetoothd[11131]: Failed to read advertising features: Unknown Command (0x01)
bluetoothd[11131]: hci0 Load Connection Parameters failed: Unknown Command (0x01)

This test is running on ubuntu 14.04. We stop bluetooth service before starting bluetoothd.
We also run the test on arm target but without trouble this time.

Arthur.

2016-06-29 07:20:20

by Tobias Svehagen

[permalink] [raw]
Subject: Re: gatt server and reset of hci device

Hi,

What version of bluez are you using?

> Is there any example in c using glibdbus ?

Yes you can also look at tools/gatt-service.c for a C example of using
the GATT dbus API.

> * Run bluetoothd with experimental mode enable :
> sudo ./bluetoothd -E

Can you run 'bluetoothd -nE -d src/gatt-database.c'. Do you see
something like 'GATT Manager registered for adapter: /org/bluez/hci0'?

/Tobias

2016-06-27 15:54:13

by Arthur Lambert

[permalink] [raw]
Subject: Re: gatt server and reset of hci device

> Is that something preventing you to use bluetoothd and just create a
> plugin or use the GATT API for your server? Manually using hciconfig
> is not recommended since it may interfere with other users, for manual
> testing it is actually recommended to use btmgmt or bluetoothd +
> bluetoothctl. Also note that having btgatt-server along side with
> bluetoothd will not work because both listen on the same channel and
> the kernel can only redirect the packets to one process.

If I want to properly implement custom gatt service with dbus instead of low c api.
Can we use the python script test/example-gatt-server as reference ?
Is there any example in c using glibdbus ?

Is it normal that I am not able to run it with success ?


* Run bluetoothd with experimental mode enable :
sudo ./bluetoothd -E

* Run python script from test directory :
[arthur ] python3 ./example-gatt-server
Failed to register application: org.bluez.Error.Failed: No object received

Thanks,
Arthur.

2016-07-07 14:55:13

by Arthur Lambert

[permalink] [raw]
Subject: Re: gatt server and reset of hci device

Sorry for the delay of my answer.

> You should update your kernel. Ubuntu 14.04.4 uses kernel 4.2.

Ok I tried to update my kernel with linux-image-4.2.0-41-generic + headers with
apt-get. After rebooting my device all my peripherals are not working (wifi/bt/usb).
Due to that I will work directly on my ARM target. I will try to fix the problem
on x86 later.

Thanks for your help.

Arthur.