I did get a central GAP unauthenticated pairing project working, but I can't disclose the project to you unfortunately. I can however help you with implementing your own
To find, connect to, and then discover the attributes of a unit:
//Note, you will want to use the correct information when starting discovery if you want to use whitelisting
//Once you find the device you want, either by advertisement data or address data, then call
//next connect to the device you want to
//then discover the primary services of the device
//then discover all the characteristics of the service you want attributes for
//You should now have handles for the services, attributes, and the device that you are interested in.
Events you will need to handle in the BLE callback handler:
//handle discovered devices to determine if you found the one(s) you want
//standard events for BLE examples
//signals the start or stop of advertising/scanning (depending on if you have central/peripheral)
//Events for connection parameter changes
//Events to handle the authentication part of the connection
case CYBLE_EVT_GAP_AUTH_REQ: //CyBle_GapAuthReq() is the API to initiate encryption for the connection
case CYBLE_EVT_GAP_AUTH_COMPLETE: //if encryption succeeded
case CYBLE_EVT_GAP_AUTH_FAILED: //if encryption failed
//service handle from unit
//characteristic handles from service
//Used for detecting GATTC error, or when finished discovering services/characteristics
//You don't necessarily need to handle the EVT_HCI status, but it will be useful for detecting errors and development
//you don't necessarily need to handle the timeout, but you should
thank you for your reply.
At which point should i call the CyBle_GapAuthReq() function to begin the pairing process?
Upon successful GATT connection or after discovering services and characteristics?
I do have a successful GAP central / GATT client project working just without the pairing, so a lot of what you've written makes sense.
I appreciate your time.
Depending on your application, you may want to try accessing data,etc. without encryption, for which case you would only do the CyBle_GapAuthReq() when you need it. If you want the entire connection encrypted (start-to-finish), then you will probably want to call it after receiving the CYBLE_EVT_GAP_DEVICE_CONNECTED event (I call it directly inside the callback handler for that event and it's happy with it, but however you want)
Keep in mind however, that the peripheral may request authentication/encryption in response to a request. This is why I included the CYBLE_EVT_GAP_AUTH_REQ event as one of the ones you should handle.
The auth/encrypt will stay active until a CYBLE_EVT_GAP_ENCRYPT_CHANGE event occurs to change the settings, or until you disconnect/get disconnected from the device. Note: you will want to make sure the BLE attributes are set to encryption/pairing required for access if you want to prevent unencrypted communication of data over the connection.
Sorry for the delay, i've only now had a chance to experiment.
Ok so i've set my project to discover services and characteristics.
Then i call CyBle_GapAuthReq() with the following parameters:
authData.security = (CYBLE_GAP_SEC_MODE_1 | CYBLE_GAP_SEC_LEVEL_2);
authData.bonding = CYBLE_GAP_BONDING_NONE;
authData.ekeySize = 7;
authData.pairingProperties = 0;
i wasn't sure what to set the ekeySize and pairingProperties to.
sure enough i'm receiving an error: Invalid parameter.
1 of 1 people found this helpful
no worries for the delay; I get busy and can't reply sometimes too
I believe I set the settings under the BLE component, and then used the cyBle_authInfo() to get the "default" settings. I didn't have a need for more than one security setting, but I'm sure you can modify it without problems
Here's the current default settings that I saw:
CYBLE_GAP_AUTH_INFO_T cyBle_authInfo =
(CYBLE_GAP_SEC_MODE_1 | CYBLE_GAP_SEC_LEVEL_2 ), /* uint8 security */
CYBLE_GAP_BONDING, /* uint8 bonding */
0x10u, /* uint8 ekeySize */
CYBLE_GAP_AUTH_ERROR_NONE, /* CYBLE_AUTH_FAILED_REASON_T authErr */
0x00u, /* uint8 pairingProperties */
You can find this under the BLE_eventHandler.c file at about line 222.
One thing to note; I believe there was a limitation with the BLE implementation so that you had to have bonding enabled in order to use pairing, thus forcing you to deal with bonding even though it isn't something that you necessarily would want. Try enabling the bonding and adding a layer/handler for the bonding operations and see if that makes it work fully.
thanks for all your help - finally it worked out.
The main issue was due to me not setting the authErr parameter, which the data sheet says you can ignore.
"The 'authErr' parameter in
CYBLE_GAP_AUTH_INFO_T should be ignored as it is not used in this
Once i set this to CYBLE_GAP_AUTH_ERROR_NONE as you suggested it was fine.
On a side note i found i could set the bonding to CYBLE_GAP_BONDING_NONE and it worked for me.
thanks again and all the best,
Hmmm; I'll have to remember that the "ignored" error isn't truly ignored
Huh, I'll have to look into the pairing not requiring bonding anymore; Pragmatically, that would be a pretty silly requirement, but I guess I was thinking of the standard applications where you want bonded devices :/
Glad you got it all figured out, and happy hunting
did it work for you?