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

Encoded time object record sent does not match what is received

Figure 1. Data encoded and sent (attached)

Figure 2. Screen shot of wrong Time data (attached)

Here is some code that seems to be correct, sending 10 bytes that look correct, but sniffer receiving it, shows otherwise.

The code is sending updates for a CTS Time Service, which should be 10 bytes, when I check the object before it is sent, it is 10 bytes. But sniffer shows more bytes, and is showing the handle 0x0d

As well as other stuff inserted into the time object. I am encoding the object but that did not help.

 

The code:

                len = cts_time_encode(&xtime, encoded_glm);

            hvx_len = len;

 

            ble_gatts_hvx_params_t hvx_params;

 

            memset(&hvx_params, 0, sizeof(hvx_params));

 

            hvx_params.handle = ctsserv_bas.current_time_handles.value_handle;

            hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;

            hvx_params.offset = 0; //was: gatts_value.offset;

            hvx_params.p_len  = &hvx_len; //was: &gatts_value.len;

            hvx_params.p_data = encoded_glm; //was: gatts_value.p_value;

 

            err_code = sd_ble_gatts_hvx(ctsserv_bas.conn_handle, &hvx_params);

 

//encoding call

static uint8_t cts_time_encode(const current_time_char_t * p_time, uint8_t * p_encoded_buffer)

{

    uint8_t len = 0;

 

    len += ble_date_time_encode(&p_time->exact_time_256.day_date_time.date_time, &p_encoded_buffer[len]);

    p_encoded_buffer[len++] = (uint8_t) 0; //day of week unknown

    p_encoded_buffer[len++] = (uint8_t) 0; //256ths of a second

    p_encoded_buffer[len++] = (uint8_t) 2; //adjustment reason: external time source

 

    return len;

}

  • We encoded before adding to database, which fixed most of the issue, but still have extra data, making a non-standard byte count for the time object:

    Figure 2a. (replaces Figure 2 above)

    revised code:

            //First encode, then save, then send
            len = cts_time_encode(&xtime, encoded_glm);
            //gatts_value.p_value = (uint8_t*)&xtime;
            gatts_value.p_value = (uint8_t*)encoded_glm;
            gatts_value.len = len;
            gatts_value.offset  = 0;

            // Update database. BLE_CONN_HANDLE_INVALID
            //NRF_LOG_INFO("ble_ctsserv_current_time_update: m_conn_handle: '%d'\r\n",m_conn_handle);
            ctsserv_bas.conn_handle = m_conn_handle;
            err_code = sd_ble_gatts_value_set(ctsserv_bas.conn_handle,
                    ctsserv_bas.current_time_handles.value_handle,
                                              &gatts_value);

                hvx_len = len;

                ble_gatts_hvx_params_t hvx_params;

                memset(&hvx_params, 0, sizeof(hvx_params));

                hvx_params.handle = ctsserv_bas.current_time_handles.value_handle;
                hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
                hvx_params.offset = 0; //was: gatts_value.offset;
                hvx_params.p_len  = &hvx_len; //was: &gatts_value.len;
                hvx_params.p_data = encoded_glm; //was: gatts_value.p_value;

                err_code = sd_ble_gatts_hvx(ctsserv_bas.conn_handle, &hvx_params);

  • A data channel packet consist of several fields:
    https://devzone.nordicsemi.com/f/nordic-q-a/9788/of-what-does-a-notification-package-consist-packet-structure 

    Typically the sniffer log will show more than the 10byte application payload.

    Best regards,
    Kenneth

     

Related