About the use of sd_ble_gatts_rw_authorize_reply()

hi,

I have a private service with characteristics of lock, unlock, and mode, all of which have write attributes, and only use unlock without read attributes. I can already use the sd_ble_gatts_rw_authorize_reply() function to limit whether I have write permission, through its "BLE_GATT_STATUS_SUCCESS" or "BLE_GATT_STATUS_ATTERR_WRITE_NOT_PERMITTED" parameter, now there is a problem, that is, when I have write permission, the data I write does not Not updating to my characteristic value.

	case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
	{
		if(pBleEvent->evt.gatts_evt.params.authorize_request.type == BLE_GATTS_AUTHORIZE_TYPE_WRITE)
		{
			ble_gatts_rw_authorize_reply_params_t rw_authorize_reply_params;
			memset(&rw_authorize_reply_params, 0, sizeof(rw_authorize_reply_params));
			
			rw_authorize_reply_params.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
			if(GetUnlockFlag())	 /**< Get locked or unlocked status */
			{
				rw_authorize_reply_params.params.write.p_data = pBleEvent->evt.gatts_evt.params.write.data;
				rw_authorize_reply_params.params.write.len = pBleEvent->evt.gatts_evt.params.write.len;
				rw_authorize_reply_params.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS;	 /**< write permission */
				rw_authorize_reply_params.params.write.update = 1;
				err_code = sd_ble_gatts_rw_authorize_reply(pBleEvent->evt.gatts_evt.conn_handle, &rw_authorize_reply_params);
			}
			else
			{
				rw_authorize_reply_params.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_WRITE_NOT_PERMITTED; /**< no write permission */
				rw_authorize_reply_params.params.write.update = 0;
				err_code = sd_ble_gatts_rw_authorize_reply(pBleEvent->evt.gatts_evt.conn_handle, &rw_authorize_reply_params);
			}
		} /* if */
	}
	break;

SDK17.1,softdevice 7.3.

can you help me?

  • Hi,

    To clarify, what I mean is to always check the error code, like this:

    err_code = sd_ble_gatts_rw_authorize_reply(pBleEvent->evt.gatts_evt.conn_handle, &rw_authorize_reply_params);
    APP_ERROR_CHECK(err_code);

    The APP_ERROR_CHECK macro will reset (for release builds) or enter infinite loop (for debug builds) and log an error message with debug info.

    That way for a debug build you can see from log (RTT or UART, depending on configuration) or during debug session what went wrong. For release builds, on the other hand, which are intended for final products, the device resets. This makes sense since when an unknown error happens it is better to reset (into a known state) than to continue (in an unknown state.)

    In most cases one would just use the APP_ERROR_CHECK on the returned value, and not check for any values manually first. However if there are known error return values that you know how to handle programmatically (or can safely ignore), then you should check the return value in code first, and only do APP_ERROR_CHECK for values that cannot be safely ignored or handled otherwise. You may find a few examples of that in the SDK, but you will see that in most instances the APP_ERROR_CHECK is called directly on the return value.

    Regards,
    Terje

Related