SMP role, how to set? #15
Replies: 2 comments
-
Hi! The smp roles are tied to the connection role. If you are connected as a slave/peripheral, then you will have the SmpSlaveConnection object and if you are connected as a master/central, you will have the SmpMasterConnection object. It's always the central that initiates pair/bond/encryption requests. The peripheral can however "poke" the central to start encryption or initiate pairing. If the central agrees and wants to do that, it sends a pairing request or an encryption request. This is done by sending a "security request", by using the sendSecurityRequest method. https://github.com/Emill/node-ble-host#passkey-example---slave describes this flow. It can be sent immediately after connection setup. If you want to automatically reestablish encryption after a reconnection using the stored key in the bond database, you also use the security request, as explained later in the same section. Note that only one security request shall be sent, and that a security request can result in either the central reestablishes encryption using the stored key or that it initiates a new pairing attempt. So, in your case, simply always call sendSecurityRequest when a connection is established with your desired security properties as parameters and implement the callbacks you would like to handle, according to the example/documentation. |
Beta Was this translation helpful? Give feedback.
-
Oh, thanks, it seems i've mixed up some things then. Setting up sendSecurityRequest in the connected callback did the trick, thanks. Now it asks for bonding as soon as i connect to it from mobile. |
Beta Was this translation helpful? Give feedback.
-
Hi,
First of all, thank you for the effort to create this lib and letting us use it for free :)
I am trying to simulate a BLE device on a raspberry pi that intializes bonding automatically after connection. I am aware that the recommended way to do this is to trigger bonding when first trying to read an encrypted characteristic but my BLE device just behaves that way and i want to mimic that exact behavior.
I've folowed the quick guide on how to setup a GATT server, everything works fine except I cannot figure out how to trigger bonding.
Seems that by default, the connection smp object is always a SmpSlaveConnection so i can't sendPairingRequest in the connectCallback and i can't figure out how to set everything up so it will switch to a SmpMasterConnection. Could you point me in the right direction please? I see that there's a role used throughout the ble-manager but i can't seem to figure out how to set it. I am mainly a mobile developer with some nodejs knowledge so maybe i'm missing something important here.
Regards,
Alex
Beta Was this translation helpful? Give feedback.
All reactions