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

SDK13 BDS error in bds_uint8_array_decode?

Hello,

I am just using the SDK13 on the nRF52832 together with the experimental BDS example (I modified it to the point where it seems to be working fine so far).

Now when using uint8-array as data-type for a writeable characteristic, the mcu always performed a reset.

As far as I've found, the function bds_uint8_array_decode performs a memcpy to p_decoded_val->p_data, which is a null-pointer at the time being called.

The the utf8-string decode function bds_ble_srv_utf8_str_decode just performs a simple p_decoded_val->p_str = (uint8_t*)p_encoded_data; which looks perfectly fine to me (and works as expected).

Just doing this in the bds_uint8_array_decode function works fine as well.

So my real question: Is this an error in bds_uint8_array_decode or made like this on purpose? Are there other (better) solutions to this, which should be used?

Thanks for your help Marco

  • FormerMember
    0 FormerMember

    Did you first generate the file in Bluetooth developer studio, and then included it in the Keil project?

  • Yes, I generated the files and included it into the Makefile project (I'm not using Keil).

  • I can confirm a that replacing BDS generated code call to bds_uint8_array_decode with bds_ble_srv_utf8_str_decode fixes my problems too (service name obfuscated with xxx, characteristic containing uint8 array obfuscated with yyy):

    /**@brief yyy structure. */
    typedef struct
    {
        uint8_array_t thearray;
    } ble_laerdal_xxx_service_yyy_t;
    
    /**@brief xxx Service event. */
    typedef struct
    {
        ble_xxx_service_evt_type_t evt_type;    /**< Type of event. */
        union {
            uint16_t cccd_value; /**< Holds decoded data in Notify and Indicate event handler. */
            ble_xxx_service_yyy_t yyy; /**< Holds decoded data in Write event handler. */
        } params;
    } ble_xxx_service_evt_t;
    
    /**@brief Function for handling the Write event.
     *
     * @param[in]   p_xxx_service       xxx Service structure.
     * @param[in]   p_ble_evt   Event received from the BLE stack.
     */
    static void on_write(ble_xxx_service_t * p_xxx_service, ble_gatts_evt_write_t * p_ble_evt)
    {
        if(p_ble_evt->handle == p_xxx_service->yyy_handles.value_handle)
        {
            if(p_xxx_service->evt_handler != NULL)
            {
                ble_xxx_service_evt_t evt;
                evt.evt_type = BLE_XXX_SERVICE_YYY_EVT_WRITE;
                xxx_decode(p_ble_evt->len, p_ble_evt->data, &evt.params.yyy); //<--- note &evt.params.yyy undefined at this point !!!!!
                p_xxx_service->evt_handler(p_xxx_service, &evt);
            }
        }
        // other characteristics commented out .....
    }
    
     /**@brief Function for decoding xxx.
     *
     * @param[in]   data_len              Length of the field to be decoded.
     * @param[in]   p_data                Buffer where the encoded data is stored.
     * @param[out]  p_write_val           Decoded data.
     *
     * @return      Length of the decoded field.
     */
    static uint8_t xxx_decode(uint8_t data_len, uint8_t * p_data, ble_xxx_service_yyy_t * p_write_val)
    {
        /* Generated code replaced with code below, due to bug in Nordic SDK 13 bug in bds_uint8_array_decode,
           which memcpy to undefined pointer. Ref. devzone.nordicsemi.com/.../
        uint8_t pos = 0;
        pos += bds_uint8_array_decode((data_len-pos), &p_data[pos], &p_write_val->my_uint8_array);
        return pos;
         */
        uint8_t pos = 0;
        pos += bds_ble_srv_utf8_str_decode((data_len-pos), &p_data[pos], (ble_srv_utf8_str_t *)&p_write_val->my_uint8_array);
        return pos;
    }
    

    See also test_uint8_array.zip

  • Looks like the issue is present in SDK 14 too

  • Hi,

    I assume that it’s the auto-generated code that is actually using this bds_uint8_array_decode() function instead of the bds_ble_srv_utf8_str_decode() function ? So any bugs regarding this issue, is in the plugin that was written for SDK 11.

Related