1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 // 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 #ifndef __BTC_GATTS_H__ 16 #define __BTC_GATTS_H__ 17 18 #include "btc/btc_task.h" 19 #include "esp_bt_defs.h" 20 #include "esp_gatt_defs.h" 21 #include "esp_gatts_api.h" 22 #include "osi/future.h" 23 24 typedef enum { 25 BTC_GATTS_ACT_APP_REGISTER = 0, 26 BTC_GATTS_ACT_APP_UNREGISTER, 27 BTC_GATTS_ACT_CREATE_SERVICE, 28 BTC_GATTS_ACT_CREATE_ATTR_TAB, 29 BTC_GATTS_ACT_DELETE_SERVICE, 30 BTC_GATTS_ACT_START_SERVICE, 31 BTC_GATTS_ACT_STOP_SERVICE, 32 BTC_GATTS_ACT_ADD_INCLUDE_SERVICE, 33 BTC_GATTS_ACT_ADD_CHAR, 34 BTC_GATTS_ACT_ADD_CHAR_DESCR, 35 BTC_GATTS_ACT_SEND_INDICATE, 36 BTC_GATTS_ACT_SEND_RESPONSE, 37 BTC_GATTS_ACT_SET_ATTR_VALUE, 38 BTC_GATTS_ACT_OPEN, 39 BTC_GATTS_ACT_CLOSE, 40 BTC_GATTS_ACT_SEND_SERVICE_CHANGE, 41 } btc_gatts_act_t; 42 43 /* btc_ble_gatts_args_t */ 44 typedef union { 45 //BTC_GATTS_ACT_APP_REGISTER = 0, 46 struct app_reg_args { 47 uint16_t app_id; 48 } app_reg; 49 50 //BTC_GATTS_ACT_APP_UNREGISTER, 51 struct app_unreg_args { 52 esp_gatt_if_t gatts_if; 53 } app_unreg; 54 55 //BTC_GATTS_ACT_CREATE_SERVICE, 56 struct create_srvc_args { 57 esp_gatt_if_t gatts_if; 58 esp_gatt_srvc_id_t service_id; 59 uint16_t num_handle; 60 } create_srvc; 61 62 //BTC_GATTS_ACT_CREATE_ATTR_TAB 63 struct create_attr_tab_args{ 64 esp_gatt_if_t gatts_if; 65 uint8_t srvc_inst_id; 66 uint8_t max_nb_attr; 67 esp_gatts_attr_db_t *gatts_attr_db; 68 }create_attr_tab; 69 70 //BTC_GATTS_ACT_DELETE_SERVICE, 71 struct delete_srvc_args { 72 uint16_t service_handle; 73 } delete_srvc; 74 75 //BTC_GATTS_ACT_START_SERVICE, 76 struct start_srvc_args { 77 uint16_t service_handle; 78 } start_srvc; 79 80 //BTC_GATTS_ACT_STOP_SERVICE, 81 struct stop_srvc_args { 82 uint16_t service_handle; 83 } stop_srvc; 84 85 //BTC_GATTS_ACT_ADD_INCLUDE_SERVICE, 86 struct add_incl_srvc_args { 87 uint16_t service_handle; 88 uint16_t included_service_handle; 89 } add_incl_srvc; 90 91 //BTC_GATTS_ACT_ADD_CHAR, 92 struct add_char_args { 93 uint16_t service_handle; 94 esp_bt_uuid_t char_uuid; 95 esp_gatt_perm_t perm; 96 esp_gatt_char_prop_t property; 97 esp_attr_control_t attr_control; 98 esp_attr_value_t char_val; 99 } add_char; 100 101 //BTC_GATTS_ACT_ADD_CHAR_DESCR, 102 struct add_descr_args { 103 uint16_t service_handle; 104 esp_bt_uuid_t descr_uuid; 105 esp_gatt_perm_t perm; 106 esp_attr_control_t attr_control; 107 esp_attr_value_t descr_val; 108 } add_descr; 109 110 //BTC_GATTS_ACT_SEND_INDICATE, 111 struct send_indicate_args { 112 uint16_t conn_id; 113 uint16_t attr_handle; 114 bool need_confirm; 115 uint16_t value_len; 116 uint8_t *value; 117 } send_ind; 118 119 //BTC_GATTS_ACT_SEND_RESPONSE, 120 struct send_rsp_args { 121 uint16_t conn_id; 122 uint32_t trans_id; 123 esp_gatt_status_t status; 124 esp_gatt_rsp_t *rsp; 125 } send_rsp; 126 127 //BTC_GATTS_SET_ATTR_VALUE 128 struct set_attr_val_args { 129 uint16_t handle; 130 uint16_t length; 131 uint8_t *value; 132 } set_attr_val; 133 134 //BTC_GATTS_ACT_OPEN, 135 struct open_args { 136 esp_gatt_if_t gatts_if; 137 esp_bd_addr_t remote_bda; 138 bool is_direct; 139 } open; 140 141 //BTC_GATTS_ACT_CLOSE, 142 struct close_args { 143 uint16_t conn_id; 144 } close; 145 146 //BTC_GATTS_ACT_SEND_SERVICE_CHANGE, 147 struct send_service_change_args { 148 esp_gatt_if_t gatts_if; 149 esp_bd_addr_t remote_bda; 150 } send_service_change; 151 152 } btc_ble_gatts_args_t; 153 154 typedef struct { 155 future_t *complete_future; 156 uint16_t svc_start_hdl; 157 esp_bt_uuid_t svc_uuid; 158 bool is_tab_creat_svc; 159 bool is_use_svc; 160 uint8_t num_handle; 161 uint8_t handle_idx; 162 uint16_t handles[ESP_GATT_ATTR_HANDLE_MAX]; 163 } esp_btc_creat_tab_t; 164 165 #if GATT_DYNAMIC_MEMORY == TRUE 166 extern esp_btc_creat_tab_t *btc_creat_tab_env_ptr; 167 #define btc_creat_tab_env (*btc_creat_tab_env_ptr) 168 #endif 169 170 void btc_gatts_call_handler(btc_msg_t *msg); 171 void btc_gatts_cb_handler(btc_msg_t *msg); 172 void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); 173 esp_gatt_status_t btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, uint8_t **value); 174 175 176 #endif /* __BTC_GATTS_H__ */ 177