Functions
Functions
BLE » Generic Attribute Profile (GATT) » Generic Attribute Profile (GATT) Server

## Functions
uint16_t | ble_gatts_srvc_db_create (ble_gatts_create_db_t *p_param)
| Register a service's attribute list. More...
uint16_t | ble_gatts_value_set (uint16_t handle, uint16_t length, uint16_t offset, const uint8_t *p_value)
| Update attribute value only if the attribute value is saved in the BLE Stack space. More...
uint16_t | ble_gatts_value_get (uint16_t handle, uint16_t *p_length, uint8_t *p_value)
| Retrieve attribute value only if the attribute value is saved in the BLE Stack space. More...
uint16_t | ble_gatts_attr_permission_set (uint16_t handle, uint16_t perm, uint16_t ext_perm)
| Update attribute permission. More...
uint16_t | ble_gatts_attr_permission_get (uint16_t handle, uint16_t *p_perm, uint16_t *p_ext_perm)
| Retrieve attribute permission. More...
uint16_t | ble_gatts_read_cfm (uint8_t conn_idx, const ble_gatts_read_cfm_t *p_param)
| Respond to an attribute read request.. More...
uint16_t | ble_gatts_write_cfm (uint8_t conn_idx, const ble_gatts_write_cfm_t *p_param)
| Respond to an attribute write request. More...
uint16_t | ble_gatts_prepare_write_cfm (uint8_t conn_idx, const ble_gatts_prep_write_cfm_t *p_param)
| Respond to an attribute prepare write request. More...
uint16_t | ble_gatts_noti_ind (uint8_t conn_idx, const ble_gatts_noti_ind_t *p_param)
| Send out a notification or an indication. More...
void | ble_gatts_service_changed (void)
| When service on local device finishes upgrade, call this API to send service upgrade to stack. If the bonded device connects again, the stack will send service change to the bonded device until the bonded device has sent back indication confirmation. More...
uint16_t | ble_gatts_service_discoverable_set (uint8_t conn_idx, uint16_t start_hdl, bool discoverable)
| Set a service discoverable or not. More...
uint16_t | ble_gatts_service_discover_all (uint8_t conn_idx)
| Set all service discoverable. More...
uint16_t | ble_gatts_service_hide_all (uint8_t conn_idx)
| Hide all service. More...

## Detailed Description

## Function Documentation

## ◆ ble_gatts_attr_permission_get()

uint16_t ble_gatts_attr_permission_get | ( | uint16_t | handle,
|  | uint16_t * | p_perm,
|  | uint16_t * | p_ext_perm
| ) |  |

Retrieve attribute permission.

Parameters

  [in] | handle | Attribute handle.
  [out] | p_perm | Attribute permission value to be returned.
  [out] | p_ext_perm | Attribute extended permission value to be returned.

Return values

  SDK_SUCCESS | Retrieve attribute permission successfully.
  SDK_ERR_POINTER_NULL | Perm or ext_perm is NULL.
  SDK_ERR_INVALID_HANDLE | Handle not exist in the database.

## ◆ ble_gatts_attr_permission_set()

uint16_t ble_gatts_attr_permission_set | ( | uint16_t | handle,
|  | uint16_t | perm,
|  | uint16_t | ext_perm
| ) |  |

Update attribute permission.

Note
  The modifications of attribute permission to service/character/include/character_extended_properties_descriptor declaration: not supported.
  The modifications of attribute permission to others: perm can be updated and EKS of ext_perm can be updated.See Attribute Permission.

Parameters

  [in] | handle | Attribute handle.
  [in] | perm | New attribute permission.
  [in] | ext_perm | New attribute extended permission.

Return values

  SDK_SUCCESS | Update attribute permission successfully.
  SDK_ERR_INVALID_HANDLE | Handle not exist in the database.
  SDK_ERR_REQ_NOT_SUPPORTED | Attribute permission can't be modified.

## ◆ ble_gatts_noti_ind()

uint16_t ble_gatts_noti_ind | ( | uint8_t | conn_idx,
|  | const ble_gatts_noti_ind_t * | p_param
| ) |  |

Send out a notification or an indication.

Note
  Check whether the relevant Client Characteristic Configuration Descriptor is enabled before using this API.

Parameters

  [in] | conn_idx | Current connection index.
  [in] | p_param | Pointer to the parameters filled by profile. see ble_gatts_noti_ind_t.

Return values

  SDK_SUCCESS | Send Notification or Indication event to stack successfully.
  SDK_ERR_POINTER_NULL | Param is NULL.
  SDK_ERR_INVALID_CONN_IDX | Conidx is invalid.
  SDK_ERR_INVALID_PARAM | Type is invalid.
  SDK_ERR_INVALID_HANDLE | Handle not exist in the database.
  SDK_ERR_NO_RESOURCES | Not enough resources.

## ◆ ble_gatts_prepare_write_cfm()

uint16_t ble_gatts_prepare_write_cfm | ( | uint8_t | conn_idx,
|  | const ble_gatts_prep_write_cfm_t * | p_param
| ) |  |

Respond to an attribute prepare write request.

Note
  The status member gatts_prep_write_cfm_t::status should be set to BLE_ATT_ERR_INSUFF_AUTHOR to control the authorization of particular client's write operation.

Parameters

  [in] | conn_idx | Current connection index.
  [in] | p_param | Pointer to the parameters filled by profile. see ble_gatts_prep_write_cfm_t.

Return values

  SDK_SUCCESS | Send prepare write confirm status to stack successfully.
  SDK_ERR_POINTER_NULL | Param is NULL.
  SDK_ERR_INVALID_CONN_IDX | Conidx is invalid.
  SDK_ERR_NO_RESOURCES | Not enough resources.

## ◆ ble_gatts_read_cfm()

uint16_t ble_gatts_read_cfm | ( | uint8_t | conn_idx,
|  | const ble_gatts_read_cfm_t * | p_param
| ) |  |

Respond to an attribute read request..

Note
  The status member gatts_read_cfm_t::status should be set to BLE_ATT_ERR_INSUFF_AUTHOR to control the authorization of particular read operations of a client.

Parameters

  [in] | conn_idx | Current connection index.
  [in] | p_param | Pointer to the parameters filled by profile. See ble_gatts_read_cfm_t.

Return values

  SDK_SUCCESS | Send read confirm value to stack successfully.
  SDK_ERR_POINTER_NULL | Param is NULL.
  SDK_ERR_INVALID_CONN_IDX | Conidx is invalid.
  SDK_ERR_NO_RESOURCES | Not enough resources.

## ◆ ble_gatts_service_changed()

void ble_gatts_service_changed | ( | void |  | ) |

When service on local device finishes upgrade, call this API to send service upgrade to stack. If the bonded device connects again, the stack will send service change to the bonded device until the bonded device has sent back indication confirmation.

## ◆ ble_gatts_service_discover_all()

uint16_t ble_gatts_service_discover_all | ( | uint8_t | conn_idx | ) |

Set all service discoverable.

Parameters

  [in] | conn_idx | Current connection index.

Return values

  SDK_SUCCESS | Set all service discoverable successfully.
  SDK_ERR_INVALID_CONN_IDX | Conidx is invalid.

## ◆ ble_gatts_service_discoverable_set()

uint16_t ble_gatts_service_discoverable_set | ( | uint8_t | conn_idx,
|  | uint16_t | start_hdl,
|  | bool | discoverable
| ) |  |

Set a service discoverable or not.

Parameters

  [in] | conn_idx | Current connection index.
  [in] | start_hdl | Start handle of the service.
  [in] | discoverable | Flag for discoverable(true: discoverable, false: hide)

Return values

  SDK_SUCCESS | Set this service hide or not successfully.
  SDK_ERR_INVALID_CONN_IDX | Conidx is invalid.

## ◆ ble_gatts_service_hide_all()

uint16_t ble_gatts_service_hide_all | ( | uint8_t | conn_idx | ) |

Hide all service.

Parameters

  [in] | conn_idx | Current connection index.

Return values

  SDK_SUCCESS | Hide all service successfully.
  SDK_ERR_INVALID_CONN_IDX | Conidx is invalid.

## ◆ ble_gatts_srvc_db_create()

uint16_t ble_gatts_srvc_db_create | ( | ble_gatts_create_db_t * | p_param | ) |

Register a service's attribute list.

Parameters

  [in] | p_param | Pointer to the parameter used in creating databases. see ble_gatts_create_db_t.

Return values

  SDK_SUCCESS | Database has been registered successfully.
  SDK_ERR_POINTER_NULL | Param is NULL or param's members are NULL.
  SDK_ERR_INVALID_PARAM | The member of param is invalid.
  SDK_ERR_INVALID_HANDLE | The service handles can not be allocated.
  SDK_ERR_NO_RESOURCES | There is not enough memory to allocate service buffer.
  SDK_ERR_INVALID_PERM | Permissions of Client Characteristic Configuration or Server Characteristic Configuration are not set correctly.

## ◆ ble_gatts_value_get()

uint16_t ble_gatts_value_get | ( | uint16_t | handle,
|  | uint16_t * | p_length,
|  | uint8_t * | p_value
| ) |  |

Retrieve attribute value only if the attribute value is saved in the BLE Stack space.

Parameters

  [in] | handle | Attribute handle.
  [in,out] | p_length | Input as buffer size and output as attribute value length.
  [out] | p_value | Buffer to store attribute value when buffer size is enough.

Return values

  SDK_SUCCESS | Attribute value retrieved successfully.
  SDK_ERR_POINTER_NULL | The pointer to input buffer size or input buffer is NULL.
  SDK_ERR_INVALID_HANDLE | Handle not exist in the database.
  SDK_ERR_REQ_NOT_SUPPORTED | Attribute data is not present in database.
  SDK_ERR_INVALID_ATT_VAL_LEN | Attribute data value size is bigger than buffer size.
  SDK_ERR_APP_ERROR | Database is not correctly initialized by application.

## ◆ ble_gatts_value_set()

uint16_t ble_gatts_value_set | ( | uint16_t | handle,
|  | uint16_t | length,
|  | uint16_t | offset,
|  | const uint8_t * | p_value
| ) |  |

Update attribute value only if the attribute value is saved in the BLE Stack space.

Parameters

  [in] | handle | Attribute handle.
  [in] | length | Size of the value to set.
  [in] | offset | Data offset of the value in attribute value.
  [in] | p_value | The value to set. If offset = 0, the value is the new attribute value; otherwise, the value is part of the new attribute value.

Return values

  SDK_SUCCESS | Successfully update the attribute value.
  SDK_ERR_POINTER_NULL | Value is NULL.
  SDK_ERR_INVALID_HANDLE | Handle not exist in database.
  SDK_ERR_REQ_NOT_SUPPORTED | Attribute data is not present in database or cannot be modified.
  SDK_ERR_INVALID_ATT_VAL_LEN | New value length exceeds maximum attribute value length.
  SDK_ERR_INVALID_OFFSET | Offset exceeds current attribute value length.

## ◆ ble_gatts_write_cfm()

uint16_t ble_gatts_write_cfm | ( | uint8_t | conn_idx,
|  | const ble_gatts_write_cfm_t * | p_param
| ) |  |

Respond to an attribute write request.

Note
  The status member gatts_write_cfm_t::status should be set to BLE_ATT_ERR_INSUFF_AUTHOR to control the authorization of particular client's write operation.

Parameters

  [in] | conn_idx | Current connection index.
  [in] | p_param | Pointer to the parameters filled by profile. see ble_gatts_write_cfm_t.

Return values

  SDK_SUCCESS | Send write confirm status to stack successfully.
  SDK_ERR_POINTER_NULL | Param is NULL.
  SDK_ERR_INVALID_CONN_IDX | Conidx is invalid.
  SDK_ERR_NO_RESOURCES | Not enough resources.