This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Implement Static Passkey with SDK12.2.0

Hi, I want to use iOS to connect nRF82832 with passkey when connecting. I use pca10040_s132 with SDK 12.2.0.

Following is my procedure:

  1. define security parameters:

    #define SEC_PARAM_BOND 0 #define SEC_PARAM_MITM 1 #define SEC_PARAM_LESC 0 #define SEC_PARAM_KEYPRESS 0 #define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_DISPLAY_ONLY #define SEC_PARAM_OOB 0

  2. define passkey and set it:

// this is global variables
  #define STATIC_PASSKEY    "123456" 
  static ble_opt_t    m_static_pin_option;
  uint8_t passkey[] = STATIC_PASSKEY; 

// set passkey in gap_params_init()
    m_static_pin_option.gap_opt.passkey.p_passkey = &passkey[0]; 
    err_code =  sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &m_static_pin_option); 
   APP_ERROR_CHECK(err_code);
  1. send pairing request and implemet pairing procedure
 // add those cases in on_ble_evt()
      
    case BLE_GAP_EVT_CONNECTED:
        ble_gap_sec_params_t params;
        params.bond = 0;
        params.mitm = 1;
        sd_ble_gap_authenticate(m_conn_handle,&params);
       break;

   case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
       // printf("receive pair request\n");
       // resp_pair_request();
       ble_gap_sec_params_t sec_params;
       uint32_t  err_code;

      sec_param.bond           = SEC_PARAM_BOND;
      sec_param.mitm           = SEC_PARAM_MITM;
      sec_param.io_caps        = SEC_PARAM_IO_CAPABILITIES;
      sec_param.oob            = SEC_PARAM_OOB;
      sec_param.min_key_size   = SEC_PARAM_MIN_KEY_SIZE;
      sec_param.max_key_size   = SEC_PARAM_MAX_KEY_SIZE;
      sec_param.kdist_own.enc  = 1;
      sec_param.kdist_own.id   = 1;
      sec_param.kdist_peer.enc = 1;
      sec_param.kdist_peer.id  = 1;

     err_code=sd_ble_gap_sec_params_reply(m_conn_handle,BLE_GAP_SEC_STATUS_SUCCESS,&sec_param,NULL);
     APP_ERROR_CHECK(err_code);
    break;

   case BLE_GAP_EVT_AUTH_STATUS:
          if(p_ble_evt->evt.gap_evt.params.auth_status.auth_status == BLE_GAP_SEC_STATUS_SUCCESS)
          {
            //printf("pair success\r\n");
               //  int s=0;
                // s++;
          }
          else
          {
            sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
          }
          
        break;

Conclusion: When I use iOS and start connect, the pairing message shows sucessfully and I then enter the passkey "123456". But it fails after senconds with alert:"Timeout interrogating the peripheral". Actually I find "printf("pair success\r\n");" arrives with debugging. So It should be connected. I donnot know why it comes this error. Is there something wrong with my configuration? Is peer_manager_init() important? I comment this function as I donnot need bond. Thanks a lot!

Parents
  • Hi Longycy,

    I suspect the bond deleting was not executed properly. Note that deleting doesn't happen at the same time when you see the debug text. It happens after that when the softdevice schedule the flash operation.

    I suspect that the program crashed right after that and reset. Please set optimization level to 0 and add DEBUG into C/C++ preprocessor symbols and add a break point inside app_error_handler() in app_error.c to check if there is any assertion.

    Also make sure you do a full erase of flash before you try to test.

    You can also add a break point inside im_ble_evt_handler() in id_manager.c to check if the address matched is actually correct or not.

    Also please send me the full UART log you have when testing.

Reply
  • Hi Longycy,

    I suspect the bond deleting was not executed properly. Note that deleting doesn't happen at the same time when you see the debug text. It happens after that when the softdevice schedule the flash operation.

    I suspect that the program crashed right after that and reset. Please set optimization level to 0 and add DEBUG into C/C++ preprocessor symbols and add a break point inside app_error_handler() in app_error.c to check if there is any assertion.

    Also make sure you do a full erase of flash before you try to test.

    You can also add a break point inside im_ble_evt_handler() in id_manager.c to check if the address matched is actually correct or not.

    Also please send me the full UART log you have when testing.

Children
No Data
Related