[Interest] BLE : Bonding and ble security

Jérôme Godbout godboutj at amotus.ca
Mon Aug 17 16:49:32 CEST 2020


Can you discover the service and the characteristics? are there any errors while doing so? Make sure to discover those before writing to them, might help to see if anything went wrong.

From: Simon FEUTRIER <sfeutrier at bluegriot.com>
Sent: August 17, 2020 10:32 AM
To: Jérôme Godbout <godboutj at amotus.ca>
Cc: interest at qt-project.org
Subject: Re: [Interest] BLE : Bonding and ble security

Alex, thank you for your quick reply. I just tried with the pre-release 5.15.1 and this is the same behavior.
When trying to activate notification (first write to characteristic that I do), it always fails to write. Qt still never initiates the bonding.
Could you clearly tell me if it is supposed to work or if this has not been implemented yet ?

Jérôme, thank you for your message, sorry I forgot to specify I am working with Windows 10 with MSVC. I'm sure your message will be helpful but I don't think it applies to my case.

Best regards,

Simon Feutrier


Le lun. 17 août 2020 à 15:52, Jérôme Godbout <godboutj at amotus.ca<mailto:godboutj at amotus.ca>> a écrit :
Here is my error code I’m currently using:

switch (error)
    {
        case QLowEnergyController::Error::AdvertisingError:
        case QLowEnergyController::Error::UnknownRemoteDeviceError:
        case QLowEnergyController::Error::UnknownError:
        case QLowEnergyController::Error::InvalidBluetoothAdapterError:
        case QLowEnergyController::Error::NetworkError:
        case QLowEnergyController::Error::ConnectionError:
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
        case QLowEnergyController::Error::RemoteHostClosedError:
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
        case QLowEnergyController::Error::AuthorizationError:
#endif
        break;
        // Code 0x22 (0d34) seem to be link to unsupported Read Characteristic on device the read timeout, missing read/write connect on service?
        // Android problem: BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT
        case 0x22:
            qDebug() << "Android Device have problem BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT or GATT CONN LMP TIMEOUT: " << error;
            // TODO godboutj 2018-06-11, find a fix or a workaround this issue
            break;
        // Special erro 129 QLowEnergyController Error is Generic Android internal error. Often just disconnecting and reconnecting help the issue
        case 0x81: // (0d129)
            qDebug() << "Android generic error, disconnect and try to reconnect again";
            break;
        // Special erro 133 GATT_ERROR, seen on Samsung Android 8 tablet, reason can be almost anything
        case 0x85: // (0d133)
            qDebug() << "Android device error, not sure about why we get this on some device";
            break;
        // More code explaination can be found here: http://allmydroids.blogspot.com/2015/06/android-ble-error-status-codes-explained.html
        default:
            qDebug() << "UnhandledError: " << error;
            break;
    }

If that might help others developing with Android. This will generate some warning for bad enum value, but they are showing up on Android… If someone have information about those error, I will gladly be accepting any information about why they can occur.


From: Interest <interest-bounces at qt-project.org<mailto:interest-bounces at qt-project.org>> On Behalf Of Jérôme Godbout
Sent: August 17, 2020 9:25 AM
To: Simon FEUTRIER <sfeutrier at bluegriot.com<mailto:sfeutrier at bluegriot.com>>; interest at qt-project.org<mailto:interest at qt-project.org>
Subject: Re: [Interest] BLE : Bonding and ble security

Hi,
If you are using Qt and Android for the application. I did found over time to have a reliable behavior with Android connection step, you kind of need to slow things down on Android platform (this doesn’t apply to Windows, Mac, iOS). I delayed my task by 500 ms after connecting and doing anything (services discovery, pairing, authenticate… under Android. Also do this when I disconnect (garbage collector issue?!) and avoid reconnecting too quickly. This have solve many problems I had under Android. Android Bluetooth LE stack is really bad before Android 8. If you can, try to make things work with a recent device and Android 8+, then patch the behavior for older device if you can.

I also found that a few manufacturer have more issue (but this might just be a specific product, I don’t have enough data to make sure this is happening all the time):

  *   Google Nexus 7", Android 6.0.1  can raise undocumented Error 34 (0x22) GATT CONN LMP TIMEOUT
  *   LG K4 LTE, Android 5.1.1  Debugger doesn’t run too well
  *   Lenovo (cheap tablet, I don’t remember the actual model #) the advertising is a big mess (some low level filtering, making beacon continuous discovery impossible).
  *   Samsung many older version had some debugger issue (missing or renamed tools)

If you Android BLE start behaving heraldically, turn off the BLE and wait at least 20s before activating again. Seem like the garbage collector/clean up task is fairly slow.

Hope this might help you.
Jerome


[cid:image001.jpg at 01D67484.16C4F540]
une compagnie  [cid:image002.jpg at 01D67484.16C4F540]
RAPPROCHEZ LA DISTANCE
Jérôme Godbout
Développeur Logiciel Sénior /
Senior Software Developer
p: +1 (418) 800-1073 ext.:109
amotus.ca<http://www.amotus-solutions.com/>
statum-iot.com<http://statum-iot.com/>
[cid:image003.png at 01D67484.16C4F540]<https://www.facebook.com/LesSolutionsAmotus/> [cid:image004.png at 01D67484.16C4F540] <https://www.linkedin.com/company/amotus-solutions/>  [cid:image005.png at 01D67484.16C4F540] <https://twitter.com/AmotusSolutions>  [cid:image006.jpg at 01D67484.16C4F540] <https://www.youtube.com/channel/UCoYpQgsmj1iJZyDjTQ3x8Ig>
COVID-19 : we are glad to inform you that Amotus<https://www.amotus-solutions.com/> are up and running with limited impact on our performance. We will keep you informed of any changes as they occur.
COVID-19 : nous sommes fiers d’informer nos collaborateurs que Amotus opèrent adéquatement et que l’impact sur notre productivité est minimisé. Nous vous tiendrons au courant de tout changement.

From: Interest <interest-bounces at qt-project.org<mailto:interest-bounces at qt-project.org>> On Behalf Of Simon FEUTRIER
Sent: August 17, 2020 3:48 AM
To: interest at qt-project.org<mailto:interest at qt-project.org>
Subject: [Interest] BLE : Bonding and ble security

Hi,

That is the first time I use this mailing list, so tell me if I'm doing anything wrong when using it. Thanks !

Now my problem.

I'm developing a Qt application that communicates with a BLE device. It worked perfectly until I tried to add some security. When I turned on "Just Works" security mode (device side), I was not able anymore to write in a characteristic (or read) from my Qt application.

I compared the Bluetooth messages sent from Qt app and from the android app nfr Connect and I see that automatically, the nrf Connect app sends a bonding request when it fails to write.
Qt does not do this. That is the only difference that makes the android app working but not my Qt app.

I finally made it work once : I start my Qt App, pair my BLE device with Windows parameters and then it works one time only (after that I need to unpair my device from Windows parameters and redo the same process). It only works if it has been paired with Windows parameters...

I could not find anything about bonding in the API or security mode settings.
Any idea ? Should I post it as a bug or am I missing something ?

Thanks,

Regards,

Simon Feutrier
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200817/cf326f73/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 98353 bytes
Desc: image001.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200817/cf326f73/attachment-0003.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.jpg
Type: image/jpeg
Size: 1427 bytes
Desc: image002.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200817/cf326f73/attachment-0004.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 730 bytes
Desc: image003.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200817/cf326f73/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 929 bytes
Desc: image004.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200817/cf326f73/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.png
Type: image/png
Size: 839 bytes
Desc: image005.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200817/cf326f73/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image006.jpg
Type: image/jpeg
Size: 1167 bytes
Desc: image006.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200817/cf326f73/attachment-0005.jpg>


More information about the Interest mailing list