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

ble service characteristic read authorization completion notify

I have configure a authorized read from a service's characteristic as below .

void ble_band_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
{
ble_band_t * p_band = (ble_band_t *)p_context;
ble_gatts_evt_read_t const * p_evt_read = &p_ble_evt->evt.gatts_evt.params.authorize_request ;


switch (p_ble_evt->header.evt_id)
{
case BLE_GATTS_EVT_WRITE:
on_band_on_off_write(p_band, p_ble_evt);
break;

case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:


get_log_data();
break;
default:
// No implementation needed.
break;
}
}

and  get_log_data() has ,

void get_log_data(void){

ble_gatts_rw_authorize_reply_params_t test_param ;
test_param.type = BLE_GATTS_AUTHORIZE_TYPE_READ ;
test_param.params.read.gatt_status = BLE_GATT_STATUS_SUCCESS ;
test_param.params.read.update = 1 ;
test_param.params.read.offset = 0 ;

test_param.params.read.len = sizeof(log_read_buf_display);
test_param.params.read.p_data = log_read_buf_display ;

uint32_t ret = sd_ble_gatts_rw_authorize_reply(m_conn_handle, &test_param);

printf("error code  = %d \r\n",ret );

}

The read authorization works fine but "case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:" gets called multiple times( more then five) ,(for one request ) every time I send read request from nrf app( If I press read button from nrfconnect once , above case executes more then five times ) .

So , is there any flag which can be monitor to check whether the read request from peer device has completed ??  or Can we stop this multiple calling because every time I press read button from nrf app , I have to update log_read_buf_display  array  , and  with this behavior ,I am unable to distinguish the request  .

Parents
  • Hi

    There should indeed only be one BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event per read request, so it sounds like the client might be doing multiple read operations in this case. Does the service by chance have multiple characteristics, where all of them might be asked to be read?

    Please check the MSC (message sequence chart) for an illustration of how to handle authorized read requests.

    Can you also provide the log where you can see these events, as well as some information whether you're using RTT or UART, NRF_LOG_INFO() or printf, and whether you have enabled debugging?

    Are you using nRFConnect for Desktop, Android or iOS as a client?

    Best regards,

    Simon

  • Simonr,

    There should indeed only be one BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event per read request, so it sounds like the client might be doing multiple read operations in this case. Does the service by chance have multiple characteristics, where all of them might be asked to be read?

    -> I have 500 bytes of data to read( by this characteristic ) , does this cause multiple request ?? Since another characteristic which has only two bytes to read does not creat e this scenario . 

    Please check the MSC (message sequence chart) for an illustration of how to handle authorized read requests.

    -> I have followed this and it seems to be working as per the chart , but the only difference is , it calls repetitively which i have full MTU size ( 500 Bytes ) to read .

    Can you also provide the log where you can see these events, as well as some information whether you're using RTT or UART, NRF_LOG_INFO() or printf, and whether you have enabled debugging?

    -> i had put debug print inside the case and I see this is getting printed multiple times .

    switch (p_ble_evt->header.evt_id)
    {
    case BLE_GATTS_EVT_WRITE:
    on_band_on_off_write(p_band, p_ble_evt);
    break;

    case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:

    printf(" auth replay  \r\n");


    get_log_data();
    break;
    default:
    // No implementation needed.
    break;
    }
    }

     

    Are you using nRFConnect for Desktop, Android or iOS as a client?

    ->  iphone ( IOS14) . Even I checked with Android too and its the same .

Reply
  • Simonr,

    There should indeed only be one BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event per read request, so it sounds like the client might be doing multiple read operations in this case. Does the service by chance have multiple characteristics, where all of them might be asked to be read?

    -> I have 500 bytes of data to read( by this characteristic ) , does this cause multiple request ?? Since another characteristic which has only two bytes to read does not creat e this scenario . 

    Please check the MSC (message sequence chart) for an illustration of how to handle authorized read requests.

    -> I have followed this and it seems to be working as per the chart , but the only difference is , it calls repetitively which i have full MTU size ( 500 Bytes ) to read .

    Can you also provide the log where you can see these events, as well as some information whether you're using RTT or UART, NRF_LOG_INFO() or printf, and whether you have enabled debugging?

    -> i had put debug print inside the case and I see this is getting printed multiple times .

    switch (p_ble_evt->header.evt_id)
    {
    case BLE_GATTS_EVT_WRITE:
    on_band_on_off_write(p_band, p_ble_evt);
    break;

    case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:

    printf(" auth replay  \r\n");


    get_log_data();
    break;
    default:
    // No implementation needed.
    break;
    }
    }

     

    Are you using nRFConnect for Desktop, Android or iOS as a client?

    ->  iphone ( IOS14) . Even I checked with Android too and its the same .

Children
No Data
Related