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

Accept or reject bluetooth connection

Hello everyone, the sdk version that I use is 15.0 (nrF5_SDK_15.0.0). The soft device is s132.

I need to make an android custom app (with UART functionality) so that only users with passkey can access. Where do I have to modify? in the Android app or in the nRF52 module.

Why I can not connect the UART sample (inside the nRF Toolbox Android app) with the example of ble_peripheral / ble_app_hrs?

How does the Android app know that the request comes from one nRF52 example or another?
Where is acceptance made? In the app or in the module?

Thanks

Parents
  • Hi.

    If you want to use a passkey, you can look at the Glucose Application Example. This example secures bond by using Man-in-the-Middle protection (MITM).

    You modify this in the project you compile to the .hex file you program your nRF52 device with.

    I have just tested this on the ble_peripheral\ble_app_hrs example, and i did the following:

    Add the following in the header in main.c:

    #define SEC_PARAM_BOND 1 /**< Perform bonding. */
    
    #define SEC_PARAM_MITM 1 /**< Man In The Middle protection required. */
    
    #define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_DISPLAY_ONLY
    
    #define SEC_PARAM_OOB 0
    
    #define SEC_PARAM_MIN_KEY_SIZE 7
    
    #define SEC_PARAM_MAX_KEY_SIZE 16
    
    #define PASSKEY_TXT "Passkey:"
    
    #define PASSKEY_TXT_LENGTH 8
    
    #define PASSKEY_LENGTH 6
    
    #define STATIC_PASSKEY "123456"
    
    static ble_opt_t ble_opt;

    You can change your passkey by configuring STATIC_PASSKEY and PASSKEY_LENGTH

    Add the following in the function static void gap_params_init(void) in main.c:

    uint8_t passkey[] = STATIC_PASSKEY;
    
    BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&sec_mode);
    
    ble_opt.gap_opt.passkey.p_passkey = passkey;
    
    err_code = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &ble_opt);
    
    APP_ERROR_CHECK(err_code);

    You need to remove this from the same function:

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);

    Since this line of code sets the link open, as you can read here.

    Just compile and download. Open nRF Connect, and scan for devices.

    Connect to Nordic_HRM. Click then on the options buttion on the right side off Peripheral.

    Click on "Pair..", select Perform bonding, and click Pair.

    You should then get a new window where you type your passkey, like shown under:

    After you have clicked on Submit, the BLE link should now be bonded and encrypted as you see below:

    I'm not sure what you mean with your second question, have you used the right parameters for UART?

    You can find the UART example explained here, with setup and testing explained.

    Your last question:

    If you want to be sure that your devices pair and nobody eavesdrop the information, you have to use a security measurement such as a passkey, numeric comparison, OOB etc.

    Good luck.

    - Andreas

Reply
  • Hi.

    If you want to use a passkey, you can look at the Glucose Application Example. This example secures bond by using Man-in-the-Middle protection (MITM).

    You modify this in the project you compile to the .hex file you program your nRF52 device with.

    I have just tested this on the ble_peripheral\ble_app_hrs example, and i did the following:

    Add the following in the header in main.c:

    #define SEC_PARAM_BOND 1 /**< Perform bonding. */
    
    #define SEC_PARAM_MITM 1 /**< Man In The Middle protection required. */
    
    #define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_DISPLAY_ONLY
    
    #define SEC_PARAM_OOB 0
    
    #define SEC_PARAM_MIN_KEY_SIZE 7
    
    #define SEC_PARAM_MAX_KEY_SIZE 16
    
    #define PASSKEY_TXT "Passkey:"
    
    #define PASSKEY_TXT_LENGTH 8
    
    #define PASSKEY_LENGTH 6
    
    #define STATIC_PASSKEY "123456"
    
    static ble_opt_t ble_opt;

    You can change your passkey by configuring STATIC_PASSKEY and PASSKEY_LENGTH

    Add the following in the function static void gap_params_init(void) in main.c:

    uint8_t passkey[] = STATIC_PASSKEY;
    
    BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&sec_mode);
    
    ble_opt.gap_opt.passkey.p_passkey = passkey;
    
    err_code = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &ble_opt);
    
    APP_ERROR_CHECK(err_code);

    You need to remove this from the same function:

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);

    Since this line of code sets the link open, as you can read here.

    Just compile and download. Open nRF Connect, and scan for devices.

    Connect to Nordic_HRM. Click then on the options buttion on the right side off Peripheral.

    Click on "Pair..", select Perform bonding, and click Pair.

    You should then get a new window where you type your passkey, like shown under:

    After you have clicked on Submit, the BLE link should now be bonded and encrypted as you see below:

    I'm not sure what you mean with your second question, have you used the right parameters for UART?

    You can find the UART example explained here, with setup and testing explained.

    Your last question:

    If you want to be sure that your devices pair and nobody eavesdrop the information, you have to use a security measurement such as a passkey, numeric comparison, OOB etc.

    Good luck.

    - Andreas

Children
Related