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 Hung Bui,

    I use Microchip RN4020 (Core 4.1) as central to test nRF52832. Following your advice, I tried again to debug gls example. The conclusion can be described as below:

    Firstly, I configure RN4020 without MITM. When connecting, I find UART print "Collector did not use MITM, disconnecting" and "Collector's bond deleted". That is right and it proves bond information has been erased.

    Secondly, I re-configure RN4020 with MIMT.At this time, UART print "Connected to a previously bonded device." and then "connected". This is very strange as bond information has been erased before.

    So why? I guess maybe bond information has not been erased correctly even though "pm_peer_delete(m_peer_to_be_deleted);" is excuted and return SUCCESS. Whether function "pm_peer_delete(...)" can be excuted correctly or not?

    Thank you very much!

    Best Regards

Reply
  • Hi Hung Bui,

    I use Microchip RN4020 (Core 4.1) as central to test nRF52832. Following your advice, I tried again to debug gls example. The conclusion can be described as below:

    Firstly, I configure RN4020 without MITM. When connecting, I find UART print "Collector did not use MITM, disconnecting" and "Collector's bond deleted". That is right and it proves bond information has been erased.

    Secondly, I re-configure RN4020 with MIMT.At this time, UART print "Connected to a previously bonded device." and then "connected". This is very strange as bond information has been erased before.

    So why? I guess maybe bond information has not been erased correctly even though "pm_peer_delete(m_peer_to_be_deleted);" is excuted and return SUCCESS. Whether function "pm_peer_delete(...)" can be excuted correctly or not?

    Thank you very much!

    Best Regards

Children
No Data
Related