I added bonding/authentication to my application.
I have two characteristics: a "protected" characteristic (cccd_md.wr_auth = 1;) with indications and an unprotected characteristic with notifications.
I used to react to the "indication/notification turned on" event with the BLE event handler and BLE_GATTS_EVT_WRITE.
Now, enabling indications for "protected" characteristic no longer produces a BLE_GATTS_EVT_WRITE. It produces a BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST. Am I supposed to handle the "indication/notification turned on" in there? I already handle the write like this, but nothing happens after sd_ble_gatts_rw_authorize_reply
} else if (req->type == BLE_GATTS_AUTHORIZE_TYPE_WRITE) {
NRF_LOG_INFO("Unhandled write. Allowing. writeHandle: %d writeOp: %d UUID:0x%x UUID_TYPE: %d", req->request.write.handle, req->request.write.op, req->request.write.uuid.uuid, req->request.write.uuid.type);
auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
auth_reply.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS;
auth_reply.params.write.update = 1;
auth_reply.params.write.offset = req->request.write.offset;
auth_reply.params.write.len = req->request.write.len;
auth_reply.params.write.p_data = req->request.write.data;
APP_ERROR_CHECK(sd_ble_gatts_rw_authorize_reply(conn_handle, &auth_reply));
}
I thought when I use sd_ble_gatts_rw_authorize_reply, it's supposed to let my write go through and trigger a BLE_GATTS_EVT_WRITE.
For the unprotected characteristic that broke, I was detecting a write to the CCCD like this, but this condition broke
if ( (p_evt_write->handle == p_service->rx_handles.cccd_handle)
&& (p_evt_write->len == 2))
{
motion_service_evt_t evt;
NRF_LOG_INFO("motion_service_on_write 2");
if (ble_srv_is_notification_enabled(p_evt_write->data))
{
evt.evt_type = MOTION_SERVICE_EVT_NOTIFICATION_ENABLED;
p_service->is_notification_enabled = true;
start_motion_updates();
NRF_LOG_INFO("motion_service_on_write 3");
}
else
{
evt.evt_type = MOTION_SERVICE_EVT_NOTIFICATION_DISABLED;
p_service->is_notification_enabled = false;
stop_motion_updates();
}
if (p_service->evt_handler != NULL) {
// CCCD written, call application event handler.
p_service->evt_handler(p_service, &evt);
}
}
Specifically, (p_evt_write->handle == p_service->rx_handles.cccd_handle) is no longer true. What is the correct way to detect that I want to enable notifications?