Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Apple Notification Center Service - hard coded max attribute length of 32?

nrf_ble_ancs_c.h has hardcoded max attribute length of 32 (BLE_ANCS_ATTR_DATA_MAX).

1) BLE_ANCS_ATTR_DATA_MAX mainly seems to be used to allocate the size of the app_id in ble_ancs_c_evt_t.  So maybe is misnamed?

2) BLE_ANCS_ATTR_DATA_MAX is also used for checking the the length passed to nrf_ble_ancs_c_attr_add.  But that doesn't seem to make sense because the buffers are passed in and can be of any size.  Is this a bug?  I want to be able to pass in a large buffer (say 100 bytes) for the message attribute so I can get more than 32 characters of the notification message attribute.

Parents
  • It also looks like the null termination on an attribute writes 1 past the buffer end in ancs_attr_parser.c:

        // We have reached the end of the attribute, or our max allocated internal size.
        // Stop copying data over to our buffer. NUL-terminate at the current index.
        if ( (p_ancs->parse_info.current_attr_index == p_ancs->evt.attr.attr_len) ||
             (p_ancs->parse_info.current_attr_index == p_ancs->parse_info.p_attr_list[p_ancs->evt.attr.attr_id].attr_len - 1))
        {
            if (attr_is_requested(p_ancs, p_ancs->evt.attr))
            {
                p_ancs->evt.attr.p_attr_data[p_ancs->parse_info.current_attr_index] = '\0';
            }
    
  • One other note:  It looks like in the example nrf_ble_ancs_c_attr_add is called before ble_ancs_c_init.  Seems like it would be safer for ble_ancs_c_init to initialize all the ancs_notif_attr_list values to get = false and then call nrf_ble_ancs_c_attr_add only on the attributes that you want to retrieve.  (As it is now if you comment out any of the nrf_ble_ancs_c_attr_add then you have undefined values, which leads to undefined behavior.)

Reply
  • One other note:  It looks like in the example nrf_ble_ancs_c_attr_add is called before ble_ancs_c_init.  Seems like it would be safer for ble_ancs_c_init to initialize all the ancs_notif_attr_list values to get = false and then call nrf_ble_ancs_c_attr_add only on the attributes that you want to retrieve.  (As it is now if you comment out any of the nrf_ble_ancs_c_attr_add then you have undefined values, which leads to undefined behavior.)

Children
Related