Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Properly find the remote characteristic end handle for descriptor discovery. #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2021

Conversation

h2zero
Copy link
Owner

@h2zero h2zero commented May 8, 2021

Previously we used the service end handle or, if available, the handle of the next characteristic in the service
as the end handle when retrieving the descriptors of a characteristic. This process would fail when connecting to some
devices if the characteristics were retrieved individually instead of all together. The cause of failure was requesting
a handle range that is out of characteristic scope which is also out of line with BLE
specifications.

The fix included in this is to set the end handles of the characteristics either after retrieving all the characteristics
in a service by using the next charactertistic definition handle or, if the characteristic was retrieved separately,
we retrieve the next characteristic just before retrieving the descriptors.

@wakwak-koba I'd be grateful if you could test this against the device that exposed this issue in #170

@wakwak-koba
Copy link
Contributor

Hi, calling me is welcome !!

#include "NimBLEDevice.h"

static NimBLEUUID serviceUUID((uint16_t)0x1812);

void setup() {
  Serial.begin(115200);

  NimBLEDevice::init("");
  auto pBLEScan = NimBLEDevice::getScan();
  pBLEScan->setActiveScan(true);

  Serial.println("wait 10 secs..");
  auto pScanResults = pBLEScan->start(10);

  for (int i = 0; i < pScanResults.getCount(); i++) {
    auto advertisedDevice = pScanResults.getDevice(i);
    if (advertisedDevice.haveServiceUUID())  {
      Serial.println(advertisedDevice.toString().c_str());
      auto pClient = NimBLEDevice::createClient();
      if(pClient && pClient->connect(&advertisedDevice)) {
        auto pService = pClient->getService(serviceUUID);
        if(pService != NULL)  {
          Serial.println();
          Serial.print("**");
          Serial.println(pService->toString().c_str());
          pService->getCharacteristic((uint16_t)0x2a4d);
          auto pCharacteristics  = pService->getCharacteristics();
          for (auto pCharacteristic : *pCharacteristics) {
            Serial.print("****");
            Serial.println(pCharacteristic->toString().c_str());
            auto pDescriptors = pCharacteristic->getDescriptors(true);
            for (auto pDescriptor : *pDescriptors)
            {
              Serial.print("******");
              Serial.println(pDescriptor->toString().c_str());
            }            
          }    
        }
      }
      Serial.println();
    }
  }
  
  if(NimBLEDevice::getClientListSize() == 0)
    ESP.restart();
}

void loop() {
  delay(1);
}

I tested it with the above sources and it was a disappointing result.

12:56:47.680 -> wait 10 secs..
12:56:57.687 -> Name: VR BOX     
12:56:59.243 -> 
12:56:59.243 -> **Service: uuid: 0x1812, start_handle: 15 0x000f, end_handle: 39 0x0027
12:56:59.646 -> ****Characteristic: uuid: 0x2a4d, handle: 19 0x0013, props:  0x12
12:56:59.832 -> ******Descriptor: uuid: 0x2902, handle: 20
12:56:59.832 -> ******Descriptor: uuid: 0x2908, handle: 21
12:56:59.832 -> ****Characteristic: uuid: 0x2a4d, handle: 23 0x0017, props:  0x12
12:56:59.964 -> Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
12:56:59.964 -> Core 0 register dump:
12:56:59.964 -> PC      : 0x400dbb44  PS      : 0x00060b30  A0      : 0x800d74a9  A1      : 0x3ffc8ba0  
12:56:59.964 -> A2      : 0x3ffc1e20  A3      : 0x00000000  A4      : 0x00000001  A5      : 0x3ffc8c10  
12:56:59.964 -> A6      : 0x00000009  A7      : 0x0017001b  A8      : 0x00000000  A9      : 0x3ffc8b60  
12:56:59.964 -> A10     : 0x3ffc1e20  A11     : 0x00000000  A12     : 0x00000004  A13     : 0x3ffc8bac  
12:56:59.964 -> A14     : 0x07090004  A15     : 0x07090004  SAR     : 0x00000010  EXCCAUSE: 0x0000001c  
12:57:00.033 -> EXCVADDR: 0x00000004  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0x00000000  
12:57:00.033 -> 
12:57:00.033 -> ELF file SHA256: 0000000000000000
12:57:00.033 -> 
12:57:00.033 -> Backtrace: 0x400dbb44:0x3ffc8ba0 0x400d74a6:0x3ffc8bd0 0x400d7021:0x3ffc8c00 0x400de8a9:0x3ffc8c30 0x400dcc8d:0x3ffc8c60 0x400dcc9f:0x3ffc8c80 0x400e4346:0x3ffc8ca0 0x400d375f:0x3ffc8cc0 0x4008fe8e:0x3ffc8ce0

In the middle of the sample source code

          auto pCharacteristics  = pService->getCharacteristics();

When I changed this as below, Panic did not occur and it worked normally.

          auto pCharacteristics  = pService->getCharacteristics(true);
12:58:15.332 -> Name: VR BOX     
12:58:16.032 -> 
12:58:16.032 -> **Service: uuid: 0x1812, start_handle: 15 0x000f, end_handle: 39 0x0027
12:58:16.834 -> ****Characteristic: uuid: 0x2a4e, handle: 17 0x0011, props:  0x06
12:58:16.834 -> ****Characteristic: uuid: 0x2a4d, handle: 19 0x0013, props:  0x12
12:58:17.535 -> ******Descriptor: uuid: 0x2902, handle: 20
12:58:17.535 -> ******Descriptor: uuid: 0x2908, handle: 21
12:58:17.535 -> ****Characteristic: uuid: 0x2a4d, handle: 23 0x0017, props:  0x12
12:58:17.689 -> ******Descriptor: uuid: 0x2902, handle: 24
12:58:17.689 -> ******Descriptor: uuid: 0x2908, handle: 25
12:58:17.689 -> ****Characteristic: uuid: 0x2a4d, handle: 27 0x001b, props:  0x12
12:58:17.789 -> ******Descriptor: uuid: 0x2902, handle: 28
12:58:17.789 -> ******Descriptor: uuid: 0x2908, handle: 29
12:58:17.789 -> ****Characteristic: uuid: 0x2a4d, handle: 31 0x001f, props:  0x12
12:58:17.890 -> ******Descriptor: uuid: 0x2902, handle: 32
12:58:17.890 -> ******Descriptor: uuid: 0x2908, handle: 33
12:58:17.890 -> ****Characteristic: uuid: 0x2a4b, handle: 35 0x0023, props:  0x02
12:58:17.890 -> ****Characteristic: uuid: 0x2a4a, handle: 37 0x0025, props:  0x02
12:58:17.890 -> ****Characteristic: uuid: 0x2a4c, handle: 39 0x0027, props:  0x04

I'll change the DebugLevel and explore a little more.

@h2zero
Copy link
Owner Author

h2zero commented May 9, 2021

Awesome, thank you for testing it. I knew there had to be a bug somewhere when it worked so easily on the first test 😄. Looking forward to anything you find in the logs. Looks like a nullptr issue that needs to be tracked down.

@wakwak-koba
Copy link
Contributor

wakwak-koba commented May 9, 2021

When I changed DebugLevel to Debug and moved it with detailed logs, the Panic error disappeared.
There may be a place where you are making a severe request in terms of timing...

13:20:50.151 -> Name: VR BOX     
13:20:50.151 -> D NimBLEClient: ">> connect(ff:ff:1b:d9:9d:93)"
13:20:50.205 -> D NimBLEClient: "Got Client event "
13:20:50.205 -> I NimBLEClient: "Connected event"
13:20:50.305 -> D NimBLEClient: "Got Client event "
13:20:50.305 -> I NimBLEClient: "mtu update event; conn_handle=0 mtu=23"
13:20:50.305 -> I NimBLEClient: "Connection established"
13:20:50.352 -> D NimBLEClient: ">> deleteServices"
13:20:50.352 -> D NimBLEClient: "<< deleteServices"
13:20:50.352 -> D NimBLEClientCallbacks: "onConnect: default"
13:20:50.352 -> D NimBLEClient: "<< connect()"
13:20:50.352 -> D NimBLEClient: ">> getService: uuid: 0x1812"
13:20:50.352 -> D NimBLEClient: ">> retrieveServices"
13:20:50.405 -> D NimBLEClient: "Service Discovered >> status: 0 handle: 15"
13:20:50.405 -> D NimBLERemoteService: ">> NimBLERemoteService()"
13:20:50.405 -> D NimBLERemoteService: "<< NimBLERemoteService(): 0x1812"
13:20:50.506 -> D NimBLEClient: "Service Discovered >> status: 14 handle: -1"
13:20:50.506 -> D NimBLEClient: "<< << Service Discovered"
13:20:50.506 -> D NimBLEClient: "<< retrieveServices"
13:20:50.553 -> 
13:20:50.553 -> **Service: uuid: 0x1812, start_handle: 15 0x000f, end_handle: 39 0x0027
13:20:50.553 -> D NimBLERemoteService: ">> getCharacteristic: uuid: 0x2a4d"
13:20:50.553 -> D NimBLERemoteService: ">> retrieveCharacteristics() for service: 0x1812"
13:20:50.606 -> D NimBLERemoteService: "Characteristic Discovered >> status: 0 handle: 19"
13:20:50.606 -> D NimBLERemoteCharacteristic: ">> NimBLERemoteCharacteristic()"
13:20:50.653 -> D NimBLERemoteCharacteristic: "<< NimBLERemoteCharacteristic(): 0x2a4d"
13:20:50.653 -> D NimBLERemoteService: "Characteristic Discovered >> status: 0 handle: 23"
13:20:50.653 -> D NimBLERemoteCharacteristic: ">> NimBLERemoteCharacteristic()"
13:20:50.653 -> D NimBLERemoteCharacteristic: "<< NimBLERemoteCharacteristic(): 0x2a4d"
13:20:50.706 -> D NimBLERemoteService: "Characteristic Discovered >> status: 0 handle: 27"
13:20:50.706 -> D NimBLERemoteCharacteristic: ">> NimBLERemoteCharacteristic()"
13:20:50.753 -> D NimBLERemoteCharacteristic: "<< NimBLERemoteCharacteristic(): 0x2a4d"
13:20:50.753 -> D NimBLERemoteService: "Characteristic Discovered >> status: 0 handle: 31"
13:20:50.753 -> D NimBLERemoteCharacteristic: ">> NimBLERemoteCharacteristic()"
13:20:50.753 -> D NimBLERemoteCharacteristic: "<< NimBLERemoteCharacteristic(): 0x2a4d"
13:20:50.907 -> D NimBLERemoteService: "Characteristic Discovered >> status: 14 handle: -1"
13:20:50.907 -> D NimBLERemoteService: "<< Characteristic Discovered"
13:20:50.954 -> D NimBLERemoteService: "<< retrieveCharacteristics()"
13:20:50.954 -> ****Characteristic: uuid: 0x2a4d, handle: 19 0x0013, props:  0x12
13:20:50.954 -> D NimBLERemoteCharacteristic: ">> deleteDescriptors"
13:20:50.954 -> D NimBLERemoteCharacteristic: "<< deleteDescriptors"
13:20:50.954 -> D NimBLERemoteCharacteristic: ">> retrieveDescriptors() for characteristic: 0x2a4d"
13:20:50.954 -> D NimBLERemoteCharacteristic: ">> getEndHandle() for: 0x2a4d"
13:20:51.007 -> D NimBLERemoteCharacteristic: "Next Characteristic >> status: 0 handle: 23"
13:20:51.007 -> D NimBLERemoteCharacteristic: "<< getEndHandle()"
13:20:51.108 -> D NimBLERemoteCharacteristic: "Descriptor Discovered >> status: 0 handle: 20"
13:20:51.108 -> D NimBLERemoteDescriptor: ">> NimBLERemoteDescriptor()"
13:20:51.108 -> D NimBLERemoteDescriptor: "<< NimBLERemoteDescriptor(): 0x2902"
13:20:51.155 -> D NimBLERemoteCharacteristic: "<< Descriptor Discovered. status: 0"
13:20:51.155 -> D NimBLERemoteCharacteristic: "Descriptor Discovered >> status: 0 handle: 21"
13:20:51.155 -> D NimBLERemoteDescriptor: ">> NimBLERemoteDescriptor()"
13:20:51.155 -> D NimBLERemoteDescriptor: "<< NimBLERemoteDescriptor(): 0x2908"
13:20:51.155 -> D NimBLERemoteCharacteristic: "<< Descriptor Discovered. status: 0"
13:20:51.155 -> D NimBLERemoteCharacteristic: "Descriptor Discovered >> status: 14 handle: -1"
13:20:51.155 -> D NimBLERemoteCharacteristic: "<< Descriptor Discovered. status: 0"
13:20:51.155 -> D NimBLERemoteCharacteristic: "<< retrieveDescriptors(): Found 2 descriptors."
13:20:51.209 -> I NimBLERemoteCharacteristic: "Found 2 descriptor(s)"
13:20:51.209 -> ******Descriptor: uuid: 0x2902, handle: 20
13:20:51.209 -> ******Descriptor: uuid: 0x2908, handle: 21
13:20:51.209 -> ****Characteristic: uuid: 0x2a4d, handle: 23 0x0017, props:  0x12
13:20:51.209 -> D NimBLERemoteCharacteristic: ">> deleteDescriptors"
13:20:51.209 -> D NimBLERemoteCharacteristic: "<< deleteDescriptors"
13:20:51.209 -> D NimBLERemoteCharacteristic: ">> retrieveDescriptors() for characteristic: 0x2a4d"
13:20:51.209 -> D NimBLERemoteCharacteristic: ">> getEndHandle() for: 0x2a4d"
13:20:51.310 -> D NimBLERemoteCharacteristic: "Next Characteristic >> status: 0 handle: 27"
13:20:51.310 -> D NimBLERemoteCharacteristic: "<< getEndHandle()"
13:20:51.959 -> D NimBLEClient: "Got Client event "
13:20:51.959 -> D NimBLEClientCallbacks: "onAuthenticationComplete: default"
13:20:52.043 -> D NimBLERemoteCharacteristic: "Descriptor Discovered >> status: 0 handle: 24"
13:20:52.043 -> D NimBLERemoteDescriptor: ">> NimBLERemoteDescriptor()"
13:20:52.043 -> D NimBLERemoteDescriptor: "<< NimBLERemoteDescriptor(): 0x2902"
13:20:52.043 -> D NimBLERemoteCharacteristic: "<< Descriptor Discovered. status: 0"
13:20:52.043 -> D NimBLERemoteCharacteristic: "Descriptor Discovered >> status: 0 handle: 25"
13:20:52.043 -> D NimBLERemoteDescriptor: ">> NimBLERemoteDescriptor()"
13:20:52.043 -> D NimBLERemoteDescriptor: "<< NimBLERemoteDescriptor(): 0x2908"
13:20:52.043 -> D NimBLERemoteCharacteristic: "<< Descriptor Discovered. status: 0"
13:20:52.043 -> D NimBLERemoteCharacteristic: "Descriptor Discovered >> status: 14 handle: -1"
13:20:52.090 -> D NimBLERemoteCharacteristic: "<< Descriptor Discovered. status: 0"
13:20:52.090 -> D NimBLERemoteCharacteristic: "<< retrieveDescriptors(): Found 2 descriptors."
13:20:52.090 -> I NimBLERemoteCharacteristic: "Found 2 descriptor(s)"
13:20:52.090 -> ******Descriptor: uuid: 0x2902, handle: 24
13:20:52.090 -> ******Descriptor: uuid: 0x2908, handle: 25
13:20:52.090 -> ****Characteristic: uuid: 0x2a4d, handle: 27 0x001b, props:  0x12
13:20:52.090 -> D NimBLERemoteCharacteristic: ">> deleteDescriptors"
13:20:52.090 -> D NimBLERemoteCharacteristic: "<< deleteDescriptors"
13:20:52.090 -> D NimBLERemoteCharacteristic: ">> retrieveDescriptors() for characteristic: 0x2a4d"
13:20:52.128 -> D NimBLERemoteCharacteristic: ">> getEndHandle() for: 0x2a4d"
13:20:52.175 -> D NimBLERemoteCharacteristic: "Next Characteristic >> status: 0 handle: 31"
13:20:52.175 -> D NimBLERemoteCharacteristic: "<< getEndHandle()"
13:20:52.259 -> D NimBLERemoteCharacteristic: "Descriptor Discovered >> status: 0 handle: 28"
13:20:52.259 -> D NimBLERemoteDescriptor: ">> NimBLERemoteDescriptor()"
13:20:52.259 -> D NimBLERemoteDescriptor: "<< NimBLERemoteDescriptor(): 0x2902"
13:20:52.313 -> D NimBLERemoteCharacteristic: "<< Descriptor Discovered. status: 0"
13:20:52.313 -> D NimBLERemoteCharacteristic: "Descriptor Discovered >> status: 0 handle: 29"
13:20:52.313 -> D NimBLERemoteDescriptor: ">> NimBLERemoteDescriptor()"
13:20:52.313 -> D NimBLERemoteDescriptor: "<< NimBLERemoteDescriptor(): 0x2908"
13:20:52.313 -> D NimBLERemoteCharacteristic: "<< Descriptor Discovered. status: 0"
13:20:52.313 -> D NimBLERemoteCharacteristic: "Descriptor Discovered >> status: 14 handle: -1"
13:20:52.313 -> D NimBLERemoteCharacteristic: "<< Descriptor Discovered. status: 0"
13:20:52.313 -> D NimBLERemoteCharacteristic: "<< retrieveDescriptors(): Found 2 descriptors."
13:20:52.360 -> I NimBLERemoteCharacteristic: "Found 2 descriptor(s)"
13:20:52.360 -> ******Descriptor: uuid: 0x2902, handle: 28
13:20:52.360 -> ******Descriptor: uuid: 0x2908, handle: 29
13:20:52.360 -> ****Characteristic: uuid: 0x2a4d, handle: 31 0x001f, props:  0x12
13:20:52.360 -> D NimBLERemoteCharacteristic: ">> deleteDescriptors"
13:20:52.360 -> D NimBLERemoteCharacteristic: "<< deleteDescriptors"
13:20:52.360 -> D NimBLERemoteCharacteristic: ">> retrieveDescriptors() for characteristic: 0x2a4d"
13:20:52.360 -> D NimBLERemoteCharacteristic: ">> getEndHandle() for: 0x2a4d"
13:20:52.398 -> D NimBLERemoteCharacteristic: "Next Characteristic >> status: 0 handle: 35"
13:20:52.445 -> D NimBLERemoteCharacteristic: "<< getEndHandle()"
13:20:52.529 -> D NimBLERemoteCharacteristic: "Descriptor Discovered >> status: 0 handle: 32"
13:20:52.529 -> D NimBLERemoteDescriptor: ">> NimBLERemoteDescriptor()"
13:20:52.529 -> D NimBLERemoteDescriptor: "<< NimBLERemoteDescriptor(): 0x2902"
13:20:52.529 -> D NimBLERemoteCharacteristic: "<< Descriptor Discovered. status: 0"
13:20:52.529 -> D NimBLERemoteCharacteristic: "Descriptor Discovered >> status: 0 handle: 33"
13:20:52.529 -> D NimBLERemoteDescriptor: ">> NimBLERemoteDescriptor()"
13:20:52.576 -> D NimBLERemoteDescriptor: "<< NimBLERemoteDescriptor(): 0x2908"
13:20:52.576 -> D NimBLERemoteCharacteristic: "<< Descriptor Discovered. status: 0"
13:20:52.576 -> D NimBLERemoteCharacteristic: "Descriptor Discovered >> status: 14 handle: -1"
13:20:52.576 -> D NimBLERemoteCharacteristic: "<< Descriptor Discovered. status: 0"
13:20:52.576 -> D NimBLERemoteCharacteristic: "<< retrieveDescriptors(): Found 2 descriptors."
13:20:52.576 -> I NimBLERemoteCharacteristic: "Found 2 descriptor(s)"

@h2zero
Copy link
Owner Author

h2zero commented May 9, 2021

Of course that would happen lol. Looking at the code you posted it seems somehow that the vector was empty when your code accessed it, might be a core/task switch timing issue? Hopefully I can reproduce and put a taskYIELD() in a couple places to track it down.

@wakwak-koba
Copy link
Contributor

wakwak-koba commented May 9, 2021

I thought that the series of BLE operations was asynchronous (blocked).
Is my perception wrong?

I wrote the code on the assumption that the results of pService->getCharacteristics() and pCharacteristic->getDescriptors(true) would always succeed, but the result was the same even if I added the NULL check.

        auto pService = pClient->getService(serviceUUID);
        if(pService != NULL)  {
          Serial.println();
          Serial.print("**");
          Serial.println(pService->toString().c_str());
          pService->getCharacteristic((uint16_t)0x2a4d);
          auto pCharacteristics  = pService->getCharacteristics();
          if(pCharacteristics != NULL)
            for (auto pCharacteristic : *pCharacteristics) {
              Serial.print("****");
              Serial.println(pCharacteristic->toString().c_str());
              auto pDescriptors = pCharacteristic->getDescriptors(true);
              if(pDescriptors != NULL)
                for (auto pDescriptor : *pDescriptors)
                {
                  Serial.print("******");
                  Serial.println(pDescriptor->toString().c_str());
                }            
            }    
        }

When I use the master branch, it works fine without being nervous about timing.
Is this fix requiring excessive treatment?

@wakwak-koba
Copy link
Contributor

I'm not sure if this is the correct way to sprinkle taskYIELD(); but it still causes a panic.

        auto pService = pClient->getService(serviceUUID);
        if(pService != NULL)  {
          Serial.println();
          Serial.print("**");
          Serial.println(pService->toString().c_str());
          pService->getCharacteristic((uint16_t)0x2a4d);
          taskYIELD();
          auto pCharacteristics  = pService->getCharacteristics();
          taskYIELD();
          if(pCharacteristics != NULL)
            for (auto pCharacteristic : *pCharacteristics) {
              taskYIELD();
              Serial.print("****");
              Serial.println(pCharacteristic->toString().c_str());
              auto pDescriptors = pCharacteristic->getDescriptors(true);
              taskYIELD();
              if(pDescriptors != NULL)
                for (auto pDescriptor : *pDescriptors)
                {
                  taskYIELD();
                  Serial.print("******");
                  Serial.println(pDescriptor->toString().c_str());
                }            
            }    
        }

}

int rc = 0;
ble_task_data_t taskData = {this, xTaskGetCurrentTaskHandle(), 0, nullptr};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that there are unfinished tasks in xTaskGetCurrentTaskHandle().

Just before this line

    taskYIELD();

After adding, the Panic error no longer occurs.

However, I'm not sure if this fix is ​​correct, and it's possible that the problem lurks on the side of getNextCharHandle(), which is running just before.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I will try to track this down today, that gives me somewhere to start.

@h2zero
Copy link
Owner Author

h2zero commented May 9, 2021

Found the error, it's in the NimBLE core and has already been fixed upstream. I'll do some more testing and push the fix to this PR when satisfied.

@h2zero
Copy link
Owner Author

h2zero commented May 9, 2021

This will not be merged until the NimBLE core files are updated.

To make this PR work for testing you will need to change:


to:
return (criteria->matching_rx_entry != NULL);

@wakwak-koba
Copy link
Contributor

It worked perfectly fine.
I'm amazed that you were able to fix the bug with too little information I provided !!

@h2zero
Copy link
Owner Author

h2zero commented May 10, 2021

You provided plenty of information to reproduce the error, thanks again!

It was a simple matter from there to decode the backtrace which lead into the core files and I simply looked for any related commits upstream.

@wakwak-koba
Copy link
Contributor

By the way, apart from this case, I think it is a topic that should be set up as a new issue, but it does not work properly if you use the latest master branch of arduino-esp32.
My tests have been using the release-v1.0 branch all the time.

@h2zero
Copy link
Owner Author

h2zero commented May 11, 2021

Thanks for the heads up. I haven't tested with the latest master yet, I wonder what changed that would break this.

I'll look into it.

@h2zero
Copy link
Owner Author

h2zero commented May 14, 2021

@wakwak-koba I just updated master to the latest NimBLE core. If you could please test this PR with the arduino master and this master branch I would really appreciate it.

…covery.

Previously we used the service end handle or, if available, the handle of the next characteristic in the service
as the end handle when retrieving the descriptors of a characteristic. This process would fail when connecting to some
devices if the characteristics were retrieved individually instead of all together. The cause of failure was requesting
a handle range that is out of characteristic scope which is also out of line with BLE
specifications.

The fix included in this is to set the end handles of the characteristics either after retrieving all the characteristics
in a service by using the next charactertistic definition handle or, if the characteristic was retrieved separately,
we retrieve the next characteristic just before retrieving the descriptors.
@h2zero h2zero force-pushed the characteristics-end-handle-fix branch from 1a9f16a to c467231 Compare May 17, 2021 20:27
@h2zero h2zero merged commit 5b57ad6 into master May 17, 2021
@h2zero h2zero deleted the characteristics-end-handle-fix branch May 17, 2021 20:33
@wakwak-koba
Copy link
Contributor

I tested it on my device, but I haven't found any problems in combination with the master branch of arduino-esp32 !

@h2zero
Copy link
Owner Author

h2zero commented May 18, 2021

Great, thanks for testing it 😄 . I did quite a bit of testing as well and found no issues. If you find something isn't working please post an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants