1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 #ifndef H_BLE_GATT_PRIV_ 21 #define H_BLE_GATT_PRIV_ 22 23 #include "syscfg/syscfg.h" 24 #include "stats/stats.h" 25 #include "host/ble_gatt.h" 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 struct ble_att_read_type_adata; 31 struct ble_att_find_type_value_hinfo; 32 struct ble_att_find_info_idata; 33 struct ble_att_read_group_type_adata; 34 struct ble_att_prep_write_cmd; 35 36 STATS_SECT_START(ble_gattc_stats) 37 STATS_SECT_ENTRY(mtu) 38 STATS_SECT_ENTRY(mtu_fail) 39 STATS_SECT_ENTRY(disc_all_svcs) 40 STATS_SECT_ENTRY(disc_all_svcs_fail) 41 STATS_SECT_ENTRY(disc_svc_uuid) 42 STATS_SECT_ENTRY(disc_svc_uuid_fail) 43 STATS_SECT_ENTRY(find_inc_svcs) 44 STATS_SECT_ENTRY(find_inc_svcs_fail) 45 STATS_SECT_ENTRY(disc_all_chrs) 46 STATS_SECT_ENTRY(disc_all_chrs_fail) 47 STATS_SECT_ENTRY(disc_chrs_uuid) 48 STATS_SECT_ENTRY(disc_chrs_uuid_fail) 49 STATS_SECT_ENTRY(disc_all_dscs) 50 STATS_SECT_ENTRY(disc_all_dscs_fail) 51 STATS_SECT_ENTRY(read) 52 STATS_SECT_ENTRY(read_fail) 53 STATS_SECT_ENTRY(read_uuid) 54 STATS_SECT_ENTRY(read_uuid_fail) 55 STATS_SECT_ENTRY(read_long) 56 STATS_SECT_ENTRY(read_long_fail) 57 STATS_SECT_ENTRY(read_mult) 58 STATS_SECT_ENTRY(read_mult_fail) 59 STATS_SECT_ENTRY(write_no_rsp) 60 STATS_SECT_ENTRY(write_no_rsp_fail) 61 STATS_SECT_ENTRY(write) 62 STATS_SECT_ENTRY(write_fail) 63 STATS_SECT_ENTRY(write_long) 64 STATS_SECT_ENTRY(write_long_fail) 65 STATS_SECT_ENTRY(write_reliable) 66 STATS_SECT_ENTRY(write_reliable_fail) 67 STATS_SECT_ENTRY(notify) 68 STATS_SECT_ENTRY(notify_fail) 69 STATS_SECT_ENTRY(indicate) 70 STATS_SECT_ENTRY(indicate_fail) 71 STATS_SECT_ENTRY(proc_timeout) 72 STATS_SECT_END 73 extern STATS_SECT_DECL(ble_gattc_stats) ble_gattc_stats; 74 75 STATS_SECT_START(ble_gatts_stats) 76 STATS_SECT_ENTRY(svcs) 77 STATS_SECT_ENTRY(chrs) 78 STATS_SECT_ENTRY(dscs) 79 STATS_SECT_ENTRY(svc_def_reads) 80 STATS_SECT_ENTRY(svc_inc_reads) 81 STATS_SECT_ENTRY(chr_def_reads) 82 STATS_SECT_ENTRY(chr_val_reads) 83 STATS_SECT_ENTRY(chr_val_writes) 84 STATS_SECT_ENTRY(dsc_reads) 85 STATS_SECT_ENTRY(dsc_writes) 86 STATS_SECT_END 87 extern STATS_SECT_DECL(ble_gatts_stats) ble_gatts_stats; 88 89 #define BLE_GATT_CHR_DECL_SZ_16 5 90 #define BLE_GATT_CHR_DECL_SZ_128 19 91 92 typedef uint8_t ble_gatts_conn_flags; 93 94 struct ble_gatts_conn { 95 struct ble_gatts_clt_cfg *clt_cfgs; 96 int num_clt_cfgs; 97 98 uint16_t indicate_val_handle; 99 }; 100 101 /*** @client. */ 102 103 int ble_gattc_locked_by_cur_task(void); 104 void ble_gatts_indicate_fail_notconn(uint16_t conn_handle); 105 106 void ble_gattc_rx_err(uint16_t conn_handle, uint16_t handle, uint16_t status); 107 void ble_gattc_rx_mtu(uint16_t conn_handle, int status, uint16_t chan_mtu); 108 void ble_gattc_rx_read_type_adata(uint16_t conn_handle, 109 struct ble_att_read_type_adata *adata); 110 void ble_gattc_rx_read_type_complete(uint16_t conn_handle, int status); 111 void ble_gattc_rx_read_rsp(uint16_t conn_handle, int status, 112 struct os_mbuf **rxom); 113 void ble_gattc_rx_read_blob_rsp(uint16_t conn_handle, int status, 114 struct os_mbuf **rxom); 115 void ble_gattc_rx_read_mult_rsp(uint16_t conn_handle, int status, 116 struct os_mbuf **rxom); 117 void ble_gattc_rx_read_group_type_adata(uint16_t conn_handle, struct ble_att_read_group_type_adata *adata); 118 void ble_gattc_rx_read_group_type_complete(uint16_t conn_handle, int rc); 119 void ble_gattc_rx_find_type_value_hinfo(uint16_t conn_handle, struct ble_att_find_type_value_hinfo *hinfo); 120 void ble_gattc_rx_find_type_value_complete(uint16_t conn_handle, int status); 121 void ble_gattc_rx_write_rsp(uint16_t conn_handle); 122 void ble_gattc_rx_prep_write_rsp(uint16_t conn_handle, int status, 123 uint16_t handle, uint16_t offset, 124 struct os_mbuf **rxom); 125 void ble_gattc_rx_exec_write_rsp(uint16_t conn_handle, int status); 126 void ble_gattc_rx_indicate_rsp(uint16_t conn_handle); 127 void ble_gattc_rx_find_info_idata(uint16_t conn_handle, 128 struct ble_att_find_info_idata *idata); 129 void ble_gattc_rx_find_info_complete(uint16_t conn_handle, int status); 130 void ble_gattc_connection_txable(uint16_t conn_handle); 131 void ble_gattc_connection_broken(uint16_t conn_handle); 132 int32_t ble_gattc_timer(void); 133 134 int ble_gattc_any_jobs(void); 135 int ble_gattc_init(void); 136 137 /*** @server. */ 138 #define BLE_GATTS_CLT_CFG_F_NOTIFY 0x0001 139 #define BLE_GATTS_CLT_CFG_F_INDICATE 0x0002 140 #define BLE_GATTS_CLT_CFG_F_MODIFIED 0x0080 /* Internal only. */ 141 #define BLE_GATTS_CLT_CFG_F_RESERVED 0xfffc 142 143 #define BLE_GATTS_INC_SVC_LEN_NO_UUID 4 144 #define BLE_GATTS_INC_SVC_LEN_UUID 6 145 146 /** 147 * Contains counts of resources required by the GATT server. The contents of 148 * this struct are generally used to populate a configuration struct before 149 * the host is initialized. 150 */ 151 struct ble_gatt_resources { 152 /** Number of services. */ 153 uint16_t svcs; 154 155 /** Number of included services. */ 156 uint16_t incs; 157 158 /** Number of characteristics. */ 159 uint16_t chrs; 160 161 /** Number of descriptors. */ 162 uint16_t dscs; 163 164 /** 165 * Number of client characteristic configuration descriptors. Each of 166 * these also contributes to the total descriptor count. 167 */ 168 uint16_t cccds; 169 170 /** Total number of ATT attributes. */ 171 uint16_t attrs; 172 }; 173 174 int ble_gatts_rx_indicate_ack(uint16_t conn_handle, uint16_t chr_val_handle); 175 int ble_gatts_send_next_indicate(uint16_t conn_handle); 176 void ble_gatts_tx_notifications(void); 177 void ble_gatts_bonding_established(uint16_t conn_handle); 178 void ble_gatts_bonding_restored(uint16_t conn_handle); 179 void ble_gatts_connection_broken(uint16_t conn_handle); 180 void ble_gatts_lcl_svc_foreach(ble_gatt_svc_foreach_fn cb, void *arg); 181 int ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs, 182 ble_gatt_register_fn *register_cb, 183 void *cb_arg); 184 int ble_gatts_clt_cfg_access(uint16_t conn_handle, uint16_t attr_handle, 185 uint8_t op, uint16_t offset, struct os_mbuf **om, 186 void *arg); 187 188 /*** @misc. */ 189 int ble_gatts_conn_can_alloc(void); 190 int ble_gatts_conn_init(struct ble_gatts_conn *gatts_conn); 191 int ble_gatts_init(void); 192 193 #ifdef __cplusplus 194 } 195 #endif 196 197 #endif 198