• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 GOODIX.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /*
17  * INCLUDE FILES
18  *****************************************************************************************
19  */
20 #include "gr55xx_sys.h"
21 #include "user_app.h"
22 #include "app_log.h"
23 
24 /*
25  * LOCAL FUNCTION DECLARATION
26  *****************************************************************************************
27  */
28 static void app_gap_param_set_cb(uint8_t status, const gap_param_set_op_id_t set_param_op);
29 static void app_gap_psm_manager_cb(uint8_t status, const gap_psm_manager_op_id_t psm_op);
30 static void app_gap_phy_update_cb(uint8_t conn_idx, uint8_t status, const gap_le_phy_ind_t *p_phy_ind);
31 static void app_gap_dev_info_get_cb(uint8_t status, const gap_dev_info_get_t *p_dev_info);
32 static void app_gap_adv_start_cb(uint8_t inst_idx, uint8_t status);
33 static void app_gap_adv_stop_cb(uint8_t inst_idx, uint8_t status, gap_stopped_reason_t reason);
34 static void app_gap_scan_req_ind_cb(uint8_t inst_idx, const gap_bdaddr_t *p_scanner_addr);
35 static void app_gap_adv_data_update_cb(uint8_t inst_idx, uint8_t status);
36 static void app_gap_scan_start_cb(uint8_t status);
37 static void app_gap_scan_stop_cb(uint8_t status, gap_stopped_reason_t reason);
38 static void app_gap_adv_report_ind_cb(const gap_ext_adv_report_ind_t  *p_adv_report);
39 static void app_gap_sync_establish_cb(uint8_t inst_idx, uint8_t status, \
40                                       const gap_sync_established_ind_t *p_sync_established_info);
41 static void app_gap_stop_sync_cb(uint8_t inst_idx, uint8_t status);
42 static void app_gap_sync_lost_cb(uint8_t inst_idx);
43 static void app_gap_connect_cb(uint8_t conn_idx, uint8_t status, const gap_conn_cmp_t *p_conn_param);
44 static void app_gap_disconnect_cb(uint8_t conn_idx, uint8_t status, uint8_t reason);
45 static void app_gap_connect_cancel_cb(uint8_t status);
46 static void app_gap_auto_connection_timeout_cb(void);
47 static void app_gap_peer_name_ind_cb(uint8_t conn_idx, const gap_peer_name_ind_t  *p_peer_name);
48 static void app_gap_connection_update_cb(uint8_t conn_idx, uint8_t status,
49                                          const gap_conn_update_cmp_t *p_conn_param_update_info);
50 static void app_gap_connection_update_req_cb(uint8_t conn_idx, const gap_conn_param_t *p_conn_param_update_req);
51 static void app_gap_connection_info_get_cb(uint8_t conn_idx, uint8_t status, const gap_conn_info_param_t *p_conn_info);
52 static void app_gap_peer_info_get_cb(uint8_t conn_idx,  uint8_t status, const gap_peer_info_param_t *p_peer_dev_info);
53 static void app_gap_le_pkt_size_info_cb(uint8_t conn_idx,  uint8_t status,
54                                         const gap_le_pkt_size_ind_t *p_supported_data_length_size);
55 
56 /*
57  * GLOBAL VARIABLE DEFINITIONS
58  *****************************************************************************************
59  */
60 const gap_cb_fun_t app_gap_callbacks = {
61     // -------------------------  Common Callbacks       ---------------------------------
62     .app_gap_param_set_cb               = app_gap_param_set_cb,
63     .app_gap_psm_manager_cb             = app_gap_psm_manager_cb,
64     .app_gap_phy_update_cb              = app_gap_phy_update_cb,
65     .app_gap_dev_info_get_cb            = app_gap_dev_info_get_cb,
66 
67     // -------------------------  Advertising Callbacks       ----------------------------
68     .app_gap_adv_start_cb               = app_gap_adv_start_cb,
69     .app_gap_adv_stop_cb                = app_gap_adv_stop_cb,
70     .app_gap_scan_req_ind_cb            = app_gap_scan_req_ind_cb,
71     .app_gap_adv_data_update_cb         = app_gap_adv_data_update_cb,
72 
73     // --------------------  Scanning/Periodic Synchronization Callbacks  ----------------
74     .app_gap_scan_start_cb              = app_gap_scan_start_cb,
75     .app_gap_scan_stop_cb               = app_gap_scan_stop_cb,
76     .app_gap_adv_report_ind_cb          = app_gap_adv_report_ind_cb,
77     .app_gap_sync_establish_cb          = app_gap_sync_establish_cb,
78     .app_gap_stop_sync_cb               = app_gap_stop_sync_cb,
79     .app_gap_sync_lost_cb               = app_gap_sync_lost_cb,
80 
81     // -------------------------   Initiating Callbacks   --------------------------------
82     .app_gap_connect_cb                 = app_gap_connect_cb,
83     .app_gap_disconnect_cb              = app_gap_disconnect_cb,
84     .app_gap_connect_cancel_cb          = app_gap_connect_cancel_cb,
85     .app_gap_auto_connection_timeout_cb = app_gap_auto_connection_timeout_cb,
86     .app_gap_peer_name_ind_cb           = app_gap_peer_name_ind_cb,
87 
88     // -------------------------   Connection Control Callbacks  -------------------------
89     .app_gap_connection_update_cb       = app_gap_connection_update_cb,
90     .app_gap_connection_update_req_cb   = app_gap_connection_update_req_cb,
91     .app_gap_connection_info_get_cb     = app_gap_connection_info_get_cb,
92     .app_gap_peer_info_get_cb           = app_gap_peer_info_get_cb,
93     .app_gap_le_pkt_size_info_cb        = app_gap_le_pkt_size_info_cb,
94 };
95 
96 
97 /*
98  * LOCAL FUNCTION DEFINITIONS
99  *****************************************************************************************
100  */
101 /**
102  ****************************************************************************************
103  * @brief This callback function will be called when the set param(s) operation has completed.
104  *
105  * @param[in] status:       The status of set param operation.
106  * @param[in] set_param_op: The operation of setting. @see gap_param_set_op_id_t.
107  ****************************************************************************************
108  */
app_gap_param_set_cb(uint8_t status,const gap_param_set_op_id_t set_param_op)109 static void app_gap_param_set_cb(uint8_t status, const gap_param_set_op_id_t set_param_op)
110 {
111 }
112 
113 /**
114  ****************************************************************************************
115  * @brief This callback function will be called when the psm register/unregister operation has completed.
116  *
117  * @param[in] status:       The status of psm manager operations.
118  * @param[in] set_param_op: The operation of register/unregister psm. @see gap_psm_op_id_t
119  ****************************************************************************************
120  */
app_gap_psm_manager_cb(uint8_t status,const gap_psm_manager_op_id_t psm_op)121 static void app_gap_psm_manager_cb(uint8_t status, const gap_psm_manager_op_id_t psm_op)
122 {
123 }
124 
125 /**
126  ****************************************************************************************
127  * @brief This callback function will be called when update phy completed.
128  *
129  * @param[in] conn_idx:  The index of connections.
130  * @param[in] status:    The status of udpate phy operation.
131  * @param[in] p_phy_ind: The phy info.
132  ****************************************************************************************
133  */
app_gap_phy_update_cb(uint8_t conn_idx,uint8_t status,const gap_le_phy_ind_t * p_phy_ind)134 static void app_gap_phy_update_cb(uint8_t conn_idx, uint8_t status, const gap_le_phy_ind_t *p_phy_ind)
135 {
136 }
137 
138 /**
139  ****************************************************************************************
140  * @brief This callback function will be called once the requested parameters has been got.
141  *
142  * @param[in] status:     GAP operation status.
143  * @param[in] p_dev_info: The device info. See @ref gap_dev_info_get_t
144  ****************************************************************************************
145  */
app_gap_dev_info_get_cb(uint8_t status,const gap_dev_info_get_t * p_dev_info)146 static void app_gap_dev_info_get_cb(uint8_t status, const gap_dev_info_get_t *p_dev_info)
147 {
148 }
149 
150 /**
151  ****************************************************************************************
152  * @brief This callback function will be called when the adv has started.
153  *
154  * @param[in] inst_idx:  The advertising index. valid range is: 0 - 4.
155  * @param[in] status:    The status of starting a advertiser.
156  ****************************************************************************************
157  */
app_gap_adv_start_cb(uint8_t inst_idx,uint8_t status)158 static void app_gap_adv_start_cb(uint8_t inst_idx, uint8_t status)
159 {
160     if (BLE_SUCCESS != status) {
161         APP_LOG_DEBUG("Adverting started failed(0X%02X).", status);
162     }
163 }
164 
165 /**
166  ****************************************************************************************
167  * @brief This callback function will be called when the adv has stopped.
168  *
169  * @param[in] inst_idx: The advertising index. valid range is: 0 - 4.
170  * @param[in] status:   The status of stopping a advertiser. If status is not success, adv_stop_reason is invalid.
171  * @param[in] reason:   The stop reason. See @ref gap_stopped_reason_t.
172  ****************************************************************************************
173  */
app_gap_adv_stop_cb(uint8_t inst_idx,uint8_t status,gap_stopped_reason_t reason)174 static void app_gap_adv_stop_cb(uint8_t inst_idx, uint8_t status, gap_stopped_reason_t reason)
175 {
176     if (GAP_STOPPED_REASON_TIMEOUT == reason && BLE_SUCCESS == status) {
177         APP_LOG_DEBUG("Advertising timeout.");
178     }
179 }
180 
181 /**
182  ****************************************************************************************
183  * @brief This callback function will be called when app has received the scan request.
184  *
185  * @param[in] inst_idx:       The advertising index. valid range is: 0 - 4.
186  * @param[in] p_scanner_addr: The BD address. See @ref gap_bdaddr_t.
187  ****************************************************************************************
188  */
app_gap_scan_req_ind_cb(uint8_t inst_idx,const gap_bdaddr_t * p_scanner_addr)189 static void app_gap_scan_req_ind_cb(uint8_t inst_idx, const gap_bdaddr_t *p_scanner_addr)
190 {
191 }
192 
193 /**
194  ****************************************************************************************
195  * @brief This callback function will be called when update adv data completed.
196  *
197  * @param[in] inst_idx:The advertising index. valid range is: 0 - 4.
198  * @param[in] status:  The status of udpate phy operation.
199  ****************************************************************************************
200  */
app_gap_adv_data_update_cb(uint8_t inst_idx,uint8_t status)201 static void app_gap_adv_data_update_cb(uint8_t inst_idx, uint8_t status)
202 {
203 }
204 
205 /**
206  ****************************************************************************************
207  * @brief This callback function will be called when the scan has started.
208  *
209  * @param[in] status:  The status of starting a scanner.
210  ****************************************************************************************
211  */
app_gap_scan_start_cb(uint8_t status)212 static void app_gap_scan_start_cb(uint8_t status)
213 {
214 }
215 
216 /**
217  ****************************************************************************************
218  * @brief This callback function will be called when scanning stops.
219  *
220  * @param[in] status: The status of stopping a scanner.
221  * @param[in] reason: The stop reason. See @ref gap_stopped_reason_t.
222  ****************************************************************************************
223  */
app_gap_scan_stop_cb(uint8_t status,gap_stopped_reason_t reason)224 static void app_gap_scan_stop_cb(uint8_t status, gap_stopped_reason_t reason)
225 {
226 }
227 
228 /**
229  ****************************************************************************************
230  * @brief This callback function will be called once the advertising report has been received.
231  *
232  * @param[in] p_adv_report: The extended advertising report. See @ref gap_ext_adv_report_ind_t.
233  ****************************************************************************************
234  */
app_gap_adv_report_ind_cb(const gap_ext_adv_report_ind_t * p_adv_report)235 static void app_gap_adv_report_ind_cb(const gap_ext_adv_report_ind_t  *p_adv_report)
236 {
237 }
238 
239 /**
240  ****************************************************************************************
241  * @brief This callback function will be called once the periodic advertising synchronization has been established.
242  *
243  * @param[in] status:                  The status of sync.
244  * @param[in] p_sync_established_info: The established ind info.  See @ref gap_sync_established_ind_t.
245  ****************************************************************************************
246  */
app_gap_sync_establish_cb(uint8_t inst_idx,uint8_t status,const gap_sync_established_ind_t * p_sync_established_info)247 static void app_gap_sync_establish_cb(uint8_t inst_idx, uint8_t status,  \
248                                       const gap_sync_established_ind_t *p_sync_established_info)
249 {
250 }
251 
252 /**
253  ****************************************************************************************
254  * @brief This callback function will be called when sync has stopped.
255  *
256  * @param[in] status: The status of stopping sync.
257  ****************************************************************************************
258  */
app_gap_stop_sync_cb(uint8_t inst_idx,uint8_t status)259 static void app_gap_stop_sync_cb(uint8_t inst_idx, uint8_t status)
260 {
261 }
262 
263 /**
264  ****************************************************************************************
265  * @brief This callback function will be called once the periodic advertising synchronization has been lost.
266  ****************************************************************************************
267  */
app_gap_sync_lost_cb(uint8_t inst_idx)268 static void app_gap_sync_lost_cb(uint8_t inst_idx)
269 {
270 }
271 
272 /**
273  ****************************************************************************************
274  * @brief This callback function will be called when connection completed.
275  *
276  * @param[in] conn_idx:     The connection index.
277  * @param[in] status:       The status of operation. If status is not success, conn_idx and p_conn_param are invalid.
278  * @param[in] p_conn_param: The connection param.  See @ref gap_conn_cmp_t.
279  ****************************************************************************************
280  */
app_gap_connect_cb(uint8_t conn_idx,uint8_t status,const gap_conn_cmp_t * p_conn_param)281 static void app_gap_connect_cb(uint8_t conn_idx, uint8_t status, const gap_conn_cmp_t *p_conn_param)
282 {
283     if (BLE_SUCCESS == status) {
284         APP_LOG_INFO("Connected with the peer %02X:%02X:%02X:%02X:%02X:%02X.",
285                      p_conn_param->peer_addr.addr[5],
286                      p_conn_param->peer_addr.addr[4],
287                      p_conn_param->peer_addr.addr[3],
288                      p_conn_param->peer_addr.addr[2],
289                      p_conn_param->peer_addr.addr[1],
290                      p_conn_param->peer_addr.addr[0]);
291         app_connected_handler(conn_idx, p_conn_param);
292     }
293 }
294 
295 /**
296  ****************************************************************************************
297  * @brief This callback function will be called when disconnect completed.
298  *
299  * @param[in] conn_idx: The connection index.
300  * @param[in] status:   The status of operation. If status is not success, disconnect reason is invalid.
301  * @param[in] reason:   The reason of disconnect. See @ref BLE_STACK_ERROR_CODES.
302  ****************************************************************************************
303  */
app_gap_disconnect_cb(uint8_t conn_idx,uint8_t status,uint8_t reason)304 static void app_gap_disconnect_cb(uint8_t conn_idx, uint8_t status, uint8_t reason)
305 {
306     if (BLE_SUCCESS == status) {
307         APP_LOG_INFO("Disconnected (0x%02X).", reason);
308         app_disconnected_handler(conn_idx, reason);
309     }
310 }
311 
312 /**
313  ****************************************************************************************
314  * @brief This callback function will be called when connection canceled.
315  *
316  * @param[in] status: The status of cancel operation.
317  ****************************************************************************************
318 */
app_gap_connect_cancel_cb(uint8_t status)319 static void app_gap_connect_cancel_cb(uint8_t status)
320 {
321 }
322 
323 /**
324  ****************************************************************************************
325  * @brief This callback function will be called when an automatic connection timeout occurs.
326  ****************************************************************************************
327  */
app_gap_auto_connection_timeout_cb(void)328 static void app_gap_auto_connection_timeout_cb(void)
329 {
330 }
331 
332 /**
333  ****************************************************************************************
334  * @brief This callback function will be called when the peer name info has been got.
335  *
336  * @param[in] conn_idx:    The connection index.
337  * @param[in] p_peer_name: The peer device name indication info. See @ref gap_peer_name_ind_t.
338  ****************************************************************************************
339  */
app_gap_peer_name_ind_cb(uint8_t conn_idx,const gap_peer_name_ind_t * p_peer_name)340 static void app_gap_peer_name_ind_cb(uint8_t conn_idx, const gap_peer_name_ind_t  *p_peer_name)
341 {
342 }
343 
344 /**
345  ****************************************************************************************
346  * @brief This callback function will be called when connection update completed.
347  *
348  * @param[in] conn_idx:                 The connection index.
349  * @param[in] status:                   The status of GAP operation.
350  * @param[in] p_conn_param_update_info: The connection update complete param. See @ref gap_conn_update_cmp_t.
351  ****************************************************************************************
352  */
app_gap_connection_update_cb(uint8_t conn_idx,uint8_t status,const gap_conn_update_cmp_t * p_conn_param_update_info)353 static void app_gap_connection_update_cb(uint8_t conn_idx, uint8_t status, \
354                                          const gap_conn_update_cmp_t *p_conn_param_update_info)
355 {
356 }
357 
358 /**
359  ****************************************************************************************
360  * @brief This callback function will be called when the peer device requests updating connection.
361  *
362  * @param[in] conn_idx:                The connection index.
363  * @param[in] p_conn_param_update_req: The connection update request param. See @ref gap_conn_param_t.
364  ****************************************************************************************
365  */
app_gap_connection_update_req_cb(uint8_t conn_idx,const gap_conn_param_t * p_conn_param_update_req)366 static void app_gap_connection_update_req_cb(uint8_t conn_idx, const gap_conn_param_t *p_conn_param_update_req)
367 {
368     ble_gap_conn_param_update_reply(conn_idx, true);
369 }
370 
371 /**
372  ****************************************************************************************
373  * @brief This callback function will be called when app has got the connection info.
374  *
375  * @param[in] conn_idx:                The connection index.
376  * @param[in] status:                  The status of GAP operation.
377  * @param[in] p_conn_param_update_req: The connection info. See @ref  gap_conn_info_param_t.
378  ****************************************************************************************
379  */
app_gap_connection_info_get_cb(uint8_t conn_idx,uint8_t status,const gap_conn_info_param_t * p_conn_info)380 static void app_gap_connection_info_get_cb(uint8_t conn_idx, uint8_t status, const gap_conn_info_param_t *p_conn_info)
381 {
382 }
383 
384 /**
385  ****************************************************************************************
386  * @brief This callback function will be called when app has got the peer info.
387  *
388  * @param[in]  conn_idx:        The connection index.
389  * @param[in]  status:          The status of GAP operation.
390  * @param[in]  p_peer_dev_info: The peer device info. See @ref gap_peer_info_param_t.
391  ****************************************************************************************
392  */
app_gap_peer_info_get_cb(uint8_t conn_idx,uint8_t status,const gap_peer_info_param_t * p_peer_dev_info)393 static void app_gap_peer_info_get_cb(uint8_t conn_idx,  uint8_t status, const gap_peer_info_param_t *p_peer_dev_info)
394 {
395 }
396 
397 /**
398  ****************************************************************************************
399  * @brief This callback function will be called when an app sets the length size of the supported data.
400  *
401  * @param[in]  conn_idx:                     The connection index.
402  * @param[in]  status:                       The status of GAP operation.
403  * @param[in]  p_supported_data_length_size: Supported data length size. See @ref gap_le_pkt_size_ind_t.
404  ****************************************************************************************
405  */
app_gap_le_pkt_size_info_cb(uint8_t conn_idx,uint8_t status,const gap_le_pkt_size_ind_t * p_supported_data_length)406 static void app_gap_le_pkt_size_info_cb(uint8_t conn_idx,  uint8_t status, \
407                                         const gap_le_pkt_size_ind_t *p_supported_data_length)
408 {
409 }
410