Trying ble_app_blinky with one phone (Goggle Pixel XL, Android 8) causes a BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST rather than the expected BLE_GATTS_EVT_WRITE. I do get a Write with a Samsun Note 3 running Android version 5). I'm using nRF Blinky app on both phones. Since the ble_lbs.c doesn't handle this event, I'm trying to add it. Here is the updated ble_lbs_on_ble_evt handler:
void ble_lbs_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context) { ret_code_t err; ble_lbs_t * p_lbs = (ble_lbs_t *)p_context; NRF_LOG_INFO("lbs evt: %08lX",p_ble_evt->header.evt_id); switch (p_ble_evt->header.evt_id) { case BLE_GATTS_EVT_WRITE: on_write(p_lbs, p_ble_evt); break; case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST: { const ble_gatts_evt_rw_authorize_request_t* req; ble_gatts_rw_authorize_reply_params_t auth_reply; req = &p_ble_evt->evt.gatts_evt.params.authorize_request; if (req->type != BLE_GATTS_AUTHORIZE_TYPE_INVALID) { if (req->type == BLE_GATTS_AUTHORIZE_TYPE_WRITE) { auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE; auth_reply.params.write.update = 1; auth_reply.params.write.len = req->request.write.len; auth_reply.params.write.p_data = req->request.write.data; auth_reply.params.write.offset = req->request.write.offset; auth_reply.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS; NRF_LOG_INFO("lbs evt auth write len: %d",req->request.write.len); if ( (req->request.write.handle == p_lbs->led_char_handles.value_handle) && (req->request.write.len == 1) && (p_lbs->led_write_handler != NULL)) { p_lbs->led_write_handler(p_ble_evt->evt.gap_evt.conn_handle, p_lbs, req->request.write.data[0]); } else { auth_reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_WRITE_NOT_PERMITTED; } err = sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle,&auth_reply); if (err != NRF_SUCCESS){ NRF_LOG_ERROR("reply error! %08lX",err); } } } } break; default: // No implementation needed. break; } }
This manages to catch the authorize Write to turn on the LED but the call to sd_ble_gatts_rw_authorize_reply() returns code 8 (which, I believe, is INVALID_STATE). What am I doing wrong? The write request is being handled properly and the LED is coming on (it won't go off since I'm not getting an 'OFF' request).
I'm using SDK 15.2.0 and N52 DK.
Tom