BLE shield

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