gjhn

Dependents:   BLE_GENERALE

Fork of X_NUCLEO_IDB0XA1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers bluenrg_gatt_aci.h Source File

bluenrg_gatt_aci.h

00001 /******************** (C) COPYRIGHT 2014 STMicroelectronics ********************
00002 * File Name          : bluenrg_gatt_aci.h
00003 * Author             : AMS - AAS
00004 * Version            : V1.0.0
00005 * Date               : 26-Jun-2014
00006 * Description        : Header file with GATT commands for BlueNRG FW6.3.
00007 ********************************************************************************
00008 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00009 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
00010 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
00011 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
00012 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
00013 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00014 *******************************************************************************/
00015 
00016 #ifndef __BLUENRG_GATT_ACI_H__
00017 #define __BLUENRG_GATT_ACI_H__
00018 
00019 #include "bluenrg_gatt_server.h"
00020 
00021 /**
00022  *@addtogroup GATT GATT
00023  *@brief GATT layer.
00024  *@{
00025  */
00026 
00027 /**
00028  *@defgroup GATT_Functions GATT functions
00029  *@brief API for GATT layer.
00030  *@{
00031  */
00032 
00033 /**
00034   * @brief  Initialize the GATT layer for server and client roles.
00035   * @note   It adds also the GATT service with Service Changed Characteristic.
00036  *           Until this command is issued the GATT channel will not process any commands
00037   *          even if the connection is opened. This command has to be given
00038   *          before using any of the GAP features.
00039   * @return Value indicating success or error code.
00040   */
00041 tBleStatus aci_gatt_init(void);
00042 
00043 /**
00044  * @brief Add a service to the GATT Server. When a service is created in the server, the Host needs
00045  *        to reserve the handle ranges for this service using max_attr_records parameter. This
00046  *        parameter specifies the maximum number of attribute records that can be added to this
00047  *        service (including the service attribute, include attribute, characteristic attribute,
00048  *        characteristic value attribute and characteristic descriptor attribute). Handle of the
00049  *        created service is returned.
00050  * @note  Service declaration is taken from the service pool. The attributes for characteristics and descriptors
00051  *            are allocated from the attribute pool.
00052  * @param service_uuid_type Type of service UUID (16-bit or 128-bit). See @ref UUID_Types "UUID Types".
00053  * @param[in] service_uuid 16-bit or 128-bit UUID based on the UUID Type field
00054  * @param service_type Primary or secondary service. See @ref Service_type "Service Type".
00055  * @param max_attr_records Maximum number of attribute records that can be added to this service
00056  *                         (including the service declaration itself)
00057  * @param[out] serviceHandle Handle of the Service. When this service is added to the service,
00058  *                           a handle is allocated by the server to this service. Server also
00059  *                           allocates a range of handles for this service from serviceHandle to
00060  *                           <serviceHandle + max_attr_records>.
00061  * @return Value indicating success or error code.
00062  */
00063 tBleStatus aci_gatt_add_serv(uint8_t service_uuid_type,
00064                  const uint8_t* service_uuid,
00065                  uint8_t service_type,
00066                  uint8_t max_attr_records,
00067                  uint16_t *serviceHandle);
00068 
00069 /**
00070  * @brief Include a service given by included_start_handle and included_end_handle to another service
00071  *        given by service_handle. Attribute server creates an INCLUDE definition attribute and return
00072  *        the handle of this attribute in included_handle.
00073  * @param service_handle Handle of the service to which another service has to be included
00074  * @param included_start_handle Start Handle of the service which has to be included in service
00075  * @param included_end_handle End Handle of the service which has to be included in service
00076  * @param included_uuid_type Type of UUID for included service (16-bit or 128-bit). See @ref Well-Known_UUIDs "Well-Known UUIDs".
00077  * @param[in] included_uuid 16-bit or 128-bit UUID.
00078  * @param[out] included_handle Handle of the include declaration.
00079  * @return Value indicating success or error code.
00080  */
00081 tBleStatus aci_gatt_include_service(uint16_t service_handle, uint16_t included_start_handle,
00082                     uint16_t included_end_handle, uint8_t included_uuid_type,
00083                     const uint8_t* included_uuid, uint16_t *included_handle);
00084 
00085 /**
00086  * @brief Add a characteristic to a service.
00087  * @param serviceHandle Handle of the service to which the characteristic has to be added.
00088  * @param charUuidType Type of characteristic UUID (16-bit or 128-bit). See @ref UUID_Types "UUID Types".
00089  *         @arg @ref UUID_TYPE_16
00090  *         @arg @ref UUID_TYPE_128
00091  * @param charUuid 16-bit or 128-bit UUID.
00092  * @param charValueLen Maximum length of the characteristic value.
00093  * @param charProperties Bitwise OR values of Characteristic Properties (defined in Volume 3,
00094  *        Section 3.3.3.1 of Bluetooth Specification 4.0). See @ref Char_properties "Characteristic properties".
00095  * @param secPermissions Security permissions for the added characteristic. See @ref Security_permissions "Security permissions".
00096  *          @arg ATTR_PERMISSION_NONE
00097  *          @arg ATTR_PERMISSION_AUTHEN_READ
00098  *          @arg ATTR_PERMISSION_AUTHOR_READ
00099  *          @arg ATTR_PERMISSION_ENCRY_READ
00100  *          @arg ATTR_PERMISSION_AUTHEN_WRITE
00101  *          @arg ATTR_PERMISSION_AUTHOR_WRITE
00102  *          @arg ATTR_PERMISSION_ENCRY_WRITE
00103  * @param gattEvtMask Bit mask that enables events that will be sent to the application by the GATT server
00104  *                    on certain ATT requests. See @ref Gatt_Event_Mask "Gatt Event Mask".
00105  *         @arg GATT_DONT_NOTIFY_EVENTS
00106  *         @arg GATT_NOTIFY_ATTRIBUTE_WRITE
00107  *         @arg GATT_NOTIFY_WRITE_REQ_AND_WAIT_FOR_APPL_RESP
00108  *         @arg GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP
00109  * @param encryKeySize The minimum encryption key size requirement for this attribute. Valid Range: 7 to 16.
00110  * @param isVariable If the attribute has a variable length value field (1) or not (0).
00111  * @param charHandle Handle of the Characteristic that has been added. It is the handle of the characteristic declaration.
00112  *        The attribute that holds the characteristic value is allocated at the next handle, followed by the Client
00113  *        Characteristic Configuration descriptor if the characteristic has @ref CHAR_PROP_NOTIFY or @ref CHAR_PROP_INDICATE
00114  *        properties.
00115  * @return Value indicating success or error code.
00116  */
00117 tBleStatus aci_gatt_add_char(uint16_t serviceHandle,
00118                  uint8_t charUuidType,
00119                  const uint8_t* charUuid, 
00120                  uint8_t charValueLen, 
00121                  uint8_t charProperties,
00122                  uint8_t secPermissions,
00123                  uint8_t gattEvtMask,
00124                  uint8_t encryKeySize,
00125                  uint8_t isVariable,
00126                  uint16_t* charHandle);
00127 
00128 /**
00129  * Add a characteristic descriptor to a service.
00130  * @param serviceHandle Handle of the service to which the characteristic belongs
00131  * @param charHandle Handle of the characteristic to which description has to be added.
00132  * @param descUuidType 16-bit or 128-bit UUID. See @ref UUID_Types "UUID Types".
00133  *         @arg @ref UUID_TYPE_16
00134  *         @arg @ref UUID_TYPE_128
00135  * @param[in] uuid UUID of the Characteristic descriptor. It can be one of the UUID assigned by Bluetooth SIG
00136  *      (Well_known_UUIDs) or a user-defined one.
00137  * @param descValueMaxLen The maximum length of the descriptor value
00138  * @param descValueLen Current Length of the characteristic descriptor value
00139  * @param[in] descValue Value of the characteristic description
00140  * @param secPermissions Security permissions for the added descriptor. See @ref Security_permissions "Security permissions".
00141  *          @arg ATTR_PERMISSION_NONE
00142  *          @arg ATTR_PERMISSION_AUTHEN_READ
00143  *          @arg ATTR_PERMISSION_AUTHOR_READ
00144  *          @arg ATTR_PERMISSION_ENCRY_READ
00145  *          @arg ATTR_PERMISSION_AUTHEN_WRITE
00146  *          @arg ATTR_PERMISSION_AUTHOR_WRITE
00147  *          @arg ATTR_PERMISSION_ENCRY_WRITE
00148  * @param accPermissions Access permissions for the added descriptor. See @ref Access_permissions "Access permissions".
00149  *          @arg ATTR_NO_ACCESS
00150  *          @arg ATTR_ACCESS_READ_ONLY
00151  *          @arg ATTR_ACCESS_WRITE_REQ_ONLY
00152  *          @arg ATTR_ACCESS_READ_WRITE
00153  *          @arg ATTR_ACCESS_WRITE_WITHOUT_RESPONSE
00154  *          @arg ATTR_ACCESS_SIGNED_WRITE_ALLOWED
00155  * @param gattEvtMask Bit mask that enables events that will be sent to the application by the GATT server
00156  *                    on certain ATT requests. See @ref Gatt_Event_Mask "Gatt Event Mask".
00157  * @param encryKeySize The minimum encryption key size requirement for this attribute. Valid Range: 7 to 16.
00158  * @param isVariable If the attribute has a variable length value field (1) or not (0).
00159  * @param[out] descHandle Handle of the Characteristic Descriptor.
00160  * @return Value indicating success or error code.
00161  */
00162 tBleStatus aci_gatt_add_char_desc(uint16_t serviceHandle,
00163                                   uint16_t charHandle,
00164                                   uint8_t descUuidType,
00165                                   const uint8_t* uuid, 
00166                                   uint8_t descValueMaxLen,
00167                                   uint8_t descValueLen,
00168                                   const void* descValue, 
00169                                   uint8_t secPermissions,
00170                                   uint8_t accPermissions,
00171                                   uint8_t gattEvtMask,
00172                                   uint8_t encryKeySize,
00173                                   uint8_t isVariable,
00174                                   uint16_t* descHandle);
00175 
00176 /**
00177  * @brief Update a characteristic value in a service.
00178  * @note If notifications (or indications) are enabled on that characteristic, a notification (or indication)
00179  *       will be sent to the client after sending this command to the BlueNRG. The command is queued into the
00180  *       BlueNRG command queue. If the buffer is full, because previous commands could not be still processed,
00181  *       the function will return @ref BLE_STATUS_INSUFFICIENT_RESOURCES. This will happen if notifications (or
00182  *       indications) are enabled and the application calls aci_gatt_update_char_value() at an higher rate
00183  *       than what is allowed by the link. Throughput on BLE link depends on connection interval and
00184  *       connection length parameters (decided by the master, see aci_l2cap_connection_parameter_update_request()
00185  *       for more info on how to suggest new connection parameters from a slave). If the application does not
00186  *       want to lose notifications because BlueNRG buffer becomes full, it has to retry again till the function
00187  *       returns @ref BLE_STATUS_SUCCESS or any other error code.\n
00188  *       Example:\n
00189  *       Here if BlueNRG buffer become full because BlueNRG was not able to send packets for a while, some
00190  *       notifications will be lost.
00191  *       @code
00192  *       tBleStatus Free_Fall_Notify(void)
00193  *       {
00194  *          uint8_t val;
00195  *          tBleStatus ret;
00196  *
00197  *          val = 0x01;
00198  *          ret = aci_gatt_update_char_value(accServHandle, freeFallCharHandle, 0, 1, &val);
00199  *
00200  *          if (ret != BLE_STATUS_SUCCESS){
00201  *            PRINTF("Error while updating ACC characteristic.\n") ;
00202  *            return BLE_STATUS_ERROR ;
00203  *          }
00204  *          return BLE_STATUS_SUCCESS;
00205  *       }
00206  *       @endcode
00207  *       Here if BlueNRG buffer become full, the application try again to send the notification.
00208  *       @code
00209  *       struct timer t;
00210  *       Timer_Set(&t, CLOCK_SECOND*10);
00211  *       while(aci_gatt_update_char_value(chatServHandle,TXCharHandle,0,len,array_val)==BLE_STATUS_INSUFFICIENT_RESOURCES){
00212  *         // Radio is busy (buffer full).
00213  *         if(Timer_Expired(&t))
00214  *           break;
00215  *       }
00216  *       @endcode
00217  *
00218  * @param servHandle Handle of the service to which characteristic belongs
00219  * @param charHandle Handle of the characteristic
00220  * @param charValOffset The offset from which the attribute value has to be updated. If this is set to 0,
00221  *                      and the attribute value is of variable length, then the length of the attribute will
00222  *                      be set to the charValueLen. If the charValOffset is set to a value greater than 0,
00223  *                      then the length of the attribute will be set to the maximum length as specified for
00224  *                      the attribute while adding the characteristic.
00225  * @param charValueLen Length of the characteristic value in octets
00226  * @param[in] charValue Characteristic value
00227  * @return Value indicating success or error code.
00228  */
00229 tBleStatus aci_gatt_update_char_value(uint16_t servHandle, 
00230                       uint16_t charHandle,
00231                       uint8_t charValOffset,
00232                       uint8_t charValueLen,   
00233                       const void *charValue);
00234 /**
00235  * @brief Delete the specified characteristic from the service.
00236  * @param servHandle Handle of the service to which characteristic belongs
00237  * @param charHandle Handle of the characteristic to be deleted
00238  * @return Value indicating success or error code.
00239  */
00240 tBleStatus aci_gatt_del_char(uint16_t servHandle, uint16_t charHandle);
00241 
00242 /**
00243  * @brief Delete the specified service from the GATT server database.
00244  * @param servHandle Handle of the service to be deleted
00245  * @return Value indicating success or error code.
00246  */
00247 tBleStatus aci_gatt_del_service(uint16_t servHandle);
00248 
00249 /**
00250  * @brief Delete the Include definition from the service.
00251  * @param servHandle Handle of the service to which Include definition belongs
00252  * @param includeServHandle Handle of the Included definition to be deleted
00253  * @return Value indicating success or error code.
00254  */
00255 tBleStatus aci_gatt_del_include_service(uint16_t servHandle, uint16_t includeServHandle);
00256 
00257 /**
00258  * @brief Perform an ATT MTU exchange procedure.
00259  * @note  When the ATT MTU exchange procedure is completed, a @ref EVT_BLUE_ATT_EXCHANGE_MTU_RESP
00260  *        event is generated. A @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is also generated
00261  *        to indicate the end of the procedure.
00262  * @param conn_handle Connection handle for which the command is given.
00263  * @return Value indicating success or error code.
00264  */
00265 tBleStatus aci_gatt_exchange_configuration(uint16_t conn_handle);
00266 
00267 /**
00268  * @brief Send a @a Find @a Information @a Request.
00269  * @note This command is used to obtain the mapping of attribute handles with their associated
00270  *       types. The responses of the procedure are given through the
00271  *       @ref EVT_BLUE_ATT_FIND_INFORMATION_RESP event. The end of the procedure is indicated by
00272  *       a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event.
00273  * @param conn_handle Connection handle for which the command is given
00274  * @param start_handle Starting handle of the range of attributes to be discovered on the server
00275  * @param end_handle Ending handle of the range of attributes to be discovered on the server
00276  * @return Value indicating success or error code.
00277  */
00278 tBleStatus aci_att_find_information_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle);
00279 
00280 /**
00281  * @brief Send a @a Find @a By @a Type @a Value @a Request
00282  * @note The Find By Type Value Request is used to obtain the handles of attributes that
00283  *       have a given 16-bit UUID attribute type and a given attribute value.
00284  *       The responses of the procedure are given through the @ref EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP event.
00285  *       The end of the procedure is indicated by a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event.
00286  * @param conn_handle Connection handle for which the command is given.
00287  * @param start_handle  First requested handle number
00288  * @param end_handle    Last requested handle number
00289  * @param uuid          2 octet UUID to find (little-endian)
00290  * @param attr_val_len  Length of attribute value (maximum value is ATT_MTU - 7).
00291  * @param attr_val      Attribute value to find
00292  * @return Value indicating success or error code.
00293  */
00294 tBleStatus aci_att_find_by_type_value_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle,
00295                                           uint8_t* uuid, uint8_t attr_val_len, uint8_t* attr_val);
00296 
00297 /**
00298  * @brief Send a @a Read @a By @a Type @a Request
00299  * @note  The Read By Type Request is used to obtain the values of attributes where the attribute type
00300  *        is known but the handle is not known.
00301  *        The responses of the procedure are given through the @ref EVT_BLUE_ATT_READ_BY_TYPE_RESP event.
00302  *        The end of the procedure is indicated by a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event.
00303  * @param conn_handle Connection handle for which the command is given.
00304  * @param start_handle First requested handle number
00305  * @param end_handle Last requested handle number
00306  * @param uuid_type @arg @ref UUID_TYPE_16
00307  *                  @arg @ref UUID_TYPE_128
00308  * @param uuid 2 or 16 octet UUID
00309  * @return Value indicating success or error code.
00310  */
00311 tBleStatus aci_att_read_by_type_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle,
00312                                     uint8_t  uuid_type, uint8_t* uuid);
00313 
00314 /**
00315  * @brief Send a @a Read @a By @a Group @a Type @a Request
00316  * @note The Read By Group Type Request is used to obtain the values of grouping attributes where the attribute
00317  *       type is known but the handle is not known. Grouping attributes are defined at GATT layer. The grouping
00318  *       attribute types are: «Primary Service», «Secondary Service» and «Characteristic».
00319  *       The responses of the procedure are given through the @ref EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP event.
00320  *       The end of the procedure is indicated by a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE.
00321  * @param conn_handle Connection handle for which the command is given.
00322  * @param start_handle First requested handle number
00323  * @param end_handle Last requested handle number
00324  * @param uuid_type @arg @ref UUID_TYPE_16
00325  *                  @arg @ref UUID_TYPE_128
00326  * @param uuid 2 or 16 octet UUID
00327  * @return Value indicating success or error code.
00328  */
00329 tBleStatus aci_att_read_by_group_type_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle,
00330                                     uint8_t  uuid_type, uint8_t* uuid);
00331 
00332 /**
00333  * @brief Send a @a Prepare @a Write @a Request
00334  * @note  The Prepare Write Request is used to request the server to prepare to write the value of an attribute.
00335  *       The responses of the procedure are given through the @ref EVT_BLUE_ATT_PREPARE_WRITE_RESP event.
00336  *       The end of the procedure is indicated by a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE.
00337  * @param conn_handle Connection handle for which the command is given.
00338  * @param attr_handle The handle of the attribute to be written
00339  * @param value_offset The offset of the first octet to be written
00340  * @param attr_val_len Length of attribute value (maximum value is ATT_MTU - 5).
00341  * @param attr_val     The value of the attribute to be written
00342  * @return Value indicating success or error code.
00343  */
00344 tBleStatus aci_att_prepare_write_req(uint16_t conn_handle, uint16_t attr_handle, uint16_t value_offset,
00345                                     uint8_t  attr_val_len, uint8_t* attr_val);
00346 
00347 /**
00348  * @brief Send an @a Execute @a Write @a Request
00349  * @note The Execute Write Request is used to request the server to write or cancel the write of all the
00350  *       prepared values currently held in the prepare queue from this client.
00351  *       The result of the procedure is given through the @ref EVT_BLUE_ATT_EXEC_WRITE_RESP event.
00352  *       The end of the procedure is indicated by a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event.
00353  * @param conn_handle Connection handle for which the command is given.
00354  * @param execute @arg 0x00 – Cancel all prepared writes
00355  *                @arg 0x01 – Immediately write all pending prepared values.
00356  * @return Value indicating success or error code.
00357  */
00358 tBleStatus aci_att_execute_write_req(uint16_t conn_handle, uint8_t execute);
00359 
00360 /**
00361  * @brief This command will start the GATT client procedure to discover all primary services on the server.
00362  * @note  The responses of the procedure are given through the @ref EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP event.
00363  *        The end of the procedure is indicated by a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event.
00364  * @param conn_handle Connection handle for which the command is given.
00365  * @return Value indicating success or error code.
00366  */
00367 tBleStatus aci_gatt_disc_all_prim_services(uint16_t conn_handle);
00368 
00369 /**
00370  * @brief Start the procedure to discover the primary services of the specified UUID on the server.
00371  * @note The responses of the procedure are given through the @ref EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP event.
00372  *       The end of the procedure is indicated by a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event.
00373  * @param conn_handle Connection handle for which the command is given.
00374  * @param uuid_type @arg @ref UUID_TYPE_16
00375  *                  @arg @ref UUID_TYPE_128
00376  * @param uuid 2 or 16 octet UUID
00377  * @return Value indicating success or error code.
00378  */
00379 tBleStatus aci_gatt_disc_prim_service_by_uuid(uint16_t conn_handle, uint8_t uuid_type, uint8_t* uuid);
00380 
00381 /**
00382  * @brief Start the procedure to find all included services.
00383  * @note The responses of the procedure are given through the @ref EVT_BLUE_ATT_READ_BY_TYPE_RESP event.
00384  *       The end of the procedure is indicated by a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event.
00385  * @param conn_handle Connection handle for which the command is given.
00386  * @param start_handle Start handle of the service
00387  * @param end_handle End handle of the service
00388  * @return Value indicating success or error code.
00389  */
00390 tBleStatus aci_gatt_find_included_services(uint16_t conn_handle, uint16_t start_handle,
00391                        uint16_t end_handle);
00392 
00393 /**
00394  * @brief Start the procedure to discover all the characteristics of a given service.
00395  * @note When the procedure is completed, a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is generated.
00396  *       Before procedure completion the response packets are given through @ref EVT_BLUE_ATT_READ_BY_TYPE_RESP event.
00397  * @param conn_handle Connection handle for which the command is given
00398  * @param start_attr_handle Start attribute handle of the service
00399  * @param end_attr_handle End attribute handle of the service
00400  * @return Value indicating success or error code.
00401  */
00402 tBleStatus aci_gatt_disc_all_charac_of_serv(uint16_t conn_handle, uint16_t start_attr_handle,
00403                         uint16_t end_attr_handle);
00404 
00405 /**
00406  * @brief Start the procedure to discover all the characteristics specified by a UUID.
00407  * @note  When the procedure is completed, a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is generated.
00408  *        Before procedure completion the response packets are given through
00409  *        @ref EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP event.
00410  * @param conn_handle Connection handle for which the command is given
00411  * @param start_handle  Start attribute handle of the service
00412  * @param end_handle    End attribute handle of the service
00413  * @param uuid_type @arg @ref UUID_TYPE_16
00414  *                  @arg @ref UUID_TYPE_128
00415  * @param uuid 2 or 16 octet UUID
00416  * @return Value indicating success or error code.
00417  */
00418 tBleStatus aci_gatt_disc_charac_by_uuid(uint16_t conn_handle, uint16_t start_handle,
00419                                      uint16_t end_handle, uint8_t uuid_type, const uint8_t* uuid);
00420 
00421 /**
00422  * @brief Start the procedure to discover all characteristic descriptors on the server.
00423  * @note When the procedure is completed, a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is generated.
00424  *       Before procedure completion the response packets are given through @ref EVT_BLUE_ATT_FIND_INFORMATION_RESP event.
00425  * @param conn_handle Connection handle for which the command is given.
00426  * @param char_val_handle Starting handle of the characteristic
00427  * @param char_end_handle End handle of the characteristic
00428  * @return Value indicating success or error code.
00429  */
00430 tBleStatus aci_gatt_disc_all_charac_descriptors(uint16_t conn_handle, uint16_t char_val_handle,
00431                         uint16_t char_end_handle);
00432 
00433 /**
00434  * @brief Start the procedure to read the attribute value.
00435  * @note  When the procedure is completed, a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is generated.
00436  *        Before procedure completion the response packet is given through @ref EVT_BLUE_ATT_READ_RESP event.
00437  * @param conn_handle Connection handle for which the command is given
00438  * @param attr_handle Handle of the characteristic to be read
00439  * @return Value indicating success or error code.\n
00440  *       It can be @ref BLE_STATUS_NOT_ALLOWED in the following cases:\n
00441  *      - If the exchange has already taken place\n
00442  *      - If GATT is expecting response for previous request\n
00443  *      - Already a request is in the queue to be sent\n
00444  *      - Channel not open\n
00445  *      - Already one GATT procedure is started
00446  */
00447 tBleStatus aci_gatt_read_charac_val(uint16_t conn_handle, uint16_t attr_handle);
00448 
00449 /**
00450  * @brief Start the procedure to read all the characteristics specified by the UUID.
00451  * @note When the procedure is completed, a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is generated.
00452  *       Before procedure completion the response packets are given through
00453  *       @ref EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP event.
00454  * @param conn_handle Connection handle for which the command is given
00455  * @param start_handle Starting handle of the range to be searched
00456  * @param end_handle End handle of the range to be searched
00457  * @param uuid_type @arg @ref UUID_TYPE_16
00458  *                  @arg @ref UUID_TYPE_128
00459  * @param uuid 2 or 16 octet UUID
00460  * @return Value indicating success or error code.
00461  */
00462 tBleStatus aci_gatt_read_using_charac_uuid(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle,
00463                                     uint8_t  uuid_type, uint8_t* uuid);
00464 
00465 /**
00466  * @brief Start the procedure to read a long characteristic value.
00467  * @note When the procedure is completed, a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is generated.
00468  *       Before procedure completion the response packets are given through @ref EVT_BLUE_ATT_READ_BLOB_RESP event.
00469  * @param conn_handle Connection handle for which the command is given
00470  * @param attr_handle Handle of the characteristic to be read
00471  * @param val_offset Offset from which the value needs to be read
00472  * @return Value indicating success or error code.\n
00473  *       It can be @ref BLE_STATUS_NOT_ALLOWED in the following cases:\n
00474  *      - If the exchange has already taken place\n
00475  *      - If GATT is expecting response for previous request\n
00476  *      - Already a request is in the queue to be sent\n
00477  *      - Channel not open\n
00478  *      - Already one GATT procedure is started
00479  */
00480 tBleStatus aci_gatt_read_long_charac_val(uint16_t conn_handle, uint16_t attr_handle,
00481                      uint16_t val_offset);
00482 
00483 /**
00484  * @brief Start a procedure to read multiple characteristic values from a server.
00485  * @note This sub-procedure is used to read multiple Characteristic Values from a server when the
00486  *       client knows the Characteristic Value Handles.
00487  *       When the procedure is completed, a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is generated.
00488  *       Before procedure completion the response packets are given through
00489  *       @ref EVT_BLUE_ATT_READ_MULTIPLE_RESP event.
00490  * @param conn_handle Connection handle for which the command is given
00491  * @param num_handles The number of handles for which the value has to be read
00492  * @param set_of_handles The handles for which the attribute value has to be read
00493  * @return Value indicating success or error code.
00494  */
00495 tBleStatus aci_gatt_read_multiple_charac_val(uint16_t conn_handle, uint8_t num_handles, 
00496                                              uint8_t* set_of_handles);
00497 
00498 /**
00499  * @brief Start the procedure to write a characteristic value.
00500  * @note When the procedure is completed, a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is generated.
00501  * @param conn_handle Connection handle for which the command is given
00502  * @param attr_handle Handle of the characteristic to be written
00503  * @param value_len Length of the value to be written
00504  * @param[in] attr_value Value to be written
00505  * @return Value indicating success or error code.\n
00506  *       It can be @ref BLE_STATUS_NOT_ALLOWED in the following cases:\n
00507  *      - If the exchange has already taken place\n
00508  *      - If GATT is expecting response for previous request\n
00509  *      - Already a request is in the queue to be sent\n
00510  *      - Channel not open\n
00511  *      - Already one GATT procedure is started
00512  */
00513 tBleStatus aci_gatt_write_charac_value(uint16_t conn_handle, uint16_t attr_handle,
00514                        uint8_t value_len, uint8_t *attr_value);
00515 
00516 /**
00517  * @brief Start the procedure to write a long characteristic value.
00518  * @note When the procedure is completed, a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is generated.
00519  *       During the procedure, @ref EVT_BLUE_ATT_PREPARE_WRITE_RESP and @ref EVT_BLUE_ATT_EXEC_WRITE_RESP
00520  *       events are raised.
00521  * @param conn_handle Connection handle for which the command is given
00522  * @param attr_handle Handle of the attribute to be written
00523  * @param val_offset Offset at which the attribute has to be written
00524  * @param val_len Length of the value to be written
00525  * @param attr_val Value to be written
00526  * @return Value indicating success or error code.
00527  */
00528 tBleStatus aci_gatt_write_long_charac_val(uint16_t conn_handle, uint16_t attr_handle,
00529                                           uint16_t val_offset, uint8_t val_len, const uint8_t* attr_val);
00530 
00531 /**
00532  * @brief Start the procedure to write a characteristic reliably.
00533  * @note When the procedure is completed, a  @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is generated.
00534  *       During the procedure, @ref EVT_BLUE_ATT_PREPARE_WRITE_RESP and @ref EVT_BLUE_ATT_EXEC_WRITE_RESP
00535  *       events are raised.
00536  * @param conn_handle Connection handle for which the command is given
00537  * @param attr_handle Handle of the attribute to be written
00538  * @param val_offset Offset at which the attribute has to be written
00539  * @param val_len Length of the value to be written
00540  * @param attr_val Value to be written
00541  * @return Value indicating success or error code.
00542  */
00543 tBleStatus aci_gatt_write_charac_reliable(uint16_t conn_handle, uint16_t attr_handle,
00544                                           uint16_t val_offset, uint8_t val_len, uint8_t* attr_val);
00545 
00546 /**
00547  * @brief Start the procedure to write a long characteristic descriptor.
00548  * @note When the procedure is completed, a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is generated.
00549  *       During the procedure, @ref EVT_BLUE_ATT_PREPARE_WRITE_RESP and @ref EVT_BLUE_ATT_EXEC_WRITE_RESP
00550  *       events are raised.
00551  * @param conn_handle Connection handle for which the command is given
00552  * @param attr_handle Handle of the attribute to be written
00553  * @param val_offset Offset at which the attribute has to be written
00554  * @param val_len Length of the value to be written
00555  * @param attr_val Value to be written
00556  * @return Value indicating success or error code.
00557  */
00558 tBleStatus aci_gatt_write_long_charac_desc(uint16_t conn_handle, uint16_t attr_handle,
00559                                           uint16_t val_offset, uint8_t val_len, uint8_t* attr_val);
00560 
00561 /**
00562  * @brief Start the procedure to read a long characteristic value.
00563  * @note  When the procedure is completed, a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is generated.
00564  *        Before procedure completion the response packets are given through @ref EVT_BLUE_ATT_READ_BLOB_RESP
00565  *        event.
00566  * @param conn_handle Connection handle for which the command is given
00567  * @param attr_handle Handle of the characteristic descriptor
00568  * @param val_offset Offset from which the value needs to be read
00569  * @return Value indicating success or error code.
00570  */
00571 tBleStatus aci_gatt_read_long_charac_desc(uint16_t conn_handle, uint16_t attr_handle,
00572                                           uint16_t val_offset);
00573 
00574 /**
00575  * @brief Start the procedure to write a characteristic descriptor.
00576  * @note When the procedure is completed, a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is generated.
00577  * @param conn_handle Connection handle for which the command is given
00578  * @param attr_handle Handle of the attribute to be written
00579  * @param value_len Length of the value to be written
00580  * @param[in] attr_value Value to be written
00581  * @return Value indicating success or error code.\n
00582  *       It can be @ref BLE_STATUS_NOT_ALLOWED in the following cases:\n
00583  *      - If the exchange has already taken place\n
00584  *      - If GATT is expecting response for previous request\n
00585  *      - Already a request is in the queue to be sent\n
00586  *      - Channel not open\n
00587  *      - Already one GATT procedure is started
00588  */
00589 tBleStatus aci_gatt_write_charac_descriptor(uint16_t conn_handle, uint16_t attr_handle,
00590                        uint8_t value_len, uint8_t *attr_value);
00591 
00592 /**
00593  * @brief Start the procedure to read the descriptor specified.
00594  * @note When the procedure is completed, a @ref EVT_BLUE_GATT_PROCEDURE_COMPLETE event is generated.
00595  *       Before procedure completion the response packet is given through @ref EVT_BLUE_ATT_READ_RESP event.
00596  * @param conn_handle Connection handle for which the command is given
00597  * @param attr_handle Handle of the descriptor to be read
00598  * @return Value indicating success or error code.
00599  */
00600 tBleStatus aci_gatt_read_charac_desc(uint16_t conn_handle, uint16_t attr_handle);
00601 
00602 /**
00603  * @brief Start the procedure to write a characteristic value without waiting for any response from the server.
00604  * @note No events are generated after this command is executed.
00605  * @param conn_handle Connection handle for which the command is given
00606  * @param attr_handle Handle of the attribute to be written
00607  * @param val_len Length of the value to be written (up to ATT_MTU - 3)
00608  * @param[in] attr_val Value to be written
00609  * @return Value indicating success or error code.\n
00610  *       It can be @ref BLE_STATUS_NOT_ALLOWED in the following cases:\n
00611  *      - If the exchange has already taken place\n
00612  *      - If GATT is expecting response for previous request\n
00613  *      - Already a request is in the queue to be sent\n
00614  *      - Channel not open\n
00615  *      - Already one GATT procedure is started
00616  */
00617 tBleStatus aci_gatt_write_without_response(uint16_t conn_handle, uint16_t attr_handle,
00618                                               uint8_t val_len, const uint8_t* attr_val);
00619 
00620 /**
00621  * @brief Start a signed write without response from the server.
00622  * @note  The procedure i used to write a characteristic value with an authentication signature without waiting
00623  *        for any response from the server. It cannot be used when the link is encrypted.
00624  * @param conn_handle Connection handle for which the command is given
00625  * @param attr_handle Handle of the attribute to be written
00626  * @param val_len Length of the value to be written (up to ATT_MTU - 13).
00627  * @param attr_val Value to be written
00628  * @return Value indicating success or error code
00629  */
00630 tBleStatus aci_gatt_signed_write_without_resp(uint16_t conn_handle, uint16_t attr_handle,
00631                                               uint8_t val_len, uint8_t* attr_val);
00632 
00633 /**
00634  * @brief Confirm an indication
00635  * @note  This command has to be sent when the application receives the event @ref EVT_BLUE_GATT_INDICATION.
00636  * @param conn_handle Connection handle for which the command is given.
00637  * @return Value indicating success or error code.
00638  */
00639 tBleStatus aci_gatt_confirm_indication(uint16_t conn_handle);
00640 
00641 /**
00642  * @brief Allow or reject a write request from a client.
00643  * @note This command has to be sent by the application when it receives the @ref EVT_BLUE_GATT_WRITE_PERMIT_REQ.
00644  *       If the write is allowed, then the status and error code has to be set to 0. If the write is not allowed,
00645  *       then the status has to be set to 1 and the error code has to be set to the error code that has to be
00646  *       passed to the client.
00647  * @param conn_handle Connection handle for which the command is given
00648  * @param attr_handle Handle of the attribute that was passed in the event @ref EVT_BLUE_GATT_WRITE_PERMIT_REQ.
00649  * @param write_status 0x00: The value can be written to the attribute specified by attr_handle\n
00650  *                     0x01: The value cannot be written to the attribute specified by the attr_handle.
00651  * @param err_code  The error code that has to be passed to the client in case the write has to be rejected.
00652  * @param att_val_len Length of the value to be written as passed in the event @ref EVT_BLUE_GATT_WRITE_PERMIT_REQ.
00653  * @param att_val Value as passed in the event @ref EVT_BLUE_GATT_WRITE_PERMIT_REQ.
00654  * @return Value indicating success or error code.
00655  */
00656 tBleStatus aci_gatt_write_response(uint16_t conn_handle,
00657                                    uint16_t attr_handle,
00658                                    uint8_t write_status,
00659                                    uint8_t err_code,
00660                                    uint8_t att_val_len,
00661                                    uint8_t *att_val);
00662 
00663 /**
00664  * @brief Allow the GATT server to send a response to a read request from a client.
00665  * @note The application has to send this command when it receives the @ref EVT_BLUE_GATT_READ_PERMIT_REQ
00666  *       or @ref EVT_BLUE_GATT_READ_MULTI_PERMIT_REQ. This command indicates to the stack that the response
00667  *       can be sent to the client. So if the application wishes to update any of the attributes before
00668  *       they are read by the client, it has to update the characteristic values using the aci_gatt_update_char_value
00669  *       and then give this command. The application should perform the required operations within 30 seconds,
00670  *       otherwise the GATT procedure will go to timeout.
00671  * @param conn_handle Connection handle for which the command is given.
00672  * @return Value indicating success or error code.
00673  */
00674 tBleStatus aci_gatt_allow_read(uint16_t conn_handle);
00675 
00676 /**
00677  * @brief Set the security permission for the attribute handle specified.
00678  * @note  Currently the setting of security permission is allowed only for client configuration descriptor.
00679  * @param service_handle Handle of the service which contains the attribute whose security
00680  *                       permission has to be modified.
00681  * @param attr_handle   Handle of the attribute whose security permission has to be modified.
00682  * @param security_permission Security permissions for the descriptor. See @ref Security_permissions "Security permissions".
00683  *          @arg ATTR_PERMISSION_NONE
00684  *          @arg ATTR_PERMISSION_AUTHEN_READ
00685  *          @arg ATTR_PERMISSION_AUTHOR_READ
00686  *          @arg ATTR_PERMISSION_ENCRY_READ
00687  *          @arg ATTR_PERMISSION_AUTHEN_WRITE
00688  *          @arg ATTR_PERMISSION_AUTHOR_WRITE
00689  *          @arg ATTR_PERMISSION_ENCRY_WRITE
00690  * @return Value indicating success or error code.
00691  */
00692 tBleStatus aci_gatt_set_security_permission(uint16_t service_handle, uint16_t attr_handle,
00693                                             uint8_t security_permission);
00694 
00695 /**
00696  * @brief This command sets the value of the descriptor specified by charDescHandle.
00697  * @param servHandle Handle of the service which contains the descriptor.
00698  * @param charHandle Handle of the characteristic which contains the descriptor.
00699  * @param charDescHandle Handle of the descriptor whose value has to be set.
00700  * @param charDescValOffset Offset from which the descriptor value has to be updated.
00701  * @param charDescValueLen Length of the descriptor value
00702  * @param[in] charDescValue descriptor value
00703  * @return Value indicating success or error code.
00704  */
00705 tBleStatus aci_gatt_set_desc_value(uint16_t servHandle,
00706                    uint16_t charHandle,
00707                    uint16_t charDescHandle,
00708                    uint16_t charDescValOffset,
00709                    uint8_t charDescValueLen,
00710                    const void *charDescValue);
00711 
00712 /**
00713  * @brief Reads the value of the attribute handle specified from the local GATT database.
00714  * @param attr_handle Handle of the attribute to read
00715  * @param data_len Length of the data buffer.
00716  * @param[in] data_len_out_p Length of the read attribute.
00717  * @param[in] data Pointer to the buffer that will contain the read value.
00718  *              The buffer will be filled with the attribute value.
00719  *              The length will be the minimum between the provided data_len and the actual length of the
00720  *              attribute (in data_len_out_p).
00721  * @return Value indicating success or error code.
00722  */
00723 tBleStatus aci_gatt_read_handle_value(uint16_t attr_handle, uint16_t data_len, uint16_t *data_len_out_p, uint8_t *data);
00724 
00725    /**
00726  * @brief Reads the value of the attribute handle specified from the local GATT database, starting from a given offset.
00727  * @param attr_handle Handle of the attribute to read
00728  * @param offset      Offset from which the value needs to be read
00729  * @param data_len    Length of the data buffer.
00730  * @param[in] data_len_out_p Length of the read attribute.
00731  * @param[in] data Pointer to the buffer that will contain the read value.
00732  *              The buffer will be filled with the attribute value.
00733  *              The length will be the minimum between the provided data_len and the actual length of the
00734  *              attribute (in data_len_out_p).
00735  * @return Value indicating success or error code.
00736  */
00737 tBleStatus aci_gatt_read_handle_value_offset_IDB05A1(uint16_t attr_handle, uint8_t offset, uint16_t data_len, uint16_t *data_len_out_p, uint8_t *data);
00738 
00739 /**
00740  * @}
00741  */
00742 
00743 
00744 /**
00745  * @defgroup GATT_Events GATT events
00746  * The structures are the data field of @ref evt_blue_aci.
00747  * @{
00748  */
00749 
00750 /**
00751  * This event is raised to the application by the GATT server when a client modifies any attribute on the server,
00752  * if event is enabled (see @ref Gatt_Event_Mask "Gatt Event Mask").
00753  * See @ref _evt_gatt_attr_modified_IDB04A1 or @ref _evt_gatt_attr_modified__IDB05A1.
00754  */
00755 #define EVT_BLUE_GATT_ATTRIBUTE_MODIFIED          (0x0C01)
00756 typedef __packed struct _evt_gatt_attr_modified_IDB05A1{
00757   uint16_t conn_handle; /**< The connection handle which modified the attribute. */
00758   uint16_t attr_handle; /**< Handle of the attribute that was modified. */
00759   uint8_t  data_length; /**< The length of the data */
00760   uint16_t  offset; /**< Offset from which the write has been performed by the peer device */
00761   uint8_t  att_data[VARIABLE_SIZE]; /**< The new value (length is data_length) */
00762 } PACKED evt_gatt_attr_modified_IDB05A1;
00763 
00764 typedef __packed struct _evt_gatt_attr_modified_IDB04A1{
00765   uint16_t conn_handle; /**< The connection handle which modified the attribute. */
00766   uint16_t attr_handle; /**< Handle of the attribute that was modified. */
00767   uint8_t  data_length; /**< The length of the data */
00768   uint8_t  att_data[VARIABLE_SIZE]; /**< The new value (length is data_length) */
00769 } PACKED evt_gatt_attr_modified_IDB04A1;
00770 
00771 /**
00772  * This event is generated by the client/server to the application on a GATT timeout (30 seconds).
00773  * See @ref _evt_gatt_procedure_timeout.
00774  */
00775 #define EVT_BLUE_GATT_PROCEDURE_TIMEOUT           (0x0C02)
00776 typedef __packed struct _evt_gatt_procedure_timeout{
00777     uint16_t conn_handle; /**< The connection handle on which the GATT procedure has timed out */
00778 } PACKED evt_gatt_procedure_timeout;
00779 
00780 /**
00781  * This event is generated in response to an Exchange MTU request. See aci_gatt_exchange_configuration().
00782  * See @ref _evt_att_exchange_mtu_resp.
00783  */
00784 #define EVT_BLUE_ATT_EXCHANGE_MTU_RESP        (0x0C03)
00785 typedef __packed struct _evt_att_exchange_mtu_resp{
00786   uint16_t conn_handle; /**< The connection handle related to the response */
00787   uint8_t  event_data_length; /**< Length of following data (always 1). */
00788   uint16_t server_rx_mtu; /**< Attribute server receive MTU size */
00789 } PACKED evt_att_exchange_mtu_resp;
00790 
00791 /**
00792  * This event is generated in response to a @a Find @a Information @a Request. See aci_att_find_information_req() and
00793  * Find Information Response in Bluetooth Core v4.0 spec. See @ref _evt_att_find_information_resp.
00794  */
00795 #define EVT_BLUE_ATT_FIND_INFORMATION_RESP    (0x0C04)
00796 typedef __packed struct _evt_att_find_information_resp{
00797   uint16_t conn_handle;         /**< The connection handle related to the response */
00798   uint8_t  event_data_length;   /**< Length of following data. */
00799   uint8_t  format;              /**< The format of the handle_uuid_pair. @arg 1: 16-bit UUIDs @arg 2: 128-bit UUIDs */
00800   /**
00801    *  A sequence of handle-uuid pairs.\n
00802    *  @li if format=1, each pair is:\n
00803    *  [2 octets for handle, 2 octets for UUIDs] \n
00804    *  @li if format=2, each pair is:\n
00805    *  [2 octets for handle, 16 octets for UUIDs]
00806    */
00807   uint8_t  handle_uuid_pair[VARIABLE_SIZE];
00808 } PACKED evt_att_find_information_resp;
00809 
00810 /**
00811  * This event is generated in response to a @a Find @a By @a Type @a Value @a Request. See
00812  * Find By Type Value Response in Bluetooth Core v4.0 spec. See @ref _evt_att_find_by_type_val_resp.
00813  */
00814 #define EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP    (0x0C05)
00815 typedef __packed struct _evt_att_find_by_type_val_resp{
00816   uint16_t conn_handle;             /**< The connection handle related to the response */
00817   uint8_t  event_data_length;       /**< Length of following data. */
00818   /**
00819    *  Handles Information List as defined in Bluetooth Core v4.0 spec.
00820    *  A sequence of handle pairs: [2 octets for Found Attribute Handle, 2 octets for Group End Handle]
00821    */
00822   uint8_t  handles_info_list[VARIABLE_SIZE];
00823 } PACKED evt_att_find_by_type_val_resp;
00824 
00825 /**
00826  * This event is generated in response to a @a Read @a By @a Type @a Request. See aci_gatt_find_included_services() and
00827  * aci_gatt_disc_all_charac_of_serv().
00828  * For more info see Read By Type Response in Bluetooth Core v4.0 spec. See @ref _evt_att_read_by_type_resp.
00829  */
00830 #define EVT_BLUE_ATT_READ_BY_TYPE_RESP        (0x0C06)
00831 typedef __packed struct _evt_att_read_by_type_resp{
00832   uint16_t conn_handle;             /**< The connection handle related to the response */
00833   uint8_t  event_data_length;       /**< Length of following data. */
00834   uint8_t  handle_value_pair_length; /**< The size of each attribute handle-value pair */
00835   /**
00836    *  Attribute Data List as defined in Bluetooth Core v4.0 spec.
00837    *  A sequence of handle-value pairs: [2 octets for Attribute Handle, (handle_value_pair_length - 2 octets) for Attribute Value]
00838    */
00839   uint8_t  handle_value_pair[VARIABLE_SIZE];
00840 } PACKED evt_att_read_by_type_resp;
00841 
00842 /**
00843  * This event is generated in response to a @a Read @a Request. See aci_gatt_read_charac_val().
00844  * For more info see Read Response in Bluetooth Core v4.0 spec. See @ref _evt_att_read_resp.
00845  */
00846 #define EVT_BLUE_ATT_READ_RESP            (0x0C07)
00847 typedef __packed struct _evt_att_read_resp{
00848   uint16_t conn_handle;             /**< The connection handle related to the response. */
00849   uint8_t  event_data_length;       /**< Length of following data. */
00850   uint8_t  attribute_value[VARIABLE_SIZE]; /**< The value of the attribute. */
00851 } PACKED evt_att_read_resp;
00852 
00853 /**
00854  * This event is generated in response to a @a Read @a Blob @a Request. See aci_gatt_read_long_charac_val().
00855  * For more info see Read Blob Response in Bluetooth Core v4.0 spec. See @ref _evt_att_read_blob_resp.
00856  */
00857 #define EVT_BLUE_ATT_READ_BLOB_RESP       (0x0C08)
00858 typedef __packed struct _evt_att_read_blob_resp{
00859   uint16_t conn_handle;             /**< The connection handle related to the response. */
00860   uint8_t  event_data_length;       /**< Length of following data. */
00861   uint8_t  part_attribute_value[VARIABLE_SIZE]; /**< Part of the attribute value. */
00862 } PACKED evt_att_read_blob_resp;
00863 
00864 /**
00865  * This event is generated in response to a @a Read @a Multiple @a Request.
00866  * For more info see Read Multiple Response in Bluetooth Core v4.0 spec. See @ref _evt_att_read_mult_resp.
00867  */
00868 #define EVT_BLUE_ATT_READ_MULTIPLE_RESP       (0x0C09)
00869 typedef __packed struct _evt_att_read_mult_resp{
00870   uint16_t conn_handle;             /**< The connection handle related to the response. */
00871   uint8_t  event_data_length;       /**< Length of following data. */
00872   uint8_t  set_of_values[VARIABLE_SIZE]; /**< A set of two or more values.*/
00873 } PACKED evt_att_read_mult_resp;
00874 
00875 /**
00876  * This event is generated in response to a @a Read @a By @a Group @a Type @a Request. See aci_gatt_disc_all_prim_services().
00877  * For more info see Read By Group type Response in Bluetooth Core v4.0 spec. See @ref _evt_att_read_by_group_resp.
00878  */
00879 #define EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP           (0x0C0A)
00880 typedef __packed struct _evt_att_read_by_group_resp{
00881   uint16_t conn_handle;             /**< The connection handle related to the response. */
00882   uint8_t  event_data_length;       /**< Length of following data. */
00883   uint8_t  attribute_data_length;   /**< The size of each Attribute Data. */
00884   /**
00885    *  A list of Attribute Data where the attribute data is composed by:
00886    *  @li 2 octets for Attribute Handle
00887    *  @li 2 octets for End Group Handle
00888    *  @li (attribute_data_length - 4) octets for Attribute Value
00889    */
00890   uint8_t  attribute_data_list[VARIABLE_SIZE];
00891 } PACKED evt_att_read_by_group_resp;
00892 
00893 /**
00894  * This event is generated in response to a @a Prepare @a Write @a Request.
00895  * For more info see Prepare Write Response in Bluetooth Core v4.0 spec. See @ref _evt_att_prepare_write_resp.
00896  */
00897 #define EVT_BLUE_ATT_PREPARE_WRITE_RESP       (0x0C0C)
00898 typedef __packed struct _evt_att_prepare_write_resp{
00899   uint16_t conn_handle;             /**< The connection handle related to the response. */
00900   uint8_t  event_data_length;       /**< Length of following data. */
00901   uint16_t  attribute_handle;       /**< The handle of the attribute to be written. */
00902   uint16_t  offset;                 /**< The offset of the first octet to be written. */
00903   uint8_t  part_attr_value[VARIABLE_SIZE]; /**< The value of the attribute to be written. */
00904 } PACKED evt_att_prepare_write_resp;
00905 
00906 /**
00907  * This event is generated in response to an @a Execute @a Write @a Request.
00908  * For more info see Execute Write Response in Bluetooth Core v4.0 spec. See @ref _evt_att_exec_write_resp.
00909  */
00910 #define EVT_BLUE_ATT_EXEC_WRITE_RESP          (0x0C0D)
00911 typedef __packed struct _evt_att_exec_write_resp{
00912   uint16_t conn_handle;         /**< The connection handle related to the response. */
00913   uint8_t  event_data_length;   /**< Always 0. */
00914 } PACKED evt_att_exec_write_resp;
00915 
00916 /**
00917  * This event is generated when an indication is received from the server.
00918  * For more info see Handle Value Indication in Bluetooth Core v4.0 spec. See @ref _evt_gatt_indication.
00919  */
00920 #define EVT_BLUE_GATT_INDICATION          (0x0C0E)
00921 typedef __packed struct _evt_gatt_indication{
00922   uint16_t conn_handle;                 /**< The connection handle related to the event. */
00923   uint8_t  event_data_length;           /**< Length of following data. */
00924   uint16_t attr_handle;                 /**< The handle of the attribute. */
00925   uint8_t  attr_value[VARIABLE_SIZE];   /**< The current value of the attribute. */
00926 } PACKED evt_gatt_indication;
00927 
00928 /**
00929  * This event is generated when a notification is received from the server.
00930  * For more info see Handle Value Notification in Bluetooth Core v4.0 spec. See @ref _evt_gatt_notification.
00931  */
00932 #define EVT_BLUE_GATT_NOTIFICATION        (0x0C0F)
00933 typedef __packed struct _evt_gatt_notification{
00934   uint16_t conn_handle;                 /**< The connection handle related to the event. */
00935   uint8_t  event_data_length;           /**< Length of following data. */
00936   uint16_t attr_handle;                 /**< The handle of the attribute. */
00937   uint8_t  attr_value[VARIABLE_SIZE];   /**< The current value of the attribute. */
00938 } PACKED evt_gatt_attr_notification;
00939 
00940 /**
00941  * This event is generated when a GATT client procedure completes either with error or successfully.
00942  * See @ref _evt_gatt_procedure_complete.
00943  */
00944 #define EVT_BLUE_GATT_PROCEDURE_COMPLETE          (0x0C10)
00945 typedef __packed struct _evt_gatt_procedure_complete{
00946   uint16_t conn_handle; /**< The connection handle on which the GATT procedure has completed */
00947   uint8_t  data_length; /**< Length of error_code field (always 1). */
00948   /**
00949    * Indicates whether the procedure completed with error (BLE_STATUS_FAILED) or was successful (BLE_STATUS_SUCCESS).
00950    */
00951   uint8_t  error_code;
00952 } PACKED evt_gatt_procedure_complete;
00953 
00954 /**
00955  * This event is generated when an Error Response is received from the server. The error response can be given
00956  * by the server at the end of one of the GATT discovery procedures. This does not mean that the procedure ended
00957  * with an error, but this error event is part of the procedure itself. See @ref _evt_gatt_error_resp.
00958  */
00959 #define EVT_BLUE_GATT_ERROR_RESP                  (0x0C11)
00960 typedef __packed struct _evt_gatt_error_resp{
00961   uint16_t conn_handle;         /**< The connection handle related to the event. */
00962   uint8_t  event_data_length;   /**< Length of following data. */
00963   uint8_t  req_opcode;          /**< The request that generated this error response. */
00964   uint16_t attr_handle;         /**< The attribute handle that generated this error response. */
00965   uint8_t  error_code;          /**< The reason why the request has generated an error response. See Error Response in Bluetooth Core v4.0 spec.  */
00966 } PACKED evt_gatt_error_resp;
00967 
00968 /**
00969  * This event can be generated during a "Discover Characteristics By UUID" procedure or a "Read using
00970  * Characteristic UUID" procedure.
00971  * The attribute value will be a service declaration as defined in Bluetooth Core v4.0 spec (vol.3, Part G, ch. 3.3.1),
00972  * when a "Discover Characteristics By UUID" has been started. It will be the value of the Characteristic if a
00973  * "Read using Characteristic UUID" has been performed. See @ref _evt_gatt_disc_read_char_by_uuid_resp.
00974  */
00975 #define EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP (0x0C12)
00976 typedef __packed struct _evt_gatt_disc_read_char_by_uuid_resp{
00977   uint16_t conn_handle;                     /**< The connection handle related to the event. */
00978   uint8_t  event_data_length;               /**< Length of following data. */
00979   uint16_t attr_handle;                     /**< The handle of the attribute. */
00980   /**
00981    * The attribute value will be a service declaration as defined in Bluetooth Core v4.0 spec (vol.3, Part G, ch. 3.3.1),
00982    * when a "Discover Characteristics By UUID" has been started. It will be the value of the Characteristic if a
00983    * "Read using Characteristic UUID" has been performed.
00984    */
00985   uint8_t  attr_value[VARIABLE_SIZE];
00986 } PACKED evt_gatt_disc_read_char_by_uuid_resp;
00987 
00988 /**
00989  * This event is given to the application when a write request, write command or signed write command
00990  * is received by the server from the client. This event will be given to the application only if the
00991  * event bit for this event generation is set when the characteristic was added.
00992  * When this event is received, the application has to check whether the value being requested for write
00993  * is allowed to be written and respond with the command aci_gatt_write_response().
00994  * If the write is rejected by the application, then the value of the attribute will not be modified.
00995  * In case of a write request, an error response will be sent to the client, with the error code as specified by the application.
00996  * In case of write/signed write commands, no response is sent to the client but the attribute is not modified.
00997  * See @ref evt_gatt_write_permit_req.
00998  */
00999 #define EVT_BLUE_GATT_WRITE_PERMIT_REQ            (0x0C13)
01000 typedef __packed struct _evt_gatt_write_permit_req{
01001   uint16_t conn_handle; /**< Handle of the connection on which there was the request to write the attribute. */
01002   uint16_t attr_handle; /**< The handle of the attribute for which the write request has been made by the client */
01003   uint8_t  data_length; /**< Length of data field. */
01004   uint8_t  data[VARIABLE_SIZE]; /**< The data that the client has requested to write */
01005 } PACKED evt_gatt_write_permit_req;
01006 
01007 /**
01008  * This event is given to the application when a read request or read blob request is received by the server
01009  * from the client. This event will be given to the application only if the event bit for this event generation
01010  * is set when the characteristic was added.
01011  * On receiving this event, the application can update the value of the handle if it desires and when done
01012  * it has to use the aci_gatt_allow_read() command to indicate to the stack that it can send the response to the client.
01013  * See @ref evt_gatt_read_permit_req.
01014  *
01015  */
01016 #define EVT_BLUE_GATT_READ_PERMIT_REQ             (0x0C14)
01017 typedef __packed struct _evt_gatt_read_permit_req{
01018   uint16_t conn_handle; /**< Handle of the connection on which there was the request to read the attribute. */
01019   uint16_t attr_handle; /**< The handle of the attribute for which the read request has been made by the client */
01020   uint8_t  data_length; /**< Length of offset field. (always 1). */
01021   uint8_t  offset;      /**< Contains the offset from which the read has been requested */
01022 } PACKED evt_gatt_read_permit_req;
01023 
01024 /**
01025  * This event is given to the application when a read multiple request or read by type request is received
01026  * by the server from the client. This event will be given to the application only if the event bit for this
01027  * event generation is set when the characteristic was added.
01028  * On receiving this event, the application can update the values of the handles if it desires and when done
01029  * it has to send the aci_gatt_allow_read command to indicate to the stack that it can send the response to the client.
01030  * See @ref evt_gatt_read_multi_permit_req.
01031  *
01032  */
01033 #define EVT_BLUE_GATT_READ_MULTI_PERMIT_REQ       (0x0C15)
01034 typedef __packed struct _evt_gatt_read_multi_permit_req{
01035   uint16_t conn_handle; /**< Handle of the connection on which there was the request to read the attribute. */
01036   uint8_t  data_length; /**< Length of data field. */
01037   uint8_t  data[VARIABLE_SIZE]; /**< The handles of the attributes that have been requested by the client for a read. */
01038 } PACKED evt_gatt_read_multi_permit_req;
01039 
01040 /**
01041  * This event is raised when the number of available TX buffers is above a threshold TH (TH = 2).
01042  * The event will be given only if a previous ACI command returned with BLE_STATUS_INSUFFICIENT_RESOURCES.
01043  * On receiving this event, the application can continue to send notifications by calling aci_gatt_update_char_value().
01044  * See @ref evt_gatt_tx_pool_vailable.
01045  *
01046  */
01047 #define EVT_BLUE_GATT_TX_POOL_AVAILABLE_IDB05A1   (0x0C16)
01048 typedef __packed struct _evt_gatt_tx_pool_available{
01049   uint16_t conn_handle; /**< Handle of the connection on which there was the request to read the attribute. */
01050   uint16_t available_buffers; /**< Length of data field. */
01051 } PACKED evt_gatt_tx_pool_available;
01052 
01053 /**
01054  * This event is raised on the server when the client confirms the reception of an indication.
01055  */
01056 #define EVT_BLUE_GATT_SERVER_CONFIRMATION_EVENT_IDB05A1 (0x0C17)
01057 typedef __packed struct _evt_gatt_server_confirmation{
01058   uint16_t conn_handle; /**< Handle of the connection on which there was the request to read the attribute. */
01059   uint16_t reserved; /**< Not used. */
01060 } PACKED evt_gatt_server_confirmation;
01061 
01062 /**
01063  * @}
01064  */
01065 
01066 /**
01067  * @}
01068  */
01069 
01070 #endif /* __BLUENRG_GATT_ACI_H__ */