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

write with authorization is not working when VLOC_USER

I have some test code that uses VLOC_USER and when i write with authorization the data seems to get scrambled.

when i use 

 p_evt_write->data[0];

to get the data it is scrambled as well.

Does anyone have  write with authorization iworking with  VLOC_USER ?

thanks

Phil

  • Hi,

    When using BLE_GATTS_VLOC_USER, it's the application's responsibility to maintain a valid buffer through the lifetime of the attribute, since the stack will read and write directly to the memory using the pointer provided in the APIs. Generally, I would recommend using BLE_GATTS_VLOC_STACK .

    Where and how are you defining the attribute?

    Does it work with BLE_GATTS_VLOC_STACK   ?

  • The code works with VOC_USER

    the attached zip file can be unpacked in SDK15.0.0   examples->ble_peripheral

    right along siide of ble_app_template

    my question is   why does

             auth_write_params.params.write.p_data      = p_write_auth->request.write.data;//phil this works

    work and the following fail .  I think they should be pointing to the same place in memory.

             auth_write_params.params.write.p_data      = &authorization_data[0];//phil this fail

    thanks for your help

    ble_app_novel_bits_lightbulb.zip

  • Hi,

    Both p_evt_write and evt_rw_auth will be pointing to the same place in memory, since this is a union, but only one of them will have valid data placed at the correct memory locations. ble_gatts_evt_rw_authorize_request_t have a different layout than ble_gatts_evt_write_t. You are getting a BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST , not a BLE_GATTS_EVT_WRITE. So you will need to look for your data in p_write_auth->request.write.data[0] , not p_evt_write->data[0] (these data fields are not at the same memory location due to the different layout mentioned).

    Also, the code you attached is mixing authorization_test_data and authorization_data. Your auth_write_params is pointing to authorization_data, but you are placing the p_evt_write->data in the authorization_test_data. You should instead do something like this,

    Snippet:

             authorization_data [0]=p_write_auth->request.write.data[0];
             authorization_data [1]=p_write_auth->request.write.data[1];
             authorization_data [2]=p_write_auth->request.write.data[2];
             authorization_data [3]=p_write_auth->request.write.data[3];
             err_code = sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gap_evt.conn_handle,
                                                       &auth_write_params);

  • HI Sigurd,

    thank your for the email and the explanation on p_evt_write and evt_rw_auth .  I understand completely.

    some questions

    1 - if I get BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST  will I ever get  BLE_GATTS_EVT_WRITE?  in other words are they mutually exclusive?

    2. when I get   BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST because of an authorized write from a central  it comes before the characteristic value in the peripheral has been updated.  Is this correct ?

    3.  when I execute sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gap_evt.conn_handle,
                                                       &auth_write_params);

    auth_write_params.params.write.p_data has a pointer to the value that the softdevice is going to write into the characteristic which since I am using VLOC_USER is located in my application's ram space.

    is this correct?

    4.

    p_write_auth->request.write.data points to the data on the ble stack that the central has sent.  If I want I can look at this using p_write_auth->request.write.data[0] and if I think there is an error I could correct it by setting   auth_write_params.params.write.p_data = &replacement_data[0]

    is this correct ?

    I have summarized a number of thoughts on this topic and enclosed them below.  Any comments you have on what I wrote I would be very appreciative. 

    This is how I think write with authorization works.docx

    thanks

    Phil

  • I think I understand write with authorization pretty well so I am closing this ticket so you guys can focus more on my current problem with cts.

Related