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

Characteristic notify settings while using encryption on IOS or Android

Hi all,

During development I've run into issues setting up a functioning characteristic notification for IOS or Android. The notification works fine using the NRF Connect app however. 

The only way i can make the notify work correctly in either my projects app or free ios/android apps is to set the security to open for the connection and characteristics.

    ble_gap_conn_params_t gap_conn_params;
    ble_gap_conn_sec_mode_t sec_mode;

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);

In particular in the app writing to the CCCD to enable notifications caused my HW to Hardlock,  Removing all actual notifications being sent did not effect the behavior.

has anyone else run into this problem? 

Note: this is only an issue with notify, all other characteristic settings worked fine with encryption.

characteristic setup code below that has the issue:

   uint32_t err_code;
    ble_uuid_t char_uuid;
    ble_uuid128_t base_uuid = BLE_UUID_project_BASE_UUID;
    char_uuid.uuid = CharData->CharUUID;
    err_code = sd_ble_uuid_vs_add(&base_uuid, &char_uuid.type);
    Error_projectError(err_code, NULL);

    ble_gatts_char_md_t char_md;
    memset(&char_md, 0, sizeof(char_md));
    char_md.char_props.read = CharData->enableRead;
    char_md.char_props.write = CharData->enableWrite;
sq
    ble_gatts_attr_md_t attr_md;
    memset(&attr_md, 0, sizeof(attr_md));

    BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&attr_md.write_perm);
    attr_md.vlen = CharData->variableLen;
    attr_md.vloc = BLE_GATTS_VLOC_STACK;

    //for notify, must be set to open for read, otherwise the stack flags it as an issue
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
    char_md.p_cccd_md = &attr_md;
     char_md.char_props.notify = 1;

    ble_gatts_attr_t attr_char_value;
    memset(&attr_char_value, 0, sizeof(attr_char_value));
    attr_char_value.p_uuid = &char_uuid;
    attr_char_value.p_attr_md = &attr_md;

    attr_char_value.max_len = CharData->maxLen;
    attr_char_value.init_len = CharData->initLen;
    attr_char_value.p_value = CharData->pValue;

    err_code = sd_ble_gatts_characteristic_add(gprojectService.serviceHandle,
        &char_md,
        &attr_char_value,
        CharData->pCharHandles);

Parents
  • Hello,

    Note: this is only an issue with notify, all other characteristic settings worked fine with encryption. Also I'd love to know why i need to set the characteristic read permissions to open for notify, if I don't it crashes on init.

     Probably an APP_ERROR_CHECK(err_code) that receives an err_code != 0. I guess somewhere in your project you are trying to send a notification to a connection handle that hasn't enabled notifications, and it returns NRF_ERROR_INVALID_STATE. Try to define DEBUG in your preprocessor defines, and you should be able to see where your application crashes. 

    Try this, and see whether you can get any information on why the pairing is not working as well.

    Best regards,

    Edvin

Reply
  • Hello,

    Note: this is only an issue with notify, all other characteristic settings worked fine with encryption. Also I'd love to know why i need to set the characteristic read permissions to open for notify, if I don't it crashes on init.

     Probably an APP_ERROR_CHECK(err_code) that receives an err_code != 0. I guess somewhere in your project you are trying to send a notification to a connection handle that hasn't enabled notifications, and it returns NRF_ERROR_INVALID_STATE. Try to define DEBUG in your preprocessor defines, and you should be able to see where your application crashes. 

    Try this, and see whether you can get any information on why the pairing is not working as well.

    Best regards,

    Edvin

Children
  • " Probably an APP_ERROR_CHECK(err_code) that receives an err_code != 0. I guess somewhere in your project you are trying to send a notification to a connection handle that hasn't enabled notifications, and it returns NRF_ERROR_INVALID_STATE. Try to define DEBUG in your preprocessor defines, and you should be able to see where your application crashes. "

    I ran a test where i never once sent a notification and the issue still occurred when IOS/Android attempted to enable notifications so this is not the issue.

  • Did you try to define DEBUG in your preprocessor defines, and monitor your log output? 

     

    if I don't it crashes on init.

     Where does it crash? The "DEBUG" preprocessor define should point you to where the issue is.

  • I do not have any APP_ERROR_CHECKS or anything else that will hard lock my system on purpose when this occurs and yes I'm using a debug build optimization/debug configuration.

    Also i think the "if i don't it crashes on init" is just distracting the problem.  Please forget i mentioned it I'll remove it from the bug.  That actually doesn't matter much due to this one characteristic not needing to be guarded ... i just need to make sure I don't need to disable all security for all characteristics to fix the issue.

    I don't get any details as to why the system hard locks see below as to the screen shot.  it looks like the timer gets corrupted somehow when this occurs so i'm assuming there has been a stack overrun somewhere. And please remember this only occurs when using IOS/Android NRF connect works just fine.

    Is there an escalation path for help so we can talk over the phone etc?  I'm trying to make a commercial product using your chipset.

  • additional info:

    the fault id is:NRF_FAULT_ID_SDK_ASSERT

    p_file_name appears to be garbage, but the memory location is "AC EE 03 00"

    line number is "0xbfa"

  • nate said:
    I do not have any APP_ERROR_CHECKS or anything else that will hard lock my system on purpose when this occurs and yes I'm using a debug build optimization/debug configuration.

     Ok. So I see from your screenshot that you are using Segger Embedded Studio. Debug build is not quite what I meant by adding DEBUG to your preprocessor defines.

    Enter your project settings, Select Common:

    Then:

    As you see in the screenshot, go to preprocessor -> Preprocessor definitions -> and add a line saying "DEBUG".

    The reason for this is that the logger module will behave different when you have this define. It will, among other things, print out what file that is in the memory address AC EE 03 00. Try this.

Related