h2zero / NimBLE-Arduino

A fork of the NimBLE library structured for compilation with Arduino, for use with ESP32, nRF5x.
https://h2zero.github.io/NimBLE-Arduino/
Apache License 2.0
667 stars 138 forks source link

How to react to a bad passkey? #631

Closed trullock closed 5 months ago

trullock commented 5 months ago

void onAuthenticationComplete(NimBLEConnInfo& connInfo)

is not called on my client when uint32_t onPassKeyRequest() returns the wrong passkey.

This leaves my client "connected", but it can't communicate. No callbacks occur so I can't react to this state.

I can see the example code shows this for the client:

    void onAuthenticationComplete(NimBLEConnInfo& connInfo){
        Serial.println("onAuthenticationComplete");
        if(!connInfo.isEncrypted()) {
            Serial.println("Encrypt connection failed - disconnecting");
            /** Find the client with the connection handle provided in connInfo */
            NimBLEDevice::getClientByID(connInfo.getConnHandle())->disconnect();
            return;
        }
    };

Except onAuthenticationComplete isnt called at all...

Client Debug:

D NimBLEClient: Got Client event 
D NimBLEClient: Enter the passkey
uint32_t onPassKeyRequest() called (returns wrong value)
D NimBLEClient: ble_sm_inject_io result: 3
D NimBLEClient: Got Client event 

Server debug:

I NimBLEServer: subscribe event; attr_handle=12, subscribed: true
I NimBLECharacteristic: New subscribe value for conn: 0 val: 1
uint32_t onPassKeyRequest() called

What am I missing?

Thanks

trullock commented 5 months ago

Method signature had changed, somehow was using an OOD example Should be void onAuthenticationComplete(ble_gap_conn_desc* desc) {

Apologies