1 of 1 people found this helpful
If you attempt to read/write an attribute that requires encryption/authentication, then it will throw an error for insufficient encryption/authentication if it is not encrypted/authenticated.
Otherwise, you should be able to do the CyBle_GapAuthReq() function call in CYBLE_EVT_GAP_DEVICE_CONNECTED callback event to immediately encrypt upon device connection.
Yes, is wich I do, read/write an attribute that requires encryption, but I wonder myself if there ir a function that returns connection state (true/false encrytion).
I also know that exist CYBLE_EVT_GAP_ENCRYPT_CHANGE event. But I suppous that it is produced when encryption state changes, is not it ?
There are more events that occur involving encryption:
When you run the CyBle_GapAuthReq() function (as a client) then you will get either a success or failure event:
and you will get the CYBLE_EVT_GAP_AUTH_REQ event if the remote side of the connection requests authentication/encryption.
The event: CYBLE_EVT_GAP_SMP_NEGOTIATED_AUTH_INFO might have the "encryption enabled/disabled" flag you are looking for, but from what I can see, you will probably need to track the state of the encryption based upon the events that occur.
By default the device will not be encrypted when it connects, so if you have a state variable with default false when you connect to a device, and then change it based on the CYBLE_EVT_GAP_ENCRYPT_CHANGE event arguments, then you can accurately follow the encryption of the connection to ensure no "plain data" communication occurs.