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

sd_ble_gatts_rw_authorize_reply returns error (s132)

Hi,

I'm trespassing some code of nRF51 to nRF52 (s132, SDK 12.2.0) and I get an error when I try to call sd_ble_gatts_rw_authorize_reply. This is the code

case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
				if ( p_ble_evt->evt.gatts_evt.params.authorize_request.type == BLE_GATTS_AUTHORIZE_TYPE_READ  )
				{
					ble_gatts_rw_authorize_reply_params_t auth_reply;
					auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_READ;
					uint16_t handleRead=p_ble_evt->evt.gatts_evt.params.authorize_request.request.read.handle; 
																	
					auth_reply.params.read.gatt_status=BLE_GATT_STATUS_SUCCESS;
					
					err_code=sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle,&auth_reply);
					APP_ERROR_CHECK(err_code);
				}
				else if(p_ble_evt->evt.gatts_evt.params.authorize_request.type == BLE_GATTS_AUTHORIZE_TYPE_WRITE)
				{
					ble_gatts_rw_authorize_reply_params_t auth_reply;
					
					auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
					
					uint8_t handle=p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.handle;						
					ble_gatts_evt_write_t *p_evt_writex= &p_ble_evt->evt.gatts_evt.params.authorize_request.request.write;
					uint8_t len=p_evt_writex->len;
					
						uint16_t handlewrite=p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.handle; 							
						if(handle==p_GLOBALCONFIG->global_confbyte_handles.value_handle) 
						{
							if(len != 1) 
							{
								auth_reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_INVALID_ATT_VAL_LENGTH; 								}
							else
							{
								auth_reply.params.write.gatt_status=BLE_GATT_STATUS_SUCCESS;
							}
							
							err_code=sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle,&auth_reply);	
							APP_ERROR_CHECK(err_code);
						}
				}
					break;

When I read, I don't get any error, but when I write, I get the error NRF_ERROR_INVALID_PARAM when I call "sd_ble_gatts_rw_authorize_reply" . I think the problem is the "BLE_GATT_STATUS_SUCCESS" status, but I don't know why. This is the correct way or there's any other way to write and read with authorization in s132?

Parents
  • Why do you think the problem is the "BLE_GATT_STATUS_SUCCESS" status? And what do you mean by that? If you look inside the ble_gatts_rw_authorize_reply_params_t struct, you have write, which is a ble_gatts_authorize_params_t struct. Inside you have a update field, which has to be set for authorized write operations:

    /**< If set, data supplied in p_data will be used to update the attribute value. Please note that for @ref BLE_GATTS_AUTHORIZE_TYPE_WRITE operations this bit must always be set, as the data to be written needs to be stored and later provided by the application. */

    And you need to set the other fields in this struct as well.

  • The SDK 12 introduces some new flags to be set on 'ble_gatts_rw_authorize_reply_params_t' parameter and I forgot to set them. Now it works fine.

Reply Children
No Data
Related