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
22 /*
23 * LOCAL FUNCTION DECLARATION
24 ******************************************************************************************
25 */
26 static void app_gattc_srvc_disc_cb(uint8_t conn_idx, uint8_t status, const ble_gattc_srvc_disc_t *p_prim_srvc_disc);
27 static void app_gattc_inc_srvc_disc_cb(uint8_t conn_idx, uint8_t status, const ble_gattc_incl_disc_t *p_inc_srvc_disc);
28 static void app_gattc_char_disc_cb(uint8_t conn_idx, uint8_t status, const ble_gattc_char_disc_t *p_char_disc);
29 static void app_gattc_char_desc_disc_cb(uint8_t conn_idx, uint8_t status, \
30 const ble_gattc_char_desc_disc_t *p_char_desc_disc);
31 static void app_gattc_read_cb(uint8_t conn_idx, uint8_t status, const ble_gattc_read_rsp_t *p_read_rsp);
32 static void app_gattc_write_cb(uint8_t conn_idx, uint8_t status, uint16_t handle);
33 static void app_gattc_ntf_ind_cb(uint8_t conn_idx, const ble_gattc_ntf_ind_t *p_ntf_ind);
34 static void app_gattc_srvc_browse_cb(uint8_t conn_idx, uint8_t status, const ble_gattc_browse_srvc_t *p_browse_srvc);
35
36 /*
37 * GLOBAL VARIABLE DEFINITIONS
38 *****************************************************************************************
39 */
40 const gattc_cb_fun_t app_gattc_callback = {
41 .app_gattc_srvc_disc_cb = app_gattc_srvc_disc_cb,
42 .app_gattc_inc_srvc_disc_cb = app_gattc_inc_srvc_disc_cb,
43 .app_gattc_char_disc_cb = app_gattc_char_disc_cb,
44 .app_gattc_char_desc_disc_cb = app_gattc_char_desc_disc_cb,
45 .app_gattc_write_cb = app_gattc_write_cb,
46 .app_gattc_read_cb = app_gattc_read_cb,
47 .app_gattc_ntf_ind_cb = app_gattc_ntf_ind_cb,
48 .app_gattc_srvc_browse_cb = app_gattc_srvc_browse_cb,
49 };
50
51 /*
52 * LOCAL FUNCTION DEFINITIONS
53 *****************************************************************************************
54 */
55 /**
56 *****************************************************************************************
57 * @brief This callback function will be called when primary service has been discovered.
58 *
59 * @param[in] conn_idx: The connection index.
60 * @param[in] status: The status of GATTC operation.
61 * @param[in] p_prim_srvc_disc: The information of primary service. See @ref ble_gattc_srvc_disc_t.
62 *****************************************************************************************
63 */
app_gattc_srvc_disc_cb(uint8_t conn_idx,uint8_t status,const ble_gattc_srvc_disc_t * p_prim_srvc_disc)64 static void app_gattc_srvc_disc_cb(uint8_t conn_idx, uint8_t status, const ble_gattc_srvc_disc_t *p_prim_srvc_disc)
65 {
66 }
67
68 /**
69 *****************************************************************************************
70 * @brief This callback function will be called when service relationship has been discovered.
71 *
72 * @param[in] conn_idx: The connection index.
73 * @param[in] status: The status of GATTC operation.
74 * @param[in] p_inc_srvc_disc: The information of service relationship. See @ref ble_gattc_incl_disc_t.
75 *****************************************************************************************
76 */
app_gattc_inc_srvc_disc_cb(uint8_t conn_idx,uint8_t status,const ble_gattc_incl_disc_t * p_inc_srvc_disc)77 static void app_gattc_inc_srvc_disc_cb(uint8_t conn_idx, uint8_t status, const ble_gattc_incl_disc_t *p_inc_srvc_disc)
78 {
79 }
80
81 /**
82 *****************************************************************************************
83 * @brief This callback function will be called when descriptor(s) has been discovered.
84 *
85 * @param[in] conn_idx: The connection index.
86 * @param[in] status: The status of GATTC operation.
87 * @param[in] p_char_disc: The information of descriptor(s). See @ref ble_gattc_char_disc_t.
88 *****************************************************************************************
89 */
app_gattc_char_disc_cb(uint8_t conn_idx,uint8_t status,const ble_gattc_char_disc_t * p_char_disc)90 static void app_gattc_char_disc_cb(uint8_t conn_idx, uint8_t status, const ble_gattc_char_disc_t *p_char_disc)
91 {
92 }
93
94 /**
95 *****************************************************************************************
96 * @brief This callback function will be called when characteristic(s) has been discovered.
97 *
98 * @param[in] conn_idx: The connection index.
99 * @param[in] status: The status of GATTC operation.
100 * @param[in] p_char_desc_disc: The information of characteristic(s). See @ref ble_gattc_char_desc_disc_t.
101 *****************************************************************************************
102 */
app_gattc_char_desc_disc_cb(uint8_t conn_idx,uint8_t status,const ble_gattc_char_desc_disc_t * p_char_desc_disc)103 static void app_gattc_char_desc_disc_cb(uint8_t conn_idx, uint8_t status, \
104 const ble_gattc_char_desc_disc_t *p_char_desc_disc)
105 {
106 }
107
108 /**
109 *****************************************************************************************
110 * @brief This callback function will be called when receiving read response.
111 *
112 * @param[in] conn_idx: The connection index.
113 * @param[in] status: The status of GATTC operation.
114 * @param[in] handle: The handle of attribute.
115 *****************************************************************************************
116 */
app_gattc_write_cb(uint8_t conn_idx,uint8_t status,uint16_t handle)117 static void app_gattc_write_cb(uint8_t conn_idx, uint8_t status, uint16_t handle)
118 {
119 }
120
121 /**
122 *****************************************************************************************
123 * @brief This callback function will be called when receiving read response.
124 *
125 * @param[in] conn_idx: The connection index.
126 * @param[in] status: The status of GATTC operation.
127 * @param[in] p_read_rsp: The information of read response. See @ref ble_gattc_read_rsp_t.
128 *****************************************************************************************
129 */
app_gattc_read_cb(uint8_t conn_idx,uint8_t status,const ble_gattc_read_rsp_t * p_read_rsp)130 static void app_gattc_read_cb(uint8_t conn_idx, uint8_t status, const ble_gattc_read_rsp_t *p_read_rsp)
131 {
132 }
133
134 /**
135 *****************************************************************************************
136 * @brief This callback function will be called when receiving notification or indication.
137 *
138 * @param[in] conn_idx: The connection index.
139 * @param[in] status: The status of GATTC operation.
140 * @param[in] p_ntf_ind: The information of notification or indication. See @ref ble_gattc_ntf_ind_t.
141 *****************************************************************************************
142 */
app_gattc_ntf_ind_cb(uint8_t conn_idx,const ble_gattc_ntf_ind_t * p_ntf_ind)143 static void app_gattc_ntf_ind_cb(uint8_t conn_idx, const ble_gattc_ntf_ind_t *p_ntf_ind)
144 {
145 if (BLE_GATT_INDICATION == p_ntf_ind->type) {
146 ble_gattc_indicate_cfm(conn_idx, p_ntf_ind->handle);
147 }
148 }
149
150 /**
151 *****************************************************************************************
152 * @brief This callback function will be called when receiving browse service indication.
153 *
154 * @param[in] conn_idx: The connection index.
155 * @param[in] status: The status of GATTC operation.
156 * @param[in] p_browse_srvc: The information of service browse. See @ref ble_gattc_browse_srvc_t.
157 *****************************************************************************************
158 */
app_gattc_srvc_browse_cb(uint8_t conn_idx,uint8_t status,const ble_gattc_browse_srvc_t * p_browse_srvc)159 static void app_gattc_srvc_browse_cb(uint8_t conn_idx, uint8_t status, const ble_gattc_browse_srvc_t *p_browse_srvc)
160 {
161 }
162