cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC Creator & Designer Software

New Contributor II

Hello to all,

I am using BLE v3.30 and am testing authentication fail situations. One of them is also to enter wrong pin code.

I also read Bluetooth Low Energy v3.30.pdf document.

I put some traces into the ble event handler just to see what is happening and I found out following:

- an event CYBLE_EVT_GAP_AUTH_FAILED is send

- structure passed with this event is of type CYBLE_GAP_AUTH_INFO_T.

- I checked the parameters and there is a parameter called "authErr" which should describe the error.

- When I print the value of the "authErr" after I entered invalid PIN code I see that the value is 0 ??? which means CYBLE_GAP_AUTH_ERROR_NONE.

- The parameter "bonding" is set to value 0x04 which is also strange

I double check everything and implementation is ok:

       CYBLE_GAP_AUTH_INFO_T status = *(CYBLE_GAP_AUTH_INFO_T *)eventParam;               
               
       char* dummy = "CYBLE_EVT_GAP_AUTH_FAILED: bonding, authErr";
       SW_Tx_UART_1_PutString(dummy);
       SW_Tx_UART_1_PutCRLF();

       SW_Tx_UART_1_PutHexByte(status.bonding);
       SW_Tx_UART_1_PutCRLF();

       SW_Tx_UART_1_PutHexByte(status.authErr);
       SW_Tx_UART_1_PutCRLF();

So the question is, why do I get OK if for invalid PIN number I should get some error. And actually the device don't connect over the bluetooth, so this is working fine. To me it looks like this 2 parameters are inverted.

Another question is, what does the BLE send back if I enter invalid PIN code? So that the application on the other side could properly handle the error?

From the CySmart application and when using the source code with the Android studio I found out it get this information:

      D/CySmart Android: PCF: pair: registering mPairOnConnectStatusReceiver

      I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@3b88ef84 time:520152927

      D/CySmart Android: HPA: pair: BluetoothDevice.BOND_NONE

       BondingProgressDialog: pair: dismissing dialog 582622311

      D/BluetoothGatt: onClientConnectionState() - status=22 clientIf=7 device=00:A0:50:00:00:00

      I/CySmart Android: onConnectionStateChange: status: 22, newState: 0

       BluetoothLeService: action: com.example.bluetooth.le.ACTION_GATT_DISCONNECTED

status=22 was taken from the Android-BLE-Library/GattError.java at 5e0e2f08c309a6de2376d9b8705c83f9e9a80d56 · NordicSemiconductor...  and it means GATT_CONN_TERMINATE_LOCAL_HOST. But I don't see an error describing that wrong PIN number.

Any further information on how BLE handles wrong PIN code and what does it actually returns back over the BLE would be really helpful. Or is it option that I can send something back?

Thanks for the answer, Frenk

0 Likes
Reply
1 Solution
Moderator
Moderator

Hello,

If the authentication process is failed, CYBLE_EVT_GAP_AUTH_FAILED event will be received. The return value of type CYBLE_GAP_AUTH_FAILED_REASON_T indicates the reason for failure. Please add the below code snippet in the event handler function for checking the error reason.

If you enter a wrong PIN code, then you will reason CYBLE_GAP_AUTH_ERROR_CONFIRM_VALUE_NOT_MATCH error.

********************************************************
        case CYBLE_EVT_GAP_AUTH_FAILED:

            DBG_PRINTF("EVT_GAP_AUTH_FAILED, reason: ");
            switch(*(CYBLE_GAP_AUTH_FAILED_REASON_T *)eventParam)
             {        

                case CYBLE_GAP_AUTH_ERROR_CONFIRM_VALUE_NOT_MATCH:
                    DBG_PRINTF("CONFIRM_VALUE_NOT_MATCH\r\n");
                    break;

                case CYBLE_GAP_AUTH_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE:
                    DBG_PRINTF("INSUFFICIENT_ENCRYPTION_KEY_SIZE\r\n");
                    break;

                case CYBLE_GAP_AUTH_ERROR_UNSPECIFIED_REASON:
                    DBG_PRINTF("UNSPECIFIED_REASON\r\n");
                    break;

                case CYBLE_GAP_AUTH_ERROR_AUTHENTICATION_TIMEOUT:
                    DBG_PRINTF("AUTHENTICATION_TIMEOUT\r\n");
                    break;

                default:
                    DBG_PRINTF("0x%x  \r\n", *(CYBLE_GAP_AUTH_FAILED_REASON_T *)eventParam);
                    break;
            }

         break;
********************************************************

Please refer to the "BLE_4.2_DataLength_Security_Privacy" code example in the PSoC Creator for more information.

Thanks,
P Yugandhar.

View solution in original post

0 Likes
Reply
1 Reply
Moderator
Moderator

Hello,

If the authentication process is failed, CYBLE_EVT_GAP_AUTH_FAILED event will be received. The return value of type CYBLE_GAP_AUTH_FAILED_REASON_T indicates the reason for failure. Please add the below code snippet in the event handler function for checking the error reason.

If you enter a wrong PIN code, then you will reason CYBLE_GAP_AUTH_ERROR_CONFIRM_VALUE_NOT_MATCH error.

********************************************************
        case CYBLE_EVT_GAP_AUTH_FAILED:

            DBG_PRINTF("EVT_GAP_AUTH_FAILED, reason: ");
            switch(*(CYBLE_GAP_AUTH_FAILED_REASON_T *)eventParam)
             {        

                case CYBLE_GAP_AUTH_ERROR_CONFIRM_VALUE_NOT_MATCH:
                    DBG_PRINTF("CONFIRM_VALUE_NOT_MATCH\r\n");
                    break;

                case CYBLE_GAP_AUTH_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE:
                    DBG_PRINTF("INSUFFICIENT_ENCRYPTION_KEY_SIZE\r\n");
                    break;

                case CYBLE_GAP_AUTH_ERROR_UNSPECIFIED_REASON:
                    DBG_PRINTF("UNSPECIFIED_REASON\r\n");
                    break;

                case CYBLE_GAP_AUTH_ERROR_AUTHENTICATION_TIMEOUT:
                    DBG_PRINTF("AUTHENTICATION_TIMEOUT\r\n");
                    break;

                default:
                    DBG_PRINTF("0x%x  \r\n", *(CYBLE_GAP_AUTH_FAILED_REASON_T *)eventParam);
                    break;
            }

         break;
********************************************************

Please refer to the "BLE_4.2_DataLength_Security_Privacy" code example in the PSoC Creator for more information.

Thanks,
P Yugandhar.

View solution in original post

0 Likes
Reply