Skip to content

Can't remove individual bond with version 2.3.2 #994

@sanastasiou

Description

@sanastasiou

ble bonds

Number of bonded devices: 2
Bonded devices:
[1] f0:5c:77:f5:bb:25
[2] 60:7e:c9:7b:65:10

(✔ OK)

ble remove 2

Removing bond for device [2] 60:7e:c9:7b:65:10...
Error: Failed to remove bond. Individual bond removal may not be supported.
Workaround: Use 'ble reset' to remove all bonds.

(✘ Error)

ble bonds

Number of bonded devices: 2
Bonded devices:
[1] f0:5c:77:f5:bb:25
[2] 60:7e:c9:7b:65:10

(✔ OK)

ble reset

Deleting all bonded devices...
All bonded devices deleted.
Advertising restarted (device will remain invisible until pairing mode).
Note: Device restart recommended for clean state.

(✔ OK)

power r

Initiating graceful system restart...
Disconnected (device reports readiness to read but returned no data (device disconnected or multiple access on port?))
Reconnecting to /dev/ttyACM0 Connected!
ESP32NvMHal::init() Starting initialization
ESP32NvMHal::init() Opened namespace 'killswitch_'
ESP32NvMHal::init() Found header key
ESP32NvMHal::init() Header loaded: version=2, size=2, write_count=18, crc=0xFEAA
ESP32NvMHal::init() Read 2 bytes of data (header says 2 bytes, current structure is 2 bytes)
ESP32NvMHal::init() Verifying CRC...
ESP32NvMHal::calculateCrc() Calculated CRC=0xFEAA for 12 bytes (data size=2)
ESP32NvMHal::verifyCrc() CRC match: 0xFEAA
ESP32NvMHal::init() CRC verification passed
ESP32NvMHal::init() Successfully loaded data:
logger_level: 0
logger_mode: 1

ESP32NvMHal::read() address=0x00000000, size=10
ESP32NvMHal::read() Reading from header section
ESP32NvMHal::read() address=0x0000000A, size=2
ESP32NvMHal::read() Reading from data section
Logging disabled

╔════════════════════════════════════════════════╗
║ Killswitch Console v1.0.0.999.b864a71 ║
║ ║
║ Type 'help' for available commands ║
╚════════════════════════════════════════════════╝

ble bonds

Number of bonded devices: 0
No bonded devices found.

Code:

` const auto numBonds = NimBLEDevice::getNumBonds();
if (index > numBonds)
{
Serial.printf("Error: Index %d out of range. Only %d bonded device(s) available.\n", index, numBonds);
return CMD_ERROR;
}

            // Get the address at the specified index (convert 1-based to 0-based)
            NimBLEAddress addressToRemove = NimBLEDevice::getBondedAddress(index - 1);
            Serial.printf("Removing bond for device [%d] %s...\n", index, addressToRemove.toString().c_str());
            
            // Note: Check if connected to this device would be nice but 
            // getPeerDevices returns conn_handle, not easy to compare with address
            
            // Stop advertising, remove bond, restart advertising
            bool wasAdvertising = false;
            if (fBleController->isAdvertising())
            {
                wasAdvertising = true;
                fBleController->stopAdvertising();
            }
            
            // Remove the specific bond
            bool deleteResult = NimBLEDevice::deleteBond(addressToRemove);
            
            if (!deleteResult)
            {
                // If deleteBond fails, it's likely because ble_gap_unpair is not fully implemented
                Serial.printf("Error: Failed to remove bond. Individual bond removal may not be supported.\n");
                Serial.printf("Workaround: Use 'ble reset' to remove all bonds.\n");
                
                // Restart advertising if it was stopped
                if (wasAdvertising)
                {
                    fBleController->startWhitelistedAdvertising();
                }
                return CMD_ERROR;
            }
            
            if (deleteResult)
            {
                Serial.printf("Bond removed successfully.\n");
                
                // Restart advertising if it was running
                if (wasAdvertising)
                {
                    // Always use whitelisted advertising for security
                    // If no bonds remain, this will result in no advertising (device stays invisible)
                    fBleController->startWhitelistedAdvertising();
                    Serial.printf("Advertising restarted.\n");
                }
            }
            else
            {
                Serial.printf("Error: Failed to remove bond.\n");
                // Restart advertising if it was stopped
                if (wasAdvertising)
                {
                    fBleController->startWhitelistedAdvertising();
                }
                return CMD_ERROR;
            }
        }`

` // Delete all bonded devices
try
{
Serial.printf("Deleting all bonded devices...\n");

            // Stop advertising before manipulating bonds
            bool wasAdvertising = false;
            if (fBleController->isAdvertising())
            {
                wasAdvertising = true;
                fBleController->stopAdvertising();
            }
            
            NimBLEDevice::deleteAllBonds();
            Serial.printf("All bonded devices deleted.\n");
            
            // Restart advertising in whitelisted mode (stays invisible after reset)
            if (wasAdvertising)
            {
                fBleController->startWhitelistedAdvertising();
                Serial.printf("Advertising restarted (device will remain invisible until pairing mode).\n");
            }
            
            Serial.printf("Note: Device restart recommended for clean state.\n");
        }
        catch (...)
        {
            Serial.printf("Error: Unable to delete bonded devices\n");
            return CMD_ERROR;
        }
        return CMD_OK;`

Can remove all bonds, but not individuals bonds.. Something's wrong with ble_clear vs. ble_unpair.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions