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.

CC2640: Change PassKey remotely

Part Number: CC2640
Other Parts Discussed in Thread: , BLE-STACK, CC2650

Hello everyone and Happy New Year. We are working with the launchXL CC2640R2F and bluetooth communication. We connected to the device, one of our central for a gate to open and close it via APP. So far everything works perfectly. Now, we are developing other power plants to sell to our customers with the CC2640 on a custom board. Our goal is security. Is it possible to change the default passkey from remote? Each customer must have his own password. How can I do this? Thank you all

  • Hi Mark,

    We have an example for BLE-Stack 2.x that uses the TRNG to generate a passcode at the time of pairing.
    github.com/.../ble_examples-2.2

    In short, the important detail is that the app sets the passcode response based on GAPBondMgr_PasscodeRsp.
    You could configure a way for this to be set remotely.
  • Hi Sean, I can not open the page you have attached to me. So, are you telling me that I can change the passkey via APP?

  • Hi Mark,

    That is correct.
    here is the link again:
    github.com/.../ble_examples-2.2
  • What do you call the example?
  • You can reference security examples central or peripheral.

    You can find the example code at /src/examples/
  • Hi Sean, thanks for the answer. I will to test this examples with my CCS. One question for you: it's possible to associate the smartphone and CC2640 device through a button?

    1) Open CC2640
    2) Open APP on my Smartphone
    3) Click on CC2640 device and I see the message for association
    4) Click a botton on CC2640 and the board associate with smartphone
  • Hi Mark,

    If by associate you mean Pairing then yes this is possible, you will just need to set the IO capabilites on each device accordingly.
    We have some documentation about this here:
    www.ti.com/.../swru393

    See section 5.4.2 of the document above.

    Essentially it sounds like LE legacy just works pairing (no button press required) or LE Secure Connections Numeric Comparison (requires Y/N button) should work for you.
  • Yes, I mean the Pairing with a button. Then, I can to use the IO capabilites. I will to try. Thanks!
  • Hi I tried the IO capabilities, but I can not associate the cc2640 with a button. I tried to set it this way:

      uint32_t passkey = 0; // passkey "0000"
      uint8_t pairMode = GAPBOND_PAIRING_MODE_INITIATE;
      uint8_t mitm = TRUE;
      uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_YES_NO;
      uint8_t bonding = FALSE;
    
      GAPBondMgr_SetParameter(GAPBOND_DEFAULT_PASSCODE, sizeof(uint32_t),
                             &passkey);
      GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
      GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
      GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
      GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);

    In this mode on my smartphone appears:

    Bluetooth association request:

    Passkey: numeric random
    Associate with Project Zero?

    If I click on OK of my smartphone, it connects automatically and I not press nothing on my CC2640

  • Hi Mark,

    You'll need to process the keypress on the CC2650 in the handling function, for example from project zero,

        case APP_MSG_SEND_PASSCODE: /* Message about pairing PIN request */
          {
            passcode_req_t *pReq = (passcode_req_t *)pMsg->pdu;
            Log_info2("BondMgr Requested passcode. We are %s passcode %06d",
                      (IArg)(pReq->uiInputs?"Sending":"Displaying"),
                      DEFAULT_PASSCODE);
            // HERE PROMPT USER to press Y/N for pairing
            // HERE WAIT FOR USER RESPONSE/READ PIN
            // Send passcode response, SELECT SUCCESS if user confirm, failure otherwise
            GAPBondMgr_PasscodeRsp(pReq->connHandle, SUCCESS, DEFAULT_PASSCODE);
          }

    Note that the code I am referencing is in ProjectZero.c from http://software-dl.ti.com/lprf/simplelink_academy/overview.html

    The project can be found in \modules\projects\ble_projectzero

  • Ok, then I modify this part of code for implement the pression of button and I put the value of button instead of DEFAULT_PASSCODE in " GAPBondMgr_PasscodeRsp(pReq->connHandle, SUCCESS, DEFAULT_PASSCODE);"
  • Yes, basically, you can force the pairing to fail from the CC2650 by causing GAPBondMgr_PasscodeRsp() to fail.
    You can do this by either setting the second parameter != SUCCESS or making the passcode incorrect. Using !SUCCESS is probably easier.
  • I'm going to use the PinInterrupt example to press the button and then put the value inside of GAPBondMgr_PasscodeRsp()
  • Hi Sean, I try to implement the part of code the PinInterrupt on my project-zero, but I have the errors. This is a my  part of code:

    static void user_processApplicationMessage(app_msg_t *pMsg, PIN_Handle handle, PIN_Id pinId)
    {
      char_data_t *pCharData = (char_data_t *)pMsg->pdu;
      uint32_t newpass = 0;

    case APP_MSG_SEND_PASSCODE: /* Message about pairing PIN request */
          {
              if (!PIN_getInputValue(pinId)) {
                  switch (pinId) {
                                  case Board_PIN_BUTTON1:
                                  newpass =  PIN_getOutputValue(Board_PIN_BUTTON1);
    
            passcode_req_t *pReq = (passcode_req_t *)pMsg->pdu;
            Log_info2("BondMgr Requested passcode. We are %s passcode %06d",
                      (IArg)(pReq->uiInputs?"Sending":"Displaying"),
                      newpass);
            // Send passcode response.
            GAPBondMgr_PasscodeRsp(pReq->connHandle, SUCCESS, newpass);
          }
              }
          }
          break;

    In this case I have problems with the function: user_processApplicationMessage(pMsg); He tells me that there are many arguments for that kind of function. Am I doing something wrong? In the pininterrupt is the main, where do I go to insert it?

  • Hi Mark,

    You have changed the function signature of user_processApplicationMessage, this is likely colliding with the forward declaration of this function.

    Project zero will already open the PINs for the buttons, instead of using pinInterrupt, can you just use the PIN handles from the buttons and read the value of the buttons within this function.
  • Hi Sean, I implement the pininterrupt example in project-zero and it works. Now I should to associate the pression of button the passkey to send a GAPBondMgr_PasscodeRsp()
  • I passed my button value to the function, but now how should I set the GAP configuration? These are my pieces of code:

        uint32_t currVal = 0;

      uint32_t passkey = 0; // passkey "0000"
      uint8_t pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ;
      uint8_t mitm = TRUE;
      uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;
      uint8_t bonding = TRUE;
    
      GAPBondMgr_SetParameter(GAPBOND_DEFAULT_PASSCODE, sizeof(uint32_t),
                             &passkey);
      GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
      GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
      GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
      GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);
    static void  set_pass(PIN_Handle handle, PIN_Id pinId) {
        //uint32_t currVal = 0;
        CPUdelay(8000*50);
            if (!PIN_getInputValue(pinId)) {
                /* Toggle LED based on the button pressed */
                switch (pinId) {
                case Board_PIN_BUTTON0:
                        currVal =  PIN_getOutputValue(Board_PIN_BUTTON0);
                        break;
    
                    default:
                        /* Do nothing */
                        break;
                }
            }
         }
        case APP_MSG_SEND_PASSCODE: /* Message about pairing PIN request */
          {
            passcode_req_t *pReq = (passcode_req_t *)pMsg->pdu;
            Log_info2("BondMgr Requested passcode. We are %s passcode %06d",
                      (IArg)(pReq->uiInputs?"Sending":"Displaying"),
                      currVal);
            // Send passcode response.
            GAPBondMgr_PasscodeRsp(pReq->connHandle, SUCCESS, currVal);
          }
          break;

  • Mark,

    Read pin Y/N into variable, inside of APP_MSG_SEND_PASSCODE call GAPBondMgr_PasscodeRsp with this variable as SUCCESS or FAILURE.
  • I did not understand, how can I do this?
  • Hi Sean, the configuration of IOCap is correct? In this moment I have this code on APP_MSG_SEND_PASSCODE:

    case APP_MSG_SEND_PASSCODE: /* Message about pairing PIN request */
    {
    passcode_req_t *pReq = (passcode_req_t *)pMsg->pdu;
    Log_info2("BondMgr Requested passcode. We are %s passcode %06d",
    (IArg)(pReq->uiInputs?"Sending":"Displaying"),
    currVal);
    currVal =! SUCCESS;
    // Send passcode response.
    GAPBondMgr_PasscodeRsp(pReq->connHandle, SUCCESS, currVal);
    }
    break;
  • Hi Mark,

    I added some pseudocode in the comments here.

    case APP_MSG_SEND_PASSCODE: /* Message about pairing PIN request */
    {
    passcode_req_t *pReq = (passcode_req_t *)pMsg->pdu;
    Log_info2("BondMgr Requested passcode. We are %s passcode %06d",
    (IArg)(pReq->uiInputs?"Sending":"Displaying"),
    currVal);
    currVal =! SUCCESS;
    // Send passcode response.
    
    // HERE call myVAR = PIN_getInputValue(PINID);
    // Debounce if you want 
    // if myVAR set SUCCESS or FAILURE in GAPBondMgr_PasscodeRsp
    GAPBondMgr_PasscodeRsp(pReq->connHandle, SUCCESS, currVal);
    }
    break;

    Regarding IO caps these are set in the init function of the ProjectZero task in the
    GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES,...) API call. You can modify them there.

  • How can I make this passage // if myVAR set SUCCESS or FAILURE in GAPBondMgr_PasscodeRsp ? I did not get it
  • I resolve my problem for the security! Thanks of all!