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

Authorised read failure [BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST]

Hello.

 I am using SDK 15.2 with softdevice version 6.1.0 and armgcc. My goal is to update the data in my characteristic just before it is being read by the phone application.

Problem is that sd_ble_gatts_rw_authorize_reply() function returns NRF_SUCCESS (here is a proof from RTTClient ):

but in the nRF Connect an error appears ...

... it causes that a value that I am trying to send is not visible in nRF Connect. I think it may just not be sent to the phone but I might be wrong.

Here is the code which results in the behaviour shown on above screens:

// Handle the BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event

static void on_read(ble_my_service_t * p_my_service, ble_evt_t const * p_ble_evt)
{
    uint32_t time = 0;
    ret_code_t err_code;
    ble_gatts_evt_rw_authorize_request_t  req = p_ble_evt->evt.gatts_evt.params.authorize_request;

    if(req.type == BLE_GATTS_AUTHORIZE_TYPE_READ){
        time = clock_get_time();
        NRF_LOG_INFO("Clock returned:%d",time);
        ble_gatts_rw_authorize_reply_params_t response;
        response.params.read.gatt_status = BLE_GATT_STATUS_SUCCESS;
        response.type = BLE_GATTS_AUTHORIZE_TYPE_READ;
        response.params.read.update = 1;
        response.params.read.offset = 0;
        response.params.read.len = 4;
        response.params.read.p_data = (uint8_t *) &time;

        response.params.write.gatt_status = (BLE_GATT_STATUS_ATTERR_APP_BEGIN + 2); // Feature not supported
        err_code=sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle, &response);
        APP_ERROR_CHECK(err_code);
        NRF_LOG_INFO("Reply function responded with: %d", err_code);
    }
}

And also my custom characteristic initialization code:

// Add characteristic
static uint32_t my_service_time_char_add(ble_my_service_t * p_ble_my_service)
{
    ble_gatts_char_md_t char_md;
    ble_gatts_attr_t    attr_char_value;
    ble_uuid_t          ble_uuid;
    ble_gatts_attr_md_t attr_md;

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

    char_md.char_props.read   = 1;
    char_md.char_props.write  = 1;
    char_md.char_props.notify = 0;
    char_md.p_char_user_desc  = NULL;
    char_md.p_char_pf         = NULL;
    char_md.p_user_desc_md    = NULL;
    char_md.p_cccd_md         = NULL;
    char_md.p_sccd_md         = NULL;

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

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    attr_md.vloc       = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth    = 1;
    attr_md.wr_auth    = 0;
    attr_md.vlen       = 0;
    attr_md.write_perm.sm = 1;      // Security Mode 1 Level 2: Encrypted link required, MITM protection not necessary.
    attr_md.write_perm.lv = 2;
    attr_md.read_perm.sm = 1;      // Security Mode 1 Level 1: Open link
    attr_md.read_perm.lv = 1;

    ble_uuid.type = p_ble_my_service->uuid_type;
    ble_uuid.uuid = my_service_TIME_CHAR_UUID;

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

    attr_char_value.p_uuid    = &ble_uuid;
    attr_char_value.p_attr_md = &attr_md;
    attr_char_value.init_len  = sizeof(uint8_t);
    attr_char_value.init_offs = 0;
    attr_char_value.max_len   = sizeof(uint8_t)*MY_SERVICE_TIME_MSG_SIZE;


    return sd_ble_gatts_characteristic_add(p_ble_my_service->service_handle, &char_md,
                                               &attr_char_value,
                                               &p_ble_my_service->time_handles);
}

I will be very grateful for help with this problem.

Greetings

Parents Reply Children
Related