mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 14:42:05 +00:00
use executeDelete to prevent leaking BLE handles
This commit is contained in:
parent
575a15e135
commit
d5deb49d20
@ -8,53 +8,6 @@
|
|||||||
|
|
||||||
SimpleAllocator btPool;
|
SimpleAllocator btPool;
|
||||||
|
|
||||||
/**
|
|
||||||
* Create standard device info service
|
|
||||||
**/
|
|
||||||
BLEService *createDeviceInfomationService(BLEServer *server, std::string hwVendor, std::string swVersion,
|
|
||||||
std::string hwVersion = "")
|
|
||||||
{
|
|
||||||
BLEService *deviceInfoService = server->createService(BLEUUID((uint16_t)ESP_GATT_UUID_DEVICE_INFO_SVC));
|
|
||||||
|
|
||||||
BLECharacteristic *swC =
|
|
||||||
new BLECharacteristic(BLEUUID((uint16_t)ESP_GATT_UUID_SW_VERSION_STR), BLECharacteristic::PROPERTY_READ);
|
|
||||||
BLECharacteristic *mfC = new BLECharacteristic(BLEUUID((uint16_t)ESP_GATT_UUID_MANU_NAME), BLECharacteristic::PROPERTY_READ);
|
|
||||||
// BLECharacteristic SerialNumberCharacteristic(BLEUUID((uint16_t) ESP_GATT_UUID_SERIAL_NUMBER_STR),
|
|
||||||
// BLECharacteristic::PROPERTY_READ);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Mandatory characteristic for device info service?
|
|
||||||
|
|
||||||
BLECharacteristic *m_pnpCharacteristic = m_deviceInfoService->createCharacteristic(ESP_GATT_UUID_PNP_ID,
|
|
||||||
BLECharacteristic::PROPERTY_READ);
|
|
||||||
|
|
||||||
uint8_t sig, uint16_t vid, uint16_t pid, uint16_t version;
|
|
||||||
uint8_t pnp[] = { sig, (uint8_t) (vid >> 8), (uint8_t) vid, (uint8_t) (pid >> 8), (uint8_t) pid, (uint8_t) (version >>
|
|
||||||
8), (uint8_t) version }; m_pnpCharacteristic->setValue(pnp, sizeof(pnp));
|
|
||||||
*/
|
|
||||||
swC->setValue(swVersion);
|
|
||||||
deviceInfoService->addCharacteristic(addBLECharacteristic(swC));
|
|
||||||
mfC->setValue(hwVendor);
|
|
||||||
deviceInfoService->addCharacteristic(addBLECharacteristic(mfC));
|
|
||||||
if (!hwVersion.empty()) {
|
|
||||||
BLECharacteristic *hwvC =
|
|
||||||
new BLECharacteristic(BLEUUID((uint16_t)ESP_GATT_UUID_HW_VERSION_STR), BLECharacteristic::PROPERTY_READ);
|
|
||||||
hwvC->setValue(hwVersion);
|
|
||||||
deviceInfoService->addCharacteristic(addBLECharacteristic(hwvC));
|
|
||||||
}
|
|
||||||
// SerialNumberCharacteristic.setValue("FIXME");
|
|
||||||
// deviceInfoService->addCharacteristic(&SerialNumberCharacteristic);
|
|
||||||
|
|
||||||
// m_manufacturerCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t) 0x2a29,
|
|
||||||
// BLECharacteristic::PROPERTY_READ); m_manufacturerCharacteristic->setValue(name);
|
|
||||||
|
|
||||||
/* add these later?
|
|
||||||
ESP_GATT_UUID_SYSTEM_ID
|
|
||||||
*/
|
|
||||||
|
|
||||||
// caller must call service->start();
|
|
||||||
return deviceInfoService;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _BLEClientConnected = false;
|
bool _BLEClientConnected = false;
|
||||||
|
|
||||||
@ -106,6 +59,54 @@ void addWithDesc(BLEService *service, BLECharacteristic *c, const char *descript
|
|||||||
addBLEDescriptor(desc);
|
addBLEDescriptor(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create standard device info service
|
||||||
|
**/
|
||||||
|
BLEService *createDeviceInfomationService(BLEServer *server, std::string hwVendor, std::string swVersion,
|
||||||
|
std::string hwVersion = "")
|
||||||
|
{
|
||||||
|
BLEService *deviceInfoService = server->createService(BLEUUID((uint16_t)ESP_GATT_UUID_DEVICE_INFO_SVC));
|
||||||
|
|
||||||
|
BLECharacteristic *swC = new BLECharacteristic(BLEUUID((uint16_t)ESP_GATT_UUID_SW_VERSION_STR), BLECharacteristic::PROPERTY_READ);
|
||||||
|
BLECharacteristic *mfC = new BLECharacteristic(BLEUUID((uint16_t)ESP_GATT_UUID_MANU_NAME), BLECharacteristic::PROPERTY_READ);
|
||||||
|
// BLECharacteristic SerialNumberCharacteristic(BLEUUID((uint16_t) ESP_GATT_UUID_SERIAL_NUMBER_STR),
|
||||||
|
// BLECharacteristic::PROPERTY_READ);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Mandatory characteristic for device info service?
|
||||||
|
|
||||||
|
BLECharacteristic *m_pnpCharacteristic = m_deviceInfoService->createCharacteristic(ESP_GATT_UUID_PNP_ID,
|
||||||
|
BLECharacteristic::PROPERTY_READ);
|
||||||
|
|
||||||
|
uint8_t sig, uint16_t vid, uint16_t pid, uint16_t version;
|
||||||
|
uint8_t pnp[] = { sig, (uint8_t) (vid >> 8), (uint8_t) vid, (uint8_t) (pid >> 8), (uint8_t) pid, (uint8_t) (version >>
|
||||||
|
8), (uint8_t) version }; m_pnpCharacteristic->setValue(pnp, sizeof(pnp));
|
||||||
|
*/
|
||||||
|
swC->setValue(swVersion);
|
||||||
|
deviceInfoService->addCharacteristic(addBLECharacteristic(swC));
|
||||||
|
mfC->setValue(hwVendor);
|
||||||
|
deviceInfoService->addCharacteristic(addBLECharacteristic(mfC));
|
||||||
|
if (!hwVersion.empty()) {
|
||||||
|
BLECharacteristic *hwvC =
|
||||||
|
new BLECharacteristic(BLEUUID((uint16_t)ESP_GATT_UUID_HW_VERSION_STR), BLECharacteristic::PROPERTY_READ);
|
||||||
|
hwvC->setValue(hwVersion);
|
||||||
|
deviceInfoService->addCharacteristic(addBLECharacteristic(hwvC));
|
||||||
|
}
|
||||||
|
// SerialNumberCharacteristic.setValue("FIXME");
|
||||||
|
// deviceInfoService->addCharacteristic(&SerialNumberCharacteristic);
|
||||||
|
|
||||||
|
// m_manufacturerCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t) 0x2a29,
|
||||||
|
// BLECharacteristic::PROPERTY_READ); m_manufacturerCharacteristic->setValue(name);
|
||||||
|
|
||||||
|
/* add these later?
|
||||||
|
ESP_GATT_UUID_SYSTEM_ID
|
||||||
|
*/
|
||||||
|
|
||||||
|
// caller must call service->start();
|
||||||
|
return deviceInfoService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static BLECharacteristic *batteryLevelC;
|
static BLECharacteristic *batteryLevelC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -226,11 +227,12 @@ void deinitBLE()
|
|||||||
if (pUpdate != NULL) {
|
if (pUpdate != NULL) {
|
||||||
destroyUpdateService();
|
destroyUpdateService();
|
||||||
|
|
||||||
pUpdate->stop();
|
|
||||||
pUpdate->stop(); // we delete them below
|
pUpdate->stop(); // we delete them below
|
||||||
|
pUpdate->executeDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
pDevInfo->stop();
|
pDevInfo->stop();
|
||||||
|
pDevInfo->executeDelete();
|
||||||
|
|
||||||
// First shutdown bluetooth
|
// First shutdown bluetooth
|
||||||
BLEDevice::deinit(false);
|
BLEDevice::deinit(false);
|
||||||
@ -245,8 +247,9 @@ void deinitBLE()
|
|||||||
|
|
||||||
batteryLevelC = NULL; // Don't let anyone generate bogus notifies
|
batteryLevelC = NULL; // Don't let anyone generate bogus notifies
|
||||||
|
|
||||||
for (int i = 0; i < numChars; i++)
|
for (int i = 0; i < numChars; i++) {
|
||||||
delete chars[i];
|
delete chars[i];
|
||||||
|
}
|
||||||
numChars = 0;
|
numChars = 0;
|
||||||
|
|
||||||
for (int i = 0; i < numDescs; i++)
|
for (int i = 0; i < numDescs; i++)
|
||||||
@ -280,7 +283,8 @@ BLEServer *initBLE(StartBluetoothPinScreenCallback startBtPinScreen, StopBluetoo
|
|||||||
// We now let users create the battery service only if they really want (not all devices have a battery)
|
// We now let users create the battery service only if they really want (not all devices have a battery)
|
||||||
// BLEService *pBattery = createBatteryService(pServer);
|
// BLEService *pBattery = createBatteryService(pServer);
|
||||||
|
|
||||||
#ifdef BLE_SOFTWARE_UPDATE // Disable for now
|
#define BLE_SOFTWARE_UPDATE
|
||||||
|
#ifdef BLE_SOFTWARE_UPDATE
|
||||||
pUpdate = createUpdateService(pServer, hwVendor, swVersion,
|
pUpdate = createUpdateService(pServer, hwVendor, swVersion,
|
||||||
hwVersion); // We need to advertise this so our android ble scan operation can see it
|
hwVersion); // We need to advertise this so our android ble scan operation can see it
|
||||||
|
|
||||||
|
@ -133,6 +133,7 @@ void stopMeshBluetoothService()
|
|||||||
{
|
{
|
||||||
assert(meshService);
|
assert(meshService);
|
||||||
meshService->stop();
|
meshService->stop();
|
||||||
|
meshService->executeDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroyMeshBluetoothService()
|
void destroyMeshBluetoothService()
|
||||||
|
Loading…
Reference in New Issue
Block a user