1 #ifndef GATTC_TASK_INT_H_
2 #define GATTC_TASK_INT_H_
3 
4 /**
5  ****************************************************************************************
6  * @addtogroup GATTC_INT Internals
7  * @ingroup GATTC
8  * @brief Internal features of the GATTC module
9  *
10  * @{
11  ****************************************************************************************
12  */
13 /*
14  * INCLUDE FILES
15  ****************************************************************************************
16  */
17 #include "rwip_config.h"
18 
19 #if (BLE_GATTC)
20 #include "gattc.h"
21 #include "gattc_task.h"
22 #include "ke_task.h"
23 
24 /*
25  * DEFINES
26  ****************************************************************************************
27  */
28 /// retrieve on-going operation command
29 #define GATT_OPERATION_CMD(conidx, op_type, cmd) \
30     ((struct cmd*) gattc_get_operation_ptr(conidx, op_type))
31 
32 #define GATT_WRITE_ERROR_CODE (0xFFFF)
33 
34 
35 /// number of GATT Controller Process
36 #define GATTC_IDX_MAX                                 BLE_CONNECTION_MAX
37 
38 
39 
40 /// states of GATT Controller task
41 enum gattc_state_id
42 {
43     /// Connection ready state
44     GATTC_READY = 0,
45     #if (BLE_ATTC)
46     /// Client operation on-going
47     GATTC_CLIENT_BUSY       = (1 << GATTC_OP_CLIENT),
48     /// Service Discovery Procedure operation on-going
49     GATTC_SDP_BUSY          = (1 << GATTC_OP_SDP),
50     #endif // (BLE_ATTC)
51     #if (BLE_ATTS)
52     /// Server operation on-going
53     GATTC_SERVER_BUSY       = (1 << GATTC_OP_SERVER),
54     GATTC_ATTS_BUSY         = (1 << GATTC_OP_MAX),
55     #endif // (BLE_ATTS)
56     /// Connection started but ATTS not ready
57     GATTC_CONNECTED         = (1 << (GATTC_OP_MAX + 1)),
58 
59     /// Free state
60     GATTC_FREE              = (1 << (GATTC_OP_MAX + 2)),
61     /// Number of defined states.
62     GATTC_STATE_MAX
63 };
64 
65 
66 
67 /*
68  * TYPE DEFINITIONS
69  ****************************************************************************************
70  */
71 
72 
73 
74 /*
75  * GLOBAL VARIABLE DECLARATIONS
76  ****************************************************************************************
77  */
78 extern struct gattc_env_tag* gattc_env[GATTC_IDX_MAX];
79 
80 /*
81  * FUNCTION DECLARATIONS
82  ****************************************************************************************
83  */
84 
85 
86 /**
87  ****************************************************************************************
88  * @brief Initialization of the GATT controller module.
89  * This function performs all the initialization steps of the GATT module.
90  *
91  * @param[in] reset  true if it's requested by a reset; false if it's boot initialization
92  *
93  ****************************************************************************************
94  */
95 void gattc_init(bool reset);
96 
97 
98 /**
99  ****************************************************************************************
100  * @brief Initialize GATT controller for connection.
101  *
102  * @param[in] conidx    connection record index
103  * @param[in] role   device role after connection establishment
104  *
105  ****************************************************************************************
106  */
107 void gattc_create(uint8_t conidx);
108 
109 
110 
111 /**
112  ****************************************************************************************
113  * @brief Cleanup GATT controller resources for connection
114  *
115  * @param[in] conidx   connection record index
116  *
117  ****************************************************************************************
118  */
119 void gattc_cleanup(uint8_t conidx);
120 
121 /**
122  * @brief Send a complete event of ongoing executed operation to requester.
123  * It also clean-up variable used for ongoing operation.
124  *
125  * @param[in] conidx Connection index
126  * @param[in] op_type       Operation type.
127  * @param[in] status Status of completed operation
128  */
129 void gattc_send_complete_evt(uint8_t conidx, uint8_t op_type, uint8_t status);
130 
131 /**
132  ****************************************************************************************
133  * @brief Send operation completed message with status error code not related to a
134  * running operation.
135  *
136  * @param[in] conidx    Connection index
137  * @param[in] operation Operation code
138  * @param[in] seq_num   Operation sequence number
139  * @param[in] requester requester of operation
140  * @param[in] status    Error status code
141  ****************************************************************************************
142  */
143 void gattc_send_error_evt(uint8_t conidx, uint8_t operation, uint16_t seq_num, const ke_task_id_t requester, uint8_t status);
144 
145 
146 /**
147  ****************************************************************************************
148  * @brief Get operation on going
149  *
150  * @param[in] conidx        Connection Index
151  * @param[in] op_type       Operation type.
152  *
153  * @return operation code on going
154  ****************************************************************************************
155  */
156 uint8_t gattc_get_operation(uint8_t conidx, uint8_t op_type);
157 
158 /**
159  ****************************************************************************************
160  * @brief Get operation pointer
161  *
162  * @param[in] conidx        Connection Index
163  * @param[in] op_type       Operation type.
164  *
165  * @return operation pointer on going
166  ****************************************************************************************
167  */
168 void* gattc_get_operation_ptr(uint8_t conidx, uint8_t op_type);
169 
170 
171 /**
172  ****************************************************************************************
173  * @brief Set operation pointer
174  *
175  * @param[in] conidx        Connection Index
176  * @param[in] op_type       Operation type.
177  * @param[in] op            Operation pointer.
178  *
179  ****************************************************************************************
180  */
181 void gattc_set_operation_ptr(uint8_t conidx, uint8_t op_type, void* op);
182 
183 /**
184  ****************************************************************************************
185  * @brief Operation execution not finish, request kernel to reschedule it in order to
186  * continue its execution
187  *
188  * @param[in] conidx        Connection Index
189  * @param[in] op_type       Operation type.
190  *
191  * @return if operation has been rescheduled (not done if operation pointer is null)
192  ****************************************************************************************
193  */
194 bool gattc_reschedule_operation(uint8_t conidx, uint8_t op_type);
195 
196 /**
197  ****************************************************************************************
198  * @brief Get requester of on going operation
199  *
200  * @param[in] conidx        Connection Index
201  * @param[in] op_type       Operation type.
202  *
203  * @return task that requests to execute the operation
204  ****************************************************************************************
205  */
206 ke_task_id_t gattc_get_requester(uint8_t conidx, uint8_t op_type);
207 
208 
209 
210 /**
211  ****************************************************************************************
212  * @brief Get Operation Sequence Number
213  *
214  * @param[in] conidx        Connection Index
215  * @param[in] op_type       Operation type.
216  *
217  * @return Sequence number provided for operation execution
218  ****************************************************************************************
219  */
220 uint16_t gattc_get_op_seq_num(uint8_t conidx, uint8_t op_type);
221 
222 
223 /**
224  ****************************************************************************************
225  * @brief Update task state
226  *
227  * @param[in] conidx Connection index
228  * @param[in] state to update
229  * @param[in] set state to busy (true) or idle (false)
230  *
231  ****************************************************************************************
232  */
233 void gattc_update_state(uint8_t conidx, ke_state_t state, bool busy);
234 
235 
236 /*
237  * TASK DESCRIPTOR DECLARATIONS
238  ****************************************************************************************
239  */
240 
241 
242 #endif // (BLE_GATTC)
243 
244 /// @} GATTCTASK
245 #endif // GATTC_INT
246