Skip to content
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

system crashes and restart when doing discoverAttributes #375

Open
baykey opened this issue Nov 6, 2024 · 0 comments
Open

system crashes and restart when doing discoverAttributes #375

baykey opened this issue Nov 6, 2024 · 0 comments

Comments

@baykey
Copy link

baykey commented Nov 6, 2024

hardware used:
BLE client: ESP-WROOM-32
BLE server: quarq power meter

When calling discoverAttributs the function discoverDescriptors in ATT.cpp turns into an infinite loop.
I added a breaker to prevent this. Maybe someone with more skills can solve this more nicely..


>bool  ATTClass::discoverDescriptors(uint16_t connectionHandle, BLERemoteDevice* device)
> {
>   //Serial.println("discoverDescriptors");
>   uint16_t reqStartHandle = 0x0001;
>   uint16_t reqEndHandle = 0xffff;
>   uint8_t responseBuffer[_maxMtu];
> 
>   int serviceCount = device->serviceCount();  
> 
>   for (int i = 0; i < serviceCount; i++) {
>     BLERemoteService* service = device->service(i);
> 
>     uint16_t serviceEndHandle = service->endHandle();
>     int characteristicCount = service->characteristicCount();
>     for (int j = 0; j < characteristicCount; j++) {
>       BLERemoteCharacteristic* characteristic = service->characteristic(j);
>       BLERemoteCharacteristic* nextCharacteristic = (j == (characteristicCount - 1)) ? NULL : service->characteristic(j + 1);
> 
>       reqStartHandle = characteristic->valueHandle() + 1;
>       reqEndHandle = nextCharacteristic ? nextCharacteristic->valueHandle() : serviceEndHandle;
> 
>       if (reqStartHandle > reqEndHandle) {
>         continue;
>       }
> int brkr=0;
>       while (1) {
> brkr+=1;
> 
>         int respLength = findInfoReq(connectionHandle, reqStartHandle, reqEndHandle, responseBuffer);
> 
> if (brkr==50) {
>  // Serial.println("breaker");
> //Serial.println(respLength );
> //Serial.println(responseBuffer[0] );
> break;
> }
>         if (respLength == 0) {
>           return false;
>         }
> 
>         if (responseBuffer[0] == ATT_OP_FIND_INFO_RESP) {
>           uint16_t lengthPerDescriptor = responseBuffer[1] * 4;
>           uint8_t uuidLen = 2;
> 
>           for (int i = 2; i < respLength; i += lengthPerDescriptor) {
>             struct __attribute__ ((packed)) RawDescriptor {
>               uint16_t handle;
>               uint8_t uuid[16];
>             } *rawDescriptor = (RawDescriptor*)&responseBuffer[i];
> 
>             BLERemoteDescriptor* descriptor = new BLERemoteDescriptor(rawDescriptor->uuid, uuidLen,
>                                                                       connectionHandle,
>                                                                       rawDescriptor->handle);
> 
>             if (descriptor == NULL) {
>               return false;
>             }
> 
>             characteristic->addDescriptor(descriptor);
>             Serial.print("descriptor toegevoegd");            
>             reqStartHandle = rawDescriptor->handle + 1;
>           }
>         } else {
>           break;
>         }
>       }
>     }
>   }
> 
>   return true;
> }
> 
> 
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

No branches or pull requests

1 participant