mirror of https://github.com/ARMmbed/mbed-os.git
BLE: Add error code management in Gatt read and write data structures.
Also fix wrong usage of designed initializer in CPP files.pull/5060/head
parent
85e88ccb2c
commit
38bb6b4e52
|
|
@ -17,6 +17,16 @@
|
|||
#ifndef __GATT_CALLBACK_PARAM_TYPES_H__
|
||||
#define __GATT_CALLBACK_PARAM_TYPES_H__
|
||||
|
||||
/**
|
||||
* Parameter of the callback invoked on a write operation.
|
||||
* This parameter is used whether a GattServer as received a write operation or
|
||||
* if the GattClient has completed a write operation.
|
||||
*
|
||||
* @important The fields connHandle, handle and writeOp are used in both
|
||||
* callbacks while:
|
||||
* - offset, len and data are reserved for GattServer write callbacks.
|
||||
* - status and error_code are reserved for GattClient write callbacks.
|
||||
*/
|
||||
struct GattWriteCallbackParams {
|
||||
/**
|
||||
* Enumeration for write operations.
|
||||
|
|
@ -34,22 +44,48 @@ struct GattWriteCallbackParams {
|
|||
Gap::Handle_t connHandle; /**< The handle of the connection that triggered the event. */
|
||||
GattAttribute::Handle_t handle; /**< Attribute Handle to which the write operation applies. */
|
||||
WriteOp_t writeOp; /**< Type of write operation. */
|
||||
uint16_t offset; /**< Offset for the write operation. */
|
||||
uint16_t len; /**< Length (in bytes) of the data to write. */
|
||||
|
||||
// Note: offset is used in GattServer while status is used in GattClient
|
||||
union {
|
||||
uint16_t offset; /**< Offset for the GattServer write operation. */
|
||||
ble_error_t status; /**< Status of the GattClient Write operation */
|
||||
};
|
||||
|
||||
// Note: len is used in GattServer while error_code is used in GattClient
|
||||
union {
|
||||
uint16_t len; /**< Length (in bytes) of the data to write (GattServer). */
|
||||
uint8_t error_code; /**< Error code of the GattClient Write operation */
|
||||
};
|
||||
|
||||
/**
|
||||
* Pointer to the data to write.
|
||||
*
|
||||
* @note Data might not persist beyond the callback; make a local copy if
|
||||
* needed.
|
||||
* @note This field is not used by callbacks invoked by the GattClient module.
|
||||
*/
|
||||
const uint8_t *data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Parameter of the callback invoked on a read operation.
|
||||
* This parameter is used whether a GattServer as received a read operation or
|
||||
* if the GattClient has completed a read operation.
|
||||
*
|
||||
* @important The fields connHandle, handle and offset are used in both
|
||||
* callbacks while:
|
||||
* - len and data are reserved for GattServer read callbacks.
|
||||
* - status and error_code are reserved for GattClient read callbacks.
|
||||
*/
|
||||
struct GattReadCallbackParams {
|
||||
Gap::Handle_t connHandle; /**< The handle of the connection that triggered the event. */
|
||||
GattAttribute::Handle_t handle; /**< Attribute Handle to which the read operation applies. */
|
||||
uint16_t offset; /**< Offset for the read operation. */
|
||||
uint16_t len; /**< Length (in bytes) of the data to read. */
|
||||
union {
|
||||
uint16_t len; /**< Length (in bytes) of the data to read. */
|
||||
uint8_t error_code; /**< Error code if any (GattClient) */
|
||||
};
|
||||
|
||||
/**
|
||||
* Pointer to the data read.
|
||||
*
|
||||
|
|
@ -57,6 +93,7 @@ struct GattReadCallbackParams {
|
|||
* needed.
|
||||
*/
|
||||
const uint8_t *data;
|
||||
ble_error_t status; /**< Status of the operation BLE_ERROR_NONE in case of success or the error in case of error */
|
||||
};
|
||||
|
||||
enum GattAuthCallbackReply_t {
|
||||
|
|
|
|||
|
|
@ -367,11 +367,11 @@ void ArmGattServer::attCback(attEvt_t *pEvt)
|
|||
uint8_t ArmGattServer::attsReadCback(dmConnId_t connId, uint16_t handle, uint8_t operation, uint16_t offset, attsAttr_t *pAttr)
|
||||
{
|
||||
GattReadCallbackParams cbParams = {
|
||||
.connHandle = connId,
|
||||
.handle = handle,
|
||||
.offset = offset,
|
||||
.len = *pAttr->pLen,
|
||||
.data = pAttr->pValue
|
||||
/* .connHandle = */ connId,
|
||||
/* .handle = */ handle,
|
||||
/* .offset = */ offset,
|
||||
/* .len = */ *pAttr->pLen,
|
||||
/* .data = */ pAttr->pValue
|
||||
};
|
||||
getInstance().handleDataReadEvent(&cbParams);
|
||||
|
||||
|
|
@ -410,12 +410,12 @@ uint8_t ArmGattServer::attsWriteCback(dmConnId_t connId, uint16_t handle, uint8_
|
|||
}
|
||||
|
||||
GattWriteCallbackParams cbParams = {
|
||||
.connHandle = connId,
|
||||
.handle = handle,
|
||||
.writeOp = writeOp,
|
||||
.offset = offset,
|
||||
.len = len,
|
||||
.data = pValue
|
||||
/* .connHandle = */ connId,
|
||||
/* .handle = */ handle,
|
||||
/* .writeOp = */ writeOp,
|
||||
/* .offset = */ offset,
|
||||
/* .len = */ len,
|
||||
/* .data = */ pValue
|
||||
};
|
||||
getInstance().handleDataWrittenEvent(&cbParams);
|
||||
|
||||
|
|
|
|||
|
|
@ -383,11 +383,11 @@ void MaximGattServer::attCback(attEvt_t *pEvt)
|
|||
uint8_t MaximGattServer::attsReadCback(dmConnId_t connId, uint16_t handle, uint8_t operation, uint16_t offset, attsAttr_t *pAttr)
|
||||
{
|
||||
GattReadCallbackParams cbParams = {
|
||||
.connHandle = connId,
|
||||
.handle = handle,
|
||||
.offset = offset,
|
||||
.len = *pAttr->pLen,
|
||||
.data = pAttr->pValue
|
||||
/* .connHandle = */ connId,
|
||||
/* .handle = */ handle,
|
||||
/* .offset = */ offset,
|
||||
/* .len = */ *pAttr->pLen,
|
||||
/* .data = */ pAttr->pValue
|
||||
};
|
||||
getInstance().handleDataReadEvent(&cbParams);
|
||||
|
||||
|
|
@ -426,12 +426,12 @@ uint8_t MaximGattServer::attsWriteCback(dmConnId_t connId, uint16_t handle, uint
|
|||
}
|
||||
|
||||
GattWriteCallbackParams cbParams = {
|
||||
.connHandle = connId,
|
||||
.handle = handle,
|
||||
.writeOp = writeOp,
|
||||
.offset = offset,
|
||||
.len = len,
|
||||
.data = pValue
|
||||
/* .connHandle = */ connId,
|
||||
/* .handle = */ handle,
|
||||
/* .writeOp = */ writeOp,
|
||||
/* .offset = */ offset,
|
||||
/* .len = */ len,
|
||||
/* .data = */ pValue
|
||||
};
|
||||
getInstance().handleDataWrittenEvent(&cbParams);
|
||||
|
||||
|
|
|
|||
|
|
@ -63,11 +63,11 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
|||
|
||||
case BLE_GATTC_EVT_READ_RSP: {
|
||||
GattReadCallbackParams response = {
|
||||
.connHandle = p_ble_evt->evt.gattc_evt.conn_handle,
|
||||
.handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle,
|
||||
.offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
|
||||
.len = p_ble_evt->evt.gattc_evt.params.read_rsp.len,
|
||||
.data = p_ble_evt->evt.gattc_evt.params.read_rsp.data,
|
||||
/* .connHandle = */ p_ble_evt->evt.gattc_evt.conn_handle,
|
||||
/* .handle = */ p_ble_evt->evt.gattc_evt.params.read_rsp.handle,
|
||||
/* .offset = */ p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
|
||||
/* .len = */ p_ble_evt->evt.gattc_evt.params.read_rsp.len,
|
||||
/* .data = */ p_ble_evt->evt.gattc_evt.params.read_rsp.data,
|
||||
};
|
||||
gattClient.processReadResponse(&response);
|
||||
}
|
||||
|
|
@ -75,12 +75,12 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
|||
|
||||
case BLE_GATTC_EVT_WRITE_RSP: {
|
||||
GattWriteCallbackParams response = {
|
||||
.connHandle = p_ble_evt->evt.gattc_evt.conn_handle,
|
||||
.handle = p_ble_evt->evt.gattc_evt.params.write_rsp.handle,
|
||||
.writeOp = (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op),
|
||||
.offset = p_ble_evt->evt.gattc_evt.params.write_rsp.offset,
|
||||
.len = p_ble_evt->evt.gattc_evt.params.write_rsp.len,
|
||||
.data = p_ble_evt->evt.gattc_evt.params.write_rsp.data,
|
||||
/* .connHandle = */ p_ble_evt->evt.gattc_evt.conn_handle,
|
||||
/* .handle = */ p_ble_evt->evt.gattc_evt.params.write_rsp.handle,
|
||||
/* .writeOp = */ (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op),
|
||||
/* .offset = */ p_ble_evt->evt.gattc_evt.params.write_rsp.offset,
|
||||
/* .len = */ p_ble_evt->evt.gattc_evt.params.write_rsp.len,
|
||||
/* .data = */ p_ble_evt->evt.gattc_evt.params.write_rsp.data,
|
||||
};
|
||||
gattClient.processWriteResponse(&response);
|
||||
}
|
||||
|
|
@ -88,11 +88,11 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
|||
|
||||
case BLE_GATTC_EVT_HVX: {
|
||||
GattHVXCallbackParams params;
|
||||
params.connHandle = p_ble_evt->evt.gattc_evt.conn_handle;
|
||||
params.handle = p_ble_evt->evt.gattc_evt.params.hvx.handle;
|
||||
params.type = static_cast<HVXType_t>(p_ble_evt->evt.gattc_evt.params.hvx.type);
|
||||
params.len = p_ble_evt->evt.gattc_evt.params.hvx.len;
|
||||
params.data = p_ble_evt->evt.gattc_evt.params.hvx.data;
|
||||
/* params.connHandle = */ p_ble_evt->evt.gattc_evt.conn_handle;
|
||||
/* params.handle = */ p_ble_evt->evt.gattc_evt.params.hvx.handle;
|
||||
/* params.type = */ static_cast<HVXType_t>(p_ble_evt->evt.gattc_evt.params.hvx.type);
|
||||
/* params.len = */ p_ble_evt->evt.gattc_evt.params.hvx.len;
|
||||
/* params.data = */ p_ble_evt->evt.gattc_evt.params.hvx.data;
|
||||
|
||||
gattClient.processHVXEvent(¶ms);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -440,12 +440,12 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
|
|||
switch (eventType) {
|
||||
case GattServerEvents::GATT_EVENT_DATA_WRITTEN: {
|
||||
GattWriteCallbackParams cbParams = {
|
||||
.connHandle = gattsEventP->conn_handle,
|
||||
.handle = handle_value,
|
||||
.writeOp = static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.write.op),
|
||||
.offset = gattsEventP->params.write.offset,
|
||||
.len = gattsEventP->params.write.len,
|
||||
.data = gattsEventP->params.write.data
|
||||
/* .connHandle = */ gattsEventP->conn_handle,
|
||||
/* .handle = */ handle_value,
|
||||
/* .writeOp = */ static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.write.op),
|
||||
/* .offset = */ gattsEventP->params.write.offset,
|
||||
/* .len = */ gattsEventP->params.write.len,
|
||||
/* .data = */ gattsEventP->params.write.data
|
||||
};
|
||||
handleDataWrittenEvent(&cbParams);
|
||||
break;
|
||||
|
|
@ -480,12 +480,12 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
|
|||
*/
|
||||
if (reply.params.write.gatt_status == BLE_GATT_STATUS_SUCCESS) {
|
||||
GattWriteCallbackParams cbParams = {
|
||||
.connHandle = gattsEventP->conn_handle,
|
||||
.handle = handle_value,
|
||||
.writeOp = static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.authorize_request.request.write.op),
|
||||
.offset = gattsEventP->params.authorize_request.request.write.offset,
|
||||
.len = gattsEventP->params.authorize_request.request.write.len,
|
||||
.data = gattsEventP->params.authorize_request.request.write.data,
|
||||
/* .connHandle = */ gattsEventP->conn_handle,
|
||||
/* .handle = */ handle_value,
|
||||
/* .writeOp = */ static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.authorize_request.request.write.op),
|
||||
/* .offset = */ gattsEventP->params.authorize_request.request.write.offset,
|
||||
/* .len = */ gattsEventP->params.authorize_request.request.write.len,
|
||||
/* .data = */ gattsEventP->params.authorize_request.request.write.data,
|
||||
};
|
||||
handleDataWrittenEvent(&cbParams);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,11 +63,11 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
|||
|
||||
case BLE_GATTC_EVT_READ_RSP: {
|
||||
GattReadCallbackParams response = {
|
||||
.connHandle = p_ble_evt->evt.gattc_evt.conn_handle,
|
||||
.handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle,
|
||||
.offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
|
||||
.len = p_ble_evt->evt.gattc_evt.params.read_rsp.len,
|
||||
.data = p_ble_evt->evt.gattc_evt.params.read_rsp.data,
|
||||
/* .connHandle = */ p_ble_evt->evt.gattc_evt.conn_handle,
|
||||
/* .handle = */ p_ble_evt->evt.gattc_evt.params.read_rsp.handle,
|
||||
/* .offset = */ p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
|
||||
/* .len = */ p_ble_evt->evt.gattc_evt.params.read_rsp.len,
|
||||
/* .data = */ p_ble_evt->evt.gattc_evt.params.read_rsp.data,
|
||||
};
|
||||
gattClient.processReadResponse(&response);
|
||||
}
|
||||
|
|
@ -75,12 +75,12 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
|||
|
||||
case BLE_GATTC_EVT_WRITE_RSP: {
|
||||
GattWriteCallbackParams response = {
|
||||
.connHandle = p_ble_evt->evt.gattc_evt.conn_handle,
|
||||
.handle = p_ble_evt->evt.gattc_evt.params.write_rsp.handle,
|
||||
.writeOp = (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op),
|
||||
.offset = p_ble_evt->evt.gattc_evt.params.write_rsp.offset,
|
||||
.len = p_ble_evt->evt.gattc_evt.params.write_rsp.len,
|
||||
.data = p_ble_evt->evt.gattc_evt.params.write_rsp.data,
|
||||
/* .connHandle = */ p_ble_evt->evt.gattc_evt.conn_handle,
|
||||
/* .handle = */ p_ble_evt->evt.gattc_evt.params.write_rsp.handle,
|
||||
/* .writeOp = */ (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op),
|
||||
/* .offset = */ p_ble_evt->evt.gattc_evt.params.write_rsp.offset,
|
||||
/* .len = */ p_ble_evt->evt.gattc_evt.params.write_rsp.len,
|
||||
/* .data = */ p_ble_evt->evt.gattc_evt.params.write_rsp.data,
|
||||
};
|
||||
gattClient.processWriteResponse(&response);
|
||||
}
|
||||
|
|
@ -88,11 +88,11 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
|||
|
||||
case BLE_GATTC_EVT_HVX: {
|
||||
GattHVXCallbackParams params;
|
||||
params.connHandle = p_ble_evt->evt.gattc_evt.conn_handle;
|
||||
params.handle = p_ble_evt->evt.gattc_evt.params.hvx.handle;
|
||||
params.type = static_cast<HVXType_t>(p_ble_evt->evt.gattc_evt.params.hvx.type);
|
||||
params.len = p_ble_evt->evt.gattc_evt.params.hvx.len;
|
||||
params.data = p_ble_evt->evt.gattc_evt.params.hvx.data;
|
||||
/* params.connHandle = */ p_ble_evt->evt.gattc_evt.conn_handle;
|
||||
/* params.handle = */ p_ble_evt->evt.gattc_evt.params.hvx.handle;
|
||||
/* params.type = */ static_cast<HVXType_t>(p_ble_evt->evt.gattc_evt.params.hvx.type);
|
||||
/* params.len = */ p_ble_evt->evt.gattc_evt.params.hvx.len;
|
||||
/* params.data = */ p_ble_evt->evt.gattc_evt.params.hvx.data;
|
||||
|
||||
gattClient.processHVXEvent(¶ms);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -503,12 +503,12 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
|
|||
switch (eventType) {
|
||||
case GattServerEvents::GATT_EVENT_DATA_WRITTEN: {
|
||||
GattWriteCallbackParams cbParams = {
|
||||
.connHandle = gattsEventP->conn_handle,
|
||||
.handle = handle_value,
|
||||
.writeOp = static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.write.op),
|
||||
.offset = gattsEventP->params.write.offset,
|
||||
.len = gattsEventP->params.write.len,
|
||||
.data = gattsEventP->params.write.data
|
||||
/* .connHandle = */ gattsEventP->conn_handle,
|
||||
/* .handle = */ handle_value,
|
||||
/* .writeOp = */ static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.write.op),
|
||||
/* .offset = */ gattsEventP->params.write.offset,
|
||||
/* .len = */ gattsEventP->params.write.len,
|
||||
/* .data = */ gattsEventP->params.write.data
|
||||
};
|
||||
handleDataWrittenEvent(&cbParams);
|
||||
break;
|
||||
|
|
@ -539,7 +539,7 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
|
|||
if (req->length == 0) {
|
||||
req->attr_handle = input_req.handle;
|
||||
req->offset = input_req.offset;
|
||||
} else {
|
||||
} else {
|
||||
// it should be the subsequent write
|
||||
if ((req->offset + req->length) != input_req.offset) {
|
||||
sd_ble_gatts_rw_authorize_reply(conn_handle, &write_auth_invalid_offset_reply);
|
||||
|
|
@ -627,12 +627,12 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
|
|||
sd_ble_gatts_rw_authorize_reply(conn_handle, &write_auth_succes_reply);
|
||||
|
||||
GattWriteCallbackParams writeParams = {
|
||||
.connHandle = conn_handle,
|
||||
.handle = req->attr_handle,
|
||||
.writeOp = static_cast<GattWriteCallbackParams::WriteOp_t>(input_req.op),
|
||||
.offset = req->offset,
|
||||
.len = req->length,
|
||||
.data = req->data,
|
||||
/* .connHandle = */ conn_handle,
|
||||
/* .handle = */ req->attr_handle,
|
||||
/* .writeOp = */ static_cast<GattWriteCallbackParams::WriteOp_t>(input_req.op),
|
||||
/* .offset = */ req->offset,
|
||||
/* .len = */ req->length,
|
||||
/* .data = */ req->data,
|
||||
};
|
||||
handleDataWrittenEvent(&writeParams);
|
||||
releaseLongWriteRequest(conn_handle);
|
||||
|
|
@ -649,7 +649,7 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
|
|||
* set to AUTH_CALLBACK_REPLY_SUCCESS if the client
|
||||
* request is to proceed. */
|
||||
};
|
||||
|
||||
|
||||
ble_gatts_rw_authorize_reply_params_t reply = {
|
||||
.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE,
|
||||
.params = {
|
||||
|
|
@ -662,12 +662,12 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
if (reply.params.write.gatt_status != BLE_GATT_STATUS_SUCCESS)
|
||||
{
|
||||
reply.params.write.update = 0;
|
||||
}
|
||||
|
||||
|
||||
sd_ble_gatts_rw_authorize_reply(gattsEventP->conn_handle, &reply);
|
||||
|
||||
/*
|
||||
|
|
@ -679,12 +679,12 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
|
|||
*/
|
||||
if (reply.params.write.gatt_status == BLE_GATT_STATUS_SUCCESS) {
|
||||
GattWriteCallbackParams cbParams = {
|
||||
.connHandle = gattsEventP->conn_handle,
|
||||
.handle = handle_value,
|
||||
.writeOp = static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.authorize_request.request.write.op),
|
||||
.offset = gattsEventP->params.authorize_request.request.write.offset,
|
||||
.len = gattsEventP->params.authorize_request.request.write.len,
|
||||
.data = gattsEventP->params.authorize_request.request.write.data,
|
||||
/* .connHandle = */ gattsEventP->conn_handle,
|
||||
/* .handle = */ handle_value,
|
||||
/* .writeOp = */ static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.authorize_request.request.write.op),
|
||||
/* .offset = */ gattsEventP->params.authorize_request.request.write.offset,
|
||||
/* .len = */ gattsEventP->params.authorize_request.request.write.len,
|
||||
/* .data = */ gattsEventP->params.authorize_request.request.write.data,
|
||||
};
|
||||
handleDataWrittenEvent(&cbParams);
|
||||
}
|
||||
|
|
@ -789,4 +789,4 @@ void nRF5xGattServer::releaseAllWriteRequests() {
|
|||
req.data = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue