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

If no use bonding and secure fuction may I just mask the pm_conn_secure in central device project

Hi I use nRF52832 and SDK13 and Central Device project. and my device has not bonding function so may I mask my central device pm_conn_secure call here is my part of code

#define SEC_PARAM_BOND  0//1
static void peer_manager_init(void)

{ ble_gap_sec_params_t sec_param; ret_code_t err_code;

err_code = pm_init();
APP_ERROR_CHECK(err_code);

memset(&sec_param, 0, sizeof(ble_gap_sec_params_t));

// Security parameters to be used for all security procedures.
sec_param.bond           = SEC_PARAM_BOND;
sec_param.mitm           = SEC_PARAM_MITM;
sec_param.lesc           = SEC_PARAM_LESC;
sec_param.keypress       = SEC_PARAM_KEYPRESS;
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  = 0;//1;
sec_param.kdist_own.id   = 0;//1;
sec_param.kdist_peer.enc = 0;//1;
sec_param.kdist_peer.id  = 0;//1;

err_code = pm_sec_params_set(&sec_param);
APP_ERROR_CHECK(err_code);

err_code = pm_register(pm_evt_handler);
APP_ERROR_CHECK(err_code);

}

static void hrs_c_evt_handler(ble_hrs_c_t * p_hrs_c, ble_hrs_c_evt_t * p_hrs_c_evt)

{ switch (p_hrs_c_evt->evt_type) { case BLE_HRS_C_EVT_DISCOVERY_COMPLETE: {
ret_code_t err_code;

         err_code = ble_hrs_c_handles_assign(p_hrs_c,p_hrs_c_evt->conn_handle, &p_hrs_c_evt->params.peer_db);
         APP_ERROR_CHECK(err_code);
         // Initiate bonding.
         //err_code = pm_conn_secure( p_hrs_c_evt->conn_handle, false);
         //if (err_code != NRF_ERROR_INVALID_STATE)
         //{
         //    APP_ERROR_CHECK(err_code);
         //}
         // Heart rate service discovered. Enable notification of Heart Rate Measurement.
         err_code = ble_hrs_c_hrm_notif_enable(p_hrs_c);
         APP_ERROR_CHECK(err_code);
    } break; // BLE_HRS_C_EVT_DISCOVERY_COMPLETE

    case BLE_HRS_C_EVT_HRM_NOTIFICATION:
    {
        m_scr.m_hr.hr = p_hrs_c_evt->params.hrm.hr_value;
    } break; // BLE_HRS_C_EVT_HRM_NOTIFICATION

    default:
        break;
}

}

The reason is I just need scan the device and connect to it and there is no bonding and secure need.

May I delete the pm_conn_secure function call.

Thanks

  • @Vincent: If you want to reject bonding , you can set SEC_PARAM_BOND = 0 .

    If you want to reject both bonding and pairing, try to call pm_sec_params_set(NULL). Peer manager then will reject any encryption request. Please have a look atht the documentation of the function.

  • Ok, I got it and I will check the document. and If I set pm_sec_params_set(NULL) the pm_conn_secure( p_hrs_c_evt->conn_handle, false); still need keep it or I can mask this function call. I ask that because I do my device save or delete in fs_init() and fs_erase ..... flash read/write datas. and the Document says: Until this function is called, all bonding procedures that are initiated by the peer are rejected. If I dont need those two bonding and pairing may I just delete whole Peer Manager functions call.

    Thanks

  • No, if you don't plan to do any encryption, you shouldn't call pm_conn_secure(). If you don't plan to do encryption at all (not turn off and on when you need) You can get rid of peer manager. But then you have to handle some BLE events manually. Please have a look at ble_app_uart to see how it's done. (check on_ble_evt() )

  • Hi, I follow the ble_app_uart and I add these 3 handle

    case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
        case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST:
        case BLE_GATTS_EVT_SYS_ATTR_MISSING:
    

    and remove the Peer Manager whole function. Now I test My central part connect to device works fine and peripheral part add 3 handle into on_ble_peripheral_evt and cell phone connect to my device works fine.

    Thanks

Related