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

event form read request

Hi,

I'm using SDK 15.2 with Nrf52832,

I've implemented a custom service with read, write and notification services.

I would appreciate if you could send me an example of how to get an event of a read request, I understand that its part of the SodtDevice and I can get authorize read event - but it is not clear how...

Shimon

Parents
  • Hi Shimon, 

    Normal read requests are handled without application interaction. If you want to receive an event you need to enable authorization like you indicated (MSC). Below is a diff showing the changes needed to enable this in the ble_app_blinky_example.

    diff --git a/components/ble/ble_services/ble_lbs/ble_lbs.c b/components/ble/ble_services/ble_lbs/ble_lbs.c
    index 1c83a99..5324428 100644
    --- a/components/ble/ble_services/ble_lbs/ble_lbs.c
    +++ b/components/ble/ble_services/ble_lbs/ble_lbs.c
    @@ -60,6 +60,24 @@ static void on_write(ble_lbs_t * p_lbs, ble_evt_t const * p_ble_evt)
         }
     }
     
    +static void on_rw_authorize_request(ble_lbs_t * p_lbs, ble_evt_t const * p_ble_evt)
    +{
    +      ble_gatts_rw_authorize_reply_params_t        reply_params;
    +      ble_gatts_evt_rw_authorize_request_t const * p_evt_rw_auth = &p_ble_evt->evt.gatts_evt.params.authorize_request;
    +
    +      memset (&reply_params, 0, sizeof(ble_gatts_rw_authorize_reply_params_t));
    +
    +      if ( (p_evt_rw_auth->type == BLE_GATTS_AUTHORIZE_TYPE_READ) &&
    +           (p_lbs->button_char_handles.value_handle == p_evt_rw_auth->request.read.handle))
    +      {
    +          reply_params.type = BLE_GATTS_AUTHORIZE_TYPE_READ;
    +          reply_params.params.read.gatt_status = BLE_GATT_STATUS_SUCCESS;
    +
    +          (void) sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.common_evt.conn_handle, &reply_params);
    +          
    +      }
    +
    +}
     
     void ble_lbs_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
     {
    @@ -71,6 +89,10 @@ void ble_lbs_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
                 on_write(p_lbs, p_ble_evt);
                 break;
     
    +        case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
    +            on_rw_authorize_request(p_lbs, p_ble_evt);
    +            break;
    +
             default:
                 // No implementation needed.
                 break;
    @@ -106,6 +128,8 @@ uint32_t ble_lbs_init(ble_lbs_t * p_lbs, const ble_lbs_init_t * p_lbs_init)
         add_char_params.max_len           = sizeof(uint8_t);
         add_char_params.char_props.read   = 1;
         add_char_params.char_props.notify = 1;
    +    add_char_params.is_defered_read   = 1;
    +
     
         add_char_params.read_access       = SEC_OPEN;
         add_char_params.cccd_write_access = SEC_OPEN;
    
    

    If anything is unclear, let me know. 

    Vidar

  • Hi Shimon,

    I have a similar problem of getting an event for a read request. Searching for answer I ran into this post. I followed your recommendation above and modified my code based on the example you provided. Unfortunately, I didn't work out for me. As soon as I add this line:   add_char_params.is_defered_read   = 1;  the NRF_connect freezes for a few seconds and then gives me "Gatt timeout error". If I remove this line, everything works well, except I won't get any event for my read requests.  I was wondering if you have any comments.

    I really appreciate any help.

    Thanks,

    Reza

  • Hi Reza,

    Sorry for the late response 

    In the service init did you add:

    // Initialize CUS Service init structure to zero.
    cus_init.evt_handler = on_cus_evt;

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cus_init.custom_value_char_attr_md.cccd_write_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cus_init.custom_value_char_attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cus_init.custom_value_char_attr_md.write_perm);

    err_code = ble_cus_init(&m_cus, &cus_init);
    APP_ERROR_CHECK(err_code);
    }

    ?

  • Hi Shimon,

    Thanks for you reply. I used the following to set the security open:

    add_char_params.char_props.read = 1;
    add_char_params.char_props.notify = 1;
    add_char_params.is_defered_read = 1;

    add_char_params.cccd_write_access = SEC_OPEN;
    add_char_params.read_access = SEC_OPEN;

    Basically, I followed Vidar's example code (above). The example seems very simple but I get the error below:

    Error when calling 'reduceApp': Cannot read property 'toUppedCase' of null

    I appreciate any comment.

    Thanks,

    Reza

Reply
  • Hi Shimon,

    Thanks for you reply. I used the following to set the security open:

    add_char_params.char_props.read = 1;
    add_char_params.char_props.notify = 1;
    add_char_params.is_defered_read = 1;

    add_char_params.cccd_write_access = SEC_OPEN;
    add_char_params.read_access = SEC_OPEN;

    Basically, I followed Vidar's example code (above). The example seems very simple but I get the error below:

    Error when calling 'reduceApp': Cannot read property 'toUppedCase' of null

    I appreciate any comment.

    Thanks,

    Reza

Children
Related