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?

Parents
  • Through nordic official routine ble_app_cgms, I found that I can achieve the effect I want. Use sd_ble_gatts_rw_authorize_reply() to confirm whether you have permission, and then sd_ble_gatts_value_set() to update the attribute value. I used to use "write data", so the value has not been updated, and now I use "authorize_request data" to find that it can be updated.

    	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 */
    			{
    			    ble_gatts_value_t gatts_value;
                    memset(&gatts_value, 0, sizeof(gatts_value));
                    
    				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);
    			    
                    gatts_value.len     = pBleEvent->evt.gatts_evt.params.authorize_request.request.write.len;
                    gatts_value.offset  = 0;
                    gatts_value.p_value = (uint8_t*)(pBleEvent->evt.gatts_evt.params.authorize_request.request.write.data);
                    
                    sd_ble_gatts_value_set(BLE_CONN_HANDLE_INVALID, pBleEvent->evt.gatts_evt.params.authorize_request.request.write.handle, &gatts_value);
    			}
    			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;

Reply
  • Through nordic official routine ble_app_cgms, I found that I can achieve the effect I want. Use sd_ble_gatts_rw_authorize_reply() to confirm whether you have permission, and then sd_ble_gatts_value_set() to update the attribute value. I used to use "write data", so the value has not been updated, and now I use "authorize_request data" to find that it can be updated.

    	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 */
    			{
    			    ble_gatts_value_t gatts_value;
                    memset(&gatts_value, 0, sizeof(gatts_value));
                    
    				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);
    			    
                    gatts_value.len     = pBleEvent->evt.gatts_evt.params.authorize_request.request.write.len;
                    gatts_value.offset  = 0;
                    gatts_value.p_value = (uint8_t*)(pBleEvent->evt.gatts_evt.params.authorize_request.request.write.data);
                    
                    sd_ble_gatts_value_set(BLE_CONN_HANDLE_INVALID, pBleEvent->evt.gatts_evt.params.authorize_request.request.write.handle, &gatts_value);
    			}
    			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;

Children
Related