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

  • " 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.

  • 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.

  • OK, that helped clarify what you were asking for thanks Slight smile

    here is the log output

    <error> app: ASSERTION FAILED at C:\SVN\trunk\FW\Nordic\SDK_V15_3_0\external\freertos\source\tasks.c:3066

    <error> hardfault: HARD FAULT at 0x000278D8

    <error> hardfault:   R0:  0x00000000  R1:  0x00000001  R2:  0x00000000  R3:  0x01010001

    <error> hardfault:   R12: 0x00000000  LR:  0x00026B0D  PSR: 0x21000000

    Here is the call stack:

  • also since this is the timing task effecting me, here is my config


    /*-----------------------------------------------------------
     * Possible configurations for system timer
     */
    #define FREERTOS_USE_RTC 0     /**< Use real time clock for the system */
    #define FREERTOS_USE_SYSTICK 1 /**< Use SysTick timer for system */

    /*-----------------------------------------------------------
     * Application specific definitions.
     *
     * These definitions should be adjusted for your particular hardware and
     * application requirements.
     *
     * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
     * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
     *
     * See www.freertos.org/a00110.html.
     *----------------------------------------------------------*/

    #define configTICK_SOURCE FREERTOS_USE_RTC

    #define configUSE_PREEMPTION 1
    #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
    #define configUSE_TICKLESS_IDLE 1
    #define configUSE_TICKLESS_IDLE_SIMPLE_DEBUG 1 /* See into vPortSuppressTicksAndSleep source code for explanation */
    #define configCPU_CLOCK_HZ (SystemCoreClock)
    #define configTICK_RATE_HZ 1024
    #define configMAX_PRIORITIES (3)
    #define configMINIMAL_STACK_SIZE (60)
    #define configTOTAL_HEAP_SIZE (10240)
    #define configMAX_TASK_NAME_LEN (4)
    #define configUSE_16_BIT_TICKS 0
    #define configIDLE_SHOULD_YIELD 1
    #define configUSE_MUTEXES 1
    #define configUSE_RECURSIVE_MUTEXES 1
    #define configUSE_COUNTING_SEMAPHORES 1
    #define configUSE_ALTERNATIVE_API 0 /* Deprecated! */
    #define configQUEUE_REGISTRY_SIZE 2
    #define configUSE_QUEUE_SETS 0
    #define configUSE_TIME_SLICING 0
    #define configUSE_NEWLIB_REENTRANT 0
    #define configENABLE_BACKWARD_COMPATIBILITY 1

    /* Hook function related definitions. */
    #define configUSE_IDLE_HOOK 1
    #define configUSE_TICK_HOOK 0
    #define configCHECK_FOR_STACK_OVERFLOW 0
    #define configUSE_MALLOC_FAILED_HOOK 0

    /* Run time and task stats gathering related definitions. */
    #define configGENERATE_RUN_TIME_STATS 0
    #define configUSE_TRACE_FACILITY 0
    #define configUSE_STATS_FORMATTING_FUNCTIONS 0

    /* Co-routine definitions. */
    #define configUSE_CO_ROUTINES 0
    #define configMAX_CO_ROUTINE_PRIORITIES (2)

    /* Software timer definitions. */
    #define configUSE_TIMERS 1
    #define configTIMER_TASK_PRIORITY (2)
    #define configTIMER_QUEUE_LENGTH 32
    #define configTIMER_TASK_STACK_DEPTH (80)

    /* Tickless Idle configuration. */
    #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2

    /* Tickless idle/low power functionality. */

    /* Define to trap errors during development. */
    #if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER)
    #define configASSERT(x) ASSERT(x)
    #endif

    /* FreeRTOS MPU specific definitions. */
    #define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 1

    /* Optional functions - most linkers will remove unused functions anyway. */
    #define INCLUDE_vTaskPrioritySet 1
    #define INCLUDE_uxTaskPriorityGet 1
    #define INCLUDE_vTaskDelete 1
    #define INCLUDE_vTaskSuspend 1
    #define INCLUDE_xResumeFromISR 1
    #define INCLUDE_vTaskDelayUntil 1
    #define INCLUDE_vTaskDelay 1
    #define INCLUDE_xTaskGetSchedulerState 1
    #define INCLUDE_xTaskGetCurrentTaskHandle 1
    #define INCLUDE_uxTaskGetStackHighWaterMark 1
    #define INCLUDE_xTaskGetIdleTaskHandle 1
    #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
    #define INCLUDE_pcTaskGetTaskName 1
    #define INCLUDE_eTaskGetState 1
    #define INCLUDE_xEventGroupSetBitFromISR 1
    #define INCLUDE_xTimerPendFunctionCall 1

    /* The lowest interrupt priority that can be used in a call to a "set priority"
    function. */
    #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf

    /* The highest interrupt priority that can be used by any interrupt service
    routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
    INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
    PRIORITY THAN THIS! (higher priorities are lower numeric values. */
    #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY _PRIO_APP_HIGH

    /* Interrupt priorities used by the kernel port layer itself.  These are generic
    to all Cortex-M ports, and do not rely on any particular library functions. */
    #define configKERNEL_INTERRUPT_PRIORITY configLIBRARY_LOWEST_INTERRUPT_PRIORITY
    /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
    See www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
    #define configMAX_SYSCALL_INTERRUPT_PRIORITY configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY

    /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
    standard names - or at least those used in the unmodified vector table. */

    #define vPortSVCHandler SVC_Handler
    #define xPortPendSVHandler PendSV_Handler

    /*-----------------------------------------------------------
     * Settings that are generated automatically
     * basing on the settings above
     */
    #if (configTICK_SOURCE == FREERTOS_USE_SYSTICK)
    // do not define configSYSTICK_CLOCK_HZ for SysTick to be configured automatically
    // to CPU clock source
    #define xPortSysTickHandler SysTick_Handler
    #elif (configTICK_SOURCE == FREERTOS_USE_RTC)
    #define configSYSTICK_CLOCK_HZ (32768UL)
    #define xPortSysTickHandler RTC1_IRQHandler
    #else
    #error Unsupported configTICK_SOURCE value
    #endif

    /* Code below should be only used by the compiler, and not the assembler. */
    #if !(defined(__ASSEMBLY__) || defined(__ASSEMBLER__))
    #include "nrf.h"
    #include "nrf_assert.h"

    /* This part of definitions may be problematic in assembly - it uses definitions from files that are not assembly compatible. */
    /* Cortex-M specific definitions. */
    #ifdef __NVIC_PRIO_BITS
    /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
    #define configPRIO_BITS __NVIC_PRIO_BITS
    #else
    #error "This port requires __NVIC_PRIO_BITS to be defined"
    #endif

    /* Access to current system core clock is required only if we are ticking the system by systimer */
    #if (configTICK_SOURCE == FREERTOS_USE_SYSTICK)
    #include <stdint.h>
    extern uint32_t SystemCoreClock;
    #endif
    #endif /* !assembler */

    /** Implementation note:  Use this with caution and set this to 1 ONLY for debugging
     * ----------------------------------------------------------
         * Set the value of configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG to below for enabling or disabling RTOS tick auto correction:
         * 0. This is default. If the RTC tick interrupt is masked for more than 1 tick by higher priority interrupts, then most likely
         *    one or more RTC ticks are lost. The tick interrupt inside RTOS will detect this and make a correction needed. This is needed
         *    for the RTOS internal timers to be more accurate.
         * 1. The auto correction for RTOS tick is disabled even though few RTC tick interrupts were lost. This feature is desirable when debugging
         *    the RTOS application and stepping though the code. After stepping when the application is continued in debug mode, the auto-corrections of
         *    RTOS tick might cause asserts. Setting configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG to 1 will make RTC and RTOS go out of sync but could be
         *    convenient for debugging.
         */
    #define configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG 0

Reply
  • also since this is the timing task effecting me, here is my config


    /*-----------------------------------------------------------
     * Possible configurations for system timer
     */
    #define FREERTOS_USE_RTC 0     /**< Use real time clock for the system */
    #define FREERTOS_USE_SYSTICK 1 /**< Use SysTick timer for system */

    /*-----------------------------------------------------------
     * Application specific definitions.
     *
     * These definitions should be adjusted for your particular hardware and
     * application requirements.
     *
     * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
     * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
     *
     * See www.freertos.org/a00110.html.
     *----------------------------------------------------------*/

    #define configTICK_SOURCE FREERTOS_USE_RTC

    #define configUSE_PREEMPTION 1
    #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
    #define configUSE_TICKLESS_IDLE 1
    #define configUSE_TICKLESS_IDLE_SIMPLE_DEBUG 1 /* See into vPortSuppressTicksAndSleep source code for explanation */
    #define configCPU_CLOCK_HZ (SystemCoreClock)
    #define configTICK_RATE_HZ 1024
    #define configMAX_PRIORITIES (3)
    #define configMINIMAL_STACK_SIZE (60)
    #define configTOTAL_HEAP_SIZE (10240)
    #define configMAX_TASK_NAME_LEN (4)
    #define configUSE_16_BIT_TICKS 0
    #define configIDLE_SHOULD_YIELD 1
    #define configUSE_MUTEXES 1
    #define configUSE_RECURSIVE_MUTEXES 1
    #define configUSE_COUNTING_SEMAPHORES 1
    #define configUSE_ALTERNATIVE_API 0 /* Deprecated! */
    #define configQUEUE_REGISTRY_SIZE 2
    #define configUSE_QUEUE_SETS 0
    #define configUSE_TIME_SLICING 0
    #define configUSE_NEWLIB_REENTRANT 0
    #define configENABLE_BACKWARD_COMPATIBILITY 1

    /* Hook function related definitions. */
    #define configUSE_IDLE_HOOK 1
    #define configUSE_TICK_HOOK 0
    #define configCHECK_FOR_STACK_OVERFLOW 0
    #define configUSE_MALLOC_FAILED_HOOK 0

    /* Run time and task stats gathering related definitions. */
    #define configGENERATE_RUN_TIME_STATS 0
    #define configUSE_TRACE_FACILITY 0
    #define configUSE_STATS_FORMATTING_FUNCTIONS 0

    /* Co-routine definitions. */
    #define configUSE_CO_ROUTINES 0
    #define configMAX_CO_ROUTINE_PRIORITIES (2)

    /* Software timer definitions. */
    #define configUSE_TIMERS 1
    #define configTIMER_TASK_PRIORITY (2)
    #define configTIMER_QUEUE_LENGTH 32
    #define configTIMER_TASK_STACK_DEPTH (80)

    /* Tickless Idle configuration. */
    #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2

    /* Tickless idle/low power functionality. */

    /* Define to trap errors during development. */
    #if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER)
    #define configASSERT(x) ASSERT(x)
    #endif

    /* FreeRTOS MPU specific definitions. */
    #define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 1

    /* Optional functions - most linkers will remove unused functions anyway. */
    #define INCLUDE_vTaskPrioritySet 1
    #define INCLUDE_uxTaskPriorityGet 1
    #define INCLUDE_vTaskDelete 1
    #define INCLUDE_vTaskSuspend 1
    #define INCLUDE_xResumeFromISR 1
    #define INCLUDE_vTaskDelayUntil 1
    #define INCLUDE_vTaskDelay 1
    #define INCLUDE_xTaskGetSchedulerState 1
    #define INCLUDE_xTaskGetCurrentTaskHandle 1
    #define INCLUDE_uxTaskGetStackHighWaterMark 1
    #define INCLUDE_xTaskGetIdleTaskHandle 1
    #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
    #define INCLUDE_pcTaskGetTaskName 1
    #define INCLUDE_eTaskGetState 1
    #define INCLUDE_xEventGroupSetBitFromISR 1
    #define INCLUDE_xTimerPendFunctionCall 1

    /* The lowest interrupt priority that can be used in a call to a "set priority"
    function. */
    #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf

    /* The highest interrupt priority that can be used by any interrupt service
    routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
    INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
    PRIORITY THAN THIS! (higher priorities are lower numeric values. */
    #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY _PRIO_APP_HIGH

    /* Interrupt priorities used by the kernel port layer itself.  These are generic
    to all Cortex-M ports, and do not rely on any particular library functions. */
    #define configKERNEL_INTERRUPT_PRIORITY configLIBRARY_LOWEST_INTERRUPT_PRIORITY
    /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
    See www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
    #define configMAX_SYSCALL_INTERRUPT_PRIORITY configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY

    /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
    standard names - or at least those used in the unmodified vector table. */

    #define vPortSVCHandler SVC_Handler
    #define xPortPendSVHandler PendSV_Handler

    /*-----------------------------------------------------------
     * Settings that are generated automatically
     * basing on the settings above
     */
    #if (configTICK_SOURCE == FREERTOS_USE_SYSTICK)
    // do not define configSYSTICK_CLOCK_HZ for SysTick to be configured automatically
    // to CPU clock source
    #define xPortSysTickHandler SysTick_Handler
    #elif (configTICK_SOURCE == FREERTOS_USE_RTC)
    #define configSYSTICK_CLOCK_HZ (32768UL)
    #define xPortSysTickHandler RTC1_IRQHandler
    #else
    #error Unsupported configTICK_SOURCE value
    #endif

    /* Code below should be only used by the compiler, and not the assembler. */
    #if !(defined(__ASSEMBLY__) || defined(__ASSEMBLER__))
    #include "nrf.h"
    #include "nrf_assert.h"

    /* This part of definitions may be problematic in assembly - it uses definitions from files that are not assembly compatible. */
    /* Cortex-M specific definitions. */
    #ifdef __NVIC_PRIO_BITS
    /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
    #define configPRIO_BITS __NVIC_PRIO_BITS
    #else
    #error "This port requires __NVIC_PRIO_BITS to be defined"
    #endif

    /* Access to current system core clock is required only if we are ticking the system by systimer */
    #if (configTICK_SOURCE == FREERTOS_USE_SYSTICK)
    #include <stdint.h>
    extern uint32_t SystemCoreClock;
    #endif
    #endif /* !assembler */

    /** Implementation note:  Use this with caution and set this to 1 ONLY for debugging
     * ----------------------------------------------------------
         * Set the value of configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG to below for enabling or disabling RTOS tick auto correction:
         * 0. This is default. If the RTC tick interrupt is masked for more than 1 tick by higher priority interrupts, then most likely
         *    one or more RTC ticks are lost. The tick interrupt inside RTOS will detect this and make a correction needed. This is needed
         *    for the RTOS internal timers to be more accurate.
         * 1. The auto correction for RTOS tick is disabled even though few RTC tick interrupts were lost. This feature is desirable when debugging
         *    the RTOS application and stepping though the code. After stepping when the application is continued in debug mode, the auto-corrections of
         *    RTOS tick might cause asserts. Setting configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG to 1 will make RTC and RTOS go out of sync but could be
         *    convenient for debugging.
         */
    #define configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG 0

Children
No Data
Related