1 /**
2  ****************************************************************************************
3  *
4  * @file gattc.h
5  *
6  * @brief Header file - GATT Controller.
7  *
8  * Copyright (C) RivieraWaves 2009-2016
9  *
10  *
11  ****************************************************************************************
12  */
13 
14 #ifndef GATTC_H_
15 #define GATTC_H_
16 
17 /**
18  ****************************************************************************************
19  * @addtogroup GATTC Generic Attribute Profile Controller
20  * @ingroup GATT
21  * @brief Generic Attribute Profile Controller.
22  *
23  * This GATT module is responsible for providing an API for all attribute related operations
24  * related to a BLE connection.
25  * It is responsible for all the service framework activities using the Attribute protocol
26  * for discovering services and for reading and writing characteristic values on a peer device.
27  * To achieve this, the GATT interfaces with @ref ATTC "ATTC" and the @ref ATTS "ATTS".
28  *
29  * @{
30  ****************************************************************************************
31  */
32 
33 /*
34  * INCLUDE FILES
35  ****************************************************************************************
36  */
37 /* kernel task */
38 #include "rwip_config.h"
39 #if (BLE_GATTC)
40 
41 #include "co_list.h"
42 
43 
44 /*
45  * DEFINES
46  ****************************************************************************************
47  */
48 
49 /// Operation type
50 enum gattc_op_type
51 {
52     #if (BLE_ATTS)
53     /// Operation used to Server Request operations
54     GATTC_OP_SERVER,
55     #endif // (BLE_ATTS)
56 
57     #if (BLE_ATTC)
58     /// Operation used to Client Request operations
59     GATTC_OP_CLIENT,
60     /// Service Discovery Procedure operation
61     GATTC_OP_SDP,
62     #endif // (BLE_ATTC)
63 
64     /// Max number of operations
65     GATTC_OP_MAX
66 };
67 
68 /*
69  * TYPES DEFINITIONS
70  ****************************************************************************************
71  */
72 
73 #if (BLE_ATTC)
74 /// Attribute Client environment variable requirements
75 struct attc_env
76 {
77     /// List of ATT message used to aggregate long value in a single buffer.
78     struct co_list rsp_list;
79     /// List that contains peer device event registration
80     struct co_list reg_evt;
81     /// List that contains data for service discovery
82     struct co_list sdp_data;
83 };
84 #endif // (BLE_ATTC)
85 
86 #if (BLE_ATTS)
87 /// Attribute server environment variables
88 struct atts_env
89 {
90     /// This is used to merge save all the prepare write request received ,
91     /// before receiving the execute or cancel or disconnection.
92     struct co_list             prep_wr_req_list;
93     /// This list is used to put any data in order to send a response to peer device
94     struct co_list             rsp;
95     /// List of PDU to process
96     struct co_list             pdu_queue;
97     /// This structure is used to store in cache latest attribute read value
98     struct gattc_read_cfm*     read_cache;
99 };
100 #endif // (BLE_ATTS)
101 
102 /// GATT controller environment variable structure.
103 struct gattc_env_tag
104 {
105     /// Request operation Kernel message
106     void* operation[GATTC_OP_MAX];
107 
108     #if (BLE_ATTC)
109     struct attc_env client;
110     #endif // (BLE_ATTC)
111 
112     #if (BLE_ATTS)
113     struct atts_env server;
114     #endif // (BLE_ATTS)
115 
116     /// Current MTU Size
117     uint16_t mtu_size;
118 
119     /// A transaction timeout occurs, reject next attribute commands
120     bool     trans_timeout;
121 };
122 /*
123  * MACRO DEFINITIONS
124  ****************************************************************************************
125  */
126 
127 
128 /*
129  * FUNCTION DECLARATIONS
130  ****************************************************************************************
131  */
132 
133 
134 /**
135  ****************************************************************************************
136  * @brief Created link connection parameters (from bond data) has been set, connection
137  * ready to be used.
138  *
139  * @param[in] conidx     Connection Index
140  *
141  ****************************************************************************************
142  */
143 void gattc_con_enable(uint8_t conidx);
144 
145 
146 /**
147  ****************************************************************************************
148  * @brief Gets the negotiated MTU. This function gets the negotiated MTU.
149  *
150  * @param[in] idx   connection record index
151  *
152  * @return MTU negotiated
153  *
154  ****************************************************************************************
155  */
156 uint16_t gattc_get_mtu(uint8_t idx);
157 
158 /**
159  ****************************************************************************************
160  * @brief Sets the negotiated MTU This function stores the negotiated MTU.
161  *
162  * @param[in] idx   connection record index
163  * @param[in] mtu   negotiated MTU
164  *
165  * @return status   indicates if the MTU setting operation is successful
166  *
167  ****************************************************************************************
168  */
169 void gattc_set_mtu(uint8_t idx, uint16_t mtu);
170 
171 
172 
173 #endif /* (BLE_GATTC) */
174 
175 /// @} GATTC
176 #endif // GATTC_H_
177