Need to disable pairing with Windows 10

Greetings,

I've searched the forum, but haven't found a particular answer. I need to configure the project to not pair with Windows 10 PC because it blocks other software that needs to send commands to the device. This is critical. Tried to pair it with Android, but it rejects the pairing. Where can I disable this pairing?

The project is based on a merged hex from:

  1. secure_bootloader_ble_s132_pca10040.hex
  2. s132_nrf52_7.2.0_softdevice.hex
  3. dfu (ble_app_uart_pca10040_s132.hex)
Parents Reply
  • Tried to pair it with Android, but it rejects the pairing.

    This may indicate the problem is not really the Windows PC, but that the device is advertising with whitelist, and will then only connect to a previous bonded device. Maybe use the restart advertisement without whitelist api, this will allow connection with new peer device. The HID examples show this.

    But as mentioned, if you don't change the gap address and you already have a central device in the area with a bonded relationship, the central device (even if it's not Windows) will try to connect.

    Kenneth

Children
  • I will check this. BTW, is it possible to add password before pairing a device?

  • The HID keyboard example should support passkey.

    Kenneth

  • Ok, I started with that example. So far, I tweaked the peer_manager_init function. This seems to disable access Windows 10 connecting with the devkit, but connect with the phone, which is what I need. Now I want to integrate that function in my project and add peer_manager.c with its' dependencies. I'm stuck on that part with Segger. How do I add that with the dependencies? I have peer_manager.c in the components folder of the project.

  • Update:

    I have implemented a timeout after 13 seconds, so it disconnects a device if it is connected longer than 13 seconds. The issue is when it is paired with Windows 10, it blocks the timer somehow and it can't disconnect. Any suggestions?

    **@brief Function for handling BLE events.
     *
     * @param[in]   p_ble_evt   Bluetooth stack event.
     * @param[in]   p_context   Unused.
     */
    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        uint32_t err_code;
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_CONNECTED:
                uart_init();
                NRF_LOG_INFO("Connected");
                //err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
                //APP_ERROR_CHECK(err_code);
                m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
                err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
                APP_ERROR_CHECK(err_code);
                // Start the inactivity timer
                err_code = app_timer_start(m_inactivity_timer_id, APP_TIMER_TICKS(13000), NULL);
                APP_ERROR_CHECK(err_code);
                break;
    
            case BLE_GAP_EVT_DISCONNECTED:
                // Stop the inactivity timer
                err_code = app_timer_stop(m_inactivity_timer_id);
                APP_ERROR_CHECK(err_code);
                // Wait for UART to finish
                while(app_uart_tx_done());
                app_uart_close();
                NRF_LOG_INFO("Disconnected");
                // LED indication will be changed when advertising starts.
                m_conn_handle = BLE_CONN_HANDLE_INVALID;
                break;
    
            case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
            {
                NRF_LOG_DEBUG("PHY update request.");
                ble_gap_phys_t const phys =
                {
                    .rx_phys = BLE_GAP_PHY_AUTO,
                    .tx_phys = BLE_GAP_PHY_AUTO,
                };
                err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
                APP_ERROR_CHECK(err_code);
            } break;
    
            case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
                // Pairing not supported
                err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
                APP_ERROR_CHECK(err_code);
                break;
    
            case BLE_GATTS_EVT_SYS_ATTR_MISSING:
                // No system attributes have been stored.
                err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
                APP_ERROR_CHECK(err_code);
                break;
    
            case BLE_GATTC_EVT_TIMEOUT:
                // Stop the inactivity timer
                err_code = app_timer_stop(m_inactivity_timer_id);
                APP_ERROR_CHECK(err_code);
                // Disconnect on GATT Client timeout event.
                err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
                                                 BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                APP_ERROR_CHECK(err_code);
                break;
    
            case BLE_GATTS_EVT_TIMEOUT:
                // Stop the inactivity timer
                err_code = app_timer_stop(m_inactivity_timer_id);
                APP_ERROR_CHECK(err_code);
                // Disconnect on GATT Server timeout event.
                err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle,
                                                 BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                APP_ERROR_CHECK(err_code);
                break;
    
            default:
                // No implementation needed.
                break;
        }
    }

  • Ok, so it seems I fixed it somehow. I had issues with importing files in the SEGGER Embedded Studio with dependencies. It seems that if you don't include the headers that are connected to peer_manager.c (or other files that you might use) in the main.c file, it won't show the dependencies as imported. Also clean & build seems to fix it. Had to manually adjust some things in the component folder due to issues with the sdk_config file, mainly in the IF part because the sdk_config didn't have those definitions to enable/disable them. I imported the peer manager and added the following code, which blocks peering with PC Windows 10 devices.

    // PASSKEY
    #define PASSKEY_TXT                     "Passkey:"                                  /**< Message to be displayed together with the pass-key. */
    #define PASSKEY_TXT_LENGTH              8                                           /**< Length of message to be displayed together with the pass-key. */
    #define PASSKEY_LENGTH                  6                                           /**< Length of pass-key received by the stack for display. */
    
    #define SEC_PARAM_BOND                  1                                           /**< Perform bonding. */
    #define SEC_PARAM_MITM                  1                                           /**< Man In The Middle protection required (applicable when display module is detected). */
    #define SEC_PARAM_LESC                  1                                           /**< LE Secure Connections enabled. */
    #define SEC_PARAM_KEYPRESS              0                                           /**< Keypress notifications not enabled. */
    #define SEC_PARAM_IO_CAPABILITIES       BLE_GAP_IO_CAPS_DISPLAY_ONLY                /**< Display I/O capabilities. */
    #define SEC_PARAM_OOB                   0                                           /**< Out Of Band data not available. */
    #define SEC_PARAM_MIN_KEY_SIZE          7                                           /**< Minimum encryption key size. */
    #define SEC_PARAM_MAX_KEY_SIZE          16                                          /**< Maximum encryption key size. */

    /**@brief Function for the Peer Manager initialization.
     */
    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  = 1;
        sec_param.kdist_own.id   = 1;
        sec_param.kdist_peer.enc = 1;
        sec_param.kdist_peer.id  = 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);
    }

Related