This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/CC2640R2F: Manage more attempts of pairing

Part Number: CC2640R2F
Other Parts Discussed in Thread: SIMPLELINK-CC2640R2-SDK

Tool/software: Code Composer Studio

Hi All,

I would like to attempt the connection entering the password only for X times and after my device will be offline for some time.

How to is possible to ask another pairing request? I found the API GAPBondMgr_Pair() on:

http://software-dl.ti.com/simplelink/esd/simplelink_cc2640r2_sdk/2.20.00.49/exports/docs/ble5stack/ble_user_guide/doxygen/ble/html/group___g_a_p_bond_mgr.html#ga15379572e5d31e014e84e5457d4b1633

but this API is not supported by my SDK cc2640r2_sdk_2_40_00_32.

Is there a SDK that contain this API? Or If you can suggest me another mechanism to manage more pairing attempts on the same connection.

Regards,

Alfredo

  • Hi Alfredo,

    Yes, I would recommend using the GAPBondMgr_Pair API for the task you are trying to accomplish. This API is available on the newest SDK SIMPLELINK-CC2640R2-SDK_4.20.00.04. Are you able to update your SDK to the latest version?

    Best Regards,

    Jenny

  • Hi Jenny,

    I've installed the SDK SIMPLELINK-CC2640R2-SDK_4.20.00.04, but during building I have the followings error:

    ../Application/simple_serial_socket/simple_serial_socket_server.c", line 1790: warning #225-D: function "GAPBondMgr_Pair" declared implicitly

    Are you sure that this API is in SDK that you mention?

    On Internet I founded this API in SDK SIMPLELINK-CC2640R2-SDK_2.20.00.49... please see the attached file.

    Could you verify if effectively this API is present ONLY in SDK SIMPLELINK-CC2640R2-SDK_2.20.00.49 and not in SDK SIMPLELINK-CC2640R2-SDK_4.20.00.04?

    Best Regards,

    Alfredogapbondmgr.h

  • Hi Alfredo,

    I have verified that this API is present in SDK SIMPLELINK-CC2640R2-SDK_4.20.00.04. Navigate to the SDK folder source\ti\ble5stack\host\gapbondmgr.c and you should be able to find GAPBondMgr_Pair. Is gapbondmgr.h being included in simple_serial_socket_server.c using #include "gapbondmgr.h"? This could be why it's giving a warning that it's declared implicitly. 

    Best Regards,

    Jenny

  • Hi Jenny,

    I founded my develop on blestack library and not ble5stack... so I have a difficulty to use ble5stack.

    Is possible in your opinion to manage more attempts of pairing without using GAPBondMgr_Pair API?

    Let me know.

    Best Regards,

    Alfredo

  • Hi Alfredo,

    Thank you for clarifying this. I don't believe there's an API I can suggest for you to use that satisfies what GAPBondMgr_Pair does in ble5stack. However, this might be a workaround for your case. I would test to see if this workaround allows you to start pairing from application for more pairings. Add the following case statement within the API GAPBondMgr_SetParameter within source\ti\blestack\profiles\roles\gapbondmgr.c:

          case GAPBOND_START_PAIRING:
          {
            uint16 connHandle = 0; 
            
            if(len == sizeof ( uint16 ))
              connHandle = *((uint16*)pValue);        // Find connection role
            linkDBInfo_t linkInfo;
            linkDB_GetInfo(connHandle, &linkInfo);
            uint8_t role = linkInfo.connRole;        //save pairing mode and initiate pairing
            uint8 pairingModeSave = gapBond_PairingMode;
            gapBond_PairingMode = GAPBOND_PAIRING_MODE_INITIATE;
            GAPBondMgr_LinkEst(linkInfo.addrType, linkInfo.addr, connHandle, role);
       
            //Restore previous pairing mode
            gapBond_PairingMode = pairingModeSave;
          }
          break;

    Please let me know if you have any additional questions regarding this. Thanks!

    Best Regards,

    Jenny

  • Hi Jenny,

    I tryed your code but I see a few error when I try to build:

    GAPBOND_START_PAIRING is not existing define. Infact I see only the GAPBOND_PAIRING_MODE. In any case when I try to do this assignment: connHandle = *((uint16*)pValue);

    connHandle is the pairing mode and not connection info, this info I can get from GAPRole_GetParameter(GAPROLE_CONNHANDLE, &connectionHandle), but I think this API is not called in gapbondmgr.c.

    In any case let me know if you have something to say about it that i am wrong.

    B.R.,

    Alfredo

  • Hi Alfredo,

    I apologize for not clarifying in my previous post. You would need to create the new case GAPBOND_START_PAIRING as this case does not exist within the function GAPBondMgr_SetParameter. You can create a define for GAPBOND_START_PAIRING within gapbondmgr.h similar to how GAPBOND_PAIRING_MODE is defined. These existing defines can be found in source\ti\blestack\profiles\roles\gapbondmgr.h. 

    In regards to your second observation, when you pass in pValue into the function GAPBondMgr_SetParameter you can pass in the connectionHandle as this parameter. I think when you say pValue is the pairing mode you might be referring to the case GAPBOND_PAIRING_MODE. In this new case GAPBOND_START_PAIRING, you can pass in the connection handle as pValue and use this connection handle to look up the link to start pairing.

    Best Regards,

    Jenny

  • Hello Jenny,

    I understand now well your suggestion, so I create the define GAPBOND_START_PAIRING e put your code into my gapbondmgr.c. I building successfully, but I see on My App LightBlue only 1 pairing request :(

    I don't understand though, when the case GAPBOND_START_PAIRING will be selected in blestack.
    Regards,
    Alfredo
  • Hi Alfredo,

    Thanks for making the additional modifications to create the define for GAPBOND_START_PAIRING!

    Since this is not a feature or API in the project you are working with, this is intended to be a workaround only so the blestack won't select this by default. This responsibility of start pairing will fall on the application you're developing. You will need to manually call GAPBondMgr_SetParameter with the param variable GAPBOND_START_PAIRING. The purpose of this workaround is to allow you to manually start pairing from the application.

    Best Regards,

    Jenny

  • Hi Jenny,

    I tried to put a GAPBondMgr_SetParameter(GAPBOND_START_PAIRING, sizeof(uint16_t), &connectionHandle); at the end of the pairing process in case of failure (as is explained in the Figure 53 @ link: http://software-dl.ti.com/lprf/simplelink_cc2640r2_sdk/1.00.00.22/exports/docs/blestack/html/ble-stack/index.html#gap-bond-manager-and-le-secure-connections you can see also the below code).

    No pairing process is restarted.

    static void MyApplication_processPairState(uint8_t state, uint8_t status)
    {
      if (state == GAPBOND_PAIRING_STATE_STARTED)
      {
        Display_print0(dispHandle, 2, 0, "Pairing started");
      }
      else if (state == GAPBOND_PAIRING_STATE_COMPLETE)
      {
        if (status == SUCCESS)
        {
            Display_print0(dispHandle, 2, 0, "Pairing success");
        }
        else
        {
            Display_print1(dispHandle, 2, 0, "Pairing fail: %d", status);
            uint16_t connectionHandle;
            GAPRole_GetParameter(GAPROLE_CONNHANDLE, &connectionHandle);
            GAPBondMgr_SetParameter(GAPBOND_START_PAIRING, sizeof(uint16_t), &connectionHandle);       
           
        }
        ....
    Regards,
    Alfredo

  • Hi Alfredo,

    I will try to replicate this as similar to your setup as possible and let you know if any additional changes need to be made for the pairing to successfully work. Thank you for sharing the results of your test.

    Best Regards,

    Jenny

  • Hi Alfredo,

    I tried testing pairing with a connection and it seems successful. The following was the setup I used:

    Project I modified with this new GAPBOND_START_PAIRING case: simple_peripheral (blestack)

    SDK: simplelink_cc2640r2_sdk_4_20_00_04

    Modifications:

    • Added GAPBOND_START_PAIRING case to GAPBondMgr_SetParameter
    • Within simple_peripheral.c in the function SimplePeripheral_processStateChangeEvt I added some additional lines to the case GAPROLE_CONNECTED. At the end of the case statement, I added the following lines:

    Verification:

    • Using LightBlue application, I connected to the peripheral and placed a breakpoint within this case statement to see that it was entering. I also received the Pair passcode request on LightBlue which confirms that the pairing process was initiated after the connection was established.

    Can you set a breakpoint within this case statement to verify that it is being called?

    Best Regards,

    Jenny

    
    

  • Hi Jenny,

    sorry you probably forget to write the code when you write: At the end of the case statement, I added the following lines:....

    Please could you specificates this code linees?

    In any case could you try to insert a wrong passcode and verify if the pairing process restart again with a new request of the passcode? This is my topic!

    Best Regards,

    Alfredo

  • Hi Alfredo,

    I apologize, here are the following lines:

      uint16_t connectionHandle;
      GAPRole_GetParameter(GAPROLE_CONNHANDLE, &connectionHandle);
      GAPBondMgr_SetParameter(GAPBOND_START_PAIRING, sizeof(uint8_t), &connectionHandle);

    Best Regards,

    Jenny

  • Hi Jenny,

    I set the breakpoint within the case GAPROLE_CONNECTED and the pairing process works fine and the connection was established. But the problem for me is not to obtain the connections but is the follows:

    - when insert a wrong  wrong passcode I want to obtain a restart of the pairing process for x times and not the disconnection of the device.

    My topic is this.

    I don't know if this more pairing attempts is a feature to do in Android App or in my Application.

    Best Regards,

    Alfredo

  • Hi Alfredo,

    This GAPBOND_START_PAIRING case statement you added to GAPBondMgr_SetParameter will help you initiate the pairing. As seen when adding this to GAPROLE_CONNECTED, you are able to initiate the pairing process after the connection has been made. Similarly, in your use case you can apply the same snippet of code after a wrong passcode is entered:

      uint16_t connectionHandle;
      GAPRole_GetParameter(GAPROLE_CONNHANDLE, &connectionHandle);
      GAPBondMgr_SetParameter(GAPBOND_START_PAIRING, sizeof(uint8_t), &connectionHandle);

    This piece of code isn't for obtaining the connection only, but will also initiate pairing from the application. From the scenario you described, you can utilize the piece of code as shown above if you enter a wrong passcode. You can check for the passcode and once that has failed, call GAPBondMgr_SetParameter with the GAPBOND_START_PAIRING parameter to try to pair again with the device you are currently connected to.

    Please let me know if this explanation isn't clear or I am misinterpreting your use case. Thanks!

    Best Regards,

    Jenny

  • Hi Jenny,

    I've already trye the solution that you propose, so I put the:

    uint16_t connectionHandle;
    GAPRole_GetParameter(GAPROLE_CONNHANDLE, &connectionHandle);
    GAPBondMgr_SetParameter(GAPBOND_START_PAIRING, sizeof(uint8_t), &connectionHandle);

    code when the check passcode fails, but the pairing process with LightBlue App don't start… probably is due to the App that don't allows more pairing attemps… I don't know.

    So I will try with another App as soon as possible and give you a feedback!

    B.R.,

    Alfredo

  • Hello Jenny,

    I tryed with LightBlue App updated and also with another App BLE Analyzer, but however it doesn't work.

    Regards,

    Alfredo

  • Hi Alfredo,

    Thank you for verifying with another phone application to see if it works. I added the call to GAPBondMgr_SetParameter in the same location you have yours in: SimplePeripheral_processPairState in the pairing fail else statement. It appears that this probably doesn't successfully pair due to the phone sending a like termination so sending a start pair won't matter in this case as the phone terminates the connection. To verify this I will perform the test and take a sniffer log to see if this supports my explanation and we can work on a workaround if this is the case.

    Best Regards,

    Jenny