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

how to transmitt encryption data with nRF51 SDK9 hrm example?

I just want to understand concept. For example, I need transmit battery level, heart rate level and other.. in closed (encrypted characteristic). I use S130 nRF51 SDK9. HRS example. If I run this example, on my smartfone I can see all of this data. But data not crypted. I use s130 in advertise mode.

I need underastand concept what I sould do to crypted it? Is it necessary add to

static void gap_params_init(void) ()

uint8_t passkey[] = "123456";

ble_opt_t static_pin_option;
static_pin_option.gap_opt.passkey.p_passkey = passkey;
err_code = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &static_pin_option);
APP_ERROR_CHECK(err_code);

Or I need add another fields more? With those added lines, I don't see crypted data on smartfone. Why?

  • Hi Mikhail,

    Do did you check if the data was encrypted or not ?

    The easiest way is to encrypt data is to pair/bond your phone with the device. After pairing/bonding, the communication between the phone and the device is encrypted with AES128.

    The passkey configuration is part of the pairing process when you want to have MITM protection.

    But you need to start pairing first. Please try to test with our proximity example where bonding is required to read a characteristic.

    I would suggest you to have a look at a BLE book to have a rough overview of how BLE security works for example "Bluetooth Low Energy: The Developer's Handbook" , "Getting Started with Bluetooth Low Energy: Tools and Techniques for Low-Power Networking" or have a look here.

  • Thanks for answer. With only code like in 1-st post

    static void gap_params_init(void) ()
    

    I don't have encrypted dsta. Any data of charactericstic I can see without encryption. But if I add in characteristic property encription, I can't see data in that characteristic.

  • @Mikhail: please give more information on how you test it. What you meant by "see" and "can't see" ? which tool did you use ? Which central device?

  • Thanks for answer. I use HRS example on nRF51 and I want to understand about encryption. How to do it. So, on nRF51 I run HRS example in advertise mode. On central (smartfone application nRF connect) I can see data. Battery level for example. When on HRS project I add into

    static void gap_params_init(void) ()
    

    code like on 1st post, on the smartfone I can see all my data without any encryption. For ex, I can see battery level. What I should do for crypted this data? For crypted battery level for ex? I suppose, I need add in

    static void services_init(void)
        BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&bas_init.battery_level_char_attr_md.cccd_write_perm); 
    BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&bas_init.battery_level_char_attr_md.read_perm); 
    BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&bas_init.battery_level_char_attr_md.write_perm);
    
    BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&bas_init.battery_level_report_read_perm);
    

    instead of

    	BLE_GAP_CONN_SEC_MODE_SET_OPEN(&bas_init.battery_level_char_attr_md.cccd_write_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&bas_init.battery_level_char_attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&bas_init.battery_level_char_attr_md.write_perm);
    
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&bas_init.battery_level_report_read_perm);
    

    Is it correct? If I want to crypted one of charecteristic? Or is there method to cripted all data?

  • If you set BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM() to the characteristic, encryption will be required when the central want to read your data. And then you will get a popup on the phone to ask for pairing.

    After you pair, the link will be encrypted. But note that, the application will still show the normal data value when you read the characteristic, just because the encryption happens on lower layer and it's transparent to the application.

Related